My working unpac space for OCaml projects in development
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add golden compression tests, remove debug executables

- Add test_golden_compress.ml: Tests compression of zstd reference
golden test files at all compression levels (1-19) with both OCaml
roundtrip and C zstd interop verification
- Remove debug executable entries from dune (files already deleted)

All 8 golden compression tests pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

+74 -39
+7 -39
test/dune
··· 24 24 (libraries zstd) 25 25 (modules scan_failures)) 26 26 27 - (executable 28 - (name debug_failure) 29 - (libraries zstd unix) 30 - (modules debug_failure)) 31 - 32 - (executable 33 - (name debug_failure2) 34 - (libraries zstd unix) 35 - (modules debug_failure2)) 36 - 37 - (executable 38 - (name debug_huffman) 39 - (libraries zstd) 40 - (modules debug_huffman)) 41 - 42 - (executable 43 - (name debug_simple) 44 - (libraries zstd unix) 45 - (modules debug_simple)) 46 - 47 - (executable 48 - (name debug_large) 49 - (libraries zstd) 50 - (modules debug_large)) 51 - 52 - (executable 53 - (name debug_json) 54 - (libraries zstd) 55 - (modules debug_json)) 56 - 57 - (executable 58 - (name debug_binary) 59 - (libraries zstd) 60 - (modules debug_binary)) 61 - 62 - (executable 63 - (name debug_sparse) 64 - (libraries zstd) 65 - (modules debug_sparse)) 27 + (test 28 + (name test_golden_compress) 29 + (package zstd-test) 30 + (libraries zstd alcotest) 31 + (deps 32 + (source_tree ../vendor/git/zstd-c/tests/golden-compression)) 33 + (modules test_golden_compress)) 66 34
+67
test/test_golden_compress.ml
··· 1 + (** Test compression of golden test files *) 2 + 3 + let project_root = Sys.getcwd () 4 + let golden_dir = project_root ^ "/vendor/git/zstd-c/tests/golden-compression" 5 + 6 + let read_file path = 7 + let ic = open_in_bin path in 8 + let len = in_channel_length ic in 9 + let buf = Bytes.create len in 10 + really_input ic buf 0 len; 11 + close_in ic; 12 + Bytes.to_string buf 13 + 14 + let test_file filename () = 15 + let path = golden_dir ^ "/" ^ filename in 16 + let original = read_file path in 17 + Printf.printf "Testing %s (%d bytes)... %!" filename (String.length original); 18 + 19 + (* Test at multiple compression levels *) 20 + for level = 1 to 19 do 21 + let compressed = Zstd.compress ~level original in 22 + match Zstd.decompress compressed with 23 + | Ok decompressed -> 24 + if decompressed <> original then 25 + Alcotest.fail (Printf.sprintf "Level %d: roundtrip mismatch" level) 26 + | Error msg -> 27 + Alcotest.fail (Printf.sprintf "Level %d: decompression failed: %s" level msg) 28 + done; 29 + Printf.printf "OK (all levels)\n%!" 30 + 31 + let test_c_interop filename () = 32 + let path = golden_dir ^ "/" ^ filename in 33 + let original = read_file path in 34 + Printf.printf "C interop for %s (%d bytes)... %!" filename (String.length original); 35 + 36 + (* Compress with OCaml, decompress with C zstd *) 37 + let compressed = Zstd.compress ~level:3 original in 38 + let tmp_zst = Filename.temp_file "test" ".zst" in 39 + let tmp_out = Filename.temp_file "test" ".out" in 40 + 41 + let oc = open_out_bin tmp_zst in 42 + output_string oc compressed; 43 + close_out oc; 44 + 45 + let ret = Sys.command (Printf.sprintf "zstd -d %s -o %s -f 2>/dev/null" tmp_zst tmp_out) in 46 + if ret <> 0 then begin 47 + Sys.remove tmp_zst; 48 + Alcotest.fail "C zstd failed to decompress OCaml output" 49 + end; 50 + 51 + let decompressed = read_file tmp_out in 52 + Sys.remove tmp_zst; 53 + Sys.remove tmp_out; 54 + 55 + if decompressed <> original then 56 + Alcotest.fail "C decompressed data doesn't match original" 57 + else 58 + Printf.printf "OK\n%!" 59 + 60 + let () = 61 + let files = ["http"; "huffman-compressed-larger"; "large-literal-and-match-lengths"; 62 + "PR-3517-block-splitter-corruption-test"] in 63 + 64 + Alcotest.run "golden compression" [ 65 + "roundtrip", List.map (fun f -> f, `Quick, test_file f) files; 66 + "c interop", List.map (fun f -> f ^ " (C)", `Quick, test_c_interop f) files; 67 + ]