summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-07-23 12:13:42 +0800
committerBill Richardson <wfrichar@chromium.org>2013-07-30 10:35:40 -0700
commit7431c57f476c6a9ceb7fb7f34480ecd142bb9306 (patch)
tree3002343b1906ee1f4ae1a49599ccfad319e4a0db
parent004236110b1f55a5a8e4e2c2e86f2d3f0c1b0a50 (diff)
downloadchrome-ec-7431c57f476c6a9ceb7fb7f34480ecd142bb9306.tar.gz
Reboot emulator with execv()
With this, the emulator is able to reboot itself without the help of run_host_test script. This makes it easier for development and also speeds up the test. BUG=chrome-os-partner:19235 TEST=Pass all tests BRANCH=None Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/62969 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org> (cherry picked from commit 99e4a977986f67334f6b82a87f23f66cf88f4cb4) Change-Id: Ib0b0cf4016e3f2cec8b164a4b4c89b5da438f2a4 Reviewed-on: https://gerrit.chromium.org/gerrit/63727 Commit-Queue: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r--chip/host/build.mk2
-rw-r--r--chip/host/reboot.c18
-rw-r--r--chip/host/reboot.h13
-rw-r--r--chip/host/system.c5
-rw-r--r--core/host/main.c11
-rw-r--r--include/host_test.h4
-rwxr-xr-xutil/run_host_test13
7 files changed, 50 insertions, 16 deletions
diff --git a/chip/host/build.mk b/chip/host/build.mk
index 10630914ce..694734cd57 100644
--- a/chip/host/build.mk
+++ b/chip/host/build.mk
@@ -8,5 +8,5 @@
CORE:=host
-chip-y=system.o gpio.o uart.o persistence.o flash.o lpc.o
+chip-y=system.o gpio.o uart.o persistence.o flash.o lpc.o reboot.o
chip-$(HAS_TASK_KEYSCAN)+=keyboard_raw.o
diff --git a/chip/host/reboot.c b/chip/host/reboot.c
new file mode 100644
index 0000000000..dd7c2b2fe2
--- /dev/null
+++ b/chip/host/reboot.c
@@ -0,0 +1,18 @@
+/* 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.
+ */
+
+/* Emulator self-reboot procedure */
+
+#include <string.h>
+#include <unistd.h>
+
+#include "host_test.h"
+#include "reboot.h"
+
+void emulator_reboot(void)
+{
+ char *argv[] = {strdup(__get_prog_name()), NULL};
+ execv(__get_prog_name(), argv);
+}
diff --git a/chip/host/reboot.h b/chip/host/reboot.h
new file mode 100644
index 0000000000..b6a7d817e6
--- /dev/null
+++ b/chip/host/reboot.h
@@ -0,0 +1,13 @@
+/* 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.
+ */
+
+/* Emulator self-reboot procedure */
+
+#ifndef __REBOOT_H
+#define __REBOOT_H
+
+void emulator_reboot(void);
+
+#endif
diff --git a/chip/host/system.c b/chip/host/system.c
index 3a0be45a20..e726245ee0 100644
--- a/chip/host/system.c
+++ b/chip/host/system.c
@@ -11,6 +11,7 @@
#include "host_test.h"
#include "panic.h"
#include "persistence.h"
+#include "reboot.h"
#include "system.h"
#include "timer.h"
#include "util.h"
@@ -146,7 +147,7 @@ test_mockable void system_reset(int flags)
save_flags |= RESET_FLAG_HARD;
if (save_flags)
save_reset_flags(save_flags);
- exit(EXIT_CODE_RESET);
+ emulator_reboot();
}
test_mockable void system_hibernate(uint32_t seconds, uint32_t microseconds)
@@ -226,7 +227,7 @@ static void __jump_resetvec(void)
{
save_time(get_time());
ramdata_set_persistent();
- exit(EXIT_CODE_RESET);
+ emulator_reboot();
}
static void __ro_jump_resetvec(void)
diff --git a/core/host/main.c b/core/host/main.c
index e7b6718ac8..ed8985670b 100644
--- a/core/host/main.c
+++ b/core/host/main.c
@@ -18,8 +18,17 @@
#define CPUTS(outstr) cputs(CC_SYSTEM, outstr)
#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args)
-int main(void)
+const char *__prog_name;
+
+const char *__get_prog_name(void)
{
+ return __prog_name;
+}
+
+int main(int argc, char **argv)
+{
+ __prog_name = argv[0];
+
register_test_end_hook();
flash_pre_init();
diff --git a/include/host_test.h b/include/host_test.h
index 0c1b95d1fa..6eac0bc62e 100644
--- a/include/host_test.h
+++ b/include/host_test.h
@@ -9,7 +9,9 @@
#define __CROS_EC_HOST_TEST_H
/* Emulator exit codes */
-#define EXIT_CODE_RESET (1 << 6) /* Leave six bits for SYSTEM_RESET_* */
#define EXIT_CODE_HIBERNATE (1 << 7)
+/* Get emulator executable name */
+const char *__get_prog_name(void);
+
#endif /* __CROS_EC_HOST_TEST_H */
diff --git a/util/run_host_test b/util/run_host_test
index e36e8d8280..ba59454527 100755
--- a/util/run_host_test
+++ b/util/run_host_test
@@ -11,12 +11,9 @@ import time
TIMEOUT=10
-EXIT_CODE_REBOOT = (1 << 6)
-
RESULT_ID_TIMEOUT = 0
RESULT_ID_PASS = 1
RESULT_ID_FAIL = 2
-RESULT_ID_REBOOT = 3
EXPECT_LIST = [pexpect.TIMEOUT, 'Pass!', 'Fail!']
@@ -40,11 +37,7 @@ def RunOnce(test_name, log, timeout_secs):
return child.expect(EXPECT_LIST)
except pexpect.EOF:
child.close()
- if child.exitstatus & EXIT_CODE_REBOOT:
- sys.stderr.write('System rebooting\n')
- return RESULT_ID_REBOOT
- else:
- raise
+ raise
finally:
child.kill(15)
@@ -53,9 +46,7 @@ tee_log = Tee(log)
test_name = sys.argv[1]
start_time = time.time()
-result_id = RESULT_ID_REBOOT
-while result_id == RESULT_ID_REBOOT:
- result_id = RunOnce(test_name, tee_log, start_time + TIMEOUT - time.time())
+result_id = RunOnce(test_name, tee_log, start_time + TIMEOUT - time.time())
elapsed_time = time.time() - start_time
failed = False