summaryrefslogtreecommitdiffhomepage
path: root/test/user_tests/kernel_test/error.test.cc
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-03-06 06:36:01 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-03-06 06:37:15 +0100
commitac993e1cf8ec4c55cbd1e80c7b94ac492d6dc4e8 (patch)
tree7993e57bdab4fa9b6400d81ae477c736193de352 /test/user_tests/kernel_test/error.test.cc
parenta5f3fdf32ba6aa34a5dd05eeb807446a9f046393 (diff)
[FEAT] HeapMgr: Add LockDelegate to allocation calls, and re-introduce double-free prevention.
[CHORE] FileMgr: Cleanup and tweaks. [CHORE] ABI: Update copyright year. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'test/user_tests/kernel_test/error.test.cc')
-rw-r--r--test/user_tests/kernel_test/error.test.cc67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/user_tests/kernel_test/error.test.cc b/test/user_tests/kernel_test/error.test.cc
new file mode 100644
index 00000000..ece8f71d
--- /dev/null
+++ b/test/user_tests/kernel_test/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;
+}