tools+tests: Add a system to run all tests at once automatically
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
916a73ca95
commit
35b1b36599
@ -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 ${CMAKE_CURRENT_LIST_DIR})
|
||||||
target_include_directories(test PUBLIC ${LUNA_BASE}/usr/include)
|
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})
|
add_executable(${APP_NAME} ${SOURCE_FILE})
|
||||||
target_compile_options(${APP_NAME} PRIVATE -Os ${COMMON_FLAGS} -Wno-write-strings)
|
target_compile_options(${APP_NAME} PRIVATE -Os ${COMMON_FLAGS} -Wno-write-strings)
|
||||||
add_dependencies(${APP_NAME} libc)
|
add_dependencies(${APP_NAME} libc)
|
||||||
target_include_directories(${APP_NAME} PRIVATE ${LUNA_BASE}/usr/include)
|
target_include_directories(${APP_NAME} PRIVATE ${LUNA_BASE}/usr/include)
|
||||||
target_link_libraries(${APP_NAME} PRIVATE test os)
|
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()
|
endfunction()
|
||||||
|
|
||||||
if(BUILD_TESTS)
|
if(BUILD_TESTS)
|
||||||
luna_test(libluna/TestVector.cpp TestVector)
|
luna_test(libluna/TestVector.cpp TestVector)
|
||||||
luna_test(libluna/TestBase64.cpp TestBase64)
|
luna_test(libluna/TestBase64.cpp TestBase64)
|
||||||
luna_test(libluna/TestUtf8.cpp TestUtf8)
|
luna_test(libluna/TestUtf8.cpp TestUtf8)
|
||||||
|
|
||||||
|
luna_app(run-tests.cpp run-tests)
|
||||||
endif()
|
endif()
|
||||||
|
32
tests/run-tests.cpp
Normal file
32
tests/run-tests.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include <luna/String.h>
|
||||||
|
#include <os/ArgumentParser.h>
|
||||||
|
#include <os/Directory.h>
|
||||||
|
#include <os/File.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
Result<int> 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;
|
||||||
|
}
|
29
tools/run-tests.sh
Executable file
29
tools/run-tests.sh
Executable file
@ -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/
|
Loading…
Reference in New Issue
Block a user