Skip to content

Commit

Permalink
Merge branch 'esl-epfl:main' into i2c_HAL
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanoAlbini96 authored Jun 14, 2024
2 parents be1084c + 8ed5eee commit 2ef2d92
Show file tree
Hide file tree
Showing 245 changed files with 16,076 additions and 4,353 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build-apps-job/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ echo ========================================
echo ========================================

# Create the virtual environment and install the requirements.
make venv
. .venv/bin/activate
conda init bash
source /root/.bashrc
conda activate core-v-mini-mcu

echo ========================================
echo ========================================
Expand All @@ -17,12 +18,12 @@ echo ========================================
echo ========================================

# The variable could also be obtained from the container.
export RISCV='/home/root/tools/riscv' &&\
export RISCV='/tools/riscv' &&\

# All peripherals are included to make sure all apps can be built.
sed 's/is_included: "no",/is_included: "yes",/' -i mcu_cfg.hjson
# The MCU is generated with various memory banks to avoid example code not fitting.
make mcu-gen MEMORY_BANKS=6
make mcu-gen X_HEEP_CFG=configs/ci.hjson

echo ========================================
echo ========================================
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/building.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
test_applications:
runs-on: ubuntu-latest
container:
image: ghcr.io/esl-epfl/xheep-compiler:latest
image: ghcr.io/esl-epfl/x-heep-toolchain:latest
name: Builds apps with gcc and clang. All must build successfully.
steps:
- name: Checkout the pushed code.
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# Copyright 2022 OpenHW Group
# Solderpad Hardware License, Version 2.1, see LICENSE.md for details.
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1

# Run all lint checks
name: lint
on: [push, pull_request]

env:
VERIBLE_VERSION: 0.0-1824-ga3b5bedf

jobs:

#####################
# Vendor Up-to-Date #
#####################
Expand All @@ -28,9 +24,9 @@ jobs:
- name: Re-vendor and diff
run: |
find . \
-name '*.vendor.hjson' \
| xargs -n1 util/vendor.py --verbose \
&& util/git-diff.py --error-msg "::error ::Found differences, please re-vendor."
-name '*.vendor.hjson' \
| xargs -n1 util/vendor.py --verbose \
&& util/git-diff.py --error-msg "::error ::Found differences, please re-vendor."
##################
# MCU Generator #
##################
Expand Down
188 changes: 188 additions & 0 deletions .github/workflows/sim-apps-job/test_apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
"""
This script compiles and runs all the apps in the sw/applications directory
"""

import os
import subprocess
import re


class BColors:
"""
Class to define colors in the terminal output.
"""
HEADER = "\033[95m"
OKBLUE = "\033[94m"
OKCYAN = "\033[96m"
OKGREEN = "\033[92m"
WARNING = "\033[93m"
FAIL = "\033[91m"
ENDC = "\033[0m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"


# Define parameters for the test_apps.py script
SIMULATOR = "verilator"
SIM_TIMEOUT_S = 120
LINKER = "on_chip"
COMPILER = "gcc"

# Blacklist of apps to skip
blacklist = [
"example_spi_read",
"example_spi_host_dma_power_gate",
"example_spi_write",
]

app_list = [app for app in os.listdir("sw/applications")]

print(BColors.OKCYAN + "Apps to test:" + BColors.ENDC)
for app in app_list:
if app not in blacklist:
print(BColors.OKCYAN + f" - {app}" + BColors.ENDC)

apps = {app: {"building": "", "simulation": ""} for app in app_list}


# Compile the {SIMULATOR} model and suppress the output
print(BColors.OKBLUE + f"Generating {SIMULATOR} model of X-HEEP..." + BColors.ENDC)
try:
simulation_build_output = subprocess.run(
["make", f"{SIMULATOR}-sim"], capture_output=True, check=False
)
except subprocess.CalledProcessError as exc:
print(BColors.FAIL + "=====================================" + BColors.ENDC)
print(BColors.FAIL + "Error building verilated model!" + BColors.ENDC)
print(BColors.FAIL + "=====================================" + BColors.ENDC)
print(str(exc.stderr.decode("utf-8")))
exit(1)
else:
print(
BColors.OKGREEN
+ f"Generated {SIMULATOR} model of X-HEEP successfully!"
+ BColors.ENDC
)

error_pattern = r"Program Finished with value (\d+)"

