Commit b148c8b9 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Daniel Borkmann

selftests/bpf: Add few corner cases to test padding handling of btf_dump

Add few hand-crafted cases and few randomized cases found using script
from [0] that tests btf_dump's padding logic.

  [0] https://lore.kernel.org/bpf/85f83c333f5355c8ac026f835b18d15060725fcb.camel@ericsson.com/Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20221212211505.558851-7-andrii@kernel.org
parent ea2ce1ba
......@@ -58,7 +58,64 @@ union jump_code_union {
} __attribute__((packed));
};
/*------ END-EXPECTED-OUTPUT ------ */
/* ----- 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;
};
int f(struct {
struct packed_trailing_space _1;
......@@ -69,6 +126,8 @@ int f(struct {
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;
} *_)
{
return 0;
......
......@@ -128,6 +128,98 @@ struct padding_weird_2 {
char: 8;
};
/* ----- START-EXPECTED-OUTPUT ----- */
struct exact_1byte {
char x;
};
struct padded_1byte {
char: 8;
};
struct exact_2bytes {
short x;
};
struct padded_2bytes {
short: 16;
};
struct exact_4bytes {
int x;
};
struct padded_4bytes {
int: 32;
};
struct exact_8bytes {
long x;
};
struct padded_8bytes {
long: 64;
};
struct ff_periodic_effect {
int: 32;
short magnitude;
long: 0;
short phase;
long: 0;
int: 32;
int custom_len;
short *custom_data;
};
struct ib_wc {
long: 64;
long: 64;
int: 32;
int byte_len;
void *qp;
union {} ex;
long: 64;
int slid;
int wc_flags;
long: 64;
char smac[6];
long: 0;
char network_hdr_type;
};
struct acpi_object_method {
long: 64;
char: 8;
char type;
short reference_count;
char flags;
short: 0;
char: 8;
char sync_level;
long: 64;
void *node;
void *aml_start;
union {} dispatch;
long: 64;
int aml_length;
};
struct nested_unpacked {
int x;
};
struct nested_packed {
struct nested_unpacked a;
char c;
} __attribute__((packed));
struct outer_mixed_but_unpacked {
struct nested_packed b1;
short a1;
struct nested_packed b2;
};
/* ------ END-EXPECTED-OUTPUT ------ */
int f(struct {
......@@ -139,6 +231,18 @@ int f(struct {
struct padding_wo_named_members _6;
struct padding_weird_1 _7;
struct padding_weird_2 _8;
struct exact_1byte _100;
struct padded_1byte _101;
struct exact_2bytes _102;
struct padded_2bytes _103;
struct exact_4bytes _104;
struct padded_4bytes _105;
struct exact_8bytes _106;
struct padded_8bytes _107;
struct ff_periodic_effect _200;
struct ib_wc _201;
struct acpi_object_method _202;
struct outer_mixed_but_unpacked _203;
} *_)
{
return 0;
......
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