Add random number API test

Change-Id: I810705c84609ca3497cc1d2dd7a2f7706f140815
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
This commit is contained in:
Dmitriy Korovkin 2015-05-25 15:10:29 -04:00 committed by Anas Nashif
commit b08727ed2d
7 changed files with 182 additions and 0 deletions

View file

@ -0,0 +1,36 @@
# Makefile - random number generator regression testing Makefile for microkernel
#
# Copyright (c) 2015 Wind River Systems, Inc.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1) Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2) Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3) Neither the name of Wind River Systems nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
BSP ?= generic_pc
VPFILE = prj.vpf
KERNEL_TYPE = micro
CONF_FILE = prj.conf
include ${TIMO_BASE}/Makefile.inc

View file

@ -0,0 +1,30 @@
Title: Microkernel random number generator test suite
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 microkernel.qemu
--------------------------------------------------------------------------------
Sample Output:
Starting random number tests
===================================================================
Generating random numbers
Generated 10 values with expected randomness
===================================================================
PASS - RegressionTaskEntry.
===================================================================
VXMICRO PROJECT EXECUTION SUCCESSFUL

View file

@ -0,0 +1,5 @@
# Use non-random number generator if BSP does not
# provide one
# This option is NOT to be used in production code.
CONFIG_TEST_RANDOM_GENERATOR=y

View file

@ -0,0 +1,11 @@
% Application : test random number APIs
% Warning: Saving a VxMicro project file (.vpf) with the
% VxMicro Project Manager (VPM) tool will result in any
% manually entered comments being removed, along with
% any format changes being undone.
% TASK NAME PRIO ENTRY STACK GROUPS
% =======================================================
TASK tTestTask 5 RegressionTaskEntry 2048 [EXE]

View file

@ -0,0 +1,3 @@
EXTRA_CFLAGS += ${PROJECTINCLUDE} -I${srctree}/samples/include
obj-y = test-rand32.o

View file

@ -0,0 +1,95 @@
/* test random number generator APIs */
/*
* Copyright (c) 2015 Wind River Systems, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1) Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2) Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3) Neither the name of Wind River Systems nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* DESCRIPTION
* This module tests the following random number routines:
* uint32_t sys_rand32_get(void);
*/
#include <tc_util.h>
#include <vxmicro.h>
#define N_VALUES 10
/*******************************************************************************
*
* RegressionTaskEntry - regression test's entry point
*
*
* RETURNS: N/A
*/
void RegressionTaskEntry(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");
/*
* Get several subsequent numbers as fast as possible.
* If random number generator is based on timer, check
* the situation when random number generator is called
* faster than timer clock ticks.
* In order to do this, make several subsequent calls
* and save results in an array to verify them on the
* next step
*/
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;
}
}
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);
}

View file

@ -116,6 +116,7 @@ microkernel/test/test_mail <uq> ti_lm3s6965! fsl_frdm_k64f \n\
microkernel/test/test_map <uq> ti_lm3s6965! fsl_frdm_k64f \n\
microkernel/test/test_pool <uq> ti_lm3s6965! fsl_frdm_k64f \n\
microkernel/test/test_mutex <uq> ti_lm3s6965! fsl_frdm_k64f \n\
microkernel/test/test_rand32 <uq> ti_lm3s6965! fsl_frdm_k64f \n\
microkernel/test/test_secure_string_api <u> ti_lm3s6965! fsl_frdm_k64f \n\
microkernel/test/test_sema <uq> ti_lm3s6965! fsl_frdm_k64f \n\
microkernel/test/test_sprintf <u> ti_lm3s6965! fsl_frdm_k64f \n\
@ -133,6 +134,7 @@ microkernel/test/test_map <uq> minuteia! pentium4! atom quark \n\
microkernel/test/test_pipe <uq> minuteia! pentium4! atom quark \n\
microkernel/test/test_pool <uq> minuteia! pentium4! atom quark \n\
microkernel/test/test_mutex <uq> minuteia! pentium4! atom quark \n\
microkernel/test/test_rand32 <uq> minuteia! pentium4! atom quark \n\
microkernel/test/test_secure_string_api <u> pentium4! minuteia! atom quark \n\
microkernel/test/test_sema <uq> pentium4! minuteia! atom quark \n\
microkernel/test/test_sprintf <u> pentium4! minuteia! atom quark \n\