summaryrefslogtreecommitdiff
path: root/testsuites/validation/tc-task.c
diff options
context:
space:
mode:
Diffstat (limited to 'testsuites/validation/tc-task.c')
-rw-r--r--testsuites/validation/tc-task.c207
1 files changed, 207 insertions, 0 deletions
diff --git a/testsuites/validation/tc-task.c b/testsuites/validation/tc-task.c
new file mode 100644
index 0000000000..40fc309b6c
--- /dev/null
+++ b/testsuites/validation/tc-task.c
@@ -0,0 +1,207 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup RTEMSTestCaseRtemsTaskValTask
+ */
+
+/*
+ * 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 <string.h>
+#include <rtems/score/apimutex.h>
+
+#include <rtems/test.h>
+
+/**
+ * @defgroup RTEMSTestCaseRtemsTaskValTask spec:/rtems/task/val/task
+ *
+ * @ingroup RTEMSTestSuiteTestsuitesValidation0
+ *
+ * @brief This test case collection provides validation test cases for
+ * requirements of the @ref RTEMSAPIClassicTasks.
+ *
+ * This test case performs the following actions:
+ *
+ * - Call rtems_task_self() check the returned value.
+ *
+ * - Check that the returned value is equal to the object identifier of the
+ * calling task.
+ *
+ * - Call rtems_task_iterate() with a visitor which always returns false.
+ *
+ * - Check that the all counter is equal to the count of tasks. Check that
+ * the calling task was visited exacly once. Firstly, this shows that
+ * rtems_task_iterate() used the parameters specified by ``visitor`` and
+ * ``arg``. Secondly, this shows that the iteration was done over all
+ * tasks.
+ *
+ * - Check that the object alloctor mutex was not owned before and after the
+ * call. Check that the object alloctor mutex was owned during the
+ * iteration.
+ *
+ * - Call rtems_task_iterate() with a visitor which returns true.
+ *
+ * - Check that the all counter is equal to one. This shows that the
+ * iteration stops when the visitor returns true.
+ *
+ * @{
+ */
+
+typedef struct {
+ bool owner_before;
+ bool owner_in_visitor;
+ bool owner_after;
+ uint32_t counter_all;
+ uint32_t counter_self;
+ bool done;
+} TaskIterateContext;
+
+static bool TaskVisitor( rtems_tcb *tcb, void *arg )
+{
+ TaskIterateContext *ctx;
+
+ ctx = arg;
+ ++ctx->counter_all;
+
+ if ( rtems_task_self() == tcb->Object.id ) {
+ ++ctx->counter_self;
+ }
+
+ ctx->owner_in_visitor = _RTEMS_Allocator_is_owner();
+
+ return ctx->done;
+}
+
+/**
+ * @brief Call rtems_task_self() check the returned value.
+ */
+static void RtemsTaskValTask_Action_0( void )
+{
+ rtems_id id;
+
+ id = rtems_task_self();
+
+ /*
+ * Check that the returned value is equal to the object identifier of the
+ * calling task.
+ */
+ T_step_eq_u32( 0, id, 0x0a010001 );
+}
+
+/**
+ * @brief Call rtems_task_iterate() with a visitor which always returns false.
+ */
+static void RtemsTaskValTask_Action_1( void )
+{
+ TaskIterateContext ctx;
+ uint32_t task_count;
+
+ task_count = rtems_scheduler_get_processor_maximum();
+
+ if ( task_count > 4 ) {
+ task_count = 4;
+ }
+
+ ++task_count;
+
+ memset( &ctx, 0, sizeof( ctx ) );
+ ctx.owner_before = _RTEMS_Allocator_is_owner();
+ rtems_task_iterate( TaskVisitor, &ctx );
+ ctx.owner_after = _RTEMS_Allocator_is_owner();
+
+ /*
+ * Check that the all counter is equal to the count of tasks. Check that the
+ * calling task was visited exacly once. Firstly, this shows that
+ * rtems_task_iterate() used the parameters specified by ``visitor`` and
+ * ``arg``. Secondly, this shows that the iteration was done over all tasks.
+ */
+ T_step_eq_u32( 1, ctx.counter_all, task_count );
+ T_step_eq_u32( 2, ctx.counter_self, 1 );
+
+ /*
+ * Check that the object alloctor mutex was not owned before and after the
+ * call. Check that the object alloctor mutex was owned during the
+ * iteration.
+ */
+ T_step_false( 3, ctx.owner_before );
+ T_step_true( 4, ctx.owner_in_visitor );
+ T_step_false( 5, ctx.owner_after );
+}
+
+/**
+ * @brief Call rtems_task_iterate() with a visitor which returns true.
+ */
+static void RtemsTaskValTask_Action_2( void )
+{
+ TaskIterateContext ctx;
+
+ memset( &ctx, 0, sizeof( ctx ) );
+ ctx.done = true;
+ rtems_task_iterate( TaskVisitor, &ctx );
+
+ /*
+ * Check that the all counter is equal to one. This shows that the iteration
+ * stops when the visitor returns true.
+ */
+ T_step_eq_u32( 6, ctx.counter_all, 1 );
+}
+
+/**
+ * @fn void T_case_body_RtemsTaskValTask( void )
+ */
+T_TEST_CASE( RtemsTaskValTask )
+{
+ T_plan( 7 );
+
+ RtemsTaskValTask_Action_0();
+ RtemsTaskValTask_Action_1();
+ RtemsTaskValTask_Action_2();
+}
+
+/** @} */