summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRong Chang <rongchang@chromium.org>2013-07-24 08:22:48 -0700
committerChromeBot <chrome-bot@google.com>2013-07-24 13:07:13 -0700
commit6c280b1b324d56416732ff532f0d8d69d2dbdfad (patch)
treeb31a23b435b8174eb4c187cd80c6280257e00528 /test
parent7b95d397feab540fa35d47ce810628e03af34e4b (diff)
downloadchrome-ec-6c280b1b324d56416732ff532f0d8d69d2dbdfad.tar.gz
Move TPSChrome charging temperature range to battery pack
This change moves vendor specific temperature ranges to battery pack files or board setup files. And added a host test case to verify that does not change x86 smart battery charging state machine behavior. BUG=chrome-os-partner:21181 BRANCH=None TEST=manual build test: util/ecmakeall.sh hosttests: make hosttests && make runtests Change-Id: I48e76826b5555f64b78e3c063ce5f02416c72aa2 Signed-off-by: Rong Chang <rongchang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/62978 Reviewed-by: Vic Yang <victoryang@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/build.mk2
-rw-r--r--test/sbs_charging.c112
-rw-r--r--test/sbs_charging.tasklist19
-rw-r--r--test/test_config.mk1
4 files changed, 134 insertions, 0 deletions
diff --git a/test/build.mk b/test/build.mk
index 3e09caa0fb..e2212fa71a 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -31,6 +31,7 @@ test-list-$(BOARD_bolt)=
# Emulator tests
test-list-host=mutex pingpong utils kb_scan kb_mkbp lid_sw power_button hooks
test-list-host+=thermal flash queue kb_8042 extpwr_gpio console_edit system
+test-list-host+=sbs_charging
console_edit-y=console_edit.o
extpwr_gpio-y=extpwr_gpio.o
@@ -46,6 +47,7 @@ pingpong-y=pingpong.o
power_button-y=power_button.o
powerdemo-y=powerdemo.o
queue-y=queue.o
+sbs_charging-y=sbs_charging.o
stress-y=stress.o
system-y=system.o
thermal-y=thermal.o
diff --git a/test/sbs_charging.c b/test/sbs_charging.c
new file mode 100644
index 0000000000..ef2337997e
--- /dev/null
+++ b/test/sbs_charging.c
@@ -0,0 +1,112 @@
+/* Copyright (c) 2013 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.
+ *
+ * Test lid switch.
+ */
+
+#include "battery_pack.h"
+#include "charge_state.h"
+#include "chipset.h"
+#include "common.h"
+#include "smart_battery.h"
+#include "task.h"
+#include "test_util.h"
+#include "util.h"
+
+#define WAIT_CHARGER_TASK 500
+
+static int mock_ac_present = 1;
+static int mock_chipset_state = CHIPSET_STATE_ON;
+static int is_shutdown;
+
+/* Mock GPIOs */
+int gpio_get_level(enum gpio_signal signal)
+{
+ if (signal == GPIO_AC_PRESENT)
+ return mock_ac_present;
+ return 0;
+}
+
+void chipset_force_shutdown(void)
+{
+ is_shutdown = 1;
+}
+
+int chipset_in_state(int state_mask)
+{
+ return state_mask & mock_chipset_state;
+}
+
+/* Setup init condition */
+static void test_setup(void)
+{
+ const struct battery_info *bat_info = battery_get_info();
+
+ /* 50% of charge */
+ sb_write(SB_RELATIVE_STATE_OF_CHARGE, 50);
+ sb_write(SB_ABSOLUTE_STATE_OF_CHARGE, 50);
+ /* 25 degree Celsius */
+ sb_write(SB_TEMPERATURE, 250 + 2731);
+ /* Normal voltage */
+ sb_write(SB_VOLTAGE, bat_info->voltage_normal);
+ sb_write(SB_CHARGING_VOLTAGE, bat_info->voltage_max);
+ sb_write(SB_CHARGING_CURRENT, 4000);
+ /* Discharging at 100mAh */
+ sb_write(SB_CURRENT, -100);
+ /* Unplug AC */
+ mock_ac_present = 0;
+}
+
+static int wait_charging_state(void)
+{
+ enum power_state state;
+ task_wake(TASK_ID_CHARGER);
+ msleep(WAIT_CHARGER_TASK);
+ state = charge_get_state();
+ ccprintf("[CHARGING TEST] state = %d\n", state);
+ return state;
+}
+
+static int test_charge_state(void)
+{
+ enum power_state state;
+
+ state = wait_charging_state();
+ /* Plug AC, charging at 1000mAh */
+ ccprintf("[CHARGING TEST] AC on\n");
+ mock_ac_present = 1;
+ sb_write(SB_CURRENT, 1000);
+ state = wait_charging_state();
+ TEST_ASSERT(state == PWR_STATE_CHARGE);
+
+ /* Unplug AC, discharging at 1000mAh */
+ ccprintf("[CHARGING TEST] AC off\n");
+ mock_ac_present = 0;
+ sb_write(SB_CURRENT, -1000);
+ state = wait_charging_state();
+ TEST_ASSERT(state == PWR_STATE_DISCHARGE);
+
+ /* Discharging overtemp */
+ ccprintf("[CHARGING TEST] AC off, batt temp = 90 C\n");
+ mock_ac_present = 0;
+ sb_write(SB_CURRENT, -1000);
+
+ state = wait_charging_state();
+ TEST_ASSERT(state == PWR_STATE_DISCHARGE);
+ sb_write(SB_TEMPERATURE, CELSIUS_TO_DECI_KELVIN(90));
+ state = wait_charging_state();
+ TEST_ASSERT(is_shutdown);
+ TEST_ASSERT(state == PWR_STATE_DISCHARGE);
+
+ return EC_SUCCESS;
+}
+
+void run_test(void)
+{
+ test_setup();
+
+ RUN_TEST(test_charge_state);
+
+ test_print_result();
+}
diff --git a/test/sbs_charging.tasklist b/test/sbs_charging.tasklist
new file mode 100644
index 0000000000..6ca1e65553
--- /dev/null
+++ b/test/sbs_charging.tasklist
@@ -0,0 +1,19 @@
+/* Copyright (c) 2013 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.
+ */
+
+/**
+ * List of enabled tasks in the priority order
+ *
+ * The first one has the lowest priority.
+ *
+ * For each task, use the macro TASK_TEST(n, r, d, s) where :
+ * 'n' in the name of the task
+ * 'r' in the main routine of the task
+ * 'd' in an opaque parameter passed to the routine at startup
+ * 's' is the stack size in bytes; must be a multiple of 8
+ */
+#define CONFIG_TEST_TASK_LIST \
+ TASK_TEST(CHARGER, charger_task, NULL, TASK_STACK_SIZE) \
+ TASK_TEST(CHIPSET, chipset_task, NULL, TASK_STACK_SIZE)
diff --git a/test/test_config.mk b/test/test_config.mk
index 968519fa22..9837c0fe01 100644
--- a/test/test_config.mk
+++ b/test/test_config.mk
@@ -7,3 +7,4 @@
#
CFLAGS-kb_8042=-DKB_8042
+CFLAGS-sbs_charging=-DSMART_BATTERY_CHARGER