1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0 3# description: Test creation and deletion of trace instances while setting an event 4# requires: instances 5 6fail() { # mesg 7 rmdir foo 2>/dev/null 8 echo $1 9 set -e 10 exit_fail 11} 12 13cd instances 14 15# we don't want to fail on error 16set +e 17 18mkdir x 19rmdir x 20result=$? 21 22if [ $result -ne 0 ]; then 23 echo "instance rmdir not supported" 24 exit_unsupported 25fi 26 27instance_slam() { 28 while :; do 29 mkdir foo 2> /dev/null 30 rmdir foo 2> /dev/null 31 done 32} 33 34instance_read() { 35 while :; do 36 cat foo/trace 1> /dev/null 2>&1 37 done 38} 39 40instance_set() { 41 while :; do 42 echo 1 > foo/events/sched/sched_switch 43 done 2> /dev/null 44} 45 46instance_slam & 47p1=$! 48echo $p1 49 50instance_set & 51p2=$! 52echo $p2 53 54instance_read & 55p3=$! 56echo $p3 57 58sleep 1 59 60kill -1 $p3 61kill -1 $p2 62kill -1 $p1 63 64echo "Wait for processes to finish" 65wait $p1 $p2 $p3 66echo "all processes finished, wait for cleanup" 67sleep 1 68 69mkdir foo 70ls foo > /dev/null 71rmdir foo 72if [ -d foo ]; then 73 fail "foo still exists" 74fi 75 76mkdir foo 77echo "schedule:enable_event:sched:sched_switch" > foo/set_ftrace_filter 78rmdir foo 79if [ -d foo ]; then 80 fail "foo still exists" 81fi 82if grep -q "schedule:enable_event:sched:sched_switch" ../set_ftrace_filter; then 83 echo "Older kernel detected. Cleanup filter" 84 echo '!schedule:enable_event:sched:sched_switch' > ../set_ftrace_filter 85fi 86 87instance_slam() { 88 while :; do 89 mkdir x 90 mkdir y 91 mkdir z 92 rmdir x 93 rmdir y 94 rmdir z 95 done 2>/dev/null 96} 97 98instance_slam & 99p1=$! 100echo $p1 101 102instance_slam & 103p2=$! 104echo $p2 105 106instance_slam & 107p3=$! 108echo $p3 109 110instance_slam & 111p4=$! 112echo $p4 113 114instance_slam & 115p5=$! 116echo $p5 117 118ls -lR >/dev/null 119sleep 1 120 121kill -1 $p1 122kill -1 $p2 123kill -1 $p3 124kill -1 $p4 125kill -1 $p5 126 127echo "Wait for processes to finish" 128wait $p1 $p2 $p3 $p4 $p5 129echo "all processes finished, wait for cleanup" 130 131mkdir x y z 132ls x y z 133rmdir x y z 134for d in x y z; do 135 if [ -d $d ]; then 136 fail "instance $d still exists" 137 fi 138done 139 140set -e 141 142exit 0 143