diff --git a/runtime/Makefile b/runtime/Makefile index f8dd02127..f3757ec29 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -9,6 +9,15 @@ INVARIANTS_CHECK_FLAGS=$(TEST_FLAGS) -DFULL_INVARIANT_CHECKS all: gc.o runtime.o ar rc runtime.a runtime.o gc.o +NEGATIVE_TESTS=$(sort $(basename $(notdir $(wildcard negative_scenarios/*_neg.c)))) + +$(NEGATIVE_TESTS): %: negative_scenarios/%.c + @echo "Running test $@" + @$(CC) -o $@.o $(COMMON_FLAGS) negative_scenarios/$@.c gc.c + @./$@.o 2> negative_scenarios/$@.err || diff negative_scenarios/$@.err negative_scenarios/expected/$@.err + +negative_tests: $(NEGATIVE_TESTS) + # this is a target that runs unit tests, scenarios are written in a single file `test_main.c` unit_tests.o: gc.c gc.h runtime.c runtime.h runtime_common.h virt_stack.c virt_stack.h test_main.c test_util.s $(CC) -o unit_tests.o $(UNIT_TESTS_FLAGS) gc.c virt_stack.c runtime.c test_main.c test_util.s @@ -32,4 +41,4 @@ runtime.o: runtime.c runtime.h $(CC) $(PROD_FLAGS) -c runtime.c clean: - $(RM) *.a *.o *~ + $(RM) *.a *.o *~ negative_scenarios/*.err diff --git a/runtime/negative_scenarios/expected/extra_roots_empty_pop_neg.err b/runtime/negative_scenarios/expected/extra_roots_empty_pop_neg.err new file mode 100644 index 000000000..9b9f69fec --- /dev/null +++ b/runtime/negative_scenarios/expected/extra_roots_empty_pop_neg.err @@ -0,0 +1,2 @@ +ERROR: pop_extra_root: extra_roots are empty +: Success diff --git a/runtime/negative_scenarios/expected/extra_roots_overflow_neg.err b/runtime/negative_scenarios/expected/extra_roots_overflow_neg.err new file mode 100644 index 000000000..24df3dbbe --- /dev/null +++ b/runtime/negative_scenarios/expected/extra_roots_overflow_neg.err @@ -0,0 +1,2 @@ +ERROR: push_extra_roots: extra_roots_pool overflow +: Success diff --git a/runtime/negative_scenarios/expected/extra_roots_pop_mismatch_neg.err b/runtime/negative_scenarios/expected/extra_roots_pop_mismatch_neg.err new file mode 100644 index 000000000..950d19495 --- /dev/null +++ b/runtime/negative_scenarios/expected/extra_roots_pop_mismatch_neg.err @@ -0,0 +1,2 @@ +ERROR: pop_extra_root: stack invariant violation +: Success diff --git a/runtime/negative_scenarios/extra_roots_empty_pop_neg.c b/runtime/negative_scenarios/extra_roots_empty_pop_neg.c new file mode 100644 index 000000000..ada20b6a9 --- /dev/null +++ b/runtime/negative_scenarios/extra_roots_empty_pop_neg.c @@ -0,0 +1,5 @@ +#include "../gc.h" + +#include + +int main () { pop_extra_root((void **)NULL); } \ No newline at end of file diff --git a/runtime/negative_scenarios/extra_roots_overflow_neg.c b/runtime/negative_scenarios/extra_roots_overflow_neg.c new file mode 100644 index 000000000..f03e2e98d --- /dev/null +++ b/runtime/negative_scenarios/extra_roots_overflow_neg.c @@ -0,0 +1,7 @@ +#include "../gc.h" + +#include + +int main () { + for (size_t i = 0; i < MAX_EXTRA_ROOTS_NUMBER + 1; ++i) { push_extra_root(NULL); } +} \ No newline at end of file diff --git a/runtime/negative_scenarios/extra_roots_pop_mismatch_neg.c b/runtime/negative_scenarios/extra_roots_pop_mismatch_neg.c new file mode 100644 index 000000000..8e55a8bf1 --- /dev/null +++ b/runtime/negative_scenarios/extra_roots_pop_mismatch_neg.c @@ -0,0 +1,6 @@ +#include "../gc.h" + +int main () { + push_extra_root(NULL); + pop_extra_root((void **)239); +} \ No newline at end of file