r4406 - in trunk/src/host/envedit: . tests xtests

werner at docs.openmoko.org werner at docs.openmoko.org
Tue Apr 29 03:40:57 CEST 2008


Author: werner
Date: 2008-04-29 03:40:56 +0200 (Tue, 29 Apr 2008)
New Revision: 4406

Added:
   trunk/src/host/envedit/CHANGES
   trunk/src/host/envedit/README
   trunk/src/host/envedit/tests/
   trunk/src/host/envedit/tests/Common
   trunk/src/host/envedit/tests/Makefile
   trunk/src/host/envedit/tests/blanks
   trunk/src/host/envedit/tests/cmdline
   trunk/src/host/envedit/tests/comment
   trunk/src/host/envedit/tests/wrap
   trunk/src/host/envedit/xtests/
   trunk/src/host/envedit/xtests/Common
   trunk/src/host/envedit/xtests/Env.sample
   trunk/src/host/envedit/xtests/Environment.in
   trunk/src/host/envedit/xtests/Makefile
   trunk/src/host/envedit/xtests/dump
   trunk/src/host/envedit/xtests/edits
   trunk/src/host/envedit/xtests/output
   trunk/src/host/envedit/xtests/processed
Modified:
   trunk/src/host/envedit/Makefile
   trunk/src/host/envedit/cpp.c
   trunk/src/host/envedit/cpp.h
   trunk/src/host/envedit/env.c
   trunk/src/host/envedit/envedit.c
   trunk/src/host/envedit/parse.c
Log:
Add regression tests, fix various parser bugs, most of them hidden by the
preprocessor.

- added README and CHANGES
- cpp.h, cpp.c: added global variable cpp_command to allow run-time override
  of preprocessor default
- envedit.c: new option -P to set the preprocessor command
- envedit.c: don't call the preprocessor "CPP"
- env.c (write_env): allocate the environment if not already present
- parse.c (flush): strip trailing blanks
- parse.c (newline): var\n must be followed by whitespace
- parse.c (newline): insert a blank in values when wrapping
- parse.c: new state st_spc_val_add that adds a blank for the first whitespace
  encountered and skips the rest
- parse.c: removed state st_spc_eq, because it's identical to st_spc_val
- parse.c: convert all whitespace to blanks
- parse.c (parse_edit): removed special-case state change on newline
- tests/: regression tests only for the C version of envedit
- xtests/: compatibility tests between the C and the Perl version
- env.c (set_env): passed the wrong string as variable name
- env.c (set_env): close memory leak



Added: trunk/src/host/envedit/CHANGES
===================================================================
--- trunk/src/host/envedit/CHANGES	                        (rev 0)
+++ trunk/src/host/envedit/CHANGES	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,21 @@
+2008-04-28: add regression tests, fix various parser bugs, most of them hidden
+  by the preprocessor
+
+- added README and CHANGES
+- cpp.h, cpp.c: added global variable cpp_command to allow run-time override
+  of preprocessor default
+- envedit.c: new option -P to set the preprocessor command
+- envedit.c: don't call the preprocessor "CPP"
+- env.c (write_env): allocate the environment if not already present
+- parse.c (flush): strip trailing blanks
+- parse.c (newline): var\n must be followed by whitespace
+- parse.c (newline): insert a blank in values when wrapping
+- parse.c: new state st_spc_val_add that adds a blank for the first whitespace
+  encountered and skips the rest
+- parse.c: removed state st_spc_eq, because it's identical to st_spc_val
+- parse.c: convert all whitespace to blanks
+- parse.c (parse_edit): removed special-case state change on newline
+- tests/: regression tests only for the C version of envedit
+- xtests/: compatibility tests between the C and the Perl version
+- env.c (set_env): passed the wrong string as variable name
+- env.c (set_env): close memory leak

Modified: trunk/src/host/envedit/Makefile
===================================================================
--- trunk/src/host/envedit/Makefile	2008-04-28 10:57:12 UTC (rev 4405)
+++ trunk/src/host/envedit/Makefile	2008-04-29 01:40:56 UTC (rev 4406)
@@ -7,7 +7,7 @@
 
 OBJS=envedit.o env.o parse.o var.o cpp.o
 
-.PHONY:		all install uninstall dep depend clean spotless
+.PHONY:		all install uninstall dep depend clean spotless test tests
 
 all:		envedit
 
@@ -29,3 +29,7 @@
 
 spotless:	clean
 		rm -f envedit
+
+test tests:	envedit
+		$(MAKE) -C tests
+		$(MAKE) -C xtests

