diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-07-10 11:31:46 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-07-10 11:31:46 +0800 |
| commit | e90b72ec3082588b296956730bd2930cf8d5d671 (patch) | |
| tree | 36ff6916af9b4176ea5a9662219d11e721f0b691 /test/test_random.cc | |
| parent | 1767d390fbf3d0c65389de46caf0b6d43ef3b6ad (diff) | |
| download | lume-e90b72ec3082588b296956730bd2930cf8d5d671.tar.gz lume-e90b72ec3082588b296956730bd2930cf8d5d671.tar.xz | |
refactor: promote new architecture to repository root
Archive the deprecated implementation under lume-legacy, make the new kernel the default root-level build, and update repository entry points without changing kernel behavior.
Diffstat (limited to 'test/test_random.cc')
| -rw-r--r-- | test/test_random.cc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/test_random.cc b/test/test_random.cc new file mode 100644 index 0000000..d546410 --- /dev/null +++ b/test/test_random.cc @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Copyright (C) 2026 Richard Qin */ + +#include <lume/selftest.h> +#include <lume/random.h> +#include <lume/kprintf.h> + +void selftest_random() +{ + /* Test 1: Basic 64-bit generation */ + kprintf("[test] random: basic 64-bit generation ... "); + uint64 v1 = get_random_u64(); + uint64 v2 = get_random_u64(); + if (v1 == v2) { + kernel_panic("random: two consecutive generations were identical!"); + } + kprintf("PASS\n"); + + /* Test 2: Basic 32-bit generation */ + kprintf("[test] random: basic 32-bit generation ... "); + uint32 v3 = get_random_u32(); + uint32 v4 = get_random_u32(); + if (v3 == v4) { + kernel_panic("random: two consecutive 32-bit generations were identical!"); + } + kprintf("PASS\n"); + + /* Test 3: Byte generation */ + kprintf("[test] random: byte generation ... "); + uint8 buf1[16]; + uint8 buf2[16]; + get_random_bytes(buf1, sizeof(buf1)); + get_random_bytes(buf2, sizeof(buf2)); + + bool all_zero1 = true; + bool all_zero2 = true; + bool same = true; + + for (int i = 0; i < 16; i++) { + if (buf1[i] != 0) all_zero1 = false; + if (buf2[i] != 0) all_zero2 = false; + if (buf1[i] != buf2[i]) same = false; + } + + if (all_zero1 || all_zero2 || same) { + kernel_panic("random: byte generation statistical failure!"); + } + kprintf("PASS\n"); +} |
