summaryrefslogtreecommitdiff
path: root/zephyr/test/skyrim/src/common/fan.c
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/test/skyrim/src/common/fan.c')
-rw-r--r--zephyr/test/skyrim/src/common/fan.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/zephyr/test/skyrim/src/common/fan.c b/zephyr/test/skyrim/src/common/fan.c
new file mode 100644
index 0000000000..4968938298
--- /dev/null
+++ b/zephyr/test/skyrim/src/common/fan.c
@@ -0,0 +1,92 @@
+/* Copyright 2023 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/devicetree.h>
+#include <zephyr/fff.h>
+#include <zephyr/ztest.h>
+
+#include <cros_board_info.h>
+#include <cros_cbi.h>
+#include <fan.h>
+#include <hooks.h>
+
+FAKE_VOID_FUNC(fan_set_count, int);
+FAKE_VALUE_FUNC(int, cros_cbi_get_fw_config, enum cbi_fw_config_field_id,
+ uint32_t *);
+FAKE_VALUE_FUNC(int, cbi_get_board_version, uint32_t *);
+
+void fan_init(void);
+bool board_supports_pcore_ocp(void);
+
+static bool fan_present;
+static int board_version;
+
+static int cros_cbi_get_fw_config_mock(enum cbi_fw_config_field_id field_id,
+ uint32_t *value)
+{
+ if (field_id != FW_FAN)
+ return -EINVAL;
+
+ *value = fan_present ? FW_FAN_PRESENT : FW_FAN_NOT_PRESENT;
+ return 0;
+}
+
+static int cbi_get_board_version_mock(uint32_t *value)
+{
+ *value = board_version;
+ return EC_SUCCESS;
+}
+
+static void fan_before(void *fixture)
+{
+ ARG_UNUSED(fixture);
+ RESET_FAKE(fan_set_count);
+ RESET_FAKE(cros_cbi_get_fw_config);
+ RESET_FAKE(cbi_get_board_version);
+
+ cros_cbi_get_fw_config_fake.custom_fake = cros_cbi_get_fw_config_mock;
+ cbi_get_board_version_fake.custom_fake = cbi_get_board_version_mock;
+}
+
+ZTEST_SUITE(fan, NULL, NULL, fan_before, NULL, NULL);
+
+ZTEST(fan, board_supports_pcore_ocp)
+{
+ /* Only supported for board version > 3. */
+ board_version = 2;
+ zassert_false(board_supports_pcore_ocp());
+ board_version = 3;
+ zassert_false(board_supports_pcore_ocp());
+ board_version = 4;
+ zassert_true(board_supports_pcore_ocp());
+}
+
+ZTEST(fan, fan_init)
+{
+ /* Only disable fans on board version >= 3. */
+ fan_present = false;
+ board_version = 2;
+ fan_init();
+ zassert_equal(fan_set_count_fake.call_count, 0);
+
+ fan_present = true;
+ board_version = 3;
+ fan_init();
+ zassert_equal(fan_set_count_fake.call_count, 0);
+
+ fan_present = true;
+ board_version = 4;
+ fan_init();
+ zassert_equal(fan_set_count_fake.call_count, 0);
+
+ fan_present = false;
+ board_version = 3;
+ fan_init();
+ zassert_equal(fan_set_count_fake.call_count, 1);
+
+ fan_present = false;
+ board_version = 4;
+ fan_init();
+ zassert_equal(fan_set_count_fake.call_count, 2);
+}