Commit 6ffe559a authored by Yoshiki Komachi's avatar Yoshiki Komachi Committed by Alexei Starovoitov

selftests/bpf: Add test for the packed enum member in struct/union

Add a simple test to the existing selftest program in order to make
sure that a packed enum member in struct unexceeds the struct_size.
Signed-off-by: default avatarYoshiki Komachi <komachi.yoshiki@gmail.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/1583825550-18606-3-git-send-email-komachi.yoshiki@gmail.com
parent da6c7fae
......@@ -1062,6 +1062,48 @@ static struct btf_raw_test raw_tests[] = {
.err_str = "Member exceeds struct_size",
},
/* Test member unexceeds the size of struct
*
* enum E {
* E0,
* E1,
* };
*
* struct A {
* char m;
* enum E __attribute__((packed)) n;
* };
*/
{
.descr = "size check test #5",
.raw_types = {
/* int */ /* [1] */
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, sizeof(int)),
/* char */ /* [2] */
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1),
/* enum E { */ /* [3] */
BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), 1),
BTF_ENUM_ENC(NAME_TBD, 0),
BTF_ENUM_ENC(NAME_TBD, 1),
/* } */
/* struct A { */ /* [4] */
BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 2),
BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* char m; */
BTF_MEMBER_ENC(NAME_TBD, 3, 8),/* enum E __attribute__((packed)) n; */
/* } */
BTF_END_RAW,
},
.str_sec = "\0E\0E0\0E1\0A\0m\0n",
.str_sec_size = sizeof("\0E\0E0\0E1\0A\0m\0n"),
.map_type = BPF_MAP_TYPE_ARRAY,
.map_name = "size_check5_map",
.key_size = sizeof(int),
.value_size = 2,
.key_type_id = 1,
.value_type_id = 4,
.max_entries = 4,
},
/* typedef const void * const_void_ptr;
* struct A {
* const_void_ptr m;
......
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