Skip to content

Commit fbc509e

Browse files
committed
kernel: add shared interrupt counter parsing helpers
Add reusable helpers in Runner/utils/functestlib.sh for interrupt-based tests: - get_interrupt_line_by_name() - extract_interrupt_cpu_counts() - count_interrupt_cpu_counts() These helpers parse only numeric per-CPU interrupt counters from /proc/interrupts and avoid hardcoded assumptions about CPU count. Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
1 parent 5036042 commit fbc509e

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Runner/utils/functestlib.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4687,3 +4687,40 @@ file_size_bytes() {
46874687
printf '%s\n' "$size"
46884688
return 0
46894689
}
4690+
4691+
# Return the first /proc/interrupts line matching the given pattern.
4692+
# Prints the full line and returns 0 on success, 1 if no match is found.
4693+
get_interrupt_line_by_name() {
4694+
pattern="$1"
4695+
[ -n "$pattern" ] || return 1
4696+
grep "$pattern" /proc/interrupts 2>/dev/null | head -n 1
4697+
}
4698+
4699+
# Extract only numeric per-CPU interrupt counters from a /proc/interrupts line.
4700+
# Prints one counter per line, stopping at the first non-numeric token after the IRQ field.
4701+
extract_interrupt_cpu_counts() {
4702+
printf '%s\n' "$1" | awk '
4703+
{
4704+
seen_irq = 0
4705+
for (i = 1; i <= NF; i++) {
4706+
if (seen_irq == 0) {
4707+
if ($i ~ /:$/) {
4708+
seen_irq = 1
4709+
}
4710+
continue
4711+
}
4712+
if ($i ~ /^[0-9]+$/) {
4713+
print $i
4714+
} else {
4715+
break
4716+
}
4717+
}
4718+
}
4719+
'
4720+
}
4721+
4722+
# Count extracted per-CPU interrupt counters.
4723+
# Prints the count as a decimal integer.
4724+
count_interrupt_cpu_counts() {
4725+
printf '%s\n' "$1" | awk 'NF { c++ } END { print c + 0 }'
4726+
}

0 commit comments

Comments
 (0)