source: tests/test_util.sh @ 1afd681

abac0-leakabac0-mei
Last change on this file since 1afd681 was 3c30b59, checked in by Mei <mei@…>, 11 years ago

1) add in new refactored regression testing directory
2) undo the abac.hh/ABAC.hh api changes
3) merged with Ted's changes to attribute format/nickname/issuer processing

  • Property mode set to 100755
File size: 2.7 KB
Line 
1#!/bin/sh
2
3debug=0
4
5# look for creddy,
6if [ -n "${CREDDY_LOCATION}" ]; then
7    eloc=${CREDDY_LOCATION}
8    if ! [ -e $eloc/creddy ] ; then
9        echo "ERROR: has CREDDY_LOCATION but creddy is not there!!!"
10        exit 1
11    fi
12else
13    eloc=`which creddy | sed 's/\/creddy//'`
14    if [ -z "$eloc" ]; then
15        echo "ERROR: creddy is not in the search path nor CREDDY_LOCATION defined!!!"
16        exit 1
17    fi
18fi
19
20# look for abac_prover,
21if [ -n "${PROVER_LOCATION}" ]; then
22    ploc=${PROVER_LOCATION}
23    if ! [ -e $ploc/abac_prover ] ; then
24        echo "ERROR: has PROVER_LOCATION but abac_provery is not there!!!"
25        exit 1
26    fi
27else
28    ploc=`which abac_prover | sed 's/\/abac_prover//'`
29    if [ -z "$ploc" ]; then
30        echo "ERROR: abac_prover is not in the search path nor PROVER_LOCATION defined!!!"
31        exit 1
32    fi
33fi
34
35
36# runTest fname test1 testbody expect msg
37# if expect success, expect=0
38# if expect failure, expect=1
39runTest() {
40    FNAME=$1
41    LABEL=$2
42    TESTBODY=$3
43    EXPECT=$4
44    MSG=$5
45    rc=`${TESTBODY} 2>&1`
46    if [ $? -eq $EXPECT ]; then
47        echo "GOOD:${FNAME}:${LABEL}:${MSG}"
48    else
49        if [ $EXPECT ]; then
50           echo "BAD:${FNAME}:${LABEL}:expected failure but got success,${MSG}"
51        else
52           echo "BAD:${FNAME}:${LABEL}:${MSG}"
53        fi
54    fi
55    if [ $debug -eq 1 ]; then
56        echo $rc
57    fi
58}
59
60# runXTest fname test1 testbody expect matchResult msg
61# if expect success, expect=0
62# if expect failure, expect=1
63runXTest() {
64    FNAME=$1
65    LABEL=$2
66    TESTBODY=$3
67    EXPECT=$4
68    MATCH=$5
69    MSG=$6
70    rc=`${TESTBODY} 2>&1`
71    if [ $? -eq $EXPECT ]; then
72        match=`echo "${rc}" | grep "${MATCH}" | wc -l`
73        if [ $match -eq 1 ]; then
74            echo "GOOD:${FNAME}:${LABEL}:${MSG}"
75        else
76            echo "BADX:${FNAME}:${LABEL}:${MSG}, but result is not as expected"
77        fi
78    else
79        echo "BAD:${FNAME}:${LABEL}:${MSG}"
80    fi
81    if [ $debug -eq 1 ]; then
82        echo $rc
83    fi
84}
85
86# runCTest fname test1 testbody expect msg pattern count
87# if expect success, expect=0
88# if expect failure, expect=1
89runCTest() {
90    FNAME=$1
91    LABEL=$2
92    TESTBODY=$3
93    EXPECT=$4
94    MSG=$5
95    PATTERN=$6
96    COUNT=$7
97    rc=`${TESTBODY} 1>atmp 2>/dev/null`
98    if [ $? -eq $EXPECT ]; then
99        cnt=`grep "$PATTERN" atmp | wc -l`
100        if [ $cnt -eq $COUNT ]; then
101            echo "GOOD:${FNAME}:${LABEL}:${MSG}"
102        else
103            echo "BAD:${FNAME}:${LABEL}:${MSG},did not have expected output"
104        fi
105    else
106        if [ $EXPECT ]; then
107           echo "BAD:${FNAME}:${LABEL}:expected failure but got success,${MSG}"
108        else
109           echo "BAD:${FNAME}:${LABEL}:${MSG}"
110        fi
111    fi
112    rm -rf atmp
113    return 0
114}
Note: See TracBrowser for help on using the repository browser.