Skip to content

Commit 8cd8ca0

Browse files
committed
Add: test script for validating Qualcomm Crypto functionality
- Added initial test script to validate Qualcomm Crypto functionality Signed-off-by: Naveenkumar Suresh <[email protected]>
1 parent 3d52665 commit 8cd8ca0

File tree

2 files changed

+201
-0
lines changed

2 files changed

+201
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2+
SPDX-License-Identifier: BSD-3-Clause-Clear
3+
4+
# Qualcomm Crypto (qcom_crypto) Functionality Test Script
5+
# Overview
6+
7+
The qcom_crypto test script validates the basic functionality of cryptographic operations using the kcapi tool. It ensures that encryption, decryption, and HMAC-SHA256 operations are correctly executed and verified against expected outputs.
8+
9+
## Features
10+
11+
- Environment Initialization: Robustly locates and sources the init_env file from the directory hierarchy.
12+
- Dependency Check: Verifies the presence of required tools like kcapi.
13+
- Crypto Validation: Performs AES-CBC encryption/decryption and HMAC-SHA256 operations.
14+
- Automated Result Logging: Outputs test results to a .res file for automated result collection.
15+
- Modular Integration: Designed to work within a larger test framework using functestlib.sh.
16+
17+
## Prerequisites
18+
19+
Ensure the following components are present on the target device:
20+
21+
- `kcapi` (Kernel Crypto tool) Available in /usr/bin
22+
- `libkcapi.so.1` (Kernel Crypto library) Available in /usr/lib
23+
24+
## Directory Structure
25+
```
26+
Runner/
27+
├── suites/
28+
│ ├── Kernel/
29+
│ │ ├── FunctionalArea/
30+
│ │ │ ├── baseport/
31+
│ │ │ │ ├── qcom_crypto/
32+
│ │ │ │ │ ├── run.sh
33+
```
34+
## Usage
35+
36+
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 ```/<user-defined-location>``` directory on the target device.
37+
38+
2. Verify Transfer: Ensure that the repo have been successfully copied to the ```/<user-defined-location>``` directory on the target device.
39+
40+
3. Run Scripts: Navigate to the ```/<user-defined-location>``` directory on the target device and execute the scripts as needed.
41+
42+
---
43+
Quick Example
44+
```
45+
git clone <this-repo>
46+
cd <this-repo>
47+
scp -r common Runner user@target_device_ip:/<user-defined-location>
48+
ssh user@target_device_ip
49+
cd /<user-defined-location>/Runner && ./run-test.sh qcom_hwrng
50+
51+
Sample output:
52+
sh-5.2# ./run-test.sh qcom_crypto
53+
[Executing test case: qcom_crypto] 1970-01-01 05:44:18 -
54+
[INFO] 1970-01-01 05:44:18 - -----------------------------------------------------------------------------------------
55+
[INFO] 1970-01-01 05:44:18 - -------------------Starting qcom_crypto Testcase----------------------------
56+
[INFO] 1970-01-01 05:44:18 - === Test Initialization ===
57+
[INFO] 1970-01-01 05:44:18 - Checking if dependency binary is available
58+
[INFO] 1970-01-01 05:44:18 - Running encryption test
59+
[INFO] 1970-01-01 05:44:18 - Encryption test passed
60+
[INFO] 1970-01-01 05:44:18 - Running decryption test
61+
[INFO] 1970-01-01 05:44:18 - Decryption test passed
62+
[INFO] 1970-01-01 05:44:18 - Running HMAC-SHA256 test
63+
[INFO] 1970-01-01 05:44:18 - HMAC-SHA256 test passed
64+
[PASS] 1970-01-01 05:44:18 - qcom_crypto : All tests passed
65+
[PASS] 1970-01-01 05:44:18 - qcom_crypto passed
66+
67+
[INFO] 1970-01-01 05:44:18 - ========== Test Summary ==========
68+
PASSED:
69+
qcom_crypto
70+
71+
FAILED:
72+
None
73+
74+
SKIPPED:
75+
None
76+
[INFO] 1970-01-01 05:44:18 - ==================================
77+
```
78+
4. Results will be available in the `/<user-defined-location>/Runner/suites/Kernel/FunctionalArea/baseport/qcom_crypto/` directory.
79+
80+
## Notes
81+
82+
- It uses kcapi to validate AES-CBC encryption/decryption and HMAC-SHA256 hashing.
83+
- If any test fails, the script logs the expected vs actual output and exits with a failure code.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
#!/bin/bash
33+
34+
TESTNAME="qcom_crypto"
35+
test_path=$(find_test_case_by_name "$TESTNAME")
36+
cd "$test_path" || exit 1
37+
res_file="./$TESTNAME.res"
38+
39+
log_info "-----------------------------------------------------------------------------------------"
40+
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
41+
log_info "=== Test Initialization ==="
42+
43+
log_info "Checking if dependency binary is available"
44+
check_dependencies kcapi
45+
46+
# Initialize test status
47+
TEST_PASSED=true
48+
49+
# Encryption Test
50+
log_info "Running encryption test"
51+
ENCRYPT_OUTPUT=$(kcapi -x 1 -e -c "cbc(aes)" \
52+
-k 8d7dd9b0170ce0b5f2f8e1aa768e01e91da8bfc67fd486d081b28254c99eb423 \
53+
-i 7fbc02ebf5b93322329df9bfccb635af \
54+
-p 48981da18e4bb9ef7e2e3162d16b1910 2>&1)
55+
56+
EXPECTED_ENCRYPT="8b19050f66582cb7f7e4b6c873819b71"
57+
58+
if [ "$ENCRYPT_OUTPUT" != "$EXPECTED_ENCRYPT" ]; then
59+
log_fail "$TESTNAME : Encryption test failed"
60+
log_info "Expected: $EXPECTED_ENCRYPT"
61+
log_info "Got : $ENCRYPT_OUTPUT"
62+
TEST_PASSED=false
63+
else
64+
log_info "Encryption test passed"
65+
fi
66+
67+
# Decryption Test
68+
log_info "Running decryption test"
69+
DECRYPT_OUTPUT=$(kcapi -x 1 -c "cbc(aes)" \
70+
-k 3023b2418ea59a841757dcf07881b3a8def1c97b659a4dad \
71+
-i 95aa5b68130be6fcf5cabe7d9f898a41 \
72+
-q c313c6b50145b69a77b33404cb422598 2>&1)
73+
74+
EXPECTED_DECRYPT="836de0065f9d6f6a3dd2c53cd17e33a5"
75+
76+
if [ "$DECRYPT_OUTPUT" != "$EXPECTED_DECRYPT" ]; then
77+
log_fail "$TESTNAME : Decryption test failed"
78+
log_info "Expected: $EXPECTED_DECRYPT"
79+
log_info "Got : $DECRYPT_OUTPUT"
80+
TEST_PASSED=false
81+
else
82+
log_info "Decryption test passed"
83+
fi
84+
85+
# HMAC-SHA256 Test
86+
log_info "Running HMAC-SHA256 test"
87+
HMAC_OUTPUT=$(kcapi -x 12 -c "hmac(sha256)" \
88+
-k 0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b \
89+
-i 000102030405060708090a0b0c \
90+
-p f0f1f2f3f4f5f6f7f8f9 \
91+
-b 42 2>&1)
92+
93+
EXPECTED_HMAC="3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865"
94+
95+
if [ "$HMAC_OUTPUT" != "$EXPECTED_HMAC" ]; then
96+
log_fail "$TESTNAME : HMAC-SHA256 test failed"
97+
log_info "Expected: $EXPECTED_HMAC"
98+
log_info "Got : $HMAC_OUTPUT"
99+
TEST_PASSED=false
100+
else
101+
log_info "HMAC-SHA256 test passed"
102+
fi
103+
104+
# Final Result
105+
if [ "$TEST_PASSED" = true ]; then
106+
log_pass "$TESTNAME : All tests passed"
107+
echo "$TESTNAME PASS" > "$res_file"
108+
exit 0
109+
else
110+
log_fail "$TESTNAME : One or more tests failed"
111+
echo "$TESTNAME FAIL" > "$res_file"
112+
exit 1
113+
fi
114+
115+
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
116+
117+
118+

0 commit comments

Comments
 (0)