summaryrefslogtreecommitdiffstats
path: root/testsuites/libtests
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-08-07 20:30:39 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-08-11 08:03:47 +0200
commitc1354f05149a9290d61ff9acf39129df46d5eac5 (patch)
tree9d39aa0f455d86f5aa1b2b2f66f616f08c3038d7 /testsuites/libtests
parentlibtest: Constify (diff)
downloadrtems-c1354f05149a9290d61ff9acf39129df46d5eac5.tar.bz2
libtest: Add T_thread_switch_record()
Add support to record thread switch events. This can be used to check that a blocking operation results in the expected sequence of thread switches. Update #3199.
Diffstat (limited to 'testsuites/libtests')
-rw-r--r--testsuites/libtests/ttest02/init.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/testsuites/libtests/ttest02/init.c b/testsuites/libtests/ttest02/init.c
index 78c874faf7..846a778536 100644
--- a/testsuites/libtests/ttest02/init.c
+++ b/testsuites/libtests/ttest02/init.c
@@ -32,6 +32,8 @@
#include <rtems/test.h>
#include <rtems/test-info.h>
+#include <string.h>
+
#include <rtems.h>
static void
@@ -206,6 +208,70 @@ T_TEST_CASE(TestInterruptBlocked)
T_step_eq_int(2, state, T_INTERRUPT_TEST_DONE);
}
+T_TEST_CASE(TestThreadSwitch)
+{
+ T_thread_switch_log_2 log_2;
+ T_thread_switch_log_4 log_4;
+ T_thread_switch_log_10 log_10;
+ T_thread_switch_log *log;
+ uint32_t executing;
+ uint32_t heir;
+ size_t i;
+
+ memset(&log_2, 0xff, sizeof(log_2));
+ log = T_thread_switch_record_2(&log_2);
+ T_null(log);
+ T_eq_sz(log_2.log.recorded, 0);
+ T_eq_sz(log_2.log.capacity, 2);
+ T_eq_u64(log_2.log.switches, 0);
+
+ memset(&log_4, 0xff, sizeof(log_4));
+ log = T_thread_switch_record_4(&log_4);
+ T_eq_ptr(log, &log_2.log);
+ T_eq_sz(log_4.log.recorded, 0);
+ T_eq_sz(log_4.log.capacity, 4);
+ T_eq_u64(log_4.log.switches, 0);
+
+ memset(&log_10, 0xff, sizeof(log_10));
+ log = T_thread_switch_record_10(&log_10);
+ T_eq_ptr(log, &log_4.log);
+ T_eq_sz(log_10.log.recorded, 0);
+ T_eq_sz(log_10.log.capacity, 10);
+ T_eq_u64(log_10.log.switches, 0);
+
+ for (i = 0; i < 6; ++i) {
+ rtems_status_code sc;
+
+ sc = rtems_task_wake_after(2);
+ T_rsc_success(sc);
+ }
+
+ log = T_thread_switch_record(NULL);
+ T_eq_ptr(log, &log_10.log);
+ T_eq_sz(log->recorded, 10);
+ T_eq_sz(log->capacity, 10);
+ T_eq_u64(log->switches, 12);
+ executing = rtems_task_self();
+ T_eq_u32(log->events[0].executing, executing);
+ T_ne_u32(log->events[0].heir, 0);
+ heir = log->events[0].heir;
+ T_eq_u32(log->events[0].cpu, 0);
+ T_ne_u64(log->events[0].instant, 0);
+
+ for (i = 1; i < 10; ++i) {
+ uint32_t tmp;
+
+ tmp = executing;
+ executing = heir;
+ heir = tmp;
+
+ T_eq_u32(log->events[i].executing, executing);
+ T_eq_u32(log->events[i].heir, heir);
+ T_eq_u32(log->events[i].cpu, 0);
+ T_gt_u64(log->events[i].instant, log->events[i - 1].instant);
+ }
+}
+
const char rtems_test_name[] = "TTEST 2";
static void