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

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
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -754,6 +754,7 @@ static const struct core_reloc_test_case test_cases[] = {
	/* validate type existence, match, and size relocations */
	TYPE_BASED_CASE(type_based, {
		.struct_exists = 1,
		.complex_struct_exists = 1,
		.union_exists = 1,
		.enum_exists = 1,
		.typedef_named_struct_exists = 1,
@@ -766,6 +767,7 @@ static const struct core_reloc_test_case test_cases[] = {
		.typedef_arr_exists = 1,

		.struct_matches = 1,
		.complex_struct_matches = 1,
		.union_matches = 1,
		.enum_matches = 1,
		.typedef_named_struct_matches = 1,
@@ -794,6 +796,7 @@ static const struct core_reloc_test_case test_cases[] = {
	}),
	TYPE_BASED_CASE(type_based___diff, {
		.struct_exists = 1,
		.complex_struct_exists = 1,
		.union_exists = 1,
		.enum_exists = 1,
		.typedef_named_struct_exists = 1,
@@ -806,6 +809,7 @@ static const struct core_reloc_test_case test_cases[] = {
		.typedef_arr_exists = 1,

		.struct_matches = 1,
		.complex_struct_matches = 1,
		.union_matches = 1,
		.enum_matches = 1,
		.typedef_named_struct_matches = 1,
+42 −20
Original line number Diff line number Diff line
@@ -864,6 +864,7 @@ struct core_reloc_size___err_ambiguous2 {
 */
struct core_reloc_type_based_output {
	bool struct_exists;
	bool complex_struct_exists;
	bool union_exists;
	bool enum_exists;
	bool typedef_named_struct_exists;
@@ -876,6 +877,7 @@ struct core_reloc_type_based_output {
	bool typedef_arr_exists;

	bool struct_matches;
	bool complex_struct_matches;
	bool union_matches;
	bool enum_matches;
	bool typedef_named_struct_matches;
@@ -904,6 +906,14 @@ struct a_struct {
	int x;
};

struct a_complex_struct {
	union {
		struct a_struct * restrict a;
		void *b;
	} x;
	volatile long y;
};

union a_union {
	int y;
	int z;
@@ -935,16 +945,17 @@ typedef char arr_typedef[20];

struct core_reloc_type_based {
	struct a_struct f1;
	union a_union f2;
	enum an_enum f3;
	named_struct_typedef f4;
	anon_struct_typedef f5;
	struct_ptr_typedef f6;
	int_typedef f7;
	enum_typedef f8;
	void_ptr_typedef f9;
	func_proto_typedef f10;
	arr_typedef f11;
	struct a_complex_struct f2;
	union a_union f3;
	enum an_enum f4;
	named_struct_typedef f5;
	anon_struct_typedef f6;
	struct_ptr_typedef f7;
	int_typedef f8;
	enum_typedef f9;
	void_ptr_typedef f10;
	func_proto_typedef f11;
	arr_typedef f12;
};

/* no types in target */
@@ -957,6 +968,16 @@ struct a_struct___diff {
	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 {
	int z;
	int y;
@@ -990,16 +1011,17 @@ typedef char arr_typedef___diff[3];

struct core_reloc_type_based___diff {
	struct a_struct___diff f1;
	union a_union___diff f2;
	enum an_enum___diff f3;
	named_struct_typedef___diff f4;
	anon_struct_typedef___diff f5;
	struct_ptr_typedef___diff f6;
	int_typedef___diff f7;
	enum_typedef___diff f8;
	void_ptr_typedef___diff f9;
	func_proto_typedef___diff f10;
	arr_typedef___diff f11;
	struct a_complex_struct___diff f2;
	union a_union___diff f3;
	enum an_enum___diff f4;
	named_struct_typedef___diff f5;
	anon_struct_typedef___diff f6;
	struct_ptr_typedef___diff f7;
	int_typedef___diff f8;
	enum_typedef___diff f9;
	void_ptr_typedef___diff f10;
	func_proto_typedef___diff f11;
	arr_typedef___diff f12;
};

/* different type sizes, extra modifiers, anon vs named enums, etc */
+12 −0
Original line number Diff line number Diff line
@@ -19,6 +19,14 @@ struct a_struct {
	int x;
};

struct a_complex_struct {
	union {
		struct a_struct *a;
		void *b;
	} x;
	volatile long y;
};

union a_union {
	int y;
	int z;
@@ -50,6 +58,7 @@ typedef char arr_typedef[20];

struct core_reloc_type_based_output {
	bool struct_exists;
	bool complex_struct_exists;
	bool union_exists;
	bool enum_exists;
	bool typedef_named_struct_exists;
@@ -62,6 +71,7 @@ struct core_reloc_type_based_output {
	bool typedef_arr_exists;

	bool struct_matches;
	bool complex_struct_matches;
	bool union_matches;
	bool enum_matches;
	bool typedef_named_struct_matches;
@@ -99,6 +109,7 @@ int test_core_type_based(void *ctx)
	struct core_reloc_type_based_output *out = (void *)&data.out;

	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->enum_exists = bpf_core_type_exists(enum an_enum);
	out->typedef_named_struct_exists = bpf_core_type_exists(named_struct_typedef);
@@ -111,6 +122,7 @@ int test_core_type_based(void *ctx)
	out->typedef_arr_exists = bpf_core_type_exists(arr_typedef);

	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->enum_matches = bpf_core_type_matches(enum an_enum);
	out->typedef_named_struct_matches = bpf_core_type_matches(named_struct_typedef);