Skip to content

Commit 8adfbfe

Browse files
committed
ci: update AVR toolchain installation and add simulation steps for testing
1 parent 6f2f0a2 commit 8adfbfe

3 files changed

Lines changed: 80 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,30 @@ jobs:
275275
opt: [-O0, -O1, -O2, -O3, -Os]
276276
steps:
277277
- uses: actions/checkout@v6
278-
- name: install-avr-toolchain
279-
run: sudo apt-get update && sudo apt-get install -y gcc-avr avr-libc
280-
- name: compile-library-no-malloc
278+
279+
- name: install-avr-toolchain-and-simulator
280+
run: sudo apt-get update && sudo apt-get install -y gcc-avr avr-libc simavr
281+
282+
- name: compile-library-and-print-size
281283
run: |
284+
# Compile the isolated library object file to check standalone footprint
282285
avr-gcc -mmcu=atmega328p ${{ matrix.opt }} -Wall -Wextra -Werror \
283286
-Wshadow -Wconversion -Wsign-conversion -Wcast-align \
284-
-DESTACK_NO_MALLOC -DESTACK_NO_AUTO_ALIGN -DEASY_STACK_IMPLEMENTATION \
287+
-DESTACK_NO_MALLOC -DEASY_STACK_IMPLEMENTATION \
285288
-x c -c easy_stack.h -o easy_stack.o
286-
- name: verify-binary-size
287-
run: avr-size easy_stack.o
289+
290+
echo "=== Standalone Library Footprint ==="
291+
avr-size easy_stack.o
292+
293+
- name: compile-and-run-avr-simulation
294+
run: |
295+
# Compile the standalone AVR test for ATmega328P
296+
avr-gcc -mmcu=atmega328p ${{ matrix.opt }} -Wall -Wextra -Werror \
297+
-Wshadow -Wconversion -Wsign-conversion -Wcast-align \
298+
-I. tests/avr_test.c -o avr_test.elf
299+
300+
echo "=== Full Test Binary Footprint ==="
301+
avr-size avr_test.elf
302+
303+
# Run the test binary inside the simavr emulator
304+
simavr -m atmega328p avr_test.elf

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export UBSAN_OPTIONS=halt_on_error=0:exitcode=1:print_stacktrace=1
5353
export ASAN_OPTIONS=$(ASAN_OPTS)
5454

5555
TEST_DIR = tests
56-
TEST_SRCS = $(wildcard $(TEST_DIR)/*.c)
56+
# Collect all tests except the specialized AVR bare-metal simulation
57+
TEST_SRCS = $(filter-out $(TEST_DIR)/avr_test.c, $(wildcard $(TEST_DIR)/*.c))
5758
# Generate names for coverage object files
5859
TEST_COV_OBJS = $(TEST_SRCS:$(TEST_DIR)/%.c=$(TEST_DIR)/%.cov.o)
5960
# Generate names for coverage executables

tests/avr_test.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#define EASY_STACK_IMPLEMENTATION
2+
#define ESTACK_NO_MALLOC
3+
#include "easy_stack.h"
4+
#include <stdlib.h>
5+
6+
/*
7+
* Standalone assertion helper for bare-metal AVR environment.
8+
* If the condition fails, we trigger abort() which halts simavr with an error.
9+
*/
10+
static void avr_assert(bool condition) {
11+
if (!condition) {
12+
abort();
13+
}
14+
}
15+
16+
int main(void) {
17+
// 1. Initialize a small static buffer (128 bytes)
18+
uint8_t pool[128];
19+
EStack *stack = estack_create_static(pool, sizeof(pool));
20+
21+
avr_assert(stack != NULL);
22+
avr_assert(estack_get_meta_index(stack) == 0);
23+
avr_assert(estack_get_meta_type(stack) == 0); // Must use uint8_t offsets
24+
25+
// 2. Test basic allocation (default word alignment on AVR is 2 bytes)
26+
void *p1 = estack_alloc(stack, 10);
27+
avr_assert(p1 != NULL);
28+
avr_assert(estack_get_meta_index(stack) == 1);
29+
avr_assert(((uintptr_t)p1 % 2) == 0);
30+
31+
// 3. Test power-of-two alignment (requesting 4-byte boundary on 16-bit system)
32+
void *p2 = estack_alloc_aligned(stack, 15, 4);
33+
avr_assert(p2 != NULL);
34+
avr_assert(((uintptr_t)p2 % 4) == 0);
35+
36+
// 4. Test LIFO deallocation
37+
estack_free(stack, p2);
38+
estack_free(stack, p1);
39+
avr_assert(estack_get_meta_index(stack) == 0);
40+
41+
// 5. Test Stack Marker Rollbacks
42+
void *t1 = estack_alloc(stack, 8);
43+
EStackMarker marker = estack_get_marker(stack);
44+
45+
void *t2 = estack_alloc(stack, 16);
46+
avr_assert(estack_get_meta_index(stack) == 2);
47+
48+
estack_free_to_marker(stack, marker);
49+
avr_assert(estack_get_meta_index(stack) == 1);
50+
51+
estack_free(stack, t1);
52+
avr_assert(estack_get_meta_index(stack) == 0);
53+
54+
return 0; // Success
55+
}

0 commit comments

Comments
 (0)