]> git.meshlink.io Git - meshlink/blobdiff - test/blackbox/common/test_step.c
Ensure NDEBUG is not set in the test suite.
[meshlink] / test / blackbox / common / test_step.c
index 4a2bf853896886c03d7f9fdeb13dbd91aa359eed..b772b9396c71481e881d453c0d8d66c5598a006b 100644 (file)
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
+#ifdef NDEBUG
+#undef NDEBUG
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
@@ -39,6 +43,7 @@ meshlink_handle_t *execute_open(char *node_name, char *dev_class) {
        /* Create meshlink instance */
        mesh_handle = meshlink_open("testconf", node_name, "node_sim", atoi(dev_class));
        fprintf(stderr, "meshlink_open status: %s\n", meshlink_strerror(meshlink_errno));
+       meshlink_enable_discovery(mesh_handle, false);
        PRINT_TEST_CASE_MSG("meshlink_open status: %s\n", meshlink_strerror(meshlink_errno));
        assert(mesh_handle);
 
@@ -50,8 +55,8 @@ meshlink_handle_t *execute_open(char *node_name, char *dev_class) {
        return mesh_handle;
 }
 
-char *execute_invite(char *invitee) {
-       char *invite_url = meshlink_invite(mesh_handle, invitee);
+char *execute_invite(char *invitee, meshlink_submesh_t *submesh) {
+       char *invite_url = meshlink_invite_ex(mesh_handle, submesh, invitee, MESHLINK_INVITE_LOCAL | MESHLINK_INVITE_NUMERIC);
 
        PRINT_TEST_CASE_MSG("meshlink_invite status: %s\n", meshlink_strerror(meshlink_errno));
        assert(invite_url);
@@ -62,15 +67,7 @@ char *execute_invite(char *invitee) {
 void execute_join(char *invite_url) {
        bool join_status;
 
-       /* The inviting node may take a moment to open its listening port
-           This sleep() prevents meshlink_join() from failing when the listening port is not open */
-       /* TO DO: Replace this with code that actually checks for the port being open, if possible */
-       PRINT_TEST_CASE_MSG("Sleeping 1 sec to allow inviting node to start listening...\n");
-       sleep(1);
-
-       PRINT_TEST_CASE_MSG("About to join with mesh_handle = %p, invite_url = %s\n", mesh_handle, invite_url);
        join_status = meshlink_join(mesh_handle, invite_url);
-       PRINT_TEST_CASE_MSG("meshlink_join status: %s\n", meshlink_strerror(meshlink_errno));
        assert(join_status);
 }
 
@@ -96,18 +93,16 @@ void execute_close(void) {
 void execute_change_ip(void) {
        char *eth_if_ip;
        int last_byte;
-       char new_ip[20], gateway_ip[20];
+       char new_ip[20] = "", gateway_ip[20] = "";
        char *last_dot_in_ip;
        char *eth_if_netmask;
-       char route_chg_command[200];
-       int route_chg_status;
 
        /* Get existing IP Address of Ethernet Bridge Interface */
-       assert(eth_if_ip = get_ip(eth_if_name));
+       assert((eth_if_ip = get_ip(eth_if_name)));
 
        /* Set new IP Address by replacing the last byte with last byte + 1 */
-       strncpy(new_ip, eth_if_ip, sizeof(new_ip));
-       assert(last_dot_in_ip = strrchr(new_ip, '.'));
+       strncpy(new_ip, eth_if_ip, sizeof(new_ip) - 1);
+       assert((last_dot_in_ip = strrchr(new_ip, '.')));
        last_byte = atoi(last_dot_in_ip + 1);
        assert(snprintf(last_dot_in_ip + 1, 4, "%d", (last_byte > 253) ? 2 : (last_byte + 1)) >= 0);
 
@@ -115,7 +110,7 @@ void execute_change_ip(void) {
        /* Bring the network interface down before making changes */
        stop_nw_intf(eth_if_name);
        /* Save the netmask first, then restore it after setting the new IP Address */
-       assert(eth_if_netmask = get_netmask(eth_if_name));
+       assert((eth_if_netmask = get_netmask(eth_if_name)));
        set_ip(eth_if_name, new_ip);
        set_netmask(eth_if_name, eth_if_netmask);
        /* Bring the network interface back up again to apply changes */
@@ -123,8 +118,8 @@ void execute_change_ip(void) {
 
        /* Get Gateway's IP Address, by replacing the last byte with 1 in the current IP Address */
        /* TO DO: Obtain the actual Gateway IP Address */
-       strncpy(gateway_ip, eth_if_ip, sizeof(gateway_ip));
-       assert(last_dot_in_ip = strrchr(gateway_ip, '.'));
+       strncpy(gateway_ip, eth_if_ip, sizeof(gateway_ip) - 1);
+       assert((last_dot_in_ip = strrchr(gateway_ip, '.')));
        assert(snprintf(last_dot_in_ip + 1, 4, "%d", 1) >= 0);
 
        /* Add the default route back again, which would have been deleted when the