Skip to content

Commit e7729d9

Browse files
authored
Undo googletest in .gn and replace it with a build variant (project-chip#36268)
* Googletest as a variant in build_examples.py * Fix unit tests * A bit more cleanup * Apply some updates from Arkadiusz * Remove extra arg
1 parent 928efd7 commit e7729d9

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

.gn

-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
import("//build_overrides/build.gni")
16-
import("//build_overrides/googletest.gni")
1716
import("//build_overrides/pigweed.gni")
1817

1918
# The location of the build configuration file.
@@ -34,11 +33,6 @@ default_args = {
3433
# GN target to use for the default Python build venv.
3534
pw_build_PYTHON_BUILD_VENV = "//:matter_build_venv"
3635

37-
# Use the GoogleTest backend for unit tests running on host.
38-
pw_unit_test_BACKEND = "$dir_pw_unit_test:googletest"
39-
pw_unit_test_MAIN = "$dir_pigweed/third_party/googletest:gmock_main"
40-
dir_pw_third_party_googletest = "$dir_googletest"
41-
4236
# Required for pw_unit_test
4337
pw_sys_io_BACKEND = "$dir_pw_sys_io_stdio"
4438
pw_assert_BACKEND = "$dir_pw_assert_log"

build/chip/chip_test_suite.gni

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
17+
import("//build_overrides/googletest.gni")
1718
import("//build_overrides/pigweed.gni")
1819

1920
import("${chip_root}/build/chip/tests.gni")
@@ -120,6 +121,10 @@ template("chip_test_suite") {
120121
# Link to the common lib for this suite so we get its `sources`.
121122
public_deps += [ ":${_suite_name}.lib" ]
122123

124+
if (pw_unit_test_BACKEND == "$dir_pw_unit_test:googletest") {
125+
test_main = "$dir_pigweed/third_party/googletest:gmock_main"
126+
}
127+
123128
# Set variables that the platform executable may need.
124129
if (test_executable_output_name != "") {
125130
output_name = test_executable_output_name + _test_name +

scripts/build/build/targets.py

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ def BuildHostTarget():
200200
target.AppendModifier('data-model-disabled', data_model_interface="disabled").ExceptIfRe('-data-model-(check|enabled)')
201201
target.AppendModifier('data-model-enabled', data_model_interface="enabled").ExceptIfRe('-data-model-(check|disabled)')
202202
target.AppendModifier('check-failure-die', chip_data_model_check_die_on_failure=True).OnlyIfRe('-data-model-check')
203+
target.AppendModifier('googletest', use_googletest=True).OnlyIfRe('-tests')
203204

204205
return target
205206

scripts/build/builders/host.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
336336
chip_casting_simplified: Optional[bool] = None,
337337
data_model_interface: Optional[str] = None,
338338
chip_data_model_check_die_on_failure: Optional[bool] = None,
339-
disable_shell=False
339+
disable_shell=False,
340+
use_googletest=False,
340341
):
341342
super(HostBuilder, self).__init__(
342343
root=os.path.join(root, 'examples', app.ExamplePath()),
@@ -496,6 +497,12 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
496497
if self.app == HostApp.TESTS and fuzzing_type == HostFuzzingType.PW_FUZZTEST:
497498
self.build_command = 'pw_fuzz_tests'
498499

500+
if self.app == HostApp.TESTS and use_googletest:
501+
self.extra_gn_options.append('import("//build_overrides/pigweed.gni")')
502+
self.extra_gn_options.append('import("//build_overrides/googletest.gni")')
503+
self.extra_gn_options.append('pw_unit_test_BACKEND="$dir_pw_unit_test:googletest"')
504+
self.extra_gn_options.append('dir_pw_third_party_googletest="$dir_googletest"')
505+
499506
def GnBuildArgs(self):
500507
if self.board == HostBoard.NATIVE:
501508
return self.extra_gn_options

scripts/build/testdata/all_targets_linux_x64.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ efr32-{brd2704b,brd4316a,brd4317a,brd4318a,brd4319a,brd4186a,brd4187a,brd2601b,b
99
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]
1010
genio-lighting-app
1111
linux-fake-tests[-mbedtls][-boringssl][-asan][-tsan][-ubsan][-libfuzzer][-ossfuzz][-pw-fuzztest][-coverage][-dmalloc][-clang]
12-
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]
12+
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]
1313
linux-x64-efr32-test-runner[-clang]
1414
imx-{chip-tool,lighting-app,thermostat,all-clusters-app,all-clusters-minimal-app,ota-provider-app}[-release]
1515
infineon-psoc6-{lock,light,all-clusters,all-clusters-minimal}[-ota][-updateimage][-trustm]

src/test_driver/tizen/.gn

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ default_args = {
3131
pw_log_BACKEND = "$dir_pw_log_basic"
3232

3333
pw_unit_test_BACKEND = "$dir_pw_unit_test:googletest"
34-
pw_unit_test_MAIN = "$dir_pigweed/third_party/googletest:gmock_main"
3534
dir_pw_third_party_googletest = "$dir_googletest"
3635

3736
# TODO: Make sure only unit tests link against this

0 commit comments

Comments
 (0)