-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#66307] Migrate to newer Renode, newer Python and bzlmod
- Loading branch information
1 parent
53c4881
commit bc49d06
Showing
26 changed files
with
541 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
bazel-* | ||
.bazelrc | ||
|
||
examples/*/*.log | ||
MODULE.bazel.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.