Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/hardware-bu585.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ jobs:
- name: Build and Flash Supervisor
run: |
. /opt/zephyr-venv/bin/activate
west build -p always -b b_u585i_iot02a ocre-runtime/src/samples/supervisor/zephyr -- "-DOCRE_SDK_PRELOADED_IMAGES=hello-world.wasm"
west build -p always -b b_u585i_iot02a --shield wiznet_w5500 ocre-runtime/src/samples/supervisor/zephyr -- "-DOCRE_SDK_PRELOADED_IMAGES=hello-world.wasm;webserver-complex.wasm"
west flash --extload=/usr/local/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/ExternalLoader/MX25LM51245G_STM32U585I-IOT02A.stldr --hex-file build/zephyr/merged.hex

supervisor-test-set-1:
Expand All @@ -260,6 +260,8 @@ jobs:
test:
- name: Hello-World
group: supervisor-helloWorld
- name: Webserver-Complex
group: supervisor-webserverComplex

steps:
- name: Checkout
Expand All @@ -269,6 +271,6 @@ jobs:
run: |
cd tests_hw && bash beginTests.sh ${{ matrix.test.group }}

- name: Print Hello-World Test Case Logs
- name: Print ${{ matrix.test.name }} Testcase Logs
if: always()
run: cat /tmp/${{ matrix.test.group }}.log
30 changes: 30 additions & 0 deletions tests_hw/groups/supervisor-webserverComplex/clean.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3
# @copyright Copyright (c) contributors to Project Ocre,
# which has been established as Project Ocre a Series of LF Projects, LLC
#
# SPDX-License-Identifier: Apache-2.0

import sys
sys.path.append("../..")

import testlib # noqa: E402
import pexpect # noqa: E402


def main():
serial_conn, pex = testlib.setup('/dev/ttyACM0')

print("Cleaning up container webserver-complex")
serial_conn.send_break()
expect_index = pex.expect(["ocre:~$", pexpect.TIMEOUT], 30)
runtime_output = bytes(pex.before).decode(errors='ignore')
if (expect_index == 1):
print("Zephyr runtime failed to come back up after a break")
testlib.full_exit(serial_conn, 1)

testlib.format_runtime_output(runtime_output, "Cleanup")
testlib.full_exit(serial_conn, 0)


if __name__ == "__main__":
main()
28 changes: 28 additions & 0 deletions tests_hw/groups/supervisor-webserverComplex/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "Supervisor Sample - Webserver Complex",
"description": "Test webserver complex container on the supervisor sample",
"setup": [
{
"name": "Create Webserver Complex Container",
"exec": "./setup.py"
}
],
"test_suites": [
{
"name": "Test Container Output and Connectivity",
"description": "Test webserver complex container features and networking",
"test_cases": [
{
"name": "Test the container's response to http requests",
"exec": "./testcase.py"
}
]
}
],
"cleanup": [
{
"name": "Remove Webserver Complex Container",
"exec": "./clean.py"
}
]
}
47 changes: 47 additions & 0 deletions tests_hw/groups/supervisor-webserverComplex/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3
# @copyright Copyright (c) contributors to Project Ocre,
# which has been established as Project Ocre a Series of LF Projects, LLC
#
# SPDX-License-Identifier: Apache-2.0

import sys
sys.path.append("../..")

import testlib # noqa: E402
import pexpect # noqa: E402


def main():
serial_conn, pex = testlib.setup('/dev/ttyACM0')

pex.write(b'net iface\n')
pex.expect(["ocre:~$", pexpect.TIMEOUT], 30)
runtime_output = bytes(pex.before).decode(errors='ignore')
if ("DHCP preferred" not in runtime_output): # Listed under IPv4 address if one exists
print("Board does not have an IP address, running DHCP client")
pex.write(b'net dhcpv4 client start 1\n')
while ("DHCP preferred" not in runtime_output):
print(".", end='')
pex.write(b'net iface\n')
pex.expect(["ocre:~$", pexpect.TIMEOUT], 5)
runtime_output = bytes(pex.before).decode(errors='ignore')
print('\nBoard obtained IP address')

print("Creating container on board off of webserver-complex.wasm")
pex.write(
b'ocre run -n webserver-complex -k networking -d webserver-complex.wasm\n')
pex.expect([pexpect.TIMEOUT, pexpect.EOF], 30)
runtime_output = bytes(pex.before).decode(errors='ignore')

if ("Failed to create container" in runtime_output) or ("Server Status: ONLINE" not in runtime_output):
print("Failed to create container")
testlib.format_runtime_output(runtime_output, "Failed")

testlib.full_exit(serial_conn, 1)

testlib.format_runtime_output(runtime_output, "Setup")
testlib.full_exit(serial_conn, 0)


if __name__ == "__main__":
main()
53 changes: 53 additions & 0 deletions tests_hw/groups/supervisor-webserverComplex/testcase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3
# @copyright Copyright (c) contributors to Project Ocre,
# which has been established as Project Ocre a Series of LF Projects, LLC
#
# SPDX-License-Identifier: Apache-2.0

import sys
sys.path.append("../..")

import requests # noqa: E402
import testlib # noqa: E402

"""
This testcase is to be used following the flashing of the supervisor sample to a board with the webserver-complex container put up.

The testcase forms a serial connection to the board, runs the hello-world container
and checks the string "powered by Ocre" appears in the output of the container.

This testcase makes multiple http GET requests to the webserver-complex server to make sure
the container is able to process http requests and send back valid responses
"""


def send_get_request(url: str) -> requests.Response:
print(f"Sending GET request to '{url}'")
http_response: requests.Response = requests.get(f'{url}')
if (http_response.status_code != 200):
print(f"Unable to reach container webserver, got status code {
http_response.status_code}")
sys.exit(1)

return http_response


def main():
http_response1: requests.Response = send_get_request(
f'{testlib.bu585_base_url}/api/counter')

send_get_request(f'{testlib.bu585_base_url}/increment')

http_response2: requests.Response = send_get_request(
f'{testlib.bu585_base_url}/api/counter')

if (http_response2.json().get('counter') < http_response1.json().get('counter')):
print(f"Remote server did not increment counter correctly, went from {
http_response1.json().get('counter')} to {http_response2.json().get('counter')}")
sys.exit(1)

sys.exit(0)


if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions tests_hw/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
from typing import Tuple

shell_prompt = "ocre:~$"
bu585_base_url = "http://ocre-b-u585i.lfedge.iol.unh.edu:8000"


def setup(device_filepath: str) -> Tuple[serial.Serial, pexpect.fdpexpect.fdspawn]:
conn = serial.Serial(device_filepath, 115200, timeout=10)
conn.reset_input_buffer()
conn.reset_output_buffer()
conn.flush()
pex = pexpect.fdpexpect.fdspawn(conn.fileno())

return (conn, pex)


def full_exit(conn: serial.Serial, status: int):
conn.reset_input_buffer()
conn.reset_output_buffer()
conn.flush()
conn.close()
sys.exit(status)

Expand Down
Loading