Skip to content

Commit

Permalink
Add LLVM LIT/FileCheck tests for Core files
Browse files Browse the repository at this point in the history
  • Loading branch information
JonatanAntoni authored Oct 24, 2023
1 parent c5806c4 commit 5d06d1d
Show file tree
Hide file tree
Showing 53 changed files with 2,526 additions and 1 deletion.
37 changes: 37 additions & 0 deletions .devcontainer/ubuntu-22.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM --platform=linux/amd64 ubuntu:22.04

SHELL ["/bin/bash", "-c"]

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get -y install \
build-essential \
curl \
gdb \
less \
python3 \
python3-pip \
python-is-python3 \
git \
libtinfo5 \
llvm-15-tools \
unzip && \
ln -s /usr/bin/FileCheck-15 /usr/bin/FileCheck

RUN pip install \
lit \
python-matrix-runner

RUN bash -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)" && \
sed -i 's/OSH_THEME="font"/OSH_THEME="powerline"/' ~/.bashrc

ADD vcpkg-configuration.json /root/

RUN pushd /root && \
. <(curl https://aka.ms/vcpkg-init.sh -L) && \
echo "\n# Initialize vcpkg\n. /root/.vcpkg/vcpkg-init" >> .bashrc && \
vcpkg x-update-registry --all && \
vcpkg activate

CMD ["/bin/bash"]
13 changes: 13 additions & 0 deletions .devcontainer/ubuntu-22.04/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Ubuntu-22.04",
"build": { "dockerfile": "Dockerfile" },

"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack"
]
}
}
}
23 changes: 23 additions & 0 deletions .devcontainer/ubuntu-22.04/vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"registries": [
{
"kind": "artifact",
"location": "https://aka.ms/vcpkg-ce-default",
"name": "microsoft"
},
{
"kind": "artifact",
"location": "https://artifacts.keil.arm.com/vcpkg-ce-registry/registry.zip",
"name": "arm"
}
],
"requires": {
"microsoft:ninja": "^1.10.2",
"arm:compilers/arm/armclang":"^6.20.0",
"arm:compilers/arm/arm-none-eabi-gcc": "^12.2.1-0",
"arm:compilers/arm/llvm-embedded": "^17.0.1-0",
"arm:tools/open-cmsis-pack/cmsis-toolbox": "^2.1.0-0",
"arm:models/arm/avh": "^11.21.15"
}
}

91 changes: 91 additions & 0 deletions .github/workflows/core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Core Checks
on:
workflow_dispatch:
pull_request:
push:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lit:
runs-on: ubuntu-latest

env:
ARM_UBL_ACTIVATION_CODE: ${{ secrets.ARM_UBL_ACTIVATION_CODE }}

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'

- name: Python requirements
run: |
pip install -r ./CMSIS/Core/Test/requirements.txt
- name: Cache vcpkg
uses: actions/cache@v3
with:
key: vcpkg-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}-${{ matrix.compiler }}
restore-keys: |
vcpkg-${{ runner.os }}-${{ runner.arch }}-
path: /home/runner/.vcpkg

