2022-07-27 11:57:31 +02:00
|
|
|
# Allocator Tests
|
|
|
|
|
|
|
|
## Test Setup / Helpers
|
|
|
|
|
|
|
|
```
|
|
|
|
hex
|
|
|
|
:print s:put nl ;
|
|
|
|
:n:print n:put nl ;
|
|
|
|
:double:print n:put n:put nl ;
|
|
|
|
```
|
|
|
|
|
|
|
|
## Test 1: `mem:alloc`
|
|
|
|
|
|
|
|
Attempt to allocate 32 bytes of memory and assign it to the const `region1`:
|
|
|
|
|
|
|
|
```
|
|
|
|
'===TEST1:_mem:alloc print
|
|
|
|
'Allocating... print
|
|
|
|
#32 mem:alloc
|
|
|
|
'Storing_to_`region1`... print
|
|
|
|
'region1 double:const
|
|
|
|
'New_memory_region_allocated_at print
|
|
|
|
region1 double:print
|
|
|
|
'===OK print nl nl
|
|
|
|
```
|
|
|
|
|
2022-08-08 18:04:29 +02:00
|
|
|
## Test 2: `mem:store`
|
2022-07-27 11:57:31 +02:00
|
|
|
|
|
|
|
```
|
2022-08-08 18:04:29 +02:00
|
|
|
'===TEST2:_mem:store print
|
2022-07-27 11:57:31 +02:00
|
|
|
'Creating_a_random_value... print
|
|
|
|
n:random
|
|
|
|
'Storing_to_`random-value`... print
|
|
|
|
'random-value const
|
|
|
|
'New_random_value_is: print
|
|
|
|
random-value n:print
|
|
|
|
'Storing_value_to_`region1`... print
|
2022-08-08 18:04:29 +02:00
|
|
|
region1 random-value mem:store
|
|
|
|
region1 #8 + random-value mem:store
|
2022-07-27 11:57:31 +02:00
|
|
|
'===OK print nl nl
|
|
|
|
```
|
|
|
|
|
2022-08-08 18:04:29 +02:00
|
|
|
## Test 3: `mem:fetch`
|
2022-07-27 11:57:31 +02:00
|
|
|
|
|
|
|
```
|
2022-08-08 18:04:29 +02:00
|
|
|
'===TEST3:_mem:fetch print
|
2022-07-27 11:57:31 +02:00
|
|
|
'Expect_ s:put 'to_contain_ s:put random-value n:put nl
|
2022-08-08 18:04:29 +02:00
|
|
|
'Actual_value:_____ s:put region1 mem:fetch n:put nl
|
2022-07-31 02:46:20 +02:00
|
|
|
'Calculating_memory_offset_should_not_segfault...
|
2022-08-08 18:04:29 +02:00
|
|
|
region1 #8 + mem:fetch
|
2022-07-31 02:46:20 +02:00
|
|
|
'Contents_of_(region1_+_1)_=_ s:put n:put nl
|
2022-07-27 11:57:31 +02:00
|
|
|
'===OK print nl nl
|
|
|
|
```
|
|
|
|
|
|
|
|
## Test 4: `mem:resize`
|
|
|
|
|
|
|
|
```
|
|
|
|
'===TEST4:_mem:resize print
|
|
|
|
'Resizing_`region1`_to_64_bytes... print
|
|
|
|
region1 #64 mem:resize
|
|
|
|
'Storing_to_`region2`... print
|
|
|
|
'region2 double:const
|
|
|
|
'New_region_address:_ s:put region2 double:print
|
|
|
|
'Old_region_address:_ s:put region1 double:print
|
|
|
|
'===OK print nl nl
|
|
|
|
```
|
|
|
|
|
|
|
|
## Test 5: Read/Write to resized region
|
|
|
|
|
|
|
|
```
|
|
|
|
'Region2_contains: print
|
2022-08-08 18:04:29 +02:00
|
|
|
region2 mem:fetch n:put nl
|
2022-07-27 11:57:31 +02:00
|
|
|
'Should_equal: print
|
|
|
|
random-value n:print nl
|
|
|
|
```
|
|
|
|
|
|
|
|
## Test 5: `mem:free`
|