Skip to content

Commit bcd467f

Browse files
committed
review
Signed-off-by: Vamsee Narapareddi <vnarapar@qti.qualcomm.com>
1 parent 812acf6 commit bcd467f

File tree

2 files changed

+67
-37
lines changed

2 files changed

+67
-37
lines changed

Runner/suites/Kernel/Baseport/cma/cma.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ metadata:
1717

1818
run:
1919
steps:
20-
- cd $PWD/suites/Kernel/Baseport/cma
20+
- REPO_PATH=$PWD
21+
- cd Runner/suites/Kernel/Baseport/cma
2122
- ./run.sh
23+
- $REPO_PATH/Runner/utils/send-to-lava.sh cma.res

Runner/suites/Kernel/Baseport/cma/run.sh

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,30 @@ OPTIONAL_CMA_CONFIGS="CONFIG_CMA_SIZE_MBYTES CONFIG_CMA_SIZE_SEL_MBYTES CONFIG_C
5555

5656
log_info "Checking optional CMA configurations..."
5757
for cfg in $OPTIONAL_CMA_CONFIGS; do
58-
if check_kernel_config "$cfg" 2>/dev/null; then
59-
value=$(grep "^$cfg=" /proc/config.gz 2>/dev/null | cut -d'=' -f2 || echo "enabled")
60-
log_info " $cfg: $value"
58+
if check_optional_config "$cfg" 2>/dev/null; then
59+
log_pass " $cfg: enabled"
6160
else
62-
log_info " $cfg: not set (optional)"
61+
log_warn " $cfg: not enabled (optional)"
6362
fi
6463
done
6564

65+
if check_kernel_config "CONFIG_CMA_DEBUGFS" 2>/dev/null; then
66+
log_pass "CONFIG_CMA_DEBUGFS: enabled"
67+
if [ ! -d "/sys/kernel/debug/cma" ]; then
68+
if [ ! -d "/sys/kernel/debug" ]; then
69+
log_info "CONFIG_CMA_DEBUGFS is enabled but debugfs is not mounted"
70+
log_info "Mounting debugfs"
71+
if mount -t debugfs debugfs /sys/kernel/debug 2>/dev/null; then
72+
log_pass "debugfs mounted successfully"
73+
else
74+
log_warn "Could not mount debugfs — CMA debugfs checks will be skipped"
75+
fi
76+
else
77+
log_warn "CONFIG_CMA_DEBUGFS is enabled but /sys/kernel/debug/cma not found"
78+
fi
79+
fi
80+
fi
81+
6682
log_info "=== CMA Memory Statistics ==="
6783

6884
if [ -f "/proc/meminfo" ]; then
@@ -114,53 +130,67 @@ fi
114130

115131
log_info "=== CMA Initialization and Runtime ==="
116132

117-
# Check dmesg for CMA initialization
118-
if dmesg | grep -i -q "cma.*reserved"; then
133+
# Capture dmesg once to a temp file to avoid subshell issues (pass=false inside
134+
# a pipe subshell would not propagate to the outer shell) and to avoid running
135+
# dmesg multiple times.
136+
dmesg_tmp=$(mktemp /tmp/cma_dmesg.XXXXXX 2>/dev/null || echo "/tmp/cma_dmesg_$$.tmp")
137+
dmesg > "$dmesg_tmp" 2>/dev/null
138+
139+
# Broaden CMA reservation patterns to cover multiple kernel variants:
140+
# cma: Reserved N MiB at ... (common upstream)
141+
# CMA: Reserved N MiB at ... (some arch variants)
142+
# Reserved memory: created CMA memory pool at ...
143+
# OF: reserved mem: initialized node linux,cma ...
144+
# reserved mem.*CMA (generic DT path)
145+
CMA_INIT_PATTERN="cma:.*reserved|reserved memory:.*cma|linux,cma|of:.*reserved mem.*cma"
146+
147+
if grep -i -q -E "$CMA_INIT_PATTERN" "$dmesg_tmp" 2>/dev/null; then
119148
log_pass "CMA initialization messages found in dmesg:"
120-
121-
dmesg | grep -i "cma.*reserved" | tail -n 5 | while IFS= read -r line; do
149+
grep -i -E "$CMA_INIT_PATTERN" "$dmesg_tmp" 2>/dev/null | tail -n 5 | while IFS= read -r line; do
122150
log_info " $line"
123151
done
124152
else
125153
log_fail "No CMA initialization messages found in dmesg"
126-
pass=false
154+
pass=false
127155
fi
128156

