Commit 537905c4 authored by Daniel Müller's avatar Daniel Müller Committed by Andrii Nakryiko

selftests/bpf: Add nested type to type based tests

This change extends the type based tests with another struct type (in
addition to a_struct) to check relocations against: a_complex_struct.
This type is nested more deeply to provide additional coverage of
certain paths in the type match logic.
Signed-off-by: default avatarDaniel Müller <deso@posteo.net>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220628160127.607834-10-deso@posteo.net
parent bed56a6d
...@@ -754,6 +754,7 @@ static const struct core_reloc_test_case test_cases[] = { ...@@ -754,6 +754,7 @@ static const struct core_reloc_test_case test_cases[] = {
/* validate type existence, match, and size relocations */ /* validate type existence, match, and size relocations */
TYPE_BASED_CASE(type_based, { TYPE_BASED_CASE(type_based, {
.struct_exists = 1, .struct_exists = 1,
.complex_struct_exists = 1,
.union_exists = 1, .union_exists = 1,
.enum_exists = 1, .enum_exists = 1,
.typedef_named_struct_exists = 1, .typedef_named_struct_exists = 1,
...@@ -766,6 +767,7 @@ static const struct core_reloc_test_case test_cases[] = { ...@@ -766,6 +767,7 @@ static const struct core_reloc_test_case test_cases[] = {
.typedef_arr_exists = 1, .typedef_arr_exists = 1,
.struct_matches = 1, .struct_matches = 1,
.complex_struct_matches = 1,
.union_matches = 1, .union_matches = 1,
.enum_matches = 1, .enum_matches = 1,
.typedef_named_struct_matches = 1, .typedef_named_struct_matches = 1,
...@@ -794,6 +796,7 @@ static const struct core_reloc_test_case test_cases[] = { ...@@ -794,6 +796,7 @@ static const struct core_reloc_test_case test_cases[] = {
}), }),
TYPE_BASED_CASE(type_based___diff, { TYPE_BASED_CASE(type_based___diff, {
.struct_exists = 1, .struct_exists = 1,
.complex_struct_exists = 1,
.union_exists = 1, .union_exists = 1,
.enum_exists = 1, .enum_exists = 1,
.typedef_named_struct_exists = 1, .typedef_named_struct_exists = 1,
...@@ -806,6 +809,7 @@ static const struct core_reloc_test_case test_cases[] = { ...@@ -806,6 +809,7 @@ static const struct core_reloc_test_case test_cases[] = {
.typedef_arr_exists = 1, .typedef_arr_exists = 1,
.struct_matches = 1, .struct_matches = 1,
.complex_struct_matches = 1,
.union_matches = 1, .union_matches = 1,
.enum_matches = 1, .enum_matches = 1,
.typedef_named_struct_matches = 1, .typedef_named_struct_matches = 1,
......
...@@ -864,6 +864,7 @@ struct core_reloc_size___err_ambiguous2 { ...@@ -864,6 +864,7 @@ struct core_reloc_size___err_ambiguous2 {
*/ */
struct core_reloc_type_based_output { struct core_reloc_type_based_output {
bool struct_exists; bool struct_exists;
bool complex_struct_exists;
bool union_exists; bool union_exists;
bool enum_exists; bool enum_exists;
bool typedef_named_struct_exists; bool typedef_named_struct_exists;
...@@ -876,6 +877,7 @@ struct core_reloc_type_based_output { ...@@ -876,6 +877,7 @@ struct core_reloc_type_based_output {
bool typedef_arr_exists; bool typedef_arr_exists;
bool struct_matches; bool struct_matches;
bool complex_struct_matches;
bool union_matches; bool union_matches;
bool enum_matches; bool enum_matches;
bool typedef_named_struct_matches; bool typedef_named_struct_matches;
...@@ -904,6 +906,14 @@ struct a_struct { ...@@ -904,6 +906,14 @@ struct a_struct {
int x; int x;
}; };
struct a_complex_struct {
union {
struct a_struct * restrict a;
void *b;
} x;
volatile long y;
};
union a_union { union a_union {
int y; int y;
int z; int z;
...@@ -935,16 +945,17 @@ typedef char arr_typedef[20]; ...@@ -935,16 +945,17 @@ typedef char arr_typedef[20];
struct core_reloc_type_based { struct core_reloc_type_based {
struct a_struct f1; struct a_struct f1;
union a_union f2; struct a_complex_struct f2;
enum an_enum f3; union a_union f3;
named_struct_typedef f4; enum an_enum f4;
anon_struct_typedef f5; named_struct_typedef f5;
struct_ptr_typedef f6; anon_struct_typedef f6;
int_typedef f7; struct_ptr_typedef f7;
enum_typedef f8; int_typedef f8;
void_ptr_typedef f9; enum_typedef f9;
func_proto_typedef f10; void_ptr_typedef f10;
arr_typedef f11; func_proto_typedef f11;
arr_typedef f12;
}; };
/* no types in target */ /* no types in target */
...@@ -957,6 +968,16 @@ struct a_struct___diff { ...@@ -957,6 +968,16 @@ struct a_struct___diff {
int a; int a;
}; };
struct a_struct___forward;
struct a_complex_struct___diff {
union {
struct a_struct___forward *a;
void *b;
} x;
volatile long y;
};
union a_union___diff { union a_union___diff {
int z; int z;
int y; int y;
...@@ -990,16 +1011,17 @@ typedef char arr_typedef___diff[3]; ...@@ -990,16 +1011,17 @@ typedef char arr_typedef___diff[3];
struct core_reloc_type_based___diff { struct core_reloc_type_based___diff {
struct a_struct___diff f1; struct a_struct___diff f1;
union a_union___diff f2; struct a_complex_struct___diff f2;
enum an_enum___diff f3; union a_union___diff f3;
named_struct_typedef___diff f4; enum an_enum___diff f4;
anon_struct_typedef___diff f5; named_struct_typedef___diff f5;
struct_ptr_typedef___diff f6; anon_struct_typedef___diff f6;
int_typedef___diff f7; struct_ptr_typedef___diff f7;
enum_typedef___diff f8; int_typedef___diff f8;
void_ptr_typedef___diff f9; enum_typedef___diff f9;
func_proto_typedef___diff f10; void_ptr_typedef___diff f10;
arr_typedef___diff f11; func_proto_typedef___diff f11;
arr_typedef___diff f12;
}; };
/* different type sizes, extra modifiers, anon vs named enums, etc */ /* different type sizes, extra modifiers, anon vs named enums, etc */
......
...@@ -19,6 +19,14 @@ struct a_struct { ...@@ -19,6 +19,14 @@ struct a_struct {
int x; int x;
}; };
struct a_complex_struct {
union {
struct a_struct *a;
void *b;
} x;
volatile long y;
};
union a_union { union a_union {
int y; int y;
int z; int z;
...@@ -50,6 +58,7 @@ typedef char arr_typedef[20]; ...@@ -50,6 +58,7 @@ typedef char arr_typedef[20];
struct core_reloc_type_based_output { struct core_reloc_type_based_output {
bool struct_exists; bool struct_exists;
bool complex_struct_exists;
bool union_exists; bool union_exists;
bool enum_exists; bool enum_exists;
bool typedef_named_struct_exists; bool typedef_named_struct_exists;
...@@ -62,6 +71,7 @@ struct core_reloc_type_based_output { ...@@ -62,6 +71,7 @@ struct core_reloc_type_based_output {
bool typedef_arr_exists; bool typedef_arr_exists;
bool struct_matches; bool struct_matches;
bool complex_struct_matches;
bool union_matches; bool union_matches;
bool enum_matches; bool enum_matches;
bool typedef_named_struct_matches; bool typedef_named_struct_matches;
...@@ -99,6 +109,7 @@ int test_core_type_based(void *ctx) ...@@ -99,6 +109,7 @@ int test_core_type_based(void *ctx)
struct core_reloc_type_based_output *out = (void *)&data.out; struct core_reloc_type_based_output *out = (void *)&data.out;
out->struct_exists = bpf_core_type_exists(struct a_struct); out->struct_exists = bpf_core_type_exists(struct a_struct);
out->complex_struct_exists = bpf_core_type_exists(struct a_complex_struct);
out->union_exists = bpf_core_type_exists(union a_union); out->union_exists = bpf_core_type_exists(union a_union);
out->enum_exists = bpf_core_type_exists(enum an_enum); out->enum_exists = bpf_core_type_exists(enum an_enum);
out->typedef_named_struct_exists = bpf_core_type_exists(named_struct_typedef); out->typedef_named_struct_exists = bpf_core_type_exists(named_struct_typedef);
...@@ -111,6 +122,7 @@ int test_core_type_based(void *ctx) ...@@ -111,6 +122,7 @@ int test_core_type_based(void *ctx)
out->typedef_arr_exists = bpf_core_type_exists(arr_typedef); out->typedef_arr_exists = bpf_core_type_exists(arr_typedef);
out->struct_matches = bpf_core_type_matches(struct a_struct); out->struct_matches = bpf_core_type_matches(struct a_struct);
out->complex_struct_matches = bpf_core_type_matches(struct a_complex_struct);
out->union_matches = bpf_core_type_matches(union a_union); out->union_matches = bpf_core_type_matches(union a_union);
out->enum_matches = bpf_core_type_matches(enum an_enum); out->enum_matches = bpf_core_type_matches(enum an_enum);
out->typedef_named_struct_matches = bpf_core_type_matches(named_struct_typedef); out->typedef_named_struct_matches = bpf_core_type_matches(named_struct_typedef);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment