From 3dc1179d97a760233b547e6fdfc58776fbb86911 Mon Sep 17 00:00:00 2001 From: Anton Zhilin Date: Wed, 13 Dec 2023 19:51:17 +0300 Subject: [PATCH] feat tests: use userver requirements (#61) Also, correct Makefile to support Ninja generator (avoid direct usage of low-level make). --- .github/workflows/docker.yaml | 2 +- .gitignore | 1 + CMakeLists.txt | 20 ++++++++-- Makefile | 69 +++++++++++++++++------------------ Makefile.local | 1 - docker-compose.yml | 2 +- tests/requirements.txt | 2 - third_party/userver | 2 +- 8 files changed, 53 insertions(+), 46 deletions(-) delete mode 100644 Makefile.local delete mode 100644 tests/requirements.txt diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index b1132dd..b285c92 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -9,7 +9,7 @@ name: Docker build - feature/** env: - CMAKE_OPTIONS: -DUserverGrpc_VERSION=1.51.0 + CMAKE_COMMON_FLAGS: -DUserverGrpc_VERSION=1.51.0 jobs: tests: diff --git a/.gitignore b/.gitignore index fb29c34..ede5619 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ compile_commands.json cmake-build-* Testing/ .DS_Store +Makefile.local diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e52d19..d5972d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,23 @@ cmake_minimum_required(VERSION 3.12) project(service_template CXX) +# Disable userver libraries that are not needed in this project +set(USERVER_FEATURE_MONGODB OFF CACHE BOOL "" FORCE) +set(USERVER_FEATURE_POSTGRESQL OFF CACHE BOOL "" FORCE) +set(USERVER_FEATURE_REDIS OFF CACHE BOOL "" FORCE) +set(USERVER_FEATURE_CLICKHOUSE OFF CACHE BOOL "" FORCE) +set(USERVER_FEATURE_GRPC OFF CACHE BOOL "" FORCE) +set(USERVER_FEATURE_RABBITMQ OFF CACHE BOOL "" FORCE) + +# Compatibility mode: some systems don't support these features +set(USERVER_FEATURE_CRYPTOPP_BLAKE2 OFF CACHE BOOL "" FORCE) +set(USERVER_FEATURE_GRPC_CHANNELZ OFF CACHE BOOL "" FORCE) +set(USERVER_FEATURE_REDIS_HI_MALLOC ON CACHE BOOL "" FORCE) + + +# Adding userver dependency include(third_party/userver/cmake/SetupEnvironment.cmake) include(GNUInstallDirs) - add_subdirectory(third_party/userver) @@ -39,9 +53,7 @@ add_google_benchmark_tests(${PROJECT_NAME}_benchmark) # Functional Tests include(UserverTestsuite) -userver_testsuite_add_simple( - REQUIREMENTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/requirements.txt" -) +userver_testsuite_add_simple() # Install diff --git a/Makefile b/Makefile index 99a54cf..5ec81a8 100644 --- a/Makefile +++ b/Makefile @@ -1,69 +1,66 @@ CMAKE_COMMON_FLAGS ?= -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMAKE_DEBUG_FLAGS ?= -DUSERVER_SANITIZE='addr ub' CMAKE_RELEASE_FLAGS ?= -CMAKE_OS_FLAGS ?= -DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0 -DUSERVER_FEATURE_REDIS_HI_MALLOC=1 NPROCS ?= $(shell nproc) CLANG_FORMAT ?= clang-format DOCKER_COMPOSE ?= docker-compose -# NOTE: use Makefile.local for customization +# NOTE: use Makefile.local to override the options defined above. -include Makefile.local +CMAKE_DEBUG_FLAGS += -DCMAKE_BUILD_TYPE=Debug $(CMAKE_COMMON_FLAGS) +CMAKE_RELEASE_FLAGS += -DCMAKE_BUILD_TYPE=Release $(CMAKE_COMMON_FLAGS) + .PHONY: all all: test-debug test-release -# Debug cmake configuration -build_debug/Makefile: - @git submodule update --init - @mkdir -p build_debug - @cd build_debug && \ - cmake -DCMAKE_BUILD_TYPE=Debug $(CMAKE_COMMON_FLAGS) $(CMAKE_DEBUG_FLAGS) $(CMAKE_OS_FLAGS) $(CMAKE_OPTIONS) .. +# Run cmake +.PHONY: cmake-debug +cmake-debug: + git submodule update --init + cmake -B build_debug $(CMAKE_DEBUG_FLAGS) -# Release cmake configuration -build_release/Makefile: - @git submodule update --init - @mkdir -p build_release - @cd build_release && \ - cmake -DCMAKE_BUILD_TYPE=Release $(CMAKE_COMMON_FLAGS) $(CMAKE_RELEASE_FLAGS) $(CMAKE_OS_FLAGS) $(CMAKE_OPTIONS) .. +.PHONY: cmake-release +cmake-release: + git submodule update --init + cmake -B build_release $(CMAKE_RELEASE_FLAGS) -# Run cmake -.PHONY: cmake-debug cmake-release -cmake-debug cmake-release: cmake-%: build_%/Makefile +build_debug/CMakeCache.txt: cmake-debug +build_release/CMakeCache.txt: cmake-release # Build using cmake .PHONY: build-debug build-release -build-debug build-release: build-%: cmake-% - @cmake --build build_$* -j $(NPROCS) --target service_template +build-debug build-release: build-%: build_%/CMakeCache.txt + cmake --build build_$* -j $(NPROCS) --target service_template # Test .PHONY: test-debug test-release test-debug test-release: test-%: build-% - @cmake --build build_$* -j $(NPROCS) --target service_template_unittest - @cmake --build build_$* -j $(NPROCS) --target service_template_benchmark - @cd build_$* && ((test -t 1 && GTEST_COLOR=1 PYTEST_ADDOPTS="--color=yes" ctest -V) || ctest -V) - @pep8 tests + cmake --build build_$* -j $(NPROCS) --target service_template_unittest + cmake --build build_$* -j $(NPROCS) --target service_template_benchmark + cd build_$* && ((test -t 1 && GTEST_COLOR=1 PYTEST_ADDOPTS="--color=yes" ctest -V) || ctest -V) + pep8 tests # Start the service (via testsuite service runner) .PHONY: service-start-debug service-start-release -service-start-debug service-start-release: service-start-%: build-% - @cd ./build_$* && $(MAKE) start-service_template +service-start-debug service-start-release: service-start-%: + cmake --build build_$* -v --target=start-service_template # Cleanup data .PHONY: clean-debug clean-release clean-debug clean-release: clean-%: - cd build_$* && $(MAKE) clean + cmake --build build_$* --target clean .PHONY: dist-clean dist-clean: - @rm -rf build_* - @rm -rf tests/__pycache__/ - @rm -rf tests/.pytest_cache/ + rm -rf build_* + rm -rf tests/__pycache__/ + rm -rf tests/.pytest_cache/ # Install .PHONY: install-debug install-release install-debug install-release: install-%: build-% - @cd build_$* && \ - cmake --install . -v --component service_template + cmake --install build_$* -v --component service_template .PHONY: install install: install-release @@ -71,20 +68,20 @@ install: install-release # Format the sources .PHONY: format format: - @find src -name '*pp' -type f | xargs $(CLANG_FORMAT) -i - @find tests -name '*.py' -type f | xargs autopep8 -i + find src -name '*pp' -type f | xargs $(CLANG_FORMAT) -i + find tests -name '*.py' -type f | xargs autopep8 -i # Internal hidden targets that are used only in docker environment .PHONY: --in-docker-start-debug --in-docker-start-release --in-docker-start-debug --in-docker-start-release: --in-docker-start-%: install-% - @/home/user/.local/bin/service_template \ + /home/user/.local/bin/service_template \ --config /home/user/.local/etc/service_template/static_config.yaml \ --config_vars /home/user/.local/etc/service_template/config_vars.yaml # Build and run service in docker environment .PHONY: docker-start-service-debug docker-start-service-release docker-start-service-debug docker-start-service-release: docker-start-service-%: - @$(DOCKER_COMPOSE) run -p 8080:8080 --rm service_template-container make -- --in-docker-start-$* + $(DOCKER_COMPOSE) run -p 8080:8080 --rm service_template-container make -- --in-docker-start-$* # Start specific target in docker environment .PHONY: docker-cmake-debug docker-build-debug docker-test-debug docker-clean-debug docker-install-debug docker-cmake-release docker-build-release docker-test-release docker-clean-release docker-install-release @@ -94,4 +91,4 @@ docker-cmake-debug docker-build-debug docker-test-debug docker-clean-debug docke # Stop docker container and cleanup data .PHONY: docker-clean-data docker-clean-data: - @$(DOCKER_COMPOSE) down -v + $(DOCKER_COMPOSE) down -v diff --git a/Makefile.local b/Makefile.local deleted file mode 100644 index 5e40df6..0000000 --- a/Makefile.local +++ /dev/null @@ -1 +0,0 @@ -CMAKE_COMMON_FLAGS += -DUSERVER_FEATURE_CRYPTOPP_BLAKE=0 -DUSERVER_FEATURE_GRPC_CHANNELZ=0 diff --git a/docker-compose.yml b/docker-compose.yml index e0ab9c7..83737a0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,7 +17,7 @@ services: - CORES_DIR=/cores - CXX - MAKE_OPTS - - CMAKE_OPTIONS + - CMAKE_COMMON_FLAGS volumes: - .:/service_template:rw - ./third_party/userver/tools/docker:/tools:ro diff --git a/tests/requirements.txt b/tests/requirements.txt deleted file mode 100644 index 366916e..0000000 --- a/tests/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -yandex-taxi-testsuite >= 0.1.17 -websockets >= 11.0.3 diff --git a/third_party/userver b/third_party/userver index d89f688..b65445d 160000 --- a/third_party/userver +++ b/third_party/userver @@ -1 +1 @@ -Subproject commit d89f68897136ce79c188579a98f00fda0b55c111 +Subproject commit b65445d20df6a3814c84dc4d85836e7ed7d04f81