.travis-script.sh 5.2 KB

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