summaryrefslogtreecommitdiff
path: root/test/system.c
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-07-23 01:58:49 +0800
committerChromeBot <chrome-bot@google.com>2013-07-22 16:09:47 -0700
commit8218aa1346e533423d445018a289f938f36bcebd (patch)
tree4ad96173a6f980034bc842e670f6ee87df59aed9 /test/system.c
parent2d205f97cbfd7eecf9d6cf6b9a44c4f667e9be79 (diff)
downloadchrome-ec-8218aa1346e533423d445018a289f938f36bcebd.tar.gz
Add system_common unit test
This tests reboot-on-ap-shutdown. BUG=chrome-os-partner:19236 TEST=Pass the test BRANCH=None Change-Id: Ic1a07670f82646e85d014d52a2aba0835319c212 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/62855 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'test/system.c')
-rw-r--r--test/system.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/test/system.c b/test/system.c
new file mode 100644
index 0000000000..a116fa3cb6
--- /dev/null
+++ b/test/system.c
@@ -0,0 +1,107 @@
+/* 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 system_common.
+ */
+
+#include "common.h"
+#include "console.h"
+#include "host_command.h"
+#include "system.h"
+#include "test_util.h"
+#include "timer.h"
+#include "util.h"
+
+#define TEST_STATE_STEP_2 (1 << 0)
+#define TEST_STATE_FAIL (1 << 1)
+
+static int test_reboot_on_shutdown(void)
+{
+ struct ec_params_reboot_ec params;
+
+ /* Fails if the system reboots unexpectedly */
+ system_set_scratchpad(TEST_STATE_FAIL);
+
+ test_chipset_on();
+ msleep(30);
+
+ params.cmd = EC_REBOOT_COLD;
+ params.flags = EC_REBOOT_FLAG_ON_AP_SHUTDOWN;
+
+ TEST_ASSERT(test_send_host_command(
+ EC_CMD_REBOOT_EC, 0, &params,
+ sizeof(params), NULL, 0) == EC_SUCCESS);
+
+ system_set_scratchpad(TEST_STATE_STEP_2);
+ test_chipset_off();
+ msleep(30);
+
+ /* Shouldn't reach here */
+ return EC_ERROR_UNKNOWN;
+}
+
+static int test_cancel_reboot(void)
+{
+ struct ec_params_reboot_ec params;
+
+ /* Fails if the system reboots unexpectedly */
+ system_set_scratchpad(TEST_STATE_FAIL);
+
+ test_chipset_on();
+ msleep(30);
+
+ params.cmd = EC_REBOOT_COLD;
+ params.flags = EC_REBOOT_FLAG_ON_AP_SHUTDOWN;
+
+ TEST_ASSERT(test_send_host_command(
+ EC_CMD_REBOOT_EC, 0, &params,
+ sizeof(params), NULL, 0) == EC_SUCCESS);
+
+ params.cmd = EC_REBOOT_CANCEL;
+ params.flags = 0;
+
+ TEST_ASSERT(test_send_host_command(
+ EC_CMD_REBOOT_EC, 0, &params,
+ sizeof(params), NULL, 0) == EC_SUCCESS);
+
+ test_chipset_off();
+ msleep(30);
+
+ return EC_SUCCESS;
+}
+
+static void run_test_step1(void)
+{
+ if (test_reboot_on_shutdown() != EC_SUCCESS)
+ test_fail();
+}
+
+static void run_test_step2(void)
+{
+ if (test_cancel_reboot() != EC_SUCCESS)
+ test_fail();
+
+ system_set_scratchpad(0);
+ test_pass();
+}
+
+static void fail_and_clean_up(void)
+{
+ system_set_scratchpad(0);
+ test_fail();
+}
+
+void run_test(void)
+{
+ uint32_t state = system_get_scratchpad();
+
+ test_reset();
+
+ if (state == 0)
+ run_test_step1();
+ else if (state & TEST_STATE_STEP_2)
+ run_test_step2();
+ else if (state & TEST_STATE_FAIL)
+ fail_and_clean_up();
+}