# LZ4 frame fixtures (tools/fixtures.py): corpora compressed by the lz4 tool 1.10 (nixpkgs#lz4) with its frame options # (default, linked blocks -BD, 64 KB blocks -B4 with and without -BD, block checksums -BX, --content-size, # --no-frame-crc, -9, the legacy format -l), concatenated frames and a skippable frame; and our writer's frames # (tools/fixtures/_lz4frame_encode.luau under the luau CLI) decompressed by `lz4 -d`, as verdicts. # tests/gen/lz4frame.luau { cases = { { name, corpus, data } }, ours = { { name, ok } } } # tests/gen/lz4frame_corpora.luau { [name] = bytes } import os, shutil, struct, subprocess, tempfile INPUTS = ["src/Rosetta/archive/lz4/init.luau", "src/Rosetta/codecs/compress/Lz4.luau", "src/Rosetta/codecs/compress/Xxh32.luau", "tools/fixtures/_lz4frame_encode.luau"] def lz4(args, data=None, path=None): argv = ["nix", "shell", "nixpkgs#lz4", "-c", "lz4"] + args + ([path] if path else []) return subprocess.run(argv, input=data, capture_output=True, check=True).stdout def corpora(rng): base = os.path.dirname(os.__file__) text = bytearray() for name in sorted(os.listdir(base)): if name.endswith(".py"): with open(os.path.join(base, name), "rb") as f: text += f.read() if len(text) >= 160000: break return {"empty": b"", "short": b"hello, lz4 frames\n", "text": bytes(text[:160000]), "random": rng.randbytes(20000), "zeros": b"\0" * 300000} def luau_cmd(): exe = shutil.which("luau") return [exe] if exe else ["nix", "shell", "nixpkgs#luau", "-c", "luau"] def generate(ctx): cs = corpora(ctx.rng(43)) cases = [] tmp = tempfile.mkdtemp() try: for name, data in cs.items(): path = os.path.join(tmp, name) with open(path, "wb") as f: f.write(data) variants = [("default", ["-c"])] if name in ("text", "zeros", "short"): variants += [("BD", ["-c", "-BD"]), ("B4", ["-c", "-B4"]), ("B4BD", ["-c", "-B4", "-BD"]), ("BX", ["-c", "-B4", "-BX"]), ("size", ["-c", "--content-size"]), ("nocrc", ["-c", "--no-frame-crc"]), ("hc9", ["-c", "-9", "-B4", "-BD"]), ("legacy", ["-c", "-l"])] for vname, args in variants: cases.append({"name": name + "/" + vname, "corpus": name, "data": lz4(args, path=path)}) finally: shutil.rmtree(tmp) # two frames, and a skippable frame in front two = lz4(["-c"], data=cs["short"]) + lz4(["-c", "-B4"], data=cs["text"]) cases.append({"name": "concat", "corpus": "short+text", "data": two}) skip = struct.pack("