Refine wifi-aware-pub/sub-test
authorCheoleun Moon <chleun.moon@samsung.com>
Tue, 7 Apr 2020 07:54:48 +0000 (16:54 +0900)
committerCheoleun Moon <chleun.moon@samsung.com>
Tue, 7 Apr 2020 07:54:48 +0000 (16:54 +0900)
test/wifi-aware-publish-test.c
test/wifi-aware-subscribe-test.c

index 8391097d55924cebd9e6b6b28dbccdbc55f4aa7b..409a4179dfde0532c40dea130afd06515ee8d285 100644 (file)
                } \
        } while (0)
 
+#define PRINT_SUCCESS(format, args...) printf(MAKE_GREEN format RESET_COLOR "\n", ##args)
+#define PRINT_FAILURE(format, args...) printf(MAKE_RED format RESET_COLOR, ##args)
+#define PRINT_FAILURE_ERROR(format, error) printf(MAKE_RED format " Failure(%d:%s)\n" RESET_COLOR, error, __print_error(error))
+
 #define SERVICE_NAME "Wi-Fi Aware Test"
 #define PUB_SSI "Extra bytes in the publisher discovery"
 #define MSG_PUB_TO_SUB "Ready"
@@ -194,16 +198,6 @@ const char *__print_error(wifi_aware_error_e err)
        }
 }
 
