#!/bin/sh 

######################################################################
# FileName    [regerssion_test]
#
# Synopsis    [Script to perform regression tests]
#
# Description [This script can be used to perform regression tests of
#              the NuSMV system. To run this script you have to pass
#              as arguments to the script itself the source directory
#              where the directory containing the examples can be
#              found, and the name of the directory of examples.
#              Eg. suppose the examples are located in
#              /export/nusmv/nusmv/examples the script has to be
#              called as:
#              regression_test /export/nusmv/nusmv examples
#              The script searches direcories for files ending in
#              ".smv" if any. For each file "file.smv" found it looks if
#              there exist the files "file.ord" and "file.opt". The
#              first is the file contains the ordering of variables,
#              the second contains the options that ahve to be passed
#              to NuSMV to execute fastly the corresponding example.]
#
# Author      [Marco Roveri]
#
# Copyright   [Copyright (c) 1998 by ITC-IRST and Carnegie Mellon University.
#              All Rights Reserved.  This software is for educational
#              purposes only. Permission is given to use, copy, modify,
#              and distribute this software and its documentation
#              provided that this introductory message is not removed
#              and no monies are exchanged. No guarantee is expressed
#              or implied by the distribution of this code. 
#              Send bug-reports and/or questions to: nusmv@irst.itc.it
#             ]
#
######################################################################

examples=

# The NuSMV executable
NuSMV=NuSMV

# The examples dir
example_dir=.

if [ $# -ne 0 ]; then
    if [ -d $1 ]; then
        example_dir=$1/$2
        NuSMV=$1/${NuSMV}
        echo $example_dir
        echo $NuSMV
    else
        echo Error $1 does not exists
        exit 1
    fi
else 
    echo "####################################################################"
    echo "Usage: $0 <src_dir> <example_subdir>"
    echo "####################################################################"
    exit 1
fi

# extracts the examples file from the example dir
example_pb="{a7|reactor|futurebus|tcas16|abp16}"
examples=`find ${example_dir} -name "*.smv" -print| grep -v "${example_pb}"`

# NuSMV options
orig_options="-v 1 " 
options=

for file in ${examples}; do
    echo "----------------------------------"
    echo Checking $file
    echo "----------------------------------"
    ord_file=`echo $file | cut -f-2 -d"."`
    opt_file=`echo $file | cut -f-2 -d"."`
    options="${orig_options}"
    if [ -f ${ord_file}.ord ]; then
        options="${options} -i ${ord_file}.ord"
    fi
    if [ -f ${opt_file}.opt ]; then
        options="${options} `cat ${opt_file}.opt`"
    fi
    echo ${NuSMV} ${options} $file
    ${NuSMV} ${options} $file
done
