@@ -3528,7 +3528,8 @@ struct pprint_mapv {
3528
3528
} aenum ;
3529
3529
};
3530
3530
3531
- static struct btf_raw_test pprint_test_template = {
3531
+ static struct btf_raw_test pprint_test_template [] = {
3532
+ {
3532
3533
.raw_types = {
3533
3534
/* unsighed char */ /* [1] */
3534
3535
BTF_TYPE_INT_ENC (NAME_TBD , 0 , 0 , 8 , 1 ),
@@ -3578,13 +3579,140 @@ static struct btf_raw_test pprint_test_template = {
3578
3579
BTF_MEMBER_ENC (NAME_TBD , 15 , 192 ), /* aenum */
3579
3580
BTF_END_RAW ,
3580
3581
},
3581
- .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" ,
3582
- .str_sec_size = sizeof ("\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" ),
3582
+ 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" ),
3583
+ .key_size = sizeof (unsigned int ),
3584
+ .value_size = sizeof (struct pprint_mapv ),
3585
+ .key_type_id = 3 , /* unsigned int */
3586
+ .value_type_id = 16 , /* struct pprint_mapv */
3587
+ .max_entries = 128 * 1024 ,
3588
+ },
3589
+
3590
+ {
3591
+ /* this type will have the same type as the
3592
+ * first .raw_types definition, but struct type will
3593
+ * be encoded with kind_flag set.
3594
+ */
3595
+ .raw_types = {
3596
+ /* unsighed char */ /* [1] */
3597
+ BTF_TYPE_INT_ENC (NAME_TBD , 0 , 0 , 8 , 1 ),
3598
+ /* unsigned short */ /* [2] */
3599
+ BTF_TYPE_INT_ENC (NAME_TBD , 0 , 0 , 16 , 2 ),
3600
+ /* unsigned int */ /* [3] */
3601
+ BTF_TYPE_INT_ENC (NAME_TBD , 0 , 0 , 32 , 4 ),
3602
+ /* int */ /* [4] */
3603
+ BTF_TYPE_INT_ENC (NAME_TBD , BTF_INT_SIGNED , 0 , 32 , 4 ),
3604
+ /* unsigned long long */ /* [5] */
3605
+ BTF_TYPE_INT_ENC (NAME_TBD , 0 , 0 , 64 , 8 ),
3606
+ BTF_TYPE_INT_ENC (0 , 0 , 0 , 32 , 4 ), /* [6] */
3607
+ BTF_TYPE_INT_ENC (0 , 0 , 0 , 32 , 4 ), /* [7] */
3608
+ /* uint8_t[8] */ /* [8] */
3609
+ BTF_TYPE_ARRAY_ENC (9 , 1 , 8 ),
3610
+ /* typedef unsigned char uint8_t */ /* [9] */
3611
+ BTF_TYPEDEF_ENC (NAME_TBD , 1 ),
3612
+ /* typedef unsigned short uint16_t */ /* [10] */
3613
+ BTF_TYPEDEF_ENC (NAME_TBD , 2 ),
3614
+ /* typedef unsigned int uint32_t */ /* [11] */
3615
+ BTF_TYPEDEF_ENC (NAME_TBD , 3 ),
3616
+ /* typedef int int32_t */ /* [12] */
3617
+ BTF_TYPEDEF_ENC (NAME_TBD , 4 ),
3618
+ /* typedef unsigned long long uint64_t */ /* [13] */
3619
+ BTF_TYPEDEF_ENC (NAME_TBD , 5 ),
3620
+ /* union (anon) */ /* [14] */
3621
+ BTF_TYPE_ENC (0 , BTF_INFO_ENC (BTF_KIND_UNION , 0 , 2 ), 8 ),
3622
+ BTF_MEMBER_ENC (NAME_TBD , 13 , 0 ),/* uint64_t ui64; */
3623
+ BTF_MEMBER_ENC (NAME_TBD , 8 , 0 ), /* uint8_t ui8a[8]; */
3624
+ /* enum (anon) */ /* [15] */
3625
+ BTF_TYPE_ENC (0 , BTF_INFO_ENC (BTF_KIND_ENUM , 0 , 4 ), 4 ),
3626
+ BTF_ENUM_ENC (NAME_TBD , 0 ),
3627
+ BTF_ENUM_ENC (NAME_TBD , 1 ),
3628
+ BTF_ENUM_ENC (NAME_TBD , 2 ),
3629
+ BTF_ENUM_ENC (NAME_TBD , 3 ),
3630
+ /* struct pprint_mapv */ /* [16] */
3631
+ BTF_TYPE_ENC (NAME_TBD , BTF_INFO_ENC (BTF_KIND_STRUCT , 1 , 8 ), 32 ),
3632
+ BTF_MEMBER_ENC (NAME_TBD , 11 , BTF_MEMBER_OFFSET (0 , 0 )), /* uint32_t ui32 */
3633
+ BTF_MEMBER_ENC (NAME_TBD , 10 , BTF_MEMBER_OFFSET (0 , 32 )), /* uint16_t ui16 */
3634
+ BTF_MEMBER_ENC (NAME_TBD , 12 , BTF_MEMBER_OFFSET (0 , 64 )), /* int32_t si32 */
3635
+ BTF_MEMBER_ENC (NAME_TBD , 6 , BTF_MEMBER_OFFSET (2 , 96 )), /* unused_bits2a */
3636
+ BTF_MEMBER_ENC (NAME_TBD , 7 , BTF_MEMBER_OFFSET (28 , 98 )), /* bits28 */
3637
+ BTF_MEMBER_ENC (NAME_TBD , 6 , BTF_MEMBER_OFFSET (2 , 126 )), /* unused_bits2b */
3638
+ BTF_MEMBER_ENC (0 , 14 , BTF_MEMBER_OFFSET (0 , 128 )), /* union (anon) */
3639
+ BTF_MEMBER_ENC (NAME_TBD , 15 , BTF_MEMBER_OFFSET (0 , 192 )), /* aenum */
3640
+ BTF_END_RAW ,
3641
+ },
3642
+ 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" ),
3583
3643
.key_size = sizeof (unsigned int ),
3584
3644
.value_size = sizeof (struct pprint_mapv ),
3585
3645
.key_type_id = 3 , /* unsigned int */
3586
3646
.value_type_id = 16 , /* struct pprint_mapv */
3587
3647
.max_entries = 128 * 1024 ,
3648
+ },
3649
+
3650
+ {
3651
+ /* this type will have the same layout as the
3652
+ * first .raw_types definition. The struct type will
3653
+ * be encoded with kind_flag set, bitfield members
3654
+ * are added typedef/const/volatile, and bitfield members
3655
+ * will have both int and enum types.
3656
+ */
3657
+ .raw_types = {
3658
+ /* unsighed char */ /* [1] */
3659
+ BTF_TYPE_INT_ENC (NAME_TBD , 0 , 0 , 8 , 1 ),
3660
+ /* unsigned short */ /* [2] */
3661
+ BTF_TYPE_INT_ENC (NAME_TBD , 0 , 0 , 16 , 2 ),
3662
+ /* unsigned int */ /* [3] */
3663
+ BTF_TYPE_INT_ENC (NAME_TBD , 0 , 0 , 32 , 4 ),
3664
+ /* int */ /* [4] */
3665
+ BTF_TYPE_INT_ENC (NAME_TBD , BTF_INT_SIGNED , 0 , 32 , 4 ),
3666
+ /* unsigned long long */ /* [5] */
3667
+ BTF_TYPE_INT_ENC (NAME_TBD , 0 , 0 , 64 , 8 ),
3668
+ BTF_TYPE_INT_ENC (0 , 0 , 0 , 32 , 4 ), /* [6] */
3669
+ BTF_TYPE_INT_ENC (0 , 0 , 0 , 32 , 4 ), /* [7] */
3670
+ /* uint8_t[8] */ /* [8] */
3671
+ BTF_TYPE_ARRAY_ENC (9 , 1 , 8 ),
3672
+ /* typedef unsigned char uint8_t */ /* [9] */
3673
+ BTF_TYPEDEF_ENC (NAME_TBD , 1 ),
3674
+ /* typedef unsigned short uint16_t */ /* [10] */
3675
+ BTF_TYPEDEF_ENC (NAME_TBD , 2 ),
3676
+ /* typedef unsigned int uint32_t */ /* [11] */
3677
+ BTF_TYPEDEF_ENC (NAME_TBD , 3 ),
3678
+ /* typedef int int32_t */ /* [12] */
3679
+ BTF_TYPEDEF_ENC (NAME_TBD , 4 ),
3680
+ /* typedef unsigned long long uint64_t */ /* [13] */
3681
+ BTF_TYPEDEF_ENC (NAME_TBD , 5 ),
3682
+ /* union (anon) */ /* [14] */
3683
+ BTF_TYPE_ENC (0 , BTF_INFO_ENC (BTF_KIND_UNION , 0 , 2 ), 8 ),
3684
+ BTF_MEMBER_ENC (NAME_TBD , 13 , 0 ),/* uint64_t ui64; */
3685
+ BTF_MEMBER_ENC (NAME_TBD , 8 , 0 ), /* uint8_t ui8a[8]; */
3686
+ /* enum (anon) */ /* [15] */
3687
+ BTF_TYPE_ENC (0 , BTF_INFO_ENC (BTF_KIND_ENUM , 0 , 4 ), 4 ),
3688
+ BTF_ENUM_ENC (NAME_TBD , 0 ),
3689
+ BTF_ENUM_ENC (NAME_TBD , 1 ),
3690
+ BTF_ENUM_ENC (NAME_TBD , 2 ),
3691
+ BTF_ENUM_ENC (NAME_TBD , 3 ),
3692
+ /* struct pprint_mapv */ /* [16] */
3693
+ BTF_TYPE_ENC (NAME_TBD , BTF_INFO_ENC (BTF_KIND_STRUCT , 1 , 8 ), 32 ),
3694
+ BTF_MEMBER_ENC (NAME_TBD , 11 , BTF_MEMBER_OFFSET (0 , 0 )), /* uint32_t ui32 */
3695
+ BTF_MEMBER_ENC (NAME_TBD , 10 , BTF_MEMBER_OFFSET (0 , 32 )), /* uint16_t ui16 */
3696
+ BTF_MEMBER_ENC (NAME_TBD , 12 , BTF_MEMBER_OFFSET (0 , 64 )), /* int32_t si32 */
3697
+ BTF_MEMBER_ENC (NAME_TBD , 17 , BTF_MEMBER_OFFSET (2 , 96 )), /* unused_bits2a */
3698
+ BTF_MEMBER_ENC (NAME_TBD , 7 , BTF_MEMBER_OFFSET (28 , 98 )), /* bits28 */
3699
+ BTF_MEMBER_ENC (NAME_TBD , 19 , BTF_MEMBER_OFFSET (2 , 126 )),/* unused_bits2b */
3700
+ BTF_MEMBER_ENC (0 , 14 , BTF_MEMBER_OFFSET (0 , 128 )), /* union (anon) */
3701
+ BTF_MEMBER_ENC (NAME_TBD , 15 , BTF_MEMBER_OFFSET (0 , 192 )), /* aenum */
3702
+ /* typedef unsigned int ___int */ /* [17] */
3703
+ BTF_TYPEDEF_ENC (NAME_TBD , 18 ),
3704
+ BTF_TYPE_ENC (0 , BTF_INFO_ENC (BTF_KIND_VOLATILE , 0 , 0 ), 6 ), /* [18] */
3705
+ BTF_TYPE_ENC (0 , BTF_INFO_ENC (BTF_KIND_CONST , 0 , 0 ), 15 ), /* [19] */
3706
+ BTF_END_RAW ,
3707
+ },
3708
+ 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\0___int" ),
3709
+ .key_size = sizeof (unsigned int ),
3710
+ .value_size = sizeof (struct pprint_mapv ),
3711
+ .key_type_id = 3 , /* unsigned int */
3712
+ .value_type_id = 16 , /* struct pprint_mapv */
3713
+ .max_entries = 128 * 1024 ,
3714
+ },
3715
+
3588
3716
};
3589
3717
3590
3718
static struct btf_pprint_test_meta {
@@ -3687,9 +3815,9 @@ static int check_line(const char *expected_line, int nexpected_line,
3687
3815
}
3688
3816
3689
3817
3690
- static int do_test_pprint (void )
3818
+ static int do_test_pprint (int test_num )
3691
3819
{
3692
- const struct btf_raw_test * test = & pprint_test_template ;
3820
+ const struct btf_raw_test * test = & pprint_test_template [ test_num ] ;
3693
3821
struct bpf_create_map_attr create_attr = {};
3694
3822
bool ordered_map , lossless_map , percpu_map ;
3695
3823
int err , ret , num_cpus , rounded_value_size ;
@@ -3705,7 +3833,7 @@ static int do_test_pprint(void)
3705
3833
uint8_t * raw_btf ;
3706
3834
ssize_t nread ;
3707
3835
3708
- fprintf (stderr , "%s......" , test -> descr );
3836
+ fprintf (stderr , "%s(#%d) ......" , test -> descr , test_num );
3709
3837
raw_btf = btf_raw_create (& hdr_tmpl , test -> raw_types ,
3710
3838
test -> str_sec , test -> str_sec_size ,
3711
3839
& raw_btf_size , NULL );
@@ -3898,15 +4026,27 @@ static int test_pprint(void)
3898
4026
unsigned int i ;
3899
4027
int err = 0 ;
3900
4028
4029
+ /* test various maps with the first test template */
3901
4030
for (i = 0 ; i < ARRAY_SIZE (pprint_tests_meta ); i ++ ) {
3902
- pprint_test_template .descr = pprint_tests_meta [i ].descr ;
3903
- pprint_test_template .map_type = pprint_tests_meta [i ].map_type ;
3904
- pprint_test_template .map_name = pprint_tests_meta [i ].map_name ;
3905
- pprint_test_template .ordered_map = pprint_tests_meta [i ].ordered_map ;
3906
- pprint_test_template .lossless_map = pprint_tests_meta [i ].lossless_map ;
3907
- pprint_test_template .percpu_map = pprint_tests_meta [i ].percpu_map ;
3908
-
3909
- err |= count_result (do_test_pprint ());
4031
+ pprint_test_template [0 ].descr = pprint_tests_meta [i ].descr ;
4032
+ pprint_test_template [0 ].map_type = pprint_tests_meta [i ].map_type ;
4033
+ pprint_test_template [0 ].map_name = pprint_tests_meta [i ].map_name ;
4034
+ pprint_test_template [0 ].ordered_map = pprint_tests_meta [i ].ordered_map ;
4035
+ pprint_test_template [0 ].lossless_map = pprint_tests_meta [i ].lossless_map ;
4036
+ pprint_test_template [0 ].percpu_map = pprint_tests_meta [i ].percpu_map ;
4037
+
4038
+ err |= count_result (do_test_pprint (0 ));
4039
+ }
4040
+
4041
+ /* test rest test templates with the first map */
4042
+ for (i = 1 ; i < ARRAY_SIZE (pprint_test_template ); i ++ ) {
4043
+ pprint_test_template [i ].descr = pprint_tests_meta [0 ].descr ;
4044
+ pprint_test_template [i ].map_type = pprint_tests_meta [0 ].map_type ;
4045
+ pprint_test_template [i ].map_name = pprint_tests_meta [0 ].map_name ;
4046
+ pprint_test_template [i ].ordered_map = pprint_tests_meta [0 ].ordered_map ;
4047
+ pprint_test_template [i ].lossless_map = pprint_tests_meta [0 ].lossless_map ;
4048
+ pprint_test_template [i ].percpu_map = pprint_tests_meta [0 ].percpu_map ;
4049
+ err |= count_result (do_test_pprint (i ));
3910
4050
}
3911
4051
3912
4052
return err ;
0 commit comments