Skip to content

Commit

Permalink
[CN-Test-Gen] Control backtracks from size splits
Browse files Browse the repository at this point in the history
  • Loading branch information
ZippeyKeys12 committed Dec 5, 2024
1 parent eb595be commit dc6bf28
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 2 deletions.
14 changes: 14 additions & 0 deletions backend/cn/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ let run_tests
allowed_depth_failures
max_generator_size
random_size_splits
allowed_size_split_backtracks
sized_null
coverage
disable_passes
Expand Down Expand Up @@ -520,6 +521,7 @@ let run_tests
allowed_depth_failures;
max_generator_size;
random_size_splits;
allowed_size_split_backtracks;
sized_null;
coverage;
disable_passes
Expand Down Expand Up @@ -1007,6 +1009,17 @@ module Testing_flags = struct
Arg.(value & flag & info [ "random-size-splits" ] ~doc)


let allowed_size_split_backtracks =
let doc =
"Set the maximum attempts to split up a generator's size (between recursive calls) \
before backtracking further, during input generation"
in
Arg.(
value
& opt (some int) TestGeneration.default_cfg.allowed_size_split_backtracks
& info [ "allowed-size-split-backtracks" ] ~doc)


let sized_null =
let doc =
"Scale the likelihood of [NULL] proportionally for a desired size (1/n for size n)"
Expand Down Expand Up @@ -1070,6 +1083,7 @@ let testing_cmd =
$ Testing_flags.allowed_depth_failures
$ Testing_flags.max_generator_size
$ Testing_flags.random_size_splits
$ Testing_flags.allowed_size_split_backtracks
$ Testing_flags.sized_null
$ Testing_flags.coverage
$ Testing_flags.disable_passes
Expand Down
7 changes: 7 additions & 0 deletions backend/cn/lib/testGeneration/specTests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,13 @@ let compile_script ~(output_dir : string) ~(test_file : string) : Pp.document =
|> Option.map (fun allowed_depth_failures ->
[ "--allowed-depth-failures"; string_of_int allowed_depth_failures ])
|> Option.to_list
|> List.flatten)
@ (Config.has_allowed_size_split_backtracks ()
|> Option.map (fun allowed_size_split_backtracks ->
[ "--allowed-size-split-backtracks";
string_of_int allowed_size_split_backtracks
])
|> Option.to_list
|> List.flatten))
in
cmd
Expand Down
4 changes: 4 additions & 0 deletions backend/cn/lib/testGeneration/testGenConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type t =
allowed_depth_failures : int option;
max_generator_size : int option;
random_size_splits : bool;
allowed_size_split_backtracks : int option;
sized_null : bool;
coverage : bool;
disable_passes : string list
Expand All @@ -35,6 +36,7 @@ let default =
allowed_depth_failures = None;
max_generator_size = None;
random_size_splits = false;
allowed_size_split_backtracks = None;
sized_null = false;
coverage = false;
disable_passes = []
Expand Down Expand Up @@ -73,6 +75,8 @@ let has_max_generator_size () = !instance.max_generator_size

let is_random_size_splits () = !instance.random_size_splits

let has_allowed_size_split_backtracks () = !instance.allowed_size_split_backtracks

let is_sized_null () = !instance.sized_null

let is_coverage () = !instance.coverage
Expand Down
3 changes: 3 additions & 0 deletions backend/cn/lib/testGeneration/testGenConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type t =
allowed_depth_failures : int option;
max_generator_size : int option;
random_size_splits : bool;
allowed_size_split_backtracks : int option;
sized_null : bool;
coverage : bool;
disable_passes : string list
Expand Down Expand Up @@ -52,6 +53,8 @@ val has_max_generator_size : unit -> int option

val is_random_size_splits : unit -> bool

val has_allowed_size_split_backtracks : unit -> int option

val is_sized_null : unit -> bool

val is_coverage : unit -> bool
Expand Down
9 changes: 8 additions & 1 deletion runtime/libcn/include/cn-testing/dsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
urn_free(tmp##_urn); \

#define CN_GEN_SPLIT_BEGIN(tmp, size, ...) \
int tmp##_backtracks = cn_gen_get_size_split_backtracks_allowed(); \
alloc_checkpoint tmp##_checkpoint = alloc_save_checkpoint(); \
void *tmp##_alloc_checkpoint = cn_gen_alloc_save(); \
void *tmp##_ownership_checkpoint = cn_gen_ownership_save(); \
Expand All @@ -254,7 +255,7 @@
#define CN_GEN_SPLIT_END(ty, tmp, size, last_var, ...) \
if (count >= size) { \
cn_gen_backtrack_depth_exceeded(); \
char* toAdd[] = { __VA_ARGS__, NULL }; \
char* toAdd[] = { __VA_ARGS__ }; \
cn_gen_backtrack_relevant_add_many(toAdd); \
goto cn_label_##last_var##_backtrack; \
} \
Expand All @@ -275,6 +276,12 @@
cn_gen_alloc_restore(tmp##_alloc_checkpoint); \
cn_gen_ownership_restore(tmp##_ownership_checkpoint); \
if (cn_gen_backtrack_relevant_contains(#tmp)) { \
char* toAdd[] = { __VA_ARGS__ }; \
cn_gen_backtrack_relevant_add_many(toAdd); \
if (tmp##_backtracks <= 0) { \
goto cn_label_##last_var##_backtrack; \
} \
tmp##_backtracks--; \
cn_gen_backtrack_reset(); \
goto cn_label_##tmp##_gen; \
} else { \
Expand Down
3 changes: 3 additions & 0 deletions runtime/libcn/include/cn-testing/size.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ void cn_gen_decrement_depth();

void cn_gen_set_depth_failures_allowed(uint16_t allowed);
uint16_t cn_gen_get_depth_failures_allowed();

void cn_gen_set_size_split_backtracks_allowed(uint16_t allowed);
uint16_t cn_gen_get_size_split_backtracks_allowed();
10 changes: 10 additions & 0 deletions runtime/libcn/src/cn-testing/size.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,13 @@ void cn_gen_set_depth_failures_allowed(uint16_t allowed) {
uint16_t cn_gen_get_depth_failures_allowed() {
return depth_failures_allowed;
}

static uint16_t size_split_backtracks_allowed = 0;

void cn_gen_set_size_split_backtracks_allowed(uint16_t allowed) {
size_split_backtracks_allowed = allowed;
}

uint16_t cn_gen_get_size_split_backtracks_allowed() {
return size_split_backtracks_allowed;
}
4 changes: 4 additions & 0 deletions runtime/libcn/src/cn-testing/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ int cn_test_main(int argc, char* argv[]) {
cn_gen_set_depth_failures_allowed(strtoul(argv[i + 1], NULL, 10));
i++;
}
else if (strcmp("--allowed-size-split-backtracks", arg) == 0) {
cn_gen_set_size_split_backtracks_allowed(strtoul(argv[i + 1], NULL, 10));
i++;
}
}

if (interactive) {
Expand Down
2 changes: 1 addition & 1 deletion tests/run-cn-test-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function separator() {
printf '\n\n'
}

CONFIGS=("--coverage" "--sized-null" "--random-size-splits")
CONFIGS=("--coverage" "--sized-null" "--random-size-splits" "--random-size-splits --allowed-size-split-backtracks=10")

# For each configuration
for CONFIG in ${CONFIGS[@]}; do
Expand Down

0 comments on commit dc6bf28

Please sign in to comment.