@@ -60,13 +60,19 @@ static void test_set_global_vars_succeeds(void)
6060 " -G \"var_s8 = -128\" " \
6161 " -G \"var_u8 = 255\" " \
6262 " -G \"var_ea = EA2\" " \
63- " -G \"var_eb = EB2\" " \
64- " -G \"var_ec = EC2\" " \
63+ " -G \"var_eb = EB2\" " \
64+ " -G \"var_ec= EC2\" " \
6565 " -G \"var_b = 1\" " \
66- " -G \"struct1.struct2.u.var_u8 = 170\" " \
66+ " -G \"struct1[2] .struct2[1][2] .u.var_u8[2]= 170\" " \
6767 " -G \"union1.struct3.var_u8_l = 0xaa\" " \
6868 " -G \"union1.struct3.var_u8_h = 0xaa\" " \
69- "-vl2 > %s" , fix -> veristat , fix -> tmpfile );
69+ " -G \"arr[3]= 171\" " \
70+ " -G \"arr[EA2] =172\" " \
71+ " -G \"enum_arr[EC2]=EA3\" " \
72+ " -G \"three_d[31][7][EA2]=173\"" \
73+ " -G \"struct1[2].struct2[1][2].u.mat[5][3]=174\" " \
74+ " -G \"struct11 [ 7 ] [ 5 ] .struct2[0][1].u.mat[3][0] = 175\" " \
75+ " -vl2 > %s" , fix -> veristat , fix -> tmpfile );
7076
7177 read (fix -> fd , fix -> output , fix -> sz );
7278 __CHECK_STR ("_w=0xf000000000000001 " , "var_s64 = 0xf000000000000001" );
@@ -81,8 +87,14 @@ static void test_set_global_vars_succeeds(void)
8187 __CHECK_STR ("_w=12 " , "var_eb = EB2" );
8288 __CHECK_STR ("_w=13 " , "var_ec = EC2" );
8389 __CHECK_STR ("_w=1 " , "var_b = 1" );
84- __CHECK_STR ("_w=170 " , "struct1.struct2.u.var_u8 = 170" );
90+ __CHECK_STR ("_w=170 " , "struct1[2] .struct2[1][2] .u.var_u8[2]= 170" );
8591 __CHECK_STR ("_w=0xaaaa " , "union1.var_u16 = 0xaaaa" );
92+ __CHECK_STR ("_w=171 " , "arr[3]= 171" );
93+ __CHECK_STR ("_w=172 " , "arr[EA2] =172" );
94+ __CHECK_STR ("_w=10 " , "enum_arr[EC2]=EA3" );
95+ __CHECK_STR ("_w=173 " , "matrix[31][7][11]=173" );
96+ __CHECK_STR ("_w=174 " , "struct1[2].struct2[1][2].u.mat[5][3]=174" );
97+ __CHECK_STR ("_w=175 " , "struct11[7][5].struct2[0][1].u.mat[3][0]=175" );
8698
8799out :
88100 teardown_fixture (fix );
@@ -129,6 +141,95 @@ static void test_set_global_vars_out_of_range(void)
129141 teardown_fixture (fix );
130142}
131143
144+ static void test_unsupported_ptr_array_type (void )
145+ {
146+ struct fixture * fix = init_fixture ();
147+
148+ SYS_FAIL (out ,
149+ "%s set_global_vars.bpf.o -G \"ptr_arr[0] = 0\" -vl2 2> %s" ,
150+ fix -> veristat , fix -> tmpfile );
151+
152+ read (fix -> fd , fix -> output , fix -> sz );
153+ __CHECK_STR ("Can't set ptr_arr[0]. Only ints and enums are supported" , "ptr_arr" );
154+
155+ out :
156+ teardown_fixture (fix );
157+ }
158+
159+ static void test_array_out_of_bounds (void )
160+ {
161+ struct fixture * fix = init_fixture ();
162+
163+ SYS_FAIL (out ,
164+ "%s set_global_vars.bpf.o -G \"arr[99] = 0\" -vl2 2> %s" ,
165+ fix -> veristat , fix -> tmpfile );
166+
167+ read (fix -> fd , fix -> output , fix -> sz );
168+ __CHECK_STR ("Array index 99 is out of bounds" , "arr[99]" );
169+
170+ out :
171+ teardown_fixture (fix );
172+ }
173+
174+ static void test_array_index_not_found (void )
175+ {
176+ struct fixture * fix = init_fixture ();
177+
178+ SYS_FAIL (out ,
179+ "%s set_global_vars.bpf.o -G \"arr[EG2] = 0\" -vl2 2> %s" ,
180+ fix -> veristat , fix -> tmpfile );
181+
182+ read (fix -> fd , fix -> output , fix -> sz );
183+ __CHECK_STR ("Can't resolve enum value EG2" , "arr[EG2]" );
184+
185+ out :
186+ teardown_fixture (fix );
187+ }
188+
189+ static void test_array_index_for_non_array (void )
190+ {
191+ struct fixture * fix = init_fixture ();
192+
193+ SYS_FAIL (out ,
194+ "%s set_global_vars.bpf.o -G \"var_b[0] = 1\" -vl2 2> %s" ,
195+ fix -> veristat , fix -> tmpfile );
196+
197+ pread (fix -> fd , fix -> output , fix -> sz , 0 );
198+ __CHECK_STR ("Array index is not expected for var_b" , "var_b[0] = 1" );
199+
200+ SYS_FAIL (out ,
201+ "%s set_global_vars.bpf.o -G \"union1.struct3[0].var_u8_l=1\" -vl2 2> %s" ,
202+ fix -> veristat , fix -> tmpfile );
203+
204+ pread (fix -> fd , fix -> output , fix -> sz , 0 );
205+ __CHECK_STR ("Array index is not expected for struct3" , "union1.struct3[0].var_u8_l=1" );
206+
207+ out :
208+ teardown_fixture (fix );
209+ }
210+
211+ static void test_no_array_index_for_array (void )
212+ {
213+ struct fixture * fix = init_fixture ();
214+
215+ SYS_FAIL (out ,
216+ "%s set_global_vars.bpf.o -G \"arr = 1\" -vl2 2> %s" ,
217+ fix -> veristat , fix -> tmpfile );
218+
219+ pread (fix -> fd , fix -> output , fix -> sz , 0 );
220+ __CHECK_STR ("Can't set arr. Only ints and enums are supported" , "arr = 1" );
221+
222+ SYS_FAIL (out ,
223+ "%s set_global_vars.bpf.o -G \"struct1[0].struct2.u.var_u8[2]=1\" -vl2 2> %s" ,
224+ fix -> veristat , fix -> tmpfile );
225+
226+ pread (fix -> fd , fix -> output , fix -> sz , 0 );
227+ __CHECK_STR ("Can't resolve field u for non-composite type" , "struct1[0].struct2.u.var_u8[2]=1" );
228+
229+ out :
230+ teardown_fixture (fix );
231+ }
232+
132233void test_veristat (void )
133234{
134235 if (test__start_subtest ("set_global_vars_succeeds" ))
@@ -139,6 +240,22 @@ void test_veristat(void)
139240
140241 if (test__start_subtest ("set_global_vars_from_file_succeeds" ))
141242 test_set_global_vars_from_file_succeeds ();
243+
244+ if (test__start_subtest ("test_unsupported_ptr_array_type" ))
245+ test_unsupported_ptr_array_type ();
246+
247+ if (test__start_subtest ("test_array_out_of_bounds" ))
248+ test_array_out_of_bounds ();
249+
250+ if (test__start_subtest ("test_array_index_not_found" ))
251+ test_array_index_not_found ();
252+
253+ if (test__start_subtest ("test_array_index_for_non_array" ))
254+ test_array_index_for_non_array ();
255+
256+ if (test__start_subtest ("test_no_array_index_for_array" ))
257+ test_no_array_index_for_array ();
258+
142259}
143260
144261#undef __CHECK_STR
0 commit comments