Skip to content

Commit cf5efac

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 330c16e commit cf5efac

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# shmbridge Validation Test
2+
3+
## 📌 Overview
4+
5+
This test case validates the encryption and access functionality of the `shmbridge` partition by:
6+
7+
- Formatting the partition with ext4 and encryption options
8+
- Mounting it with `inlinecrypt`
9+
- Adding an encryption key using `fscryptctl`
10+
- Setting and verifying an encryption policy
11+
- Writing and reading a test file to confirm data integrity
12+
13+
## How to Run
14+
15+
```sh
16+
source init_env
17+
cd suites/Kernel/FunctionalArea/baseport/shmbridge
18+
./run.sh
19+
```
20+
21+
## Prerequisites
22+
- `fscryptctl` must be available
23+
- Root access is required
24+
- Partition /dev/disk/by-partlabel/xbl_ramdump_a must exist and be accessible
25+
26+
## Result Format
27+
28+
Test result will be saved in shmbridge.res as:
29+
✅ Pass Criteria
30+
- Partition is found and formatted
31+
- Encryption key is added and policy is set
32+
- Test file is written and read successfully
33+
- `Test Passed` – if all validations succeed
34+
<!-- -->
35+
❌ Fail Criteria
36+
- Partition not found
37+
- Encryption setup fails
38+
- Test file cannot be read or content mismatch
39+
- `Test Failed` – if any check fails
40+
41+
## 📄 Output
42+
A .res file is generated in the same directory:
43+
44+
`PASS shmbridge` OR `FAIL shmbridge`
45+
46+
## License
47+
48+
SPDX-License-Identifier: BSD-3-Clause-Clear
49+
(C) Qualcomm Technologies, Inc. and/or its subsidiaries.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 is available"
44+
check_dependencies fscryptctl
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+
head -c 64 /dev/urandom > "$KEY_FILE"
74+
75+
log_info "Checking if dependency binary is available"
76+
check_dependencies fscryptctl
77+
78+
log_info "Adding encryption key using fscryptctl"
79+
identifier=$(fscryptctl add_key "$MOUNT_POINT" < "$KEY_FILE")
80+
81+
mkdir -p "$TEST_DIR"
82+
83+
log_info "Setting encryption policy on $TEST_DIR"
84+
fscryptctl set_policy --iv-ino-lblk-64 "$identifier" "$TEST_DIR"
85+
86+
log_info "Verifying encryption policy"
87+
fscryptctl get_policy "$TEST_DIR"
88+
89+
log_info "Writing test file"
90+
echo "hello" > "$TEST_FILE"
91+
sync
92+
echo 3 > /proc/sys/vm/drop_caches
93+
94+
log_info "Reading test file"
95+
if cat "$TEST_FILE" | grep -q "hello"; then
96+
log_pass "$TESTNAME : Test Passed"
97+
echo "PASS $TESTNAME" > "$res_file"
98+
else
99+
log_fail "$TESTNAME : Test Failed"
100+
echo "FAIL $TESTNAME" > "$res_file"
101+
exit 1
102+
fi
103+
104+
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
105+

0 commit comments

Comments
 (0)