123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- progName=serviceProgram
- debugFileName=$progName"Debug.log"
-
- if [ "$(uname --operating-system)" == "Msys" ]
- then
- CFLAGS='-I.. -Wall -std=c++11 -DWIN32 -pthread -static -DDEBUG_LOG_FILE="'
- CFLAGS=$CFLAGS$(pwd)/$debugFileName\"
- CFLAGS='-I.. -Wall -std=c++11 -DWIN32 -pthread -static'
- else
- CFLAGS='-I.. -Wall -std=c++11 -g -O0 -pthread -DDEBUG_LOG_FILE="'
- CFLAGS=$CFLAGS$(pwd)/$debugFileName\"
- CFLAGS='-I.. -Wall -std=c++11 -g -O0 -pthread'
- fi
-
- g++ $CFLAGS $progName.cpp ../CodeDweller/service.cpp -o $progName
- if [ $? -ne 0 ]
- then
- exit -1
- fi
-
- rm -f $debugFileName
-
- # Function to run a test.
- #
- # Usage:
- #
- # run_test <message>
- #
- run_test() {
-
- message=$1
-
- logFile=$progName$message.log
-
- rm -f $logFile
-
- if [ "$(uname --operating-system)" == "Msys" ]
- then
-
- sc create "Test Service" binPath= "$(pwd)/$progName.exe" > /dev/null 2>&1
-
- #echo "Starting at "$(date +"%H:%M:%S.%N")
- sc start "Test Service" "$(pwd)/$logFile" $message > /dev/null 2>&1
- #echo "Sleeping 1 s at "$(date +"%H:%M:%S.%N")
- sleep 1
-
- #echo "Pausing at "$(date +"%H:%M:%S.%N")
- sc pause "Test Service" > /dev/null 2>&1
- #echo "Sleeping 2 s at "$(date +"%H:%M:%S.%N")
- sleep 2
-
- #echo "Continuing at "$(date +"%H:%M:%S.%N")
- sc continue "Test Service" > /dev/null 2>&1
- #echo "Sleeping 2 s at "$(date +"%H:%M:%S.%N")
- sleep 2
-
- #echo "Stopping at "$(date +"%H:%M:%S.%N")
- sc stop "Test Service" > /dev/null 2>&1
- #echo "Returned at "$(date +"%H:%M:%S.%N")
- sleep 1
-
- sc delete "Test Service" > /dev/null 2>&1
-
- else
-
- name=$(pwd)/$progName
- killall --exact --signal KILL --quiet $name
- sleep 1
-
- $name $(pwd)/$logFile $message
-
- PID=$(pidof $name)
- sleep 1
-
- kill -TSTP $PID
-
- if [ $message != "Pause" ]
- then
- # In the Pause test, the service should have exited.
- sleep 2
- kill -CONT $PID
-
- if [ $message != "Resume" ]
- then
- # In the Resume test, the service should have exited.
- sleep 2
- kill -TERM $PID
- fi
- fi
-
- # Wait for process to exit.
- exited=no
- for i in $(seq 10)
- do
- if pidof $name > /dev/null 2>&1
- then
- sleep 1
- else
- exited=yes
- break
- fi
- done
-
- if [ $exited == "no" ]
- then
- echo CodeDweller::Service $message: fail--$progName did not exit
- return 1
- fi
-
- fi
-
- if diff --strip-trailing-cr expected_$logFile $logFile > /dev/null 2>&1
- then
- echo CodeDweller::Service $message: ok
- else
- echo CodeDweller::Service $message: fail
- return 1
- fi
-
- return 0
-
- }
-
- stat=0
-
- # Run tests.
- run_test Nominal
- nominal_status=$?
-
- # Stop timeout.
- run_test Stop
- stop_status=$?
-
- if [ $nominal_status == "0" -a \
- $stop_status == "0" ]
- then
- exit 0
- fi
- exit 1
|