Skip to content

Commit 57b97ec

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: reduce verboseness of reg_bounds selftest logs
Reduce verboseness of test_progs' output in reg_bounds set of tests with two changes. First, instead of each different operator (<, <=, >, ...) being it's own subtest, combine all different ops for the same (x, y, init_t, cond_t) values into single subtest. Instead of getting 6 subtests, we get one generic one, e.g.: #192/53 reg_bounds_crafted/(s64)[0xffffffffffffffff; 0] (s64)<op> 0xffffffff00000000:OK Second, for random generated test cases, treat all of them as a single test to eliminate very verbose output with random values in them. So now we'll just get one line per each combination of (init_t, cond_t), instead of 6 x 25 = 150 subtests before this change: #225 reg_bounds_rand_consts_s32_s32:OK Given we reduce verboseness so much, it makes sense to do a bit more random testing, so we also bump default number of random tests to 100, up from 25. This doesn't increase runtime significantly, especially in parallelized mode. With all the above changes we still make sure that we have all the information necessary for reproducing test case if it happens to fail. That includes reporting random seed and specific operator that is failing. Those will only be printed to console if related test/subtest fails, so it doesn't have any added verboseness implications. Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 3e124aa commit 57b97ec

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

tools/testing/selftests/bpf/prog_tests/reg_bounds.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,11 +1361,11 @@ struct subtest_case {
13611361
enum op op;
13621362
};
13631363

1364-
static void subtest_case_str(struct strbuf *sb, struct subtest_case *t)
1364+
static void subtest_case_str(struct strbuf *sb, struct subtest_case *t, bool use_op)
13651365
{
13661366
snappendf(sb, "(%s)", t_str(t->init_t));
13671367
snprintf_range(t->init_t, sb, t->x);
1368-
snappendf(sb, " (%s)%s ", t_str(t->cond_t), op_str(t->op));
1368+
snappendf(sb, " (%s)%s ", t_str(t->cond_t), use_op ? op_str(t->op) : "<op>");
13691369
snprintf_range(t->init_t, sb, t->y);
13701370
}
13711371

@@ -1440,8 +1440,8 @@ static int verify_case_op(enum num_t init_t, enum num_t cond_t,
14401440
/* Given setup ranges and number types, go over all supported operations,
14411441
* generating individual subtest for each allowed combination
14421442
*/
1443-
static int verify_case(struct ctx *ctx, enum num_t init_t, enum num_t cond_t,
1444-
struct range x, struct range y)
1443+
static int verify_case_opt(struct ctx *ctx, enum num_t init_t, enum num_t cond_t,
1444+
struct range x, struct range y, bool is_subtest)
14451445
{
14461446
DEFINE_STRBUF(sb, 256);
14471447
int err;
@@ -1452,11 +1452,14 @@ static int verify_case(struct ctx *ctx, enum num_t init_t, enum num_t cond_t,
14521452
.y = y,
14531453
};
14541454

1455+
sb->pos = 0; /* reset position in strbuf */
1456+
subtest_case_str(sb, &sub, false /* ignore op */);
1457+
if (is_subtest && !test__start_subtest(sb->buf))
1458+
return 0;
1459+
14551460
for (sub.op = first_op; sub.op <= last_op; sub.op++) {
14561461
sb->pos = 0; /* reset position in strbuf */
1457-
subtest_case_str(sb, &sub);
1458-
if (!test__start_subtest(sb->buf))
1459-
continue;
1462+
subtest_case_str(sb, &sub, true /* print op */);
14601463

14611464
if (env.verbosity >= VERBOSE_NORMAL) /* this speeds up debugging */
14621465
printf("TEST CASE: %s\n", sb->buf);
@@ -1491,6 +1494,12 @@ static int verify_case(struct ctx *ctx, enum num_t init_t, enum num_t cond_t,
14911494
return 0;
14921495
}
14931496

1497+
static int verify_case(struct ctx *ctx, enum num_t init_t, enum num_t cond_t,
1498+
struct range x, struct range y)
1499+
{
1500+
return verify_case_opt(ctx, init_t, cond_t, x, y, true /* is_subtest */);
1501+
}
1502+
14941503
/* ================================
14951504
* GENERATED CASES FROM SEED VALUES
14961505
* ================================
@@ -1913,7 +1922,7 @@ void test_reg_bounds_gen_ranges_s32_s64(void) { validate_gen_range_vs_range(S32,
19131922
void test_reg_bounds_gen_ranges_s32_u32(void) { validate_gen_range_vs_range(S32, U32); }
19141923
void test_reg_bounds_gen_ranges_s32_s32(void) { validate_gen_range_vs_range(S32, S32); }
19151924

1916-
#define DEFAULT_RAND_CASE_CNT 25
1925+
#define DEFAULT_RAND_CASE_CNT 100
19171926

19181927
#define RAND_21BIT_MASK ((1 << 22) - 1)
19191928

@@ -1968,7 +1977,6 @@ static void validate_rand_ranges(enum num_t init_t, enum num_t cond_t, bool cons
19681977
"[RANDOM SEED %u] RANGE x %s, %s -> %s",
19691978
ctx.rand_seed, const_range ? "CONST" : "RANGE",
19701979
t_str(init_t), t_str(cond_t));
1971-
fprintf(env.stdout, "%s\n", ctx.progress_ctx);
19721980

19731981
for (i = 0; i < ctx.rand_case_cnt; i++) {
19741982
range1 = rand_range(init_t);
@@ -1980,14 +1988,16 @@ static void validate_rand_ranges(enum num_t init_t, enum num_t cond_t, bool cons
19801988
}
19811989

19821990
/* <range1> x <range2> */
1983-
if (verify_case(&ctx, init_t, cond_t, range1, range2))
1991+
if (verify_case_opt(&ctx, init_t, cond_t, range1, range2, false /* !is_subtest */))
19841992
goto cleanup;
19851993
/* <range2> x <range1> */
1986-
if (verify_case(&ctx, init_t, cond_t, range2, range1))
1994+
if (verify_case_opt(&ctx, init_t, cond_t, range2, range1, false /* !is_subtest */))
19871995
goto cleanup;
19881996
}
19891997

19901998
cleanup:
1999+
/* make sure we report random seed for reproducing */
2000+
ASSERT_TRUE(true, ctx.progress_ctx);
19912001
cleanup_ctx(&ctx);
19922002
}
19932003

0 commit comments

Comments
 (0)