diff options
| author | vassvik <mvassvik@gmail.com> | 2021-08-28 13:32:32 +0200 |
|---|---|---|
| committer | vassvik <mvassvik@gmail.com> | 2021-08-28 13:32:32 +0200 |
| commit | 8ca4286624581dcb39d22a041670bdccca50d194 (patch) | |
| tree | 07164070c009d66c04fba03b1787ca6dbe781e25 | |
| parent | 165118c64197bf962e78a9ea354bebe1141b6d7c (diff) | |
Add core:c/libc tests
| -rw-r--r-- | core/c/libc/tests/general.odin | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/core/c/libc/tests/general.odin b/core/c/libc/tests/general.odin new file mode 100644 index 000000000..1c311a8f3 --- /dev/null +++ b/core/c/libc/tests/general.odin @@ -0,0 +1,50 @@ +package libc_tests + +import "core:c/libc" + +test_stdio :: proc() { + c: libc.char = 'C'; + libc.puts("Hello from puts"); + libc.printf("Hello from printf in %c\n", c); +} +test_thread :: proc() { + thread_proc :: proc "c" (rawptr) -> libc.int { + libc.printf("Hello from thread"); + return 42; + } + thread: libc.thrd_t; + libc.thrd_create(&thread, thread_proc, nil); + result: libc.int; + libc.thrd_join(thread, &result); + libc.printf(" %d\n", result); +} + +jmp: libc.jmp_buf; +test_sjlj :: proc() { + if libc.setjmp(&jmp) != 0 { + libc.printf("Hello from longjmp\n"); + return; + } + libc.printf("Hello from setjmp\n"); + libc.longjmp(&jmp, 1); +} +test_signal :: proc() { + handler :: proc "c" (sig: libc.int) { + libc.printf("Hello from signal handler\n"); + } + libc.signal(libc.SIGABRT, handler); + libc.raise(libc.SIGABRT); +} +test_atexit :: proc() { + handler :: proc "c" () { + libc.printf("Hello from atexit\n"); + } + libc.atexit(handler); +} +main :: proc() { + test_stdio(); + test_thread(); + test_sjlj(); + test_signal(); + test_atexit(); +}
\ No newline at end of file |