1#!/bin/sh 2################################################################################ 3## ## 4## Copyright (c) International Business Machines Corp., 2008 ## 5## Copyright (c) Jinbing Guo, guojb@cn.ibm.com, 2008 ## 6## ## 7## This program is free software; you can redistribute it and#or modify ## 8## it under the terms of the GNU General Public License as published by ## 9## the Free Software Foundation; either version 2 of the License, or ## 10## (at your option) any later version. ## 11## ## 12## This program is distributed in the hope that it will be useful, but ## 13## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## 14## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## 15## for more details. ## 16## ## 17## You should have received a copy of the GNU General Public License ## 18## along with this program; if not, write to the Free Software ## 19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## 20## ## 21################################################################################ 22################################################################################ 23# File : run_semaphore_test_01.sh 24# 25# Description: run semaphore_test_01, check the result, clean the resource. 26# 27# Author: Jinbing Guo, guojb@cn.ibm.com 28# 29# History: Aug. 14 2008 - Created - Jinbing Guo. 30# 31################################################################################ 32# 33# Function: setup 34# 35# Description: - Check if required commands exits 36# - Export global variables 37# - Check if required config files exits 38# - Create temporary files and directories 39# 40# Return - zero on success 41# - non zero on failure. return value from commands ($RC) 42setup() 43{ 44export TST_TOTAL=1 # Total number of test cases in this file. 45LTPTMP=${TMP} # Temporary directory to create files, etc. 46export TCID="setup" # Test case identifier 47export TST_COUNT=0 # Set up is initialized as test 0 48 49# Initialize cleanup function to execute on program exit. 50# This function will be called before the test program exits. 51trap "cleanup" 0 52 53RC=0 # Exit values of system commands used 54 55# Set up some variables 56SEM_ID=0 57 58if [ -f $LTPROOT/testcases/bin/semaphore_test_01 ]; then 59 RC=0 60else 61 tst_resm TBROK, "Could not find the case semaphore_test_01." 62 RC=1 63fi 64 65return $RC 66} 67# Function: cleanup 68# 69# Description - remove temporary files and directories. 70# 71# Return - zero on success 72# - non zero on failure. return value from commands ($RC) 73cleanup() 74{ 75 if [ -n "$SEM_IPCS" ];then 76 ipcrm -s $SEM_IPCS # remove the semaphore. 77 fi 78 tst_resm TINFO "CLOSE: exit." 79} 80 81# Function: test01 82# 83test01() 84{ 85TCID="semaphore_test_01" # Identifier of this testcase. 86TST_COUNT=1 # Test case number. 87RC=0 # return code from commands. 88 89SEM_ID=`semaphore_test_01` 90RC=$? 91 92# Check the return value of semaphore_test_01 93if [ $RC -ne 0 ] 94then 95tst_resm TFAIL "semaphore_test_01 failed." 96return $RC 97else 98tst_resm TINFO "Created semaphore ID: $SEM_ID" 99fi 100 101# Get the semphore ID by "ipcs -s" 102SEMS=`LANG= ipcs -s | awk '{print $2}' | grep [[:digit:]]` 103for SEM_IPCS in $SEMS 104do 105 if [ $SEM_IPCS -eq $SEM_ID ] ;then 106 tst_resm TPASS "semaphore ID comparing passed." 107 return $RC 108 fi 109done 110# Failed in comparing with the output of 'ipcs -s' 111RC=1 112tst_resm TFAIL "Comparing failed with the output of 'ipcs -s'." 113return $RC 114} 115# Function: main 116# 117# Description: - Execute all tests, exit with test status. 118# 119# Exit: - zero on success 120# - non-zero on failure. 121# 122RC=0 # Return value from setup, and test functions. 123setup || exit $RC 124test01 || exit $RC 125 126