Skip to content

Commit c0bb2cf

Browse files
author
Shuah Khan
committed
selftests: kselftest framework: add error counter
Some tests track errors in addition to test failures. Add ksft_error counter, ksft_get_error_cnt(), and ksft_test_result_error() API to get the counter value and print error message. Update ksft_print_cnts(), and ksft_test_num() to include error counter. Signed-off-by: Shuah Khan <[email protected]>
1 parent 7d00519 commit c0bb2cf

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

tools/testing/selftests/kselftest.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct ksft_count {
2828
unsigned int ksft_xfail;
2929
unsigned int ksft_xpass;
3030
unsigned int ksft_xskip;
31+
unsigned int ksft_error;
3132
};
3233

3334
static struct ksft_count ksft_cnt;
@@ -36,20 +37,22 @@ static inline int ksft_test_num(void)
3637
{
3738
return ksft_cnt.ksft_pass + ksft_cnt.ksft_fail +
3839
ksft_cnt.ksft_xfail + ksft_cnt.ksft_xpass +
39-
ksft_cnt.ksft_xskip;
40+
ksft_cnt.ksft_xskip + ksft_cnt.ksft_error;
4041
}
4142

4243
static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; }
4344
static inline void ksft_inc_fail_cnt(void) { ksft_cnt.ksft_fail++; }
4445
static inline void ksft_inc_xfail_cnt(void) { ksft_cnt.ksft_xfail++; }
4546
static inline void ksft_inc_xpass_cnt(void) { ksft_cnt.ksft_xpass++; }
4647
static inline void ksft_inc_xskip_cnt(void) { ksft_cnt.ksft_xskip++; }
48+
static inline void ksft_inc_error_cnt(void) { ksft_cnt.ksft_error++; }
4749

4850
static inline int ksft_get_pass_cnt(void) { return ksft_cnt.ksft_pass; }
4951
static inline int ksft_get_fail_cnt(void) { return ksft_cnt.ksft_fail; }
5052
static inline int ksft_get_xfail_cnt(void) { return ksft_cnt.ksft_xfail; }
5153
static inline int ksft_get_xpass_cnt(void) { return ksft_cnt.ksft_xpass; }
5254
static inline int ksft_get_xskip_cnt(void) { return ksft_cnt.ksft_xskip; }
55+
static inline int ksft_get_error_cnt(void) { return ksft_cnt.ksft_error; }
5356

5457
static inline void ksft_print_header(void)
5558
{
@@ -58,10 +61,10 @@ static inline void ksft_print_header(void)
5861

5962
static inline void ksft_print_cnts(void)
6063
{
61-
printf("Pass %d Fail %d Xfail %d Xpass %d Skip %d\n",
64+
printf("Pass %d Fail %d Xfail %d Xpass %d Skip %d Error %d\n",
6265
ksft_cnt.ksft_pass, ksft_cnt.ksft_fail,
6366
ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass,
64-
ksft_cnt.ksft_xskip);
67+
ksft_cnt.ksft_xskip, ksft_cnt.ksft_error);
6568
printf("1..%d\n", ksft_test_num());
6669
}
6770

@@ -111,6 +114,18 @@ static inline void ksft_test_result_skip(const char *msg, ...)
111114
va_end(args);
112115
}
113116

117+
static inline void ksft_test_result_error(const char *msg, ...)
118+
{
119+
va_list args;
120+
121+
ksft_cnt.ksft_error++;
122+
123+
va_start(args, msg);
124+
printf("not ok %d # error ", ksft_test_num());
125+
vprintf(msg, args);
126+
va_end(args);
127+
}
128+
114129
static inline int ksft_exit_pass(void)
115130
{
116131
ksft_print_cnts();

0 commit comments

Comments
 (0)