summaryrefslogtreecommitdiffstats
path: root/testsuites
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-04-28 11:36:11 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2019-01-29 13:51:33 +0100
commitdca618404ee61c1be8a883ddb679889dbfea284b (patch)
tree49a61cb40d4fcce31c1c84b7f83737a4852630a0 /testsuites
parentm68k: Avoid _Addresses_Add_offset() (diff)
downloadrtems-dca618404ee61c1be8a883ddb679889dbfea284b.tar.bz2
Add low level event recording support
Add low level event recording infrastructure for system and user defined events. The infrastructure is able to record high frequency events such as * SMP lock acquire/release, * interrupt entry/exit, * thread switches, * UMA zone allocate/free, and * Ethernet packet input/output, etc. It allows post-mortem analysis in fatal error handlers, e.g. the last events are in the record buffer, the newest event overwrites the oldest event. It is possible to detect record buffer overflows for consumers that expect a continuous stream of events, e.g. to display the system state in real-time. The implementation supports high-end SMP machines (more than 1GHz processor frequency, more than four processors). Add a new API instead. The implementation uses per-processor data structures and no atomic read-modify-write operations. It is uses per-processor ring buffers to record the events. The CPU counter is used to get the time of events. It is combined with periodic uptime events to synchronize it with CLOCK_REALTIME. The existing capture engine tries to solve this problem also, but its performance is not good enough for high-end production systems. The main issues are the variable-size buffers and the use of SMP locks for synchronization. To fix this, the API would change significantly. Update #3665.
Diffstat (limited to 'testsuites')
-rw-r--r--testsuites/libtests/Makefile.am18
-rw-r--r--testsuites/libtests/configure.ac2
-rw-r--r--testsuites/libtests/record01/init.c714
-rw-r--r--testsuites/libtests/record01/record01.doc15
-rw-r--r--testsuites/libtests/record01/record01.scn7
-rw-r--r--testsuites/libtests/record02/init.c132
-rw-r--r--testsuites/libtests/record02/record02.doc12
-rw-r--r--testsuites/libtests/record02/record02.scn82
8 files changed, 982 insertions, 0 deletions
diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am
index cb632f8d88..411c12ead1 100644
--- a/testsuites/libtests/Makefile.am
+++ b/testsuites/libtests/Makefile.am
@@ -995,6 +995,24 @@ realloc_norun_SOURCES = POSIX/realloc.c
realloc_norun_LDADD = $(RTEMS_ROOT)cpukit/librtemsdefaultconfig.a $(LDADD)
endif
+if TEST_record01
+lib_tests += record01
+lib_screens += record01/record01.scn
+lib_docs += record01/record01.doc
+record01_SOURCES = record01/init.c
+record01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_record01) \
+ $(support_includes) -I$(RTEMS_SOURCE_ROOT)/cpukit/libnetworking
+endif
+
+if TEST_record02
+lib_tests += record02
+lib_screens += record02/record02.scn
+lib_docs += record02/record02.doc
+record02_SOURCES = record02/init.c
+record02_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_record02) \
+ $(support_includes)
+endif
+
if TEST_rtmonuse
lib_tests += rtmonuse
lib_screens += rtmonuse/rtmonuse.scn
diff --git a/testsuites/libtests/configure.ac b/testsuites/libtests/configure.ac
index a2a0df01f1..c76fb799b4 100644
--- a/testsuites/libtests/configure.ac
+++ b/testsuites/libtests/configure.ac
@@ -189,6 +189,8 @@ RTEMS_TEST_CHECK([rbheap01])
RTEMS_TEST_CHECK([read])
RTEMS_TEST_CHECK([readv])
RTEMS_TEST_CHECK([realloc])
+RTEMS_TEST_CHECK([record01])
+RTEMS_TEST_CHECK([record02])
RTEMS_TEST_CHECK([rtmonuse])
RTEMS_TEST_CHECK([setjmp])
RTEMS_TEST_CHECK([sha])
diff --git a/testsuites/libtests/record01/init.c b/testsuites/libtests/record01/init.c
new file mode 100644
index 0000000000..dbae1cbcc7
--- /dev/null
+++ b/testsuites/libtests/record01/init.c
@@ -0,0 +1,714 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2018, 2019 embedded brains GmbH
+ *
+ * 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/record.h>
+#include <rtems.h>
+
+#include <sys/endian.h>
+#include <sys/socket.h>
+
+#include <string.h>
+#include <unistd.h>
+
+#include <netinet/in.h>
+
+#ifdef RTEMS_NETWORKING
+#include <rtems/rtems_bsdnet.h>
+#endif
+
+#include <tmacros.h>
+
+const char rtems_test_name[] = "RECORD 1";
+
+#define ITEM_COUNT 4
+
+#define ITEM_SIZE (ITEM_COUNT * sizeof(rtems_record_item))
+
+typedef struct {
+ Record_Control control;
+ rtems_record_item items[ITEM_COUNT];
+} test_context;
+
+static test_context test_instance;
+
+const unsigned int _Record_Item_count = ITEM_COUNT;
+
+#define UE(user) (RTEMS_RECORD_USER + (user))
+
+#define TE(t, e) RTEMS_RECORD_TIME_EVENT(t, e)
+
+static const rtems_record_item expected_items_0[ITEM_COUNT] = {
+ { .event = TE(2, UE(1)), .data = 3 }
+};
+
+static const rtems_record_item expected_items_1[ITEM_COUNT] = {
+ { .event = TE(2, UE(1)), .data = 3 },
+ { .event = TE(6, UE(5)), .data = 7 }
+};
+
+static const rtems_record_item expected_items_2[ITEM_COUNT] = {
+ { .event = TE(2, UE(1)), .data = 3 },
+ { .event = TE(6, UE(5)), .data = 7 },
+ { .event = TE(10, UE(9)), .data = 11 }
+};
+
+static const rtems_record_item expected_items_3[ITEM_COUNT] = {
+ { .event = TE(2, UE(1)), .data = 3 },
+ { .event = TE(6, UE(5)), .data = 7 },
+ { .event = TE(10, UE(9)), .data = 11 },
+ { .event = TE(14, UE(13)), .data = 15 }
+};
+
+static const rtems_record_item expected_items_4[ITEM_COUNT] = {
+ { .event = TE(18, UE(17)), .data = 19 },
+ { .event = TE(6, UE(5)), .data = 7 },
+ { .event = TE(10, UE(9)), .data = 11 },
+ { .event = TE(14, UE(13)), .data = 15 }
+};
+
+static const rtems_record_item expected_items_5[ITEM_COUNT] = {
+ { .event = TE(2, UE(1)), .data = 3 }
+};
+
+static const rtems_record_item expected_items_6[ITEM_COUNT] = {
+ { .event = TE(2, UE(1)), .data = 3 },
+ { .event = TE(6, UE(5)), .data = 7 }
+};
+
+static const rtems_record_item expected_items_7[ITEM_COUNT] = {
+ { .event = TE(2, UE(1)), .data = 3 },
+ { .event = TE(6, UE(5)), .data = 7 },
+ { .event = TE(10, UE(9)), .data = 11 }
+};
+
+static const rtems_record_item expected_items_8[] = {
+ { .event = TE(0, RTEMS_RECORD_PROCESSOR), .data = 0 },
+ { .event = TE(0, RTEMS_RECORD_TAIL), .data = 0 },
+ { .event = TE(0, RTEMS_RECORD_HEAD), .data = 3 },
+ { .event = TE(2, UE(1)), .data = 3 },
+ { .event = TE(5, UE(4)), .data = 6 },
+ { .event = TE(8, UE(7)), .data = 9 }
+};
+
+static const rtems_record_item expected_items_9[] = {
+ { .event = TE(0, RTEMS_RECORD_PROCESSOR), .data = 0 },
+ { .event = TE(0, RTEMS_RECORD_TAIL), .data = 3 },
+ { .event = TE(0, RTEMS_RECORD_HEAD), .data = 5 },
+ { .event = TE(11, UE(10)), .data = 12 },
+ { .event = TE(14, UE(13)), .data = 15 }
+};
+
+static const rtems_record_item expected_items_10[] = {
+ { .event = TE(0, RTEMS_RECORD_PROCESSOR), .data = 0 },
+ { .event = TE(0, RTEMS_RECORD_TAIL), .data = 5 },
+ { .event = TE(0, RTEMS_RECORD_HEAD), .data = 8 },
+ { .event = TE(17, UE(16)), .data = 18 },
+ { .event = TE(20, UE(19)), .data = 21 },
+ { .event = TE(23, UE(22)), .data = 24 }
+};
+
+static const rtems_record_item expected_items_11[] = {
+ { .event = TE(0, RTEMS_RECORD_PROCESSOR), .data = 0 },
+ { .event = TE(0, RTEMS_RECORD_TAIL), .data = 8 },
+ { .event = TE(0, RTEMS_RECORD_HEAD), .data = 9 },
+ { .event = TE(26, UE(25)), .data = 27 }
+};
+
+static const rtems_record_item expected_items_12[] = {
+ { .event = TE(0, RTEMS_RECORD_PROCESSOR), .data = 0 },
+ { .event = TE(0, RTEMS_RECORD_TAIL), .data = 9 },
+ { .event = TE(0, RTEMS_RECORD_HEAD), .data = 15 },
+ { .event = TE(38, UE(37)), .data = 39 },
+ { .event = TE(41, UE(40)), .data = 42 },
+ { .event = TE(44, UE(43)), .data = 45 }
+};
+
+static void init_context(test_context *ctx)
+{
+ memset(ctx, 0, sizeof(*ctx));
+ ctx->control.mask = ITEM_COUNT - 1;
+}
+
+static void test_capacity(const Record_Control *control)
+{
+ unsigned int capacity;
+
+ capacity = _Record_Capacity(control, 0, 0);
+ rtems_test_assert(capacity == 3);
+
+ capacity = _Record_Capacity(control, 0, 1);
+ rtems_test_assert(capacity == 2);
+
+ capacity = _Record_Capacity(control, 0, 2);
+ rtems_test_assert(capacity == 1);
+
+ capacity = _Record_Capacity(control, 0, 3);
+ rtems_test_assert(capacity == 0);
+
+ capacity = _Record_Capacity(control, 3, 3);
+ rtems_test_assert(capacity == 3);
+
+ capacity = _Record_Capacity(control, 3, 0);
+ rtems_test_assert(capacity == 2);
+
+ capacity = _Record_Capacity(control, 3, 1);
+ rtems_test_assert(capacity == 1);
+
+ capacity = _Record_Capacity(control, 3, 2);
+ rtems_test_assert(capacity == 0);
+}
+
+static void test_index(const Record_Control *control)
+{
+ unsigned int index;
+
+ index = _Record_Index(control, 0);
+ rtems_test_assert(index == 0);
+
+ index = _Record_Index(control, 1);
+ rtems_test_assert(index == 1);
+
+ index = _Record_Index(control, 2);
+ rtems_test_assert(index == 2);
+
+ index = _Record_Index(control, 3);
+ rtems_test_assert(index == 3);
+
+ index = _Record_Index(control, 4);
+ rtems_test_assert(index == 0);
+}
+
+static void test_add_2_items(test_context *ctx, Record_Control *control)
+{
+ rtems_record_context rc;
+
+ init_context(ctx);
+
+ rtems_record_prepare(&rc);
+ rtems_test_assert(rc.control == control);
+ rtems_test_assert(rc.head == 0);
+ rtems_test_assert(_Record_Head(control) == 0);
+ rtems_test_assert(_Record_Tail(control) == 0);
+
+ rc.now = RTEMS_RECORD_TIME_EVENT(2, 0);
+ rtems_record_add(&rc, UE(1), 3);
+ rtems_test_assert(rc.head == 1);
+ rtems_test_assert(memcmp(control->Items, expected_items_0, ITEM_SIZE) == 0);
+ rtems_test_assert(_Record_Head(control) == 0);
+ rtems_test_assert(_Record_Tail(control) == 0);
+
+ rc.now = RTEMS_RECORD_TIME_EVENT(6, 0);
+ rtems_record_add(&rc, UE(5), 7);
+ rtems_record_commit(&rc);
+ rtems_test_assert(rc.head == 2);
+ rtems_test_assert(memcmp(control->Items, expected_items_1, ITEM_SIZE) == 0);
+ rtems_test_assert(_Record_Head(control) == 2);
+ rtems_test_assert(_Record_Tail(control) == 0);
+}
+
+static void test_add_3_items(test_context *ctx, Record_Control *control)
+{
+ rtems_record_context rc;
+
+ init_context(ctx);
+
+ rtems_record_prepare(&rc);
+ rtems_test_assert(rc.control == control);
+ rtems_test_assert(rc.head == 0);
+ rtems_test_assert(_Record_Head(control) == 0);
+ rtems_test_assert(_Record_Tail(control) == 0);
+
+ rc.now = RTEMS_RECORD_TIME_EVENT(2, 0);
+ rtems_record_add(&rc, UE(1), 3);
+ rtems_test_assert(rc.head == 1);
+ rtems_test_assert(memcmp(control->Items, expected_items_5, ITEM_SIZE) == 0);
+ rtems_test_assert(_Record_Head(control) == 0);
+ rtems_test_assert(_Record_Tail(control) == 0);
+
+ rc.now = RTEMS_RECORD_TIME_EVENT(6, 0);
+ rtems_record_add(&rc, UE(5), 7);
+ rtems_test_assert(rc.head == 2);
+ rtems_test_assert(memcmp(control->Items, expected_items_6, ITEM_SIZE) == 0);
+ rtems_test_assert(_Record_Head(control) == 0);
+ rtems_test_assert(_Record_Tail(control) == 0);
+
+ rc.now = RTEMS_RECORD_TIME_EVENT(10, 0);
+ rtems_record_add(&rc, UE(9), 11);
+ rtems_record_commit(&rc);
+ rtems_test_assert(rc.head == 3);
+ rtems_test_assert(memcmp(control->Items, expected_items_7, ITEM_SIZE) == 0);
+ rtems_test_assert(_Record_Head(control) == 3);
+ rtems_test_assert(_Record_Tail(control) == 0);
+}
+
+static void set_time(rtems_record_item *item, uint32_t time)
+{
+ uint32_t event;
+
+ event = item->event;
+ event &= 0x3ff;
+ event |= time << 10;
+ item->event = event;
+}
+
+static void test_produce(test_context *ctx, Record_Control *control)
+{
+ init_context(ctx);
+
+ rtems_record_produce(UE(1), 3);
+ set_time(&control->Items[0], 2);
+ rtems_test_assert(memcmp(control->Items, expected_items_0, ITEM_SIZE) == 0);
+ rtems_test_assert(_Record_Head(control) == 1);
+ rtems_test_assert(_Record_Tail(control) == 0);
+
+ rtems_record_produce(UE(5), 7);
+ set_time(&control->Items[1], 6);
+ rtems_test_assert(memcmp(control->Items, expected_items_1, ITEM_SIZE) == 0);
+ rtems_test_assert(_Record_Head(control) == 2);
+ rtems_test_assert(_Record_Tail(control) == 0);
+
+ rtems_record_produce(UE(9), 11);
+ set_time(&control->Items[2], 10);
+ rtems_test_assert(memcmp(control->Items, expected_items_2, ITEM_SIZE) == 0);
+ rtems_test_assert(_Record_Head(control) == 3);
+ rtems_test_assert(_Record_Tail(control) == 0);
+
+ rtems_record_produce(UE(13), 15);
+ set_time(&control->Items[3], 14);
+ rtems_test_assert(memcmp(control->Items, expected_items_3, ITEM_SIZE) == 0);
+ rtems_test_assert(_Record_Head(control) == 4);
+ rtems_test_assert(_Record_Tail(control) == 0);
+
+ rtems_record_produce(UE(17), 19);
+ set_time(&control->Items[0], 18);
+ rtems_test_assert(memcmp(control->Items, expected_items_4, ITEM_SIZE) == 0);
+ rtems_test_assert(_Record_Head(control) == 5);
+ rtems_test_assert(_Record_Tail(control) == 0);
+}
+
+static void test_produce_2(test_context *ctx, Record_Control *control)
+{
+ init_context(ctx);
+
+ rtems_record_produce_2(UE(1), 3, UE(5), 7);
+ set_time(&control->Items[0], 2);
+ set_time(&control->Items[1], 6);
+ rtems_test_assert(memcmp(control->Items, expected_items_1, ITEM_SIZE) == 0);
+ rtems_test_assert(_Record_Head(control) == 2);
+ rtems_test_assert(_Record_Tail(control) == 0);
+
+ rtems_record_produce(UE(9), 11);
+ set_time(&control->Items[2], 10);
+ rtems_test_assert(memcmp(control->Items, expected_items_2, ITEM_SIZE) == 0);
+ rtems_test_assert(_Record_Head(control) == 3);
+ rtems_test_assert(_Record_Tail(control) == 0);
+
+ rtems_record_produce_2(UE(13), 15, UE(17), 19);
+ set_time(&control->Items[3], 14);
+ set_time(&control->Items[0], 18);
+ rtems_test_assert(memcmp(control->Items, expected_items_4, ITEM_SIZE) == 0);
+ rtems_test_assert(_Record_Head(control) == 5);
+ rtems_test_assert(_Record_Tail(control) == 0);
+}
+
+static void test_produce_n(test_context *ctx, Record_Control *control)
+{
+ rtems_record_item items[5];
+
+ init_context(ctx);
+
+ items[0].event = UE(1);
+ items[0].data = 3;
+ items[1].event = UE(5);
+ items[1].data = 7;
+ items[2].event = UE(9);
+ items[2].data = 11;
+ items[3].event = UE(13);
+ items[3].data = 15;
+ items[4].event = UE(17);
+ items[4].data = 19;
+ rtems_record_produce_n(items, RTEMS_ARRAY_SIZE(items));
+ set_time(&control->Items[1], 6);
+ set_time(&control->Items[2], 10);
+ set_time(&control->Items[3], 14);
+ set_time(&control->Items[0], 18);
+ rtems_test_assert(memcmp(control->Items, expected_items_4, ITEM_SIZE) == 0);
+ rtems_test_assert(_Record_Head(control) == 5);
+ rtems_test_assert(_Record_Tail(control) == 0);
+}
+
+typedef struct {
+ size_t todo;
+ const rtems_record_item *items;
+} visitor_context;
+
+static void visitor(const rtems_record_item *items, size_t count, void *arg)
+{
+ visitor_context *vctx;
+
+ vctx = arg;
+ rtems_test_assert(vctx->todo >= count);
+
+ while (count > 0) {
+ rtems_test_assert(memcmp(items, vctx->items, sizeof(*items)) == 0);
+ ++items;
+ ++vctx->items;
+ --count;
+ --vctx->todo;
+ }
+}
+
+static void test_drain(test_context *ctx, Record_Control *control)
+{
+ visitor_context vctx;
+
+ init_context(ctx);
+
+ vctx.todo = 0;
+ vctx.items = NULL;
+ rtems_record_drain(visitor, &vctx);
+ rtems_test_assert(vctx.todo == 0);
+
+ rtems_record_produce(UE(1), 3);
+ set_time(&control->Items[0], 2);
+ rtems_record_produce(UE(4), 6);
+ set_time(&control->Items[1], 5);
+ rtems_record_produce(UE(7), 9);
+ set_time(&control->Items[2], 8);
+
+ vctx.todo = RTEMS_ARRAY_SIZE(expected_items_8);
+ vctx.items = expected_items_8;
+ rtems_record_drain(visitor, &vctx);
+ rtems_test_assert(vctx.todo == 0);
+
+ vctx.todo = 0;
+ vctx.items = NULL;
+ rtems_record_drain(visitor, &vctx);
+ rtems_test_assert(vctx.todo == 0);
+
+ rtems_record_produce(UE(10), 12);
+ set_time(&control->Items[3], 11);
+ rtems_record_produce(UE(13), 15);
+ set_time(&control->Items[0], 14);
+
+ vctx.todo = RTEMS_ARRAY_SIZE(expected_items_9);
+ vctx.items = expected_items_9;
+ rtems_record_drain(visitor, &vctx);
+ rtems_test_assert(vctx.todo == 0);
+
+ vctx.todo = 0;
+ vctx.items = NULL;
+ rtems_record_drain(visitor, &vctx);
+ rtems_test_assert(vctx.todo == 0);
+
+ rtems_record_produce(UE(16), 18);
+ set_time(&control->Items[1], 17);
+ rtems_record_produce(UE(19), 21);
+ set_time(&control->Items[2], 20);
+ rtems_record_produce(UE(22), 24);
+ set_time(&control->Items[3], 23);
+
+ vctx.todo = RTEMS_ARRAY_SIZE(expected_items_10);
+ vctx.items = expected_items_10;
+ rtems_record_drain(visitor, &vctx);
+ rtems_test_assert(vctx.todo == 0);
+
+ vctx.todo = 0;
+ vctx.items = NULL;
+ rtems_record_drain(visitor, &vctx);
+ rtems_test_assert(vctx.todo == 0);
+
+ rtems_record_produce(UE(25), 27);
+ set_time(&control->Items[0], 26);
+
+ vctx.todo = RTEMS_ARRAY_SIZE(expected_items_11);
+ vctx.items = expected_items_11;
+ rtems_record_drain(visitor, &vctx);
+ rtems_test_assert(vctx.todo == 0);
+
+ vctx.todo = 0;
+ vctx.items = NULL;
+ rtems_record_drain(visitor, &vctx);
+ rtems_test_assert(vctx.todo == 0);
+
+ rtems_record_produce(UE(28), 30);
+ set_time(&control->Items[1], 29);
+ rtems_record_produce(UE(31), 33);
+ set_time(&control->Items[2], 32);
+ rtems_record_produce(UE(34), 36);
+ set_time(&control->Items[3], 35);
+ rtems_record_produce(UE(37), 39);
+ set_time(&control->Items[0], 38);
+ rtems_record_produce(UE(40), 42);
+ set_time(&control->Items[1], 41);
+ rtems_record_produce(UE(43), 45);
+ set_time(&control->Items[2], 44);
+
+ vctx.todo = RTEMS_ARRAY_SIZE(expected_items_12);
+ vctx.items = expected_items_12;
+ rtems_record_drain(visitor, &vctx);
+ rtems_test_assert(vctx.todo == 0);
+
+ vctx.todo = 0;
+ vctx.items = NULL;
+ rtems_record_drain(visitor, &vctx);
+ rtems_test_assert(vctx.todo == 0);
+}
+
+#ifdef RTEMS_NETWORKING
+#define PORT 1234
+
+static uint32_t get_format(void)
+{
+ uint32_t format;
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+#if __INTPTR_WIDTH__ == 32
+ format = RTEMS_RECORD_FORMAT_LE_32;
+#elif __INTPTR_WIDTH__ == 64
+ format = RTEMS_RECORD_FORMAT_LE_64;
+#else
+#error "unexpected __INTPTR_WIDTH__"
+#endif
+#elif BYTE_ORDER == BIG_ENDIAN
+#if __INTPTR_WIDTH__ == 32
+ format = RTEMS_RECORD_FORMAT_BE_32;
+#elif __INTPTR_WIDTH__ == 64
+ format = RTEMS_RECORD_FORMAT_BE_64;
+#else
+#error "unexpected __INTPTR_WIDTH__"
+#endif
+#else
+#error "unexpected BYTE_ORDER"
+#endif
+
+ return format;
+}
+
+static int connect_client(void)
+{
+ struct sockaddr_in addr;
+ int fd;
+ int rv;
+ ssize_t n;
+ uint32_t v;
+ rtems_record_item item;
+
+ fd = socket(PF_INET, SOCK_STREAM, 0);
+ rtems_test_assert(fd >= 0);
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(PORT);
+ addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ rv = connect(fd, (struct sockaddr *) &addr, sizeof(addr));
+ rtems_test_assert(rv == 0);
+
+ n = read(fd, &v, sizeof(v));
+ rtems_test_assert(n == 4);
+ rtems_test_assert(v == get_format());
+
+ n = read(fd, &v, sizeof(v));
+ rtems_test_assert(n == 4);
+ rtems_test_assert(v == RTEMS_RECORD_MAGIC);
+
+ n = read(fd, &item, sizeof(item));
+ rtems_test_assert(n == (ssize_t) sizeof(item));
+ rtems_test_assert(item.event == TE(0, RTEMS_RECORD_VERSION));
+ rtems_test_assert(item.data == RTEMS_RECORD_THE_VERSION);
+
+ n = read(fd, &item, sizeof(item));
+ rtems_test_assert(n == (ssize_t) sizeof(item));
+ rtems_test_assert(item.event == TE(0, RTEMS_RECORD_PROCESSOR_MAXIMUM));
+ rtems_test_assert(item.data == 0);
+
+ n = read(fd, &item, sizeof(item));
+ rtems_test_assert(n == (ssize_t) sizeof(item));
+ rtems_test_assert(item.event == TE(0, RTEMS_RECORD_COUNT));
+ rtems_test_assert(item.data == ITEM_COUNT);
+
+ n = read(fd, &item, sizeof(item));
+ rtems_test_assert(n == (ssize_t) sizeof(item));
+ rtems_test_assert(item.event == TE(0, RTEMS_RECORD_FREQUENCY));
+ rtems_test_assert(item.data == rtems_counter_frequency());
+
+ return fd;
+}
+
+static void produce_and_read(int fd, Record_Control *control)
+{
+ rtems_record_item items[6];
+ ssize_t n;
+
+ rtems_record_produce(UE(1), 3);
+ set_time(&control->Items[0], 2);
+ rtems_record_produce(UE(4), 6);
+ set_time(&control->Items[1], 5);
+ rtems_record_produce(UE(7), 9);
+ set_time(&control->Items[2], 8);
+
+ n = read(fd, items, sizeof(expected_items_8));
+ rtems_test_assert(n == (ssize_t) sizeof(expected_items_8));
+ rtems_test_assert(
+ memcmp(items, expected_items_8, sizeof(expected_items_8)) == 0
+ );
+
+ rtems_record_produce(UE(10), 12);
+ set_time(&control->Items[3], 11);
+ rtems_record_produce(UE(13), 15);
+ set_time(&control->Items[0], 14);
+
+ n = read(fd, items, sizeof(expected_items_9));
+ rtems_test_assert(n == (ssize_t) sizeof(expected_items_9));
+ rtems_test_assert(
+ memcmp(items, expected_items_9, sizeof(expected_items_9)) == 0
+ );
+
+ rtems_record_produce(UE(16), 18);
+ set_time(&control->Items[1], 17);
+ rtems_record_produce(UE(19), 21);
+ set_time(&control->Items[2], 20);
+ rtems_record_produce(UE(22), 24);
+ set_time(&control->Items[3], 23);
+
+ n = read(fd, items, sizeof(expected_items_10));
+ rtems_test_assert(n == (ssize_t) sizeof(expected_items_10));
+ rtems_test_assert(
+ memcmp(items, expected_items_10, sizeof(expected_items_10)) == 0
+ );
+
+ rtems_record_produce(UE(25), 27);
+ set_time(&control->Items[0], 26);
+
+ n = read(fd, items, sizeof(expected_items_11));
+ rtems_test_assert(n == (ssize_t) sizeof(expected_items_11));
+ rtems_test_assert(
+ memcmp(items, expected_items_11, sizeof(expected_items_11)) == 0
+ );
+
+ rtems_record_produce(UE(28), 30);
+ set_time(&control->Items[1], 29);
+ rtems_record_produce(UE(31), 33);
+ set_time(&control->Items[2], 32);
+ rtems_record_produce(UE(34), 36);
+ set_time(&control->Items[3], 35);
+ rtems_record_produce(UE(37), 39);
+ set_time(&control->Items[0], 38);
+ rtems_record_produce(UE(40), 42);
+ set_time(&control->Items[1], 41);
+ rtems_record_produce(UE(43), 45);
+ set_time(&control->Items[2], 44);
+
+ n = read(fd, items, sizeof(expected_items_12));
+ rtems_test_assert(n == (ssize_t) sizeof(expected_items_12));
+ rtems_test_assert(
+ memcmp(items, expected_items_12, sizeof(expected_items_12)) == 0
+ );
+}
+
+static void test_server(test_context *ctx, Record_Control *control)
+{
+ rtems_status_code sc;
+ int rv;
+ int fd;
+
+ init_context(ctx);
+
+ rv = rtems_bsdnet_initialize_network();
+ rtems_test_assert(rv == 0);
+
+ sc = rtems_record_start_server(1, PORT, 1);
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+ fd = connect_client();
+ produce_and_read(fd, control);
+
+ rv = close(fd);
+ rtems_test_assert(rv == 0);
+}
+#endif
+
+static void Init(rtems_task_argument arg)
+{
+ test_context *ctx;
+ Per_CPU_Control *cpu_self;
+
+ TEST_BEGIN();
+
+ ctx = &test_instance;
+
+ cpu_self = _Per_CPU_Get_snapshot();
+ cpu_self->record = &ctx->control;
+
+ init_context(ctx);
+ test_capacity(&ctx->control);
+ test_index(&ctx->control);
+ test_add_2_items(ctx, &ctx->control);
+ test_add_3_items(ctx, &ctx->control);
+ test_produce(ctx, &ctx->control);
+ test_produce_2(ctx, &ctx->control);
+ test_produce_n(ctx, &ctx->control);
+ test_drain(ctx, &ctx->control);
+#ifdef RTEMS_NETWORKING
+ test_server(ctx, &ctx->control);
+#endif
+
+ TEST_END();
+ rtems_test_exit(0);
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
+
+#ifdef RTEMS_NETWORKING
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 7
+
+#define CONFIGURE_MAXIMUM_TASKS 3
+
+#define CONFIGURE_MAXIMUM_TIMERS 1
+
+#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
+#else
+#define CONFIGURE_MAXIMUM_TASKS 1
+#endif
+
+#define CONFIGURE_INIT_TASK_PRIORITY 2
+
+#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/libtests/record01/record01.doc b/testsuites/libtests/record01/record01.doc
new file mode 100644
index 0000000000..a0592be97d
--- /dev/null
+++ b/testsuites/libtests/record01/record01.doc
@@ -0,0 +1,15 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name: record01
+
+directives:
+
+ - rtems_record_drain()
+ - rtems_record_produce()
+ - rtems_record_produce_2()
+ - rtems_record_produce_n()
+ - rtems_record_start_server()
+
+concepts:
+
+ - Ensure that the event recording works.
diff --git a/testsuites/libtests/record01/record01.scn b/testsuites/libtests/record01/record01.scn
new file mode 100644
index 0000000000..2f1492b0c2
--- /dev/null
+++ b/testsuites/libtests/record01/record01.scn
@@ -0,0 +1,7 @@
+*** BEGIN OF TEST RECORD 1 ***
+*** TEST VERSION: 5.0.0.f0ae613ba72bc4b95797e2482c4bd0fa5546331d
+*** TEST STATE: EXPECTED-PASS
+*** TEST BUILD: RTEMS_NETWORKING
+*** TEST TOOLS: 7.4.0 20181206 (RTEMS 5, RSB 376edee1c734fb412b731a7d9e57757dd4cc5f07, Newlib dc6e94551f09d3a983afd571478d63a09d6f66fa)
+
+*** END OF TEST RECORD 1 ***
diff --git a/testsuites/libtests/record02/init.c b/testsuites/libtests/record02/init.c
new file mode 100644
index 0000000000..642d3d5422
--- /dev/null
+++ b/testsuites/libtests/record02/init.c
@@ -0,0 +1,132 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2018, 2019 embedded brains GmbH
+ *
+ * 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/record.h>
+#include <rtems/recordclient.h>
+#include <rtems.h>
+
+#include <string.h>
+
+#include "tmacros.h"
+
+const char rtems_test_name[] = "RECORD 2";
+
+typedef struct {
+ rtems_record_client_context client;
+} test_context;
+
+static test_context test_instance;
+
+static rtems_record_client_status client_handler(
+ uint32_t seconds,
+ uint32_t nanoseconds,
+ uint32_t cpu,
+ rtems_record_event event,
+ uint64_t data,
+ void *arg
+)
+{
+ const char *event_text;
+
+ (void) arg;
+
+ if ( seconds != 0 && nanoseconds != 0 ) {
+ printf( "%" PRIu32 ".%09" PRIu32 ":", seconds, nanoseconds );
+ } else {
+ printf( "*:" );
+ }
+
+ event_text = rtems_record_event_text( event );
+
+ if ( event_text != NULL ) {
+ printf( "%" PRIu32 ":%s:%" PRIx64 "\n", cpu, event_text, data );
+ } else {
+ printf( "%" PRIu32 ":%i:%" PRIx64 "\n", cpu, event, data );
+ }
+
+ return RTEMS_RECORD_CLIENT_SUCCESS;
+}
+
+static void drain_visitor(
+ const rtems_record_item *items,
+ size_t count,
+ void *arg
+)
+{
+ test_context *ctx;
+ rtems_record_client_status cs;
+
+ ctx = arg;
+ cs = rtems_record_client_run(&ctx->client, items, count * sizeof(*items));
+ rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS);
+}
+
+static void Init(rtems_task_argument arg)
+{
+ test_context *ctx;
+ Record_Stream_header header;
+ rtems_record_client_status cs;
+ int i;
+
+ TEST_BEGIN();
+ ctx = &test_instance;
+
+ for (i = 0; i < 10; ++i) {
+ rtems_task_wake_after(1);
+ }
+
+ rtems_record_client_init(&ctx->client, client_handler, NULL);
+ _Record_Stream_header_initialize(&header);
+ cs = rtems_record_client_run(&ctx->client, &header, sizeof(header));
+ rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS);
+ rtems_record_drain(drain_visitor, ctx);
+
+ TEST_END();
+ rtems_test_exit(0);
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_RECORD_PER_PROCESSOR_ITEMS 128
+
+#define CONFIGURE_RECORD_EXTENSIONS_ENABLED
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/libtests/record02/record02.doc b/testsuites/libtests/record02/record02.doc
new file mode 100644
index 0000000000..a34aa7e30f
--- /dev/null
+++ b/testsuites/libtests/record02/record02.doc
@@ -0,0 +1,12 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name: record02
+
+directives:
+
+ - rtems_record_client_init()
+ - rtems_record_client_run()
+
+concepts:
+
+ - Simple event recording use case.
diff --git a/testsuites/libtests/record02/record02.scn b/testsuites/libtests/record02/record02.scn
new file mode 100644
index 0000000000..487c601caf
--- /dev/null
+++ b/testsuites/libtests/record02/record02.scn
@@ -0,0 +1,82 @@
+*** BEGIN OF TEST RECORD 2 ***
+*** TEST VERSION: 5.0.0.f0ae613ba72bc4b95797e2482c4bd0fa5546331d
+*** TEST STATE: EXPECTED-PASS
+*** TEST BUILD: RTEMS_NETWORKING
+*** TEST TOOLS: 7.4.0 20181206 (RTEMS 5, RSB 376edee1c734fb412b731a7d9e57757dd4cc5f07, Newlib dc6e94551f09d3a983afd571478d63a09d6f66fa)
+*:0:VERSION:1
+*:0:PROCESSOR_MAXIMUM:0
+*:0:COUNT:80
+*:0:FREQUENCY:f4240
+*:0:PROCESSOR:0
+*:0:TAIL:0
+*:0:HEAD:44
+*:0:THREAD_CREATE:9010001
+*:0:THREAD_START:9010001
+*:0:UPTIME_LOW:9a240
+*:0:UPTIME_HIGH:1
+1.000537999:0:THREAD_CREATE:a010001
+1.000843999:0:THREAD_START:a010001
+1.003692999:0:THREAD_BEGIN:a010001
+1.005548999:0:THREAD_SWITCH_OUT:a010001
+1.005548999:0:THREAD_STACK_CURRENT:d48
+1.005548999:0:THREAD_SWITCH_IN:9010001
+1.005645999:0:THREAD_BEGIN:9010001
+1.013832999:0:THREAD_SWITCH_OUT:9010001
+1.013832999:0:THREAD_STACK_CURRENT:d38
+1.013832999:0:THREAD_SWITCH_IN:a010001
+1.014077999:0:THREAD_SWITCH_OUT:a010001
+1.014077999:0:THREAD_STACK_CURRENT:d48
+1.014077999:0:THREAD_SWITCH_IN:9010001
+1.023821999:0:THREAD_SWITCH_OUT:9010001
+1.023821999:0:THREAD_STACK_CURRENT:d38
+1.023821999:0:THREAD_SWITCH_IN:a010001
+1.024065999:0:THREAD_SWITCH_OUT:a010001
+1.024065999:0:THREAD_STACK_CURRENT:d48
+1.024065999:0:THREAD_SWITCH_IN:9010001
+1.033821999:0:THREAD_SWITCH_OUT:9010001
+1.033821999:0:THREAD_STACK_CURRENT:d38
+1.033821999:0:THREAD_SWITCH_IN:a010001
+1.034065999:0:THREAD_SWITCH_OUT:a010001
+1.034065999:0:THREAD_STACK_CURRENT:d48
+1.034065999:0:THREAD_SWITCH_IN:9010001
+1.043821999:0:THREAD_SWITCH_OUT:9010001
+1.043821999:0:THREAD_STACK_CURRENT:d38
+1.043821999:0:THREAD_SWITCH_IN:a010001
+1.044065999:0:THREAD_SWITCH_OUT:a010001
+1.044065999:0:THREAD_STACK_CURRENT:d48
+1.044065999:0:THREAD_SWITCH_IN:9010001
+1.053821999:0:THREAD_SWITCH_OUT:9010001
+1.053821999:0:THREAD_STACK_CURRENT:d38
+1.053821999:0:THREAD_SWITCH_IN:a010001
+1.054065999:0:THREAD_SWITCH_OUT:a010001
+1.054065999:0:THREAD_STACK_CURRENT:d48
+1.054065999:0:THREAD_SWITCH_IN:9010001
+1.063821999:0:THREAD_SWITCH_OUT:9010001
+1.063821999:0:THREAD_STACK_CURRENT:d38
+1.063821999:0:THREAD_SWITCH_IN:a010001
+1.064065999:0:THREAD_SWITCH_OUT:a010001
+1.064065999:0:THREAD_STACK_CURRENT:d48
+1.064065999:0:THREAD_SWITCH_IN:9010001
+1.073821999:0:THREAD_SWITCH_OUT:9010001
+1.073821999:0:THREAD_STACK_CURRENT:d38
+1.073821999:0:THREAD_SWITCH_IN:a010001
+1.074065999:0:THREAD_SWITCH_OUT:a010001
+1.074065999:0:THREAD_STACK_CURRENT:d48
+1.074065999:0:THREAD_SWITCH_IN:9010001
+1.083821999:0:THREAD_SWITCH_OUT:9010001
+1.083821999:0:THREAD_STACK_CURRENT:d38
+1.083821999:0:THREAD_SWITCH_IN:a010001
+1.084065999:0:THREAD_SWITCH_OUT:a010001
+1.084065999:0:THREAD_STACK_CURRENT:d48
+1.084065999:0:THREAD_SWITCH_IN:9010001
+1.093821999:0:THREAD_SWITCH_OUT:9010001
+1.093821999:0:THREAD_STACK_CURRENT:d38
+1.093821999:0:THREAD_SWITCH_IN:a010001
+1.094065999:0:THREAD_SWITCH_OUT:a010001
+1.094065999:0:THREAD_STACK_CURRENT:d48
+1.094065999:0:THREAD_SWITCH_IN:9010001
+1.103821999:0:THREAD_SWITCH_OUT:9010001
+1.103821999:0:THREAD_STACK_CURRENT:d38
+1.103821999:0:THREAD_SWITCH_IN:a010001
+
+*** END OF TEST RECORD 2 ***