run_test.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #!/bin/bash
  2. # Copyright The OpenTelemetry Authors
  3. # SPDX-License-Identifier: Apache-2.0
  4. set -e
  5. # To run tests in a local dev environment:
  6. # - make sure docker is running
  7. # - set BUILD_DIR to the top level build directory,
  8. [ -z "${BUILD_DIR}" ] && export BUILD_DIR="${HOME}/build"
  9. export CERT_DIR=../cert
  10. export TEST_BIN_DIR="${BUILD_DIR}/functional/otlp/"
  11. # SELINUX
  12. # https://docs.docker.com/storage/bind-mounts/#configure-the-selinux-label
  13. USE_MOUNT_OPTION=""
  14. if [ -x "$(command -v getenforce)" ]; then
  15. SELINUXSTATUS=$(getenforce);
  16. if [ "${SELINUXSTATUS}" == "Enforcing" ]; then
  17. echo "Detected SELINUX"
  18. USE_MOUNT_OPTION=":z"
  19. fi;
  20. fi
  21. #
  22. # Prepare docker image
  23. #
  24. docker build -t otelcpp-func-test .
  25. echo "REPORT:" > report.log
  26. #
  27. # Exercising HTTP functional tests
  28. #
  29. export TEST_EXECUTABLE="func_otlp_http"
  30. export TEST_URL="localhost:4318/v1/traces"
  31. #
  32. # MODE 'NONE'
  33. #
  34. export SERVER_MODE="none"
  35. ./run_test_mode.sh
  36. #
  37. # MODE 'HTTP'
  38. #
  39. echo ""
  40. echo "###############################################################"
  41. echo "Starting otelcol --config otel-config-http.yaml"
  42. echo "###############################################################"
  43. echo ""
  44. docker run -d \
  45. -v `pwd`/otel-docker-config-http.yaml:/otel-cpp/otel-config.yaml${USE_MOUNT_OPTION} \
  46. -p 4318:4318 \
  47. --name otelcpp-test-http \
  48. otelcpp-func-test
  49. sleep 5;
  50. export SERVER_MODE="http"
  51. ./run_test_mode.sh
  52. echo ""
  53. echo "###############################################################"
  54. echo "Stopping otelcol (http)"
  55. echo "###############################################################"
  56. echo ""
  57. docker stop otelcpp-test-http
  58. docker rm otelcpp-test-http
  59. #
  60. # MODE 'SSL'
  61. #
  62. echo ""
  63. echo "###############################################################"
  64. echo "Starting otelcol --config otel-config-https.yaml"
  65. echo "###############################################################"
  66. echo ""
  67. docker run -d \
  68. -v `pwd`/otel-docker-config-https.yaml:/otel-cpp/otel-config.yaml${USE_MOUNT_OPTION} \
  69. -v `pwd`/../cert/ca.pem:/otel-cpp/ca.pem${USE_MOUNT_OPTION} \
  70. -v `pwd`/../cert/server_cert.pem:/otel-cpp/server_cert.pem${USE_MOUNT_OPTION} \
  71. -v `pwd`/../cert/server_cert-key.pem:/otel-cpp/server_cert-key.pem${USE_MOUNT_OPTION} \
  72. -p 4318:4318 \
  73. --name otelcpp-test-https \
  74. otelcpp-func-test
  75. sleep 5;
  76. export SERVER_MODE="https"
  77. ./run_test_mode.sh
  78. echo ""
  79. echo "###############################################################"
  80. echo "Stopping otelcol (https)"
  81. echo "###############################################################"
  82. echo ""
  83. docker stop otelcpp-test-https
  84. docker rm otelcpp-test-https
  85. #
  86. # Exercising gRPC functional tests
  87. #
  88. export TEST_EXECUTABLE="func_otlp_grpc"
  89. export TEST_URL="localhost:4317"
  90. #
  91. # MODE 'SSL'
  92. #
  93. echo ""
  94. echo "###############################################################"
  95. echo "Starting otelcol --config otel-config-https-mtls.yaml"
  96. echo "###############################################################"
  97. echo ""
  98. docker run -d \
  99. -v `pwd`/otel-docker-config-https-mtls.yaml:/otel-cpp/otel-config.yaml${USE_MOUNT_OPTION} \
  100. -v `pwd`/../cert/ca.pem:/otel-cpp/ca.pem${USE_MOUNT_OPTION} \
  101. -v `pwd`/../cert/client_cert.pem:/otel-cpp/client_cert.pem${USE_MOUNT_OPTION} \
  102. -v `pwd`/../cert/server_cert.pem:/otel-cpp/server_cert.pem${USE_MOUNT_OPTION} \
  103. -v `pwd`/../cert/server_cert-key.pem:/otel-cpp/server_cert-key.pem${USE_MOUNT_OPTION} \
  104. -p 4317:4317 \
  105. --name otelcpp-test-grpc-mtls \
  106. otelcpp-func-test
  107. sleep 5;
  108. export SERVER_MODE="https"
  109. ./run_test_mode.sh
  110. echo ""
  111. echo "###############################################################"
  112. echo "Stopping otelcol (https / mTLS)"
  113. echo "###############################################################"
  114. echo ""
  115. docker stop otelcpp-test-grpc-mtls
  116. docker rm otelcpp-test-grpc-mtls
  117. echo ""
  118. echo "###############################################################"
  119. echo "TEST REPORT"
  120. echo "###############################################################"
  121. echo ""
  122. cat report.log
  123. export PASSED_COUNT=`grep -c "PASSED" report.log`
  124. export FAILED_COUNT=`grep -c "FAILED" report.log`
  125. echo ""
  126. echo "###############################################################"
  127. echo "TEST VERDICT: ${PASSED_COUNT} PASSED, ${FAILED_COUNT} FAILED"
  128. echo "###############################################################"
  129. echo ""
  130. if [ "${FAILED_COUNT}" != "0" ]; then
  131. #
  132. # CI FAILED
  133. #
  134. exit 1
  135. fi;
  136. #
  137. # CI PASSED
  138. #
  139. exit 0