diff options
| author | Laytan Laats <laytanlaats@hotmail.com> | 2023-11-09 12:12:01 +0100 |
|---|---|---|
| committer | Laytan Laats <laytanlaats@hotmail.com> | 2023-11-15 19:08:03 +0100 |
| commit | 9078ddaf5a89b1b8d46f0fa7d86dee027f686f5a (patch) | |
| tree | bb55433d4685d3a57f4c63cd98857f923e4a9d5e /tests/core/thread | |
| parent | 8028033513d21219886516a4d356949ebbd7489b (diff) | |
Allow larger thread poly data
The poly data currently has the restriction of being less than a
pointer's size, but there is much more space in the `Thread.user_args`
array which can be utilized, this commit allows you to pass types that are
larger than pointer length as long as the total size of the poly data is
less than that of the `Thread.user_args`.
Diffstat (limited to 'tests/core/thread')
| -rw-r--r-- | tests/core/thread/test_core_thread.odin | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/core/thread/test_core_thread.odin b/tests/core/thread/test_core_thread.odin new file mode 100644 index 000000000..e02fcc0f7 --- /dev/null +++ b/tests/core/thread/test_core_thread.odin @@ -0,0 +1,80 @@ +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 t: ^testing.T + 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(t, b == b_expect, "thread poly data not correct") + }, self_cleanup = true) + + 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(t, b == b_expect, "thread poly data not correct") + expect(t, b2 == b2_expect, "thread poly data not correct") + }, self_cleanup = true) + + 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(t, b == b_expect, "thread poly data not correct") + expect(t, b2 == b2_expect, "thread poly data not correct") + expect(t, b3 == 333, "thread poly data not correct") + }, self_cleanup = true) + + 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(t, n == 111, "thread poly data not correct") + expect(t, b == b_expect, "thread poly data not correct") + expect(t, n2 == 333, "thread poly data not correct") + expect(t, n4 == 5, "thread poly data not correct") + }, self_cleanup = true) + + thread.join_multiple(t1, t2, t3, t4) +} |