Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interoperability tests #151

Open
anatol opened this issue Nov 11, 2021 · 4 comments
Open

Add interoperability tests #151

anatol opened this issue Nov 11, 2021 · 4 comments

Comments

@anatol
Copy link
Contributor

anatol commented Nov 11, 2021

It would be great to add tests to make sure this library is compatible with lz4 C library (that can be considered here as a reference implementation).

Add a test that

  • compresses some text with lz4 command-line tool and then decompresses with this golang library
  • compresses some text with this library and decompress it with the command-line tool

Verify different compression mode, legacy/modern formats, ....

@pierrec
Copy link
Owner

pierrec commented Nov 11, 2021

All the LZ4 compressed files in the testdata directory have been generated by the C reference implementation.
I agree that not all combinations are currently tested though.

@anatol
Copy link
Contributor Author

anatol commented Nov 11, 2021

It is interesting. lz4 tool complains about some of the files under testdata/ dir:

➜  testdata git:(v4) lz4 --version
*** LZ4 command line interface 64-bits v1.9.3, by Yann Collet ***
➜  testdata git:(v4) lz4 --test vmlinux_LZ4_19377.lz4
Stream followed by undecodable data at position 11398804 
vmlinux_LZ4_19377.lz : decoded 45037000 bytes                                  
➜  testdata git:(v4) lz4 --test bzImage_lz4_isolated.lz4 
Error 52 : Read error : cannot access compressed block !

@anatol
Copy link
Contributor Author

anatol commented Dec 3, 2021

Here is an example of interoperability test for legacy writer

diff --git a/writer_test.go b/writer_test.go
index e43fd36..f0fee40 100644
--- a/writer_test.go
+++ b/writer_test.go
@@ -7,6 +7,7 @@ import (
        "io"
        "io/ioutil"
        "os"
+       "os/exec"
        "reflect"
        "strings"
        "testing"
@@ -247,6 +248,22 @@ func TestWriterLegacy(t *testing.T) {
                                t.Fatal(err)
                        }
 
+                       tmp, err := os.CreateTemp("", "")
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       defer os.Remove(tmp.Name())
+                       if _, err := tmp.Write(out.Bytes()); err != nil {
+                               t.Fatal(err)
+                       }
+
+                       cmd := exec.Command("lz4", "--test", tmp.Name())
+                       cmd.Stdout = os.Stdout
+                       cmd.Stderr = os.Stderr
+                       if err := cmd.Run(); err != nil {
+                               t.Fatal(err)
+                       }
+
                        out2 := new(bytes.Buffer)

@anatol
Copy link
Contributor Author

anatol commented Dec 3, 2021

Weird fact that lz4 dies not return error code on some invalid inputs, e.g. it prints

Stream followed by undecodable data at position 8 
/tmp/4278189638      : decoded 0 bytes 

but the error code is 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants