Received: by 2002:ac8:3b51:0:b0:3f3:9eb6:4eb6 with SMTP id r17csp1144626qtf; Wed, 17 May 2023 11:20:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7vUpRLOCu7zhFFDieU3ZUFbyF4AMeZYyVVBbwt45uzDwTZ2A4KwgtwFk6HGfdzl0EjtU2r X-Received: by 2002:a05:6a20:9143:b0:106:c9b7:c93d with SMTP id x3-20020a056a20914300b00106c9b7c93dmr9822105pzc.19.1684347619134; Wed, 17 May 2023 11:20:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684347619; cv=none; d=google.com; s=arc-20160816; b=oLTPnYxDUXmF7G9/o/csCm9MSgSZYQsUbibpkncd5anAWqbAnz2hio0I/xm5rpxXNh eTSL5kK3a7HZ0rtL84vybE00tYoOVaEqePt7FeKrIgv1JYlgAdJlfL0zKrCgNsfmKYNX 85z3/6wpSe6esiJgdJxMREe8iM3EYyAXfExClN1PVV/2gOPiwieFJMOqM86C173caeDg sT8CwFUhoD2GZfkdZCbuV0cu6ya3tSV1GbQa1jkVFEMVyMvH1arrlMWKBQC4tqlrv3RH EZPoaSzR9opKsEthoKqOhW0MnOlIggOVeR/RbdIFs5AD0yyGI5tdcYKVRIR5hqch75cK GTBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date:dkim-signature; bh=UGE3NXi6rcUbLBxKiYlvCxBLm529P79UtKh2oEAjpgo=; b=sAi2/6cUAvXppkH0VltqYX7zJM21QtAOYj692QiDrrxna/jc5UUTSMCgPq5BsCW6G4 poo2mxho45yiCAYBmVTXzw+NNG5WyajmjJ11LQKeEyZF4vuaR1tjxbJZJQBJfTo8XspO MSrbeKmyWH/L/zWrk+7jLNPSoMVrz7dER3OvtCy6EhSwlcGEaBD3QJzlL4PzPazkvHTF fh3I2DdF7eVaylTy+mNq2PdyYp/Bl/+CGWV5mKxgqALAQ0B5zPao8D7tf7kHZzpE2xAV bVllzo2eJ/dUeFmf7a/YhWbPLJ6t2LP8egcfJd3L2BHvEb2XFEPMOwOEQgQH6TWue/B3 j93w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=DibZbTfZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m12-20020a633f0c000000b00528a60ab393si21450504pga.314.2023.05.17.11.20.04; Wed, 17 May 2023 11:20:19 -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=@gmail.com header.s=20221208 header.b=DibZbTfZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230033AbjEQSJk (ORCPT + 99 others); Wed, 17 May 2023 14:09:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229829AbjEQSJj (ORCPT ); Wed, 17 May 2023 14:09:39 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E8DE359F; Wed, 17 May 2023 11:09:36 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-643846c006fso1053911b3a.0; Wed, 17 May 2023 11:09:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684346976; x=1686938976; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=UGE3NXi6rcUbLBxKiYlvCxBLm529P79UtKh2oEAjpgo=; b=DibZbTfZrH4oA9G/Vp7WCaLw2Eo5CUkdJEfxpNB1XCzNCtUlV0pijJQ7RfNhUjH4MY u8DzJTHQnYIigcSFjQ5WQx1TY2N3UcuPEZhDAonb562M8a8pmxRNGsJ3v0WDreJ0H6nz EjSlcYF9+YHSksUSHXVMeJEHPdfFiQb8v3RweZZot9xA94yiNE2Mxe9dwzu8/GHFLmbj GFoAltU25auZ5wp2R7vaEptJPYLJNc4DKBO0s7C+hXwuLQdx3gkLyN0KhHm9TMEPfmJD ZUyviS1TqSJCe7qUThrdzZtxrkmsx4LIduhWAaIbg4ysfDRwNwBeVc9BGDg22fDF6x84 0LTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684346976; x=1686938976; 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=UGE3NXi6rcUbLBxKiYlvCxBLm529P79UtKh2oEAjpgo=; b=cdy+kgMcUDeu4uOmRBx/Z3uRJXY4BzzPPD2li+Hvc2GDCUmOSs+UA9vWzJv5kzv6yh w4V5DAbmY7yF4EGBzAEGaZb/BVLpbQO1/0hky7n93OBXabVJnuZL8SwTp31gHAsa8XJG W06RaA3rfBMM8Xbx4kJhmUQq82djXU0DxJGygOt9+2y7LnOqob+gMKT6OyiFEgl+NCqK 2l4JdAQtMpgvzfPA9ii3QIb3n1dNjauBeemFsEDQrdwlKRfAGv+qUK+VmX2no/S53ZI3 GxuQKMTAAMXEJPXYlTVEP1kvkXi/IA8fwiS85hmta0G5NJODtnxzi1iMDzoFdsGKt0sJ wjpw== X-Gm-Message-State: AC+VfDzfFt/IP+5PzRIztJmIlAhIjtaaTcFjidmyxh53DP6DtYqoTbS/ UA1r0YPiynBQ39txjTZOW1Y= X-Received: by 2002:a05:6a00:a05:b0:64c:c5f9:152a with SMTP id p5-20020a056a000a0500b0064cc5f9152amr786344pfh.23.1684346975661; Wed, 17 May 2023 11:09:35 -0700 (PDT) Received: from yoga ([2400:1f00:13:2292:1768:6fe3:f627:5671]) by smtp.gmail.com with ESMTPSA id 9-20020aa79249000000b0063db25e140bsm15484080pfp.32.2023.05.17.11.09.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 11:09:34 -0700 (PDT) Date: Wed, 17 May 2023 23:39:26 +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] 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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 --- .../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 + +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" + 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 + 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 + if jq '.' "${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 + fi + else + echo "File not found [FAILED]" + err=2 + exit + fi +} + +check + +test_json +validate_json_format + +exit ${err} -- 2.34.1