Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,3 @@
#!/bin/sh
# description: Basic trace file check
test -f README -a -f trace -a -f tracing_on -a -f trace_pipe
@@ -0,0 +1,9 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Basic test for tracers
# flags: instance
test -f available_tracers
for t in `cat available_tracers`; do
echo $t > current_tracer
done
echo nop > current_tracer
@@ -0,0 +1,10 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Basic trace clock test
# flags: instance
test -f trace_clock
for c in `cat trace_clock | tr -d \[\]`; do
echo $c > trace_clock
grep '\['$c'\]' trace_clock
done
echo local > trace_clock
@@ -0,0 +1,5 @@
#!/bin/sh
# description: Basic event tracing check
test -f available_events -a -f set_event -a -d events
# check scheduler events are available
grep -q sched available_events && exit_pass || exit_fail
@@ -0,0 +1,101 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Test tracefs GID mount option
# requires: "[gid=<gid>]":README
fail() {
local msg="$1"
echo "FAILED: $msg"
exit_fail
}
find_alternate_gid() {
local original_gid="$1"
tac /etc/group | grep -v ":$original_gid:" | head -1 | cut -d: -f3
}
remount_tracefs_with_options() {
local mount_point="$1"
local options="$2"
mount -t tracefs -o "remount,$options" nodev "$mount_point"
setup
}
unmount_tracefs() {
local mount_point="$1"
# Need to make sure the mount isn't busy so that we can umount it
(cd $mount_point; finish_system;)
cleanup
}
create_instance() {
local mount_point="$1"
local instance="$mount_point/instances/$(mktemp -u test-XXXXXX)"
mkdir "$instance"
echo "$instance"
}
remove_instance() {
local instance="$1"
rmdir "$instance"
}
check_gid() {
local mount_point="$1"
local expected_gid="$2"
echo "Checking permission group ..."
cd "$mount_point"
for file in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable"; do
local gid=`stat -c "%g" $file`
if [ "$gid" -ne "$expected_gid" ]; then
cd - # Return to the previous working directory (tracefs root)
fail "$(realpath $file): Expected group $expected_gid; Got group $gid"
fi
done
cd - # Return to the previous working directory (tracefs root)
}
test_gid_mount_option() {
local mount_point=$(get_mount_point)
local mount_options=$(get_mnt_options "$mount_point")
local original_group=$(stat -c "%g" .)
local other_group=$(find_alternate_gid "$original_group")
# Set up mount options with new GID for testing
local new_options=`echo "$mount_options" | sed -e "s/gid=[0-9]*/gid=$other_group/"`
if [ "$new_options" = "$mount_options" ]; then
new_options="$mount_options,gid=$other_group"
mount_options="$mount_options,gid=$original_group"
fi
# Unmount existing tracefs instance and mount with new GID
unmount_tracefs "$mount_point"
remount_tracefs_with_options "$mount_point" "$new_options"
check_gid "$mount_point" "$other_group"
# Check that files created after the mount inherit the GID
local instance=$(create_instance "$mount_point")
check_gid "$instance" "$other_group"
remove_instance "$instance"
# Unmount and remount with the original GID
unmount_tracefs "$mount_point"
remount_tracefs_with_options "$mount_point" "$mount_options"
check_gid "$mount_point" "$original_group"
}
test_gid_mount_option
exit 0
@@ -0,0 +1,22 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Change the ringbuffer size
# flags: instance
rb_size_test() {
ORIG=`cat buffer_size_kb`
expr $ORIG / 2 > buffer_size_kb
expr $ORIG \* 2 > buffer_size_kb
echo $ORIG > buffer_size_kb
}
rb_size_test
: "If per-cpu buffer is supported, imbalance it"
if [ -d per_cpu/cpu0 ]; then
cd per_cpu/cpu0
rb_size_test
fi
@@ -0,0 +1,95 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Change the ringbuffer sub-buffer size
# requires: buffer_subbuf_size_kb
# flags: instance
get_buffer_data_size() {
sed -ne 's/^.*data.*size:\([0-9][0-9]*\).*/\1/p' events/header_page
}
get_buffer_data_offset() {
sed -ne 's/^.*data.*offset:\([0-9][0-9]*\).*/\1/p' events/header_page
}
get_event_header_size() {
type_len=`sed -ne 's/^.*type_len.*:[^0-9]*\([0-9][0-9]*\).*/\1/p' events/header_event`
time_len=`sed -ne 's/^.*time_delta.*:[^0-9]*\([0-9][0-9]*\).*/\1/p' events/header_event`
array_len=`sed -ne 's/^.*array.*:[^0-9]*\([0-9][0-9]*\).*/\1/p' events/header_event`
total_bits=$((type_len+time_len+array_len))
total_bits=$((total_bits+7))
echo $((total_bits/8))
}
get_print_event_buf_offset() {
sed -ne 's/^.*buf.*offset:\([0-9][0-9]*\).*/\1/p' events/ftrace/print/format
}
event_header_size=`get_event_header_size`
print_header_size=`get_print_event_buf_offset`
data_offset=`get_buffer_data_offset`
marker_meta=$((event_header_size+print_header_size))
make_str() {
cnt=$1
printf -- 'X%.0s' $(seq $cnt)
}
write_buffer() {
size=$1
str=`make_str $size`
# clear the buffer
echo > trace
# write the string into the marker
echo $str > trace_marker
echo $str
}
test_buffer() {
size_kb=$1
page_size=$((size_kb*1024))
size=`get_buffer_data_size`
# the size must be greater than or equal to page_size - data_offset
page_size=$((page_size-data_offset))
if [ $size -lt $page_size ]; then
exit fail
fi
# Now add a little more the meta data overhead will overflow
str=`write_buffer $size`
# Make sure the line was broken
new_str=`awk ' /tracing_mark_write:/ { sub(/^.*tracing_mark_write: /,"");printf "%s", $0; exit}' trace`
if [ "$new_str" = "$str" ]; then
exit fail;
fi
# Make sure the entire line can be found
new_str=`awk ' /tracing_mark_write:/ { sub(/^.*tracing_mark_write: /,"");printf "%s", $0; }' trace`
if [ "$new_str" != "$str" ]; then
exit fail;
fi
}
ORIG=`cat buffer_subbuf_size_kb`
# Could test bigger sizes than 32K, but then creating the string
# to write into the ring buffer takes too long
for a in 4 8 16 32 ; do
echo $a > buffer_subbuf_size_kb
test_buffer $a
done
echo $ORIG > buffer_subbuf_size_kb
@@ -0,0 +1,27 @@
#!/bin/sh
# description: Snapshot and tracing setting
# requires: snapshot
# flags: instance
echo "Set tracing off"
echo 0 > tracing_on
echo "Allocate and take a snapshot"
echo 1 > snapshot
# Since trace buffer is empty, snapshot is also empty, but allocated
grep -q "Snapshot is allocated" snapshot
echo "Ensure keep tracing off"
test `cat tracing_on` -eq 0
echo "Set tracing on"
echo 1 > tracing_on
echo "Take a snapshot again"
echo 1 > snapshot
echo "Ensure keep tracing on"
test `cat tracing_on` -eq 1
exit 0
@@ -0,0 +1,31 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Snapshot and tracing_cpumask
# requires: trace_marker tracing_cpumask snapshot
# flags: instance
# This testcase is constrived to reproduce a problem that the cpu buffers
# become unavailable which is due to 'record_disabled' of array_buffer and
# max_buffer being messed up.
# Store origin cpumask
ORIG_CPUMASK=`cat tracing_cpumask`
# Stop tracing all cpu
echo 0 > tracing_cpumask
# Take a snapshot of the main buffer
echo 1 > snapshot
# Restore origin cpumask, note that there should be some cpus being traced
echo ${ORIG_CPUMASK} > tracing_cpumask
# Set tracing on
echo 1 > tracing_on
# Write a log into buffer
echo "test input 1" > trace_marker
# Ensure the log writed so that cpu buffers are still available
grep -q "test input 1" trace
exit 0
@@ -0,0 +1,122 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Test file and directory ownership changes for eventfs
# requires: "[gid=<gid>]":README
original_group=`stat -c "%g" .`
original_owner=`stat -c "%u" .`
mount_point=$(get_mount_point)
mount_options=$(get_mnt_options "$mount_point")
# find another owner and group that is not the original
other_group=`tac /etc/group | grep -v ":$original_group:" | head -1 | cut -d: -f3`
other_owner=`tac /etc/passwd | grep -v ":$original_owner:" | head -1 | cut -d: -f3`
# Remove any group ownership already
new_options=`echo "$mount_options" | sed -e "s/gid=[0-9]*/gid=$other_group/"`
if [ "$new_options" = "$mount_options" ]; then
new_options="$mount_options,gid=$other_group"
mount_options="$mount_options,gid=$original_group"
fi
canary="events/timer events/timer/timer_cancel events/timer/timer_cancel/format"
test() {
file=$1
test_group=$2
owner=`stat -c "%u" $file`
group=`stat -c "%g" $file`
echo "testing $file $owner=$original_owner and $group=$test_group"
if [ $owner -ne $original_owner ]; then
exit_fail
fi
if [ $group -ne $test_group ]; then
exit_fail
fi
# Note, the remount does not update ownership so test going to and from owner
echo "test owner $file to $other_owner"
chown $other_owner $file
owner=`stat -c "%u" $file`
if [ $owner -ne $other_owner ]; then
exit_fail
fi
chown $original_owner $file
owner=`stat -c "%u" $file`
if [ $owner -ne $original_owner ]; then
exit_fail
fi
}
run_tests() {
for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
test "$d" $other_group
done
chgrp $original_group events
test "events" $original_group
for d in "." "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
test "$d" $other_group
done
chgrp $original_group events/sched
test "events/sched" $original_group
for d in "." "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
test "$d" $other_group
done
chgrp $original_group events/sched/sched_switch
test "events/sched/sched_switch" $original_group
for d in "." "events/sched/sched_switch/enable" $canary; do
test "$d" $other_group
done
chgrp $original_group events/sched/sched_switch/enable
test "events/sched/sched_switch/enable" $original_group
for d in "." $canary; do
test "$d" $other_group
done
}
# Run the tests twice as leftovers can cause issues
for loop in 1 2 ; do
echo "Running iteration $loop"
mount -o remount,"$new_options" .
run_tests
mount -o remount,"$mount_options" .
for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
test "$d" $original_group
done
# check instances as well
chgrp $other_group instances
instance="$(mktemp -u test-XXXXXX)"
mkdir instances/$instance
cd instances/$instance
run_tests
cd ../..
rmdir instances/$instance
chgrp $original_group instances
done
exit 0
@@ -0,0 +1,82 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Basic tests on writing to trace_marker
# requires: trace_marker
# flags: instance
get_buffer_data_size() {
sed -ne 's/^.*data.*size:\([0-9][0-9]*\).*/\1/p' events/header_page
}
get_buffer_data_offset() {
sed -ne 's/^.*data.*offset:\([0-9][0-9]*\).*/\1/p' events/header_page
}
get_event_header_size() {
type_len=`sed -ne 's/^.*type_len.*:[^0-9]*\([0-9][0-9]*\).*/\1/p' events/header_event`
time_len=`sed -ne 's/^.*time_delta.*:[^0-9]*\([0-9][0-9]*\).*/\1/p' events/header_event`
array_len=`sed -ne 's/^.*array.*:[^0-9]*\([0-9][0-9]*\).*/\1/p' events/header_event`
total_bits=$((type_len+time_len+array_len))
total_bits=$((total_bits+7))
echo $((total_bits/8))
}
get_print_event_buf_offset() {
sed -ne 's/^.*buf.*offset:\([0-9][0-9]*\).*/\1/p' events/ftrace/print/format
}
event_header_size=`get_event_header_size`
print_header_size=`get_print_event_buf_offset`
data_offset=`get_buffer_data_offset`
marker_meta=$((event_header_size+print_header_size))
make_str() {
cnt=$1
# subtract two for \n\0 as marker adds these
cnt=$((cnt-2))
printf -- 'X%.0s' $(seq $cnt)
}
write_buffer() {
size=$1
str=`make_str $size`
# clear the buffer
echo > trace
# write the string into the marker
echo -n $str > trace_marker
echo $str
}
test_buffer() {
size=`get_buffer_data_size`
oneline_size=$((size-marker_meta))
echo size = $size
echo meta size = $marker_meta
# Now add a little more the meta data overhead will overflow
str=`write_buffer $size`
# Make sure the line was broken
new_str=`awk ' /tracing_mark_write:/ { sub(/^.*tracing_mark_write: /,"");printf "%s", $0; exit}' trace`
if [ "$new_str" = "$str" ]; then
exit fail;
fi
# Make sure the entire line can be found
new_str=`awk ' /tracing_mark_write:/ { sub(/^.*tracing_mark_write: /,"");printf "%s", $0; }' trace`
if [ "$new_str" != "$str" ]; then
exit fail;
fi
}
test_buffer
@@ -0,0 +1,133 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Basic tests on writing to trace_marker_raw
# requires: trace_marker_raw
# flags: instance
check_awk_strtonum || exit_unresolved
is_little_endian() {
if lscpu | grep -q 'Little Endian'; then
echo 1;
else
echo 0;
fi
}
little=`is_little_endian`
make_str() {
id=$1
cnt=$2
if [ $little -eq 1 ]; then
val=`printf "\\%03o\\%03o\\%03o\\%03o" \
$(($id & 0xff)) \
$((($id >> 8) & 0xff)) \
$((($id >> 16) & 0xff)) \
$((($id >> 24) & 0xff))`
else
val=`printf "\\%03o\\%03o\\%03o\\%03o" \
$((($id >> 24) & 0xff)) \
$((($id >> 16) & 0xff)) \
$((($id >> 8) & 0xff)) \
$(($id & 0xff))`
fi
data=`printf -- 'X%.0s' $(seq $cnt)`
# Return escape-sequence text (e.g. "\003\000..."); the caller
# converts to binary. Shell command substitution strips NUL bytes,
# so the binary form cannot survive being captured into a variable.
printf '%s' "${val}${data}"
}
write_buffer() {
id=$1
size=$2
str=`make_str $id $size`
len=`printf "$str" | wc -c`
# Pipe through dd to ensure a single atomic write() syscall
# on architectures with 64K pages, where shell's printf builtin
# uses stdio buffering which may split the output into multiple
# writes.
printf "$str" | dd of=trace_marker_raw bs=$len iflag=fullblock
}
test_multiple_writes() {
# Write a bunch of data where the id is the count of
# data to write
for i in `seq 1 10` `seq 101 110` `seq 1001 1010`; do
write_buffer $i $i
done
# add a little buffer
echo stop > trace_marker
# Check to make sure the number of entries is the id (rounded up by 4)
awk '/.*: # [0-9a-f]* / {
print;
cnt = -1;
for (i = 0; i < NF; i++) {
# The counter is after the "#" marker
if ( $i == "#" ) {
i++;
cnt = strtonum("0x" $i);
num = NF - (i + 1);
# The number of items is always rounded up by 4
cnt2 = int((cnt + 3) / 4) * 4;
if (cnt2 != num) {
exit 1;
}
break;
}
}
}
// { if (NR > 30) { exit 0; } } ' trace_pipe;
}
get_buffer_data_size() {
sed -ne 's/^.*data.*size:\([0-9][0-9]*\).*/\1/p' events/header_page
}
test_buffer() {
# The id must be four bytes, test that 3 bytes fails a write
if echo -n abc > ./trace_marker_raw ; then
echo "Too small of write expected to fail but did not"
echo ${ORIG} > buffer_size_kb
exit_fail
fi
size=`get_buffer_data_size`
echo size = $size
# Now add a little more than what it can handle
if write_buffer 0xdeadbeef $size ; then
echo "Too big of write expected to fail but did not"
echo ${ORIG} > buffer_size_kb
exit_fail
fi
}
ORIG=`cat buffer_size_kb`
# test_multiple_writes test needs at least 12KB buffer
NEW_SIZE=12
if [ ${ORIG} -lt ${NEW_SIZE} ]; then
echo ${NEW_SIZE} > buffer_size_kb
fi
test_buffer
if ! test_multiple_writes; then
echo ${ORIG} > buffer_size_kb
exit_fail
fi
echo ${ORIG} > buffer_size_kb
@@ -0,0 +1,15 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: trace_pipe and trace_marker
# requires: trace_marker
# flags: instance
echo "test input 1" > trace_marker
: "trace interface never consume the ring buffer"
grep -q "test input 1" trace
grep -q "test input 1" trace
: "trace interface never consume the ring buffer"
head -n 1 trace_pipe | grep -q "test input 1"
! grep -q "test input 1" trace