tizen 2.4 release
[framework/api/radio.git] / test / radio_test.c
1 /*
2  *
3  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
4  *
5  * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 /* testsuite for radio api */
22 #include <stdlib.h>
23 #include <stdio.h>
24
25
26 #include "radio.h"
27 #include "radio_test_type.h"
28 #include <unistd.h>
29
30 #define DEFAULT_TEST_FREQ       107700
31 #define MENU_ITEM_MAX   20
32 #define _MAX_INPUT_STRING_ 100
33
34
35 /* test items...*/
36 int __test_radio_init(void);
37 int __test_radio_listen_gorealra(void);
38 int __test_repeat_init_release(void);
39 int __test_repeat_start_stop(void);
40 int __test_repeat_seek(void);
41 int __test_repeat_whole(void);
42 int __test_manual_api_calling(void);
43 int __test_radio_hw_debug(void);
44
45
46 /* functions*/
47 static void __print_menu(void);
48 static void __run_test(int key);
49
50 int radio_rt_api_test(void);
51 static int __menu(void);
52 static void __call_api(int choosen);
53 void __radio_seek_completed_cb(int frequency, void *user_data);
54 void __radio_scan_updated_cb(int freq, void *user_data);
55 void __radio_scan_stop_cb(void *user_data);
56 void __radio_set_scan_completed_cb(void *user_param);
57 void __radio_set_interrupted_cb(radio_interrupted_code_e code, void *user_param);
58
59
60
61 /* list of tests*/
62 test_item_t g_tests[100] = {
63         /* menu string : short string to be displayed to menu
64              description : detailed description
65              test function :  a pointer to a actual test function
66              0 : to be filled with return value of test function
67          */
68         {
69                 "init test",
70                 "check radio init function",
71                 __test_radio_init,
72                 0
73         },
74
75         {
76                 "listening gorealra",
77                 "let's listen to the gorealra!",
78                 __test_radio_listen_gorealra,
79                 0
80         },
81
82         {
83                 "repeat_init_release",
84                 "repeat init and release and check if it working and memory usage increment",
85                 __test_repeat_init_release,
86                 0
87         },
88
89         {
90                 "repeat_start_stop",
91                 "repeat start and stop and check if it working and memory usage increment",
92                 __test_repeat_start_stop,
93                 0
94         },
95
96         {
97                 "repeat_seek",
98                 "repeat seek and check if it working and memory usage increment",
99                 __test_repeat_seek,
100                 0
101         },
102
103         {
104                 "repeat_whole",
105                 "repeat whole radio sequence and check if it working and memory usage increment",
106                 __test_repeat_whole,
107                 0
108         },
109
110         {
111                 "manual api calling test",
112                 "mapping each api to each test manu. just like other testsuite. try to reproduce the bugs with it.",
113                 __test_manual_api_calling,
114                 0
115         },
116
117         /* add tests here*/
118
119         /* NOTE : do not remove this last item */
120         {"end", "", NULL, 0},
121 };
122
123 int g_num_of_tests = 0;
124 static radio_h g_my_radio = 0;
125
126 int main(int argc, char **argv)
127 {
128         int key = 0;
129
130         do {
131                 __print_menu();
132
133                 do {
134                         key = getchar();
135
136                         if (key >= '0' && key <= '9') {
137                                 __run_test(key - '0');
138                         }
139                 } while (key == '\n');
140                 if (key == 'Q' || key == 'q')
141                         break;
142         } while (1);
143
144         printf("radio test client finished\n");
145
146         return 0;
147 }
148
149 void __print_menu(void)
150 {
151         int i = 0;
152
153         printf("\n\nFMRadio testing menu\n");
154         printf("------------------------------------------\n");
155
156         for (i = 0; g_tests[i].func; i++) {
157                 printf("[%d] %s\n", i, g_tests[i].menu_string);
158         }
159         printf("[q] quit\n");
160
161         g_num_of_tests = i;
162
163         printf("Choose one : ");
164 }
165
166 void __run_test(int key)
167 {
168         int ret = 0;
169
170         /* check index */
171         printf("#tests : %d    key : %d\n", g_num_of_tests, key);
172         if (key >= g_num_of_tests || key < 0) {
173                 printf("unassigned key has pressed : %d\n", key);
174                 return;
175         }
176
177         /* display description*/
178         printf("excuting test : %s\n", g_tests[key].menu_string);
179         printf("description : %s\n", g_tests[key].description);
180
181         /* calling test function*/
182         ret = g_tests[key].func();
183
184         g_tests[key].result =  ret;
185
186         if (ret) {
187                 printf("TEST FAILED. ret code : %d\n", g_tests[key].result);
188         } else {
189                 printf("TEST SUCCEDED. ret code : %d\n", g_tests[key].result);
190         }
191 }
192
193
194 /* test items...*/
195 int __test_radio_init(void)
196 {
197         printf("%s\n", __FUNCTION__);
198
199         int ret = RADIO_ERROR_NONE;
200         radio_h radio;
201
202         RADIO_TEST__(radio_create(&radio);)
203         RADIO_TEST__(radio_destroy(radio);)
204         return ret;
205 }
206
207 int __test_radio_listen_gorealra(void)
208 {
209         printf("%s\n", __FUNCTION__);
210
211         int ret = RADIO_ERROR_NONE;
212         radio_h radio;
213
214         RADIO_TEST__(radio_create(&radio);)
215         RADIO_TEST__(radio_set_frequency(radio, DEFAULT_TEST_FREQ);)
216         RADIO_TEST__(radio_start(radio);)
217         usleep(5000 * 1000);
218         RADIO_TEST__(radio_stop(radio);)
219         RADIO_TEST__(radio_destroy(radio);)
220         return ret;
221 }
222
223 int __test_repeat_init_release(void)
224 {
225         printf("%s\n", __FUNCTION__);
226
227         int ret = RADIO_ERROR_NONE;
228         int cnt = 0;
229         radio_h radio;
230
231         while (cnt < 1000) {
232                 RADIO_TEST__(radio_create(&radio);)
233                 RADIO_TEST__(radio_destroy(radio);)
234
235                 cnt++;
236
237                 printf("%s : repeat count : %d\n", __FUNCTION__, cnt);
238         }
239
240         return 0;
241 }
242
243 int __test_repeat_start_stop(void)
244 {
245         printf("%s\n", __FUNCTION__);
246         int ret = RADIO_ERROR_NONE;
247         int cnt = 0;
248         radio_h radio;
249
250         RADIO_TEST__(radio_create(&radio);)
251         RADIO_TEST__(radio_set_frequency(radio, DEFAULT_TEST_FREQ);)
252
253         while (cnt < 10) {
254                 RADIO_TEST__(radio_start(radio);)
255                 usleep(2000 * 1000);
256                 RADIO_TEST__(radio_stop(radio);)
257
258                 cnt++;
259
260                 printf("%s : repeat count : %d\n", __FUNCTION__, cnt);
261         }
262
263         return 0;
264 }
265
266 int __test_repeat_seek(void)
267 {
268         printf("__test_repeat_seek\n");
269         return 0;
270 }
271
272 int __test_repeat_whole(void)
273 {
274         printf("__test_repeat_whole\n");
275         return 0;
276 }
277
278 int __test_manual_api_calling(void)
279 {
280
281         radio_rt_api_test();
282
283         return 0;
284 }
285
286
287 int radio_rt_api_test(void)
288 {
289         while (1) {
290                 int choosen = 0;
291
292                 choosen = __menu();
293
294                 if (choosen == -1)
295                         continue;
296
297                 if (choosen == 0)
298                         break;
299
300                 __call_api(choosen);
301         }
302
303         printf("radio test client finished\n");
304
305         return 0;
306 }
307
308 int __menu(void)
309 {
310         int menu_item = 0;
311
312         printf("---------------------------------------------------------\n");
313         printf("radio rt api test. try now!\n");
314         printf("---------------------------------------------------------\n");
315         printf("[1] radio_create\n");
316         printf("[2] radio_destroy\n");
317         printf("[3] radio_get_state\n");
318         printf("[4] radio_start\n");
319         printf("[5] radio_stop\n");
320         printf("[6] radio_seek_up\n");
321         printf("[7] radio_seek_down\n");
322         printf("[8] radio_set_frequency(ex.107700)\n");
323         printf("[9] radio_get_frequency\n");
324         printf("[10] radio_signal_strength\n");
325         printf("[11] radio_scan_start\n");
326         printf("[12] radio_scan_stop\n");
327         printf("[13] radio_set_mute\n");
328         printf("[14] radio_is_muted\n");
329         printf("[15] radio_set_scan_completed_cb\n");
330         printf("[16] radio_unset_scan_completed_cb\n");
331         printf("[17] radio_set_interrupted_cb\n");
332         printf("[18] radio_unset_interrupted_cb\n");
333         printf("[19] radio_get_frequency_range\n");
334         printf("[20] radio_get_channel_spacing\n");
335
336         printf("[0] quit\n");
337         printf("---------------------------------------------------------\n");
338         printf("choose one : ");
339
340         if (scanf("%d", &menu_item) == 0) {
341                 char temp[_MAX_INPUT_STRING_];
342                 if (scanf("%s", temp) == 0) {
343                         printf("Error while flushing the input buffer - but lets continue\n");
344                 }
345                 return -1;
346         }
347
348
349         if (menu_item > MENU_ITEM_MAX)
350                 menu_item = -1;
351
352         return menu_item;
353 }
354
355 void __call_api(int choosen)
356 {
357         int ret = RADIO_ERROR_NONE;
358
359         switch (choosen) {
360                 case 1: {
361                                 RADIO_TEST__(radio_create(&g_my_radio);)
362                         }
363                         break;
364
365                 case 2: {
366                                 RADIO_TEST__(radio_destroy(g_my_radio);)
367                                 g_my_radio = 0;
368                         }
369                         break;
370
371                 case 3: {
372                                 radio_state_e state;
373                                 RADIO_TEST__(radio_get_state(g_my_radio, &state);)
374
375                                 printf("state : %d\n", state);
376                         }
377                         break;
378
379                 case 4: {
380                                 RADIO_TEST__(radio_start(g_my_radio);)
381                         }
382                         break;
383
384                 case 5: {
385                                 RADIO_TEST__(radio_stop(g_my_radio);)
386                         }
387                         break;
388
389                 case 6: {
390                                 RADIO_TEST__(radio_seek_up(g_my_radio, __radio_seek_completed_cb, NULL);)
391
392                         }
393                         break;
394
395                 case 7: {
396                                 RADIO_TEST__(radio_seek_down(g_my_radio, __radio_seek_completed_cb, NULL);)
397                         }
398                         break;
399
400                 case 8: {
401                                 int freq = 0;
402                                 printf("input freq : ");
403                                 if (scanf("%d", &freq) == 0)
404                                         return;
405
406                                 RADIO_TEST__(radio_set_frequency(g_my_radio, freq);)
407                         }
408                         break;
409
410                 case 9: {
411                                 int freq = 0;
412                                 RADIO_TEST__(radio_get_frequency(g_my_radio, &freq);)
413
414                                 printf("freq : %d\n", freq);
415                         }
416                         break;
417
418                 case 10: {
419                                 int signal_strength = 0;
420                                 RADIO_TEST__(radio_get_signal_strength(g_my_radio, &signal_strength);)
421                                 printf("signal strength is : %d \n", signal_strength);
422                         }
423                         break;
424
425                 case 11: {
426                                 RADIO_TEST__(radio_scan_start(g_my_radio, &__radio_scan_updated_cb, NULL);)
427                         }
428                         break;
429
430                 case 12: {
431                                 RADIO_TEST__(radio_scan_stop(g_my_radio, &__radio_scan_stop_cb, NULL);)
432                         }
433                         break;
434
435                 case 13: {
436                                 int muted = 0;
437                                 printf("select one(0:UNMUTE/1:MUTE) : ");
438                                 if (scanf("%d", &muted) == 0)
439                                         return;
440                                 RADIO_TEST__(radio_set_mute(g_my_radio, muted);)
441                         }
442                         break;
443
444                 case 14: {
445                                 bool muted = 0;
446                                 RADIO_TEST__(radio_is_muted(g_my_radio, &muted);)
447                                 printf("muted : %d \n", muted);
448                         }
449                         break;
450
451
452                 case 15: {
453                                 RADIO_TEST__(radio_set_scan_completed_cb(g_my_radio, &__radio_set_scan_completed_cb, NULL);)
454                         }
455                         break;
456
457                 case 16: {
458                                 RADIO_TEST__(radio_unset_scan_completed_cb(g_my_radio);)
459                         }
460                         break;
461
462                 case 17: {
463                                 RADIO_TEST__(radio_set_interrupted_cb(g_my_radio, &__radio_set_interrupted_cb, NULL);)
464                         }
465                         break;
466
467                 case 18: {
468                                 RADIO_TEST__(radio_unset_interrupted_cb(g_my_radio);)
469                         }
470                         break;
471
472                 case 19: {
473                                 int min = 0;
474                                 int max = 0;
475                                 RADIO_TEST__(radio_get_frequency_range(g_my_radio, &min, &max);)
476                                 printf("min : %d max: %d \n", min, max);
477                         }
478                         break;
479
480                 case 20: {
481                                 int channel_spacing = 0;
482                                 RADIO_TEST__(radio_get_channel_spacing(g_my_radio, &channel_spacing);)
483                                 printf("channel_spacing : %d \n", channel_spacing);
484                         }
485                         break;
486
487                 default:
488                         break;
489         }
490 }
491
492
493 void __radio_seek_completed_cb(int frequency, void *user_data)
494 {
495         printf("__radio_seek_completed_cb freq is %d\n" , frequency);
496 }
497 void __radio_scan_updated_cb(int frequency, void *user_param)
498 {
499         printf("__radio_scan_updated_cb freq is %d\n" , frequency);
500 }
501
502 void __radio_scan_stop_cb(void *user_param)
503 {
504         printf("__radio_scan_stop_cb\n");
505 }
506
507 void __radio_set_scan_completed_cb(void *user_param)
508 {
509         printf("__radio_scan_completed_cb\n");
510 }
511
512 void __radio_set_interrupted_cb(radio_interrupted_code_e code, void *user_param)
513 {
514         printf("__radio_set_interrupted_cb\n");
515 }
516