#!/bin/ksh
#
# Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
#
#---------------------------------------------------------------------------
# CONFIGURATION SECTION:  
#    Configure this script by changing the variables in this section.
#    Please change ONLY this section!
#---------------------------------------------------------------------------

# Base directory:
base_dir="/home/poplar45/kfr/dmapi/test/laguna/jaytest"

# Primary username:
p_user="kfr"

# Path to the mountpoint of the test filesystem:
m_main="/dmapi"

# m_main concatenated with d_name == the full test directory path
#
# EXAMPLE:  If m_main is "/dmitest", and the test directory
# is "/dmitest/test", set this to "/test"
#
d_name="/kfr/test_dir"

# Path to the mountpoint of the nfs2 test filesystem:
m_nfs2="/dmapi/kfr/nfs2"

# Path to the mountpoint of the nfs3 test filesystem:
m_nfs3="/dmapi/kfr/nfs3"

# Path to the mountpoint of the realtime test filesystem:
m_rt="/dmf"
# Path to the realtime test directory:
d_rt="$m_rt/kcm"

#--------------------------------------------------------------------
# END OF CONFIGURATION SECTION:
#    No changes should be made past this point!  Please change only   
#    the above shell variables to configure this script.
#--------------------------------------------------------------------

# Path to the "bindir" directory:
bin="$base_dir/bindir"

# Path to the "generic file" (a copy of ls): 
ls_path="$bin/ls_to_copy"

# Path to the main test directory:
d_main="$m_main$d_name"

# Path to the nfs2 test directory:
d_nfs2="$m_nfs2$d_name"

# Path to the nfs3 test directory:
d_nfs3="$m_nfs2$d_name"

PS3="> "
unset Vflag
unset Pflag

while true
do 
clear
print "+-------------------------+"
print "| DMAPI tests:  main menu |"
print "+-------------------------+\n"
select menu1 in 'DMAPI function tests, which run without a daemon' \
		'DMAPI event tests, which invoke and monitor a daemon' \
                'Basic DMAPI existence/version test' \
		'quit'
