aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/selftests/bpf/progs/btf_dump_test_case_packing.c
blob: 7998f27df7dddef9c3f793eaca36555aa208dfd4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)

/*
 * BTF-to-C dumper tests for struct packing determination.
 *
 * Copyright (c) 2019 Facebook
 */
/* ----- START-EXPECTED-OUTPUT ----- */
struct packed_trailing_space {
	int a;
	short b;
} __attribute__((packed));

struct non_packed_trailing_space {
	int a;
	short b;
};

struct packed_fields {
	short a;
	int b;
} __attribute__((packed));

struct non_packed_fields {
	short a;
	int b;
};

struct nested_packed {
	char: 4;
	int a: 4;
	long b;
	struct {
		char c;
		int d;
	} __attribute__((packed)) e;
} __attribute__((packed));

union union_is_never_packed {
	int a: 4;
	char b;
	char c: 1;
};

union union_does_not_need_packing {
	struct {
		long a;
		int b;
	} __attribute__((packed));
	int c;
};

union jump_code_union {
	char code[5];
	struct {
		char jump;
		int offset;
	} __attribute__((packed));
};

/* ----- START-EXPECTED-OUTPUT ----- */
/*
 *struct nested_packed_but_aligned_struct {
 *	int x1;
 *	int x2;
 *};
 *
 *struct outer_implicitly_packed_struct {
 *	char y1;
 *	struct nested_packed_but_aligned_struct y2;
 *} __attribute__((packed));
 *
 */
/* ------ END-EXPECTED-OUTPUT ------ */

struct nested_packed_but_aligned_struct {
	int x1;
	int x2;
} __attribute__((packed));

struct outer_implicitly_packed_struct {
	char y1;
	struct nested_packed_but_aligned_struct y2;
};
/* ----- START-EXPECTED-OUTPUT ----- */
/*
 *struct usb_ss_ep_comp_descriptor {
 *	char: 8;
 *	char bDescriptorType;
 *	char bMaxBurst;
 *	short wBytesPerInterval;
 *};
 *
 *struct usb_host_endpoint {
 *	long: 64;
 *	char: 8;
 *	struct usb_ss_ep_comp_descriptor ss_ep_comp;
 *	long: 0;
 *} __attribute__((packed));
 *
 */
/* ------ END-EXPECTED-OUTPUT ------ */

struct usb_ss_ep_comp_descriptor {
	char: 8;
	char bDescriptorType;
	char bMaxBurst;
	int: 0;
	short wBytesPerInterval;
} __attribute__((packed));

struct usb_host_endpoint {
	long: 64;
	char: 8;
	struct usb_ss_ep_comp_descriptor ss_ep_comp;
	long: 0;
};

/* ----- START-EXPECTED-OUTPUT ----- */
struct nested_packed_struct {
	int a;
	char b;
} __attribute__((packed));

struct outer_nonpacked_struct {
	short a;
	struct nested_packed_struct b;
};

struct outer_packed_struct {
	short a;
	struct nested_packed_struct b;
} __attribute__((packed));

/* ------ END-EXPECTED-OUTPUT ------ */

int f(struct {
	struct packed_trailing_space _1;
	struct non_packed_trailing_space _2;
	struct packed_fields _3;
	struct non_packed_fields _4;
	struct nested_packed _5;
	union union_is_never_packed _6;
	union union_does_not_need_packing _7;
	union jump_code_union _8;
	struct outer_implicitly_packed_struct _9;
	struct usb_host_endpoint _10;
	struct outer_nonpacked_struct _11;
	struct outer_packed_struct _12;
} *_)
{
	return 0;
}