Added: trunk/src/host/envedit/README
===================================================================
--- trunk/src/host/envedit/README	                        (rev 0)
+++ trunk/src/host/envedit/README	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,25 @@
+Quick example for updating the environment on a GTA02, with envedit
+running on the machine:
+
+
+- build the envedit binary for the Neo:
+
+  cd svn.openmoko.org/trunk/src/host/envedit
+  make clean
+  make CC=arm-angstrom-linux-gnueabi-gcc
+
+- preprocess the environment changes:
+
+  ./envcpp.pl -DGTA02 ../devirginator/environment.in >environment.prep
+
+- copy everything to the GTA02:
+
+  scp envedit environment.prep 192.168.0.202:
+
+- on the GTA02, run this:
+
+  DEV=/dev/mtd2
+  nanddump -b -o -f env.old $DEV
+  envedit -s 0x40000 -i env.old -o env.new -n -f environment.prep
+  flash_eraseall $DEV
+  nandwrite -p $DEV env.new

Modified: trunk/src/host/envedit/cpp.c
===================================================================
--- trunk/src/host/envedit/cpp.c	2008-04-28 10:57:12 UTC (rev 4405)
+++ trunk/src/host/envedit/cpp.c	2008-04-29 01:40:56 UTC (rev 4406)
@@ -1,9 +1,10 @@
 /*
  * cpp.c - CPP subprocess
  *
- * Written 2002-2004, 2006 by Werner Almesberger
+ * Written 2002-2004, 2006, 2008 by Werner Almesberger
  * Copyright 2002,2003 California Institute of Technology
  * Copyright 2004, 2006 Werner Almesberger
+ * Copyright 2008 by OpenMoko, Inc.
  *
  * Distributed under GPLv2, or any later version.
  */
@@ -21,6 +22,8 @@
 #include "cpp.h"
 
 
+const char *cpp_command = CPP;
+
 static pid_t cpp_pid;
 static int cpp_argc = 0;
 static const char **cpp_argv = NULL;
@@ -37,7 +40,7 @@
 	exit(1);
     }
     if (cpp_argc == 1)
