Skip to content
Open
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
1 change: 1 addition & 0 deletions .devcontainer/linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
sudo \
jq \
yamllint \
python3-autopep8 \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
apt-get update && apt-get install -y --no-install-recommends \
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/formatting-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
- name: Run YAML Format Checks
run: sh scripts/yml_linter.sh

- name: Run Python Format Checks
run: sh scripts/check_py_formatting.sh

- name: License Banner Checks(.c files)
run: sh scripts/check_license_banner_c.sh

Expand Down
13 changes: 5 additions & 8 deletions scripts/check_license_banner_conf_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

# Checks all C/C++ files for license banner
# Checks license banner in all files that use '#' comment syntax

set -e

Expand All @@ -17,13 +17,13 @@ check_license_banner() {
local file_header
local start_line=1

# Check first line and skip if it's a shebang line(only for .sh scripts)
# Skip shebang line if present (e.g. #!/bin/sh or #!/usr/bin/python3)
local first_line
first_line=$(head -n 1 "$file")
if [ "${first_line#\#\!/bin}" != "$first_line" ]; then
if [ "${first_line#\#\!/bin}" != "$first_line" ] || [ "${first_line#\#\!/usr/bin}" != "$first_line" ]; then
Copy link
Contributor

@casaroli casaroli Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [ "${first_line#\#\!/bin}" != "$first_line" ] || [ "${first_line#\#\!/usr/bin}" != "$first_line" ]; then
if [ "${first_line#\#\!/}"x != "${first_line}x" ]; then

start_line=2
fi

file_header=$(tail -n +$start_line "$file" | head -n 4)

# Expected license banner
Expand All @@ -44,14 +44,11 @@ echo "Checking license banners."
ERROR_FOUND=0
for file in $(find . -type f \( -name 'CMakeLists.txt' -o -name '*.yaml' \
-o -name '*.yml' -o -name '*.awk' -o -name '*.conf' -o -name 'Kconfig*' \
-o -name '.gitignore' -o -name '.gitmodules' -o -name '*.sh' -o -name '*.cmake' \) \
! -name 'utlist.h' \
-o -name '.gitignore' -o -name '.gitmodules' -o -name '*.sh' -o -name '*.cmake' -o -name '*.py' \) \
! -path './tests/Unity/*' \
! -path './build/*' \
! -path './wasm-micro-runtime/*' \
! -path './ocre-sdk/*' \
! -path './src/shell/sha256/*' \
! -path './src/runtime/wamr-wasip1/ocre_api/utils/*' \
| sort); do

if ! check_license_banner "$file"; then
Expand Down
36 changes: 36 additions & 0 deletions scripts/check_py_formatting.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
# @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

# Python formatter and linter
# Checks all .py files agains autopep8 rules
# Usage: check_py_formatting.sh [-f]
# -f Fix files in place(formatting)

set -e

ARGUMENT="--diff --exit-code"

