Skip to content

Commit 1706636

Browse files
andy31415pull[bot]
authored andcommitted
Add test support to build_examples.py, including fake platform compilation and run (#12887)
* Build examples now supports tests * Fix unit tests for linux * Fake platform test support * Update options a bit, ensue build fails if fake ConfigurationManagerImpl is bad * Update CI to run tests using build_examples.py * Bump up timeout for build now that it includes both test compile and run * Reduce some compile targets from workflows * Be more explicit in what is being built * Remove useless comment
1 parent a0fc659 commit 1706636

File tree

5 files changed

+71
-9
lines changed

5 files changed

+71
-9
lines changed

.github/workflows/build.yaml

+19-5
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
run: scripts/run_in_build_env.sh "ninja -C ./out"
9393
build_linux:
9494
name: Build on Linux (gcc_release, clang, mbedtls, simulated)
95-
timeout-minutes: 60
95+
timeout-minutes: 90
9696

9797
runs-on: ubuntu-latest
9898
if: github.actor != 'restyled-io[bot]'
@@ -158,12 +158,26 @@ jobs:
158158
scripts/tests/gn_tests.sh
159159
done
160160
- name: Build using build_examples.py
161-
timeout-minutes: 30
162-
# NOTE: only vscode image contains the cross compile arm64 sysroot
163-
# so the build command below only compiles x64
161+
timeout-minutes: 40
162+
run: |
163+
./scripts/run_in_build_env.sh \
164+
"./scripts/build/build_examples.py --no-log-timestamps \
165+
--target linux-x64-all-clusters \
166+
--target linux-x64-all-clusters-ipv6only \
167+
--target linux-x64-chip-tool \
168+
--target linux-x64-chip-tool-ipv6only \
169+
--target linux-x64-minmdns-ipv6only \
170+
--target linux-x64-rpc-console \
171+
--target linux-x64-thermostat-ipv6only \
172+
--target linux-x64-tv-app-ipv6only \
173+
build \
174+
"
175+
176+
- name: Fun fake linux tests
177+
timeout-minutes: 15
164178
run: |
165179
./scripts/run_in_build_env.sh \
166-
"./scripts/build/build_examples.py --no-log-timestamps --target-glob 'linux-x64-*' build"
180+
"./scripts/build/build_examples.py --no-log-timestamps --target linux-fake-tests build"
167181
168182
# TODO Log Upload https://github.com/project-chip/connectedhomeip/issues/2227
169183
# TODO https://github.com/project-chip/connectedhomeip/issues/1512

scripts/build/build/targets.py

+4
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ def HostTargets():
195195

196196
yield variant_target
197197

198+
test_target = Target(HostBoard.NATIVE.PlatformName(), HostBuilder)
199+
for board in [HostBoard.NATIVE, HostBoard.FAKE]:
200+
yield test_target.Extend(board.BoardName() + '-tests', board=board, app=HostApp.TESTS)
201+
198202

199203
def Esp32Targets():
200204
esp32_target = Target('esp32', Esp32Builder)

scripts/build/builders/gn.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def __init__(self, root, runner):
2929
"""
3030
super(GnBuilder, self).__init__(root, runner)
3131

32+
self.build_command = None
33+
3234
def GnBuildArgs(self):
3335
"""Extra gn build `--args`
3436
@@ -73,5 +75,8 @@ def generate(self):
7375
self._Execute(cmd, title=title)
7476

7577
def _build(self):
76-
self._Execute(['ninja', '-C', self.output_dir],
77-
title='Building ' + self.identifier)
78+
cmd = ['ninja', '-C', self.output_dir]
79+
if self.build_command:
80+
cmd.append(self.build_command)
81+
82+
self._Execute(cmd, title='Building ' + self.identifier)

scripts/build/builders/host.py

+29-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class HostApp(Enum):
2727
RPC_CONSOLE = auto()
2828
MIN_MDNS = auto()
2929
TV_APP = auto()
30+
TESTS = auto()
3031

3132
def ExamplePath(self):
3233
if self == HostApp.ALL_CLUSTERS:
@@ -37,10 +38,12 @@ def ExamplePath(self):
3738
return 'thermostat/linux'
3839
elif self == HostApp.RPC_CONSOLE:
3940
return 'common/pigweed/rpc_console'
40-
if self == HostApp.MIN_MDNS:
41+
elif self == HostApp.MIN_MDNS:
4142
return 'minimal-mdns'
42-
if self == HostApp.TV_APP:
43+
elif self == HostApp.TV_APP:
4344
return 'tv-app/linux'
45+
elif self == HostApp.TESTS:
46+
return '../'
4447
else:
4548
raise Exception('Unknown app type: %r' % self)
4649

@@ -66,6 +69,8 @@ def OutputNames(self):
6669
elif self == HostApp.TV_APP:
6770
yield 'chip-tv-app'
6871
yield 'chip-tv-app.map'
72+
elif self == HostApp.TESTS:
73+
pass
6974
else:
7075
raise Exception('Unknown app type: %r' % self)
7176

@@ -76,6 +81,9 @@ class HostBoard(Enum):
7681
# cross-compile support
7782
ARM64 = auto()
7883

84+
# for test support
85+
FAKE = auto()
86+
7987
def BoardName(self):
8088
if self == HostBoard.NATIVE:
8189
uname_result = uname()
@@ -92,12 +100,16 @@ def BoardName(self):
92100
return arch
93101
elif self == HostBoard.ARM64:
94102
return 'arm64'
103+
elif self == HostBoard.FAKE:
104+
return 'fake'
95105
else:
96106
raise Exception('Unknown host board type: %r' % self)
97107

98108
def PlatformName(self):
99109
if self == HostBoard.NATIVE:
100110
return uname().system.lower()
111+
elif self == HostBoard.FAKE:
112+
return 'fake'
101113
else:
102114
# Cross compilation assumes linux currently
103115
return 'linux'
@@ -135,6 +147,10 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE, enable_ip
135147
self.extra_gn_options.append(
136148
'chip_enable_group_messaging_tests=true')
137149

150+
if app == HostApp.TESTS:
151+
self.extra_gn_options.append('chip_build_tests=true')
152+
self.build_command = 'check'
153+
138154
def GnBuildArgs(self):
139155
if self.board == HostBoard.NATIVE:
140156
return self.extra_gn_options
@@ -148,13 +164,24 @@ def GnBuildArgs(self):
148164
]
149165
)
150166

