[netfilter-cvslog] r3375 - trunk/nfsim/core

rusty at netfilter.org rusty at netfilter.org
Tue Dec 14 07:03:43 CET 2004


Author: rusty at netfilter.org
Date: 2004-12-14 07:03:42 +0100 (Tue, 14 Dec 2004)
New Revision: 3375

Modified:
   trunk/nfsim/core/core.c
   trunk/nfsim/core/core.h
   trunk/nfsim/core/expect.c
   trunk/nfsim/core/tui.c
   trunk/nfsim/core/tui.h
Log:
Introduce script_fail(): differentiate between failure in the test script, and itnernal errors (corruption or whatever).


Modified: trunk/nfsim/core/core.c
===================================================================
--- trunk/nfsim/core/core.c	2004-12-14 05:44:25 UTC (rev 3374)
+++ trunk/nfsim/core/core.c	2004-12-14 06:03:42 UTC (rev 3375)
@@ -124,7 +124,6 @@
 	return 0;
 }
 
-
 void stop()
 {
 	running = 0;

Modified: trunk/nfsim/core/core.h
===================================================================
--- trunk/nfsim/core/core.h	2004-12-14 05:44:25 UTC (rev 3374)
+++ trunk/nfsim/core/core.h	2004-12-14 06:03:42 UTC (rev 3375)
@@ -171,7 +171,6 @@
 		   const struct net_device *in,
 		   const struct net_device *out,
 		   const char *fmt, ...);
- 
 
 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
 		 struct net_device *indev,

Modified: trunk/nfsim/core/expect.c
===================================================================
--- trunk/nfsim/core/expect.c	2004-12-14 05:44:25 UTC (rev 3374)
+++ trunk/nfsim/core/expect.c	2004-12-14 06:03:42 UTC (rev 3375)
@@ -154,9 +154,10 @@
 			continue;
 
 		if (!(*e)->invert && !(*e)->matched)
-			barf("Pattern '%s' did not match", (*e)->pattern);
+			script_fail("Pattern '%s' did not match",
+				    (*e)->pattern);
 		else if ((*e)->invert && (*e)->matched)
-			barf("Pattern '%s' matched", (*e)->pattern);
+			script_fail("Pattern '%s' matched", (*e)->pattern);
 
 		/* Unlink from list and free. */
 		old = *e;

Modified: trunk/nfsim/core/tui.c
===================================================================
--- trunk/nfsim/core/tui.c	2004-12-14 05:44:25 UTC (rev 3374)
+++ trunk/nfsim/core/tui.c	2004-12-14 06:03:42 UTC (rev 3375)
@@ -34,6 +34,7 @@
 int tui_echo_commands;
 int tui_abort_on_fail;
 int tui_quiet;
+static int linenum = 1;
 
 static void process_line(char *line);
 
@@ -183,10 +184,25 @@
 	return fileno(stdin);
 }
 
+void script_fail(const char *fmt, ...)
+{
+	char *str;
+	va_list arglist;
+
+	fprintf(stderr, "Script failed at line %i: ", linenum);
+
+	va_start(arglist, fmt);
+	str = talloc_vasprintf(NULL, fmt, arglist);
+	va_end(arglist);
+
+	nfsim_log(LOG_ALWAYS, "%s", str);
+	talloc_free(str);
+	exit(1);
+}
+
 void process_line(char *line)
 {
 	int argc, prevspace;
-	static int linenum = 1;
 	char *argv[TUI_MAX_ARGS+1], quotemode;
 	struct command *cmd;
 
@@ -201,7 +217,8 @@
 
 	add_history(line);
 	if (tui_echo_commands)
-		printf("%u:%s\n", linenum++, line);
+		printf("%u:%s\n", linenum, line);
+	linenum++;
 
 	/* FIXME: only handles quotes at the beginning and end of args */
 	while (*line) {
@@ -230,14 +247,14 @@
 			/* Abort on UNEXPECTED failure. */
 			if (!nfsim_log(LOG_UI, "%s: command failed", argv[0])
 			    && tui_abort_on_fail)
-				exit(1);
+				script_fail("%s failed", argv[0]);
 		}
 		do_post_commands(cmd->name);
 	} else {
 		/* Someone might expect this command not to be found? */
 		if (!nfsim_log(LOG_UI, "%s: command not found", argv[0])
 		    && tui_abort_on_fail)
-			exit(1);
+			script_fail("%s not found", argv[0]);
 	}
 }
 

Modified: trunk/nfsim/core/tui.h
===================================================================
--- trunk/nfsim/core/tui.h	2004-12-14 05:44:25 UTC (rev 3374)
+++ trunk/nfsim/core/tui.h	2004-12-14 06:03:42 UTC (rev 3375)
@@ -42,6 +42,9 @@
 /* Is this a valid command?  Sanity check for expect. */
 bool tui_is_command(const char *name);
 
+/* A script test failed (a command failed with -e, or an expect failed). */
+void script_fail(const char *fmt, ...) __attribute__((noreturn));
+
 extern int tui_echo_commands;
 extern int tui_abort_on_fail;
 extern int tui_quiet;




More information about the netfilter-cvslog mailing list