diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-31 09:50:47 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-31 09:50:47 +0100 |
| commit | 9f2369825584529ed2036588263aecf01bf89818 (patch) | |
| tree | e47b2f6ab27c3701eeb872be1a25cc9233455910 /test/kernel_test/process.test.cc | |
| parent | af944082df5844cf3215dc9dd4960aeedd18bd75 (diff) | |
feat: test add more tests.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'test/kernel_test/process.test.cc')
| -rw-r--r-- | test/kernel_test/process.test.cc | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/test/kernel_test/process.test.cc b/test/kernel_test/process.test.cc index 8a1a946e..1c7af22c 100644 --- a/test/kernel_test/process.test.cc +++ b/test/kernel_test/process.test.cc @@ -1,11 +1,11 @@ /// \file process.test.cc -/// \brief Process Out tests. +/// \brief Process management tests. /// \author Amlal El Mahrouss (amlal at nekernel dot org) #include <libSystem/SystemKit/System.h> #include <public/frameworks/KernelTest.fwrk/headers/TestCase.h> -/// \note Declare tests +/// \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; @@ -17,10 +17,72 @@ KT_DECL_TEST(ProcessHasSucceeded, []() -> bool { return RtlSpawnProcess("/system/list", 0, nullptr, nullptr, 0) > 0; }); +KT_DECL_TEST(ProcessSpawnWithArgs, []() -> bool { + Char* argv[] = {(Char*) "arg1", (Char*) "arg2"}; + Char* envp[] = {(Char*) "VAR=value"}; + + UIntPtr pid = RtlSpawnProcess("/system/list", 2, argv, envp, 1); + return pid > 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. SInt32 KT_TEST_MAIN() { KT_RUN_TEST(ProcessHasFailed); KT_RUN_TEST(ProcessHasSucceeded); + KT_RUN_TEST(ProcessSpawnWithArgs); + 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; } |
