예제 #1
0
static void testcase2b(void)
{
  /*
   * continue after booting to actdead
   * 2. unplug a known to be plugged in charger
   * 3. wait for the shutdown to happen
   */
  module_t* state = load_state_module("ACT_DEAD", DSME_STATE_ACTDEAD);
  assert(!timer_exists());

  // unplug charger
  connect_charger(state);
  assert(!timer_exists());
  assert(message_queue_is_empty());
  disconnect_charger(state);
  assert(timer_exists());
  assert(message_queue_is_empty());

  // plug charger
  connect_charger(state);
  assert(!timer_exists());

  // unplug charger
  disconnect_charger(state);
  assert(message_queue_is_empty());
  assert(timer_exists());

  // wait for the shutdown
  trigger_timer();
  expect_shutdown(state);

  unload_module_under_test(state);
}
예제 #2
0
static void testcase10(void)
{
  /* try to shut down when an emergency call is ongoing */
  module_t* state = load_state_module("USER", DSME_STATE_USER);
  assert(!timer_exists());

  // unplug charger
  disconnect_charger(state);
  assert(message_queue_is_empty());
  assert(!timer_exists());

  // set up an emergency call
  DSM_MSGTYPE_SET_EMERGENCY_CALL_STATE msg =
      TEST_MSG_INIT(DSM_MSGTYPE_SET_EMERGENCY_CALL_STATE);
  msg.ongoing = true;
  send_message(state, &msg);

  // request shutdown
  DSM_MSGTYPE_SHUTDOWN_REQ msg2 = TEST_MSG_INIT(DSM_MSGTYPE_SHUTDOWN_REQ);
  send_message(state, &msg2);
  assert(message_queue_is_empty());
  assert(!timer_exists());

  // stop the emergency call
  msg.ongoing = false;
  send_message(state, &msg);
  expect_shutdown(state);

  unload_module_under_test(state);
}
예제 #3
0
static void testcase23(void)
{
  /* broken timers */

  // thermal shutdown when not able to create a timer
  dsme_create_timer_fails = 1;
  module_t* state = load_state_module("USER", DSME_STATE_USER);
  assert(!timer_exists());

  DSM_MSGTYPE_SET_THERMAL_STATE msg =
      TEST_MSG_INIT(DSM_MSGTYPE_SET_THERMAL_STATE);
  msg.overheated = true;
  send_message(state, &msg);

  DSM_MSGTYPE_STATE_CHANGE_IND* ind2;
  assert((ind2 = queued(DSM_MSGTYPE_STATE_CHANGE_IND)));
  assert(ind2->state == DSME_STATE_SHUTDOWN);
  free(ind2);

  DSM_MSGTYPE_SAVE_DATA_IND* ind3;
  assert((ind3 = queued(DSM_MSGTYPE_SAVE_DATA_IND)));
  free(ind3);

  assert(message_queue_is_empty());
  assert(timer_exists());

  trigger_timer();
  DSM_MSGTYPE_HWWD_KICK* ind4;
  assert((ind4 = queued(DSM_MSGTYPE_HWWD_KICK)));
  free(ind4);
  DSM_MSGTYPE_SHUTDOWN* msg2;
  assert((msg2 = queued(DSM_MSGTYPE_SHUTDOWN)));
  assert(msg2->runlevel == 0);
  free(msg2);
  assert(!timer_exists());
  assert(message_queue_is_empty());

  unload_module_under_test(state);

  // start in actdead and plug and unplug the charger, but timer fails
  dsme_create_timer_fails = 1;
  state = load_state_module("ACT_DEAD", DSME_STATE_ACTDEAD);
  assert(!timer_exists());

  connect_charger(state);
  assert(message_queue_is_empty());
  assert(!timer_exists());

  disconnect_charger(state);
  expect_shutdown(state);

  assert(!timer_exists());
  assert(message_queue_is_empty());

  unload_module_under_test(state);
}
예제 #4
0
static void testcase8(void)
{
  /* start in actdead and unplug the charger */
  module_t* state = load_state_module("ACT_DEAD", DSME_STATE_ACTDEAD);
  assert(!timer_exists());

  // unplug charger
  disconnect_charger(state);
  expect_shutdown(state);

  unload_module_under_test(state);
}
예제 #5
0
static void testcase4(void)
{
  /* request shutdown when charger is known to be unplugged */

  // boot to user state
  module_t* state = load_state_module("USER", DSME_STATE_USER);
  assert(!timer_exists());

  disconnect_charger(state);

  request_shutdown_expecting_shutdown(state);

  unload_module_under_test(state);
}
예제 #6
0
static void testcase13(void)
{
  /*
   * 1. request shutdown when charger is known to be unplugged
   * 2. start emergency call before timer runs out
   * 3. stop emergency call
   */
  module_t* state = load_state_module("USER", DSME_STATE_USER);
  assert(!timer_exists());

  // unplug charger
  disconnect_charger(state);
  assert(message_queue_is_empty());
  assert(!timer_exists());

  // request shutdown
  DSM_MSGTYPE_SHUTDOWN_REQ msg = TEST_MSG_INIT(DSM_MSGTYPE_SHUTDOWN_REQ);
  send_message(state, &msg);

  DSM_MSGTYPE_STATE_CHANGE_IND* ind;
  assert((ind = queued(DSM_MSGTYPE_STATE_CHANGE_IND)));
  assert(ind->state == DSME_STATE_SHUTDOWN);
  free(ind);

  DSM_MSGTYPE_SAVE_DATA_IND* ind2;
  assert((ind2 = queued(DSM_MSGTYPE_SAVE_DATA_IND)));
  free(ind2);

  assert(message_queue_is_empty());
  assert(timer_exists());

  // start emergency call
  DSM_MSGTYPE_SET_EMERGENCY_CALL_STATE msg2 =
      TEST_MSG_INIT(DSM_MSGTYPE_SET_EMERGENCY_CALL_STATE);
  msg2.ongoing = true;
  send_message(state, &msg2);
  assert(message_queue_is_empty());
  assert(!timer_exists());

  // stop emergency call
  msg2.ongoing = false;
  send_message(state, &msg2);

  // TODO: should we do a shutdown instead?
  assert(message_queue_is_empty());
  assert(!timer_exists());

  unload_module_under_test(state);
}
예제 #7
0
static void testcase5(void)
{
  /*
   * 1. request shutdown when charger is known to be unplugged
   * 2. plug in charger before timer runs out
   * => expect shutdown
   */
  module_t* state = load_state_module("USER", DSME_STATE_USER);
  assert(!timer_exists());

  // unplug charger
  disconnect_charger(state);
  assert(message_queue_is_empty());
  assert(!timer_exists());

  // request shutdown
  DSM_MSGTYPE_SHUTDOWN_REQ msg = TEST_MSG_INIT(DSM_MSGTYPE_SHUTDOWN_REQ);
  send_message(state, &msg);

  DSM_MSGTYPE_STATE_CHANGE_IND* ind;
  assert((ind = queued(DSM_MSGTYPE_STATE_CHANGE_IND)));
  assert(ind->state == DSME_STATE_SHUTDOWN);
  free(ind);

  DSM_MSGTYPE_SAVE_DATA_IND* ind2;
  assert((ind2 = queued(DSM_MSGTYPE_SAVE_DATA_IND)));
  free(ind2);

  assert(message_queue_is_empty());
  assert(timer_exists());

  // plug in charger
  connect_charger(state);
  assert(message_queue_is_empty());

  // expect shutdown
  trigger_timer();
  DSM_MSGTYPE_HWWD_KICK* ind3;
  assert((ind3 = queued(DSM_MSGTYPE_HWWD_KICK)));
  free(ind3);
  DSM_MSGTYPE_SHUTDOWN* msg2;
  assert((msg2 = queued(DSM_MSGTYPE_SHUTDOWN)));
  assert(msg2->runlevel == 0);
  free(msg2);
  assert(!timer_exists());
  assert(message_queue_is_empty());

  unload_module_under_test(state);
}
예제 #8
0
static void testcase6(void)
{
  module_t* state = load_state_module("USER", DSME_STATE_USER);
  assert(!timer_exists());

  // plug and unplug charger
  connect_charger(state);
  assert(message_queue_is_empty());
  assert(!timer_exists());

  disconnect_charger(state);
  assert(message_queue_is_empty());
  assert(!timer_exists());

  unload_module_under_test(state);
}
예제 #9
0
static void testcase11(void)
{
  /* reboot */
  module_t* state = load_state_module("USER", DSME_STATE_USER);
  assert(!timer_exists());

  // unplug charger
  disconnect_charger(state);
  assert(message_queue_is_empty());
  assert(!timer_exists());

  // request reboot
  DSM_MSGTYPE_REBOOT_REQ msg = TEST_MSG_INIT(DSM_MSGTYPE_REBOOT_REQ);
  send_message(state, &msg);
  expect_reboot(state);

  unload_module_under_test(state);
}
예제 #10
0
static void testcase19(void)
{
  /* request shutdown when an alarm is about to happen */

  // boot to user state
  module_t* state = load_state_module("USER", DSME_STATE_USER);
  assert(!timer_exists());
  disconnect_charger(state);

  // set up an alarm
  DSM_MSGTYPE_SET_ALARM_STATE msg = TEST_MSG_INIT(DSM_MSGTYPE_SET_ALARM_STATE);
  msg.alarm_set = true;
  send_message(state, &msg);

  request_shutdown_expecting_reboot(state);

  unload_module_under_test(state);
}
예제 #11
0
static void testcase12(void)
{
  /* shutdown on empty battery */
  module_t* state = load_state_module("USER", DSME_STATE_USER);
  assert(!timer_exists());

  // unplug charger
  disconnect_charger(state);

  // indicate an empty battery
  DSM_MSGTYPE_SET_BATTERY_STATE msg =
      TEST_MSG_INIT(DSM_MSGTYPE_SET_BATTERY_STATE);
  msg.empty = true;
  send_message(state, &msg);

  assert(timer_exists());
  trigger_timer();

  DSM_MSGTYPE_BATTERY_EMPTY_IND* ind;
  assert((ind = queued(DSM_MSGTYPE_BATTERY_EMPTY_IND)));
  free(ind);

  DSM_MSGTYPE_STATE_CHANGE_IND* ind2;
  assert((ind2 = queued(DSM_MSGTYPE_STATE_CHANGE_IND)));
  assert(ind2->state == DSME_STATE_SHUTDOWN);
  free(ind2);

  DSM_MSGTYPE_SAVE_DATA_IND* ind3;
  assert((ind3 = queued(DSM_MSGTYPE_SAVE_DATA_IND)));
  free(ind3);

  // expect shutdown
  trigger_timer();
  DSM_MSGTYPE_SHUTDOWN* msg2;
  assert((msg2 = queued(DSM_MSGTYPE_SHUTDOWN)));
  assert(msg2->runlevel == 0);
  free(msg2);
  assert(!timer_exists());
  assert(message_queue_is_empty());

  unload_module_under_test(state);
}
예제 #12
0
static void testcase9(void)
{
  /* start in actdead and plug and uplug the charger */
  module_t* state = load_state_module("ACT_DEAD", DSME_STATE_ACTDEAD);
  assert(!timer_exists());

  // plug charger
  connect_charger(state);
  assert(message_queue_is_empty());
  assert(!timer_exists());

  // unplug charger
  disconnect_charger(state);
  assert(message_queue_is_empty());
  assert(timer_exists());

  // wait for the shutdown
  trigger_timer();
  expect_shutdown(state);

  unload_module_under_test(state);
}