diff --git a/src/kernel/Makefile b/src/kernel/Makefile index 5033784f..5fc4c28a 100644 --- a/src/kernel/Makefile +++ b/src/kernel/Makefile @@ -35,6 +35,9 @@ BUILDDIR = build INCLUDEDIR = include CPU = cortex-a7 +# Seeds the random order in which tests are run. +TESTS_SEED = $(shell date '+%s') + # =================== End Configuration =================== TOOLCHAIN_PATH=$(CURDIR)/../$(TOOLCHAIN_DIR)/$(BARE_METAL_TARGET)/bin CC=$(TOOLCHAIN_PATH)/$(BARE_METAL_TUPLE)-gcc @@ -134,7 +137,7 @@ $(BUILDDIR)/%.o: $(SOURCEDIR)/%.s | builddir $(SOURCEDIR)/test/test.c: dummy | builddir @echo Generating tests - @$(SOURCEDIR)/test/generate_tests.sh + @$(SOURCEDIR)/test/generate_tests.sh $(TESTS_SEED) # depend on dummy to always recompile. There aren't that many files atm anyway and # when the definitions change, we have to recompile. TODO: move definitions to some kind of file diff --git a/src/kernel/README.md b/src/kernel/README.md index 2361c2e4..c6d9e471 100644 --- a/src/kernel/README.md +++ b/src/kernel/README.md @@ -12,6 +12,7 @@ The [makefile](Makefile) in this directory contains a number of configuration op | BUILDDIR | The name of the directory containing object files and binaries | | INCLUDEDIR | Any directory in SOURCEDIR with this name, will be globally included in every c file. This means they can be included with `#include ` instead of `#include "something.h"`. | | TEST_MAIN_FILE | The name of the file generated to contain all [tests](src/test/README.md). | +| TESTS_SEED | The seed used to randomize the order in which the tests are run. | | CPU | The cpu type emulated by qemu. Supported cpu types are the `arm1176` and `cortex-a7`| diff --git a/src/kernel/src/test/generate_tests.sh b/src/kernel/src/test/generate_tests.sh index 53ad8564..2f2fba01 100755 --- a/src/kernel/src/test/generate_tests.sh +++ b/src/kernel/src/test/generate_tests.sh @@ -4,6 +4,16 @@ # the makefile will run this file automatically while building, # so all tests are automatically executed. +# https://www.gnu.org/software/coreutils/manual/html_node/Random-sources.html +get_seeded_random() +{ + RANDOM=$1 + while true + do + echo "$RANDOM" + done +} + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # clear the file @@ -23,8 +33,9 @@ size_t global_counter = 0; " >> "$DIR/test.c" +echo "Seed used for test order randomization: $1" #TESTFNS=$(grep -hr --include "*.c" -oP "(?<=TEST_CREATE\()(.*)(?=,)") -TESTFNS=$(grep -hr --include "*.c" -vP "^\s*\/\/.+" | grep -oP "(?<=TEST_CREATE\()(.*)(?=,)" | sort -R) +TESTFNS=$(grep -hr --include "*.c" -vP "^\s*\/\/.+" | grep -oP "(?<=TEST_CREATE\()(.*)(?=,)" | sort -R --random-source=<(get_seeded_random $1)) for FNNAME in $TESTFNS do