From 9088a589e11bbf05875d7101fedf7860b4cc532d Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 28 Oct 2024 10:28:47 -0400 Subject: [PATCH 1/5] Googletest as a variant in build_examples.py --- .gn | 5 ----- scripts/build/build/targets.py | 1 + scripts/build/builders/host.py | 8 +++++++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.gn b/.gn index 07b5accb51456c..ddcec4ddd78647 100644 --- a/.gn +++ b/.gn @@ -34,11 +34,6 @@ default_args = { # GN target to use for the default Python build venv. pw_build_PYTHON_BUILD_VENV = "//:matter_build_venv" - # Use the GoogleTest backend for unit tests running on host. - pw_unit_test_BACKEND = "$dir_pw_unit_test:googletest" - pw_unit_test_MAIN = "$dir_pigweed/third_party/googletest:gmock_main" - dir_pw_third_party_googletest = "$dir_googletest" - # Required for pw_unit_test pw_sys_io_BACKEND = "$dir_pw_sys_io_stdio" pw_assert_BACKEND = "$dir_pw_assert_log" diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index 779855f4ed2633..d86c36f328031e 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -200,6 +200,7 @@ def BuildHostTarget(): target.AppendModifier('data-model-disabled', data_model_interface="disabled").ExceptIfRe('-data-model-(check|enabled)') target.AppendModifier('data-model-enabled', data_model_interface="enabled").ExceptIfRe('-data-model-(check|disabled)') target.AppendModifier('check-failure-die', chip_data_model_check_die_on_failure=True).OnlyIfRe('-data-model-check') + target.AppendModifier('googletest', use_googletest=True).OnlyIfRe('-tests') return target diff --git a/scripts/build/builders/host.py b/scripts/build/builders/host.py index 3b81f5d94423fa..2f7aeb229e3ba8 100644 --- a/scripts/build/builders/host.py +++ b/scripts/build/builders/host.py @@ -336,7 +336,8 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE, chip_casting_simplified: Optional[bool] = None, data_model_interface: Optional[str] = None, chip_data_model_check_die_on_failure: Optional[bool] = None, - disable_shell=False + disable_shell=False, + use_googletest=False, ): super(HostBuilder, self).__init__( root=os.path.join(root, 'examples', app.ExamplePath()), @@ -496,6 +497,11 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE, if self.app == HostApp.TESTS and fuzzing_type == HostFuzzingType.PW_FUZZTEST: self.build_command = 'pw_fuzz_tests' + if self.app == HostApp.TESTS and use_googletest: + self.extra_gn_options.append('pw_unit_test_BACKEND = "$dir_pw_unit_test:googletest"') + self.extra_gn_options.append('pw_unit_test_MAIN = "$dir_pigweed/third_party/googletest:gmock_main"') + self.extra_gn_options.append('dir_pw_third_party_googletest = "$dir_googletest"') + def GnBuildArgs(self): if self.board == HostBoard.NATIVE: return self.extra_gn_options From 65ca97828ea498a8d2f9540f0ace9ba1df7431a5 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 28 Oct 2024 10:33:14 -0400 Subject: [PATCH 2/5] Fix unit tests --- scripts/build/testdata/all_targets_linux_x64.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index 084b80bea3ab17..58a1fc1021d305 100644 --- a/scripts/build/testdata/all_targets_linux_x64.txt +++ b/scripts/build/testdata/all_targets_linux_x64.txt @@ -9,7 +9,7 @@ efr32-{brd2704b,brd4316a,brd4317a,brd4318a,brd4319a,brd4186a,brd4187a,brd2601b,b esp32-{m5stack,c3devkit,devkitc,qemu}-{all-clusters,all-clusters-minimal,energy-management,ota-provider,ota-requestor,shell,light,lock,bridge,temperature-measurement,ota-requestor,tests}[-rpc][-ipv6only][-tracing][-data-model-disabled][-data-model-enabled] genio-lighting-app linux-fake-tests[-mbedtls][-boringssl][-asan][-tsan][-ubsan][-libfuzzer][-ossfuzz][-pw-fuzztest][-coverage][-dmalloc][-clang] -linux-{x64,arm64}-{rpc-console,all-clusters,all-clusters-minimal,chip-tool,thermostat,java-matter-controller,kotlin-matter-controller,minmdns,light,light-data-model-no-unique-id,lock,shell,ota-provider,ota-requestor,simulated-app1,simulated-app2,python-bindings,tv-app,tv-casting-app,bridge,fabric-admin,fabric-bridge,fabric-sync,tests,chip-cert,address-resolve-tool,contact-sensor,dishwasher,microwave-oven,refrigerator,rvc,air-purifier,lit-icd,air-quality-sensor,network-manager,energy-management,water-leak-detector}[-nodeps][-nlfaultinject][-platform-mdns][-minmdns-verbose][-libnl][-same-event-loop][-no-interactive][-ipv6only][-no-ble][-no-wifi][-no-thread][-no-shell][-mbedtls][-boringssl][-asan][-tsan][-ubsan][-libfuzzer][-ossfuzz][-pw-fuzztest][-coverage][-dmalloc][-clang][-test][-rpc][-with-ui][-evse-test-event][-enable-dnssd-tests][-disable-dnssd-tests][-chip-casting-simplified][-data-model-check][-data-model-disabled][-data-model-enabled][-check-failure-die] +linux-{x64,arm64}-{rpc-console,all-clusters,all-clusters-minimal,chip-tool,thermostat,java-matter-controller,kotlin-matter-controller,minmdns,light,light-data-model-no-unique-id,lock,shell,ota-provider,ota-requestor,simulated-app1,simulated-app2,python-bindings,tv-app,tv-casting-app,bridge,fabric-admin,fabric-bridge,fabric-sync,tests,chip-cert,address-resolve-tool,contact-sensor,dishwasher,microwave-oven,refrigerator,rvc,air-purifier,lit-icd,air-quality-sensor,network-manager,energy-management,water-leak-detector}[-nodeps][-nlfaultinject][-platform-mdns][-minmdns-verbose][-libnl][-same-event-loop][-no-interactive][-ipv6only][-no-ble][-no-wifi][-no-thread][-no-shell][-mbedtls][-boringssl][-asan][-tsan][-ubsan][-libfuzzer][-ossfuzz][-pw-fuzztest][-coverage][-dmalloc][-clang][-test][-rpc][-with-ui][-evse-test-event][-enable-dnssd-tests][-disable-dnssd-tests][-chip-casting-simplified][-data-model-check][-data-model-disabled][-data-model-enabled][-check-failure-die][-googletest] linux-x64-efr32-test-runner[-clang] imx-{chip-tool,lighting-app,thermostat,all-clusters-app,all-clusters-minimal-app,ota-provider-app}[-release] infineon-psoc6-{lock,light,all-clusters,all-clusters-minimal}[-ota][-updateimage][-trustm] From c755d5770bfa874657e3ab4e095123c78dc6e653 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 28 Oct 2024 10:41:50 -0400 Subject: [PATCH 3/5] A bit more cleanup --- .gn | 1 - scripts/build/builders/host.py | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gn b/.gn index ddcec4ddd78647..f844fd20e9b87d 100644 --- a/.gn +++ b/.gn @@ -13,7 +13,6 @@ # limitations under the License. import("//build_overrides/build.gni") -import("//build_overrides/googletest.gni") import("//build_overrides/pigweed.gni") # The location of the build configuration file. diff --git a/scripts/build/builders/host.py b/scripts/build/builders/host.py index 2f7aeb229e3ba8..7d703f0c5dace8 100644 --- a/scripts/build/builders/host.py +++ b/scripts/build/builders/host.py @@ -498,9 +498,11 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE, self.build_command = 'pw_fuzz_tests' if self.app == HostApp.TESTS and use_googletest: - self.extra_gn_options.append('pw_unit_test_BACKEND = "$dir_pw_unit_test:googletest"') - self.extra_gn_options.append('pw_unit_test_MAIN = "$dir_pigweed/third_party/googletest:gmock_main"') - self.extra_gn_options.append('dir_pw_third_party_googletest = "$dir_googletest"') + self.extra_gn_options.append('import("//build_overrides/pigweed.gni")') + 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('pw_unit_test_MAIN="$dir_pigweed/third_party/googletest:gmock_main"') + self.extra_gn_options.append('dir_pw_third_party_googletest="$dir_googletest"') def GnBuildArgs(self): if self.board == HostBoard.NATIVE: From a3b6e103acd371d912fa0791341f73b2195b8b0c Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 28 Oct 2024 11:15:38 -0400 Subject: [PATCH 4/5] Apply some updates from Arkadiusz --- build/chip/chip_test_suite.gni | 5 +++++ src/test_driver/tizen/.gn | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/build/chip/chip_test_suite.gni b/build/chip/chip_test_suite.gni index de6b7c16848eb5..19264b905104ee 100644 --- a/build/chip/chip_test_suite.gni +++ b/build/chip/chip_test_suite.gni @@ -14,6 +14,7 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") +import("//build_overrides/googletest.gni") import("//build_overrides/pigweed.gni") import("${chip_root}/build/chip/tests.gni") @@ -120,6 +121,10 @@ template("chip_test_suite") { # Link to the common lib for this suite so we get its `sources`. public_deps += [ ":${_suite_name}.lib" ] + if (pw_unit_test_BACKEND == "$dir_pw_unit_test:googletest") { + test_main = "$dir_pigweed/third_party/googletest:gmock_main" + } + # Set variables that the platform executable may need. if (test_executable_output_name != "") { output_name = test_executable_output_name + _test_name + diff --git a/src/test_driver/tizen/.gn b/src/test_driver/tizen/.gn index 26cd7015b64f76..c8f8c5181d0627 100644 --- a/src/test_driver/tizen/.gn +++ b/src/test_driver/tizen/.gn @@ -31,7 +31,6 @@ default_args = { pw_log_BACKEND = "$dir_pw_log_basic" pw_unit_test_BACKEND = "$dir_pw_unit_test:googletest" - pw_unit_test_MAIN = "$dir_pigweed/third_party/googletest:gmock_main" dir_pw_third_party_googletest = "$dir_googletest" # TODO: Make sure only unit tests link against this From f280583933294063aa4d412cdec913b54c804a88 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 28 Oct 2024 11:17:15 -0400 Subject: [PATCH 5/5] Remove extra arg --- scripts/build/builders/host.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/build/builders/host.py b/scripts/build/builders/host.py index 7d703f0c5dace8..114f47f971f1df 100644 --- a/scripts/build/builders/host.py +++ b/scripts/build/builders/host.py @@ -501,7 +501,6 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE, self.extra_gn_options.append('import("//build_overrides/pigweed.gni")') 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('pw_unit_test_MAIN="$dir_pigweed/third_party/googletest:gmock_main"') self.extra_gn_options.append('dir_pw_third_party_googletest="$dir_googletest"') def GnBuildArgs(self):