[PATCH next 3/7] random32: Fix tests for xor -> add change to prandom_u32_state()
From: David Laight
Date: Mon Nov 02 2026 - 16:38:11 EST
The test vectors check the result of prandom_u32_state() against known
values. The change to prandom_u32_state() to add the four values to
make determining the state not completely trivial breaks this.
Rather than change the test data fix the tests by adding a local
function that combines the four values using xor.
Signed-off-by: David Laight <david.laight.linux@xxxxxxxxx>
---
lib/tests/random32_kunit.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/lib/tests/random32_kunit.c b/lib/tests/random32_kunit.c
index 0b4af2b09c01..ccf439686fda 100644
--- a/lib/tests/random32_kunit.c
+++ b/lib/tests/random32_kunit.c
@@ -136,6 +136,16 @@ static void prandom_state_test_seed(struct rnd_state *state, u32 seed)
state->s4 = __seed(LCG(state->s3), 128U);
}
+/*
+ * prandom_u32_state() adds the values to stop the generator being linear.
+ * To avoid changing the test recover the expected value.
+ */
+static u32 prandom_u32_state_xor(struct rnd_state *state)
+{
+ prandom_u32_state(state);
+ return state->s1 ^ state->s2 ^ state->s3 ^ state->s4;
+}
+
static void test_prandom_seed_boundary(struct kunit *test)
{
int i;
@@ -144,7 +154,7 @@ static void test_prandom_seed_boundary(struct kunit *test)
for (i = 0; i < ARRAY_SIZE(test1); i++) {
prandom_state_test_seed(&state, test1[i].seed);
prandom_warmup(&state);
- KUNIT_EXPECT_EQ(test, test1[i].result, prandom_u32_state(&state));
+ KUNIT_EXPECT_EQ(test, test1[i].result, prandom_u32_state_xor(&state));
}
}
@@ -160,7 +170,7 @@ static void test_prandom_taus113(struct kunit *test)
for (j = 0; j < test2[i].iteration - 1; j++)
prandom_u32_state(&state);
- KUNIT_EXPECT_EQ(test, test2[i].result, prandom_u32_state(&state));
+ KUNIT_EXPECT_EQ(test, test2[i].result, prandom_u32_state_xor(&state));
}
}
--
2.39.5