From 122869f0862f52d84ce12cd5a8d22846bf1d7f2d Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Tue, 27 Apr 2021 02:39:32 -0700 Subject: [PATCH] Tests: Convert unveil-test-failures.cpp to be LibTest based. --- Userland/Tests/Kernel/CMakeLists.txt | 7 ++ Userland/Tests/Kernel/TestKernelUnveil.cpp | 55 +++++++++++++ .../Tests/Kernel/unveil-test-failures.cpp | 80 ------------------- 3 files changed, 62 insertions(+), 80 deletions(-) create mode 100644 Userland/Tests/Kernel/TestKernelUnveil.cpp delete mode 100644 Userland/Tests/Kernel/unveil-test-failures.cpp diff --git a/Userland/Tests/Kernel/CMakeLists.txt b/Userland/Tests/Kernel/CMakeLists.txt index 408d82163c..9c02b425ee 100644 --- a/Userland/Tests/Kernel/CMakeLists.txt +++ b/Userland/Tests/Kernel/CMakeLists.txt @@ -1,4 +1,6 @@ file(GLOB CMD_SOURCES CONFIGURE_DEPENDS "*.cpp") +file(GLOB LIBTEST_BASED_SOURCES "Test*.cpp") +list(REMOVE_ITEM CMD_SOURCES ${LIBTEST_BASED_SOURCES}) # FIXME: These tests do not use LibTest foreach(CMD_SRC ${CMD_SOURCES}) @@ -8,6 +10,11 @@ foreach(CMD_SRC ${CMD_SOURCES}) install(TARGETS ${CMD_NAME} RUNTIME DESTINATION usr/Tests/Kernel) endforeach() + +foreach(TEST_SRC ${LIBTEST_BASED_SOURCES}) + serenity_test(${TEST_SRC} Kernel) +endforeach() + target_link_libraries(elf-execve-mmap-race LibPthread) target_link_libraries(kill-pidtid-confusion LibPthread) target_link_libraries(nanosleep-race-outbuf-munmap LibPthread) diff --git a/Userland/Tests/Kernel/TestKernelUnveil.cpp b/Userland/Tests/Kernel/TestKernelUnveil.cpp new file mode 100644 index 0000000000..17faade242 --- /dev/null +++ b/Userland/Tests/Kernel/TestKernelUnveil.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2020, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +TEST_CASE(test_failures) +{ + auto res = unveil("/etc", "r"); + if (res < 0) + FAIL("unveil read only failed"); + + res = unveil("/etc", "w"); + if (res >= 0) + FAIL("unveil write permitted after unveil read only"); + + res = unveil("/etc", "x"); + if (res >= 0) + FAIL("unveil execute permitted after unveil read only"); + + res = unveil("/etc", "c"); + if (res >= 0) + FAIL("unveil create permitted after unveil read only"); + + res = unveil("/tmp/doesnotexist", "c"); + if (res < 0) + FAIL("unveil create on non-existent path failed"); + + res = unveil("/home", "b"); + if (res < 0) + FAIL("unveil browse failed"); + + res = unveil("/home", "w"); + if (res >= 0) + FAIL("unveil write permitted after unveil browse only"); + + res = unveil("/home", "x"); + if (res >= 0) + FAIL("unveil execute permitted after unveil browse only"); + + res = unveil("/home", "c"); + if (res >= 0) + FAIL("unveil create permitted after unveil browse only"); + + res = unveil(nullptr, nullptr); + if (res < 0) + FAIL("unveil state lock failed"); + + res = unveil("/bin", "w"); + if (res >= 0) + FAIL("unveil permitted after unveil state locked"); +} diff --git a/Userland/Tests/Kernel/unveil-test-failures.cpp b/Userland/Tests/Kernel/unveil-test-failures.cpp deleted file mode 100644 index 33d05c04e0..0000000000 --- a/Userland/Tests/Kernel/unveil-test-failures.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2020, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include - -int main() -{ - int res = unveil("/etc", "r"); - if (res < 0) { - fprintf(stderr, "FAIL, unveil read only failed\n"); - return 1; - } - - res = unveil("/etc", "w"); - if (res >= 0) { - fprintf(stderr, "FAIL, unveil write permitted after unveil read only\n"); - return 1; - } - - res = unveil("/etc", "x"); - if (res >= 0) { - fprintf(stderr, "FAIL, unveil execute permitted after unveil read only\n"); - return 1; - } - - res = unveil("/etc", "c"); - if (res >= 0) { - fprintf(stderr, "FAIL, unveil create permitted after unveil read only\n"); - return 1; - } - - res = unveil("/tmp/doesnotexist", "c"); - if (res < 0) { - fprintf(stderr, "FAIL, unveil create on non-existent path failed\n"); - return 1; - } - - res = unveil("/home", "b"); - if (res < 0) { - fprintf(stderr, "FAIL, unveil browse failed\n"); - return 1; - } - - res = unveil("/home", "w"); - if (res >= 0) { - fprintf(stderr, "FAIL, unveil write permitted after unveil browse only\n"); - return 1; - } - - res = unveil("/home", "x"); - if (res >= 0) { - fprintf(stderr, "FAIL, unveil execute permitted after unveil browse only\n"); - return 1; - } - - res = unveil("/home", "c"); - if (res >= 0) { - fprintf(stderr, "FAIL, unveil create permitted after unveil browse only\n"); - return 1; - } - - res = unveil(nullptr, nullptr); - if (res < 0) { - fprintf(stderr, "FAIL, unveil state lock failed\n"); - return 1; - } - - res = unveil("/bin", "w"); - if (res >= 0) { - fprintf(stderr, "FAIL, unveil permitted after unveil state locked\n"); - return 1; - } - - printf("PASS\n"); - return 0; -}