From 35b1b365995ed6d14049a642c90adcccbf01d54c Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 7 May 2023 23:04:24 +0200 Subject: [PATCH] tools+tests: Add a system to run all tests at once automatically --- tests/CMakeLists.txt | 6 ++++-- tests/run-tests.cpp | 32 ++++++++++++++++++++++++++++++++ tools/run-tests.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 tests/run-tests.cpp create mode 100755 tools/run-tests.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c4244e6f..df154734 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,17 +3,19 @@ target_compile_options(test PRIVATE ${COMMON_FLAGS}) target_include_directories(test PUBLIC ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(test PUBLIC ${LUNA_BASE}/usr/include) -function(luna_test SOURCE_FILE APP_NAME SETUID) +function(luna_test SOURCE_FILE APP_NAME) add_executable(${APP_NAME} ${SOURCE_FILE}) target_compile_options(${APP_NAME} PRIVATE -Os ${COMMON_FLAGS} -Wno-write-strings) add_dependencies(${APP_NAME} libc) target_include_directories(${APP_NAME} PRIVATE ${LUNA_BASE}/usr/include) target_link_libraries(${APP_NAME} PRIVATE test os) - install(TARGETS ${APP_NAME} DESTINATION ${LUNA_ROOT}/initrd/tests) + install(TARGETS ${APP_NAME} DESTINATION ${LUNA_ROOT}/initrd/bin/tests) endfunction() if(BUILD_TESTS) luna_test(libluna/TestVector.cpp TestVector) luna_test(libluna/TestBase64.cpp TestBase64) luna_test(libluna/TestUtf8.cpp TestUtf8) + +luna_app(run-tests.cpp run-tests) endif() diff --git a/tests/run-tests.cpp b/tests/run-tests.cpp new file mode 100644 index 00000000..9bf75e30 --- /dev/null +++ b/tests/run-tests.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +#include + +Result luna_main(int argc, char** argv) +{ + StringView test_dir; + + os::ArgumentParser parser; + parser.add_description("Run the system test suite."); + parser.add_system_program_info("run-tests"_sv); + parser.add_positional_argument(test_dir, "test-dir", "/bin/tests"_sv); + parser.parse(argc, argv); + + auto dir = TRY(os::Directory::open(test_dir)); + + auto files = TRY(dir->list(os::Directory::Filter::Hidden)); + + for (const auto& program : files) + { + auto command = TRY(String::format("%s/%s"_sv, test_dir.chars(), program.chars())); + int status = system(command.chars()); + if (WEXITSTATUS(status) != 0) return WEXITSTATUS(status); + } + + os::println("All tests passed."); + + return 0; +} diff --git a/tools/run-tests.sh b/tools/run-tests.sh new file mode 100755 index 00000000..bf93adbb --- /dev/null +++ b/tools/run-tests.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -e + +source $(dirname $0)/env.sh + +cd $LUNA_ROOT + +tools/setup.sh + +tools/full-clean.sh + +tools/install-headers.sh + +cmake -S . -B $LUNA_BUILD_DIR -G "$LUNA_CMAKE_GENERATOR_NAME" -DBUILD_TESTS=ON +cmake --build $LUNA_BUILD_DIR + +rm initrd/etc/init/* + +printf "Name=test\nCommand=/bin/run-tests\nWait=true\n" > initrd/etc/init/00-tests + +tools/make-iso.sh + +set +e +tools/fast-run.sh +set -e + +rm initrd/etc/init/00-tests + +git checkout initrd/etc/init/