test_core_runtime.odin 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package test_core_runtime
  2. import "base:intrinsics"
  3. import "core:mem"
  4. import "base:runtime"
  5. import "core:testing"
  6. // Tests that having space for the allocation, but not for the allocation and alignment
  7. // is handled correctly.
  8. @(test)
  9. test_temp_allocator_alignment_boundary :: proc(t: ^testing.T) {
  10. arena: runtime.Arena
  11. context.allocator = runtime.arena_allocator(&arena)
  12. defer runtime.arena_destroy(&arena)
  13. _, _ = mem.alloc(int(runtime.DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE)-120)
  14. _, err := mem.alloc(112, 32)
  15. testing.expect(t, err == nil)
  16. }
  17. // Tests that big allocations with big alignments are handled correctly.
  18. @(test)
  19. test_temp_allocator_big_alloc_and_alignment :: proc(t: ^testing.T) {
  20. arena: runtime.Arena
  21. context.allocator = runtime.arena_allocator(&arena)
  22. defer runtime.arena_destroy(&arena)
  23. mappy: map[[8]int]int
  24. err := reserve(&mappy, 50000)
  25. testing.expect(t, err == nil)
  26. }
  27. @(test)
  28. test_temp_allocator_returns_correct_size :: proc(t: ^testing.T) {
  29. arena: runtime.Arena
  30. context.allocator = runtime.arena_allocator(&arena)
  31. defer runtime.arena_destroy(&arena)
  32. bytes, err := mem.alloc_bytes(10, 16)
  33. testing.expect(t, err == nil)
  34. testing.expect(t, len(bytes) == 10)
  35. }