Skip to content

Commit

Permalink
add BUILD_BUG_ON* macros
Browse files Browse the repository at this point in the history
Signed-off-by: Li Wang <liwang@redhat.com>
  • Loading branch information
wangli5665 committed Dec 6, 2018
1 parent 9b02cd4 commit bbf2368
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
13 changes: 13 additions & 0 deletions include/tst_common.h
Expand Up @@ -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__ */
8 changes: 6 additions & 2 deletions include/tst_test.h
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion lib/tst_test.c
Expand Up @@ -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);
Expand Down

0 comments on commit bbf2368

Please sign in to comment.