Skip to content

Commit ff44ed0

Browse files
committed
update(single-baremetal): fix recipe and tests
Signed-off-by: Diogo Costa <[email protected]>
1 parent 5cc8a96 commit ff44ed0

File tree

3 files changed

+62
-32
lines changed

3 files changed

+62
-32
lines changed

tests/recipes/single-baremetal/default.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ let
3434

3535
#Build guests
3636
guests = [
37-
(callPackage (../../bao-nix/pkgs/guest/tf/baremetal.nix)
37+
(callPackage (../../bao-nix/pkgs/guest/baremetal/tf/guest.nix)
3838
{
3939
inherit setup-cfg;
4040
inherit toolchain;
4141
guest_name = "baremetal";
4242
list_tests = "";
43-
list_suites = "CPU_BOOT_CHECK IRQ_CHECK";
44-
inherit log_level;
43+
list_suites = "BOOT_CHECK IRQ_CHECK";
44+
inherit log_level;
4545
}
4646
)
4747
];
Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
1+
#include <cpu.h>
2+
#include <timer.h>
3+
#include <spinlock.h>
14
#include "testf.h"
25

3-
BAO_TEST(CPU_BOOT_CHECK,BOOT)
6+
#define NUM_CPUS 4
7+
#define CPU_BOOT_WAIT_TIME TIME_MS(1000)
8+
9+
volatile bool cpu_boot_status[NUM_CPUS] = {false};
10+
spinlock_t boot_status_lock = SPINLOCK_INITVAL;
11+
12+
BAO_TEST(BOOT_CHECK, VM_BOOT)
413
{
5-
TESTF_PASS("System booted successfully!\n");
14+
if(cpu_is_master()) {
15+
TESTF_PASS("System booted successfully!\n");
16+
}
617
}
718

19+
BAO_TEST(BOOT_CHECK, CPU_BOOT)
20+
{
21+
int cpu_id = get_cpuid();
22+
spin_lock(&boot_status_lock);
23+
cpu_boot_status[cpu_id] = true;
24+
spin_unlock(&boot_status_lock);
25+
26+
if(cpu_is_master()) {
27+
timer_wait(CPU_BOOT_WAIT_TIME);
28+
for(int i = 0; i < NUM_CPUS; i++) {
29+
if(!cpu_boot_status[i]) {
30+
TESTF_FAIL("CPUs did not boot successfully!\n");
31+
return;
32+
}
33+
}
34+
TESTF_PASS("All CPUs booted successfully!\n");
35+
}
36+
}

tests/recipes/single-baremetal/src/irq.c

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
#include "testf.h"
2-
// #include <plat.h>
3-
// #include <irq.h>
4-
// #include <timer.h>
5-
// #include <uart.h>
6-
// #include <core.h>
72
#include <core.h>
83
#include <stdlib.h>
94
#include <stdio.h>
@@ -24,34 +19,40 @@ volatile bool irq_en_timer = false;
2419
volatile bool irq_en_uart = false;
2520

2621
#define TIMER_INTERVAL (TIME_MS(100))
27-
#define TEST_TIME_WAIT (TIME_MS(100))
28-
#define TEST_TIMEOUT "200"
22+
#define TEST_TIME_WAIT (TIME_MS(200))
23+
#define TEST_TIMEOUT "300"
2924

30-
BAO_TEST(IRQ_CHECK1, TIMER)
25+
BAO_TEST(IRQ_CHECK, TIMER)
3126
{
32-
COMMAND_SEND_TIMEOUT(TEST_TIMEOUT);
33-
34-
irq_set_handler(TIMER_IRQ_ID, test_interrupt_timer_callback);
35-
timer_set(TIMER_INTERVAL);
36-
irq_enable(TIMER_IRQ_ID);
37-
irq_set_prio(TIMER_IRQ_ID, IRQ_MAX_PRIO);
38-
39-
while(!irq_en_timer);
40-
EXPECTED_TRUE(irq_en_timer);
27+
if(cpu_is_master()) {
28+
COMMAND_SET_TIMEOUT(TEST_TIMEOUT);
29+
30+
irq_set_handler(TIMER_IRQ_ID, test_interrupt_timer_callback);
31+
timer_set(TIMER_INTERVAL);
32+
irq_enable(TIMER_IRQ_ID);
33+
irq_set_prio(TIMER_IRQ_ID, IRQ_MAX_PRIO);
34+
35+
while(!irq_en_timer);
36+
EXPECTED_TRUE(irq_en_timer);
37+
COMMAND_CLEAR_TIMEOUT();
38+
}
4139
}
4240

4341
BAO_TEST(IRQ_CHECK, UART)
4442
{
45-
COMMAND_SEND_TIMEOUT(TEST_TIMEOUT);
46-
47-
irq_set_handler(33, uart_rx_handler);
48-
uart_enable_rxirq();
49-
irq_enable(33);
50-
irq_set_prio(33, IRQ_MAX_PRIO);
51-
COMMAND_SEND_CHAR("a");
52-
53-
timer_wait(TEST_TIME_WAIT);
54-
EXPECTED_TRUE(irq_en_uart);
43+
if(cpu_is_master()) {
44+
COMMAND_SET_TIMEOUT(TEST_TIMEOUT);
45+
46+
irq_set_handler(UART_IRQ_ID, uart_rx_handler);
47+
uart_enable_rxirq();
48+
irq_enable(UART_IRQ_ID);
49+
irq_set_prio(UART_IRQ_ID, IRQ_MAX_PRIO);
50+
COMMAND_SEND_CHAR("a");
51+
52+
timer_wait(TEST_TIME_WAIT);
53+
EXPECTED_TRUE(irq_en_uart);
54+
COMMAND_CLEAR_TIMEOUT();
55+
}
5556
}
5657

5758
void test_interrupt_timer_callback()

0 commit comments

Comments
 (0)