X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Fblackbox%2Frun_blackbox_tests%2Ftest_cases_key_rotation.c;h=8987d7c54d6885d479bcc33e1f63fcd52064ce02;hb=61ab7adcdb4ac160e57ef7b22f56df9676b6381d;hp=2768c80c6e3898ec08ece10794386e15a393fcfd;hpb=3be622ad230c70e9753f9f9737333a2f803b125e;p=meshlink diff --git a/test/blackbox/run_blackbox_tests/test_cases_key_rotation.c b/test/blackbox/run_blackbox_tests/test_cases_key_rotation.c index 2768c80c..8987d7c5 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_key_rotation.c +++ b/test/blackbox/run_blackbox_tests/test_cases_key_rotation.c @@ -17,6 +17,10 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#ifdef NDEBUG +#undef NDEBUG +#endif + #include #include #include @@ -50,19 +54,6 @@ static bool test_key_rotation_04(void); static void test_case_key_rotation_05(void **state); static bool test_key_rotation_05(void); -static void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - - static const char *levelstr[] = { - [MESHLINK_DEBUG] = "\x1b[34mDEBUG", - [MESHLINK_INFO] = "\x1b[32mINFO", - [MESHLINK_WARNING] = "\x1b[33mWARNING", - [MESHLINK_ERROR] = "\x1b[31mERROR", - [MESHLINK_CRITICAL] = "\x1b[31mCRITICAL", - }; - - fprintf(stderr, "%s(%s):\x1b[0m %s\n", mesh->name, levelstr[level], text); -} - /* Execute key rotation Test Case # 1 - Sanity test */ static void test_case_key_rotation_01(void **state) { execute_test(test_key_rotation_01, state); @@ -79,7 +70,7 @@ static void test_case_key_rotation_01(void **state) { */ static bool test_key_rotation_01(void) { meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); // Open a new meshlink instance. @@ -100,7 +91,7 @@ static bool test_key_rotation_01(void) { // Cleanup meshlink_close(mesh); - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); return true; } @@ -122,7 +113,7 @@ static void test_case_key_rotation_02(void **state) { */ static bool test_key_rotation_02(void) { meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); // Open a new meshlink instance. @@ -154,7 +145,7 @@ static bool test_key_rotation_02(void) { // Cleanup meshlink_close(mesh); - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); return true; } @@ -175,7 +166,7 @@ static void test_case_key_rotation_03(void **state) { been changed to new by key rotate API. */ static bool test_key_rotation_03(void) { - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); // Open a new meshlink instance. @@ -197,7 +188,7 @@ static bool test_key_rotation_03(void) { // Cleanup - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); return true; } @@ -233,7 +224,7 @@ static bool test_key_rotation_04(void) { bool join_status; char *invitations_directory_path = "encrypted_conf/current/invitations/"; - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); // Open a new meshlink instance. @@ -319,9 +310,9 @@ static bool test_key_rotation_04(void) { meshlink_close(mesh); meshlink_close(mesh1); meshlink_close(mesh2); - meshlink_destroy("encrypted_conf"); - meshlink_destroy("encrypted_conf.1"); - meshlink_destroy("encrypted_conf.2"); + assert(meshlink_destroy("encrypted_conf")); + assert(meshlink_destroy("encrypted_conf.1")); + assert(meshlink_destroy("encrypted_conf.2")); return true; } @@ -334,6 +325,8 @@ static void test_case_key_rotation_05(void **state) { static int break_stage; static void nop_stage(int stage) { + (void)stage; + return; } @@ -342,7 +335,7 @@ static void debug_probe(int stage) { // Terminate the node at the specified stage (by @ break_stage @ ) if(stage == break_stage) { raise(SIGINT); - } else if((break_stage < 1) || (break_stage > 11)) { + } else if((break_stage < 1) || (break_stage > 3)) { fprintf(stderr, "INVALID stage break\n"); raise(SIGABRT); } @@ -367,7 +360,7 @@ static bool test_key_rotation_05(void) { pid_t pid; int status; meshlink_handle_t *mesh; - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); assert(signal(SIGINT, SIG_DFL) != SIG_ERR); @@ -381,9 +374,9 @@ static bool test_key_rotation_05(void) { // incrementally debug meshlink_encrypted_key_rotate API atomicity - for(break_stage = 1; break_stage <= 10; break_stage += 1) { + for(break_stage = 1; break_stage <= 3; break_stage += 1) { fprintf(stderr, "Debugging stage %d\n", break_stage); - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); assert(pipe(pipefd) != -1); @@ -404,7 +397,7 @@ static bool test_key_rotation_05(void) { assert(write(pipefd[1], invitation, strlen(invitation) + 1) != -1); - meshlink_encrypted_key_rotate(mesh, "newkey", 6); + assert(meshlink_encrypted_key_rotate(mesh, "newkey", 6)); raise(SIGABRT); } @@ -448,15 +441,11 @@ static bool test_key_rotation_05(void) { assert(meshlink_start(mesh)); - meshlink_destroy("encrypted_conf.1"); - - set_sync_flag(&status_changed_cond, false); - bar_reachable = false; + assert(meshlink_destroy("encrypted_conf.1")); meshlink_handle_t *mesh2 = meshlink_open("encrypted_conf.1", "bar", "bar", DEV_CLASS_BACKBONE); assert(mesh2); - meshlink_set_node_status_cb(mesh2, node_status_cb); meshlink_set_log_cb(mesh2, MESHLINK_DEBUG, log_cb); meshlink_enable_discovery(mesh2, false); @@ -472,8 +461,8 @@ static bool test_key_rotation_05(void) { // Cleanup - meshlink_destroy("encrypted_conf"); - meshlink_destroy("encrypted_conf.1"); + assert(meshlink_destroy("encrypted_conf")); + assert(meshlink_destroy("encrypted_conf.1")); devtool_keyrotate_probe = nop_stage; return true; }