Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp508472rwd; Wed, 17 May 2023 23:15:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5aSXvgJ76Me3n0bl4Ivolf4d6FO3A8fLaC8Bfw6I3Opuvae/sYCfbWHlA9gB8SsOudHpaV X-Received: by 2002:a05:6a21:3987:b0:103:9c05:1664 with SMTP id ad7-20020a056a21398700b001039c051664mr1068038pzc.12.1684390517421; Wed, 17 May 2023 23:15:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684390517; cv=none; d=google.com; s=arc-20160816; b=VOI3D6UWGuPibvWi/L7qZ/p1nf/fhVq3QnfkAHR2I1LAa1qZ2k0U4JMCRV6BGV4kMT VzC8aMacXrtyDjoxGIx6dugel0ZkCWTuLZgzy3Q1Ri0V7aRyejs8uVJpMONdXREExf7D HyRL5kdqoQMUJcuNlbJ3rFDSmaQmNXY8QXWB3MoNSrvXf6RvAPVDmt6xdeoru6r4ihXi Wp7IP/IBsCU9HDDCQGpi1JJ39jnZFHoRknhrCFumjRrp8bxeW/00+UL7zEGCS1Rdwz5Z rZ1kwqQ7gySgSPOdKPhSi8jBj9R8/vz3iLS7dAVb75frjt4eYkulmmLh/fYytsrdXj22 Fi/A== 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; bh=DrgVer5C/183yqHL3vYsXJoiSqObbxZ2hssiYuUjXYg=; b=QoyrN6AG0O8Vyo2AhzngNIOwebrzTR3VtQmU56i1O+WbfNI4ro4rZs9vKvB6v8hNp1 mASZpnAhp9PnJ3lECtEQ9eAaoSL7Sdd1L/oGujz8zdM8pa6ZjDaTK7Lus6TjzToHEn3X 6+xHUz94AofcB7qd51JAvPhJ3F9niDmwXH8xJAgpADK8cFK45ltAHVLvz2hbN/mV/oKG oSkoDwM13vCAEjSDaHWmNpss4pOwtpNdym37QdfVJYrsN6m0uoFEFMxknbwOQED40+jd XWVjcOhRgu3o/cyOqWWbSDCnDxao5QYDCBKRsVoXb24n37hGweQlR+TXsK8V+kawd19p svRw== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 141-20020a630093000000b0052c2061447dsi629409pga.522.2023.05.17.23.15.01; Wed, 17 May 2023 23:15:17 -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; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229524AbjERGDr convert rfc822-to-8bit (ORCPT + 99 others); Thu, 18 May 2023 02:03:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230022AbjERGDp (ORCPT ); Thu, 18 May 2023 02:03:45 -0400 Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C10342696; Wed, 17 May 2023 23:03:42 -0700 (PDT) Received: by mail-vk1-f177.google.com with SMTP id 71dfb90a1353d-4518d3a9b12so628576e0c.2; Wed, 17 May 2023 23:03:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684389822; x=1686981822; 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=bXsUEZdg7frRdNYYyqBOXtRmmOUkZTVlUYkUEGA36aE=; b=fJ4kV94GZ2rMO4Ej6/kG8/EV4zG7nvKjSmeGl5x1NdMkG2LJRUoJ/Rc9zyyu2WAGlH Vk2dMwk/D3uhXKhZGWKuGQg1a/gvqAu/Q6CQZ7xIaGdZbO5IdpPVaD/Yh/Rto2Bov/qJ Md2CxXc2n5+Hz10a21m59OjKoy/GGw/rXno/zTyLj1kUDeKgepY8WucMWZfIASnuN6Hg y5DX99LuCjAR2N7dfMmEqMIQj5mDAiqqzcGHb514ZB0BiBgW44OFbH27mdF3rou3DwAQ RxiNJii9jIKiFs3OwTPB/RNlV6UN7m2Y70+cPqDclZjGWA1XcUwO+RimYb8gCEGh9nTm JACg== X-Gm-Message-State: AC+VfDzgc1XQGYkjlJQjHc9AaY4Nk73M9kiZKBLPtNQ8+fhnP/wSegzh 1rye6Yc10ZsUiOYXy2TcvAl/LEf/XAfRbsJp3Qc= X-Received: by 2002:a1f:5f06:0:b0:453:8a02:8d9 with SMTP id t6-20020a1f5f06000000b004538a0208d9mr301432vkb.11.1684389821697; Wed, 17 May 2023 23:03:41 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Namhyung Kim Date: Wed, 17 May 2023 23:03:30 -0700 Message-ID: Subject: Re: [PATCH] perf: test: Add support for testing JSON generated by perf data command To: Ian Rogers Cc: Anup Sharma , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 Hello, On Wed, May 17, 2023 at 12:57 PM Ian Rogers wrote: > > On Wed, May 17, 2023 at 11:09 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. > > > > 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! +1 > > > --- > > .../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/tools/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 You may want to run shellcheck when you write a shell script. > > + > > +set -e > > + > > +err=0 > > +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 > > + > > +check() > > +{ > > + if [ `id -u` != 0 ]; then > > + echo "[Skip] No root permission" I don't think we actually need root permission for this test. > > + err=2 > > + 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 The -a/--system-wide option requires root permission usually. We can run perf record in per-task mode instead. Please remove the -a option and run some other command instead of 'sleep 1'. The perf tool has a couple of test workloads and benchmark programs. So you can try something like perf record -o $perfdata -F 99 -g -- perf test -w noploop or perf record -o $perfdata -F 99 -g -- perf bench sched messaging Thanks, Namhyung > > + perf data convert --to-json $result --force -i $perfdata >/dev/null 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 [FAILED]" > > + err=1 > > + fi > > + else > > + echo "File not found [FAILED]" > > + err=2 > > + exit > > + fi > > +} > > + > > +check > > + > > +test_json > > +validate_json_format > > + > > +exit ${err} > > -- > > 2.34.1 > >