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.
29 #include "execute_tests.h"
30 #include "../common/common_handlers.h"
31 #include "../common/containers.h"
32 #include "../common/test_step.h"
34 int setup_test(void **state) {
37 fprintf(stderr, "Setting up Containers\n");
38 state_ptr = (black_box_state_t *)(*state);
40 for(i = 0; i < state_ptr->num_nodes; i++) {
41 meta_conn_status[i] = false;
44 setup_containers(state);
49 void execute_test(test_step_func_t step_func, void **state) {
50 black_box_state_t *test_state = (black_box_state_t *)(*state);
52 fprintf(stderr, "\n\x1b[32mRunning Test\x1b[0m : \x1b[34m%s\x1b[0m\n", test_state->test_case_name);
53 test_state->test_result = step_func();
55 if(!test_state->test_result) {
60 int teardown_test(void **state) {
61 black_box_state_t *test_state = (black_box_state_t *)(*state);
62 char container_old_name[100], container_new_name[100];
65 if(test_state->test_result) {
66 PRINT_TEST_CASE_MSG("Test successful! Shutting down nodes.\n");
68 for(i = 0; i < test_state->num_nodes; i++) {
70 node_step_in_container(test_state->node_names[i], "SIGTERM");
71 /* Rename Container to run_<node-name> - this allows it to be re-used for the
72 next test, otherwise it will be ignored assuming that it has been saved
74 assert(snprintf(container_old_name, sizeof(container_old_name), "%s_%s",
75 test_state->test_case_name, test_state->node_names[i]) >= 0);
76 assert(snprintf(container_new_name, sizeof(container_new_name), "run_%s",
77 test_state->node_names[i]) >= 0);
78 rename_container(container_old_name, container_new_name);
87 bool change_state(node_status_t *status, mesh_event_t currentEv) {
89 if(status->current_index == status->max_events) {
93 if(currentEv == status->expected_events[status->current_index]) {
94 status->current_index = status->current_index + 1;
102 void signal_node_start(node_status_t *node_status, int start, int end, char *node_ids[]) {
105 for(i = start; i <= end; i++) {
106 index = node_status[i].current_index;
108 if(index < 1 || NODE_JOINED != node_status[i].expected_events[index - 1]) {
114 for(i = start; i <= end; i++) {
115 fprintf(stderr, "\tSending signals to '%s'\n", node_ids[i]);
116 node_step_in_container(node_ids[i], "SIGIO");
122 bool check_nodes_finished(node_status_t *node_status, int length) {
123 for(int i = 0; i < length; i++) {
124 if(node_status[i].current_index != node_status[i].max_events) {