From 6fbb4aa9d94454b9b030dc40277028ed53ff70cb Mon Sep 17 00:00:00 2001 From: Naveenkumar Suresh Date: Thu, 12 Jun 2025 14:18:50 +0530 Subject: [PATCH] Add: Qualcomm HWRNG test script with documentation - Added initial test script to validate Qualcomm HWRNG functionality - Refined script and documentation based on review feedback Signed-off-by: Naveenkumar Suresh --- .../baseport/qcom_hwrng/README_qcom_hwrng.md | 77 +++++++++++++++++++ .../FunctionalArea/baseport/qcom_hwrng/run.sh | 76 ++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100755 Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng/README_qcom_hwrng.md create mode 100755 Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng/run.sh diff --git a/Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng/README_qcom_hwrng.md b/Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng/README_qcom_hwrng.md new file mode 100755 index 00000000..b8f498fa --- /dev/null +++ b/Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng/README_qcom_hwrng.md @@ -0,0 +1,77 @@ +Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +SPDX-License-Identifier: BSD-3-Clause-Clear + +# Qualcomm Hardware Random Number Generator (QRNG) Script +# Overview + +The qcom_hwrng test script validates Qualcomm Hardware Random Number Generator (HWRNG) basic functionality. This test ensures that the HWRNG kernel driver is correctly integrated and functional. + +## Features + +- Driver Validation: Confirms the presence and correct configuration of the qcom_hwrng kernel driver. +- Dependency Check: Verifies the availability of required tools like rngtest before execution. +- Automated Result Logging: Outputs test results to a .res file for automated result collection. +- Remote Execution Ready: Supports remote deployment and execution via scp and ssh. + +## Prerequisites + +Ensure the following components are present in the target: + +- `rngtest` (Binary Available in /usr/bin) - this test app can be compiled from https://github.com/cernekee/rng-tools/ + +## Directory Structure +``` +Runner/ +├── suites/ +│ ├── Kernel/ +│ │ ├── FunctionalArea/ +│ │ │ ├── baseport/ +│ │ │ │ ├── qcom_hwrng/ +│ │ │ │ │ ├── run.sh +``` +## Usage + +1. Copy repo to Target Device: Use scp to transfer the scripts from the host to the target device. The scripts should be copied to the /var directory on the target device. + +2. Verify Transfer: Ensure that the repo have been successfully copied to the /var directory on the target device. + +3. Run Scripts: Navigate to the /var directory on the target device and execute the scripts as needed. + +--- +Quick Example +``` +git clone +cd +scp -r common Runner user@target_device_ip:/ +ssh user@target_device_ip +cd //Runner && ./run-test.sh qcom_hwrng + +Sample output: +sh-5.2# ./run-test.sh qcom_hwrng +[Executing test case: qcom_hwrng] 1970-01-05 16:56:59 - +[INFO] 1970-01-05 16:56:59 - ----------------------------------------------------------------------------------------- +[INFO] 1970-01-05 16:56:59 - -------------------Starting qcom_hwrng Testcase---------------------------- +[INFO] 1970-01-05 16:56:59 - qcom_hwrng successfully set as the current RNG source. +[INFO] 1970-01-05 16:56:59 - Checking if dependency binary is available +1000+0 records in +1000+0 records out +1000 bytes (1.0 kB) copied, 0.00145641 s, 687 kB/s +[PASS] 1970-01-05 16:56:59 - qcom_hwrng : Test Passed +[INFO] 1970-01-05 16:56:59 - -------------------Completed qcom_hwrng Testcase---------------------------- +[PASS] 1970-01-05 16:56:59 - qcom_hwrng passed + +[INFO] 1970-01-05 16:56:59 - ========== Test Summary ========== +PASSED: +qcom_hwrng + +FAILED: + None +[INFO] 1970-01-05 16:56:59 - ================================== +``` +4. Results will be available in the `//Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng/` directory. + +## Notes + +- The script sets qcom_hwrng as the primary hwrng. +- It validates Qualcomm Hardware Random Number Generator (HWRNG) basic functionality. +- If any critical tool is missing, the script exits with an error message. \ No newline at end of file diff --git a/Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng/run.sh b/Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng/run.sh new file mode 100755 index 00000000..afc325dc --- /dev/null +++ b/Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng/run.sh @@ -0,0 +1,76 @@ +#!/bin/sh + +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause-Clear + +# Robustly find and source init_env +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +INIT_ENV="" +SEARCH="$SCRIPT_DIR" +while [ "$SEARCH" != "/" ]; do + if [ -f "$SEARCH/init_env" ]; then + INIT_ENV="$SEARCH/init_env" + break + fi + SEARCH=$(dirname "$SEARCH") +done + +if [ -z "$INIT_ENV" ]; then + echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2 + exit 1 +fi + +# Only source if not already loaded (idempotent) +if [ -z "$__INIT_ENV_LOADED" ]; then + # shellcheck disable=SC1090 + . "$INIT_ENV" +fi +# Always source functestlib.sh, using $TOOLS exported by init_env +# shellcheck disable=SC1090,SC1091 +. "$TOOLS/functestlib.sh" + +TESTNAME="qcom_hwrng" +test_path=$(find_test_case_by_name "$TESTNAME") +cd "$test_path" || exit 1 + +log_info "-----------------------------------------------------------------------------------------" +log_info "-------------------Starting $TESTNAME Testcase----------------------------" + +# Set the hardware RNG source to Qualcomm's RNG +if [ -e /sys/class/misc/hw_random/rng_current ]; then + echo qcom_hwrng > /sys/class/misc/hw_random/rng_current +else + echo "Path /sys/class/misc/hw_random/rng_current does not exist." + log_fail "$TESTNAME : Test Failed" + exit 1 +fi + +# Verify that qcom_hwrng was successfully set +current_rng=$(cat /sys/class/misc/hw_random/rng_current) +if [ "$current_rng" != "qcom_hwrng" ]; then + log_info "Error: Failed to set qcom_hwrng as the current RNG source." + log_fail "$TESTNAME : Test Failed" + exit 1 +else + log_info "qcom_hwrng successfully set as the current RNG source." +fi + +log_info "Checking if dependency binary is available" +check_dependencies rngtest + +dd if=/dev/random bs=1 count=1000 | rngtest -c 1000 > ./qcom_hwrng_output.txt 2>&1 + +grep 'FIPS 140-2 failures' ./qcom_hwrng_output.txt | awk '{print $NF}' > ./rngtest_failures.txt + +value=$(cat ./rngtest_failures.txt) + +if [ "$value" -lt 10 ]; then + log_pass "$TESTNAME : Test Passed" + echo "$TESTNAME PASS" > $test_path/$TESTNAME.res + exit 0 +else + log_fail "$TESTNAME : Test Failed" + echo "$TESTNAME FAIL" > $test_path/$TESTNAME.res + exit 1 +fi +log_info "-------------------Completed $TESTNAME Testcase----------------------------" \ No newline at end of file