Skip to content

Commit

Permalink
Add initial Arm Virtual Hardware (AVH) workflow with end to end test
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepmistry committed Aug 15, 2023
1 parent af74ecf commit 1155131
Show file tree
Hide file tree
Showing 10 changed files with 750 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ autogenerated
automake
autotools
avahi
AVH
avL
AwaitNextAction
AXXXF
Expand Down
114 changes: 114 additions & 0 deletions .github/workflows/avh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Copyright (c) 2022 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Arm Virtual Hardware

on:
schedule:
- cron: '0 * * * *'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

jobs:
arm_crosscompile:
name: Linux ARM Cross compile
timeout-minutes: 70

runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build-crosscompile:0.6.47

steps:
- uses: Wandalen/[email protected]
name: Checkout
with:
action: actions/checkout@v3
with: |
token: ${{ github.token }}
attempt_limit: 3
attempt_delay: 2000

- name: Checkout submodules
run: scripts/checkout_submodules.py --shallow --platform linux

- name: Bootstrap cache
uses: actions/cache@v3
timeout-minutes: 10
with:
key: ${{ runner.os }}-env-${{ hashFiles('scripts/setup/*', 'third_party/pigweed/**') }}
path: |
.environment
build_overrides/pigweed_environment.gni
- name: Bootstrap
timeout-minutes: 10
run: scripts/build/gn_bootstrap.sh

- name: Build Samples
timeout-minutes: 45
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py \
--target linux-arm64-chip-tool-ipv6only-mbedtls-clang-minmdns-verbose \
--target linux-arm64-light-ipv6only-mbedtls-clang-minmdns-verbose \
build \
"
- name: Upload built samples
uses: actions/upload-artifact@v3
with:
name: arm_crosscompiled_samples
path: |
out/linux-arm64-chip-tool-ipv6only-mbedtls-clang-minmdns-verbose/chip-tool
out/linux-arm64-light-ipv6only-mbedtls-clang-minmdns-verbose/chip-lighting-app
arm_e2e_tests:
name: Arm Virtual Hardware End to end tests
timeout-minutes: 10

runs-on: ubuntu-latest

env:
AVH_API_TOKEN: ${{ secrets.AVH_API_TOKEN }}

needs: arm_crosscompile

steps:
- name: Checkout
uses: Wandalen/[email protected]
with:
action: actions/checkout@v3
with: |
token: ${{ github.token }}
attempt_limit: 3
attempt_delay: 2000

- name: Downloads Cross-compiled samples
uses: actions/download-artifact@v3
with:
name: arm_crosscompiled_samples
path: scripts/tests/avh/out

- name: Install Python dependencies
run: |
pip3 install -r scripts/tests/avh/requirements.txt
- name: Run end to end test
run: |
cd scripts/tests/avh
python3 -u -m unittest test_lighting_app.py
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
avh-api
paramiko
38 changes: 38 additions & 0 deletions scripts/tests/avh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Arm Virtual Hardware (AVH) based tests

This folder contains end to end tests that use the
[Arm Virtual Hardware (AVH)](https://www.arm.com/products/development-tools/simulation/virtual-hardware)
service.

The tests require the `AVH_API_TOKEN` environment variable is set with the value
from `AVH -> Profile -> API -> API Token`.

## Current tests

- [`test_lighting_app.py`](test_lighting_app.py)
- This test uses two virtual Raspberry Pi Model 4 boards running Ubuntu
Server 22.04 and pre-built `chip-tool` and `chip-lighting-app` binaries
(`linux-arm64`), and tests commissioning and control over BLE and Wi-Fi
using the virtual Bluetooth and Wi-Fi network features of AVH.

## Running the tests

1. Install dependencies

```
pip3 install -r requirements.txt
```

2. Set AVH_API_TOKEN` environment variable

```
export AVH_API_TOKEN=<AVH API TOKEN value>
```

3. Place cross-compiled `chip-tool` and `lighting-app` binaries in `out` folder

4. Run

```
python3 -u -m unittest test_lighting_app.py
```
61 changes: 61 additions & 0 deletions scripts/tests/avh/helpers/avh_chiptool_instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright (c) 2022 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .avh_instance import AvhInstance

APPLICATION_BINARY = "chip-tool"


class AvhChiptoolInstance(AvhInstance):
def __init__(self, avh_client, name, application_binary_path):
super().__init__(avh_client, name)

self.application_binary_path = application_binary_path

def upload_application_binary(self):
super().upload_application_binary(
self.application_binary_path, APPLICATION_BINARY
)

def configure_system(self):
self.log_in_to_console()

# set wlan0 ipv6 to have generated address based on EUI64
self.console_exec_command("sudo sysctl net.ipv6.conf.wlan0.addr_gen_mode=0")

# disable eth0
self.console_exec_command("sudo nmcli dev set eth0 managed no")
self.console_exec_command("sudo ip link set dev eth0 down")

def pairing_ble_wifi(self, node_id, ssid, password, pin_code, discriminator):
output = self.console_exec_command(
f"./{APPLICATION_BINARY} pairing ble-wifi {node_id} {ssid} {password} {pin_code} {discriminator}",
timeout=60.0,
)

return output

def on(self, node_id):
output = self.console_exec_command(
f"./{APPLICATION_BINARY} onoff on {node_id} 1", timeout=30.0
)

return output

def off(self, node_id):
output = self.console_exec_command(
f"./{APPLICATION_BINARY} onoff off {node_id} 1", timeout=30.0
)

return output
71 changes: 71 additions & 0 deletions scripts/tests/avh/helpers/avh_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (c) 2022 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from avh_api import ApiClient as AvhApiClient
from avh_api import Configuration as AvhApiConfiguration
from avh_api.api.arm_api import ArmApi as AvhApi
from avh_api.model.project_key import ProjectKey as AvhProjectKey


class AvhClient:
def __init__(self, api_token):
avh_api_config = AvhApiConfiguration()
self.avh_api_client = AvhApiClient(avh_api_config)

self.avh_api = AvhApi(self.avh_api_client)

avh_api_config.access_token = self.avh_api.v1_auth_login(
{"api_token": api_token}
).token

self.default_project_id = self.avh_api.v1_get_projects()[0]["id"]

def create_instance(self, name, flavor, os, osbuild):
return self.avh_api.v1_create_instance(
{
"name": name,
"project": self.default_project_id,
"flavor": flavor,
"os": os,
"osbuild": osbuild,
}
)["id"]

def instance_state(self, instance_id):
return str(self.avh_api.v1_get_instance_state(instance_id))

def instance_console_log(self, instance_id):
return self.avh_api.v1_get_instance_console_log(instance_id)

def instance_quick_connect_command(self, instance_id):
return self.avh_api.v1_get_instance_quick_connect_command(instance_id)

def create_ssh_project_key(self, label, key):
return self.avh_api.v1_add_project_key(
self.default_project_id,
AvhProjectKey(kind="ssh", key=key, label=label),
)["identifier"]

def instance_console_url(self, instance_id):
return self.avh_api.v1_get_instance_console(instance_id).url

def delete_ssh_project_key(self, key_id):
self.avh_api.v1_remove_project_key(self.default_project_id, key_id)

def delete_instance(self, instance_id):
self.avh_api.v1_delete_instance(instance_id)

def close(self):
self.avh_api_client.rest_client.pool_manager.clear()
self.avh_api_client.close()
Loading

0 comments on commit 1155131

Please sign in to comment.