tests: adapted to HWRNG interface changes

This commit is contained in:
Hauke Petersen 2016-02-05 16:48:36 +01:00
parent 0c375e2bae
commit a95ec92633
6 changed files with 22 additions and 26 deletions

View File

@ -1,7 +1,7 @@
export APPLICATION = periph_random export APPLICATION = periph_hwrng
include ../Makefile.tests_common include ../Makefile.tests_common
FEATURES_REQUIRED = periph_random FEATURES_REQUIRED = periph_hwrng
USEMODULE += xtimer USEMODULE += xtimer

View File

@ -0,0 +1,9 @@
Expected result
===============
This test outputs a sequence of random bytes, starting with one, then two and so
on, until 20 random bytes are printed. Then the application sleeps for a second
and starts over.
Background
==========
Test the functionality of a platforms HWRNG implementation.

View File

@ -22,19 +22,20 @@
#include <string.h> #include <string.h>
#include "xtimer.h" #include "xtimer.h"
#include "periph/random.h" #include "periph/hwrng.h"
#define LIMIT (20U) #define LIMIT (20U)
int main(void) int main(void)
{ {
char buf[LIMIT]; uint8_t buf[LIMIT];
puts("\nRandom number generator low-level driver test\n"); puts("\nHWRNG peripheral driver test\n");
printf("This test will print from 1 to %i random bytes about every second\n\n", LIMIT); printf("This test will print from 1 to %i random bytes about every"
"second\n\n", LIMIT);
puts("Initializing Random Number Generator driver.\n"); puts("Initializing the HWRNG driver.\n");
random_init(); hwrng_init();
while (1) { while (1) {
/* zero out buffer */ /* zero out buffer */
@ -43,12 +44,7 @@ int main(void)
/* create random numbers */ /* create random numbers */
for (unsigned i = 1; i <= LIMIT; i++) { for (unsigned i = 1; i <= LIMIT; i++) {
printf("generating %u random byte(s)\n", i); printf("generating %u random byte(s)\n", i);
unsigned count = random_read(buf, i); hwrng_read(buf, i);
if (count != i) {
printf("Error generating random bytes, got %u instead of %u", count, i);
return 0;
}
printf("Got:"); printf("Got:");
for (unsigned j = 0; j < i; j++) { for (unsigned j = 0; j < i; j++) {

View File

@ -1,7 +0,0 @@
Expected result
===============
This test outputs a sequence of random bytes, starting with one, then two and so on, until 20 random bytes are printed. Then the application sleeps for a second and starts over.
Background
==========
This test was introduced to test the implementation of the low-level random number generator driver. For most platforms the implementation is based on hardware CPU peripherals.

View File

@ -1,7 +1,7 @@
APPLICATION = micro-ecc APPLICATION = micro-ecc
include ../Makefile.tests_common include ../Makefile.tests_common
FEATURES_REQUIRED = periph_random FEATURES_REQUIRED = periph_hwrng
USEPKG += micro-ecc USEPKG += micro-ecc
include $(RIOTBASE)/Makefile.include include $(RIOTBASE)/Makefile.include

View File

@ -37,7 +37,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "uECC.h" #include "uECC.h"
#include "periph/random.h" #include "periph/hwrng.h"
#define TESTROUNDS 16 #define TESTROUNDS 16
@ -61,9 +61,7 @@ int main(void)
uint8_t l_sig[uECC_BYTES * 2]; uint8_t l_sig[uECC_BYTES * 2];
/* initialize hardware random number generator */ /* initialize hardware random number generator */
random_init(); hwrng_init();
/* power off RNG to save energy */
random_poweroff();
printf("Testing %d random private key pairs and signature\n", TESTROUNDS); printf("Testing %d random private key pairs and signature\n", TESTROUNDS);