Skip to content

Commit e3070fa

Browse files
author
Alexandre Ghiti
committed
Add cfi tests
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
1 parent e8eb032 commit e3070fa

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

automated/linux/cfi/cfi.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
2+
3+
# shellcheck disable=SC1091
4+
. ../../lib/sh-test-lib
5+
6+
OUTPUT="$(pwd)/output"
7+
RESULT_FILE="${OUTPUT}/result.txt"
8+
RESULT_LOG="${OUTPUT}/result_log.txt"
9+
CWD=""
10+
11+
cfi_run_test() {
12+
# shellcheck disable=SC2164
13+
# Redirect stdout (not stderr)
14+
cd /opt/cfi/
15+
16+
echo -n "cfi_compiled_should_succeed " > "${RESULT_FILE}"
17+
./cfi_compiled_should_succeed | tee -a "${RESULT_LOG}"
18+
if [[ "${PIPESTATUS[0]}" == "0" ]]; then
19+
echo "pass" >> "${RESULT_FILE}"
20+
else
21+
echo "fail" >> "${RESULT_FILE}"
22+
fi
23+
24+
echo -n "not_cfi_compiled_should_fail " >> "${RESULT_FILE}"
25+
./not_cfi_compiled_should_fail | tee -a "${RESULT_LOG}"
26+
if [[ "${PIPESTATUS[0]}" == "139" ]]; then
27+
echo "pass" >> "${RESULT_FILE}"
28+
else
29+
echo "fail" >> "${RESULT_FILE}"
30+
fi
31+
32+
# TODO should check lock and disable
33+
}
34+
35+
# Test run.
36+
! check_root && error_msg "This script must be run as root"
37+
create_out_dir "${OUTPUT}"
38+
# shellcheck disable=SC2164
39+
cd "${OUTPUT}"
40+
41+
info_msg "About to run cfi tests..."
42+
info_msg "Output directory: ${OUTPUT}"
43+
44+
if [ -f /proc/config.gz ]
45+
then
46+
CONFIG_RISCV_USER_CFI=$(zcat /proc/config.gz | grep "CONFIG_RISCV_USER_CFI=")
47+
elif [ -f /boot/config-"$(uname -r)" ]
48+
then
49+
KERNEL_CONFIG_FILE="/boot/config-$(uname -r)"
50+
CONFIG_RISCV_USER_CFI=$(grep "CONFIG_RISCV_USER_CFI=" "${KERNEL_CONFIG_FILE}")
51+
else
52+
exit_on_skip "cfi-pre-requirements" "Kernel config file not available"
53+
fi
54+
55+
[ "${CONFIG_RISCV_USER_CFI}" = "CONFIG_RISCV_USER_CFI=y" ]
56+
exit_on_skip "cfi-pre-requirements" "Kernel config CONFIG_RISCV_USER_CFI=y not enabled"
57+
58+
# Binaries must be provided via an overlay
59+
cfi_run_test

automated/linux/cfi/cfi.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
metadata:
2+
name: cfi
3+
format: "Lava-Test Test Definition 1.0"
4+
description: "Run basic CFI tests.
5+
Tests that a non-cfi rootfs boots fine, that a cfi compiled
6+
binary runs fine and that a non-cfi compiled binary which
7+
prctl does not work (segfault)"
8+
maintainer:
9+
- alexghiti@rivosinc.com
10+
os:
11+
- debian
12+
- ubuntu
13+
- centos
14+
- fedora
15+
scope:
16+
- functional
17+
devices:
18+
- rtsm_ve-armv8
19+
- arndale
20+
- mustang
21+
- overdrive
22+
- d05
23+
- d03
24+
- hi6220-hikey
25+
- apq8016-sbc
26+
27+
params:
28+
SKIP_INSTALL: "False"
29+
30+
run:
31+
steps:
32+
- cd ./automated/linux/cfi/
33+
- ./cfi.sh
34+
- ../../utils/send-to-lava.sh ./output/result.txt

0 commit comments

Comments
 (0)