From 07e18043145f3d91c8ea7ec3ad41b3c905585277 Mon Sep 17 00:00:00 2001 From: Ethan Werner Date: Wed, 1 Jul 2026 09:42:39 +0400 Subject: initial commit: ts time series analysis library v0.1.0 - 354 financial and mathematical time-series indicators - Uniform C11 API with consistent function signatures - 349 passing tests with -Werror - Static and shared library builds - pkg-config integration - Python bindings - Fuzzing and sanitizer support - Security hardening flags --- scripts/gen_fuzz.py | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 scripts/gen_fuzz.py (limited to 'scripts/gen_fuzz.py') diff --git a/scripts/gen_fuzz.py b/scripts/gen_fuzz.py new file mode 100644 index 0000000..a1d20e3 --- /dev/null +++ b/scripts/gen_fuzz.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +"""Generate fuzz table entries from ts indicator metadata. + +Parses lib/*.c via ts_parser to extract function names and input/output +counts, then generates a C source file with the complete fuzz table. +""" + +import argparse +import importlib.util +import os +import sys + +_spec = importlib.util.spec_from_file_location( + "ts_parser", + os.path.join(os.path.dirname(os.path.abspath(__file__)), "ts_parser.py"), +) +if _spec and _spec.loader: + _ts_parser = importlib.util.module_from_spec(_spec) + _spec.loader.exec_module(_ts_parser) + parse_all = _ts_parser.parse_all +else: + print("Error: could not load ts_parser", file=sys.stderr) + sys.exit(1) + +OUT = os.path.join( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))), + "test", + "fuzz_table_generated.c", +) + + +def generate_table(funcs, dry_run=False): + """Generate the fuzz table C source file.""" + if dry_run: + print(f"[dry-run] Would generate {len(funcs)} fuzz entries -> {OUT}") + return + + with open(OUT, "w", encoding="utf-8") as f: + f.write("/* Auto-generated fuzz table. Do not edit. */\n\n") + f.write('#include "ts.h"\n\n') + f.write("static const fuzz_entry_t _fuzz_table_generated[] = {\n") + + for fm in funcs: + f.write(f" {{ts_{fm.name}, {fm.x_n}, {fm.y_n}}},\n") + + f.write("};\n\n") + f.write( + "static const uint_t _fuzz_generated_n = sizeof(_fuzz_table_generated) / sizeof(_fuzz_table_generated[0]);\n" + ) + + +def main(): + parser = argparse.ArgumentParser(description="Generate fuzz table from registry") + parser.add_argument( + "--dry-run", + action="store_true", + help="Print what would be generated without writing", + ) + args = parser.parse_args() + + funcs = parse_all(detect_x_access=True) + + if not funcs: + print("Warning: no ts_parameter declarations found.", file=sys.stderr) + sys.exit(1) + + generate_table(funcs, dry_run=args.dry_run) + + if not args.dry_run: + print(f"Generated {len(funcs)} fuzz entries -> {OUT}") + + +if __name__ == "__main__": + main() -- cgit v1.3.1