perf tests: Add daemon 'lock' test
authorJiri Olsa <jolsa@kernel.org>
Mon, 8 Feb 2021 20:09:08 +0000 (21:09 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 11 Feb 2021 13:19:53 +0000 (10:19 -0300)
Add a test for the perf daemon 'lock' command ensuring only one instance
of daemon can run over one base directory.

Committer testing:

  [root@five ~]# perf test -v daemon
  76: daemon operations                                               :
  --- start ---
  test child forked, pid 793255
  test daemon list
  test daemon reconfig
  test daemon stop
  test daemon signal
  signal 12 sent to session 'test [793506]'
  signal 12 sent to session 'test [793506]'
  test daemon ping
  test daemon lock
  test child finished with 0
  ---- end ----
  daemon operations: Ok
  [root@five ~]#

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Budankov <abudankov@huawei.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: https://lore.kernel.org/r/20210208200908.1019149-25-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/shell/daemon.sh

index 9fcb987..e5b824d 100755 (executable)
@@ -426,6 +426,43 @@ EOF
        rm -f ${config}
 }
 
+test_lock()
+{
+       echo "test daemon lock"
+
+       local config=$(mktemp /tmp/perf.daemon.config.XXX)
+       local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
+
+       # prepare config
+       cat <<EOF > ${config}
+[daemon]
+base=BASE
+
+[session-size]
+run = -e cpu-clock
+EOF
+
+       sed -i -e "s|BASE|${base}|" ${config}
+
+       # start daemon
+       daemon_start ${config} size
+
+       # start second daemon over the same config/base
+       failed=`perf daemon start --config ${config} 2>&1 | awk '{ print $1 }'`
+
+       # check that we failed properly
+       if [ ${failed} != "failed:" ]; then
+               error=1
+               echo "FAILED: daemon lock failed"
+       fi
+
+       # stop daemon
+       daemon_exit ${base} ${config}
+
+       rm -rf ${base}
+       rm -f ${config}
+}
+
 error=0
 
 test_list
@@ -433,5 +470,6 @@ test_reconfig
 test_stop
 test_signal
 test_ping
+test_lock
 
 exit ${error}