mirror of
git://projects.qi-hardware.com/fped.git
synced 2024-11-22 06:34:05 +02:00
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 git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5943 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
parent
190bcaf982
commit
bc27b094af
14
Makefile
14
Makefile
@ -82,7 +82,7 @@ endif
|
|||||||
# ----- Rules -----------------------------------------------------------------
|
# ----- Rules -----------------------------------------------------------------
|
||||||
|
|
||||||
.PHONY: all dep depend clean install uninstall manual upload-manual
|
.PHONY: all dep depend clean install uninstall manual upload-manual
|
||||||
.PHONY: update montage
|
.PHONY: update montage test tests valgrind
|
||||||
|
|
||||||
.SUFFIXES: .fig .xpm .ppm
|
.SUFFIXES: .fig .xpm .ppm
|
||||||
|
|
||||||
@ -156,6 +156,18 @@ dep depend .depend:
|
|||||||
|
|
||||||
-include $(OBJS:.o=.d)
|
-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 ---------------------------------------------------------------
|
# ----- Cleanup ---------------------------------------------------------------
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
2
README
2
README
@ -613,4 +613,4 @@ output. %exit immediately exits fped, without invoking the GUI.
|
|||||||
%tsort is used to test-drive the topological sort algorithm. The items
|
%tsort is used to test-drive the topological sort algorithm. The items
|
||||||
in the curly braces are declarations of nodes with (-<id>) or without
|
in the curly braces are declarations of nodes with (-<id>) or without
|
||||||
(+<id>) decay or edges in the partial order. The optional number is
|
(+<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.
|
||||||
|
14
fped.c
14
fped.c
@ -65,10 +65,11 @@ static void load_file(const char *name)
|
|||||||
static void usage(const char *name)
|
static void usage(const char *name)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
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"
|
" -k write KiCad output, then exit\n"
|
||||||
" -p write Postscript output, then exit\n"
|
" -p write Postscript output, then exit\n"
|
||||||
" -P write Postscript output (full page), 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"
|
" cpp_option -Idir, -Dname[=value], or -Uname\n"
|
||||||
, name);
|
, name);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -82,12 +83,13 @@ int main(int argc, char **argv)
|
|||||||
char *args[2];
|
char *args[2];
|
||||||
int fake_argc;
|
int fake_argc;
|
||||||
char opt[] = "-?";
|
char opt[] = "-?";
|
||||||
int error, batch;
|
int error;
|
||||||
|
int batch = 0;
|
||||||
int batch_write_kicad = 0;
|
int batch_write_kicad = 0;
|
||||||
int batch_write_ps = 0, batch_write_ps_fullpage = 0;
|
int batch_write_ps = 0, batch_write_ps_fullpage = 0;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "kpD:I:U:P")) != EOF)
|
while ((c = getopt(argc, argv, "kpD:I:PTU:")) != EOF)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'k':
|
case 'k':
|
||||||
batch_write_kicad = 1;
|
batch_write_kicad = 1;
|
||||||
@ -98,6 +100,9 @@ int main(int argc, char **argv)
|
|||||||
case 'P':
|
case 'P':
|
||||||
batch_write_ps_fullpage = 1;
|
batch_write_ps_fullpage = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'T':
|
||||||
|
batch = 1;
|
||||||
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
case 'U':
|
case 'U':
|
||||||
case 'I':
|
case 'I':
|
||||||
@ -112,7 +117,8 @@ int main(int argc, char **argv)
|
|||||||
if (batch_write_ps && batch_write_ps_fullpage)
|
if (batch_write_ps && batch_write_ps_fullpage)
|
||||||
usage(name);
|
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) {
|
if (!batch) {
|
||||||
args[0] = name;
|
args[0] = name;
|
||||||
|
56
test/Common
Executable file
56
test/Common
Executable file
@ -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`
|
||||||
|
}
|
155
test/tsort
Normal file
155
test/tsort
Normal file
@ -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 ...
|
||||||
|
|
||||||
|
###############################################################################
|
4
tsort.c
4
tsort.c
@ -152,8 +152,10 @@ void **end_tsort(struct tsort *tsort)
|
|||||||
}
|
}
|
||||||
free(node);
|
free(node);
|
||||||
}
|
}
|
||||||
if (tsort->nodes) /* we have at least one cycle */
|
if (tsort->nodes) {
|
||||||
|
fprintf(stderr, "cycle detected in partial order\n");
|
||||||
abort();
|
abort();
|
||||||
|
}
|
||||||
free(tsort);
|
free(tsort);
|
||||||
res[n] = NULL;
|
res[n] = NULL;
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
Reference in New Issue
Block a user