summaryrefslogtreecommitdiffstats
path: root/testsuite/swi01
diff options
context:
space:
mode:
authorChristian Mauderer <christian.mauderer@embedded-brains.de>2012-05-10 15:06:10 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2012-05-10 16:30:49 +0200
commitee6b343cbaa434d8c31a4d71dac5316b4404da35 (patch)
tree3ed32e5a8c1458207346eb0b203a2457ec109e44 /testsuite/swi01
parentMove rtems_bsd_thread0_ucred (diff)
downloadrtems-libbsd-ee6b343cbaa434d8c31a4d71dac5316b4404da35.tar.bz2
Provide SWI(9) and TIMEOUT(9)
Diffstat (limited to 'testsuite/swi01')
-rw-r--r--testsuite/swi01/Makefile29
-rw-r--r--testsuite/swi01/init.c76
-rw-r--r--testsuite/swi01/swi_test.c208
-rw-r--r--testsuite/swi01/swi_test.h45
4 files changed, 358 insertions, 0 deletions
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
+ * <rtems@embedded-brains.de>
+ *
+ * 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 <stdlib.h>
+#include <assert.h>
+
+#include <rtems.h>
+
+#include <freebsd/bsd.h>
+
+#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 <rtems/confdefs.h>
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
+ * <rtems@embedded-brains.de>
+ *
+ * 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 <assert.h>
+
+#include <stdio.h>
+#include <unistd.h>
+
+#include <freebsd/machine/rtems-bsd-config.h>
+
+#include <freebsd/sys/types.h>
+#include <freebsd/sys/systm.h>
+
+#include <freebsd/sys/param.h>
+#include <freebsd/sys/bus.h>
+#include <freebsd/sys/interrupt.h>
+
+#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
+ * <rtems@embedded-brains.de>
+ *
+ * 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 */