r5943 - in trunk/eda/fped: . test

werner at docs.openmoko.org werner at docs.openmoko.org
Mon Apr 26 23:30:22 CEST 2010


Author: werner
Date: 2010-04-26 23:30:21 +0200 (Mon, 26 Apr 2010)
New Revision: 5943

Added:
   trunk/eda/fped/test/
   trunk/eda/fped/test/Common
   trunk/eda/fped/test/tsort
Modified:
   trunk/eda/fped/Makefile
   trunk/eda/fped/README
   trunk/eda/fped/fped.c
   trunk/eda/fped/tsort.c
Log:
With a little help from m8cutils and abyss, we now have regression tests for
the topological sort. "make test" or "make tests" invokes the regression tests,
"make valgrind" runs them under valgrind's watchful eyes.

- fped.c (usage, main): added option -T to force batch mode (for regression
  testing)
- Makefile, test/Common: added regression test infrastructure
- test/tsort: test cases for the topological sort
- README: added pointer to test/tsort



Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile	2010-04-26 15:18:01 UTC (rev 5942)
+++ trunk/eda/fped/Makefile	2010-04-26 21:30:21 UTC (rev 5943)
@@ -82,7 +82,7 @@
 # ----- Rules -----------------------------------------------------------------
 
 .PHONY:		all dep depend clean install uninstall manual upload-manual
-.PHONY:		update montage
+.PHONY:		update montage test tests valgrind
 
 .SUFFIXES:	.fig .xpm .ppm
 
@@ -156,6 +156,18 @@
 
 -include $(OBJS:.o=.d)
 
+# ----- Tests -----------------------------------------------------------------
+
+test tests:	all
+		LANG= sh -c \
+		  'passed=0 && cd test && \
+		  for n in [a-z]*; do \
+		  SCRIPT=$$n . ./$$n; done; \
+		  echo "Passed all $$passed tests"'
+
+valgrind:
+		VALGRIND="valgrind -q" $(MAKE) tests
+
 # ----- Cleanup ---------------------------------------------------------------
 
 clean:

Modified: trunk/eda/fped/README
===================================================================
--- trunk/eda/fped/README	2010-04-26 15:18:01 UTC (rev 5942)
+++ trunk/eda/fped/README	2010-04-26 21:30:21 UTC (rev 5943)
@@ -613,4 +613,4 @@
 %tsort is used to test-drive the topological sort algorithm. The items
 in the curly braces are declarations of nodes with (-<id>) or without
 (+<id>) decay or edges in the partial order. The optional number is
-the edge's priority. See tsort.c for details.
+the edge's priority. See tsort.c for details, test/tsort for examples.

