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
|
/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <zephyr/ztest.h>
#include "task.h"
#include "test/drivers/test_state.h"
#include "test/drivers/utils.h"
#include "timer.h"
struct tasks_fixture {
timestamp_t fake_time;
};
static void *setup(void)
{
static struct tasks_fixture fixture;
return &fixture;
}
static void before(void *f)
{
struct tasks_fixture *fixture = f;
fixture->fake_time.val = 0;
}
static void after(void *f)
{
ARG_UNUSED(f);
get_time_mock = NULL;
}
ZTEST_SUITE(tasks, drivers_predicate_post_main, setup, before, after, NULL);
ZTEST(tasks, test_enable_irq)
{
arch_irq_disable(0);
task_enable_irq(0);
zassert_true(arch_irq_is_enabled(0));
}
ZTEST(tasks, test_interrupt_context)
{
zassert_false(in_interrupt_context());
}
ZTEST_F(tasks, test_timer_arm_before_now)
{
timestamp_t deadline = {
.val = 5,
};
fixture->fake_time.val = 15;
get_time_mock = &fixture->fake_time;
zassert_ok(timer_arm(deadline, TASK_ID_MOTIONSENSE));
zassert_equal(*task_get_event_bitmap(TASK_ID_MOTIONSENSE) &
TASK_EVENT_TIMER,
TASK_EVENT_TIMER);
}
ZTEST_F(tasks, test_timer_arm_busy)
{
timestamp_t deadline = {
.val = UINT64_C(5000000),
};
fixture->fake_time.val = 0;
get_time_mock = &fixture->fake_time;
zassert_ok(timer_arm(deadline, TASK_ID_MOTIONSENSE));
zassert_equal(EC_ERROR_BUSY, timer_arm(deadline, TASK_ID_MOTIONSENSE));
}
ZTEST(tasks, test_get_event_bitmap_invalid_tid)
{
zassert_is_null(
task_get_event_bitmap(TASK_ID_COUNT + EXTRA_TASK_COUNT));
}
|