From 6538b038e7ff61e0ee8051a4a7dd11f3d4d408e4 Mon Sep 17 00:00:00 2001 From: Eric-Paul Ickhorn Date: Sun, 28 Jan 2024 17:13:00 +0100 Subject: [PATCH] Added a basic testing infrastructure and found a bug through it. --- action.bash | 3 +- build_tests.bash | 76 +++++++++++++++++++ .../include_paths.txt | 3 + .../internal/basic-tag-registry-usage/main.c | 15 ++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100755 build_tests.bash create mode 100644 core/tests/internal/basic-tag-registry-usage/include_paths.txt create mode 100644 core/tests/internal/basic-tag-registry-usage/main.c diff --git a/action.bash b/action.bash index d5c9155..6cec013 100755 --- a/action.bash +++ b/action.bash @@ -31,7 +31,8 @@ function build_dependencies { cd .build/depends/libRR/Core/ bash build.bash release - cp .build/libRR-Core.a "$REPOSITORY_FOLDER/.build/" + cp .build/librr-core.a "$REPOSITORY_FOLDER/.build/" + cp .build/librr-platform.a "$REPOSITORY_FOLDER/.build/" cd "$REPOSITORY_FOLDER" } diff --git a/build_tests.bash b/build_tests.bash new file mode 100755 index 0000000..adce3a6 --- /dev/null +++ b/build_tests.bash @@ -0,0 +1,76 @@ +#!/usr/bin/env bash + +cd $(dirname "$(pwd)/$0") +REPOSITORY_FOLDER=$(pwd) + +MAIN_OBJECTS_FOLDER="$REPOSITORY_FOLDER/.build/objects/" +DEFAULT_LINKAGE_PATHS=" +$REPOSITORY_FOLDER/.build/maintree-core.a +$REPOSITORY_FOLDER/.build/librr-core.a +$REPOSITORY_FOLDER/.build/librr-platform.a +" + +function get_include_path_configuration() { + TEST_PATH=$1 + + INCLUDE_CONFIG_PATH="$TEST_PATH/include_paths.txt" + INCLUDE_STATEMENTS="-I $TEST_PATH/inc-c/" + if [[ ! -f $INCLUDE_CONFIG_PATH ]] + then + return + fi + + for LINE in $(cat $INCLUDE_CONFIG_PATH) + do + INCLUDE_STATEMENTS="$INCLUDE_STATEMENTS -I $REPOSITORY_FOLDER/$LINE" + done +} + +function get_linkage_path_configuration() { + TEST_PATH=$1 + + LINKAGE_PATHS=$DEFAULT_LINKAGE_PATHS + if [[ -f "$TEST_PATH/linkage_paths.txt" ]] + then + for LINKAGE_ITEM in $(cat "$TEST_PATH/linkage_paths.txt") + do + LINKAGE_PATHS="$LINKAGE_PATHS $REPOSITORY_FOLDER/$LINKAGE_ITEM" + done + fi +} + +function compile_single_test() { + TEST_PATH=$1 + TEST_NAME=$(basename $TEST_PATH) + + echo "Compiling Test: $TEST_NAME" + + # TODO: As a small improvement, the tests could be able to have multiple sub-folders for sources. + + get_include_path_configuration $TEST_PATH + get_linkage_path_configuration $TEST_PATH + gcc -o $TEST_PATH/$TEST_NAME.elf $TEST_PATH/*.c $LINKAGE_PATHS $INCLUDE_STATEMENTS +} + +function compile_all_tests_of_module() { + MODULE_NAME=$1 + + echo "================================================================" + echo "COMPILING ALL TESTS OF MODULE: '$MODULE_NAME'." + echo " " + + TEST_PATH_LIST_PATH="$REPOSITORY_FOLDER/$MODULE_NAME/build-config/tests.txt" + if [[ ! -f $TEST_PATH_LIST_PATH ]] + then + echo "Couldn't find list of tests for module '$MODULE_NAME'. Skipping." + return + fi + + for RELATIVE_TEST_PATH in $(cat $TEST_PATH_LIST_PATH) + do + TEST_PATH=$REPOSITORY_FOLDER/$MODULE_NAME/$RELATIVE_TEST_PATH + compile_single_test $TEST_PATH + done +} + +compile_all_tests_of_module core diff --git a/core/tests/internal/basic-tag-registry-usage/include_paths.txt b/core/tests/internal/basic-tag-registry-usage/include_paths.txt new file mode 100644 index 0000000..615bb49 --- /dev/null +++ b/core/tests/internal/basic-tag-registry-usage/include_paths.txt @@ -0,0 +1,3 @@ +.build/depends/libRR/Core/core/exports/ +.build/depends/libRR/Core/platform/exports/ +core/inc-c/ \ No newline at end of file diff --git a/core/tests/internal/basic-tag-registry-usage/main.c b/core/tests/internal/basic-tag-registry-usage/main.c new file mode 100644 index 0000000..dace36f --- /dev/null +++ b/core/tests/internal/basic-tag-registry-usage/main.c @@ -0,0 +1,15 @@ +#include +#include +#include + +int main(int argc, char **argv) +{ + MtTagRegistry tag_registry = mt_create_tag_registry(NULL); + u32_t some_tag = mt_get_tag_id(&tag_registry, "some_tag"); + if(some_tag != mt_get_tag_id(&tag_registry, "some_tag")) + { + puts("Inconsistent returned tag identifiers."); + return -1; + } + return 0; +}