From ee6b343cbaa434d8c31a4d71dac5316b4404da35 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Thu, 10 May 2012 15:06:10 +0200 Subject: Provide SWI(9) and TIMEOUT(9) --- testsuite/swi01/Makefile | 29 ++++ testsuite/swi01/init.c | 76 ++++++++++ testsuite/swi01/swi_test.c | 208 ++++++++++++++++++++++++++ testsuite/swi01/swi_test.h | 45 ++++++ testsuite/timeout01/Makefile | 29 ++++ testsuite/timeout01/init.c | 81 ++++++++++ testsuite/timeout01/timeout_helper.c | 142 ++++++++++++++++++ testsuite/timeout01/timeout_helper.h | 46 ++++++ testsuite/timeout01/timeout_test.c | 282 +++++++++++++++++++++++++++++++++++ testsuite/timeout01/timeout_test.h | 45 ++++++ 10 files changed, 983 insertions(+) create mode 100644 testsuite/swi01/Makefile create mode 100644 testsuite/swi01/init.c create mode 100644 testsuite/swi01/swi_test.c create mode 100644 testsuite/swi01/swi_test.h create mode 100644 testsuite/timeout01/Makefile create mode 100644 testsuite/timeout01/init.c create mode 100644 testsuite/timeout01/timeout_helper.c create mode 100644 testsuite/timeout01/timeout_helper.h create mode 100644 testsuite/timeout01/timeout_test.c create mode 100644 testsuite/timeout01/timeout_test.h (limited to 'testsuite') diff --git a/testsuite/swi01/Makefile b/testsuite/swi01/Makefile new file mode 100644 index 00000000..dd7c6882 --- /dev/null +++ b/testsuite/swi01/Makefile @@ -0,0 +1,29 @@ +include ../../config.inc + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +APP_PIECES = init swi_test + +APP_O_FILES = $(APP_PIECES:%=%.o) +APP_DEP_FILES = $(APP_PIECES:%=%.dep) + +APP = app.exe + +DEPFLAGS = -MT $@ -MD -MP -MF $*.dep +AM_CPPFLAGS += -I $(INSTALL_BASE)/include -I. + +CFLAGS += $(DEPFLAGS) $(GCCFLAGS) $(AM_CPPFLAGS) -Wno-unused -Wl,-Map,app.map + +LINK_LIBS += $(INSTALL_BASE)/libbsd.a + +all: $(APP) + +$(APP): $(APP_O_FILES) + $(CC) $(CFLAGS) $^ $(LINK_LIBS) -o $(APP) + +clean: + rm -f app.map $(APP) $(APP_O_FILES) $(APP_DEP_FILES) + +-include $(APP_DEP_FILES) diff --git a/testsuite/swi01/init.c b/testsuite/swi01/init.c new file mode 100644 index 00000000..9bc13dc6 --- /dev/null +++ b/testsuite/swi01/init.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include + +#include + +#include "swi_test.h" + +static void Init(rtems_task_argument arg) +{ + rtems_status_code sc; + + puts("\n\n*** TEST SOFTWARE INTERRUPT 1 ***"); + + sc = rtems_bsd_initialize(); + assert(sc == RTEMS_SUCCESSFUL); + + swi_test(); + + puts("*** END OF TEST SOFTWARE INTERRUPT 1 ***"); + + exit(0); +} + +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + +#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM + +#define CONFIGURE_FILESYSTEM_IMFS + +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 + +#define CONFIGURE_UNLIMITED_OBJECTS + +#define CONFIGURE_UNIFIED_WORK_AREAS + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_STACK_CHECKER_ENABLED + +#define CONFIGURE_INIT + +#include diff --git a/testsuite/swi01/swi_test.c b/testsuite/swi01/swi_test.c new file mode 100644 index 00000000..99ba94f4 --- /dev/null +++ b/testsuite/swi01/swi_test.c @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include + +#include + +#include +#include + +#include +#include +#include + +#define SWI_TEST_THREAD_PRIO (0) + +// Time to wait for swi-test-handler +#define SWI_SLEEP_TIME (100) + +enum arg { + HANDLER_NOT_VISITED, + HANDLER_VISITED, +}; + +// The swi handler function, that will be called by all tests. +void swi_test_handler(void *arg) +{ + enum arg* argument = arg; + + printf("This is swi_test_handler.\n"); + + *argument = HANDLER_VISITED; +} + +void swi_test_normal_handler() +{ + struct intr_event *test_intr_event = NULL; + enum arg argument = HANDLER_NOT_VISITED; + void *test_ih = NULL; + int retval = 0; + + printf("== Create thread and install a functional handler.\n"); + + retval = swi_add(&test_intr_event, "swi_test", swi_test_handler, &argument, + SWI_TEST_THREAD_PRIO, 0, &test_ih); + assert(retval == 0); + + swi_sched(test_ih, 0); + + usleep(SWI_SLEEP_TIME); + + assert(argument == HANDLER_VISITED); +} + +void swi_test_exclusive_handler() +{ + struct intr_event *test_intr_event = NULL; + enum arg argument = HANDLER_NOT_VISITED; + void *test_ih = NULL; + int retval = 0; + + printf("== Create a thread with a exclusive handler.\n"); + + retval = swi_add(&test_intr_event, "swi_test", swi_test_handler, &argument, + SWI_TEST_THREAD_PRIO, INTR_EXCL, &test_ih); + assert(retval == 0); + + swi_sched(test_ih, 0); + + usleep(SWI_SLEEP_TIME); + + assert(argument == HANDLER_VISITED); +} + +void swi_test_error_number_of_processes_exceeded() +{ + // [EAGAIN] The system-imposed limit on the total number of processes + // under execution would be exceeded. The limit is given by the + // sysctl(3) MIB variable KERN_MAXPROC. +#warning TODO: write test case +} + +void swi_test_error_intr_entropy_set() +{ + struct intr_event *test_intr_event = NULL; + enum arg argument = HANDLER_NOT_VISITED; + void *test_ih = NULL; + int retval = 0; + + printf("== Set the INTR_ENTROPY flag.\n"); + + retval = swi_add(&test_intr_event, "swi_test", swi_test_handler, &argument, + SWI_TEST_THREAD_PRIO, INTR_ENTROPY, &test_ih); + assert(retval == EINVAL); + + usleep(SWI_SLEEP_TIME); + + assert(argument == HANDLER_NOT_VISITED); +} + +void swi_test_error_point_to_hardware_interrupt_thread() +{ + //[EINVAL] The ithdp argument points to a hardware interrupt thread. +#warning TODO: write test case +} + +void swi_test_error_name_null() +{ + struct intr_event *test_intr_event = NULL; + enum arg argument = HANDLER_NOT_VISITED; + void *test_ih = NULL; + int retval = 0; + + printf("== Set name to NULL.\n"); + + retval = swi_add(&test_intr_event, NULL, swi_test_handler, &argument, + SWI_TEST_THREAD_PRIO, 0, &test_ih); + assert(retval == EINVAL); + + usleep(SWI_SLEEP_TIME); + + assert(argument == HANDLER_NOT_VISITED); +} + +void swi_test_error_handler_null() +{ + struct intr_event *test_intr_event = NULL; + enum arg argument = HANDLER_NOT_VISITED; + void *test_ih = NULL; + int retval = 0; + + printf("== Set handler to NULL.\n"); + + retval = swi_add(&test_intr_event, "swi_test", NULL, &argument, + SWI_TEST_THREAD_PRIO, 0, &test_ih); + assert(retval == EINVAL); + + usleep(SWI_SLEEP_TIME); + + assert(argument == HANDLER_NOT_VISITED); +} + +void swi_test_error_has_allready_exclusive() +{ + struct intr_event *test_intr_event = NULL; + enum arg argument = HANDLER_NOT_VISITED; + void *test_ih1 = NULL; + void *test_ih2 = NULL; + int retval = 0; + + printf("== Create a thread with a exclusive handler and try to add another handler.\n"); + + retval = swi_add(&test_intr_event, "swi_test1", swi_test_handler, &argument, + SWI_TEST_THREAD_PRIO, INTR_EXCL, &test_ih1); + assert(retval == 0); + + retval = swi_add(&test_intr_event, "swi_test2", swi_test_handler, &argument, + SWI_TEST_THREAD_PRIO, 0, &test_ih2); + assert(retval == EINVAL); + + usleep(SWI_SLEEP_TIME); + + assert(argument == HANDLER_NOT_VISITED); +} + +void swi_test(void) +{ + swi_test_normal_handler(); + swi_test_exclusive_handler(); + swi_test_error_number_of_processes_exceeded(); + swi_test_error_intr_entropy_set(); + swi_test_error_point_to_hardware_interrupt_thread(); + swi_test_error_name_null(); + swi_test_error_handler_null(); + swi_test_error_has_allready_exclusive(); +} + diff --git a/testsuite/swi01/swi_test.h b/testsuite/swi01/swi_test.h new file mode 100644 index 00000000..e7708b6c --- /dev/null +++ b/testsuite/swi01/swi_test.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef SWI_TEST_H +#define SWI_TEST_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +void swi_test(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* TEST_H */ diff --git a/testsuite/timeout01/Makefile b/testsuite/timeout01/Makefile new file mode 100644 index 00000000..6e38da14 --- /dev/null +++ b/testsuite/timeout01/Makefile @@ -0,0 +1,29 @@ +include ../../config.inc + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +APP_PIECES = init timeout_test timeout_helper + +APP_O_FILES = $(APP_PIECES:%=%.o) +APP_DEP_FILES = $(APP_PIECES:%=%.dep) + +APP = app.exe + +DEPFLAGS = -MT $@ -MD -MP -MF $*.dep +AM_CPPFLAGS += -I $(INSTALL_BASE)/include -I. + +CFLAGS += $(DEPFLAGS) $(GCCFLAGS) $(AM_CPPFLAGS) -Wno-unused -Wl,-Map,app.map + +LINK_LIBS += $(INSTALL_BASE)/libbsd.a + +all: $(APP) + +$(APP): $(APP_O_FILES) + $(CC) $(CFLAGS) $^ $(LINK_LIBS) -o $(APP) + +clean: + rm -f app.map $(APP) $(APP_O_FILES) $(APP_DEP_FILES) + +-include $(APP_DEP_FILES) diff --git a/testsuite/timeout01/init.c b/testsuite/timeout01/init.c new file mode 100644 index 00000000..f1bd5291 --- /dev/null +++ b/testsuite/timeout01/init.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include + +#include + +#include + +#include "timeout_test.h" +#include "timeout_helper.h" + +static void Init(rtems_task_argument arg) +{ + rtems_status_code sc; + + puts("\n\n*** TEST TIMOUT 1 ***"); + + sc = rtems_bsd_initialize(); + assert(sc == RTEMS_SUCCESSFUL); + + timeout_table_init(); + callout_tick_task_init(); + + timeout_test(); + + puts("*** END OF TEST TIMOUT 1 ***"); + + exit(0); +} + +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + +#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM + +#define CONFIGURE_FILESYSTEM_IMFS + +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 + +#define CONFIGURE_UNLIMITED_OBJECTS + +#define CONFIGURE_UNIFIED_WORK_AREAS + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_STACK_CHECKER_ENABLED + +#define CONFIGURE_INIT + +#include diff --git a/testsuite/timeout01/timeout_helper.c b/testsuite/timeout01/timeout_helper.c new file mode 100644 index 00000000..88d8510d --- /dev/null +++ b/testsuite/timeout01/timeout_helper.c @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include + +#include +#include + +#include "timeout_helper.h" + +void timeout_table_init() +{ + size_t size = 0; + caddr_t v = 0; + void* firstaddr = 0; + + /* calculates how much memory is needed */ + v = kern_timeout_callwheel_alloc(v); + + /* allocate memory */ + size = (size_t)v; + firstaddr = malloc(round_page(size)); + assert(firstaddr != NULL); + + /* now set correct addresses for callwheel */ + v = (caddr_t) firstaddr; + v = kern_timeout_callwheel_alloc(v); + + assert((size_t)((void *)v - firstaddr) == size); + + /* Initialize the callouts we just allocated. */ + kern_timeout_callwheel_init(); +} + +#define CALLOUT_TICK_TASK_PRIO (PRIORITY_DEFAULT_MAXIMUM - 1) +#define CALLOUT_TICK_TASK_STACK_SIZE (1024) +#define CALLOUT_TICK_TASK_NAME rtems_build_name('C', 'O', 'U', 'T') +#define CALLOUT_TICKS_PER_CALLOUT_TICK 1 + +static const rtems_event_set TRIGGER_EVENT = RTEMS_EVENT_13; + +static void callout_tick_task_trigger(rtems_id timer, void *arg) +{ + rtems_status_code status; + rtems_id *task_id = arg; + + status = rtems_event_send(*task_id, TRIGGER_EVENT); + assert(status == RTEMS_SUCCESSFUL); + + status = rtems_timer_reset(timer); + assert(status == RTEMS_SUCCESSFUL); +} + +rtems_task callout_tick_task(rtems_task_argument arg) +{ + rtems_name name; + rtems_id timer; + rtems_status_code status; + const rtems_interval ticks_per_ms = CALLOUT_TICKS_PER_CALLOUT_TICK; + rtems_id self_id = rtems_task_self(); + + name = CALLOUT_TICK_TASK_NAME; + + status = rtems_timer_create( name, &timer ); + assert(status == RTEMS_SUCCESSFUL); + + status = rtems_timer_fire_after( timer, ticks_per_ms, callout_tick_task_trigger, &self_id ); + assert(status == RTEMS_SUCCESSFUL); + + while ( 1 ) { + rtems_event_set event; + + status = rtems_event_receive( + TRIGGER_EVENT, + RTEMS_EVENT_ALL | RTEMS_WAIT, + RTEMS_NO_TIMEOUT, + &event + ); + assert(status == RTEMS_SUCCESSFUL); + assert(event == TRIGGER_EVENT); + + callout_tick(); + } +} + + +void callout_tick_task_init(void) +{ + static bool initialized = false; + rtems_status_code sc = RTEMS_SUCCESSFUL; + + if (!initialized) { + rtems_id id = RTEMS_ID_NONE; + + initialized = true; + + sc = rtems_task_create( + CALLOUT_TICK_TASK_NAME, + CALLOUT_TICK_TASK_PRIO, + CALLOUT_TICK_TASK_STACK_SIZE, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, + &id + ); + assert(sc == RTEMS_SUCCESSFUL); + + sc = rtems_task_start(id, callout_tick_task, 0); + assert(sc == RTEMS_SUCCESSFUL); + } +} + diff --git a/testsuite/timeout01/timeout_helper.h b/testsuite/timeout01/timeout_helper.h new file mode 100644 index 00000000..7e5acce1 --- /dev/null +++ b/testsuite/timeout01/timeout_helper.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef TIMEOUT_HELPER_H +#define TIMEOUT_HELPER_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +void timeout_table_init(void); +void callout_tick_task_init(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* TIMEOUT_HELPER_H */ diff --git a/testsuite/timeout01/timeout_test.c b/testsuite/timeout01/timeout_test.c new file mode 100644 index 00000000..b89feb84 --- /dev/null +++ b/testsuite/timeout01/timeout_test.c @@ -0,0 +1,282 @@ +/* + * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include + +#define TIMEOUT_MILLISECONDS (100) + +// test after TEST_NOT_FIRED_MS, if handlar has not been executed +#define TEST_NOT_FIRED_MS (TIMEOUT_MILLISECONDS * 80 / 100) +// test TEST_FIRED_MS after TEST_NOT_FIRED_MS, if handlar has been executed +#define TEST_FIRED_MS (TIMEOUT_MILLISECONDS * 40 / 100) +// delay handler by this time with a mutex +#define TEST_DELAY_MS (TIMEOUT_MILLISECONDS) + +enum arg { + HANDLER_NOT_VISITED, + HANDLER_VISITED, +}; + +static void timeout_handler(void *arg) +{ + enum arg* argument = arg; + + printf("This is the timout_handler.\n"); + + *argument = HANDLER_VISITED; +} + +void timeout_test_timeout() +{ + enum arg argument = HANDLER_NOT_VISITED; + struct callout_handle handle; + + printf("== Start a timeout and test if handler has been called.\n"); + + callout_handle_init(&handle); + + handle = timeout(timeout_handler, &argument, RTEMS_MILLISECONDS_TO_TICKS(TIMEOUT_MILLISECONDS)); + + usleep(TEST_NOT_FIRED_MS * 1000); + assert(argument == HANDLER_NOT_VISITED); + + usleep(TEST_FIRED_MS * 1000); + assert(argument == HANDLER_VISITED); +} + +void timeout_test_cancel_timeout() +{ + enum arg argument = HANDLER_NOT_VISITED; + struct callout_handle handle; + + printf("== Start a timeout and cancel it.\n"); + + callout_handle_init(&handle); + + handle = timeout(timeout_handler, &argument, RTEMS_MILLISECONDS_TO_TICKS(TIMEOUT_MILLISECONDS)); + + usleep(TEST_NOT_FIRED_MS * 1000); + + untimeout(timeout_handler, &argument, handle); + + usleep(TEST_FIRED_MS * 1000); + assert(argument == HANDLER_NOT_VISITED); +} + +void timeout_test_callout(int mpsave) +{ + enum arg argument = HANDLER_NOT_VISITED; + struct callout callout; + int retval = 0; + printf("== Start a callout and test if handler has been called. mpsave=%d\n", mpsave); + + callout_init(&callout, mpsave); + + retval = callout_reset(&callout, RTEMS_MILLISECONDS_TO_TICKS(TIMEOUT_MILLISECONDS), timeout_handler, &argument); + assert(retval == 0); + + usleep(TEST_NOT_FIRED_MS * 1000); + assert(argument == HANDLER_NOT_VISITED); + + usleep(TEST_FIRED_MS * 1000); + assert(argument == HANDLER_VISITED); + + callout_deactivate(&callout); +} + +void timeout_test_cancel_callout(int mpsave, bool use_drain) +{ + enum arg argument = HANDLER_NOT_VISITED; + struct callout callout; + int retval = 0; + printf("== Start a callout and cancel it with %s. mpsave=%d\n", use_drain ? "drain" : "stop", mpsave); + + callout_init(&callout, mpsave); + + retval = callout_reset(&callout, RTEMS_MILLISECONDS_TO_TICKS(TIMEOUT_MILLISECONDS), timeout_handler, &argument); + assert(retval == 0); + + usleep(TEST_NOT_FIRED_MS * 1000); + + if(!use_drain) + { + retval = callout_stop(&callout); + } + else + { + retval = callout_drain(&callout); + } + assert(retval != 0); + + usleep(TEST_FIRED_MS * 1000); + assert(argument == HANDLER_NOT_VISITED); + + callout_deactivate(&callout); +} + +void timeout_test_callout_reschedule(int mpsave, bool use_reset) +{ + enum arg argument = HANDLER_NOT_VISITED; + struct callout callout; + int retval = 0; + printf("== Start a callout and reschedule it after some time with %s. mpsave=%d\n", use_reset ? "reset" : "schedule", mpsave); + + callout_init(&callout, mpsave); + + retval = callout_reset(&callout, RTEMS_MILLISECONDS_TO_TICKS(TIMEOUT_MILLISECONDS), timeout_handler, &argument); + assert(retval == 0); + + usleep(TEST_NOT_FIRED_MS * 1000); + assert(argument == HANDLER_NOT_VISITED); + + if(!use_reset) + { + retval = callout_schedule(&callout, RTEMS_MILLISECONDS_TO_TICKS(TIMEOUT_MILLISECONDS)); + } + else + { + retval = callout_reset(&callout, RTEMS_MILLISECONDS_TO_TICKS(TIMEOUT_MILLISECONDS), timeout_handler, &argument); + } + assert(retval != 0); + + usleep(TEST_NOT_FIRED_MS * 1000); + assert(argument == HANDLER_NOT_VISITED); + + usleep(TEST_FIRED_MS * 1000); + assert(argument == HANDLER_VISITED); + + callout_deactivate(&callout); +} + +void timeout_test_callout_mutex(bool delay_with_lock) +{ + enum arg argument = HANDLER_NOT_VISITED; + struct callout callout; + struct mtx mtx; + int retval = 0; + printf("== Start a callout with a mutex%s\n", delay_with_lock ? " and delay execution by locking it." : "."); + + mtx_init(&mtx, "callouttest", NULL, MTX_DEF); + callout_init_mtx(&callout, &mtx, 0); + + retval = callout_reset(&callout, RTEMS_MILLISECONDS_TO_TICKS(TIMEOUT_MILLISECONDS), timeout_handler, &argument); + assert(retval == 0); + + usleep(TEST_NOT_FIRED_MS * 1000); + assert(argument == HANDLER_NOT_VISITED); + + if(delay_with_lock) + { + retval = mtx_trylock(&mtx); + assert(retval != 0); + + usleep(TEST_DELAY_MS * 1000); + assert(argument == HANDLER_NOT_VISITED); + + mtx_unlock(&mtx); + } + + usleep(TEST_FIRED_MS * 1000); + assert(argument == HANDLER_VISITED); + + callout_deactivate(&callout); + + mtx_destroy(&mtx); +} + +void timeout_test_callout_rwlock(bool delay_with_lock) +{ + enum arg argument = HANDLER_NOT_VISITED; + struct callout callout; + struct rwlock rw; + int retval = 0; + printf("== Start a callout with a rwlock%s\n", delay_with_lock ? " and delay execution by locking it." : "."); + + rw_init(&rw, "callouttest"); + callout_init_rw(&callout, &rw, 0); + + retval = callout_reset(&callout, RTEMS_MILLISECONDS_TO_TICKS(TIMEOUT_MILLISECONDS), timeout_handler, &argument); + assert(retval == 0); + + usleep(TEST_NOT_FIRED_MS * 1000); + assert(argument == HANDLER_NOT_VISITED); + + if(delay_with_lock) + { + retval = rw_try_wlock(&rw); + assert(retval != 0); + + usleep(TEST_DELAY_MS * 1000); + assert(argument == HANDLER_NOT_VISITED); + + rw_wunlock(&rw); + } + + usleep(TEST_FIRED_MS * 1000); + assert(argument == HANDLER_VISITED); + + callout_deactivate(&callout); +} + +void timeout_test(void) +{ + int mpsave = 0; + + timeout_test_timeout(); + timeout_test_cancel_timeout(); + + for(mpsave = 0; mpsave<=1; mpsave++) + { + timeout_test_callout(mpsave); + timeout_test_cancel_callout(mpsave, false); + timeout_test_cancel_callout(mpsave, true); + timeout_test_callout_reschedule(mpsave, false); + timeout_test_callout_reschedule(mpsave, true); + } + + timeout_test_callout_mutex(false); + timeout_test_callout_mutex(true); + timeout_test_callout_rwlock(false); + timeout_test_callout_rwlock(true); +} diff --git a/testsuite/timeout01/timeout_test.h b/testsuite/timeout01/timeout_test.h new file mode 100644 index 00000000..25d4cb20 --- /dev/null +++ b/testsuite/timeout01/timeout_test.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef TIMEOUT_TEST_H +#define TIMEOUT_TEST_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +void timeout_test(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* TIMEOUT_TEST_H */ -- cgit v1.2.3