2014-03-05 18:33:30 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Freie Universität Berlin
|
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2014-03-05 18:33:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup tests
|
|
|
|
* @{
|
|
|
|
* @file
|
|
|
|
* @brief Test if the queue used for messaging is fair.
|
|
|
|
* @author René Kijewski <rene.kijewski@fu-berlin.de>
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "msg.h"
|
|
|
|
#include "sched.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "vtimer.h"
|
|
|
|
|
2014-07-04 15:39:43 +02:00
|
|
|
#define STACK_SIZE (KERNEL_CONF_STACKSIZE_DEFAULT + KERNEL_CONF_STACKSIZE_MAIN)
|
2014-03-05 18:33:30 +01:00
|
|
|
|
|
|
|
#define NUM_CHILDREN (3)
|
|
|
|
#define NUM_ITERATIONS (10)
|
|
|
|
|
|
|
|
static char stacks[NUM_CHILDREN][STACK_SIZE];
|
2014-07-06 22:57:56 +02:00
|
|
|
static kernel_pid_t pids[NUM_CHILDREN];
|
2014-03-05 18:33:30 +01:00
|
|
|
static char names[NUM_CHILDREN][8];
|
|
|
|
|
2014-08-06 09:44:31 +02:00
|
|
|
static kernel_pid_t parent_pid = KERNEL_PID_UNDEF;
|
2014-03-05 18:33:30 +01:00
|
|
|
|
2014-03-04 20:20:01 +01:00
|
|
|
static void *child_fun(void *arg)
|
2014-03-05 18:33:30 +01:00
|
|
|
{
|
2014-10-15 00:04:58 +02:00
|
|
|
printf("Start of %s.\n", (char*) arg);
|
2014-03-05 18:33:30 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < NUM_ITERATIONS; ++i) {
|
|
|
|
msg_t m;
|
|
|
|
m.type = i + 1;
|
2014-10-15 00:04:58 +02:00
|
|
|
m.content.ptr = (char*) arg;
|
2014-10-20 16:49:40 +02:00
|
|
|
msg_send(&m, parent_pid);
|
2014-03-05 18:33:30 +01:00
|
|
|
}
|
|
|
|
|
2014-10-15 00:04:58 +02:00
|
|
|
printf("End of %s.\n", (char*) arg);
|
2014-03-04 20:20:01 +01:00
|
|
|
return NULL;
|
2014-03-05 18:33:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
puts("Start.");
|
2014-04-10 22:28:35 +02:00
|
|
|
parent_pid = sched_active_pid;
|
2014-03-05 18:33:30 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < NUM_CHILDREN; ++i) {
|
2014-07-09 07:15:19 +02:00
|
|
|
snprintf(names[i], sizeof(names[i]), "child%2u", i + 1);
|
2014-03-05 18:33:30 +01:00
|
|
|
pids[i] = thread_create(stacks[i],
|
2014-07-09 07:15:19 +02:00
|
|
|
sizeof(stacks[i]),
|
2014-03-05 18:33:30 +01:00
|
|
|
PRIORITY_MAIN + 1,
|
|
|
|
CREATE_WOUT_YIELD | CREATE_STACKTEST,
|
|
|
|
child_fun,
|
2014-10-15 00:04:58 +02:00
|
|
|
names[i],
|
2014-03-05 18:33:30 +01:00
|
|
|
names[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int last_iteration = 0;
|
|
|
|
for (int i = 0; i < NUM_ITERATIONS * NUM_CHILDREN; ++i) {
|
|
|
|
msg_t m;
|
|
|
|
msg_receive(&m);
|
|
|
|
int cur_iteration = (int) m.type;
|
|
|
|
char *child = (char *) m.content.ptr;
|
|
|
|
|
2014-05-12 02:44:57 +02:00
|
|
|
printf("Received message from %s, iteration %d / %u: %s\n",
|
2014-03-05 18:33:30 +01:00
|
|
|
child, cur_iteration, NUM_ITERATIONS,
|
|
|
|
cur_iteration >= last_iteration ? "okay" : "ERROR");
|
|
|
|
|
|
|
|
last_iteration = cur_iteration;
|
|
|
|
vtimer_usleep(25 * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
puts("Done.");
|
|
|
|
return 0;
|
|
|
|
}
|