-
Notifications
You must be signed in to change notification settings - Fork 15
Add: test script for validating Qualcomm HWRNG functionality #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nklazy
wants to merge
1
commit into
qualcomm-linux:main
Choose a base branch
from
nklazy:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng/README_qcom_hwrng.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# 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 <this-repo> | ||
cd <this-repo> | ||
scp -r common Runner user@target_device_ip:/var | ||
ssh user@target_device_ip | ||
cd /var/Runner && ./run-test.sh qcom_hwrng | ||
|
||
Sample output: | ||
sh-5.2# ./run-test.sh qcom_hwrng | ||
[Executing test case: /var/Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng] 2025-05-16 06:08:41 - | ||
[INFO] 2025-05-16 06:08:41 - ----------------------------------------------------------------------------------------- | ||
[INFO] 2025-05-16 06:08:41 - -------------------Starting qcom_hwrng Testcase---------------------------- | ||
[INFO] 2025-05-16 06:08:41 - qcom_hwrng successfully set as the current RNG source. | ||
[INFO] 2025-05-16 06:08:41 - Checking if dependency binary is available | ||
[PASS] 2025-05-16 06:08:41 - Test related dependencies are present. | ||
cat: write error: Broken pipe | ||
[PASS] 2025-05-16 06:08:41 - qcom_hwrng : Test Passed | ||
[INFO] 2025-05-16 06:08:41 - -------------------Completed qcom_hwrng Testcase---------------------------- | ||
``` | ||
4. Results will be available in the `/var/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. |
74 changes: 74 additions & 0 deletions
74
Runner/suites/Kernel/FunctionalArea/baseport/qcom_hwrng/run.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/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 | ||
|
||
cat /dev/random | rngtest -c 1000 > /tmp/qcom_hwrng_output.txt 2>&1 | ||
|
||
grep 'FIPS 140-2 failures' /tmp/qcom_hwrng_output.txt | awk '{print $NF}' > /tmp/rngtest_failures.txt | ||
|
||
value=$(cat /tmp/rngtest_failures.txt) | ||
|
||
if [ "$value" -lt 10 ]; then | ||
log_pass "$TESTNAME : Test Passed" | ||
echo "$TESTNAME PASS" > $test_path/$TESTNAME.res | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For effectiveness, better add |
||
else | ||
log_fail "$TESTNAME : Test Failed" | ||
echo "$TESTNAME FAIL" > $test_path/$TESTNAME.res | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For effectiveness, better add |
||
fi | ||
log_info "-------------------Completed $TESTNAME Testcase----------------------------" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of using
cat
. Its better to usedd
. Also its better to use current folder to save the log file for post processing.