Back to home page

LXR

 
 

    


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

0001 #include <rtems/test.h>
0002 
0003 #include <rtems.h>
0004 
0005 static void
0006 wakeup(rtems_id id, void *arg)
0007 {
0008     rtems_status_code sc;
0009     rtems_id *task;
0010 
0011     (void)id;
0012     task = arg;
0013     sc = rtems_event_send(*task, RTEMS_EVENT_0);
0014     T_step_rsc_success(3, sc);
0015     T_step_false(4, T_is_runner(), "ISR is runner");
0016 }
0017 
0018 T_TEST_CASE(timer)
0019 {
0020     rtems_status_code sc;
0021     rtems_id id;
0022     rtems_id task;
0023     rtems_event_set events;
0024 
0025     T_plan(8);
0026     T_step_true(0, T_is_runner(), "test body is not runner");
0027 
0028     sc = rtems_timer_create(rtems_build_name('T', 'E', 'S', 'T'), &id);
0029     T_step_assert_rsc_success(1, sc);
0030 
0031     /*
0032      * Make sure that the next step is not immediately interrupted by the
0033      * clock interrupt.
0034      */
0035     (void)rtems_task_wake_after(1);
0036 
0037     task = rtems_task_self();
0038     sc = rtems_timer_fire_after(id, 1, wakeup, &task);
0039     T_step_rsc_success(2, sc);
0040 
0041     events = 0;
0042     sc = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT | RTEMS_EVENT_ALL,
0043         RTEMS_NO_TIMEOUT, &events);
0044     T_step_rsc_success(5, sc);
0045     T_step_eq_u32(6, events, RTEMS_EVENT_0);
0046 
0047     sc = rtems_timer_delete(id);
0048     T_step_rsc_success(7, sc);
0049 }
0050 
0051 T_TEST_CASE(rsc)
0052 {
0053     T_plan(6);
0054     T_rsc(RTEMS_INVALID_ID, RTEMS_INVALID_ID);
0055     T_rsc(RTEMS_INVALID_NUMBER, RTEMS_INVALID_ID);
0056     T_quiet_rsc(RTEMS_INVALID_ID, RTEMS_INVALID_ID);
0057     T_quiet_rsc(RTEMS_INVALID_NUMBER, RTEMS_INVALID_ID);
0058     T_assert_rsc(RTEMS_INVALID_ID, RTEMS_INVALID_ID);
0059     T_assert_rsc(RTEMS_INVALID_NUMBER, RTEMS_INVALID_ID);
0060 }
0061 
0062 T_TEST_CASE(rsc_success)
0063 {
0064     T_plan(6);
0065     T_rsc_success(RTEMS_SUCCESSFUL);
0066     T_rsc_success(RTEMS_INVALID_NUMBER);
0067     T_quiet_rsc_success(RTEMS_SUCCESSFUL);
0068     T_quiet_rsc_success(RTEMS_INVALID_NUMBER);
0069     T_assert_rsc_success(RTEMS_SUCCESSFUL);
0070     T_assert_rsc_success(RTEMS_INVALID_NUMBER);
0071 }
0072 
0073 #include "t-self-test.h"
0074 
0075 T_TEST_OUTPUT(timer,
0076 "B:timer\n"
0077 "P:0:0:UI1:test-rtems.c:26\n"
0078 "P:1:0:UI1:test-rtems.c:29\n"
0079 "P:2:0:UI1:test-rtems.c:39\n"
0080 "P:3:0:ISR:test-rtems.c:14\n"
0081 "P:4:0:ISR:test-rtems.c:15\n"
0082 "P:5:0:UI1:test-rtems.c:44\n"
0083 "P:6:0:UI1:test-rtems.c:45\n"
0084 "P:7:0:UI1:test-rtems.c:48\n"
0085 "E:timer:N:8:F:0:D:0.001000\n");
0086 
0087 T_TEST_OUTPUT(rsc,
0088 "B:rsc\n"
0089 "P:0:0:UI1:test-rtems.c:54\n"
0090 "F:1:0:UI1:test-rtems.c:55:RTEMS_INVALID_NUMBER == RTEMS_INVALID_ID\n"
0091 "F:*:0:UI1:test-rtems.c:57:RTEMS_INVALID_NUMBER == RTEMS_INVALID_ID\n"
0092 "P:2:0:UI1:test-rtems.c:58\n"
0093 "F:3:0:UI1:test-rtems.c:59:RTEMS_INVALID_NUMBER == RTEMS_INVALID_ID\n"
0094 "E:rsc:N:4:F:3:D:0.001000\n");
0095 
0096 T_TEST_OUTPUT(rsc_success,
0097 "B:rsc_success\n"
0098 "P:0:0:UI1:test-rtems.c:65\n"
0099 "F:1:0:UI1:test-rtems.c:66:RTEMS_INVALID_NUMBER == RTEMS_SUCCESSFUL\n"
0100 "F:*:0:UI1:test-rtems.c:68:RTEMS_INVALID_NUMBER == RTEMS_SUCCESSFUL\n"
0101 "P:2:0:UI1:test-rtems.c:69\n"
0102 "F:3:0:UI1:test-rtems.c:70:RTEMS_INVALID_NUMBER == RTEMS_SUCCESSFUL\n"
0103 "E:rsc_success:N:4:F:3:D:0.001000\n");
0104 
0105 /*
0106  * The license is at the end of the file to be able to use the test code and
0107  * output in examples in the documentation.  This is also the reason for the
0108  * dual licensing.  The license for RTEMS documentation is CC-BY-SA-4.0.
0109  */
0110 
0111 /*
0112  * SPDX-License-Identifier: BSD-2-Clause OR CC-BY-SA-4.0
0113  *
0114  * Copyright (C) 2018, 2019 embedded brains GmbH & Co. KG
0115  *
0116  * Redistribution and use in source and binary forms, with or without
0117  * modification, are permitted provided that the following conditions
0118  * are met:
0119  * 1. Redistributions of source code must retain the above copyright
0120  *    notice, this list of conditions and the following disclaimer.
0121  * 2. Redistributions in binary form must reproduce the above copyright
0122  *    notice, this list of conditions and the following disclaimer in the
0123  *    documentation and/or other materials provided with the distribution.
0124  *
0125  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0126  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0127  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0128  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0129  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0130  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0131  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0132  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0133  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0134  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0135  * POSSIBILITY OF SUCH DAMAGE.
0136  *
0137  * ALTERNATIVELY, this software may be distributed under the terms of the
0138  * Creative Commons Attribution-ShareAlike 4.0 International Public License as
0139  * published by Creative Commons, PO Box 1866, Mountain View, CA 94042
0140  * (https://creativecommons.org/licenses/by-sa/4.0/legalcode).
0141  */