File indexing completed on 2025-05-11 08:24:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031
0032 #include <rtems/profiling.h>
0033 #include <rtems/bspIo.h>
0034 #include <rtems.h>
0035
0036 #include <stdio.h>
0037 #include <string.h>
0038
0039 #include "tmacros.h"
0040
0041 const char rtems_test_name[] = "SPPROFILING 1";
0042
0043 typedef struct {
0044 rtems_interrupt_lock a;
0045 rtems_interrupt_lock b;
0046 rtems_interrupt_lock c;
0047 rtems_interrupt_lock d;
0048 enum {
0049 WAIT_FOR_A,
0050 EXPECT_B,
0051 EXPECT_D,
0052 DONE
0053 } state;
0054 } visitor_context;
0055
0056 static bool is_equal(const rtems_profiling_smp_lock *psl, const char *name)
0057 {
0058 return strcmp(psl->name, name) == 0;
0059 }
0060
0061 static void visitor(void *arg, const rtems_profiling_data *data)
0062 {
0063 visitor_context *ctx = arg;
0064
0065 if (data->header.type == RTEMS_PROFILING_SMP_LOCK) {
0066 const rtems_profiling_smp_lock *psl = &data->smp_lock;
0067
0068 switch (ctx->state) {
0069 case WAIT_FOR_A:
0070 rtems_test_assert(!is_equal(psl, "b"));
0071 rtems_test_assert(!is_equal(psl, "c"));
0072 rtems_test_assert(!is_equal(psl, "d"));
0073
0074 if (is_equal(psl, "a")) {
0075 ctx->state = EXPECT_B;
0076 }
0077 break;
0078 case EXPECT_B:
0079 rtems_test_assert(is_equal(psl, "b"));
0080 rtems_interrupt_lock_destroy(&ctx->c);
0081 ctx->state = EXPECT_D;
0082 break;
0083 case EXPECT_D:
0084 rtems_test_assert(is_equal(psl, "d"));
0085 ctx->state = DONE;
0086 break;
0087 case DONE:
0088 rtems_test_assert(!is_equal(psl, "a"));
0089 rtems_test_assert(!is_equal(psl, "b"));
0090 rtems_test_assert(!is_equal(psl, "c"));
0091 rtems_test_assert(!is_equal(psl, "d"));
0092 break;
0093 }
0094 }
0095 }
0096
0097 static void lock_init(rtems_interrupt_lock *lock, const char *name)
0098 {
0099 rtems_interrupt_lock_context lock_context;
0100
0101 rtems_interrupt_lock_initialize(lock, name);
0102 rtems_interrupt_lock_acquire(lock, &lock_context);
0103 rtems_interrupt_lock_release(lock, &lock_context);
0104 }
0105
0106 static void test_iterate(void)
0107 {
0108 visitor_context ctx_instance;
0109 visitor_context *ctx = &ctx_instance;
0110
0111 ctx->state = WAIT_FOR_A;
0112 lock_init(&ctx->a, "a");
0113 lock_init(&ctx->b, "b");
0114 lock_init(&ctx->c, "c");
0115 lock_init(&ctx->d, "d");
0116
0117 rtems_profiling_iterate(visitor, ctx);
0118
0119 rtems_interrupt_lock_destroy(&ctx->a);
0120 rtems_interrupt_lock_destroy(&ctx->b);
0121
0122 if (ctx->state != DONE) {
0123 rtems_interrupt_lock_destroy(&ctx->c);
0124 }
0125
0126 rtems_interrupt_lock_destroy(&ctx->d);
0127 }
0128
0129 static void test_report_xml(void)
0130 {
0131 rtems_status_code sc;
0132 int rv;
0133
0134 sc = rtems_task_wake_after(3);
0135 rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0136
0137 rv = rtems_profiling_report_xml("X", &rtems_test_printer, 1, " ");
0138 printf("characters produced by rtems_profiling_report_xml(): %i\n", rv);
0139 }
0140
0141 static void Init(rtems_task_argument arg)
0142 {
0143 TEST_BEGIN();
0144
0145 test_iterate();
0146 test_report_xml();
0147
0148 TEST_END();
0149
0150 rtems_test_exit(0);
0151 }
0152
0153 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0154 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0155
0156 #define CONFIGURE_MAXIMUM_TASKS 1
0157
0158 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0159
0160 #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
0161
0162 #define CONFIGURE_INIT
0163
0164 #include <rtems/confdefs.h>