Skip to content

Commit

Permalink
Add target for native unit test execution for nrfconnect in build_exa…
Browse files Browse the repository at this point in the history
…mples.py (#12956)

* Add a nrf test target for native unit test execution

* Remove obsolete script

* Avoid the need to cd ... use ctest directly and tell it to not run cmake

* Restyle fixes

* Remove errand space in build nocmake
  • Loading branch information
andy31415 authored and pull[bot] committed Apr 6, 2022
1 parent 09c00e7 commit aa86680
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 39 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/examples-nrfconnect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ jobs:
- name: Run unit tests for Zephyr native_posix_64 platform
timeout-minutes: 10
run: |
scripts/run_in_build_env.sh "scripts/tests/nrfconnect_native_posix_tests.sh native_posix_64"
scripts/run_in_build_env.sh "./scripts/build/build_examples.py --target nrf-native-posix-64-tests build"
- name: Uploading Failed Test Logs
uses: actions/upload-artifact@v2
if: ${{ failure() }} && ${{ !env.ACT }}
Expand Down
2 changes: 2 additions & 0 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ def Efr32Targets():
def NrfTargets():
target = Target('nrf', NrfConnectBuilder)

yield target.Extend('native-posix-64-tests', board=NrfBoard.NATIVE_POSIX_64, app=NrfApp.UNIT_TESTS)

targets = [
target.Extend('nrf5340', board=NrfBoard.NRF5340),
target.Extend('nrf52840', board=NrfBoard.NRF52840),
Expand Down
35 changes: 28 additions & 7 deletions scripts/build/builders/nrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ class NrfApp(Enum):
SHELL = auto()
PUMP = auto()
PUMP_CONTROLLER = auto()
UNIT_TESTS = auto()

def ExampleName(self):
def AppPath(self):
if self == NrfApp.LIGHT:
return 'lighting-app'
return 'examples/lighting-app'
elif self == NrfApp.LOCK:
return 'lock-app'
return 'examples/lock-app'
elif self == NrfApp.SHELL:
return 'shell'
return 'examples/shell'
elif self == NrfApp.PUMP:
return 'pump-app'
return 'examples/pump-app'
elif self == NrfApp.PUMP_CONTROLLER:
return 'pump-controller-app'
return 'examples/pump-controller-app'
elif self == NrfApp.UNIT_TESTS:
return 'src/test_driver'
else:
raise Exception('Unknown app type: %r' % self)

Expand All @@ -53,6 +56,8 @@ def AppNamePrefix(self):
return 'chip-nrf-pump-example'
elif self == NrfApp.PUMP_CONTROLLER:
return 'chip-nrf-pump-controller-example'
elif self == NrfApp.UNIT_TESTS:
return 'chip-nrf-unit-tests'
else:
raise Exception('Unknown app type: %r' % self)

Expand All @@ -67,6 +72,9 @@ def _FlashBundlePrefix(self):
return 'chip-nrfconnect-pump-example'
elif self == NrfApp.PUMP_CONTROLLER:
return 'chip-nrfconnect-pump-controller-example'
elif self == NrfApp.UNIT_TESTS:
raise Exception(
'Unit tests compile natively and do not have a flashbundle')
else:
raise Exception('Unknown app type: %r' % self)

Expand All @@ -78,12 +86,15 @@ def FlashBundleName(self):
class NrfBoard(Enum):
NRF52840 = auto()
NRF5340 = auto()
NATIVE_POSIX_64 = auto()

def GnArgName(self):
if self == NrfBoard.NRF52840:
return 'nrf52840dk_nrf52840'
elif self == NrfBoard.NRF5340:
return 'nrf5340dk_nrf5340_cpuapp'
elif self == NrfBoard.NATIVE_POSIX_64:
return 'native_posix_64'
else:
raise Exception('Unknown board type: %r' % self)

Expand Down Expand Up @@ -136,7 +147,7 @@ def generate(self):
outdir=shlex.quote(self.output_dir),
board=self.board.GnArgName(),
sourcedir=shlex.quote(os.path.join(
self.root, 'examples', self.app.ExampleName(), 'nrfconnect')),
self.root, self.app.AppPath(), 'nrfconnect')),
rpcs=" -- -DOVERLAY_CONFIG=rpc.overlay" if self.enable_rpcs else ""
).strip()