-	cpp_argv[0] = CPP;
+	cpp_argv[0] = cpp_command;
     if (arg) {
 	arg = strdup(arg);
 	if (!arg) {
@@ -112,8 +115,9 @@
 	    perror("dup2");
 	    exit(1);
 	}
-	if (execvp(CPP,(char **) cpp_argv) < 0) { /* prototype is weird */
-	    perror("execvp " CPP);
+	if (execvp(cpp_command,(char **) cpp_argv) < 0) {
+	  /* prototype is weird */
+	    perror(cpp_command);
 	    exit(1);
 	}
 	/* not reached */

Modified: trunk/src/host/envedit/cpp.h
===================================================================
--- trunk/src/host/envedit/cpp.h	2008-04-28 10:57:12 UTC (rev 4405)
+++ trunk/src/host/envedit/cpp.h	2008-04-29 01:40:56 UTC (rev 4406)
@@ -1,7 +1,9 @@
 /*
  * cpp.h - CPP subprocess
  *
- * Written 2002,2003 by Werner Almesberger, Caltech Netlab FAST project
+ * Written 2002,2003,2008 by Werner Almesberger
+ * Copyright 2002,2003 Caltech Netlab FAST project
+ * Copyright 2008 by OpenMoko, Inc.
  *
  * Distributed under GPLv2, or any later version.
  *
@@ -10,6 +12,9 @@
 #ifndef CPP_H
 #define CPP_H
 
+
+extern const char *cpp_command;
+
 void add_cpp_arg(const char *arg);
 void add_cpp_Wp(const char *arg);
 void run_cpp_on_file(const char *name); /* NULL for stdin */

Modified: trunk/src/host/envedit/env.c
===================================================================
--- trunk/src/host/envedit/env.c	2008-04-28 10:57:12 UTC (rev 4405)
+++ trunk/src/host/envedit/env.c	2008-04-29 01:40:56 UTC (rev 4406)
@@ -65,17 +65,23 @@
 }
 
 
+static void alloc_env(void)
+{
+	env = malloc(env_size+1);
+	if (!env) {
+		perror("malloc");
+		exit(1);
+	}
+}
+
+
 void read_env(const char *name, int warn_crc)
 {
 	FILE *file;
 	size_t got;
 	uint32_t orig, crc;
 
-	env = malloc(env_size+1);
-	if (!env) {
-		perror("malloc");
-		exit(1);
-	}
+	alloc_env();
 	env[env_size] = 0; /* make sure parse_env stops */
 
 	file = file_open(name, "r", stdin);
@@ -181,6 +187,8 @@
 	uint32_t crc;
 	size_t wrote;
 
+	if (!env)
+		alloc_env();
 	memset(env, 0, env_size);
 	reset_var();
 	for (p = env+4; 1; p += n+1) {
@@ -232,9 +240,10 @@
 	}
 	*eq = 0;
 	if (eq[1])
-		set_var(var, eq+1);
+		set_var(tmp, eq+1);
 	else
-		del_var(var);
+		del_var(tmp);
+	free(tmp);
 }
 
 

Modified: trunk/src/host/envedit/envedit.c
===================================================================
--- trunk/src/host/envedit/envedit.c	2008-04-28 10:57:12 UTC (rev 4405)
+++ trunk/src/host/envedit/envedit.c	2008-04-29 01:40:56 UTC (rev 4406)
@@ -21,6 +21,9 @@
 #include "env.h"
 
 
+static const char *cpp_command_orig;
+
+
 static void usage(const char *name)
 {
 	fprintf(stderr,
@@ -29,21 +32,23 @@
 "  -c             ignore CRC errors in input environment\n"
 "  -f env_file    read changed from file (default: no changes from file)\n"
 "  -i file        read environment from file (default: use empty environment)\n"
-"  -n             don't run env_file through CPP\n"
+"  -n             don't run env_file through preprocessor\n"
 "  -o file        write environment to file (default: write to stdout)\n"
 "  -p             print environment in human-readable form\n"
 "  -s bytes       environment size in bytes (default: 16384)\n"
 "  -D var[=value] define a variable for env_file processing only\n"
+"  -P pp_cmd      preprocessor command. This must precede any -D options.\n"
+"                 (default: %s)\n"
 "  var=           remove the specified variable\n"
 "  var=value      set the specified variable\n",
-	  name, "");
+	  name, "", cpp_command_orig);
 	exit(1);
 }
 
 
 int main(int argc, char **argv)
 {
-	int warn_crc = 0;
+	int warn_crc = 0, cpp_locked = 0;
 	const char *env_file = NULL;
 	const char *in_file = NULL, *out_file = NULL;
 	int cpp = 1;
@@ -51,7 +56,8 @@
 	char *tmp, *end;
 	int c, i;
 
-	while ((c = getopt(argc, argv, "cf:i:no:ps:D:")) != EOF)
+	cpp_command_orig = cpp_command;
+	while ((c = getopt(argc, argv, "cf:i:no:ps:D:P:")) != EOF)
 		switch (c) {
 		case 'c':
 			warn_crc = 1;
@@ -77,6 +83,7 @@
 				usage(*argv);
 			break;
 		case 'D':
+			cpp_locked = 1;
 			tmp = malloc(strlen(optarg)+3);
 			if (!tmp) {
 				perror("strdup");
@@ -88,6 +95,13 @@
 			add_cpp_arg(tmp);
 			free(tmp);
 			break;
+		case 'P':
+			if (cpp_locked) {
+				fprintf(stderr, "-P must precede -D\n");
+				exit(1);
+			}
+			cpp_command = optarg;
+			break;
 		default:
 			usage(*argv);
 		}

Modified: trunk/src/host/envedit/parse.c
===================================================================
--- trunk/src/host/envedit/parse.c	2008-04-28 10:57:12 UTC (rev 4405)
+++ trunk/src/host/envedit/parse.c	2008-04-29 01:40:56 UTC (rev 4406)
@@ -26,9 +26,9 @@
 	st_0,		/* waiting for variable */
 	st_var,		/* in variable name */
 	st_spc_var,	/* skipping whitespace after variable name */
-	st_spc_eq,	/* skipping whitespace after equal sign */
 	st_val,		/* in value */
 	st_spc_val,	/* skipping whitespace in value */
+	st_spc_val_add,	/* add whitespace to value, then skip */
 } state = st_0;
 
 
@@ -43,13 +43,24 @@
 }
 
 
+static void trim(char *s)
+{
+	char *p;
+
+	for (p = strchr(s, 0)-1; p >= s && isspace(*p); p--)
+		*p = 0;
+}
+
+
 static void flush(void)
 {
 	assert(var);
-	if (value)
+	if (!value)
+		del_var(var);
+	else {
+		trim(value);
 		set_var(var, value);
-	else
-		del_var(var);
+	}
 	free(var);
 	if (value)
 		free(value);
@@ -105,7 +116,7 @@
 			break;
 		}
 		if (c == '=') {
-			state = st_spc_eq;
+			state = st_spc_val;
 			break;
 		}
 		if (!alnum(c))
@@ -116,12 +127,17 @@
 		if (isspace(c))
 			break;
 		if (c == '=') {
-			state = st_spc_eq;
+			state = st_spc_val;
 			break;
 		}
 		syntax();
 		break;
-	case st_spc_eq:
+	case st_spc_val_add:
+		if (isspace(c)) {
+			add_to_value(' ');
+			state = st_spc_val;
+		}
+		/* fall through */
 	case st_spc_val:
 		if (isspace(c))
 			break;
@@ -129,7 +145,10 @@
 		state = st_val;
 		break;
 	case st_val:
