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
|
/* 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 "cros_cbi.h"
#include "fan.h"
#include "hooks.h"
#include <zephyr/fff.h>
#include <zephyr/ztest.h>
DECLARE_FAKE_VALUE_FUNC(int, cros_cbi_get_fw_config,
enum cbi_fw_config_field_id, uint32_t *);
DEFINE_FAKE_VALUE_FUNC(int, cros_cbi_get_fw_config, enum cbi_fw_config_field_id,
uint32_t *);
DECLARE_FAKE_VOID_FUNC(fan_set_count, int);
DEFINE_FAKE_VOID_FUNC(fan_set_count, int);
int cros_cbi_get_fw_config_mock(enum cbi_fw_config_field_id field_id,
uint32_t *value)
{
*value = FW_FAN_PRESENT;
return 0;
}
int cros_cbi_get_fw_config_mock_no_fan(enum cbi_fw_config_field_id field_id,
uint32_t *value)
{
*value = FW_FAN_NOT_PRESENT;
return 0;
}
int cros_cbi_get_fw_config_mock_error(enum cbi_fw_config_field_id field_id,
uint32_t *value)
{
return -1;
}
void fan_set_count_mock(int count)
{
zassert_equal(0, count);
}
static void fan_before(void *fixture)
{
ARG_UNUSED(fixture);
RESET_FAKE(cros_cbi_get_fw_config);
RESET_FAKE(fan_set_count);
}
ZTEST_USER(fan, test_fan_init)
{
cros_cbi_get_fw_config_fake.custom_fake = cros_cbi_get_fw_config_mock;
fan_set_count_fake.custom_fake = fan_set_count_mock;
hook_notify(HOOK_INIT);
zassert_equal(1, cros_cbi_get_fw_config_fake.call_count);
zassert_equal(0, fan_set_count_fake.call_count);
}
ZTEST_USER(fan, test_fan_init_no_fan)
{
cros_cbi_get_fw_config_fake.custom_fake =
cros_cbi_get_fw_config_mock_no_fan;
fan_set_count_fake.custom_fake = fan_set_count_mock;
hook_notify(HOOK_INIT);
zassert_equal(1, cros_cbi_get_fw_config_fake.call_count);
zassert_equal(1, fan_set_count_fake.call_count);
}
ZTEST_USER(fan, test_fan_init_error_reading_cbi)
{
cros_cbi_get_fw_config_fake.custom_fake =
cros_cbi_get_fw_config_mock_error;
fan_set_count_fake.custom_fake = fan_set_count_mock;
hook_notify(HOOK_INIT);
zassert_equal(1, cros_cbi_get_fw_config_fake.call_count);
zassert_equal(0, fan_set_count_fake.call_count);
}
ZTEST_SUITE(fan, NULL, NULL, fan_before, NULL, NULL);
|