.travis-script.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. GREEN='\033[0;32m'
  18. BLUE='\033[0;34m'
  19. NO_COLOR='\033[0m'
  20. info() {
  21. printf "${BLUE}$1${NO_COLOR}\n"
  22. }
  23. success() {
  24. printf "${GREEN}$1${NO_COLOR}\n"
  25. }
  26. setup_environment() {
  27. echo -en 'travis_fold:start:script.environment\\r'
  28. export PATH=$HOME/local/bin:$PATH
  29. export LD_LIBRARY_PATH=$HOME/local/lib
  30. echo -en 'travis_fold:end:script.environment\\r'
  31. }
  32. make_all() {
  33. echo -en 'travis_fold:start:make.all\\r'
  34. info "Running make all"
  35. make all
  36. success "make all succeeded"
  37. echo -en 'travis_fold:end:make.all\\r'
  38. }
  39. make_test() {
  40. echo -en 'travis_fold:start:make.test\\r'
  41. info "Running Swift tests"
  42. make test
  43. success "Swift tests passed"
  44. echo -en 'travis_fold:end:make.test\\r'
  45. }
  46. make_test_plugin() {
  47. echo -en 'travis_fold:start:make.test_plugin\\r'
  48. info "Validating protoc plugins on the Echo service"
  49. make test-plugin
  50. success "Validated protoc plugins on the Echo service"
  51. echo -en 'travis_fold:end:make.test_plugin\\r'
  52. }
  53. make_check_linuxmain() {
  54. echo -en 'travis_fold:start:make.test_generate_linuxmain\\r'
  55. info "Validating LinuxMain is up-to-date"
  56. if [ "$TRAVIS_OS_NAME" = "osx" ]; then
  57. make test-generate-linuxmain
  58. success "LinuxMain is up-to-date"
  59. else
  60. info "Not running on macOS, skipping LinuxMain validation"
  61. fi
  62. echo -en 'travis_fold:end:make.test_generate_linuxmain\\r'
  63. }
  64. make_project() {
  65. echo -en 'travis_fold:start:make.project\\r'
  66. info "Validating .xcodeproj can be generated"
  67. if [ "$TRAVIS_OS_NAME" = "osx" ]; then
  68. make project
  69. info ".xcodeproj was successfully generated"
  70. else
  71. info "Not running on macOS, skipping .xcodeproj generation"
  72. fi
  73. echo -en 'travis_fold:end:make.project\\r'
  74. }
  75. run_interop_tests() {
  76. echo -en 'travis_fold:start:test.interop_tests\\r'
  77. make interop-test-runner
  78. INTEROP_TEST_SERVER_PORT=8080
  79. # interop_server should be on $PATH
  80. info "Starting C++ interop server on port $INTEROP_TEST_SERVER_PORT"
  81. "$HOME"/local/bin/interop_server -port "$INTEROP_TEST_SERVER_PORT" &
  82. INTEROP_SERVER_PID=$!
  83. success "C++ interop server started, pid=$INTEROP_SERVER_PID"
  84. # Names of the tests we should run:
  85. TESTS=(
  86. empty_unary
  87. large_unary
  88. client_streaming
  89. server_streaming
  90. ping_pong
  91. empty_stream
  92. custom_metadata
  93. status_code_and_message
  94. special_status_message
  95. unimplemented_method
  96. unimplemented_service
  97. cancel_after_begin
  98. cancel_after_first_response
  99. timeout_on_sleeping_server
  100. )
  101. # Run the tests; logs are written to stderr, capture them per-test.
  102. for test in "${TESTS[@]}"; do
  103. info "Running $test"
  104. $BUILD_OUTPUT/GRPCInteroperabilityTests run_test \
  105. "localhost" \
  106. "$INTEROP_TEST_SERVER_PORT" \
  107. "$test" \
  108. 2> "interop.$test.log"
  109. success "PASSED $test"
  110. done
  111. success "Interop tests PASSED"
  112. info "Stopping C++ interop server"
  113. kill "$INTEROP_SERVER_PID"
  114. success "Stopped C++ interop server"
  115. echo -en 'travis_fold:end:test.interop_tests\\r'
  116. }
  117. run_interop_reconnect_test() {
  118. echo -en 'travis_fold:start:test.interop_reconnect\\r'
  119. make interop-backoff-test-runner
  120. INTEROP_TEST_SERVER_CONTROL_PORT=8081
  121. INTEROP_TEST_SERVER_RETRY_PORT=8082
  122. # reconnect_interop_server should be on $PATH
  123. info "Starting C++ reconnect interop server:"
  124. info " - control port: ${INTEROP_TEST_SERVER_CONTROL_PORT}"
  125. info " - retry port: ${INTEROP_TEST_SERVER_RETRY_PORT}"
  126. "$HOME"/local/bin/reconnect_interop_server \
  127. -control_port "$INTEROP_TEST_SERVER_CONTROL_PORT" \
  128. -retry_port "$INTEROP_TEST_SERVER_RETRY_PORT" &
  129. INTEROP_RECONNECT_SERVER_PID=$!
  130. success "C++ reconnect interop server started, pid=$INTEROP_RECONNECT_SERVER_PID"
  131. info "Running connection backoff interop test"
  132. # Run the test; logs are written to stderr, redirect them to a file.
  133. ${BUILD_OUTPUT}/GRPCConnectionBackoffInteropTest \
  134. ${INTEROP_TEST_SERVER_CONTROL_PORT} \
  135. ${INTEROP_TEST_SERVER_RETRY_PORT} \
  136. 2> "interop.connection_backoff.log"
  137. success "connection backoff interop test PASSED"
  138. info "Stopping C++ reconnect interop server"
  139. kill "$INTEROP_RECONNECT_SERVER_PID"
  140. success "Stopped C++ reconnect interop server"
  141. echo -en 'travis_fold:end:test.interop_reconnect\\r'
  142. }
  143. main() {
  144. setup_environment
  145. # If we're running interop tests don't bother with the other stuff.
  146. if [ "$RUN_INTEROP_TESTS" = "true" ]; then
  147. run_interop_tests
  148. run_interop_reconnect_test
  149. else
  150. make_all
  151. make_check_linuxmain
  152. make_test
  153. make_test_plugin
  154. make_project
  155. fi
  156. }
  157. # Run the thing!
  158. main