1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */ 3 4 #include <test_progs.h> 5 #include "tracing_struct.skel.h" 6 #include "tracing_struct_many_args.skel.h" 7 8 static void test_struct_args(void) 9 { 10 struct tracing_struct *skel; 11 int err; 12 13 skel = tracing_struct__open_and_load(); 14 if (!ASSERT_OK_PTR(skel, "tracing_struct__open_and_load")) 15 return; 16 17 err = tracing_struct__attach(skel); 18 if (!ASSERT_OK(err, "tracing_struct__attach")) 19 goto destroy_skel; 20 21 ASSERT_OK(trigger_module_test_read(256), "trigger_read"); 22 23 ASSERT_EQ(skel->bss->t1_a_a, 2, "t1:a.a"); 24 ASSERT_EQ(skel->bss->t1_a_b, 3, "t1:a.b"); 25 ASSERT_EQ(skel->bss->t1_b, 1, "t1:b"); 26 ASSERT_EQ(skel->bss->t1_c, 4, "t1:c"); 27 28 ASSERT_EQ(skel->bss->t1_nregs, 4, "t1 nregs"); 29 ASSERT_EQ(skel->bss->t1_reg0, 2, "t1 reg0"); 30 ASSERT_EQ(skel->bss->t1_reg1, 3, "t1 reg1"); 31 ASSERT_EQ(skel->bss->t1_reg2, 1, "t1 reg2"); 32 ASSERT_EQ(skel->bss->t1_reg3, 4, "t1 reg3"); 33 ASSERT_EQ(skel->bss->t1_ret, 10, "t1 ret"); 34 35 ASSERT_EQ(skel->bss->t2_a, 1, "t2:a"); 36 ASSERT_EQ(skel->bss->t2_b_a, 2, "t2:b.a"); 37 ASSERT_EQ(skel->bss->t2_b_b, 3, "t2:b.b"); 38 ASSERT_EQ(skel->bss->t2_c, 4, "t2:c"); 39 ASSERT_EQ(skel->bss->t2_ret, 10, "t2 ret"); 40 41 ASSERT_EQ(skel->bss->t3_a, 1, "t3:a"); 42 ASSERT_EQ(skel->bss->t3_b, 4, "t3:b"); 43 ASSERT_EQ(skel->bss->t3_c_a, 2, "t3:c.a"); 44 ASSERT_EQ(skel->bss->t3_c_b, 3, "t3:c.b"); 45 ASSERT_EQ(skel->bss->t3_ret, 10, "t3 ret"); 46 47 ASSERT_EQ(skel->bss->t4_a_a, 10, "t4:a.a"); 48 ASSERT_EQ(skel->bss->t4_b, 1, "t4:b"); 49 ASSERT_EQ(skel->bss->t4_c, 2, "t4:c"); 50 ASSERT_EQ(skel->bss->t4_d, 3, "t4:d"); 51 ASSERT_EQ(skel->bss->t4_e_a, 2, "t4:e.a"); 52 ASSERT_EQ(skel->bss->t4_e_b, 3, "t4:e.b"); 53 ASSERT_EQ(skel->bss->t4_ret, 21, "t4 ret"); 54 55 ASSERT_EQ(skel->bss->t5_ret, 1, "t5 ret"); 56 57 ASSERT_EQ(skel->bss->t6, 1, "t6 ret"); 58 59 destroy_skel: 60 tracing_struct__destroy(skel); 61 } 62 63 static void test_struct_many_args(void) 64 { 65 struct tracing_struct_many_args *skel; 66 int err; 67 68 skel = tracing_struct_many_args__open_and_load(); 69 if (!ASSERT_OK_PTR(skel, "tracing_struct_many_args__open_and_load")) 70 return; 71 72 err = tracing_struct_many_args__attach(skel); 73 if (!ASSERT_OK(err, "tracing_struct_many_args__attach")) 74 goto destroy_skel; 75 76 ASSERT_OK(trigger_module_test_read(256), "trigger_read"); 77 78 ASSERT_EQ(skel->bss->t7_a, 16, "t7:a"); 79 ASSERT_EQ(skel->bss->t7_b, 17, "t7:b"); 80 ASSERT_EQ(skel->bss->t7_c, 18, "t7:c"); 81 ASSERT_EQ(skel->bss->t7_d, 19, "t7:d"); 82 ASSERT_EQ(skel->bss->t7_e, 20, "t7:e"); 83 ASSERT_EQ(skel->bss->t7_f_a, 21, "t7:f.a"); 84 ASSERT_EQ(skel->bss->t7_f_b, 22, "t7:f.b"); 85 ASSERT_EQ(skel->bss->t7_ret, 133, "t7 ret"); 86 87 ASSERT_EQ(skel->bss->t8_a, 16, "t8:a"); 88 ASSERT_EQ(skel->bss->t8_b, 17, "t8:b"); 89 ASSERT_EQ(skel->bss->t8_c, 18, "t8:c"); 90 ASSERT_EQ(skel->bss->t8_d, 19, "t8:d"); 91 ASSERT_EQ(skel->bss->t8_e, 20, "t8:e"); 92 ASSERT_EQ(skel->bss->t8_f_a, 21, "t8:f.a"); 93 ASSERT_EQ(skel->bss->t8_f_b, 22, "t8:f.b"); 94 ASSERT_EQ(skel->bss->t8_g, 23, "t8:g"); 95 ASSERT_EQ(skel->bss->t8_ret, 156, "t8 ret"); 96 97 ASSERT_EQ(skel->bss->t9_a, 16, "t9:a"); 98 ASSERT_EQ(skel->bss->t9_b, 17, "t9:b"); 99 ASSERT_EQ(skel->bss->t9_c, 18, "t9:c"); 100 ASSERT_EQ(skel->bss->t9_d, 19, "t9:d"); 101 ASSERT_EQ(skel->bss->t9_e, 20, "t9:e"); 102 ASSERT_EQ(skel->bss->t9_f, 21, "t9:f"); 103 ASSERT_EQ(skel->bss->t9_g, 22, "t9:f"); 104 ASSERT_EQ(skel->bss->t9_h_a, 23, "t9:h.a"); 105 ASSERT_EQ(skel->bss->t9_h_b, 24, "t9:h.b"); 106 ASSERT_EQ(skel->bss->t9_h_c, 25, "t9:h.c"); 107 ASSERT_EQ(skel->bss->t9_h_d, 26, "t9:h.d"); 108 ASSERT_EQ(skel->bss->t9_i, 27, "t9:i"); 109 ASSERT_EQ(skel->bss->t9_ret, 258, "t9 ret"); 110 111 destroy_skel: 112 tracing_struct_many_args__destroy(skel); 113 } 114 115 void test_tracing_struct(void) 116 { 117 if (test__start_subtest("struct_args")) 118 test_struct_args(); 119 if (test__start_subtest("struct_many_args")) 120 test_struct_many_args(); 121 } 122