|
|
@@ -24,20 +24,29 @@ import (
|
|
|
var download = flag.Bool("download", false, "If true, download any missing files before running benchmarks")
|
|
|
|
|
|
// goEncoderShouldMatchCppEncoder is whether to test that the algorithm used by
|
|
|
-// Go's encoder matches byte-for-byte what the C++ snappy encoder produces.
|
|
|
-// There is more than one valid encoding of any given input, and there is more
|
|
|
-// than one good algorithm along the frontier of trading off throughput for
|
|
|
-// output size. Nonetheless, we presume that the C++ encoder's algorithm is a
|
|
|
-// good one and has been tested on a wide range of inputs, so matching that
|
|
|
-// exactly should mean that the Go encoder's algorithm is also good, without
|
|
|
-// needing to gather our own corpus of test data.
|
|
|
+// Go's encoder matches byte-for-byte what the C++ snappy encoder produces, on
|
|
|
+// this GOARCH. There is more than one valid encoding of any given input, and
|
|
|
+// there is more than one good algorithm along the frontier of trading off
|
|
|
+// throughput for output size. Nonetheless, we presume that the C++ encoder's
|
|
|
+// algorithm is a good one and has been tested on a wide range of inputs, so
|
|
|
+// matching that exactly should mean that the Go encoder's algorithm is also
|
|
|
+// good, without needing to gather our own corpus of test data.
|
|
|
//
|
|
|
-// The exact algorithm used, though, is endianness-dependent, as it puns a
|
|
|
-// byte-pointer to a uint32-pointer to load and compare 4 bytes at a time. For
|
|
|
-// example, the "testdata/pi.txt.rawsnappy" file was generated by C++ code on a
|
|
|
-// little-endian system. The runtime package doesn't export endianness per se,
|
|
|
+// The exact algorithm used by the C++ code is potentially endian dependent, as
|
|
|
+// it puns a byte pointer to a uint32 pointer to load, hash and compare 4 bytes
|
|
|
+// at a time. The Go implementation is endian agnostic, in that its output is
|
|
|
+// the same (as little-endian C++ code), regardless of the CPU's endianness.
|
|
|
+//
|
|
|
+// Thus, when comparing Go's output to C++ output generated beforehand, such as
|
|
|
+// the "testdata/pi.txt.rawsnappy" file generated by C++ code on a little-
|
|
|
+// endian system, we can run that test regardless of the runtime.GOARCH value.
|
|
|
+//
|
|
|
+// When comparing Go's output to dynamically generated C++ output, i.e. the
|
|
|
+// result of fork/exec'ing a C++ program, we can run that test only on
|
|
|
+// little-endian systems, because the C++ output might be different on
|
|
|
+// big-endian systems. The runtime package doesn't export endianness per se,
|
|
|
// but we can restrict this match-C++ test to common little-endian systems.
|
|
|
-const goEncoderShouldMatchCppEncoder = runtime.GOARCH == "386" || runtime.GOARCH == "amd64"
|
|
|
+const goEncoderShouldMatchCppEncoder = runtime.GOARCH == "386" || runtime.GOARCH == "amd64" || runtime.GOARCH == "arm"
|
|
|
|
|
|
func TestMaxEncodedLenOfMaxBlockSize(t *testing.T) {
|
|
|
got := maxEncodedLenOfMaxBlockSize
|
|
|
@@ -469,9 +478,6 @@ func TestDecodeGoldenInput(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestEncodeGoldenInput(t *testing.T) {
|
|
|
- if !goEncoderShouldMatchCppEncoder {
|
|
|
- t.Skipf("skipping testing that the encoding is byte-for-byte identical to C++: GOARCH=%s", runtime.GOARCH)
|
|
|
- }
|
|
|
src, err := ioutil.ReadFile("testdata/pi.txt")
|
|
|
if err != nil {
|
|
|
t.Fatalf("ReadFile: %v", err)
|