Skip to content

Commit

Permalink
[#66307] Migrate to newer Renode, newer Python and bzlmod
Browse files Browse the repository at this point in the history
  • Loading branch information
JanOlencki committed Oct 23, 2024
1 parent 53c4881 commit bc49d06
Show file tree
Hide file tree
Showing 26 changed files with 541 additions and 287 deletions.
43 changes: 43 additions & 0 deletions .ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
stages:
- test

.common_triggers: &common_triggers
only:
variables:
- $CI_COMMIT_REF_NAME == "main"
- $CI_PIPELINE_SOURCE == "merge_request"

.install_bazel: &install_bazel |-
apt -qq update
apt -qqy install apt-transport-https curl gnupg clang file zip
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-archive-keyring.gpg
mv bazel-archive-keyring.gpg /usr/share/keyrings
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list
apt -qq update
apt -qqy install bazel

test_examples:
image: debian:12-slim
stage: test
<<: *common_triggers
script:
- *install_bazel
- useradd -m non_root
- chmod a+w -R .
- pushd examples/cortex-r52
# rules_python doesn't support a hermetic toolchain run by root
- su non_root -c "bazel test //:all"
- popd
- pushd examples/failing-test
- su non_root -c "! bazel test //:all > test.log || exit 1"
- grep -E "//:success-test +PASSED" test.log
- grep -E "//:failing-test +FAILED" test.log
- popd
after_script:
- mkdir artifacts
- cp -LR examples/*/bazel-testlogs/* artifacts
artifacts:
when:
always
paths:
- artifacts
16 changes: 10 additions & 6 deletions .github/workflows/bazel_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Temporary workaround
run: mkdir -p ~/.config/renode

- name: Run example test
- name: Run example tests
run: |
bazel test //examples/nxp-k64f:nxp-k64f-test
pushd examples/cortex-r52
bazel test //:all
popd
pushd examples/failing-test
! bazel test //:all > test.log || exit 1
grep -E "//:success-test +PASSED" test.log
grep -E "//:failing-test +FAILED" test.log
popd
- name: Upload Bazel artifacts
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: renode-bazel-artifacts
path: bazel-testlogs*/**/*
path: examples/*/bazel-testlogs*/**/*
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
bazel-*
.bazelrc

examples/*/*.log
MODULE.bazel.lock
4 changes: 0 additions & 4 deletions BUILD

This file was deleted.

23 changes: 23 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module(
name = "rules_renode",
version = "0.1.0",
)

bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "rules_python", version = "0.36.0")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
python_version = "3.11",
)

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "renode_test_python_deps",
python_version = "3.11",
requirements_lock = "//renode:renode_requirements_lock.txt",
)
use_repo(pip, "renode_test_python_deps")

renode = use_extension("@rules_renode//renode:extensions.bzl", "renode")
use_repo(renode, renode_toolchains_default = "renode_toolchains")
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Bazel rules for Renode

Copyright (c) 2021 [Antmicro](https://www.antmicro.com/)
Copyright (c) 2021-2024 [Antmicro](https://www.antmicro.com/)

This repository contains rules for running Renode tests inside Bazel and provides use case examples.

In order to guarantee hermeticity of tests, the ``renode_test`` rule uses Renode portable and Python 3.8 (together with dependencies) as a hermetic toolchain.
In order to guarantee hermeticity of tests, the ``renode_test`` rule uses Renode portable and Python 3.11 (together with dependencies) as a hermetic toolchain.
The implication of this is that it's not necessary to install any of the aforementioned pieces of software on the host machine in order to run tests.

## Running an example

An example that tests an ELF binary with Zephyr OS compiled for the [NXP FRDM-K64F](https://www.nxp.com/design/development-boards/freedom-development-boards/mcu-boards/freedom-development-platform-for-kinetis-k64-k63-and-k24-mcus:FRDM-K64F) platform is provided in `examples/nxp-k64f`.
An example that tests an ELF binary with HiRTOS compiled for Cortex-R52 is provided in `examples/cortex-r52`.

In order to run this test, issue `bazel test //examples/nxp-k64f:nxp-k64f-test`.
In order to run this test, issue `bazel test //:cortex-r52-test` in the example directory.

After the test has completed (irrespectively of its status), you'll find the resulting artifacts (logs, report, etc) in the `bazel-testlogs/examples/nxp/nxp-k64f-test/test.outputs` directory in the `outputs.zip` file.
After the test has completed (irrespectively of its status), you'll find the resulting artifacts (logs, report, etc) in the `bazel-testlogs/examples/cortex-r52-test/test.outputs` directory in the `outputs.zip` file.
53 changes: 0 additions & 53 deletions WORKSPACE

This file was deleted.

16 changes: 16 additions & 0 deletions examples/cortex-r52/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@rules_renode//renode:defs.bzl", "renode_test")

renode_test(
name = "cortex-r52-test",
timeout = "short",
robot_test = "test.robot",
tags = [
"no-sandbox",
],
variables = {
"ELF": "$(location @cortex-r52-hirtos-hello//file)",
},
deps = [
"@cortex-r52-hirtos-hello//file",
],
)
23 changes: 23 additions & 0 deletions examples/cortex-r52/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module(
name = "renode_bazel_examples",
version = "0.0.0",
)

bazel_dep(name = "rules_renode", version = "0.0.0")
local_path_override(
module_name = "rules_renode",
path = "../..",
)

renode = use_extension("@rules_renode//renode:extensions.bzl", "renode")
use_repo(renode, "renode_toolchains")

register_toolchains("@renode_toolchains//:all")

http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")

http_file(
name = "cortex-r52-hirtos-hello",
sha256 = "73d6dea92d5bcff9c29b4e5c76aba5a691797cd68d458c243855055756f8093c",
url = "https://dl.antmicro.com/projects/renode/cortex-r52--hirtos-hello.elf-s_140356-d44a0b48e22a17fa8cb83ef08243ec23942812c0",
)
46 changes: 46 additions & 0 deletions examples/cortex-r52/test.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
*** Variables ***
${UART0} sysbus.uart0

*** Keywords ***
Create Machine
Execute Command mach create
Execute Command machine LoadPlatformDescription @platforms/cpus/cortex-r52.repl

Wait For Lines Per Thread
[Arguments] @{lines} ${testerId}
FOR ${thread} IN RANGE 1 8
${id}= Evaluate str(${thread}+1)
${prio}= Evaluate str(31-${thread})
${thread}= Evaluate str(${thread})
FOR ${line} IN @{lines}
${line}= Replace String ${line} %THREAD% ${thread}
${line}= Replace String ${line} %ID% ${id}
${line}= Replace String ${line} %PRIO% ${prio}
Wait For Line On Uart ${line} treatAsRegex=true testerId=${testerId}
END
END

Wait For Hello Sample
[Arguments] ${testerId} ${cpu}=0
Wait For Line On Uart HiRTOS running on CPU ${cpu} testerId=${testerId}

Wait For Line On Uart FVP ARMv8-R Hello running on CPU ${cpu} testerId=${testerId}
Wait For Line On Uart HiRTOS: Thread scheduler started testerId=${testerId}
Wait For Line On Uart HiRTOS: Timer thread started testerId=${testerId}

# First, check if all threads have been started
Wait For Lines Per Thread Thread %THREAD% \\(id %ID%, prio %PRIO%\\): .* Wakeups 1 testerId=${testerId}

Wait For Line On Uart HiRTOS: Idle thread started testerId=${testerId}

# Then, make sure each of them has been woken up at least once
Wait For Lines Per Thread Thread %THREAD% \\(id %ID%, prio %PRIO%\\): .* Wakeups [^1]\d* testerId=${testerId}


*** Test Cases ***
Should Run Hello Sample On One Core
Create Machine
${tester}= Create Terminal Tester ${UART0} defaultPauseEmulation=true
Execute Command sysbus LoadELF @${EXECDIR}/${ELF}

Wait For Hello Sample ${tester}
23 changes: 23 additions & 0 deletions examples/failing-test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@rules_renode//renode:defs.bzl", "renode_test")

renode_test(
name = "failing-test",
timeout = "short",
robot_test = "test.robot",
tags = [
"no-sandbox",
],
)

renode_test(
name = "success-test",
timeout = "short",
additional_arguments = [
"--exclude",
"failing_test_tag",
],
robot_test = "test.robot",
tags = [
"no-sandbox",
],
)
23 changes: 23 additions & 0 deletions examples/failing-test/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module(
name = "renode_bazel_examples",
version = "0.0.0",
)

bazel_dep(name = "rules_renode", version = "0.0.0")
local_path_override(
module_name = "rules_renode",
path = "../..",
)

renode = use_extension("@rules_renode//renode:extensions.bzl", "renode")
use_repo(renode, "renode_toolchains")

register_toolchains("@renode_toolchains//:all")

http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")

http_file(
name = "cortex-r52-hirtos-hello",
sha256 = "73d6dea92d5bcff9c29b4e5c76aba5a691797cd68d458c243855055756f8093c",
url = "https://dl.antmicro.com/projects/renode/cortex-r52--hirtos-hello.elf-s_140356-d44a0b48e22a17fa8cb83ef08243ec23942812c0",
)
8 changes: 8 additions & 0 deletions examples/failing-test/test.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*** Test Cases ***
Failing Test Case
[Tags] failing_test_tag
Execute Command mach create
Fail Fail for a testing purpose

Should Succeed
Execute Command mach create
9 changes: 0 additions & 9 deletions examples/nxp-k64f/BUILD

This file was deleted.

34 changes: 0 additions & 34 deletions examples/nxp-k64f/NXP-K64F.robot

This file was deleted.

24 changes: 0 additions & 24 deletions renode/BUILD

This file was deleted.

Loading

0 comments on commit bc49d06

Please sign in to comment.