# Compile every app and run the simulator
for an_app in apps.keys():
if an_app not in blacklist:
apps[an_app] = {"building": "OK", "simulation": "OK"}
print(BColors.OKBLUE + f"Compiling {an_app}..." + BColors.ENDC)
try:
compile_output = subprocess.run(
[
"make",
"app",
f"PROJECT={an_app}",
f"COMPILER={COMPILER}",
f"LINKER={LINKER}",
],
capture_output=True,
check=True,
)
except subprocess.CalledProcessError as exc:
print(BColors.FAIL + f"Error compiling {an_app}!" + BColors.ENDC)
print(exc.stderr.decode("utf-8"))
apps[an_app] = {"building": "Failed", "simulation": "Skipped"}
else:
apps[an_app] = {"building": "OK", "simulation": "Skipped"}
print(BColors.OKGREEN + f"Compiled successfully {an_app}!" + BColors.ENDC)
print(
BColors.OKBLUE
+ f"Running {SIMULATOR} simulation of {an_app}..."
+ BColors.ENDC
)
try:
run_output = subprocess.run(
["./Vtestharness", "+firmware=../../../sw/build/main.hex"],
cwd="build/openhwgroup.org_systems_core-v-mini-mcu_0/sim-verilator",
capture_output=True,
timeout=SIM_TIMEOUT_S,
check=False,
)
except subprocess.TimeoutExpired:
print(
BColors.FAIL + f"Simulation of {an_app} timed out!" + BColors.ENDC
)
apps[an_app] = {"building": "OK", "simulation": "Timed out"}
else:
match = re.search(error_pattern, str(run_output.stdout.decode("utf-8")))
if (
"Error" in str(run_output.stdout.decode("utf-8"))
or match.group(1) != "0"
):
print(
BColors.FAIL
+ str(run_output.stdout.decode("utf-8"))
+ BColors.ENDC
)
uart_output = open(
"build/openhwgroup.org_systems_core-v-mini-mcu_0/sim-verilator/uart0.log",
"r",
encoding="utf-8",
)
print(BColors.FAIL + "UART output:" + BColors.ENDC)
print(BColors.FAIL + uart_output.read() + BColors.ENDC)
uart_output.close()
apps[an_app] = {"building": "OK", "simulation": "Failed"}
else:
apps[an_app] = {"building": "OK", "simulation": "OK"}
print(
BColors.OKGREEN + f"Ran {an_app} successfully!" + BColors.ENDC
)
print(BColors.OKBLUE + f"Finished running {an_app}." + BColors.ENDC)
else:
print(BColors.WARNING + f"Skipping {an_app}..." + BColors.ENDC)
apps[an_app] = {"building": "Skipped", "simulation": "Skipped"}

# Print the results
print(BColors.BOLD + "=================================" + BColors.ENDC)
print(BColors.BOLD + "Results:" + BColors.ENDC)
print(BColors.BOLD + "=================================" + BColors.ENDC)

# Filter the dictionary by values
ok_apps = [
app
for app, status in apps.items()
if (status["simulation"] == "OK" and status["building"] == "OK")
]
no_build_apps = [app for app, status in apps.items() if status["building"] == "Failed"]
no_sim_apps = [app for app, status in apps.items() if status["simulation"] == "Failed"]
skipped_apps = [
app
for app, status in apps.items()
if (status["simulation"] == "Skipped" or status["building"] == "Skipped")
]
timed_out_apps = [
app for app, status in apps.items() if status["simulation"] == "Timed out"
]

# Print the filtered results
print(
BColors.OKGREEN
+ f"{len(ok_apps)} out of {len(app_list)} apps compiled and ran successfully!"
+ BColors.ENDC
)
if len(no_build_apps) > 0:
print(BColors.FAIL + f"{len(no_build_apps)} apps failed to build!" + BColors.ENDC)
for failed_build_app in no_build_apps:
print(BColors.FAIL + f" - {failed_build_app}" + BColors.ENDC)
if len(no_sim_apps) > 0:
print(BColors.FAIL + f"{len(no_sim_apps)} apps failed to run!" + BColors.ENDC)
for failed_run_app in no_sim_apps:
print(BColors.FAIL + f" - {failed_run_app}" + BColors.ENDC)
if len(skipped_apps) > 0:
print(BColors.WARNING + f"{len(skipped_apps)} apps were skipped!" + BColors.ENDC)
for skipped_app in skipped_apps:
print(BColors.WARNING + f" - {skipped_app}" + BColors.ENDC)
if len(timed_out_apps) > 0:
print(BColors.FAIL + f"{len(timed_out_apps)} apps timed out!" + BColors.ENDC)
for timed_out_app in timed_out_apps:
print(BColors.FAIL + f" - {timed_out_app}" + BColors.ENDC)
print(BColors.BOLD + "=================================" + BColors.ENDC)

if len(no_build_apps) > 0 or len(no_sim_apps) > 0:
exit(1)
21 changes: 21 additions & 0 deletions .github/workflows/simulate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Simulate all apps
on: [pull_request]

jobs:
simulate:
runs-on: ubuntu-latest
container:
image: ghcr.io/esl-epfl/x-heep-toolchain:latest
name: Simulate all apps. All must pass.
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run all apps
run: |
conda init bash
source /root/.bashrc
conda activate core-v-mini-mcu
make clean-all
sed 's/is_included: "no",/is_included: "yes",/' -i mcu_cfg.hjson
make mcu-gen MEMORY_BANKS=6
python3 .github/workflows/sim-apps-job/test_apps.py
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ build/
*.dis
*.map
*.do
*.jou
*.str
.venv/
util/__pycache__/*
__pycache__/

# ignore apps output file
run_verif_rtl_log.txt
Expand All @@ -32,8 +34,11 @@ hw/system/pad_control/data/pad_control.hjson
hw/system/pad_control/rtl/pad_control.sv
hw/system/pad_control/rtl/pad_control_reg_pkg.sv
hw/system/pad_control/rtl/pad_control_reg_top.sv
hw/fpga/sram_wrapper.sv
hw/fpga/scripts/generate_sram.tcl

# same for the C header file and linker scripts
# same for the C header file and linker scripts and assembly files
sw/device/lib/crt/crt0.S
sw/device/lib/runtime/core_v_mini_mcu.h
sw/linker/link.ld
sw/linker/link_flash_exec.ld
Expand All @@ -46,6 +51,9 @@ sw/device/lib/drivers/**/*_structs.h
# openroad
flow/OpenROAD-flow-scripts

# automatically generated docs
/docs/source/Configuration/generated

# User-dependent configuration files
.vscode
private/
Loading

0 comments on commit 2ef2d92

Please sign in to comment.