129-
if dmesg | grep -i -q "cma.*alloc\|cma.*release"; then
157+
# CMA allocation/release activity (informational only)
158+
if grep -i -q -E "cma.*alloc|cma.*release" "$dmesg_tmp" 2>/dev/null; then
130159
log_info "CMA allocation/release activity detected"
131-
alloc_count=$(dmesg | grep -i -c "cma.*alloc" || echo 0)
132-
release_count=$(dmesg | grep -i -c "cma.*release" || echo 0)
160+
alloc_count=$(grep -i -c "cma.*alloc" "$dmesg_tmp" 2>/dev/null || echo 0)
161+
release_count=$(grep -i -c "cma.*release" "$dmesg_tmp" 2>/dev/null || echo 0)
133162
log_info " Allocations: $alloc_count"
134163
log_info " Releases: $release_count"
135164
fi
136165

137-
if dmesg | grep -i "cma" | grep -i -q "error\|fail\|warn"; then
166+
# Check for CMA errors/warnings — capture to variable (not a pipe) so pass=false works
167+
cma_errors=$(grep -i "cma" "$dmesg_tmp" 2>/dev/null | grep -i "error\|fail\|warn" || true)
168+
if [ -n "$cma_errors" ]; then
138169
log_fail "CMA warnings/errors found in dmesg:"
139-
pass=false
140-
dmesg | grep -i "cma" | grep -i "error\|fail\|warn" | tail -n 3 | while IFS= read -r line; do
170+
pass=false
171+
printf '%s\n' "$cma_errors" | tail -n 3 | while IFS= read -r line; do
141172
log_warn " $line"
142173
done
143174
fi
144175

176+
rm -f "$dmesg_tmp"
177+
145178
log_info "=== CMA Sysfs/Debugfs Interface ==="
146179

147180
if [ -d "/sys/kernel/debug/cma" ]; then
148181
log_info "Found CMA debugfs: /sys/kernel/debug/cma"
149-
150-
# List CMA areas
151-
if [ -d "/sys/kernel/debug/cma" ]; then
152-
cma_area_count=0
153-
for area in /sys/kernel/debug/cma/*; do
154-
if [ -d "$area" ]; then
155-
area_name=$(basename "$area")
156-
log_info " CMA area: $area_name"
157-
cma_area_count=$((cma_area_count + 1))
158-
fi
159-
done
160-
log_info " Total CMA areas: $cma_area_count"
161-
fi
182+
183+
cma_area_count=0
184+
for area in /sys/kernel/debug/cma/*; do
185+
if [ -d "$area" ]; then
186+
area_name=$(basename "$area")
187+
log_info " CMA area: $area_name"
188+
cma_area_count=$((cma_area_count + 1))
189+
fi
190+
done
191+
log_info " Total CMA areas: $cma_area_count"
162192
else
163-
log_warn "CMA debugfs not found (may need debugfs mounted)"
193+
log_warn "CMA debugfs not found (may need debugfs mounted or CONFIG_CMA_DEBUGFS enabled)"
164194
fi
165195

166196
if [ -f "/proc/vmstat" ]; then
@@ -169,20 +199,18 @@ if [ -f "/proc/vmstat" ]; then
169199
grep "cma" /proc/vmstat | while IFS= read -r line; do
170200
log_info " $line"
171201
done
172-
else
173-
log_fail "CMA statistics not found in /proc/vmstat:"
174-
pass=false
202+
else
203+
log_fail "CMA statistics not found in /proc/vmstat"
204+
pass=false
175205
fi
176206
fi
177207

178-
log_info "================================================================================"
179-
180208
if $pass; then
181209
log_pass "$TESTNAME : Test Passed"
182210
echo "$TESTNAME PASS" > "$res_file"
183-
exit 0
184211
else
185212
log_fail "$TESTNAME : Test Failed"
186213
echo "$TESTNAME FAIL" > "$res_file"
187-
exit 1
188214
fi
215+
log_info "================================================================================"
216+
exit 0

0 commit comments

Comments
 (0)