Skip to content

Commit

Permalink
[OIS] Add socket API option to examples build
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Anna Bridge <[email protected]>
Signed-off-by: paul-szczepanek-arm <[email protected]>
  • Loading branch information
ATmobica and adbridge committed May 15, 2023
1 parent 71b8783 commit 56ff883
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 29 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/examples-openiotsdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
fail-fast: false
matrix:
cryptoBackend: ["psa", "mbedtls"]
socketAPI: ["iotsocket", "lwip"]

name: Open IoT SDK examples building
timeout-minutes: 90
Expand Down Expand Up @@ -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 \
Expand All @@ -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 \
Expand All @@ -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 \
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
"-d${input:openiotsdkDebugMode}",
"-l${input:openiotsdkLwipDebug}",
"-b${input:openiotsdkCryptoBackend}",
"-S${input:openiotsdkSocketAPI}",
"${input:openiotsdkExample}"
],
"group": "build",
Expand All @@ -273,6 +274,7 @@
"-d${input:openiotsdkDebugMode}",
"-l${input:openiotsdkLwipDebug}",
"-b${input:openiotsdkCryptoBackend}",
"-S${input:openiotsdkSocketAPI}",
"unit-tests"
],
"group": "build",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion docs/examples/openiotsdk_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) => <example name>
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)
=> <example name>
```
This will call the scripts with the selected parameters.
Expand Down
6 changes: 5 additions & 1 deletion scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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


Expand Down
20 changes: 19 additions & 1 deletion scripts/build/builders/openiotsdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions scripts/build/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/testdata/all_targets_linux_x64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Original file line number Diff line number Diff line change
@@ -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
8 changes: 0 additions & 8 deletions scripts/build/testdata/dry_run_openiotsdk-lock-mbedtls.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
8 changes: 0 additions & 8 deletions scripts/build/testdata/dry_run_openiotsdk-shell-mbedtls.txt

This file was deleted.

23 changes: 21 additions & 2 deletions scripts/examples/openiotsdk_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -67,6 +68,7 @@ Options:
-d,--debug <debug_enable> Build in debug mode <true | false - default>
-l,--lwipdebug <lwip_debug_enable> Build with LwIP debug logs support <true | false - default>
-b,--backend <crypto_backend) Select crypto backend <psa | mbedtls - default>
-S,--socket <socket_api> Select socket API <lwip | iotsocket - default)
-p,--path <build_path> Build path <build_path - default is example_dir/build>
-n,--network <network_name> FVP network interface name <network_name - default is "user" which means user network mode>
-v,--version <version_number> Application version number <version_number - default is 1>
Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 56ff883

Please sign in to comment.