Skip to content

Commit 5383f27

Browse files
authored
Fixes for util unit tests (#288)
1 parent fd29a18 commit 5383f27

File tree

7 files changed

+442
-55
lines changed

7 files changed

+442
-55
lines changed

.github/actions/build/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ runs:
99
run: |
1010
mkdir -p ../build
1111
rm -rf ../build/*
12-
cmake -DYDB_SDK_TESTS=On -DYDB_SDK_EXAMPLES=On --preset release
12+
cmake --preset release-test-with-ccache-basedir
1313
- name: Build
1414
shell: bash
1515
run: |

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ set(YDB-CPP-SDK_AVAILABLE_COMPONENTS "" CACHE INTERNAL "")
1818
set(YDB-CPP-SDK_COMPONENT_TARGETS "" CACHE INTERNAL "")
1919
file(READ "src/client/resources/ydb_sdk_version.txt" YDB_SDK_VERSION)
2020

21+
#[=============================================================================[
22+
NOTE: if `ccache` is used with the environment variable `CCACHE_BASEDIR`,
23+
these cached variable should be set manually by passing them to `cmake` as
24+
`-DARCADIA_ROOT=source/path/relative/to/build/dir` and
25+
`-DARCADIA_BUILD_ROOT=.`, because in that case the macro `__FILE__` will be
26+
expanded to a relative path, even if the source code file was specified as
27+
an absolute path, and we have to know the proper prefix of that path.
28+
See details: https://ccache.dev/manual/3.1.html#_compiling_in_different_directories
29+
#]=============================================================================]
30+
set(ARCADIA_ROOT ${YDB_SDK_SOURCE_DIR} CACHE INTERNAL "The source root directory")
31+
set(ARCADIA_BUILD_ROOT ${YDB_SDK_BINARY_DIR} CACHE INTERNAL "The build root directory")
32+
2133
include(GNUInstallDirs)
2234
include(CMakePackageConfigHelpers)
2335

CMakePresets.json

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@
4040
"displayName": "Default Release Config",
4141
"description": "Default release build configuration using Ninja generator and Clang compiler",
4242
"binaryDir": "${sourceDir}/../build"
43+
},
44+
{
45+
"name": "release-test",
46+
"inherits": "release",
47+
"displayName": "Default Release Test Config",
48+
"description": "Default release build configuration with all tests and examples",
49+
"cacheVariables": {
50+
"YDB_SDK_TESTS": "TRUE",
51+
"YDB_SDK_EXAMPLES": "TRUE"
52+
}
53+
},
54+
{
55+
"name": "release-test-with-ccache-basedir",
56+
"inherits": "release-test",
57+
"displayName": "Release Test Config CCACHE_BASEDIR Case",
58+
"description": "Only for the case when using CCACHE_BASEDIR",
59+
"cacheVariables": {
60+
"ARCADIA_ROOT": "../ydb-cpp-sdk",
61+
"ARCADIA_BUILD_ROOT": "."
62+
}
4363
}
4464
],
4565
"buildPresets": [
@@ -51,51 +71,46 @@
5171
],
5272
"testPresets": [
5373
{
54-
"name": "release",
55-
"configurePreset": "release",
56-
"displayName": "Default Release Tests",
74+
"name": "common",
75+
"hidden": true,
5776
"output": {
5877
"outputOnFailure": true
5978
},
6079
"execution": {
6180
"timeout": 1200
62-
},
81+
}
82+
},
83+
{
84+
"name": "release",
85+
"inherits": "common",
86+
"configurePreset": "release-test",
87+
"displayName": "Default Release Tests",
6388
"environment": {
6489
"YDB_ENDPOINT": "localhost:2136",
6590
"YDB_DATABASE": "/local"
6691
}
6792
},
6893
{
6994
"name": "release-unit",
70-
"configurePreset": "release",
95+
"inherits": "common",
96+
"configurePreset": "release-test",
7197
"displayName": "Default Unit Release Tests",
7298
"filter" : {
7399
"include": {
74100
"label": "unit"
75101
}
76-
},
77-
"output": {
78-
"outputOnFailure": true
79-
},
80-
"execution": {
81-
"timeout": 1200
82102
}
83103
},
84104
{
85105
"name": "release-integration",
86-
"configurePreset": "release",
106+
"inherits": "common",
107+
"configurePreset": "release-test",
87108
"displayName": "Default Integration Release Tests",
88-
"output": {
89-
"outputOnFailure": true
90-
},
91109
"filter" : {
92110
"include": {
93111
"label": "integration"
94112
}
95113
},
96-
"execution": {
97-
"timeout": 1200
98-
},
99114
"environment": {
100115
"YDB_ENDPOINT": "localhost:2136",
101116
"YDB_DATABASE": "/local"

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,14 @@ Running integration tests only:
138138

139139
```bash
140140
ctest -j$(nproc) --preset release-integration
141-
```
141+
```
142+
143+
Note that some tests use a legacy test library instead of GoogleTest, see `./<test_target> --help` for details. If you need to run only certain test cases, here is an alternative for `--gtest_filter` option:
144+
145+
```bash
146+
cat <<EOF | ./<test_target> --filter-file /dev/fd/0
147+
-ExcludedTestCase
148+
+IncludedTestCase
149+
+IncludedTestCase::TestName
150+
EOF
151+
```

cmake/ccache.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
if (NOT CCACHE_PATH)
2-
find_program(CCACHE_PATH ccache)
3-
endif()
1+
find_program(CCACHE_PATH ccache)
42
if (NOT CCACHE_PATH)
53
message(AUTHOR_WARNING
64
"Ccache is not found, that will increase the re-compilation time; "

cmake/testing.cmake

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function(add_yunittest)
22
set(opts "")
3-
set(oneval_args NAME TEST_TARGET)
3+
set(oneval_args NAME TEST_TARGET WORKING_DIRECTORY)
44
set(multival_args TEST_ARG)
55
cmake_parse_arguments(YUNITTEST_ARGS
66
"${opts}"
@@ -13,13 +13,19 @@ function(add_yunittest)
1313
get_property(SPLIT_TYPE TARGET ${YUNITTEST_ARGS_TEST_TARGET} PROPERTY SPLIT_TYPE)
1414

1515
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/run_testpack")
16-
add_test(NAME ${YUNITTEST_ARGS_NAME} COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/run_testpack" ${YUNITTEST_ARGS_TEST_ARG})
16+
add_test(NAME ${YUNITTEST_ARGS_NAME}
17+
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/run_testpack" ${YUNITTEST_ARGS_TEST_ARG}
18+
WORKING_DIRECTORY ${YUNITTEST_ARGS_WORKING_DIRECTORY}
19+
)
1720
set_property(TEST ${YUNITTEST_ARGS_NAME} PROPERTY ENVIRONMENT "source_root=${YDB_SDK_SOURCE_DIR};build_root=${YDB_SDK_BINARY_DIR};test_split_factor=${SPLIT_FACTOR};test_split_type=${SPLIT_TYPE}")
1821
return()
1922
endif()
2023

2124
if (${SPLIT_FACTOR} EQUAL 1)
22-
add_test(NAME ${YUNITTEST_ARGS_NAME} COMMAND ${YUNITTEST_ARGS_TEST_TARGET} ${YUNITTEST_ARGS_TEST_ARG})
25+
add_test(NAME ${YUNITTEST_ARGS_NAME}
26+
COMMAND ${YUNITTEST_ARGS_TEST_TARGET} ${YUNITTEST_ARGS_TEST_ARG}
27+
WORKING_DIRECTORY ${YUNITTEST_ARGS_WORKING_DIRECTORY}
28+
)
2329
return()
2430
endif()
2531

@@ -29,8 +35,12 @@ function(add_yunittest)
2935
math(EXPR LastIdx "${SPLIT_FACTOR} - 1")
3036
foreach(Idx RANGE ${LastIdx})
3137
add_test(NAME ${YUNITTEST_ARGS_NAME}_${Idx}
32-
COMMAND Python3::Interpreter ${YDB_SDK_SOURCE_DIR}/scripts/split_unittest.py --split-factor ${SPLIT_FACTOR} ${FORK_MODE_ARG} --shard ${Idx}
33-
$<TARGET_FILE:${YUNITTEST_ARGS_TEST_TARGET}> ${YUNITTEST_ARGS_TEST_ARG})
38+
COMMAND Python3::Interpreter ${YDB_SDK_SOURCE_DIR}/scripts/split_unittest.py
39+
--split-factor ${SPLIT_FACTOR} ${FORK_MODE_ARG}
40+
--shard ${Idx}
41+
$<TARGET_FILE:${YUNITTEST_ARGS_TEST_TARGET}> ${YUNITTEST_ARGS_TEST_ARG}
42+
WORKING_DIRECTORY ${YUNITTEST_ARGS_WORKING_DIRECTORY}
43+
)
3444
endforeach()
3545
endfunction()
3646

@@ -59,15 +69,23 @@ endfunction()
5969

6070
function(add_ydb_test)
6171
set(opts GTEST)
62-
set(oneval_args NAME)
63-
set(multival_args INCLUDE_DIRS SOURCES LINK_LIBRARIES LABELS)
72+
set(oneval_args NAME WORKING_DIRECTORY OUTPUT_DIRECTORY)
73+
set(multival_args INCLUDE_DIRS SOURCES LINK_LIBRARIES LABELS TEST_ARG)
6474
cmake_parse_arguments(YDB_TEST
6575
"${opts}"
6676
"${oneval_args}"
6777
"${multival_args}"
6878
${ARGN}
6979
)
7080

81+
if (YDB_TEST_WORKING_DIRECTORY AND NOT EXISTS "${YDB_TEST_WORKING_DIRECTORY}")
82+
file(MAKE_DIRECTORY "${YDB_TEST_WORKING_DIRECTORY}")
83+
endif()
84+
85+
if (YDB_TEST_OUTPUT_DIRECTORY AND NOT EXISTS "${YDB_TEST_OUTPUT_DIRECTORY}")
86+
file(MAKE_DIRECTORY "${YDB_TEST_OUTPUT_DIRECTORY}")
87+
endif()
88+
7189
add_executable(${YDB_TEST_NAME})
7290
target_include_directories(${YDB_TEST_NAME} PRIVATE ${YDB_TEST_INCLUDE_DIRS})
7391
target_link_libraries(${YDB_TEST_NAME} PRIVATE ${YDB_TEST_LINK_LIBRARIES})
@@ -96,56 +114,63 @@ function(add_ydb_test)
96114

97115
set_property(
98116
TARGET
99-
${YDB_TEST_NAME}
117+
${YDB_TEST_NAME}
100118
PROPERTY
101-
SPLIT_FACTOR
102-
1
119+
SPLIT_FACTOR
120+
1
103121
)
104122
if (YDB_TEST_GTEST)
105123
add_yunittest(
106124
NAME
107-
${YDB_TEST_NAME}
125+
${YDB_TEST_NAME}
108126
TEST_TARGET
109-
${YDB_TEST_NAME}
127+
${YDB_TEST_NAME}
128+
TEST_ARG
129+
${YDB_TEST_TEST_ARG}
130+
WORKING_DIRECTORY
131+
${YDB_TEST_WORKING_DIRECTORY}
110132
)
111133
else()
112134
add_yunittest(
113135
NAME
114-
${YDB_TEST_NAME}
136+
${YDB_TEST_NAME}
115137
TEST_TARGET
116-
${YDB_TEST_NAME}
138+
${YDB_TEST_NAME}
117139
TEST_ARG
118-
--print-before-suite
119-
--print-before-test
120-
--fork-tests
121-
--print-times
122-
--show-fails
140+
--print-before-suite
141+
--print-before-test
142+
--fork-tests
143+
--print-times
144+
--show-fails
145+
${YDB_TEST_TEST_ARG}
146+
WORKING_DIRECTORY
147+
${YDB_TEST_WORKING_DIRECTORY}
123148
)
124149
endif()
125150

126151
set_yunittest_property(
127152
TEST
128-
${YDB_TEST_NAME}
153+
${YDB_TEST_NAME}
129154
PROPERTY
130-
LABELS
131-
MEDIUM
132-
${YDB_TEST_LABELS}
155+
LABELS
156+
MEDIUM
157+
${YDB_TEST_LABELS}
133158
)
134159

135160
set_yunittest_property(
136161
TEST
137-
${YDB_TEST_NAME}
162+
${YDB_TEST_NAME}
138163
PROPERTY
139-
PROCESSORS
140-
1
164+
PROCESSORS
165+
1
141166
)
142167

143168
set_yunittest_property(
144169
TEST
145-
${YDB_TEST_NAME}
170+
${YDB_TEST_NAME}
146171
PROPERTY
147-
TIMEOUT
148-
600
172+
TIMEOUT
173+
600
149174
)
150175

151176
vcs_info(${YDB_TEST_NAME})

0 commit comments

Comments
 (0)