test_core_thread.odin 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package test_core_thread
  2. import "core:testing"
  3. import "core:thread"
  4. import "base:intrinsics"
  5. @(test)
  6. poly_data_test :: proc(_t: ^testing.T) {
  7. MAX :: size_of(rawptr) * thread.MAX_USER_ARGUMENTS
  8. @static poly_data_test_t: ^testing.T
  9. poly_data_test_t = _t
  10. b: [MAX]byte = 8
  11. t1 := thread.create_and_start_with_poly_data(b, proc(b: [MAX]byte) {
  12. b_expect: [MAX]byte = 8
  13. testing.expect(poly_data_test_t, b == b_expect, "thread poly data not correct")
  14. })
  15. defer free(t1)
  16. b1: [3]uintptr = 1
  17. b2: [MAX / 2]byte = 3
  18. t2 := thread.create_and_start_with_poly_data2(b1, b2, proc(b: [3]uintptr, b2: [MAX / 2]byte) {
  19. b_expect: [3]uintptr = 1
  20. b2_expect: [MAX / 2]byte = 3
  21. testing.expect(poly_data_test_t, b == b_expect, "thread poly data not correct")
  22. testing.expect(poly_data_test_t, b2 == b2_expect, "thread poly data not correct")
  23. })
  24. defer free(t2)
  25. t3 := thread.create_and_start_with_poly_data3(b1, b2, uintptr(333), proc(b: [3]uintptr, b2: [MAX / 2]byte, b3: uintptr) {
  26. b_expect: [3]uintptr = 1
  27. b2_expect: [MAX / 2]byte = 3
  28. testing.expect(poly_data_test_t, b == b_expect, "thread poly data not correct")
  29. testing.expect(poly_data_test_t, b2 == b2_expect, "thread poly data not correct")
  30. testing.expect(poly_data_test_t, b3 == 333, "thread poly data not correct")
  31. })
  32. defer free(t3)
  33. 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) {
  34. b_expect: [3]uintptr = 1
  35. testing.expect(poly_data_test_t, n == 111, "thread poly data not correct")
  36. testing.expect(poly_data_test_t, b == b_expect, "thread poly data not correct")
  37. testing.expect(poly_data_test_t, n2 == 333, "thread poly data not correct")
  38. testing.expect(poly_data_test_t, n4 == 5, "thread poly data not correct")
  39. })
  40. defer free(t4)
  41. thread.join_multiple(t1, t2, t3, t4)
  42. }