testsuite: fix memory access

Depending on optimization level, the TC_RESULT_STR[]
array could actually be placed in memory instead of
being expanded at compile time, resulting in memory
access errors from user mode.

Just replace TC_RESULT_TO_STR() with an inline function
containing a switch statement instead.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2019-05-01 13:00:00 -07:00 committed by Anas Nashif
commit a682dedd50

View file

@ -58,13 +58,19 @@
#define TC_FAIL 1 #define TC_FAIL 1
#define TC_SKIP 2 #define TC_SKIP 2
static __unused const char *TC_RESULT_STR[] = { static inline const char *TC_RESULT_TO_STR(int result)
[TC_PASS] = "PASS", {
[TC_FAIL] = "FAIL", switch (result) {
[TC_SKIP] = "SKIP", case TC_PASS:
}; return "PASS";
case TC_FAIL:
#define TC_RESULT_TO_STR(result) TC_RESULT_STR[result] return "FAIL";
case TC_SKIP:
return "SKIP";
default:
return "?";
}
}
#define TC_ERROR(fmt, ...) \ #define TC_ERROR(fmt, ...) \
do { \ do { \