Skip to content

Add test support to build_examples.py, including fake platform compilation and run #12887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 10, 2021
24 changes: 19 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
run: scripts/run_in_build_env.sh "ninja -C ./out"
build_linux:
name: Build on Linux (gcc_release, clang, mbedtls, simulated)
timeout-minutes: 60
timeout-minutes: 90

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]'
Expand Down Expand Up @@ -158,12 +158,26 @@ jobs:
scripts/tests/gn_tests.sh
done
- name: Build using build_examples.py
timeout-minutes: 30
# NOTE: only vscode image contains the cross compile arm64 sysroot
# so the build command below only compiles x64
timeout-minutes: 40
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py --no-log-timestamps \
--target linux-x64-all-clusters \
--target linux-x64-all-clusters-ipv6only \
--target linux-x64-chip-tool \
--target linux-x64-chip-tool-ipv6only \
--target linux-x64-minmdns-ipv6only \
--target linux-x64-rpc-console \
--target linux-x64-thermostat-ipv6only \
--target linux-x64-tv-app-ipv6only \
build \
"

- name: Fun fake linux tests
timeout-minutes: 15
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py --no-log-timestamps --target-glob 'linux-x64-*' build"
"./scripts/build/build_examples.py --no-log-timestamps --target linux-fake-tests build"

# TODO Log Upload https://github.com/project-chip/connectedhomeip/issues/2227
# TODO https://github.com/project-chip/connectedhomeip/issues/1512
Expand Down
4 changes: 4 additions & 0 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ def HostTargets():

yield variant_target

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


def Esp32Targets():
esp32_target = Target('esp32', Esp32Builder)
Expand Down
9 changes: 7 additions & 2 deletions scripts/build/builders/gn.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def __init__(self, root, runner):
"""
super(GnBuilder, self).__init__(root, runner)

self.build_command = None

def GnBuildArgs(self):
"""Extra gn build `--args`

Expand Down Expand Up @@ -73,5 +75,8 @@ def generate(self):
self._Execute(cmd, title=title)

def _build(self):
self._Execute(['ninja', '-C', self.output_dir],
title='Building ' + self.identifier)
cmd = ['ninja', '-C', self.output_dir]
if self.build_command:
cmd.append(self.build_command)

self._Execute(cmd, title='Building ' + self.identifier)
31 changes: 29 additions & 2 deletions scripts/build/builders/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class HostApp(Enum):
RPC_CONSOLE = auto()
MIN_MDNS = auto()
TV_APP = auto()
TESTS = auto()

def ExamplePath(self):
if self == HostApp.ALL_CLUSTERS:
Expand All @@ -37,10 +38,12 @@ def ExamplePath(self):
return 'thermostat/linux'
elif self == HostApp.RPC_CONSOLE:
return 'common/pigweed/rpc_console'
if self == HostApp.MIN_MDNS:
elif self == HostApp.MIN_MDNS:
return 'minimal-mdns'
if self == HostApp.TV_APP:
elif self == HostApp.TV_APP:
return 'tv-app/linux'
elif self == HostApp.TESTS:
return '../'
else:
raise Exception('Unknown app type: %r' % self)

Expand All @@ -66,6 +69,8 @@ def OutputNames(self):
elif self == HostApp.TV_APP:
yield 'chip-tv-app'
yield 'chip-tv-app.map'
elif self == HostApp.TESTS:
pass
else:
raise Exception('Unknown app type: %r' % self)

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

# for test support
FAKE = auto()

def BoardName(self):
if self == HostBoard.NATIVE:
uname_result = uname()
Expand All @@ -92,12 +100,16 @@ def BoardName(self):
return arch
elif self == HostBoard.ARM64:
return 'arm64'
elif self == HostBoard.FAKE:
return 'fake'
else:
raise Exception('Unknown host board type: %r' % self)

def PlatformName(self):
if self == HostBoard.NATIVE:
return uname().system.lower()
elif self == HostBoard.FAKE:
return 'fake'
else:
# Cross compilation assumes linux currently
return 'linux'
Expand Down Expand Up @@ -135,6 +147,10 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE, enable_ip
self.extra_gn_options.append(
'chip_enable_group_messaging_tests=true')

if app == HostApp.TESTS:
self.extra_gn_options.append('chip_build_tests=true')
self.build_command = 'check'

def GnBuildArgs(self):
if self.board == HostBoard.NATIVE:
return self.extra_gn_options
Expand All @@ -148,13 +164,24 @@ def GnBuildArgs(self):
]
)

return self.extra_gn_options
elif self.board == HostBoard.FAKE:
self.extra_gn_options.extend(
[
'custom_toolchain="//build/toolchain/fake:fake_x64_gcc"',
'chip_link_tests=true',
'chip_device_platform="fake"',
]
)
return self.extra_gn_options
else:
raise Exception('Unknown host board type: %r' % self)

def GnBuildEnv(self):
if self.board == HostBoard.NATIVE:
return None
elif self.board == HostBoard.FAKE:
return None
elif self.board == HostBoard.ARM64:
return {
'PKG_CONFIG_PATH': self.SysRootPath('SYSROOT_AARCH64') + '/lib/aarch64-linux-gnu/pkgconfig',
Expand Down
12 changes: 12 additions & 0 deletions scripts/build/testdata/build_linux_on_x64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ bash -c '
PKG_CONFIG_PATH="SYSROOT_AARCH64/lib/aarch64-linux-gnu/pkgconfig" \
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'

# Generating linux-fake-tests
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

# Generating linux-x64-all-clusters
gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/all-clusters-app/linux {out}/linux-x64-all-clusters

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

# Generating linux-x64-tests
gn gen --check --fail-on-unused-args --export-compile-commands --root={root} --args=chip_build_tests=true {out}/linux-x64-tests

# Generating linux-x64-thermostat
gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/thermostat/linux {out}/linux-x64-thermostat

Expand Down Expand Up @@ -98,6 +104,9 @@ ninja -C {out}/linux-arm64-thermostat
# Building linux-arm64-thermostat-ipv6only
ninja -C {out}/linux-arm64-thermostat-ipv6only

# Building linux-fake-tests
ninja -C {out}/linux-fake-tests check

# Building linux-x64-all-clusters
ninja -C {out}/linux-x64-all-clusters

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

# Building linux-x64-tests
ninja -C {out}/linux-x64-tests check

# Building linux-x64-thermostat
ninja -C {out}/linux-x64-thermostat

Expand Down