diff options
| author | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2025-05-29 16:04:56 -0400 |
|---|---|---|
| committer | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2025-05-29 16:34:07 -0400 |
| commit | b15a665898e72433d8b1486819cd57cc2a9b5f71 (patch) | |
| tree | 238be5d84ef9ca8b0418fa7bd47790fc0d05860a /tests | |
| parent | 34698288b812147202cd30cc357b47f306cc8f41 (diff) | |
Add tests for `runtime.memory_*` comparison procedures
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/core/runtime/test_core_runtime.odin | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/core/runtime/test_core_runtime.odin b/tests/core/runtime/test_core_runtime.odin index 472a5527d..6bbb9fb8a 100644 --- a/tests/core/runtime/test_core_runtime.odin +++ b/tests/core/runtime/test_core_runtime.odin @@ -4,6 +4,7 @@ package test_core_runtime import "base:intrinsics" import "core:mem" import "base:runtime" +import "core:slice" import "core:testing" // Tests that having space for the allocation, but not for the allocation and alignment @@ -177,3 +178,78 @@ test_map_get :: proc(t: ^testing.T) { check(t, m) } } + +@(test) +test_memory_equal :: proc(t: ^testing.T) { + data: [256]u8 + cmp: [256]u8 + + slice.fill(data[:], 0xAA) + slice.fill(cmp[:], 0xAA) + + for offset in 0..<len(data) { + subdata := data[offset:] + subcmp := cmp[offset:] + for idx in 0..<len(subdata) { + if !testing.expect_value(t, runtime.memory_equal(&subdata[0], &subcmp[0], len(subdata)), true) { + return + } + + subcmp[idx] = 0x55 + if !testing.expect_value(t, runtime.memory_equal(&subdata[0], &subcmp[0], len(subdata)), false) { + return + } + subcmp[idx] = 0xAA + } + } +} + +@(test) +test_memory_compare :: proc(t: ^testing.T) { + data: [256]u8 + cmp: [256]u8 + + for offset in 0..<len(data) { + subdata := data[offset:] + subcmp := cmp[offset:] + for idx in 0..<len(subdata) { + if !testing.expect_value(t, runtime.memory_compare(&subdata[0], &subcmp[0], len(subdata)), 0) { + return + } + + subdata[idx] = 0x7F + subcmp[idx] = 0xFF + if !testing.expect_value(t, runtime.memory_compare(&subdata[0], &subcmp[0], len(subdata)), -1) { + return + } + + subdata[idx] = 0xFF + subcmp[idx] = 0x7F + if !testing.expect_value(t, runtime.memory_compare(&subdata[0], &subcmp[0], len(subdata)), 1) { + return + } + + subdata[idx] = 0 + subcmp[idx] = 0 + } + } +} + +@(test) +test_memory_compare_zero :: proc(t: ^testing.T) { + data: [256]u8 + + for offset in 0..<len(data) { + subdata := data[offset:] + for idx in 0..<len(subdata) { + if !testing.expect_value(t, runtime.memory_compare_zero(&subdata[0], len(subdata)), 0) { + return + } + subdata[idx] = 0xFF + if !testing.expect_value(t, runtime.memory_compare_zero(&subdata[0], len(subdata)), 1) { + return + } + subdata[idx] = 0 + } + } +} |