Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update(guest): fix baremetal nix recipes #3

Merged
merged 20 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c2cd86c
fix(naming): rename baremetal build recipe
Diogo21Costa Dec 15, 2023
32b657c
update(baremetal): include guest naming feature
Diogo21Costa Nov 28, 2023
d968944
fix(format): remove trailing whitespaces
Diogo21Costa Dec 15, 2023
5cf8d2e
feat(recipe): add recipe to build baremetal w/ local srcs
Diogo21Costa Dec 15, 2023
abdba73
fix(naming): rename nix recipe to build baremetal-tf w/ remote srcs
Diogo21Costa Dec 15, 2023
f7f7006
fix(pname): rename nix script project name of baremetal-tf remote build
Diogo21Costa Dec 15, 2023
a0f0af0
fix(build): allow to build remote baremetal w/ local tests
Diogo21Costa Dec 15, 2023
d315f19
fix(patch): remove static patch path
Diogo21Costa Dec 15, 2023
747dd25
fix(build): remove useless steps of baremetal-remote-tf
Diogo21Costa Dec 15, 2023
4ac747e
fix(install): enable output binary naming of baremetal-remote-tf
Diogo21Costa Dec 15, 2023
920a7ee
fix(inputs): remove useless inputs to baremetal-tf remote build
Diogo21Costa Dec 15, 2023
706e6af
fix(naming): rename nix recipe to build baremetal-tf w/ local srcs
Diogo21Costa Dec 15, 2023
3343050
fix(pname): rename nix script project name of baremetal-tf local build
Diogo21Costa Dec 15, 2023
f158013
fix(src): remove static path of local baremetal build
Diogo21Costa Dec 15, 2023
ddfafe2
fix(unpack): update unpack phase to use local sources
Diogo21Costa Dec 15, 2023
3250ab9
fix(build): remove useless steps of baremetal-local-tf
Diogo21Costa Dec 15, 2023
705809a
fix(install): enable output binary naming of baremetal-local-tf
Diogo21Costa Dec 15, 2023
65b2d37
fix(inputs): remove useless inputs to baremetal-tf local build
Diogo21Costa Dec 15, 2023
d792258
feat(PR): include support to test branch changes
Diogo21Costa Dec 15, 2023
b22a784
fix(unpack): fix unpackPhase on baremetal-remote-tf
miguelafsilva5 Jan 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions PR_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Test on exp/bao-tests (@ Bao Hypervisor repo)

Define the current directory as the root directory of the PR test:
```sh
export ROOT_DIR=$(realpath .)
```
Clone the `exp/bao-tests` branch of the Bao hypervisor repo:
```sh
export BAO_EXP_TESTS=$ROOT_DIR/exp-bao-tests
git clone -b exp/bao-tests https://github.com/bao-project/bao-hypervisor.git\
$BAO_EXP_TESTS
```
Init bao-nix git submodule:
```sh
cd $BAO_EXP_TESTS/tests
git submodule update --init
```

Checkout the submodule to the branch `update/guests-recipes`
```sh
git -C $BAO_EXP_TESTS/tests/bao-nix checkout update/guests-recipes
```

Build the test setup for `qemu-aarch64-virt` (tests compiled
[here](./exp-bao-tests/tests/src/HELLO.c)):
```sh
cd $ROOT_DIR
nix-build exp-bao-tests.nix --argstr platform qemu-aarch64-virt\
--argstr list_suites HELLO
```

Finally, run qemu to see the tests logging:
```sh
sh run_qemu.sh
```

To test the other guest recipes, change the [build recipe](exp-bao-tests.nix) as follows:

1. **baremetal-local.nix** - allows to test a baremetal build with local srcs:

Make the following changes in the build recipe:
```diff
- baremetal = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/guest/baremetal.nix
{
toolchain = aarch64-none-elf;
guest_name = "baremetal";
platform_cfg = plat_cfg;
};
+ baremetal = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/guest/baremetal_local.nix
{
toolchain = aarch64-none-elf;
guest_name = "baremetal";
platform_cfg = plat_cfg;
+ baremetal_srcs_path = ./bao-baremetal-guest;
};
```

Clone and patch the baremetal srcs from `bao-baremetal-guest` repo, clone the `bao-test` repo,
and copy the PR test files:
```sh
cd $ROOT_DIR
git clone -b demo https://github.com/bao-project/bao-baremetal-guest.git
```

Build the test setup:
```sh
nix-build exp-bao-tests.nix --argstr platform qemu-aarch64-virt\
--argstr list_suites HELLO
```

Finally, run qemu to see the tests logging:
```sh
sh run_qemu.sh
```

2. **baremetal-local-tf.nix** - allows to test a baremetal build with local srcs to run tests:

Make the following changes in the build recipe:
```diff
- baremetal = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/guest/baremetal.nix
{
toolchain = aarch64-none-elf;
guest_name = "baremetal";
platform_cfg = plat_cfg;
};
+ baremetal = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/guest/baremetal_local.nix
{
toolchain = aarch64-none-elf;
guest_name = "baremetal";
platform_cfg = plat_cfg;
+ inherit list_tests;
+ inherit list_suites;
baremetal_srcs_path = ./bao-baremetal-guest;
};
```

Clone and patch the baremetal srcs from `bao-baremetal-guest` repo, clone the `bao-test` repo,
and copy the PR test files:
```sh
cd $ROOT_DIR
git -C ./bao-baremetal-guest apply $ROOT_DIR/baremetal.patch

cd $ROOT_DIR/bao-baremetal-guest
mkdir tests
cp -r $ROOT_DIR/tests/* ./tests
cd ./tests
git clone https://github.com/bao-project/bao-tests.git
```

Then, copy the `testf_entry.c` file to the `bao-test` directory:
```sh
cp $ROOT_DIR/tests/testf_entry.c $ROOT_DIR/bao-baremetal-guest/tests/bao-tests/src
```

Build the test setup:
```sh
cd $ROOT_DIR
nix-build exp-bao-tests.nix --argstr platform qemu-aarch64-virt\
--argstr list_suites HELLO
```

Finally, run qemu to see the tests logging:
```sh
sh run_qemu.sh
```

3. **baremetal-remote-tf.nix** - allows to test a baremetal build with remote srcs to run tests:

Make the following changes in the build recipe:
```diff
- baremetal = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/guest/baremetal.nix
{
toolchain = aarch64-none-elf;
guest_name = "baremetal";
platform_cfg = plat_cfg;
};
+ baremetal = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/guest/baremetal_local.nix
{
toolchain = aarch64-none-elf;
guest_name = "baremetal";
platform_cfg = plat_cfg;
inherit list_tests;
inherit list_suites;
+ inherit bao-tests;
+ testf_patch = ./baremetal.patch;
- baremetal_srcs_path = ./bao-baremetal-guest;
};
```

Build the test setup:
```sh
cd $ROOT_DIR
nix-build exp-bao-tests.nix --argstr platform qemu-aarch64-virt\
--argstr list_suites HELLO
```

Finally, run qemu to see the tests logging:
```sh
sh run_qemu.sh
```
32 changes: 32 additions & 0 deletions PR_test/baremetal.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/setup.mk b/setup.mk
index 3a230aa..2edf9ee 100644
--- a/setup.mk
+++ b/setup.mk
@@ -29,6 +29,14 @@ src_dirs+=$(src_dir) $(core_dir) $(platform_dir)
SRC_DIRS+=$(src_dirs)
INC_DIRS+=$(addsuffix /inc, $(src_dirs))

+# Test framework setup
+include $(TESTF_REPO_DIR)/src/bao-test.mk
+SRC_DIRS+=$(TESTF_SRC_DIR) $(TESTF_TESTS_DIR)
+C_SRC+=$(TESTF_SRCS)
+INC_DIRS+=$(TESTF_INC_DIR)
+CFLAGS+=$(TESTF_FLAGS)
+# End of test framework setup
+
ifeq ($(wildcard $(platform_dir)),)
$(error unsupported platform $(PLATFORM))
endif
diff --git a/src/main.c b/src/main.c
index 9a9e972..69cfa6f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -54,6 +54,8 @@ void main(void){
printf("Bao bare-metal test guest\n");
spin_unlock(&print_lock);

+ testf_entry();
+
irq_set_handler(UART_IRQ_ID, uart_rx_handler);
irq_set_handler(TIMER_IRQ_ID, timer_handler);
irq_set_handler(IPI_IRQ_ID, ipi_handler);
91 changes: 91 additions & 0 deletions PR_test/exp-bao-tests.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
pkgs ? import (fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/refs/tags/22.11.tar.gz";
sha256 = "sha256:11w3wn2yjhaa5pv20gbfbirvjq6i3m7pqrq2msf0g7cv44vijwgw";
}) {},
platform ? " ",
list_tests ? " ",
list_suites ? " "
}:

with pkgs;

