diff --git a/samples/microkernel/test/test_rand32/Makefile b/samples/microkernel/test/test_rand32/Makefile new file mode 100644 index 00000000000..8bb22db02f5 --- /dev/null +++ b/samples/microkernel/test/test_rand32/Makefile @@ -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 diff --git a/samples/microkernel/test/test_rand32/README.txt b/samples/microkernel/test/test_rand32/README.txt new file mode 100644 index 00000000000..aaee0cbf141 --- /dev/null +++ b/samples/microkernel/test/test_rand32/README.txt @@ -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 diff --git a/samples/microkernel/test/test_rand32/prj.conf b/samples/microkernel/test/test_rand32/prj.conf new file mode 100644 index 00000000000..f3b77c1ff14 --- /dev/null +++ b/samples/microkernel/test/test_rand32/prj.conf @@ -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 + diff --git a/samples/microkernel/test/test_rand32/prj.vpf b/samples/microkernel/test/test_rand32/prj.vpf new file mode 100644 index 00000000000..5b442a8c7f1 --- /dev/null +++ b/samples/microkernel/test/test_rand32/prj.vpf @@ -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] + diff --git a/samples/microkernel/test/test_rand32/src/Makefile b/samples/microkernel/test/test_rand32/src/Makefile new file mode 100644 index 00000000000..26f9af07b1e --- /dev/null +++ b/samples/microkernel/test/test_rand32/src/Makefile @@ -0,0 +1,3 @@ +EXTRA_CFLAGS += ${PROJECTINCLUDE} -I${srctree}/samples/include + +obj-y = test-rand32.o diff --git a/samples/microkernel/test/test_rand32/src/test-rand32.c b/samples/microkernel/test/test_rand32/src/test-rand32.c new file mode 100644 index 00000000000..ae47364582d --- /dev/null +++ b/samples/microkernel/test/test_rand32/src/test-rand32.c @@ -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 +#include + +#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); +} diff --git a/scripts/sanity_chk/regression_chk b/scripts/sanity_chk/regression_chk index fd1089ab907..5083043d31c 100755 --- a/scripts/sanity_chk/regression_chk +++ b/scripts/sanity_chk/regression_chk @@ -116,6 +116,7 @@ microkernel/test/test_mail ti_lm3s6965! fsl_frdm_k64f \n\ microkernel/test/test_map ti_lm3s6965! fsl_frdm_k64f \n\ microkernel/test/test_pool ti_lm3s6965! fsl_frdm_k64f \n\ microkernel/test/test_mutex ti_lm3s6965! fsl_frdm_k64f \n\ +microkernel/test/test_rand32 ti_lm3s6965! fsl_frdm_k64f \n\ microkernel/test/test_secure_string_api ti_lm3s6965! fsl_frdm_k64f \n\ microkernel/test/test_sema ti_lm3s6965! fsl_frdm_k64f \n\ microkernel/test/test_sprintf ti_lm3s6965! fsl_frdm_k64f \n\ @@ -133,6 +134,7 @@ microkernel/test/test_map minuteia! pentium4! atom quark \n\ microkernel/test/test_pipe minuteia! pentium4! atom quark \n\ microkernel/test/test_pool minuteia! pentium4! atom quark \n\ microkernel/test/test_mutex minuteia! pentium4! atom quark \n\ +microkernel/test/test_rand32 minuteia! pentium4! atom quark \n\ microkernel/test/test_secure_string_api pentium4! minuteia! atom quark \n\ microkernel/test/test_sema pentium4! minuteia! atom quark \n\ microkernel/test/test_sprintf pentium4! minuteia! atom quark \n\