-		add_to_value(c);
+		if (!isspace(c))
+			add_to_value(c);
+		else
+			add_to_value(' ');
 		break;
 	default:
 		abort();
@@ -153,25 +172,24 @@
 		state = st_var;
 		break;
 	case st_var:
+		if (!isspace(c))
+			syntax();
 		state = st_spc_var;
 		/* fall through */
 	case st_spc_var:
 		in_line(c);
 		break;
-	case st_spc_eq:
-		if (isspace(c))
-			break;
-		goto flush;
+	case st_spc_val_add:
+		/* fall through */
 	case st_val:
-		if (isspace(c)) {
-			state = st_spc_val;
-			break;
-		}
-		goto flush;
+		trim(value);
+		add_to_value(' ');
+		state = st_spc_val;
+		/* fall through */
 	case st_spc_val:
-		if (isspace(c))
-			break;
-		goto flush;
+		if (!isspace(c))
+			goto flush;
+		break;
 	default:
 		abort();
 	}
@@ -187,7 +205,6 @@
 	case st_spc_var:
 		syntax();
 		break;
-	case st_spc_eq:
 	case st_val:
 	case st_spc_val:
 		flush();
@@ -207,21 +224,23 @@
 		int c;
 
 		c = fgetc(file);
+//fprintf(stderr, "[%d -> '%c']\n",state,c);
 		if (c == EOF)
 			break;
 		if (c == '#')
 			comment = 1;
 		if (c == '\n')
 			line++;
-		if (comment && c != '\n')
-			continue;
-		comment = 0;
+		if (comment) {
+			if (c != '\n')
+				continue;
+			comment = 0;
+			nl = 0;
+		}
 		if (c == '\n') {
 			if (nl)
 				double_newline();
 			nl = 1;
-			if (state == st_val)
-				state = st_spc_val;
 			continue;
 		}
 		if (nl)
@@ -238,7 +257,6 @@
 	case st_spc_var:
 		syntax();
 		break;
-	case st_spc_eq:
 	case st_val:
 	case st_spc_val:
 		flush();

Added: trunk/src/host/envedit/tests/Common
===================================================================
--- trunk/src/host/envedit/tests/Common	                        (rev 0)
+++ trunk/src/host/envedit/tests/Common	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+
+fail()
+{
+    echo FAILED "($SCRIPT)" 1>&2
+    cat _out 1>&2
+    exit 1
+}
+
+
+setup()
+{
+    echo -n "$1: " 1>&2
+    shift
+    ../envedit -o _env "$@" -P ../envcpp.pl -f - || fail
+}
+
+
+edit()
+{
+    ../envedit -i _env "$@" -P ../envcpp.pl -f - >_out 2>&1 || fail
+}
+
+
+edit_raw()
+{
+    ../envedit -i _env "$@" -n -f - >_out 2>&1 || fail
+}
+
+
+edit_fail()
+{
+    ../envedit -i _env "$@" -P ../envcpp.pl f - >_out 2>&1 && fail
+}
+
+
+edit_raw_fail()
+{
+    ../envedit -i _env "$@" -n -f - >_out 2>&1 && fail
+}
+
+
+expect()
+{
+    if ! diff -u - _out >_tmp; then
+	echo FAILED "($SCRIPT)" 1>&2
+	cat _tmp
+	exit
+    fi
+    rm -f _env _out _tmp
+    echo PASSED 1>&2
+    passed=`expr ${passed:-0} + 1`
+}

Added: trunk/src/host/envedit/tests/Makefile
===================================================================
--- trunk/src/host/envedit/tests/Makefile	                        (rev 0)
+++ trunk/src/host/envedit/tests/Makefile	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,11 @@
+.PHONY:	tests clean
+
+# Explicitly enumerate the lower case letters to escape localization weirdness.
+
+tests:
+	for n in [abcdefghijklmnopqrstuvwxyz]*; do \
+	  SCRIPT=$$n . ./$$n; done; \
+	  echo "Passed all $$passed tests" 2>&1
+
+clean:
+	rm -f _*

Added: trunk/src/host/envedit/tests/blanks
===================================================================
--- trunk/src/host/envedit/tests/blanks	                        (rev 0)
+++ trunk/src/host/envedit/tests/blanks	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,81 @@
+#!/bin/sh
+. Common
+
+# -----------------------------------------------------------------------------
+
+setup "one=eins" <<EOF
+EOF
+
+edit_raw -p <<EOF
+one=eins
+EOF
+
+expect <<EOF
+one=eins
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "two=deux  # comment" <<EOF
+EOF
+
+edit_raw -p <<EOF
+two=deux  # comment
+EOF
+
+expect <<EOF
+two=deux
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "three=  tres" <<EOF
+EOF
+
+edit_raw -p <<EOF
+three=  tres
+EOF
+
+expect <<EOF
+three=tres
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "four  =vier" <<EOF
+EOF
+
+edit_raw -p <<EOF
+four  =vier
+EOF
+
+expect <<EOF
+four=vier
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup " five=cinq (error)" <<EOF
+EOF
+
+edit_raw_fail -p <<EOF
+  five=cinq
+EOF
+
+expect <<EOF
+syntax error in line 1
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "abc = a b  c" <<EOF
+EOF
+
+edit_raw -p <<EOF
+abc = a b  c
+EOF
+
+expect <<EOF
+abc=a b  c
+EOF
+


