2
0

signal_handler.odin 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #+private
  2. package testing
  3. /*
  4. (c) Copyright 2024 Feoramund <[email protected]>.
  5. Made available under Odin's BSD-3 license.
  6. List of contributors:
  7. Feoramund: Total rewrite.
  8. */
  9. import "base:runtime"
  10. import "core:log"
  11. @(private, thread_local)
  12. local_test_expected_failures: struct {
  13. signal: i32,
  14. message_count: int,
  15. messages: [MAX_EXPECTED_ASSERTIONS_PER_TEST]string,
  16. location_count: int,
  17. locations: [MAX_EXPECTED_ASSERTIONS_PER_TEST]runtime.Source_Code_Location,
  18. }
  19. @(private, thread_local)
  20. local_test_assertion_raised: struct {
  21. message: string,
  22. location: runtime.Source_Code_Location,
  23. }
  24. Stop_Reason :: enum {
  25. Unknown,
  26. Successful_Stop,
  27. Illegal_Instruction,
  28. Arithmetic_Error,
  29. Segmentation_Fault,
  30. Unhandled_Trap,
  31. }
  32. test_assertion_failure_proc :: proc(prefix, message: string, loc: runtime.Source_Code_Location) -> ! {
  33. if local_test_expected_failures.message_count + local_test_expected_failures.location_count > 0 {
  34. local_test_assertion_raised = { message, loc }
  35. log.debugf("%s\n\tmessage: %q\n\tlocation: %w", prefix, message, loc)
  36. } else {
  37. log.fatalf("%s: %s", prefix, message, location = loc)
  38. }
  39. runtime.trap()
  40. }
  41. setup_signal_handler :: proc() {
  42. _setup_signal_handler()
  43. }
  44. setup_task_signal_handler :: proc(test_index: int) {
  45. _setup_task_signal_handler(test_index)
  46. }
  47. should_stop_runner :: proc() -> bool {
  48. return _should_stop_runner()
  49. }
  50. should_stop_test :: proc() -> (test_index: int, reason: Stop_Reason, ok: bool) {
  51. return _should_stop_test()
  52. }