1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018 Facebook */
7 #include <linux/kernel.h>
8 #include <linux/filter.h>
9 #include <linux/unistd.h>
11 #include <sys/resource.h>
22 #include <bpf/libbpf.h>
25 #include "bpf_rlimit.h"
30 #define MAX_SUBPROGS 16
32 static uint32_t pass_cnt
;
33 static uint32_t error_cnt
;
34 static uint32_t skip_cnt
;
36 #define CHECK(condition, format...) ({ \
37 int __ret = !!(condition); \
39 fprintf(stderr, "%s:%d:FAIL ", __func__, __LINE__); \
40 fprintf(stderr, format); \
45 static int count_result(int err
)
52 fprintf(stderr
, "\n");
56 static int __base_pr(enum libbpf_print_level level
__attribute__((unused
)),
57 const char *format
, va_list args
)
59 return vfprintf(stderr
, format
, args
);
62 #define BTF_END_RAW 0xdeadbeef
63 #define NAME_TBD 0xdeadb33f
65 #define NAME_NTH(N) (0xffff0000 | N)
66 #define IS_NAME_NTH(X) ((X & 0xffff0000) == 0xffff0000)
67 #define GET_NAME_NTH_IDX(X) (X & 0x0000ffff)
69 #define MAX_NR_RAW_U32 1024
70 #define BTF_LOG_BUF_SIZE 65535
73 unsigned int raw_test_num
;
74 unsigned int file_test_num
;
75 unsigned int get_info_test_num
;
76 unsigned int info_raw_test_num
;
77 unsigned int dedup_test_num
;
87 static char btf_log_buf
[BTF_LOG_BUF_SIZE
];
89 static struct btf_header hdr_tmpl
= {
91 .version
= BTF_VERSION
,
92 .hdr_len
= sizeof(struct btf_header
),
95 /* several different mapv kinds(types) supported by pprint */
96 enum pprint_mapv_kind_t
{
97 PPRINT_MAPV_KIND_BASIC
= 0,
98 PPRINT_MAPV_KIND_INT128
,
101 struct btf_raw_test
{
104 const char *map_name
;
106 __u32 raw_types
[MAX_NR_RAW_U32
];
108 enum bpf_map_type map_type
;
123 enum pprint_mapv_kind_t mapv_kind
;
126 #define BTF_STR_SEC(str) \
127 .str_sec = str, .str_sec_size = sizeof(str)
129 static struct btf_raw_test raw_tests
[] = {
136 * unsigned long long m;
146 .descr
= "struct test #1",
149 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
150 /* unsigned long long */
151 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
153 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
155 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
156 /* struct A { */ /* [5] */
157 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 6), 180),
158 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
159 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
160 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
161 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
162 BTF_MEMBER_ENC(NAME_TBD
, 6, 384),/* int q[4][8] */
163 BTF_MEMBER_ENC(NAME_TBD
, 7, 1408), /* enum E r */
166 BTF_TYPE_ARRAY_ENC(4, 1, 4), /* [6] */
167 /* enum E */ /* [7] */
168 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 2), sizeof(int)),
169 BTF_ENUM_ENC(NAME_TBD
, 0),
170 BTF_ENUM_ENC(NAME_TBD
, 1),
173 .str_sec
= "\0A\0m\0n\0o\0p\0q\0r\0E\0E0\0E1",
174 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0q\0r\0E\0E0\0E1"),
175 .map_type
= BPF_MAP_TYPE_ARRAY
,
176 .map_name
= "struct_test1_map",
177 .key_size
= sizeof(int),
184 /* typedef struct b Struct_B;
189 * const Struct_B o[4];
198 .descr
= "struct test #2",
201 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
202 /* struct b [4] */ /* [2] */
203 BTF_TYPE_ARRAY_ENC(4, 1, 4),
205 /* struct A { */ /* [3] */
206 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 3), 68),
207 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int m; */
208 BTF_MEMBER_ENC(NAME_TBD
, 2, 32),/* struct B n[4] */
209 BTF_MEMBER_ENC(NAME_TBD
, 8, 288),/* const Struct_B o[4];*/
212 /* struct B { */ /* [4] */
213 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), 8),
214 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int m; */
215 BTF_MEMBER_ENC(NAME_TBD
, 1, 32),/* int n; */
218 /* const int */ /* [5] */
219 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 1),
220 /* typedef struct b Struct_B */ /* [6] */
221 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_TYPEDEF
, 0, 0), 4),
222 /* const Struct_B */ /* [7] */
223 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 6),
224 /* const Struct_B [4] */ /* [8] */
225 BTF_TYPE_ARRAY_ENC(7, 1, 4),
228 .str_sec
= "\0A\0m\0n\0o\0B\0m\0n\0Struct_B",
229 .str_sec_size
= sizeof("\0A\0m\0n\0o\0B\0m\0n\0Struct_B"),
230 .map_type
= BPF_MAP_TYPE_ARRAY
,
231 .map_name
= "struct_test2_map",
232 .key_size
= sizeof(int),
239 .descr
= "struct test #3 Invalid member offset",
242 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
243 /* int64 */ /* [2] */
244 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 64, 8),
246 /* struct A { */ /* [3] */
247 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), 16),
248 BTF_MEMBER_ENC(NAME_TBD
, 1, 64), /* int m; */
249 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* int64 n; */
253 .str_sec
= "\0A\0m\0n\0",
254 .str_sec_size
= sizeof("\0A\0m\0n\0"),
255 .map_type
= BPF_MAP_TYPE_ARRAY
,
256 .map_name
= "struct_test3_map",
257 .key_size
= sizeof(int),
262 .btf_load_err
= true,
263 .err_str
= "Invalid member bits_offset",
267 * unsigned long long m;
275 .descr
= "global data test #1",
278 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
279 /* unsigned long long */
280 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
282 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
284 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
285 /* struct A { */ /* [5] */
286 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
287 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
288 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
289 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
290 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
294 .str_sec
= "\0A\0m\0n\0o\0p",
295 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p"),
296 .map_type
= BPF_MAP_TYPE_ARRAY
,
297 .map_name
= "struct_test1_map",
298 .key_size
= sizeof(int),
306 * unsigned long long m;
312 * static struct A t; <- in .bss
315 .descr
= "global data test #2",
318 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
319 /* unsigned long long */
320 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
322 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
324 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
325 /* struct A { */ /* [5] */
326 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
327 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
328 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
329 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
330 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
332 /* static struct A t */
333 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
334 /* .bss section */ /* [7] */
335 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 48),
336 BTF_VAR_SECINFO_ENC(6, 0, 48),
339 .str_sec
= "\0A\0m\0n\0o\0p\0t\0.bss",
340 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
341 .map_type
= BPF_MAP_TYPE_ARRAY
,
343 .key_size
= sizeof(int),
350 .descr
= "global data test #3",
353 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
355 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [2] */
356 /* .bss section */ /* [3] */
357 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
358 BTF_VAR_SECINFO_ENC(2, 0, 4),
361 .str_sec
= "\0t\0.bss",
362 .str_sec_size
= sizeof("\0t\0.bss"),
363 .map_type
= BPF_MAP_TYPE_ARRAY
,
365 .key_size
= sizeof(int),
372 .descr
= "global data test #4, unsupported linkage",
375 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
377 BTF_VAR_ENC(NAME_TBD
, 1, 2), /* [2] */
378 /* .bss section */ /* [3] */
379 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
380 BTF_VAR_SECINFO_ENC(2, 0, 4),
383 .str_sec
= "\0t\0.bss",
384 .str_sec_size
= sizeof("\0t\0.bss"),
385 .map_type
= BPF_MAP_TYPE_ARRAY
,
387 .key_size
= sizeof(int),
392 .btf_load_err
= true,
393 .err_str
= "Linkage not supported",
396 .descr
= "global data test #5, invalid var type",
399 BTF_VAR_ENC(NAME_TBD
, 0, 0), /* [1] */
400 /* .bss section */ /* [2] */
401 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
402 BTF_VAR_SECINFO_ENC(1, 0, 4),
405 .str_sec
= "\0t\0.bss",
406 .str_sec_size
= sizeof("\0t\0.bss"),
407 .map_type
= BPF_MAP_TYPE_ARRAY
,
409 .key_size
= sizeof(int),
414 .btf_load_err
= true,
415 .err_str
= "Invalid type_id",
418 .descr
= "global data test #6, invalid var type (fwd type)",
421 BTF_TYPE_ENC(NAME_TBD
,
422 BTF_INFO_ENC(BTF_KIND_FWD
, 1, 0), 0), /* [1] */
423 /* static union A t */
424 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [2] */
425 /* .bss section */ /* [3] */
426 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
427 BTF_VAR_SECINFO_ENC(2, 0, 4),
430 .str_sec
= "\0A\0t\0.bss",
431 .str_sec_size
= sizeof("\0A\0t\0.bss"),
432 .map_type
= BPF_MAP_TYPE_ARRAY
,
434 .key_size
= sizeof(int),
439 .btf_load_err
= true,
440 .err_str
= "Invalid type",
443 .descr
= "global data test #7, invalid var type (fwd type)",
446 BTF_TYPE_ENC(NAME_TBD
,
447 BTF_INFO_ENC(BTF_KIND_FWD
, 1, 0), 0), /* [1] */
448 /* static union A t */
449 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [2] */
450 /* .bss section */ /* [3] */
451 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
452 BTF_VAR_SECINFO_ENC(1, 0, 4),
455 .str_sec
= "\0A\0t\0.bss",
456 .str_sec_size
= sizeof("\0A\0t\0.bss"),
457 .map_type
= BPF_MAP_TYPE_ARRAY
,
459 .key_size
= sizeof(int),
464 .btf_load_err
= true,
465 .err_str
= "Invalid type",
468 .descr
= "global data test #8, invalid var size",
471 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
472 /* unsigned long long */
473 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
475 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
477 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
478 /* struct A { */ /* [5] */
479 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
480 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
481 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
482 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
483 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
485 /* static struct A t */
486 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
487 /* .bss section */ /* [7] */
488 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 48),
489 BTF_VAR_SECINFO_ENC(6, 0, 47),
492 .str_sec
= "\0A\0m\0n\0o\0p\0t\0.bss",
493 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
494 .map_type
= BPF_MAP_TYPE_ARRAY
,
496 .key_size
= sizeof(int),
501 .btf_load_err
= true,
502 .err_str
= "Invalid size",
505 .descr
= "global data test #9, invalid var size",
508 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
509 /* unsigned long long */
510 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
512 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
514 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
515 /* struct A { */ /* [5] */
516 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
517 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
518 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
519 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
520 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
522 /* static struct A t */
523 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
524 /* .bss section */ /* [7] */
525 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 46),
526 BTF_VAR_SECINFO_ENC(6, 0, 48),
529 .str_sec
= "\0A\0m\0n\0o\0p\0t\0.bss",
530 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
531 .map_type
= BPF_MAP_TYPE_ARRAY
,
533 .key_size
= sizeof(int),
538 .btf_load_err
= true,
539 .err_str
= "Invalid size",
542 .descr
= "global data test #10, invalid var size",
545 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
546 /* unsigned long long */
547 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
549 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
551 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
552 /* struct A { */ /* [5] */
553 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
554 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
555 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
556 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
557 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
559 /* static struct A t */
560 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
561 /* .bss section */ /* [7] */
562 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 46),
563 BTF_VAR_SECINFO_ENC(6, 0, 46),
566 .str_sec
= "\0A\0m\0n\0o\0p\0t\0.bss",
567 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
568 .map_type
= BPF_MAP_TYPE_ARRAY
,
570 .key_size
= sizeof(int),
575 .btf_load_err
= true,
576 .err_str
= "Invalid size",
579 .descr
= "global data test #11, multiple section members",
582 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
583 /* unsigned long long */
584 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
586 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
588 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
589 /* struct A { */ /* [5] */
590 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
591 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
592 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
593 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
594 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
596 /* static struct A t */
597 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
599 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [7] */
600 /* .bss section */ /* [8] */
601 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 2), 62),
602 BTF_VAR_SECINFO_ENC(6, 10, 48),
603 BTF_VAR_SECINFO_ENC(7, 58, 4),
606 .str_sec
= "\0A\0m\0n\0o\0p\0t\0u\0.bss",
607 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
608 .map_type
= BPF_MAP_TYPE_ARRAY
,
610 .key_size
= sizeof(int),
617 .descr
= "global data test #12, invalid offset",
620 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
621 /* unsigned long long */
622 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
624 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
626 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
627 /* struct A { */ /* [5] */
628 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
629 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
630 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
631 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
632 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
634 /* static struct A t */
635 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
637 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [7] */
638 /* .bss section */ /* [8] */
639 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 2), 62),
640 BTF_VAR_SECINFO_ENC(6, 10, 48),
641 BTF_VAR_SECINFO_ENC(7, 60, 4),
644 .str_sec
= "\0A\0m\0n\0o\0p\0t\0u\0.bss",
645 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
646 .map_type
= BPF_MAP_TYPE_ARRAY
,
648 .key_size
= sizeof(int),
653 .btf_load_err
= true,
654 .err_str
= "Invalid offset+size",
657 .descr
= "global data test #13, invalid offset",
660 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
661 /* unsigned long long */
662 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
664 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
666 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
667 /* struct A { */ /* [5] */
668 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
669 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
670 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
671 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
672 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
674 /* static struct A t */
675 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
677 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [7] */
678 /* .bss section */ /* [8] */
679 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 2), 62),
680 BTF_VAR_SECINFO_ENC(6, 10, 48),
681 BTF_VAR_SECINFO_ENC(7, 12, 4),
684 .str_sec
= "\0A\0m\0n\0o\0p\0t\0u\0.bss",
685 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
686 .map_type
= BPF_MAP_TYPE_ARRAY
,
688 .key_size
= sizeof(int),
693 .btf_load_err
= true,
694 .err_str
= "Invalid offset",
697 .descr
= "global data test #14, invalid offset",
700 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
701 /* unsigned long long */
702 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
704 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
706 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
707 /* struct A { */ /* [5] */
708 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
709 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
710 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
711 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
712 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
714 /* static struct A t */
715 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
717 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [7] */
718 /* .bss section */ /* [8] */
719 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 2), 62),
720 BTF_VAR_SECINFO_ENC(7, 58, 4),
721 BTF_VAR_SECINFO_ENC(6, 10, 48),
724 .str_sec
= "\0A\0m\0n\0o\0p\0t\0u\0.bss",
725 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
726 .map_type
= BPF_MAP_TYPE_ARRAY
,
728 .key_size
= sizeof(int),
733 .btf_load_err
= true,
734 .err_str
= "Invalid offset",
737 .descr
= "global data test #15, not var kind",
740 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
741 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [2] */
742 /* .bss section */ /* [3] */
743 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
744 BTF_VAR_SECINFO_ENC(1, 0, 4),
747 .str_sec
= "\0A\0t\0.bss",
748 .str_sec_size
= sizeof("\0A\0t\0.bss"),
749 .map_type
= BPF_MAP_TYPE_ARRAY
,
751 .key_size
= sizeof(int),
756 .btf_load_err
= true,
757 .err_str
= "Not a VAR kind member",
760 .descr
= "global data test #16, invalid var referencing sec",
763 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
764 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [2] */
765 BTF_VAR_ENC(NAME_TBD
, 2, 0), /* [3] */
766 /* a section */ /* [4] */
767 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
768 BTF_VAR_SECINFO_ENC(3, 0, 4),
769 /* a section */ /* [5] */
770 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
771 BTF_VAR_SECINFO_ENC(6, 0, 4),
772 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [6] */
775 .str_sec
= "\0A\0t\0s\0a\0a",
776 .str_sec_size
= sizeof("\0A\0t\0s\0a\0a"),
777 .map_type
= BPF_MAP_TYPE_ARRAY
,
779 .key_size
= sizeof(int),
784 .btf_load_err
= true,
785 .err_str
= "Invalid type_id",
788 .descr
= "global data test #17, invalid var referencing var",
791 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
792 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [2] */
793 BTF_VAR_ENC(NAME_TBD
, 2, 0), /* [3] */
794 /* a section */ /* [4] */
795 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
796 BTF_VAR_SECINFO_ENC(3, 0, 4),
799 .str_sec
= "\0A\0t\0s\0a\0a",
800 .str_sec_size
= sizeof("\0A\0t\0s\0a\0a"),
801 .map_type
= BPF_MAP_TYPE_ARRAY
,
803 .key_size
= sizeof(int),
808 .btf_load_err
= true,
809 .err_str
= "Invalid type_id",
812 .descr
= "global data test #18, invalid var loop",
815 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
816 BTF_VAR_ENC(NAME_TBD
, 2, 0), /* [2] */
817 /* .bss section */ /* [3] */
818 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
819 BTF_VAR_SECINFO_ENC(2, 0, 4),
822 .str_sec
= "\0A\0t\0aaa",
823 .str_sec_size
= sizeof("\0A\0t\0aaa"),
824 .map_type
= BPF_MAP_TYPE_ARRAY
,
826 .key_size
= sizeof(int),
831 .btf_load_err
= true,
832 .err_str
= "Invalid type_id",
835 .descr
= "global data test #19, invalid var referencing var",
838 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
839 BTF_VAR_ENC(NAME_TBD
, 3, 0), /* [2] */
840 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [3] */
843 .str_sec
= "\0A\0t\0s\0a\0a",
844 .str_sec_size
= sizeof("\0A\0t\0s\0a\0a"),
845 .map_type
= BPF_MAP_TYPE_ARRAY
,
847 .key_size
= sizeof(int),
852 .btf_load_err
= true,
853 .err_str
= "Invalid type_id",
856 .descr
= "global data test #20, invalid ptr referencing var",
859 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
860 /* PTR type_id=3 */ /* [2] */
861 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 3),
862 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [3] */
865 .str_sec
= "\0A\0t\0s\0a\0a",
866 .str_sec_size
= sizeof("\0A\0t\0s\0a\0a"),
867 .map_type
= BPF_MAP_TYPE_ARRAY
,
869 .key_size
= sizeof(int),
874 .btf_load_err
= true,
875 .err_str
= "Invalid type_id",
878 .descr
= "global data test #21, var included in struct",
881 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
882 /* struct A { */ /* [2] */
883 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), sizeof(int) * 2),
884 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int m; */
885 BTF_MEMBER_ENC(NAME_TBD
, 3, 32),/* VAR type_id=3; */
887 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [3] */
890 .str_sec
= "\0A\0t\0s\0a\0a",
891 .str_sec_size
= sizeof("\0A\0t\0s\0a\0a"),
892 .map_type
= BPF_MAP_TYPE_ARRAY
,
894 .key_size
= sizeof(int),
899 .btf_load_err
= true,
900 .err_str
= "Invalid member",
903 .descr
= "global data test #22, array of var",
906 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
907 BTF_TYPE_ARRAY_ENC(3, 1, 4), /* [2] */
908 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [3] */
911 .str_sec
= "\0A\0t\0s\0a\0a",
912 .str_sec_size
= sizeof("\0A\0t\0s\0a\0a"),
913 .map_type
= BPF_MAP_TYPE_ARRAY
,
915 .key_size
= sizeof(int),
920 .btf_load_err
= true,
921 .err_str
= "Invalid elem",
923 /* Test member exceeds the size of struct.
931 .descr
= "size check test #1",
934 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
935 /* struct A { */ /* [2] */
936 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), sizeof(int) * 2 - 1),
937 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int m; */
938 BTF_MEMBER_ENC(NAME_TBD
, 1, 32),/* int n; */
942 .str_sec
= "\0A\0m\0n",
943 .str_sec_size
= sizeof("\0A\0m\0n"),
944 .map_type
= BPF_MAP_TYPE_ARRAY
,
945 .map_name
= "size_check1_map",
946 .key_size
= sizeof(int),
951 .btf_load_err
= true,
952 .err_str
= "Member exceeds struct_size",
955 /* Test member exeeds the size of struct
963 .descr
= "size check test #2",
966 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, sizeof(int)),
967 /* int[2] */ /* [2] */
968 BTF_TYPE_ARRAY_ENC(1, 1, 2),
969 /* struct A { */ /* [3] */
970 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), sizeof(int) * 3 - 1),
971 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int m; */
972 BTF_MEMBER_ENC(NAME_TBD
, 2, 32),/* int n[2]; */
976 .str_sec
= "\0A\0m\0n",
977 .str_sec_size
= sizeof("\0A\0m\0n"),
978 .map_type
= BPF_MAP_TYPE_ARRAY
,
979 .map_name
= "size_check2_map",
980 .key_size
= sizeof(int),
985 .btf_load_err
= true,
986 .err_str
= "Member exceeds struct_size",
989 /* Test member exeeds the size of struct
997 .descr
= "size check test #3",
1000 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, sizeof(int)),
1001 /* void* */ /* [2] */
1002 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 0),
1003 /* struct A { */ /* [3] */
1004 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), sizeof(int) + sizeof(void *) - 1),
1005 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int m; */
1006 BTF_MEMBER_ENC(NAME_TBD
, 2, 32),/* void *n; */
1010 .str_sec
= "\0A\0m\0n",
1011 .str_sec_size
= sizeof("\0A\0m\0n"),
1012 .map_type
= BPF_MAP_TYPE_ARRAY
,
1013 .map_name
= "size_check3_map",
1014 .key_size
= sizeof(int),
1019 .btf_load_err
= true,
1020 .err_str
= "Member exceeds struct_size",
1023 /* Test member exceeds the size of struct
1036 .descr
= "size check test #4",
1039 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, sizeof(int)),
1040 /* enum E { */ /* [2] */
1041 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 2), sizeof(int)),
1042 BTF_ENUM_ENC(NAME_TBD
, 0),
1043 BTF_ENUM_ENC(NAME_TBD
, 1),
1045 /* struct A { */ /* [3] */
1046 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), sizeof(int) * 2 - 1),
1047 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int m; */
1048 BTF_MEMBER_ENC(NAME_TBD
, 2, 32),/* enum E n; */
1052 .str_sec
= "\0E\0E0\0E1\0A\0m\0n",
1053 .str_sec_size
= sizeof("\0E\0E0\0E1\0A\0m\0n"),
1054 .map_type
= BPF_MAP_TYPE_ARRAY
,
1055 .map_name
= "size_check4_map",
1056 .key_size
= sizeof(int),
1061 .btf_load_err
= true,
1062 .err_str
= "Member exceeds struct_size",
1065 /* Test member unexceeds the size of struct
1074 * enum E __attribute__((packed)) n;
1078 .descr
= "size check test #5",
1081 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, sizeof(int)),
1082 /* char */ /* [2] */
1083 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1),
1084 /* enum E { */ /* [3] */
1085 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 2), 1),
1086 BTF_ENUM_ENC(NAME_TBD
, 0),
1087 BTF_ENUM_ENC(NAME_TBD
, 1),
1089 /* struct A { */ /* [4] */
1090 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), 2),
1091 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* char m; */
1092 BTF_MEMBER_ENC(NAME_TBD
, 3, 8),/* enum E __attribute__((packed)) n; */
1096 .str_sec
= "\0E\0E0\0E1\0A\0m\0n",
1097 .str_sec_size
= sizeof("\0E\0E0\0E1\0A\0m\0n"),
1098 .map_type
= BPF_MAP_TYPE_ARRAY
,
1099 .map_name
= "size_check5_map",
1100 .key_size
= sizeof(int),
1107 /* typedef const void * const_void_ptr;
1113 .descr
= "void test #1",
1116 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1117 /* const void */ /* [2] */
1118 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 0),
1119 /* const void* */ /* [3] */
1120 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 2),
1121 /* typedef const void * const_void_ptr */
1122 BTF_TYPEDEF_ENC(NAME_TBD
, 3), /* [4] */
1123 /* struct A { */ /* [5] */
1124 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), sizeof(void *)),
1125 /* const_void_ptr m; */
1126 BTF_MEMBER_ENC(NAME_TBD
, 4, 0),
1130 .str_sec
= "\0const_void_ptr\0A\0m",
1131 .str_sec_size
= sizeof("\0const_void_ptr\0A\0m"),
1132 .map_type
= BPF_MAP_TYPE_ARRAY
,
1133 .map_name
= "void_test1_map",
1134 .key_size
= sizeof(int),
1135 .value_size
= sizeof(void *),
1146 .descr
= "void test #2",
1149 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1150 /* const void */ /* [2] */
1151 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 0),
1152 /* struct A { */ /* [3] */
1153 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), 8),
1155 BTF_MEMBER_ENC(NAME_TBD
, 2, 0),
1159 .str_sec
= "\0A\0m",
1160 .str_sec_size
= sizeof("\0A\0m"),
1161 .map_type
= BPF_MAP_TYPE_ARRAY
,
1162 .map_name
= "void_test2_map",
1163 .key_size
= sizeof(int),
1164 .value_size
= sizeof(void *),
1168 .btf_load_err
= true,
1169 .err_str
= "Invalid member",
1172 /* typedef const void * const_void_ptr;
1176 .descr
= "void test #3",
1179 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1180 /* const void */ /* [2] */
1181 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 0),
1182 /* const void* */ /* [3] */
1183 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 2),
1184 /* typedef const void * const_void_ptr */
1185 BTF_TYPEDEF_ENC(NAME_TBD
, 3), /* [4] */
1186 /* const_void_ptr[4] */
1187 BTF_TYPE_ARRAY_ENC(4, 1, 4), /* [5] */
1190 .str_sec
= "\0const_void_ptr",
1191 .str_sec_size
= sizeof("\0const_void_ptr"),
1192 .map_type
= BPF_MAP_TYPE_ARRAY
,
1193 .map_name
= "void_test3_map",
1194 .key_size
= sizeof(int),
1195 .value_size
= sizeof(void *) * 4,
1203 .descr
= "void test #4",
1206 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1207 /* const void */ /* [2] */
1208 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 0),
1209 /* const void[4] */ /* [3] */
1210 BTF_TYPE_ARRAY_ENC(2, 1, 4),
1213 .str_sec
= "\0A\0m",
1214 .str_sec_size
= sizeof("\0A\0m"),
1215 .map_type
= BPF_MAP_TYPE_ARRAY
,
1216 .map_name
= "void_test4_map",
1217 .key_size
= sizeof(int),
1218 .value_size
= sizeof(void *) * 4,
1222 .btf_load_err
= true,
1223 .err_str
= "Invalid elem",
1226 /* Array_A <------------------+
1227 * elem_type == Array_B |
1230 * Array_B <-------- + |
1231 * elem_type == Array A --+
1234 .descr
= "loop test #1",
1237 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1238 /* Array_A */ /* [2] */
1239 BTF_TYPE_ARRAY_ENC(3, 1, 8),
1240 /* Array_B */ /* [3] */
1241 BTF_TYPE_ARRAY_ENC(2, 1, 8),
1245 .str_sec_size
= sizeof(""),
1246 .map_type
= BPF_MAP_TYPE_ARRAY
,
1247 .map_name
= "loop_test1_map",
1248 .key_size
= sizeof(int),
1249 .value_size
= sizeof(sizeof(int) * 8),
1253 .btf_load_err
= true,
1254 .err_str
= "Loop detected",
1257 /* typedef is _before_ the BTF type of Array_A and Array_B
1259 * typedef Array_B int_array;
1261 * Array_A <------------------+
1262 * elem_type == int_array |
1265 * Array_B <-------- + |
1266 * elem_type == Array_A --+
1269 .descr
= "loop test #2",
1272 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
1273 /* typedef Array_B int_array */
1274 BTF_TYPEDEF_ENC(1, 4), /* [2] */
1276 BTF_TYPE_ARRAY_ENC(2, 1, 8), /* [3] */
1278 BTF_TYPE_ARRAY_ENC(3, 1, 8), /* [4] */
1281 .str_sec
= "\0int_array\0",
1282 .str_sec_size
= sizeof("\0int_array"),
1283 .map_type
= BPF_MAP_TYPE_ARRAY
,
1284 .map_name
= "loop_test2_map",
1285 .key_size
= sizeof(int),
1286 .value_size
= sizeof(sizeof(int) * 8),
1290 .btf_load_err
= true,
1291 .err_str
= "Loop detected",
1294 /* Array_A <------------------+
1295 * elem_type == Array_B |
1298 * Array_B <-------- + |
1299 * elem_type == Array_A --+
1302 .descr
= "loop test #3",
1305 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1306 /* Array_A */ /* [2] */
1307 BTF_TYPE_ARRAY_ENC(3, 1, 8),
1308 /* Array_B */ /* [3] */
1309 BTF_TYPE_ARRAY_ENC(2, 1, 8),
1313 .str_sec_size
= sizeof(""),
1314 .map_type
= BPF_MAP_TYPE_ARRAY
,
1315 .map_name
= "loop_test3_map",
1316 .key_size
= sizeof(int),
1317 .value_size
= sizeof(sizeof(int) * 8),
1321 .btf_load_err
= true,
1322 .err_str
= "Loop detected",
1325 /* typedef is _between_ the BTF type of Array_A and Array_B
1327 * typedef Array_B int_array;
1329 * Array_A <------------------+
1330 * elem_type == int_array |
1333 * Array_B <-------- + |
1334 * elem_type == Array_A --+
1337 .descr
= "loop test #4",
1340 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1341 /* Array_A */ /* [2] */
1342 BTF_TYPE_ARRAY_ENC(3, 1, 8),
1343 /* typedef Array_B int_array */ /* [3] */
1344 BTF_TYPEDEF_ENC(NAME_TBD
, 4),
1345 /* Array_B */ /* [4] */
1346 BTF_TYPE_ARRAY_ENC(2, 1, 8),
1349 .str_sec
= "\0int_array\0",
1350 .str_sec_size
= sizeof("\0int_array"),
1351 .map_type
= BPF_MAP_TYPE_ARRAY
,
1352 .map_name
= "loop_test4_map",
1353 .key_size
= sizeof(int),
1354 .value_size
= sizeof(sizeof(int) * 8),
1358 .btf_load_err
= true,
1359 .err_str
= "Loop detected",
1362 /* typedef struct B Struct_B
1375 .descr
= "loop test #5",
1378 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
1379 /* struct A */ /* [2] */
1380 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), 8),
1381 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int x; */
1382 BTF_MEMBER_ENC(NAME_TBD
, 3, 32),/* Struct_B y; */
1383 /* typedef struct B Struct_B */
1384 BTF_TYPEDEF_ENC(NAME_TBD
, 4), /* [3] */
1385 /* struct B */ /* [4] */
1386 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), 8),
1387 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int x; */
1388 BTF_MEMBER_ENC(NAME_TBD
, 2, 32),/* struct A y; */
1391 .str_sec
= "\0A\0x\0y\0Struct_B\0B\0x\0y",
1392 .str_sec_size
= sizeof("\0A\0x\0y\0Struct_B\0B\0x\0y"),
1393 .map_type
= BPF_MAP_TYPE_ARRAY
,
1394 .map_name
= "loop_test5_map",
1395 .key_size
= sizeof(int),
1400 .btf_load_err
= true,
1401 .err_str
= "Loop detected",
1406 * struct A array_a[4];
1410 .descr
= "loop test #6",
1413 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
1414 BTF_TYPE_ARRAY_ENC(3, 1, 4), /* [2] */
1415 /* struct A */ /* [3] */
1416 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), 8),
1417 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int x; */
1418 BTF_MEMBER_ENC(NAME_TBD
, 2, 32),/* struct A array_a[4]; */
1421 .str_sec
= "\0A\0x\0y",
1422 .str_sec_size
= sizeof("\0A\0x\0y"),
1423 .map_type
= BPF_MAP_TYPE_ARRAY
,
1424 .map_name
= "loop_test6_map",
1425 .key_size
= sizeof(int),
1430 .btf_load_err
= true,
1431 .err_str
= "Loop detected",
1435 .descr
= "loop test #7",
1438 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1439 /* struct A { */ /* [2] */
1440 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), sizeof(void *)),
1441 /* const void *m; */
1442 BTF_MEMBER_ENC(NAME_TBD
, 3, 0),
1443 /* CONST type_id=3 */ /* [3] */
1444 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 4),
1445 /* PTR type_id=2 */ /* [4] */
1446 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 3),
1449 .str_sec
= "\0A\0m",
1450 .str_sec_size
= sizeof("\0A\0m"),
1451 .map_type
= BPF_MAP_TYPE_ARRAY
,
1452 .map_name
= "loop_test7_map",
1453 .key_size
= sizeof(int),
1454 .value_size
= sizeof(void *),
1458 .btf_load_err
= true,
1459 .err_str
= "Loop detected",
1463 .descr
= "loop test #8",
1466 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1467 /* struct A { */ /* [2] */
1468 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), sizeof(void *)),
1469 /* const void *m; */
1470 BTF_MEMBER_ENC(NAME_TBD
, 4, 0),
1471 /* struct B { */ /* [3] */
1472 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), sizeof(void *)),
1473 /* const void *n; */
1474 BTF_MEMBER_ENC(NAME_TBD
, 6, 0),
1475 /* CONST type_id=5 */ /* [4] */
1476 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 5),
1477 /* PTR type_id=6 */ /* [5] */
1478 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 6),
1479 /* CONST type_id=7 */ /* [6] */
1480 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 7),
1481 /* PTR type_id=4 */ /* [7] */
1482 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 4),
1485 .str_sec
= "\0A\0m\0B\0n",
1486 .str_sec_size
= sizeof("\0A\0m\0B\0n"),
1487 .map_type
= BPF_MAP_TYPE_ARRAY
,
1488 .map_name
= "loop_test8_map",
1489 .key_size
= sizeof(int),
1490 .value_size
= sizeof(void *),
1494 .btf_load_err
= true,
1495 .err_str
= "Loop detected",
1499 .descr
= "string section does not end with null",
1502 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
1506 .str_sec_size
= sizeof("\0int") - 1,
1507 .map_type
= BPF_MAP_TYPE_ARRAY
,
1508 .map_name
= "hdr_test_map",
1509 .key_size
= sizeof(int),
1510 .value_size
= sizeof(int),
1514 .btf_load_err
= true,
1515 .err_str
= "Invalid string section",
1519 .descr
= "empty string section",
1522 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1527 .map_type
= BPF_MAP_TYPE_ARRAY
,
1528 .map_name
= "hdr_test_map",
1529 .key_size
= sizeof(int),
1530 .value_size
= sizeof(int),
1534 .btf_load_err
= true,
1535 .err_str
= "Invalid string section",
1539 .descr
= "empty type section",
1544 .str_sec_size
= sizeof("\0int"),
1545 .map_type
= BPF_MAP_TYPE_ARRAY
,
1546 .map_name
= "hdr_test_map",
1547 .key_size
= sizeof(int),
1548 .value_size
= sizeof(int),
1552 .btf_load_err
= true,
1553 .err_str
= "No type found",
1557 .descr
= "btf_header test. Longer hdr_len",
1560 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
1564 .str_sec_size
= sizeof("\0int"),
1565 .map_type
= BPF_MAP_TYPE_ARRAY
,
1566 .map_name
= "hdr_test_map",
1567 .key_size
= sizeof(int),
1568 .value_size
= sizeof(int),
1572 .btf_load_err
= true,
1574 .err_str
= "Unsupported btf_header",
1578 .descr
= "btf_header test. Gap between hdr and type",
1581 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
1585 .str_sec_size
= sizeof("\0int"),
1586 .map_type
= BPF_MAP_TYPE_ARRAY
,
1587 .map_name
= "hdr_test_map",
1588 .key_size
= sizeof(int),
1589 .value_size
= sizeof(int),
1593 .btf_load_err
= true,
1594 .type_off_delta
= 4,
1595 .err_str
= "Unsupported section found",
1599 .descr
= "btf_header test. Gap between type and str",
1602 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
1606 .str_sec_size
= sizeof("\0int"),
1607 .map_type
= BPF_MAP_TYPE_ARRAY
,
1608 .map_name
= "hdr_test_map",
1609 .key_size
= sizeof(int),
1610 .value_size
= sizeof(int),
1614 .btf_load_err
= true,
1616 .err_str
= "Unsupported section found",
1620 .descr
= "btf_header test. Overlap between type and str",
1623 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
1627 .str_sec_size
= sizeof("\0int"),
1628 .map_type
= BPF_MAP_TYPE_ARRAY
,
1629 .map_name
= "hdr_test_map",
1630 .key_size
= sizeof(int),
1631 .value_size
= sizeof(int),
1635 .btf_load_err
= true,
1636 .str_off_delta
= -4,
1637 .err_str
= "Section overlap found",
1641 .descr
= "btf_header test. Larger BTF size",
1644 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
1648 .str_sec_size
= sizeof("\0int"),
1649 .map_type
= BPF_MAP_TYPE_ARRAY
,
1650 .map_name
= "hdr_test_map",
1651 .key_size
= sizeof(int),
1652 .value_size
= sizeof(int),
1656 .btf_load_err
= true,
1657 .str_len_delta
= -4,
1658 .err_str
= "Unsupported section found",
1662 .descr
= "btf_header test. Smaller BTF size",
1665 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
1669 .str_sec_size
= sizeof("\0int"),
1670 .map_type
= BPF_MAP_TYPE_ARRAY
,
1671 .map_name
= "hdr_test_map",
1672 .key_size
= sizeof(int),
1673 .value_size
= sizeof(int),
1677 .btf_load_err
= true,
1679 .err_str
= "Total section length too long",
1683 .descr
= "array test. index_type/elem_type \"int\"",
1686 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1687 /* int[16] */ /* [2] */
1688 BTF_TYPE_ARRAY_ENC(1, 1, 16),
1692 .str_sec_size
= sizeof(""),
1693 .map_type
= BPF_MAP_TYPE_ARRAY
,
1694 .map_name
= "array_test_map",
1695 .key_size
= sizeof(int),
1696 .value_size
= sizeof(int),
1703 .descr
= "array test. index_type/elem_type \"const int\"",
1706 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1707 /* int[16] */ /* [2] */
1708 BTF_TYPE_ARRAY_ENC(3, 3, 16),
1709 /* CONST type_id=1 */ /* [3] */
1710 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 1),
1714 .str_sec_size
= sizeof(""),
1715 .map_type
= BPF_MAP_TYPE_ARRAY
,
1716 .map_name
= "array_test_map",
1717 .key_size
= sizeof(int),
1718 .value_size
= sizeof(int),
1725 .descr
= "array test. index_type \"const int:31\"",
1728 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1729 /* int:31 */ /* [2] */
1730 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 31, 4),
1731 /* int[16] */ /* [3] */
1732 BTF_TYPE_ARRAY_ENC(1, 4, 16),
1733 /* CONST type_id=2 */ /* [4] */
1734 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 2),
1738 .str_sec_size
= sizeof(""),
1739 .map_type
= BPF_MAP_TYPE_ARRAY
,
1740 .map_name
= "array_test_map",
1741 .key_size
= sizeof(int),
1742 .value_size
= sizeof(int),
1746 .btf_load_err
= true,
1747 .err_str
= "Invalid index",
1751 .descr
= "array test. elem_type \"const int:31\"",
1754 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1755 /* int:31 */ /* [2] */
1756 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 31, 4),
1757 /* int[16] */ /* [3] */
1758 BTF_TYPE_ARRAY_ENC(4, 1, 16),
1759 /* CONST type_id=2 */ /* [4] */
1760 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 2),
1764 .str_sec_size
= sizeof(""),
1765 .map_type
= BPF_MAP_TYPE_ARRAY
,
1766 .map_name
= "array_test_map",
1767 .key_size
= sizeof(int),
1768 .value_size
= sizeof(int),
1772 .btf_load_err
= true,
1773 .err_str
= "Invalid array of int",
1777 .descr
= "array test. index_type \"void\"",
1780 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1781 /* int[16] */ /* [2] */
1782 BTF_TYPE_ARRAY_ENC(1, 0, 16),
1786 .str_sec_size
= sizeof(""),
1787 .map_type
= BPF_MAP_TYPE_ARRAY
,
1788 .map_name
= "array_test_map",
1789 .key_size
= sizeof(int),
1790 .value_size
= sizeof(int),
1794 .btf_load_err
= true,
1795 .err_str
= "Invalid index",
1799 .descr
= "array test. index_type \"const void\"",
1802 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1803 /* int[16] */ /* [2] */
1804 BTF_TYPE_ARRAY_ENC(1, 3, 16),
1805 /* CONST type_id=0 (void) */ /* [3] */
1806 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 0),
1810 .str_sec_size
= sizeof(""),
1811 .map_type
= BPF_MAP_TYPE_ARRAY
,
1812 .map_name
= "array_test_map",
1813 .key_size
= sizeof(int),
1814 .value_size
= sizeof(int),
1818 .btf_load_err
= true,
1819 .err_str
= "Invalid index",
1823 .descr
= "array test. elem_type \"const void\"",
1826 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1827 /* int[16] */ /* [2] */
1828 BTF_TYPE_ARRAY_ENC(3, 1, 16),
1829 /* CONST type_id=0 (void) */ /* [3] */
1830 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 0),
1834 .str_sec_size
= sizeof(""),
1835 .map_type
= BPF_MAP_TYPE_ARRAY
,
1836 .map_name
= "array_test_map",
1837 .key_size
= sizeof(int),
1838 .value_size
= sizeof(int),
1842 .btf_load_err
= true,
1843 .err_str
= "Invalid elem",
1847 .descr
= "array test. elem_type \"const void *\"",
1850 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1851 /* const void *[16] */ /* [2] */
1852 BTF_TYPE_ARRAY_ENC(3, 1, 16),
1853 /* CONST type_id=4 */ /* [3] */
1854 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 4),
1855 /* void* */ /* [4] */
1856 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 0),
1860 .str_sec_size
= sizeof(""),
1861 .map_type
= BPF_MAP_TYPE_ARRAY
,
1862 .map_name
= "array_test_map",
1863 .key_size
= sizeof(int),
1864 .value_size
= sizeof(int),
1871 .descr
= "array test. index_type \"const void *\"",
1874 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1875 /* const void *[16] */ /* [2] */
1876 BTF_TYPE_ARRAY_ENC(3, 3, 16),
1877 /* CONST type_id=4 */ /* [3] */
1878 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 4),
1879 /* void* */ /* [4] */
1880 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 0),
1884 .str_sec_size
= sizeof(""),
1885 .map_type
= BPF_MAP_TYPE_ARRAY
,
1886 .map_name
= "array_test_map",
1887 .key_size
= sizeof(int),
1888 .value_size
= sizeof(int),
1892 .btf_load_err
= true,
1893 .err_str
= "Invalid index",
1897 .descr
= "array test. t->size != 0\"",
1900 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1901 /* int[16] */ /* [2] */
1902 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ARRAY
, 0, 0), 1),
1903 BTF_ARRAY_ENC(1, 1, 16),
1907 .str_sec_size
= sizeof(""),
1908 .map_type
= BPF_MAP_TYPE_ARRAY
,
1909 .map_name
= "array_test_map",
1910 .key_size
= sizeof(int),
1911 .value_size
= sizeof(int),
1915 .btf_load_err
= true,
1916 .err_str
= "size != 0",
1920 .descr
= "int test. invalid int_data",
1922 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_INT
, 0, 0), 4),
1927 .str_sec_size
= sizeof(""),
1928 .map_type
= BPF_MAP_TYPE_ARRAY
,
1929 .map_name
= "array_test_map",
1930 .key_size
= sizeof(int),
1931 .value_size
= sizeof(int),
1935 .btf_load_err
= true,
1936 .err_str
= "Invalid int_data",
1940 .descr
= "invalid BTF_INFO",
1943 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1944 BTF_TYPE_ENC(0, 0x10000000, 4),
1948 .str_sec_size
= sizeof(""),
1949 .map_type
= BPF_MAP_TYPE_ARRAY
,
1950 .map_name
= "array_test_map",
1951 .key_size
= sizeof(int),
1952 .value_size
= sizeof(int),
1956 .btf_load_err
= true,
1957 .err_str
= "Invalid btf_info",
1961 .descr
= "fwd test. t->type != 0\"",
1964 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1965 /* fwd type */ /* [2] */
1966 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FWD
, 0, 0), 1),
1970 .str_sec_size
= sizeof(""),
1971 .map_type
= BPF_MAP_TYPE_ARRAY
,
1972 .map_name
= "fwd_test_map",
1973 .key_size
= sizeof(int),
1974 .value_size
= sizeof(int),
1978 .btf_load_err
= true,
1979 .err_str
= "type != 0",
1983 .descr
= "typedef (invalid name, name_off = 0)",
1985 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
1986 BTF_TYPEDEF_ENC(0, 1), /* [2] */
1989 .str_sec
= "\0__int",
1990 .str_sec_size
= sizeof("\0__int"),
1991 .map_type
= BPF_MAP_TYPE_ARRAY
,
1992 .map_name
= "typedef_check_btf",
1993 .key_size
= sizeof(int),
1994 .value_size
= sizeof(int),
1998 .btf_load_err
= true,
1999 .err_str
= "Invalid name",
2003 .descr
= "typedef (invalid name, invalid identifier)",
2005 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2006 BTF_TYPEDEF_ENC(NAME_TBD
, 1), /* [2] */
2009 .str_sec
= "\0__!int",
2010 .str_sec_size
= sizeof("\0__!int"),
2011 .map_type
= BPF_MAP_TYPE_ARRAY
,
2012 .map_name
= "typedef_check_btf",
2013 .key_size
= sizeof(int),
2014 .value_size
= sizeof(int),
2018 .btf_load_err
= true,
2019 .err_str
= "Invalid name",
2023 .descr
= "ptr type (invalid name, name_off <> 0)",
2025 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2026 BTF_TYPE_ENC(NAME_TBD
,
2027 BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 1), /* [2] */
2030 .str_sec
= "\0__int",
2031 .str_sec_size
= sizeof("\0__int"),
2032 .map_type
= BPF_MAP_TYPE_ARRAY
,
2033 .map_name
= "ptr_type_check_btf",
2034 .key_size
= sizeof(int),
2035 .value_size
= sizeof(int),
2039 .btf_load_err
= true,
2040 .err_str
= "Invalid name",
2044 .descr
= "volatile type (invalid name, name_off <> 0)",
2046 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2047 BTF_TYPE_ENC(NAME_TBD
,
2048 BTF_INFO_ENC(BTF_KIND_VOLATILE
, 0, 0), 1), /* [2] */
2051 .str_sec
= "\0__int",
2052 .str_sec_size
= sizeof("\0__int"),
2053 .map_type
= BPF_MAP_TYPE_ARRAY
,
2054 .map_name
= "volatile_type_check_btf",
2055 .key_size
= sizeof(int),
2056 .value_size
= sizeof(int),
2060 .btf_load_err
= true,
2061 .err_str
= "Invalid name",
2065 .descr
= "const type (invalid name, name_off <> 0)",
2067 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2068 BTF_TYPE_ENC(NAME_TBD
,
2069 BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 1), /* [2] */
2072 .str_sec
= "\0__int",
2073 .str_sec_size
= sizeof("\0__int"),
2074 .map_type
= BPF_MAP_TYPE_ARRAY
,
2075 .map_name
= "const_type_check_btf",
2076 .key_size
= sizeof(int),
2077 .value_size
= sizeof(int),
2081 .btf_load_err
= true,
2082 .err_str
= "Invalid name",
2086 .descr
= "restrict type (invalid name, name_off <> 0)",
2088 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2089 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 1), /* [2] */
2090 BTF_TYPE_ENC(NAME_TBD
,
2091 BTF_INFO_ENC(BTF_KIND_RESTRICT
, 0, 0), 2), /* [3] */
2094 .str_sec
= "\0__int",
2095 .str_sec_size
= sizeof("\0__int"),
2096 .map_type
= BPF_MAP_TYPE_ARRAY
,
2097 .map_name
= "restrict_type_check_btf",
2098 .key_size
= sizeof(int),
2099 .value_size
= sizeof(int),
2103 .btf_load_err
= true,
2104 .err_str
= "Invalid name",
2108 .descr
= "fwd type (invalid name, name_off = 0)",
2110 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2111 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FWD
, 0, 0), 0), /* [2] */
2114 .str_sec
= "\0__skb",
2115 .str_sec_size
= sizeof("\0__skb"),
2116 .map_type
= BPF_MAP_TYPE_ARRAY
,
2117 .map_name
= "fwd_type_check_btf",
2118 .key_size
= sizeof(int),
2119 .value_size
= sizeof(int),
2123 .btf_load_err
= true,
2124 .err_str
= "Invalid name",
2128 .descr
= "fwd type (invalid name, invalid identifier)",
2130 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2131 BTF_TYPE_ENC(NAME_TBD
,
2132 BTF_INFO_ENC(BTF_KIND_FWD
, 0, 0), 0), /* [2] */
2135 .str_sec
= "\0__!skb",
2136 .str_sec_size
= sizeof("\0__!skb"),
2137 .map_type
= BPF_MAP_TYPE_ARRAY
,
2138 .map_name
= "fwd_type_check_btf",
2139 .key_size
= sizeof(int),
2140 .value_size
= sizeof(int),
2144 .btf_load_err
= true,
2145 .err_str
= "Invalid name",
2149 .descr
= "array type (invalid name, name_off <> 0)",
2151 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2152 BTF_TYPE_ENC(NAME_TBD
,
2153 BTF_INFO_ENC(BTF_KIND_ARRAY
, 0, 0), 0), /* [2] */
2154 BTF_ARRAY_ENC(1, 1, 4),
2157 .str_sec
= "\0__skb",
2158 .str_sec_size
= sizeof("\0__skb"),
2159 .map_type
= BPF_MAP_TYPE_ARRAY
,
2160 .map_name
= "array_type_check_btf",
2161 .key_size
= sizeof(int),
2162 .value_size
= sizeof(int),
2166 .btf_load_err
= true,
2167 .err_str
= "Invalid name",
2171 .descr
= "struct type (name_off = 0)",
2173 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2175 BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), 4), /* [2] */
2176 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
2180 .str_sec_size
= sizeof("\0A"),
2181 .map_type
= BPF_MAP_TYPE_ARRAY
,
2182 .map_name
= "struct_type_check_btf",
2183 .key_size
= sizeof(int),
2184 .value_size
= sizeof(int),
2191 .descr
= "struct type (invalid name, invalid identifier)",
2193 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2194 BTF_TYPE_ENC(NAME_TBD
,
2195 BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), 4), /* [2] */
2196 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
2199 .str_sec
= "\0A!\0B",
2200 .str_sec_size
= sizeof("\0A!\0B"),
2201 .map_type
= BPF_MAP_TYPE_ARRAY
,
2202 .map_name
= "struct_type_check_btf",
2203 .key_size
= sizeof(int),
2204 .value_size
= sizeof(int),
2208 .btf_load_err
= true,
2209 .err_str
= "Invalid name",
2213 .descr
= "struct member (name_off = 0)",
2215 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2217 BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), 4), /* [2] */
2218 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
2222 .str_sec_size
= sizeof("\0A"),
2223 .map_type
= BPF_MAP_TYPE_ARRAY
,
2224 .map_name
= "struct_type_check_btf",
2225 .key_size
= sizeof(int),
2226 .value_size
= sizeof(int),
2233 .descr
= "struct member (invalid name, invalid identifier)",
2235 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2236 BTF_TYPE_ENC(NAME_TBD
,
2237 BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), 4), /* [2] */
2238 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
2241 .str_sec
= "\0A\0B*",
2242 .str_sec_size
= sizeof("\0A\0B*"),
2243 .map_type
= BPF_MAP_TYPE_ARRAY
,
2244 .map_name
= "struct_type_check_btf",
2245 .key_size
= sizeof(int),
2246 .value_size
= sizeof(int),
2250 .btf_load_err
= true,
2251 .err_str
= "Invalid name",
2255 .descr
= "enum type (name_off = 0)",
2257 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2259 BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1),
2260 sizeof(int)), /* [2] */
2261 BTF_ENUM_ENC(NAME_TBD
, 0),
2264 .str_sec
= "\0A\0B",
2265 .str_sec_size
= sizeof("\0A\0B"),
2266 .map_type
= BPF_MAP_TYPE_ARRAY
,
2267 .map_name
= "enum_type_check_btf",
2268 .key_size
= sizeof(int),
2269 .value_size
= sizeof(int),
2276 .descr
= "enum type (invalid name, invalid identifier)",
2278 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2279 BTF_TYPE_ENC(NAME_TBD
,
2280 BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1),
2281 sizeof(int)), /* [2] */
2282 BTF_ENUM_ENC(NAME_TBD
, 0),
2285 .str_sec
= "\0A!\0B",
2286 .str_sec_size
= sizeof("\0A!\0B"),
2287 .map_type
= BPF_MAP_TYPE_ARRAY
,
2288 .map_name
= "enum_type_check_btf",
2289 .key_size
= sizeof(int),
2290 .value_size
= sizeof(int),
2294 .btf_load_err
= true,
2295 .err_str
= "Invalid name",
2299 .descr
= "enum member (invalid name, name_off = 0)",
2301 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2303 BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1),
2304 sizeof(int)), /* [2] */
2309 .str_sec_size
= sizeof(""),
2310 .map_type
= BPF_MAP_TYPE_ARRAY
,
2311 .map_name
= "enum_type_check_btf",
2312 .key_size
= sizeof(int),
2313 .value_size
= sizeof(int),
2317 .btf_load_err
= true,
2318 .err_str
= "Invalid name",
2322 .descr
= "enum member (invalid name, invalid identifier)",
2324 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2326 BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1),
2327 sizeof(int)), /* [2] */
2328 BTF_ENUM_ENC(NAME_TBD
, 0),
2332 .str_sec_size
= sizeof("\0A!"),
2333 .map_type
= BPF_MAP_TYPE_ARRAY
,
2334 .map_name
= "enum_type_check_btf",
2335 .key_size
= sizeof(int),
2336 .value_size
= sizeof(int),
2340 .btf_load_err
= true,
2341 .err_str
= "Invalid name",
2344 .descr
= "arraymap invalid btf key (a bit field)",
2347 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
2348 /* 32 bit int with 32 bit offset */ /* [2] */
2349 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 32, 32, 8),
2353 .str_sec_size
= sizeof(""),
2354 .map_type
= BPF_MAP_TYPE_ARRAY
,
2355 .map_name
= "array_map_check_btf",
2356 .key_size
= sizeof(int),
2357 .value_size
= sizeof(int),
2361 .map_create_err
= true,
2365 .descr
= "arraymap invalid btf key (!= 32 bits)",
2368 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
2369 /* 16 bit int with 0 bit offset */ /* [2] */
2370 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 16, 2),
2374 .str_sec_size
= sizeof(""),
2375 .map_type
= BPF_MAP_TYPE_ARRAY
,
2376 .map_name
= "array_map_check_btf",
2377 .key_size
= sizeof(int),
2378 .value_size
= sizeof(int),
2382 .map_create_err
= true,
2386 .descr
= "arraymap invalid btf value (too small)",
2389 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
2393 .str_sec_size
= sizeof(""),
2394 .map_type
= BPF_MAP_TYPE_ARRAY
,
2395 .map_name
= "array_map_check_btf",
2396 .key_size
= sizeof(int),
2397 /* btf_value_size < map->value_size */
2398 .value_size
= sizeof(__u64
),
2402 .map_create_err
= true,
2406 .descr
= "arraymap invalid btf value (too big)",
2409 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
2413 .str_sec_size
= sizeof(""),
2414 .map_type
= BPF_MAP_TYPE_ARRAY
,
2415 .map_name
= "array_map_check_btf",
2416 .key_size
= sizeof(int),
2417 /* btf_value_size > map->value_size */
2418 .value_size
= sizeof(__u16
),
2422 .map_create_err
= true,
2426 .descr
= "func proto (int (*)(int, unsigned int))",
2428 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2429 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2430 /* int (*)(int, unsigned int) */
2431 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
2432 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2433 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2437 .str_sec_size
= sizeof(""),
2438 .map_type
= BPF_MAP_TYPE_ARRAY
,
2439 .map_name
= "func_proto_type_check_btf",
2440 .key_size
= sizeof(int),
2441 .value_size
= sizeof(int),
2448 .descr
= "func proto (vararg)",
2450 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2451 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2452 /* void (*)(int, unsigned int, ...) */
2453 BTF_FUNC_PROTO_ENC(0, 3), /* [3] */
2454 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2455 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2456 BTF_FUNC_PROTO_ARG_ENC(0, 0),
2460 .str_sec_size
= sizeof(""),
2461 .map_type
= BPF_MAP_TYPE_ARRAY
,
2462 .map_name
= "func_proto_type_check_btf",
2463 .key_size
= sizeof(int),
2464 .value_size
= sizeof(int),
2471 .descr
= "func proto (vararg with name)",
2473 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2474 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2475 /* void (*)(int a, unsigned int b, ... c) */
2476 BTF_FUNC_PROTO_ENC(0, 3), /* [3] */
2477 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2478 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2479 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 0),
2482 .str_sec
= "\0a\0b\0c",
2483 .str_sec_size
= sizeof("\0a\0b\0c"),
2484 .map_type
= BPF_MAP_TYPE_ARRAY
,
2485 .map_name
= "func_proto_type_check_btf",
2486 .key_size
= sizeof(int),
2487 .value_size
= sizeof(int),
2491 .btf_load_err
= true,
2492 .err_str
= "Invalid arg#3",
2496 .descr
= "func proto (arg after vararg)",
2498 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2499 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2500 /* void (*)(int a, ..., unsigned int b) */
2501 BTF_FUNC_PROTO_ENC(0, 3), /* [3] */
2502 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2503 BTF_FUNC_PROTO_ARG_ENC(0, 0),
2504 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2507 .str_sec
= "\0a\0b",
2508 .str_sec_size
= sizeof("\0a\0b"),
2509 .map_type
= BPF_MAP_TYPE_ARRAY
,
2510 .map_name
= "func_proto_type_check_btf",
2511 .key_size
= sizeof(int),
2512 .value_size
= sizeof(int),
2516 .btf_load_err
= true,
2517 .err_str
= "Invalid arg#2",
2521 .descr
= "func proto (CONST=>TYPEDEF=>PTR=>FUNC_PROTO)",
2523 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2524 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2525 /* typedef void (*func_ptr)(int, unsigned int) */
2526 BTF_TYPEDEF_ENC(NAME_TBD
, 5), /* [3] */
2527 /* const func_ptr */
2528 BTF_CONST_ENC(3), /* [4] */
2529 BTF_PTR_ENC(6), /* [5] */
2530 BTF_FUNC_PROTO_ENC(0, 2), /* [6] */
2531 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2532 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2535 .str_sec
= "\0func_ptr",
2536 .str_sec_size
= sizeof("\0func_ptr"),
2537 .map_type
= BPF_MAP_TYPE_ARRAY
,
2538 .map_name
= "func_proto_type_check_btf",
2539 .key_size
= sizeof(int),
2540 .value_size
= sizeof(int),
2547 .descr
= "func proto (TYPEDEF=>FUNC_PROTO)",
2549 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2550 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2551 BTF_TYPEDEF_ENC(NAME_TBD
, 4), /* [3] */
2552 BTF_FUNC_PROTO_ENC(0, 2), /* [4] */
2553 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2554 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2557 .str_sec
= "\0func_typedef",
2558 .str_sec_size
= sizeof("\0func_typedef"),
2559 .map_type
= BPF_MAP_TYPE_ARRAY
,
2560 .map_name
= "func_proto_type_check_btf",
2561 .key_size
= sizeof(int),
2562 .value_size
= sizeof(int),
2569 .descr
= "func proto (btf_resolve(arg))",
2571 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2572 /* void (*)(const void *) */
2573 BTF_FUNC_PROTO_ENC(0, 1), /* [2] */
2574 BTF_FUNC_PROTO_ARG_ENC(0, 3),
2575 BTF_CONST_ENC(4), /* [3] */
2576 BTF_PTR_ENC(0), /* [4] */
2580 .str_sec_size
= sizeof(""),
2581 .map_type
= BPF_MAP_TYPE_ARRAY
,
2582 .map_name
= "func_proto_type_check_btf",
2583 .key_size
= sizeof(int),
2584 .value_size
= sizeof(int),
2591 .descr
= "func proto (Not all arg has name)",
2593 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2594 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2595 /* void (*)(int, unsigned int b) */
2596 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2597 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2598 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2602 .str_sec_size
= sizeof("\0b"),
2603 .map_type
= BPF_MAP_TYPE_ARRAY
,
2604 .map_name
= "func_proto_type_check_btf",
2605 .key_size
= sizeof(int),
2606 .value_size
= sizeof(int),
2613 .descr
= "func proto (Bad arg name_off)",
2615 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2616 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2617 /* void (*)(int a, unsigned int <bad_name_off>) */
2618 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2619 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2620 BTF_FUNC_PROTO_ARG_ENC(0x0fffffff, 2),
2624 .str_sec_size
= sizeof("\0a"),
2625 .map_type
= BPF_MAP_TYPE_ARRAY
,
2626 .map_name
= "func_proto_type_check_btf",
2627 .key_size
= sizeof(int),
2628 .value_size
= sizeof(int),
2632 .btf_load_err
= true,
2633 .err_str
= "Invalid arg#2",
2637 .descr
= "func proto (Bad arg name)",
2639 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2640 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2641 /* void (*)(int a, unsigned int !!!) */
2642 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2643 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2644 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2647 .str_sec
= "\0a\0!!!",
2648 .str_sec_size
= sizeof("\0a\0!!!"),
2649 .map_type
= BPF_MAP_TYPE_ARRAY
,
2650 .map_name
= "func_proto_type_check_btf",
2651 .key_size
= sizeof(int),
2652 .value_size
= sizeof(int),
2656 .btf_load_err
= true,
2657 .err_str
= "Invalid arg#2",
2661 .descr
= "func proto (Invalid return type)",
2663 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2664 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2665 /* <bad_ret_type> (*)(int, unsigned int) */
2666 BTF_FUNC_PROTO_ENC(100, 2), /* [3] */
2667 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2668 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2672 .str_sec_size
= sizeof(""),
2673 .map_type
= BPF_MAP_TYPE_ARRAY
,
2674 .map_name
= "func_proto_type_check_btf",
2675 .key_size
= sizeof(int),
2676 .value_size
= sizeof(int),
2680 .btf_load_err
= true,
2681 .err_str
= "Invalid return type",
2685 .descr
= "func proto (with func name)",
2687 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2688 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2689 /* void func_proto(int, unsigned int) */
2690 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO
, 0, 2), 0), /* [3] */
2691 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2692 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2695 .str_sec
= "\0func_proto",
2696 .str_sec_size
= sizeof("\0func_proto"),
2697 .map_type
= BPF_MAP_TYPE_ARRAY
,
2698 .map_name
= "func_proto_type_check_btf",
2699 .key_size
= sizeof(int),
2700 .value_size
= sizeof(int),
2704 .btf_load_err
= true,
2705 .err_str
= "Invalid name",
2709 .descr
= "func proto (const void arg)",
2711 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2712 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2713 /* void (*)(const void) */
2714 BTF_FUNC_PROTO_ENC(0, 1), /* [3] */
2715 BTF_FUNC_PROTO_ARG_ENC(0, 4),
2716 BTF_CONST_ENC(0), /* [4] */
2720 .str_sec_size
= sizeof(""),
2721 .map_type
= BPF_MAP_TYPE_ARRAY
,
2722 .map_name
= "func_proto_type_check_btf",
2723 .key_size
= sizeof(int),
2724 .value_size
= sizeof(int),
2728 .btf_load_err
= true,
2729 .err_str
= "Invalid arg#1",
2733 .descr
= "func (void func(int a, unsigned int b))",
2735 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2736 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2737 /* void (*)(int a, unsigned int b) */
2738 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2739 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2740 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2741 /* void func(int a, unsigned int b) */
2742 BTF_FUNC_ENC(NAME_TBD
, 3), /* [4] */
2745 .str_sec
= "\0a\0b\0func",
2746 .str_sec_size
= sizeof("\0a\0b\0func"),
2747 .map_type
= BPF_MAP_TYPE_ARRAY
,
2748 .map_name
= "func_type_check_btf",
2749 .key_size
= sizeof(int),
2750 .value_size
= sizeof(int),
2757 .descr
= "func (No func name)",
2759 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2760 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2761 /* void (*)(int a, unsigned int b) */
2762 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2763 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2764 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2765 /* void <no_name>(int a, unsigned int b) */
2766 BTF_FUNC_ENC(0, 3), /* [4] */
2769 .str_sec
= "\0a\0b",
2770 .str_sec_size
= sizeof("\0a\0b"),
2771 .map_type
= BPF_MAP_TYPE_ARRAY
,
2772 .map_name
= "func_type_check_btf",
2773 .key_size
= sizeof(int),
2774 .value_size
= sizeof(int),
2778 .btf_load_err
= true,
2779 .err_str
= "Invalid name",
2783 .descr
= "func (Invalid func name)",
2785 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2786 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2787 /* void (*)(int a, unsigned int b) */
2788 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2789 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2790 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2791 /* void !!!(int a, unsigned int b) */
2792 BTF_FUNC_ENC(NAME_TBD
, 3), /* [4] */
2795 .str_sec
= "\0a\0b\0!!!",
2796 .str_sec_size
= sizeof("\0a\0b\0!!!"),
2797 .map_type
= BPF_MAP_TYPE_ARRAY
,
2798 .map_name
= "func_type_check_btf",
2799 .key_size
= sizeof(int),
2800 .value_size
= sizeof(int),
2804 .btf_load_err
= true,
2805 .err_str
= "Invalid name",
2809 .descr
= "func (Some arg has no name)",
2811 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2812 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2813 /* void (*)(int a, unsigned int) */
2814 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2815 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2816 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2817 /* void func(int a, unsigned int) */
2818 BTF_FUNC_ENC(NAME_TBD
, 3), /* [4] */
2821 .str_sec
= "\0a\0func",
2822 .str_sec_size
= sizeof("\0a\0func"),
2823 .map_type
= BPF_MAP_TYPE_ARRAY
,
2824 .map_name
= "func_type_check_btf",
2825 .key_size
= sizeof(int),
2826 .value_size
= sizeof(int),
2830 .btf_load_err
= true,
2831 .err_str
= "Invalid arg#2",
2835 .descr
= "func (Non zero vlen)",
2837 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2838 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2839 /* void (*)(int a, unsigned int b) */
2840 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2841 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2842 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2843 /* void func(int a, unsigned int b) */
2844 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_FUNC
, 0, 2), 3), /* [4] */
2847 .str_sec
= "\0a\0b\0func",
2848 .str_sec_size
= sizeof("\0a\0b\0func"),
2849 .map_type
= BPF_MAP_TYPE_ARRAY
,
2850 .map_name
= "func_type_check_btf",
2851 .key_size
= sizeof(int),
2852 .value_size
= sizeof(int),
2856 .btf_load_err
= true,
2857 .err_str
= "Invalid func linkage",
2861 .descr
= "func (Not referring to FUNC_PROTO)",
2863 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2864 BTF_FUNC_ENC(NAME_TBD
, 1), /* [2] */
2867 .str_sec
= "\0func",
2868 .str_sec_size
= sizeof("\0func"),
2869 .map_type
= BPF_MAP_TYPE_ARRAY
,
2870 .map_name
= "func_type_check_btf",
2871 .key_size
= sizeof(int),
2872 .value_size
= sizeof(int),
2876 .btf_load_err
= true,
2877 .err_str
= "Invalid type_id",
2881 .descr
= "invalid int kind_flag",
2883 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2884 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_INT
, 1, 0), 4), /* [2] */
2885 BTF_INT_ENC(0, 0, 32),
2889 .map_type
= BPF_MAP_TYPE_ARRAY
,
2890 .map_name
= "int_type_check_btf",
2891 .key_size
= sizeof(int),
2892 .value_size
= sizeof(int),
2896 .btf_load_err
= true,
2897 .err_str
= "Invalid btf_info kind_flag",
2901 .descr
= "invalid ptr kind_flag",
2903 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2904 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 1, 0), 1), /* [2] */
2908 .map_type
= BPF_MAP_TYPE_ARRAY
,
2909 .map_name
= "ptr_type_check_btf",
2910 .key_size
= sizeof(int),
2911 .value_size
= sizeof(int),
2915 .btf_load_err
= true,
2916 .err_str
= "Invalid btf_info kind_flag",
2920 .descr
= "invalid array kind_flag",
2922 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2923 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ARRAY
, 1, 0), 0), /* [2] */
2924 BTF_ARRAY_ENC(1, 1, 1),
2928 .map_type
= BPF_MAP_TYPE_ARRAY
,
2929 .map_name
= "array_type_check_btf",
2930 .key_size
= sizeof(int),
2931 .value_size
= sizeof(int),
2935 .btf_load_err
= true,
2936 .err_str
= "Invalid btf_info kind_flag",
2940 .descr
= "invalid enum kind_flag",
2942 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2943 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 1, 1), 4), /* [2] */
2944 BTF_ENUM_ENC(NAME_TBD
, 0),
2948 .map_type
= BPF_MAP_TYPE_ARRAY
,
2949 .map_name
= "enum_type_check_btf",
2950 .key_size
= sizeof(int),
2951 .value_size
= sizeof(int),
2955 .btf_load_err
= true,
2956 .err_str
= "Invalid btf_info kind_flag",
2960 .descr
= "valid fwd kind_flag",
2962 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2963 BTF_TYPE_ENC(NAME_TBD
,
2964 BTF_INFO_ENC(BTF_KIND_FWD
, 1, 0), 0), /* [2] */
2968 .map_type
= BPF_MAP_TYPE_ARRAY
,
2969 .map_name
= "fwd_type_check_btf",
2970 .key_size
= sizeof(int),
2971 .value_size
= sizeof(int),
2978 .descr
= "invalid typedef kind_flag",
2980 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2981 BTF_TYPE_ENC(NAME_TBD
,
2982 BTF_INFO_ENC(BTF_KIND_TYPEDEF
, 1, 0), 1), /* [2] */
2986 .map_type
= BPF_MAP_TYPE_ARRAY
,
2987 .map_name
= "typedef_type_check_btf",
2988 .key_size
= sizeof(int),
2989 .value_size
= sizeof(int),
2993 .btf_load_err
= true,
2994 .err_str
= "Invalid btf_info kind_flag",
2998 .descr
= "invalid volatile kind_flag",
3000 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3001 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE
, 1, 0), 1), /* [2] */
3005 .map_type
= BPF_MAP_TYPE_ARRAY
,
3006 .map_name
= "volatile_type_check_btf",
3007 .key_size
= sizeof(int),
3008 .value_size
= sizeof(int),
3012 .btf_load_err
= true,
3013 .err_str
= "Invalid btf_info kind_flag",
3017 .descr
= "invalid const kind_flag",
3019 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3020 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 1, 0), 1), /* [2] */
3024 .map_type
= BPF_MAP_TYPE_ARRAY
,
3025 .map_name
= "const_type_check_btf",
3026 .key_size
= sizeof(int),
3027 .value_size
= sizeof(int),
3031 .btf_load_err
= true,
3032 .err_str
= "Invalid btf_info kind_flag",
3036 .descr
= "invalid restrict kind_flag",
3038 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3039 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_RESTRICT
, 1, 0), 1), /* [2] */
3043 .map_type
= BPF_MAP_TYPE_ARRAY
,
3044 .map_name
= "restrict_type_check_btf",
3045 .key_size
= sizeof(int),
3046 .value_size
= sizeof(int),
3050 .btf_load_err
= true,
3051 .err_str
= "Invalid btf_info kind_flag",
3055 .descr
= "invalid func kind_flag",
3057 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3058 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO
, 0, 0), 0), /* [2] */
3059 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_FUNC
, 1, 0), 2), /* [3] */
3063 .map_type
= BPF_MAP_TYPE_ARRAY
,
3064 .map_name
= "func_type_check_btf",
3065 .key_size
= sizeof(int),
3066 .value_size
= sizeof(int),
3070 .btf_load_err
= true,
3071 .err_str
= "Invalid btf_info kind_flag",
3075 .descr
= "invalid func_proto kind_flag",
3077 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3078 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO
, 1, 0), 0), /* [2] */
3082 .map_type
= BPF_MAP_TYPE_ARRAY
,
3083 .map_name
= "func_proto_type_check_btf",
3084 .key_size
= sizeof(int),
3085 .value_size
= sizeof(int),
3089 .btf_load_err
= true,
3090 .err_str
= "Invalid btf_info kind_flag",
3094 .descr
= "valid struct, kind_flag, bitfield_size = 0",
3096 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3097 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 8), /* [2] */
3098 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(0, 0)),
3099 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(0, 32)),
3102 BTF_STR_SEC("\0A\0B"),
3103 .map_type
= BPF_MAP_TYPE_ARRAY
,
3104 .map_name
= "struct_type_check_btf",
3105 .key_size
= sizeof(int),
3106 .value_size
= sizeof(int),
3113 .descr
= "valid struct, kind_flag, int member, bitfield_size != 0",
3115 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3116 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 4), /* [2] */
3117 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(4, 0)),
3118 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(4, 4)),
3121 BTF_STR_SEC("\0A\0B"),
3122 .map_type
= BPF_MAP_TYPE_ARRAY
,
3123 .map_name
= "struct_type_check_btf",
3124 .key_size
= sizeof(int),
3125 .value_size
= sizeof(int),
3132 .descr
= "valid union, kind_flag, int member, bitfield_size != 0",
3134 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3135 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION
, 1, 2), 4), /* [2] */
3136 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(4, 0)),
3137 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(4, 0)),
3140 BTF_STR_SEC("\0A\0B"),
3141 .map_type
= BPF_MAP_TYPE_ARRAY
,
3142 .map_name
= "union_type_check_btf",
3143 .key_size
= sizeof(int),
3144 .value_size
= sizeof(int),
3151 .descr
= "valid struct, kind_flag, enum member, bitfield_size != 0",
3153 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3154 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4), /* [2] */
3155 BTF_ENUM_ENC(NAME_TBD
, 0),
3156 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 4),/* [3] */
3157 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(4, 0)),
3158 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(4, 4)),
3161 BTF_STR_SEC("\0A\0B\0C"),
3162 .map_type
= BPF_MAP_TYPE_ARRAY
,
3163 .map_name
= "struct_type_check_btf",
3164 .key_size
= sizeof(int),
3165 .value_size
= sizeof(int),
3172 .descr
= "valid union, kind_flag, enum member, bitfield_size != 0",
3174 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3175 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4), /* [2] */
3176 BTF_ENUM_ENC(NAME_TBD
, 0),
3177 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION
, 1, 2), 4), /* [3] */
3178 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(4, 0)),
3179 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(4, 0)),
3182 BTF_STR_SEC("\0A\0B\0C"),
3183 .map_type
= BPF_MAP_TYPE_ARRAY
,
3184 .map_name
= "union_type_check_btf",
3185 .key_size
= sizeof(int),
3186 .value_size
= sizeof(int),
3193 .descr
= "valid struct, kind_flag, typedef member, bitfield_size != 0",
3195 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3196 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4), /* [2] */
3197 BTF_ENUM_ENC(NAME_TBD
, 0),
3198 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 4),/* [3] */
3199 BTF_MEMBER_ENC(NAME_TBD
, 4, BTF_MEMBER_OFFSET(4, 0)),
3200 BTF_MEMBER_ENC(NAME_TBD
, 5, BTF_MEMBER_OFFSET(4, 4)),
3201 BTF_TYPEDEF_ENC(NAME_TBD
, 1), /* [4] */
3202 BTF_TYPEDEF_ENC(NAME_TBD
, 2), /* [5] */
3205 BTF_STR_SEC("\0A\0B\0C\0D\0E"),
3206 .map_type
= BPF_MAP_TYPE_ARRAY
,
3207 .map_name
= "struct_type_check_btf",
3208 .key_size
= sizeof(int),
3209 .value_size
= sizeof(int),
3216 .descr
= "valid union, kind_flag, typedef member, bitfield_size != 0",
3218 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3219 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4), /* [2] */
3220 BTF_ENUM_ENC(NAME_TBD
, 0),
3221 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION
, 1, 2), 4), /* [3] */
3222 BTF_MEMBER_ENC(NAME_TBD
, 4, BTF_MEMBER_OFFSET(4, 0)),
3223 BTF_MEMBER_ENC(NAME_TBD
, 5, BTF_MEMBER_OFFSET(4, 0)),
3224 BTF_TYPEDEF_ENC(NAME_TBD
, 1), /* [4] */
3225 BTF_TYPEDEF_ENC(NAME_TBD
, 2), /* [5] */
3228 BTF_STR_SEC("\0A\0B\0C\0D\0E"),
3229 .map_type
= BPF_MAP_TYPE_ARRAY
,
3230 .map_name
= "union_type_check_btf",
3231 .key_size
= sizeof(int),
3232 .value_size
= sizeof(int),
3239 .descr
= "invalid struct, kind_flag, bitfield_size greater than struct size",
3241 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3242 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 4), /* [2] */
3243 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(20, 0)),
3244 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(20, 20)),
3247 BTF_STR_SEC("\0A\0B"),
3248 .map_type
= BPF_MAP_TYPE_ARRAY
,
3249 .map_name
= "struct_type_check_btf",
3250 .key_size
= sizeof(int),
3251 .value_size
= sizeof(int),
3255 .btf_load_err
= true,
3256 .err_str
= "Member exceeds struct_size",
3260 .descr
= "invalid struct, kind_flag, bitfield base_type int not regular",
3262 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3263 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 20, 4), /* [2] */
3264 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 4), /* [3] */
3265 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(20, 0)),
3266 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(20, 20)),
3269 BTF_STR_SEC("\0A\0B"),
3270 .map_type
= BPF_MAP_TYPE_ARRAY
,
3271 .map_name
= "struct_type_check_btf",
3272 .key_size
= sizeof(int),
3273 .value_size
= sizeof(int),
3277 .btf_load_err
= true,
3278 .err_str
= "Invalid member base type",
3282 .descr
= "invalid struct, kind_flag, base_type int not regular",
3284 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3285 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 12, 4), /* [2] */
3286 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 4), /* [3] */
3287 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(8, 0)),
3288 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(8, 8)),
3291 BTF_STR_SEC("\0A\0B"),
3292 .map_type
= BPF_MAP_TYPE_ARRAY
,
3293 .map_name
= "struct_type_check_btf",
3294 .key_size
= sizeof(int),
3295 .value_size
= sizeof(int),
3299 .btf_load_err
= true,
3300 .err_str
= "Invalid member base type",
3304 .descr
= "invalid union, kind_flag, bitfield_size greater than struct size",
3306 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3307 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION
, 1, 2), 2), /* [2] */
3308 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(8, 0)),
3309 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(20, 0)),
3312 BTF_STR_SEC("\0A\0B"),
3313 .map_type
= BPF_MAP_TYPE_ARRAY
,
3314 .map_name
= "union_type_check_btf",
3315 .key_size
= sizeof(int),
3316 .value_size
= sizeof(int),
3320 .btf_load_err
= true,
3321 .err_str
= "Member exceeds struct_size",
3325 .descr
= "invalid struct, kind_flag, int member, bitfield_size = 0, wrong byte alignment",
3327 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3328 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [2] */
3329 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 12), /* [3] */
3330 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(0, 0)),
3331 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(0, 36)),
3334 BTF_STR_SEC("\0A\0B"),
3335 .map_type
= BPF_MAP_TYPE_ARRAY
,
3336 .map_name
= "struct_type_check_btf",
3337 .key_size
= sizeof(int),
3338 .value_size
= sizeof(int),
3342 .btf_load_err
= true,
3343 .err_str
= "Invalid member offset",
3347 .descr
= "invalid struct, kind_flag, enum member, bitfield_size = 0, wrong byte alignment",
3349 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3350 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [2] */
3351 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4), /* [2] */
3352 BTF_ENUM_ENC(NAME_TBD
, 0),
3353 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 12), /* [3] */
3354 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(0, 0)),
3355 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(0, 36)),
3358 BTF_STR_SEC("\0A\0B\0C"),
3359 .map_type
= BPF_MAP_TYPE_ARRAY
,
3360 .map_name
= "struct_type_check_btf",
3361 .key_size
= sizeof(int),
3362 .value_size
= sizeof(int),
3366 .btf_load_err
= true,
3367 .err_str
= "Invalid member offset",
3371 .descr
= "128-bit int",
3373 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3374 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 128, 16), /* [2] */
3378 .map_type
= BPF_MAP_TYPE_ARRAY
,
3379 .map_name
= "int_type_check_btf",
3380 .key_size
= sizeof(int),
3381 .value_size
= sizeof(int),
3388 .descr
= "struct, 128-bit int member",
3390 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3391 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 128, 16), /* [2] */
3392 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), 16), /* [3] */
3393 BTF_MEMBER_ENC(NAME_TBD
, 2, 0),
3397 .map_type
= BPF_MAP_TYPE_ARRAY
,
3398 .map_name
= "struct_type_check_btf",
3399 .key_size
= sizeof(int),
3400 .value_size
= sizeof(int),
3407 .descr
= "struct, 120-bit int member bitfield",
3409 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3410 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 120, 16), /* [2] */
3411 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), 16), /* [3] */
3412 BTF_MEMBER_ENC(NAME_TBD
, 2, 0),
3416 .map_type
= BPF_MAP_TYPE_ARRAY
,
3417 .map_name
= "struct_type_check_btf",
3418 .key_size
= sizeof(int),
3419 .value_size
= sizeof(int),
3426 .descr
= "struct, kind_flag, 128-bit int member",
3428 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3429 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 128, 16), /* [2] */
3430 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 1), 16), /* [3] */
3431 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(0, 0)),
3435 .map_type
= BPF_MAP_TYPE_ARRAY
,
3436 .map_name
= "struct_type_check_btf",
3437 .key_size
= sizeof(int),
3438 .value_size
= sizeof(int),
3445 .descr
= "struct, kind_flag, 120-bit int member bitfield",
3447 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3448 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 128, 16), /* [2] */
3449 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 1), 16), /* [3] */
3450 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(120, 0)),
3454 .map_type
= BPF_MAP_TYPE_ARRAY
,
3455 .map_name
= "struct_type_check_btf",
3456 .key_size
= sizeof(int),
3457 .value_size
= sizeof(int),
3463 * typedef int arr_t[16];
3469 .descr
= "struct->ptr->typedef->array->int size resolution",
3471 BTF_STRUCT_ENC(NAME_TBD
, 1, 8), /* [1] */
3472 BTF_MEMBER_ENC(NAME_TBD
, 2, 0),
3473 BTF_PTR_ENC(3), /* [2] */
3474 BTF_TYPEDEF_ENC(NAME_TBD
, 4), /* [3] */
3475 BTF_TYPE_ARRAY_ENC(5, 5, 16), /* [4] */
3476 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [5] */
3479 BTF_STR_SEC("\0s\0a\0arr_t"),
3480 .map_type
= BPF_MAP_TYPE_ARRAY
,
3481 .map_name
= "ptr_mod_chain_size_resolve_map",
3482 .key_size
= sizeof(int),
3483 .value_size
= sizeof(int) * 16,
3484 .key_type_id
= 5 /* int */,
3485 .value_type_id
= 3 /* arr_t */,
3489 * typedef int arr_t[16][8][4];
3495 .descr
= "struct->ptr->typedef->multi-array->int size resolution",
3497 BTF_STRUCT_ENC(NAME_TBD
, 1, 8), /* [1] */
3498 BTF_MEMBER_ENC(NAME_TBD
, 2, 0),
3499 BTF_PTR_ENC(3), /* [2] */
3500 BTF_TYPEDEF_ENC(NAME_TBD
, 4), /* [3] */
3501 BTF_TYPE_ARRAY_ENC(5, 7, 16), /* [4] */
3502 BTF_TYPE_ARRAY_ENC(6, 7, 8), /* [5] */
3503 BTF_TYPE_ARRAY_ENC(7, 7, 4), /* [6] */
3504 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [7] */
3507 BTF_STR_SEC("\0s\0a\0arr_t"),
3508 .map_type
= BPF_MAP_TYPE_ARRAY
,
3509 .map_name
= "multi_arr_size_resolve_map",
3510 .key_size
= sizeof(int),
3511 .value_size
= sizeof(int) * 16 * 8 * 4,
3512 .key_type_id
= 7 /* int */,
3513 .value_type_id
= 3 /* arr_t */,
3517 * typedef int int_t;
3518 * typedef int_t arr3_t[4];
3519 * typedef arr3_t arr2_t[8];
3520 * typedef arr2_t arr1_t[16];
3526 .descr
= "typedef/multi-arr mix size resolution",
3528 BTF_STRUCT_ENC(NAME_TBD
, 1, 8), /* [1] */
3529 BTF_MEMBER_ENC(NAME_TBD
, 2, 0),
3530 BTF_PTR_ENC(3), /* [2] */
3531 BTF_TYPEDEF_ENC(NAME_TBD
, 4), /* [3] */
3532 BTF_TYPE_ARRAY_ENC(5, 10, 16), /* [4] */
3533 BTF_TYPEDEF_ENC(NAME_TBD
, 6), /* [5] */
3534 BTF_TYPE_ARRAY_ENC(7, 10, 8), /* [6] */
3535 BTF_TYPEDEF_ENC(NAME_TBD
, 8), /* [7] */
3536 BTF_TYPE_ARRAY_ENC(9, 10, 4), /* [8] */
3537 BTF_TYPEDEF_ENC(NAME_TBD
, 10), /* [9] */
3538 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [10] */
3541 BTF_STR_SEC("\0s\0a\0arr1_t\0arr2_t\0arr3_t\0int_t"),
3542 .map_type
= BPF_MAP_TYPE_ARRAY
,
3543 .map_name
= "typedef_arra_mix_size_resolve_map",
3544 .key_size
= sizeof(int),
3545 .value_size
= sizeof(int) * 16 * 8 * 4,
3546 .key_type_id
= 10 /* int */,
3547 .value_type_id
= 3 /* arr_t */,
3551 }; /* struct btf_raw_test raw_tests[] */
3553 static const char *get_next_str(const char *start
, const char *end
)
3555 return start
< end
- 1 ? start
+ 1 : NULL
;
3558 static int get_raw_sec_size(const __u32
*raw_types
)
3562 for (i
= MAX_NR_RAW_U32
- 1;
3563 i
>= 0 && raw_types
[i
] != BTF_END_RAW
;
3567 return i
< 0 ? i
: i
* sizeof(raw_types
[0]);
3570 static void *btf_raw_create(const struct btf_header
*hdr
,
3571 const __u32
*raw_types
,
3573 unsigned int str_sec_size
,
3574 unsigned int *btf_size
,
3575 const char **ret_next_str
)
3577 const char *next_str
= str
, *end_str
= str
+ str_sec_size
;
3578 const char **strs_idx
= NULL
, **tmp_strs_idx
;
3579 int strs_cap
= 0, strs_cnt
= 0, next_str_idx
= 0;
3580 unsigned int size_needed
, offset
;
3581 struct btf_header
*ret_hdr
;
3582 int i
, type_sec_size
, err
= 0;
3583 uint32_t *ret_types
;
3584 void *raw_btf
= NULL
;
3586 type_sec_size
= get_raw_sec_size(raw_types
);
3587 if (CHECK(type_sec_size
< 0, "Cannot get nr_raw_types"))
3590 size_needed
= sizeof(*hdr
) + type_sec_size
+ str_sec_size
;
3591 raw_btf
= malloc(size_needed
);
3592 if (CHECK(!raw_btf
, "Cannot allocate memory for raw_btf"))
3596 memcpy(raw_btf
, hdr
, sizeof(*hdr
));
3597 offset
= sizeof(*hdr
);
3600 while ((next_str
= get_next_str(next_str
, end_str
))) {
3601 if (strs_cnt
== strs_cap
) {
3602 strs_cap
+= max(16, strs_cap
/ 2);
3603 tmp_strs_idx
= realloc(strs_idx
,
3604 sizeof(*strs_idx
) * strs_cap
);
3605 if (CHECK(!tmp_strs_idx
,
3606 "Cannot allocate memory for strs_idx")) {
3610 strs_idx
= tmp_strs_idx
;
3612 strs_idx
[strs_cnt
++] = next_str
;
3613 next_str
+= strlen(next_str
);
3616 /* Copy type section */
3617 ret_types
= raw_btf
+ offset
;
3618 for (i
= 0; i
< type_sec_size
/ sizeof(raw_types
[0]); i
++) {
3619 if (raw_types
[i
] == NAME_TBD
) {
3620 if (CHECK(next_str_idx
== strs_cnt
,
3621 "Error in getting next_str #%d",
3626 ret_types
[i
] = strs_idx
[next_str_idx
++] - str
;
3627 } else if (IS_NAME_NTH(raw_types
[i
])) {
3628 int idx
= GET_NAME_NTH_IDX(raw_types
[i
]);
3630 if (CHECK(idx
<= 0 || idx
> strs_cnt
,
3631 "Error getting string #%d, strs_cnt:%d",
3636 ret_types
[i
] = strs_idx
[idx
-1] - str
;
3638 ret_types
[i
] = raw_types
[i
];
3641 offset
+= type_sec_size
;
3643 /* Copy string section */
3644 memcpy(raw_btf
+ offset
, str
, str_sec_size
);
3646 ret_hdr
= (struct btf_header
*)raw_btf
;
3647 ret_hdr
->type_len
= type_sec_size
;
3648 ret_hdr
->str_off
= type_sec_size
;
3649 ret_hdr
->str_len
= str_sec_size
;
3651 *btf_size
= size_needed
;
3654 next_str_idx
< strs_cnt
? strs_idx
[next_str_idx
] : NULL
;
3667 static int do_test_raw(unsigned int test_num
)
3669 struct btf_raw_test
*test
= &raw_tests
[test_num
- 1];
3670 struct bpf_create_map_attr create_attr
= {};
3671 int map_fd
= -1, btf_fd
= -1;
3672 unsigned int raw_btf_size
;
3673 struct btf_header
*hdr
;
3677 fprintf(stderr
, "BTF raw test[%u] (%s): ", test_num
, test
->descr
);
3678 raw_btf
= btf_raw_create(&hdr_tmpl
,
3682 &raw_btf_size
, NULL
);
3689 hdr
->hdr_len
= (int)hdr
->hdr_len
+ test
->hdr_len_delta
;
3690 hdr
->type_off
= (int)hdr
->type_off
+ test
->type_off_delta
;
3691 hdr
->str_off
= (int)hdr
->str_off
+ test
->str_off_delta
;
3692 hdr
->str_len
= (int)hdr
->str_len
+ test
->str_len_delta
;
3694 *btf_log_buf
= '\0';
3695 btf_fd
= bpf_load_btf(raw_btf
, raw_btf_size
,
3696 btf_log_buf
, BTF_LOG_BUF_SIZE
,
3700 err
= ((btf_fd
== -1) != test
->btf_load_err
);
3701 if (CHECK(err
, "btf_fd:%d test->btf_load_err:%u",
3702 btf_fd
, test
->btf_load_err
) ||
3703 CHECK(test
->err_str
&& !strstr(btf_log_buf
, test
->err_str
),
3704 "expected err_str:%s", test
->err_str
)) {
3709 if (err
|| btf_fd
== -1)
3712 create_attr
.name
= test
->map_name
;
3713 create_attr
.map_type
= test
->map_type
;
3714 create_attr
.key_size
= test
->key_size
;
3715 create_attr
.value_size
= test
->value_size
;
3716 create_attr
.max_entries
= test
->max_entries
;
3717 create_attr
.btf_fd
= btf_fd
;
3718 create_attr
.btf_key_type_id
= test
->key_type_id
;
3719 create_attr
.btf_value_type_id
= test
->value_type_id
;
3721 map_fd
= bpf_create_map_xattr(&create_attr
);
3723 err
= ((map_fd
== -1) != test
->map_create_err
);
3724 CHECK(err
, "map_fd:%d test->map_create_err:%u",
3725 map_fd
, test
->map_create_err
);
3729 fprintf(stderr
, "OK");
3731 if (*btf_log_buf
&& (err
|| args
.always_log
))
3732 fprintf(stderr
, "\n%s", btf_log_buf
);
3742 static int test_raw(void)
3747 if (args
.raw_test_num
)
3748 return count_result(do_test_raw(args
.raw_test_num
));
3750 for (i
= 1; i
<= ARRAY_SIZE(raw_tests
); i
++)
3751 err
|= count_result(do_test_raw(i
));
3756 struct btf_get_info_test
{
3758 const char *str_sec
;
3759 __u32 raw_types
[MAX_NR_RAW_U32
];
3762 int (*special_test
)(unsigned int test_num
);
3765 static int test_big_btf_info(unsigned int test_num
);
3766 static int test_btf_id(unsigned int test_num
);
3768 const struct btf_get_info_test get_info_tests
[] = {
3770 .descr
= "== raw_btf_size+1",
3773 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
3777 .str_sec_size
= sizeof(""),
3778 .btf_size_delta
= 1,
3781 .descr
= "== raw_btf_size-3",
3784 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
3788 .str_sec_size
= sizeof(""),
3789 .btf_size_delta
= -3,
3792 .descr
= "Large bpf_btf_info",
3795 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
3799 .str_sec_size
= sizeof(""),
3800 .special_test
= test_big_btf_info
,
3806 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
3807 /* unsigned int */ /* [2] */
3808 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),
3812 .str_sec_size
= sizeof(""),
3813 .special_test
= test_btf_id
,
3817 static inline __u64
ptr_to_u64(const void *ptr
)
3819 return (__u64
)(unsigned long)ptr
;
3822 static int test_big_btf_info(unsigned int test_num
)
3824 const struct btf_get_info_test
*test
= &get_info_tests
[test_num
- 1];
3825 uint8_t *raw_btf
= NULL
, *user_btf
= NULL
;
3826 unsigned int raw_btf_size
;
3828 struct bpf_btf_info info
;
3831 struct bpf_btf_info
*info
;
3832 int btf_fd
= -1, err
;
3835 raw_btf
= btf_raw_create(&hdr_tmpl
,
3839 &raw_btf_size
, NULL
);
3844 *btf_log_buf
= '\0';
3846 user_btf
= malloc(raw_btf_size
);
3847 if (CHECK(!user_btf
, "!user_btf")) {
3852 btf_fd
= bpf_load_btf(raw_btf
, raw_btf_size
,
3853 btf_log_buf
, BTF_LOG_BUF_SIZE
,
3855 if (CHECK(btf_fd
== -1, "errno:%d", errno
)) {
3861 * GET_INFO should error out if the userspace info
3862 * has non zero tailing bytes.
3864 info
= &info_garbage
.info
;
3865 memset(info
, 0, sizeof(*info
));
3866 info_garbage
.garbage
= 0xdeadbeef;
3867 info_len
= sizeof(info_garbage
);
3868 info
->btf
= ptr_to_u64(user_btf
);
3869 info
->btf_size
= raw_btf_size
;
3871 err
= bpf_obj_get_info_by_fd(btf_fd
, info
, &info_len
);
3872 if (CHECK(!err
, "!err")) {
3878 * GET_INFO should succeed even info_len is larger than
3879 * the kernel supported as long as tailing bytes are zero.
3880 * The kernel supported info len should also be returned
3883 info_garbage
.garbage
= 0;
3884 err
= bpf_obj_get_info_by_fd(btf_fd
, info
, &info_len
);
3885 if (CHECK(err
|| info_len
!= sizeof(*info
),
3886 "err:%d errno:%d info_len:%u sizeof(*info):%lu",
3887 err
, errno
, info_len
, sizeof(*info
))) {
3892 fprintf(stderr
, "OK");
3895 if (*btf_log_buf
&& (err
|| args
.always_log
))
3896 fprintf(stderr
, "\n%s", btf_log_buf
);
3907 static int test_btf_id(unsigned int test_num
)
3909 const struct btf_get_info_test
*test
= &get_info_tests
[test_num
- 1];
3910 struct bpf_create_map_attr create_attr
= {};
3911 uint8_t *raw_btf
= NULL
, *user_btf
[2] = {};
3912 int btf_fd
[2] = {-1, -1}, map_fd
= -1;
3913 struct bpf_map_info map_info
= {};
3914 struct bpf_btf_info info
[2] = {};
3915 unsigned int raw_btf_size
;
3919 raw_btf
= btf_raw_create(&hdr_tmpl
,
3923 &raw_btf_size
, NULL
);
3928 *btf_log_buf
= '\0';
3930 for (i
= 0; i
< 2; i
++) {
3931 user_btf
[i
] = malloc(raw_btf_size
);
3932 if (CHECK(!user_btf
[i
], "!user_btf[%d]", i
)) {
3936 info
[i
].btf
= ptr_to_u64(user_btf
[i
]);
3937 info
[i
].btf_size
= raw_btf_size
;
3940 btf_fd
[0] = bpf_load_btf(raw_btf
, raw_btf_size
,
3941 btf_log_buf
, BTF_LOG_BUF_SIZE
,
3943 if (CHECK(btf_fd
[0] == -1, "errno:%d", errno
)) {
3948 /* Test BPF_OBJ_GET_INFO_BY_ID on btf_id */
3949 info_len
= sizeof(info
[0]);
3950 err
= bpf_obj_get_info_by_fd(btf_fd
[0], &info
[0], &info_len
);
3951 if (CHECK(err
, "errno:%d", errno
)) {
3956 btf_fd
[1] = bpf_btf_get_fd_by_id(info
[0].id
);
3957 if (CHECK(btf_fd
[1] == -1, "errno:%d", errno
)) {
3963 err
= bpf_obj_get_info_by_fd(btf_fd
[1], &info
[1], &info_len
);
3964 if (CHECK(err
|| info
[0].id
!= info
[1].id
||
3965 info
[0].btf_size
!= info
[1].btf_size
||
3966 (ret
= memcmp(user_btf
[0], user_btf
[1], info
[0].btf_size
)),
3967 "err:%d errno:%d id0:%u id1:%u btf_size0:%u btf_size1:%u memcmp:%d",
3968 err
, errno
, info
[0].id
, info
[1].id
,
3969 info
[0].btf_size
, info
[1].btf_size
, ret
)) {
3974 /* Test btf members in struct bpf_map_info */
3975 create_attr
.name
= "test_btf_id";
3976 create_attr
.map_type
= BPF_MAP_TYPE_ARRAY
;
3977 create_attr
.key_size
= sizeof(int);
3978 create_attr
.value_size
= sizeof(unsigned int);
3979 create_attr
.max_entries
= 4;
3980 create_attr
.btf_fd
= btf_fd
[0];
3981 create_attr
.btf_key_type_id
= 1;
3982 create_attr
.btf_value_type_id
= 2;
3984 map_fd
= bpf_create_map_xattr(&create_attr
);
3985 if (CHECK(map_fd
== -1, "errno:%d", errno
)) {
3990 info_len
= sizeof(map_info
);
3991 err
= bpf_obj_get_info_by_fd(map_fd
, &map_info
, &info_len
);
3992 if (CHECK(err
|| map_info
.btf_id
!= info
[0].id
||
3993 map_info
.btf_key_type_id
!= 1 || map_info
.btf_value_type_id
!= 2,
3994 "err:%d errno:%d info.id:%u btf_id:%u btf_key_type_id:%u btf_value_type_id:%u",
3995 err
, errno
, info
[0].id
, map_info
.btf_id
, map_info
.btf_key_type_id
,
3996 map_info
.btf_value_type_id
)) {
4001 for (i
= 0; i
< 2; i
++) {
4006 /* Test BTF ID is removed from the kernel */
4007 btf_fd
[0] = bpf_btf_get_fd_by_id(map_info
.btf_id
);
4008 if (CHECK(btf_fd
[0] == -1, "errno:%d", errno
)) {
4015 /* The map holds the last ref to BTF and its btf_id */
4018 btf_fd
[0] = bpf_btf_get_fd_by_id(map_info
.btf_id
);
4019 if (CHECK(btf_fd
[0] != -1, "BTF lingers")) {
4024 fprintf(stderr
, "OK");
4027 if (*btf_log_buf
&& (err
|| args
.always_log
))
4028 fprintf(stderr
, "\n%s", btf_log_buf
);
4033 for (i
= 0; i
< 2; i
++) {
4035 if (btf_fd
[i
] != -1)
4042 static int do_test_get_info(unsigned int test_num
)
4044 const struct btf_get_info_test
*test
= &get_info_tests
[test_num
- 1];
4045 unsigned int raw_btf_size
, user_btf_size
, expected_nbytes
;
4046 uint8_t *raw_btf
= NULL
, *user_btf
= NULL
;
4047 struct bpf_btf_info info
= {};
4048 int btf_fd
= -1, err
, ret
;
4051 fprintf(stderr
, "BTF GET_INFO test[%u] (%s): ",
4052 test_num
, test
->descr
);
4054 if (test
->special_test
)
4055 return test
->special_test(test_num
);
4057 raw_btf
= btf_raw_create(&hdr_tmpl
,
4061 &raw_btf_size
, NULL
);
4066 *btf_log_buf
= '\0';
4068 user_btf
= malloc(raw_btf_size
);
4069 if (CHECK(!user_btf
, "!user_btf")) {
4074 btf_fd
= bpf_load_btf(raw_btf
, raw_btf_size
,
4075 btf_log_buf
, BTF_LOG_BUF_SIZE
,
4077 if (CHECK(btf_fd
== -1, "errno:%d", errno
)) {
4082 user_btf_size
= (int)raw_btf_size
+ test
->btf_size_delta
;
4083 expected_nbytes
= min(raw_btf_size
, user_btf_size
);
4084 if (raw_btf_size
> expected_nbytes
)
4085 memset(user_btf
+ expected_nbytes
, 0xff,
4086 raw_btf_size
- expected_nbytes
);
4088 info_len
= sizeof(info
);
4089 info
.btf
= ptr_to_u64(user_btf
);
4090 info
.btf_size
= user_btf_size
;
4093 err
= bpf_obj_get_info_by_fd(btf_fd
, &info
, &info_len
);
4094 if (CHECK(err
|| !info
.id
|| info_len
!= sizeof(info
) ||
4095 info
.btf_size
!= raw_btf_size
||
4096 (ret
= memcmp(raw_btf
, user_btf
, expected_nbytes
)),
4097 "err:%d errno:%d info.id:%u info_len:%u sizeof(info):%lu raw_btf_size:%u info.btf_size:%u expected_nbytes:%u memcmp:%d",
4098 err
, errno
, info
.id
, info_len
, sizeof(info
),
4099 raw_btf_size
, info
.btf_size
, expected_nbytes
, ret
)) {
4104 while (expected_nbytes
< raw_btf_size
) {
4105 fprintf(stderr
, "%u...", expected_nbytes
);
4106 if (CHECK(user_btf
[expected_nbytes
++] != 0xff,
4107 "user_btf[%u]:%x != 0xff", expected_nbytes
- 1,
4108 user_btf
[expected_nbytes
- 1])) {
4114 fprintf(stderr
, "OK");
4117 if (*btf_log_buf
&& (err
|| args
.always_log
))
4118 fprintf(stderr
, "\n%s", btf_log_buf
);
4129 static int test_get_info(void)
4134 if (args
.get_info_test_num
)
4135 return count_result(do_test_get_info(args
.get_info_test_num
));
4137 for (i
= 1; i
<= ARRAY_SIZE(get_info_tests
); i
++)
4138 err
|= count_result(do_test_get_info(i
));
4143 struct btf_file_test
{
4145 bool btf_kv_notfound
;
4148 static struct btf_file_test file_tests
[] = {
4149 { .file
= "test_btf_haskv.o", },
4150 { .file
= "test_btf_newkv.o", },
4151 { .file
= "test_btf_nokv.o", .btf_kv_notfound
= true, },
4154 static int do_test_file(unsigned int test_num
)
4156 const struct btf_file_test
*test
= &file_tests
[test_num
- 1];
4157 const char *expected_fnames
[] = {"_dummy_tracepoint",
4158 "test_long_fname_1",
4159 "test_long_fname_2"};
4160 struct btf_ext
*btf_ext
= NULL
;
4161 struct bpf_prog_info info
= {};
4162 struct bpf_object
*obj
= NULL
;
4163 struct bpf_func_info
*finfo
;
4164 struct bpf_program
*prog
;
4165 __u32 info_len
, rec_size
;
4166 bool has_btf_ext
= false;
4167 struct btf
*btf
= NULL
;
4168 void *func_info
= NULL
;
4169 struct bpf_map
*map
;
4170 int i
, err
, prog_fd
;
4172 fprintf(stderr
, "BTF libbpf test[%u] (%s): ", test_num
,
4175 btf
= btf__parse_elf(test
->file
, &btf_ext
);
4177 if (PTR_ERR(btf
) == -ENOENT
) {
4178 fprintf(stderr
, "SKIP. No ELF %s found", BTF_ELF_SEC
);
4182 return PTR_ERR(btf
);
4186 has_btf_ext
= btf_ext
!= NULL
;
4187 btf_ext__free(btf_ext
);
4189 obj
= bpf_object__open(test
->file
);
4190 if (CHECK(IS_ERR(obj
), "obj: %ld", PTR_ERR(obj
)))
4191 return PTR_ERR(obj
);
4193 prog
= bpf_program__next(NULL
, obj
);
4194 if (CHECK(!prog
, "Cannot find bpf_prog")) {
4199 bpf_program__set_type(prog
, BPF_PROG_TYPE_TRACEPOINT
);
4200 err
= bpf_object__load(obj
);
4201 if (CHECK(err
< 0, "bpf_object__load: %d", err
))
4203 prog_fd
= bpf_program__fd(prog
);
4205 map
= bpf_object__find_map_by_name(obj
, "btf_map");
4206 if (CHECK(!map
, "btf_map not found")) {
4211 err
= (bpf_map__btf_key_type_id(map
) == 0 || bpf_map__btf_value_type_id(map
) == 0)
4212 != test
->btf_kv_notfound
;
4213 if (CHECK(err
, "btf_key_type_id:%u btf_value_type_id:%u test->btf_kv_notfound:%u",
4214 bpf_map__btf_key_type_id(map
), bpf_map__btf_value_type_id(map
),
4215 test
->btf_kv_notfound
))
4221 /* get necessary program info */
4222 info_len
= sizeof(struct bpf_prog_info
);
4223 err
= bpf_obj_get_info_by_fd(prog_fd
, &info
, &info_len
);
4225 if (CHECK(err
== -1, "invalid get info (1st) errno:%d", errno
)) {
4226 fprintf(stderr
, "%s\n", btf_log_buf
);
4230 if (CHECK(info
.nr_func_info
!= 3,
4231 "incorrect info.nr_func_info (1st) %d",
4232 info
.nr_func_info
)) {
4236 rec_size
= info
.func_info_rec_size
;
4237 if (CHECK(rec_size
!= sizeof(struct bpf_func_info
),
4238 "incorrect info.func_info_rec_size (1st) %d\n", rec_size
)) {
4243 func_info
= malloc(info
.nr_func_info
* rec_size
);
4244 if (CHECK(!func_info
, "out of memory")) {
4249 /* reset info to only retrieve func_info related data */
4250 memset(&info
, 0, sizeof(info
));
4251 info
.nr_func_info
= 3;
4252 info
.func_info_rec_size
= rec_size
;
4253 info
.func_info
= ptr_to_u64(func_info
);
4255 err
= bpf_obj_get_info_by_fd(prog_fd
, &info
, &info_len
);
4257 if (CHECK(err
== -1, "invalid get info (2nd) errno:%d", errno
)) {
4258 fprintf(stderr
, "%s\n", btf_log_buf
);
4262 if (CHECK(info
.nr_func_info
!= 3,
4263 "incorrect info.nr_func_info (2nd) %d",
4264 info
.nr_func_info
)) {
4268 if (CHECK(info
.func_info_rec_size
!= rec_size
,
4269 "incorrect info.func_info_rec_size (2nd) %d",
4270 info
.func_info_rec_size
)) {
4275 err
= btf__get_from_id(info
.btf_id
, &btf
);
4276 if (CHECK(err
, "cannot get btf from kernel, err: %d", err
))
4279 /* check three functions */
4281 for (i
= 0; i
< 3; i
++) {
4282 const struct btf_type
*t
;
4285 t
= btf__type_by_id(btf
, finfo
->type_id
);
4286 if (CHECK(!t
, "btf__type_by_id failure: id %u",
4292 fname
= btf__name_by_offset(btf
, t
->name_off
);
4293 err
= strcmp(fname
, expected_fnames
[i
]);
4294 /* for the second and third functions in .text section,
4295 * the compiler may order them either way.
4298 err
= strcmp(fname
, expected_fnames
[3 - i
]);
4299 if (CHECK(err
, "incorrect fname %s", fname
? : "")) {
4304 finfo
= (void *)finfo
+ rec_size
;
4308 fprintf(stderr
, "OK");
4312 bpf_object__close(obj
);
4316 static int test_file(void)
4321 if (args
.file_test_num
)
4322 return count_result(do_test_file(args
.file_test_num
));
4324 for (i
= 1; i
<= ARRAY_SIZE(file_tests
); i
++)
4325 err
|= count_result(do_test_file(i
));
4330 const char *pprint_enum_str
[] = {
4337 struct pprint_mapv
{
4342 uint32_t unused_bits2a
:2,
4357 uint8_t si8_4
[2][2];
4360 #ifdef __SIZEOF_INT128__
4361 struct pprint_mapv_int128
{
4364 unsigned __int128 bits3
:3;
4365 unsigned __int128 bits80
:80;
4366 unsigned __int128 ui128
;
4370 static struct btf_raw_test pprint_test_template
[] = {
4373 /* unsighed char */ /* [1] */
4374 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 8, 1),
4375 /* unsigned short */ /* [2] */
4376 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 16, 2),
4377 /* unsigned int */ /* [3] */
4378 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4),
4380 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
4381 /* unsigned long long */ /* [5] */
4382 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 64, 8),
4383 /* 2 bits */ /* [6] */
4384 BTF_TYPE_INT_ENC(0, 0, 0, 2, 2),
4385 /* 28 bits */ /* [7] */
4386 BTF_TYPE_INT_ENC(0, 0, 0, 28, 4),
4387 /* uint8_t[8] */ /* [8] */
4388 BTF_TYPE_ARRAY_ENC(9, 1, 8),
4389 /* typedef unsigned char uint8_t */ /* [9] */
4390 BTF_TYPEDEF_ENC(NAME_TBD
, 1),
4391 /* typedef unsigned short uint16_t */ /* [10] */
4392 BTF_TYPEDEF_ENC(NAME_TBD
, 2),
4393 /* typedef unsigned int uint32_t */ /* [11] */
4394 BTF_TYPEDEF_ENC(NAME_TBD
, 3),
4395 /* typedef int int32_t */ /* [12] */
4396 BTF_TYPEDEF_ENC(NAME_TBD
, 4),
4397 /* typedef unsigned long long uint64_t *//* [13] */
4398 BTF_TYPEDEF_ENC(NAME_TBD
, 5),
4399 /* union (anon) */ /* [14] */
4400 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION
, 0, 2), 8),
4401 BTF_MEMBER_ENC(NAME_TBD
, 13, 0),/* uint64_t ui64; */
4402 BTF_MEMBER_ENC(NAME_TBD
, 8, 0), /* uint8_t ui8a[8]; */
4403 /* enum (anon) */ /* [15] */
4404 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 4), 4),
4405 BTF_ENUM_ENC(NAME_TBD
, 0),
4406 BTF_ENUM_ENC(NAME_TBD
, 1),
4407 BTF_ENUM_ENC(NAME_TBD
, 2),
4408 BTF_ENUM_ENC(NAME_TBD
, 3),
4409 /* struct pprint_mapv */ /* [16] */
4410 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 11), 40),
4411 BTF_MEMBER_ENC(NAME_TBD
, 11, 0), /* uint32_t ui32 */
4412 BTF_MEMBER_ENC(NAME_TBD
, 10, 32), /* uint16_t ui16 */
4413 BTF_MEMBER_ENC(NAME_TBD
, 12, 64), /* int32_t si32 */
4414 BTF_MEMBER_ENC(NAME_TBD
, 6, 96), /* unused_bits2a */
4415 BTF_MEMBER_ENC(NAME_TBD
, 7, 98), /* bits28 */
4416 BTF_MEMBER_ENC(NAME_TBD
, 6, 126), /* unused_bits2b */
4417 BTF_MEMBER_ENC(0, 14, 128), /* union (anon) */
4418 BTF_MEMBER_ENC(NAME_TBD
, 15, 192), /* aenum */
4419 BTF_MEMBER_ENC(NAME_TBD
, 11, 224), /* uint32_t ui32b */
4420 BTF_MEMBER_ENC(NAME_TBD
, 6, 256), /* bits2c */
4421 BTF_MEMBER_ENC(NAME_TBD
, 17, 264), /* si8_4 */
4422 BTF_TYPE_ARRAY_ENC(18, 1, 2), /* [17] */
4423 BTF_TYPE_ARRAY_ENC(1, 1, 2), /* [18] */
4426 BTF_STR_SEC("\0unsigned char\0unsigned short\0unsigned int\0int\0unsigned long long\0uint8_t\0uint16_t\0uint32_t\0int32_t\0uint64_t\0ui64\0ui8a\0ENUM_ZERO\0ENUM_ONE\0ENUM_TWO\0ENUM_THREE\0pprint_mapv\0ui32\0ui16\0si32\0unused_bits2a\0bits28\0unused_bits2b\0aenum\0ui32b\0bits2c\0si8_4"),
4427 .key_size
= sizeof(unsigned int),
4428 .value_size
= sizeof(struct pprint_mapv
),
4429 .key_type_id
= 3, /* unsigned int */
4430 .value_type_id
= 16, /* struct pprint_mapv */
4431 .max_entries
= 128 * 1024,
4435 /* this type will have the same type as the
4436 * first .raw_types definition, but struct type will
4437 * be encoded with kind_flag set.
4440 /* unsighed char */ /* [1] */
4441 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 8, 1),
4442 /* unsigned short */ /* [2] */
4443 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 16, 2),
4444 /* unsigned int */ /* [3] */
4445 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4),
4447 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
4448 /* unsigned long long */ /* [5] */
4449 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 64, 8),
4450 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [6] */
4451 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [7] */
4452 /* uint8_t[8] */ /* [8] */
4453 BTF_TYPE_ARRAY_ENC(9, 1, 8),
4454 /* typedef unsigned char uint8_t */ /* [9] */
4455 BTF_TYPEDEF_ENC(NAME_TBD
, 1),
4456 /* typedef unsigned short uint16_t */ /* [10] */
4457 BTF_TYPEDEF_ENC(NAME_TBD
, 2),
4458 /* typedef unsigned int uint32_t */ /* [11] */
4459 BTF_TYPEDEF_ENC(NAME_TBD
, 3),
4460 /* typedef int int32_t */ /* [12] */
4461 BTF_TYPEDEF_ENC(NAME_TBD
, 4),
4462 /* typedef unsigned long long uint64_t *//* [13] */
4463 BTF_TYPEDEF_ENC(NAME_TBD
, 5),
4464 /* union (anon) */ /* [14] */
4465 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION
, 0, 2), 8),
4466 BTF_MEMBER_ENC(NAME_TBD
, 13, 0),/* uint64_t ui64; */
4467 BTF_MEMBER_ENC(NAME_TBD
, 8, 0), /* uint8_t ui8a[8]; */
4468 /* enum (anon) */ /* [15] */
4469 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 4), 4),
4470 BTF_ENUM_ENC(NAME_TBD
, 0),
4471 BTF_ENUM_ENC(NAME_TBD
, 1),
4472 BTF_ENUM_ENC(NAME_TBD
, 2),
4473 BTF_ENUM_ENC(NAME_TBD
, 3),
4474 /* struct pprint_mapv */ /* [16] */
4475 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 11), 40),
4476 BTF_MEMBER_ENC(NAME_TBD
, 11, BTF_MEMBER_OFFSET(0, 0)), /* uint32_t ui32 */
4477 BTF_MEMBER_ENC(NAME_TBD
, 10, BTF_MEMBER_OFFSET(0, 32)), /* uint16_t ui16 */
4478 BTF_MEMBER_ENC(NAME_TBD
, 12, BTF_MEMBER_OFFSET(0, 64)), /* int32_t si32 */
4479 BTF_MEMBER_ENC(NAME_TBD
, 6, BTF_MEMBER_OFFSET(2, 96)), /* unused_bits2a */
4480 BTF_MEMBER_ENC(NAME_TBD
, 7, BTF_MEMBER_OFFSET(28, 98)), /* bits28 */
4481 BTF_MEMBER_ENC(NAME_TBD
, 6, BTF_MEMBER_OFFSET(2, 126)), /* unused_bits2b */
4482 BTF_MEMBER_ENC(0, 14, BTF_MEMBER_OFFSET(0, 128)), /* union (anon) */
4483 BTF_MEMBER_ENC(NAME_TBD
, 15, BTF_MEMBER_OFFSET(0, 192)), /* aenum */
4484 BTF_MEMBER_ENC(NAME_TBD
, 11, BTF_MEMBER_OFFSET(0, 224)), /* uint32_t ui32b */
4485 BTF_MEMBER_ENC(NAME_TBD
, 6, BTF_MEMBER_OFFSET(2, 256)), /* bits2c */
4486 BTF_MEMBER_ENC(NAME_TBD
, 17, 264), /* si8_4 */
4487 BTF_TYPE_ARRAY_ENC(18, 1, 2), /* [17] */
4488 BTF_TYPE_ARRAY_ENC(1, 1, 2), /* [18] */
4491 BTF_STR_SEC("\0unsigned char\0unsigned short\0unsigned int\0int\0unsigned long long\0uint8_t\0uint16_t\0uint32_t\0int32_t\0uint64_t\0ui64\0ui8a\0ENUM_ZERO\0ENUM_ONE\0ENUM_TWO\0ENUM_THREE\0pprint_mapv\0ui32\0ui16\0si32\0unused_bits2a\0bits28\0unused_bits2b\0aenum\0ui32b\0bits2c\0si8_4"),
4492 .key_size
= sizeof(unsigned int),
4493 .value_size
= sizeof(struct pprint_mapv
),
4494 .key_type_id
= 3, /* unsigned int */
4495 .value_type_id
= 16, /* struct pprint_mapv */
4496 .max_entries
= 128 * 1024,
4500 /* this type will have the same layout as the
4501 * first .raw_types definition. The struct type will
4502 * be encoded with kind_flag set, bitfield members
4503 * are added typedef/const/volatile, and bitfield members
4504 * will have both int and enum types.
4507 /* unsighed char */ /* [1] */
4508 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 8, 1),
4509 /* unsigned short */ /* [2] */
4510 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 16, 2),
4511 /* unsigned int */ /* [3] */
4512 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4),
4514 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
4515 /* unsigned long long */ /* [5] */
4516 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 64, 8),
4517 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [6] */
4518 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [7] */
4519 /* uint8_t[8] */ /* [8] */
4520 BTF_TYPE_ARRAY_ENC(9, 1, 8),
4521 /* typedef unsigned char uint8_t */ /* [9] */
4522 BTF_TYPEDEF_ENC(NAME_TBD
, 1),
4523 /* typedef unsigned short uint16_t */ /* [10] */
4524 BTF_TYPEDEF_ENC(NAME_TBD
, 2),
4525 /* typedef unsigned int uint32_t */ /* [11] */
4526 BTF_TYPEDEF_ENC(NAME_TBD
, 3),
4527 /* typedef int int32_t */ /* [12] */
4528 BTF_TYPEDEF_ENC(NAME_TBD
, 4),
4529 /* typedef unsigned long long uint64_t *//* [13] */
4530 BTF_TYPEDEF_ENC(NAME_TBD
, 5),
4531 /* union (anon) */ /* [14] */
4532 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION
, 0, 2), 8),
4533 BTF_MEMBER_ENC(NAME_TBD
, 13, 0),/* uint64_t ui64; */
4534 BTF_MEMBER_ENC(NAME_TBD
, 8, 0), /* uint8_t ui8a[8]; */
4535 /* enum (anon) */ /* [15] */
4536 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 4), 4),
4537 BTF_ENUM_ENC(NAME_TBD
, 0),
4538 BTF_ENUM_ENC(NAME_TBD
, 1),
4539 BTF_ENUM_ENC(NAME_TBD
, 2),
4540 BTF_ENUM_ENC(NAME_TBD
, 3),
4541 /* struct pprint_mapv */ /* [16] */
4542 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 11), 40),
4543 BTF_MEMBER_ENC(NAME_TBD
, 11, BTF_MEMBER_OFFSET(0, 0)), /* uint32_t ui32 */
4544 BTF_MEMBER_ENC(NAME_TBD
, 10, BTF_MEMBER_OFFSET(0, 32)), /* uint16_t ui16 */
4545 BTF_MEMBER_ENC(NAME_TBD
, 12, BTF_MEMBER_OFFSET(0, 64)), /* int32_t si32 */
4546 BTF_MEMBER_ENC(NAME_TBD
, 17, BTF_MEMBER_OFFSET(2, 96)), /* unused_bits2a */
4547 BTF_MEMBER_ENC(NAME_TBD
, 7, BTF_MEMBER_OFFSET(28, 98)), /* bits28 */
4548 BTF_MEMBER_ENC(NAME_TBD
, 19, BTF_MEMBER_OFFSET(2, 126)),/* unused_bits2b */
4549 BTF_MEMBER_ENC(0, 14, BTF_MEMBER_OFFSET(0, 128)), /* union (anon) */
4550 BTF_MEMBER_ENC(NAME_TBD
, 15, BTF_MEMBER_OFFSET(0, 192)), /* aenum */
4551 BTF_MEMBER_ENC(NAME_TBD
, 11, BTF_MEMBER_OFFSET(0, 224)), /* uint32_t ui32b */
4552 BTF_MEMBER_ENC(NAME_TBD
, 17, BTF_MEMBER_OFFSET(2, 256)), /* bits2c */
4553 BTF_MEMBER_ENC(NAME_TBD
, 20, BTF_MEMBER_OFFSET(0, 264)), /* si8_4 */
4554 /* typedef unsigned int ___int */ /* [17] */
4555 BTF_TYPEDEF_ENC(NAME_TBD
, 18),
4556 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE
, 0, 0), 6), /* [18] */
4557 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 15), /* [19] */
4558 BTF_TYPE_ARRAY_ENC(21, 1, 2), /* [20] */
4559 BTF_TYPE_ARRAY_ENC(1, 1, 2), /* [21] */
4562 BTF_STR_SEC("\0unsigned char\0unsigned short\0unsigned int\0int\0unsigned long long\0uint8_t\0uint16_t\0uint32_t\0int32_t\0uint64_t\0ui64\0ui8a\0ENUM_ZERO\0ENUM_ONE\0ENUM_TWO\0ENUM_THREE\0pprint_mapv\0ui32\0ui16\0si32\0unused_bits2a\0bits28\0unused_bits2b\0aenum\0ui32b\0bits2c\0___int\0si8_4"),
4563 .key_size
= sizeof(unsigned int),
4564 .value_size
= sizeof(struct pprint_mapv
),
4565 .key_type_id
= 3, /* unsigned int */
4566 .value_type_id
= 16, /* struct pprint_mapv */
4567 .max_entries
= 128 * 1024,
4570 #ifdef __SIZEOF_INT128__
4574 /* unsigned int */ /* [1] */
4575 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4),
4576 /* __int128 */ /* [2] */
4577 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 128, 16),
4578 /* unsigned __int128 */ /* [3] */
4579 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 128, 16),
4580 /* struct pprint_mapv_int128 */ /* [4] */
4581 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 5), 64),
4582 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(0, 0)), /* si128a */
4583 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(0, 128)), /* si128b */
4584 BTF_MEMBER_ENC(NAME_TBD
, 3, BTF_MEMBER_OFFSET(3, 256)), /* bits3 */
4585 BTF_MEMBER_ENC(NAME_TBD
, 3, BTF_MEMBER_OFFSET(80, 259)), /* bits80 */
4586 BTF_MEMBER_ENC(NAME_TBD
, 3, BTF_MEMBER_OFFSET(0, 384)), /* ui128 */
4589 BTF_STR_SEC("\0unsigned int\0__int128\0unsigned __int128\0pprint_mapv_int128\0si128a\0si128b\0bits3\0bits80\0ui128"),
4590 .key_size
= sizeof(unsigned int),
4591 .value_size
= sizeof(struct pprint_mapv_int128
),
4594 .max_entries
= 128 * 1024,
4595 .mapv_kind
= PPRINT_MAPV_KIND_INT128
,
4601 static struct btf_pprint_test_meta
{
4603 enum bpf_map_type map_type
;
4604 const char *map_name
;
4608 } pprint_tests_meta
[] = {
4610 .descr
= "BTF pretty print array",
4611 .map_type
= BPF_MAP_TYPE_ARRAY
,
4612 .map_name
= "pprint_test_array",
4613 .ordered_map
= true,
4614 .lossless_map
= true,
4615 .percpu_map
= false,
4619 .descr
= "BTF pretty print hash",
4620 .map_type
= BPF_MAP_TYPE_HASH
,
4621 .map_name
= "pprint_test_hash",
4622 .ordered_map
= false,
4623 .lossless_map
= true,
4624 .percpu_map
= false,
4628 .descr
= "BTF pretty print lru hash",
4629 .map_type
= BPF_MAP_TYPE_LRU_HASH
,
4630 .map_name
= "pprint_test_lru_hash",
4631 .ordered_map
= false,
4632 .lossless_map
= false,
4633 .percpu_map
= false,
4637 .descr
= "BTF pretty print percpu array",
4638 .map_type
= BPF_MAP_TYPE_PERCPU_ARRAY
,
4639 .map_name
= "pprint_test_percpu_array",
4640 .ordered_map
= true,
4641 .lossless_map
= true,
4646 .descr
= "BTF pretty print percpu hash",
4647 .map_type
= BPF_MAP_TYPE_PERCPU_HASH
,
4648 .map_name
= "pprint_test_percpu_hash",
4649 .ordered_map
= false,
4650 .lossless_map
= true,
4655 .descr
= "BTF pretty print lru percpu hash",
4656 .map_type
= BPF_MAP_TYPE_LRU_PERCPU_HASH
,
4657 .map_name
= "pprint_test_lru_percpu_hash",
4658 .ordered_map
= false,
4659 .lossless_map
= false,
4665 static size_t get_pprint_mapv_size(enum pprint_mapv_kind_t mapv_kind
)
4667 if (mapv_kind
== PPRINT_MAPV_KIND_BASIC
)
4668 return sizeof(struct pprint_mapv
);
4670 #ifdef __SIZEOF_INT128__
4671 if (mapv_kind
== PPRINT_MAPV_KIND_INT128
)
4672 return sizeof(struct pprint_mapv_int128
);
4678 static void set_pprint_mapv(enum pprint_mapv_kind_t mapv_kind
,
4679 void *mapv
, uint32_t i
,
4680 int num_cpus
, int rounded_value_size
)
4684 if (mapv_kind
== PPRINT_MAPV_KIND_BASIC
) {
4685 struct pprint_mapv
*v
= mapv
;
4687 for (cpu
= 0; cpu
< num_cpus
; cpu
++) {
4690 v
->unused_bits2a
= 3;
4692 v
->unused_bits2b
= 3;
4694 v
->aenum
= i
& 0x03;
4697 v
->si8_4
[0][0] = (cpu
+ i
) & 0xff;
4698 v
->si8_4
[0][1] = (cpu
+ i
+ 1) & 0xff;
4699 v
->si8_4
[1][0] = (cpu
+ i
+ 2) & 0xff;
4700 v
->si8_4
[1][1] = (cpu
+ i
+ 3) & 0xff;
4701 v
= (void *)v
+ rounded_value_size
;
4705 #ifdef __SIZEOF_INT128__
4706 if (mapv_kind
== PPRINT_MAPV_KIND_INT128
) {
4707 struct pprint_mapv_int128
*v
= mapv
;
4709 for (cpu
= 0; cpu
< num_cpus
; cpu
++) {
4712 v
->bits3
= i
& 0x07;
4713 v
->bits80
= (((unsigned __int128
)1) << 64) + i
;
4714 v
->ui128
= (((unsigned __int128
)2) << 64) + i
;
4715 v
= (void *)v
+ rounded_value_size
;
4721 ssize_t
get_pprint_expected_line(enum pprint_mapv_kind_t mapv_kind
,
4722 char *expected_line
, ssize_t line_size
,
4723 bool percpu_map
, unsigned int next_key
,
4724 int cpu
, void *mapv
)
4726 ssize_t nexpected_line
= -1;
4728 if (mapv_kind
== PPRINT_MAPV_KIND_BASIC
) {
4729 struct pprint_mapv
*v
= mapv
;
4731 nexpected_line
= snprintf(expected_line
, line_size
,
4732 "%s%u: {%u,0,%d,0x%x,0x%x,0x%x,"
4733 "{%lu|[%u,%u,%u,%u,%u,%u,%u,%u]},%s,"
4734 "%u,0x%x,[[%d,%d],[%d,%d]]}\n",
4735 percpu_map
? "\tcpu" : "",
4736 percpu_map
? cpu
: next_key
,
4742 v
->ui8a
[0], v
->ui8a
[1],
4743 v
->ui8a
[2], v
->ui8a
[3],
4744 v
->ui8a
[4], v
->ui8a
[5],
4745 v
->ui8a
[6], v
->ui8a
[7],
4746 pprint_enum_str
[v
->aenum
],
4749 v
->si8_4
[0][0], v
->si8_4
[0][1],
4750 v
->si8_4
[1][0], v
->si8_4
[1][1]);
4753 #ifdef __SIZEOF_INT128__
4754 if (mapv_kind
== PPRINT_MAPV_KIND_INT128
) {
4755 struct pprint_mapv_int128
*v
= mapv
;
4757 nexpected_line
= snprintf(expected_line
, line_size
,
4758 "%s%u: {0x%lx,0x%lx,0x%lx,"
4759 "0x%lx%016lx,0x%lx%016lx}\n",
4760 percpu_map
? "\tcpu" : "",
4761 percpu_map
? cpu
: next_key
,
4762 (uint64_t)v
->si128a
,
4763 (uint64_t)v
->si128b
,
4765 (uint64_t)(v
->bits80
>> 64),
4766 (uint64_t)v
->bits80
,
4767 (uint64_t)(v
->ui128
>> 64),
4768 (uint64_t)v
->ui128
);
4772 return nexpected_line
;
4775 static int check_line(const char *expected_line
, int nexpected_line
,
4776 int expected_line_len
, const char *line
)
4778 if (CHECK(nexpected_line
== expected_line_len
,
4779 "expected_line is too long"))
4782 if (strcmp(expected_line
, line
)) {
4783 fprintf(stderr
, "unexpected pprint output\n");
4784 fprintf(stderr
, "expected: %s", expected_line
);
4785 fprintf(stderr
, " read: %s", line
);
4793 static int do_test_pprint(int test_num
)
4795 const struct btf_raw_test
*test
= &pprint_test_template
[test_num
];
4796 enum pprint_mapv_kind_t mapv_kind
= test
->mapv_kind
;
4797 struct bpf_create_map_attr create_attr
= {};
4798 bool ordered_map
, lossless_map
, percpu_map
;
4799 int err
, ret
, num_cpus
, rounded_value_size
;
4800 unsigned int key
, nr_read_elems
;
4801 int map_fd
= -1, btf_fd
= -1;
4802 unsigned int raw_btf_size
;
4803 char expected_line
[255];
4804 FILE *pin_file
= NULL
;
4806 size_t line_len
= 0;
4812 fprintf(stderr
, "%s(#%d)......", test
->descr
, test_num
);
4813 raw_btf
= btf_raw_create(&hdr_tmpl
, test
->raw_types
,
4814 test
->str_sec
, test
->str_sec_size
,
4815 &raw_btf_size
, NULL
);
4820 *btf_log_buf
= '\0';
4821 btf_fd
= bpf_load_btf(raw_btf
, raw_btf_size
,
4822 btf_log_buf
, BTF_LOG_BUF_SIZE
,
4826 if (CHECK(btf_fd
== -1, "errno:%d", errno
)) {
4831 create_attr
.name
= test
->map_name
;
4832 create_attr
.map_type
= test
->map_type
;
4833 create_attr
.key_size
= test
->key_size
;
4834 create_attr
.value_size
= test
->value_size
;
4835 create_attr
.max_entries
= test
->max_entries
;
4836 create_attr
.btf_fd
= btf_fd
;
4837 create_attr
.btf_key_type_id
= test
->key_type_id
;
4838 create_attr
.btf_value_type_id
= test
->value_type_id
;
4840 map_fd
= bpf_create_map_xattr(&create_attr
);
4841 if (CHECK(map_fd
== -1, "errno:%d", errno
)) {
4846 ret
= snprintf(pin_path
, sizeof(pin_path
), "%s/%s",
4847 "/sys/fs/bpf", test
->map_name
);
4849 if (CHECK(ret
== sizeof(pin_path
), "pin_path %s/%s is too long",
4850 "/sys/fs/bpf", test
->map_name
)) {
4855 err
= bpf_obj_pin(map_fd
, pin_path
);
4856 if (CHECK(err
, "bpf_obj_pin(%s): errno:%d.", pin_path
, errno
))
4859 percpu_map
= test
->percpu_map
;
4860 num_cpus
= percpu_map
? bpf_num_possible_cpus() : 1;
4861 rounded_value_size
= round_up(get_pprint_mapv_size(mapv_kind
), 8);
4862 mapv
= calloc(num_cpus
, rounded_value_size
);
4863 if (CHECK(!mapv
, "mapv allocation failure")) {
4868 for (key
= 0; key
< test
->max_entries
; key
++) {
4869 set_pprint_mapv(mapv_kind
, mapv
, key
, num_cpus
, rounded_value_size
);
4870 bpf_map_update_elem(map_fd
, &key
, mapv
, 0);
4873 pin_file
= fopen(pin_path
, "r");
4874 if (CHECK(!pin_file
, "fopen(%s): errno:%d", pin_path
, errno
)) {
4879 /* Skip lines start with '#' */
4880 while ((nread
= getline(&line
, &line_len
, pin_file
)) > 0 &&
4884 if (CHECK(nread
<= 0, "Unexpected EOF")) {
4890 ordered_map
= test
->ordered_map
;
4891 lossless_map
= test
->lossless_map
;
4893 ssize_t nexpected_line
;
4894 unsigned int next_key
;
4898 next_key
= ordered_map
? nr_read_elems
: atoi(line
);
4899 set_pprint_mapv(mapv_kind
, mapv
, next_key
, num_cpus
, rounded_value_size
);
4902 for (cpu
= 0; cpu
< num_cpus
; cpu
++) {
4904 /* for percpu map, the format looks like:
4906 * cpu0: <value_on_cpu0>
4907 * cpu1: <value_on_cpu1>
4909 * cpun: <value_on_cpun>
4912 * let us verify the line containing the key here.
4915 nexpected_line
= snprintf(expected_line
,
4916 sizeof(expected_line
),
4920 err
= check_line(expected_line
, nexpected_line
,
4921 sizeof(expected_line
), line
);
4926 /* read value@cpu */
4927 nread
= getline(&line
, &line_len
, pin_file
);
4932 nexpected_line
= get_pprint_expected_line(mapv_kind
, expected_line
,
4933 sizeof(expected_line
),
4934 percpu_map
, next_key
,
4936 err
= check_line(expected_line
, nexpected_line
,
4937 sizeof(expected_line
), line
);
4941 cmapv
= cmapv
+ rounded_value_size
;
4945 /* skip the last bracket for the percpu map */
4946 nread
= getline(&line
, &line_len
, pin_file
);
4951 nread
= getline(&line
, &line_len
, pin_file
);
4952 } while (++nr_read_elems
< test
->max_entries
&& nread
> 0);
4955 CHECK(nr_read_elems
< test
->max_entries
,
4956 "Unexpected EOF. nr_read_elems:%u test->max_entries:%u",
4957 nr_read_elems
, test
->max_entries
)) {
4962 if (CHECK(nread
> 0, "Unexpected extra pprint output: %s", line
)) {
4973 fprintf(stderr
, "OK");
4974 if (*btf_log_buf
&& (err
|| args
.always_log
))
4975 fprintf(stderr
, "\n%s", btf_log_buf
);
4988 static int test_pprint(void)
4993 /* test various maps with the first test template */
4994 for (i
= 0; i
< ARRAY_SIZE(pprint_tests_meta
); i
++) {
4995 pprint_test_template
[0].descr
= pprint_tests_meta
[i
].descr
;
4996 pprint_test_template
[0].map_type
= pprint_tests_meta
[i
].map_type
;
4997 pprint_test_template
[0].map_name
= pprint_tests_meta
[i
].map_name
;
4998 pprint_test_template
[0].ordered_map
= pprint_tests_meta
[i
].ordered_map
;
4999 pprint_test_template
[0].lossless_map
= pprint_tests_meta
[i
].lossless_map
;
5000 pprint_test_template
[0].percpu_map
= pprint_tests_meta
[i
].percpu_map
;
5002 err
|= count_result(do_test_pprint(0));
5005 /* test rest test templates with the first map */
5006 for (i
= 1; i
< ARRAY_SIZE(pprint_test_template
); i
++) {
5007 pprint_test_template
[i
].descr
= pprint_tests_meta
[0].descr
;
5008 pprint_test_template
[i
].map_type
= pprint_tests_meta
[0].map_type
;
5009 pprint_test_template
[i
].map_name
= pprint_tests_meta
[0].map_name
;
5010 pprint_test_template
[i
].ordered_map
= pprint_tests_meta
[0].ordered_map
;
5011 pprint_test_template
[i
].lossless_map
= pprint_tests_meta
[0].lossless_map
;
5012 pprint_test_template
[i
].percpu_map
= pprint_tests_meta
[0].percpu_map
;
5013 err
|= count_result(do_test_pprint(i
));
5019 #define BPF_LINE_INFO_ENC(insn_off, file_off, line_off, line_num, line_col) \
5020 (insn_off), (file_off), (line_off), ((line_num) << 10 | ((line_col) & 0x3ff))
5022 static struct prog_info_raw_test
{
5024 const char *str_sec
;
5025 const char *err_str
;
5026 __u32 raw_types
[MAX_NR_RAW_U32
];
5028 struct bpf_insn insns
[MAX_INSNS
];
5030 __u32 func_info
[MAX_SUBPROGS
][2];
5031 __u32 func_info_rec_size
;
5032 __u32 func_info_cnt
;
5033 __u32 line_info
[MAX_NR_RAW_U32
];
5034 __u32 line_info_rec_size
;
5035 __u32 nr_jited_ksyms
;
5036 bool expected_prog_load_failure
;
5037 __u32 dead_code_cnt
;
5038 __u32 dead_code_mask
;
5039 __u32 dead_func_cnt
;
5040 __u32 dead_func_mask
;
5041 } info_raw_tests
[] = {
5043 .descr
= "func_type (main func + one sub)",
5045 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5046 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4), /* [2] */
5047 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
5048 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5049 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
5050 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
5051 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
5052 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5053 BTF_FUNC_ENC(NAME_TBD
, 3), /* [5] */
5054 BTF_FUNC_ENC(NAME_TBD
, 4), /* [6] */
5057 .str_sec
= "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5058 .str_sec_size
= sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5060 BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 1, 0, 2),
5061 BPF_MOV64_IMM(BPF_REG_0
, 1),
5063 BPF_MOV64_IMM(BPF_REG_0
, 2),
5066 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5067 .func_info
= { {0, 5}, {3, 6} },
5068 .func_info_rec_size
= 8,
5070 .line_info
= { BTF_END_RAW
},
5074 .descr
= "func_type (Incorrect func_info_rec_size)",
5076 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5077 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4), /* [2] */
5078 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
5079 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5080 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
5081 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
5082 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
5083 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5084 BTF_FUNC_ENC(NAME_TBD
, 3), /* [5] */
5085 BTF_FUNC_ENC(NAME_TBD
, 4), /* [6] */
5088 .str_sec
= "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5089 .str_sec_size
= sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5091 BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 1, 0, 2),
5092 BPF_MOV64_IMM(BPF_REG_0
, 1),
5094 BPF_MOV64_IMM(BPF_REG_0
, 2),
5097 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5098 .func_info
= { {0, 5}, {3, 6} },
5099 .func_info_rec_size
= 4,
5101 .line_info
= { BTF_END_RAW
},
5102 .expected_prog_load_failure
= true,
5106 .descr
= "func_type (Incorrect func_info_cnt)",
5108 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5109 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4), /* [2] */
5110 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
5111 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5112 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
5113 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
5114 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
5115 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5116 BTF_FUNC_ENC(NAME_TBD
, 3), /* [5] */
5117 BTF_FUNC_ENC(NAME_TBD
, 4), /* [6] */
5120 .str_sec
= "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5121 .str_sec_size
= sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5123 BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 1, 0, 2),
5124 BPF_MOV64_IMM(BPF_REG_0
, 1),
5126 BPF_MOV64_IMM(BPF_REG_0
, 2),
5129 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5130 .func_info
= { {0, 5}, {3, 6} },
5131 .func_info_rec_size
= 8,
5133 .line_info
= { BTF_END_RAW
},
5134 .expected_prog_load_failure
= true,
5138 .descr
= "func_type (Incorrect bpf_func_info.insn_off)",
5140 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5141 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4), /* [2] */
5142 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
5143 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5144 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
5145 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
5146 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
5147 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5148 BTF_FUNC_ENC(NAME_TBD
, 3), /* [5] */
5149 BTF_FUNC_ENC(NAME_TBD
, 4), /* [6] */
5152 .str_sec
= "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5153 .str_sec_size
= sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5155 BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 1, 0, 2),
5156 BPF_MOV64_IMM(BPF_REG_0
, 1),
5158 BPF_MOV64_IMM(BPF_REG_0
, 2),
5161 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5162 .func_info
= { {0, 5}, {2, 6} },
5163 .func_info_rec_size
= 8,
5165 .line_info
= { BTF_END_RAW
},
5166 .expected_prog_load_failure
= true,
5170 .descr
= "line_info (No subprog)",
5172 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5175 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5177 BPF_MOV64_IMM(BPF_REG_0
, 1),
5178 BPF_MOV64_IMM(BPF_REG_1
, 2),
5179 BPF_ALU64_REG(BPF_ADD
, BPF_REG_0
, BPF_REG_1
),
5182 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5185 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5186 BPF_LINE_INFO_ENC(1, 0, NAME_TBD
, 2, 9),
5187 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 8),
5188 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 4, 7),
5191 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5192 .nr_jited_ksyms
= 1,
5196 .descr
= "line_info (No subprog. insn_off >= prog->len)",
5198 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5201 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5203 BPF_MOV64_IMM(BPF_REG_0
, 1),
5204 BPF_MOV64_IMM(BPF_REG_1
, 2),
5205 BPF_ALU64_REG(BPF_ADD
, BPF_REG_0
, BPF_REG_1
),
5208 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5211 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5212 BPF_LINE_INFO_ENC(1, 0, NAME_TBD
, 2, 9),
5213 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 8),
5214 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 4, 7),
5215 BPF_LINE_INFO_ENC(4, 0, 0, 5, 6),
5218 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5219 .nr_jited_ksyms
= 1,
5220 .err_str
= "line_info[4].insn_off",
5221 .expected_prog_load_failure
= true,
5225 .descr
= "line_info (Zero bpf insn code)",
5227 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5228 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 64, 8), /* [2] */
5229 BTF_TYPEDEF_ENC(NAME_TBD
, 2), /* [3] */
5232 BTF_STR_SEC("\0int\0unsigned long\0u64\0u64 a=1;\0return a;"),
5234 BPF_LD_IMM64(BPF_REG_0
, 1),
5237 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5240 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5241 BPF_LINE_INFO_ENC(1, 0, 0, 2, 9),
5242 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 8),
5245 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5246 .nr_jited_ksyms
= 1,
5247 .err_str
= "Invalid insn code at line_info[1]",
5248 .expected_prog_load_failure
= true,
5252 .descr
= "line_info (No subprog. zero tailing line_info",
5254 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5257 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5259 BPF_MOV64_IMM(BPF_REG_0
, 1),
5260 BPF_MOV64_IMM(BPF_REG_1
, 2),
5261 BPF_ALU64_REG(BPF_ADD
, BPF_REG_0
, BPF_REG_1
),
5264 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5267 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10), 0,
5268 BPF_LINE_INFO_ENC(1, 0, NAME_TBD
, 2, 9), 0,
5269 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 8), 0,
5270 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 4, 7), 0,
5273 .line_info_rec_size
= sizeof(struct bpf_line_info
) + sizeof(__u32
),
5274 .nr_jited_ksyms
= 1,
5278 .descr
= "line_info (No subprog. nonzero tailing line_info)",
5280 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5283 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5285 BPF_MOV64_IMM(BPF_REG_0
, 1),
5286 BPF_MOV64_IMM(BPF_REG_1
, 2),
5287 BPF_ALU64_REG(BPF_ADD
, BPF_REG_0
, BPF_REG_1
),
5290 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5293 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10), 0,
5294 BPF_LINE_INFO_ENC(1, 0, NAME_TBD
, 2, 9), 0,
5295 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 8), 0,
5296 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 4, 7), 1,
5299 .line_info_rec_size
= sizeof(struct bpf_line_info
) + sizeof(__u32
),
5300 .nr_jited_ksyms
= 1,
5301 .err_str
= "nonzero tailing record in line_info",
5302 .expected_prog_load_failure
= true,
5306 .descr
= "line_info (subprog)",
5308 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5311 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5313 BPF_MOV64_IMM(BPF_REG_2
, 1),
5314 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_2
, 1),
5315 BPF_MOV64_REG(BPF_REG_1
, BPF_REG_2
),
5318 BPF_MOV64_REG(BPF_REG_0
, BPF_REG_1
),
5319 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5322 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5325 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5326 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 2, 9),
5327 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 3, 8),
5328 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 4, 7),
5331 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5332 .nr_jited_ksyms
= 2,
5336 .descr
= "line_info (subprog + func_info)",
5338 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5339 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5340 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5341 BTF_FUNC_ENC(NAME_TBD
, 2), /* [3] */
5342 BTF_FUNC_ENC(NAME_TBD
, 2), /* [4] */
5345 BTF_STR_SEC("\0int\0x\0sub\0main\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5347 BPF_MOV64_IMM(BPF_REG_2
, 1),
5348 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_2
, 1),
5349 BPF_MOV64_REG(BPF_REG_1
, BPF_REG_2
),
5352 BPF_MOV64_REG(BPF_REG_0
, BPF_REG_1
),
5353 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5356 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5358 .func_info_rec_size
= 8,
5359 .func_info
= { {0, 4}, {5, 3} },
5361 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5362 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 2, 9),
5363 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 3, 8),
5364 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 4, 7),
5367 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5368 .nr_jited_ksyms
= 2,
5372 .descr
= "line_info (subprog. missing 1st func line info)",
5374 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5377 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5379 BPF_MOV64_IMM(BPF_REG_2
, 1),
5380 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_2
, 1),
5381 BPF_MOV64_REG(BPF_REG_1
, BPF_REG_2
),
5384 BPF_MOV64_REG(BPF_REG_0
, BPF_REG_1
),
5385 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5388 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5391 BPF_LINE_INFO_ENC(1, 0, NAME_TBD
, 1, 10),
5392 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 2, 9),
5393 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 3, 8),
5394 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 4, 7),
5397 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5398 .nr_jited_ksyms
= 2,
5399 .err_str
= "missing bpf_line_info for func#0",
5400 .expected_prog_load_failure
= true,
5404 .descr
= "line_info (subprog. missing 2nd func line info)",
5406 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5409 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5411 BPF_MOV64_IMM(BPF_REG_2
, 1),
5412 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_2
, 1),
5413 BPF_MOV64_REG(BPF_REG_1
, BPF_REG_2
),
5416 BPF_MOV64_REG(BPF_REG_0
, BPF_REG_1
),
5417 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5420 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5423 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5424 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 2, 9),
5425 BPF_LINE_INFO_ENC(6, 0, NAME_TBD
, 3, 8),
5426 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 4, 7),
5429 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5430 .nr_jited_ksyms
= 2,
5431 .err_str
= "missing bpf_line_info for func#1",
5432 .expected_prog_load_failure
= true,
5436 .descr
= "line_info (subprog. unordered insn offset)",
5438 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5441 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5443 BPF_MOV64_IMM(BPF_REG_2
, 1),
5444 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_2
, 1),
5445 BPF_MOV64_REG(BPF_REG_1
, BPF_REG_2
),
5448 BPF_MOV64_REG(BPF_REG_0
, BPF_REG_1
),
5449 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5452 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5455 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5456 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 2, 9),
5457 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 8),
5458 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 4, 7),
5461 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5462 .nr_jited_ksyms
= 2,
5463 .err_str
= "Invalid line_info[2].insn_off",
5464 .expected_prog_load_failure
= true,
5468 .descr
= "line_info (dead start)",
5470 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5473 BTF_STR_SEC("\0int\0/* dead jmp */\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5475 BPF_JMP_IMM(BPF_JA
, 0, 0, 0),
5476 BPF_MOV64_IMM(BPF_REG_0
, 1),
5477 BPF_MOV64_IMM(BPF_REG_1
, 2),
5478 BPF_ALU64_REG(BPF_ADD
, BPF_REG_0
, BPF_REG_1
),
5481 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5484 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5485 BPF_LINE_INFO_ENC(1, 0, NAME_TBD
, 2, 9),
5486 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 8),
5487 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 4, 7),
5488 BPF_LINE_INFO_ENC(4, 0, NAME_TBD
, 5, 6),
5491 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5492 .nr_jited_ksyms
= 1,
5494 .dead_code_mask
= 0x01,
5498 .descr
= "line_info (dead end)",
5500 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5503 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0/* dead jmp */\0return a + b;\0/* dead exit */"),
5505 BPF_MOV64_IMM(BPF_REG_0
, 1),
5506 BPF_MOV64_IMM(BPF_REG_1
, 2),
5507 BPF_ALU64_REG(BPF_ADD
, BPF_REG_0
, BPF_REG_1
),
5508 BPF_JMP_IMM(BPF_JGE
, BPF_REG_0
, 10, 1),
5512 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5515 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 12),
5516 BPF_LINE_INFO_ENC(1, 0, NAME_TBD
, 2, 11),
5517 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 10),
5518 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 4, 9),
5519 BPF_LINE_INFO_ENC(4, 0, NAME_TBD
, 5, 8),
5520 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 6, 7),
5523 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5524 .nr_jited_ksyms
= 1,
5526 .dead_code_mask
= 0x28,
5530 .descr
= "line_info (dead code + subprog + func_info)",
5532 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5533 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5534 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5535 BTF_FUNC_ENC(NAME_TBD
, 2), /* [3] */
5536 BTF_FUNC_ENC(NAME_TBD
, 2), /* [4] */
5539 BTF_STR_SEC("\0int\0x\0sub\0main\0int a=1+1;\0/* dead jmp */"
5540 "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
5541 "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
5542 "\0return func(a);\0b+=1;\0return b;"),
5544 BPF_MOV64_IMM(BPF_REG_2
, 1),
5545 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_2
, 1),
5546 BPF_MOV64_REG(BPF_REG_1
, BPF_REG_2
),
5547 BPF_JMP_IMM(BPF_JGE
, BPF_REG_2
, 0, 8),
5548 BPF_MOV64_IMM(BPF_REG_2
, 1),
5549 BPF_MOV64_IMM(BPF_REG_2
, 1),
5550 BPF_MOV64_IMM(BPF_REG_2
, 1),
5551 BPF_MOV64_IMM(BPF_REG_2
, 1),
5552 BPF_MOV64_IMM(BPF_REG_2
, 1),
5553 BPF_MOV64_IMM(BPF_REG_2
, 1),
5554 BPF_MOV64_IMM(BPF_REG_2
, 1),
5555 BPF_MOV64_IMM(BPF_REG_2
, 1),
5558 BPF_MOV64_REG(BPF_REG_0
, BPF_REG_1
),
5559 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5562 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5564 .func_info_rec_size
= 8,
5565 .func_info
= { {0, 4}, {14, 3} },
5567 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5568 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 1, 10),
5569 BPF_LINE_INFO_ENC(4, 0, NAME_TBD
, 1, 10),
5570 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 1, 10),
5571 BPF_LINE_INFO_ENC(6, 0, NAME_TBD
, 1, 10),
5572 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 1, 10),
5573 BPF_LINE_INFO_ENC(8, 0, NAME_TBD
, 1, 10),
5574 BPF_LINE_INFO_ENC(9, 0, NAME_TBD
, 1, 10),
5575 BPF_LINE_INFO_ENC(10, 0, NAME_TBD
, 1, 10),
5576 BPF_LINE_INFO_ENC(11, 0, NAME_TBD
, 2, 9),
5577 BPF_LINE_INFO_ENC(12, 0, NAME_TBD
, 2, 9),
5578 BPF_LINE_INFO_ENC(14, 0, NAME_TBD
, 3, 8),
5579 BPF_LINE_INFO_ENC(16, 0, NAME_TBD
, 4, 7),
5582 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5583 .nr_jited_ksyms
= 2,
5585 .dead_code_mask
= 0x3fe,
5589 .descr
= "line_info (dead subprog)",
5591 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5592 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5593 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5594 BTF_FUNC_ENC(NAME_TBD
, 2), /* [3] */
5595 BTF_FUNC_ENC(NAME_TBD
, 2), /* [4] */
5596 BTF_FUNC_ENC(NAME_TBD
, 2), /* [5] */
5599 BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* live call */"
5600 "\0return 0;\0return 0;\0/* dead */\0/* dead */"
5601 "\0/* dead */\0return bla + 1;\0return bla + 1;"
5602 "\0return bla + 1;\0return func(a);\0b+=1;\0return b;"),
5604 BPF_MOV64_IMM(BPF_REG_2
, 1),
5605 BPF_JMP_IMM(BPF_JGE
, BPF_REG_2
, 0, 1),
5608 BPF_MOV64_IMM(BPF_REG_0
, 0),
5610 BPF_MOV64_IMM(BPF_REG_0
, 0),
5613 BPF_MOV64_REG(BPF_REG_0
, 2),
5614 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5617 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5619 .func_info_rec_size
= 8,
5620 .func_info
= { {0, 4}, {6, 3}, {9, 5} },
5622 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5623 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 1, 10),
5624 BPF_LINE_INFO_ENC(4, 0, NAME_TBD
, 1, 10),
5625 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 1, 10),
5626 BPF_LINE_INFO_ENC(6, 0, NAME_TBD
, 1, 10),
5627 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 1, 10),
5628 BPF_LINE_INFO_ENC(8, 0, NAME_TBD
, 1, 10),
5629 BPF_LINE_INFO_ENC(9, 0, NAME_TBD
, 1, 10),
5630 BPF_LINE_INFO_ENC(10, 0, NAME_TBD
, 1, 10),
5631 BPF_LINE_INFO_ENC(11, 0, NAME_TBD
, 2, 9),
5634 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5635 .nr_jited_ksyms
= 2,
5637 .dead_code_mask
= 0x70,
5639 .dead_func_mask
= 0x2,
5643 .descr
= "line_info (dead last subprog)",
5645 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5646 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5647 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5648 BTF_FUNC_ENC(NAME_TBD
, 2), /* [3] */
5649 BTF_FUNC_ENC(NAME_TBD
, 2), /* [5] */
5652 BTF_STR_SEC("\0int\0x\0dead\0main\0int a=1+1;\0/* live call */"
5653 "\0return 0;\0/* dead */\0/* dead */"),
5655 BPF_MOV64_IMM(BPF_REG_2
, 1),
5656 BPF_JMP_IMM(BPF_JGE
, BPF_REG_2
, 0, 1),
5658 BPF_MOV64_IMM(BPF_REG_0
, 0),
5660 BPF_MOV64_IMM(BPF_REG_0
, 0),
5663 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5665 .func_info_rec_size
= 8,
5666 .func_info
= { {0, 4}, {5, 3} },
5668 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5669 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 1, 10),
5670 BPF_LINE_INFO_ENC(4, 0, NAME_TBD
, 1, 10),
5671 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 1, 10),
5672 BPF_LINE_INFO_ENC(6, 0, NAME_TBD
, 1, 10),
5675 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5676 .nr_jited_ksyms
= 1,
5678 .dead_code_mask
= 0x18,
5680 .dead_func_mask
= 0x2,
5684 .descr
= "line_info (dead subprog + dead start)",
5686 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5687 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5688 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5689 BTF_FUNC_ENC(NAME_TBD
, 2), /* [3] */
5690 BTF_FUNC_ENC(NAME_TBD
, 2), /* [4] */
5691 BTF_FUNC_ENC(NAME_TBD
, 2), /* [5] */
5694 BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* dead */"
5695 "\0return 0;\0return 0;\0return 0;"
5696 "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
5697 "\0return b + 1;\0return b + 1;\0return b + 1;"),
5699 BPF_JMP_IMM(BPF_JA
, 0, 0, 0),
5700 BPF_MOV64_IMM(BPF_REG_2
, 1),
5701 BPF_JMP_IMM(BPF_JGE
, BPF_REG_2
, 0, 1),
5704 BPF_MOV64_IMM(BPF_REG_0
, 0),
5706 BPF_MOV64_IMM(BPF_REG_0
, 0),
5709 BPF_JMP_IMM(BPF_JA
, 0, 0, 0),
5710 BPF_MOV64_REG(BPF_REG_0
, 2),
5711 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5714 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5716 .func_info_rec_size
= 8,
5717 .func_info
= { {0, 4}, {7, 3}, {10, 5} },
5719 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5720 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 1, 10),
5721 BPF_LINE_INFO_ENC(4, 0, NAME_TBD
, 1, 10),
5722 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 1, 10),
5723 BPF_LINE_INFO_ENC(6, 0, NAME_TBD
, 1, 10),
5724 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 1, 10),
5725 BPF_LINE_INFO_ENC(8, 0, NAME_TBD
, 1, 10),
5726 BPF_LINE_INFO_ENC(9, 0, NAME_TBD
, 1, 10),
5727 BPF_LINE_INFO_ENC(10, 0, NAME_TBD
, 1, 10),
5728 BPF_LINE_INFO_ENC(11, 0, NAME_TBD
, 2, 9),
5729 BPF_LINE_INFO_ENC(12, 0, NAME_TBD
, 2, 9),
5730 BPF_LINE_INFO_ENC(13, 0, NAME_TBD
, 2, 9),
5733 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5734 .nr_jited_ksyms
= 2,
5736 .dead_code_mask
= 0x1e2,
5738 .dead_func_mask
= 0x2,
5742 .descr
= "line_info (dead subprog + dead start w/ move)",
5744 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5745 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5746 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5747 BTF_FUNC_ENC(NAME_TBD
, 2), /* [3] */
5748 BTF_FUNC_ENC(NAME_TBD
, 2), /* [4] */
5749 BTF_FUNC_ENC(NAME_TBD
, 2), /* [5] */
5752 BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* live call */"
5753 "\0return 0;\0return 0;\0/* dead */\0/* dead */"
5754 "\0/* dead */\0return bla + 1;\0return bla + 1;"
5755 "\0return bla + 1;\0return func(a);\0b+=1;\0return b;"),
5757 BPF_MOV64_IMM(BPF_REG_2
, 1),
5758 BPF_JMP_IMM(BPF_JGE
, BPF_REG_2
, 0, 1),
5761 BPF_MOV64_IMM(BPF_REG_0
, 0),
5763 BPF_MOV64_IMM(BPF_REG_0
, 0),
5766 BPF_JMP_IMM(BPF_JA
, 0, 0, 0),
5767 BPF_MOV64_REG(BPF_REG_0
, 2),
5768 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5771 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5773 .func_info_rec_size
= 8,
5774 .func_info
= { {0, 4}, {6, 3}, {9, 5} },
5776 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5777 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 1, 10),
5778 BPF_LINE_INFO_ENC(4, 0, NAME_TBD
, 1, 10),
5779 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 1, 10),
5780 BPF_LINE_INFO_ENC(6, 0, NAME_TBD
, 1, 10),
5781 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 1, 10),
5782 BPF_LINE_INFO_ENC(8, 0, NAME_TBD
, 1, 10),
5783 BPF_LINE_INFO_ENC(9, 0, NAME_TBD
, 1, 10),
5784 BPF_LINE_INFO_ENC(11, 0, NAME_TBD
, 1, 10),
5785 BPF_LINE_INFO_ENC(12, 0, NAME_TBD
, 2, 9),
5788 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5789 .nr_jited_ksyms
= 2,
5791 .dead_code_mask
= 0x70,
5793 .dead_func_mask
= 0x2,
5797 .descr
= "line_info (dead end + subprog start w/ no linfo)",
5799 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5800 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5801 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5802 BTF_FUNC_ENC(NAME_TBD
, 2), /* [3] */
5803 BTF_FUNC_ENC(NAME_TBD
, 2), /* [4] */
5806 BTF_STR_SEC("\0int\0x\0main\0func\0/* main linfo */\0/* func linfo */"),
5808 BPF_MOV64_IMM(BPF_REG_0
, 0),
5809 BPF_JMP_IMM(BPF_JGE
, BPF_REG_0
, 1, 3),
5811 BPF_MOV64_IMM(BPF_REG_0
, 0),
5814 BPF_JMP_IMM(BPF_JA
, 0, 0, 0),
5817 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5819 .func_info_rec_size
= 8,
5820 .func_info
= { {0, 3}, {6, 4}, },
5822 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5823 BPF_LINE_INFO_ENC(6, 0, NAME_TBD
, 1, 10),
5826 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5827 .nr_jited_ksyms
= 2,
5832 static size_t probe_prog_length(const struct bpf_insn
*fp
)
5836 for (len
= MAX_INSNS
- 1; len
> 0; --len
)
5837 if (fp
[len
].code
!= 0 || fp
[len
].imm
!= 0)
5842 static __u32
*patch_name_tbd(const __u32
*raw_u32
,
5843 const char *str
, __u32 str_off
,
5844 unsigned int str_sec_size
,
5845 unsigned int *ret_size
)
5847 int i
, raw_u32_size
= get_raw_sec_size(raw_u32
);
5848 const char *end_str
= str
+ str_sec_size
;
5849 const char *next_str
= str
+ str_off
;
5850 __u32
*new_u32
= NULL
;
5852 if (raw_u32_size
== -1)
5853 return ERR_PTR(-EINVAL
);
5855 if (!raw_u32_size
) {
5860 new_u32
= malloc(raw_u32_size
);
5862 return ERR_PTR(-ENOMEM
);
5864 for (i
= 0; i
< raw_u32_size
/ sizeof(raw_u32
[0]); i
++) {
5865 if (raw_u32
[i
] == NAME_TBD
) {
5866 next_str
= get_next_str(next_str
, end_str
);
5867 if (CHECK(!next_str
, "Error in getting next_str\n")) {
5869 return ERR_PTR(-EINVAL
);
5871 new_u32
[i
] = next_str
- str
;
5872 next_str
+= strlen(next_str
);
5874 new_u32
[i
] = raw_u32
[i
];
5878 *ret_size
= raw_u32_size
;
5882 static int test_get_finfo(const struct prog_info_raw_test
*test
,
5885 struct bpf_prog_info info
= {};
5886 struct bpf_func_info
*finfo
;
5887 __u32 info_len
, rec_size
, i
;
5888 void *func_info
= NULL
;
5892 /* get necessary lens */
5893 info_len
= sizeof(struct bpf_prog_info
);
5894 err
= bpf_obj_get_info_by_fd(prog_fd
, &info
, &info_len
);
5895 if (CHECK(err
== -1, "invalid get info (1st) errno:%d", errno
)) {
5896 fprintf(stderr
, "%s\n", btf_log_buf
);
5899 nr_func_info
= test
->func_info_cnt
- test
->dead_func_cnt
;
5900 if (CHECK(info
.nr_func_info
!= nr_func_info
,
5901 "incorrect info.nr_func_info (1st) %d",
5902 info
.nr_func_info
)) {
5906 rec_size
= info
.func_info_rec_size
;
5907 if (CHECK(rec_size
!= sizeof(struct bpf_func_info
),
5908 "incorrect info.func_info_rec_size (1st) %d", rec_size
)) {
5912 if (!info
.nr_func_info
)
5915 func_info
= malloc(info
.nr_func_info
* rec_size
);
5916 if (CHECK(!func_info
, "out of memory"))
5919 /* reset info to only retrieve func_info related data */
5920 memset(&info
, 0, sizeof(info
));
5921 info
.nr_func_info
= nr_func_info
;
5922 info
.func_info_rec_size
= rec_size
;
5923 info
.func_info
= ptr_to_u64(func_info
);
5924 err
= bpf_obj_get_info_by_fd(prog_fd
, &info
, &info_len
);
5925 if (CHECK(err
== -1, "invalid get info (2nd) errno:%d", errno
)) {
5926 fprintf(stderr
, "%s\n", btf_log_buf
);
5930 if (CHECK(info
.nr_func_info
!= nr_func_info
,
5931 "incorrect info.nr_func_info (2nd) %d",
5932 info
.nr_func_info
)) {
5936 if (CHECK(info
.func_info_rec_size
!= rec_size
,
5937 "incorrect info.func_info_rec_size (2nd) %d",
5938 info
.func_info_rec_size
)) {
5944 for (i
= 0; i
< nr_func_info
; i
++) {
5945 if (test
->dead_func_mask
& (1 << i
))
5947 if (CHECK(finfo
->type_id
!= test
->func_info
[i
][1],
5948 "incorrect func_type %u expected %u",
5949 finfo
->type_id
, test
->func_info
[i
][1])) {
5953 finfo
= (void *)finfo
+ rec_size
;
5963 static int test_get_linfo(const struct prog_info_raw_test
*test
,
5964 const void *patched_linfo
,
5965 __u32 cnt
, int prog_fd
)
5967 __u32 i
, info_len
, nr_jited_ksyms
, nr_jited_func_lens
;
5968 __u64
*jited_linfo
= NULL
, *jited_ksyms
= NULL
;
5969 __u32 rec_size
, jited_rec_size
, jited_cnt
;
5970 struct bpf_line_info
*linfo
= NULL
;
5971 __u32 cur_func_len
, ksyms_found
;
5972 struct bpf_prog_info info
= {};
5973 __u32
*jited_func_lens
= NULL
;
5974 __u64 cur_func_ksyms
;
5979 rec_size
= sizeof(*linfo
);
5980 jited_rec_size
= sizeof(*jited_linfo
);
5981 if (test
->nr_jited_ksyms
)
5982 nr_jited_ksyms
= test
->nr_jited_ksyms
;
5984 nr_jited_ksyms
= test
->func_info_cnt
- test
->dead_func_cnt
;
5985 nr_jited_func_lens
= nr_jited_ksyms
;
5987 info_len
= sizeof(struct bpf_prog_info
);
5988 err
= bpf_obj_get_info_by_fd(prog_fd
, &info
, &info_len
);
5989 if (CHECK(err
== -1, "err:%d errno:%d", err
, errno
)) {
5994 if (!info
.jited_prog_len
) {
5995 /* prog is not jited */
5998 nr_jited_func_lens
= 1;
6001 if (CHECK(info
.nr_line_info
!= cnt
||
6002 info
.nr_jited_line_info
!= jited_cnt
||
6003 info
.nr_jited_ksyms
!= nr_jited_ksyms
||
6004 info
.nr_jited_func_lens
!= nr_jited_func_lens
||
6005 (!info
.nr_line_info
&& info
.nr_jited_line_info
),
6006 "info: nr_line_info:%u(expected:%u) nr_jited_line_info:%u(expected:%u) nr_jited_ksyms:%u(expected:%u) nr_jited_func_lens:%u(expected:%u)",
6007 info
.nr_line_info
, cnt
,
6008 info
.nr_jited_line_info
, jited_cnt
,
6009 info
.nr_jited_ksyms
, nr_jited_ksyms
,
6010 info
.nr_jited_func_lens
, nr_jited_func_lens
)) {
6015 if (CHECK(info
.line_info_rec_size
!= sizeof(struct bpf_line_info
) ||
6016 info
.jited_line_info_rec_size
!= sizeof(__u64
),
6017 "info: line_info_rec_size:%u(userspace expected:%u) jited_line_info_rec_size:%u(userspace expected:%u)",
6018 info
.line_info_rec_size
, rec_size
,
6019 info
.jited_line_info_rec_size
, jited_rec_size
)) {
6027 rec_size
= info
.line_info_rec_size
;
6028 jited_rec_size
= info
.jited_line_info_rec_size
;
6030 memset(&info
, 0, sizeof(info
));
6032 linfo
= calloc(cnt
, rec_size
);
6033 if (CHECK(!linfo
, "!linfo")) {
6037 info
.nr_line_info
= cnt
;
6038 info
.line_info_rec_size
= rec_size
;
6039 info
.line_info
= ptr_to_u64(linfo
);
6042 jited_linfo
= calloc(jited_cnt
, jited_rec_size
);
6043 jited_ksyms
= calloc(nr_jited_ksyms
, sizeof(*jited_ksyms
));
6044 jited_func_lens
= calloc(nr_jited_func_lens
,
6045 sizeof(*jited_func_lens
));
6046 if (CHECK(!jited_linfo
|| !jited_ksyms
|| !jited_func_lens
,
6047 "jited_linfo:%p jited_ksyms:%p jited_func_lens:%p",
6048 jited_linfo
, jited_ksyms
, jited_func_lens
)) {
6053 info
.nr_jited_line_info
= jited_cnt
;
6054 info
.jited_line_info_rec_size
= jited_rec_size
;
6055 info
.jited_line_info
= ptr_to_u64(jited_linfo
);
6056 info
.nr_jited_ksyms
= nr_jited_ksyms
;
6057 info
.jited_ksyms
= ptr_to_u64(jited_ksyms
);
6058 info
.nr_jited_func_lens
= nr_jited_func_lens
;
6059 info
.jited_func_lens
= ptr_to_u64(jited_func_lens
);
6062 err
= bpf_obj_get_info_by_fd(prog_fd
, &info
, &info_len
);
6065 * Only recheck the info.*line_info* fields.
6066 * Other fields are not the concern of this test.
6068 if (CHECK(err
== -1 ||
6069 info
.nr_line_info
!= cnt
||
6070 (jited_cnt
&& !info
.jited_line_info
) ||
6071 info
.nr_jited_line_info
!= jited_cnt
||
6072 info
.line_info_rec_size
!= rec_size
||
6073 info
.jited_line_info_rec_size
!= jited_rec_size
,
6074 "err:%d errno:%d info: nr_line_info:%u(expected:%u) nr_jited_line_info:%u(expected:%u) line_info_rec_size:%u(expected:%u) jited_linfo_rec_size:%u(expected:%u) line_info:%p jited_line_info:%p",
6076 info
.nr_line_info
, cnt
,
6077 info
.nr_jited_line_info
, jited_cnt
,
6078 info
.line_info_rec_size
, rec_size
,
6079 info
.jited_line_info_rec_size
, jited_rec_size
,
6080 (void *)(long)info
.line_info
,
6081 (void *)(long)info
.jited_line_info
)) {
6087 while (test
->dead_code_mask
& (1 << dead_insns
))
6090 CHECK(linfo
[0].insn_off
, "linfo[0].insn_off:%u",
6092 for (i
= 1; i
< cnt
; i
++) {
6093 const struct bpf_line_info
*expected_linfo
;
6095 while (test
->dead_code_mask
& (1 << (i
+ dead_insns
)))
6098 expected_linfo
= patched_linfo
+
6099 ((i
+ dead_insns
) * test
->line_info_rec_size
);
6100 if (CHECK(linfo
[i
].insn_off
<= linfo
[i
- 1].insn_off
,
6101 "linfo[%u].insn_off:%u <= linfo[%u].insn_off:%u",
6102 i
, linfo
[i
].insn_off
,
6103 i
- 1, linfo
[i
- 1].insn_off
)) {
6107 if (CHECK(linfo
[i
].file_name_off
!= expected_linfo
->file_name_off
||
6108 linfo
[i
].line_off
!= expected_linfo
->line_off
||
6109 linfo
[i
].line_col
!= expected_linfo
->line_col
,
6110 "linfo[%u] (%u, %u, %u) != (%u, %u, %u)", i
,
6111 linfo
[i
].file_name_off
,
6114 expected_linfo
->file_name_off
,
6115 expected_linfo
->line_off
,
6116 expected_linfo
->line_col
)) {
6123 fprintf(stderr
, "not jited. skipping jited_line_info check. ");
6128 if (CHECK(jited_linfo
[0] != jited_ksyms
[0],
6129 "jited_linfo[0]:%lx != jited_ksyms[0]:%lx",
6130 (long)(jited_linfo
[0]), (long)(jited_ksyms
[0]))) {
6136 cur_func_len
= jited_func_lens
[0];
6137 cur_func_ksyms
= jited_ksyms
[0];
6138 for (i
= 1; i
< jited_cnt
; i
++) {
6139 if (ksyms_found
< nr_jited_ksyms
&&
6140 jited_linfo
[i
] == jited_ksyms
[ksyms_found
]) {
6141 cur_func_ksyms
= jited_ksyms
[ksyms_found
];
6142 cur_func_len
= jited_ksyms
[ksyms_found
];
6147 if (CHECK(jited_linfo
[i
] <= jited_linfo
[i
- 1],
6148 "jited_linfo[%u]:%lx <= jited_linfo[%u]:%lx",
6149 i
, (long)jited_linfo
[i
],
6150 i
- 1, (long)(jited_linfo
[i
- 1]))) {
6155 if (CHECK(jited_linfo
[i
] - cur_func_ksyms
> cur_func_len
,
6156 "jited_linfo[%u]:%lx - %lx > %u",
6157 i
, (long)jited_linfo
[i
], (long)cur_func_ksyms
,
6164 if (CHECK(ksyms_found
!= nr_jited_ksyms
,
6165 "ksyms_found:%u != nr_jited_ksyms:%u",
6166 ksyms_found
, nr_jited_ksyms
)) {
6177 free(jited_func_lens
);
6181 static int do_test_info_raw(unsigned int test_num
)
6183 const struct prog_info_raw_test
*test
= &info_raw_tests
[test_num
- 1];
6184 unsigned int raw_btf_size
, linfo_str_off
, linfo_size
;
6185 int btf_fd
= -1, prog_fd
= -1, err
= 0;
6186 void *raw_btf
, *patched_linfo
= NULL
;
6187 const char *ret_next_str
;
6188 union bpf_attr attr
= {};
6190 fprintf(stderr
, "BTF prog info raw test[%u] (%s): ", test_num
, test
->descr
);
6191 raw_btf
= btf_raw_create(&hdr_tmpl
, test
->raw_types
,
6192 test
->str_sec
, test
->str_sec_size
,
6193 &raw_btf_size
, &ret_next_str
);
6198 *btf_log_buf
= '\0';
6199 btf_fd
= bpf_load_btf(raw_btf
, raw_btf_size
,
6200 btf_log_buf
, BTF_LOG_BUF_SIZE
,
6204 if (CHECK(btf_fd
== -1, "invalid btf_fd errno:%d", errno
)) {
6209 if (*btf_log_buf
&& args
.always_log
)
6210 fprintf(stderr
, "\n%s", btf_log_buf
);
6211 *btf_log_buf
= '\0';
6213 linfo_str_off
= ret_next_str
- test
->str_sec
;
6214 patched_linfo
= patch_name_tbd(test
->line_info
,
6215 test
->str_sec
, linfo_str_off
,
6216 test
->str_sec_size
, &linfo_size
);
6217 if (IS_ERR(patched_linfo
)) {
6218 fprintf(stderr
, "error in creating raw bpf_line_info");
6223 attr
.prog_type
= test
->prog_type
;
6224 attr
.insns
= ptr_to_u64(test
->insns
);
6225 attr
.insn_cnt
= probe_prog_length(test
->insns
);
6226 attr
.license
= ptr_to_u64("GPL");
6227 attr
.prog_btf_fd
= btf_fd
;
6228 attr
.func_info_rec_size
= test
->func_info_rec_size
;
6229 attr
.func_info_cnt
= test
->func_info_cnt
;
6230 attr
.func_info
= ptr_to_u64(test
->func_info
);
6231 attr
.log_buf
= ptr_to_u64(btf_log_buf
);
6232 attr
.log_size
= BTF_LOG_BUF_SIZE
;
6235 attr
.line_info_rec_size
= test
->line_info_rec_size
;
6236 attr
.line_info
= ptr_to_u64(patched_linfo
);
6237 attr
.line_info_cnt
= linfo_size
/ attr
.line_info_rec_size
;
6240 prog_fd
= syscall(__NR_bpf
, BPF_PROG_LOAD
, &attr
, sizeof(attr
));
6241 err
= ((prog_fd
== -1) != test
->expected_prog_load_failure
);
6242 if (CHECK(err
, "prog_fd:%d expected_prog_load_failure:%u errno:%d",
6243 prog_fd
, test
->expected_prog_load_failure
, errno
) ||
6244 CHECK(test
->err_str
&& !strstr(btf_log_buf
, test
->err_str
),
6245 "expected err_str:%s", test
->err_str
)) {
6253 err
= test_get_finfo(test
, prog_fd
);
6257 err
= test_get_linfo(test
, patched_linfo
,
6258 attr
.line_info_cnt
- test
->dead_code_cnt
,
6265 fprintf(stderr
, "OK");
6267 if (*btf_log_buf
&& (err
|| args
.always_log
))
6268 fprintf(stderr
, "\n%s", btf_log_buf
);
6275 if (!IS_ERR(patched_linfo
))
6276 free(patched_linfo
);
6281 static int test_info_raw(void)
6286 if (args
.info_raw_test_num
)
6287 return count_result(do_test_info_raw(args
.info_raw_test_num
));
6289 for (i
= 1; i
<= ARRAY_SIZE(info_raw_tests
); i
++)
6290 err
|= count_result(do_test_info_raw(i
));
6295 struct btf_raw_data
{
6296 __u32 raw_types
[MAX_NR_RAW_U32
];
6297 const char *str_sec
;
6301 struct btf_dedup_test
{
6303 struct btf_raw_data input
;
6304 struct btf_raw_data expect
;
6305 struct btf_dedup_opts opts
;
6308 const struct btf_dedup_test dedup_tests
[] = {
6311 .descr
= "dedup: unused strings filtering",
6314 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED
, 0, 32, 4),
6315 BTF_TYPE_INT_ENC(NAME_NTH(5), BTF_INT_SIGNED
, 0, 64, 8),
6318 BTF_STR_SEC("\0unused\0int\0foo\0bar\0long"),
6322 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 4),
6323 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED
, 0, 64, 8),
6326 BTF_STR_SEC("\0int\0long"),
6329 .dont_resolve_fwds
= false,
6333 .descr
= "dedup: strings deduplication",
6336 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 4),
6337 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED
, 0, 64, 8),
6338 BTF_TYPE_INT_ENC(NAME_NTH(3), BTF_INT_SIGNED
, 0, 32, 4),
6339 BTF_TYPE_INT_ENC(NAME_NTH(4), BTF_INT_SIGNED
, 0, 64, 8),
6340 BTF_TYPE_INT_ENC(NAME_NTH(5), BTF_INT_SIGNED
, 0, 32, 4),
6343 BTF_STR_SEC("\0int\0long int\0int\0long int\0int"),
6347 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 4),
6348 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED
, 0, 64, 8),
6351 BTF_STR_SEC("\0int\0long int"),
6354 .dont_resolve_fwds
= false,
6358 .descr
= "dedup: struct example #1",
6370 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
6372 BTF_TYPE_ARRAY_ENC(1, 1, 16), /* [2] */
6374 BTF_STRUCT_ENC(NAME_NTH(2), 4, 84), /* [3] */
6375 BTF_MEMBER_ENC(NAME_NTH(3), 4, 0), /* struct s *next; */
6376 BTF_MEMBER_ENC(NAME_NTH(4), 5, 64), /* const int *a; */
6377 BTF_MEMBER_ENC(NAME_NTH(5), 2, 128), /* int b[16]; */
6378 BTF_MEMBER_ENC(NAME_NTH(6), 1, 640), /* int c; */
6379 /* ptr -> [3] struct s */
6380 BTF_PTR_ENC(3), /* [4] */
6381 /* ptr -> [6] const int */
6382 BTF_PTR_ENC(6), /* [5] */
6383 /* const -> [1] int */
6384 BTF_CONST_ENC(1), /* [6] */
6386 /* full copy of the above */
6387 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 4), /* [7] */
6388 BTF_TYPE_ARRAY_ENC(7, 7, 16), /* [8] */
6389 BTF_STRUCT_ENC(NAME_NTH(2), 4, 84), /* [9] */
6390 BTF_MEMBER_ENC(NAME_NTH(3), 10, 0),
6391 BTF_MEMBER_ENC(NAME_NTH(4), 11, 64),
6392 BTF_MEMBER_ENC(NAME_NTH(5), 8, 128),
6393 BTF_MEMBER_ENC(NAME_NTH(6), 7, 640),
6394 BTF_PTR_ENC(9), /* [10] */
6395 BTF_PTR_ENC(12), /* [11] */
6396 BTF_CONST_ENC(7), /* [12] */
6399 BTF_STR_SEC("\0int\0s\0next\0a\0b\0c\0"),
6404 BTF_TYPE_INT_ENC(NAME_NTH(4), BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
6406 BTF_TYPE_ARRAY_ENC(1, 1, 16), /* [2] */
6408 BTF_STRUCT_ENC(NAME_NTH(6), 4, 84), /* [3] */
6409 BTF_MEMBER_ENC(NAME_NTH(5), 4, 0), /* struct s *next; */
6410 BTF_MEMBER_ENC(NAME_NTH(1), 5, 64), /* const int *a; */
6411 BTF_MEMBER_ENC(NAME_NTH(2), 2, 128), /* int b[16]; */
6412 BTF_MEMBER_ENC(NAME_NTH(3), 1, 640), /* int c; */
6413 /* ptr -> [3] struct s */
6414 BTF_PTR_ENC(3), /* [4] */
6415 /* ptr -> [6] const int */
6416 BTF_PTR_ENC(6), /* [5] */
6417 /* const -> [1] int */
6418 BTF_CONST_ENC(1), /* [6] */
6421 BTF_STR_SEC("\0a\0b\0c\0int\0next\0s"),
6424 .dont_resolve_fwds
= false,
6428 .descr
= "dedup: struct <-> fwd resolution w/ hash collision",
6444 BTF_FWD_ENC(NAME_TBD
, 0 /* struct fwd */), /* [1] fwd x */
6445 BTF_PTR_ENC(1), /* [2] ptr -> [1] */
6446 BTF_STRUCT_ENC(NAME_TBD
, 1, 8), /* [3] struct s */
6447 BTF_MEMBER_ENC(NAME_TBD
, 2, 0),
6449 BTF_STRUCT_ENC(NAME_TBD
, 0, 0), /* [4] struct x */
6450 BTF_PTR_ENC(4), /* [5] ptr -> [4] */
6451 BTF_STRUCT_ENC(NAME_TBD
, 1, 8), /* [6] struct s */
6452 BTF_MEMBER_ENC(NAME_TBD
, 5, 0),
6455 BTF_STR_SEC("\0x\0s\0x\0x\0s\0x\0"),
6459 BTF_PTR_ENC(3), /* [1] ptr -> [3] */
6460 BTF_STRUCT_ENC(NAME_TBD
, 1, 8), /* [2] struct s */
6461 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
6462 BTF_STRUCT_ENC(NAME_NTH(2), 0, 0), /* [3] struct x */
6465 BTF_STR_SEC("\0s\0x"),
6468 .dont_resolve_fwds
= false,
6469 .dedup_table_size
= 1, /* force hash collisions */
6473 .descr
= "dedup: void equiv check",
6487 BTF_STRUCT_ENC(0, 0, 1), /* [1] struct {} */
6488 BTF_PTR_ENC(1), /* [2] ptr -> [1] */
6489 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [3] struct s */
6490 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
6492 BTF_PTR_ENC(0), /* [4] ptr -> void */
6493 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [5] struct s */
6494 BTF_MEMBER_ENC(NAME_NTH(2), 4, 0),
6497 BTF_STR_SEC("\0s\0x"),
6502 BTF_STRUCT_ENC(0, 0, 1), /* [1] struct {} */
6503 BTF_PTR_ENC(1), /* [2] ptr -> [1] */
6504 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [3] struct s */
6505 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
6507 BTF_PTR_ENC(0), /* [4] ptr -> void */
6508 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [5] struct s */
6509 BTF_MEMBER_ENC(NAME_NTH(2), 4, 0),
6512 BTF_STR_SEC("\0s\0x"),
6515 .dont_resolve_fwds
= false,
6516 .dedup_table_size
= 1, /* force hash collisions */
6520 .descr
= "dedup: all possible kinds (no duplicates)",
6523 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 8), /* [1] int */
6524 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 2), 4), /* [2] enum */
6525 BTF_ENUM_ENC(NAME_TBD
, 0),
6526 BTF_ENUM_ENC(NAME_TBD
, 1),
6527 BTF_FWD_ENC(NAME_TBD
, 1 /* union kind_flag */), /* [3] fwd */
6528 BTF_TYPE_ARRAY_ENC(2, 1, 7), /* [4] array */
6529 BTF_STRUCT_ENC(NAME_TBD
, 1, 4), /* [5] struct */
6530 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
6531 BTF_UNION_ENC(NAME_TBD
, 1, 4), /* [6] union */
6532 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
6533 BTF_TYPEDEF_ENC(NAME_TBD
, 1), /* [7] typedef */
6534 BTF_PTR_ENC(0), /* [8] ptr */
6535 BTF_CONST_ENC(8), /* [9] const */
6536 BTF_VOLATILE_ENC(8), /* [10] volatile */
6537 BTF_RESTRICT_ENC(8), /* [11] restrict */
6538 BTF_FUNC_PROTO_ENC(1, 2), /* [12] func_proto */
6539 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
6540 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 8),
6541 BTF_FUNC_ENC(NAME_TBD
, 12), /* [13] func */
6544 BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M"),
6548 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 8), /* [1] int */
6549 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 2), 4), /* [2] enum */
6550 BTF_ENUM_ENC(NAME_TBD
, 0),
6551 BTF_ENUM_ENC(NAME_TBD
, 1),
6552 BTF_FWD_ENC(NAME_TBD
, 1 /* union kind_flag */), /* [3] fwd */
6553 BTF_TYPE_ARRAY_ENC(2, 1, 7), /* [4] array */
6554 BTF_STRUCT_ENC(NAME_TBD
, 1, 4), /* [5] struct */
6555 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
6556 BTF_UNION_ENC(NAME_TBD
, 1, 4), /* [6] union */
6557 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
6558 BTF_TYPEDEF_ENC(NAME_TBD
, 1), /* [7] typedef */
6559 BTF_PTR_ENC(0), /* [8] ptr */
6560 BTF_CONST_ENC(8), /* [9] const */
6561 BTF_VOLATILE_ENC(8), /* [10] volatile */
6562 BTF_RESTRICT_ENC(8), /* [11] restrict */
6563 BTF_FUNC_PROTO_ENC(1, 2), /* [12] func_proto */
6564 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
6565 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 8),
6566 BTF_FUNC_ENC(NAME_TBD
, 12), /* [13] func */
6569 BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M"),
6572 .dont_resolve_fwds
= false,
6576 .descr
= "dedup: no int duplicates",
6579 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 8),
6580 /* different name */
6581 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED
, 0, 32, 8),
6582 /* different encoding */
6583 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_CHAR
, 0, 32, 8),
6584 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_BOOL
, 0, 32, 8),
6585 /* different bit offset */
6586 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 8, 32, 8),
6587 /* different bit size */
6588 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 27, 8),
6589 /* different byte size */
6590 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 4),
6593 BTF_STR_SEC("\0int\0some other int"),
6597 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 8),
6598 /* different name */
6599 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED
, 0, 32, 8),
6600 /* different encoding */
6601 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_CHAR
, 0, 32, 8),
6602 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_BOOL
, 0, 32, 8),
6603 /* different bit offset */
6604 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 8, 32, 8),
6605 /* different bit size */
6606 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 27, 8),
6607 /* different byte size */
6608 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 4),
6611 BTF_STR_SEC("\0int\0some other int"),
6614 .dont_resolve_fwds
= false,
6618 .descr
= "dedup: enum fwd resolution",
6621 /* [1] fwd enum 'e1' before full enum */
6622 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 0), 4),
6623 /* [2] full enum 'e1' after fwd */
6624 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4),
6625 BTF_ENUM_ENC(NAME_NTH(2), 123),
6626 /* [3] full enum 'e2' before fwd */
6627 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4),
6628 BTF_ENUM_ENC(NAME_NTH(4), 456),
6629 /* [4] fwd enum 'e2' after full enum */
6630 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 0), 4),
6631 /* [5] incompatible fwd enum with different size */
6632 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 0), 1),
6633 /* [6] incompatible full enum with different value */
6634 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4),
6635 BTF_ENUM_ENC(NAME_NTH(2), 321),
6638 BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
6642 /* [1] full enum 'e1' */
6643 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4),
6644 BTF_ENUM_ENC(NAME_NTH(2), 123),
6645 /* [2] full enum 'e2' */
6646 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4),
6647 BTF_ENUM_ENC(NAME_NTH(4), 456),
6648 /* [3] incompatible fwd enum with different size */
6649 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 0), 1),
6650 /* [4] incompatible full enum with different value */
6651 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4),
6652 BTF_ENUM_ENC(NAME_NTH(2), 321),
6655 BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
6658 .dont_resolve_fwds
= false,
6662 .descr
= "dedup: datasec and vars pass-through",
6666 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
6668 BTF_VAR_ENC(NAME_NTH(2), 1, 0), /* [2] */
6669 /* .bss section */ /* [3] */
6670 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
6671 BTF_VAR_SECINFO_ENC(2, 0, 4),
6672 /* int, referenced from [5] */
6673 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [4] */
6674 /* another static int t */
6675 BTF_VAR_ENC(NAME_NTH(2), 4, 0), /* [5] */
6676 /* another .bss section */ /* [6] */
6677 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
6678 BTF_VAR_SECINFO_ENC(5, 0, 4),
6681 BTF_STR_SEC("\0.bss\0t"),
6686 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
6688 BTF_VAR_ENC(NAME_NTH(2), 1, 0), /* [2] */
6689 /* .bss section */ /* [3] */
6690 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
6691 BTF_VAR_SECINFO_ENC(2, 0, 4),
6692 /* another static int t */
6693 BTF_VAR_ENC(NAME_NTH(2), 1, 0), /* [4] */
6694 /* another .bss section */ /* [5] */
6695 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
6696 BTF_VAR_SECINFO_ENC(4, 0, 4),
6699 BTF_STR_SEC("\0.bss\0t"),
6702 .dont_resolve_fwds
= false,
6703 .dedup_table_size
= 1
6709 static int btf_type_size(const struct btf_type
*t
)
6711 int base_size
= sizeof(struct btf_type
);
6712 __u16 vlen
= BTF_INFO_VLEN(t
->info
);
6713 __u16 kind
= BTF_INFO_KIND(t
->info
);
6717 case BTF_KIND_CONST
:
6718 case BTF_KIND_VOLATILE
:
6719 case BTF_KIND_RESTRICT
:
6721 case BTF_KIND_TYPEDEF
:
6725 return base_size
+ sizeof(__u32
);
6727 return base_size
+ vlen
* sizeof(struct btf_enum
);
6728 case BTF_KIND_ARRAY
:
6729 return base_size
+ sizeof(struct btf_array
);
6730 case BTF_KIND_STRUCT
:
6731 case BTF_KIND_UNION
:
6732 return base_size
+ vlen
* sizeof(struct btf_member
);
6733 case BTF_KIND_FUNC_PROTO
:
6734 return base_size
+ vlen
* sizeof(struct btf_param
);
6736 return base_size
+ sizeof(struct btf_var
);
6737 case BTF_KIND_DATASEC
:
6738 return base_size
+ vlen
* sizeof(struct btf_var_secinfo
);
6740 fprintf(stderr
, "Unsupported BTF_KIND:%u\n", kind
);
6745 static void dump_btf_strings(const char *strs
, __u32 len
)
6747 const char *cur
= strs
;
6750 while (cur
< strs
+ len
) {
6751 fprintf(stderr
, "string #%d: '%s'\n", i
, cur
);
6752 cur
+= strlen(cur
) + 1;
6757 static int do_test_dedup(unsigned int test_num
)
6759 const struct btf_dedup_test
*test
= &dedup_tests
[test_num
- 1];
6760 __u32 test_nr_types
, expect_nr_types
, test_btf_size
, expect_btf_size
;
6761 const struct btf_header
*test_hdr
, *expect_hdr
;
6762 struct btf
*test_btf
= NULL
, *expect_btf
= NULL
;
6763 const void *test_btf_data
, *expect_btf_data
;
6764 const char *ret_test_next_str
, *ret_expect_next_str
;
6765 const char *test_strs
, *expect_strs
;
6766 const char *test_str_cur
, *test_str_end
;
6767 const char *expect_str_cur
, *expect_str_end
;
6768 unsigned int raw_btf_size
;
6772 fprintf(stderr
, "BTF dedup test[%u] (%s):", test_num
, test
->descr
);
6774 raw_btf
= btf_raw_create(&hdr_tmpl
, test
->input
.raw_types
,
6775 test
->input
.str_sec
, test
->input
.str_sec_size
,
6776 &raw_btf_size
, &ret_test_next_str
);
6779 test_btf
= btf__new((__u8
*)raw_btf
, raw_btf_size
);
6781 if (CHECK(IS_ERR(test_btf
), "invalid test_btf errno:%ld",
6782 PTR_ERR(test_btf
))) {
6787 raw_btf
= btf_raw_create(&hdr_tmpl
, test
->expect
.raw_types
,
6788 test
->expect
.str_sec
,
6789 test
->expect
.str_sec_size
,
6790 &raw_btf_size
, &ret_expect_next_str
);
6793 expect_btf
= btf__new((__u8
*)raw_btf
, raw_btf_size
);
6795 if (CHECK(IS_ERR(expect_btf
), "invalid expect_btf errno:%ld",
6796 PTR_ERR(expect_btf
))) {
6801 err
= btf__dedup(test_btf
, NULL
, &test
->opts
);
6802 if (CHECK(err
, "btf_dedup failed errno:%d", err
)) {
6807 test_btf_data
= btf__get_raw_data(test_btf
, &test_btf_size
);
6808 expect_btf_data
= btf__get_raw_data(expect_btf
, &expect_btf_size
);
6809 if (CHECK(test_btf_size
!= expect_btf_size
,
6810 "test_btf_size:%u != expect_btf_size:%u",
6811 test_btf_size
, expect_btf_size
)) {
6816 test_hdr
= test_btf_data
;
6817 test_strs
= test_btf_data
+ sizeof(*test_hdr
) + test_hdr
->str_off
;
6818 expect_hdr
= expect_btf_data
;
6819 expect_strs
= expect_btf_data
+ sizeof(*test_hdr
) + expect_hdr
->str_off
;
6820 if (CHECK(test_hdr
->str_len
!= expect_hdr
->str_len
,
6821 "test_hdr->str_len:%u != expect_hdr->str_len:%u",
6822 test_hdr
->str_len
, expect_hdr
->str_len
)) {
6823 fprintf(stderr
, "\ntest strings:\n");
6824 dump_btf_strings(test_strs
, test_hdr
->str_len
);
6825 fprintf(stderr
, "\nexpected strings:\n");
6826 dump_btf_strings(expect_strs
, expect_hdr
->str_len
);
6831 test_str_cur
= test_strs
;
6832 test_str_end
= test_strs
+ test_hdr
->str_len
;
6833 expect_str_cur
= expect_strs
;
6834 expect_str_end
= expect_strs
+ expect_hdr
->str_len
;
6835 while (test_str_cur
< test_str_end
&& expect_str_cur
< expect_str_end
) {
6836 size_t test_len
, expect_len
;
6838 test_len
= strlen(test_str_cur
);
6839 expect_len
= strlen(expect_str_cur
);
6840 if (CHECK(test_len
!= expect_len
,
6841 "test_len:%zu != expect_len:%zu "
6842 "(test_str:%s, expect_str:%s)",
6843 test_len
, expect_len
, test_str_cur
, expect_str_cur
)) {
6847 if (CHECK(strcmp(test_str_cur
, expect_str_cur
),
6848 "test_str:%s != expect_str:%s",
6849 test_str_cur
, expect_str_cur
)) {
6853 test_str_cur
+= test_len
+ 1;
6854 expect_str_cur
+= expect_len
+ 1;
6856 if (CHECK(test_str_cur
!= test_str_end
,
6857 "test_str_cur:%p != test_str_end:%p",
6858 test_str_cur
, test_str_end
)) {
6863 test_nr_types
= btf__get_nr_types(test_btf
);
6864 expect_nr_types
= btf__get_nr_types(expect_btf
);
6865 if (CHECK(test_nr_types
!= expect_nr_types
,
6866 "test_nr_types:%u != expect_nr_types:%u",
6867 test_nr_types
, expect_nr_types
)) {
6872 for (i
= 1; i
<= test_nr_types
; i
++) {
6873 const struct btf_type
*test_type
, *expect_type
;
6874 int test_size
, expect_size
;
6876 test_type
= btf__type_by_id(test_btf
, i
);
6877 expect_type
= btf__type_by_id(expect_btf
, i
);
6878 test_size
= btf_type_size(test_type
);
6879 expect_size
= btf_type_size(expect_type
);
6881 if (CHECK(test_size
!= expect_size
,
6882 "type #%d: test_size:%d != expect_size:%u",
6883 i
, test_size
, expect_size
)) {
6887 if (CHECK(memcmp((void *)test_type
,
6888 (void *)expect_type
,
6890 "type #%d: contents differ", i
)) {
6898 fprintf(stderr
, "OK");
6899 if (!IS_ERR(test_btf
))
6900 btf__free(test_btf
);
6901 if (!IS_ERR(expect_btf
))
6902 btf__free(expect_btf
);
6907 static int test_dedup(void)
6912 if (args
.dedup_test_num
)
6913 return count_result(do_test_dedup(args
.dedup_test_num
));
6915 for (i
= 1; i
<= ARRAY_SIZE(dedup_tests
); i
++)
6916 err
|= count_result(do_test_dedup(i
));
6921 static void usage(const char *cmd
)
6923 fprintf(stderr
, "Usage: %s [-l] [[-r btf_raw_test_num (1 - %zu)] |\n"
6924 "\t[-g btf_get_info_test_num (1 - %zu)] |\n"
6925 "\t[-f btf_file_test_num (1 - %zu)] |\n"
6926 "\t[-k btf_prog_info_raw_test_num (1 - %zu)] |\n"
6927 "\t[-p (pretty print test)] |\n"
6928 "\t[-d btf_dedup_test_num (1 - %zu)]]\n",
6929 cmd
, ARRAY_SIZE(raw_tests
), ARRAY_SIZE(get_info_tests
),
6930 ARRAY_SIZE(file_tests
), ARRAY_SIZE(info_raw_tests
),
6931 ARRAY_SIZE(dedup_tests
));
6934 static int parse_args(int argc
, char **argv
)
6936 const char *optstr
= "hlpk:f:r:g:d:";
6939 while ((opt
= getopt(argc
, argv
, optstr
)) != -1) {
6942 args
.always_log
= true;
6945 args
.file_test_num
= atoi(optarg
);
6946 args
.file_test
= true;
6949 args
.raw_test_num
= atoi(optarg
);
6950 args
.raw_test
= true;
6953 args
.get_info_test_num
= atoi(optarg
);
6954 args
.get_info_test
= true;
6957 args
.pprint_test
= true;
6960 args
.info_raw_test_num
= atoi(optarg
);
6961 args
.info_raw_test
= true;
6964 args
.dedup_test_num
= atoi(optarg
);
6965 args
.dedup_test
= true;
6976 if (args
.raw_test_num
&&
6977 (args
.raw_test_num
< 1 ||
6978 args
.raw_test_num
> ARRAY_SIZE(raw_tests
))) {
6979 fprintf(stderr
, "BTF raw test number must be [1 - %zu]\n",
6980 ARRAY_SIZE(raw_tests
));
6984 if (args
.file_test_num
&&
6985 (args
.file_test_num
< 1 ||
6986 args
.file_test_num
> ARRAY_SIZE(file_tests
))) {
6987 fprintf(stderr
, "BTF file test number must be [1 - %zu]\n",
6988 ARRAY_SIZE(file_tests
));
6992 if (args
.get_info_test_num
&&
6993 (args
.get_info_test_num
< 1 ||
6994 args
.get_info_test_num
> ARRAY_SIZE(get_info_tests
))) {
6995 fprintf(stderr
, "BTF get info test number must be [1 - %zu]\n",
6996 ARRAY_SIZE(get_info_tests
));
7000 if (args
.info_raw_test_num
&&
7001 (args
.info_raw_test_num
< 1 ||
7002 args
.info_raw_test_num
> ARRAY_SIZE(info_raw_tests
))) {
7003 fprintf(stderr
, "BTF prog info raw test number must be [1 - %zu]\n",
7004 ARRAY_SIZE(info_raw_tests
));
7008 if (args
.dedup_test_num
&&
7009 (args
.dedup_test_num
< 1 ||
7010 args
.dedup_test_num
> ARRAY_SIZE(dedup_tests
))) {
7011 fprintf(stderr
, "BTF dedup test number must be [1 - %zu]\n",
7012 ARRAY_SIZE(dedup_tests
));
7019 static void print_summary(void)
7021 fprintf(stderr
, "PASS:%u SKIP:%u FAIL:%u\n",
7022 pass_cnt
- skip_cnt
, skip_cnt
, error_cnt
);
7025 int main(int argc
, char **argv
)
7029 err
= parse_args(argc
, argv
);
7033 if (args
.always_log
)
7034 libbpf_set_print(__base_pr
);
7039 if (args
.get_info_test
)
7040 err
|= test_get_info();
7045 if (args
.pprint_test
)
7046 err
|= test_pprint();
7048 if (args
.info_raw_test
)
7049 err
|= test_info_raw();
7051 if (args
.dedup_test
)
7052 err
|= test_dedup();
7054 if (args
.raw_test
|| args
.get_info_test
|| args
.file_test
||
7055 args
.pprint_test
|| args
.info_raw_test
|| args
.dedup_test
)
7059 err
|= test_get_info();
7061 err
|= test_info_raw();
7062 err
|= test_dedup();