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
|
/* 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 "board_chipset.h"
#include "ec_commands.h"
#include "hooks.h"
#include "usb_pd.h"
#include "usbc_ppc.h"
#include <zephyr/kernel.h>
#include <zephyr/ztest.h>
static int battery_soc_abs_value = 50;
int battery_state_of_charge_abs(int *percent)
{
*percent = battery_soc_abs_value;
return EC_SUCCESS;
}
int charger_get_min_bat_pct_for_power_on(void)
{
return 2;
}
int ppc_init(int port)
{
return EC_SUCCESS;
}
enum pd_cc_states pd_get_task_cc_state(int port)
{
return PD_CC_NONE;
}
ZTEST_USER(board_chipset, test_good_battery_normal_boot)
{
timestamp_t start_time;
uint64_t time_diff_us;
battery_soc_abs_value = 50;
start_time = get_time();
hook_notify(HOOK_CHIPSET_PRE_INIT);
time_diff_us = get_time().val - start_time.val;
zassert_true(time_diff_us <= 20000, "CHIPSET_PRE_INIT hook delayed",
NULL);
}
ZTEST_USER(board_chipset, test_low_battery_normal_boot)
{
timestamp_t start_time;
uint64_t time_diff_us;
battery_soc_abs_value = 1;
start_time = get_time();
hook_notify(HOOK_CHIPSET_PRE_INIT);
time_diff_us = get_time().val - start_time.val;
zassert_true(time_diff_us <= 20000, "CHIPSET_PRE_INIT hook delayed",
NULL);
}
ZTEST_USER(board_chipset, test_low_battery_delayed_boot)
{
timestamp_t start_time;
uint64_t time_diff_us;
battery_soc_abs_value = 1;
/* The PD connect event delays the power on sequence */
hook_notify(HOOK_USB_PD_CONNECT);
start_time = get_time();
hook_notify(HOOK_CHIPSET_PRE_INIT);
time_diff_us = get_time().val - start_time.val;
zassert_true(time_diff_us > 500000, "CHIPSET_PRE_INIT hook not delayed",
NULL);
}
static void test_before(void *data)
{
ARG_UNUSED(data);
reset_pp5000_inited();
}
ZTEST_SUITE(board_chipset, NULL, NULL, test_before, NULL, NULL);
|