Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2691967rwd; Wed, 17 May 2023 13:05:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lT3d4BneBdnrHk/TDgGuE/2i+5j6KjBSkwcadYof2gVMfcpXwdsZhZzo9yM0cGdAk87rL X-Received: by 2002:a05:6a21:900c:b0:103:d538:5e94 with SMTP id tq12-20020a056a21900c00b00103d5385e94mr21675475pzb.12.1684353933860; Wed, 17 May 2023 13:05:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684353933; cv=none; d=google.com; s=arc-20160816; b=KzoWEs5VY4uQRCnk8ySbSlAII/W+0HEV6+0ls2m+nTvZENGF01bxZ41okEUZ9Q45cY n9TOWJDUJRJgCKLV452fOlb/nsm0siI9ZZVuIVo6JpGF2PHVpw+R3d/Ug9tgCnGSmBJk XsJ7MDLq2zpaZ0TsV+Qh7FsjmqaWQ1BZeaqG6w9DBYZI+3L/d+/aD/5JWJcMFEK/42/z 6qMA9GR5VI4V0ZuaOOIf5uYFmqsF4CyffO5GYPzuTghpm1TOjJbnS40aO0xDaAu752zL BUNnvmqQVEK1fieF/V4LsCTsQxn34s4FD8iJA9CMYaVnezainxChVWsDBt3Ckxmz4/MD hWLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=7PuhUAmuAWN2zg9B5H7JpxfVt8/E1PBqFeU+rQFkSJg=; b=SMSqs8ojD4m+MFcx2mKXOIq4kdyyM3ZTMtZIiUo4verSKTxzYFAt5t2t7sXXCISiH3 Z/qaYFmDO89lBnjMFeb4FZnfURli79/c+WjbUZRjtYVki9+5WZJHO3Ljhbmd+PIKsKV+ 1pbm91HAjDA45BTAhbeYM0VJr1+MuR6NEtstaxq6ameJuiCGC8S/k7P+9BxgktKjIWVv 8GPrE290v3I5R2eHddk6SyTipwTIfXICX4cvf8sD4EzRCkWvBYNa+HIOIwVtf4eTORjP 4xf++4NX9cAzddyJ1/lUXyFYaeDFuLoYpCbsJUYLcfuSPW6iD+kGJk5xkyEZzJkS04Uu lw/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=v5ZjVpaB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t64-20020a638143000000b0052c96dcaa82si22134874pgd.98.2023.05.17.13.05.19; Wed, 17 May 2023 13:05:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=v5ZjVpaB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229483AbjEQT5H (ORCPT + 99 others); Wed, 17 May 2023 15:57:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjEQT5G (ORCPT ); Wed, 17 May 2023 15:57:06 -0400 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF44459E1 for ; Wed, 17 May 2023 12:57:05 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-338458a9304so4975ab.1 for ; Wed, 17 May 2023 12:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684353425; x=1686945425; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7PuhUAmuAWN2zg9B5H7JpxfVt8/E1PBqFeU+rQFkSJg=; b=v5ZjVpaBb6iZa0hSwYV500ZA3Ke59Sg524tk3MudH+mTJ2OReFBmhRQeLlK3+NoO52 b9iIZnnf9pW6II0Jxv/lLOWCPoXob+8QM9YqfWtizoS3DcF/qiWtaJo5PpF+nN4HmmY3 4ZSfFzLCM0jWoDb2Yhn5BNFSYHAbKfxQl2aB2qvLNBui/rx6jgXOLH2+IvbOI3ZQH6H7 4qmCuGugwe0E9ctJomBfQLlIx1GvEGBwlpVt6ImTkB7mz26vqWLYmjUdqs5LEQgQp7Sy jxLndMr9vXh66NGAGkSqTVJYyifkZjfPrHeg2FYQIC+zc2F405Z4nULPFkV9/et/BQ7q j9Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684353425; x=1686945425; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7PuhUAmuAWN2zg9B5H7JpxfVt8/E1PBqFeU+rQFkSJg=; b=S9R+LBJjlfKBOuxf3ddEG9sSw5NfcmdEfFSwAR1x4fEzrvHnFN7mr/iqUYMLs0sZhA 8e+IHINYPlL+acsMI43K972EoiAZalSgRjJu1qilFjc+9Rkp5ql0LcKv9+PyVZ75ybaJ RBynqTAtfpsf9f0jUNiQHsV0YZVKFa1mxBhLdzb3ohbhgHvfYDKVXwvAslALh7Golzj2 tnwu/jD2VEPIZqmfD3tfsrbTiP/VQOkoWhD147eGfCIdNIea/jFlCFkxAgaNkmuViUvW BzA+r7ZzoLjuuFtsHX0E+zWMxUwomJ/k8MRi+KDkNB67Ff9+KJTbBZ8jfXsy8Em92sv7 8Cvg== X-Gm-Message-State: AC+VfDzrMtM9k9gp9UOngx9YhWCQcKxuYeEyoFzAdCMoFCWM+Zu1UHvd 1zWSqgPTkzmtjhxX/8k0Ya0f3jzn4jUWQRz6DGILvg== X-Received: by 2002:a05:6e02:198b:b0:32f:7831:dea5 with SMTP id g11-20020a056e02198b00b0032f7831dea5mr3825ilf.8.1684353424981; Wed, 17 May 2023 12:57:04 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ian Rogers Date: Wed, 17 May 2023 12:56:52 -0700 Message-ID: Subject: Re: [PATCH] perf: test: Add support for testing JSON generated by perf data command To: Anup Sharma Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 17, 2023 at 11:09=E2=80=AFAM 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. > > As a newcomer to this community, any feedback on the implementation > is highly appreciated. > > Signed-off-by: Anup Sharma Congratulations on sending your first patch! Anup is this summer's Google Summer-of-Code contributor for the Linux perf tool. I'm sure everyone on the lists is looking forward to your contributions! > --- > .../shell/test_perf_data_converter_json.sh | 64 +++++++++++++++++++ > 1 file changed, 64 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/to= ols/perf/tests/shell/test_perf_data_converter_json.sh > new file mode 100755 > index 000000000000..88db96e38925 > --- /dev/null > +++ b/tools/perf/tests/shell/test_perf_data_converter_json.sh > @@ -0,0 +1,64 @@ > +#!/bin/sh > +# perf data json converter test > +# SPDX-License-Identifier: GPL-2.0 > + > +set -e > + > +err=3D0 > +perfdata=3D$(mktemp /tmp/__perf_test.perf.data.XXXXX) > +result=3D$(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 > + > +check() > +{ > + if [ `id -u` !=3D 0 ]; then > + echo "[Skip] No root permission" > + err=3D2 > + exit > + fi > +} > + > +test_json() > +{ > + echo "Testing perf data convertion to JSON" > + perf record -o $perfdata -F 99 -a -g -- sleep 1 > /dev/null 2>&1 > + perf data convert --to-json $result --force -i $perfdata >/dev/nu= ll 2>&1 > + echo "Perf Data Converter to JSON [SUCCESS]" > +} > + > +validate_json_format() > +{ > + echo "Testing perf data converted to JSON format" > + if [ -f "${result}" ]; then It can be a good idea to test for failure and early exit. It would avoid being as indented in the following if. > + if jq '.' "${result}" > /dev/null 2>&1; then This assumes the jq program is available and it isn't by default on my distribution. We could test: if ! which jq; then but it may be better to depend on Python and json.loads - Python is already a dependency for a number of the tests. Thanks, Ian > + echo "The file contains valid JSON format [SUCCESS]" > + else > + echo "The file does not contain valid JSON format [FA= ILED]" > + err=3D1 > + fi > + else > + echo "File not found [FAILED]" > + err=3D2 > + exit > + fi > +} > + > +check > + > +test_json > +validate_json_format > + > +exit ${err} > -- > 2.34.1 >