tst_taint: print readable error instead of numerical codes
PATCH v2 1/2 tst_taint: print readable error instead of numerical codes
Fixes #776
This patch prints human readable messages when kernel is tainted instead of numerical codes.
Git Hub Issue link - https://github.com/linux-test-project/ltp/issues/776
--- lib/tst_taint.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
lib/tst_taint.c +28 -1
@@ -8,6 +8,32 @@static unsigned int taint_mask =-1 ; +const char *tst_strtaint (int err) +{ +static const struct pair taint_pairs[] = { + STRPAIR(TST_TAINT_A, "A (ACPI table overridden)") + STRPAIR(TST_TAINT_B, "B (Bad page reference)") + STRPAIR(TST_TAINT_C, "C (Staging driver loaded)") + STRPAIR(TST_TAINT_D, "D (OOPS/BUG)") + STRPAIR(TST_TAINT_E, "E (Unsigned module loaded)") + STRPAIR(TST_TAINT_F, "F (Module force loaded)") + STRPAIR(TST_TAINT_G, "G (Propriety module loaded)") + STRPAIR(TST_TAINT_I, "I (Workaround BIOS/FW bug)") + STRPAIR(TST_TAINT_K, "K (Live patched)") + STRPAIR(TST_TAINT_L, "L (Soft lock up occured)") + STRPAIR(TST_TAINT_M, "M (Machine check exception)") + STRPAIR(TST_TAINT_O, "O (Out of tree module loaded)") + STRPAIR(TST_TAINT_R, "R (Module force unloaded)") + STRPAIR(TST_TAINT_S, "S (Running on out of spec system)") + STRPAIR(TST_TAINT_T, "T (Built with struct randomization)") + STRPAIR(TST_TAINT_U, "U (User request)") + STRPAIR(TST_TAINT_W, "W (Warning)") +STRPAIR (TST_TAINT_X ,"X (Auxilary)" ) + }; + +PAIR_LOOKUP (taint_pairs, err); +} +static unsigned int tst_taint_read (void ) {unsigned int val;
@@ -90,7 +116,8 @@ void tst_taint_init(unsigned int mask) }if ((taint & taint_mask) !=0 ) -tst_brk (TBROK ,"Kernel is already tainted: %u" , taint); +tst_brk (TBROK ,"Kernel is already tainted: %s" , +tst_strtaint (taint)); }
Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/2 tst_common.h: Move struct pair definition from tst_res to include/tst_common.h to avoid duplicate code
This patch moves definition of struct pair from tst_res.c to include/tst_common.h to avoid code duplication as struct pair is also used by tst_taint.c.
--- include/tst_common.h | 15 +++++++++++++++ lib/tst_res.c | 15 --------------- 2 files changed, 15 insertions(+), 15 deletions(-)
include/tst_common.h +15 -0
@@ -83,4 +83,19 @@#define TST_RES_SUPPORTS_TCONF_TFAIL_TINFO_TPASS_TWARN (condition) \ TST_BUILD_BUG_ON(condition) +struct pair { +const char *name; +int val; +}; + +#define PAIR (def) [def] = {.name = #def, .val = def}, +#define STRPAIR (key, value) [key] = {.name = value, .val = key}, + +#define PAIR_LOOKUP (pair_arr, idx) do { \ + if (idx < 0 || (size_t)idx >= ARRAY_SIZE(pair_arr) || \ + pair_arr[idx].name == NULL) \ + return "???"; \ + return pair_arr[idx].name; \ +} while (0) +#endif /* TST_COMMON_H__ */
lib/tst_res.c +0 -15
@@ -124,21 +124,6 @@ extern char *TCID; /* Test case identifier from the test source */extern int TST_TOTAL ;/* Total number of test cases from the test */ -struct pair { -const char *name; -int val; -}; - -#define PAIR (def) [def] = {.name = #def, .val = def}, -#define STRPAIR (key, value) [key] = {.name = value, .val = key}, - -#define PAIR_LOOKUP (pair_arr, idx) do { \ - if (idx < 0 || (size_t)idx >= ARRAY_SIZE(pair_arr) || \ - pair_arr[idx].name == NULL) \ - return "???"; \ - return pair_arr[idx].name; \ -} while (0) -const char *strttype (int ttype) {static const struct pair ttype_pairs[] = {
Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp