brintos

brintos / linux-shallow public Read only

0
0
Text · 1.3 KiB · c4f1b59 Raw
66 lines · bash
1#!/bin/bash2# 'perf data convert --to-json' command test3# SPDX-License-Identifier: GPL-2.04 5set -e6 7err=08 9shelldir=$(dirname "$0")10# shellcheck source=lib/setup_python.sh11. "${shelldir}"/lib/setup_python.sh12 13perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)14result=$(mktemp /tmp/__perf_test.output.json.XXXXX)15 16cleanup()17{18	rm -f "${perfdata}"19	rm -f "${result}"20	trap - exit term int21}22 23trap_cleanup()24{25	cleanup26	exit ${err}27}28trap trap_cleanup exit term int29 30test_json_converter_command()31{32	echo "Testing Perf Data Convertion Command to JSON"33	perf record -o "$perfdata" -F 99 -g -- perf test -w noploop > /dev/null 2>&134	perf data convert --to-json "$result" --force -i "$perfdata" >/dev/null 2>&135	if [ "$(cat ${result} | wc -l)" -gt "0" ] ; then36		echo "Perf Data Converter Command to JSON [SUCCESS]"37	else38		echo "Perf Data Converter Command to JSON [FAILED]"39		err=140		exit41	fi42}43 44validate_json_format()45{46	echo "Validating Perf Data Converted JSON file"47	if [ -f "$result" ] ; then48		if $PYTHON -c  "import json; json.load(open('$result'))" >/dev/null 2>&1 ; then49			echo "The file contains valid JSON format [SUCCESS]"50		else51			echo "The file does not contain valid JSON format [FAILED]"52			err=153			exit54		fi55	else56		echo "File not found [FAILED]"57		err=258		exit59	fi60}61 62test_json_converter_command63validate_json_format64 65exit ${err}66