From 832003dd4b20b3581e22f57ffef72e67d6cb7146 Mon Sep 17 00:00:00 2001 From: CiD- Date: Tue, 8 Mar 2022 17:15:45 -0500 Subject: [PATCH] os2 tests --- core/os/os2/errors_linux.odin | 11 +++++++++++ core/os/os2/file.odin | 4 ---- core/os/os2/file_linux.odin | 29 +---------------------------- tests/core/Makefile | 7 +++++-- 4 files changed, 17 insertions(+), 34 deletions(-) diff --git a/core/os/os2/errors_linux.odin b/core/os/os2/errors_linux.odin index f074c7c86..d9056bd6b 100644 --- a/core/os/os2/errors_linux.odin +++ b/core/os/os2/errors_linux.odin @@ -1,6 +1,8 @@ //+private package os2 +import "core:sys/unix" + EPERM :: 1 ENOENT :: 2 ESRCH :: 3 @@ -126,6 +128,15 @@ ENOTRECOVERABLE:: 131 /* State not recoverable */ ERFKILL :: 132 /* Operation not possible due to RF-kill */ EHWPOISON :: 133 /* Memory page has hardware error */ +_get_platform_error :: proc(res: int) -> Error { + errno := unix.get_errno(res) + return Platform_Error{i32(errno)} +} + +_ok_or_error :: proc(res: int) -> Error { + return res >= 0 ? nil : _get_platform_error(res) +} + _error_string :: proc(errno: i32) -> string { if errno == 0 { return "" diff --git a/core/os/os2/file.odin b/core/os/os2/file.odin index 09e1e8daf..707df37a2 100644 --- a/core/os/os2/file.odin +++ b/core/os/os2/file.odin @@ -61,10 +61,6 @@ create :: proc(name: string, perm: File_Mode = 0) -> (Handle, Error) { return open(name, {.Read, .Write, .Create}, perm) } -opendir :: proc(name: string) -> (Handle, Error) { - return _opendir(name) -} - open :: proc(name: string, flags := File_Flags{.Read}, perm: File_Mode = 0) -> (Handle, Error) { flags := flags if .Write not_in flags { diff --git a/core/os/os2/file_linux.odin b/core/os/os2/file_linux.odin index a88515b0e..db0e2efa8 100644 --- a/core/os/os2/file_linux.odin +++ b/core/os/os2/file_linux.odin @@ -7,22 +7,8 @@ import "core:strings" import "core:sys/unix" -_get_platform_error :: proc(res: int) -> Error { - errno := unix.get_errno(res) - return Platform_Error{i32(errno)} -} - -_ok_or_error :: proc(res: int) -> Error { - return res >= 0 ? nil : _get_platform_error(res) -} - _std_handle :: proc(kind: Std_Handle_Kind) -> Handle { - switch kind { - case .stdin: return Handle(0) - case .stdout: return Handle(1) - case .stderr: return Handle(2) - } - unreachable() + return Handle(kind) } __O_RDONLY :: 0o0 @@ -38,19 +24,6 @@ __O_DIRECTORY :: 0o200000 __O_SYNC :: 0o4010000 __O_CLOEXEC :: 0o2000000 -_opendir :: proc(name: string) -> (Handle, Error) { - cstr := strings.clone_to_cstring(name, context.temp_allocator) - - flags := __O_RDONLY|__O_NONBLOCK|__O_DIRECTORY|__O_LARGEFILE|__O_CLOEXEC - - handle_i := unix.sys_open(cstr, flags) - if handle_i < 0 { - return INVALID_HANDLE, _get_platform_error(handle_i) - } - - return Handle(handle_i), nil -} - _open :: proc(name: string, flags: File_Flags, perm: File_Mode) -> (Handle, Error) { cstr := strings.clone_to_cstring(name, context.temp_allocator) diff --git a/tests/core/Makefile b/tests/core/Makefile index 1c2cee6bd..0c3e1e09a 100644 --- a/tests/core/Makefile +++ b/tests/core/Makefile @@ -1,7 +1,7 @@ ODIN=../../odin PYTHON=$(shell which python3) -all: download_test_assets image_test compress_test strings_test hash_test crypto_test noise_test +all: download_test_assets image_test compress_test strings_test hash_test crypto_test noise_test os2_test download_test_assets: $(PYTHON) download_assets.py @@ -22,4 +22,7 @@ crypto_test: $(ODIN) run crypto -out=crypto_hash -o:speed -no-bounds-check noise_test: - $(ODIN) run math/noise -out=test_noise \ No newline at end of file + $(ODIN) run math/noise -out=test_noise + +os2_test: + $(ODIN) run os2/test_os2.odin -out=test_os2