/* testsuite for radio api */
#include <stdlib.h>
#include <stdio.h>
+#include <glib.h>
+#include <string.h>
#include "radio.h"
#include "radio_test_type.h"
#include <unistd.h>
#define DEFAULT_TEST_FREQ 107700
-#define MENU_ITEM_MAX 20
-#define _MAX_INPUT_STRING_ 100
+#define MAX_STRING_LEN 100
+
+enum {
+ CURRENT_STATUS_MAINMENU,
+ CURRENT_STATUS_CALL_API,
+ CURRENT_STATUS_SET_FREQ,
+ CURRENT_STATUS_SET_MUTE
+};
+
+int g_menu_state = CURRENT_STATUS_MAINMENU;
/* test items...*/
int __test_radio_init(void);
int __test_manual_api_calling(void);
int __test_radio_hw_debug(void);
-/* functions*/
-static void __print_menu(void);
-static void __run_test(int key);
-
-int radio_rt_api_test(void);
-static int __menu(void);
-static void __call_api(int choosen);
void __radio_seek_completed_cb(int frequency, void *user_data);
void __radio_scan_updated_cb(int freq, void *user_data);
void __radio_scan_stop_cb(void *user_data);
void __radio_set_scan_completed_cb(void *user_param);
void __radio_set_interrupted_cb(radio_interrupted_code_e code, void *user_param);
-/* list of tests*/
-test_item_t g_tests[100] = {
- /* menu string : short string to be displayed to menu
- description : detailed description
- test function : a pointer to a actual test function
- 0 : to be filled with return value of test function
- */
- {
- "init test",
- "check radio init function",
- __test_radio_init,
- 0},
-
- {
- "listening gorealra",
- "let's listen to the gorealra!",
- __test_radio_listen_gorealra,
- 0},
-
- {
- "repeat_init_release",
- "repeat init and release and check if it working and memory usage increment",
- __test_repeat_init_release,
- 0},
-
- {
- "repeat_start_stop",
- "repeat start and stop and check if it working and memory usage increment",
- __test_repeat_start_stop,
- 0},
-
- {
- "repeat_seek",
- "repeat seek and check if it working and memory usage increment",
- __test_repeat_seek,
- 0},
-
- {
- "repeat_whole",
- "repeat whole radio sequence and check if it working and memory usage increment",
- __test_repeat_whole,
- 0},
-
- {
- "manual api calling test",
- "mapping each api to each test manu. just like other testsuite. try to reproduce the bugs with it.",
- __test_manual_api_calling,
- 0},
-
- /* add tests here */
-
- /* NOTE : do not remove this last item */
- {"end", "", NULL, 0},
-};
-
int g_num_of_tests = 0;
static radio_h g_my_radio = 0;
-int main(int argc, char **argv)
-{
- int key = 0;
-
- do {
- __print_menu();
- do {
- key = getchar();
- if (key >= '0' && key <= '9')
- __run_test(key - '0');
- } while (key == '\n');
- if (key == 'Q' || key == 'q')
- break;
- } while (1);
- printf("radio test client finished\n");
+static void display_sub_basic()
+{
+ g_print("\n");
+ g_print("=============================================================\n");
+ g_print(" FMRadio testing menu\n");
+ g_print("-------------------------------------------------------------\n");
+ g_print(" 1. init test\n");
+ g_print(" 2. listening gorelra\n");
+ g_print(" 3. repeat_init_release\n");
+ g_print(" 4. repeat_start_stop\n");
+ g_print(" 5. repeat_seek\n");
+ g_print(" 6. repeat_whole\n");
+ g_print(" 7. manual api calling test\n");
+ g_print(" q. quit\n");
+ g_print("-------------------------------------------------------------\n");
- return 0;
}
-
-void __print_menu(void)
+static void displaymenu(void)
{
- int i = 0;
-
- printf("\n\nFMRadio testing menu\n");
- printf("------------------------------------------\n");
-
- for (i = 0; g_tests[i].func; i++)
- printf("[%d] %s\n", i, g_tests[i].menu_string);
-
- printf("[q] quit\n");
-
- g_num_of_tests = i;
-
- printf("Choose one : ");
+ if (g_menu_state == CURRENT_STATUS_MAINMENU) {
+ display_sub_basic();
+ } else if (g_menu_state == CURRENT_STATUS_CALL_API) {
+ g_print("---------------------------------------------------------------------------\n");
+ g_print("\t radio api test. try now!\n");
+ g_print("---------------------------------------------------------------------------\n");
+ g_print("[1] radio_create\t");
+ g_print("[2] radio_destroy\t");
+ g_print("[3] radio_get_state\n");
+ g_print("[4] radio_start\t\t");
+ g_print("[5] radio_stop\n");
+ g_print("[6] radio_seek_up\t");
+ g_print("[7] radio_seek_dow\n");
+ g_print("[8] radio_set_frequency\t");
+ g_print("[9] radio_get_frequency\n");
+ g_print("[10] radio_scan_start\t");
+ g_print("[11] radio_scan_stop\n");
+ g_print("[12] radio_set_mute\t");
+ g_print("[13] radio_is_muted\n");
+ g_print("[14] radio_set_scan_completed_cb\t");
+ g_print("[15] radio_unset_scan_completed_cb\n");
+ g_print("[16] radio_set_interrupted_cb\t\t");
+ g_print("[17] radio_unset_interrupted_cb\n");
+ g_print("[18] radio_get_frequency_range\t\t");
+ g_print("[19] radio_get_channel_spacing\n");
+ g_print("[20] radio_signal_strength\t\t");
+ g_print("[0] quit\n");
+ g_print("---------------------------------------------------------------------------\n");
+ g_print("choose one : ");
+ } else if (g_menu_state == CURRENT_STATUS_SET_FREQ) {
+ g_print("input freq : ");
+ } else if (g_menu_state == CURRENT_STATUS_SET_MUTE) {
+ g_print("select one(0:UNMUTE/1:MUTE) : ");
+ } else {
+ g_print("*** unknown status.\n");
+ /* exit(0); */
+ }
+// g_print(" >>> ");
}
-void __run_test(int key)
+gboolean timeout_menu_display(void *data)
{
- int ret = 0;
+ displaymenu();
+ return FALSE;
+}
- /* check index */
- printf("#tests : %d key : %d\n", g_num_of_tests, key);
- if (key >= g_num_of_tests || key < 0) {
- printf("unassigned key has pressed : %d\n", key);
- return;
+void _interpret_main_menu(char *cmd)
+{
+ int len = strlen(cmd);
+ if (len == 1) {
+ if (strncmp(cmd, "1", 1) == 0) {
+ __test_radio_init();
+ } else if (strncmp(cmd, "2", 1) == 0) {
+ __test_radio_listen_gorealra();
+ } else if (strncmp(cmd, "3", 1) == 0) {
+ __test_repeat_init_release();
+ } else if (strncmp(cmd, "4", 1) == 0) {
+ __test_repeat_start_stop();
+ } else if (strncmp(cmd, "5", 1) == 0) {
+ __test_repeat_seek();
+ } else if (strncmp(cmd, "6", 1) == 0) {
+ __test_repeat_whole();
+ } else if (strncmp(cmd, "7", 1) == 0) {
+ g_menu_state = CURRENT_STATUS_CALL_API;
+ } else if (strncmp(cmd, "q", 1) == 0) {
+ exit(0);
+ } else {
+ g_print("unknown menu \n");
+ }
}
+ return;
+}
- /* display description */
- printf("excuting test : %s\n", g_tests[key].menu_string);
- printf("description : %s\n", g_tests[key].description);
-
- /* calling test function */
- ret = g_tests[key].func();
-
- g_tests[key].result = ret;
- if (ret)
- printf("TEST FAILED. ret code : %d\n", g_tests[key].result);
- else
- printf("TEST SUCCEDED. ret code : %d\n", g_tests[key].result);
+static void interpret(char *cmd)
+{
+ int ret = RADIO_ERROR_NONE;
+ switch (g_menu_state) {
+ case CURRENT_STATUS_MAINMENU: {
+ _interpret_main_menu(cmd);
+ break;
+ }
+ case CURRENT_STATUS_CALL_API: {
+ int len = strlen(cmd);
+ if (len == 1) {
+ if (strncmp(cmd, "1", len) == 0) {
+ RADIO_TEST__(radio_create(&g_my_radio);)
+ } else if (strncmp(cmd, "2", len) == 0) {
+ RADIO_TEST__(radio_destroy(g_my_radio);)
+ } else if (strncmp(cmd, "3", len) == 0) {
+ radio_state_e state;
+ RADIO_TEST__(radio_get_state(g_my_radio, &state);)
+ g_print("state : %d\n", state);
+ } else if (strncmp(cmd, "4", len) == 0) {
+ RADIO_TEST__(radio_start(g_my_radio);)
+ } else if (strncmp(cmd, "5", len) == 0) {
+ RADIO_TEST__(radio_stop(g_my_radio);)
+ } else if (strncmp(cmd, "6", len) == 0) {
+ RADIO_TEST__(radio_seek_up(g_my_radio, __radio_seek_completed_cb, NULL);)
+ } else if (strncmp(cmd, "7", len) == 0) {
+ RADIO_TEST__(radio_seek_down(g_my_radio, __radio_seek_completed_cb, NULL);)
+ } else if (strncmp(cmd, "8", len) == 0) {
+ g_menu_state = CURRENT_STATUS_SET_FREQ;
+ } else if (strncmp(cmd, "9", len) == 0) {
+ int freq = 0;
+ RADIO_TEST__(radio_get_frequency(g_my_radio, &freq);)
+ g_print("freq : %d\n", freq);
+ } else if (strncmp(cmd, "0", len) == 0) {
+ g_menu_state = CURRENT_STATUS_MAINMENU;
+ } else {
+ g_print("UNKNOW COMMAND\n");
+ }
+ } else if (len == 2) {
+ if (strncmp(cmd, "10", len) == 0) {
+ RADIO_TEST__(radio_scan_start(g_my_radio, &__radio_scan_updated_cb, NULL);)
+ } else if (strncmp(cmd, "11", len) == 0) {
+ RADIO_TEST__(radio_scan_stop(g_my_radio, &__radio_scan_stop_cb, NULL);)
+ } else if (strncmp(cmd, "12", len) == 0) {
+ g_menu_state = CURRENT_STATUS_SET_MUTE;
+ } else if (strncmp(cmd, "13", len) == 0) {
+ bool muted = 0;
+ RADIO_TEST__(radio_is_muted(g_my_radio, &muted);)
+ g_print("muted : %d\n", muted);
+ } else if (strncmp(cmd, "14", len) == 0) {
+ RADIO_TEST__(radio_set_scan_completed_cb(g_my_radio, &__radio_set_scan_completed_cb, NULL);)
+ } else if (strncmp(cmd, "15", len) == 0) {
+ RADIO_TEST__(radio_unset_scan_completed_cb(g_my_radio);)
+ } else if (strncmp(cmd, "16", len) == 0) {
+ RADIO_TEST__(radio_set_interrupted_cb(g_my_radio, &__radio_set_interrupted_cb, NULL);)
+ } else if (strncmp(cmd, "17", len) == 0) {
+ RADIO_TEST__(radio_unset_interrupted_cb(g_my_radio);)
+ } else if (strncmp(cmd, "15", len) == 0) {
+ int min = 0;
+ int max = 0;
+ RADIO_TEST__(radio_get_frequency_range(g_my_radio, &min, &max);)
+ g_print("min : %d max: %d \n", min, max);
+ } else if (strncmp(cmd, "19", len) == 0) {
+ int channel_spacing = 0;
+ RADIO_TEST__(radio_get_channel_spacing(g_my_radio, &channel_spacing);)
+ g_print("channel_spacing : %d \n", channel_spacing);
+ } else if (strncmp(cmd, "20", len) == 0) {
+ int signal_strength = 0;
+ RADIO_TEST__(radio_get_signal_strength(g_my_radio, &signal_strength);)
+ g_print("signal strength is : %d \n", signal_strength);
+ } else {
+ g_print("UNKNOW COMMAND\n");
+ }
+ } else {
+ g_print("UNKNOW COMMAND\n");
+ }
+ break;
+ }
+ case CURRENT_STATUS_SET_FREQ: {
+ int freq = atoi(cmd);
+ RADIO_TEST__(radio_set_frequency(g_my_radio, freq);)
+ g_menu_state = CURRENT_STATUS_CALL_API;
+ break;
+ }
+ case CURRENT_STATUS_SET_MUTE: {
+ int muted = atoi(cmd);
+ RADIO_TEST__(radio_set_mute(g_my_radio, muted);)
+ g_menu_state = CURRENT_STATUS_CALL_API;
+ break;
+ }
+ default:
+ break;
+ }
+ g_timeout_add(100, timeout_menu_display, 0);
}
/* test items...*/
return 0;
}
-int __test_manual_api_calling(void)
+void __radio_seek_completed_cb(int frequency, void *user_data)
{
-
- radio_rt_api_test();
-
- return 0;
+ g_print("__radio_seek_completed_cb freq is %d\n", frequency);
}
-int radio_rt_api_test(void)
+void __radio_scan_updated_cb(int frequency, void *user_param)
{
- while (1) {
- int choosen = 0;
-
- choosen = __menu();
-
- if (choosen == -1)
- continue;
-
- if (choosen == 0)
- break;
-
- __call_api(choosen);
- }
-
- printf("radio test client finished\n");
-
- return 0;
+ g_print("__radio_scan_updated_cb freq is %d\n", frequency);
}
-int __menu(void)
+void __radio_scan_stop_cb(void *user_param)
{
- int menu_item = 0;
-
- printf("---------------------------------------------------------\n");
- printf("radio rt api test. try now!\n");
- printf("---------------------------------------------------------\n");
- printf("[1] radio_create\n");
- printf("[2] radio_destroy\n");
- printf("[3] radio_get_state\n");
- printf("[4] radio_start\n");
- printf("[5] radio_stop\n");
- printf("[6] radio_seek_up\n");
- printf("[7] radio_seek_down\n");
- printf("[8] radio_set_frequency(ex.107700)\n");
- printf("[9] radio_get_frequency\n");
- printf("[10] radio_signal_strength\n");
- printf("[11] radio_scan_start\n");
- printf("[12] radio_scan_stop\n");
- printf("[13] radio_set_mute\n");
- printf("[14] radio_is_muted\n");
- printf("[15] radio_set_scan_completed_cb\n");
- printf("[16] radio_unset_scan_completed_cb\n");
- printf("[17] radio_set_interrupted_cb\n");
- printf("[18] radio_unset_interrupted_cb\n");
- printf("[19] radio_get_frequency_range\n");
- printf("[20] radio_get_channel_spacing\n");
-
- printf("[0] quit\n");
- printf("---------------------------------------------------------\n");
- printf("choose one : ");
-
- if (scanf("%d", &menu_item) == 0) {
- char temp[_MAX_INPUT_STRING_];
- if (scanf("%100s", temp) == 0)
- printf("Error while flushing the input buffer - but lets continue\n");
- return -1;
- }
-
- if (menu_item > MENU_ITEM_MAX)
- menu_item = -1;
-
- return menu_item;
+ g_print("__radio_scan_stop_cb\n");
}
-void __call_api(int choosen)
+void __radio_set_scan_completed_cb(void *user_param)
{
- int ret = RADIO_ERROR_NONE;
-
- switch (choosen) {
- case 1:
- {
- RADIO_TEST__(radio_create(&g_my_radio);)
- }
- break;
-
- case 2:
- {
- RADIO_TEST__(radio_destroy(g_my_radio);)
- g_my_radio = 0;
- }
- break;
-
- case 3:
- {
- radio_state_e state;
- RADIO_TEST__(radio_get_state(g_my_radio, &state);)
- printf("state : %d\n", state);
- }
- break;
-
- case 4:
- {
- RADIO_TEST__(radio_start(g_my_radio);)
- }
- break;
-
- case 5:
- {
- RADIO_TEST__(radio_stop(g_my_radio);)
- }
- break;
-
- case 6:
- {
- RADIO_TEST__(radio_seek_up(g_my_radio, __radio_seek_completed_cb, NULL);)
-
- }
- break;
-
- case 7:
- {
- RADIO_TEST__(radio_seek_down(g_my_radio, __radio_seek_completed_cb, NULL);)
- }
- break;
-
- case 8:
- {
- int freq = 0;
- printf("input freq : ");
- if (scanf("%d", &freq) == 0)
- return;
-
- RADIO_TEST__(radio_set_frequency(g_my_radio, freq);)
- }
- break;
-
- case 9:
- {
- int freq = 0;
- RADIO_TEST__(radio_get_frequency(g_my_radio, &freq);)
-
- printf("freq : %d\n", freq);
- }
- break;
-
- case 10:
- {
- int signal_strength = 0;
- RADIO_TEST__(radio_get_signal_strength(g_my_radio, &signal_strength);)
- printf("signal strength is : %d \n", signal_strength);
- }
- break;
-
- case 11:
- {
- RADIO_TEST__(radio_scan_start(g_my_radio, &__radio_scan_updated_cb, NULL);)
- }
- break;
-
- case 12:
- {
- RADIO_TEST__(radio_scan_stop(g_my_radio, &__radio_scan_stop_cb, NULL);)
- }
- break;
-
- case 13:
- {
- int muted = 0;
- printf("select one(0:UNMUTE/1:MUTE) : ");
- if (scanf("%d", &muted) == 0)
- return;
- RADIO_TEST__(radio_set_mute(g_my_radio, muted);)
- }
- break;
-
- case 14:
- {
- bool muted = 0;
- RADIO_TEST__(radio_is_muted(g_my_radio, &muted);)
- printf("muted : %d \n", muted);
- }
- break;
-
- case 15:
- {
- RADIO_TEST__(radio_set_scan_completed_cb(g_my_radio, &__radio_set_scan_completed_cb, NULL);)
- }
- break;
-
- case 16:
- {
- RADIO_TEST__(radio_unset_scan_completed_cb(g_my_radio);)
- }
- break;
-
- case 17:
- {
- RADIO_TEST__(radio_set_interrupted_cb(g_my_radio, &__radio_set_interrupted_cb, NULL);)
- }
- break;
-
- case 18:
- {
- RADIO_TEST__(radio_unset_interrupted_cb(g_my_radio);)
- }
- break;
-
- case 19:
- {
- int min = 0;
- int max = 0;
- RADIO_TEST__(radio_get_frequency_range(g_my_radio, &min, &max);)
- printf("min : %d max: %d \n", min, max);
- }
- break;
-
- case 20:
- {
- int channel_spacing = 0;
- RADIO_TEST__(radio_get_channel_spacing(g_my_radio, &channel_spacing);)
- printf("channel_spacing : %d \n", channel_spacing);
- }
- break;
-
- default:
- break;
- }
+ g_print("__radio_scan_completed_cb\n");
}
-void __radio_seek_completed_cb(int frequency, void *user_data)
+void __radio_set_interrupted_cb(radio_interrupted_code_e code, void *user_param)
{
- printf("__radio_seek_completed_cb freq is %d\n", frequency);
+ g_print("__radio_set_interrupted_cb\n");
}
-void __radio_scan_updated_cb(int frequency, void *user_param)
+gboolean input(GIOChannel *channel)
{
- printf("__radio_scan_updated_cb freq is %d\n", frequency);
+ gchar buf[MAX_STRING_LEN];
+ gsize read;
+ GError *error = NULL;
+ g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error);
+ buf[read] = '\0';
+ g_strstrip(buf);
+ interpret(buf);
+ return TRUE;
}
-void __radio_scan_stop_cb(void *user_param)
-{
- printf("__radio_scan_stop_cb\n");
-}
-void __radio_set_scan_completed_cb(void *user_param)
+int main(int argc, char *argv[])
{
- printf("__radio_scan_completed_cb\n");
-}
+ GIOChannel *stdin_channel;
+ GMainLoop *loop = g_main_loop_new(NULL, 0);
+ stdin_channel = g_io_channel_unix_new(0);
+ g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
+ g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc) input, NULL);
-void __radio_set_interrupted_cb(radio_interrupted_code_e code, void *user_param)
-{
- printf("__radio_set_interrupted_cb\n");
+ displaymenu();
+
+ g_print("RUN main loop\n");
+ g_main_loop_run(loop);
+ g_print("STOP main loop\n");
+
+ g_main_loop_unref(loop);
+ return 0;
}
+