tests: common: add rand32 test
Change-Id: I499586a3be1f9794b68b5cf2e5047a762ea11104 Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
5058bb75bc
commit
f431084619
|
@ -2,3 +2,4 @@ CONFIG_ZTEST=y
|
|||
CONFIG_RING_BUFFER=y
|
||||
CONFIG_PRINTK=y
|
||||
CONFIG_SYS_LOG=y
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
|
|
|
@ -4,3 +4,4 @@ obj-y += main.o atomic.o byteorder.o intmath.o printk.o
|
|||
obj-y += ring_buf.o
|
||||
obj-y += slist.o
|
||||
obj-n += bitfield.o
|
||||
obj-y += rand32.o
|
||||
|
|
|
@ -26,6 +26,7 @@ extern void intmath_test(void);
|
|||
extern void printk_test(void);
|
||||
extern void ring_buffer_test(void);
|
||||
extern void slist_test(void);
|
||||
extern void rand32_test(void);
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
|
@ -36,6 +37,7 @@ void test_main(void)
|
|||
ztest_unit_test(printk_test),
|
||||
ztest_unit_test(ring_buffer_test),
|
||||
ztest_unit_test(slist_test),
|
||||
ztest_unit_test(rand32_test),
|
||||
ztest_unit_test(intmath_test)
|
||||
);
|
||||
|
||||
|
|
|
@ -17,13 +17,12 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* DESCRIPTION
|
||||
* This module tests the following random number routines:
|
||||
* uint32_t sys_rand32_get(void);
|
||||
*/
|
||||
|
||||
#include <tc_util.h>
|
||||
#include <zephyr.h>
|
||||
#include <ztest.h>
|
||||
#include <misc/sys_log.h>
|
||||
|
||||
#define N_VALUES 10
|
||||
|
||||
|
@ -35,20 +34,16 @@
|
|||
* @return N/A
|
||||
*/
|
||||
|
||||
void main(void)
|
||||
void rand32_test(void)
|
||||
{
|
||||
int tc_result; /* test result code */
|
||||
uint32_t rnd_values[N_VALUES];
|
||||
int i;
|
||||
|
||||
PRINT_DATA("Starting random number tests\n");
|
||||
PRINT_LINE;
|
||||
|
||||
/*
|
||||
* Test subsequently calls sys_rand32_get(), checking
|
||||
* that two values are not equal.
|
||||
*/
|
||||
PRINT_DATA("Generating random numbers\n");
|
||||
SYS_LOG_DBG("Generating random numbers");
|
||||
/*
|
||||
* Get several subsequent numbers as fast as possible.
|
||||
* If random number generator is based on timer, check
|
||||
|
@ -61,21 +56,9 @@ void main(void)
|
|||
for (i = 0; i < N_VALUES; i++) {
|
||||
rnd_values[i] = sys_rand32_get();
|
||||
}
|
||||
for (tc_result = TC_PASS, i = 1; i < N_VALUES; i++) {
|
||||
if (rnd_values[i - 1] == rnd_values[i]) {
|
||||
tc_result = TC_FAIL;
|
||||
break;
|
||||
}
|
||||
for (i = 1; i < N_VALUES; i++) {
|
||||
assert_false((rnd_values[i - 1] == rnd_values[i]),
|
||||
"random number subsequent calls return same value");
|
||||
}
|
||||
|
||||
if (tc_result == TC_FAIL) {
|
||||
TC_ERROR("random number subsequent calls\n"
|
||||
"returned same value %d\n", rnd_values[i]);
|
||||
} else {
|
||||
PRINT_DATA("Generated %d values with expected randomness\n",
|
||||
N_VALUES);
|
||||
}
|
||||
|
||||
TC_END_RESULT(tc_result);
|
||||
TC_END_REPORT(tc_result);
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
# Makefile - random number generator regression testing Makefile for microkernel
|
||||
#
|
||||
# Copyright (c) 2015 Wind River Systems, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
KERNEL_TYPE = unified
|
||||
BOARD ?= qemu_x86
|
||||
CONF_FILE = prj.conf
|
||||
|
||||
include ${ZEPHYR_BASE}/Makefile.inc
|
|
@ -1,30 +0,0 @@
|
|||
Title: Random Number Generator APIs
|
||||
|
||||
Description:
|
||||
|
||||
This test verifies the following random number APIs operate
|
||||
as expected:
|
||||
sys_rand32_get()
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Building and Running Project:
|
||||
|
||||
This microkernel project outputs to the console. It can be built and executed
|
||||
on QEMU as follows:
|
||||
|
||||
make pristine
|
||||
make qemu
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Sample Output:
|
||||
|
||||
Starting random number tests
|
||||
===================================================================
|
||||
Generating random numbers
|
||||
Generated 10 values with expected randomness
|
||||
===================================================================
|
||||
PASS - RegressionTaskEntry.
|
||||
===================================================================
|
||||
PROJECT EXECUTION SUCCESSFUL
|
|
@ -1,5 +0,0 @@
|
|||
# Use non-random number generator if platform does not
|
||||
# provide one
|
||||
# This option is NOT to be used in production code.
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
ccflags-y += -I${ZEPHYR_BASE}/tests/include
|
||||
|
||||
obj-y = test-rand32.o
|
|
@ -1,3 +0,0 @@
|
|||
[test]
|
||||
tags = core bat_commit
|
||||
kernel = unified
|
Loading…
Reference in a new issue