test.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/bash
  2. #
  3. # Copyright 2019 The Abseil Authors.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # https://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. # Unit and integration tests for Abseil LTS CMake installation
  18. # Fail on any error. Treat unset variables an error. Print commands as executed.
  19. set -euox pipefail
  20. absl_dir=/abseil-cpp
  21. absl_build_dir=/buildfs
  22. googletest_builddir=/googletest_builddir
  23. project_dir="${absl_dir}"/CMake/install_test_project
  24. project_build_dir=/buildfs/project-build
  25. build_shared_libs="OFF"
  26. if [ "${LINK_TYPE:-}" = "DYNAMIC" ]; then
  27. build_shared_libs="ON"
  28. fi
  29. # Build and install GoogleTest
  30. mkdir "${googletest_builddir}"
  31. pushd "${googletest_builddir}"
  32. curl -L "${ABSL_GOOGLETEST_DOWNLOAD_URL}" --output "${ABSL_GOOGLETEST_COMMIT}".zip
  33. unzip "${ABSL_GOOGLETEST_COMMIT}".zip
  34. pushd "googletest-${ABSL_GOOGLETEST_COMMIT}"
  35. mkdir build
  36. pushd build
  37. cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS="${build_shared_libs}" ..
  38. make -j $(nproc)
  39. make install
  40. ldconfig
  41. popd
  42. popd
  43. popd
  44. # Run the LTS transformations
  45. ./create_lts.py 99998877
  46. # Build and install Abseil
  47. pushd "${absl_build_dir}"
  48. cmake "${absl_dir}" \
  49. -DABSL_USE_EXTERNAL_GOOGLETEST=ON \
  50. -DABSL_FIND_GOOGLETEST=ON \
  51. -DCMAKE_BUILD_TYPE=Release \
  52. -DBUILD_TESTING=ON \
  53. -DBUILD_SHARED_LIBS="${build_shared_libs}"
  54. make -j $(nproc)
  55. ctest -j $(nproc)
  56. make install
  57. ldconfig
  58. popd
  59. # Test the project against the installed Abseil
  60. mkdir -p "${project_build_dir}"
  61. pushd "${project_build_dir}"
  62. cmake "${project_dir}"
  63. cmake --build . --target simple
  64. output="$(${project_build_dir}/simple "printme" 2>&1)"
  65. if [[ "${output}" != *"Arg 1: printme"* ]]; then
  66. echo "Faulty output on simple project:"
  67. echo "${output}"
  68. exit 1
  69. fi
  70. popd
  71. if ! grep absl::strings "/usr/local/lib/cmake/absl/abslTargets.cmake"; then
  72. cat "/usr/local/lib/cmake/absl/abslTargets.cmake"
  73. echo "CMake targets named incorrectly"
  74. exit 1
  75. fi
  76. pushd "${HOME}"
  77. cat > hello-abseil.cc << EOF
  78. #include <cstdlib>
  79. #include "absl/strings/str_format.h"
  80. int main(int argc, char **argv) {
  81. absl::PrintF("Hello Abseil!\n");
  82. return EXIT_SUCCESS;
  83. }
  84. EOF
  85. if [ "${LINK_TYPE:-}" != "DYNAMIC" ]; then
  86. pc_args=($(pkg-config --cflags --libs --static absl_str_format))
  87. g++ -static -o hello-abseil hello-abseil.cc "${pc_args[@]}"
  88. else
  89. pc_args=($(pkg-config --cflags --libs absl_str_format))
  90. g++ -o hello-abseil hello-abseil.cc "${pc_args[@]}"
  91. fi
  92. hello="$(./hello-abseil)"
  93. [[ "${hello}" == "Hello Abseil!" ]]
  94. popd
  95. echo "Install test complete!"
  96. exit 0