Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:39

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  Copyright (C) 2020 embedded brains GmbH & Co. KG
0005  *
0006  *  COPYRIGHT (c) 1989-2012.
0007  *  On-Line Applications Research Corporation (OAR).
0008  *
0009  * Redistribution and use in source and binary forms, with or without
0010  * modification, are permitted provided that the following conditions
0011  * are met:
0012  * 1. Redistributions of source code must retain the above copyright
0013  *    notice, this list of conditions and the following disclaimer.
0014  * 2. Redistributions in binary form must reproduce the above copyright
0015  *    notice, this list of conditions and the following disclaimer in the
0016  *    documentation and/or other materials provided with the distribution.
0017  *
0018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0028  * POSSIBILITY OF SUCH DAMAGE.
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   /* create POSIX Timer */
0124   sc = timer_create (CLOCK_REALTIME, NULL, &ctx.timer);
0125   T_psx_success(sc);
0126 
0127   /* we don't care if it ever fires */
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 /* configuration information */
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 /* global variables */