summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-05-18 18:38:27 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-07-12 15:09:25 +0200
commitc404de4474e4f913597f8dd2dbd6ce0d64cdac4c (patch)
tree5776c52c496f085c32b1786de778ec2d7645520a
parent5346204f8b161399d6efe8d44606eb5e71ef8205 (diff)
validation: Test rtems_task_wake_after()
-rw-r--r--spec/build/testsuites/validation/validation-2.yml1
-rw-r--r--testsuites/validation/tc-task-wake-after.c451
2 files changed, 452 insertions, 0 deletions
diff --git a/spec/build/testsuites/validation/validation-2.yml b/spec/build/testsuites/validation/validation-2.yml
index 755c6cfd64..035edf6792 100644
--- a/spec/build/testsuites/validation/validation-2.yml
+++ b/spec/build/testsuites/validation/validation-2.yml
@@ -12,6 +12,7 @@ ldflags: []
links: []
source:
- testsuites/validation/tc-clock-nanosleep.c
+- testsuites/validation/tc-task-wake-after.c
- testsuites/validation/tc-timer-cancel.c
- testsuites/validation/tc-timer-fire-after.c
- testsuites/validation/tc-timer-fire-when.c
diff --git a/testsuites/validation/tc-task-wake-after.c b/testsuites/validation/tc-task-wake-after.c
new file mode 100644
index 0000000000..7eed2bbdab
--- /dev/null
+++ b/testsuites/validation/tc-task-wake-after.c
@@ -0,0 +1,451 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup RTEMSTestCaseRtemsTaskReqWakeAfter
+ */
+
+/*
+ * Copyright (C) 2021 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 <rtems.h>
+#include <rtems/test-scheduler.h>
+#include <rtems/score/timecounter.h>
+
+#include "tx-support.h"
+
+#include <rtems/test.h>
+
+/**
+ * @defgroup RTEMSTestCaseRtemsTaskReqWakeAfter spec:/rtems/task/req/wake-after
+ *
+ * @ingroup RTEMSTestSuiteTestsuitesValidation2
+ *
+ * @{
+ */
+
+typedef enum {
+ RtemsTaskReqWakeAfter_Pre_Ticks_Yield,
+ RtemsTaskReqWakeAfter_Pre_Ticks_Interval,
+ RtemsTaskReqWakeAfter_Pre_Ticks_NA
+} RtemsTaskReqWakeAfter_Pre_Ticks;
+
+typedef enum {
+ RtemsTaskReqWakeAfter_Post_Status_Ok,
+ RtemsTaskReqWakeAfter_Post_Status_NA
+} RtemsTaskReqWakeAfter_Post_Status;
+
+typedef enum {
+ RtemsTaskReqWakeAfter_Post_Timer_Inactive,
+ RtemsTaskReqWakeAfter_Post_Timer_Ticks,
+ RtemsTaskReqWakeAfter_Post_Timer_NA
+} RtemsTaskReqWakeAfter_Post_Timer;
+
+typedef enum {
+ RtemsTaskReqWakeAfter_Post_Expire_Relative,
+ RtemsTaskReqWakeAfter_Post_Expire_NA
+} RtemsTaskReqWakeAfter_Post_Expire;
+
+typedef enum {
+ RtemsTaskReqWakeAfter_Post_Scheduler_Block,
+ RtemsTaskReqWakeAfter_Post_Scheduler_Yield,
+ RtemsTaskReqWakeAfter_Post_Scheduler_NA
+} RtemsTaskReqWakeAfter_Post_Scheduler;
+
+/**
+ * @brief Test context for spec:/rtems/task/req/wake-after test case.
+ */
+typedef struct {
+ /**
+ * @brief This member provides the scheduler operation records.
+ */
+ T_scheduler_log_4 scheduler_log;;
+
+ /**
+ * @brief This member contains the clock tick value before the
+ * rtems_task_wake_after() call.
+ */
+ uint64_t now;;
+
+ /**
+ * @brief This member contains the worker task identifier.
+ */
+ rtems_id worker_id;;
+
+ /**
+ * @brief This member contains the timer information of the worker task.
+ */
+ TaskTimerInfo timer_info;;
+
+ /**
+ * @brief This member contains the return value of the
+ * rtems_task_wake_after() call.
+ */
+ rtems_status_code status;
+
+ /**
+ * @brief This member specifies the ``ticks`` parameter value.
+ */
+ rtems_interval ticks;
+
+ /**
+ * @brief This member defines the pre-condition states for the next action.
+ */
+ size_t pcs[ 1 ];
+
+ /**
+ * @brief This member indicates if the test action loop is currently
+ * executed.
+ */
+ bool in_action_loop;
+} RtemsTaskReqWakeAfter_Context;
+
+static RtemsTaskReqWakeAfter_Context
+ RtemsTaskReqWakeAfter_Instance;
+
+static const char * const RtemsTaskReqWakeAfter_PreDesc_Ticks[] = {
+ "Yield",
+ "Interval",
+ "NA"
+};
+
+static const char * const * const RtemsTaskReqWakeAfter_PreDesc[] = {
+ RtemsTaskReqWakeAfter_PreDesc_Ticks,
+ NULL
+};
+
+typedef RtemsTaskReqWakeAfter_Context Context;
+
+static void Worker( rtems_task_argument arg )
+{
+ Context *ctx;
+
+ ctx = (Context *) arg;
+
+ while ( true ) {
+ T_scheduler_log *log;
+
+ SuspendSelf();
+
+ log = T_scheduler_record_4( &ctx->scheduler_log );
+ T_null( log );
+
+ ctx->now = rtems_clock_get_ticks_since_boot();
+
+ ctx->status = rtems_task_wake_after( ctx->ticks );
+
+ (void) T_scheduler_record( NULL );
+ }
+}
+
+static void RtemsTaskReqWakeAfter_Pre_Ticks_Prepare(
+ RtemsTaskReqWakeAfter_Context *ctx,
+ RtemsTaskReqWakeAfter_Pre_Ticks state
+)
+{
+ switch ( state ) {
+ case RtemsTaskReqWakeAfter_Pre_Ticks_Yield: {
+ /*
+ * While the ``ticks`` parameter is equal to RTEMS_YIELD_PROCESSOR.
+ */
+ ctx->ticks = RTEMS_YIELD_PROCESSOR;
+ break;
+ }
+
+ case RtemsTaskReqWakeAfter_Pre_Ticks_Interval: {
+ /*
+ * While the ``ticks`` parameter is not equal to RTEMS_YIELD_PROCESSOR.
+ */
+ ctx->ticks = UINT32_MAX;
+ break;
+ }
+
+ case RtemsTaskReqWakeAfter_Pre_Ticks_NA:
+ break;
+ }
+}
+
+static void RtemsTaskReqWakeAfter_Post_Status_Check(
+ RtemsTaskReqWakeAfter_Context *ctx,
+ RtemsTaskReqWakeAfter_Post_Status state
+)
+{
+ switch ( state ) {
+ case RtemsTaskReqWakeAfter_Post_Status_Ok: {
+ /*
+ * The return status of rtems_task_wake_after() shall be
+ * RTEMS_SUCCESSFUL.
+ */
+ T_rsc_success( ctx->status );
+ break;
+ }
+
+ case RtemsTaskReqWakeAfter_Post_Status_NA:
+ break;
+ }
+}
+
+static void RtemsTaskReqWakeAfter_Post_Timer_Check(
+ RtemsTaskReqWakeAfter_Context *ctx,
+ RtemsTaskReqWakeAfter_Post_Timer state
+)
+{
+ switch ( state ) {
+ case RtemsTaskReqWakeAfter_Post_Timer_Inactive: {
+ /*
+ * The timer of the calling task shall be inactive.
+ */
+ T_eq_int( ctx->timer_info.state, TASK_TIMER_INACTIVE );
+ break;
+ }
+
+ case RtemsTaskReqWakeAfter_Post_Timer_Ticks: {
+ /*
+ * The timer of the calling task shall be active using the clock tick.
+ */
+ T_eq_int( ctx->timer_info.state, TASK_TIMER_TICKS );
+ break;
+ }
+
+ case RtemsTaskReqWakeAfter_Post_Timer_NA:
+ break;
+ }
+}
+
+static void RtemsTaskReqWakeAfter_Post_Expire_Check(
+ RtemsTaskReqWakeAfter_Context *ctx,
+ RtemsTaskReqWakeAfter_Post_Expire state
+)
+{
+ switch ( state ) {
+ case RtemsTaskReqWakeAfter_Post_Expire_Relative: {
+ /*
+ * The timer of the calling task shall expire at the time point specified
+ * by the sum of the current clock tick and the interval specified by the
+ * ``ticks`` parameter.
+ */
+ T_eq_u64( ctx->timer_info.expire_ticks, ctx->now + UINT32_MAX );
+ break;
+ }
+
+ case RtemsTaskReqWakeAfter_Post_Expire_NA:
+ break;
+ }
+}
+
+static void RtemsTaskReqWakeAfter_Post_Scheduler_Check(
+ RtemsTaskReqWakeAfter_Context *ctx,
+ RtemsTaskReqWakeAfter_Post_Scheduler state
+)
+{
+ switch ( state ) {
+ case RtemsTaskReqWakeAfter_Post_Scheduler_Block: {
+ /*
+ * The calling task shall be blocked by the scheduler exactly once by the
+ * rtems_task_wake_after() call.
+ */
+ T_eq_sz( ctx->scheduler_log.header.recorded, 1 );
+ T_eq_int(
+ ctx->scheduler_log.events[ 0 ].operation,
+ T_SCHEDULER_BLOCK
+ );
+ break;
+ }
+
+ case RtemsTaskReqWakeAfter_Post_Scheduler_Yield: {
+ /*
+ * The calling task shall yield by the scheduler exactly once by the
+ * rtems_task_wake_after() call.
+ */
+ T_eq_sz( ctx->scheduler_log.header.recorded, 1 );
+ T_eq_int(
+ ctx->scheduler_log.events[ 0 ].operation,
+ T_SCHEDULER_YIELD
+ );
+ break;
+ }
+
+ case RtemsTaskReqWakeAfter_Post_Scheduler_NA:
+ break;
+ }
+}
+
+static void RtemsTaskReqWakeAfter_Setup( RtemsTaskReqWakeAfter_Context *ctx )
+{
+ SetSelfPriority( PRIO_NORMAL );
+ ctx->worker_id = CreateTask( "WORK", PRIO_HIGH );
+ StartTask( ctx->worker_id, Worker, ctx );
+}
+
+static void RtemsTaskReqWakeAfter_Setup_Wrap( void *arg )
+{
+ RtemsTaskReqWakeAfter_Context *ctx;
+
+ ctx = arg;
+ ctx->in_action_loop = false;
+ RtemsTaskReqWakeAfter_Setup( ctx );
+}
+
+static void RtemsTaskReqWakeAfter_Teardown(
+ RtemsTaskReqWakeAfter_Context *ctx
+)
+{
+ DeleteTask( ctx->worker_id );
+ RestoreRunnerPriority();
+}
+
+static void RtemsTaskReqWakeAfter_Teardown_Wrap( void *arg )
+{
+ RtemsTaskReqWakeAfter_Context *ctx;
+
+ ctx = arg;
+ ctx->in_action_loop = false;
+ RtemsTaskReqWakeAfter_Teardown( ctx );
+}
+
+static void RtemsTaskReqWakeAfter_Prepare( RtemsTaskReqWakeAfter_Context *ctx )
+{
+ ctx->status = RTEMS_NOT_IMPLEMENTED;
+}
+
+static void RtemsTaskReqWakeAfter_Action( RtemsTaskReqWakeAfter_Context *ctx )
+{
+ ResumeTask( ctx->worker_id );
+ (void) T_scheduler_record( NULL );
+ GetTaskTimerInfo( ctx->worker_id, &ctx->timer_info );
+ FinalClockTick();
+}
+
+typedef struct {
+ uint8_t Skip : 1;
+ uint8_t Pre_Ticks_NA : 1;
+ uint8_t Post_Status : 1;
+ uint8_t Post_Timer : 2;
+ uint8_t Post_Expire : 1;
+ uint8_t Post_Scheduler : 2;
+} RtemsTaskReqWakeAfter_Entry;
+
+static const RtemsTaskReqWakeAfter_Entry
+RtemsTaskReqWakeAfter_Entries[] = {
+ { 0, 0, RtemsTaskReqWakeAfter_Post_Status_Ok,
+ RtemsTaskReqWakeAfter_Post_Timer_Inactive,
+ RtemsTaskReqWakeAfter_Post_Expire_NA,
+ RtemsTaskReqWakeAfter_Post_Scheduler_Yield },
+ { 0, 0, RtemsTaskReqWakeAfter_Post_Status_Ok,
+ RtemsTaskReqWakeAfter_Post_Timer_Ticks,
+ RtemsTaskReqWakeAfter_Post_Expire_Relative,
+ RtemsTaskReqWakeAfter_Post_Scheduler_Block }
+};
+
+static const uint8_t
+RtemsTaskReqWakeAfter_Map[] = {
+ 0, 1
+};
+
+static size_t RtemsTaskReqWakeAfter_Scope( void *arg, char *buf, size_t n )
+{
+ RtemsTaskReqWakeAfter_Context *ctx;
+
+ ctx = arg;
+
+ if ( ctx->in_action_loop ) {
+ return T_get_scope( RtemsTaskReqWakeAfter_PreDesc, buf, n, ctx->pcs );
+ }
+
+ return 0;
+}
+
+static T_fixture RtemsTaskReqWakeAfter_Fixture = {
+ .setup = RtemsTaskReqWakeAfter_Setup_Wrap,
+ .stop = NULL,
+ .teardown = RtemsTaskReqWakeAfter_Teardown_Wrap,
+ .scope = RtemsTaskReqWakeAfter_Scope,
+ .initial_context = &RtemsTaskReqWakeAfter_Instance
+};
+
+static inline RtemsTaskReqWakeAfter_Entry RtemsTaskReqWakeAfter_GetEntry(
+ size_t index
+)
+{
+ return RtemsTaskReqWakeAfter_Entries[
+ RtemsTaskReqWakeAfter_Map[ index ]
+ ];
+}
+
+/**
+ * @fn void T_case_body_RtemsTaskReqWakeAfter( void )
+ */
+T_TEST_CASE_FIXTURE( RtemsTaskReqWakeAfter, &RtemsTaskReqWakeAfter_Fixture )
+{
+ RtemsTaskReqWakeAfter_Context *ctx;
+ size_t index;
+
+ ctx = T_fixture_context();
+ ctx->in_action_loop = true;
+ index = 0;
+
+ for (
+ ctx->pcs[ 0 ] = RtemsTaskReqWakeAfter_Pre_Ticks_Yield;
+ ctx->pcs[ 0 ] < RtemsTaskReqWakeAfter_Pre_Ticks_NA;
+ ++ctx->pcs[ 0 ]
+ ) {
+ RtemsTaskReqWakeAfter_Entry entry;
+
+ entry = RtemsTaskReqWakeAfter_GetEntry( index );
+ ++index;
+
+ RtemsTaskReqWakeAfter_Prepare( ctx );
+ RtemsTaskReqWakeAfter_Pre_Ticks_Prepare( ctx, ctx->pcs[ 0 ] );
+ RtemsTaskReqWakeAfter_Action( ctx );
+ RtemsTaskReqWakeAfter_Post_Status_Check( ctx, entry.Post_Status );
+ RtemsTaskReqWakeAfter_Post_Timer_Check( ctx, entry.Post_Timer );
+ RtemsTaskReqWakeAfter_Post_Expire_Check( ctx, entry.Post_Expire );
+ RtemsTaskReqWakeAfter_Post_Scheduler_Check( ctx, entry.Post_Scheduler );
+ }
+}
+
+/** @} */