[svn] / ecrypt / trunk / scripts / run  

svn: ecrypt/trunk/scripts/run

File: [svn] / ecrypt / trunk / scripts / run (download)
Revision: 61, Mon Aug 15 21:50:35 2005 UTC (7 years, 9 months ago) by cdecanni
File size: 4784 byte(s)
* improved scripts.
#!/bin/sh

[ -z "$BASH_VERSION" ] && (which bash > /dev/null 2>&1) && exec bash $0;

# -----------------------------------------------------------------------------

root=$(cd $(dirname $(which "$0"))/.. && pwd);

. $root/scripts/tools.sh;

# -----------------------------------------------------------------------------

dir=$1;

[ -n "$dir" ] || dir=.;

vectors=unverified.test-vectors;
cpu_speed=$(tail -n 1 "$root/config/cpuinfo");

if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" ]; then
    status 1 "warming up CPU";

    i=0;
    while [ $i -lt 10000 ]; do ((i++));
	curr_speed=$(awk '/^cpu MHz/ { print $4; exit; }' /proc/cpuinfo);
	
	[ $((${cpu_speed%.*} - ${curr_speed%.*})) -gt 10 ] \
	    || break;
    done

    status 1;
fi

# -----------------------------------------------------------------------------

run ()
{ 
    conf=$1;
    name=$(make name);

    status 1 "compiling $name under $conf";
	      
    make conf="$conf" clean &> /dev/null;

    cat > ./reports/info_current <<EOF
DATE:
-------------------------------------------------------------------------------
$(date)

CPU:
-------------------------------------------------------------------------------
$(head -n -1 "$root/config/cpuinfo")

COMPILER:
-------------------------------------------------------------------------------
$(make conf="$conf" version 2>&1)

COMPILATION:
-------------------------------------------------------------------------------
make conf="$conf"

$(make conf="$conf" 2>&1)

EXECUTABLE:
-------------------------------------------------------------------------------
EOF

    status 1;

    if make conf="$conf" -q &> /dev/null; then
	hash=$(make conf="$conf" hash 2> /dev/null);
    else
	echo "none" >> ./reports/info_current;
	mv ./reports/info_current ./reports/errors_$conf;
	error 0 "compilation failed (see ./reports/errors_$conf).";

	return;
    fi

    status 1 "checking for duplicates";

    matches=$(cd ./reports; grep -l "$hash" {info,speed}_*_* 2> /dev/null);

    status 1;

    echo "$hash" >> ./reports/info_current;

    if [ -n "$matches" ]; then
	info 1 "executable has been checked before (see $(echo $matches))";
	mv ./reports/info_current ./reports/info_$conf;

	return;
    fi

    test=$(make conf="$conf" command);

    status 1 "generating test vectors";

    error=$($test -v -q > ./reports/vectors_$conf 2> /dev/null; echo "$?"); 
    
    status 1;

    if [ "$error" -gt "1" ]; then
	mv ./reports/vectors_$conf ./reports/errors_$conf;
	error 0 "execution failed.";

	return;
    fi

    status 1 "verifying test vectors";

    if diff -waq ./reports/vectors_$conf $vectors > /dev/null; then
	status 1;
	rm -f ./reports/vectors_$conf;
    else
	if diff -wad ./reports/vectors_$conf $vectors \
	    | grep '<' > /dev/null; then
	    status 1;
	    mv ./reports/info_current ./reports/info_$conf;
	    error 0 "vectors do not match. check ./reports/vectors_$conf.";

	    return;
	else
	    status 1;
	    warning 1 "vectors are incomplete but match.";
	    rm -f ./reports/vectors_$conf;
	fi
    fi
	
    status 1 "running speed measurements on $cpu_speed MHz CPU";
    
    cat > ./reports/speed_$conf <<EOF
$($test -c $cpu_speed -s -k -p 2> /dev/null)

*******************************************************************************

$(cat ./reports/info_current)
EOF

    status 1;

    make conf="$conf" clean &> /dev/null;

    cycles=$(awk '{ sub(/\r/, ""); } /cycles\/byte/ { print $4; exit; }' \
	./reports/speed_$conf);

    info 1 "Current compilation of $name encrypts at $cycles cycles/byte."

    rm -f ./reports/info_current
}

# -----------------------------------------------------------------------------

process_dir ()
{
    dir=$1;
    conf=$2;

    info 1 "Entering directory $dir";

    for subdir in "$dir"/*; do
	if [ -d "$subdir" -a "$(basename $subdir)" != "reports" ]; then
	    (process_dir "$subdir" "$conf");
	fi
    done

    cd "$dir";

    [ -e $vectors ] || return 1;

    mkdir -p reports;

    errors=$(ls ./reports/{errors,vectors}_${conf%%_*}* 2> /dev/null | wc -l);

    if [ "$errors" -ge "5" ]; then
	error 0 "This implementation seems to be buggy. Please fix it first.";
	return;
    fi

    ls ./reports/*_$conf &> /dev/null || run $conf;
}

# -----------------------------------------------------------------------------

for conf in $(cd "$root/config/configs"; ls *.mk); do
    tag=$(awk '/tag = / { print $3; exit; }' "$root/config/configs/$conf");
    score=$(awk '/'$tag'/ { print $1; exit; }' "$root/config/shortlist");

    echo $((score + 0)) ${conf%.mk};
done | sort -rn | while read score conf; do
    info 1 "Testing $conf configuration (score: $score).";

    process_dir "$dir" $conf;
done

# -----------------------------------------------------------------------------

eSTREAM Project

Powered by ViewCVS 1.0-dev
(Powered by Apache)

ViewCVS and CVS Help