Skip to content

Commit d0c663e

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 d35285c commit d0c663e

File tree

2 files changed

+176
-0
lines changed

2 files changed

+176
-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: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
# SPDX-License-Identifier: BSD-3-Clause-Clear
5+
6+
# Locate 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+
# 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 "$TESTNAME FAIL" > "./$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+
check_dependencies fscryptctl mkfs.ext4 mount dd grep cat
44+
45+
MOUNT_POINT="/mnt/overlay"
46+
PARTITION="/dev/disk/by-partlabel/xbl_ramdump_a"
47+
KEY_FILE="$MOUNT_POINT/stdkey"
48+
TEST_DIR="$MOUNT_POINT/test"
49+
TEST_FILE="$TEST_DIR/txt"
50+
51+
log_info "Creating mount point at $MOUNT_POINT"
52+
mkdir -p "$MOUNT_POINT"
53+
54+
if [ ! -e "$PARTITION" ]; then
55+
log_fail "Partition $PARTITION not found"
56+
echo "$TESTNAME FAIL" > "$res_file"
57+
exit 1
58+
fi
59+
60+
if ! mount | grep -q "$PARTITION"; then
61+
log_info "Formatting $PARTITION with ext4 (encrypt, stable_inodes)"
62+
mkfs.ext4 -F -O encrypt,stable_inodes "$PARTITION"
63+
else
64+
log_warn "$PARTITION already mounted, skipping format"
65+
fi
66+
67+
log_info "Mounting $PARTITION to $MOUNT_POINT with inlinecrypt"
68+
if ! mount "$PARTITION" -o inlinecrypt "$MOUNT_POINT"; then
69+
log_fail "Failed to mount $PARTITION"
70+
echo "$TESTNAME FAIL" > "$res_file"
71+
exit 1
72+
fi
73+
74+
log_info "Generating 64-byte encryption key"
75+
dd if=/dev/urandom bs=1 count=64 of="$KEY_FILE" status=none
76+
77+
log_info "Adding encryption key with fscryptctl"
78+
identifier=$(fscryptctl add_key "$MOUNT_POINT" < "$KEY_FILE") || {
79+
log_fail "Failed to add key to $MOUNT_POINT"
80+
echo "$TESTNAME FAIL" > "$res_file"
81+
umount "$MOUNT_POINT"
82+
exit 1
83+
}
84+
85+
mkdir -p "$TEST_DIR"
86+
log_info "Applying encryption policy to $TEST_DIR"
87+
fscryptctl set_policy --iv-ino-lblk-64 "$identifier" "$TEST_DIR" || {
88+
log_fail "Failed to set policy on $TEST_DIR"
89+
echo "$TESTNAME FAIL" > "$res_file"
90+
umount "$MOUNT_POINT"
91+
exit 1
92+
}
93+
94+
log_info "Verifying encryption policy"
95+
fscryptctl get_policy "$TEST_DIR"
96+
97+
log_info "Writing and reading test file"
98+
echo "hello" > "$TEST_FILE"
99+
sync
100+
echo 3 > /proc/sys/vm/drop_caches
101+
102+
if grep -q "hello" "$TEST_FILE"; then
103+
log_pass "$TESTNAME : Test Passed"
104+
echo "$TESTNAME PASS" > "$res_file"
105+
else
106+
log_fail "$TESTNAME : Test Failed to verify data"
107+
echo "$TESTNAME FAIL" > "$res_file"
108+
umount "$MOUNT_POINT"
109+
exit 1
110+
fi
111+
112+
umount "$MOUNT_POINT"
113+
log_info "Unmounted $MOUNT_POINT and cleaned up."
114+
115+
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
116+
exit 0
117+

0 commit comments

Comments
 (0)