*
* \brief Message test.
*
- * \version $Id$
*
* \author Daniele Basile <asterix@develer.com>
*
#include <kern/msg.h>
#include <kern/proc.h>
-#include <kern/irq.h>
+#include <kern/signal.h>
+
+#include <mware/event.h>
#include <drv/timer.h>
+/*
+ * In the nightly build test, signals are disables, so this
+ * code won't compile.
+ * Since this code is used when we run "make check" it will be
+ * compiled and therefor tested there.
+ */
+#if CONFIG_KERN_SIGNALS
+
+
// Global settings for the test.
#define MAX_GLOBAL_COUNT 11040
-#define TEST_TIME_OUT_MS 10
+#define TEST_TIME_OUT_MS 5000
#define DELAY 5
// Settings for the test message.
/*
* These macros generate the code needed to create the test process functions.
*/
-#define RECV_PROC(num, sig) static void receiver_proc##num(void) \
- { \
- TestMsg *rec_msg; \
- for (;;) \
- { \
- sig_wait(sig); \
- kprintf("Proc[%d]..get message\n", num); \
- rec_msg = containerof(msg_get(&test_port##num), TestMsg, msg); \
- timer_delay(rec_msg->delay); \
- rec_msg->result += rec_msg->val; \
- kprintf("Proc[%d]..process message val[%d],delay[%d],res[%d]\n", num, rec_msg->val, rec_msg->delay, rec_msg->result); \
- msg_reply(&rec_msg->msg); \
- kprintf("Proc[%d] reply\n", num); \
- } \
- }
+#define RECV_PROC(num, sig) \
+static NORETURN void receiver_proc##num(void) \
+{ \
+ TestMsg *rec_msg; \
+ for(;;) \
+ { \
+ sig_wait(sig); \
+ kprintf("Proc[%d]..get message\n", num); \
+ rec_msg = containerof(msg_get(&test_port##num), TestMsg, msg); \
+ timer_delay(rec_msg->delay); \
+ rec_msg->result += rec_msg->val; \
+ kprintf("Proc[%d]..process message val[%d],delay[%d],res[%d]\n", num, rec_msg->val, rec_msg->delay, rec_msg->result); \
+ msg_reply(&rec_msg->msg); \
+ process_num++; \
+ kprintf("Proc[%d] reply\n", num); \
+ } \
+}
#define SEND_MSG(num) \
do { \
msg_put(&test_port##num, &msg##num.msg); \
} while(0)
-#define RECV_STACK(num) static cpu_stack_t receiver_stack##num[CONFIG_KERN_MINSTACKSIZE / sizeof(cpu_stack_t)]
+#define RECV_STACK(num) PROC_DEFINE_STACK(receiver_stack##num, KERN_MINSTACKSIZE * 2)
#define RECV_INIT_PROC(num) proc_new(receiver_proc##num, NULL, sizeof(receiver_stack##num), receiver_stack##num)
-#define RECV_INIT_MSG(num, proc,sig) msg_initPort(&test_port##num, event_createSignal(proc, sig))
+#define RECV_INIT_MSG(num, proc, sig) msg_initPort(&test_port##num, event_createSignal(proc, sig))
// A test message with the parameters and a result.
typedef struct
// Global count to check if the test is going ok.
static int count = 0;
+static int process_num;
// Our message port.
static MsgPort test_port0;
TestMsg msg4;
TestMsg msg5;
TestMsg *reply;
- ticks_t start_time = timer_clock();
// Allocate and start the test process
struct Process *recv0 = RECV_INIT_PROC(0);
// Send and wait the message
for (int i = 0; i < 23; ++i)
{
+ process_num = 0;
SEND_MSG(0);
SEND_MSG(1);
SEND_MSG(2);
SEND_MSG(5);
while(1)
{
- if(sig_waitTimeout(SIG_SINGLE, TEST_TIME_OUT_MS) && SIG_SINGLE)
+ sigmask_t sigs = sig_waitTimeout(SIG_SINGLE, ms_to_ticks(TEST_TIME_OUT_MS));
+ if (sigs & SIG_SINGLE)
{
// Wait for a reply...
- reply = containerof(msg_get(&test_portMain), TestMsg, msg);
- if(reply == NULL)
- break;
- count += reply->result;
- kprintf("Main recv[%d] count[%d]\n", reply->result, count);
+ while ((reply = (TestMsg *)msg_get(&test_portMain)))
+ {
+ count += reply->result;
+ kprintf("Main recv[%d] count[%d]\n", reply->result, count);
+ }
+ }
+
+ if (process_num == 6)
+ break;
+
+ if (sigs & SIG_TIMEOUT)
+ {
+ kputs("Main: sig timeout\n");
+ goto error;
}
}
}
kprintf("Message test finished..ok!\n");
return 0;
}
-
+
+error:
kprintf("Message test finished..fail!\n");
return -1;
}
{
kdbg_init();
- #if CONFIG_KERN_PREEMPT
- kprintf("Init Interrupt (preempt mode)..");
- irq_init();
- kprintf("Done.\n");
- #endif
-
kprintf("Init Timer..");
timer_init();
kprintf("Done.\n");
}
TEST_MAIN(msg);
+
+#endif /* CONFIG_KERN_SIGNALS */