summaryrefslogtreecommitdiff
path: root/test/pingpong.c
blob: f08a9554a76f45f77062a455f2b2340dfdd1c065 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 *
 * Tasks for scheduling test.
 */

#include "common.h"
#include "console.h"
#include "task.h"
#include "test_util.h"
#include "timer.h"
#include "util.h"

#define TEST_COUNT 3000

static int wake_count[3];

int task_abc(void *data)
{
	int myid = task_get_current() - TASK_ID_TESTA;
	task_id_t next = task_get_current() + 1;
	if (next > TASK_ID_TESTC)
		next = TASK_ID_TESTA;

	task_wait_event(-1);

	ccprintf("\n[starting Task %c]\n", ('A' + myid));

	while (1) {
		wake_count[myid]++;
		if (myid == 2 && wake_count[myid] == TEST_COUNT) {
			if (wake_count[0] == TEST_COUNT &&
			    wake_count[1] == TEST_COUNT)
				test_pass();
			else
				test_fail();
			wake_count[0] = wake_count[1] = wake_count[2] = 0;
			task_wait_event(-1);
		} else {
			task_set_event(next, TASK_EVENT_WAKE, 1);
		}
	}

	return EC_SUCCESS;
}

int task_tick(void *data)
{
	task_wait_event(-1);
	ccprintf("\n[starting Task T]\n");

	/* Wake up every tick */
	while (1) {
		/* Wait for timer interrupt message */
		usleep(3000);
	}

	return EC_SUCCESS;
}

void run_test(void)
{
	wait_for_task_started();
	task_wake(TASK_ID_TICK);
	task_wake(TASK_ID_TESTA);
}