.travis-script.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #!/bin/bash -e
  2. # Copyright 2019, gRPC Authors All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # See: Makefile
  16. BUILD_OUTPUT=./.build/debug
  17. info() {
  18. printf '\033[0;34m%s\033[0m\n' "$1"
  19. }
  20. success() {
  21. printf '\033[0;32m%s\033[0m\n' "$1"
  22. }
  23. setup_environment() {
  24. echo -en 'travis_fold:start:script.environment\\r'
  25. export PATH=$HOME/local/bin:$PATH
  26. export LD_LIBRARY_PATH=$HOME/local/lib
  27. echo -en 'travis_fold:end:script.environment\\r'
  28. }
  29. make_all() {
  30. echo -en 'travis_fold:start:make.all\\r'
  31. info "Running make all"
  32. make all
  33. success "make all succeeded"
  34. echo -en 'travis_fold:end:make.all\\r'
  35. }
  36. make_test() {
  37. local tsan=$1
  38. echo -en 'travis_fold:start:make.test\\r'
  39. if $tsan; then
  40. info "Running Swift tests with TSAN"
  41. make test-tsan
  42. else
  43. info "Running Swift tests"
  44. make test
  45. fi
  46. success "Swift tests passed"
  47. echo -en 'travis_fold:end:make.test\\r'
  48. }
  49. make_test_plugin() {
  50. echo -en 'travis_fold:start:make.test_plugin\\r'
  51. info "Validating protoc plugins on the Echo service"
  52. make test-plugin
  53. success "Validated protoc plugins on the Echo service"
  54. echo -en 'travis_fold:end:make.test_plugin\\r'
  55. }
  56. make_check_linuxmain() {
  57. echo -en 'travis_fold:start:make.test_generate_linuxmain\\r'
  58. info "Validating LinuxMain is up-to-date"
  59. if [ "$TRAVIS_OS_NAME" = "osx" ]; then
  60. make test-generate-linuxmain
  61. success "LinuxMain is up-to-date"
  62. else
  63. info "Not running on macOS, skipping LinuxMain validation"
  64. fi
  65. echo -en 'travis_fold:end:make.test_generate_linuxmain\\r'
  66. }
  67. make_project() {
  68. echo -en 'travis_fold:start:make.project\\r'
  69. info "Validating .xcodeproj can be generated"
  70. if [ "$TRAVIS_OS_NAME" = "osx" ]; then
  71. make project
  72. info ".xcodeproj was successfully generated"
  73. else
  74. info "Not running on macOS, skipping .xcodeproj generation"
  75. fi
  76. echo -en 'travis_fold:end:make.project\\r'
  77. }
  78. run_interop_tests() {
  79. echo -en 'travis_fold:start:test.interop_tests\\r'
  80. make interop-test-runner
  81. INTEROP_TEST_SERVER_PORT=8080
  82. # interop_server should be on $PATH
  83. info "Starting C++ interop server on port $INTEROP_TEST_SERVER_PORT"
  84. "$HOME"/local/bin/interop_server -port "$INTEROP_TEST_SERVER_PORT" &
  85. INTEROP_SERVER_PID=$!
  86. success "C++ interop server started, pid=$INTEROP_SERVER_PID"
  87. # Names of the tests we should run:
  88. TESTS=(
  89. empty_unary
  90. large_unary
  91. client_streaming
  92. server_streaming
  93. ping_pong
  94. empty_stream
  95. custom_metadata
  96. status_code_and_message
  97. special_status_message
  98. unimplemented_method
  99. unimplemented_service
  100. cancel_after_begin
  101. cancel_after_first_response
  102. timeout_on_sleeping_server
  103. )
  104. # Run the tests; logs are written to stderr, capture them per-test.
  105. for test in "${TESTS[@]}"; do
  106. info "Running $test"
  107. $BUILD_OUTPUT/GRPCInteroperabilityTests run_test \
  108. "localhost" \
  109. "$INTEROP_TEST_SERVER_PORT" \
  110. "$test" \
  111. 2> "interop.$test.log"
  112. success "PASSED $test"
  113. done
  114. success "Interop tests PASSED"
  115. info "Stopping C++ interop server"
  116. kill "$INTEROP_SERVER_PID"
  117. success "Stopped C++ interop server"
  118. echo -en 'travis_fold:end:test.interop_tests\\r'
  119. }
  120. run_interop_reconnect_test() {
  121. echo -en 'travis_fold:start:test.interop_reconnect\\r'
  122. make interop-backoff-test-runner
  123. INTEROP_TEST_SERVER_CONTROL_PORT=8081
  124. INTEROP_TEST_SERVER_RETRY_PORT=8082
  125. # reconnect_interop_server should be on $PATH
  126. info "Starting C++ reconnect interop server:"
  127. info " - control port: ${INTEROP_TEST_SERVER_CONTROL_PORT}"
  128. info " - retry port: ${INTEROP_TEST_SERVER_RETRY_PORT}"
  129. "$HOME"/local/bin/reconnect_interop_server \
  130. -control_port "$INTEROP_TEST_SERVER_CONTROL_PORT" \
  131. -retry_port "$INTEROP_TEST_SERVER_RETRY_PORT" &
  132. INTEROP_RECONNECT_SERVER_PID=$!
  133. success "C++ reconnect interop server started, pid=$INTEROP_RECONNECT_SERVER_PID"
  134. info "Running connection backoff interop test"
  135. # Run the test; logs are written to stderr, redirect them to a file.
  136. ${BUILD_OUTPUT}/GRPCConnectionBackoffInteropTest \
  137. ${INTEROP_TEST_SERVER_CONTROL_PORT} \
  138. ${INTEROP_TEST_SERVER_RETRY_PORT} \
  139. 2> "interop.connection_backoff.log"
  140. success "connection backoff interop test PASSED"
  141. info "Stopping C++ reconnect interop server"
  142. kill "$INTEROP_RECONNECT_SERVER_PID"
  143. success "Stopped C++ reconnect interop server"
  144. echo -en 'travis_fold:end:test.interop_reconnect\\r'
  145. }
  146. just_sanity=false
  147. just_interop_tests=false
  148. tsan=false
  149. while getopts "sit" optname; do
  150. case $optname in
  151. s)
  152. just_sanity=true
  153. ;;
  154. i)
  155. just_interop_tests=true
  156. ;;
  157. t)
  158. tsan=true
  159. ;;
  160. \?)
  161. echo "Uknown option $optname"
  162. exit 2
  163. ;;
  164. esac
  165. done
  166. setup_environment
  167. if $just_sanity; then
  168. ./scripts/sanity.sh
  169. elif $just_interop_tests; then
  170. run_interop_tests
  171. run_interop_reconnect_test
  172. else
  173. make_all
  174. make_check_linuxmain
  175. make_test $tsan
  176. make_test_plugin
  177. make_project
  178. fi