aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_start_with_config.c
blob: 4705eb9b23dc4836a9979ce63fe7f6579f4f2522 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
      This file is part of GNUnet
      Copyright (C) 2021 GNUnet e.V.

      GNUnet is free software: you can redistribute it and/or modify it
      under the terms of the GNU Affero General Public License as published
      by the Free Software Foundation, either version 3 of the License,
      or (at your option) any later version.

      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.

      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.

     SPDX-License-Identifier: AGPL3.0-or-later
 */

/**
 * @file transport/test_transport_start_with_config.c
 * @brief Generic program to start testcases in an configurable topology.
 * @author t3sserakt
 */
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
#include "gnunet_testing_netjail_lib.h"
#include "transport-testing-cmds.h"
#include "gnunet_util_lib.h"

#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)


int
main (int argc,
      char *const *argv)
{
  char *topology_data;
  char *topology_data_script;
  struct GNUNET_TESTING_NetjailTopology *topology;
  unsigned int read_file = GNUNET_YES;
  int ret;
  char *rest = NULL;
  char *token;
  size_t single_line_len;
  size_t data_len;

  GNUNET_log_setup ("test-netjail",
                    "DEBUG",
                    NULL);

  if (0 == strcmp ("-s", argv[1]))
  {
    data_len = strlen (argv[2]);
    topology_data = GNUNET_malloc (data_len);
    topology_data_script = GNUNET_malloc (data_len);
    token = strtok_r (argv[2], "\n", &rest);
    while (NULL != token)
    {
      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "token1 %s\n",
                  token);
      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "token2 %s\n",
                  token);
      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "topology_data %s\n",
                  topology_data);
      strcat (topology_data_script, token);
      strcat (topology_data_script, " ");
      strcat (topology_data, token);
      strcat (topology_data, "\n");
      token = strtok_r (NULL, "\n", &rest);
    }
    single_line_len = strlen (topology_data);
    topology_data_script [single_line_len - 1] = '\0';
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "read from string\n");
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "topology_data %s\n",
                topology_data);
    read_file = GNUNET_NO;
    topology = GNUNET_TESTING_get_topo_from_string (topology_data);
  }
  else
  {
    topology_data = argv[1];
    topology_data_script = argv[1];
    topology = GNUNET_TESTING_get_topo_from_file (topology_data);
  }

  struct GNUNET_TESTING_Command commands[] = {
    GNUNET_TESTING_cmd_netjail_start ("netjail-start",
                                      topology_data_script,
                                      &read_file),
    GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed",
                                                     topology,
                                                     &read_file,
                                                     topology_data_script,
                                                     TIMEOUT),
    GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
                                            "netjail-start-testbed",
                                            topology),
    GNUNET_TESTING_cmd_netjail_stop ("netjail-stop",
                                     topology_data_script,
                                     &read_file),
    GNUNET_TESTING_cmd_end ()
  };

  ret = GNUNET_TESTING_main (commands,
                             TIMEOUT);

  if (0 == strcmp ("-s", argv[1]))
  {
    GNUNET_free (topology_data_script);
    GNUNET_free (topology_data);
  }
  GNUNET_TESTING_free_topology (topology);

  return ret;
}