do case $menu1 in
    'DMAPI function tests, which run without a daemon')
    while true 
    do
    if [[ $Vflag = -v ]] 
    then Vstr='turn off verbose mode'
    else Vstr='turn on verbose mode'
    fi
    clear
    print "+----------------------+"
    print "| DMAPI function tests |"
    print "+----------------------+\n"
    select menu2 in  'ALL of the following function tests:' \
		    '    get/set_dmattr' \
		    '    get/set_eventlist' \
		    '    get/set_fileattr, get_bulkattr, get_dirattrs' \
		    '    probe/punch_hole' \
		    '    read/write_invis' \
		    '    get/set_region' \
		    '    EFAULT errno' \
		    '    EACCES errno and access rights' \
                    '    get_allocinfo vs. xfs_bmap' \
                    '    get_allocinfo with various buffer sizes' \
		    "$Vstr" \
		    'previous menu' \
		    'quit'
     do case $menu2 in
	'ALL of the following function tests:')
	    for run_me in \
		"$bin/test_dmattr $Vflag $ls_path $d_main" \
	        "$bin/test_eventlist $Vflag $ls_path $d_main" \
		"$bin/test_fileattr $Vflag $ls_path $d_main" \
		"$bin/test_hole $Vflag $ls_path $d_main" \
		"$bin/test_invis $Vflag $ls_path $d_main" \
		"$bin/test_region $Vflag $ls_path $d_main" \
		"$bin/test_efault $Vflag $ls_path $d_main" \
		"$bin/test_rights $Vflag $ls_path $d_main" \
		"$bin/test_allocinfo_1 $bin $d_main" \
		"$bin/test_allocinfo_2  $bin $d_main" 
	    do
	    eval $run_me
	    print "Press enter to continue..."; read go
	    done
	    break;;	
	'    get/set_dmattr')
	    eval "$bin/test_dmattr $Vflag $ls_path $d_main"
	    print "Press enter to continue..."; read go
	    break;;
	'    get/set_eventlist')
	    eval "$bin/test_eventlist $Vflag $ls_path $d_main"
	    print "Press enter to continue..."; read go
	    break;;
	'    get/set_fileattr, get_bulkattr, get_dirattrs')
	    eval "$bin/test_fileattr $Vflag $ls_path $d_main"
	    print "Press enter to continue..."; read go
	    break;;
	'    probe/punch_hole')
	    eval "$bin/test_hole $Vflag $ls_path $d_main"
	    print "Press enter to continue..."; read go
	    break;;
	'    read/write_invis')
	    eval "$bin/test_invis $Vflag $ls_path $d_main"
	    print "Press enter to continue..."; read go
	    break;;
	'    get/set_region')
	    eval "$bin/test_region $Vflag $ls_path $d_main"
	    print "Press enter to continue..."; read go
	    break;; 
	'    EFAULT errno') 
	    eval "$bin/test_efault $Vflag $ls_path $d_main"
	    print "Press enter to continue..."; read go
	    break;;
	'    EACCES errno and access rights')
	    eval "$bin/test_rights $Vflag $ls_path $d_main"
	    break;;
	'    get_allocinfo vs. xfs_bmap')
	    eval "$bin/test_allocinfo_1 $bin $d_main" 
	    print "Press enter to continue..."; read go
	    break;;
	'    get_allocinfo with various buffer sizes')
	    eval "$bin/test_allocinfo_2  $bin $d_main"
	    print "Press enter to continue..."; read go
	    break;;
	"$Vstr")
	    if [[ $Vflag = -v ]] 
	    then unset Vflag 
	    else Vflag=-v
	    fi
	    break;;
	'previous menu')
	    break 2;;
	'quit')
	    exit 0;;
	*) break;;
       esac
    done
    done
    break;;

    'DMAPI event tests, which invoke and monitor a daemon' )
    while true
    do
    if [[ $Pflag = -p ]] 
    then Pstr='turn off pausing after each command'
    else Pstr='turn on pausing after each command'
    fi
    clear
    print "+--------------------------+"
    print "| DMAPI daemon/event tests |"
    print "+--------------------------+\n"
    select menu2 in 'ALL of the following four:' \
		    '    standard i/o' \
		    '    abort responses to events, and other i/o' \
		    '    unsuccessful commands (bad file permissions)' \
		    '    dm_pending' \
		    'realtime filesystem' \
		    'small event queue' \
		    'nfs2 tests' \
		    'nfs3 tests' \
		    "$Pstr" \
		    'previous menu' \
		    'quit'
    do case $menu2 in
	'ALL of the following four:')
	for run_me in \
	    "$bin/run_test $Pflag -u $p_user -f standard.dat $bin $d_main $m_main" \
	    "$bin/run_test $Pflag -u $p_user $bin $d_main $m_main" \
	    "$bin/run_test $Pflag -u $p_user -f fail.dat $bin $d_main $m_main" \
	    "$bin/run_test $Pflag -u $p_user -f pending.dat $bin $d_main $m_main" 
	do
	    eval $run_me
	done
	break;;
	'    standard i/o')
	    eval "$bin/run_test $Pflag -u $p_user -f standard.dat $bin $d_main $m_main"
	    break;;
	'    abort responses to events, and other i/o')
	    eval "$bin/run_test $Pflag -u $p_user $bin $d_main $m_main"
	    break;;
	'    unsuccessful commands (bad file permissions)')
	    eval "$bin/run_test $Pflag -u $p_user -f fail.dat $bin $d_main $m_main"
	    break;;
	'    dm_pending')
	    eval "$bin/run_test $Pflag -u $p_user -f pending.dat $bin $d_main $m_main"
	    break;;
	'nfs2 tests')
	    while true
	    do
	    clear
	    print "+--------------------------------+"
	    print "| DMAPI daemon/event tests: nfs2 |"
	    print "+--------------------------------+\n"
	    select menu3 in 'ALL of the following four:' \
                            '    nfs2: standard i/o' \
			    '    nfs2: abort responses to events, and other i/o' \
			    '    nfs2: unsuccessful commands (bad file permissions)' \
			    '    nfs2: dm_pending' \
			    'previous menu' \
			    'quit'
	    do case $menu3 in
		'ALL of the following four:')
		    eval "$bin/run_test $Pflag -u $p_user -F nfs2 -M $m_nfs2 -R $d_main -f standard_nfs.dat $bin $d_nfs2 $m_main"
		    eval "$bin/run_test $Pflag -u $p_user -F nfs2 -M $m_nfs2 -R $d_main -f nfs.dat $bin $d_nfs2 $m_main"
		    eval "$bin/run_test $Pflag -u $p_user -F nfs2 -M $m_nfs2 -R $d_main -f fail.dat $bin $d_nfs2 $m_main"
		    eval "$bin/run_test $Pflag -u $p_user -F nfs2 -M $m_nfs2 -R $d_main -f pending_nfs.dat $bin $d_nfs2 $m_main"
		    break;;
                '    nfs2: standard i/o')
		    eval "$bin/run_test $Pflag -u $p_user -F nfs2 -M $m_nfs2 -R $d_main -f standard_nfs.dat $bin $d_nfs2 $m_main"
		    break;;
		'    nfs2: abort responses to events, and other i/o')
		    eval "$bin/run_test $Pflag -u $p_user -F nfs2 -M $m_nfs2 -R $d_main -f nfs.dat $bin $d_nfs2 $m_main"
		    break;;
		'    nfs2: unsuccessful commands (bad file permissions)')
		    eval "$bin/run_test $Pflag -u $p_user -F nfs2 -M $m_nfs2 -R $d_main -f fail.dat $bin $d_nfs2 $m_main"
		    break;;
		'    nfs2: dm_pending')
		    eval "$bin/run_test $Pflag -u $p_user -F nfs2 -M $m_nfs2 -R $d_main -f pending_nfs.dat $bin $d_nfs2 $m_main"
		    break;;
		'previous menu')
		    break 2;;
		'quit')
		    exit 0;;
	       esac
	    done
	    done
	    break;;
	'nfs3 tests')
	    while true 
	    do
	    clear
	    print "+--------------------------------+"
	    print "| DMAPI daemon/event tests: nfs3 |"
	    print "+--------------------------------+"
	    select menu3 in 'ALL of the following four:' \
                            '    nfs3: standard i/o' \
                            '    nfs3: abort responses to events, and other i/o' \
			    '    nfs3: unsuccessful commands (bad file permissions)' \
			    '    nfs3: dm_pending' \
			    'previous menu' \
			    'quit'
	    do case $menu3 in
		'ALL of the following four:')
		    eval "$bin/run_test $Pflag -u $p_user -F nfs3 -M $m_nfs3 -R $d_main -f standard_nfs.dat $bin $d_nfs3 $m_main"
		    eval "$bin/run_test $Pflag -u $p_user -F nfs3 -M $m_nfs3 -R $d_main -f nfs.dat $bin $d_nfs3 $m_main"
		    eval "$bin/run_test $Pflag -u $p_user -F nfs3 -M $m_nfs3 -R $d_main -f fail.dat $bin $d_nfs3 $m_main"
		    eval "$bin/run_test $Pflag -u $p_user -F nfs3 -M $m_nfs3 -R $d_main -f pending_nfs.dat $bin $d_nfs3 $m_main"
		    break;;
		'    nfs3: standard i/o')
		    eval "$bin/run_test $Pflag -u $p_user -F nfs3 -M $m_nfs3 -R $d_main -f standard_nfs.dat $bin $d_nfs3 $m_main"
		    break;;
		'    nfs3: abort responses to events, and other i/o')
		    eval "$bin/run_test $Pflag -u $p_user -F nfs3 -M $m_nfs3 -R $d_main -f nfs.dat $bin $d_nfs3 $m_main"
		    break;;
		'    nfs3: unsuccessful commands (bad file permissions)')
		    eval "$bin/run_test $Pflag -u $p_user -F nfs3 -M $m_nfs3 -R $d_main -f fail.dat $bin $d_nfs3 $m_main"
		    break;;
		'    nfs3: dm_pending')
		    eval "$bin/run_test $Pflag -u $p_user -F nfs3 -M $m_nfs3 -R $d_main -f pending_nfs.dat $bin $d_nfs3 $m_main"
		    break;;
		'previous menu')
		    break 2;;
		'quit')
		    exit 0;;
	       esac
	    done
	    done
	    break;;
	'realtime filesystem')
	    eval "$bin/run_test $Pflag -u $p_user -f realtime.dat $bin $d_rt $m_rt"
	    break;;
	'small event queue')
	    # Set dm_max_queued to about 5 or so before running!
	    eval "$bin/run_test $Pflag -u $p_user -s 2 -f smallq.dat $bin $d_main $m_main"
	    break;;
	"$Pstr")
	    if [[ $Pflag = -p ]] 
	    then unset Pflag
	    else Pflag=-p
	    fi
	    break;;
	'previous menu')
	    break 2;;
	'quit')
	    exit 0;;
       esac
    done
    done
    break;;
    'Basic DMAPI existence/version test')
       eval "$bin/check_dmapi $Vflag"
       print "Press enter to continue..."; read go
       break;;
    quit)
       break 2;;
    esac
    done
done
