aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2023-11-24 14:06:24 +0100
committerGitHub <noreply@github.com>2023-11-24 14:06:24 +0100
commit4d89249caf2f07716db8a21ccf065bb9a73afa98 (patch)
treeef5834ce0e8d1bcc86baaab5bdb42951dd90942b /tests
parent0df1645422071e7a39340d6a8e21602394a0dbf1 (diff)
parent2e64866838e6d99387bbcaf272fdeaf063b1a308 (diff)
Merge pull request #2939 from laytan/allow-larger-thread-poly-data
Allow larger thread poly data
Diffstat (limited to 'tests')
-rw-r--r--tests/core/Makefile5
-rw-r--r--tests/core/build.bat5
-rw-r--r--tests/core/thread/test_core_thread.odin84
3 files changed, 93 insertions, 1 deletions
diff --git a/tests/core/Makefile b/tests/core/Makefile
index 919262f85..3fdadc246 100644
--- a/tests/core/Makefile
+++ b/tests/core/Makefile
@@ -3,7 +3,7 @@ PYTHON=$(shell which python3)
all: download_test_assets image_test compress_test strings_test hash_test crypto_test noise_test encoding_test \
math_test linalg_glsl_math_test filepath_test reflect_test os_exit_test i18n_test match_test c_libc_test net_test \
- fmt_test
+ fmt_test thread_test
download_test_assets:
$(PYTHON) download_assets.py
@@ -61,3 +61,6 @@ net_test:
fmt_test:
$(ODIN) run fmt -out:test_core_fmt
+
+thread_test:
+ $(ODIN) run thread -out:test_core_thread
diff --git a/tests/core/build.bat b/tests/core/build.bat
index 1d146c8a4..311c9c78e 100644
--- a/tests/core/build.bat
+++ b/tests/core/build.bat
@@ -85,3 +85,8 @@ echo ---
echo Running core:container tests
echo ---
%PATH_TO_ODIN% run container %COMMON% %COLLECTION% -out:test_core_container.exe || exit /b
+
+echo ---
+echo Running core:thread tests
+echo ---
+%PATH_TO_ODIN% run thread %COMMON% %COLLECTION% -out:test_core_thread.exe || exit /b
diff --git a/tests/core/thread/test_core_thread.odin b/tests/core/thread/test_core_thread.odin
new file mode 100644
index 000000000..c0c7396a7
--- /dev/null
+++ b/tests/core/thread/test_core_thread.odin
@@ -0,0 +1,84 @@
+package test_core_thread
+
+import "core:testing"
+import "core:thread"
+import "core:fmt"
+import "core:os"
+
+TEST_count := 0
+TEST_fail := 0
+
+t := &testing.T{}
+
+when ODIN_TEST {
+ expect :: testing.expect
+ log :: testing.log
+} else {
+ expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
+ TEST_count += 1
+ if !condition {
+ TEST_fail += 1
+ fmt.printf("[%v] %v\n", loc, message)
+ return
+ }
+ }
+ log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
+ fmt.printf("[%v] ", loc)
+ fmt.printf("log: %v\n", v)
+ }
+}
+
+main :: proc() {
+ poly_data_test(t)
+
+ if TEST_fail > 0 {
+ os.exit(1)
+ }
+}
+
+@(test)
+poly_data_test :: proc(_t: ^testing.T) {
+ MAX :: size_of(rawptr) * thread.MAX_USER_ARGUMENTS
+
+ @static poly_data_test_t: ^testing.T
+ poly_data_test_t = _t
+
+ b: [MAX]byte = 8
+ t1 := thread.create_and_start_with_poly_data(b, proc(b: [MAX]byte) {
+ b_expect: [MAX]byte = 8
+ expect(poly_data_test_t, b == b_expect, "thread poly data not correct")
+ })
+ defer free(t1)
+
+ b1: [3]uintptr = 1
+ b2: [MAX / 2]byte = 3
+ t2 := thread.create_and_start_with_poly_data2(b1, b2, proc(b: [3]uintptr, b2: [MAX / 2]byte) {
+ b_expect: [3]uintptr = 1
+ b2_expect: [MAX / 2]byte = 3
+ expect(poly_data_test_t, b == b_expect, "thread poly data not correct")
+ expect(poly_data_test_t, b2 == b2_expect, "thread poly data not correct")
+ })
+ defer free(t2)
+
+ t3 := thread.create_and_start_with_poly_data3(b1, b2, uintptr(333), proc(b: [3]uintptr, b2: [MAX / 2]byte, b3: uintptr) {
+ b_expect: [3]uintptr = 1
+ b2_expect: [MAX / 2]byte = 3
+
+ expect(poly_data_test_t, b == b_expect, "thread poly data not correct")
+ expect(poly_data_test_t, b2 == b2_expect, "thread poly data not correct")
+ expect(poly_data_test_t, b3 == 333, "thread poly data not correct")
+ })
+ defer free(t3)
+
+ t4 := thread.create_and_start_with_poly_data4(uintptr(111), b1, uintptr(333), u8(5), proc(n: uintptr, b: [3]uintptr, n2: uintptr, n4: u8) {
+ b_expect: [3]uintptr = 1
+
+ expect(poly_data_test_t, n == 111, "thread poly data not correct")
+ expect(poly_data_test_t, b == b_expect, "thread poly data not correct")
+ expect(poly_data_test_t, n2 == 333, "thread poly data not correct")
+ expect(poly_data_test_t, n4 == 5, "thread poly data not correct")
+ })
+ defer free(t4)
+
+ thread.join_multiple(t1, t2, t3, t4)
+}