2 execute_tests.c -- Utility functions for black box test execution
3 Copyright (C) 2018 Guus Sliepen <guus@meshlink.io>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "execute_tests.h"
26 #include "../common/common_handlers.h"
27 #include "../common/containers.h"
28 #include "../common/test_step.h"
30 int setup_test(void **state) {
33 fprintf(stderr, "Setting up Containers\n");
34 state_ptr = (black_box_state_t *)(*state);
36 for(i = 0; i < state_ptr->num_nodes; i++) {
37 meta_conn_status[i] = false;
38 node_reachable_status[i] = false;
41 setup_containers(state);
46 void execute_test(test_step_func_t step_func, void **state) {
47 black_box_state_t *test_state = (black_box_state_t *)(*state);
49 fprintf(stderr, "\n\x1b[32mRunning Test\x1b[0m : \x1b[34m%s\x1b[0m\n", test_state->test_case_name);
50 test_state->test_result = step_func();
52 if(!test_state->test_result) {
57 int teardown_test(void **state) {
58 black_box_state_t *test_state = (black_box_state_t *)(*state);
59 char container_old_name[100], container_new_name[100];
62 if(test_state->test_result) {
63 PRINT_TEST_CASE_MSG("Test successful! Shutting down nodes.\n");
65 for(i = 0; i < test_state->num_nodes; i++) {
67 node_step_in_container(test_state->node_names[i], "SIGTERM");
68 /* Rename Container to run_<node-name> - this allows it to be re-used for the
69 next test, otherwise it will be ignored assuming that it has been saved
71 assert(snprintf(container_old_name, sizeof(container_old_name), "%s_%s",
72 test_state->test_case_name, test_state->node_names[i]) >= 0);
73 assert(snprintf(container_new_name, sizeof(container_new_name), "run_%s",
74 test_state->node_names[i]) >= 0);
75 rename_container(container_old_name, container_new_name);