diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-05-30 21:43:09 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-05-30 21:43:09 +0000 |
commit | 2e839a61c6d4379a6b7acb23be64b9b2ad62a113 (patch) | |
tree | 9a47133d0689bcd8cc45c7a9a321f85b6efa263a | |
parent | 279d169d25efb2a9e77f0efd9b2da4e57e2989e5 (diff) | |
download | gnunet-2e839a61c6d4379a6b7acb23be64b9b2ad62a113.tar.gz gnunet-2e839a61c6d4379a6b7acb23be64b9b2ad62a113.zip |
-added testcase file
-rw-r--r-- | src/testing/test_testing_new_peerstartup.c | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/src/testing/test_testing_new_peerstartup.c b/src/testing/test_testing_new_peerstartup.c new file mode 100644 index 000000000..18d8217a1 --- /dev/null +++ b/src/testing/test_testing_new_peerstartup.c | |||
@@ -0,0 +1,135 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2008, 2009, 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testing/test_testing_new_peerstartup.c | ||
23 | * @brief test case for testing peer startup and shutdown using new testing | ||
24 | * library | ||
25 | * @author Sree Harsha Totakura | ||
26 | */ | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_configuration_lib.h" | ||
30 | #include "gnunet_os_lib.h" | ||
31 | #include "gnunet_testing_lib-new.h" | ||
32 | |||
33 | #define LOG(kind,...) \ | ||
34 | GNUNET_log (kind, __VA_ARGS__) | ||
35 | |||
36 | #define TIME_REL_SEC(sec) \ | ||
37 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) | ||
38 | |||
39 | /** | ||
40 | * The testing context | ||
41 | */ | ||
42 | struct TestingContext | ||
43 | { | ||
44 | /** | ||
45 | * The testing system | ||
46 | */ | ||
47 | struct GNUNET_TESTING_System *system; | ||
48 | |||
49 | /** | ||
50 | * The peer which has been started by the testing system | ||
51 | */ | ||
52 | struct GNUNET_TESTING_Peer *peer; | ||
53 | }; | ||
54 | |||
55 | |||
56 | /** | ||
57 | * Task for shutdown | ||
58 | * | ||
59 | * @param cls the testing context | ||
60 | * @param tc the tast context | ||
61 | */ | ||
62 | static void | ||
63 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
64 | { | ||
65 | struct TestingContext *test_ctx = cls; | ||
66 | |||
67 | GNUNET_assert (GNUNET_OK == GNUNET_TESTING_peer_stop (test_ctx->peer)); | ||
68 | GNUNET_TESTING_peer_destroy (test_ctx->peer); | ||
69 | GNUNET_TESTING_hostkeys_unload (test_ctx->system); | ||
70 | GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); | ||
71 | GNUNET_free (test_ctx); | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Main point of test execution | ||
77 | */ | ||
78 | static void | ||
79 | run (void *cls, char *const *args, const char *cfgfile, | ||
80 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
81 | { | ||
82 | struct GNUNET_TESTING_System *system; | ||
83 | struct GNUNET_TESTING_Peer *peer; | ||
84 | struct GNUNET_CONFIGURATION_Handle *new_cfg; | ||
85 | struct TestingContext *test_ctx; | ||
86 | char *data_dir; | ||
87 | char *hostkeys_file; | ||
88 | char *emsg; | ||
89 | char *tmpdir; | ||
90 | struct GNUNET_PeerIdentity id; | ||
91 | |||
92 | GNUNET_asprintf (&tmpdir, "%s/%s", P_tmpdir, | ||
93 | "test-gnunet-testing_new-XXXXXX"); | ||
94 | GNUNET_assert (mkdtemp (tmpdir) == tmpdir); | ||
95 | /* LOG (GNUNET_ERROR_TYPE_ERROR, */ | ||
96 | /* "Temporary directory: %s\n", tmpdir); */ | ||
97 | system = GNUNET_TESTING_system_create (tmpdir, | ||
98 | "localhost"); | ||
99 | GNUNET_assert (NULL != system); | ||
100 | GNUNET_free (tmpdir); | ||
101 | data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); | ||
102 | GNUNET_asprintf (&hostkeys_file, "%s/testing_hostkeys.dat", data_dir); | ||
103 | GNUNET_free (data_dir); | ||
104 | GNUNET_assert (GNUNET_OK == | ||
105 | GNUNET_TESTING_hostkeys_load (system, hostkeys_file)); | ||
106 | GNUNET_free (hostkeys_file); | ||
107 | new_cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
108 | emsg = NULL; | ||
109 | peer = GNUNET_TESTING_peer_configure (system, new_cfg, 0, &id, &emsg); | ||
110 | GNUNET_assert (NULL != peer); | ||
111 | GNUNET_assert (NULL == emsg); | ||
112 | GNUNET_assert (GNUNET_OK == GNUNET_TESTING_peer_start (peer)); | ||
113 | test_ctx = GNUNET_malloc (sizeof (struct TestingContext)); | ||
114 | test_ctx->system = system; | ||
115 | test_ctx->peer = peer; | ||
116 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SEC (5), | ||
117 | &do_shutdown, test_ctx); | ||
118 | |||
119 | } | ||
120 | |||
121 | |||
122 | int main (int argc, char *argv[]) | ||
123 | { | ||
124 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
125 | GNUNET_GETOPT_OPTION_END | ||
126 | }; | ||
127 | |||
128 | if (GNUNET_OK != | ||
129 | GNUNET_PROGRAM_run (argc, argv, | ||
130 | "test_testing_new_peerstartup", | ||
131 | "test case for peerstartup using new testing library", | ||
132 | options, &run, NULL)) | ||
133 | return 1; | ||
134 | return 0; | ||
135 | } | ||