aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-05-31 10:40:36 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-05-31 10:40:36 +0000
commit87df203c4b021746b5a4ff626243f71af7874e6c (patch)
tree42da2bb0af1a29b21f189f54bb6f2e882865a4fb /src/testing
parentac637c3061ba5dbeb71da8b3586dbb968606dc80 (diff)
downloadgnunet-87df203c4b021746b5a4ff626243f71af7874e6c.tar.gz
gnunet-87df203c4b021746b5a4ff626243f71af7874e6c.zip
-fixed memory leaks and added windows support for temp dirs
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/test_testing_new_peerstartup.c29
-rw-r--r--src/testing/testing_new.c3
2 files changed, 27 insertions, 5 deletions
diff --git a/src/testing/test_testing_new_peerstartup.c b/src/testing/test_testing_new_peerstartup.c
index 18d8217a1..3793e8436 100644
--- a/src/testing/test_testing_new_peerstartup.c
+++ b/src/testing/test_testing_new_peerstartup.c
@@ -50,6 +50,11 @@ struct TestingContext
50 * The peer which has been started by the testing system 50 * The peer which has been started by the testing system
51 */ 51 */
52 struct GNUNET_TESTING_Peer *peer; 52 struct GNUNET_TESTING_Peer *peer;
53
54 /**
55 * The running configuration of the peer
56 */
57 struct GNUNET_CONFIGURATION_Handle *cfg;
53}; 58};
54 59
55 60
@@ -66,6 +71,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
66 71
67 GNUNET_assert (GNUNET_OK == GNUNET_TESTING_peer_stop (test_ctx->peer)); 72 GNUNET_assert (GNUNET_OK == GNUNET_TESTING_peer_stop (test_ctx->peer));
68 GNUNET_TESTING_peer_destroy (test_ctx->peer); 73 GNUNET_TESTING_peer_destroy (test_ctx->peer);
74 GNUNET_CONFIGURATION_destroy (test_ctx->cfg);
69 GNUNET_TESTING_hostkeys_unload (test_ctx->system); 75 GNUNET_TESTING_hostkeys_unload (test_ctx->system);
70 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); 76 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES);
71 GNUNET_free (test_ctx); 77 GNUNET_free (test_ctx);
@@ -86,14 +92,28 @@ run (void *cls, char *const *args, const char *cfgfile,
86 char *data_dir; 92 char *data_dir;
87 char *hostkeys_file; 93 char *hostkeys_file;
88 char *emsg; 94 char *emsg;
95 char *tmpdir_;
89 char *tmpdir; 96 char *tmpdir;
97#ifdef MINGW
98 char *tmpdir_w;
99#endif
100
90 struct GNUNET_PeerIdentity id; 101 struct GNUNET_PeerIdentity id;
91 102
92 GNUNET_asprintf (&tmpdir, "%s/%s", P_tmpdir, 103 tmpdir_ = getenv ("TMPDIR");
93 "test-gnunet-testing_new-XXXXXX"); 104 tmpdir_ = tmpdir_ ? tmpdir_ : "/tmp";
105 GNUNET_asprintf (&tmpdir, "%s/%s", tmpdir_, "test-gnunet-testing_new-XXXXXX");
106#ifdef MINGW
107 tmpdir_w = GNUNET_malloc (MAX_PATH + 1);
108 GNUNET_assert (ERROR_SUCCESS == plibc_conv_to_win_path (tmpdir, tmpdir_w));
109 GNUNET_free (tmpdir);
110 tmpdir = tmpdir_w;
111 GNUNET_assert (0 == _mktemp_s (tmpdir, strlen (tmpdir) + 1));
112#else
94 GNUNET_assert (mkdtemp (tmpdir) == tmpdir); 113 GNUNET_assert (mkdtemp (tmpdir) == tmpdir);
95 /* LOG (GNUNET_ERROR_TYPE_ERROR, */ 114#endif
96 /* "Temporary directory: %s\n", tmpdir); */ 115 LOG (GNUNET_ERROR_TYPE_ERROR,
116 "Temporary directory: %s\n", tmpdir);
97 system = GNUNET_TESTING_system_create (tmpdir, 117 system = GNUNET_TESTING_system_create (tmpdir,
98 "localhost"); 118 "localhost");
99 GNUNET_assert (NULL != system); 119 GNUNET_assert (NULL != system);
@@ -113,6 +133,7 @@ run (void *cls, char *const *args, const char *cfgfile,
113 test_ctx = GNUNET_malloc (sizeof (struct TestingContext)); 133 test_ctx = GNUNET_malloc (sizeof (struct TestingContext));
114 test_ctx->system = system; 134 test_ctx->system = system;
115 test_ctx->peer = peer; 135 test_ctx->peer = peer;
136 test_ctx->cfg = new_cfg;
116 GNUNET_SCHEDULER_add_delayed (TIME_REL_SEC (5), 137 GNUNET_SCHEDULER_add_delayed (TIME_REL_SEC (5),
117 &do_shutdown, test_ctx); 138 &do_shutdown, test_ctx);
118 139
diff --git a/src/testing/testing_new.c b/src/testing/testing_new.c
index 1bdf7a45f..c19f5c8e1 100644
--- a/src/testing/testing_new.c
+++ b/src/testing/testing_new.c
@@ -592,13 +592,14 @@ update_config_sections (void *cls,
592 GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, "ACCEPT_FROM", 592 GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, "ACCEPT_FROM",
593 &orig_allowed_hosts)) 593 &orig_allowed_hosts))
594 { 594 {
595 orig_allowed_hosts = "127.0.0.1;"; 595 orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;");
596 } 596 }
597 if (NULL == uc->system->controller) 597 if (NULL == uc->system->controller)
598 allowed_hosts = GNUNET_strdup (orig_allowed_hosts); 598 allowed_hosts = GNUNET_strdup (orig_allowed_hosts);
599 else 599 else
600 GNUNET_asprintf (&allowed_hosts, "%s %s;", orig_allowed_hosts, 600 GNUNET_asprintf (&allowed_hosts, "%s %s;", orig_allowed_hosts,
601 uc->system->controller); 601 uc->system->controller);
602 GNUNET_free (orig_allowed_hosts);
602 GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, "ACCEPT_FROM", 603 GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, "ACCEPT_FROM",
603 allowed_hosts); 604 allowed_hosts);
604 GNUNET_free (allowed_hosts); 605 GNUNET_free (allowed_hosts);