test.sh (3031B)
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 19 # Fail on any error. Treat unset variables an error. Print commands as executed. 20 set -euox pipefail 21 22 absl_dir=/abseil-cpp 23 absl_build_dir=/buildfs 24 googletest_builddir=/googletest_builddir 25 googletest_archive="googletest-${ABSL_GOOGLETEST_VERSION}.tar.gz" 26 project_dir="${absl_dir}/CMake/install_test_project" 27 project_build_dir=/buildfs/project-build 28 29 build_shared_libs="OFF" 30 if [ "${LINK_TYPE:-}" = "DYNAMIC" ]; then 31 build_shared_libs="ON" 32 fi 33 34 # Build and install GoogleTest 35 mkdir "${googletest_builddir}" 36 pushd "${googletest_builddir}" 37 curl -L "${ABSL_GOOGLETEST_DOWNLOAD_URL}" --output "${googletest_archive}" 38 tar -xz -f "${googletest_archive}" 39 pushd "googletest-${ABSL_GOOGLETEST_VERSION}" 40 mkdir build 41 pushd build 42 cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS="${build_shared_libs}" .. 43 make -j $(nproc) 44 make install 45 ldconfig 46 popd 47 popd 48 popd 49 50 # Run the LTS transformations 51 ./create_lts.py 99998877 52 53 # Build and install Abseil 54 pushd "${absl_build_dir}" 55 cmake "${absl_dir}" \ 56 -DABSL_USE_EXTERNAL_GOOGLETEST=ON \ 57 -DABSL_FIND_GOOGLETEST=ON \ 58 -DCMAKE_BUILD_TYPE=Release \ 59 -DABSL_BUILD_TESTING=ON \ 60 -DBUILD_SHARED_LIBS="${build_shared_libs}" 61 make -j $(nproc) 62 ctest -j $(nproc) --output-on-failure 63 make install 64 ldconfig 65 popd 66 67 # Test the project against the installed Abseil 68 mkdir -p "${project_build_dir}" 69 pushd "${project_build_dir}" 70 cmake "${project_dir}" 71 cmake --build . --target simple 72 73 output="$(${project_build_dir}/simple "printme" 2>&1)" 74 if [[ "${output}" != *"Arg 1: printme"* ]]; then 75 echo "Faulty output on simple project:" 76 echo "${output}" 77 exit 1 78 fi 79 80 popd 81 82 if ! grep absl::strings "/usr/local/lib/cmake/absl/abslTargets.cmake"; then 83 cat "/usr/local/lib/cmake/absl/abslTargets.cmake" 84 echo "CMake targets named incorrectly" 85 exit 1 86 fi 87 88 pushd "${HOME}" 89 cat > hello-abseil.cc << EOF 90 #include <cstdlib> 91 92 #include "absl/strings/str_format.h" 93 94 int main(int argc, char **argv) { 95 absl::PrintF("Hello Abseil!\n"); 96 return EXIT_SUCCESS; 97 } 98 EOF 99 100 if [ "${LINK_TYPE:-}" != "DYNAMIC" ]; then 101 pc_args=($(pkg-config --cflags --libs --static absl_str_format)) 102 g++ -static -o hello-abseil hello-abseil.cc "${pc_args[@]}" 103 else 104 pc_args=($(pkg-config --cflags --libs absl_str_format)) 105 g++ -o hello-abseil hello-abseil.cc "${pc_args[@]}" 106 fi 107 hello="$(./hello-abseil)" 108 [[ "${hello}" == "Hello Abseil!" ]] 109 110 popd 111 112 echo "Install test complete!" 113 exit 0