aboutsummaryrefslogtreecommitdiff
path: root/src/monkey
diff options
context:
space:
mode:
authorSafey A.Halim <safey.allah@gmail.com>2011-01-16 21:51:12 +0000
committerSafey A.Halim <safey.allah@gmail.com>2011-01-16 21:51:12 +0000
commit08e3df5862d1ce437be0ba4eaaa0aa61a48b3658 (patch)
treeebaad98830b6b8c77b39990b213840960c4e161e /src/monkey
parentedbbe838a5348d89c54e2f1036919da8d855dcb0 (diff)
downloadgnunet-08e3df5862d1ce437be0ba4eaaa0aa61a48b3658.tar.gz
gnunet-08e3df5862d1ce437be0ba4eaaa0aa61a48b3658.zip
Expression Database API, and Action API (without implementation).
Diffstat (limited to 'src/monkey')
-rw-r--r--src/monkey/Makefile.am38
-rw-r--r--src/monkey/action_api.c59
-rw-r--r--src/monkey/edb_api.c64
-rw-r--r--src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java8
-rw-r--r--src/monkey/test.dbbin0 -> 7168 bytes
-rw-r--r--src/monkey/test_monkey_edb.c69
6 files changed, 214 insertions, 24 deletions
diff --git a/src/monkey/Makefile.am b/src/monkey/Makefile.am
index 39e5f8d5d..308a40866 100644
--- a/src/monkey/Makefile.am
+++ b/src/monkey/Makefile.am
@@ -14,6 +14,28 @@ if !MINGW
14if HAVE_ESMTP 14if HAVE_ESMTP
15if HAVE_OPENSSL 15if HAVE_OPENSSL
16 16
17
18lib_LTLIBRARIES = libmonkeyedb.la \
19 libmonkeyaction.la
20
21libmonkeyedb_la_SOURCES = \
22 edb_api.c \
23 gnunet_monkey_edb.h
24
25libmonkeyedb_la_LIBADD = \
26 $(top_builddir)/src/util/libgnunetutil.la \
27 -lsqlite3 \
28 $(GN_LIBINTL) $(XLIB)
29
30libmonkeyaction_la_SOURCES = \
31 action_api.c \
32 gnunet_monkey_action.h
33
34libmonkeyaction_la_LIBADD = \
35 $(top_builddir)/src/util/libgnunetutil.la \
36 $(GN_LIBINTL) $(XLIB)
37
38
17bin_PROGRAMS = \ 39bin_PROGRAMS = \
18 gnunet-monkey \ 40 gnunet-monkey \
19 gnunet-service-monkey 41 gnunet-service-monkey
@@ -39,11 +61,12 @@ gnunet_monkey_SOURCES = \
39 gdbmi_thread.c \ 61 gdbmi_thread.c \
40 gdbmi_var_obj.c \ 62 gdbmi_var_obj.c \
41 gnunet-monkey.c \ 63 gnunet-monkey.c \
42 mail_sender.c \ 64 mail_sender.c
43 edb_api.c
44 65
45gnunet_monkey_LDADD = \ 66gnunet_monkey_LDADD = \
46 $(top_builddir)/src/util/libgnunetutil.la \ 67 $(top_builddir)/src/util/libgnunetutil.la \
68 $(top_builddir)/src/monkey/libmonkeyedb.la \
69 $(top_builddir)/src/monkey/libmonkeyaction.la \
47 -lesmtp \ 70 -lesmtp \
48 $(GN_LIBINTL) 71 $(GN_LIBINTL)
49 72
@@ -59,13 +82,21 @@ bug_null_pointer_exception:
59 gcc -g -O0 -o bug_null_pointer_exception bug_null_pointer_exception.c 82 gcc -g -O0 -o bug_null_pointer_exception bug_null_pointer_exception.c
60 83
61check_PROGRAMS = \ 84check_PROGRAMS = \
62 bug_null_pointer_exception 85 bug_null_pointer_exception \
86 test_monkey_edb
63 #test_gnunet_monkey 87 #test_gnunet_monkey
64 88
65if !DISABLE_TEST_RUN 89if !DISABLE_TEST_RUN
66# TESTS = $(check_SCRIPTS) 90# TESTS = $(check_SCRIPTS)
91TESTS = $(check_PROGRAMS)
67endif 92endif
68 93
94test_monkey_edb_SOURCES = \
95 test_monkey_edb.c
96test_monkey_edb_LDADD = \
97 $(top_builddir)/src/util/libgnunetutil.la \
98 $(top_builddir)/src/monkey/libmonkeyedb.la
99
69#test_gnunet_monkey_SOURCES = \ 100#test_gnunet_monkey_SOURCES = \
70 #test_gnunet_monkey.c 101 #test_gnunet_monkey.c
71#test_gnunet_monkey_LDADD = \ 102#test_gnunet_monkey_LDADD = \
@@ -84,4 +115,3 @@ check_SCRIPTS = \
84endif 115endif
85endif 116endif
86endif 117endif
87
diff --git a/src/monkey/action_api.c b/src/monkey/action_api.c
new file mode 100644
index 000000000..c1f39e788
--- /dev/null
+++ b/src/monkey/action_api.c
@@ -0,0 +1,59 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010, 2011 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 monkey/action_api.c
23 * @brief Monkey API for actions taken by Monkey while debugging
24 */
25
26#include "platform.h"
27#include "gnunet_common.h"
28#include "gnunet_monkey_action.h"
29
30
31int GNUNET_MONKEY_ACTION_report_file()
32{
33 return GNUNET_OK;
34}
35
36
37int GNUNET_MONKEY_ACTION_report_email()
38{
39 return GNUNET_OK;
40}
41
42
43
44int GNUNET_MONKEY_ACTION_rerun_with_valgrind()
45{
46 return GNUNET_OK;
47}
48
49
50int GNUNET_MONKEY_ACTION_rerun_with_gdb()
51{
52 return GNUNET_OK;
53}
54
55
56int GNUNET_MONKEY_ACTION_check_bug_redundancy()
57{
58 return GNUNET_OK;
59}
diff --git a/src/monkey/edb_api.c b/src/monkey/edb_api.c
index 3e7de2d09..78a340cd5 100644
--- a/src/monkey/edb_api.c
+++ b/src/monkey/edb_api.c
@@ -50,46 +50,76 @@ struct GNUNET_MONKEY_EDB_Context
50struct GNUNET_MONKEY_EDB_Context * 50struct GNUNET_MONKEY_EDB_Context *
51GNUNET_MONKEY_EDB_connect (const char *db_file_name) 51GNUNET_MONKEY_EDB_connect (const char *db_file_name)
52{ 52{
53 /* TODO: Implementation */ 53 int err;
54 return NULL; 54 struct GNUNET_MONKEY_EDB_Context *ctxt =
55 GNUNET_malloc (sizeof (struct GNUNET_MONKEY_EDB_Context));
56
57 err = sqlite3_open (db_file_name, &ctxt->db_handle);
58 if (err)
59 {
60 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
61 "Cannot open Expression Database. `%s'\n",
62 sqlite3_errmsg (ctxt->db_handle));
63 return NULL;
64 }
65 return ctxt;
55} 66}
56 67
57 68
58/** 69/**
59 * Disconnect from Database, and cleanup resources 70 * Disconnect from Database, and cleanup resources
60 * 71 *
61 * @param context context 72 * @param context context containing the Expression Database handle
62 * @return GNUNET_OK on success, GNUNET_NO on failure 73 * @return GNUNET_OK on success, GNUNET_NO on failure
63 */ 74 */
64int 75int
65GNUNET_MONKEY_EDB_disconnect (struct GNUNET_MONKEY_EDB_Context *context) 76GNUNET_MONKEY_EDB_disconnect (struct GNUNET_MONKEY_EDB_Context *cntxt)
66{ 77{
67 /* TODO: Implementation */ 78 sqlite3_close (cntxt->db_handle);
68 return GNUNET_OK; 79 GNUNET_free (cntxt);
80 return GNUNET_OK;
69} 81}
70 82
71 83
72/** 84/**
73 * Update the context with a list of expressions. 85 * Run an SQLite query to retrieve those expressions that are previous to
74 * The list is the initializations of sub-expressions 86 * given expression and are in the same scope of the given expression
75 * of the expression pointed to by start_line_no and end_line_no
76 * 87 *
77 * @param context the returned expessions will be available in it. 88 * @param cntxt context containing the Expression Database handle.
78 * expression_list_head and expression_list_tail must be NULL,
79 * otherwise GNUNET_NO will be returned
80 * @param file_name path to the file in which the expression in question exists 89 * @param file_name path to the file in which the expression in question exists
81 * @param start_line_no expression beginning line 90 * @param start_line_no expression beginning line
82 * @param end_line_no expression end line 91 * @param end_line_no line number for the expression's scope end
83 * @param iter callback function, iterator for expressions returned from the Database 92 * @param iter callback function, iterator for expressions returned from the Database
84 * @param iter_cls closure for the expression iterator 93 * @param iter_cls closure for the expression iterator
85 * @return GNUNET_OK success, GNUNET_NO failure 94 * @return GNUNET_OK success, GNUNET_NO failure
86 */ 95 */
87int 96int
88GNUNET_MONKEY_EDB_get_expressions (struct GNUNET_MONKEY_EDB_Context *context, 97GNUNET_MONKEY_EDB_get_expressions (struct GNUNET_MONKEY_EDB_Context *cntxt,
89 const char *file_name, int start_line_no, 98 const char *file_name, int start_line_no,
90 int end_line_no, 99 int end_line_no,
91 GNUNET_MONKEY_ExpressionIterator iter, void *iter_cls) 100 GNUNET_MONKEY_ExpressionIterator iter,
101 void *iter_cls)
92{ 102{
93 /* TODO: Implementation */ 103 int err;
94 return GNUNET_OK; 104 char *errMsg;
105 char *query;
106 if (asprintf
107 (&query,
108 "select expr_syntax, start_lineno from Expression where file_name = \'%s\' and start_lineno < %d and end_lineno = %d",
109 file_name, start_line_no, end_line_no) == -1)
110 {
111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
112 "Memory allocation problem occurred.");
113 return GNUNET_NO;
114 }
115
116 err = sqlite3_exec (cntxt->db_handle, query, iter, iter_cls, &errMsg);
117 if (err)
118 {
119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
120 "Error occurred while executing Database query. `%s'",
121 errMsg);
122 return GNUNET_NO;
123 }
124 return GNUNET_OK;
95} 125}
diff --git a/src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java b/src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java
index 2c1df1b54..b9a1e2cf8 100644
--- a/src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java
+++ b/src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java
@@ -38,7 +38,7 @@ public class ExpressionDatabaseHandler {
38 private static Stack<HashMap<String, Integer>> expressionStack = new Stack<HashMap<String, Integer>>(); 38 private static Stack<HashMap<String, Integer>> expressionStack = new Stack<HashMap<String, Integer>>();
39 39
40 public static void createExpressionDatabase(String databasePath) { 40 public static void createExpressionDatabase(String databasePath) {
41 String createTableQuery = "CREATE TABLE Expression ( expr_ID INT NOT NULL PRIMARY KEY , " 41 String createTableQuery = "CREATE TABLE Expression ( expr_ID INTEGER PRIMARY KEY AUTOINCREMENT, "
42 + "file_name TEXT NOT NULL , expr_syntax TEXT NOT NULL ," 42 + "file_name TEXT NOT NULL , expr_syntax TEXT NOT NULL ,"
43 + " start_lineno INT, end_lineno INT)"; 43 + " start_lineno INT, end_lineno INT)";
44 44
@@ -79,7 +79,7 @@ public class ExpressionDatabaseHandler {
79 if (DEBUG) 79 if (DEBUG)
80 System.out.println(fileName + ":[" + startLineNo + "-" 80 System.out.println(fileName + ":[" + startLineNo + "-"
81 + endLineNo + "]: " + expressionSyntax); 81 + endLineNo + "]: " + expressionSyntax);
82 table.insert(currentFileName, expressionSyntax, startLineNo, 82 table.insert(null, currentFileName, expressionSyntax, startLineNo,
83 endLineNo); 83 endLineNo);
84 } catch (SqlJetException e) { 84 } catch (SqlJetException e) {
85 e.printStackTrace(); 85 e.printStackTrace();
@@ -195,7 +195,9 @@ public class ExpressionDatabaseHandler {
195 .println("Error:Database handle is not initialized. Program will exit now!"); 195 .println("Error:Database handle is not initialized. Program will exit now!");
196 System.exit(1); 196 System.exit(1);
197 } 197 }
198 198
199 String[] fileNameArr = fileName.split("src/");
200 fileName = fileNameArr[1];
199 insertExpression(fileName, expressionSyntax, startLineNo, endLineNo); 201 insertExpression(fileName, expressionSyntax, startLineNo, endLineNo);
200 } 202 }
201} 203}
diff --git a/src/monkey/test.db b/src/monkey/test.db
new file mode 100644
index 000000000..6d15e709f
--- /dev/null
+++ b/src/monkey/test.db
Binary files differ
diff --git a/src/monkey/test_monkey_edb.c b/src/monkey/test_monkey_edb.c
new file mode 100644
index 000000000..b418bee9a
--- /dev/null
+++ b/src/monkey/test_monkey_edb.c
@@ -0,0 +1,69 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010 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 * @file monkey/test_monkey_edb.c
22 * @brief testcase for edb_api.c
23 */
24#include "platform.h"
25#include "gnunet_common.h"
26#include "gnunet_monkey_edb.h"
27
28
29static const char *ref[16] =
30 { "args", "32", "argv", "32", "whole", "42", "whole.member", "42",
31 "whole.member=1", "42", "whole.part", "43", "&part", "43",
32 "whole.part=&part", "43"
33};
34
35static int refCount = 0;
36static int ret = 1;
37
38int
39expressionIterator (void *cls, int colNum, char **colValues, char **colNames)
40{
41 int i;
42 for (i = 0; i < colNum; i++)
43 {
44 if (strcmp (colValues[i], ref[refCount]) != 0)
45 return 1;
46 refCount++;
47 }
48
49 return 0;
50}
51
52
53int
54main (int args, const char *argv[])
55{
56 struct GNUNET_MONKEY_EDB_Context *cntxt;
57 cntxt = GNUNET_MONKEY_EDB_connect ("test.db");
58 ret =
59 GNUNET_MONKEY_EDB_get_expressions (cntxt,
60 "monkey/seaspider/SeaspiderTest.c", 44,
61 83, &expressionIterator, NULL);
62 GNUNET_MONKEY_EDB_disconnect (cntxt);
63
64 if (ret == GNUNET_OK)
65 {
66 return 0;
67 }
68 return 1;
69}