Skip to content

Commit 6fbb4aa

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 6fbb4aa

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2+
SPDX-License-Identifier: BSD-3-Clause-Clear
3+
4+
# Qualcomm Hardware Random Number Generator (QRNG) Script
5+
# Overview
6+
7+
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.
8+
9+
## Features
10+
11+
- Driver Validation: Confirms the presence and correct configuration of the qcom_hwrng kernel driver.
12+
- Dependency Check: Verifies the availability of required tools like rngtest before execution.
13+
- Automated Result Logging: Outputs test results to a .res file for automated result collection.
14+
- Remote Execution Ready: Supports remote deployment and execution via scp and ssh.
15+
16+
## Prerequisites
17+
18+
Ensure the following components are present in the target:
19+
20+
- `rngtest` (Binary Available in /usr/bin) - this test app can be compiled from https://github.com/cernekee/rng-tools/
21+
22+
## Directory Structure
23+
```
24+
Runner/
25+
├── suites/
26+
│ ├── Kernel/
27+
│ │ ├── FunctionalArea/
28+
│ │ │ ├── baseport/
29+
│ │ │ │ ├── qcom_hwrng/
30+
│ │ │ │ │ ├── run.sh
31+
```
32+
## Usage
33+
34+
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.
35+
36+
2. Verify Transfer: Ensure that the repo have been successfully copied to the /var directory on the target device.
37+
38+
3. Run Scripts: Navigate to the /var directory on the target device and execute the scripts as needed.
39+
40+
---
41+
Quick Example
42+
```
43+
git clone <this-repo>
44+
cd <this-repo>
45+
scp -r common Runner user@target_device_ip:/<user-defined-location>
46+
ssh user@target_device_ip
47+
cd /<user-defined-location>/Runner && ./run-test.sh qcom_hwrng
48+
49+
Sample output:
50+
sh-5.2# ./run-test.sh qcom_hwrng
51+
[Executing test case: qcom_hwrng] 1970-01-05 16:56:59 -
52+
[INFO] 1970-01-05 16:56:59 - -----------------------------------------------------------------------------------------
53+
[INFO] 1970-01-05 16:56:59 - -------------------Starting qcom_hwrng Testcase----------------------------
54+
[INFO] 1970-01-05 16:56:59 - qcom_hwrng successfully set as the current RNG source.
55+
[INFO] 1970-01-05 16:56:59 - Checking if dependency binary is available
56+
1000+0 records in
57+
1000+0 records out
58+
1000 bytes (1.0 kB) copied, 0.00145641 s, 687 kB/s
59+
[PASS] 1970-01-05 16:56:59 - qcom_hwrng : Test Passed
60+
[INFO] 1970-01-05 16:56:59 - -------------------Completed qcom_hwrng Testcase----------------------------
61+
[PASS] 1970-01-05 16:56:59 - qcom_hwrng passed
62+
63+
[INFO] 1970-01-05 16:56:59 - ========== Test Summary ==========
64+
PASSED:
65+
qcom_hwrng
66+
67+
FAILED:
68+
None
69+
[INFO] 1970-01-05 16:56:59 - ==================================
70+
```
71+
4. Results will be available in the `/<user-defined-location>/Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng/` directory.
72+
73+
## Notes
74+
75+
- The script sets qcom_hwrng as the primary hwrng.
76+
- It validates Qualcomm Hardware Random Number Generator (HWRNG) basic functionality.
77+
- If any critical tool is missing, the script exits with an error message.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
dd if=/dev/random bs=1 count=1000 | rngtest -c 1000 > ./qcom_hwrng_output.txt 2>&1
62+
63+
grep 'FIPS 140-2 failures' ./qcom_hwrng_output.txt | awk '{print $NF}' > ./rngtest_failures.txt
64+
65+
value=$(cat ./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+
exit 0
71+
else
72+
log_fail "$TESTNAME : Test Failed"
73+
echo "$TESTNAME FAIL" > $test_path/$TESTNAME.res
74+
exit 1
75+
fi
76+
log_info "-------------------Completed $TESTNAME Testcase----------------------------"

0 commit comments

Comments
 (0)