@@ -49,6 +49,7 @@ struct pre_build_s
49
49
{
50
50
FAR char * gpio_a ;
51
51
FAR char * gpio_b ;
52
+ bool loop ;
52
53
};
53
54
54
55
/****************************************************************************
@@ -62,10 +63,11 @@ struct pre_build_s
62
63
static void show_usage (FAR const char * progname , int exitcode )
63
64
{
64
65
printf ("Usage: %s -a <gpio_a>[dev/gpio0] -b"
65
- " <gpio_b>[dev/gpio1] \n" , progname );
66
+ " <gpio_b>[dev/gpio1] -l [loop test] \n" , progname );
66
67
printf ("Where:\n" );
67
68
printf (" -a <gpio_a> gpio_a location [default location: dev/gpio0].\n" );
68
69
printf (" -b <gpio_b> gpio_b location [default location: dev/gpio1].\n" );
70
+ printf (" -l <loop test> [default: Test the input and output of GPIO ]\n" );
69
71
exit (exitcode );
70
72
}
71
73
@@ -78,7 +80,7 @@ static void parse_commandline(int argc, FAR char **argv,
78
80
{
79
81
int option ;
80
82
81
- while ((option = getopt (argc , argv , "a:b:" )) != ERROR )
83
+ while ((option = getopt (argc , argv , "a:b:l " )) != ERROR )
82
84
{
83
85
switch (option )
84
86
{
@@ -88,6 +90,9 @@ static void parse_commandline(int argc, FAR char **argv,
88
90
case 'b' :
89
91
pre_build -> gpio_b = optarg ;
90
92
break ;
93
+ case 'l' :
94
+ pre_build -> loop = true;
95
+ break ;
91
96
case '?' :
92
97
printf ("Unknown option: %c\n" , optopt );
93
98
show_usage (argv [0 ], EXIT_FAILURE );
@@ -133,10 +138,55 @@ static int setup(FAR void **state)
133
138
}
134
139
135
140
/****************************************************************************
136
- * Name: gpiotest01
141
+ * Name: drivertest_gpio_one
142
+ ****************************************************************************/
143
+
144
+ static void drivertest_gpio_one (FAR void * * state )
145
+ {
146
+ FAR struct pre_build_s * pre_build ;
147
+ bool outvalue ;
148
+ bool invalue ;
149
+ int fd [2 ];
150
+ int ret ;
151
+ int i ;
152
+ int j ;
153
+
154
+ pre_build = (FAR struct pre_build_s * )* state ;
155
+ fd [0 ] = open (pre_build -> gpio_a , O_RDWR );
156
+ assert_false (fd [0 ] < 0 );
157
+
158
+ fd [1 ] = open (pre_build -> gpio_b , O_RDWR );
159
+ assert_false (fd [1 ] < 0 );
160
+
161
+ /* Test Single GPIO I/O functionality */
162
+
163
+ for (i = 0 ; i < 2 ; i ++ )
164
+ {
165
+ ret = ioctl (fd [i ], GPIOC_SETPINTYPE , GPIO_INPUT_PIN | GPIO_OUTPUT_PIN );
166
+ assert_false (ret < 0 );
167
+ for (j = 0 ; j < GPIOTEST_MAXVALUE ; j ++ )
168
+ {
169
+ outvalue = gpiotest_randbin ();
170
+ ret = ioctl (fd [i ], GPIOC_WRITE , outvalue );
171
+ assert_false (ret < 0 );
172
+
173
+ ret = ioctl (fd [i ], GPIOC_READ , & invalue );
174
+ assert_false (ret < 0 );
175
+
176
+ printf ("[input and output test] outvalue is %d, invalue is %d\n" ,
177
+ outvalue , invalue );
178
+ assert_int_equal (invalue , outvalue );
179
+ }
180
+
181
+ close (fd [i ]);
182
+ }
183
+ }
184
+
185
+ /****************************************************************************
186
+ * Name: drivertest_gpio_loop
137
187
****************************************************************************/
138
188
139
- static void gpiotest01 (FAR void * * state )
189
+ static void drivertest_gpio_loop (FAR void * * state )
140
190
{
141
191
FAR struct pre_build_s * pre_build ;
142
192
int fd_a ;
@@ -179,7 +229,7 @@ static void gpiotest01(FAR void **state)
179
229
ret = ioctl (fd_b , GPIOC_READ , (unsigned long )((uintptr_t )& invalue ));
180
230
assert_false (ret < 0 );
181
231
182
- printf ("[__Verify__ ] outvalue is %d, invalue is %d\n" ,
232
+ printf ("[Loop test ] outvalue is %d, invalue is %d\n" ,
183
233
outvalue , invalue );
184
234
assert_int_equal (invalue , outvalue );
185
235
}
@@ -205,7 +255,7 @@ static void gpiotest01(FAR void **state)
205
255
ret = ioctl (fd_a , GPIOC_READ , (unsigned long )((uintptr_t )& invalue ));
206
256
assert_false (ret < 0 );
207
257
208
- printf ("[__Verify__ ] outvalue is %d, invalue is %d\n" ,
258
+ printf ("[Loop test ] outvalue is %d, invalue is %d\n" ,
209
259
outvalue , invalue );
210
260
assert_int_equal (invalue , outvalue );
211
261
}
@@ -233,16 +283,28 @@ static int teardown(FAR void **state)
233
283
234
284
int main (int argc , FAR char * argv [])
235
285
{
286
+ void (* drivertest_gpio )(FAR void * * state );
236
287
FAR struct pre_build_s pre_build =
237
288
{
238
289
.gpio_a = "dev/gpio0" ,
239
- .gpio_b = "dev/gpio1"
290
+ .gpio_b = "dev/gpio1" ,
291
+ .loop = false
240
292
};
241
293
242
294
parse_commandline (argc , argv , & pre_build );
295
+
296
+ if (pre_build .loop )
297
+ {
298
+ drivertest_gpio = drivertest_gpio_loop ;
299
+ }
300
+ else
301
+ {
302
+ drivertest_gpio = drivertest_gpio_one ;
303
+ }
304
+
243
305
const struct CMUnitTest tests [] =
244
306
{
245
- cmocka_unit_test_prestate_setup_teardown (gpiotest01 , setup ,
307
+ cmocka_unit_test_prestate_setup_teardown (drivertest_gpio , setup ,
246
308
teardown , & pre_build ),
247
309
};
248
310
0 commit comments