if [ $# -eq 1 ]; then
if [ "$1" = "-f" ]; then
echo "Fixing files in place if necessary"
ARGUMENT="--in-place"
else
echo "Invalid option: $1"
exit 1
fi
fi

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$ROOT_DIR"

echo "Checking Python formatting."

find . -type f -name '*.py' \
! -path './tests/Unity/*' \
! -path './wasm-micro-runtime/*' \
! -path './ocre-sdk/*' \
-print0 | xargs -0 autopep8 ${ARGUMENT}
5 changes: 2 additions & 3 deletions scripts/yml_linter_rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
extends: default

rules:
line-length:
max: 150
level: warning
line-length: disable
indentation:
spaces: 2
document-start: disable
Expand All @@ -18,3 +16,4 @@ rules:
empty-lines:
max: 1
truthy: {check-keys: false}
comments-indentation: disable
13 changes: 9 additions & 4 deletions tests_hw/groups/demo/testcase.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/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 pexpect
import testlib
import pexpect # noqa: E402
import testlib # noqa: E402

"""
This testcase is to be used following the flashing of the default demo sample to a board.
Expand All @@ -24,6 +28,7 @@
"Demo completed successfully",
]


def main():
serial_conn, pex = testlib.setup('/dev/ttyACM0')
serial_conn.send_break()
Expand All @@ -43,6 +48,6 @@ def main():
testlib.format_runtime_output(runtime_output, "Entire")
testlib.full_exit(serial_conn, 0)


if __name__ == "__main__":
main()
main()
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/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 serial
import time
Expand All @@ -11,6 +15,7 @@
the string Hello World! appears in the output of that break command.
"""


def main():
conn = serial.Serial('/dev/ttyACM0', 115200, timeout=10)

Expand Down Expand Up @@ -43,4 +48,4 @@ def main():


if __name__ == "__main__":
main()
main()
14 changes: 10 additions & 4 deletions tests_hw/groups/mini/testcase.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#!/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 pexpect
import testlib
import pexpect # noqa: E402
import testlib # noqa: E402


"""
This testcase is to be used following the flashing of the default mini sample to a board.
Expand All @@ -17,6 +22,7 @@
"powered by Ocre",
]


def main():
serial_conn, pex = testlib.setup('/dev/ttyACM0')
serial_conn.send_break()
Expand All @@ -36,6 +42,6 @@ def main():
testlib.format_runtime_output(runtime_output, "Entire")
testlib.full_exit(serial_conn, 0)


if __name__ == "__main__":
main()
main()
11 changes: 8 additions & 3 deletions tests_hw/groups/supervisor-helloWorld/clean.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/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 pexpect
import testlib
import testlib # noqa: E402
import pexpect # noqa: E402


def main():
Expand All @@ -21,5 +25,6 @@ def main():
testlib.format_runtime_output(runtime_output, "Cleanup")
testlib.full_exit(serial_conn, 0)


if __name__ == "__main__":
main()
main()
17 changes: 11 additions & 6 deletions tests_hw/groups/supervisor-helloWorld/setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#!/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
import pexpect
import testlib # noqa: E402
import pexpect # noqa: E402


def main():
serial_conn, pex = testlib.setup('/dev/ttyACM0')
Expand All @@ -13,7 +18,7 @@ def main():
pex.write(b'ocre create -n hello-world -k ocre:api hello-world.wasm\n')
expect_index = pex.expect(["ocre:~$", pexpect.TIMEOUT], 30)
runtime_output = bytes(pex.before).decode(errors='ignore')

if (expect_index == 1):
print("Container failed to create container in given timeout")
testlib.format_runtime_output(runtime_output, "Failed")
Expand All @@ -23,9 +28,9 @@ def main():
print("Failed to create container")
testlib.format_runtime_output(runtime_output, "Failed")
testlib.full_exit(serial_conn, 1)

testlib.full_exit(serial_conn, 0)


if __name__ == "__main__":
main()
main()
14 changes: 10 additions & 4 deletions tests_hw/groups/supervisor-helloWorld/testcase.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/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 pexpect
import testlib
import pexpect # noqa: E402
import testlib # noqa: E402

"""
This testcase is to be used following the flashing of the supervisor sample to a board with the hello-world container put up.
Expand All @@ -15,6 +19,7 @@

line = "powered by Ocre"


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

Expand All @@ -36,6 +41,7 @@ def main():

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



if __name__ == "__main__":
main()
main()
10 changes: 8 additions & 2 deletions tests_hw/testlib.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# @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 serial
import sys
import pexpect
import pexpect.fdpexpect
from typing import Tuple

shell_prompt = "ocre:~$"
shell_prompt = "ocre:~$"


def setup(device_filepath: str) -> Tuple[serial.Serial, pexpect.fdpexpect.fdspawn]:
conn = serial.Serial(device_filepath, 115200, timeout=10)
Expand All @@ -29,4 +35,4 @@ def format_runtime_output(runtime_output: str, section: str) -> None:
{runtime_output}
==========--------------------------==========
""")
return
return