From bb9785434672bce9cd3461fb8b9e46ab343959ce Mon Sep 17 00:00:00 2001 From: Seongil Hahm Date: Thu, 7 Sep 2017 09:30:28 -0700 Subject: [PATCH] Add unit testcase for scan API of Wi-Fi Manager Test the basic functions of scan API --- .../ta_tc/wifi_manager/utc/utc_wifi_manager_main.c | 74 ++++++++++++++++++++-- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/apps/examples/testcase/ta_tc/wifi_manager/utc/utc_wifi_manager_main.c b/apps/examples/testcase/ta_tc/wifi_manager/utc/utc_wifi_manager_main.c index 59bf747..75ecf32 100644 --- a/apps/examples/testcase/ta_tc/wifi_manager/utc/utc_wifi_manager_main.c +++ b/apps/examples/testcase/ta_tc/wifi_manager/utc/utc_wifi_manager_main.c @@ -28,18 +28,45 @@ extern sem_t tc_sem; extern int working_tc; -static void wifi_sta_connected(void); -static void wifi_sta_disconnected(void); -static void wifi_softap_sta_join(void); -static void wifi_softap_sta_leave(void); +static void wifi_sta_connected(void); // in station mode, connected to ap +static void wifi_sta_disconnected(void); // in station mode, disconnected from ap +static void wifi_softap_sta_joined(void); // in softap mode, a station joined +static void wifi_softap_sta_left(void); // in softap mode, a station left +static void wifi_sta_scan_ap_done(wifi_manager_scan_info_s **scan_info, wifi_manager_scan_result_e res); // in station mode, scanning ap is done static wifi_manager_cb_s wifi_callbacks = { NULL, //wifi_sta_connected, NULL, //wifi_sta_disconnected, - NULL, //wifi_softap_sta_join, - NULL, //wifi_softap_sta_leave, + NULL, //wifi_softap_sta_joined, + NULL, //wifi_softap_sta_left, + wifi_sta_scan_ap_done, // in station mode, this callback function is called when scanning ap is done. }; +static wifi_manager_cb_s wifi_null_callbacks = { + NULL, //wifi_sta_connected, + NULL, //wifi_sta_disconnected, + NULL, //wifi_softap_sta_joined, + NULL, //wifi_softap_sta_left, + NULL, // in station mode, this callback function is called when scanning ap is done. +}; + +static void wifi_sta_scan_ap_done(wifi_manager_scan_info_s **scan_info, wifi_manager_scan_result_e res) +{ + printf("[pkes] T%d --> %s\n", getpid(), __FUNCTION__); + /* Make sure you copy the scan results onto a local data structure. + * It will be deleted soon eventually as you exit this function. + */ + if (res == WIFI_SCAN_FAIL) { + printf("WiFi scan failed\n"); + return; + } + wifi_manager_scan_info_s *wifi_scan_iter = *scan_info; + while (wifi_scan_iter != NULL) { + printf("WiFi AP SSID: %-20s, WiFi AP BSSID: %-20s, WiFi Rssi: %d\n", wifi_scan_iter->ssid, wifi_scan_iter->bssid, wifi_scan_iter->rssi); + wifi_scan_iter = wifi_scan_iter->next; + } +} + static void utc_wifi_manager_init_n(void) { wifi_manager_result_e ret = WIFI_MANAGER_FAIL; @@ -210,6 +237,9 @@ static void utc_wifi_manager_deinit_p(void) TC_SUCCESS_RESULT(); } +/* Initialize wifi manager without callback for scan results + * this leads to failure. + */ static void utc_wifi_manager_deinit_n(void) { wifi_manager_result_e ret = WIFI_MANAGER_FAIL; @@ -220,6 +250,35 @@ static void utc_wifi_manager_deinit_n(void) TC_SUCCESS_RESULT(); } +static void utc_wifi_manager_scan_ap_n(void) +{ + wifi_manager_result_e ret = WIFI_MANAGER_FAIL; + + ret = wifi_manager_init(&wifi_null_callbacks); + TC_ASSERT_EQ("wifi_manager_scan_ap", ret, WIFI_MANAGER_SUCCESS); + + ret = wifi_manager_scan_ap(); + TC_ASSERT_EQ("wifi_manager_scan_ap", ret, WIFI_MANAGER_INVALID_ARGS); + + TC_SUCCESS_RESULT(); +} + +static void utc_wifi_manager_scan_ap_p(void) +{ + wifi_manager_result_e ret = WIFI_MANAGER_FAIL; + + ret = wifi_manager_deinit(); + TC_ASSERT_EQ("wifi_manager_scan_ap", ret, WIFI_MANAGER_SUCCESS); + + ret = wifi_manager_init(&wifi_callbacks); + TC_ASSERT_EQ("wifi_manager_scan_ap", ret, WIFI_MANAGER_SUCCESS); + + ret = wifi_manager_scan_ap(); + TC_ASSERT_EQ("wifi_manager_scan_ap", ret, WIFI_MANAGER_SUCCESS); + + TC_SUCCESS_RESULT(); +} + int wifi_manager_utc(int argc, FAR char *argv[]) { sem_wait(&tc_sem); @@ -257,6 +316,9 @@ int wifi_manager_utc(int argc, FAR char *argv[]) utc_wifi_manager_deinit_p(); utc_wifi_manager_deinit_n(); // Should be run after positive tc, that is, the second deinit gets failed. + utc_wifi_manager_scan_ap_n(); // Get failed becasue there is no callback hander for scan results + utc_wifi_manager_scan_ap_p(); // Reinitialized wifi manager with the callback hander for scan results + printf("\n=== TINYARA WIFI_MANAGER TC COMPLETE ===\n"); printf("\t\tTotal pass : %d\n\t\tTotal fail : %d\n", total_pass, total_fail); -- 2.7.4