From 56ff88310d9f49551f7f8538190c2e4b214047b1 Mon Sep 17 00:00:00 2001 From: ATmobica Date: Wed, 1 Feb 2023 08:54:12 +0000 Subject: [PATCH] [OIS] Add socket API option to examples build Add option to choose socket API in build script. Validate both socket API options in CI. Add socket API option to VScode tasks. This adds the option to select the socket type when building Update the OIS example doc to show the new options. Extend Matter Python builder with socket API options. Co-authored-by: ATmobica Co-authored-by: Anna Bridge Signed-off-by: paul-szczepanek-arm --- .github/workflows/examples-openiotsdk.yaml | 11 +++++---- .vscode/tasks.json | 9 ++++++++ docs/examples/openiotsdk_examples.md | 8 ++++++- scripts/build/build/targets.py | 6 ++++- scripts/build/builders/openiotsdk.py | 20 +++++++++++++++- scripts/build/test.py | 4 ++-- .../build/testdata/all_targets_linux_x64.txt | 2 +- ..._run_openiotsdk-lock-mbedtls-iotsocket.txt | 8 +++++++ .../dry_run_openiotsdk-lock-mbedtls.txt | 8 ------- ...run_openiotsdk-shell-mbedtls-iotsocket.txt | 8 +++++++ .../dry_run_openiotsdk-shell-mbedtls.txt | 8 ------- scripts/examples/openiotsdk_example.sh | 23 +++++++++++++++++-- 12 files changed, 86 insertions(+), 29 deletions(-) create mode 100644 scripts/build/testdata/dry_run_openiotsdk-lock-mbedtls-iotsocket.txt delete mode 100644 scripts/build/testdata/dry_run_openiotsdk-lock-mbedtls.txt create mode 100644 scripts/build/testdata/dry_run_openiotsdk-shell-mbedtls-iotsocket.txt delete mode 100644 scripts/build/testdata/dry_run_openiotsdk-shell-mbedtls.txt diff --git a/.github/workflows/examples-openiotsdk.yaml b/.github/workflows/examples-openiotsdk.yaml index 4049eaf5bbdde1..5003079b690bfc 100644 --- a/.github/workflows/examples-openiotsdk.yaml +++ b/.github/workflows/examples-openiotsdk.yaml @@ -35,6 +35,7 @@ jobs: fail-fast: false matrix: cryptoBackend: ["psa", "mbedtls"] + socketAPI: ["iotsocket", "lwip"] name: Open IoT SDK examples building timeout-minutes: 90 @@ -90,7 +91,7 @@ jobs: id: build_shell timeout-minutes: 10 run: | - scripts/examples/openiotsdk_example.sh -b ${{ matrix.cryptoBackend }} shell + scripts/examples/openiotsdk_example.sh -b ${{ matrix.cryptoBackend }} -S ${{ matrix.socketAPI }} shell .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ openiotsdk release shell \ examples/shell/openiotsdk/build/chip-openiotsdk-shell-example.elf \ @@ -100,7 +101,7 @@ jobs: id: build_lock_app timeout-minutes: 10 run: | - scripts/examples/openiotsdk_example.sh -b ${{ matrix.cryptoBackend }} lock-app + scripts/examples/openiotsdk_example.sh -b ${{ matrix.cryptoBackend }} -S ${{ matrix.socketAPI }} lock-app .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ openiotsdk release lock-app \ examples/lock-app/openiotsdk/build/chip-openiotsdk-lock-app-example.elf \ @@ -110,7 +111,7 @@ jobs: id: build_ota_requestor_app timeout-minutes: 10 run: | - scripts/examples/openiotsdk_example.sh -b ${{ matrix.cryptoBackend }} -v 1 -V 0.0.1 ota-requestor-app + scripts/examples/openiotsdk_example.sh -b ${{ matrix.cryptoBackend }} -S ${{ matrix.socketAPI }} -v 1 -V 0.0.1 ota-requestor-app .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ openiotsdk release lock-app \ examples/ota-requestor-app/openiotsdk/build/chip-openiotsdk-ota-requestor-app-example.elf \ @@ -120,7 +121,7 @@ jobs: id: build_unit_tests timeout-minutes: 10 run: | - scripts/examples/openiotsdk_example.sh -b ${{ matrix.cryptoBackend }} unit-tests + scripts/examples/openiotsdk_example.sh -b ${{ matrix.cryptoBackend }} -S ${{ matrix.socketAPI }} unit-tests - name: Build the OTA provider (Linux) id: build_ota_provider_app @@ -149,7 +150,7 @@ jobs: run: | mkdir out/binaries cp examples/ota-requestor-app/openiotsdk/build/chip-openiotsdk-ota-requestor-app-example.elf out/binaries/ - scripts/examples/openiotsdk_example.sh -c -b ${{ matrix.cryptoBackend }} -v 2 -V 0.0.2 ota-requestor-app + scripts/examples/openiotsdk_example.sh -c -b ${{ matrix.cryptoBackend }} -S ${{ matrix.socketAPI }} -v 2 -V 0.0.2 ota-requestor-app cp examples/ota-requestor-app/openiotsdk/build/chip-openiotsdk-ota-requestor-app-example.ota out/binaries/ scripts/setup/openiotsdk/network_setup.sh -n $TEST_NETWORK_NAME up scripts/run_in_ns.sh ${TEST_NETWORK_NAME}ns scripts/examples/openiotsdk_example.sh -p out/binaries -v 2 -V 0.0.2 -C test -n ${TEST_NETWORK_NAME}tap ota-requestor-app diff --git a/.vscode/tasks.json b/.vscode/tasks.json index bc50ec21a0df3b..1fe6bfa80d327d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -252,6 +252,7 @@ "-d${input:openiotsdkDebugMode}", "-l${input:openiotsdkLwipDebug}", "-b${input:openiotsdkCryptoBackend}", + "-S${input:openiotsdkSocketAPI}", "${input:openiotsdkExample}" ], "group": "build", @@ -273,6 +274,7 @@ "-d${input:openiotsdkDebugMode}", "-l${input:openiotsdkLwipDebug}", "-b${input:openiotsdkCryptoBackend}", + "-S${input:openiotsdkSocketAPI}", "unit-tests" ], "group": "build", @@ -476,6 +478,13 @@ "options": ["mbedtls", "psa"], "default": "mbedtls" }, + { + "type": "pickString", + "id": "openiotsdkSocketAPI", + "description": "Which socket API do you wish to use?", + "options": ["iotsocket", "lwip"], + "default": "iotsocket" + }, { "type": "pickString", "id": "openiotsdkExample", diff --git a/docs/examples/openiotsdk_examples.md b/docs/examples/openiotsdk_examples.md index e2a6de1cd7bb64..5d3df272d903af 100644 --- a/docs/examples/openiotsdk_examples.md +++ b/docs/examples/openiotsdk_examples.md @@ -236,7 +236,13 @@ You build using a vscode task or call the script directly from the command line. ### Building using vscode task ``` -Command Palette (F1) => Run Task... => Build Open IoT SDK example => (debug on/off) => +Command Palette (F1) +=> Run Task... +=> Build Open IoT SDK example +=> Use debug mode (True/False) +=> Choose crypto algorithm (mbedtls/psa) +=> Choose socket API (iotsocket/lwip) +=> ``` This will call the scripts with the selected parameters. diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index 16be4f3875d8a7..b366a5d93c3fdf 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -28,7 +28,7 @@ from builders.mbed import MbedApp, MbedBoard, MbedBuilder, MbedProfile from builders.mw320 import MW320App, MW320Builder from builders.nrf import NrfApp, NrfBoard, NrfConnectBuilder -from builders.openiotsdk import OpenIotSdkApp, OpenIotSdkBuilder, OpenIotSdkCryptoBackend +from builders.openiotsdk import OpenIotSdkApp, OpenIotSdkBuilder, OpenIotSdkCryptoBackend, OpenIotSdkSocketApi from builders.qpg import QpgApp, QpgBoard, QpgBuilder from builders.telink import TelinkApp, TelinkBoard, TelinkBuilder from builders.tizen import TizenApp, TizenBoard, TizenBuilder @@ -571,6 +571,7 @@ def BuildTelinkTarget(): def BuildOpenIotSdkTargets(): target = BuildTarget('openiotsdk', OpenIotSdkBuilder) + # Apps target.AppendFixedTargets([ TargetPart('shell', app=OpenIotSdkApp.SHELL), TargetPart('lock', app=OpenIotSdkApp.LOCK), @@ -580,6 +581,9 @@ def BuildOpenIotSdkTargets(): target.AppendModifier('mbedtls', crypto=OpenIotSdkCryptoBackend.MBEDTLS).ExceptIfRe('-(psa)') target.AppendModifier('psa', crypto=OpenIotSdkCryptoBackend.PSA).ExceptIfRe('-(mbedtls)') + target.AppendModifier('lwip', ).ExceptIfRe('-(iotsocket)') + target.AppendModifier('iotsocket', socketApi=OpenIotSdkSocketApi.IOT_SOCKET).ExceptIfRe('-(lwip)') + return target diff --git a/scripts/build/builders/openiotsdk.py b/scripts/build/builders/openiotsdk.py index 89aad6a59e9a16..28d51c32762d96 100644 --- a/scripts/build/builders/openiotsdk.py +++ b/scripts/build/builders/openiotsdk.py @@ -56,15 +56,31 @@ def CryptoBackendName(self): raise Exception('Unknown crypto backend type: %r' % self) +class OpenIotSdkSocketApi(Enum): + LWIP = auto() + IOT_SOCKET = auto() + + @property + def SocketApiName(self): + if self == OpenIotSdkSocketApi.LWIP: + return 'lwip' + elif self == OpenIotSdkSocketApi.IOT_SOCKET: + return 'iotsocket' + else: + raise Exception('Unknown socket API type: %r' % self) + + class OpenIotSdkBuilder(Builder): def __init__(self, root, runner, app: OpenIotSdkApp = OpenIotSdkApp.SHELL, - crypto: OpenIotSdkCryptoBackend = OpenIotSdkCryptoBackend.MBEDTLS): + crypto: OpenIotSdkCryptoBackend = OpenIotSdkCryptoBackend.MBEDTLS, + socketApi: OpenIotSdkSocketApi = OpenIotSdkSocketApi.IOT_SOCKET): super(OpenIotSdkBuilder, self).__init__(root, runner) self.app = app self.crypto = crypto + self.socket_api = socketApi self.toolchain_path = os.path.join( 'toolchains', 'toolchain-arm-none-eabi-gcc.cmake') self.system_processor = 'cortex-m55' @@ -83,6 +99,8 @@ def generate(self): '-DCMAKE_BUILD_TYPE=Release', '-DCONFIG_CHIP_CRYPTO={}'.format( self.crypto.CryptoBackendName), + '-DCONFIG_CHIP_OPEN_IOT_SDK_USE_IOT_SOCKET={enable}'.format( + enable="YES" if self.socket_api == OpenIotSdkSocketApi.IOT_SOCKET else "NO"), ], title='Generating ' + self.identifier) def _build(self): diff --git a/scripts/build/test.py b/scripts/build/test.py index 999ee72ec833af..8a9f359d32e07b 100644 --- a/scripts/build/test.py +++ b/scripts/build/test.py @@ -108,8 +108,8 @@ def test_general_dry_runs(self): 'android-arm64-chip-tool', 'nrf-nrf52840dk-pump', 'efr32-brd4161a-light-rpc-no-version', - 'openiotsdk-lock-mbedtls', - 'openiotsdk-shell-mbedtls' + 'openiotsdk-lock-mbedtls-iotsocket', + 'openiotsdk-shell-mbedtls-iotsocket' ] for target in TARGETS: diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index 571d0311dee0c4..394519872aba96 100644 --- a/scripts/build/testdata/all_targets_linux_x64.txt +++ b/scripts/build/testdata/all_targets_linux_x64.txt @@ -20,4 +20,4 @@ nrf-native-posix-64-tests qpg-qpg6105-{lock,light,shell,persistent-storage} tizen-arm-{all-clusters,all-clusters-minimal,chip-tool,light,tests}[-no-ble][-no-thread][-no-wifi][-asan][-ubsan] telink-tlsr9518adk80d-{all-clusters,all-clusters-minimal,bridge,contact-sensor,light,light-switch,lock,ota-requestor,pump,pump-controller,temperature-measurement,thermostat,window-covering}[-rpc][-factory-data] -openiotsdk-{shell,lock}[-mbedtls][-psa] +openiotsdk-{shell,lock}[-mbedtls][-psa][-lwip][-iotsocket] diff --git a/scripts/build/testdata/dry_run_openiotsdk-lock-mbedtls-iotsocket.txt b/scripts/build/testdata/dry_run_openiotsdk-lock-mbedtls-iotsocket.txt new file mode 100644 index 00000000000000..15f99bc69c5b3e --- /dev/null +++ b/scripts/build/testdata/dry_run_openiotsdk-lock-mbedtls-iotsocket.txt @@ -0,0 +1,8 @@ +# Commands will be run in CHIP project root. +cd "{root}" + +# Generating openiotsdk-lock-mbedtls-iotsocket +cmake -GNinja -S {root}/examples/lock-app/openiotsdk -B {out}/openiotsdk-lock-mbedtls-iotsocket --toolchain=toolchains/toolchain-arm-none-eabi-gcc.cmake -DCMAKE_SYSTEM_PROCESSOR=cortex-m55 -DCMAKE_BUILD_TYPE=Release -DCONFIG_CHIP_CRYPTO=mbedtls -DCONFIG_CHIP_OPEN_IOT_SDK_USE_IOT_SOCKET=YES + +# Building openiotsdk-lock-mbedtls-iotsocket +cmake --build {out}/openiotsdk-lock-mbedtls-iotsocket diff --git a/scripts/build/testdata/dry_run_openiotsdk-lock-mbedtls.txt b/scripts/build/testdata/dry_run_openiotsdk-lock-mbedtls.txt deleted file mode 100644 index 77816cf664190c..00000000000000 --- a/scripts/build/testdata/dry_run_openiotsdk-lock-mbedtls.txt +++ /dev/null @@ -1,8 +0,0 @@ -# Commands will be run in CHIP project root. -cd "{root}" - -# Generating openiotsdk-lock-mbedtls -cmake -GNinja -S {root}/examples/lock-app/openiotsdk -B {out}/openiotsdk-lock-mbedtls --toolchain=toolchains/toolchain-arm-none-eabi-gcc.cmake -DCMAKE_SYSTEM_PROCESSOR=cortex-m55 -DCMAKE_BUILD_TYPE=Release -DCONFIG_CHIP_CRYPTO=mbedtls - -# Building openiotsdk-lock-mbedtls -cmake --build {out}/openiotsdk-lock-mbedtls diff --git a/scripts/build/testdata/dry_run_openiotsdk-shell-mbedtls-iotsocket.txt b/scripts/build/testdata/dry_run_openiotsdk-shell-mbedtls-iotsocket.txt new file mode 100644 index 00000000000000..40ae32c7d4f551 --- /dev/null +++ b/scripts/build/testdata/dry_run_openiotsdk-shell-mbedtls-iotsocket.txt @@ -0,0 +1,8 @@ +# Commands will be run in CHIP project root. +cd "{root}" + +# Generating openiotsdk-shell-mbedtls-iotsocket +cmake -GNinja -S {root}/examples/shell/openiotsdk -B {out}/openiotsdk-shell-mbedtls-iotsocket --toolchain=toolchains/toolchain-arm-none-eabi-gcc.cmake -DCMAKE_SYSTEM_PROCESSOR=cortex-m55 -DCMAKE_BUILD_TYPE=Release -DCONFIG_CHIP_CRYPTO=mbedtls -DCONFIG_CHIP_OPEN_IOT_SDK_USE_IOT_SOCKET=YES + +# Building openiotsdk-shell-mbedtls-iotsocket +cmake --build {out}/openiotsdk-shell-mbedtls-iotsocket diff --git a/scripts/build/testdata/dry_run_openiotsdk-shell-mbedtls.txt b/scripts/build/testdata/dry_run_openiotsdk-shell-mbedtls.txt deleted file mode 100644 index 70438c5fe091bd..00000000000000 --- a/scripts/build/testdata/dry_run_openiotsdk-shell-mbedtls.txt +++ /dev/null @@ -1,8 +0,0 @@ -# Commands will be run in CHIP project root. -cd "{root}" - -# Generating openiotsdk-shell-mbedtls -cmake -GNinja -S {root}/examples/shell/openiotsdk -B {out}/openiotsdk-shell-mbedtls --toolchain=toolchains/toolchain-arm-none-eabi-gcc.cmake -DCMAKE_SYSTEM_PROCESSOR=cortex-m55 -DCMAKE_BUILD_TYPE=Release -DCONFIG_CHIP_CRYPTO=mbedtls - -# Building openiotsdk-shell-mbedtls -cmake --build {out}/openiotsdk-shell-mbedtls diff --git a/scripts/examples/openiotsdk_example.sh b/scripts/examples/openiotsdk_example.sh index f033d5ee67fd72..0ec34724675f02 100755 --- a/scripts/examples/openiotsdk_example.sh +++ b/scripts/examples/openiotsdk_example.sh @@ -30,6 +30,7 @@ BUILD_PATH="" TOOLCHAIN=arm-none-eabi-gcc DEBUG=false LWIP_DEBUG=false +SOCKET_API="iotsocket" EXAMPLE="" FVP_BIN=FVP_Corstone_SSE-300_Ethos-U55 GDB_PLUGIN="$FAST_MODEL_PLUGINS_PATH/GDBRemoteConnection.so" @@ -67,6 +68,7 @@ Options: -d,--debug Build in debug mode -l,--lwipdebug Build with LwIP debug logs support -b,--backend + -S,--socket Select socket API Build path -n,--network FVP network interface name -v,--version Application version number @@ -128,6 +130,10 @@ function build_with_cmake() { BUILD_OPTIONS+=(-DCONFIG_CHIP_CRYPTO="$CRYPTO_BACKEND") + if [[ $SOCKET_API == "iotsocket" ]]; then + BUILD_OPTIONS+=(-DCONFIG_CHIP_OPEN_IOT_SDK_USE_IOT_SOCKET=YES) + fi + cmake -G Ninja -S "$EXAMPLE_PATH" -B "$BUILD_PATH" --toolchain="$TOOLCHAIN_PATH" "${BUILD_OPTIONS[@]}" cmake --build "$BUILD_PATH" } @@ -262,8 +268,8 @@ function run_test() { fi } -SHORT=C:,p:,d:,l:,b:,n:,v:,V:,c,s,h -LONG=command:,path:,debug:,lwipdebug:,backend:,network:,version:,versionStr:,clean,scratch,help +SHORT=C:,p:,d:,l:,b:,S:,n:,v:,V:,c,s,h +LONG=command:,path:,debug:,lwipdebug:,backend:,socket:,network:,version:,versionStr:,clean,scratch,help OPTS=$(getopt -n build --options "$SHORT" --longoptions "$LONG" -- "$@") eval set -- "$OPTS" @@ -298,6 +304,10 @@ while :; do CRYPTO_BACKEND=$2 shift 2 ;; + -S | --socket) + SOCKET_API=$2 + shift 2 + ;; -p | --path) BUILD_PATH=$CHIP_ROOT/$2 shift 2 @@ -378,6 +388,15 @@ case "$CRYPTO_BACKEND" in ;; esac +case "$SOCKET_API" in + lwip | iotsocket) ;; + *) + echo "Wrong socket API definition" + show_usage + exit 2 + ;; +esac + TOOLCHAIN_PATH="toolchains/toolchain-$TOOLCHAIN.cmake" if [ -z "$BUILD_PATH" ]; then