Skip to content

Commit c5faa57

Browse files
Add QEMU-based CI tests for demos (#94)
Resolves #41
1 parent dc08a8a commit c5faa57

File tree

5 files changed

+219
-2
lines changed

5 files changed

+219
-2
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
secrets: inherit
4040

4141
demo_check_lpc4078:
42-
uses: libhal/ci/.github/workflows/demo_builder.yml@5.x.y
42+
uses: ./.github/workflows/demo_check.yml
4343
with:
4444
compiler_profile_url: https://github.com/libhal/arm-gnu-toolchain.git
4545
compiler_profile: v1/arm-gcc-12.3
@@ -48,7 +48,7 @@ jobs:
4848
secrets: inherit
4949

5050
demo_check_stm32f103c8:
51-
uses: libhal/ci/.github/workflows/demo_builder.yml@5.x.y
51+
uses: ./.github/workflows/demo_check.yml
5252
with:
5353
compiler_profile_url: https://github.com/libhal/arm-gnu-toolchain.git
5454
compiler_profile: v1/arm-gcc-12.3

.github/workflows/demo_check.yml

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
name: 👨🏻‍💻 QEMU
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
repo:
7+
type: string
8+
default: ${{ github.repository }}
9+
version:
10+
type: string
11+
default: ""
12+
conan_version:
13+
type: string
14+
default: ""
15+
compiler_profile_url:
16+
type: string
17+
required: true
18+
compiler_profile:
19+
type: string
20+
required: true
21+
compiler_profile_branch:
22+
type: string
23+
default: "main"
24+
platform_profile_url:
25+
type: string
26+
required: true
27+
platform_profile:
28+
type: string
29+
required: true
30+
platform_profile_branch:
31+
type: string
32+
default: "main"
33+
jobs:
34+
build_release: # b/c building the debug does not guarantee that normal build works
35+
uses: libhal/ci/.github/workflows/[email protected]
36+
with:
37+
compiler_profile_url: ${{ inputs.compiler_profile_url }}
38+
compiler_profile: ${{ inputs.compiler_profile }}
39+
platform_profile_url: ${{ inputs.platform_profile_url }}
40+
platform_profile: ${{ inputs.platform_profile }}
41+
secrets: inherit
42+
43+
build_debug: # STOLEN from libhal/ci
44+
runs-on: ubuntu-22.04
45+
steps:
46+
- uses: actions/[email protected]
47+
if: ${{ inputs.version != '' }}
48+
with:
49+
submodules: true
50+
repository: ${{ inputs.repo }}
51+
ref: ${{ inputs.version }}
52+
53+
- uses: actions/[email protected]
54+
if: ${{ inputs.version == '' }}
55+
with:
56+
submodules: true
57+
repository: ${{ inputs.repo }}
58+
59+
- name: 📥 Install Conan ${{ inputs.conan_version }}
60+
if: ${{ inputs.conan_version != '' }}
61+
run: pipx install conan==${{ inputs.conan_version }}
62+
63+
- name: 📥 Install Conan Latest
64+
if: ${{ inputs.conan_version == '' }}
65+
run: pipx install conan
66+
67+
- name: 📡 Add `libhal` repo to conan remotes
68+
run: conan remote add libhal
69+
https://libhal.jfrog.io/artifactory/api/conan/trunk-conan
70+
71+
- name: 📡 Create and setup default profile
72+
run: conan profile detect --force
73+
74+
- name: 👁️‍🗨️ Show conan profile
75+
run: conan profile show
76+
77+
- name: Install libhal settings_user.yml
78+
run: conan config install -sf profiles/baremetal/v2 https://github.com/libhal/conan-config.git
79+
80+
- name: Install compiler profiles
81+
run: conan config install -tf profiles -sf conan/profiles --args "-b ${{ inputs.compiler_profile_branch }} --single-branch" ${{ inputs.compiler_profile_url }}
82+
83+
- name: Install platform profiles
84+
run: conan config install -tf profiles -sf conan/profiles --args "-b ${{ inputs.platform_profile_branch }} --single-branch" ${{ inputs.platform_profile_url }}
85+
86+
- name: 🏗️ Build debug demos for ${{ inputs.platform_profile }}
87+
run: conan build demos -pr ${{ inputs.compiler_profile }} -pr ${{ inputs.platform_profile }} -s build_type=Debug
88+
89+
- name: Trim profile version
90+
id: trim
91+
run: |
92+
profile="${{ inputs.platform_profile }}"
93+
echo "trimmed=${profile##*/}" >> $GITHUB_OUTPUT
94+
95+
- name: 🚀 Upload build artifacts
96+
uses: actions/upload-artifact@v4
97+
with:
98+
name: build-${{ steps.trim.outputs.trimmed }}
99+
path: demos/build/
100+
101+
check_single_level:
102+
runs-on: ubuntu-24.04
103+
needs: build_debug
104+
steps:
105+
- name: Install Dependencies
106+
run: |
107+
sudo apt-get update
108+
sudo apt-get install qemu-system-arm gdb-multiarch
109+
110+
- name: Trim profile version
111+
id: trim
112+
run: |
113+
profile="${{ inputs.platform_profile }}"
114+
echo "trimmed=${profile##*/}" >> $GITHUB_OUTPUT
115+
116+
- name: Download Build Artifacts
117+
uses: actions/download-artifact@v4
118+
with:
119+
name: build-${{ steps.trim.outputs.trimmed }}
120+
121+
- name: Run Single Level Demo
122+
run: |
123+
nohup qemu-system-arm \
124+
-M olimex-stm32-h405 \
125+
-kernel ${{ github.workspace }}/${{ steps.trim.outputs.trimmed }}/Debug/single_level.elf \
126+
-S -s -nographic \
127+
&
128+
129+
timeout 5s gdb-multiarch --batch \
130+
-ex "set output-radix 16" \
131+
-ex "target remote :1234" \
132+
-ex "watch global" \
133+
-ex "continue" \
134+
-ex "monitor quit" \
135+
${{ github.workspace }}/${{ steps.trim.outputs.trimmed }}/Debug/single_level.elf \
136+
> gdb.log || {
137+
# Make timeouts more explicit
138+
code=$?
139+
if [ "$code" -eq 124 ]; then
140+
echo "❌ GDB timeout after 5 seconds" >&2
141+
else
142+
echo "❌ GDB failed with code $code" >&2
143+
fi
144+
exit $code
145+
}
146+
147+
- name: Check Single Level Result
148+
run: |
149+
cat gdb.log
150+
grep -q "New value = 0x5" gdb.log
151+
152+
check_multiple_inheritance:
153+
runs-on: ubuntu-24.04
154+
needs: build_debug
155+
steps:
156+
- name: Install Dependencies
157+
run: |
158+
sudo apt-get update
159+
sudo apt-get install qemu-system-arm gdb-multiarch
160+
161+
- name: Trim profile version
162+
id: trim
163+
run: |
164+
profile="${{ inputs.platform_profile }}"
165+
echo "trimmed=${profile##*/}" >> $GITHUB_OUTPUT
166+
167+
- name: Download Build Artifacts
168+
uses: actions/download-artifact@v4
169+
with:
170+
name: build-${{ steps.trim.outputs.trimmed }}
171+
172+
- name: Run Multiple Inheritance Demo
173+
run: |
174+
nohup qemu-system-arm \
175+
-M olimex-stm32-h405 \
176+
-kernel ${{ github.workspace }}/${{ steps.trim.outputs.trimmed }}/Debug/multiple_inheritance.elf \
177+
-S -s -nographic \
178+
&
179+
180+
timeout 5s gdb-multiarch --batch \
181+
-ex "set output-radix 16" \
182+
-ex "target remote :1234" \
183+
-ex "watch global" \
184+
-ex "continue" \
185+
-ex "monitor quit" \
186+
${{ github.workspace }}/${{ steps.trim.outputs.trimmed }}/Debug/multiple_inheritance.elf \
187+
> gdb.log || {
188+
# Make timeouts more explicit
189+
code=$?
190+
if [ "$code" -eq 124 ]; then
191+
echo "❌ GDB timeout after 5 seconds" >&2
192+
else
193+
echo "❌ GDB failed with code $code" >&2
194+
fi
195+
exit $code
196+
}
197+
198+
- name: Check Multiple Inheritance Result
199+
run: |
200+
cat gdb.log
201+
grep -q "New value = 0x6666" gdb.log
202+

demos/conanfile.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
from conan import ConanFile
16+
from conan.tools.cmake import CMakeToolchain, CMakeDeps
1617

1718

1819
class demos(ConanFile):
@@ -23,3 +24,12 @@ def requirements(self):
2324
bootstrap = self.python_requires["libhal-bootstrap"]
2425
bootstrap.module.add_demo_requirements(self)
2526
self.requires("libhal-exceptions/1.2.0")
27+
28+
# To eliminate clocks for ci
29+
def generate(self):
30+
tc = CMakeToolchain(self)
31+
tc.preprocessor_definitions.debug["DEBUG"] = "1"
32+
tc.generate()
33+
34+
deps = CMakeDeps(self)
35+
deps.generate()

demos/platforms/lpc4078.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ void initialize_platform()
2525
using namespace hal::literals;
2626

2727
// Set the MCU to the maximum clock speed
28+
#ifndef DEBUG
2829
hal::lpc40::maximum(12.0_MHz);
30+
#endif
2931

3032
static hal::cortex_m::dwt_counter dwt_steady_clock(
3133
hal::lpc40::get_frequency(hal::lpc40::peripheral::cpu));

demos/platforms/stm32f103c8.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ hal::cortex_m::dwt_counter* counter;
2323
void initialize_platform()
2424
{
2525
using namespace hal::literals;
26+
27+
#ifndef DEBUG
2628
hal::stm32f1::maximum_speed_using_internal_oscillator();
29+
#endif
2730

2831
static hal::cortex_m::dwt_counter dwt_steady_clock(
2932
hal::stm32f1::frequency(hal::stm32f1::peripheral::cpu));

0 commit comments

Comments
 (0)