|
| 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 |
0 commit comments