Skip to content

Commit b1e642d

Browse files
committed
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 <[email protected]>
1 parent d75bcd4 commit b1e642d

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Qualcomm Hardware Random Number Generator (QRNG) Script
2+
# Overview
3+
4+
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.
5+
6+
## Features
7+
8+
- Driver Validation: Confirms the presence and correct configuration of the qcom_hwrng kernel driver.
9+
- Dependency Check: Verifies the availability of required tools like rngtest before execution.
10+
- Automated Result Logging: Outputs test results to a .res file for automated result collection.
11+
- Remote Execution Ready: Supports remote deployment and execution via scp and ssh.
12+
13+
## Prerequisites
14+
15+
Ensure the following components are present in the target:
16+
17+
- `rngtest` (Binary Available in /usr/bin) - this test app can be compiled from https://github.com/cernekee/rng-tools/
18+
19+
## Directory Structure
20+
```
21+
Runner/
22+
├── suites/
23+
│ ├── Kernel/
24+
│ │ ├── FunctionalArea/
25+
│ │ │ ├── baseport/
26+
│ │ │ │ ├── qcom_hwrng/
27+
│ │ │ │ │ ├── run.sh
28+
```
29+
## Usage
30+
31+
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.
32+
33+
2. Verify Transfer: Ensure that the repo have been successfully copied to the /var directory on the target device.
34+
35+
3. Run Scripts: Navigate to the /var directory on the target device and execute the scripts as needed.
36+
37+
---
38+
Quick Example
39+
```
40+
git clone <this-repo>
41+
cd <this-repo>
42+
scp -r common Runner user@target_device_ip:/var
43+
ssh user@target_device_ip
44+
cd /var/Runner && ./run-test.sh qcom_hwrng
45+
46+
Sample output:
47+
sh-5.2# ./run-test.sh qcom_hwrng
48+
[Executing test case: /var/Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng] 2025-05-16 06:08:41 -
49+
[INFO] 2025-05-16 06:08:41 - -----------------------------------------------------------------------------------------
50+
[INFO] 2025-05-16 06:08:41 - -------------------Starting qcom_hwrng Testcase----------------------------
51+
[INFO] 2025-05-16 06:08:41 - qcom_hwrng successfully set as the current RNG source.
52+
[INFO] 2025-05-16 06:08:41 - Checking if dependency binary is available
53+
[PASS] 2025-05-16 06:08:41 - Test related dependencies are present.
54+
cat: write error: Broken pipe
55+
[PASS] 2025-05-16 06:08:41 - qcom_hwrng : Test Passed
56+
[INFO] 2025-05-16 06:08:41 - -------------------Completed qcom_hwrng Testcase----------------------------
57+
```
58+
4. Results will be available in the `/var/Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng/` directory.
59+
60+
## Notes
61+
62+
- The script sets qcom_hwrng as the primary hwrng.
63+
- It validates Qualcomm Hardware Random Number Generator (HWRNG) basic functionality.
64+
- If any critical tool is missing, the script exits with an error message.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
# SPDX-License-Identifier: BSD-3-Clause-Clear
5+
6+
# Robustly find and source init_env
7+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
8+
INIT_ENV=""
9+
SEARCH="$SCRIPT_DIR"
10+
while [ "$SEARCH" != "/" ]; do
11+
if [ -f "$SEARCH/init_env" ]; then
12+
INIT_ENV="$SEARCH/init_env"
13+
break
14+
fi
15+
SEARCH=$(dirname "$SEARCH")
16+
done
17+
18+
if [ -z "$INIT_ENV" ]; then
19+
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
20+
exit 1
21+
fi
22+
23+
# Only source if not already loaded (idempotent)
24+
if [ -z "$__INIT_ENV_LOADED" ]; then
25+
# shellcheck disable=SC1090
26+
. "$INIT_ENV"
27+
fi
28+
# Always source functestlib.sh, using $TOOLS exported by init_env
29+
# shellcheck disable=SC1090,SC1091
30+
. "$TOOLS/functestlib.sh"
31+
32+
TESTNAME="qcom_hwrng"
33+
test_path=$(find_test_case_by_name "$TESTNAME")
34+
cd "$test_path" || exit 1
35+
36+
log_info "-----------------------------------------------------------------------------------------"
37+
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
38+
39+
# Set the hardware RNG source to Qualcomm's RNG
40+
if [ -e /sys/class/misc/hw_random/rng_current ]; then
41+
echo qcom_hwrng > /sys/class/misc/hw_random/rng_current
42+
else
43+
echo "Path /sys/class/misc/hw_random/rng_current does not exist."
44+
log_fail "$TESTNAME : Test Failed"
45+
exit 1
46+
fi
47+
48+
# Verify that qcom_hwrng was successfully set
49+
current_rng=$(cat /sys/class/misc/hw_random/rng_current)
50+
if [ "$current_rng" != "qcom_hwrng" ]; then
51+
log_info "Error: Failed to set qcom_hwrng as the current RNG source."
52+
log_fail "$TESTNAME : Test Failed"
53+
exit 1
54+
else
55+
log_info "qcom_hwrng successfully set as the current RNG source."
56+
fi
57+
58+
log_info "Checking if dependency binary is available"
59+
check_dependencies rngtest
60+
61+
cat /dev/random | rngtest -c 1000 > /tmp/qcom_hwrng_output.txt 2>&1
62+
63+
grep 'FIPS 140-2 failures' /tmp/qcom_hwrng_output.txt | awk '{print $NF}' > /tmp/rngtest_failures.txt
64+
65+
value=$(cat /tmp/rngtest_failures.txt)
66+
67+
if [ "$value" -lt 10 ]; then
68+
log_pass "$TESTNAME : Test Passed"
69+
echo "$TESTNAME PASS" > $test_path/$TESTNAME.res
70+
else
71+
log_fail "$TESTNAME : Test Failed"
72+
echo "$TESTNAME FAIL" > $test_path/$TESTNAME.res
73+
fi
74+
log_info "-------------------Completed $TESTNAME Testcase----------------------------"

0 commit comments

Comments
 (0)