Expand All @@ -149,6 +160,13 @@ def _build(self):
self._Execute(['ninja', '-C', self.output_dir],
title='Building ' + self.identifier)

if self.app == NrfApp.UNIT_TESTS:
# Note: running zephyr/zephyr.elf has the same result except it creates
# a flash.bin in the current directory. ctest has more options and does not
# pollute the source directory
self._Execute(['ctest', '--build-nocmake', '-V', '--output-on-failure', '--test-dir', self.output_dir],
title='Run Tests ' + self.identifier)

def _generate_flashbundle(self):
logging.info(f'Generating flashbundle at {self.output_dir}')

Expand All @@ -162,6 +180,9 @@ def build_outputs(self):
}

def flashbundle(self):
if self.app == NrfApp.UNIT_TESTS:
return dict()

with open(os.path.join(self.output_dir, self.app.FlashBundleName()), 'r') as fp:
return {
l.strip(): os.path.join(self.output_dir, l.strip()) for l in fp.readlines() if l.strip()
Expand Down
1 change: 1 addition & 0 deletions scripts/build/testdata/all_targets_except_host.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ mbed-CY8CPROTO_062_4343W-pigweed-release
mbed-CY8CPROTO_062_4343W-shell-debug (NOGLOB: Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html)
mbed-CY8CPROTO_062_4343W-shell-develop (NOGLOB: Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html)
mbed-CY8CPROTO_062_4343W-shell-release
nrf-native-posix-64-tests
nrf-nrf52840-light
nrf-nrf52840-light-rpc
nrf-nrf52840-lock
Expand Down
11 changes: 11 additions & 0 deletions scripts/build/testdata/build_all_except_host.txt
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,11 @@ mbed-tools configure -t GCC_ARM -m CY8CPROTO_062_4343W -p {root}/examples/shell/
# Generating mbed-CY8CPROTO_062_4343W-shell-release
cmake -S {root}/examples/shell/mbed -B {out}/mbed-CY8CPROTO_062_4343W-shell-release -GNinja -DCMAKE_BUILD_TYPE=release -DMBED_OS_PATH={root}/third_party/mbed-os/repo -DMBED_OS_POSIX_SOCKET_PATH={root}/third_party/mbed-os-posix-socket/repo

# Generating nrf-native-posix-64-tests
bash -c 'source "$ZEPHYR_BASE/zephyr-env.sh";
export GNUARMEMB_TOOLCHAIN_PATH="$PW_PIGWEED_CIPD_INSTALL_DIR";
west build --cmake-only -d {out}/nrf-native-posix-64-tests -b native_posix_64 {root}/src/test_driver/nrfconnect'

# Generating nrf-nrf52840-light
bash -c 'source "$ZEPHYR_BASE/zephyr-env.sh";
export GNUARMEMB_TOOLCHAIN_PATH="$PW_PIGWEED_CIPD_INSTALL_DIR";
Expand Down Expand Up @@ -1071,6 +1076,12 @@ bash -c 'rm -rf {out}/mbed-CY8CPROTO_062_4343W-shell-release/chip-*'
# Building mbed-CY8CPROTO_062_4343W-shell-release
cmake --build {out}/mbed-CY8CPROTO_062_4343W-shell-release

# Building nrf-native-posix-64-tests
ninja -C {out}/nrf-native-posix-64-tests

# Run Tests nrf-native-posix-64-tests
ctest --build-nocmake -V --output-on-failure --test-dir {out}/nrf-native-posix-64-tests

# Building nrf-nrf52840-light
ninja -C {out}/nrf-nrf52840-light

Expand Down
1 change: 1 addition & 0 deletions scripts/build/testdata/glob_star_targets_except_host.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mbed-CY8CPROTO_062_4343W-light-release
mbed-CY8CPROTO_062_4343W-lock-release
mbed-CY8CPROTO_062_4343W-pigweed-release
mbed-CY8CPROTO_062_4343W-shell-release
nrf-native-posix-64-tests
nrf-nrf52840-light
nrf-nrf52840-light-rpc
nrf-nrf52840-lock
Expand Down
30 changes: 0 additions & 30 deletions scripts/tests/nrfconnect_native_posix_tests.sh

This file was deleted.

0 comments on commit aa86680

Please sign in to comment.