Home | History | Annotate | Download | only in bin
      1 #! /usr/bin/ksh -p
      2 #
      3 # CDDL HEADER START
      4 #
      5 # The contents of this file are subject to the terms of the
      6 # Common Development and Distribution License (the "License").
      7 # You may not use this file except in compliance with the License.
      8 #
      9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10 # or http://www.opensolaris.org/os/licensing.
     11 # See the License for the specific language governing permissions
     12 # and limitations under the License.
     13 #
     14 # When distributing Covered Code, include this CDDL HEADER in each
     15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16 # If applicable, add the following below this CDDL HEADER, with the
     17 # fields enclosed by brackets "[]" replaced with your own identifying
     18 # information: Portions Copyright [yyyy] [name of copyright owner]
     19 #
     20 # CDDL HEADER END
     21 #
     22 
     23 #
     24 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     25 # Use is subject to license terms.
     26 #
     27 # ident	"@(#)stf_add_static_testcases.ksh	1.5	08/06/26 SMI"
     28 #
     29 
     30 . ${STF_TOOLS}/include/stf_common.kshlib
     31 
     32 function fail
     33 {
     34 	print -u2 "Fatal error creating testcases!"
     35 	exit 1
     36 }
     37 
     38 #
     39 # This script searches in the current directory for any statically
     40 # defined test cases and generates the appropriate test case list
     41 # during the configure process, using publicly defined interfaces.
     42 # The STF_*_TESTCASES variables are defined by the STF.  In creating
     43 # your own dynamic test case generator, follow the example syntax for
     44 # stf_addassert as indicated below.
     45 #
     46 # In our static cases below, the testcase name will be the same
     47 # as the test command, by virtue of the nature of statically defined
     48 # assertions.  See comments at the end of this file for an example
     49 # of dynamically defined testcases.  Note that the nominalizespaces
     50 # function removes gratuitous whitespace to ensure a variable is
     51 # defined as something actionable
     52 #
     53 
     54 #
     55 # Define root test cases, as indicated by the Makefile in the current
     56 # configuration directory
     57 #
     58 STF_ROOT_TESTCASES=$(nominalizespaces $STF_ROOT_TESTCASES)
     59 if (( ${#STF_ROOT_TESTCASES} )); then
     60 	print "Creating static root testcases in ${reldir}...\n"
     61 	for testcase in $STF_ROOT_TESTCASES; do
     62 		stf_addassert -u root -t "$testcase" \
     63 		    -c "$testcase" || fail
     64 	done
     65 fi
     66 
     67 #
     68 # Define user test cases, as indicated by the Makefile in the current
     69 # configuration directory
     70 #
     71 STF_USER_TESTCASES=$(nominalizespaces $STF_USER_TESTCASES)
     72 if (( ${#STF_USER_TESTCASES} )); then
     73 	print "Creating static user testcases in ${reldir}...\n"
     74 	for testcase in $STF_USER_TESTCASES; do
     75 		stf_addassert -t "$testcase" -c "$testcase" || fail
     76 	done
     77 fi
     78 
     79 #
     80 # More notes on creating a dynamic test case generator...
     81 #
     82 # Suppose that you have a configuration file called /var/tmp/mytest.cfg
     83 # and that the dynamic test cases to be run as root are based on the
     84 # values of var1, var2, var3, and foo1, foo2, foo3.  Each test case
     85 # will be run by a program called "runme".  A simple generator
     86 # could be constructed as follows:
     87 #
     88 # - Define STF_TESTCASES_GEN=mkassert_root in your Makefile for
     89 #   that test subdirectory
     90 #
     91 # - Create a mkassert_root.ksh testcase generator like the following:
     92 # 
     93 #  ----------------------------------------------------------------------
     94 #  #!/bin/ksh -p
     95 #  # source the config file to determine our config
     96 #
     97 #  . /var/tmp/mytest.cfg
     98 #
     99 #  for var in var1 var2 var3; do
    100 #  	for var2 in foo1 foo2 foo3; do
    101 #  		echo "gencomment: adding test $var-$var2..."
    102 #  		stf_addassert -u root -t "$var-$var2" -c runme $var:$var2
    103 #		if [[ $? -ne 0 ]]; then
    104 #		    echo "Failure adding test case $var-$var2, aborting." 2>&1
    105 #		    exit 1
    106 #		fi 
    107 #  	done
    108 #  done
    109 #  ----------------------------------------------------------------------
    110 # 
    111 # - In this example, runme is either a program defined as an STF_EXECUTABLE
    112 #   in the current test suite, some program in the test suite's bin path,
    113 #   or a program on the system.  Absolute path can be specified if needed.
    114 #   The example above says "Define a root-executed test called $var-$var2
    115 #   with test command "runme $var-$var2".  These tests are defined at configure
    116 #   time, so configuration and test cases can change based on user input
    117 #   with no compilation changes.
    118 #
    119