aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-11-01 22:02:16 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-11-01 22:02:16 +0000
commit4d501ee10c63e2edc044d6bcdb8ba060f78b34e5 (patch)
tree1bf7dca53ed163cf9f7acdd4e9a9e9e7a1f75ccc /src/testing
parent71cc3e168ae8b07413645ff4a8be8bfe5b732cf7 (diff)
downloadgnunet-4d501ee10c63e2edc044d6bcdb8ba060f78b34e5.tar.gz
gnunet-4d501ee10c63e2edc044d6bcdb8ba060f78b34e5.zip
fix crashing checks
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/test_testing_peerstartup.c57
-rw-r--r--src/testing/test_testing_portreservation.c18
2 files changed, 52 insertions, 23 deletions
diff --git a/src/testing/test_testing_peerstartup.c b/src/testing/test_testing_peerstartup.c
index 7f78827f6..1de3d5b35 100644
--- a/src/testing/test_testing_peerstartup.c
+++ b/src/testing/test_testing_peerstartup.c
@@ -33,6 +33,10 @@
33#define LOG(kind,...) \ 33#define LOG(kind,...) \
34 GNUNET_log (kind, __VA_ARGS__) 34 GNUNET_log (kind, __VA_ARGS__)
35 35
36/**
37 * The status of the test
38 */
39int status;
36 40
37/** 41/**
38 * The testing context 42 * The testing context
@@ -67,10 +71,16 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
67{ 71{
68 struct TestingContext *test_ctx = cls; 72 struct TestingContext *test_ctx = cls;
69 73
70 GNUNET_assert (GNUNET_OK == GNUNET_TESTING_peer_stop (test_ctx->peer)); 74 GNUNET_assert (NULL != test_ctx);
71 GNUNET_TESTING_peer_destroy (test_ctx->peer); 75 if (NULL != test_ctx->peer)
72 GNUNET_CONFIGURATION_destroy (test_ctx->cfg); 76 {
73 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); 77 (void) GNUNET_TESTING_peer_stop (test_ctx->peer);
78 GNUNET_TESTING_peer_destroy (test_ctx->peer);
79 }
80 if (NULL != test_ctx->cfg)
81 GNUNET_CONFIGURATION_destroy (test_ctx->cfg);
82 if (NULL != test_ctx->system)
83 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES);
74 GNUNET_free (test_ctx); 84 GNUNET_free (test_ctx);
75} 85}
76 86
@@ -82,26 +92,33 @@ static void
82run (void *cls, char *const *args, const char *cfgfile, 92run (void *cls, char *const *args, const char *cfgfile,
83 const struct GNUNET_CONFIGURATION_Handle *cfg) 93 const struct GNUNET_CONFIGURATION_Handle *cfg)
84{ 94{
85 struct GNUNET_TESTING_System *system;
86 struct GNUNET_TESTING_Peer *peer;
87 struct GNUNET_CONFIGURATION_Handle *new_cfg;
88 struct TestingContext *test_ctx; 95 struct TestingContext *test_ctx;
89 char *emsg; 96 char *emsg;
90 struct GNUNET_PeerIdentity id; 97 struct GNUNET_PeerIdentity id;
91 98
92 system = GNUNET_TESTING_system_create ("test-gnunet-testing",
93 "127.0.0.1", NULL);
94 GNUNET_assert (NULL != system);
95 new_cfg = GNUNET_CONFIGURATION_dup (cfg);
96 emsg = NULL;
97 peer = GNUNET_TESTING_peer_configure (system, new_cfg, 0, &id, &emsg);
98 GNUNET_assert (NULL != peer);
99 GNUNET_assert (NULL == emsg);
100 GNUNET_assert (GNUNET_OK == GNUNET_TESTING_peer_start (peer));
101 test_ctx = GNUNET_malloc (sizeof (struct TestingContext)); 99 test_ctx = GNUNET_malloc (sizeof (struct TestingContext));
102 test_ctx->system = system; 100 test_ctx->system =
103 test_ctx->peer = peer; 101 GNUNET_TESTING_system_create ("test-gnunet-testing",
104 test_ctx->cfg = new_cfg; 102 "127.0.0.1", NULL);
103 if (NULL == test_ctx->system)
104 goto end;
105 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
106 emsg = NULL;
107 test_ctx->peer =
108 GNUNET_TESTING_peer_configure (test_ctx->system,
109 test_ctx->cfg,
110 0, &id, &emsg);
111 if (NULL == test_ctx->peer)
112 {
113 if (NULL != emsg)
114 printf ("Test failed upon error: %s", emsg);
115 goto end;
116 }
117 if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer))
118 goto end;
119 status = GNUNET_OK;
120
121 end:
105 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx); 122 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx);
106} 123}
107 124
diff --git a/src/testing/test_testing_portreservation.c b/src/testing/test_testing_portreservation.c
index 664031633..9a69916fa 100644
--- a/src/testing/test_testing_portreservation.c
+++ b/src/testing/test_testing_portreservation.c
@@ -33,6 +33,11 @@
33 GNUNET_log (kind, __VA_ARGS__) 33 GNUNET_log (kind, __VA_ARGS__)
34 34
35/** 35/**
36 * The status of the test
37 */
38int status;
39
40/**
36 * Main point of test execution 41 * Main point of test execution
37 */ 42 */
38static void 43static void
@@ -50,11 +55,13 @@ run (void *cls, char *const *args, const char *cfgfile,
50 new_port1 = GNUNET_TESTING_reserve_port (system, GNUNET_YES); 55 new_port1 = GNUNET_TESTING_reserve_port (system, GNUNET_YES);
51 LOG (GNUNET_ERROR_TYPE_DEBUG, 56 LOG (GNUNET_ERROR_TYPE_DEBUG,
52 "Reserved TCP port %u\n", new_port1); 57 "Reserved TCP port %u\n", new_port1);
53 GNUNET_assert (0 != new_port1); 58 if (0 == new_port1)
59 goto end;
54 new_port2 = GNUNET_TESTING_reserve_port (system, GNUNET_YES); 60 new_port2 = GNUNET_TESTING_reserve_port (system, GNUNET_YES);
55 LOG (GNUNET_ERROR_TYPE_DEBUG, 61 LOG (GNUNET_ERROR_TYPE_DEBUG,
56 "Reserved TCP port %u\n", new_port2); 62 "Reserved TCP port %u\n", new_port2);
57 GNUNET_assert (0 != new_port2); 63 if (0 == new_port2)
64 goto end;
58 GNUNET_assert (new_port1 != new_port2); 65 GNUNET_assert (new_port1 != new_port2);
59 GNUNET_TESTING_release_port (system, GNUNET_YES, new_port1); 66 GNUNET_TESTING_release_port (system, GNUNET_YES, new_port1);
60 old_port1 = new_port1; 67 old_port1 = new_port1;
@@ -66,6 +73,9 @@ run (void *cls, char *const *args, const char *cfgfile,
66 GNUNET_assert (old_port1 == new_port1); 73 GNUNET_assert (old_port1 == new_port1);
67 GNUNET_TESTING_release_port (system, GNUNET_YES, new_port1); 74 GNUNET_TESTING_release_port (system, GNUNET_YES, new_port1);
68 GNUNET_TESTING_release_port (system, GNUNET_YES, new_port2); 75 GNUNET_TESTING_release_port (system, GNUNET_YES, new_port2);
76 status = GNUNET_OK;
77
78 end:
69 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 79 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
70} 80}
71 81
@@ -75,6 +85,8 @@ int main (int argc, char *argv[])
75 struct GNUNET_GETOPT_CommandLineOption options[] = { 85 struct GNUNET_GETOPT_CommandLineOption options[] = {
76 GNUNET_GETOPT_OPTION_END 86 GNUNET_GETOPT_OPTION_END
77 }; 87 };
88
89 status = GNUNET_SYSERR;
78 if (GNUNET_OK != 90 if (GNUNET_OK !=
79 GNUNET_PROGRAM_run (argc, 91 GNUNET_PROGRAM_run (argc,
80 argv, 92 argv,
@@ -87,7 +99,7 @@ int main (int argc, char *argv[])
87 { 99 {
88 return 1; 100 return 1;
89 } 101 }
90 return 0; 102 return (GNUNET_OK == status) ? 0 : 1;
91} 103}
92 104
93/* end of test_testing_portreservation.c */ 105/* end of test_testing_portreservation.c */