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 # 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