merge master into ws/videoctl
This commit is contained in:
commit
f7c8abc1b4
24 files changed
+16704
-1565
No files matched your search
@@ -0,0 +1,56 @@
|
||||
# Detection fixtures (tools/fixtures.py): samples of every other fixture module, for tests/detect.luau (lazy detection
|
||||
# against the eager reference). Runs after the other generators (LAST) and reads their tests/gen output.
|
||||
# tests/gen/detect_blobs_<1..4>.luau { { from = "<module>", data = <bytes> } }: up to PER_MODULE string literals of
|
||||
# 16 bytes or more per module, evenly spaced, cut to CUT bytes, without repeats
|
||||
import hashlib, os, re
|
||||
|
||||
LAST = True
|
||||
PER_MODULE = 6
|
||||
CUT = 16384
|
||||
PARTS = 4
|
||||
PART_BYTES = 5_000_000
|
||||
HEADER = "-- generated by tools/fixtures.py"
|
||||
LITERAL = re.compile(rb'"([^"]*)"')
|
||||
ESCAPE = re.compile(rb"\\x([0-9a-f]{2})")
|
||||
|
||||
|
||||
def decode(raw):
|
||||
return ESCAPE.sub(lambda m: bytes([int(m.group(1), 16)]), raw)
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
names = sorted(f[:-5] for f in os.listdir(ctx.gen) if f.endswith(".luau") and not f.startswith("detect_"))
|
||||
seen, blobs = set(), []
|
||||
for name in names:
|
||||
with open(os.path.join(ctx.gen, name + ".luau"), "rb") as f:
|
||||
text = f.read()
|
||||
if not text.startswith(HEADER.encode()):
|
||||
continue
|
||||
lits = [m.span(1) for m in LITERAL.finditer(text) if m.end(1) - m.start(1) >= 16]
|
||||
lits = [(a, b) for a, b in lits if len(decode(text[a:min(b, a + 64)])) >= 16]
|
||||
if not lits:
|
||||
continue
|
||||
step = max(1, len(lits) / PER_MODULE)
|
||||
picks = sorted({int(i * step) for i in range(PER_MODULE)} & set(range(len(lits))))
|
||||
for i in picks:
|
||||
a, b = lits[i]
|
||||
data = decode(text[a:min(b, a + CUT * 4)])[:CUT]
|
||||
h = hashlib.sha1(data).digest()
|
||||
if h in seen:
|
||||
continue
|
||||
seen.add(h)
|
||||
blobs.append({"from": name, "data": data})
|
||||
parts, cur, size = [], [], 0
|
||||
for b in blobs:
|
||||
if size + len(b["data"]) > PART_BYTES and cur:
|
||||
parts.append(cur)
|
||||
cur, size = [], 0
|
||||
cur.append(b)
|
||||
size += len(b["data"])
|
||||
parts.append(cur)
|
||||
if len(parts) > PARTS:
|
||||
raise SystemExit("fixtures/detect: %d parts, raise PARTS (and the requires in tests/detect.luau)" % len(parts))
|
||||
while len(parts) < PARTS:
|
||||
parts.append([])
|
||||
for i, p in enumerate(parts, 1):
|
||||
ctx.emit("detect_blobs_%d" % i, p)
|
||||
Reference in new issue
Block a user