dovecot-2.0-pigeonhole: Further developed new runtime trace debu...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Wed Jul 21 18:43:25 EEST 2010


details:   http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/48af633e3e9f
changeset: 1339:48af633e3e9f
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Wed Jul 21 17:43:16 2010 +0200
description:
Further developed new runtime trace debugging; test suite is also now included.

diffstat:

 Makefile.am                                             |   2 +-
 doc/man/sieve-test.1                                    |  31 ++++---
 src/lib-sieve-tool/sieve-tool.c                         |  74 ++++++++++++++----
 src/lib-sieve-tool/sieve-tool.h                         |  13 +++
 src/lib-sieve/plugins/spamvirustest/tst-spamvirustest.c |  10 ++-
 src/lib-sieve/sieve-code.c                              |   2 -
 src/lib-sieve/sieve-match.c                             |   5 +-
 src/lib-sieve/sieve-runtime-trace.c                     |   6 +
 src/lib-sieve/sieve-runtime-trace.h                     |  14 ++-
 src/sieve-tools/sieve-test.c                            |  70 +++++------------
 src/testsuite/cmd-test-config.c                         |   6 +-
 src/testsuite/cmd-test-mailbox.c                        |   7 +-
 src/testsuite/cmd-test-message.c                        |   8 +-
 src/testsuite/cmd-test.c                                |   2 +
 src/testsuite/testsuite.c                               |  29 +++++--
 src/testsuite/tst-test-error.c                          |   8 +-
 src/testsuite/tst-test-multiscript.c                    |   4 +-
 src/testsuite/tst-test-result-execute.c                 |   2 +-
 18 files changed, 181 insertions(+), 112 deletions(-)

diffs (truncated from 658 to 300 lines):

diff -r 01ee63b788c9 -r 48af633e3e9f Makefile.am
--- a/Makefile.am	Tue Jul 20 13:29:46 2010 +0200
+++ b/Makefile.am	Wed Jul 21 17:43:16 2010 +0200
@@ -24,7 +24,7 @@
 
 # Testsuite tests
 
-TESTSUITE_BIN = $(top_builddir)/src/testsuite/testsuite
+TESTSUITE_BIN = $(top_builddir)/src/testsuite/testsuite $(TESTSUITE_OPTIONS)
 
 if TESTSUITE_VALGRIND
 TEST_BIN = valgrind -q --error-exitcode=1 --show-reachable=yes --leak-check=full $(TESTSUITE_BIN) 
diff -r 01ee63b788c9 -r 48af633e3e9f doc/man/sieve-test.1
--- a/doc/man/sieve-test.1	Tue Jul 20 13:29:46 2010 +0200
+++ b/doc/man/sieve-test.1	Wed Jul 21 17:43:16 2010 +0200
@@ -91,9 +91,14 @@
 allowed and the specified scripts are executed sequentially in the order specified at the command
 line.
 .TP
-\fB\-t\fP \fItrace\-option\fP
-Configure runtime trace debugging. Trace debugging provides detailed insight in the operations performed
-by the Sieve script. Refer to the trace debugging section below. 
+\fB\-t\fP \fItrace\-file\fP
+Enables runtime trace debugging. Trace debugging provides detailed insight in the operations performed
+by the Sieve script. Refer to the runtime trace debugging section below. The trace information is
+written to the specified file. Using '\-' as filename causes the trace data to be written to \fBstdout\fP.
+.TP
+\fB\-T\fP \fItrace\-option\fP
+Configures runtime trace debugging, which is enabled with the \fP\-t\fP option. Refer to the runtime
+trace debugging section below.  
 .TP
 \fB\-x\fP "\fIextension extension ...\fP"
 Set the available extensions. The parameter is a space\-separated list of the active extensions. By
@@ -108,21 +113,19 @@
 
 .SH RUNTIME TRACE DEBUGGING
 .PP
-Using the \fB-t\fP option, the \fBsieve\-test\fP tool can be configured to print detailed information on
-the Sieve script execution. For example, the encountered commands, the performed tests and the matched 
-values can be printed. 
+Using the \fB-t\fP option, the \fBsieve\-test\fP tool can be configured to print detailed trace information
+on the Sieve script execution to a file or standard output. For example, the encountered commands, the
+performed tests and the matched values can be printed. 
 .PP
-The \fB\-t\fP option can be specified multiple times. It can be used as follows:
+The runtime trace can be configured using the \fB\-T\fP option, which can be specified multiple times. 
+It can be used as follows:
 
 .TP 2
-\fB\-tlevel=...\fP
+\fB\-Tlevel=...\fP
 Set the verbosity level of the trace debugging. One of the following values can be supplied:
 .RS 2
 .TP 3 
-\fInone\fP (default)
-No trace debugging.
-.TP 
-\fIactions\fP
+\fIactions\fP (default)
 Only print executed action commands, like keep, fileinto, reject and redirect.
 .TP
 \fIcommands\fP
@@ -135,10 +138,10 @@
 Print all commands, performed tests and the values matched for those tests. 
 .RE
 .TP 2