Property changes on: trunk/src/host/envedit/tests/blanks
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/host/envedit/tests/cmdline
===================================================================
--- trunk/src/host/envedit/tests/cmdline	                        (rev 0)
+++ trunk/src/host/envedit/tests/cmdline	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,77 @@
+#!/bin/sh
+. Common
+
+# -----------------------------------------------------------------------------
+
+setup "command line: empty + one=eins" <<EOF
+EOF
+
+edit_raw -p one=eins <<EOF
+EOF
+
+expect <<EOF
+one=eins
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "command line: two=deux + two=dos" <<EOF
+two=deux
+EOF
+
+edit_raw -p two=dos <<EOF
+EOF
+
+expect <<EOF
+two=dos
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "command line: three=3 + four=vier" <<EOF
+three=3
+EOF
+
+edit_raw -p four=vier <<EOF
+EOF
+
+expect <<EOF
+four=vier
+three=3
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "command line: empty + five=" <<EOF
+EOF
+
+edit_raw -p five= <<EOF
+EOF
+
+expect <<EOF
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "command line: six=seis + six=" <<EOF
+six=seis
+EOF
+
+edit_raw -p six= <<EOF
+EOF
+
+expect <<EOF
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "command line: seven=sept + eight=" <<EOF
+seven=sept
+EOF
+
+edit_raw -p eight= <<EOF
+EOF
+
+expect <<EOF
+seven=sept
+EOF


Property changes on: trunk/src/host/envedit/tests/cmdline
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/host/envedit/tests/comment
===================================================================
--- trunk/src/host/envedit/tests/comment	                        (rev 0)
+++ trunk/src/host/envedit/tests/comment	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,117 @@
+#!/bin/sh
+. Common
+
+# -----------------------------------------------------------------------------
+
+setup "one=eins  # comment" <<EOF
+EOF
+
+edit_raw -p <<EOF
+one=eins  # comment
+EOF
+
+expect <<EOF
+one=eins
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "two=# comment\n dos" <<EOF
+EOF
+
+edit_raw -p <<EOF
+two=# comment
+ dos
+EOF
+
+expect <<EOF
+two=dos
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "three=  # comment\n trois" <<EOF
+EOF
+
+edit_raw -p <<EOF
+three=  # comment
+ trois
+EOF
+
+expect <<EOF
+three=trois
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "four#comment\n = cuatro" <<EOF
+EOF
+
+edit_raw -p <<EOF
+four#comment
+ = quatro
+EOF
+
+expect <<EOF
+four=quatro
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "five  #comment\n = fuenf" <<EOF
+EOF
+
+edit_raw -p <<EOF
+five  #comment
+ = fuenf
+EOF
+
+expect <<EOF
+five=fuenf
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "abc=# alpha\n a # beta\n b c # gamma" <<EOF
+EOF
+
+edit_raw -p <<EOF
+abc=#alpha
+ a # beta
+ b c #gamma
+EOF
+
+expect <<EOF
+abc=a b c
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "xy=x # foo\n# bar\n y" <<EOF
+EOF
+
+edit_raw -p <<EOF
+xy=x # foo
+# bar
+ y
+EOF
+
+expect <<EOF
+xy=x y
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "uv=u\n# foo\n# bar\n v" <<EOF
+EOF
+
+edit_raw -p <<EOF
+uv=u
+# foo
+# bar
+ v
+EOF
+
+expect <<EOF
+uv=u v
+EOF


