Home | History | Annotate | Download | only in freezer
      1 #!/bin/bash
      2 # Copyright (c) International Business Machines  Corp., 2008
      3 # Author: Matt Helsley <matthltc (at] us.ibm.com>
      4 #
      5 # This library is free software; you can redistribute it and/or
      6 # modify it under the terms of the GNU Lesser General Public
      7 # License as published by the Free Software Foundation; either
      8 # version 2.1 of the License, or (at your option) any later version.
      9 #
     10 # This library is distributed in the hope that it will be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13 # Lesser General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU Lesser General Public
     16 # License along with this library; if not, write to the Free Software
     17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     18 #
     19 
     20 #set -x
     21 P='ltp-cgroup-freezer'
     22 
     23 export EXIT_GOOD=0
     24 export EXIT_TERMINATE=-1
     25 
     26 
     27 trap "exit ${EXIT_TERMINATE}" ERR
     28 
     29 #
     30 # Run tests for freezer and signal controllers
     31 #
     32 
     33 	# TODO add:
     34 	#vfork_freeze.sh
     35 	# write signal/send_invalid_sig.sh
     36 	# write signal/read_signal.kill.sh
     37 FREEZER_TEST_SCRIPTS=(	write_freezing.sh
     38 			freeze_write_freezing.sh
     39 			freeze_thaw.sh
     40 			freeze_sleep_thaw.sh
     41 			freeze_kill_thaw.sh
     42 			freeze_move_thaw.sh
     43 			freeze_cancel.sh
     44 			freeze_self_thaw.sh
     45 			stop_freeze_thaw_cont.sh
     46 			stop_freeze_sleep_thaw_cont.sh
     47 			fork_freeze.sh )
     48 
     49 TEST_SCRIPTS=( )
     50 
     51 function test_setup()
     52 {
     53 	if [ -z "${LTPROOT}" ]; then
     54 		CGROUPS_TESTROOT="$(pwd)"
     55 		. libltp
     56 	else
     57 		CGROUPS_TESTROOT="${LTPROOT}/testcases/bin"
     58 	fi
     59 
     60 	#######################################################################
     61 	## Initialize some LTP variables -- Set _COUNT and _TOTAL to fake values
     62 	## else LTP complains.
     63 	#######################################################################
     64 	TCID="$0"
     65 	TST_COUNT=1
     66 	TST_TOTAL=$(( ${#TEST_SCRIPTS[@]} + 0 ))
     67 	TMPDIR="${TMPDIR:-/tmp}"
     68 
     69 	export LTPBIN PATH TCID TST_COUNT TST_TOTAL CGROUPS_TESTROOT
     70 	tst_resm TINFO "Preparing to run: ${P} $@"
     71 
     72 	# this is not require here
     73 	#make all
     74 }
     75 
     76 function test_prereqs()
     77 {
     78 	cat /proc/filesystems | grep -E '\bcgroup\b' > /dev/null 2>&1 || {
     79 		tst_resm TINFO "Kernel does not support cgroups. Skipping."
     80 		exit ${EXIT_GOOD} # 0
     81 	}
     82 
     83 	tst_resm TINFO " Testing prereqs for cgroup freezer tests."
     84 	if [ ! -f /proc/cgroups ]; then
     85 		tst_resm TINFO "Tests require cgroup freezer support in the kernel."
     86 		exit 1
     87 	fi
     88 
     89 	if [ "$(grep -w freezer /proc/cgroups | cut -f1)" != "freezer" ]; then
     90 		tst_resm TINFO "Tests require cgroup freezer support in the kernel."
     91 		exit 1
     92 	fi
     93 
     94 	. "${CGROUPS_TESTROOT}/libcgroup_freezer"
     95 
     96 	tst_resm TINFO " It's ok if there's an ERROR before the next INFO."
     97 	mount_freezer && umount_freezer && {
     98 		TEST_SCRIPTS=( "${TEST_SCRIPTS[@]}" "${FREEZER_TEST_SCRIPTS[@]}" )
     99 	}
    100 	tst_resm TINFO " OK, resume worrying about ERRORS."
    101 	export TST_TOTAL=$(( ${#TEST_SCRIPTS[@]} + 0 ))
    102 }
    103 
    104 function main()
    105 {
    106 	local rc=0
    107 
    108 	for TEST in "${TEST_SCRIPTS[@]}" ; do
    109 		export TCID="${TEST}"
    110 		tst_resm TINFO " running ${TEST}"
    111 		((TST_COUNT++))
    112 		export TST_COUNT
    113 		"${CGROUPS_TESTROOT}/${TEST}"
    114 		rc=$?
    115 
    116 		if [ $rc != 0 ]; then
    117 			tst_resm TFAIL "${TEST} $rc"
    118 			break
    119 		else
    120 			tst_resm TPASS "${TEST}"
    121 		fi
    122 	done
    123 	trap '' ERR
    124 	return $rc
    125 }
    126 
    127 test_setup && \
    128 test_prereqs && \
    129 declare -r TST_TOTAL && \
    130 main
    131 rc=$?
    132 trap '' ERR
    133 exit $rc
    134