9c594ff07a49aeb8a89ed2cc8ab424dbaed10b4d
[platform/core/api/peripheral-io.git] / test / src / test_peripheral_gpio.c
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <string.h>
19 #include <peripheral_io.h>
20 #include "test_peripheral_gpio.h"
21
22 #define GPIO_PIN_RPI3 26
23 #define GPIO_PIN_ARTIK530 128
24 #define GPIO_PIN_INVALID -99
25
26 static bool g_feature = false;
27 static int pin;
28
29 int test_peripheral_io_gpio_initialize(char *model, bool feature)
30 {
31         g_feature = feature;
32
33         if (!strcmp(model, "rpi3"))
34                 pin = GPIO_PIN_RPI3;
35         else if (!strcmp(model, "artik"))
36                 pin = GPIO_PIN_ARTIK530;
37         else
38                 return -1;
39         return 0;
40 }
41
42 int test_peripheral_io_gpio_peripheral_gpio_open_p(void)
43 {
44         int ret = PERIPHERAL_ERROR_NONE;
45
46         peripheral_gpio_h gpio_h = NULL;
47
48         if (g_feature == false) {
49                 ret = peripheral_gpio_open(pin, &gpio_h);
50                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
51
52         } else {
53                 ret = peripheral_gpio_open(pin, &gpio_h);
54                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
55
56                 ret = peripheral_gpio_close(gpio_h);
57                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
58         }
59
60         return PERIPHERAL_ERROR_NONE;
61 }
62
63 int test_peripheral_io_gpio_peripheral_gpio_open_n1(void)
64 {
65         int ret = PERIPHERAL_ERROR_NONE;
66
67         if (g_feature == false) {
68                 ret = peripheral_gpio_open(pin, NULL);
69                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
70
71         } else {
72                 ret = peripheral_gpio_open(pin, NULL);
73                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
74         }
75
76         return PERIPHERAL_ERROR_NONE;
77 }
78
79 int test_peripheral_io_gpio_peripheral_gpio_open_n2(void)
80 {
81         int ret = PERIPHERAL_ERROR_NONE;
82
83         peripheral_gpio_h gpio_h = NULL;
84
85         if (g_feature == false) {
86                 ret = peripheral_gpio_open(GPIO_PIN_INVALID, &gpio_h);
87                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
88
89         } else {
90                 ret = peripheral_gpio_open(GPIO_PIN_INVALID, &gpio_h);
91                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
92         }
93
94         return PERIPHERAL_ERROR_NONE;
95 }
96
97 int test_peripheral_io_gpio_peripheral_gpio_close_p(void)
98 {
99         int ret = PERIPHERAL_ERROR_NONE;
100
101         peripheral_gpio_h gpio_h = NULL;
102
103         if (g_feature == false) {
104                 ret = peripheral_gpio_close(gpio_h);
105                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
106
107         } else {
108                 ret = peripheral_gpio_open(pin, &gpio_h);
109                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
110
111                 ret = peripheral_gpio_close(gpio_h);
112                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
113         }
114
115         return PERIPHERAL_ERROR_NONE;
116 }
117
118 int test_peripheral_io_gpio_peripheral_gpio_close_n(void)
119 {
120         int ret = PERIPHERAL_ERROR_NONE;
121
122         if (g_feature == false) {
123                 ret = peripheral_gpio_close(NULL);
124                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
125
126         } else {
127                 ret = peripheral_gpio_close(NULL);
128                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
129         }
130
131         return PERIPHERAL_ERROR_NONE;
132 }
133
134 int test_peripheral_io_gpio_peripheral_gpio_set_direction_p1(void)
135 {
136         int ret = PERIPHERAL_ERROR_NONE;
137
138         peripheral_gpio_h gpio_h = NULL;
139
140         if (g_feature == false) {
141                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
142                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
143
144         } else {
145                 ret = peripheral_gpio_open(pin, &gpio_h);
146                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
147
148                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
149                 if (ret != PERIPHERAL_ERROR_NONE) {
150                         peripheral_gpio_close(gpio_h);
151                         return PERIPHERAL_ERROR_UNKNOWN;
152                 }
153
154                 ret = peripheral_gpio_close(gpio_h);
155                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
156         }
157
158         return PERIPHERAL_ERROR_NONE;
159 }
160
161 int test_peripheral_io_gpio_peripheral_gpio_set_direction_p2(void)
162 {
163         int ret = PERIPHERAL_ERROR_NONE;
164
165         peripheral_gpio_h gpio_h = NULL;
166
167         if (g_feature == false) {
168                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH);
169                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
170
171         } else {
172                 ret = peripheral_gpio_open(pin, &gpio_h);
173                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
174
175                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH);
176                 if (ret != PERIPHERAL_ERROR_NONE) {
177                         peripheral_gpio_close(gpio_h);
178                         return PERIPHERAL_ERROR_UNKNOWN;
179                 }
180
181                 ret = peripheral_gpio_close(gpio_h);
182                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
183         }
184
185         return PERIPHERAL_ERROR_NONE;
186 }
187
188 int test_peripheral_io_gpio_peripheral_gpio_set_direction_p3(void)
189 {
190         int ret = PERIPHERAL_ERROR_NONE;
191
192         peripheral_gpio_h gpio_h = NULL;
193
194         if (g_feature == false) {
195                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
196                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
197
198         } else {
199                 ret = peripheral_gpio_open(pin, &gpio_h);
200                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
201
202                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
203                 if (ret != PERIPHERAL_ERROR_NONE) {
204                         peripheral_gpio_close(gpio_h);
205                         return PERIPHERAL_ERROR_UNKNOWN;
206                 }
207
208                 ret = peripheral_gpio_close(gpio_h);
209                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
210         }
211
212         return PERIPHERAL_ERROR_NONE;
213 }
214
215 int test_peripheral_io_gpio_peripheral_gpio_set_direction_n1(void)
216 {
217         int ret = PERIPHERAL_ERROR_NONE;
218
219         if (g_feature == false) {
220                 ret = peripheral_gpio_set_direction(NULL, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH);
221                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
222
223         } else {
224                 ret = peripheral_gpio_set_direction(NULL, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH);
225                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
226         }
227
228         return PERIPHERAL_ERROR_NONE;
229 }
230
231 int test_peripheral_io_gpio_peripheral_gpio_set_direction_n2(void)
232 {
233         int ret = PERIPHERAL_ERROR_NONE;
234
235         peripheral_gpio_h gpio_h = NULL;
236
237         if (g_feature == false) {
238                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN - 1);
239                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
240
241         } else {
242                 ret = peripheral_gpio_open(pin, &gpio_h);
243                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
244
245                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN - 1);
246                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
247                         peripheral_gpio_close(gpio_h);
248                         return PERIPHERAL_ERROR_UNKNOWN;
249                 }
250
251                 ret = peripheral_gpio_close(gpio_h);
252                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
253         }
254
255         return PERIPHERAL_ERROR_NONE;
256 }
257
258 int test_peripheral_io_gpio_peripheral_gpio_set_direction_n3(void)
259 {
260         int ret = PERIPHERAL_ERROR_NONE;
261
262         peripheral_gpio_h gpio_h = NULL;
263
264         if (g_feature == false) {
265                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW + 1);
266                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
267
268         } else {
269                 ret = peripheral_gpio_open(pin, &gpio_h);
270                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
271
272                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW + 1);
273                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
274                         peripheral_gpio_close(gpio_h);
275                         return PERIPHERAL_ERROR_UNKNOWN;
276                 }
277
278                 ret = peripheral_gpio_close(gpio_h);
279                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
280         }
281
282         return PERIPHERAL_ERROR_NONE;
283 }
284
285 int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p1(void)
286 {
287         int ret = PERIPHERAL_ERROR_NONE;
288
289         peripheral_gpio_h gpio_h = NULL;
290
291         if (g_feature == false) {
292                 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_NONE);
293                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
294
295         } else {
296                 ret = peripheral_gpio_open(pin, &gpio_h);
297                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
298
299                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
300                 if (ret != PERIPHERAL_ERROR_NONE) {
301                         peripheral_gpio_close(gpio_h);
302                         return PERIPHERAL_ERROR_UNKNOWN;
303                 }
304
305                 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_NONE);
306                 if (ret != PERIPHERAL_ERROR_NONE) {
307                         peripheral_gpio_close(gpio_h);
308                         return PERIPHERAL_ERROR_UNKNOWN;
309                 }
310
311                 ret = peripheral_gpio_close(gpio_h);
312                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
313         }
314
315         return PERIPHERAL_ERROR_NONE;
316 }
317
318 int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p2(void)
319 {
320         int ret = PERIPHERAL_ERROR_NONE;
321
322         peripheral_gpio_h gpio_h = NULL;
323
324         if (g_feature == false) {
325                 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_RISING);
326                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
327
328         } else {
329                 ret = peripheral_gpio_open(pin, &gpio_h);
330                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
331
332                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
333                 if (ret != PERIPHERAL_ERROR_NONE) {
334                         peripheral_gpio_close(gpio_h);
335                         return PERIPHERAL_ERROR_UNKNOWN;
336                 }
337
338                 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_RISING);
339                 if (ret != PERIPHERAL_ERROR_NONE && ret != PERIPHERAL_ERROR_TRY_AGAIN) {
340                         peripheral_gpio_close(gpio_h);
341                         return PERIPHERAL_ERROR_UNKNOWN;
342                 }
343
344                 ret = peripheral_gpio_close(gpio_h);
345                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
346         }
347
348         return PERIPHERAL_ERROR_NONE;
349 }
350
351 int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p3(void)
352 {
353         int ret = PERIPHERAL_ERROR_NONE;
354
355         peripheral_gpio_h gpio_h = NULL;
356
357         if (g_feature == false) {
358                 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_FALLING);
359                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
360
361         } else {
362                 ret = peripheral_gpio_open(pin, &gpio_h);
363                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
364
365                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
366                 if (ret != PERIPHERAL_ERROR_NONE) {
367                         peripheral_gpio_close(gpio_h);
368                         return PERIPHERAL_ERROR_UNKNOWN;
369                 }
370
371                 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_FALLING);
372                 if (ret != PERIPHERAL_ERROR_NONE) {
373                         peripheral_gpio_close(gpio_h);
374                         return PERIPHERAL_ERROR_UNKNOWN;
375                 }
376
377                 ret = peripheral_gpio_close(gpio_h);
378                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
379         }
380
381         return PERIPHERAL_ERROR_NONE;
382 }
383
384 int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p4(void)
385 {
386         int ret = PERIPHERAL_ERROR_NONE;
387
388         peripheral_gpio_h gpio_h = NULL;
389
390         if (g_feature == false) {
391                 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_BOTH);
392                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
393
394         } else {
395                 ret = peripheral_gpio_open(pin, &gpio_h);
396                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
397
398                 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_BOTH);
399                 if (ret != PERIPHERAL_ERROR_NONE) {
400                         peripheral_gpio_close(gpio_h);
401                         return PERIPHERAL_ERROR_UNKNOWN;
402                 }
403
404                 ret = peripheral_gpio_close(gpio_h);
405                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
406         }
407
408         return PERIPHERAL_ERROR_NONE;
409 }
410
411 int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n1(void)
412 {
413         int ret = PERIPHERAL_ERROR_NONE;
414
415         if (g_feature == false) {
416                 ret = peripheral_gpio_set_edge_mode(NULL, PERIPHERAL_GPIO_EDGE_RISING);
417                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
418
419         } else {
420                 ret = peripheral_gpio_set_edge_mode(NULL, PERIPHERAL_GPIO_EDGE_RISING);
421                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
422         }
423
424         return PERIPHERAL_ERROR_NONE;
425 }
426
427 int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n2(void)
428 {
429         int ret = PERIPHERAL_ERROR_NONE;
430
431         peripheral_gpio_h gpio_h = NULL;
432
433         if (g_feature == false) {
434                 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_NONE - 1);
435                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
436
437         } else {
438                 ret = peripheral_gpio_open(pin, &gpio_h);
439                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
440
441                 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_NONE - 1);
442                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
443                         peripheral_gpio_close(gpio_h);
444                         return PERIPHERAL_ERROR_UNKNOWN;
445                 }
446
447                 ret = peripheral_gpio_close(gpio_h);
448                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
449         }
450
451         return PERIPHERAL_ERROR_NONE;
452 }
453
454 int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n3(void)
455 {
456         int ret = PERIPHERAL_ERROR_NONE;
457
458         peripheral_gpio_h gpio_h = NULL;
459
460         if (g_feature == false) {
461                 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_BOTH + 1);
462                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
463
464         } else {
465                 ret = peripheral_gpio_open(pin, &gpio_h);
466                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
467
468                 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_BOTH + 1);
469                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
470                         peripheral_gpio_close(gpio_h);
471                         return PERIPHERAL_ERROR_UNKNOWN;
472                 }
473
474                 ret = peripheral_gpio_close(gpio_h);
475                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
476         }
477
478         return PERIPHERAL_ERROR_NONE;
479 }
480
481 static void gpio_interrupted_cb(peripheral_gpio_h gpio_h, peripheral_error_e error, void *user_data)
482 {
483         // interrupted callback
484 }
485
486 int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_p(void)
487 {
488         // see the gpio_interrupted_cb();
489
490         int ret = PERIPHERAL_ERROR_NONE;
491
492         peripheral_gpio_h gpio_h = NULL;
493
494         if (g_feature == false) {
495                 ret = peripheral_gpio_set_interrupted_cb(gpio_h, gpio_interrupted_cb, NULL);
496                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
497
498         } else {
499                 ret = peripheral_gpio_open(pin, &gpio_h);
500                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
501
502                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
503                 if (ret != PERIPHERAL_ERROR_NONE) {
504                         peripheral_gpio_close(gpio_h);
505                         return PERIPHERAL_ERROR_UNKNOWN;
506                 }
507
508                 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_RISING);
509                 if (ret != PERIPHERAL_ERROR_NONE) {
510                         peripheral_gpio_close(gpio_h);
511                         return PERIPHERAL_ERROR_UNKNOWN;
512                 }
513
514                 ret = peripheral_gpio_set_interrupted_cb(gpio_h, gpio_interrupted_cb, NULL);
515                 if (ret != PERIPHERAL_ERROR_NONE) {
516                         peripheral_gpio_close(gpio_h);
517                         return PERIPHERAL_ERROR_UNKNOWN;
518                 }
519
520                 ret = peripheral_gpio_unset_interrupted_cb(gpio_h);
521                 if (ret != PERIPHERAL_ERROR_NONE) {
522                         peripheral_gpio_close(gpio_h);
523                         return PERIPHERAL_ERROR_UNKNOWN;
524                 }
525
526                 ret = peripheral_gpio_close(gpio_h);
527                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
528         }
529
530         return PERIPHERAL_ERROR_NONE;
531 }
532
533 int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_n1(void)
534 {
535         int ret = PERIPHERAL_ERROR_NONE;
536
537         if (g_feature == false) {
538                 ret = peripheral_gpio_set_interrupted_cb(NULL, gpio_interrupted_cb, NULL);
539                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
540
541         } else {
542                 ret = peripheral_gpio_set_interrupted_cb(NULL, gpio_interrupted_cb, NULL);
543                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
544         }
545
546         return PERIPHERAL_ERROR_NONE;
547 }
548
549 int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_n2(void)
550 {
551         int ret = PERIPHERAL_ERROR_NONE;
552
553         peripheral_gpio_h gpio_h = NULL;
554
555         if (g_feature == false) {
556                 ret = peripheral_gpio_set_interrupted_cb(gpio_h, NULL, NULL);
557                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
558
559         } else {
560                 ret = peripheral_gpio_open(pin, &gpio_h);
561                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
562
563                 ret = peripheral_gpio_set_interrupted_cb(gpio_h, NULL, NULL);
564                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
565                         peripheral_gpio_close(gpio_h);
566                         return PERIPHERAL_ERROR_UNKNOWN;
567                 }
568
569                 ret = peripheral_gpio_close(gpio_h);
570                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
571         }
572
573         return PERIPHERAL_ERROR_NONE;
574 }
575
576 int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_p1(void)
577 {
578         int ret = PERIPHERAL_ERROR_NONE;
579
580         peripheral_gpio_h gpio_h = NULL;
581
582         if (g_feature == false) {
583                 ret = peripheral_gpio_unset_interrupted_cb(gpio_h);
584                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
585
586         } else {
587                 ret = peripheral_gpio_open(pin, &gpio_h);
588                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
589
590                 ret = peripheral_gpio_set_interrupted_cb(gpio_h, gpio_interrupted_cb, NULL);
591                 if (ret != PERIPHERAL_ERROR_NONE) {
592                         peripheral_gpio_close(gpio_h);
593                         return PERIPHERAL_ERROR_UNKNOWN;
594                 }
595
596                 ret = peripheral_gpio_unset_interrupted_cb(gpio_h);
597                 if (ret != PERIPHERAL_ERROR_NONE) {
598                         peripheral_gpio_close(gpio_h);
599                         return PERIPHERAL_ERROR_UNKNOWN;
600                 }
601
602                 ret = peripheral_gpio_close(gpio_h);
603                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
604         }
605
606         return PERIPHERAL_ERROR_NONE;
607 }
608
609 int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_p2(void)
610 {
611         int ret = PERIPHERAL_ERROR_NONE;
612
613         peripheral_gpio_h gpio_h = NULL;
614
615         if (g_feature == false) {
616                 ret = peripheral_gpio_unset_interrupted_cb(gpio_h);
617                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
618
619         } else {
620                 ret = peripheral_gpio_open(pin, &gpio_h);
621                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
622
623                 ret = peripheral_gpio_unset_interrupted_cb(gpio_h);
624                 if (ret != PERIPHERAL_ERROR_NONE) {
625                         peripheral_gpio_close(gpio_h);
626                         return PERIPHERAL_ERROR_UNKNOWN;
627                 }
628
629                 ret = peripheral_gpio_close(gpio_h);
630                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
631         }
632
633         return PERIPHERAL_ERROR_NONE;
634 }
635
636 int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_n(void)
637 {
638         int ret = PERIPHERAL_ERROR_NONE;
639
640         if (g_feature == false) {
641                 ret = peripheral_gpio_unset_interrupted_cb(NULL);
642                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
643
644         } else {
645                 ret = peripheral_gpio_unset_interrupted_cb(NULL);
646                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
647         }
648
649         return PERIPHERAL_ERROR_NONE;
650 }
651
652 int test_peripheral_io_gpio_peripheral_gpio_read_p(void)
653 {
654         int ret = PERIPHERAL_ERROR_NONE;
655
656         peripheral_gpio_h gpio_h = NULL;
657
658         uint32_t value;
659
660         if (g_feature == false) {
661                 ret = peripheral_gpio_read(gpio_h, &value);
662                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
663
664         } else {
665                 ret = peripheral_gpio_open(pin, &gpio_h);
666                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
667
668                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
669                 if (ret != PERIPHERAL_ERROR_NONE) {
670                         peripheral_gpio_close(gpio_h);
671                         return PERIPHERAL_ERROR_UNKNOWN;
672                 }
673
674                 ret = peripheral_gpio_read(gpio_h, &value);
675                 if (ret != PERIPHERAL_ERROR_NONE) {
676                         peripheral_gpio_close(gpio_h);
677                         return PERIPHERAL_ERROR_UNKNOWN;
678                 }
679
680                 ret = peripheral_gpio_close(gpio_h);
681                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
682         }
683
684         return PERIPHERAL_ERROR_NONE;
685 }
686
687 int test_peripheral_io_gpio_peripheral_gpio_read_n1(void)
688 {
689         int ret = PERIPHERAL_ERROR_NONE;
690
691         uint32_t value;
692
693         if (g_feature == false) {
694                 ret = peripheral_gpio_read(NULL, &value);
695                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
696
697         } else {
698                 ret = peripheral_gpio_read(NULL, &value);
699                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
700         }
701
702         return PERIPHERAL_ERROR_NONE;
703 }
704
705 int test_peripheral_io_gpio_peripheral_gpio_read_n2(void)
706 {
707         int ret = PERIPHERAL_ERROR_NONE;
708
709         peripheral_gpio_h gpio_h = NULL;
710
711         if (g_feature == false) {
712                 ret = peripheral_gpio_read(gpio_h, NULL);
713                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
714
715         } else {
716                 ret = peripheral_gpio_open(pin, &gpio_h);
717                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
718
719                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
720                 if (ret != PERIPHERAL_ERROR_NONE) {
721                         peripheral_gpio_close(gpio_h);
722                         return PERIPHERAL_ERROR_UNKNOWN;
723                 }
724
725                 ret = peripheral_gpio_read(gpio_h, NULL);
726                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
727                         peripheral_gpio_close(gpio_h);
728                         return PERIPHERAL_ERROR_UNKNOWN;
729                 }
730
731                 ret = peripheral_gpio_close(gpio_h);
732                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
733         }
734
735         return PERIPHERAL_ERROR_NONE;
736 }
737
738 int test_peripheral_io_gpio_peripheral_gpio_write_p(void)
739 {
740         int ret = PERIPHERAL_ERROR_NONE;
741
742         peripheral_gpio_h gpio_h = NULL;
743
744         uint32_t value = 1;
745
746         if (g_feature == false) {
747                 ret = peripheral_gpio_write(gpio_h, value);
748                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
749
750         } else {
751                 ret = peripheral_gpio_open(pin, &gpio_h);
752                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
753
754                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
755                 if (ret != PERIPHERAL_ERROR_NONE) {
756                         peripheral_gpio_close(gpio_h);
757                         return PERIPHERAL_ERROR_UNKNOWN;
758                 }
759
760                 ret = peripheral_gpio_write(gpio_h, value);
761                 if (ret != PERIPHERAL_ERROR_NONE) {
762                         peripheral_gpio_close(gpio_h);
763                         return PERIPHERAL_ERROR_UNKNOWN;
764                 }
765
766                 ret = peripheral_gpio_close(gpio_h);
767                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
768         }
769
770         return PERIPHERAL_ERROR_NONE;
771 }
772
773 int test_peripheral_io_gpio_peripheral_gpio_write_n1(void)
774 {
775         int ret = PERIPHERAL_ERROR_NONE;
776
777         uint32_t value = 1;
778
779         if (g_feature == false) {
780                 ret = peripheral_gpio_write(NULL, value);
781                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
782
783         } else {
784                 ret = peripheral_gpio_write(NULL, value);
785                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
786         }
787
788         return PERIPHERAL_ERROR_NONE;
789 }
790
791 int test_peripheral_io_gpio_peripheral_gpio_write_n2(void)
792 {
793         int ret = PERIPHERAL_ERROR_NONE;
794
795         peripheral_gpio_h gpio_h = NULL;
796
797         uint32_t value = 2;
798
799         if (g_feature == false) {
800                 ret = peripheral_gpio_write(gpio_h, value);
801                 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
802
803         } else {
804                 ret = peripheral_gpio_open(pin, &gpio_h);
805                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
806
807                 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
808                 if (ret != PERIPHERAL_ERROR_NONE) {
809                         peripheral_gpio_close(gpio_h);
810                         return PERIPHERAL_ERROR_UNKNOWN;
811                 }
812
813                 ret = peripheral_gpio_write(gpio_h, value);
814                 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
815                         peripheral_gpio_close(gpio_h);
816                         return PERIPHERAL_ERROR_UNKNOWN;
817                 }
818
819                 ret = peripheral_gpio_close(gpio_h);
820                 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
821         }
822
823         return PERIPHERAL_ERROR_NONE;
824 }