From 2acc29588ae13ebe335b968bfac6fe37c6cd5401 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 17 Sep 2020 13:14:13 +0200 Subject: validation: Add space profile testsuite --- spec/build/testsuites/validation/grp.yml | 2 + spec/build/testsuites/validation/space-profile.yml | 17 + testsuites/validation/tc-space-profile.c | 366 +++++++++++++++++++++ testsuites/validation/ts-space-profile.c | 225 +++++++++++++ 4 files changed, 610 insertions(+) create mode 100644 spec/build/testsuites/validation/space-profile.yml create mode 100644 testsuites/validation/tc-space-profile.c create mode 100644 testsuites/validation/ts-space-profile.c diff --git a/spec/build/testsuites/validation/grp.yml b/spec/build/testsuites/validation/grp.yml index 564b1c62ac..83401179d7 100644 --- a/spec/build/testsuites/validation/grp.yml +++ b/spec/build/testsuites/validation/grp.yml @@ -12,6 +12,8 @@ ldflags: [] links: - role: build-dependency uid: performance-0 +- role: build-dependency + uid: space-profile - role: build-dependency uid: validation-0 - role: build-dependency diff --git a/spec/build/testsuites/validation/space-profile.yml b/spec/build/testsuites/validation/space-profile.yml new file mode 100644 index 0000000000..8dc59b802b --- /dev/null +++ b/spec/build/testsuites/validation/space-profile.yml @@ -0,0 +1,17 @@ +build-type: test-program +cflags: [] +cppflags: [] +cxxflags: [] +enabled-by: [] +features: c cprogram +includes: [] +ldflags: [] +links: [] +source: +- testsuites/validation/tc-space-profile.c +- testsuites/validation/ts-space-profile.c +stlib: [] +target: testsuites/validation/ts-space-profile.exe +type: build +use-after: [] +use-before: [] diff --git a/testsuites/validation/tc-space-profile.c b/testsuites/validation/tc-space-profile.c new file mode 100644 index 0000000000..ceb0780ce2 --- /dev/null +++ b/testsuites/validation/tc-space-profile.c @@ -0,0 +1,366 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseTestsuitesValidationCLibrary + * @ingroup RTEMSTestCaseTestsuitesValidationClassicBarrier + */ + +/* + * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) + * + * 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. + * + * 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 OWNER 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. + */ + +/* + * This file is part of the RTEMS quality process and was automatically + * generated. If you find something that needs to be fixed or + * worded better please post a report or patch to an RTEMS mailing list + * or raise a bug report: + * + * https://www.rtems.org/bugs.html + * + * For information on updating and regenerating please refer to the How-To + * section in the Software Requirements Engineering chapter of the + * RTEMS Software Engineering manual. The manual is provided as a part of + * a release. For development sources please refer to the online + * documentation at: + * + * https://docs.rtems.org + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include + +/** + * @defgroup RTEMSTestCaseTestsuitesValidationCLibrary \ + * spec:/testsuites/validation/c-library + * + * @ingroup RTEMSTestSuiteTestsuitesValidationProfile + * + * @brief This test case calls functions of the C Library which are included in + * the space profile. + * + * This test case performs the following actions: + * + * - Allocate four bytes with an alignment of 128 bytes with aligned_alloc(). + * + * - Check that the returned pointer is not NULL. + * + * - Check that the returned pointer is aligned by 128 bytes. + * + * - Allocate four bytes with rtems_malloc(). + * + * - Check that the returned pointer is not NULL. + * + * - Set an integer variable to one and then to zero with memset(). + * + * - Check that the integer variable is equal to zero. + * + * - Set a source integer variable to one, set a destination integer variable + * to two, and copy the source to the destination variable through memcpy(). + * + * - Check that the destination integer variable is equal to one. + * + * @{ + */ + +/** + * @brief Allocate four bytes with an alignment of 128 bytes with + * aligned_alloc(). + */ +static void TestsuitesValidationCLibrary_Action_0( void ) +{ + void *p; + + p = aligned_alloc(128, 4); + + /* + * Check that the returned pointer is not NULL. + */ + T_step_not_null(0, p); + + /* + * Check that the returned pointer is aligned by 128 bytes. + */ + T_step_eq_uptr(1, (uintptr_t) p % 128, 0); +} + +/** + * @brief Allocate four bytes with rtems_malloc(). + */ +static void TestsuitesValidationCLibrary_Action_1( void ) +{ + void *p; + + p = rtems_malloc(4); + + /* + * Check that the returned pointer is not NULL. + */ + T_step_not_null(2, p); +} + +/** + * @brief Set an integer variable to one and then to zero with memset(). + */ +static void TestsuitesValidationCLibrary_Action_2( void ) +{ + int d; + + d = 1; + memset(&d, 0, sizeof(d)); + + /* + * Check that the integer variable is equal to zero. + */ + T_step_eq_int(3, d, 0); +} + +/** + * @brief Set a source integer variable to one, set a destination integer + * variable to two, and copy the source to the destination variable through + * memcpy(). + */ +static void TestsuitesValidationCLibrary_Action_3( void ) +{ + int s; + int d; + + s = 1; + d = 2; + memcpy(&d, &s, sizeof(d)); + + /* + * Check that the destination integer variable is equal to one. + */ + T_step_eq_int(4, d, 1); +} + +/** + * @fn void T_case_body_TestsuitesValidationCLibrary( void ) + */ +T_TEST_CASE( TestsuitesValidationCLibrary ) +{ + T_plan( 5 ); + + TestsuitesValidationCLibrary_Action_0(); + TestsuitesValidationCLibrary_Action_1(); + TestsuitesValidationCLibrary_Action_2(); + TestsuitesValidationCLibrary_Action_3(); +} + +/** @} */ + +/** + * @defgroup RTEMSTestCaseTestsuitesValidationClassicBarrier \ + * spec:/testsuites/validation/classic-barrier + * + * @ingroup RTEMSTestSuiteTestsuitesValidationProfile + * + * @brief This test case calls functions of the Barrier Manager which are + * included in the space profile. + * + * This test case performs the following actions: + * + * - Set an object identifier to an invalid value and create an automatic + * release barrier object for one task. + * + * - Check that the barrier creation was successful. + * + * - Set a second object identifier to an invalid value and identify a barrier + * object by its name. + * + * - Check that the barrier identification by name was successful. + * + * - Check that the second identifier is equal to the one returned by the + * barrier creation. + * + * - Set the count of released tasks to one and release the barrier. + * + * - Check that the barrier release was successful. + * + * - Check that the count of released tasks is zero. + * + * - Wait with an infinite timeout for the barrier. + * + * - Check that the barrier wait was successful. + * + * @{ + */ + +/** + * @brief Test context for spec:/testsuites/validation/classic-barrier test + * case. + */ +typedef struct { + rtems_id id; +} TestsuitesValidationClassicBarrier_Context; + +static TestsuitesValidationClassicBarrier_Context + TestsuitesValidationClassicBarrier_Instance; + +static void TestsuitesValidationClassicBarrier_Teardown( + TestsuitesValidationClassicBarrier_Context *ctx +) +{ + T_check_rtems_barriers(T_EVENT_RUN_INITIALIZE_EARLY, T_case_name()); +} + +static void TestsuitesValidationClassicBarrier_Teardown_Wrap( void *arg ) +{ + TestsuitesValidationClassicBarrier_Context *ctx; + + ctx = arg; + TestsuitesValidationClassicBarrier_Teardown( ctx ); +} + +static T_fixture TestsuitesValidationClassicBarrier_Fixture = { + .setup = NULL, + .stop = NULL, + .teardown = TestsuitesValidationClassicBarrier_Teardown_Wrap, + .scope = NULL, + .initial_context = &TestsuitesValidationClassicBarrier_Instance +}; + +static const rtems_name name = rtems_build_name( 'B', 'A', 'R', 'R' ); + +/** + * @brief Set an object identifier to an invalid value and create an automatic + * release barrier object for one task. + */ +static void TestsuitesValidationClassicBarrier_Action_0( + TestsuitesValidationClassicBarrier_Context *ctx +) +{ + rtems_status_code sc; + + ctx->id = 0xffffffff; + sc = rtems_barrier_create( + name, + RTEMS_BARRIER_AUTOMATIC_RELEASE, + 1, + &ctx->id + ); + + /* + * Check that the barrier creation was successful. + */ + T_step_rsc_success(0, sc); +} + +/** + * @brief Set a second object identifier to an invalid value and identify a + * barrier object by its name. + */ +static void TestsuitesValidationClassicBarrier_Action_1( + TestsuitesValidationClassicBarrier_Context *ctx +) +{ + rtems_status_code sc; + rtems_id id; + + id = 0xffffffff; + sc = rtems_barrier_ident(name, &id); + + /* + * Check that the barrier identification by name was successful. + */ + T_step_rsc_success(1, sc); + + /* + * Check that the second identifier is equal to the one returned by the + * barrier creation. + */ + T_step_eq_u32(2, id, ctx->id); +} + +/** + * @brief Set the count of released tasks to one and release the barrier. + */ +static void TestsuitesValidationClassicBarrier_Action_2( + TestsuitesValidationClassicBarrier_Context *ctx +) +{ + rtems_status_code sc; + uint32_t released; + + released = 1; + sc = rtems_barrier_release(ctx->id, &released); + + /* + * Check that the barrier release was successful. + */ + T_step_rsc_success(3, sc); + + /* + * Check that the count of released tasks is zero. + */ + T_step_eq_u32(4, released, 0); +} + +/** + * @brief Wait with an infinite timeout for the barrier. + */ +static void TestsuitesValidationClassicBarrier_Action_3( + TestsuitesValidationClassicBarrier_Context *ctx +) +{ + rtems_status_code sc; + + sc = rtems_barrier_wait(ctx->id, RTEMS_NO_TIMEOUT); + + /* + * Check that the barrier wait was successful. + */ + T_step_rsc_success(5, sc); +} + +/** + * @fn void T_case_body_TestsuitesValidationClassicBarrier( void ) + */ +T_TEST_CASE_FIXTURE( + TestsuitesValidationClassicBarrier, + &TestsuitesValidationClassicBarrier_Fixture +) +{ + TestsuitesValidationClassicBarrier_Context *ctx; + + ctx = T_fixture_context(); + + T_plan( 6 ); + + TestsuitesValidationClassicBarrier_Action_0( ctx ); + TestsuitesValidationClassicBarrier_Action_1( ctx ); + TestsuitesValidationClassicBarrier_Action_2( ctx ); + TestsuitesValidationClassicBarrier_Action_3( ctx ); +} + +/** @} */ diff --git a/testsuites/validation/ts-space-profile.c b/testsuites/validation/ts-space-profile.c new file mode 100644 index 0000000000..7b35042ad2 --- /dev/null +++ b/testsuites/validation/ts-space-profile.c @@ -0,0 +1,225 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestSuiteTestsuitesValidationProfile + */ + +/* + * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) + * + * 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. + * + * 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 OWNER 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. + */ + +/* + * This file is part of the RTEMS quality process and was automatically + * generated. If you find something that needs to be fixed or + * worded better please post a report or patch to an RTEMS mailing list + * or raise a bug report: + * + * https://www.rtems.org/bugs.html + * + * For information on updating and regenerating please refer to the How-To + * section in the Software Requirements Engineering chapter of the + * RTEMS Software Engineering manual. The manual is provided as a part of + * a release. For development sources please refer to the online + * documentation at: + * + * https://docs.rtems.org + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +#include + +/** + * @defgroup RTEMSTestSuiteTestsuitesValidationProfile \ + * spec:/testsuites/validation/profile + * + * @ingroup RTEMSTestSuites + * + * @brief This test suite contains test cases which call in combination all + * functions included in the space profile. + * + * @{ + */ + +#define NAME rtems_build_name('N', 'A', 'M', 'E') + +static void fatal_extension( + rtems_fatal_source source, + bool always_set_to_false, + rtems_fatal_code error +) +{ + T_make_runner(); + T_step_eq_int(0, source, RTEMS_FATAL_SOURCE_APPLICATION); + T_step_false(1, always_set_to_false, "always_set_to_false"); + T_step_eq_ulong(2, error, 123); + T_case_end(); + T_run_finalize(); +} + +static void Init(rtems_task_argument arg) +{ + (void) arg; + + T_make_runner(); + T_register(); + T_run_all(); + T_case_begin("SpaceProfileFatalError", NULL); + T_plan(3); + rtems_fatal(RTEMS_FATAL_SOURCE_APPLICATION, 123); +} + +#define INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES + +#define MAX_TLS_SIZE RTEMS_ALIGN_UP(64, RTEMS_TASK_STORAGE_ALIGNMENT) + +RTEMS_ALIGNED(RTEMS_TASK_STORAGE_ALIGNMENT) static char init_task_storage[ + RTEMS_TASK_STORAGE_SIZE( + MAX_TLS_SIZE + RTEMS_MINIMUM_STACK_SIZE, + INIT_TASK_ATTRIBUTES + ) +]; + +static char buffer[512]; + +static void check_task_context(T_event event, const char *name) +{ + if (_System_state_Is_up(_System_state_Get())) { + T_check_task_context(event, name); + } +} + +static const T_action actions[] = { + T_report_hash_sha256, + check_task_context, + T_check_rtems_barriers, + T_check_rtems_extensions, + T_check_rtems_message_queues, + T_check_rtems_partitions, + T_check_rtems_periods, + T_check_rtems_semaphores, + T_check_rtems_tasks, + T_check_rtems_timers +}; + +static const T_config test_config = { + .name = "SpaceProfile", + .buf = buffer, + .buf_size = sizeof(buffer), + .putchar = rtems_put_char, + .verbosity = T_VERBOSE, + .now = T_now_clock, + .action_count = T_ARRAY_SIZE(actions), + .actions = actions +}; + +static const rtems_task_config task_config = { + .name = NAME, + .initial_priority = 1, + .storage_area = init_task_storage, + .storage_size = sizeof(init_task_storage), + .maximum_thread_local_storage_size = MAX_TLS_SIZE, + .initial_modes = RTEMS_DEFAULT_MODES, + .attributes = INIT_TASK_ATTRIBUTES +}; + +static void init_task(void) +{ + rtems_id id; + rtems_status_code sc; + + T_run_initialize(&test_config); + T_case_begin("SpaceProfileTaskBuild", NULL); + T_plan(2); + + sc = rtems_task_construct(&task_config, &id); + T_step_rsc_success(0, sc); + + sc = rtems_task_start(id, Init, 0); + T_step_rsc_success(1, sc); + + T_check_rtems_tasks(T_EVENT_RUN_INITIALIZE_EARLY, T_case_name()); + T_case_end(); +} + +RTEMS_SYSINIT_ITEM( + init_task, + RTEMS_SYSINIT_CLASSIC_USER_TASKS, + RTEMS_SYSINIT_ORDER_MIDDLE +); + +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_MAXIMUM_PROCESSORS 4 + +#define CONFIGURE_MAXIMUM_BARRIERS 1 + +#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1 + +#define CONFIGURE_MAXIMUM_PARTITIONS 1 + +#define CONFIGURE_MAXIMUM_PERIODS 1 + +#define CONFIGURE_MAXIMUM_SEMAPHORES 1 + +#define CONFIGURE_MAXIMUM_TASKS 1 + +#define CONFIGURE_MAXIMUM_TIMERS 1 + +#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 + +#define CONFIGURE_MESSAGE_BUFFER_MEMORY 1 + +#define CONFIGURE_MICROSECONDS_PER_TICK 10000 + +#define CONFIGURE_SCHEDULER_NAME NAME + +#define CONFIGURE_INITIAL_EXTENSIONS { .fatal = fatal_extension } + +/* Mandatory for space profile */ + +#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 0 + +#define CONFIGURE_DISABLE_NEWLIB_REENTRANCY + +#define CONFIGURE_APPLICATION_DISABLE_FILESYSTEM + +#define CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION + +#define CONFIGURE_IDLE_TASK_BODY _CPU_Thread_Idle_body + +#define CONFIGURE_INIT + +#include + +/** @} */ -- cgit v1.2.3