aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/coverage/Makefile142
-rw-r--r--test/coverage/chconf.h437
-rw-r--r--test/coverage/chcore.c128
-rw-r--r--test/coverage/chcore.h206
-rw-r--r--test/coverage/chtypes.h47
-rw-r--r--test/coverage/main.c43
-rw-r--r--test/coverage/readme.txt6
-rw-r--r--test/coverage/simcom.c66
8 files changed, 1075 insertions, 0 deletions
diff --git a/test/coverage/Makefile b/test/coverage/Makefile
new file mode 100644
index 000000000..8910d981d
--- /dev/null
+++ b/test/coverage/Makefile
@@ -0,0 +1,142 @@
+#
+# !!!! Do NOT edit this makefile with an editor which replace tabs by spaces !!!!
+#
+##############################################################################################
+#
+# On command line:
+#
+# make all = Create project
+#
+# make clean = Clean project files.
+#
+# To rebuild project do "make clean" and "make all".
+#
+
+##############################################################################################
+# Start of default section
+#
+
+TRGT = mingw32-
+CC = $(TRGT)gcc
+AS = $(TRGT)gcc -x assembler-with-cpp
+COV = gcov
+
+# List all default C defines here, like -D_DEBUG=1
+DDEFS =
+
+# List all default ASM defines here, like -D_DEBUG=1
+DADEFS =
+
+# List all default directories to look for include files here
+DINCDIR =
+
+# List the default directory to look for the libraries here
+DLIBDIR =
+
+# List all default libraries here
+DLIBS = -lws2_32
+
+#
+# End of default section
+##############################################################################################
+
+##############################################################################################
+# Start of user section
+#
+
+# Define project name here
+PROJECT = ch
+
+# Define linker script file here
+LDSCRIPT=
+
+# List all user C define here, like -D_DEBUG=1
+UDEFS =
+
+# Define ASM defines here
+UADEFS =
+
+# Imported source files
+include ../../src/kernel.mk
+include ../../test/test.mk
+
+# List C source files here
+SRC = chcore.c main.c simcom.c \
+ ${KERNSRC} \
+ ${TESTSRC}
+
+# List ASM source files here
+ASRC =
+
+# List all user directories here
+UINCDIR = ../../src/include ../../test
+
+# List the user directory to look for the libraries here
+ULIBDIR =
+
+# List all user libraries here
+ULIBS =
+
+# Define optimisation level here
+OPT = -ggdb -O0 -fomit-frame-pointer -fprofile-arcs -ftest-coverage
+
+#
+# End of user defines
+##############################################################################################
+
+
+INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))
+LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
+DEFS = $(DDEFS) $(UDEFS)
+ADEFS = $(DADEFS) $(UADEFS)
+OBJS = $(ASRC:.s=.o) $(SRC:.c=.o)
+LIBS = $(DLIBS) $(ULIBS)
+
+LDFLAGS = -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch -lgcov $(LIBDIR)
+ASFLAGS = -Wa,-amhls=$(<:.s=.lst) $(ADEFS)
+CPFLAGS = $(OPT) -Wall -Wstrict-prototypes -fverbose-asm -Wa,-alms=$(<:.c=.lst) $(DEFS)
+
+# Generate dependency information
+CPFLAGS += -MD -MP -MF .dep/$(@F).d
+
+#
+# makefile rules
+#
+
+all: $(OBJS) $(PROJECT).exe
+
+%o : %c
+ $(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@
+
+%o : %s
+ $(AS) -c $(ASFLAGS) $< -o $@
+
+%exe: $(OBJS)
+ $(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
+
+.PHONY: gcov
+gcov:
+ -mkdir gcov
+ $(COV) -u $(subst /,\,$(KERNSRC))
+ -mv *.gcov ./gcov
+
+.PHONY: clean
+clean:
+ -rm -f $(OBJS)
+ -rm -f $(PROJECT).exe
+ -rm -f $(PROJECT).map
+ -rm -f $(SRC:.c=.c.bak)
+ -rm -f $(SRC:.c=.lst)
+ -rm -f $(SRC:.c=.gcno)
+ -rm -f $(SRC:.c=.gcda)
+ -rm -f $(ASRC:.s=.s.bak)
+ -rm -f $(ASRC:.s=.lst)
+ -rm -fR .dep
+ -rm -fR gcov
+
+#
+# Include the dependency files, should be the last of the makefile
+#
+-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
+
+# *** EOF ***
diff --git a/test/coverage/chconf.h b/test/coverage/chconf.h
new file mode 100644
index 000000000..b979a9517
--- /dev/null
+++ b/test/coverage/chconf.h
@@ -0,0 +1,437 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file src/templates/chconf.h
+ * @brief Configuration file template.
+ * @addtogroup Config
+ * @{
+ */
+
+#ifndef _CHCONF_H_
+#define _CHCONF_H_
+
+/*===========================================================================*/
+/* Kernel parameters. */
+/*===========================================================================*/
+
+/**
+ * Frequency of the system timer that drives the system ticks. This also
+ * defines the system tick time unit.
+ */
+#if !defined(CH_FREQUENCY) || defined(__DOXYGEN__)
+#define CH_FREQUENCY 1000
+#endif
+
+/**
+ * This constant is the number of system ticks allowed for the threads before
+ * preemption occurs. This option is only meaningful if the option
+ * @p CH_USE_ROUNDROBIN is also active.
+ */
+#if !defined(CH_TIME_QUANTUM) || defined(__DOXYGEN__)
+#define CH_TIME_QUANTUM 20
+#endif
+
+/**
+ * If enabled then the use of nested @p chSysLock() / @p chSysUnlock()
+ * operations is allowed.<br>
+ * For performance and code size reasons the recommended setting is to leave
+ * this option disabled.<br>
+ * You can use this option if you need to merge ChibiOS/RT with external
+ * libraries that require nested lock/unlock operations.
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_USE_NESTED_LOCKS) || defined(__DOXYGEN__)
+#define CH_USE_NESTED_LOCKS FALSE
+#endif
+
+/**
+ * If specified then the kernel performs the round robin scheduling algorithm
+ * on threads of equal priority.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_ROUNDROBIN) || defined(__DOXYGEN__)
+#define CH_USE_ROUNDROBIN TRUE
+#endif
+
+/**
+ * Number of RAM bytes to use as system heap. If set to zero then the whole
+ * available RAM is used as system heap.
+ * @note In order to use the whole RAM as system heap the linker script must
+ * provide the @p __heap_base__ and @p __heap_end__ symbols.
+ * @note Requires @p CH_USE_HEAP.
+ */
+#if !defined(CH_HEAP_SIZE) || defined(__DOXYGEN__)
+#define CH_HEAP_SIZE 0x20000
+#endif
+
+/*===========================================================================*/
+/* Performance options. */
+/*===========================================================================*/
+
+/**
+ * If specified then time efficient rather than space efficient code is used
+ * when two possible implementations exist.
+ * @note This is not related to the compiler optimization options.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_OPTIMIZE_SPEED) || defined(__DOXYGEN__)
+#define CH_OPTIMIZE_SPEED FALSE
+#endif
+
+/**
+ * If enabled defines a CPU register to be used as storage for the global
+ * @p currp variable. Caching this variable in a register can greatly
+ * improve both space and time efficiency of the generated code. Another side
+ * effect is that one less register has to be saved during the context switch
+ * resulting in lower RAM usage and faster code.
+ * @note This option is only usable with the GCC compiler and is only useful
+ * on processors with many registers like ARM cores.
+ * @note If this option is enabled then ALL the libraries linked to the
+ * ChibiOS/RT code <b>must</b> be recompiled with the GCC option @p
+ * -ffixed-@<reg@>.
+ * @note This option must be enabled in the Makefile, it is listed here for
+ * documentation.
+ */
+#if defined(__DOXYGEN__)
+#define CH_CURRP_REGISTER_CACHE "reg"
+#endif
+
+/*===========================================================================*/
+/* Subsystem options. */
+/*===========================================================================*/
+
+/**
+ * If specified then the @p chThdWait() function is included in the kernel.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_WAITEXIT) || defined(__DOXYGEN__)
+#define CH_USE_WAITEXIT TRUE
+#endif
+
+/**
+ * If specified then the Semaphores APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_SEMAPHORES) || defined(__DOXYGEN__)
+#define CH_USE_SEMAPHORES TRUE
+#endif
+
+/**
+ * If enabled then the threads are enqueued on semaphores by priority rather
+ * than FIFO order.
+ * @note The default is @p FALSE. Enable this if you have special requirements.
+ * @note Requires @p CH_USE_SEMAPHORES.
+ */
+#if !defined(CH_USE_SEMAPHORES_PRIORITY) || defined(__DOXYGEN__)
+#define CH_USE_SEMAPHORES_PRIORITY FALSE
+#endif
+
+/**
+ * If specified then the Semaphores the @p chSemWaitSignal() API is included
+ * in the kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_SEMAPHORES.
+ */
+#if !defined(CH_USE_SEMSW) || defined(__DOXYGEN__)
+#define CH_USE_SEMSW TRUE
+#endif
+
+/**
+ * If specified then the Semaphores with timeout APIs are included in the
+ * kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_SEMAPHORES.
+ */
+#if !defined(CH_USE_SEMAPHORES_TIMEOUT) || defined(__DOXYGEN__)
+#define CH_USE_SEMAPHORES_TIMEOUT TRUE
+#endif
+
+/**
+ * If specified then the Mutexes APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_MUTEXES) || defined(__DOXYGEN__)
+#define CH_USE_MUTEXES TRUE
+#endif
+
+/**
+ * If specified then the Conditional Variables APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_MUTEXES.
+ */
+#if !defined(CH_USE_CONDVARS) || defined(__DOXYGEN__)
+#define CH_USE_CONDVARS TRUE
+#endif
+
+/**
+ * If specified then the Conditional Variables APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_CONDVARS.
+ */
+#if !defined(CH_USE_CONDVARS_TIMEOUT) || defined(__DOXYGEN__)
+#define CH_USE_CONDVARS_TIMEOUT TRUE
+#endif
+
+/**
+ * If specified then the Event flags APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_EVENTS) || defined(__DOXYGEN__)
+#define CH_USE_EVENTS TRUE
+#endif
+
+/**
+ * If specified then the @p chEvtWaitXXXTimeout() functions are included in
+ * the kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_EVENTS.
+ */
+#if !defined(CH_USE_EVENTS_TIMEOUT) || defined(__DOXYGEN__)
+#define CH_USE_EVENTS_TIMEOUT TRUE
+#endif
+
+/**
+ * If specified then the Synchronous Messages APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_MESSAGES) || defined(__DOXYGEN__)
+#define CH_USE_MESSAGES TRUE
+#endif
+
+/**
+ * If specified then the @p chMsgSendWithEvent() function is included in the
+ * kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_MESSAGES and @p CH_USE_EVENTS.
+ */
+#if !defined(CH_USE_MESSAGES_EVENT) || defined(__DOXYGEN__)
+#define CH_USE_MESSAGES_EVENT TRUE
+#endif
+
+/**
+ * If enabled then messages are served by priority rather than in FIFO order.
+ * @note The default is @p FALSE. Enable this if you have special requirements.
+ * @note Requires @p CH_USE_MESSAGES.
+ */
+#if !defined(CH_USE_MESSAGES_PRIORITY) || defined(__DOXYGEN__)
+#define CH_USE_MESSAGES_PRIORITY FALSE
+#endif
+
+/**
+ * If specified then the Asynchronous Messages (Mailboxes) APIs are included
+ * in the kernel.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_MAILBOXES) || defined(__DOXYGEN__)
+#define CH_USE_MAILBOXES TRUE
+#endif
+
+/**
+ * If specified then the I/O queues APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_SEMAPHORES.
+ */
+#if !defined(CH_USE_QUEUES) || defined(__DOXYGEN__)
+#define CH_USE_QUEUES TRUE
+#endif
+
+/**
+ * If specified then the half duplex queues APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_SEMAPHORES.
+ */
+#if !defined(CH_USE_QUEUES_HALFDUPLEX) || defined(__DOXYGEN__)
+#define CH_USE_QUEUES_HALFDUPLEX TRUE
+#endif
+
+/**
+ * If specified then the I/O queues with timeout APIs are included in the
+ * kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_QUEUES and @p CH_USE_SEMAPHORES_TIMEOUT.
+ */
+#if !defined(CH_USE_QUEUES_TIMEOUT) || defined(__DOXYGEN__)
+#define CH_USE_QUEUES_TIMEOUT TRUE
+#endif
+
+/**
+ * If specified then the full duplex serial driver APIs are included in the
+ * kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_QUEUES.
+ */
+#if !defined(CH_USE_SERIAL_FULLDUPLEX) || defined(__DOXYGEN__)
+#define CH_USE_SERIAL_FULLDUPLEX TRUE
+#endif
+
+/**
+ * If specified then the half duplex serial driver APIs are included in the
+ * kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_QUEUES_HALFDUPLEX.
+ */
+#if !defined(CH_USE_SERIAL_HALFDUPLEX) || defined(__DOXYGEN__)
+#define CH_USE_SERIAL_HALFDUPLEX TRUE
+#endif
+
+/**
+ * If specified then the memory heap allocator APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_MUTEXES or @p CH_USE_SEMAPHORES.
+ * @note Mutexes are recommended.
+ */
+#if !defined(CH_USE_HEAP) || defined(__DOXYGEN__)
+#define CH_USE_HEAP TRUE
+#endif
+
+/**
+ * If enabled enforces the use of the C-runtime @p malloc() and @p free()
+ * functions as backend for the system heap allocator.
+ * @note The default is @p FALSE.
+ * @note Requires @p CH_USE_HEAP.
+ */
+#if !defined(CH_USE_MALLOC_HEAP) || defined(__DOXYGEN__)
+#define CH_USE_MALLOC_HEAP FALSE
+#endif
+
+/**
+ * If specified then the memory pools allocator APIs are included in the
+ * kernel.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_MEMPOOLS) || defined(__DOXYGEN__)
+#define CH_USE_MEMPOOLS TRUE
+#endif
+
+/**
+ * If specified then the dynamic threads creation APIs are included in the
+ * kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_WAITEXIT.
+ */
+#if !defined(CH_USE_DYNAMIC) || defined(__DOXYGEN__)
+#define CH_USE_DYNAMIC TRUE
+#endif
+
+/*===========================================================================*/
+/* Debug options. */
+/*===========================================================================*/
+
+/**
+ * Debug option, if enabled then the checks on the API functions input
+ * parameters are activated.
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_DBG_ENABLE_CHECKS) || defined(__DOXYGEN__)
+#define CH_DBG_ENABLE_CHECKS FALSE
+#endif
+
+/**
+ * Debug option, if enabled then all the assertions in the kernel code are
+ * activated. This includes consistency checks inside the kernel, runtime
+ * anomalies and port-defined checks.
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_DBG_ENABLE_ASSERTS) || defined(__DOXYGEN__)
+#define CH_DBG_ENABLE_ASSERTS FALSE
+#endif
+
+/**
+ * Debug option, if enabled the context switch circular trace buffer is
+ * activated.
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_DBG_ENABLE_TRACE) || defined(__DOXYGEN__)
+#define CH_DBG_ENABLE_TRACE TRUE
+#endif
+
+/**
+ * Debug option, if enabled a runtime stack check is performed.
+ * @note The stack check is performed in a architecture/port dependent way. It
+ * may not be implemented at all.
+ */
+#if !defined(CH_DBG_ENABLE_STACK_CHECK) || defined(__DOXYGEN__)
+#define CH_DBG_ENABLE_STACK_CHECK TRUE
+#endif
+
+/**
+ * Debug option, if enabled the threads working area is filled with a byte
+ * pattern when a thread is created.
+ */
+#if !defined(CH_DBG_FILL_THREADS) || defined(__DOXYGEN__)
+#define CH_DBG_FILL_THREADS TRUE
+#endif
+
+/**
+ * Debug option, if enabled a field is added to the @p Thread structure that
+ * counts the system ticks occurred while executing the thread.
+ */
+#if !defined(CH_DBG_THREADS_PROFILING) || defined(__DOXYGEN__)
+#define CH_DBG_THREADS_PROFILING TRUE
+#endif
+
+/*===========================================================================*/
+/* Kernel hooks. */
+/*===========================================================================*/
+
+/**
+ * User fields added to the end of the @p Thread structure.
+ */
+#if !defined(THREAD_EXT_FIELDS) || defined(__DOXYGEN__)
+#define THREAD_EXT_FIELDS \
+struct { \
+ /* Add thread custom fields here.*/ \
+ /* The thread termination \p EventSource.*/ \
+};
+#endif
+
+/**
+ * User initialization code added to the @p chThdInit() API.
+ * @note It is invoked from within @p chThdInit().
+ */
+#if !defined(THREAD_EXT_INIT) || defined(__DOXYGEN__)
+#define THREAD_EXT_INIT(tp) { \
+ /* Add thread initialization code here.*/ \
+}
+#endif
+
+/**
+ * User finalization code added to the @p chThdExit() API.
+ * @note It is inserted into lock zone.
+ */
+#if !defined(THREAD_EXT_EXIT) || defined(__DOXYGEN__)
+#define THREAD_EXT_EXIT(tp) { \
+ /* Add thread finalization code here.*/ \
+}
+#endif
+
+/**
+ * Code inserted inside the idle thread loop immediately after an interrupt
+ * resumed execution.
+ */
+#if !defined(IDLE_LOOP_HOOK) || defined(__DOXYGEN__)
+#define IDLE_LOOP_HOOK() { \
+ /* Idle loop code here.*/ \
+}
+#endif
+
+#endif /* _CHCONF_H_ */
+
+/** @} */
diff --git a/test/coverage/chcore.c b/test/coverage/chcore.c
new file mode 100644
index 000000000..cdc87ceb5
--- /dev/null
+++ b/test/coverage/chcore.c
@@ -0,0 +1,128 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <windows.h>
+#include <stdio.h>
+
+#undef CDECL
+
+/**
+ * @addtogroup WIN32SIM_CORE
+ * @{
+ */
+
+#include <ch.h>
+
+static LARGE_INTEGER nextcnt;
+static LARGE_INTEGER slice;
+
+void init_simcom1(void);
+bool_t com1_conn_chkint(void);
+bool_t com1_in_chkint(void);
+bool_t com1_out_chkint(void);
+
+/*
+ * Simulated HW initialization.
+ */
+void InitCore(void) {
+ printf("ChibiOS/RT test simulator\n\n");
+ printf("Thread structure %d bytes\n", sizeof(Thread));
+ if (!QueryPerformanceFrequency(&slice)) {
+ fprintf(stderr, "QueryPerformanceFrequency() error");
+ fflush(stderr);
+ exit(1);
+ }
+ printf("Core Frequency %u Hz\n", (int)slice.LowPart);
+ slice.QuadPart /= CH_FREQUENCY;
+ QueryPerformanceCounter(&nextcnt);
+ nextcnt.QuadPart += slice.QuadPart;
+
+ init_simcom1();
+
+ fflush(stdout);
+}
+
+/*
+ * Interrupt simulation.
+ */
+void ChkIntSources(void) {
+ LARGE_INTEGER n;
+ bool_t rflag = FALSE;
+
+ if (com1_conn_chkint() || com1_in_chkint() || com1_out_chkint()) {
+ if (chSchRescRequiredI())
+ rflag = TRUE;
+ }
+
+ // Interrupt Timer simulation (10ms interval).
+ QueryPerformanceCounter(&n);
+ if (n.QuadPart > nextcnt.QuadPart) {
+ nextcnt.QuadPart += slice.QuadPart;
+ chSysTimerHandlerI();
+ if (chSchRescRequiredI())
+ rflag = TRUE;
+ }
+
+ if (rflag)
+ chSchDoRescheduleI();
+}
+
+/**
+ * Performs a context switch between two threads.
+ * @param otp the thread to be switched out
+ * @param ntp the thread to be switched in
+ */
+__attribute__((used))
+static void __dummy(Thread *otp, Thread *ntp) {
+ asm volatile (".globl @port_switch@8 \n\t" \
+ "@port_switch@8: \n\t" \
+ "push %ebp \n\t" \
+ "push %esi \n\t" \
+ "push %edi \n\t" \
+ "push %ebx \n\t" \
+ "movl %esp, 16(%ecx) \n\t" \
+ "movl 16(%edx), %esp \n\t" \
+ "pop %ebx \n\t" \
+ "pop %edi \n\t" \
+ "pop %esi \n\t" \
+ "pop %ebp \n\t" \
+ "ret");
+}
+
+/**
+ * Halts the system. In this implementation it just exits the simulation.
+ */
+__attribute__((fastcall))
+void port_halt(void) {
+
+ fprintf(stderr, "\nHalted\n");
+ fflush(stderr);
+ exit(2);
+}
+
+/**
+ * Threads return point, it just invokes @p chThdExit().
+ */
+void threadexit(void) {
+
+ asm volatile ("push %eax \n\t" \
+ "call _chThdExit");
+}
+
+/** @} */
diff --git a/test/coverage/chcore.h b/test/coverage/chcore.h
new file mode 100644
index 000000000..276b935da
--- /dev/null
+++ b/test/coverage/chcore.h
@@ -0,0 +1,206 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @addtogroup WIN32SIM_CORE
+ * @{
+ */
+
+#ifndef _CHCORE_H_
+#define _CHCORE_H_
+
+/**
+ * Macro defining the a simulated architecture into Win32.
+ */
+#define CH_ARCHITECTURE_WIN32SIM
+
+/**
+ * 32 bit stack alignment.
+ */
+typedef uint32_t stkalign_t;
+
+/**
+ * Generic x86 register.
+ */
+typedef void *regx86;
+
+/**
+ * Interrupt saved context.
+ * This structure represents the stack frame saved during a preemption-capable
+ * interrupt handler.
+ */
+struct extctx {
+};
+
+/**
+ * System saved context.
+ * @note In this demo the floating point registers are not saved.
+ */
+struct intctx {
+ regx86 ebx;
+ regx86 edi;
+ regx86 esi;
+ regx86 ebp;
+ regx86 eip;
+};
+
+/**
+ * Platform dependent part of the @p Thread structure.
+ * This structure usually contains just the saved stack pointer defined as a
+ * pointer to a @p intctx structure.
+ */
+struct context {
+ struct intctx volatile *esp;
+};
+
+#define APUSH(p, a) (p) -= sizeof(void *), *(void **)(p) = (void*)(a)
+
+/**
+ * Platform dependent part of the @p chThdInit() API.
+ * This code usually setup the context switching frame represented by a
+ * @p intctx structure.
+ */
+#define SETUP_CONTEXT(workspace, wsize, pf, arg) { \
+ uint8_t *esp = (uint8_t *)workspace + wsize; \
+ APUSH(esp, arg); \
+ APUSH(esp, threadexit); \
+ esp -= sizeof(struct intctx); \
+ ((struct intctx *)esp)->eip = pf; \
+ ((struct intctx *)esp)->ebx = 0; \
+ ((struct intctx *)esp)->edi = 0; \
+ ((struct intctx *)esp)->esi = 0; \
+ ((struct intctx *)esp)->ebp = 0; \
+ tp->p_ctx.esp = (struct intctx *)esp; \
+}
+
+/**
+ * Stack size for the system idle thread.
+ */
+#ifndef IDLE_THREAD_STACK_SIZE
+#define IDLE_THREAD_STACK_SIZE 256
+#endif
+
+/**
+ * Per-thread stack overhead for interrupts servicing, it is used in the
+ * calculation of the correct working area size.
+ * It requires stack space because the simulated "interrupt handlers" invoke
+ * Win32 APIs inside so it better have a lot of space.
+ */
+#ifndef INT_REQUIRED_STACK
+#define INT_REQUIRED_STACK 16384
+#endif
+
+/**
+ * Enforces a correct alignment for a stack area size value.
+ */
+#define STACK_ALIGN(n) ((((n) - 1) | (sizeof(stkalign_t) - 1)) + 1)
+
+ /**
+ * Computes the thread working area global size.
+ */
+#define THD_WA_SIZE(n) STACK_ALIGN(sizeof(Thread) + \
+ sizeof(void *) * 2 + \
+ sizeof(struct intctx) + \
+ sizeof(struct extctx) + \
+ (n) + (INT_REQUIRED_STACK))
+
+/**
+ * Macro used to allocate a thread working area aligned as both position and
+ * size.
+ */
+#define WORKING_AREA(s, n) stkalign_t s[THD_WA_SIZE(n) / sizeof(stkalign_t)];
+
+/**
+ * IRQ prologue code, inserted at the start of all IRQ handlers enabled to
+ * invoke system APIs.
+ */
+#define PORT_IRQ_PROLOGUE()
+
+/**
+ * IRQ epilogue code, inserted at the end of all IRQ handlers enabled to
+ * invoke system APIs.
+ */
+#define PORT_IRQ_EPILOGUE()
+
+/**
+ * IRQ handler function declaration.
+ */
+#define PORT_IRQ_HANDLER(id) void id(void)
+
+/**
+ * Simulator initialization.
+ */
+#define port_init() InitCore()
+
+/**
+ * Does nothing in this simulator.
+ */
+#define port_lock()
+
+/**
+ * Does nothing in this simulator.
+ */
+#define port_unlock()
+
+/**
+ * Does nothing in this simulator.
+ */
+#define port_lock_from_isr()
+
+/**
+ * Does nothing in this simulator.
+ */
+#define port_unlock_from_isr()
+
+/**
+ * Does nothing in this simulator.
+ */
+#define port_disable()
+
+/**
+ * Does nothing in this simulator.
+ */
+#define port_suspend()
+
+/**
+ * Does nothing in this simulator.
+ */
+#define port_enable()
+
+/**
+ * In the simulator this does a polling pass on the simulated interrupt
+ * sources.
+ */
+#define port_wait_for_interrupt() ChkIntSources()
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ __attribute__((fastcall)) void port_switch(Thread *otp, Thread *ntp);
+ __attribute__((fastcall)) void port_halt(void);
+ void InitCore(void);
+ void ChkIntSources(void);
+ void threadexit(void);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CHCORE_H_ */
+
+/** @} */
diff --git a/test/coverage/chtypes.h b/test/coverage/chtypes.h
new file mode 100644
index 000000000..354da269e
--- /dev/null
+++ b/test/coverage/chtypes.h
@@ -0,0 +1,47 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CHTYPES_H_
+#define _CHTYPES_H_
+
+#define __need_NULL
+#define __need_size_t
+#define __need_ptrdiff_t
+#include <stddef.h>
+
+#if !defined(_STDINT_H) && !defined(__STDINT_H_)
+#include <stdint.h>
+#endif
+
+typedef int8_t bool_t;
+typedef uint8_t tmode_t;
+typedef uint8_t tstate_t;
+typedef uint32_t tprio_t;
+typedef int32_t msg_t;
+typedef int32_t eventid_t;
+typedef uint32_t eventmask_t;
+typedef uint32_t systime_t;
+typedef int32_t cnt_t;
+
+#define INLINE inline
+#define PACK_STRUCT_STRUCT __attribute__((packed))
+#define PACK_STRUCT_BEGIN
+#define PACK_STRUCT_END
+
+#endif /* _CHTYPES_H_ */
diff --git a/test/coverage/main.c b/test/coverage/main.c
new file mode 100644
index 000000000..af8762562
--- /dev/null
+++ b/test/coverage/main.c
@@ -0,0 +1,43 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <windows.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <ch.h>
+#include <test.h>
+
+extern FullDuplexDriver COM1;
+
+/*
+ * Simulator main.
+ */
+int main(int argc, char *argv[]) {
+ msg_t result;
+
+ chSysInit();
+ result = TestThread(&COM1);
+ chThdSleepMilliseconds(1); /* Gives time to flush COM1 output queue */
+ fflush(stdout);
+ if (result)
+ exit(1);
+ else
+ exit(0);
+}
diff --git a/test/coverage/readme.txt b/test/coverage/readme.txt
new file mode 100644
index 000000000..fc3595112
--- /dev/null
+++ b/test/coverage/readme.txt
@@ -0,0 +1,6 @@
+In order to compute the code coverage:
+
+- Build the test application: make
+- Run the test suite: ch
+- Compute the code coverage: make gcov
+- Clear everything: make clean
diff --git a/test/coverage/simcom.c b/test/coverage/simcom.c
new file mode 100644
index 000000000..e8fceb76a
--- /dev/null
+++ b/test/coverage/simcom.c
@@ -0,0 +1,66 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/*
+ * Win32 COM port simulator (on stdout).
+ */
+
+#include <chconf.h>
+
+#include <windows.h>
+#include <stdio.h>
+
+#undef CDECL
+
+#include <ch.h>
+
+FullDuplexDriver COM1;
+
+static uint8_t com_ib[1024];
+static uint8_t com_ob[1024];
+
+void init_simcom1(void) {
+
+ chFDDInit(&COM1, com_ib, sizeof(com_ib), NULL, com_ob, sizeof(com_ob), NULL);
+}
+
+bool_t com1_conn_chkint(void) {
+
+ return FALSE;
+}
+
+bool_t com1_in_chkint(void) {
+
+ return FALSE;
+}
+
+bool_t com1_out_chkint(void) {
+ msg_t n;
+ bool_t rflag = FALSE;
+
+ while (TRUE) {
+ n = chFDDRequestDataI(&COM1);
+ if (n < 0) {
+ fflush(stdout);
+ return rflag;
+ }
+ fputc(n, stdout);
+ rflag = TRUE;
+ }
+}