let
packages = rec {

plat_cfg = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/platforms/platforms.nix {
inherit platform;
};

aarch64-none-elf = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/toolchains/aarch64-none-elf-11-3.nix{};
demos = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/demos/demos.nix {};
bao-tests = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/bao-tests/bao-tests.nix {};
tests = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/tests/tests.nix {};

# Baremetal Remote
# baremetal = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/guest/baremetal-remote.nix
# {
# toolchain = aarch64-none-elf;
# guest_name = "baremetal";
# platform_cfg = plat_cfg;
# };

# Baremetal Local
# baremetal = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/guest/baremetal-local.nix
# {
# toolchain = aarch64-none-elf;
# guest_name = "baremetal";
# platform_cfg = plat_cfg;
# baremetal_srcs_path = ./bao-baremetal-guest; # /home/diogo/Desktop/bao-git/tests-workspace/bao-nix/PR_test/bao-baremetal-guest;
# };

# Baremetal Local TF
# baremetal = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/guest/baremetal-local-tf.nix
# {
# toolchain = aarch64-none-elf;
# guest_name = "baremetal";
# platform_cfg = plat_cfg;
# inherit list_tests;
# inherit list_suites;
# baremetal_srcs_path = ./bao-baremetal-guest;
# };

# Baremetal Remote TF
baremetal = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/guest/baremetal-remote-tf.nix
{
toolchain = aarch64-none-elf;
guest_name = "baremetal";
platform_cfg = plat_cfg;
inherit list_tests;
inherit list_suites;
inherit bao-tests;
tests_srcs = /home/diogo/Desktop/bao-git/tests-workspace/bao-nix/PR_test/tests;
testf_patch = ./baremetal.patch;
};

bao = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/bao/bao_tf.nix
{
toolchain = aarch64-none-elf;
guest = baremetal;
inherit demos;
platform_cfg = plat_cfg;
};

u-boot = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/u-boot/u-boot.nix
{
toolchain = aarch64-none-elf;
};

atf = callPackage ./exp-bao-tests/tests/bao-nix/pkgs/atf/atf.nix
{
toolchain = aarch64-none-elf;
inherit u-boot;
inherit platform;
};

inherit pkgs;
};
in
packages


10 changes: 10 additions & 0 deletions PR_test/run_qemu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env nix-shell
#!nix-shell --pure -p qemu -i bash

qemu-system-aarch64 -nographic\
-M virt,secure=on,virtualization=on,gic-version=3 \
-cpu cortex-a53 -smp 4 -m 4G\
-bios ./result-2/bin/qemu-aarch64-virt/flash.bin \
-device loader,file="./result-3/bin/bao.bin",addr=0x50000000,force-raw=on\
-device virtio-net-device,netdev=net0 -netdev user,id=net0,hostfwd=tcp:127.0.0.1:5555-:22\
-device virtio-serial-device -chardev pty,id=serial3 -device virtconsole,chardev=serial3
14 changes: 14 additions & 0 deletions PR_test/tests/configs/config.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/dts-v1/;
/ {
platform = "qemu-aarch64-virt";
log_echo = <1>;

test_config {
recipe_test {
nix_file = "default.nix";
suites = "HELLO";
tests = "";
log_level = "0";
};
};
};
12 changes: 12 additions & 0 deletions PR_test/tests/src/HELLO.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "testf.h"

BAO_TEST(HELLO, TEST_A)
{
printf("Test Framework, Hello World!!!\n");
}

BAO_TEST(HELLO, TEST_B)
{
printf(" Hello World 2!!!\n");
}

32 changes: 32 additions & 0 deletions PR_test/tests/src/testf_entry.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) Bao Project and Contributors. All rights reserved
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "testf.h"
#include <stdio.h>
#include <string.h>

unsigned int testframework_tests;
unsigned int testframework_fails;

void testf_entry(void)
{
// codegen.py section begin
#if defined TEST_A || HELLO
entry_test_HELLO_TEST_A();
#endif

#if defined TEST_B || HELLO
entry_test_HELLO_TEST_B();
#endif // codegen.py section end

if (testframework_tests > 0) {
LOG_TESTS();
} else {
INFO_TAG();
printf("No tests were executed!\n");
}
return;
}
32 changes: 32 additions & 0 deletions PR_test/tests/testf_entry.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) Bao Project and Contributors. All rights reserved
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "testf.h"
#include <stdio.h>
#include <string.h>

unsigned int testframework_tests;
unsigned int testframework_fails;

void testf_entry(void)
{
// codegen.py section begin
#if defined TEST_A || HELLO
entry_test_HELLO_TEST_A();
#endif

#if defined TEST_B || HELLO
entry_test_HELLO_TEST_B();
#endif // codegen.py section end

if (testframework_tests > 0) {
LOG_TESTS();
} else {
INFO_TAG();
printf("No tests were executed!\n");
}
return;
}
Loading
Loading