Skip to content

Commit

Permalink
DSME enters MALF with a delay in boot
Browse files Browse the repository at this point in the history
  • Loading branch information
Matias Muhonen committed Jul 27, 2011
1 parent 0dbf656 commit 8ff94bf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 69 deletions.
1 change: 1 addition & 0 deletions debian/changelog
Expand Up @@ -5,6 +5,7 @@ dsme (0.62.0) unstable; urgency=low
* Check for socket connect errors in dsmetool (Fixes: NB#269307)
* Beautify the automake test configuration
* Implemented test cases for the usbtracker and emergencycalltracker modules
* DSME enters MALF with a delay in boot (Fixes: NB#272448)

[Antti Virtanen]
* Include process name into iphb module log messages if verbose logging used.
Expand Down
80 changes: 21 additions & 59 deletions modules/state.c
Expand Up @@ -82,9 +82,6 @@
#define USER_TIMER_MIN_TIMEOUT 2
#define USER_TIMER_MAX_TIMEOUT 15

/* In non-R&D mode we enter malf after this many seconds in MALF */
#define ENTER_MALF_TIMER 2

/* Seconds from overheating or empty battery to the start of shutdown timer */
#define DSME_THERMAL_SHUTDOWN_TIMER 8
#define DSME_BATTERY_EMPTY_SHUTDOWN_TIMER 8
Expand Down Expand Up @@ -117,7 +114,6 @@ static dsme_state_t current_state = DSME_STATE_NOT_SET;
/* timers for delayed setting of state bits */
static dsme_timer_t overheat_timer = 0;
static dsme_timer_t charger_disconnect_timer = 0;
static dsme_timer_t malf_timer = 0;

/* timers for giving other programs a bit of time before shutting down */
static dsme_timer_t delayed_shutdown_timer = 0;
Expand All @@ -139,11 +135,6 @@ static int delayed_user_fn(void* unused);
static void stop_delayed_runlevel_timers(void);
static void change_runlevel(dsme_state_t state);

static void start_malf_timer(const char* reason,
const char* component,
const char* details);
static int delayed_malf_fn(void* unused);

static void start_overheat_timer(void);
static int delayed_overheat_fn(void* unused);

Expand Down Expand Up @@ -536,54 +527,6 @@ static int delayed_overheat_fn(void* unused)
return 0; /* stop the interval */
}


// TODO: pass these via the timer data pointer
static char* malf_reason = 0;
static char* malf_component = 0;
static char* malf_details = 0;

static void start_malf_timer(const char* reason,
const char* component,
const char* details)
{
if (!malf_timer) {
malf_reason = strdup(reason);
malf_component = strdup(component);
malf_details = details ? strdup(details) : 0;

if (!(malf_timer = dsme_create_timer(ENTER_MALF_TIMER,
delayed_malf_fn,
NULL)))
{
dsme_log(LOG_CRIT, "Could not create a timer; malf immediately!");
delayed_malf_fn(0);
} else {
dsme_log(LOG_CRIT,
"MALF in %d seconds",
ENTER_MALF_TIMER);
}
}
}

static int delayed_malf_fn(void* unused)
{
DSM_MSGTYPE_ENTER_MALF malf = DSME_MSG_INIT(DSM_MSGTYPE_ENTER_MALF);
malf.reason = strcmp(malf_reason, "HARDWARE") ? DSME_MALF_SOFTWARE
: DSME_MALF_HARDWARE;
malf.component = malf_component;

if (malf_details) {
broadcast_internally_with_extra(&malf,
strlen(malf_details) + 1,
malf_details);
} else {
broadcast_internally(&malf);
}

return 0; /* stop the interval */
}


static void start_charger_disconnect_timer(void)
{
if (!charger_disconnect_timer) {
Expand Down Expand Up @@ -1030,6 +973,25 @@ static void parse_malf_info(char* malf_info,
}
}

static void enter_malf(const char* reason,
const char* component,
const char* details)
{
char* malf_details = details ? strdup(details) : 0;
DSM_MSGTYPE_ENTER_MALF malf = DSME_MSG_INIT(DSM_MSGTYPE_ENTER_MALF);
malf.reason = strcmp(reason, "HARDWARE") ? DSME_MALF_SOFTWARE
: DSME_MALF_HARDWARE;
malf.component = strdup(component);

if (malf_details) {
broadcast_internally_with_extra(&malf,
strlen(malf_details) + 1,
malf_details);
} else {
broadcast_internally(&malf);
}
}

/*
* If string 'string' begins with prefix 'prefix',
* DSME_SKIP_PREFIX returns a pointer to the first character
Expand Down Expand Up @@ -1090,15 +1052,15 @@ static void set_initial_state_bits(const char* bootstate)
if (p && *p) {
// we got a bootstate followed by malf information

// If allowed to malf, enter malf after the timer
// If allowed to malf, enter malf
if (must_malf || !rd_mode_enabled()) {
char* reason = 0;
char* component = 0;
char* details = 0;

char* malf_info = strdup(p);
parse_malf_info(malf_info, &reason, &component, &details);
start_malf_timer(reason, component, details);
enter_malf(reason, component, details);
free(malf_info);

} else {
Expand Down
14 changes: 4 additions & 10 deletions test/testmod_state.c
Expand Up @@ -115,7 +115,8 @@ static module_t* load_state_module(const char* bootstate,
free(ind2);
}

assert(message_queue_is_empty());
// TODO: this assert is not valid in case we MALF when loading the module
// assert(message_queue_is_empty());

return module;
}
Expand Down Expand Up @@ -772,12 +773,9 @@ static void testcase20(void)
// specify a bad $BOOTSTATE
state = load_state_module("DIIBADAABA", DSME_STATE_USER);

assert(timer_exists());
trigger_timer();
DSM_MSGTYPE_ENTER_MALF* msg;
assert(msg = queued(DSM_MSGTYPE_ENTER_MALF));
free(msg);

assert(!timer_exists());
assert(message_queue_is_empty());
unload_module_under_test(state);
Expand Down Expand Up @@ -822,9 +820,7 @@ static void testcase21(void)
assert(ind = queued(DSM_MSGTYPE_STATE_CHANGE_IND));
assert(ind->state == DSME_STATE_USER);
free(ind);
assert(message_queue_is_empty());
assert(timer_exists());
trigger_timer();
assert(!message_queue_is_empty());
DSM_MSGTYPE_ENTER_MALF* malfmsg;
assert((malfmsg = queued(DSM_MSGTYPE_ENTER_MALF)));
//TODO: Should the reason / component be checked?
Expand All @@ -841,9 +837,7 @@ static void testcase21(void)
assert(ind = queued(DSM_MSGTYPE_STATE_CHANGE_IND));
assert(ind->state == DSME_STATE_USER);
free(ind);
assert(message_queue_is_empty());
assert(timer_exists());
trigger_timer();
assert(!message_queue_is_empty());
assert(malfmsg = queued(DSM_MSGTYPE_ENTER_MALF));
//TODO: Should the reason / component be checked?
free(malfmsg);
Expand Down

0 comments on commit 8ff94bf

Please sign in to comment.