summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/mock/battery_mock.c211
-rw-r--r--common/mock/build.mk1
2 files changed, 212 insertions, 0 deletions
diff --git a/common/mock/battery_mock.c b/common/mock/battery_mock.c
new file mode 100644
index 0000000000..63e94c660b
--- /dev/null
+++ b/common/mock/battery_mock.c
@@ -0,0 +1,211 @@
+/* Copyright 2021 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.
+ */
+
+#include "battery.h"
+#include "string.h"
+
+/*****************************************************************************
+ * Battery functions needed to enable CONFIG_BATTERY
+ */
+static int battery_soc_value = 100;
+int board_get_battery_soc(void)
+{
+ return battery_soc_value;
+}
+void set_battery_soc(int new_value)
+{
+ battery_soc_value = new_value;
+}
+
+static int battery_status_value;
+int battery_status(int *status)
+{
+ *status = battery_status_value;
+ return EC_SUCCESS;
+}
+void set_battery_status(int new_value)
+{
+ battery_status_value = new_value;
+}
+
+static int battery_serial_number_value;
+int battery_serial_number(int *serial)
+{
+ *serial = battery_serial_number_value;
+ return EC_SUCCESS;
+}
+void set_battery_serial_number(int new_value)
+{
+ battery_serial_number_value = new_value;
+}
+
+static int battery_design_voltage_value = 5000;
+int battery_design_voltage(int *voltage)
+{
+ *voltage = battery_design_voltage_value;
+ return EC_SUCCESS;
+}
+void set_battery_design_voltage(int new_value)
+{
+ battery_design_voltage_value = new_value;
+}
+
+static int battery_mode_value;
+int battery_get_mode(int *mode)
+{
+ *mode = battery_mode_value;
+ return EC_SUCCESS;
+}
+void set_battery_mode(int new_value)
+{
+ battery_mode_value = new_value;
+}
+
+static int battery_soc_abs_value = 100;
+int battery_state_of_charge_abs(int *percent)
+{
+ *percent = battery_soc_abs_value;
+ return EC_SUCCESS;
+}
+void set_battery_soc_abs(int new_value)
+{
+ battery_soc_abs_value = new_value;
+}
+
+static int battery_remaining_capacity_value = 100;
+int battery_remaining_capacity(int *capacity)
+{
+ *capacity = battery_remaining_capacity_value;
+ return EC_SUCCESS;
+}
+void set_battery_remaining_capacity(int new_value)
+{
+ battery_remaining_capacity_value = new_value;
+}
+
+static int battery_full_charge_capacity_value = 100;
+int battery_full_charge_capacity(int *capacity)
+{
+ *capacity = battery_full_charge_capacity_value;
+ return EC_SUCCESS;
+}
+void set_battery_full_charge_capacity(int new_value)
+{
+ battery_full_charge_capacity_value = new_value;
+}
+
+static int battery_design_capacity_value = 100;
+int battery_design_capacity(int *capacity)
+{
+ *capacity = battery_design_capacity_value;
+ return EC_SUCCESS;
+}
+void set_battery_design_capacity(int new_value)
+{
+ battery_design_capacity_value = new_value;
+}
+
+static int battery_time_to_empty_value = 60;
+int battery_time_to_empty(int *minutes)
+{
+ *minutes = battery_time_to_empty_value;
+ return EC_SUCCESS;
+}
+void set_battery_time_to_empty(int new_value)
+{
+ battery_time_to_empty_value = new_value;
+}
+
+static int battery_run_time_to_empty_value = 60;
+int battery_run_time_to_empty(int *minutes)
+{
+ *minutes = battery_run_time_to_empty_value;
+ return EC_SUCCESS;
+}
+void set_battery_run_time_to_empty(int new_value)
+{
+ battery_run_time_to_empty_value = new_value;
+}
+
+static int battery_time_to_full_value;
+int battery_time_to_full(int *minutes)
+{
+ *minutes = battery_time_to_full_value;
+ return EC_SUCCESS;
+}
+void set_battery_time_to_full(int new_value)
+{
+ battery_time_to_full_value = new_value;
+}
+
+#define MAX_DEVICE_NAME_LENGTH 40
+static char battery_device_name_value[MAX_DEVICE_NAME_LENGTH+1] = "?";
+int battery_device_name(char *dest, int size)
+{
+ int i;
+
+ for (i = 0; i < size && i < MAX_DEVICE_NAME_LENGTH; ++i)
+ dest[i] = battery_device_name_value[i];
+ for (; i < size; ++i)
+ dest[i] = '\0';
+ return EC_SUCCESS;
+}
+void set_battery_device_name(char *new_value)
+{
+ int i;
+ int size = strlen(new_value);
+
+ for (i = 0; i < size && i < MAX_DEVICE_NAME_LENGTH; ++i)
+ battery_device_name_value[i] = new_value[i];
+ for (; i < MAX_DEVICE_NAME_LENGTH+1; ++i)
+ battery_device_name_value[i] = '\0';
+}
+
+#define MAX_DEVICE_CHEMISTRY_LENGTH 40
+static char battery_device_chemistry_value[MAX_DEVICE_CHEMISTRY_LENGTH+1] = "?";
+int battery_device_chemistry(char *dest, int size)
+{
+ int i;
+
+ for (i = 0; i < size && i < MAX_DEVICE_CHEMISTRY_LENGTH; ++i)
+ dest[i] = battery_device_chemistry_value[i];
+ for (; i < size; ++i)
+ dest[i] = '\0';
+ return EC_SUCCESS;
+}
+void set_battery_device_chemistry(char *new_value)
+{
+ int i;
+ int size = strlen(new_value);
+
+ for (i = 0; i < size && i < MAX_DEVICE_CHEMISTRY_LENGTH; ++i)
+ battery_device_chemistry_value[i] = new_value[i];
+ for (; i < MAX_DEVICE_CHEMISTRY_LENGTH+1; ++i)
+ battery_device_chemistry_value[i] = '\0';
+}
+
+static int battery_current_value = 3000;
+static int battery_desired_current_value = 3000;
+static int battery_desired_voltage_value = 5000;
+static int battery_is_present_value = BP_YES;
+static int battery_temperature_value = 20;
+static int battery_voltage_value = 5000;
+void battery_get_params(struct batt_params *batt)
+{
+ struct batt_params batt_new = {0};
+
+ batt_new.temperature = battery_temperature_value;
+ batt_new.state_of_charge = battery_soc_value;
+ batt_new.voltage = battery_voltage_value;
+ batt_new.current = battery_current_value;
+ batt_new.desired_voltage = battery_desired_voltage_value;
+ batt_new.desired_current = battery_desired_current_value;
+ batt_new.remaining_capacity = battery_remaining_capacity_value;
+ batt_new.full_capacity = battery_full_charge_capacity_value;
+ batt_new.status = battery_status_value;
+ batt_new.is_present = battery_is_present_value;
+
+ memcpy(batt, &batt_new, sizeof(*batt));
+}
diff --git a/common/mock/build.mk b/common/mock/build.mk
index bc824259a6..bacf52069b 100644
--- a/common/mock/build.mk
+++ b/common/mock/build.mk
@@ -4,6 +4,7 @@
# See common/mock/README.md for more information.
+mock-$(HAS_MOCK_BATTERY) += battery_mock.o
mock-$(HAS_MOCK_FP_SENSOR) += fp_sensor_mock.o
mock-$(HAS_MOCK_FPSENSOR_DETECT) += fpsensor_detect_mock.o
mock-$(HAS_MOCK_FPSENSOR_STATE) += fpsensor_state_mock.o