Skip to content

Commit 086f17a

Browse files
committed
Adding shmbridge validation test case
This test validates the encryption and access functionality of the shmbridge partition by formatting it, applying fscrypt encryption, and verifying data integrity through read/write operations. - Compliant with qcom-linux-testkit structure - Generates .res file for CI/CD - Uses functestlib logging and dependency checks Signed-off-by: Anil Yadav <[email protected]>
1 parent a9fe7d5 commit 086f17a

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2+
SPDX-License-Identifier: BSD-3-Clause-Clear
3+
4+
# shmbridge Validation Test
5+
6+
## Overview
7+
8+
This test case validates the encryption and access functionality of the `shmbridge` partition by:
9+
10+
- Formatting the partition with ext4 and encryption options
11+
- Mounting it with `inlinecrypt`
12+
- Adding an encryption key using `fscryptctl`
13+
- Setting and verifying an encryption policy
14+
- Writing and reading a test file to confirm data integrity
15+
16+
## Usage
17+
18+
Instructions:
19+
20+
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 any directory on the target device.
21+
2. Verify Transfer: Ensure that the repo have been successfully copied to any directory on the target device.
22+
3. Run Scripts: Navigate to the directory where these files are copied on the target device and execute the scripts as needed.
23+
24+
Run a Kernel Baseport shmbridge test using:
25+
---
26+
#### Quick Example
27+
```
28+
git clone <this-repo>
29+
cd <this-repo>
30+
scp -r common Runner user@target_device_ip:<Path in device>
31+
ssh user@target_device_ip
32+
cd <Path in device>/Runner && ./run-test.sh shmbridge
33+
```
34+
35+
## Prerequisites
36+
- `fscryptctl`, `mkfs.ext4` and `mount` must be available
37+
- Root access is required
38+
- Partition /dev/disk/by-partlabel/xbl_ramdump_a must exist and be accessible
39+
40+
## Result Format
41+
42+
Test result will be saved in shmbridge.res as:
43+
#### Pass Criteria
44+
- Partition is found and formatted
45+
- Encryption key is added and policy is set
46+
- Test file is written and read successfully
47+
- `Test Passed` – if all validations succeed
48+
<!-- -->
49+
#### Fail Criteria
50+
- Partition not found
51+
- Encryption setup fails
52+
- Test file cannot be read or content mismatch
53+
- `Test Failed` – if any check fails
54+
55+
## Output
56+
A .res file is generated in the same directory:
57+
58+
`PASS shmbridge` OR `FAIL shmbridge`
59+
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
# SPDX-License-Identifier: BSD-3-Clause-Clear
5+
6+
# Source init_env and functestlib.sh
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+
# shellcheck disable=SC1090
24+
. "$INIT_ENV"
25+
26+
# shellcheck disable=SC1090,SC1091
27+
. "$TOOLS/functestlib.sh"
28+
29+
TESTNAME="shmbridge"
30+
test_path=$(find_test_case_by_name "$TESTNAME") || {
31+
log_fail "$TESTNAME : Test directory not found."
32+
echo "FAIL $TESTNAME" > "./$TESTNAME.res"
33+
exit 1
34+
}
35+
36+
cd "$test_path" || exit 1
37+
res_file="./$TESTNAME.res"
38+
rm -f "$res_file"
39+
40+
log_info "--------------------------------------------------------------------------"
41+
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
42+
43+
log_info "Checking if dependency: fscryptctl mkfs.ext4 mount is available"
44+
check_dependencies fscryptctl mkfs.ext4 mount
45+
46+
MOUNT_POINT="/mnt/overlay"
47+
PARTITION="/dev/disk/by-partlabel/xbl_ramdump_a"
48+
KEY_FILE="$MOUNT_POINT/stdkey"
49+
TEST_DIR="$MOUNT_POINT/test"
50+
TEST_FILE="$TEST_DIR/txt"
51+
52+
log_info "Creating mount point at $MOUNT_POINT"
53+
mkdir -p "$MOUNT_POINT"
54+
55+
log_info "Checking if partition exists"
56+
if [ ! -e "$PARTITION" ]; then
57+
log_fail "Partition $PARTITION not found"
58+
echo "FAIL $TESTNAME" > "$res_file"
59+
exit 1
60+
fi
61+
62+
log_info "Formatting partition with ext4 and encryption options"
63+
if ! mount | grep -q "$PARTITION"; then
64+
mkfs.ext4 -F -O encrypt,stable_inodes "$PARTITION"
65+
else
66+
log_warn "$PARTITION is already mounted; skipping format"
67+
fi
68+
69+
log_info "Mounting partition to $MOUNT_POINT with inlinecrypt"
70+
mount "$PARTITION" -o inlinecrypt "$MOUNT_POINT"
71+
72+
log_info "Generating 64-byte encryption key"
73+
dd if=/dev/urandom bs=1 count=64 > "$KEY_FILE"
74+
75+
log_info "Adding encryption key using fscryptctl"
76+
identifier=$(fscryptctl add_key "$MOUNT_POINT" < "$KEY_FILE")
77+
78+
mkdir -p "$TEST_DIR"
79+
80+
log_info "Setting encryption policy on $TEST_DIR"
81+
fscryptctl set_policy --iv-ino-lblk-64 "$identifier" "$TEST_DIR"
82+
83+
log_info "Verifying encryption policy"
84+
fscryptctl get_policy "$TEST_DIR"
85+
86+
log_info "Writing test file"
87+
echo "hello" > "$TEST_FILE"
88+
sync
89+
echo 3 > /proc/sys/vm/drop_caches
90+
91+
log_info "Reading test file"
92+
if cat "$TEST_FILE" | grep -q "hello"; then
93+
log_pass "$TESTNAME : Test Passed"
94+
echo "PASS $TESTNAME" > "$res_file"
95+
else
96+
log_fail "$TESTNAME : Test Failed"
97+
echo "FAIL $TESTNAME" > "$res_file"
98+
exit 1
99+
fi
100+
101+
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
102+
103+

0 commit comments

Comments
 (0)