You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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