4343#define TEST_TAG_EXPECT_STDERR_PFX_UNPRIV "comment:test_expect_stderr_unpriv="
4444#define TEST_TAG_EXPECT_STDOUT_PFX "comment:test_expect_stdout="
4545#define TEST_TAG_EXPECT_STDOUT_PFX_UNPRIV "comment:test_expect_stdout_unpriv="
46+ #define TEST_TAG_LINEAR_SIZE "comment:test_linear_size="
4647
4748/* Warning: duplicated in bpf_misc.h */
4849#define POINTER_VALUE 0xbadcafe
@@ -89,6 +90,7 @@ struct test_spec {
8990 int mode_mask ;
9091 int arch_mask ;
9192 int load_mask ;
93+ int linear_sz ;
9294 bool auxiliary ;
9395 bool valid ;
9496};
@@ -633,6 +635,21 @@ static int parse_test_spec(struct test_loader *tester,
633635 & spec -> unpriv .stdout );
634636 if (err )
635637 goto cleanup ;
638+ } else if (str_has_pfx (s , TEST_TAG_LINEAR_SIZE )) {
639+ switch (bpf_program__type (prog )) {
640+ case BPF_PROG_TYPE_SCHED_ACT :
641+ case BPF_PROG_TYPE_SCHED_CLS :
642+ case BPF_PROG_TYPE_CGROUP_SKB :
643+ val = s + sizeof (TEST_TAG_LINEAR_SIZE ) - 1 ;
644+ err = parse_int (val , & spec -> linear_sz , "test linear size" );
645+ if (err )
646+ goto cleanup ;
647+ break ;
648+ default :
649+ PRINT_FAIL ("__linear_size for unsupported program type" );
650+ err = - EINVAL ;
651+ goto cleanup ;
652+ }
636653 }
637654 }
638655
@@ -1007,10 +1024,11 @@ static bool is_unpriv_capable_map(struct bpf_map *map)
10071024 }
10081025}
10091026
1010- static int do_prog_test_run (int fd_prog , int * retval , bool empty_opts )
1027+ static int do_prog_test_run (int fd_prog , int * retval , bool empty_opts , int linear_sz )
10111028{
10121029 __u8 tmp_out [TEST_DATA_LEN << 2 ] = {};
10131030 __u8 tmp_in [TEST_DATA_LEN ] = {};
1031+ struct __sk_buff ctx = {};
10141032 int err , saved_errno ;
10151033 LIBBPF_OPTS (bpf_test_run_opts , topts ,
10161034 .data_in = tmp_in ,
@@ -1020,6 +1038,12 @@ static int do_prog_test_run(int fd_prog, int *retval, bool empty_opts)
10201038 .repeat = 1 ,
10211039 );
10221040
1041+ if (linear_sz ) {
1042+ ctx .data_end = linear_sz ;
1043+ topts .ctx_in = & ctx ;
1044+ topts .ctx_size_in = sizeof (ctx );
1045+ }
1046+
10231047 if (empty_opts ) {
10241048 memset (& topts , 0 , sizeof (struct bpf_test_run_opts ));
10251049 topts .sz = sizeof (struct bpf_test_run_opts );
@@ -1269,7 +1293,8 @@ void run_subtest(struct test_loader *tester,
12691293 }
12701294
12711295 err = do_prog_test_run (bpf_program__fd (tprog ), & retval ,
1272- bpf_program__type (tprog ) == BPF_PROG_TYPE_SYSCALL ? true : false);
1296+ bpf_program__type (tprog ) == BPF_PROG_TYPE_SYSCALL ? true : false,
1297+ spec -> linear_sz );
12731298 if (!err && retval != subspec -> retval && subspec -> retval != POINTER_VALUE ) {
12741299 PRINT_FAIL ("Unexpected retval: %d != %d\n" , retval , subspec -> retval );
12751300 goto tobj_cleanup ;
0 commit comments