summaryrefslogtreecommitdiff
path: root/cesar/lib/scenario
diff options
context:
space:
mode:
authorNicolas Schodet2010-10-14 11:13:19 +0200
committerNicolas Schodet2010-10-19 14:06:40 +0200
commit73fc1055108d75437dce38d09505186c386013b1 (patch)
treee40b12545f7f902f97b0c126eb0b8811d47947b8 /cesar/lib/scenario
parent1a35aeac885661a5d2f80d8dc71376c84d774871 (diff)
cesar/lib/scenario: reference event file and line on failure, closes #1961
Diffstat (limited to 'cesar/lib/scenario')
-rw-r--r--cesar/lib/scenario/scenario.h26
-rw-r--r--cesar/lib/scenario/src/scenario.c4
2 files changed, 19 insertions, 11 deletions
diff --git a/cesar/lib/scenario/scenario.h b/cesar/lib/scenario/scenario.h
index fe7af0d216..55299056fc 100644
--- a/cesar/lib/scenario/scenario.h
+++ b/cesar/lib/scenario/scenario.h
@@ -151,6 +151,10 @@ struct scenario_entry_t
scenario_action_cb_t action_cb;
/** Entry parameters. */
scenario_params_t params;
+ /** Entry file. */
+ const char *file;
+ /** Entry line. */
+ int line;
};
/** Scenario globals. */
@@ -203,9 +207,9 @@ extern char *scenario_event_names[];
dbg_assert (scenario.current->event_id < SCENARIO_NB_ID); \
test_fail_unless (scenario.current->event_id \
== SCENARIO_EVENT_ ## event, \
- "unexpected <%s>, expecting <%s> at %d", #event, \
+ "unexpected <%s>, expecting <%s> at %s:%d", #event, \
scenario_event_names[scenario.current->event_id], \
- scenario.current - scenario.entries); \
+ scenario.current->file, scenario.current->line); \
scenario.current++
#define scenario_event_2(event, params_var) \
@@ -217,24 +221,27 @@ extern char *scenario_event_names[];
scenario_event_2 (event, params_var); \
scenario_globals_t *globals_var = scenario.globals
+/** Keep trace of scenario file and line. */
+#define SCENARIO_FILELINE , __FILE__, __LINE__
+
/** Use this to define an event in a scenario list of entries. The first
* parameter is the event name. The following parameters are fields
* assignments for the event parameters. */
#define SCENARIO_EVENT(event, params_def...) \
{ SCENARIO_EVENT_ ## event, NULL, \
- { .event_ ## event = { params_def } } }
+ { .event_ ## event = { params_def } } SCENARIO_FILELINE }
/** Use this to define a conditional event in a scenario list of entries.
* This is similar to SCENARIO_EVENT, but it will be replaced with a no
* operation if the condition given is false. */
#define SCENARIO_EVENT_COND(cond, event, params_def...) \
{ (cond) ? SCENARIO_EVENT_ ## event : SCENARIO_NOP_ID, NULL, \
- { .event_ ## event = { params_def } } }
+ { .event_ ## event = { params_def } } SCENARIO_FILELINE }
/** Use this to define an action in a scenario list of entries. */
#define SCENARIO_ACTION(action, params_def...) \
{ SCENARIO_ACTION_ID, scenario_action_ ## action ## _cb, \
- { .action_ ## action = { params_def } } }
+ { .action_ ## action = { params_def } } SCENARIO_FILELINE }
/** Use this to define a conditional action in a scenario list of entries.
* This is similar to SCENARIO_ACTION, but it will replaced with a no
@@ -242,22 +249,23 @@ extern char *scenario_event_names[];
#define SCENARIO_ACTION_COND(cond, action, params_def...) \
{ (cond) ? SCENARIO_ACTION_ID : SCENARIO_NOP_ID, \
scenario_action_ ## action ## _cb, \
- { .action_ ## action = { params_def } } }
+ { .action_ ## action = { params_def } } SCENARIO_FILELINE }
/** Use this to define a sublist of entries. The sublist will be used as the
* main list, and processing will return to the main list once the sub list is
* ended. */
#define SCENARIO_SUB(entries_) \
{ SCENARIO_ACTION_ID, scenario_action_predefined_sub_cb, \
- { .action_predefined_sub = { .entries = entries_ } } }
+ { .action_predefined_sub = { .entries = entries_ } } \
+ SCENARIO_FILELINE }
/** Use this for a no operation in a scenario list of entries. */
#define SCENARIO_NOP \
- { SCENARIO_NOP_ID, NULL, { } }
+ { SCENARIO_NOP_ID, NULL, { } SCENARIO_FILELINE }
/** Use this to mark end of scenario list of entries. */
#define SCENARIO_END \
- { SCENARIO_NULL_ID, NULL, { } }
+ { SCENARIO_NULL_ID, NULL, { } SCENARIO_FILELINE }
BEGIN_DECLS
diff --git a/cesar/lib/scenario/src/scenario.c b/cesar/lib/scenario/src/scenario.c
index 47403daf9f..c4c654ae4d 100644
--- a/cesar/lib/scenario/src/scenario.c
+++ b/cesar/lib/scenario/src/scenario.c
@@ -46,9 +46,9 @@ scenario_run (test_t t, scenario_entry_t *entries,
else
{
test_fail_unless (scenario.current->event_id == SCENARIO_ACTION_ID,
- "Expected event <%s> did not occurs at %d",
+ "Expected event <%s> did not occurs at %s:%d",
scenario_event_names[scenario.current->event_id],
- scenario.current - scenario.entries);
+ scenario.current->file, scenario.current->line);
scenario_entry_t *action = scenario.current++;
action->action_cb (globals, &action->params);
}