From bbf236875c11861e40845edd875e517dd475bfac Mon Sep 17 00:00:00 2001 From: Li Wang Date: Thu, 6 Dec 2018 17:20:24 +0800 Subject: [PATCH] add BUILD_BUG_ON* macros Signed-off-by: Li Wang --- include/tst_common.h | 13 +++++++++++++ include/tst_test.h | 8 ++++++-- lib/tst_test.c | 4 +++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/tst_common.h b/include/tst_common.h index 27924766ef6..0662d647620 100644 --- a/include/tst_common.h +++ b/include/tst_common.h @@ -65,4 +65,17 @@ ERET; \ }) +# define BUILD_BUG_ON(cond) \ + do { ((void)sizeof(char[1 - 2 * !!(cond)])); } while (0) + +#define BUILD_BUG_ON_MSG(cond, msg) \ + compiletime_assert(!(cond), msg, check_tst_brk_parameter_) + +#define compiletime_assert(condition, msg, funcname_) \ + do { \ + void funcname_(void) __attribute__((__error__(msg))); \ + if (!(condition)) \ + funcname_(); \ + } while (0) + #endif /* TST_COMMON_H__ */ diff --git a/include/tst_test.h b/include/tst_test.h index 2ebf746eb72..35732f60d28 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -69,8 +69,12 @@ void tst_brk_(const char *file, const int lineno, int ttype, const char *fmt, ...) __attribute__ ((format (printf, 4, 5))); -#define tst_brk(ttype, arg_fmt, ...) \ - tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__) +#define tst_brk(ttype, arg_fmt, ...) \ + ({ \ + BUILD_BUG_ON_MSG(!((ttype) & (TBROK | TCONF | TFAIL)), \ + "tst_brk(): invalid type, please use TBROK/TCONF/TFAIL"); \ + tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__);\ + }) /* flush stderr and stdout */ void tst_flush(void); diff --git a/lib/tst_test.c b/lib/tst_test.c index 661fbbfce00..433e11a0cc4 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -351,8 +351,10 @@ static void check_child_status(pid_t pid, int status) case TPASS: break; case TBROK: + tst_brk(TBROK, "Reported by child (%i)", pid); + break; case TCONF: - tst_brk(ret, "Reported by child (%i)", pid); + tst_brk(TCONF, "Reported by child (%i)", pid); break; default: tst_brk(TBROK, "Invalid child (%i) exit value %i", pid, ret);