From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1170C77B73 for ; Mon, 22 May 2023 18:43:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231556AbjEVSnZ (ORCPT ); Mon, 22 May 2023 14:43:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbjEVSnZ (ORCPT ); Mon, 22 May 2023 14:43:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD591C4; Mon, 22 May 2023 11:43:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6937861E8B; Mon, 22 May 2023 18:43:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C716C4339B; Mon, 22 May 2023 18:43:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684781002; bh=im28E1p35zGS1s3biu77XRcVQQtJ0gF9+C0RLsYZrlg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iF12K1myeoZNrnbsQxIOeLVrbMaBa6fKweGWNioD8aPsyC2Cc0W1qI2OqfIfqDeas /d8qVmFz8E36QNCscqVeBbcebQdlq0rhl8c2+pAd8q2hVk0Rq5HaWd3HoOZjWSkAA0 0sRJ33jx27BaTVpElCpUFfDmAHfktr8gXxo4n4eTnt1L8Q6crH6U+n8tSPfghcb79M 79sNdvLGuNM6fudHMH8XMDKtEFNjHXoj+g9WsFGbyY/DcMtAMu7/AKbwVCyQt9WlnT L7lEaqbzjKy8uH7VCSfj6BJRlkcXezEOu5mJJXlSvMBaPlC91jcY8fIHRdgpYk+vIy AzRYOKO62pkPw== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id C0610403B5; Mon, 22 May 2023 15:43:19 -0300 (-03) Date: Mon, 22 May 2023 15:43:19 -0300 From: Arnaldo Carvalho de Melo To: Anup Sharma Cc: Ian Rogers , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] perf: test: Add support for testing JSON generated by perf data command Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org Em Mon, May 22, 2023 at 03:31:06PM -0300, Arnaldo Carvalho de Melo escreveu: > Em Mon, May 22, 2023 at 03:28:20PM -0300, Arnaldo Carvalho de Melo escreveu: > > Em Mon, May 22, 2023 at 11:10:43AM -0700, Ian Rogers escreveu: > > > On Fri, May 19, 2023 at 12:41 AM Anup Sharma wrote: > > > > > > > > This commit adds support for testing the JSON output generated > > > > by the perf data command's conversion to JSON functionality. > > > > The test script now includes a validation step to ensure that > > > > the resulting JSON file is contain valid data. > > > > > > > > Signed-off-by: Anup Sharma > > > > > > Acked-by: Ian Rogers > > > > I'm fixing these and some other identation minor issues: > I have this on top, making the indentation to be consistent, using tabs, as the other .sh files in that directory and also having the 'then' be on the 'if' line, separated by ; diff --git a/tools/perf/tests/shell/test_perf_data_converter_json.sh b/tools/perf/tests/shell/test_perf_data_converter_json.sh index 8f4d6575f34fa82e..72ac6c83231c03d5 100755 --- a/tools/perf/tests/shell/test_perf_data_converter_json.sh +++ b/tools/perf/tests/shell/test_perf_data_converter_json.sh @@ -1,18 +1,15 @@ #!/bin/bash -# perf data json converter command test +# 'perf data convert --to-json' command test # SPDX-License-Identifier: GPL-2.0 set -e err=0 -if [ "$PYTHON" = "" ] -then - if which python3 > /dev/null - then +if [ "$PYTHON" = "" ] ; then + if which python3 > /dev/null ; then PYTHON=python3 - elif which python > /dev/null - then + elif which python > /dev/null ; then PYTHON=python else echo Skipping test, python not detected please set environment variable PYTHON. @@ -42,8 +39,7 @@ test_json_converter_command() echo "Testing Perf Data Convertion Command to JSON" perf record -o "$perfdata" -F 99 -g -- perf test -w noploop > /dev/null 2>&1 perf data convert --to-json "$result" --force -i "$perfdata" >/dev/null 2>&1 - if [ $(cat "${result}" | wc -l) -gt "0" ] - then + if [ $(cat "${result}" | wc -l) -gt "0" ] ; then echo "Perf Data Converter Command to JSON [SUCCESS]" else echo "Perf Data Converter Command to JSON [FAILED]" @@ -54,22 +50,20 @@ test_json_converter_command() validate_json_format() { - echo "Validating Perf Data Converted JSON file" - if [ -f "$result" ] - then - if $PYTHON -c "import json; json.load(open('$result'))" >/dev/null 2>&1 - then - echo "The file contains valid JSON format [SUCCESS]" - else - echo "The file does not contain valid JSON format [FAILED]" - err=1 - exit - fi - else - echo "File not found [FAILED]" - err=2 - exit - fi + echo "Validating Perf Data Converted JSON file" + if [ -f "$result" ] ; then + if $PYTHON -c "import json; json.load(open('$result'))" >/dev/null 2>&1 ; then + echo "The file contains valid JSON format [SUCCESS]" + else + echo "The file does not contain valid JSON format [FAILED]" + err=1 + exit + fi + else + echo "File not found [FAILED]" + err=2 + exit + fi } test_json_converter_command