Date:2010-04-26 23:30:21 (9 years 5 months ago)
Author:werner
Commit:bc27b094af74a7c6f8b71ceaa63d1ba80d067cbb
Message: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
Files: Makefile (2 diffs)
README (1 diff)
fped.c (4 diffs)
test/Common (1 diff)
test/tsort (1 diff)
tsort.c (1 diff)

Change Details

Makefile
8282# ----- Rules -----------------------------------------------------------------
8383
8484.PHONY: all dep depend clean install uninstall manual upload-manual
85.PHONY: update montage
85.PHONY: update montage test tests valgrind
8686
8787.SUFFIXES: .fig .xpm .ppm
8888
...... 
156156
157157-include $(OBJS:.o=.d)
158158
159# ----- Tests -----------------------------------------------------------------
160
161test tests: all
162        LANG= sh -c \
163          'passed=0 && cd test && \
164          for n in [a-z]*; do \
165          SCRIPT=$$n . ./$$n; done; \
166          echo "Passed all $$passed tests"'
167
168valgrind:
169        VALGRIND="valgrind -q" $(MAKE) tests
170
159171# ----- Cleanup ---------------------------------------------------------------
160172
161173clean:
README
613613%tsort is used to test-drive the topological sort algorithm. The items
614614in the curly braces are declarations of nodes with (-<id>) or without
615615(+<id>) decay or edges in the partial order. The optional number is
616the edge's priority. See tsort.c for details.
616the edge's priority. See tsort.c for details, test/tsort for examples.
fped.c
6565static void usage(const char *name)
6666{
6767    fprintf(stderr,
68"usage: %s [-k] [-p|-P] [cpp_option ...] [in_file [out_file]]\n\n"
68"usage: %s [-k] [-p|-P] [-T] [cpp_option ...] [in_file [out_file]]\n\n"
6969" -k write KiCad output, then exit\n"
7070" -p write Postscript output, then exit\n"
7171" -P write Postscript output (full page), then exit\n"
72" -T test mode. Load file, then exit\n"
7273" cpp_option -Idir, -Dname[=value], or -Uname\n"
7374    , name);
7475    exit(1);
...... 
8283    char *args[2];
8384    int fake_argc;
8485    char opt[] = "-?";
85    int error, batch;
86    int error;
87    int batch = 0;
8688    int batch_write_kicad = 0;
8789    int batch_write_ps = 0, batch_write_ps_fullpage = 0;
8890    int c;
8991
90    while ((c = getopt(argc, argv, "kpD:I:U:P")) != EOF)
92    while ((c = getopt(argc, argv, "kpD:I:PTU:")) != EOF)
9193        switch (c) {
9294        case 'k':
9395            batch_write_kicad = 1;
...... 
98100        case 'P':
99101            batch_write_ps_fullpage = 1;
100102            break;
103        case 'T':
104            batch = 1;
105            break;
101106        case 'D':
102107        case 'U':
103108        case 'I':
...... 
112117    if (batch_write_ps && batch_write_ps_fullpage)
113118        usage(name);
114119
115    batch = batch_write_kicad || batch_write_ps || batch_write_ps_fullpage;
120    if (batch_write_kicad || batch_write_ps || batch_write_ps_fullpage)
121        batch = 1;
116122
117123    if (!batch) {
118124        args[0] = name;
test/Common
1#!/bin/sh
2#
3# Common - Elements shared by all regression tests for fped
4#
5# Written 2010 by Werner Almesberger
6# Copyright 2010 Werner Almesberger
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13
14
15fped()
16{
17    echo -n "$1: " 1>&2
18    shift
19    cat >_in
20    $VALGRIND ../fped -T _in "$@" >_out 2>&1 || {
21    echo FAILED "($SCRIPT)" 1>&2
22    cat _out
23    rm -f _in _out
24    exit 1
25    }
26    rm -f _in
27}
28
29
30fped_fail()
31{
32    echo -n "$1: " 1>&2
33    shift
34    cat >_in
35    $VALGRIND ../fped -T _in "$@" >_out 2>&1 && {
36    echo FAILED "($SCRIPT)" 1>&2
37    cat _out
38    rm -f _in _out
39    exit 1
40    }
41    rm -f _in
42}
43
44
45expect()
46{
47    diff -u - "$@" _out >_diff || {
48    echo FAILED "($SCRIPT)" 1>&2
49    cat _diff 1>&2
50    rm -f _out _diff
51    exit 1
52    }
53    echo PASSED 1>&2
54    rm -f _out _diff
55    passed=`expr ${passed:-0} + 1`
56}
test/tsort
1#!/bin/sh
2. ./Common
3
4###############################################################################
5
6fped "tsort: total order" <<EOF
7package "_"
8
9%tsort {
10    a b
11    a c
12    a d
13    b c
14    b d
15    c d
16}
17EOF
18expect <<EOF
19a
20b
21c
22d
23EOF
24
25#------------------------------------------------------------------------------
26
27fped "tsort: partial order change (1)" <<EOF
28package "_"
29
30%tsort {
31    a b
32    a c
33    a d
34    d b
35}
36EOF
37expect <<EOF
38a
39c
40d
41b
42EOF
43
44#------------------------------------------------------------------------------
45
46fped "tsort: partial order change (2)" <<EOF
47package "_"
48
49%tsort {
50    b c
51    c d
52    a b
53}
54EOF
55expect <<EOF
56a
57b
58c
59d
60EOF
61
62#------------------------------------------------------------------------------
63
64fped "tsort: old order differs from resolution order" <<EOF
65package "_"
66
67%tsort {
68    +a +b +c +d
69    a c
70    a b
71    a d
72}
73EOF
74expect <<EOF
75a
76b
77c
78d
79EOF
80
81#------------------------------------------------------------------------------
82
83fped "tsort: order change due to priority" <<EOF
84package "_"
85
86%tsort {
87    a b
88    a c 1
89    a d
90}
91EOF
92expect <<EOF
93a
94c
95b
96d
97EOF
98
99#------------------------------------------------------------------------------
100
101fped "tsort: priority accumulation without decay" <<EOF
102package "_"
103
104%tsort {
105    +a +b +c +d
106    a b 1
107    a d 1
108}
109EOF
110expect <<EOF
111a
112b
113d
114c
115EOF
116
117#------------------------------------------------------------------------------
118
119fped "tsort: priority accumulation with decay" <<EOF
120package "_"
121
122%tsort {
123    +a -b +c +d
124    a b 1
125    a d 1
126}
127EOF
128expect <<EOF
129a
130b
131c
132d
133EOF
134
135#------------------------------------------------------------------------------
136
137fped_fail "tsort: cycle" <<EOF
138package "_"
139
140%tsort {
141    a b
142    b a
143}
144EOF
145expect <<EOF
146cycle detected in partial order
147Aborted (core dumped)
148EOF
149
150# not entirely comfortable about the "Aborted (core dumped)". It's a system
151# message (from the shell) that may get mangled. Also, since few people keep
152# their cores these days, "(core dumped)" shouldn't really appear. Wonder why
153# it does. strace agrees that __WCOREFLAG is set ...
154
155###############################################################################
tsort.c
152152        }
153153        free(node);
154154    }
155    if (tsort->nodes) /* we have at least one cycle */
155    if (tsort->nodes) {
156        fprintf(stderr, "cycle detected in partial order\n");
156157        abort();
158    }
157159    free(tsort);
158160    res[n] = NULL;
159161    return res;

Archive Download the corresponding diff file

Branches:
master



interactive