167+
return self.extra_gn_options
168+
elif self.board == HostBoard.FAKE:
169+
self.extra_gn_options.extend(
170+
[
171+
'custom_toolchain="//build/toolchain/fake:fake_x64_gcc"',
172+
'chip_link_tests=true',
173+
'chip_device_platform="fake"',
174+
]
175+
)
151176
return self.extra_gn_options
152177
else:
153178
raise Exception('Unknown host board type: %r' % self)
154179

155180
def GnBuildEnv(self):
156181
if self.board == HostBoard.NATIVE:
157182
return None
183+
elif self.board == HostBoard.FAKE:
184+
return None
158185
elif self.board == HostBoard.ARM64:
159186
return {
160187
'PKG_CONFIG_PATH': self.SysRootPath('SYSROOT_AARCH64') + '/lib/aarch64-linux-gnu/pkgconfig',

scripts/build/testdata/build_linux_on_x64.txt

+12
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ bash -c '
4141
PKG_CONFIG_PATH="SYSROOT_AARCH64/lib/aarch64-linux-gnu/pkgconfig" \
4242
gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/thermostat/linux '"'"'--args=chip_inet_config_enable_ipv4=false target_cpu="arm64" is_clang=true chip_crypto="mbedtls" sysroot="SYSROOT_AARCH64"'"'"' {out}/linux-arm64-thermostat-ipv6only'
4343

44+
# Generating linux-fake-tests
45+
gn gen --check --fail-on-unused-args --export-compile-commands --root={root} '--args=chip_build_tests=true custom_toolchain="//build/toolchain/fake:fake_x64_gcc" chip_link_tests=true chip_device_platform="fake"' {out}/linux-fake-tests
46+
4447
# Generating linux-x64-all-clusters
4548
gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/all-clusters-app/linux {out}/linux-x64-all-clusters
4649

@@ -62,6 +65,9 @@ gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/exa
6265
# Generating linux-x64-rpc-console
6366
gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/common/pigweed/rpc_console {out}/linux-x64-rpc-console
6467

68+
# Generating linux-x64-tests
69+
gn gen --check --fail-on-unused-args --export-compile-commands --root={root} --args=chip_build_tests=true {out}/linux-x64-tests
70+
6571
# Generating linux-x64-thermostat
6672
gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/thermostat/linux {out}/linux-x64-thermostat
6773

@@ -98,6 +104,9 @@ ninja -C {out}/linux-arm64-thermostat
98104
# Building linux-arm64-thermostat-ipv6only
99105
ninja -C {out}/linux-arm64-thermostat-ipv6only
100106

107+
# Building linux-fake-tests
108+
ninja -C {out}/linux-fake-tests check
109+
101110
# Building linux-x64-all-clusters
102111
ninja -C {out}/linux-x64-all-clusters
103112

@@ -119,6 +128,9 @@ ninja -C {out}/linux-x64-minmdns-ipv6only
119128
# Building linux-x64-rpc-console
120129
ninja -C {out}/linux-x64-rpc-console
121130

131+
# Building linux-x64-tests
132+
ninja -C {out}/linux-x64-tests check
133+
122134
# Building linux-x64-thermostat
123135
ninja -C {out}/linux-x64-thermostat
124136

0 commit comments

Comments
 (0)