Property changes on: trunk/src/host/envedit/tests/comment
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/host/envedit/tests/wrap
===================================================================
--- trunk/src/host/envedit/tests/wrap	                        (rev 0)
+++ trunk/src/host/envedit/tests/wrap	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,119 @@
+#!/bin/sh
+. Common
+
+# -----------------------------------------------------------------------------
+
+setup "one=\n eins" <<EOF
+EOF
+
+edit_raw -p <<EOF
+one=
+ eins
+EOF
+
+expect <<EOF
+one=eins
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "two=  \n  dos" <<EOF
+EOF
+
+# the test case below has whitespace at the end of the line !
+edit_raw -p <<EOF
+two=  
+  dos
+EOF
+
+expect <<EOF
+two=dos
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "three\n =trois" <<EOF
+EOF
+
+edit_raw -p <<EOF
+three
+ = trois
+EOF
+
+expect <<EOF
+three=trois
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "four  \n = cuatro" <<EOF
+EOF
+
+# the test case below has whitespace at the end of the line !
+edit_raw -p <<EOF
+four  
+ = quatro
+EOF
+
+expect <<EOF
+four=quatro
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "five=\nsix=sechs (two settings)" <<EOF
+EOF
+
+edit_raw -p <<EOF
+five=
+six=sechs
+EOF
+
+expect <<EOF
+six=sechs
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "seven\n=siete (invalid)" <<EOF
+EOF
+
+edit_raw_fail -p <<EOF
+seven
+=siete
+EOF
+
+expect <<EOF
+syntax error in line 2
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "abc=a\n b\n  c" <<EOF
+EOF
+
+edit_raw -p <<EOF
+abc=a
+ b
+  c
+EOF
+
+expect <<EOF
+abc=a b c
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "def=d \n e  \n  f   \n" <<EOF
+EOF
+
+# the test case below has whitespace at the end of all lines !
+edit_raw -p <<EOF
+def=d 
+ e  
+  f   
+EOF
+
+expect <<EOF
+def=d e f
+EOF


Property changes on: trunk/src/host/envedit/tests/wrap
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/host/envedit/xtests/Common
===================================================================
--- trunk/src/host/envedit/xtests/Common	                        (rev 0)
+++ trunk/src/host/envedit/xtests/Common	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,78 @@
+#!/bin/sh
+
+
+fail()
+{
+    echo FAILED "($SCRIPT)" 1>&2
+    cat _out_$1 _err_$1  1>&2
+    exit 1
+}
+
+
+setup()
+{
+    echo -n "$1: " 1>&2
+}
+
+
+edit_out()
+{
+    ../../devirginator/envedit.pl "$@" -o _out_1 >_err_1 2>&1 || fail 1
+    ../envedit -P ../envcpp.pl    "$@" -o _out_2 >_err_2 2>&1 || fail 2
+}
+
+
+edit()
+{
+    ../../devirginator/envedit.pl "$@" >_out_1 2>_err_1 || fail 1
+    ../envedit -P ../envcpp.pl    "$@" >_out_2 2>_err_2 || fail 2
+}
+
+
+process()
+{
+    in_file=$1
+    shift
+    pp_opts="$*"
+    ../envcpp.pl "$@" "$in_file" >_out_1 2>_err_1 || fail 1
+    mv _out_1 _in
+}
+
+
+edit_processed()
+{
+    ../../devirginator/envedit.pl $pp_opts \
+      "$@" -f "$in_file" >_out_1 2>_err_1 || fail 1
+    ../envedit -n \
+      "$@" -f _in        >_out_2 2>_err_2 || fail 2
+}
+
+
+expect()
+{
+    if ! diff -u _out_1 _out_2 >_tmp; then
+	echo FAILED "($SCRIPT)" 1>&2
+	cat _tmp
+	exit
+    fi
+    cat _err_1 _err_2 >_err
+    if ! diff -u - _err >_tmp; then
+	echo FAILED "($SCRIPT)" 1>&2
+	cat _tmp
+	exit
+    fi
+    rm -f _in _out_1 _out_2 _err_1 _err_2 _err _tmp
+    echo PASSED 1>&2
+    passed=`expr ${passed:-0} + 1`
+}
+
+
+differ()
+{
+    if diff -u _out_1 _out_2 >/dev/null; then
+	echo FAILED "($SCRIPT)" 1>&2
+	exit
+    fi
+    cp _out_1 _out_2
+    expect
+}

Added: trunk/src/host/envedit/xtests/Env.sample
===================================================================
(Binary files differ)


