OCaml wire format DSL with EverParse 3D output for verified parsers
1; Differential testing: OCaml wire vs EverParse C parsers
2;
3; Workflow:
4; 1. BUILD_EVERPARSE=1 dune build @ocaml-wire/test/diff/gen_c
5; (generates .3d schemas, runs EverParse, produces C stubs)
6; 2. BUILD_EVERPARSE=1 dune build @ocaml-wire/test/diff/diff
7; (runs differential tests)
8;
9; EverParse is slow, so code generation only runs when BUILD_EVERPARSE=1.
10; Generated C code can be promoted and committed for C API consumers.
11
12; Alcotest tests for wire_diff library
13
14(test
15 (name test_diff)
16 (modules test_diff)
17 (libraries wire wire_diff alcotest fmt))
18
19; Schema library for differential testing
20
21(library
22 (name schema)
23 (modules schema)
24 (libraries wire))
25
26; Generate .3d files from OCaml schemas
27
28(executable
29 (name gen_schemas)
30 (modules gen_schemas)
31 (libraries schema))
32
33(rule
34 (alias gen_schemas)
35 (targets SimpleHeader.3d ConstrainedPacket.3d)
36 (deps gen_schemas.exe)
37 (action
38 (run ./gen_schemas.exe)))
39
40; Generate random schemas into schemas/ directory
41; Also generates stubs.c, stubs.ml, diff_test.ml
42;
43; Run with: BUILD_EVERPARSE=1 dune build @ocaml-wire/test/diff/gen_c
44
45(executable
46 (name gen_c)
47 (modules gen_c)
48 (enabled_if
49 (= %{env:BUILD_EVERPARSE=} "1"))
50 (libraries wire unix))
51
52(rule
53 (alias gen_c)
54 (enabled_if
55 (= %{env:BUILD_EVERPARSE=} "1"))
56 (targets
57 (dir schemas)
58 stubs.c
59 stubs.ml
60 diff_test.ml)
61 (deps gen_c.exe)
62 (action
63 (run ./gen_c.exe schemas 100)))
64
65; Differential test: compile C stubs (includes EverParse generated C)
66; NOTE: Only builds with BUILD_EVERPARSE=1 after running @gen_c first
67
68(library
69 (name stubs)
70 (modules stubs)
71 (enabled_if
72 (= %{env:BUILD_EVERPARSE=} "1"))
73 (foreign_stubs
74 (language c)
75 (names stubs)
76 (flags :standard -I schemas)))
77
78(executable
79 (name diff_test)
80 (modules diff_test)
81 (enabled_if
82 (= %{env:BUILD_EVERPARSE=} "1"))
83 (libraries stubs))
84
85(rule
86 (alias diff)
87 (enabled_if
88 (= %{env:BUILD_EVERPARSE=} "1"))
89 (deps diff_test.exe)
90 (action
91 (run ./diff_test.exe)))
92
93; Fuzz tests for schemas (OCaml only - no C dependency)
94
95(executable
96 (name fuzz_schema)
97 (modules fuzz_schema)
98 (libraries schema crowbar))
99
100(rule
101 (alias fuzz)
102 (deps fuzz_schema.exe)
103 (action
104 (run %{exe:fuzz_schema.exe})))