Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat tests: use userver requirements #61

Merged
merged 10 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ compile_commands.json
cmake-build-*
Testing/
.DS_Store
Makefile.local
20 changes: 16 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)


Expand Down Expand Up @@ -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
Expand Down
69 changes: 33 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,90 +1,87 @@
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

# 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
Expand All @@ -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
1 change: 0 additions & 1 deletion Makefile.local

This file was deleted.

2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion third_party/userver
Submodule userver updated 519 files
Loading