Property changes on: trunk/src/host/envedit/xtests/Env.sample
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/src/host/envedit/xtests/Environment.in
===================================================================
--- trunk/src/host/envedit/xtests/Environment.in	                        (rev 0)
+++ trunk/src/host/envedit/xtests/Environment.in	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,148 @@
+#
+# environment.in - The default environment
+#
+
+#
+# Note: for backwards-compatibility, we don't test whether the symbol "GTA01"
+# is defined, but we only test for "GTA02".
+#
+
+#ifdef GTA02
+
+#define CONSOLE ttySAC2
+#define ROOTDEV /dev/mtdblock6
+#define FRAMEBUFFER 0x8800000
+#define MMC_NUM 1
+
+#else # GTA01
+
+#define CONSOLE ttySAC0
+#define ROOTDEV /dev/mtdblock4
+#define FRAMEBUFFER 0x33d00000
+#define MMC_NUM 0
+
+#endif
+
+#ifdef INIT
+#define INIT_OPT init=INIT
+#else
+#define INIT_OPT
+#endif
+
+#ifndef SD_KERNEL
+#define SD_KERNEL uImage.bin
+#endif
+
+
+##### Common settings #########################################################
+
+
+bootargs_base=
+  rootfstype=jffs2
+  root=ROOTDEV
+  console=CONSOLE,115200
+  console=tty0
+  loglevel=8
+  INIT_OPT
+  regular_boot
+
+bootcmd=
+  setenv bootargs ${bootargs_base} ${mtdparts};
+  nand read.e 0x32000000 kernel 0x200000;
+  bootm 0x32000000
+
+stdout=usbtty
+stderr=usbtty
+stdin=usbtty
+
+usbtty=cdc_acm
+
+sd_image_name=SD_KERNEL
+
+
+##### Appearance and mode of interaction ######################################
+
+
+#ifdef NOR_ENV
+
+bootdelay=5
+boot_menu_timeout=60
+
+#else
+
+bootdelay=1
+
+quiet=1
+
+splashimage=
+  nand read.e 0x32000000 splash 0x5000;
+  unzip 0x32000000 FRAMEBUFFER 0x96000
+
+#endif
+
+
+##### Menu items ##############################################################
+
+
+menu_1=
+  Boot from microSD (FAT+ext2):
+  setenv bootargs
+    ${bootargs_base} rootfstype=ext2 root=/dev/mmcblk0p2 rootdelay=5
+    ${mtdparts} ro;
+  mmcinit;
+  fatload mmc MMC_NUM 0x32000000 ${sd_image_name};
+  bootm 0x32000000
+
+#ifdef ext2_not_broken_in_uboot
+
+menu_2=
+  Boot from microSD (ext2):
+  setenv bootargs
+    ${bootargs_base} rootfstype=ext2 root=/dev/mmcblk0p1 rootdelay=5
+    ${mtdparts} ro;
+  mmcinit;
+  ext2load mmc MMC_NUM 0x32000000 /boot/${sd_image_name};
+  bootm 0x32000000
+
+#endif
+
+#ifdef look_into_this_later_NOR_ENV
+
+menu_3=
+  Copy u-boot from NOR to NAND:
+  cp.l 0x18000000 0x32000000 0x10000;
+  mw.l 0x32000040 0 2;	# preboot_override and env_override
+  nand write.e 0x32000000 0 0x40000;
+  dynenv set u-boot_env
+
+#endif
+
+menu_4=
+  Set console to USB:
+  setenv stdin usbtty;
+  setenv stdout usbtty;
+  setenv stderr usbtty
+
+menu_5=
+  Set console to serial:
+  setenv stdin serial;
+  setenv stdout serial;
+  setenv stderr serial
+
+menu_6=
+  Reboot:
+  reset
+
+#ifdef UNUSED
+
+menu_7=
+  Factory reset:
+  defaultenv;
+  dynpart;
+  bootd
+
+#endif
+
+menu_8=
+  Power off:
+  neo1973 power-off

Added: trunk/src/host/envedit/xtests/Makefile
===================================================================
--- trunk/src/host/envedit/xtests/Makefile	                        (rev 0)
+++ trunk/src/host/envedit/xtests/Makefile	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,11 @@
+.PHONY:	tests clean
+
+# Explicitly enumerate the lower case letters to escape localization weirdness.
+
+tests:
+	for n in [abcdefghijklmnopqrstuvwxyz]*; do \
+	  SCRIPT=$$n . ./$$n; done; \
+	  echo "Passed all $$passed tests" 2>&1
+
+clean:
+	rm -f _*

Added: trunk/src/host/envedit/xtests/dump
===================================================================
--- trunk/src/host/envedit/xtests/dump	                        (rev 0)
+++ trunk/src/host/envedit/xtests/dump	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,28 @@
+#!/bin/sh
+. Common
+
+# -----------------------------------------------------------------------------
+
+setup "Dump example environment (correct size)"
+
+edit -s 0x40000 -i Env.sample -p
+
+expect <<EOF
+warning: skipping empty entry for "bootargs="
+warning: skipping empty entry for "bootargs="
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "Dump example environment (wrong size, thus CRC error)"
+
+edit -c -i Env.sample -p
+
+expect <<EOF
+warning: environment is 262144 bytes, expected 16384
+CRC error: expected 0xe0e5154e, got 0xda960321
+warning: skipping empty entry for "bootargs="
+warning: environment is 262144 bytes, expected 16384
+CRC error: file says 0xda960321, calculated 0xe0e5154e
+warning: skipping empty entry for "bootargs="
+EOF


