()
| 819 | |
| 820 | kmain: () { |
| 821 | heap_set_region(KHEAP_BASE, KHEAP_END) |
| 822 | |
| 823 | ptr: u8* = 0 as u8* |
| 824 | first := memory_allocator.allocate(5, 64) |
| 825 | match first { |
| 826 | Ok(value) -> { ptr = value } |
| 827 | Err(error) -> { fail(1) } |
| 828 | } |
| 829 | if (ptr as u64) % 64 != 0 { fail(2) } |
| 830 | ptr[0] = 17 |
| 831 | ptr[4] = 93 |
| 832 | |
| 833 | grown: u8* = 0 as u8* |
| 834 | resized := memory_allocator.reallocate(ptr, 5, 19, 64) |
| 835 | match resized { |
| 836 | Ok(value) -> { grown = value } |
| 837 | Err(error) -> { fail(3) } |
| 838 | } |
| 839 | if (grown as u64) % 64 != 0 { fail(4) } |
| 840 | if grown[0] != 17 or grown[4] != 93 { fail(5) } |
| 841 | |
| 842 | failed := memory_allocator.reallocate(grown, 19, 1099511627776, 64) |
| 843 | match failed { |
| 844 | Ok(value) -> { fail(9) } |
| 845 | Err(error) -> {} |
| 846 | } |
| 847 | if grown[0] != 17 or grown[4] != 93 { fail(10) } |
| 848 | memory_allocator.deallocate(grown, 19, 64) |
| 849 | |
| 850 | zero: u8* = 0 as u8* |
| 851 | empty := memory_allocator.allocate(0, 128) |
| 852 | match empty { |
| 853 | Ok(value) -> { zero = value } |
| 854 | Err(error) -> { fail(11) } |
| 855 | } |
| 856 | if zero == null or (zero as u64) % 128 != 0 { fail(12) } |
| 857 | memory_allocator.deallocate(zero, 0, 128) |
| 858 | |
| 859 | invalid := memory_allocator.allocate(8, 3) |
| 860 | match invalid { |
| 861 | Ok(value) -> { fail(6) } |
| 862 | Err(error) -> { |
| 863 | match error { |
| 864 | InvalidAlignment -> {} |
| 865 | OutOfMemory -> { fail(7) } |
| 866 | SizeOverflow -> { fail(8) } |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | max: u64 = 0 |
| 872 | max -= 1 |
| 873 | overflow := memory_allocator.allocate(max, 8) |
| 874 | match overflow { |
| 875 | Ok(value) -> { fail(13) } |
| 876 | Err(error) -> { |
| 877 | match error { |
| 878 | SizeOverflow -> {} |
nothing calls this directly
no test coverage detected