mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-10 17:41:54 +00:00
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>
This commit is contained in:
@@ -8,4 +8,5 @@
|
||||
|
||||
CHIP:=host
|
||||
|
||||
board-y=board.o chipset.o
|
||||
board-y=board.o
|
||||
board-$(HAS_TASK_CHIPSET)+=chipset.o
|
||||
|
||||
@@ -8,7 +8,13 @@
|
||||
#include <stdio.h>
|
||||
#include "chipset.h"
|
||||
#include "common.h"
|
||||
#include "hooks.h"
|
||||
#include "task.h"
|
||||
#include "test_util.h"
|
||||
|
||||
static int chipset_state = CHIPSET_STATE_SOFT_OFF;
|
||||
static int power_on_req;
|
||||
static int power_off_req;
|
||||
|
||||
test_mockable void chipset_reset(int cold_reset)
|
||||
{
|
||||
@@ -20,15 +26,40 @@ test_mockable void chipset_force_shutdown(void)
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
#ifdef HAS_TASK_CHIPSET
|
||||
test_mockable int chipset_in_state(int state_mask)
|
||||
{
|
||||
return state_mask & CHIPSET_STATE_SOFT_OFF;
|
||||
return state_mask & chipset_state;
|
||||
}
|
||||
|
||||
void test_chipset_on(void)
|
||||
{
|
||||
if (chipset_in_state(CHIPSET_STATE_ON))
|
||||
return;
|
||||
power_on_req = 1;
|
||||
task_wake(TASK_ID_CHIPSET);
|
||||
}
|
||||
|
||||
void test_chipset_off(void)
|
||||
{
|
||||
if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
|
||||
return;
|
||||
power_off_req = 1;
|
||||
task_wake(TASK_ID_CHIPSET);
|
||||
}
|
||||
|
||||
test_mockable void chipset_task(void)
|
||||
{
|
||||
while (1)
|
||||
task_wait_event(-1);
|
||||
while (1) {
|
||||
while (!power_on_req)
|
||||
task_wait_event(-1);
|
||||
power_on_req = 0;
|
||||
hook_notify(HOOK_CHIPSET_PRE_INIT);
|
||||
chipset_state = CHIPSET_STATE_ON;
|
||||
hook_notify(HOOK_CHIPSET_STARTUP);
|
||||
while (!power_off_req)
|
||||
task_wait_event(-1);
|
||||
power_off_req = 0;
|
||||
chipset_state = CHIPSET_STATE_SOFT_OFF;
|
||||
hook_notify(HOOK_CHIPSET_SHUTDOWN);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -62,27 +62,43 @@
|
||||
return EC_ERROR_UNKNOWN; \
|
||||
} while (0)
|
||||
|
||||
/* Hooks gcov_flush() for test coverage report generation */
|
||||
void register_test_end_hook(void);
|
||||
|
||||
/* Test entry point */
|
||||
void run_test(void);
|
||||
|
||||
/* Resets test error count */
|
||||
void test_reset(void);
|
||||
|
||||
/* Reports test pass */
|
||||
void test_pass(void);
|
||||
|
||||
/* Reports test failure */
|
||||
void test_fail(void);
|
||||
|
||||
/* Prints test result, including number of failed tests */
|
||||
void test_print_result(void);
|
||||
|
||||
/* Returns the number of failed tests */
|
||||
int test_get_error_count(void);
|
||||
|
||||
/* Simulates host command sent from the host */
|
||||
int test_send_host_command(int command, int version, const void *params,
|
||||
int params_size, void *resp, int resp_size);
|
||||
|
||||
/* Number of failed tests */
|
||||
extern int __test_error_count;
|
||||
|
||||
/* Simulates UART input */
|
||||
void uart_inject_char(char *s, int sz);
|
||||
|
||||
#define UART_INJECT(s) uart_inject_char(s, strlen(s));
|
||||
|
||||
/* Simulates chipset power on */
|
||||
void test_chipset_on(void);
|
||||
|
||||
/* Simulates chipset power off */
|
||||
void test_chipset_off(void);
|
||||
|
||||
#endif /* __CROS_EC_TEST_UTIL_H */
|
||||
|
||||
@@ -29,7 +29,7 @@ test-list-$(BOARD_wolf)=
|
||||
|
||||
# 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
|
||||
test-list-host+=thermal flash queue kb_8042 extpwr_gpio console_edit system
|
||||
|
||||
console_edit-y=console_edit.o
|
||||
extpwr_gpio-y=extpwr_gpio.o
|
||||
@@ -46,6 +46,7 @@ power_button-y=power_button.o
|
||||
powerdemo-y=powerdemo.o
|
||||
queue-y=queue.o
|
||||
stress-y=stress.o
|
||||
system-y=system.o
|
||||
thermal-y=thermal.o
|
||||
thermal-scale=200
|
||||
timer_calib-y=timer_calib.o
|
||||
|
||||
107
test/system.c
Normal file
107
test/system.c
Normal file
@@ -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, ¶ms,
|
||||
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, ¶ms,
|
||||
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, ¶ms,
|
||||
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();
|
||||
}
|
||||
18
test/system.tasklist
Normal file
18
test/system.tasklist
Normal file
@@ -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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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(CHIPSET, chipset_task, NULL, TASK_STACK_SIZE)
|
||||
Reference in New Issue
Block a user