Commit fd089217 authored by POTTIER Francois's avatar POTTIER Francois

Integrate Gabriel Radanne's stress test. Fix [make test] in the demos.

parent cf88cfd2
SHELL := bash SHELL := bash
BUILD := ../../_build/default/demos/brz
.PHONY: all .PHONY: all
all: all:
...@@ -6,7 +7,7 @@ all: ...@@ -6,7 +7,7 @@ all:
.PHONY: test .PHONY: test
test: all test: all
_build/default/Main.exe $(BUILD)/Main.exe
@ if command -v dot >/dev/null ; then \ @ if command -v dot >/dev/null ; then \
for f in *.dot ; do \ for f in *.dot ; do \
dot -Tpng $$f -O ; \ dot -Tpng $$f -O ; \
...@@ -15,6 +16,12 @@ test: all ...@@ -15,6 +16,12 @@ test: all
echo "The program dot is required to visualize DFAs. Please install graphviz." ; \ echo "The program dot is required to visualize DFAs. Please install graphviz." ; \
fi fi
# This stress test, contributed by Gabriel Radanne, takes about 5 minutes.
.PHONY: testgen
testgen:
dune build TestGen.exe
$(BUILD)/TestGen.exe
.PHONY: clean .PHONY: clean
clean: clean:
rm -f *~ *.dot.png rm -f *~ *.dot.png
......
(* This testing infrastructure has been contributed by Gabriel Radanne.
It is based on regenerate: https://github.com/regex-generate/regenerate *)
let bos = '^'
let eos = '$'
let alphabet = ['a'; 'b'; 'c']
module Char = struct
include Char
let hash = Hashtbl.hash
let foreach f =
List.iter f (bos :: eos :: alphabet)
let print c =
Printf.sprintf "%c" c
let pp = Format.pp_print_char
end
module B =
Brzozowski.Make(Char)
open B
let compl l =
List.fold_left (fun l x -> CCList.remove ~eq:Char.equal ~x l) alphabet l
let set b l = disjunction (List.map char (if b then l else compl l))
(* Turn a regular expression from Regenerate into a [B] expression. *)
let rec to_re = let open Regenerate.Regex in function
| One -> B.epsilon
| Set (b, l) -> set b l
| Seq (re, re') -> to_re re @@ to_re re'
| Or (re, re') -> to_re re ||| to_re re'
| And (re, re') -> to_re re &&& to_re re'
| Not re -> B.neg (to_re re)
| Rep (0,None,re) -> B.star (to_re re)
| Rep (_,_,_re) -> assert false
let is_match re input =
match B.exec re input with None -> false | Some _ -> true
(* Check positive and negative samples. *)
let check (re, pos, neg) =
(* 1. Compile the regular expression. *)
let cre =
try
B.dfa (to_re re)
with _ ->
(* Discard regular expressions that we do not handle. *)
QCheck.assume_fail ()
in
(* 2. Test! *)
List.for_all (fun s -> is_match cre s) pos &&
List.for_all (fun s -> not (is_match cre s)) neg
module WordSeq (C : sig include Set.OrderedType val pp : t Fmt.t end) = struct
type char = C.t
type t = C.t Seq.t
let empty = Seq.empty
let singleton = OSeq.return
let length = OSeq.length
let append = OSeq.append
let cons = OSeq.cons
let pp fmt w = Seq.iter (C.pp fmt) w
let compare = OSeq.compare ~cmp:C.compare
end
(* Ensure that the whole word is matched *)
let add_boundaries =
let bounds s =
let (@) = OSeq.append in
OSeq.(return bos @ s @ return eos)
in
let whole_string re =
Regenerate.Regex.(seq [char bos; re; char eos])
in
QCheck.map_same_type
(fun (re, pos, neg) ->
whole_string re, List.map bounds pos, List.map bounds neg)
let test =
let module Word = WordSeq(Char) in
let module Stream = Segments.ThunkList(Word) in
let generator =
Regenerate.arbitrary
(module Word) (* Datastructure for words *)
(module Stream) (* Datastructure for streams of words *)
~compl:false (* Should we generate complement operations? *)
~pp:Fmt.char (* Printer for characters *)
~samples:100 (* Average number of samples for each regular expression *)
alphabet (* Alphabet *)
in
let generator = add_boundaries generator in
QCheck.Test.make generator check
let () = QCheck_runner.run_tests_main [test]
(executable (library
(name Brzozowski)
(modules Brzozowski ListAux)
(libraries fix seq)
(flags "-w" "A-4-44")
)
(test
(name Main) (name Main)
(libraries fix) (modules Main)
(libraries Brzozowski)
(flags "-w" "A-4-44")
)
(test
(name TestGen)
(modules TestGen)
(libraries Brzozowski regenerate)
(flags "-w" "A-4-44") (flags "-w" "A-4-44")
) )
...@@ -6,3 +6,7 @@ all: ...@@ -6,3 +6,7 @@ all:
clean: clean:
rm -f *~ rm -f *~
dune clean dune clean
.PHONY: test
test:
@ echo "No test here."
BUILD := ../../_build/default/demos/cyk
.PHONY: all .PHONY: all
all: all:
dune build Bench.exe dune build Bench.exe
.PHONY: test .PHONY: test
test: all test: all
_build/default/Bench.exe $(BUILD)/Bench.exe
.PHONY: clean .PHONY: clean
clean: clean:
......
(executable (test
(name Bench) (name Bench)
(libraries fix) (libraries fix)
(flags "-w" "A") (flags "-w" "A")
......
BUILD := ../../_build/default/demos/fib
.PHONY: all .PHONY: all
all: all:
dune build Fib.exe dune build Fib.exe
.PHONY: test .PHONY: test
test: all test: all
_build/default/Fib.exe $(BUILD)/Fib.exe
.PHONY: clean .PHONY: clean
clean: clean:
......
(executable (test
(name Fib) (name Fib)
(libraries unix fix) (libraries unix fix)
(flags "-w" "A") (flags "-w" "A")
......
BUILD := ../../_build/default/demos/hco
.PHONY: all .PHONY: all
all: all:
dune build HashConsDemo.exe dune build HashConsDemo.exe
.PHONY: test .PHONY: test
test: all test: all
_build/default/HashConsDemo.exe $(BUILD)/HashConsDemo.exe
.PHONY: clean .PHONY: clean
clean: clean:
......
(executable (test
(name HashConsDemo) (name HashConsDemo)
(libraries fix) (libraries fix)
(flags "-w" "A") (flags "-w" "A")
......
BUILD := ../../_build/default/demos/tst
.PHONY: all .PHONY: all
all: all:
dune build Test.exe dune build Test.exe
.PHONY: test .PHONY: test
test: all test: all
_build/default/Test.exe $(BUILD)/Test.exe
.PHONY: clean .PHONY: clean
clean: clean:
......
(executable (test
(name Test) (name Test)
(libraries fix) (libraries fix)
(flags "-w" "A") (flags "-w" "A")
......
...@@ -524,3 +524,7 @@ automata by Brzozowski's method is a good illustration of their application. ...@@ -524,3 +524,7 @@ automata by Brzozowski's method is a good illustration of their application.
For more details, For more details,
please look at the please look at the
[full source code for this demo](https://gitlab.inria.fr/fpottier/fix/blob/master/demos/brz/). [full source code for this demo](https://gitlab.inria.fr/fpottier/fix/blob/master/demos/brz/).
As a bonus, Gabriel Radanne contributed a
[stress test](https://gitlab.inria.fr/fpottier/fix/blob/master/demos/brz/TestGen.ml)
based on [regenerate](https://github.com/regex-generate/regenerate).
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment