Skip to content

Commit

Permalink
Add a buildconfig header for GoogleTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Alami-Amine committed Oct 31, 2024
1 parent 83b60fd commit d8ab669
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions build/chip/tests.gni
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ declare_args() {
declare_args() {
# Enable building tests.
chip_build_tests = current_os != "freertos"

# building unit tests using GoogleTest framework, this should only be enabled through build_examples.py, see PR #36268
chip_build_tests_googletest = false
}

declare_args() {
Expand Down
1 change: 1 addition & 0 deletions scripts/build/builders/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
self.extra_gn_options.append('import("//build_overrides/googletest.gni")')
self.extra_gn_options.append('pw_unit_test_BACKEND="$dir_pw_unit_test:googletest"')
self.extra_gn_options.append('dir_pw_third_party_googletest="$dir_googletest"')
self.extra_gn_options.append('chip_build_tests_googletest=true')

def GnBuildArgs(self):
if self.board == HostBoard.NATIVE:
Expand Down
1 change: 1 addition & 0 deletions src/lib/core/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ buildconfig_header("chip_buildconfig") {
"CHIP_CONFIG_TLV_VALIDATE_CHAR_STRING_ON_WRITE=${chip_tlv_validate_char_string_on_write}",
"CHIP_CONFIG_TLV_VALIDATE_CHAR_STRING_ON_READ=${chip_tlv_validate_char_string_on_read}",
"CHIP_CONFIG_COMMAND_SENDER_BUILTIN_SUPPORT_FOR_BATCHED_COMMANDS=${chip_enable_sending_batch_commands}",
"CHIP_CONFIG_TEST_GOOGLETEST=${chip_build_tests_googletest}",
]

visibility = [ ":chip_config_header" ]
Expand Down
11 changes: 11 additions & 0 deletions src/lib/core/CHIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,17 @@ extern const char CHIP_NON_PRODUCTION_MARKER[];
#define CHIP_CONFIG_MAX_BDX_LOG_TRANSFERS 5
#endif // CHIP_CONFIG_MAX_BDX_LOG_TRANSFERS

/**
* @def CHIP_CONFIG_TEST_GOOGLETEST
*
* @brief
* If asserted (1), enable APIs that support unit tests built with the GoogleTest framework
*
*/
#ifndef CHIP_CONFIG_TEST_GOOGLETEST
#define CHIP_CONFIG_TEST_GOOGLETEST 0
#endif // CHIP_CONFIG_TEST_GOOGLETEST

/**
* @}
*/
5 changes: 2 additions & 3 deletions src/lib/core/StringBuilderAdapters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ StatusWithSize ToString<CHIP_ERROR>(const CHIP_ERROR & err, pw::span<char> buffe

} // namespace pw

#if CHIP_DEVICE_LAYER_TARGET_LINUX || CHIP_DEVICE_LAYER_TARGET_DARWIN || CHIP_DEVICE_LAYER_TARGET_TIZEN || \
CHIP_DEVICE_LAYER_TARGET_ANDROID
#if CHIP_CONFIG_TEST_GOOGLETEST
namespace chip {

void PrintTo(const CHIP_ERROR & err, std::ostream * os)
Expand All @@ -44,4 +43,4 @@ void PrintTo(const CHIP_ERROR & err, std::ostream * os)
*os << "CHIP_ERROR:<" << err.Format() << ">";
}
} // namespace chip
#endif
#endif //CHIP_CONFIG_TEST_GOOGLETEST
5 changes: 2 additions & 3 deletions src/lib/core/StringBuilderAdapters.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ template <>
StatusWithSize ToString<CHIP_ERROR>(const CHIP_ERROR & err, pw::span<char> buffer);

} // namespace pw
#if CHIP_DEVICE_LAYER_TARGET_LINUX || CHIP_DEVICE_LAYER_TARGET_DARWIN || CHIP_DEVICE_LAYER_TARGET_TIZEN || \
CHIP_DEVICE_LAYER_TARGET_ANDROID
#if CHIP_CONFIG_TEST_GOOGLETEST

namespace chip {

Expand All @@ -71,4 +70,4 @@ namespace chip {
/// This enhances the readability and diagnostic information in GoogleTest test logs.
void PrintTo(const CHIP_ERROR & err, std::ostream * os);
} // namespace chip
#endif
#endif //CHIP_CONFIG_TEST_GOOGLETEST

0 comments on commit d8ab669

Please sign in to comment.