Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Copyright (c) 2016 embedded brains GmbH & Co. KG
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031 
0032 #include "tmacros.h"
0033 
0034 const char rtems_test_name[] = "SPTIMERSERVER 1";
0035 
0036 #define TIMER_COUNT 2
0037 
0038 typedef struct {
0039   rtems_id timer[TIMER_COUNT];
0040   rtems_id master;
0041 } test_context;
0042 
0043 static test_context ctx_instance;
0044 
0045 static const rtems_time_of_day start = {
0046   .year = 2016,
0047   .month = 3,
0048   .day = 1,
0049   .hour = 12,
0050   .minute = 5,
0051   .second = 17
0052 };
0053 
0054 static void cancel(rtems_id id, void *arg)
0055 {
0056   test_context *ctx = arg;
0057   rtems_status_code sc;
0058 
0059   sc = rtems_timer_cancel(ctx->timer[1]);
0060   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0061 
0062   sc = rtems_event_transient_send(ctx->master);
0063   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0064 }
0065 
0066 static void never(rtems_id id, void *arg)
0067 {
0068   rtems_test_assert(0);
0069 }
0070 
0071 static void test(void)
0072 {
0073   test_context *ctx = &ctx_instance;
0074   rtems_status_code sc;
0075   size_t i;
0076   rtems_time_of_day later;
0077 
0078   ctx->master = rtems_task_self();
0079 
0080   sc = rtems_timer_initiate_server(
0081     RTEMS_MINIMUM_PRIORITY,
0082     RTEMS_MINIMUM_STACK_SIZE,
0083     RTEMS_DEFAULT_ATTRIBUTES
0084   );
0085   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0086 
0087   for (i = 0; i < TIMER_COUNT; ++i) {
0088     sc = rtems_timer_create(
0089       rtems_build_name('T', 'M', 'R', '0' + i),
0090       &ctx->timer[i]
0091     );
0092     rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0093   }
0094 
0095   sc = rtems_timer_server_fire_after(ctx->timer[0], 10, cancel, ctx);
0096   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0097 
0098   sc = rtems_timer_server_fire_after(ctx->timer[1], 10, never, NULL);
0099   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0100 
0101   sc = rtems_event_transient_receive(RTEMS_WAIT, RTEMS_NO_TIMEOUT);
0102   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0103 
0104   sc = rtems_clock_set(&start);
0105   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0106 
0107   later = start;
0108   ++later.second;
0109 
0110   sc = rtems_timer_server_fire_when(ctx->timer[0], &later, cancel, ctx);
0111   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0112 
0113   sc = rtems_timer_server_fire_when(ctx->timer[1], &later, never, NULL);
0114   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0115 
0116   sc = rtems_event_transient_receive(RTEMS_WAIT, RTEMS_NO_TIMEOUT);
0117   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0118 }
0119 
0120 static void Init(rtems_task_argument arg)
0121 {
0122   TEST_BEGIN();
0123 
0124   test();
0125 
0126   TEST_END();
0127   rtems_test_exit(0);
0128 }
0129 
0130 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0131 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0132 
0133 #define CONFIGURE_MAXIMUM_TASKS 2
0134 #define CONFIGURE_MAXIMUM_TIMERS TIMER_COUNT
0135 
0136 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0137 
0138 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0139 
0140 #define CONFIGURE_INIT
0141 
0142 #include <rtems/confdefs.h>