/ test.odin
test.odin
 1  #+private=file
 2  
 3  package listmap
 4  
 5  import "base:builtin"
 6  import "base:runtime"
 7  import "core:mem"
 8  import "core:prof/spall"
 9  import "core:slice"
10  import "core:sync"
11  import "core:testing"
12  
13  spall_ctx: spall.Context
14  @(thread_local)
15  spall_buffer: spall.Buffer
16  @(thread_local)
17  spall_buffer_back: [spall.BUFFER_DEFAULT_SIZE]byte
18  
19  @(instrumentation_enter)
20  spall_enter :: proc "contextless" (
21  	proc_address, call_site_return_address: rawptr,
22  	loc: runtime.Source_Code_Location,
23  ) {
24  	spall._buffer_begin(&spall_ctx, &spall_buffer, "", "", loc)
25  }
26  
27  @(instrumentation_exit)
28  spall_exit :: proc "contextless" (
29  	proc_address, call_site_return_address: rawptr,
30  	loc: runtime.Source_Code_Location,
31  ) {
32  	spall._buffer_end(&spall_ctx, &spall_buffer)
33  }
34  
35  buf: [1024]byte
36  list: [64]i32
37  
38  @(test)
39  test_basic :: proc(t: ^testing.T) {
40  	spall_ctx = spall.context_create(#procedure + `.spall`)
41  	defer spall.context_destroy(&spall_ctx)
42  
43  	spall_buffer = spall.buffer_create(spall_buffer_back[:], u32(sync.current_thread_id()))
44  	defer spall.buffer_destroy(&spall_ctx, &spall_buffer)
45  
46  	{
47  		control: Allocator
48  		init_allocator(&control, buf[:], list[:])
49  
50  		context.allocator = allocator(&control)
51  		context.temp_allocator = allocator(&control)
52  
53  		test_list: []int
54  		{
55  			err: mem.Allocator_Error
56  			test_list, err = make([]int, 3)
57  			assert(err == nil)
58  		}
59  
60  		test_list[0] = 5
61  		test_list[1] = 10
62  		test_list[2] = 1
63  
64  		testing.expect(t, slice.equal((transmute([]int)buf[:])[:3], []int{5, 10, 1}))
65  
66  		{
67  			err := delete(test_list)
68  			assert(err == nil)
69  		}
70  	}
71  }