Skip to content

Commit 5efbd54

Browse files
wearyzenhenrikbrixandersen
authored andcommitted
tests: arm: new test for PACBTI
Add a simple test to test branch target identification (BTI). Signed-off-by: Sudan Landge <[email protected]>
1 parent 1916ec2 commit 5efbd54

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(arm_pacbti)
7+
8+
target_sources(app PRIVATE src/main.c)

tests/arch/arm/arm_pacbti/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_ZTEST_FATAL_HOOK=y
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2025 Arm Limited and/or its affiliates <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/ztest.h>
8+
#include <zephyr/ztest_error_hook.h>
9+
#include <cmsis_core.h>
10+
11+
void test_arm_pacbti(void)
12+
{
13+
printf("%s This should never have been called if BTI was enforced\n", __func__);
14+
15+
/* If func call was successful then BTI didn't work as expected */
16+
ztest_test_fail();
17+
}
18+
19+
ZTEST(arm_pacbti, test_arm_bti)
20+
{
21+
/* Try jumping to middle of a random function and mark that fault as expected because if
22+
* BTI is enforced and an indirect jump is made on a non-BTI instruction then a usage fault
23+
* is generated.
24+
*/
25+
ztest_set_fault_valid(true);
26+
27+
__asm__ volatile(" ldr r1, =test_arm_pacbti\n"
28+
" add r1, #4\n"
29+
" bx r1\n");
30+
}
31+
32+
ZTEST_SUITE(arm_pacbti, NULL, NULL, NULL, NULL, NULL);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
common:
2+
tags:
3+
- arm
4+
platform_allow:
5+
- mps3/corstone310/fvp
6+
- mps3/corstone310/fvp/ns
7+
- mps4/corstone315/fvp
8+
- mps4/corstone320/fvp
9+
tests:
10+
arch.arm.pacbti.standard:
11+
# TODO: remove skip after Zephyr sdk makes GCC 14.3 as default
12+
skip: true
13+
extra_configs:
14+
- CONFIG_ARM_PACBTI_STANDARD=y

0 commit comments

Comments
 (0)