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 47B46C7EE2A for ; Fri, 19 May 2023 07:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230372AbjESHmC (ORCPT ); Fri, 19 May 2023 03:42:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230270AbjESHl7 (ORCPT ); Fri, 19 May 2023 03:41:59 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4318A1712; Fri, 19 May 2023 00:41:33 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-64384c6797eso2309432b3a.2; Fri, 19 May 2023 00:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684482093; x=1687074093; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=xz++8cp/MOfN7DhrMnTkQuFUltOrCffkRhgTguG3kA8=; b=PqaIy1xeFs1r7a7r4g+8W1WbHjHFnatSbr8Nq8PLwreNpDlco7i8/UhpB6kOJWAfLm x+uLudDuiQB0BwuTtGfE/gdyu/T84y0hKGkCCZpvSwAwFAzUHiuupoBOhnI03iLsgeIi FrhGGOTsmbVHd9uxMMv/ecVyzwm27NVaG2Nx4mviVB79vPL/CrT3z9YB13kAEKRfvJre tkRiwY6dPhnyNbd2wXHTPGYcHG4aHkM79Bz4jUPJZlKM7qx6truEDnYbW6hTLoBWPmBP qnvwHp6y3hzm49ZsKZkSJhODBsg1vM4/ugn9Evrpv7f2VjoYDcxfs0i9Ls/XYDV08MGh 8BEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684482093; x=1687074093; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xz++8cp/MOfN7DhrMnTkQuFUltOrCffkRhgTguG3kA8=; b=f0zCNdRN0XMep1+Mt5n33rIDSi9r0+KoyXuGQkA17OPbyF35yd/e8ptptAx2HNbMG1 eF+SC8Bry78ABddMqJj42fr4eFiIgH4HUWS2vzE2MXwZvJNN87z8qIxJDkC2tlTKk0pb a53IR6qndq05+MbhUjQ68gdASYr8i/NATHUhzUzdNFx2Jg7FXKLb8FXB3QbKzQxmbVwS voZPmuC5KJEmS+RcKQ2NVbGR3Rz0WjS+riyNkMq/ihxqAxAamPbJUXxJ4GkRQ0UWe5Uq oJRANINZZ4A9AcSpe8L7ZL3CXP1VPB2UAbyhwUF1QZxdMt4l+ajFxerO95fJdHoEJ3++ mZBA== X-Gm-Message-State: AC+VfDxhPSbV2jcpJlqeETSe+YMHowAx5akiv8pkifx0ppnOoCf6/R8Q +Kr+TlHbnHMn+PtUe+FOJJC8CDO6WRvuMlrN X-Google-Smtp-Source: ACHHUZ6riYfWPSPFysHEBQfMeS75lFvnOx9JAEpTac2x0Xug/XU92DVrbyAwpdcPDzxsO3saB8dZyw== X-Received: by 2002:a05:6a00:1783:b0:644:d77:a2c5 with SMTP id s3-20020a056a00178300b006440d77a2c5mr2161385pfg.29.1684482092509; Fri, 19 May 2023 00:41:32 -0700 (PDT) Received: from yoga ([2400:1f00:13:b468:8a9f:b695:3862:d744]) by smtp.gmail.com with ESMTPSA id v11-20020aa7808b000000b005d22639b577sm2427908pff.165.2023.05.19.00.41.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 00:41:32 -0700 (PDT) Date: Fri, 19 May 2023 13:11:24 +0530 From: Anup Sharma To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Anup Sharma , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] perf: test: Add support for testing JSON generated by perf data command Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org 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 Changes: V1 -> V2: Added a check for the existence of the result output file. Replaced the usage of jq with json.load for validating the JSON format. Checks using ShellCheck and checkpatch, addressing and resolving warnings. Removed the unnecessary root permission check. Modified the perf record command to avoid requiring root permissions. --- .../shell/test_perf_data_converter_json.sh | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 tools/perf/tests/shell/test_perf_data_converter_json.sh diff --git a/tools/perf/tests/shell/test_perf_data_converter_json.sh b/tools/perf/tests/shell/test_perf_data_converter_json.sh new file mode 100755 index 000000000000..54b7a19962fa --- /dev/null +++ b/tools/perf/tests/shell/test_perf_data_converter_json.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# perf data json converter command test +# SPDX-License-Identifier: GPL-2.0 + +set -e + +err=0 + +if [ "$PYTHON" = "" ] +then + if which python3 > /dev/null + then + PYTHON=python3 + elif which python > /dev/null + then + PYTHON=python + else + echo Skipping test, python not detected please set environment variable PYTHON. + exit 2 + fi +fi + +perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX) +result=$(mktemp /tmp/__perf_test.output.json.XXXXX) + +cleanup() +{ + rm -f "${perfdata}" + rm -f "${result}" + trap - exit term int +} + +trap_cleanup() +{ + cleanup + exit ${err} +} +trap trap_cleanup exit term int + +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 + echo "Perf Data Converter Command to JSON [SUCCESS]" + else + echo "Perf Data Converter Command to JSON [FAILED]" + err=1 + exit + fi +} + +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 +} + +test_json_converter_command +validate_json_format + +exit ${err} -- 2.34.1