summaryrefslogtreecommitdiffstats
path: root/testsuites/libtests
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-07-17 19:42:32 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-07-23 09:27:47 +0200
commitcc3fd8fcf182cfa35388fc79c14e784a968570ae (patch)
treeb1d2c4cb445837ad51f48a84d893ed05f3d4a4fa /testsuites/libtests
parentlibtest: Add rtems_test_run() (diff)
downloadrtems-cc3fd8fcf182cfa35388fc79c14e784a968570ae.tar.bz2
libtest: Add T_interrupt_test()
Update #3199.
Diffstat (limited to 'testsuites/libtests')
-rw-r--r--testsuites/libtests/Makefile.am9
-rw-r--r--testsuites/libtests/configure.ac1
-rw-r--r--testsuites/libtests/ttest02/init.c174
-rw-r--r--testsuites/libtests/ttest02/ttest02.doc11
-rw-r--r--testsuites/libtests/ttest02/ttest02.scn37
5 files changed, 232 insertions, 0 deletions
diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am
index c312f14324..2ff05f2b74 100644
--- a/testsuites/libtests/Makefile.am
+++ b/testsuites/libtests/Makefile.am
@@ -1493,6 +1493,15 @@ ttest01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_ttest01) \
$(support_includes)
endif
+if TEST_ttest02
+lib_tests += ttest02
+lib_screens += ttest02/ttest02.scn
+lib_docs += ttest02/ttest02.doc
+ttest02_SOURCES = ttest02/init.c
+ttest02_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_ttest02) \
+ $(support_includes)
+endif
+
if TEST_tztest
lib_tests += tztest
lib_screens += tztest/tztest.scn
diff --git a/testsuites/libtests/configure.ac b/testsuites/libtests/configure.ac
index 3b5462600d..2fbcb61622 100644
--- a/testsuites/libtests/configure.ac
+++ b/testsuites/libtests/configure.ac
@@ -225,6 +225,7 @@ RTEMS_TEST_CHECK([termios10])
RTEMS_TEST_CHECK([termios11])
RTEMS_TEST_CHECK([top])
RTEMS_TEST_CHECK([ttest01])
+RTEMS_TEST_CHECK([ttest02])
RTEMS_TEST_CHECK([tztest])
RTEMS_TEST_CHECK([uid01])
RTEMS_TEST_CHECK([unlink])
diff --git a/testsuites/libtests/ttest02/init.c b/testsuites/libtests/ttest02/init.c
new file mode 100644
index 0000000000..0f907e15ec
--- /dev/null
+++ b/testsuites/libtests/ttest02/init.c
@@ -0,0 +1,174 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/test.h>
+#include <rtems/test-info.h>
+
+#include <rtems.h>
+
+static void
+prepare(void *arg)
+{
+ Atomic_Uint *state;
+
+ state = arg;
+ _Atomic_Store_uint(state, 0, ATOMIC_ORDER_RELAXED);
+}
+
+static void
+action(void *arg)
+{
+ Atomic_Uint *state;
+ unsigned int expected;
+ bool success_0;
+ bool success_1;
+
+ state = arg;
+
+ /*
+ * This code models a critical section in the operating system. The
+ * interrupt should happen between the two atomic operations.
+ */
+ expected = 0;
+ success_0 = _Atomic_Compare_exchange_uint(state, &expected, 1,
+ ATOMIC_ORDER_RELAXED, ATOMIC_ORDER_RELAXED);
+ expected = 1;
+ success_1 = _Atomic_Compare_exchange_uint(state, &expected, 2,
+ ATOMIC_ORDER_RELAXED, ATOMIC_ORDER_RELAXED);
+ T_quiet_true(success_0);
+ T_quiet_true(success_1);
+
+ T_interrupt_test_busy_wait_for_interrupt();
+}
+
+static T_interrupt_test_state
+interrupt(void *arg)
+{
+ Atomic_Uint *state;
+ unsigned int expected;
+
+ if (T_interrupt_test_get_state() != T_INTERRUPT_TEST_ACTION) {
+ return T_INTERRUPT_TEST_CONTINUE;
+ }
+
+ state = arg;
+ expected = 1;
+
+ if (_Atomic_Compare_exchange_uint(state, &expected, expected,
+ ATOMIC_ORDER_RELAXED, ATOMIC_ORDER_RELAXED)) {
+ return T_INTERRUPT_TEST_DONE;
+ } else if (expected == 0) {
+ return T_INTERRUPT_TEST_EARLY;
+ } else {
+ T_quiet_eq_uint(expected, 2);
+ return T_INTERRUPT_TEST_LATE;
+ }
+}
+
+static const T_interrupt_test_config done_config = {
+ .prepare = prepare,
+ .action = action,
+ .interrupt = interrupt,
+ .max_iteration_count = 10000
+};
+
+T_TEST_CASE(TestInterruptDone)
+{
+ int i;
+
+ for (i = 0; i < 10; ++i) {
+ Atomic_Uint action_state;
+ T_interrupt_test_state state;
+
+ state = T_interrupt_test(&done_config, &action_state);
+ T_eq_int(state, T_INTERRUPT_TEST_DONE);
+ }
+}
+
+static const T_interrupt_test_config timeout_config = {
+ .interrupt = interrupt,
+ .action = action
+};
+
+T_TEST_CASE(TestInterruptTimeout)
+{
+ Atomic_Uint action_state;
+ T_interrupt_test_state state;
+
+ T_plan(1);
+ state = T_interrupt_test(&timeout_config, &action_state);
+ T_step_eq_int(0, state, T_INTERRUPT_TEST_TIMEOUT);
+}
+
+static void
+fatal(void *arg)
+{
+ (void)arg;
+ T_step(0);
+ T_stop();
+}
+
+static const T_interrupt_test_config fatal_config = {
+ .prepare = fatal,
+ .action = action,
+ .interrupt = interrupt,
+ .max_iteration_count = 10000
+};
+
+T_TEST_CASE(TestInterruptFatal)
+{
+ Atomic_Uint action_state;
+
+ T_plan(1);
+ T_interrupt_test(&fatal_config, &action_state);
+ T_unreachable();
+}
+
+const char rtems_test_name[] = "TTEST 2";
+
+static void
+Init(rtems_task_argument argument)
+{
+ rtems_test_run(argument, TEST_STATE);
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
+
+#define CONFIGURE_MICROSECONDS_PER_TICK 1000
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/libtests/ttest02/ttest02.doc b/testsuites/libtests/ttest02/ttest02.doc
new file mode 100644
index 0000000000..193f288d71
--- /dev/null
+++ b/testsuites/libtests/ttest02/ttest02.doc
@@ -0,0 +1,11 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name: ttest02
+
+directives:
+
+ - T_interrupt_test()
+
+concepts:
+
+ - Ensure that the interrupt test works.
diff --git a/testsuites/libtests/ttest02/ttest02.scn b/testsuites/libtests/ttest02/ttest02.scn
new file mode 100644
index 0000000000..7ff2fac704
--- /dev/null
+++ b/testsuites/libtests/ttest02/ttest02.scn
@@ -0,0 +1,37 @@
+*** BEGIN OF TEST TTEST 2 ***
+*** TEST VERSION: 6.0.0.133fcd71c16b87b5c3924c04039a125be9affcfa
+*** TEST STATE: EXPECTED_PASS
+*** TEST BUILD: RTEMS_SMP
+*** TEST TOOLS: 10.0.1 20200406 (RTEMS 6, RSB b69f54d51740810dc54a50662f5da4d4ba0ddd18, Newlib ece49e4)
+A:TTEST 2
+S:Platform:RTEMS
+S:Compiler:10.0.1 20200406 (RTEMS 6, RSB b69f54d51740810dc54a50662f5da4d4ba0ddd18, Newlib ece49e4)
+S:Version:6.0.0.133fcd71c16b87b5c3924c04039a125be9affcfa
+S:BSP:leon3
+S:RTEMS_DEBUG:0
+S:RTEMS_MULTIPROCESSING:0
+S:RTEMS_POSIX_API:0
+S:RTEMS_PROFILING:0
+S:RTEMS_SMP:1
+B:TestInterruptTimeout
+P:0:0:UI1:init.c:130
+E:TestInterruptTimeout:N:1:F:0:D:0.042180
+B:TestInterruptFatal
+P:0:0:UI1:init.c:137
+E:TestInterruptFatal:N:1:F:0:D:0.000360
+B:TestInterruptDone
+P:0:0:UI1:init.c:114
+P:1:0:UI1:init.c:114
+P:2:0:UI1:init.c:114
+P:3:0:UI1:init.c:114
+P:4:0:UI1:init.c:114
+P:5:0:UI1:init.c:114
+P:6:0:UI1:init.c:114
+P:7:0:UI1:init.c:114
+P:8:0:UI1:init.c:114
+P:9:0:UI1:init.c:114
+E:TestInterruptDone:N:10:F:0:D:1.233900
+Z:TTEST 2:C:3:N:12:F:0:D:1.277400
+Y:ReportHash:SHA256:308c997b3220d239738a11dac4133d9f987a34b3f5f9baf1158d1a54f85cc647
+
+*** END OF TEST TTEST 2 ***