123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- progName=serviceProgram
- debugFileName=$progName"Debug.log"
-
- #CFLAGS='-I.. -Wall -std=gnu++17 -g -O0 -pthread -DDEBUG_LOG_FILE="'
- CFLAGS='-I.. -Wall -DWINDOWS_SERVICE -static -DDEBUG_LOG_FILE="Debug.log"'
- #CFLAGS='-I.. -Wall -std=gnu++17 -g -O0 -pthread'
-
- 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"
-
- echo "Starting at "$(date +"%H:%M:%S.%N")
- sc start "Test Service" "$(pwd)/$logFile" $message
- echo "Sleeping 1 s at "$(date +"%H:%M:%S.%N")
- sleep 1
-
- echo "Pausing at "$(date +"%H:%M:%S.%N")
- sc pause "Test Service"
- echo "Sleeping 2 s at "$(date +"%H:%M:%S.%N")
- sleep 2
-
- echo "Continuing at "$(date +"%H:%M:%S.%N")
- sc continue "Test Service"
- echo "Sleeping 2 s at "$(date +"%H:%M:%S.%N")
- sleep 2
-
- echo "Stopping at "$(date +"%H:%M:%S.%N")
- sc stop "Test Service"
- echo "Returned at "$(date +"%H:%M:%S.%N")
- sleep 1
-
- sc delete "Test Service"
-
- else
-
- name=$(pwd)/$progName
- killall --exact --signal KILL --quiet $name
- sleep 1
-
- $name $(pwd)/$logFile $message
- sleep 1
-
- PID=$(pidof $name)
-
- 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
-
- }
-
- # Run tests.
- echo Running Nominal test
- run_test Nominal
- nominal_status=$?
- echo Completed Nominal test
- echo
-
- # Stop timeout.
- echo Running Stop test
- run_test Stop
- stop_status=$?
- echo Completed Stop test
-
- if [ $nominal_status == "0" -a \
- $stop_status == "0" ]
- then
- exit 0
- fi
- exit 1
|