.travis-script.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. --host "localhost" \
  98. --port "$INTEROP_TEST_SERVER_PORT" \
  99. "$test"
  100. success "PASSED $test"
  101. done
  102. success "Interop tests PASSED"
  103. info "Stopping C++ interop server"
  104. kill "$INTEROP_SERVER_PID"
  105. success "Stopped C++ interop server"
  106. echo -en 'travis_fold:end:test.interop_tests\\r'
  107. }
  108. run_interop_reconnect_test() {
  109. echo -en 'travis_fold:start:test.interop_reconnect\\r'
  110. make interop-backoff-test-runner
  111. INTEROP_TEST_SERVER_CONTROL_PORT=8081
  112. INTEROP_TEST_SERVER_RETRY_PORT=8082
  113. # reconnect_interop_server should be on $PATH
  114. info "Starting C++ reconnect interop server:"
  115. info " - control port: ${INTEROP_TEST_SERVER_CONTROL_PORT}"
  116. info " - retry port: ${INTEROP_TEST_SERVER_RETRY_PORT}"
  117. "$HOME"/local/bin/reconnect_interop_server \
  118. -control_port "$INTEROP_TEST_SERVER_CONTROL_PORT" \
  119. -retry_port "$INTEROP_TEST_SERVER_RETRY_PORT" &
  120. INTEROP_RECONNECT_SERVER_PID=$!
  121. success "C++ reconnect interop server started, pid=$INTEROP_RECONNECT_SERVER_PID"
  122. info "Running connection backoff interop test"
  123. # Run the test; logs are written to stderr, redirect them to a file.
  124. ${BUILD_OUTPUT}/GRPCConnectionBackoffInteropTest \
  125. --control-port ${INTEROP_TEST_SERVER_CONTROL_PORT} \
  126. --retry-port ${INTEROP_TEST_SERVER_RETRY_PORT}
  127. success "connection backoff interop test PASSED"
  128. info "Stopping C++ reconnect interop server"
  129. kill "$INTEROP_RECONNECT_SERVER_PID"
  130. success "Stopped C++ reconnect interop server"
  131. echo -en 'travis_fold:end:test.interop_reconnect\\r'
  132. }
  133. just_sanity=false
  134. just_interop_tests=false
  135. tsan=false
  136. while getopts "sit" optname; do
  137. case $optname in
  138. s)
  139. just_sanity=true
  140. ;;
  141. i)
  142. just_interop_tests=true
  143. ;;
  144. t)
  145. tsan=true
  146. ;;
  147. \?)
  148. echo "Uknown option $optname"
  149. exit 2
  150. ;;
  151. esac
  152. done
  153. setup_environment
  154. if $just_sanity; then
  155. ./scripts/sanity.sh
  156. elif $just_interop_tests; then
  157. run_interop_tests
  158. run_interop_reconnect_test
  159. else
  160. make_all
  161. make_test $tsan
  162. make_test_plugin
  163. make_project
  164. fi