diff options
author | Safey A.Halim <safey.allah@gmail.com> | 2011-06-02 09:27:35 +0000 |
---|---|---|
committer | Safey A.Halim <safey.allah@gmail.com> | 2011-06-02 09:27:35 +0000 |
commit | 06c08bc0f341f99e6939bc5e7b448645de5a9961 (patch) | |
tree | 1341e14243e254efb2e40b13b9419531edadcd38 /src/monkey/gnunet-monkey.c | |
parent | 1fea1c90365c01bf0e8d75ba148367ad4125f5d9 (diff) | |
download | gnunet-06c08bc0f341f99e6939bc5e7b448645de5a9961.tar.gz gnunet-06c08bc0f341f99e6939bc5e7b448645de5a9961.zip |
Monkey supports Assertions, and inspects user-defined expressions
Diffstat (limited to 'src/monkey/gnunet-monkey.c')
-rw-r--r-- | src/monkey/gnunet-monkey.c | 243 |
1 files changed, 139 insertions, 104 deletions
diff --git a/src/monkey/gnunet-monkey.c b/src/monkey/gnunet-monkey.c index 030eb0774..1019a87a0 100644 --- a/src/monkey/gnunet-monkey.c +++ b/src/monkey/gnunet-monkey.c | |||
@@ -30,12 +30,13 @@ | |||
30 | #include "gnunet_program_lib.h" | 30 | #include "gnunet_program_lib.h" |
31 | #include "gnunet_monkey_action.h" | 31 | #include "gnunet_monkey_action.h" |
32 | 32 | ||
33 | static const char* mode; | 33 | static const char *mode; |
34 | static const char* dumpFileName; | 34 | static const char *dumpFileName; |
35 | static const char* binaryName; | 35 | static const char *binaryName; |
36 | static const char* emailAddress; | 36 | static const char *emailAddress; |
37 | static const char* edbFilePath; | 37 | static const char *edbFilePath; |
38 | static const char* gdbBinaryPath; | 38 | static const char *gdbBinaryPath; |
39 | static const char *inspectExpression; | ||
39 | static int ret = 0; | 40 | static int ret = 0; |
40 | 41 | ||
41 | /** | 42 | /** |
@@ -49,113 +50,147 @@ static int ret = 0; | |||
49 | static void | 50 | static void |
50 | run (void *cls, | 51 | run (void *cls, |
51 | char *const *args, | 52 | char *const *args, |
52 | const char *cfgfile, | 53 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
53 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
54 | { | 54 | { |
55 | int result; | 55 | int result; |
56 | struct GNUNET_MONKEY_ACTION_Context *cntxt; | 56 | struct GNUNET_MONKEY_ACTION_Context *cntxt; |
57 | 57 | ||
58 | if (strcasecmp(mode, "email") == 0) { | 58 | if (strcasecmp (mode, "email") == 0) |
59 | if (NULL == emailAddress) { | 59 | { |
60 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Working in email mode requires an email address!\n"); | 60 | if (NULL == emailAddress) |
61 | ret = 1; | 61 | { |
62 | return; | 62 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
63 | } | 63 | "Working in email mode requires an email address!\n"); |
64 | } else if (strcasecmp(mode, "text") == 0) { | 64 | ret = 1; |
65 | if (NULL == dumpFileName) { | 65 | return; |
66 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Working in text mode requires a path for the dump file!\n"); | ||
67 | ret = 1; | ||
68 | return; | ||
69 | } | ||
70 | } | 66 | } |
67 | } | ||
68 | else if (strcasecmp (mode, "text") == 0) | ||
69 | { | ||
70 | if (NULL == dumpFileName) | ||
71 | { | ||
72 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
73 | "Working in text mode requires a path for the dump file!\n"); | ||
74 | ret = 1; | ||
75 | return; | ||
76 | } | ||
77 | } | ||
71 | 78 | ||
72 | /* Initialize context for the Action API */ | 79 | /* Initialize context for the Action API */ |
73 | cntxt = GNUNET_malloc(sizeof(struct GNUNET_MONKEY_ACTION_Context)); | 80 | cntxt = GNUNET_malloc (sizeof (struct GNUNET_MONKEY_ACTION_Context)); |
74 | cntxt->binary_name = binaryName; | 81 | cntxt->binary_name = binaryName; |
75 | cntxt->expression_database_path = edbFilePath; | 82 | cntxt->expression_database_path = edbFilePath; |
76 | cntxt->gdb_binary_path = gdbBinaryPath; | 83 | cntxt->gdb_binary_path = gdbBinaryPath; |
84 | cntxt->inspect_expression = inspectExpression; | ||
77 | 85 | ||
78 | result = GNUNET_MONKEY_ACTION_rerun_with_gdb(cntxt); | 86 | result = GNUNET_MONKEY_ACTION_rerun_with_gdb (cntxt); |
79 | switch (result) { | 87 | switch (result) |
80 | int retVal; | 88 | { |
81 | case GDB_STATE_ERROR: | 89 | int retVal; |
82 | break; | 90 | case GDB_STATE_ERROR: |
83 | case GDB_STATE_EXIT_NORMALLY: | 91 | break; |
84 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Debug with gdb, program exited normally!\n"); | 92 | case GDB_STATE_EXIT_NORMALLY: |
85 | /*FIXME: Valgrind should be launched here */ | 93 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
86 | break; | 94 | "Debug with gdb, program exited normally!\n"); |
87 | case GDB_STATE_STOPPED: | 95 | /*FIXME: Valgrind should be launched here */ |
88 | /*FIXME: Expression Database should be inspected here (before writing the report) */ | 96 | break; |
89 | retVal = GNUNET_MONKEY_ACTION_inspect_expression_database(cntxt); | 97 | case GDB_STATE_STOPPED: |
90 | if (GNUNET_NO == retVal) { | 98 | /*FIXME: Expression Database should be inspected here (before writing the report) */ |
91 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error using Expression Database!\n"); | 99 | retVal = GNUNET_MONKEY_ACTION_inspect_expression_database (cntxt); |
92 | ret = 1; | 100 | if (GNUNET_NO == retVal) |
93 | break; | 101 | { |
94 | } else if (GDB_STATE_ERROR == retVal) { | 102 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
95 | /* GDB could not locate a NULL value expression, launch Valgrind */ | 103 | "Error using Expression Database!\n"); |
96 | retVal = GNUNET_MONKEY_ACTION_rerun_with_valgrind(cntxt); | 104 | ret = 1; |
97 | if (GNUNET_NO == retVal) { | 105 | break; |
98 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error using Valgrind!\n"); | 106 | } |
99 | ret = 1; | 107 | else if (GDB_STATE_ERROR == retVal) |
100 | break; | 108 | { |
101 | } | 109 | /* GDB could not locate a NULL value expression, launch Valgrind */ |
102 | } | 110 | retVal = GNUNET_MONKEY_ACTION_rerun_with_valgrind (cntxt); |
103 | if(GNUNET_OK != GNUNET_MONKEY_ACTION_format_report(cntxt)){ | 111 | if (GNUNET_NO == retVal) |
104 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error in generating debug report!\n"); | 112 | { |
105 | ret = 1; | 113 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error using Valgrind!\n"); |
106 | } | 114 | ret = 1; |
107 | if (strcasecmp(mode, "email") == 0) { | 115 | break; |
108 | if (GNUNET_OK != GNUNET_MONKEY_ACTION_report_email(cntxt)) { | 116 | } |
109 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error sending email!\n"); | 117 | } |
110 | ret = 1; | 118 | if (GNUNET_OK != GNUNET_MONKEY_ACTION_format_report (cntxt)) |
111 | } | 119 | { |
112 | } else { | 120 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
113 | /* text mode */ | 121 | "Error in generating debug report!\n"); |
114 | if (GNUNET_OK != GNUNET_MONKEY_ACTION_report_file(cntxt, dumpFileName)) { | 122 | ret = 1; |
115 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error in saving debug file!\n"); | 123 | } |
116 | ret = 1; | 124 | if (strcasecmp (mode, "email") == 0) |
117 | } | 125 | { |
118 | } | 126 | if (GNUNET_OK != GNUNET_MONKEY_ACTION_report_email (cntxt)) |
119 | break; | 127 | { |
120 | default: | 128 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error sending email!\n"); |
121 | break; | 129 | ret = 1; |
130 | } | ||
122 | } | 131 | } |
132 | else | ||
133 | { | ||
134 | /* text mode */ | ||
135 | if (GNUNET_OK != | ||
136 | GNUNET_MONKEY_ACTION_report_file (cntxt, dumpFileName)) | ||
137 | { | ||
138 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
139 | "Error in saving debug file!\n"); | ||
140 | ret = 1; | ||
141 | } | ||
142 | } | ||
143 | break; | ||
144 | default: | ||
145 | break; | ||
146 | } | ||
123 | } | 147 | } |
124 | 148 | ||
125 | 149 | ||
126 | int main(int argc, char *argv[]) | 150 | int |
151 | main (int argc, char *argv[]) | ||
127 | { | 152 | { |
128 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 153 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
129 | {'m', "mode", NULL, gettext_noop ("monkey's mode of operation: options are \"text\" or \"email\""), | 154 | {'m', "mode", NULL, |
130 | GNUNET_YES, &GNUNET_GETOPT_set_string, &mode}, | 155 | gettext_noop |
131 | {'b', "binary", NULL, gettext_noop ("binary for program to debug with monkey"), | 156 | ("monkey's mode of operation: options are \"text\" or \"email\""), |
132 | GNUNET_YES, &GNUNET_GETOPT_set_string, &binaryName}, | 157 | GNUNET_YES, &GNUNET_GETOPT_set_string, &mode}, |
133 | {'o', "output", NULL, gettext_noop ("path to file to dump monkey's output in case of text mode"), | 158 | {'b', "binary", NULL, |
134 | GNUNET_YES, &GNUNET_GETOPT_set_string, &dumpFileName}, | 159 | gettext_noop ("binary for program to debug with monkey"), |
135 | {'a', "address", NULL, gettext_noop ("address to send email to in case of email mode"), | 160 | GNUNET_YES, &GNUNET_GETOPT_set_string, &binaryName}, |
136 | GNUNET_YES, &GNUNET_GETOPT_set_string, &emailAddress}, | 161 | {'o', "output", NULL, |
137 | {'d', "database", NULL, gettext_noop ("path to Expression Database file"), | 162 | gettext_noop |
138 | GNUNET_YES, &GNUNET_GETOPT_set_string, &edbFilePath}, | 163 | ("path to file to dump monkey's output in case of text mode"), |
139 | {'g', "gdb", NULL, gettext_noop ("path to gdb binary in use; default is /usr/bin/gdb"), | 164 | GNUNET_YES, &GNUNET_GETOPT_set_string, &dumpFileName}, |
140 | GNUNET_YES, &GNUNET_GETOPT_set_string, &gdbBinaryPath}, | 165 | {'a', "address", NULL, |
141 | GNUNET_GETOPT_OPTION_END | 166 | gettext_noop ("address to send email to in case of email mode"), |
142 | }; | 167 | GNUNET_YES, &GNUNET_GETOPT_set_string, &emailAddress}, |
143 | 168 | {'d', "database", NULL, gettext_noop ("path to Expression Database file"), | |
144 | if (argc < 2) { | 169 | GNUNET_YES, &GNUNET_GETOPT_set_string, &edbFilePath}, |
145 | printf("%s", "Monkey should take arguments: Use --help to get a list of options.\n"); | 170 | {'g', "gdb", NULL, |
146 | return 1; | 171 | gettext_noop ("path to gdb binary in use; default is /usr/bin/gdb"), |
147 | } | 172 | GNUNET_YES, &GNUNET_GETOPT_set_string, &gdbBinaryPath}, |
148 | 173 | {'i', "inspect", NULL, gettext_noop ("A custom expression to inspect"), | |
149 | if (GNUNET_OK == GNUNET_PROGRAM_run (argc, | 174 | GNUNET_YES, &GNUNET_GETOPT_set_string, &inspectExpression}, |
150 | argv, | 175 | GNUNET_GETOPT_OPTION_END |
151 | "gnunet-monkey", | 176 | }; |
152 | gettext_noop | ||
153 | ("Automatically debug a service"), | ||
154 | options, &run, NULL)) | ||
155 | { | ||
156 | return ret; | ||
157 | } | ||
158 | 177 | ||
159 | return 1; | 178 | if (argc < 2) |
160 | } | 179 | { |
180 | printf ("%s", | ||
181 | "Monkey should take arguments: Use --help to get a list of options.\n"); | ||
182 | return 1; | ||
183 | } | ||
161 | 184 | ||
185 | if (GNUNET_OK == GNUNET_PROGRAM_run (argc, | ||
186 | argv, | ||
187 | "gnunet-monkey", | ||
188 | gettext_noop | ||
189 | ("Automatically debug a service"), | ||
190 | options, &run, NULL)) | ||
191 | { | ||
192 | return ret; | ||
193 | } | ||
194 | |||
195 | return 1; | ||
196 | } | ||