From 490f287c09a3e9ae1f6231389720c51cfe7fa071 Mon Sep 17 00:00:00 2001 From: Kwarde Date: Fri, 25 Jul 2025 11:13:25 +0200 Subject: [PATCH] Add tests for umask_get() and umask_set() --- src/core.asm | 2 +- src/tests.asm | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/core.asm b/src/core.asm index 0fe6ba0..463d7fc 100644 --- a/src/core.asm +++ b/src/core.asm @@ -182,7 +182,7 @@ clampu: ;----- umask_set(umask) -----; ; Sets umask -; Return value: Return value of syscall sys_umask +; Return value: Return value of syscall sys_umask (old value of umask) ; Used registers: ; rax* syscall >> (ret) ; rdi umask to set diff --git a/src/tests.asm b/src/tests.asm index 16adcc6..98e3ca8 100644 --- a/src/tests.asm +++ b/src/tests.asm @@ -108,6 +108,7 @@ section .rodata TEST_maxu equ 1 TEST_clamp equ 1 TEST_clampu equ 1 + TEST_umask equ 1 ;console.asm TEST_print equ 1 TEST_puts equ 1 @@ -218,6 +219,14 @@ section .rodata addTest(clampu2, "clampu(0, 1, 1000)") addTest(clampu3, "clampu(1337, 1, 1000)") addTest(clampu4, "clampu(MAX_UINT64, 0, MAX_UINT32)") + ;umask_set() / umask_get() + addTestHeader(_umask, "umask_[g|s]et") + addTest(umask1, "umask_get()") + addTest(umask2, "umask_set(0027q)") + addTest(umask3, "umask_get()") + addTest(umask4, "umask_set(0022q)") + addTest(umask5, "umask_get()") + addTest(umask6, "umask_get()") ;extra test to check if it wasn't changed ;print() addTestHeader(_print, "print") addTest(print1, "print(''Hello, world!\n'')") @@ -687,6 +696,43 @@ _start: assert_u_eq(MAX_UINT32) %endif +;--- umask_set() / umask_get() +%if TEST_umask + printTestHeader(_umask) + + ; TEST 1 + printTest(umask1) + call umask_get + assert_u_eq(0022q) ;Bad test, since umask could be different. + + ; TEST 2 + printTest(umask2) + mov rdi, 0027q + call umask_set + assert_u_eq(0022q) + + ; TEST 3 + printTest(umask3) + call umask_get + assert_u_eq(0027q) + + ; TEST 4 + printTest(umask4) + mov rdi, 0022q + call umask_set + assert_u_eq(0027q) + + ; TEST 5 + printTest(umask5) + call umask_get + assert_u_eq(0022q) + + ; TEST 6 + printTest(umask6) + call umask_get + assert_u_eq(0022q) +%endif + ;--- print() %if TEST_print printTestHeader(_print)