-\fB\-tdebug\fP
+\fB\-Tdebug\fP
 Print debug messages as well. This is usually only useful for developers and produces messy output.
 .TP
-\fB\-taddresses\fP
+\fB\-Taddresses\fP
 Print byte code addresses for the current trace output. Normally, only the current Sieve source code 
 position is printed. The byte code addresses are equal to those listed in a binary dump produced
 using the \fB\-d\fP option or by the \fBsieved(1)\fP command.
diff -r 01ee63b788c9 -r 48af633e3e9f src/lib-sieve-tool/sieve-tool.c
--- a/src/lib-sieve-tool/sieve-tool.c	Tue Jul 20 13:29:46 2010 +0200
+++ b/src/lib-sieve-tool/sieve-tool.c	Wed Jul 21 17:43:16 2010 +0200
@@ -443,6 +443,28 @@
 }
 
 /*
+ * File I/O
+ */
+
+struct ostream *sieve_tool_open_output_stream(const char *filename)
+{
+	struct ostream *outstream;
+	int fd;
+
+	if ( strcmp(filename, "-") == 0 ) 
+		outstream = o_stream_create_fd(1, 0, TRUE);
+	else {
+		if ( (fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0600)) < 0 ) {
+			i_fatal("failed to open file for writing: %m");
+		}
+		
+		outstream = o_stream_create_fd(fd, 0, TRUE);
+	}
+	
+	return outstream;
+}
+
+/*
  * Sieve script handling
  */
 
@@ -481,32 +503,52 @@
 		
 	return sbin;
 }
-	
+
 void sieve_tool_dump_binary_to(struct sieve_binary *sbin, const char *filename)	
 {
-	int dfd = -1;
 	struct ostream *dumpstream;
-	
+
 	if ( filename == NULL ) return;
-	
-	if ( strcmp(filename, "-") == 0 ) 
-		dumpstream = o_stream_create_fd(1, 0, FALSE);
-	else {
-		if ( (dfd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0600)) < 0 ) {
-			i_fatal("failed to open dump-file for writing: %m");
-		}
-		
-		dumpstream = o_stream_create_fd(dfd, 0, FALSE);
-	}
-	
+
+	dumpstream = sieve_tool_open_output_stream(filename);
 	if ( dumpstream != NULL ) {
 		(void) sieve_dump(sbin, dumpstream, FALSE);
 		o_stream_destroy(&dumpstream);
 	} else {
 		i_fatal("Failed to create stream for sieve code dump.");
 	}
+}
 	
-	if ( dfd != -1 )
-		close(dfd);
+/*
+ * Commandline option parsing
+ */
+
+void sieve_tool_parse_trace_option
+(struct sieve_trace_config *tr_config, const char *tr_option)
+{
+    if ( strncmp(tr_option, "level=", 6) == 0 ) {
+        const char *lvl = &tr_option[6];
+
+        if ( strcmp(lvl, "none") == 0 ) {
+            tr_config->level = SIEVE_TRLVL_NONE;
+        } else if ( strcmp(lvl, "actions") == 0 ) {
+            tr_config->level = SIEVE_TRLVL_ACTIONS;
+        } else if ( strcmp(lvl, "commands") == 0 ) {
+            tr_config->level = SIEVE_TRLVL_COMMANDS;
+        } else if ( strcmp(lvl, "tests") == 0 ) {
+            tr_config->level = SIEVE_TRLVL_TESTS;
+        } else if ( strcmp(lvl, "matching") == 0 ) {
+            tr_config->level = SIEVE_TRLVL_MATCHING;
+        } else {
+            i_fatal_status(EX_USAGE, "Unknown -tlevel= trace level: %s", lvl);
+        }
+    } else if ( strcmp(tr_option, "debug") == 0 ) {
+        tr_config->flags |= SIEVE_TRFLG_DEBUG;
+    } else if ( strcmp(tr_option, "addresses") == 0 ) {
+        tr_config->flags |= SIEVE_TRFLG_ADDRESSES;
+    } else {
+        i_fatal_status(EX_USAGE, "Unknown -t trace option value: %s", tr_option);
+    }
 }
 
+
diff -r 01ee63b788c9 -r 48af633e3e9f src/lib-sieve-tool/sieve-tool.h
--- a/src/lib-sieve-tool/sieve-tool.h	Tue Jul 20 13:29:46 2010 +0200
+++ b/src/lib-sieve-tool/sieve-tool.h	Wed Jul 21 17:43:16 2010 +0200
@@ -73,6 +73,12 @@
 	(struct mail *mail, const char **recipient, const char **sender);
 
 /*
+ * File I/O
+ */
+
+struct ostream *sieve_tool_open_output_stream(const char *filename);
+
+/*
  * Sieve script handling
  */
 
@@ -83,4 +89,11 @@
 void sieve_tool_dump_binary_to
 	(struct sieve_binary *sbin, const char *filename);
 
