Skip to content

Commit 595bfc1

Browse files
authored
Merge pull request qualcomm-linux#100 from nklazy/fscryptctl-branch
Add: test script for validating Qualcomm Crypto functionality
2 parents eb98001 + 7b0142a commit 595bfc1

File tree

2 files changed

+199
-0
lines changed

2 files changed

+199
-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_crypto
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: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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_crypto"
33+
test_path=$(find_test_case_by_name "$TESTNAME")
34+
cd "$test_path" || exit 1
35+
res_file="./$TESTNAME.res"
36+
37+
log_info "-----------------------------------------------------------------------------------------"
38+
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
39+
log_info "=== Test Initialization ==="
40+
41+
log_info "Checking if dependency binary is available"
42+
check_dependencies kcapi
43+
44+
# Initialize test status
45+
TEST_PASSED=true
46+
47+
# Encryption Test
48+
log_info "Running encryption test"
49+
ENCRYPT_OUTPUT=$(kcapi -x 1 -e -c "cbc(aes)" \
50+
-k 8d7dd9b0170ce0b5f2f8e1aa768e01e91da8bfc67fd486d081b28254c99eb423 \
51+
-i 7fbc02ebf5b93322329df9bfccb635af \
52+
-p 48981da18e4bb9ef7e2e3162d16b1910 2>&1)
53+
54+
EXPECTED_ENCRYPT="8b19050f66582cb7f7e4b6c873819b71"
55+
56+
if [ "$ENCRYPT_OUTPUT" != "$EXPECTED_ENCRYPT" ]; then
57+
log_fail "$TESTNAME : Encryption test failed"
58+
log_info "Expected: $EXPECTED_ENCRYPT"
59+
log_info "Got : $ENCRYPT_OUTPUT"
60+
TEST_PASSED=false
61+
else
62+
log_pass "Encryption test passed"
63+
fi
64+
65+
# Decryption Test
66+
log_info "Running decryption test"
67+
DECRYPT_OUTPUT=$(kcapi -x 1 -c "cbc(aes)" \
68+
-k 3023b2418ea59a841757dcf07881b3a8def1c97b659a4dad \
69+
-i 95aa5b68130be6fcf5cabe7d9f898a41 \
70+
-q c313c6b50145b69a77b33404cb422598 2>&1)
71+
72+
EXPECTED_DECRYPT="836de0065f9d6f6a3dd2c53cd17e33a5"
73+
74+
if [ "$DECRYPT_OUTPUT" != "$EXPECTED_DECRYPT" ]; then
75+
log_fail "$TESTNAME : Decryption test failed"
76+
log_info "Expected: $EXPECTED_DECRYPT"
77+
log_info "Got : $DECRYPT_OUTPUT"
78+
TEST_PASSED=false
79+
else
80+
log_pass "Decryption test passed"
81+
fi
82+
83+
# HMAC-SHA256 Test
84+
log_info "Running HMAC-SHA256 test"
85+
HMAC_OUTPUT=$(kcapi -x 12 -c "hmac(sha256)" \
86+
-k 0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b \
87+
-i 000102030405060708090a0b0c \
88+
-p f0f1f2f3f4f5f6f7f8f9 \
89+
-b 42 2>&1)
90+
91+
EXPECTED_HMAC="3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865"
92+
93+
if [ "$HMAC_OUTPUT" != "$EXPECTED_HMAC" ]; then
94+
log_fail "$TESTNAME : HMAC-SHA256 test failed"
95+
log_info "Expected: $EXPECTED_HMAC"
96+
log_info "Got : $HMAC_OUTPUT"
97+
TEST_PASSED=false
98+
else
99+
log_pass "HMAC-SHA256 test passed"
100+
fi
101+
102+
# Final Result
103+
if [ "$TEST_PASSED" = true ]; then
104+
log_pass "$TESTNAME : All tests passed"
105+
echo "$TESTNAME PASS" > "$res_file"
106+
exit 0
107+
else
108+
log_fail "$TESTNAME : One or more tests failed"
109+
echo "$TESTNAME FAIL" > "$res_file"
110+
exit 1
111+
fi
112+
113+
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
114+
115+
116+

0 commit comments

Comments
 (0)