#!/bin/sh 

noise=$1

rm -rf likes_$noise
mkdir likes_$noise
sed "s/#VAL#/$noise/" base/SETUP.py > likes_$noise/setup.py
sed "s/#VAL#/$noise/" base/QUERY.py > likes_$noise/query.py
sed "s/#VAL#/$noise/" base/BQUERY.py > likes_$noise/bquery.py
sed "s/#VAL#/$noise/" base/ATTR.py > likes_$noise/attr.py

cp base/RESULT likes_$noise/likes.save

cd likes_$noise
chmod +x setup.py attr.py query.py bquery.py
./setup.py 1>/dev/null 2>& 1
env keystore=`pwd` ./attr.py 1>/dev/null 2>& 1

echo "  forward.."
time env keystore=`pwd` ABAC_CN=1 ./query.py 1>likes.tmp 2> likes.time
result=`grep "YAP query succeed" likes.tmp 2>/dev/null`
if [ "$result" = "" ]; then
   echo "   ERROR"
else   
   echo "   PASSED"
fi

echo "  backward.."
time env keystore=`pwd` ABAC_CN=1 ./bquery.py 1>likes_b.tmp 2> likes_b.time
result=`grep "YAP query failed" likes_b.tmp 2>/dev/null`
if [ "$result" = "" ]; then
   echo "   ERROR"
else   
   echo "   PASSED"
fi
