aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/entropy_sample.c
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2023-02-20 13:55:40 +0000
committerMichael Brown <mcb30@ipxe.org>2023-02-20 14:53:10 +0000
commit7d71cf318a2a6fedde7aaf9303b1cdec0cf51660 (patch)
tree1334c81e3e66bc029966bd00066fe31bcfca3abf /src/tests/entropy_sample.c
parent6625e49cea9fb9316b8eeee9b68a06ea4508bb77 (diff)
downloadipxe-7d71cf318a2a6fedde7aaf9303b1cdec0cf51660.tar.gz
[rng] Allow for entropy sources that fail during startup tests
Provide per-source state variables for the repetition count test and adaptive proportion test, to allow for the situation in which an entropy source can be enabled but then fails during the startup tests, thereby requiring an alternative entropy source to be used. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/tests/entropy_sample.c')
-rw-r--r--src/tests/entropy_sample.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/tests/entropy_sample.c b/src/tests/entropy_sample.c
index b45648c11..3c2386eab 100644
--- a/src/tests/entropy_sample.c
+++ b/src/tests/entropy_sample.c
@@ -42,8 +42,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/**
* Generate entropy samples for external testing
*
+ * @v source Entropy source
*/
-static void entropy_sample_test_exec ( void ) {
+static void entropy_sample ( struct entropy_source *source ) {
static noise_sample_t samples[SAMPLE_BLOCKSIZE];
unsigned int i;
unsigned int j;
@@ -53,22 +54,35 @@ static void entropy_sample_test_exec ( void ) {
for ( i = 0 ; i < ( SAMPLE_COUNT / SAMPLE_BLOCKSIZE ) ; i++ ) {
/* Collect one block of samples */
- rc = entropy_enable();
+ rc = entropy_enable ( source );
ok ( rc == 0 );
for ( j = 0 ; j < SAMPLE_BLOCKSIZE ; j++ ) {
- rc = get_noise ( &samples[j] );
+ rc = get_noise ( source, &samples[j] );
ok ( rc == 0 );
}
- entropy_disable();
+ entropy_disable ( source );
/* Print out sample values */
for ( j = 0 ; j < SAMPLE_BLOCKSIZE ; j++ ) {
- printf ( "SAMPLE %d %d\n", ( i * SAMPLE_BLOCKSIZE + j ),
- samples[j] );
+ printf ( "SAMPLE %s %d %d\n", source->name,
+ ( i * SAMPLE_BLOCKSIZE + j ), samples[j] );
}
}
}
+/**
+ * Generate entropy samples for external testing
+ *
+ */
+static void entropy_sample_test_exec ( void ) {
+ struct entropy_source *source;
+
+ /* Test each entropy source */
+ for_each_table_entry ( source, ENTROPY_SOURCES ) {
+ entropy_sample ( source );
+ }
+}
+
/** Entropy sampling self-test */
struct self_test entropy_sample_test __self_test = {
.name = "entropy_sample",