.travis-script.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_project() {
  57. echo -en 'travis_fold:start:make.project\\r'
  58. info "Validating .xcodeproj can be generated"
  59. if [ "$TRAVIS_OS_NAME" = "osx" ]; then
  60. make project
  61. info ".xcodeproj was successfully generated"
  62. else
  63. info "Not running on macOS, skipping .xcodeproj generation"
  64. fi
  65. echo -en 'travis_fold:end:make.project\\r'
  66. }
  67. run_interop_tests() {
  68. echo -en 'travis_fold:start:test.interop_tests\\r'
  69. make interop-test-runner
  70. INTEROP_TEST_SERVER_PORT=8080
  71. # interop_server should be on $PATH
  72. info "Starting C++ interop server on port $INTEROP_TEST_SERVER_PORT"
  73. "$HOME"/local/bin/interop_server -port "$INTEROP_TEST_SERVER_PORT" &
  74. INTEROP_SERVER_PID=$!
  75. success "C++ interop server started, pid=$INTEROP_SERVER_PID"
  76. # Names of the tests we should run:
  77. TESTS=(
  78. empty_unary
  79. large_unary
  80. client_streaming
  81. server_streaming
  82. ping_pong
  83. empty_stream
  84. custom_metadata
  85. status_code_and_message
  86. special_status_message
  87. unimplemented_method
  88. unimplemented_service
  89. cancel_after_begin
  90. cancel_after_first_response
  91. timeout_on_sleeping_server
  92. )
  93. # Run the tests; logs are written to stderr, capture them per-test.
  94. for test in "${TESTS[@]}"; do
  95. info "Running $test"
  96. $BUILD_OUTPUT/GRPCInteroperabilityTests run_test \
  97. "localhost" \
  98. "$INTEROP_TEST_SERVER_PORT" \
  99. "$test" \
  100. 2> "interop.$test.log"
  101. success "PASSED $test"
  102. done
  103. success "Interop tests PASSED"
  104. info "Stopping C++ interop server"
  105. kill "$INTEROP_SERVER_PID"
  106. success "Stopped C++ interop server"
  107. echo -en 'travis_fold:end:test.interop_tests\\r'
  108. }
  109. run_interop_reconnect_test() {
  110. echo -en 'travis_fold:start:test.interop_reconnect\\r'
  111. make interop-backoff-test-runner
  112. INTEROP_TEST_SERVER_CONTROL_PORT=8081
  113. INTEROP_TEST_SERVER_RETRY_PORT=8082
  114. # reconnect_interop_server should be on $PATH
  115. info "Starting C++ reconnect interop server:"
  116. info " - control port: ${INTEROP_TEST_SERVER_CONTROL_PORT}"
  117. info " - retry port: ${INTEROP_TEST_SERVER_RETRY_PORT}"
  118. "$HOME"/local/bin/reconnect_interop_server \
  119. -control_port "$INTEROP_TEST_SERVER_CONTROL_PORT" \
  120. -retry_port "$INTEROP_TEST_SERVER_RETRY_PORT" &
  121. INTEROP_RECONNECT_SERVER_PID=$!
  122. success "C++ reconnect interop server started, pid=$INTEROP_RECONNECT_SERVER_PID"
  123. info "Running connection backoff interop test"
  124. # Run the test; logs are written to stderr, redirect them to a file.
  125. ${BUILD_OUTPUT}/GRPCConnectionBackoffInteropTest \
  126. ${INTEROP_TEST_SERVER_CONTROL_PORT} \
  127. ${INTEROP_TEST_SERVER_RETRY_PORT} \
  128. 2> "interop.connection_backoff.log"
  129. success "connection backoff interop test PASSED"
  130. info "Stopping C++ reconnect interop server"
  131. kill "$INTEROP_RECONNECT_SERVER_PID"
  132. success "Stopped C++ reconnect interop server"
  133. echo -en 'travis_fold:end:test.interop_reconnect\\r'
  134. }
  135. just_sanity=false
  136. just_interop_tests=false
  137. tsan=false
  138. while getopts "sit" optname; do
  139. case $optname in
  140. s)
  141. just_sanity=true
  142. ;;
  143. i)
  144. just_interop_tests=true
  145. ;;
  146. t)
  147. tsan=true
  148. ;;
  149. \?)
  150. echo "Uknown option $optname"
  151. exit 2
  152. ;;
  153. esac
  154. done
  155. setup_environment
  156. if $just_sanity; then
  157. ./scripts/sanity.sh
  158. elif $just_interop_tests; then
  159. run_interop_tests
  160. run_interop_reconnect_test
  161. else
  162. make_all
  163. make_test $tsan
  164. make_test_plugin
  165. make_project
  166. fi