Property changes on: trunk/src/host/envedit/xtests/dump
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/host/envedit/xtests/edits
===================================================================
--- trunk/src/host/envedit/xtests/edits	                        (rev 0)
+++ trunk/src/host/envedit/xtests/edits	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,71 @@
+#!/bin/sh
+. Common
+
+# -----------------------------------------------------------------------------
+
+setup "Dump edits (local copy, no defines)"
+
+edit -f Environment.in -p
+
+expect <<EOF
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "Dump edits (live devirginator version, no defines)"
+
+edit -f ../../devirginator/environment.in -p
+
+expect <<EOF
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "Dump edits (local copy, GTA01)"
+
+edit -D GTA01 -f Environment.in -p
+
+expect <<EOF
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "Dump edits (live devirginator version, GTA01)"
+
+edit -D GTA01 -f ../../devirginator/environment.in -p
+
+expect <<EOF
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "Dump edits (local copy, GTA02)"
+
+edit -D GTA02 -f Environment.in -p
+
+expect <<EOF
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "Dump edits (live devirginator version, GTA02)"
+
+edit -D GTA02 -f ../../devirginator/environment.in -p
+
+expect <<EOF
+EOF
+
+# -----------------------------------------------------------------------------
+
+#
+# The following test tests if we're actually testing something :-)
+#
+# It uses the fact that envedit.pl is very sensitive to the argument order.
+#
+
+setup "Force incompatibility (local copy, GTA02, wrong argument order)"
+
+edit -f Environment.in -p -D GTA02
+
+differ <<EOF
+EOF


Property changes on: trunk/src/host/envedit/xtests/edits
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/host/envedit/xtests/output
===================================================================
--- trunk/src/host/envedit/xtests/output	                        (rev 0)
+++ trunk/src/host/envedit/xtests/output	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,79 @@
+#!/bin/sh
+. Common
+
+# -----------------------------------------------------------------------------
+
+setup "Output example environment"
+
+edit_out -s 0x40000 -i Env.sample
+
+expect <<EOF
+warning: skipping empty entry for "bootargs="
+warning: skipping empty entry for "bootargs="
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "Output example environment, with edits (local copy, no define)"
+
+edit_out -s 0x40000 -i Env.sample -f Environment.in
+
+expect <<EOF
+warning: skipping empty entry for "bootargs="
+warning: skipping empty entry for "bootargs="
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "Output example environment, with edits (devirginator copy, no define)"
+
+edit_out -s 0x40000 -i Env.sample -f ../../devirginator/environment.in
+
+expect <<EOF
+warning: skipping empty entry for "bootargs="
+warning: skipping empty entry for "bootargs="
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "Output example environment, with edits (local copy, GTA01)"
+
+edit_out -D GTA01 -s 0x40000 -i Env.sample -f Environment.in
+
+expect <<EOF
+warning: skipping empty entry for "bootargs="
+warning: skipping empty entry for "bootargs="
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "Output example environment, with edits (devirginator copy, GTA01)"
+
+edit_out -D GTA01 -s 0x40000 -i Env.sample -f ../../devirginator/environment.in
+
+expect <<EOF
+warning: skipping empty entry for "bootargs="
+warning: skipping empty entry for "bootargs="
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "Output example environment, with edits (local copy, GTA02)"
+
+edit_out -D GTA02 -s 0x40000 -i Env.sample -f Environment.in
+
+expect <<EOF
+warning: skipping empty entry for "bootargs="
+warning: skipping empty entry for "bootargs="
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "Output example environment, with edits (devirginator copy, GTA02)"
+
+edit_out -D GTA02 -s 0x40000 -i Env.sample -f ../../devirginator/environment.in
+
+expect <<EOF
+warning: skipping empty entry for "bootargs="
+warning: skipping empty entry for "bootargs="
+EOF


Property changes on: trunk/src/host/envedit/xtests/output
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/host/envedit/xtests/processed
===================================================================
--- trunk/src/host/envedit/xtests/processed	                        (rev 0)
+++ trunk/src/host/envedit/xtests/processed	2008-04-29 01:40:56 UTC (rev 4406)
@@ -0,0 +1,35 @@
+#!/bin/sh
+. Common
+
+# -----------------------------------------------------------------------------
+
+setup "Processed edits, dump (local copy, no defines)"
+
+process Environment.in
+
+edit_processed -p
+
+expect <<EOF
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "Processed edits, environment output (local copy, GTA01)"
+
+process Environment.in -D GTA01
+
+edit_processed
+
+expect <<EOF
+EOF
+
+# -----------------------------------------------------------------------------
+
+setup "Processed edits, environment output (devirginator copy, GTA02)"
+
+process ../../devirginator/environment.in -D GTA02
+
+edit_processed
+
+expect <<EOF
+EOF


Property changes on: trunk/src/host/envedit/xtests/processed
___________________________________________________________________
Name: svn:executable
   + *





More information about the commitlog mailing list