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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/* Copyright 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 "cts_common.h"
#include "task.h"
#include "timer.h"
static int repeat_count;
static int wake_count[3];
void clean_state(void)
{
wake_count[0] = wake_count[1] = wake_count[2] = 0;
}
void task_abc(void *data)
{
int task_id = task_get_current();
int id = task_id - TASK_ID_A;
task_id_t next = task_id + 1;
if (next > TASK_ID_C)
next = TASK_ID_A;
task_wait_event(-1);
CPRINTS("%c Starting", 'A' + id);
cflush();
while (1) {
wake_count[id]++;
if (id == 2 && wake_count[id] == repeat_count) {
task_set_event(TASK_ID_CTS, TASK_EVENT_WAKE);
task_wait_event(-1);
} else {
task_set_event(next, TASK_EVENT_WAKE);
task_wait_event(-1);
}
}
}
void 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);
}
enum cts_rc test_task_switch(void)
{
uint32_t event;
repeat_count = 3000;
task_wake(TASK_ID_A);
event = task_wait_event(5 * SECOND);
if (event != TASK_EVENT_WAKE) {
CPRINTS("Woken up by unexpected event: 0x%08x", event);
return CTS_RC_FAILURE;
}
if (wake_count[0] != repeat_count || wake_count[1] != repeat_count) {
CPRINTS("Unexpected counter values: %d %d %d",
wake_count[0], wake_count[1], wake_count[2]);
return CTS_RC_FAILURE;
}
/* TODO: Verify no tasks are ready, no events are pending. */
if (*task_get_event_bitmap(TASK_ID_A)
|| *task_get_event_bitmap(TASK_ID_B)
|| *task_get_event_bitmap(TASK_ID_C)) {
CPRINTS("Events are pending");
return CTS_RC_FAILURE;
}
return CTS_RC_SUCCESS;
}
enum cts_rc test_task_priority(void)
{
uint32_t event;
repeat_count = 2;
task_wake(TASK_ID_A);
task_wake(TASK_ID_C);
event = task_wait_event(5 * SECOND);
if (event != TASK_EVENT_WAKE) {
CPRINTS("Woken up by unexpected event: 0x%08x", event);
return CTS_RC_FAILURE;
}
if (wake_count[0] != repeat_count - 1
|| wake_count[1] != repeat_count - 1) {
CPRINTS("Unexpected counter values: %d %d %d",
wake_count[0], wake_count[1], wake_count[2]);
return CTS_RC_FAILURE;
}
/* TODO: Verify no tasks are ready, no events are pending. */
if (*task_get_event_bitmap(TASK_ID_A)
|| *task_get_event_bitmap(TASK_ID_B)
|| *task_get_event_bitmap(TASK_ID_C)) {
CPRINTS("Events are pending");
return CTS_RC_FAILURE;
}
return CTS_RC_SUCCESS;
}
static void recurse(int x)
{
CPRINTS("+%d", x);
msleep(1);
recurse(x + 1);
CPRINTS("-%d", x);
}
enum cts_rc test_stack_overflow(void)
{
recurse(0);
return CTS_RC_FAILURE;
}
#include "cts_testlist.h"
void cts_task(void)
{
task_wake(TASK_ID_TICK);
cts_main_loop(tests, "Task");
task_wait_event(-1);
}
|