Debian Codegraph @

tests/complexity.test

raw
1 #! /bin/sh
2
3 fail_exit() {
4 set +x
5 ct=1
6 while IFS='' read -r line
7 do
8 printf "%03u - %s\n" $ct "$line"
9 (( ct++ ))
10 done < ${outfile}
11 trap '' 0
12 exit 1
13 } 1>&2
14
15 set -x
16 srcdir=`cd ${top_srcdir}/src && pwd`
17 tstdir=${PWD}
18 rcfile="${tstdir}/.complexityrc"
19 outfile="${tstdir}/complexity.out"
20 samples=`cd ${srcdir}/../tests && \
21 ls -1 s*mple.c | sed "s@^@$PWD/@"`
22
23 cd ${top_builddir}
24
25 cat > "$rcfile" <<- _EOF_
26 hist
27 score
28 thresh 0
29 _EOF_
30 trap "rm -f '$rcfile' '${outfile}'" 0
31 cpx="${PWD}/src/complexity -< $rcfile"
32
33 cd ${srcdir}
34 ${cpx} -I main *.c > ${outfile}
35 cd ${tstdir}
36
37 set -e
38
39 lc=`grep -E '^Complexity (Scores|Histogram)$' ${outfile} | \
40 wc -l`
41
42 test $lc -eq 2 || {
43 echo "Could not find both titles in output" >&2
44 exit 1
45 }
46
47 lc=`grep -E '^ +0.*: +handle_noop' ${outfile} | wc -l`
48 test $lc -eq 1 || {
49 echo "'handle_noop' did not evaluate to zero" >&2
50 fail_exit
51 }
52
53 sedcmd='/^[A-Z]/d;/^$/d;/^Highest score:/d;s@ [^ ]*tests/@ @'
54 $cpx -t0 $samples 2>&1 | \
55 sed "$sedcmd" > ${outfile}
56 sampfile="${tstdir}/complexity.samp"
57 sed "$sedcmd" > ${sampfile} <<-_EOF_
58 Complexity Scores
59 Score | ln-ct | nc-lns| file-name(line): proc-name
60 0 1 1 .../tests/sample.c(1): oneline
61 0 1 1 .../tests/sample.c(15): tst
62 1 1 1 .../tests/sample.c(3): continuesameline
63 1 2 2 .../tests/sample.c(20): test
64 1 4 3 .../tests/sample.c(7): derefloop
65
66 Complexity Histogram
67 Score-Range Lin-Ct
68 0-9 8 ************************************************************
69
70 Scored procedure ct: 5
71 Non-comment line ct: 8
72 Average line score: 1
73 25%-ile score: 0 (75% in higher score procs)
74 50%-ile score: 1 (half in higher score procs)
75 75%-ile score: 1 (25% in higher score procs)
76 Highest score: 1 (continuesameline() in /.../sample.c)
77 _EOF_
78 set +e
79 grep -s -E '^error on ' ${outfile} && \
80 fail_exit
81 cmp ${outfile} ${sampfile} || \
82 fail_exit
83 rm -f ${outfile} ${sampfile}
84 exit 0