~crc_/retroforth

ref: 1eec7ab446e926ef6647e8977f4e9d56af7d8c66 retroforth/tests/malloc.retro -rw-r--r-- 1.5 KiB
1eec7ab4 — crc Change mem:* API to make memory offset calculation easier (from Rick C) a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 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:set`

```
'===TEST2:_mem:set 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:set
region1 #8 + random-value mem:set
'===OK print nl nl
```

## Test 3: `mem:get`

```
'===TEST3:_mem:get print
'Expect_ s:put 'to_contain_ s:put random-value n:put nl
'Actual_value:_____ s:put region1 mem:get n:put nl
'Calculating_memory_offset_should_not_segfault...
region1 #8 + mem:get
'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:get n:put nl
'Should_equal: print
random-value n:print nl
```

## Test 5: `mem:free`