File indexing completed on 2025-05-11 08:24:39
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
0029
0030
0031 #ifdef HAVE_CONFIG_H
0032 #include "config.h"
0033 #endif
0034
0035 #include <string.h>
0036 #include <time.h>
0037
0038 #include <rtems/test.h>
0039 #include <rtems/test-info.h>
0040
0041 const char rtems_test_name[] = "PSXINTRCRITICAL 1";
0042
0043 typedef struct {
0044 timer_t timer;
0045 struct itimerspec spec;
0046 volatile bool early;
0047 volatile bool late;
0048 long early_count;
0049 long late_count;
0050 long potential_hits;
0051 } test_context;
0052
0053 #define POSIX_TIMER_RELATIVE 0
0054
0055 static void prepare(void *arg)
0056 {
0057 test_context *ctx;
0058
0059 ctx = arg;
0060 ctx->early = false;
0061 ctx->late = false;
0062 }
0063
0064 static void action(void *arg)
0065 {
0066 test_context *ctx;
0067 int rv;
0068
0069 ctx = arg;
0070 ctx->early = true;
0071 rv = timer_settime(ctx->timer, POSIX_TIMER_RELATIVE, &ctx->spec, NULL);
0072 ctx->late = true;
0073 T_quiet_psx_success(rv);
0074
0075 T_interrupt_test_busy_wait_for_interrupt();
0076 }
0077
0078 static T_interrupt_test_state interrupt(void *arg)
0079 {
0080 test_context *ctx;
0081 int rv;
0082
0083 if (T_interrupt_test_get_state() != T_INTERRUPT_TEST_ACTION) {
0084 return T_INTERRUPT_TEST_EARLY;
0085 }
0086
0087 ctx = arg;
0088 rv = timer_settime(ctx->timer, POSIX_TIMER_RELATIVE, &ctx->spec, NULL);
0089 T_quiet_psx_success(rv);
0090
0091 if (ctx->late) {
0092 ++ctx->late_count;
0093 return T_INTERRUPT_TEST_LATE;
0094 } else if (ctx->early) {
0095 ++ctx->early_count;
0096 return T_INTERRUPT_TEST_EARLY;
0097 } else {
0098 ++ctx->potential_hits;
0099
0100 if (ctx->potential_hits > 13) {
0101 return T_INTERRUPT_TEST_DONE;
0102 } else {
0103 return T_INTERRUPT_TEST_CONTINUE;
0104 }
0105 }
0106 }
0107
0108 static const T_interrupt_test_config config = {
0109 .prepare = prepare,
0110 .action = action,
0111 .interrupt = interrupt,
0112 .max_iteration_count = 10000
0113 };
0114
0115 T_TEST_CASE(PSXSetTimerInterrupt)
0116 {
0117 test_context ctx;
0118 int sc;
0119 T_interrupt_test_state state;
0120
0121 memset(&ctx, 0, sizeof(ctx));
0122
0123
0124 sc = timer_create (CLOCK_REALTIME, NULL, &ctx.timer);
0125 T_psx_success(sc);
0126
0127
0128 ctx.spec.it_interval.tv_sec = 10;
0129 ctx.spec.it_value.tv_sec = 10;
0130
0131 state = T_interrupt_test(&config, &ctx);
0132 T_eq_int(state, T_INTERRUPT_TEST_DONE);
0133
0134 T_log(T_NORMAL, "early count = %ld", ctx.early_count);
0135 T_log(T_NORMAL, "late count = %ld", ctx.late_count);
0136 T_log(T_NORMAL, "potential hits = %ld", ctx.potential_hits);
0137 T_gt_int(ctx.potential_hits, 0);
0138
0139 sc = timer_delete(ctx.timer);
0140 T_psx_success(sc);
0141 }
0142
0143 static rtems_task Init(rtems_task_argument arg)
0144 {
0145 rtems_test_run(arg, TEST_STATE);
0146 }
0147
0148
0149
0150 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0151 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0152
0153 #define CONFIGURE_MAXIMUM_TASKS 1
0154 #define CONFIGURE_MAXIMUM_POSIX_TIMERS 1
0155 #define CONFIGURE_MICROSECONDS_PER_TICK 1000
0156 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0157
0158 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0159
0160 #define CONFIGURE_INIT
0161 #include <rtems/confdefs.h>
0162
0163