- name: Install LLVM dependencies and tools
working-directory: /home/runner
run: |
sudo apt-get update
sudo apt-get install libtinfo5 llvm-15-tools
sudo ln -s /usr/bin/FileCheck-15 /usr/bin/FileCheck
- name: Prepare vcpkg env
working-directory: ./CMSIS/Core/Test
run: |
. <(curl https://aka.ms/vcpkg-init.sh -L)
vcpkg x-update-registry --all
vcpkg activate
- name: Activate Arm tool license
working-directory: ./CMSIS/Core/Test
run: |
. /home/runner/.vcpkg/vcpkg-init
vcpkg activate
if [[ -n "${{ env.ARM_UBL_ACTIVATION_CODE }}" ]]; then
armlm activate --code ${{ env.ARM_UBL_ACTIVATION_CODE }}
else
armlm activate --server https://mdk-preview.keil.arm.com --product KEMDK-COM0
fi
- uses: ammaraskar/gcc-problem-matcher@master

- name: Run LIT
working-directory: ./CMSIS/Core/Test
run: |
. /home/runner/.vcpkg/vcpkg-init
vcpkg activate
./build.py lit
- name: Deactivate Arm tool license
if: always()
working-directory: ./CMSIS/Core/Test
run: |
. /home/runner/.vcpkg/vcpkg-init
vcpkg activate
if [[ -n "${{ env.ARM_UBL_ACTIVATION_CODE }}" ]]; then
armlm deactivate --code ${{ env.ARM_UBL_ACTIVATION_CODE }}
else
armlm deactivate --product KEMDK-COM0
fi
- name: Publish Test Results
if: ${{ !cancelled() && env.ARM_UBL_ACTIVATION_CODE }}
uses: EnricoMi/publish-unit-test-result-action@v2
with:
report_individual_runs: true
files: ./CMSIS/Core/Test/*.xunit
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
**/__pycache__
CMSIS/Documentation/
CMSIS/DoxyGen/**/*.dxy
CMSIS/Core/Test/*.o
CMSIS/Core/Test/*.xunit
CMSIS/Core/Test/.lit_test_times.txt
CMSIS/CoreValidation/Project/*.zip
CMSIS/CoreValidation/Project/*.junit
CMSIS/CoreValidation/Project/*.clangd
CMSIS/CoreValidation/Project/Validation.*/
CMSIS/CoreValidation/Project/Bootloader.*/
CMSIS/CoreValidation/Project/build
CMSIS/CoreValidation/Project/RTE/_**/*
*.cbuild-idx.yml
*.uvguix.*
*.uvmpw.uvgui.*
*.zip
*.bak
build
output
linkchecker-out.csv
.DS_STORE
.DS_STORE
*.tmp
11 changes: 11 additions & 0 deletions CMSIS/Core/Test/apsr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// REQUIRES: thumbv6m
// RUN: %cc% %ccflags% %ccout% %s.o %s; llvm-objdump --mcpu=%mcpu% -d %s.o | FileCheck --allow-unused-prefixes --check-prefixes %prefixes% %s

#include "cmsis_compiler.h"

void get_apsr() {
// CHECK-LABEL: <get_apsr>:
// CHECK: mrs {{r[0-9]+}}, apsr
volatile uint32_t result = __get_APSR();
// CHECK: {{(bx lr)|(pop {.*pc})}}
}
43 changes: 43 additions & 0 deletions CMSIS/Core/Test/basepri.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// REQUIRES: thumb-2, thumbv7m
// RUN: %cc% %ccflags% %ccout% %s.o %s; llvm-objdump --mcpu=%mcpu% -d %s.o | FileCheck --allow-unused-prefixes --check-prefixes %prefixes% %s

#include "cmsis_compiler.h"

void get_basepri() {
// CHECK-LABEL: <get_basepri>:
// CHECK: mrs {{r[0-9]+}}, basepri
volatile uint32_t result = __get_BASEPRI();
// CHECK: {{(bx lr)|(pop {.*pc})}}
}

void get_basepri_ns() {
// CHECK-LABEL: <get_basepri_ns>:
#if __ARM_FEATURE_CMSE == 3
// CHECK-S: mrs {{r[0-9]+}}, basepri_ns
volatile uint32_t result = __TZ_get_BASEPRI_NS();
#endif
// CHECK: {{(bx lr)|(pop {.*pc})}}
}

void set_basepri() {
// CHECK-LABEL: <set_basepri>:
// CHECK: msr basepri, {{r[0-9]+}}
__set_BASEPRI(0x0815u);
// CHECK: {{(bx lr)|(pop {.*pc})}}
}

void set_basepri_ns() {
// CHECK-LABEL: <set_basepri_ns>:
#if __ARM_FEATURE_CMSE == 3
// CHECK-S: msr basepri_ns, {{r[0-9]+}}
__TZ_set_BASEPRI_NS(0x0815u);
#endif
// CHECK: {{(bx lr)|(pop {.*pc})}}
}

void set_basepri_max() {
// CHECK-LABEL: <set_basepri_max>:
// CHECK: msr basepri_max, {{r[0-9]+}}
__set_BASEPRI_MAX(0x0815u);
// CHECK: {{(bx lr)|(pop {.*pc})}}
}
10 changes: 10 additions & 0 deletions CMSIS/Core/Test/bkpt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %cc% %ccflags% %ccout% %s.o %s; llvm-objdump --mcpu=%mcpu% -d %s.o | FileCheck --allow-unused-prefixes --check-prefixes %prefixes% %s

#include "cmsis_compiler.h"

void bkpt() {
// CHECK-LABEL: <bkpt>:
// CHECK: bkpt {{#0x15|#21}}
__BKPT(0x15);
// CHECK: {{(bx lr)|(pop {.*pc})}}
}
88 changes: 88 additions & 0 deletions CMSIS/Core/Test/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import logging

from datetime import datetime
from enum import Enum

from matrix_runner import main, matrix_axis, matrix_action, matrix_command, matrix_filter, \
FileReport, JUnitReport


@matrix_axis("device", "d", "Device(s) to be considered.")
class DeviceAxis(Enum):
CM0 = ('Cortex-M0', 'CM0')
CM0plus = ('Cortex-M0plus', 'CM0plus')
CM3 = ('Cortex-M3', 'CM3')
CM4 = ('Cortex-M4', 'CM4')
CM4FP = ('Cortex-M4FP', 'CM4FP')
CM7 = ('Cortex-M7', 'CM7')
CM7SP = ('Cortex-M7SP', 'CM7SP')
CM7DP = ('Cortex-M7DP', 'CM7DP')
CM23 = ('Cortex-M23', 'CM23')
CM23S = ('Cortex-M23S', 'CM23S')
CM23NS = ('Cortex-M23NS', 'CM23NS')
CM33 = ('Cortex-M33', 'CM33')
CM33S = ('Cortex-M33S', 'CM33S')
CM33NS = ('Cortex-M33NS', 'CM33NS')
CM35P = ('Cortex-M35P', 'CM35P')
CM35PS = ('Cortex-M35PS', 'CM35PS')
CM35PNS = ('Cortex-M35PNS', 'CM35PNS')
CM55 = ('Cortex-M55', 'CM55')
CM55S = ('Cortex-M55S', 'CM55S')
CM55NS = ('Cortex-M55NS', 'CM55NS')
CM85 = ('Cortex-M85', 'CM85')
CM85S = ('Cortex-M85S', 'CM85S')
CM85NS = ('Cortex-M85NS', 'CM85NS')
CA5 = ('Cortex-A5', 'CA5')
CA7 = ('Cortex-A7', 'CA7')
CA9 = ('Cortex-A9', 'CA9')
CA5NEON = ('Cortex-A5neon', 'CA5neon')
CA7NEON = ('Cortex-A7neon', 'CA7neon')
CA9NEON = ('Cortex-A9neon', 'CA9neon')


@matrix_axis("compiler", "c", "Compiler(s) to be considered.")
class CompilerAxis(Enum):
AC6 = ('AC6')
GCC = ('GCC')
IAR = ('IAR')
CLANG = ('Clang')

@matrix_axis("optimize", "o", "Optimization level(s) to be considered.")
class OptimizationAxis(Enum):
NONE = ('none')
BALANCED = ('balanced')
SPEED = ('speed')
SIZE = ('size')


@matrix_action
def lit(config):
"""Run tests for the selected configurations using llvm's lit."""
yield run_lit(config.compiler[0], config.device[1], config.optimize[0])


def timestamp():
return datetime.now().strftime('%Y%m%d%H%M%S')

@matrix_command()
def run_lit(toolchain, device, optimize):
return ["lit", "--xunit-xml-output", f"lit-{toolchain}-{optimize}-{device}.xunit", "-D", f"toolchain={toolchain}", "-D", f"device={device}", "-D", f"optimize={optimize}", "." ]

@matrix_filter
def filter_iar(config):
return config.compiler == CompilerAxis.IAR

@matrix_filter
def filter_gcc_cm85(config):
return config.compiler == CompilerAxis.GCC and config.device.match('CM85*')

#@matrix_filter
#def filter_clang_cortex_a(config):
# return config.compiler == CompilerAxis.CLANG and config.device.match('CA*')


if __name__ == "__main__":
main()
12 changes: 12 additions & 0 deletions CMSIS/Core/Test/clrex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// REQUIRES: ldrex
// RUN: %cc% %ccflags% %ccout% %s.o %s; llvm-objdump --mcpu=%mcpu% -d %s.o | FileCheck --allow-unused-prefixes --check-prefixes %prefixes% %s

#include "cmsis_compiler.h"

void clrex() {
// CHECK-LABEL: <clrex>:
// CHECK: clrex
__CLREX();
// CHECK: {{(bx lr)|(pop {.*pc})}}
}

14 changes: 14 additions & 0 deletions CMSIS/Core/Test/clz.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// REQUIRES: clz
// RUN: %cc% %ccflags% %ccout% %s.o %s; llvm-objdump --mcpu=%mcpu% -d %s.o | FileCheck --allow-unused-prefixes --check-prefixes %prefixes% %s

#include "cmsis_compiler.h"

static volatile uint32_t a = 10u;

void clz() {
// CHECK-LABEL: <clz>:
// CHECK: clz {{r[0-9]+}}, {{r[0-9]+}}
volatile uint32_t c = __CLZ(a);
// CHECK: {{(bx lr)|(pop {.*pc})}}
}

Loading

0 comments on commit 5d06d1d

Please sign in to comment.