Commit 2488655b authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'linux_kselftest-next-6.19-rc1' of...

Merge tag 'linux_kselftest-next-6.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kselftest updates from Shuah Khan:

 - Add basic test for trace_marker_raw file to tracing selftest

 - Fix invalid array access in printf dma_map_benchmark selftest

 - Add tprobe enable/disable testcase to tracing selftest

 - Update fprobe selftest for ftrace based fprobe

* tag 'linux_kselftest-next-6.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  selftests: tracing: Update fprobe selftest for ftrace based fprobe
  selftests: tracing: Add tprobe enable/disable testcase
  selftests/run_kselftest.sh: exit with error if tests fail
  selftests/dma: fix invalid array access in printf
  selftests/tracing: Add basic test for trace_marker_raw file
parents 2ddcf496 a2f7990d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ int main(int argc, char **argv)
	}

	printf("dma mapping benchmark: threads:%d seconds:%d node:%d dir:%s granule: %d\n",
			threads, seconds, node, dir[directions], granule);
			threads, seconds, node, directions[dir], granule);
	printf("average map latency(us):%.1f standard deviation:%.1f\n",
			map.avg_map_100ns/10.0, map.map_stddev/10.0);
	printf("average unmap latency(us):%.1f standard deviation:%.1f\n",
+107 −0
Original line number Diff line number Diff line
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Basic tests on writing to trace_marker_raw
# requires: trace_marker_raw
# flags: instance

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)`

	printf "${val}${data}"
}

write_buffer() {
	id=$1
	size=$2

	# write the string into the raw marker
	make_str $id $size > trace_marker_raw
}


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"
		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"
		exit_fail
	fi
}

test_buffer
test_multiple_writes
+4 −14
Original line number Diff line number Diff line
@@ -28,25 +28,21 @@ test -d events/fprobes/myevent1
test -d events/fprobes/myevent2

echo 1 > events/fprobes/myevent1/enable
# Make sure the event is attached and is the only one
# Make sure the event is attached.
grep -q $PLACE enabled_functions
cnt=`cat enabled_functions | wc -l`
if [ $cnt -ne $((ocnt + 1)) ]; then
if [ $cnt -eq $ocnt ]; then
	exit_fail
fi

echo 1 > events/fprobes/myevent2/enable
# It should till be the only attached function
cnt=`cat enabled_functions | wc -l`
if [ $cnt -ne $((ocnt + 1)) ]; then
	exit_fail
fi
cnt2=`cat enabled_functions | wc -l`

echo 1 > events/fprobes/myevent3/enable
# If the function is different, the attached function should be increased
grep -q $PLACE2 enabled_functions
cnt=`cat enabled_functions | wc -l`
if [ $cnt -ne $((ocnt + 2)) ]; then
if [ $cnt -eq $cnt2 ]; then
	exit_fail
fi

@@ -56,12 +52,6 @@ echo "-:myevent2" >> dynamic_events
grep -q myevent1 dynamic_events
! grep -q myevent2 dynamic_events

# should still have 2 left
cnt=`cat enabled_functions | wc -l`
if [ $cnt -ne $((ocnt + 2)) ]; then
	exit_fail
fi

echo 0 > events/fprobes/enable
echo > dynamic_events

+40 −0
Original line number Diff line number Diff line
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Generic dynamic event - enable/disable tracepoint probe events
# requires: dynamic_events "t[:[<group>/][<event>]] <tracepoint> [<args>]":README

echo 0 > events/enable
echo > dynamic_events

TRACEPOINT=sched_switch
ENABLEFILE=events/tracepoints/myprobe/enable

:;: "Add tracepoint event on $TRACEPOINT" ;:

echo "t:myprobe ${TRACEPOINT}" >> dynamic_events

:;: "Check enable/disable to ensure it works" ;:

echo 1 > $ENABLEFILE

grep -q $TRACEPOINT trace

echo 0 > $ENABLEFILE

echo > trace

! grep -q $TRACEPOINT trace

:;: "Repeat enable/disable to ensure it works" ;:

echo 1 > $ENABLEFILE

grep -q $TRACEPOINT trace

echo 0 > $ENABLEFILE

echo > trace

! grep -q $TRACEPOINT trace

exit 0
+10 −4
Original line number Diff line number Diff line
@@ -44,6 +44,12 @@ tap_timeout()
	fi
}

report_failure()
{
	echo "not ok $*"
	echo "$*" >> "$kselftest_failures_file"
}

run_one()
{
	DIR="$1"
@@ -105,7 +111,7 @@ run_one()
	echo "# $TEST_HDR_MSG"
	if [ ! -e "$TEST" ]; then
		echo "# Warning: file $TEST is missing!"
		echo "not ok $test_num $TEST_HDR_MSG"
		report_failure "$test_num $TEST_HDR_MSG"
	else
		if [ -x /usr/bin/stdbuf ]; then
			stdbuf="/usr/bin/stdbuf --output=L "
@@ -123,7 +129,7 @@ run_one()
				interpreter=$(head -n 1 "$TEST" | cut -c 3-)
				cmd="$stdbuf $interpreter ./$BASENAME_TEST"
			else
				echo "not ok $test_num $TEST_HDR_MSG"
				report_failure "$test_num $TEST_HDR_MSG"
				return
			fi
		fi
@@ -137,9 +143,9 @@ run_one()
			echo "ok $test_num $TEST_HDR_MSG # SKIP"
		elif [ $rc -eq $timeout_rc ]; then \
			echo "#"
			echo "not ok $test_num $TEST_HDR_MSG # TIMEOUT $kselftest_timeout seconds"
			report_failure "$test_num $TEST_HDR_MSG # TIMEOUT $kselftest_timeout seconds"
		else
			echo "not ok $test_num $TEST_HDR_MSG # exit=$rc"
			report_failure "$test_num $TEST_HDR_MSG # exit=$rc"
		fi)
		cd - >/dev/null
	fi
Loading