diff options
Diffstat (limited to 'test/kernel_tests/ne_kernel_tests')
| -rw-r--r-- | test/kernel_tests/ne_kernel_tests/Makefile | 22 | ||||
| -rw-r--r-- | test/kernel_tests/ne_kernel_tests/error.test.cc | 67 | ||||
| -rw-r--r-- | test/kernel_tests/ne_kernel_tests/print.test.cc | 73 | ||||
| -rw-r--r-- | test/kernel_tests/ne_kernel_tests/process.test.cc | 78 |
4 files changed, 240 insertions, 0 deletions
diff --git a/test/kernel_tests/ne_kernel_tests/Makefile b/test/kernel_tests/ne_kernel_tests/Makefile new file mode 100644 index 00000000..c4057a5e --- /dev/null +++ b/test/kernel_tests/ne_kernel_tests/Makefile @@ -0,0 +1,22 @@ +################################################## +# (c) Amlal El Mahrouss and NeKernel Authors, licensed under the Apache 2.0 license. +# This file is for kernel testing. +################################################## + +GCC=x86_64-w64-mingw32-g++ -Wl,-subsystem=17 +LIB=-L../../src/libSystem -lSystem +STD=-std=c++20 -DKT_TESTING_ENABLED +INCLUDE=-I../../src -I../../public -I../../public/frameworks/ -I../../ + +OBJ_FILES = \ + error.test.exe \ + print.test.exe \ + process.test.exe + +.PHONY: all +all: $(OBJ_FILES) + +%.exe: %.cc + @echo "==> Building test: $@" + $(GCC) $(LIB) $< \ + $(STD) $(INCLUDE) -o $(basename $<).exe
\ No newline at end of file diff --git a/test/kernel_tests/ne_kernel_tests/error.test.cc b/test/kernel_tests/ne_kernel_tests/error.test.cc new file mode 100644 index 00000000..ece8f71d --- /dev/null +++ b/test/kernel_tests/ne_kernel_tests/error.test.cc @@ -0,0 +1,67 @@ +/// \file error.test.cc +/// \brief Error handling API tests. +/// \author Amlal El Mahrouss (amlal at nekernel dot org) + +#include <libSystem/SystemKit/System.h> +#include <public/frameworks/KernelTest.fwrk/headers/TestCase.h> + +/// \note ErrGetLastError tests +KT_DECL_TEST(ErrGetLastErrorInitial, []() -> bool { + SInt32 error = ErrGetLastError(); + return error >= 0; +}); + +KT_DECL_TEST(ErrGetLastErrorAfterSuccess, []() -> bool { + auto heap = MmCreateHeap(1024, 0); + if (!heap) return NO; + + SInt32 error = ErrGetLastError(); + MmDestroyHeap(heap); + + return error == 0; +}); + +KT_DECL_TEST(ErrGetLastErrorAfterFailure, []() -> bool { + auto heap = MmCreateHeap(0, 0); + + SInt32 error = ErrGetLastError(); + + return error != 0; +}); + +KT_DECL_TEST(ErrGetLastErrorAfterInvalidFile, []() -> bool { + auto file = IoOpenFile("/invalid/path/that/does/not/exist", nullptr); + + SInt32 error = ErrGetLastError(); + + if (file) IoCloseFile(file); + + return error != 0; +}); + +KT_DECL_TEST(ErrGetLastErrorAfterNullOp, []() -> bool { + auto ptr = MmCopyMemory(nullptr, nullptr, 10); + + SInt32 error = ErrGetLastError(); + + return error != 0; +}); + +KT_DECL_TEST(ErrGetLastErrorMultipleCalls, []() -> bool { + SInt32 error1 = ErrGetLastError(); + SInt32 error2 = ErrGetLastError(); + + return error1 == error2; +}); + +/// \brief Run error tests. +IMPORT_C SInt32 KT_TEST_MAIN() { + KT_RUN_TEST(ErrGetLastErrorInitial); + KT_RUN_TEST(ErrGetLastErrorAfterSuccess); + KT_RUN_TEST(ErrGetLastErrorAfterFailure); + KT_RUN_TEST(ErrGetLastErrorAfterInvalidFile); + KT_RUN_TEST(ErrGetLastErrorAfterNullOp); + KT_RUN_TEST(ErrGetLastErrorMultipleCalls); + + return KT_TEST_SUCCESS; +} diff --git a/test/kernel_tests/ne_kernel_tests/print.test.cc b/test/kernel_tests/ne_kernel_tests/print.test.cc new file mode 100644 index 00000000..4f9bc828 --- /dev/null +++ b/test/kernel_tests/ne_kernel_tests/print.test.cc @@ -0,0 +1,73 @@ +/// \file kout.test.cc +/// \brief Konsole Out tests. + +#include <libSystem/SystemKit/System.h> +#include <public/frameworks/KernelTest.fwrk/headers/TestCase.h> + +/// \note PrintGet tests +KT_DECL_TEST(PrintIsNull, []() -> bool { return PrintGet("/null/") == nullptr; }); +KT_DECL_TEST(PrintIsNotNull, []() -> bool { return PrintGet(nullptr) != nullptr; }); + +/// \note PrintCreate/PrintRelease tests +KT_DECL_TEST(PrintCreateValid, []() -> bool { + auto handle = PrintCreate(); + if (!handle) return NO; + PrintRelease(handle); + return YES; +}); + +KT_DECL_TEST(PrintReleaseValid, []() -> bool { + auto handle = PrintCreate(); + if (!handle) return NO; + return PrintRelease(handle) == 0; +}); + +KT_DECL_TEST(PrintReleaseNull, []() -> bool { return PrintRelease(nullptr) != 0; }); + +/// \note PrintOut tests +KT_DECL_TEST(PrintOutValid, []() -> bool { + SInt32 result = PrintOut(nullptr, "Test output\n"); + return result >= 0; +}); + +KT_DECL_TEST(PrintOutWithHandle, []() -> bool { + auto handle = PrintCreate(); + SInt32 result = PrintOut(handle, "Test with handle\n"); + PrintRelease(handle); + return result >= 0; +}); + +KT_DECL_TEST(PrintOutNull, []() -> bool { + SInt32 result = PrintOut(nullptr, nullptr); + return result < 0; +}); + +KT_DECL_TEST(PrintOutFormatted, []() -> bool { + SInt32 result = PrintOut(nullptr, "Value: %d\n", 42); + return result >= 0; +}); + +/// \note PrintIn tests +KT_DECL_TEST(PrintInValid, []() -> bool { + SInt32 result = PrintIn(nullptr, "Input prompt: "); + return result >= 0; +}); + +/// \brief Run 'kout' test. +SInt32 KT_TEST_MAIN() { + KT_RUN_TEST(PrintIsNull); + KT_RUN_TEST(PrintIsNotNull); + + KT_RUN_TEST(PrintCreateValid); + KT_RUN_TEST(PrintReleaseValid); + KT_RUN_TEST(PrintReleaseNull); + + KT_RUN_TEST(PrintOutValid); + KT_RUN_TEST(PrintOutWithHandle); + KT_RUN_TEST(PrintOutNull); + KT_RUN_TEST(PrintOutFormatted); + + KT_RUN_TEST(PrintInValid); + + return KT_TEST_SUCCESS; +} diff --git a/test/kernel_tests/ne_kernel_tests/process.test.cc b/test/kernel_tests/ne_kernel_tests/process.test.cc new file mode 100644 index 00000000..2ec7d191 --- /dev/null +++ b/test/kernel_tests/ne_kernel_tests/process.test.cc @@ -0,0 +1,78 @@ +/// \file process.test.cc +/// \brief Process management tests. +/// \author Amlal El Mahrouss (amlal at nekernel dot org) + +#include <KernelTest.fwrk/headers/TestCase.h> +#include <libSystem/SystemKit/System.h> + +/// \note RtlSpawnProcess tests +KT_DECL_TEST(ProcessHasFailed, []() -> bool { + /// \todo we return -1 here, should we document that or classify as common knowledge? + return RtlSpawnProcess("/", 0, nullptr, nullptr, 0) == -1; +}); + +KT_DECL_TEST(ProcessHasSucceeded, []() -> bool { + /// \note Any process greater than zero, exists within a specific team domain (real-time, high, or + /// low domains). + return RtlSpawnProcess("/system/list", 0, nullptr, nullptr, 0) > 0; +}); + +KT_DECL_TEST(ProcessSpawnNullPath, + []() -> bool { return RtlSpawnProcess(nullptr, 0, nullptr, nullptr, 0) == -1; }); + +KT_DECL_TEST(ProcessSpawnInvalidPath, []() -> bool { + return RtlSpawnProcess("/invalid/nonexistent", 0, nullptr, nullptr, 0) == -1; +}); + +/// \note RtlSpawnIB tests +KT_DECL_TEST(ProcessSpawnIBValid, []() -> bool { + UIntPtr pid = RtlSpawnProcess("/system/list", 0, nullptr, nullptr, 0); + if (pid <= 0) return NO; + + UInt32 result = RtlSpawnIB(pid); + return result == 0; +}); + +KT_DECL_TEST(ProcessSpawnIBInvalid, []() -> bool { + UInt32 result = RtlSpawnIB(0); + return result > 0; +}); + +/// \note RtlExitProcess tests +KT_DECL_TEST(ProcessExitValid, []() -> bool { + UIntPtr pid = RtlSpawnProcess("/system/list", 0, nullptr, nullptr, 0); + if (pid <= 0) return NO; + + Bool result = RtlExitProcess(pid, 0); + return result == YES; +}); + +KT_DECL_TEST(ProcessExitWithCode, []() -> bool { + UIntPtr pid = RtlSpawnProcess("/system/list", 0, nullptr, nullptr, 0); + if (pid <= 0) return NO; + + Bool result = RtlExitProcess(pid, 42); + return result == YES; +}); + +KT_DECL_TEST(ProcessExitInvalid, []() -> bool { + Bool result = RtlExitProcess(0, 0); + return result == NO; +}); + +/// \brief Run 'process' test. +IMPORT_C SInt32 KT_TEST_MAIN() { + KT_RUN_TEST(ProcessHasFailed); + KT_RUN_TEST(ProcessHasSucceeded); + KT_RUN_TEST(ProcessSpawnNullPath); + KT_RUN_TEST(ProcessSpawnInvalidPath); + + KT_RUN_TEST(ProcessSpawnIBValid); + KT_RUN_TEST(ProcessSpawnIBInvalid); + + KT_RUN_TEST(ProcessExitValid); + KT_RUN_TEST(ProcessExitWithCode); + KT_RUN_TEST(ProcessExitInvalid); + + return KT_TEST_SUCCESS; +} |
