File indexing completed on 2025-05-11 08:24:35
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 #include <rtems/test.h>
0029
0030 #include <sys/time.h>
0031 #include <stdlib.h>
0032 #include <string.h>
0033
0034 #include <rtems.h>
0035 #include <rtems/bspIo.h>
0036 #include <rtems/score/threaddispatch.h>
0037
0038 #include "t-self-test.h"
0039
0040 #include <tmacros.h>
0041
0042 const char rtems_test_name[] = "TTEST 1";
0043
0044 #define test_assert(e) (e) ? (void)0 : test_failed(__LINE__, #e)
0045
0046 RTEMS_LINKER_ROSET(t_self_test, const char *);
0047
0048 typedef enum {
0049 CENSOR_PASS_THROUGH,
0050 CENSOR_DISCARD
0051 } censor_state;
0052
0053 typedef struct {
0054 const char *c;
0055 size_t case_begin_count;
0056 size_t case_end_count;
0057 T_putchar putchar;
0058 void *putchar_arg;
0059 const char *censor_c;
0060 censor_state censor_state;
0061 } test_context;
0062
0063 static test_context test_instance;
0064
0065 static void
0066 test_failed(int line, const char *e)
0067 {
0068 printk("FAILED:%i:%s\n", line, e);
0069 rtems_test_exit(1);
0070 }
0071
0072 static void
0073 test_putchar(int c, void *arg)
0074 {
0075 test_context *ctx;
0076
0077 ctx = arg;
0078
0079 if (c != '\r' && ctx->c != NULL) {
0080 test_assert(*ctx->c == c);
0081 ++ctx->c;
0082 }
0083
0084 rtems_putc((char)c);
0085 }
0086
0087 static void
0088 case_early(const char *name)
0089 {
0090 test_context *ctx;
0091 const char **item;
0092 ssize_t n;
0093
0094 ctx = &test_instance;
0095 ++ctx->case_begin_count;
0096 n = strlen(name);
0097
0098 RTEMS_LINKER_SET_FOREACH(t_self_test, item) {
0099 const char *to;
0100
0101 to = *item;
0102
0103 if (strncmp(name, to, n) == 0 && to[n] == ':') {
0104 ctx->c = to + n + 1;
0105 return;
0106 }
0107 }
0108
0109 test_assert(0);
0110 }
0111
0112 static void
0113 case_late(const char *name)
0114 {
0115 test_context *ctx;
0116
0117 if (strcmp(name, "check_task_context") == 0) {
0118 _Thread_Dispatch_enable(_Per_CPU_Get());
0119 }
0120
0121 ctx = &test_instance;
0122 ++ctx->case_end_count;
0123 test_assert(ctx->c != NULL);
0124 test_assert(*ctx->c == '\0');
0125 ctx->c = NULL;
0126 }
0127
0128 static const char censored_init[] = "A:ttest01\n"
0129 "S:Platform:RTEMS\n"
0130 "S:Compiler:*"
0131 "S:Version:*"
0132 "S:BSP:*"
0133 "S:BuildLabel:*"
0134 "S:TargetHash:SHA256:*"
0135 "S:RTEMS_DEBUG:*"
0136 "S:RTEMS_MULTIPROCESSING:*"
0137 "S:RTEMS_POSIX_API:*"
0138 "S:RTEMS_PROFILING:*"
0139 "S:RTEMS_SMP:*";
0140
0141 static void
0142 censor_putchar(int c, void *arg)
0143 {
0144 test_context *ctx;
0145
0146 ctx = arg;
0147
0148 if (*ctx->censor_c == '\0') {
0149 T_putchar discard_putchar;
0150 void *discard_putchar_arg;
0151
0152 (*ctx->putchar)(c, ctx->putchar_arg);
0153 T_set_putchar(ctx->putchar, ctx->putchar_arg, &discard_putchar,
0154 &discard_putchar_arg);
0155 return;
0156 }
0157
0158 switch (ctx->censor_state) {
0159 case CENSOR_PASS_THROUGH:
0160 if (*ctx->censor_c == '*') {
0161 (*ctx->putchar)('*', ctx->putchar_arg);
0162 ctx->censor_state = CENSOR_DISCARD;
0163 } else if (c == *ctx->censor_c) {
0164 (*ctx->putchar)(c, ctx->putchar_arg);
0165 ++ctx->censor_c;
0166 } else {
0167 test_assert(0);
0168 }
0169 break;
0170 case CENSOR_DISCARD:
0171 if (c == '\n') {
0172 (*ctx->putchar)(c, ctx->putchar_arg);
0173 ctx->censor_state = CENSOR_PASS_THROUGH;
0174 ++ctx->censor_c;
0175 }
0176 break;
0177 }
0178 }
0179
0180 static void
0181 run_initialize(void)
0182 {
0183 test_context *ctx;
0184
0185 ctx = &test_instance;
0186 ctx->censor_c = censored_init;
0187 T_set_putchar(censor_putchar, ctx, &ctx->putchar, &ctx->putchar_arg);
0188 }
0189
0190 static const char expected_final[] = "Z:ttest01:C:344:N:1339:F:795:D:0.691999\n"
0191 "Y:ReportHash:SHA256:LgRLA4VlIDzeH_dLPihAOjqW8IAujT-Co3FwBloXoKE=\n";
0192
0193 static void
0194 run_finalize(void)
0195 {
0196 test_context *ctx;
0197
0198 ctx = &test_instance;
0199 ctx->c = expected_final;
0200 }
0201
0202 static void
0203 test_action(T_event event, const char *name)
0204 {
0205 (void)name;
0206
0207 switch (event) {
0208 case T_EVENT_CASE_EARLY:
0209 case_early(name);
0210 break;
0211 case T_EVENT_CASE_LATE:
0212 case_late(name);
0213 break;
0214 case T_EVENT_RUN_INITIALIZE_EARLY:
0215 run_initialize();
0216 break;
0217 case T_EVENT_RUN_FINALIZE_EARLY:
0218 run_finalize();
0219 break;
0220 default:
0221 break;
0222 };
0223 }
0224
0225 static Atomic_Uint counter = ATOMIC_INITIALIZER_UINT(0);
0226
0227 static T_time
0228 now(void)
0229 {
0230 T_time t;
0231
0232 t = _Atomic_Fetch_add_uint(&counter, 1, ATOMIC_ORDER_RELAXED);
0233 return t * SBT_1MS;
0234 }
0235
0236 static char buffer[512];
0237
0238 static const T_action actions[] = {
0239 T_report_hash_sha256,
0240 test_action,
0241 T_check_task_context,
0242 T_check_file_descriptors,
0243 T_check_rtems_barriers,
0244 T_check_rtems_extensions,
0245 T_check_rtems_message_queues,
0246 T_check_rtems_partitions,
0247 T_check_rtems_periods,
0248 T_check_rtems_regions,
0249 T_check_rtems_semaphores,
0250 T_check_rtems_tasks,
0251 T_check_rtems_timers,
0252 T_check_posix_keys
0253 };
0254
0255 static const T_config config = {
0256 .name = "ttest01",
0257 .buf = buffer,
0258 .buf_size = sizeof(buffer),
0259 .putchar = test_putchar,
0260 .putchar_arg = &test_instance,
0261 .verbosity = T_VERBOSE,
0262 .now = now,
0263 .allocate = malloc,
0264 .deallocate = free,
0265 .action_count = T_ARRAY_SIZE(actions),
0266 .actions = actions
0267 };
0268
0269 static void
0270 Init(rtems_task_argument arg)
0271 {
0272 test_context *ctx;
0273 int exit_code;
0274 size_t case_count;
0275
0276 (void)arg;
0277 TEST_BEGIN();
0278 ctx = &test_instance;
0279 test_assert(!T_is_runner());
0280 T_register();
0281 test_assert(!T_is_runner());
0282 exit_code = T_main(&config);
0283 test_assert(exit_code == 1);
0284 test_assert(!T_is_runner());
0285 case_count = RTEMS_LINKER_SET_ITEM_COUNT(t_self_test);
0286 test_assert(ctx->case_begin_count == case_count);
0287 test_assert(ctx->case_end_count == case_count);
0288 TEST_END();
0289 rtems_test_exit(0);
0290 }
0291
0292 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0293
0294 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
0295
0296 #define CONFIGURE_MAXIMUM_BARRIERS 1
0297 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
0298 #define CONFIGURE_MAXIMUM_PARTITIONS 1
0299 #define CONFIGURE_MAXIMUM_PERIODS 1
0300 #define CONFIGURE_MAXIMUM_REGIONS 1
0301 #define CONFIGURE_MAXIMUM_SEMAPHORES 1
0302 #define CONFIGURE_MAXIMUM_TASKS 2
0303 #define CONFIGURE_MAXIMUM_TIMERS 1
0304 #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
0305
0306 #define CONFIGURE_MAXIMUM_POSIX_KEYS 1
0307
0308 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0309
0310 #define CONFIGURE_INIT
0311
0312 #include <rtems/confdefs.h>