-static void __print_result(int ret, gchar *msg)
-{
-    if (ret == WIFI_AWARE_ERROR_NONE) {
-        printf(MAKE_GREEN"success to %s"RESET_COLOR"\n", msg);
-    } else {
-        printf(MAKE_RED"fail to %s: %s ", msg, __print_error(ret));
-        printf(RESET_COLOR"\n");
-    }
-}
-
 static void __print_mac(unsigned char mac[6])
 {
        printf(MACSTR, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
@@ -236,7 +230,6 @@ void test_quit()
 {
        RET_IF_LOOP_IS_NULL();
 
-       printf("Bye\n");
        g_main_loop_quit(g_main_loop_p);
 
        return;
@@ -245,19 +238,16 @@ void test_quit()
 static void __published_cb(wifi_aware_session_h session,
                wifi_aware_error_e error, void *user_data)
 {
-       if (error == WIFI_AWARE_ERROR_NONE) {
-               printf("Publish Request is success.\n");
-       }
-       else {
-               printf("Publish Request fails. Error: %s\n", __print_error(error));
-               return;
-       }
+       if (error == WIFI_AWARE_ERROR_NONE)
+               PRINT_SUCCESS("[CB][Publish] Requested");
+       else
+               PRINT_FAILURE_ERROR("[CB][Publish]", error);
 }
 
 static void __data_path_terminated_cb(wifi_aware_data_path_h data_path,
                wifi_aware_termination_reason_e reason, void *user_data)
 {
-       printf("\n>>Data path(%p) is terminated.\n", data_path);
+       printf("[EVENT][DataPath Terminated] %p", data_path);
        if (data_path != NULL) {
                wifi_aware_data_path_unset_terminated_cb(data_path);
                wifi_aware_data_path_destroy(data_path);
@@ -269,35 +259,34 @@ static void __open_cb(wifi_aware_data_path_h data_path, wifi_aware_error_e error
        if (error == WIFI_AWARE_ERROR_NONE) {
                int ret = WIFI_AWARE_ERROR_NONE;
                char *interface;
-               printf("\n>>Data path is established. NDP: %p\n", data_path);
+               PRINT_SUCCESS("[CB][OpenDataPath] Requested %p", data_path);
                ret = wifi_aware_data_path_get_interface(data_path, &interface);
                if (ret == WIFI_AWARE_ERROR_NONE)
-                       printf("Interface: %s\n", interface);
+                       printf("\tInterface: %s\n", interface);
                else
-                       printf("Fail to get interface\n");
+                       PRINT_FAILURE_ERROR("\tInterface:", ret);
 
                char *ipv6_address;
                int port;
                ret = wifi_aware_data_path_get_peer_ipv6_address(data_path, &ipv6_address);
                if (ret == WIFI_AWARE_ERROR_NONE)
-                       printf("IPv6 Address of Peer: %s\n", ipv6_address);
+                       printf("\tPeer's IPv6 Address: %s\n", ipv6_address);
                else
-                       printf("Fail to get IPV6 Address\n");
+                       PRINT_FAILURE_ERROR("\tPeer's IPv6 Address:", ret);
                ret = wifi_aware_data_path_get_peer_port(data_path, &port);
                if (ret == WIFI_AWARE_ERROR_NONE)
-                       printf("Port number of Peer: %d\n", port);
+                       printf("\tPeer's Port: %d\n", port);
                else
-                       printf("Fail to get Port number\n");
+                       PRINT_FAILURE_ERROR("\tPeer's Port:", ret);
        }
        else {
-               printf("\n>>Fail to open Data path. data path: %p. error: %s\n", data_path, __print_error(error));
+               PRINT_FAILURE("[CB][OpenDataPath Requested] Failure(%d:%s) %p", error, __print_error(error), data_path);
        }
-
 }
 
 static void __open_data_path(wifi_aware_session_h session)
 {
-       printf("\n>>Open Data Path\n");
+       printf("[OpenDataPath] Request\n");
        if (g_peer == NULL) {
                printf("Peer is NULL\n");
                return;
@@ -305,23 +294,23 @@ static void __open_data_path(wifi_aware_session_h session)
 
        int ret = wifi_aware_data_path_create(session, g_peer, &g_ndp);
        if (ret != WIFI_AWARE_ERROR_NONE) {
-               printf("Fail to create data path: %s\n", __print_error(ret));
+               PRINT_FAILURE_ERROR("\tHandle:", ret);
                return;
        }
-       printf("data path: %p\n", g_ndp);
+       printf("\tHandle: %p\n", g_ndp);
 
        ret = wifi_aware_data_path_set_terminated_cb(g_ndp, __data_path_terminated_cb, NULL);
        if (ret != WIFI_AWARE_ERROR_NONE) {
-               printf("Fail to create data path: %s\n", __print_error(ret));
+               PRINT_FAILURE_ERROR("\tSet TerminatedCallback:", ret);
                return;
        }
 
        ret = wifi_aware_data_path_set_security(g_ndp, g_security_type);
        if (ret != WIFI_AWARE_ERROR_NONE) {
-               printf("Fail to set security type for data path: %s\n", __print_error(ret));
+               PRINT_FAILURE_ERROR("\tSecurity Type:", ret);
                return;
        }
-       printf("security type: ");
+       printf("\tSecurity Type: ");
        switch (g_security_type) {
        case WIFI_AWARE_SECURITY_TYPE_OPEN:
                printf("Open\n");
@@ -334,25 +323,27 @@ static void __open_data_path(wifi_aware_session_h session)
                printf("PMK\n");
                break;
        default:
-               printf("Unknown security type\n");
+               PRINT_FAILURE("Unknown security type");
                return;
        }
 
        ret = wifi_aware_data_path_set_port(g_ndp, PORT);
        if (ret != WIFI_AWARE_ERROR_NONE)
-               printf("Fail to set port for data path: %s\n", __print_error(ret));
+               PRINT_FAILURE_ERROR("\tPort:", ret);
        else
-               printf("port: %d\n", PORT);
+               printf("\tPort: %d\n", PORT);
 
        ret = wifi_aware_data_path_open(g_ndp, __open_cb, NULL);
-       if (ret != WIFI_AWARE_ERROR_NONE) {
-               printf("Fail to open data path: %s\n", __print_error(ret));
-       }
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               PRINT_FAILURE_ERROR("[OpenDataPath]", ret);
 }
 
 static void __message_result_cb(wifi_aware_session_h session, wifi_aware_error_e error, void *user_data)
 {
-       printf("\n>>Result of sending message: %s\n", __print_error(error));
+       if (error == WIFI_AWARE_ERROR_NONE)
+               PRINT_SUCCESS("[CB][Send Message] Requested");
+       else
+               PRINT_FAILURE_ERROR("[CB][Send Message]", error);
        __open_data_path(session);
 }
 
@@ -363,37 +354,38 @@ static void __message_received_cb(wifi_aware_session_h session, wifi_aware_peer_
        char buf[1024] = {0, };
        unsigned char *mac = NULL;
 
-       printf("\n>>Receive message from a Wi-Fi Aware Peer\n");
+       PRINT_SUCCESS("[Event][Receive Message]");
 
-       if (wifi_aware_peer_get_mac(peer, &mac) != WIFI_AWARE_ERROR_NONE)
-               printf("Fail to get Peer's NMI: %s\n", __print_error(ret));
+       ret = wifi_aware_peer_get_mac(peer, &mac);
+       if (ret != WIFI_AWARE_ERROR_NONE) {
+               printf("\tPeer's NMI: Failure(%d:%s)\n", ret, __print_error(ret));
+       } else {
+               printf("\tPeer's NMI: ");
+               if (mac != NULL) {
+                       __print_mac(mac);
+                       g_free(mac);
+               }
+               printf("\n");
+       }
 
        memcpy(buf, message, 1024);
        buf[len] = '\0';
-       printf("Message: %s\n", buf);
-       printf("Peer's NMI: ");
-       if (mac != NULL) {
-               __print_mac(mac);
-               g_free(mac);
-       }
-       printf("\n");
+       printf("\tMessage: %s\n", buf);
 
+       printf("[Send Message] Request\n");
        g_peer = peer;
-       printf("\n>>Send message\n");
        unsigned char send_message[1024] = {0, };
        size_t message_len = strlen(MSG_PUB_TO_SUB);
        memcpy(send_message, MSG_PUB_TO_SUB, message_len);
        ret = wifi_aware_session_send_message(session, peer, send_message, message_len, __message_result_cb, NULL);
        if (ret != WIFI_AWARE_ERROR_NONE)
-               printf("Fail to send message: %s\n", __print_error(ret));
+               PRINT_FAILURE_ERROR("[Send Message]", ret);
 }
 
 static void __session_terminated_cb(wifi_aware_session_h session,
                wifi_aware_termination_reason_e reason, void *user_data)
 {
-       printf("\n>>Session is terminated\n");
-       printf("session: %p\n", session);
-       printf("reason: %d\n", reason);
+       PRINT_FAILURE("[Event][Session Terminated] Session: %p Reason: %d", session, reason);
 
        if (session != NULL) {
                wifi_aware_session_unset_message_received_cb(session);
@@ -409,11 +401,11 @@ static bool __set_publish_config(wifi_aware_publish_h publish)
 
        ret = wifi_aware_publish_set_type(publish, g_pub_type);
        if (ret == WIFI_AWARE_ERROR_NONE) {
-               printf("publish type: %s\n", g_pub_type == WIFI_AWARE_PUBLISH_TYPE_UNSOLICITED ? 
+               printf("\tPublish Type: %s\n", g_pub_type == WIFI_AWARE_PUBLISH_TYPE_UNSOLICITED ? 
                                "Unsolicited" : "Solicited");
        }
        else {
-               printf("Fail to set publish type\n");
+               PRINT_FAILURE_ERROR("\tPublish Type:", ret);
                return false;
        }
 
@@ -421,10 +413,10 @@ static bool __set_publish_config(wifi_aware_publish_h publish)
        ret = wifi_aware_publish_set_service_name(publish,
                        service_name);
        if (ret == WIFI_AWARE_ERROR_NONE) {
-               printf("service name: %s\n", SERVICE_NAME);
+               printf("\tService Name: %s\n", SERVICE_NAME);
        }
        else {
-               printf("Fail to set service name\n");
+               PRINT_FAILURE_ERROR("\tService Name:", ret);
                return false;
        }
 
@@ -433,20 +425,20 @@ static bool __set_publish_config(wifi_aware_publish_h publish)
        ret = wifi_aware_publish_set_service_specific_info(publish,
                        specific_info, len);
        if (ret == WIFI_AWARE_ERROR_NONE) {
-               printf("service service specific info: ");
+               printf("\tService Specific Info: ");
                __print_byte_array(specific_info, len);
        }
        else {
-               printf("Fail to set service specific info\n");
+               PRINT_FAILURE_ERROR("\tService Specific Info:", ret);
                return false;
        }
 
        ret = wifi_aware_publish_enable_ranging(publish, g_ranging);
        if (ret == WIFI_AWARE_ERROR_NONE) {
-               printf("Ranging: %d\n", g_ranging);
+               printf("\tRanging: %s\n", g_ranging ? "Enable" : "Disable");
        }
        else {
-               printf("Fail to enable ranging\n");
+               PRINT_FAILURE_ERROR("\tRanging:", ret);
                return false;
        }
        return true;
@@ -455,34 +447,41 @@ static bool __set_publish_config(wifi_aware_publish_h publish)
 static void __enabled_cb(wifi_aware_error_e error, void *user_data)
 {
        if (error == WIFI_AWARE_ERROR_NONE) {
-               printf("\n>>Wi-Fi Aware is enabled\n");
+               PRINT_SUCCESS("[CB][Enable] Enabled");
        }
        else {
-               printf("\n>>Wi-Fi Aware is not enabled. Error: %s\n", __print_error(error));
+               PRINT_FAILURE_ERROR("[CB][Enable]", error);
                return;
        }
 
+       printf("[Session][Publish] Create\n");
        int ret = wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_wifi_aware_session);
-       __print_result(ret, "create publish session");
-       printf("session: %p\n", g_wifi_aware_session);
+       if (ret == WIFI_AWARE_ERROR_NONE)
+               printf("\tSession: %p\n", g_wifi_aware_session);
+       else
+               PRINT_FAILURE_ERROR("\tSession:", ret);
 
        ret = wifi_aware_publish_create(&g_publish_handle);
-       __print_result(ret, "create publish configurations");
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               PRINT_FAILURE_ERROR("\tPublish Config:", ret);
 
        if (__set_publish_config(g_publish_handle) == false) {
-               printf(MAKE_RED"Fail to set publish configurations"RESET_COLOR"\n");
+               PRINT_FAILURE("\tPublish Config: Failure");
                return;
        }
 
        ret = wifi_aware_session_set_message_received_cb(g_wifi_aware_session, __message_received_cb, NULL);
-       __print_result(ret, "set message_received_cb");
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               PRINT_FAILURE_ERROR("\tMessage Received CB:", ret);
 
        ret = wifi_aware_session_set_terminated_cb(g_wifi_aware_session, __session_terminated_cb, NULL);
-       __print_result(ret, "set session terminated callback");
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               PRINT_FAILURE_ERROR("\tSession Terminated CB:", ret);
 
-       printf("\n>>Publish a service\n");
+       printf("[Publish] Request\n");
        ret = wifi_aware_session_publish(g_wifi_aware_session, g_publish_handle, __published_cb, NULL);
-       __print_result(ret, "publish service");
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               PRINT_FAILURE_ERROR("[Publish]", ret);
 }
 
 void run_common()
@@ -491,7 +490,8 @@ void run_common()
        RET_IF_LOOP_IS_NULL();
 
        ret = wifi_aware_enable(__enabled_cb, NULL);
-       __print_result(ret, "enable Wi-Fi Aware");
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               PRINT_FAILURE_ERROR("[Enable]", ret);
 }
 
 void clear_resources()
@@ -577,7 +577,10 @@ void test_init()
        RET_IF_LOOP_IS_NULL();
 
        ret = wifi_aware_initialize();
-       __print_result(ret, "wifi_aware_initialize");
+       if (ret == WIFI_AWARE_ERROR_NONE)
+               PRINT_SUCCESS("[Initialize] Success");
+       else
+               PRINT_FAILURE_ERROR("[Initialize]", ret);
 }
 
 typedef void (*test_func)(void);
index e09b21c3813acb5b5adaed7040fbfe3bbbf13db0..260f61fb7c1ec796e53ca0f0ba2b1caf4cdc35dd 100644 (file)
                } \
        } while (0)
 
+#define PRINT_SUCCESS(format, args...) printf(MAKE_GREEN format RESET_COLOR "\n", ##args)
+#define PRINT_FAILURE(format, args...) printf(MAKE_RED format RESET_COLOR "\n", ##args)
+#define PRINT_FAILURE_ERROR(format, error) printf(MAKE_RED format " Failure(%d:%s)" RESET_COLOR "\n", error, __print_error(error))
+
 #define SERVICE_NAME "Wi-Fi Aware Test"
 #define PUB_SSI "Extra bytes in the subscriber discovery"
 #define MSG_SUB_TO_PUB "Let's talk"
@@ -204,16 +208,6 @@ const char *__print_error(wifi_aware_error_e err)
        }
 }
 
-static void __print_result(int ret, gchar *msg)
-{
-    if (ret == WIFI_AWARE_ERROR_NONE) {
-        printf(MAKE_GREEN"success to %s"RESET_COLOR"\n", msg);
-    } else {
-        printf(MAKE_RED"fail to %s: %s ", msg, __print_error(ret));
-        printf(RESET_COLOR"\n");
-    }
-}
-
 static void __print_mac(unsigned char mac[6])
 {
        printf(MACSTR, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
@@ -255,19 +249,16 @@ void test_quit()
 static void __subscribed_cb(wifi_aware_session_h session,
                wifi_aware_error_e error, void *user_data)
 {
-       if (error == WIFI_AWARE_ERROR_NONE) {
-               printf("Subscribe Request is success.\n");
+       if (error == WIFI_AWARE_ERROR_NONE)
+               PRINT_SUCCESS("[CB][Subscribe] Requested");
+       else
+               PRINT_FAILURE_ERROR("[CB][Subscribe]", error);
        }
-       else {
-               printf("Subscribe Request fails. Error: %s\n", __print_error(error));
-               return;
-       }
-}
 
 static void __data_path_terminated_cb(wifi_aware_data_path_h data_path,
                wifi_aware_termination_reason_e reason, void *user_data)
 {
-       printf("\n>>Data path(%p) is terminated.\n", data_path);
+       printf("[EVENT][DataPath Terminated] %p", data_path);
        if (data_path != NULL) {
                wifi_aware_data_path_unset_terminated_cb(data_path);
                wifi_aware_data_path_destroy(data_path);
@@ -279,35 +270,34 @@ static void __open_cb(wifi_aware_data_path_h data_path, wifi_aware_error_e error
        if (error == WIFI_AWARE_ERROR_NONE) {
                int ret = WIFI_AWARE_ERROR_NONE;
                char *interface;
-               printf("\n>>Data path is established. NDP: %p\n", data_path);
+               PRINT_SUCCESS("[CB][OpenDataPath] Requested %p", data_path);
                ret = wifi_aware_data_path_get_interface(data_path, &interface);
                if (ret == WIFI_AWARE_ERROR_NONE)
-                       printf("Interface: %s\n", interface);
+                       printf("\tInterface: %s\n", interface);
                else
-                       printf("Fail to get interface\n");
+                       PRINT_FAILURE_ERROR("\tInterface:", ret);
 
                char *ipv6_address;
                int port;
                ret = wifi_aware_data_path_get_peer_ipv6_address(data_path, &ipv6_address);
                if (ret == WIFI_AWARE_ERROR_NONE)
-                       printf("IPv6 Address of Peer: %s\n", ipv6_address);
+                       printf("\tPeer's IPv6 Address: %s\n", ipv6_address);
                else
-                       printf("Fail to get IPV6 Address\n");
+                       PRINT_FAILURE_ERROR("\tPeer's IPv6 Address:", ret);
                ret = wifi_aware_data_path_get_peer_port(data_path, &port);
                if (ret == WIFI_AWARE_ERROR_NONE)
-                       printf("Port number of Peer: %d\n", port);
+                       printf("\tPeer's Port: %d\n", port);
                else
-                       printf("Fail to get Port number\n");
+                       PRINT_FAILURE_ERROR("\tPeer's Port:", ret);
        }
        else {
-               printf("\n>>Fail to open Data path. data path: %p. error: %s\n", data_path, __print_error(error));
+               PRINT_FAILURE("[CB][OpenDataPath Requested] Failure(%d:%s) %p", error, __print_error(error), data_path);
        }
-
 }
 
 static void __open_data_path(wifi_aware_session_h session)
 {
-       printf("\n>>Open Data Path\n");
+       printf("[OpenDataPath] Request\n");
        if (g_peer == NULL) {
                printf("Peer is NULL\n");
                return;
@@ -315,23 +305,23 @@ static void __open_data_path(wifi_aware_session_h session)
 
        int ret = wifi_aware_data_path_create(session, g_peer, &g_ndp);
        if (ret != WIFI_AWARE_ERROR_NONE) {
-               printf("Fail to create data path: %s\n", __print_error(ret));
+               PRINT_FAILURE_ERROR("\tHandle:", ret);
                return;
        }
-       printf("data path: %p\n", g_ndp);
+       printf("\tHandle: %p\n", g_ndp);
 
        ret = wifi_aware_data_path_set_terminated_cb(g_ndp, __data_path_terminated_cb, NULL);
        if (ret != WIFI_AWARE_ERROR_NONE) {
-               printf("Fail to create data path: %s\n", __print_error(ret));
+               PRINT_FAILURE_ERROR("\tSet TerminatedCallback:", ret);
                return;
        }
 
        ret = wifi_aware_data_path_set_security(g_ndp, g_security_type);
        if (ret != WIFI_AWARE_ERROR_NONE) {
-               printf("Fail to set security type for data path: %s\n", __print_error(ret));
+               PRINT_FAILURE_ERROR("\tSecurity Type:", ret);
                return;
        }
-       printf("security type: ");
+       printf("\tSecurity Type: ");
        switch (g_security_type) {
        case WIFI_AWARE_SECURITY_TYPE_OPEN:
                printf("Open\n");
@@ -344,19 +334,22 @@ static void __open_data_path(wifi_aware_session_h session)
                printf("PMK\n");
                break;
        default:
-               printf("Unknown security type\n");
+               PRINT_FAILURE("Unknown security type");
                return;
        }
 
        ret = wifi_aware_data_path_open(g_ndp, __open_cb, NULL);
        if (ret != WIFI_AWARE_ERROR_NONE) {
-               printf("Fail to open data path: %s\n", __print_error(ret));
+               PRINT_FAILURE_ERROR("[OpenDataPath]", ret);
        }
 }
 
 static void __message_result_cb(wifi_aware_session_h session, wifi_aware_error_e error, void *user_data)
 {
-       printf("\n>>Result of sending message: %d(%s)\n", error, __print_error(error));
+       if (error == WIFI_AWARE_ERROR_NONE)
+               PRINT_SUCCESS("[CB][Send Message] Requested");
+       else
+               PRINT_FAILURE_ERROR("[CB][Send Message]", error);
 }
 
 static void __message_received_cb(wifi_aware_session_h session, wifi_aware_peer_h peer,
@@ -366,20 +359,22 @@ static void __message_received_cb(wifi_aware_session_h session, wifi_aware_peer_
        char buf[1024] = {0, };
        unsigned char *mac = NULL;
 
-       printf("\n>>Receive message from a Wi-Fi Aware Peer\n");
+       printf("[Event][Receive Message]\n");
 
-       if (wifi_aware_peer_get_mac(peer, &mac) != WIFI_AWARE_ERROR_NONE)
-               printf("Fail to get Peer's NMI: %s\n", __print_error(ret));
+       if (wifi_aware_peer_get_mac(peer, &mac) != WIFI_AWARE_ERROR_NONE) {
+               printf("\tPeer's NMI: Failure(%d:%s)\n", ret, __print_error(ret));
+       } else {
+               printf("\tPeer's NMI: ");
+               if (mac != NULL) {
+                       __print_mac(mac);
+                       g_free(mac);
+               }
+               printf("\n");
+       }
 
        memcpy(buf, message, 1024);
        buf[len] = '\0';
-       printf("Message: %s\n", buf);
-       printf("Peer's NMI: ");
-       if (mac != NULL) {
-               __print_mac(mac);
-               g_free(mac);
-       }
-       printf("\n");
+       printf("\tMessage: %s\n", buf);
 
        g_peer = peer;
        __open_data_path(session);
@@ -390,30 +385,42 @@ static void __service_discovered_cb(wifi_aware_session_h session,
                const unsigned char *service_specific_info, size_t service_specific_info_len,
                int distance, void *user_data)
 {
-       printf("\n>>Find A Wi-Fi Aware Peer %p\n", peer);
-       printf("Service Specific Info: ");
+       unsigned char *mac = NULL;
+       int ret = 0;
+
+       PRINT_SUCCESS("[Event][Serivce Discovered]");
+       ret = wifi_aware_peer_get_mac(peer, &mac);
+       if (ret != WIFI_AWARE_ERROR_NONE) {
+               printf("\tPeer's NMI: Failure(%d:%s)\n", ret, __print_error(ret));
+       } else {
+               printf("\tPeer's NMI: ");
+               if (mac != NULL) {
+                       __print_mac(mac);
+                       g_free(mac);
+               }
+               printf("\n");
+       }
+       printf("\tService Specific Info(%d): ", service_specific_info_len);
        __print_byte_array(service_specific_info, service_specific_info_len);
        printf("\n");
-       printf("Distance: %d\n", distance);
+       printf("\tDistance: %d\n", distance);
 
        if (g_service_discovered == false) {
                g_service_discovered = true;
-               printf("\n>>Send message\n");
+               printf("[Send Message] Request\n");
                unsigned char send_message[1024] = {0, };
                size_t message_len = strlen(MSG_SUB_TO_PUB);
                memcpy(send_message, MSG_SUB_TO_PUB, message_len);
                int ret = wifi_aware_session_send_message(session, peer, send_message, message_len, __message_result_cb, NULL);
                if (ret != WIFI_AWARE_ERROR_NONE)
-                       printf("Fail to send message: %s\n", __print_error(ret));
+                       PRINT_FAILURE_ERROR("[Send Message]", ret);
        }
 }
 
 static void __session_terminated_cb(wifi_aware_session_h session,
                wifi_aware_termination_reason_e reason, void *user_data)
 {
-       printf("\n>>Session is terminated\n");
-       printf("session: %p\n", session);
-       printf("reason: %d\n", reason);
+       PRINT_FAILURE("[Event][Session Terminated] Session: %p Reason: %d", session, reason);
 
        if (session != NULL) {
                wifi_aware_session_unset_message_received_cb(session);
@@ -429,11 +436,11 @@ static bool __set_subscribe_config(wifi_aware_subscribe_h subscribe)
 
        ret = wifi_aware_subscribe_set_type(subscribe, g_sub_type);
        if (ret == WIFI_AWARE_ERROR_NONE) {
-               printf("subscribe type: %s\n", g_sub_type == WIFI_AWARE_SUBSCRIBE_TYPE_PASSIVE ? 
-                               "Unactive" : "Solicited");
+               printf("\tSubscribe Type: %s\n", g_sub_type == WIFI_AWARE_SUBSCRIBE_TYPE_PASSIVE ? 
+                               "Passive" : "Active");
        }
        else {
-               printf("Fail to set subscribe type\n");
+               PRINT_FAILURE_ERROR("\tSubscribe Type:", ret);
                return false;
        }
 
@@ -441,10 +448,10 @@ static bool __set_subscribe_config(wifi_aware_subscribe_h subscribe)
        ret = wifi_aware_subscribe_set_service_name(subscribe,
                        service_name);
        if (ret == WIFI_AWARE_ERROR_NONE) {
-               printf("service name: %s\n", SERVICE_NAME);
+               printf("\tService Name: %s\n", SERVICE_NAME);
        }
        else {
-               printf("Fail to set service name\n");
+               PRINT_FAILURE_ERROR("\tService Name:", ret);
                return false;
        }
 
@@ -453,31 +460,31 @@ static bool __set_subscribe_config(wifi_aware_subscribe_h subscribe)
        ret = wifi_aware_subscribe_set_service_specific_info(subscribe,
                        specific_info, len);
        if (ret == WIFI_AWARE_ERROR_NONE) {
-               printf("service service specific info: ");
+               printf("\tService Specific Info: ");
                __print_byte_array(specific_info, len);
        }
        else {
-               printf("Fail to set service specific info\n");
+               PRINT_FAILURE_ERROR("\tService Specific Info:", ret);
                return false;
        }
 
        if (g_min_distance >= 0) {
                ret = wifi_aware_subscribe_set_min_distance(subscribe, g_min_distance);
                if (ret == WIFI_AWARE_ERROR_NONE) {
-                       printf("min distance: %d\n", g_min_distance);
+                       printf("\tMin Distance: %d\n", g_min_distance);
                }
                else {
-                       printf("Fail to set min distance\n");
+                       PRINT_FAILURE_ERROR("\tMin Distance:", ret);
                        return false;
                }
        }
        if (g_max_distance > 0) {
                ret = wifi_aware_subscribe_set_max_distance(subscribe, g_max_distance);
                if (ret == WIFI_AWARE_ERROR_NONE) {
-                       printf("max distance: %d\n", g_max_distance);
+                       printf("\tMax Distance: %d\n", g_min_distance);
                }
                else {
-                       printf("Fail to set max distance\n");
+                       PRINT_FAILURE_ERROR("\tMax Distance:", ret);
                        return false;
                }
        }
@@ -487,38 +494,46 @@ static bool __set_subscribe_config(wifi_aware_subscribe_h subscribe)
 static void __enabled_cb(wifi_aware_error_e error, void *user_data)
 {
        if (error == WIFI_AWARE_ERROR_NONE) {
-               printf("\n>>Wi-Fi Aware is enabled\n");
+               PRINT_SUCCESS("[CB][Enable] Enabled");
        }
        else {
-               printf("\n>>Wi-Fi Aware is not enabled. Error: %s\n", __print_error(error));
+               PRINT_FAILURE_ERROR("[CB][Enable]", error);
                return;
        }
 
+       printf("[Session][Subscribe] Create\n");
        int ret = wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_wifi_aware_session);
-       __print_result(ret, "create subscribe session");
-       printf("session: %p\n", g_wifi_aware_session);
+       if (ret == WIFI_AWARE_ERROR_NONE)
+               printf("\tSession: %p\n", g_wifi_aware_session);
+       else
+               PRINT_FAILURE_ERROR("\tSession:", ret);
 
        ret = wifi_aware_subscribe_create(&g_subscribe_handle);
-       __print_result(ret, "create subscribe configurations");
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               PRINT_FAILURE_ERROR("\tSubscribe Config:", ret);
 
        if (__set_subscribe_config(g_subscribe_handle) == false) {
-               printf(MAKE_RED"Fail to set subscribe configurations"RESET_COLOR"\n");
+               PRINT_FAILURE("\tSubscribeConfig: Failure");
                return;
        }
 
        g_service_discovered = false;
        ret = wifi_aware_session_set_service_discovered_cb(g_wifi_aware_session, __service_discovered_cb, NULL);
-       __print_result(ret, "set service_discovered_cb");
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               PRINT_FAILURE_ERROR("\tService Discovered CB:", ret);
 
        ret = wifi_aware_session_set_message_received_cb(g_wifi_aware_session, __message_received_cb, NULL);
-       __print_result(ret, "set message_received_cb");
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               PRINT_FAILURE_ERROR("\tMessage Received CB:", ret);
 
        ret = wifi_aware_session_set_terminated_cb(g_wifi_aware_session, __session_terminated_cb, NULL);
-       __print_result(ret, "set session terminated callback");
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               PRINT_FAILURE_ERROR("\tSession Terminated CB:", ret);
 
-       printf("\n>>Publish a service\n");
+       printf("[Subscribe] Request\n");
        ret = wifi_aware_session_subscribe(g_wifi_aware_session, g_subscribe_handle, __subscribed_cb, NULL);
-       __print_result(ret, "subscribe service");
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               PRINT_FAILURE_ERROR("[Subscribe]", ret);
 }
 
 void run_common()
@@ -527,7 +542,8 @@ void run_common()
        RET_IF_LOOP_IS_NULL();
 
        ret = wifi_aware_enable(__enabled_cb, NULL);
-       __print_result(ret, "enable Wi-Fi Aware");
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               PRINT_FAILURE_ERROR("[Enable]", ret);
 }
 
 void clear_resources()
@@ -636,7 +652,10 @@ void test_init()
        RET_IF_LOOP_IS_NULL();
 
        ret = wifi_aware_initialize();
-       __print_result(ret, "wifi_aware_initialize");
+       if (ret == WIFI_AWARE_ERROR_NONE)
+               PRINT_SUCCESS("[Initialize] Success");
+       else
+               PRINT_FAILURE_ERROR("[Initialize]", ret);
 }
 
 typedef void (*test_func)(void);