Skip to content

Commit

Permalink
corrected tests
Browse files Browse the repository at this point in the history
  • Loading branch information
soumeh01 committed Apr 18, 2024
1 parent f327162 commit 64e3992
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/robot-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
runs-on: ubuntu-latest
# env:
# CMSIS_PACK_ROOT: /home/runner/.cache/arm/packs
continue-on-error: true
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -56,7 +55,6 @@ jobs:
- name: Run Test
working-directory: ./test
continue-on-error: true
run: |
. /home/runner/.vcpkg/vcpkg-init
vcpkg activate
Expand All @@ -72,6 +70,7 @@ jobs:

report:
runs-on: ubuntu-latest
if: always()
needs: test
permissions: write-all
steps:
Expand Down
74 changes: 74 additions & 0 deletions test/data/trustzone/nonsecurecode/main_ns.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "interface.h" // Interface API
#include "cmsis_os2.h" // ARM::CMSIS:RTOS2:Keil RTX5

static osStatus_t Status;

static osThreadId_t ThreadAdd_Id;
static osThreadId_t ThreadMul_Id;

static const osThreadAttr_t ThreadAttr = {
.tz_module = 1U,
};

void AddThread (void *argument);
void MulThread (void *argument);

extern volatile int valueA;
extern volatile int valueB;

volatile int valueA;
volatile int valueB;


static int Addition (int val1, int val2) {
return (val1 + val2);
}

__attribute__((noreturn))
void AddThread (void *argument) {
(void)argument;

for (;;) {
valueA = function_1 (valueA);
valueA = function_2 (Addition, valueA, 2);
osDelay(2U);
}
}

static int Multiply (int val1, int val2) {
uint32_t flags;

flags = osThreadFlagsWait (1U, osFlagsWaitAny, osWaitForever);
if (flags == 1U) {
return (val1*val2);
}
else {
return (0);
}
}


__attribute__((noreturn))
void MulThread (void *argument) {
(void)argument;

for (;;) {
valueB = function_1 (valueB);
valueB = function_2 (Multiply, valueB, 2);
}
}


int main (void) {
Status = osKernelInitialize();

ThreadAdd_Id = osThreadNew(AddThread, NULL, &ThreadAttr);
ThreadMul_Id = osThreadNew(MulThread, NULL, &ThreadAttr);

Status = osKernelStart();

for(;;);
}



18 changes: 18 additions & 0 deletions test/data/trustzone/nonsecurecode/nonsecure.cproject.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/cproject.schema.json

project:
misc:
- for-compiler: AC6
C: [-fshort-enums, -fshort-wchar]
add-path:
- $OutDir(Secure)$
components:
- component: C Startup
- component: CMSIS CORE
- component: Keil RTX5 Library_NS
groups:
- group: Non-secure Code
files:
- file: main_ns.c
- file: $Source(Secure)$/interface.h
- file: $Output(Secure)$_CMSE_Lib.o
24 changes: 24 additions & 0 deletions test/data/trustzone/securecode/interface.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <arm_cmse.h>

#include "interface.h"

/* typedef for non-secure callback functions */
typedef funcptr funcptr_NS __attribute__((cmse_nonsecure_call));

/* Non-secure callable (entry) function */
int function_1(int x) __attribute__((cmse_nonsecure_entry)) {
return x+5;
}

/* Non-secure callable (entry) function, calling a non-secure callback function */
int function_2(funcptr callback, int x, int y) __attribute__((cmse_nonsecure_entry)) {
funcptr_NS callback_NS; // non-secure callback function pointer
int res;

/* return function pointer with cleared LSB */
callback_NS = (funcptr_NS)cmse_nsfptr_create(callback);
res = callback_NS (x, y);

return (res*10);
}

6 changes: 6 additions & 0 deletions test/data/trustzone/securecode/interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// function pointer
typedef int(*funcptr)(int,int);

