Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

buildAndRun 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. progName=serviceProgram
  2. debugFileName=$progName"Debug.log"
  3. if [ "$(uname --operating-system)" == "Msys" ]
  4. then
  5. CFLAGS='-I.. -Wall -std=c++11 -DWIN32 -pthread -static -DDEBUG_LOG_FILE="'
  6. CFLAGS=$CFLAGS$(pwd)/$debugFileName\"
  7. CFLAGS='-I.. -Wall -std=c++11 -DWIN32 -pthread -static'
  8. else
  9. CFLAGS='-I.. -Wall -std=c++11 -g -O0 -pthread -DDEBUG_LOG_FILE="'
  10. CFLAGS=$CFLAGS$(pwd)/$debugFileName\"
  11. CFLAGS='-I.. -Wall -std=c++11 -g -O0 -pthread'
  12. fi
  13. g++ $CFLAGS $progName.cpp ../CodeDweller/service.cpp -o $progName
  14. if [ $? -ne 0 ]
  15. then
  16. exit -1
  17. fi
  18. rm -f $debugFileName
  19. # Function to run a test.
  20. #
  21. # Usage:
  22. #
  23. # run_test <message>
  24. #
  25. run_test() {
  26. message=$1
  27. logFile=$progName$message.log
  28. rm -f $logFile
  29. if [ "$(uname --operating-system)" == "Msys" ]
  30. then
  31. sc create "Test Service" binPath= "$(pwd)/$progName.exe" > /dev/null 2>&1
  32. #echo "Starting at "$(date +"%H:%M:%S.%N")
  33. sc start "Test Service" "$(pwd)/$logFile" $message > /dev/null 2>&1
  34. #echo "Sleeping 1 s at "$(date +"%H:%M:%S.%N")
  35. sleep 1
  36. #echo "Pausing at "$(date +"%H:%M:%S.%N")
  37. sc pause "Test Service" > /dev/null 2>&1
  38. #echo "Sleeping 2 s at "$(date +"%H:%M:%S.%N")
  39. sleep 2
  40. #echo "Continuing at "$(date +"%H:%M:%S.%N")
  41. sc continue "Test Service" > /dev/null 2>&1
  42. #echo "Sleeping 2 s at "$(date +"%H:%M:%S.%N")
  43. sleep 2
  44. #echo "Stopping at "$(date +"%H:%M:%S.%N")
  45. sc stop "Test Service" > /dev/null 2>&1
  46. #echo "Returned at "$(date +"%H:%M:%S.%N")
  47. sleep 1
  48. sc delete "Test Service" > /dev/null 2>&1
  49. else
  50. name=$(pwd)/$progName
  51. killall --exact --signal KILL --quiet $name
  52. sleep 1
  53. $name $(pwd)/$logFile $message
  54. sleep 1
  55. PID=$(pidof $name)
  56. kill -TSTP $PID
  57. if [ $message != "Pause" ]
  58. then
  59. # In the Pause test, the service should have exited.
  60. sleep 2
  61. kill -CONT $PID
  62. if [ $message != "Resume" ]
  63. then
  64. # In the Resume test, the service should have exited.
  65. sleep 2
  66. kill -TERM $PID
  67. fi
  68. fi
  69. # Wait for process to exit.
  70. exited=no
  71. for i in $(seq 10)
  72. do
  73. if pidof $name > /dev/null 2>&1
  74. then
  75. sleep 1
  76. else
  77. exited=yes
  78. break
  79. fi
  80. done
  81. if [ $exited == "no" ]
  82. then
  83. echo CodeDweller::Service $message: fail--$progName did not exit
  84. return 1
  85. fi
  86. fi
  87. if diff --strip-trailing-cr expected_$logFile $logFile > /dev/null 2>&1
  88. then
  89. echo CodeDweller::Service $message: ok
  90. else
  91. echo CodeDweller::Service $message: fail
  92. return 1
  93. fi
  94. return 0
  95. }
  96. # Run tests.
  97. run_test Nominal
  98. nominal_status=$?
  99. # Stop timeout.
  100. run_test Stop
  101. stop_status=$?
  102. if [ $nominal_status == "0" -a \
  103. $stop_status == "0" ]
  104. then
  105. exit 0
  106. fi
  107. exit 1