mirror of
https://git.sr.ht/~crc_/retroforth
synced 2024-11-16 19:48:56 +01:00
34c7ffbf53
FossilOrigin-Name: 1a2425fe8ad9a5b2300c4e810680964ddf369a60f3fb2d69d59c0ea2a8fd6152
77 lines
1.5 KiB
Forth
77 lines
1.5 KiB
Forth
# 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
|
|
```
|
|
|
|
## Test 2: `mem:store`
|
|
|
|
```
|
|
'===TEST2:_mem:store print
|
|
'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
|
|
region1 random-value mem:store
|
|
region1 #8 + random-value mem:store
|
|
'===OK print nl nl
|
|
```
|
|
|
|
## Test 3: `mem:fetch`
|
|
|
|
```
|
|
'===TEST3:_mem:fetch print
|
|
'Expect_ s:put 'to_contain_ s:put random-value n:put nl
|
|
'Actual_value:_____ s:put region1 mem:fetch n:put nl
|
|
'Calculating_memory_offset_should_not_segfault...
|
|
region1 #8 + mem:fetch
|
|
'Contents_of_(region1_+_1)_=_ s:put n:put nl
|
|
'===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
|
|
region2 mem:fetch n:put nl
|
|
'Should_equal: print
|
|
random-value n:print nl
|
|
```
|
|
|
|
## Test 5: `mem:free`
|