/* Non-secure callable functions */
extern int function_1(int x);
extern int function_2(funcptr callback, int x, int y);
24 changes: 24 additions & 0 deletions test/data/trustzone/securecode/main_s.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Use CMSE intrinsics */
#include <arm_cmse.h>

#include "RTE_Components.h"
#include CMSIS_device_header

#ifndef START_NS
#define START_NS (0x200000U)
#endif

typedef void (*funcptr) (void) __attribute__((cmse_nonsecure_call));

int main(void) {
funcptr ResetHandler;

__TZ_set_MSP_NS(*((uint32_t *)(START_NS)));
ResetHandler = (funcptr)(*((uint32_t *)((START_NS) + 4U)));
ResetHandler();

while (1) {
__NOP();
}
}

17 changes: 17 additions & 0 deletions test/data/trustzone/securecode/secure.cproject.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/cproject.schema.json

project:
processor:
trustzone: secure
components:
- component: C Startup
- component: CMSIS CORE
groups:
- group: Secure Code
files:
- file: main_s.c
- group: CMSE
files:
- file: interface.c
- file: interface.h
- file: tz_context.c
34 changes: 34 additions & 0 deletions test/data/trustzone/securecode/tz_context.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "RTE_Components.h"
#include CMSIS_device_header
#include "tz_context.h"

__attribute__((cmse_nonsecure_entry))
uint32_t TZ_InitContextSystem_S(void) {
return 1U;
}

__attribute__((cmse_nonsecure_entry))
TZ_MemoryId_t TZ_AllocModuleContext_S(TZ_ModuleId_t module) {
(void)module;
return 1U;
}

__attribute__((cmse_nonsecure_entry))
uint32_t TZ_FreeModuleContext_S(TZ_MemoryId_t id) {
(void)id;
return 1U;
}


__attribute__((cmse_nonsecure_entry))
uint32_t TZ_LoadContext_S(TZ_MemoryId_t id) {
(void)id;
return 2U;
}

__attribute__((cmse_nonsecure_entry))
uint32_t TZ_StoreContext_S(TZ_MemoryId_t id) {
(void)id;
return 2U;
}

27 changes: 27 additions & 0 deletions test/data/trustzone/solution.csolution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json

solution:
target-types:
- type: CM33
device: ARMCM33_DSP_FP_TZ
- type: CM35P
device: ARMCM35P_DSP_FP_TZ

build-types:
- type: Debug
compiler: AC6
misc:
- for-compiler: AC6
C:
- -O1
- -g
- type: Release
compiler: AC6
misc:
- for-compiler: AC6
C:
- -O3

projects:
- project: ./securecode/secure.cproject.yml
- project: ./nonsecurecode/nonsecure.cproject.yml
6 changes: 6 additions & 0 deletions test/data/whitespace/project/ma in.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "RTE_Components.h"
#include CMSIS_device_header

int main(void) {
return 0;
}
14 changes: 14 additions & 0 deletions test/data/whitespace/project/project.cproject.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
project:

components:
- component: ARM::CMSIS:CORE
- component: ARM::Device:Startup&C Startup

groups:
- group: Source
files:
- file: ./ma in.c
- group: Header
files:
- file: ./tes t/tes t.h

1 change: 1 addition & 0 deletions test/data/whitespace/project/tes t/tes t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define TES_T 1
31 changes: 31 additions & 0 deletions test/data/whitespace/solution.csolution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
solution:
created-for: [email protected]
cdefault:

packs:
- pack: ARM::Cortex_DFP
- pack: ARM::CMSIS

target-types:
- type: ARMCM0
device: ARMCM0

build-types:
- type: AC6
compiler: AC6

- type: GCC
compiler: GCC
misc:
- Library:
- -lm
- -lc

# - type: IAR
# compiler: IAR

- type: CLANG
compiler: CLANG

projects:
- project: ./project/project.cproject.yml

0 comments on commit 64e3992

Please sign in to comment.