xref: /linux/tools/perf/tests/shell/test_perf_data_converter_ctf.sh (revision c7decec2f2d2ab0366567f9e30c0e1418cece43f)
1#!/bin/bash
2# 'perf data convert --to-ctf' command test
3# SPDX-License-Identifier: GPL-2.0
4
5set -e
6
7err=0
8
9perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
10ctf_dir=$(mktemp -d /tmp/__perf_test.ctf.XXXXX)
11
12cleanup()
13{
14	rm -f "${perfdata}"
15	rm -rf "${ctf_dir}"
16	trap - exit term int
17}
18
19trap_cleanup()
20{
21	echo "Unexpected signal in ${FUNCNAME[1]}"
22	cleanup
23	exit ${err}
24}
25trap trap_cleanup exit term int
26
27check_babeltrace_support()
28{
29	if ! perf check feature libbabeltrace
30	then
31		echo "perf not linked with libbabeltrace, skipping test"
32		exit 2
33	fi
34}
35
36test_ctf_converter_file()
37{
38	echo "Testing Perf Data Conversion Command to CTF (File input)"
39	# Record some data
40	if ! perf record -o "$perfdata" -F 99 -g -- perf test -w noploop
41	then
42		echo "Failed to record perf data"
43		err=1
44		return
45	fi
46
47	# Cleanup previous ctf dir
48	rm -rf "${ctf_dir}"
49
50	# Convert
51	if ! perf data convert --to-ctf "$ctf_dir" --force -i "$perfdata"
52	then
53		echo "Perf Data Converter Command to CTF (File input) [FAILED]"
54		err=1
55		return
56	fi
57
58	if [ -d "${ctf_dir}" ] && [ "$(ls -A "${ctf_dir}")" ]
59	then
60		echo "Perf Data Converter Command to CTF (File input) [SUCCESS]"
61	else
62		echo "Perf Data Converter Command to CTF (File input) [FAILED]"
63		echo "    Output directory empty or missing"
64		err=1
65	fi
66}
67
68test_ctf_converter_pipe()
69{
70	echo "Testing Perf Data Conversion Command to CTF (Pipe mode)"
71
72	# Cleanup previous ctf dir
73	rm -rf "${ctf_dir}"
74
75	# Record to stdout and pipe to $perfdata file
76	if ! perf record -o - -F 99 -g -- perf test -w noploop > "$perfdata"
77	then
78		echo "Failed to record perf data"
79		err=1
80		return
81	fi
82
83	if ! perf data convert --to-ctf "$ctf_dir" --force -i "$perfdata"
84	then
85		echo "Perf Data Converter Command to CTF (Pipe mode) [FAILED]"
86		err=1
87		return
88	fi
89
90	if [ -d "${ctf_dir}" ] && [ "$(ls -A "${ctf_dir}")" ]
91	then
92		echo "Perf Data Converter Command to CTF (Pipe mode) [SUCCESS]"
93	else
94		echo "Perf Data Converter Command to CTF (Pipe mode) [FAILED]"
95		echo "    Output directory empty or missing"
96		err=1
97	fi
98}
99
100check_babeltrace_support
101test_ctf_converter_file
102test_ctf_converter_pipe
103
104exit ${err}
105