#!/bin/sh

#########
# run_test
#

unset keystore
unset ABAC_CN

./cleanup.sh all
./setup.sh 1>/dev/null 2>&1
./policy.sh 1>/dev/null 2>&1

sed -f sfile yap_clauses > main_yap_clauses

# run_it s1
a_run()
{
    echo "---running scenario $1 "
    ./cleanup.sh
    ./policy.sh 1> /dev/null 2>&1
    ./scenario_$1.sh 1> /dev/null 2>&1
    sed -f sfile_$1 $1_yap_clauses > my_$1_yap_clauses

    ./$1_run_query > $1_result.sha
    ./$1_query.py >> $1_result.sha

    env ABAC_CN=1 ./$1_query.py > $1_result.cn
    env ABAC_CN=1 ./$1_run_query >> $1_result.cn

    rm -rf sfile*

    result=`diff -I "Restoring file" -I "YAP 6.3" $1_result.cn $1_result.save`
    if [ $? -eq 0 ]; then
        if [ "$result" = "" ]; then
           echo "   PASSED"
        else
           echo "   ERROR: access creddy_prover $1 test result differs!!!"
        fi
    else
        echo "   ERROR: access creddy_prover $1 test result differs!!!"
    fi
}

a_run s1
a_run s2
a_run s3
a_run s4
a_run s5
a_run s6

env ABAC_CN=1 ./dumpdb.py 1> yapdb_dump 2>&1