+/*
+ * Command line option parsing
+ */
+
+void sieve_tool_parse_trace_option
+	(struct sieve_trace_config *tr_config, const char *tr_option);
+
 #endif /* __SIEVE_TOOL_H */
diff -r 01ee63b788c9 -r 48af633e3e9f src/lib-sieve/plugins/spamvirustest/tst-spamvirustest.c
--- a/src/lib-sieve/plugins/spamvirustest/tst-spamvirustest.c	Tue Jul 20 13:29:46 2010 +0200
+++ b/src/lib-sieve/plugins/spamvirustest/tst-spamvirustest.c	Wed Jul 21 17:43:16 2010 +0200
@@ -279,8 +279,14 @@
 			
 	/* Perform test */
 
-	sieve_runtime_trace
-		(renv, SIEVE_TRLVL_TESTS, "%s test", sieve_operation_mnemonic(op));
+	if ( sieve_operation_is(op, spamtest_operation) ) {
+		sieve_runtime_trace
+			(renv, SIEVE_TRLVL_TESTS, "spamtest test [percent=%s]",
+				( percent ? "true" : "false" ));
+	} else {
+		sieve_runtime_trace
+			(renv, SIEVE_TRLVL_TESTS, "virustest test");
+	}
 
 	/* Initialize match */
 	mctx = sieve_match_begin(renv, &mcht, &cmp, NULL, key_value); 	
diff -r 01ee63b788c9 -r 48af633e3e9f src/lib-sieve/sieve-code.c
--- a/src/lib-sieve/sieve-code.c	Tue Jul 20 13:29:46 2010 +0200
+++ b/src/lib-sieve/sieve-code.c	Wed Jul 21 17:43:16 2010 +0200
@@ -1048,8 +1048,6 @@
 static int opc_jmp_execute
 (const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) 
 {
-	sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "jump");
-	
 	return sieve_interpreter_program_jump(renv->interp, TRUE);
 }	
 		
diff -r 01ee63b788c9 -r 48af633e3e9f src/lib-sieve/sieve-match.c
--- a/src/lib-sieve/sieve-match.c	Tue Jul 20 13:29:46 2010 +0200
+++ b/src/lib-sieve/sieve-match.c	Wed Jul 21 17:43:16 2010 +0200
@@ -147,7 +147,10 @@
 	pool_unref(&(*mctx)->pool);
 	*mctx = NULL;
 
-	if ( ret < 0 ) status = ret;
+	if ( ret < 0 || status < 0 )
+		status = ( ret <= status ? ret : status );
+	else
+		status = status || ret;
 
 	sieve_runtime_trace(renv, SIEVE_TRLVL_MATCHING,
 		"  finishing match with result: %s", 
diff -r 01ee63b788c9 -r 48af633e3e9f src/lib-sieve/sieve-runtime-trace.c
--- a/src/lib-sieve/sieve-runtime-trace.c	Tue Jul 20 13:29:46 2010 +0200
+++ b/src/lib-sieve/sieve-runtime-trace.c	Wed Jul 21 17:43:16 2010 +0200
@@ -138,3 +138,9 @@
 		"## Finished executing script '%s'", script_name);
 	_trace_line_print_empty(renv);
 }
+
+void _sieve_runtime_trace_sep(const struct sieve_runtime_env *renv)
+{
+	_trace_line_print_empty(renv);	
+}
+
diff -r 01ee63b788c9 -r 48af633e3e9f src/lib-sieve/sieve-runtime-trace.h
--- a/src/lib-sieve/sieve-runtime-trace.h	Tue Jul 20 13:29:46 2010 +0200
+++ b/src/lib-sieve/sieve-runtime-trace.h	Wed Jul 21 17:43:16 2010 +0200
@@ -125,21 +125,27 @@
 
 void _sieve_runtime_trace_begin(const struct sieve_runtime_env *renv);
 void _sieve_runtime_trace_end(const struct sieve_runtime_env *renv);
+void _sieve_runtime_trace_sep(const struct sieve_runtime_env *renv);
 
 static inline void sieve_runtime_trace_begin
 (const struct sieve_runtime_env *renv)
 {
-	if ( renv->trace_stream != NULL && 
-		renv->trace_config.level > SIEVE_TRLVL_NONE )
+	if ( renv->trace_stream != NULL )
 		_sieve_runtime_trace_begin(renv);
 }
 
 static inline void sieve_runtime_trace_end
 (const struct sieve_runtime_env *renv)
 {
-	if ( renv->trace_stream != NULL && 
-		renv->trace_config.level > SIEVE_TRLVL_NONE )
+	if ( renv->trace_stream != NULL )
 		_sieve_runtime_trace_end(renv);
 }
 
+static inline void sieve_runtime_trace_sep
+(const struct sieve_runtime_env *renv)
+{
+	if ( renv->trace_stream != NULL )
+		_sieve_runtime_trace_sep(renv);
+}
+
 #endif /* __SIEVE_TRACE_H */
diff -r 01ee63b788c9 -r 48af633e3e9f src/sieve-tools/sieve-test.c


More information about the dovecot-cvs mailing list