Skip to content

Commit

Permalink
Enable running otlp exporter unit-tests on ubuntu. (open-telemetry#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Mar 25, 2021
1 parent 1a3e6cc commit 067e98c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
43 changes: 29 additions & 14 deletions ci/setup_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,39 @@ export DEBIAN_FRONTEND=noninteractive
apt-get update

export CMAKE_VERSION=3.15.2
export GOOGLETEST_VERSION=1.10.0

pushd /tmp
wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-Linux-x86_64.sh
chmod +x cmake-${CMAKE_VERSION}-Linux-x86_64.sh
./cmake-${CMAKE_VERSION}-Linux-x86_64.sh --prefix=/usr/local --skip-license
rm cmake-${CMAKE_VERSION}-Linux-x86_64.sh
popd
cmake_install() {
tmp_dir=$(mktemp -d)
pushd $tmp_dir
wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-Linux-x86_64.sh
chmod +x cmake-${CMAKE_VERSION}-Linux-x86_64.sh
./cmake-${CMAKE_VERSION}-Linux-x86_64.sh --prefix=/usr/local --skip-license
rm cmake-${CMAKE_VERSION}-Linux-x86_64.sh
popd
}

googletest_install() {
# Follows these instructions
# https://gist.github.com/dlime/313f74fd23e4267c4a915086b84c7d3d
tmp_dir=$(mktemp -d)
pushd $tmp_dir
wget https://github.com/google/googletest/archive/release-${GOOGLETEST_VERSION}.tar.gz
tar -xf release-${GOOGLETEST_VERSION}.tar.gz
cd googletest-release-${GOOGLETEST_VERSION}/
mkdir build && cd build
cmake .. -DBUILD_SHARED_LIBS=ON -DINSTALL_GTEST=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr
make -j $(nproc)
make install
ldconfig
popd
}

cmake_install

set +e
echo \
libbenchmark-dev \
libgtest-dev \
zlib1g-dev \
sudo \
libcurl4-openssl-dev \
Expand All @@ -26,10 +47,4 @@ echo \
nlohmann-json3-dev | xargs -n 1 apt-get install --ignore-missing --no-install-recommends --no-install-suggests -y
set -e

# Follows these instructions for setting up gtest
# https://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/
pushd /usr/src/gtest
cmake CMakeLists.txt
make
cp *.a /usr/lib || cp lib/*.a /usr/lib
popd
googletest_install
2 changes: 1 addition & 1 deletion cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ add_custom_command(
COMMAND
${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--proto_path=${PROTO_PATH}"
${PROTOBUF_INCLUDE_FLAGS} "--cpp_out=${GENERATED_PROTOBUF_PATH}"
"--grpc_out=${GENERATED_PROTOBUF_PATH}"
"--grpc_out=generate_mock_code=true:${GENERATED_PROTOBUF_PATH}"
--plugin=protoc-gen-grpc="${gRPC_CPP_PLUGIN_EXECUTABLE}" ${COMMON_PROTO}
${RESOURCE_PROTO} ${TRACE_PROTO} ${LOGS_PROTO} ${METRICS_PROTO}
${TRACE_SERVICE_PROTO} ${LOGS_SERVICE_PROTO} ${METRICS_SERVICE_PROTO})
Expand Down
18 changes: 17 additions & 1 deletion exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ if(BUILD_TESTING)
opentelemetry_exporter_otprotocol protobuf::libprotobuf gRPC::grpc++)
gtest_add_tests(
TARGET recordable_test
TEST_PREFIX exporter.
TEST_PREFIX exporter.otlp.
TEST_LIST recordable_test)
find_library(IS_GMOCK gmock PATH_SUFFIXES lib)
if(IS_GMOCK)
add_executable(otlp_exporter_test test/otlp_exporter_test.cc)
target_link_libraries(
otlp_exporter_test
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
opentelemetry_exporter_otprotocol
gmock
protobuf::libprotobuf
gRPC::grpc++)
gtest_add_tests(
TARGET otlp_exporter_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_exporter_test)
endif()
endif() # BUILD_TESTING

0 comments on commit 067e98c

Please sign in to comment.