Modified: trunk/eda/fped/fped.c
===================================================================
--- trunk/eda/fped/fped.c	2010-04-26 15:18:01 UTC (rev 5942)
+++ trunk/eda/fped/fped.c	2010-04-26 21:30:21 UTC (rev 5943)
@@ -65,10 +65,11 @@
 static void usage(const char *name)
 {
 	fprintf(stderr,
-"usage: %s [-k] [-p|-P] [cpp_option ...] [in_file [out_file]]\n\n"
+"usage: %s [-k] [-p|-P] [-T] [cpp_option ...] [in_file [out_file]]\n\n"
 "  -k          write KiCad output, then exit\n"
 "  -p          write Postscript output, then exit\n"
 "  -P          write Postscript output (full page), then exit\n"
+"  -T          test mode. Load file, then exit\n"
 "  cpp_option  -Idir, -Dname[=value], or -Uname\n"
     , name);
 	exit(1);
@@ -82,12 +83,13 @@
 	char *args[2];
 	int fake_argc;
 	char opt[] = "-?";
-	int error, batch;
+	int error;
+	int batch = 0;
 	int batch_write_kicad = 0;
 	int batch_write_ps = 0, batch_write_ps_fullpage = 0;
 	int c;
 
-	while ((c = getopt(argc, argv, "kpD:I:U:P")) != EOF)
+	while ((c = getopt(argc, argv, "kpD:I:PTU:")) != EOF)
 		switch (c) {
 		case 'k':
 			batch_write_kicad = 1;
@@ -98,6 +100,9 @@
 		case 'P':
 			batch_write_ps_fullpage = 1;
 			break;
+		case 'T':
+			batch = 1;
+			break;
 		case 'D':
 		case 'U':
 		case 'I':
@@ -112,7 +117,8 @@
 	if (batch_write_ps && batch_write_ps_fullpage)
 		usage(name);
 
-	batch = batch_write_kicad || batch_write_ps || batch_write_ps_fullpage;
+	if (batch_write_kicad || batch_write_ps || batch_write_ps_fullpage)
+		batch = 1;
 
 	if (!batch) {
 		args[0] = name;

Added: trunk/eda/fped/test/Common
===================================================================
--- trunk/eda/fped/test/Common	                        (rev 0)
+++ trunk/eda/fped/test/Common	2010-04-26 21:30:21 UTC (rev 5943)
@@ -0,0 +1,56 @@
+#!/bin/sh
+#
+# Common - Elements shared by all regression tests for fped
+#
+# Written 2010 by Werner Almesberger
+# Copyright 2010 Werner Almesberger
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+
+
+fped()
+{
+    echo -n "$1: " 1>&2
+    shift
+    cat >_in
+    $VALGRIND ../fped -T _in "$@" >_out 2>&1 || {
+	echo FAILED "($SCRIPT)" 1>&2
+	cat _out
+	rm -f _in _out
+	exit 1
+    }
+    rm -f _in
+}
+
+
+fped_fail()
+{
+    echo -n "$1: " 1>&2
+    shift
+    cat >_in
+    $VALGRIND ../fped -T _in "$@" >_out 2>&1 && {
+	echo FAILED "($SCRIPT)" 1>&2
+	cat _out
+	rm -f _in _out
+	exit 1
+    }
+    rm -f _in
+}
+
+
+expect()
+{
+    diff -u - "$@" _out >_diff || {
+	echo FAILED "($SCRIPT)" 1>&2
+	cat _diff 1>&2
+	rm -f _out _diff
+	exit 1
+    }
+    echo PASSED 1>&2
+    rm -f _out _diff
+    passed=`expr ${passed:-0} + 1`
+}


Property changes on: trunk/eda/fped/test/Common
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/eda/fped/test/tsort
===================================================================
--- trunk/eda/fped/test/tsort	                        (rev 0)
+++ trunk/eda/fped/test/tsort	2010-04-26 21:30:21 UTC (rev 5943)
@@ -0,0 +1,155 @@
+#!/bin/sh
+. ./Common
+
+###############################################################################
+
+fped "tsort: total order" <<EOF
+package "_"
+
+%tsort {
+	a b
+	a c
+	a d
+	b c
+	b d
+	c d
+}
+EOF
+expect <<EOF
+a
+b
+c
+d
+EOF
+
+#------------------------------------------------------------------------------
+
+fped "tsort: partial order change (1)" <<EOF
+package "_"
+
+%tsort {
+	a b
+	a c
+	a d
+	d b
+}
+EOF
+expect <<EOF
+a
+c
+d
+b
+EOF
+
+#------------------------------------------------------------------------------
+
+fped "tsort: partial order change (2)" <<EOF
+package "_"
+
+%tsort {
+	b c
+	c d
+	a b
+}
+EOF
+expect <<EOF
+a
+b
+c
+d
+EOF
+
+#------------------------------------------------------------------------------
+
+fped "tsort: old order differs from resolution order" <<EOF
+package "_"
+
+%tsort {
+	+a +b +c +d
+	a c
+	a b
+	a d
+}
+EOF
+expect <<EOF
+a
+b
+c
+d
+EOF
+
+#------------------------------------------------------------------------------
+
+fped "tsort: order change due to priority" <<EOF
+package "_"
+
+%tsort {
+	a b
+	a c 1
+	a d
+}
+EOF
+expect <<EOF
+a
+c
+b
+d
+EOF
+
+#------------------------------------------------------------------------------
+
+fped "tsort: priority accumulation without decay" <<EOF
+package "_"
+
+%tsort {
+	+a +b +c +d
+	a b 1
+	a d 1
+}
+EOF
+expect <<EOF
+a
+b
+d
+c
+EOF
+
+#------------------------------------------------------------------------------
+
+fped "tsort: priority accumulation with decay" <<EOF
+package "_"
+
+%tsort {
+	+a -b +c +d
+	a b 1
+	a d 1
+}
+EOF
+expect <<EOF
+a
+b
+c
+d
+EOF
+
+#------------------------------------------------------------------------------
+
+fped_fail "tsort: cycle" <<EOF
+package "_"
+
+%tsort {
+	a b
+	b a
+}
+EOF
+expect <<EOF
+cycle detected in partial order
+Aborted (core dumped)
+EOF
+
+# not entirely comfortable about the "Aborted (core dumped)". It's a system
+# message (from the shell) that may get mangled. Also, since few people keep
+# their cores these days, "(core dumped)" shouldn't really appear. Wonder why
+# it does. strace agrees that __WCOREFLAG is set ...
+
+###############################################################################

Modified: trunk/eda/fped/tsort.c
===================================================================
--- trunk/eda/fped/tsort.c	2010-04-26 15:18:01 UTC (rev 5942)
+++ trunk/eda/fped/tsort.c	2010-04-26 21:30:21 UTC (rev 5943)
@@ -152,8 +152,10 @@
 		}
 		free(node);
 	}
-	if (tsort->nodes) /* we have at least one cycle */
+	if (tsort->nodes) {
+		fprintf(stderr, "cycle detected in partial order\n");
 		abort();
+	}
 	free(tsort);
 	res[n] = NULL;
 	return res;




More information about the commitlog mailing list