mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-25 22:43:50 +01:00
test/periph_random: added test for RNG driver
This commit is contained in:
parent
ead29a12bb
commit
8f75521bc8
10
tests/periph_random/Makefile
Normal file
10
tests/periph_random/Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
export APPLICATION = periph_random
|
||||
include ../Makefile.tests_common
|
||||
|
||||
BOARD_BLACKLIST := chronos mbed_lpc1768 msb-430 msb-430h native qemu-i386 redbee-econotag telosb \
|
||||
wsn430-v1_3b wsn430-v1_4 z1
|
||||
# all listed boards: no periph_conf.h defined,
|
||||
|
||||
USEMODULE += vtimer
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
7
tests/periph_random/README.md
Normal file
7
tests/periph_random/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
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.
|
||||
79
tests/periph_random/main.c
Normal file
79
tests/periph_random/main.c
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License v2.1. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Low-level random number generator driver test
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <vtimer.h>
|
||||
#include <periph/random.h>
|
||||
#include <periph_conf.h>
|
||||
|
||||
/* only compile test if a random number generator is defined */
|
||||
#if RANDOM_NUMOF
|
||||
|
||||
#define LIMIT (20U)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char buf[LIMIT];
|
||||
int count = 0;
|
||||
|
||||
puts("\nRandom number generator low-level driver test\n");
|
||||
printf("This test will print from 1 to %i random bytes about every second\n\n", LIMIT);
|
||||
|
||||
puts("Initializing Random Number Generator driver.\n");
|
||||
random_init();
|
||||
|
||||
while (1) {
|
||||
/* zero out buffer */
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
/* create random numbers */
|
||||
for (int i = 1; i <= LIMIT; i++) {
|
||||
printf("generating %i random byte(s)\n", i);
|
||||
count = random_read(buf, i);
|
||||
|
||||
if (count != i) {
|
||||
printf("Error generating random bytes, got %i instead of %i", count, i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Got:");
|
||||
for (int j = 0; j < i; j++) {
|
||||
printf(" 0x%02x", buf[j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
vtimer_usleep(1000 * 1000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("Random number generator low-level driver test");
|
||||
puts("There is no (pseudo) random generator implementation for your platform");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* RANDOM_NUMOF */
|
||||
Loading…
x
Reference in New Issue
Block a user