예제 #1
0
/* 300sec > DSME SNOOZE TIMEOUT */
static void test_init_alarm_in5min(void)
{
  load_alarmtracker(time(0)+300);

  /* INTERNAL MSGs */
  DSM_MSGTYPE_SET_ALARM_STATE *msg;
  assert(message_queue_is_empty());

  /* DBUS IF */
  assert(dbusmsgq_async->len == 0);
  assert(dbusmsgq_blocking->len == 0);

  /* DSMESOCK */
  assert((msg = queued_dsmesock(DSM_MSGTYPE_SET_ALARM_STATE)));
  assert(msg->alarm_set);
  free(msg);
  assert(g_slist_length(dsmesock_broadcasts)==0);

  assert(timer_exists());
  sumtime(first_timer_seconds());
  trigger_timer();

  assert(!message_queue_is_empty());
  assert((msg = queued(DSM_MSGTYPE_SET_ALARM_STATE)));
  assert(msg->alarm_set);
  free(msg);
  assert(dbusmsgq_async->len == 0);
  assert(dbusmsgq_blocking->len == 0);
  assert(g_slist_length(dsmesock_broadcasts)==0);

  assert(!timer_exists());

  unload_alarmtracker();
}
예제 #2
0
static void testcase17(void)
{
  /*
   * 1. overheat
   * 2. cool down before shutdown; we still have to shutdown
   */
  module_t* state = load_state_module("USER", DSME_STATE_USER);
  assert(!timer_exists());

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

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

  // cool down
  DSM_MSGTYPE_SET_THERMAL_STATE msg2 =
      TEST_MSG_INIT(DSM_MSGTYPE_SET_THERMAL_STATE);
  msg2.overheated = false;
  send_message(state, &msg2);

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

  trigger_timer();
  expect_shutdown(state);
  unload_module_under_test(state);
}
예제 #3
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);
}
예제 #4
0
static void expect_shutdown_or_reboot(module_t*    module,
                                      dsme_state_t state,
                                      int          runlevel)
{
  DSM_MSGTYPE_STATE_CHANGE_IND* ind;
  assert((ind = queued(DSM_MSGTYPE_STATE_CHANGE_IND)));
  assert(ind->state == state);
  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());

  trigger_timer();

  DSM_MSGTYPE_SHUTDOWN* msg3;
  assert((msg3 = queued(DSM_MSGTYPE_SHUTDOWN)));
  assert(msg3->runlevel == runlevel);
  free(msg3);

  assert(!timer_exists());
  assert(message_queue_is_empty());
}
예제 #5
0
static void request_shutdown_expecting_actdead(module_t* state)
{
  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_ACTDEAD);
  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());

  trigger_timer();

  DSM_MSGTYPE_CHANGE_RUNLEVEL* msg2;
  assert((msg2 = queued(DSM_MSGTYPE_CHANGE_RUNLEVEL)));
  assert(msg2->runlevel == 5);
  free(msg2);

  assert(!timer_exists());
  assert(message_queue_is_empty());
}
예제 #6
0
static void testcase21(void)
{
  /* non-rd_mode cases and cal problems */

  // non-rd_mode
  rd_mode = "";
  setenv("BOOTSTATE", "DIIBADAABA", true);
  module_t* state = load_module_under_test("../modules/libstate.so");
  unsetenv("BOOTSTATE");
  DSM_MSGTYPE_STATE_CHANGE_IND* ind;
  assert((ind = queued(DSM_MSGTYPE_STATE_CHANGE_IND)));
  assert(ind->state == DSME_STATE_MALF);
  free(ind);
  assert(message_queue_is_empty());
  assert(timer_exists());
  trigger_timer();
  DSM_MSGTYPE_HWWD_KICK* ind3;
  assert((ind3 = queued(DSM_MSGTYPE_HWWD_KICK)));
  free(ind3);
  DSM_MSGTYPE_SHUTDOWN* msg;
  assert((msg = queued(DSM_MSGTYPE_SHUTDOWN)));
  assert(msg->runlevel == 8);
  free(msg);
  assert(message_queue_is_empty());
  assert(!timer_exists());
  unload_module_under_test(state);

  // cal problem
  rd_mode = 0;
  setenv("BOOTSTATE", "DIIBADAABA", true);
  state = load_module_under_test("../modules/libstate.so");
  unsetenv("BOOTSTATE");
  assert((ind = queued(DSM_MSGTYPE_STATE_CHANGE_IND)));
  assert(ind->state == DSME_STATE_MALF);
  free(ind);
  assert(message_queue_is_empty());
  assert(timer_exists());
  trigger_timer();
  assert((ind3 = queued(DSM_MSGTYPE_HWWD_KICK)));
  free(ind3);
  assert((msg = queued(DSM_MSGTYPE_SHUTDOWN)));
  assert(msg->runlevel == 8);
  free(msg);
  assert(message_queue_is_empty());
  assert(!timer_exists());
  unload_module_under_test(state);
}
예제 #7
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);
}
예제 #8
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);
}
예제 #9
0
/* Set alarm with com.nokia.time dbus interface */
static void test_init_set_alarm_in5min(void)
{
  load_alarmtracker(0);

  DBusMessage* alarm_setup_msg = dbus_message_new_signal("/com/nokia/time", "com.nokia.time", "next_bootup_event");

  time_t new_alarm_time = time(0)+300;
  dbus_message_append_args(alarm_setup_msg,
                           DBUS_TYPE_INT32, &new_alarm_time);

  dsme_dbus_stub_send_signal(alarm_setup_msg);
  free(alarm_setup_msg);

  assert(!message_queue_is_empty());
  assert(queued(DSM_MSGTYPE_WAIT));
  assert(message_queue_is_empty());

  DSM_MSGTYPE_WAKEUP wakeupmsg =
      TEST_MSG_INIT(DSM_MSGTYPE_WAKEUP);
  send_message(alarmtracker_module, &wakeupmsg);


  /* INTERNAL MSGs */
  DSM_MSGTYPE_SET_ALARM_STATE *msg;
  assert(message_queue_is_empty());

  /* DBUS IF */
  assert(dbusmsgq_async->len == 0);
  assert(dbusmsgq_blocking->len == 0);

  /* DSMESOCK */
  assert((msg = queued_dsmesock(DSM_MSGTYPE_SET_ALARM_STATE)));
  assert(msg->alarm_set);
  free(msg);
  assert(g_slist_length(dsmesock_broadcasts)==0);

  assert(timer_exists());
  sumtime(first_timer_seconds());
  trigger_timer();

  assert(!message_queue_is_empty());
  assert((msg = queued(DSM_MSGTYPE_SET_ALARM_STATE)));
  assert(msg->alarm_set);
  free(msg);
  assert(dbusmsgq_async->len == 0);
  assert(dbusmsgq_blocking->len == 0);
  assert(g_slist_length(dsmesock_broadcasts)==0);

  assert(!timer_exists());

  unload_alarmtracker();
}
예제 #10
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);
}
irom static void gpio_init_timer(gpio_t *gpio)
{
	const gpio_config_entry_t *cfg = get_config(gpio);

	gpio->timer.delay = 0;

	gpio_init_output(gpio);

	if(cfg->timer.direction == gpio_up)
		gpio_output_set(0, 1 << gpio->index, 0, 0);
	else
		gpio_output_set(1 << gpio->index, 0, 0, 0);

	if(cfg->timer.autotrigger)
		trigger_timer(gpio, 1);
}
예제 #12
0
static void testcase18(void)
{
  /*
   * 1. start in actdead
   * 2. request startup
   */
  module_t* state = load_state_module("ACT_DEAD", DSME_STATE_ACTDEAD);
  assert(!timer_exists());
  assert(message_queue_is_empty());

  // query state
  DSM_MSGTYPE_STATE_QUERY msg = TEST_MSG_INIT(DSM_MSGTYPE_STATE_QUERY);
  send_message(state, &msg);
  DSM_MSGTYPE_STATE_CHANGE_IND* ind;
  assert((ind = queued(DSM_MSGTYPE_STATE_CHANGE_IND)));
  assert(ind->state == DSME_STATE_ACTDEAD);
  free(ind);
  assert(message_queue_is_empty());
  assert(!timer_exists());

  // request startup
  DSM_MSGTYPE_POWERUP_REQ msg2 = TEST_MSG_INIT(DSM_MSGTYPE_POWERUP_REQ);
  send_message(state, &msg2);

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

  assert(timer_exists());
  trigger_timer();

  DSM_MSGTYPE_CHANGE_RUNLEVEL* req;
  assert((req = queued(DSM_MSGTYPE_CHANGE_RUNLEVEL)));
  assert(req->runlevel == 2);
  assert(message_queue_is_empty());
  assert(!timer_exists());

  // query state
  send_message(state, &msg);
  assert((ind = queued(DSM_MSGTYPE_STATE_CHANGE_IND)));
  assert(ind->state == DSME_STATE_USER);
  free(ind);
  assert(message_queue_is_empty());
  assert(!timer_exists());
  unload_module_under_test(state);
}
예제 #13
0
static void testcase16(void)
{
  /* thermal shutdown due to overheating */
  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);

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

  trigger_timer();
  expect_shutdown(state);

  unload_module_under_test(state);
}
예제 #14
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);
}
irom app_action_t application_function_gpio_set(application_parameters_t ap)
{
	unsigned int gpio_index;
	gpio_t *gpio;
	const gpio_config_entry_t *cfg;

	gpio_index = atoi((*ap.args)[1]);

	if(!(gpio = find_gpio(gpio_index)))
	{
		snprintf(ap.dst, ap.size, "gpio-set: invalid gpio %u\n", gpio_index);
		return(app_action_error);
	}

	cfg = get_config(gpio);

	switch(cfg->mode)
	{
		case(gpio_disabled):
		{
			snprintf(ap.dst, ap.size, "gpio-set: gpio %s is disabled\n", gpio->name);
			return(app_action_error);
		}

		case(gpio_input):
		{
			snprintf(ap.dst, ap.size, "gpio-set: gpio %s is input\n", gpio->name);
			return(app_action_error);
		}

		case(gpio_counter):
		{
			if(ap.nargs < 3)
				gpio->counter.count = 0;
			else
				gpio->counter.count = atoi((*ap.args)[2]);

			break;
		}

		case(gpio_output):
		{
			if(ap.nargs < 3)
			{
				snprintf(ap.dst, ap.size, "gpio-set: missing arguments\n");
				return(app_action_error);
			}

			set_output(gpio, !!atoi((*ap.args)[2]));

			break;
		}

		case(gpio_timer):
		{
			if(ap.nargs == 3)
				trigger_timer(gpio, !!atoi((*ap.args)[2]));
			else
				trigger_timer(gpio, !gpio->timer.delay);

			break;
		}

		case(gpio_pwm):
		{
			unsigned int min_duty;
			unsigned int max_duty;
			unsigned int delay;

			min_duty = 0;
			max_duty = 0;
			delay = 0;

			if(ap.nargs > 2)
				min_duty = atoi((*ap.args)[2]);

			if(ap.nargs > 3)
				max_duty = atoi((*ap.args)[3]);

			if(ap.nargs > 4)
				delay = atoi((*ap.args)[4]);

			if(min_duty > 65535)
			{
				snprintf(ap.dst, ap.size, "gpio-set(pwm): min_duty too large: %u > 65535\n", min_duty);
				return(app_action_error);
			}

			if(max_duty > 65535)
			{
				snprintf(ap.dst, ap.size, "gpio-set(pwm): max_duty too large: %u > 65535\n", max_duty);
				return(app_action_error);
			}

			if(delay > 100)
			{
				snprintf(ap.dst, ap.size, "gpio-set: gpio %s, delay %u%% > 100%%\n", gpio->name, delay);
				return(app_action_error);
			}

			gpio->pwm.min_duty = min_duty;
			gpio->pwm.max_duty = max_duty;
			gpio->pwm.delay_top = delay;
			gpio->pwm.direction = gpio_up;

			pwm_set_duty(min_duty, gpio->pwm.channel);
			pwm_start();

			break;
		}

		case(gpio_i2c):
		{
			snprintf(ap.dst, ap.size, "gpio-set: gpio %s is reserved for i2c\n", gpio->name);
			return(app_action_error);
		}

		default:
		{
			snprintf(ap.dst, ap.size, "gpio-set: cannot set gpio %u\n", cfg->mode);
			return(app_action_error);
		}
	}

	dump(&config->gpios, gpio, ap.size, ap.dst);
	return(app_action_normal);
}