Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1699846pxj; Wed, 19 May 2021 11:47:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw22/YyRIIr3sY52z6FxaIok0QnXOz19K1aqkPV6p9m8+fsYvqmil+O9gYV07tWH83WaoyP X-Received: by 2002:a17:906:2746:: with SMTP id a6mr541419ejd.265.1621450055573; Wed, 19 May 2021 11:47:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621450055; cv=none; d=google.com; s=arc-20160816; b=NzYXxDh4U2Qc0pxkiWGyXqsgA7/LzVFKwHYssMJ/QErQcWWvwyXv7Kn43BaXqasxjR nKDaT3gdEXRiQTxzWrt4LqE4I+sRQfDwpPTPGrnD9BY7GL5ySVIYPS064tWcdMcYJS/t zG3yv1p66vF9C4CgKDYzL3ffmhoR7Mx1ZGwO3qU/rffkEHIcPlDsZRaLJeWvpkgwozSS +LRp/UxxVoWOChlzpDtfPr7uNSQarS6NCe5neLjf6TKDWXIMCUPSH4GIEGHHNQYEJ2eE TKktIdUx/yMzMWfrAQMO7H+jDm9XYDyMiLC6EIU5UKJTOMnlqae3StcPcVDIlVxg8wV5 E+Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=dB5AZpFDnjZnCDVY6EBk4qG0EF9TZ3zY3Xl36EaiD58=; b=hIjeZ3GAivR2MCSXVyOig9+AQlzaziOI9JuCim0hyDksS8bgJuZVTRTtaBQiZAeUkW EZ8Z8Cb0hiwqkq7Wgr9rIfPp4q7ub9wW8AWvAY1Qc1r/6PG4b7xNjLsKMy/LtT+6A+c4 bYI45sPnnsX543Cp3yj6m9UDhnrQTSuB8ARsAh1vIeqCoNEi8eeg4bXmQ+BUcYL0/Sx6 1/G1vaICMdyX6Pu2xe2CxI0wxp+KxaqHvZRJbQ/bi+KjabsOEd7i2ASUB+2gkOJ53dD8 e7JEVHchxMUnr5ZU8yxR99FQYrY5idE9MUCCqiP00FkvVzcIMWn5pa9F8KdYJmh/XmIM hM0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HCWyWnip; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fl21si340293ejc.601.2021.05.19.11.47.10; Wed, 19 May 2021 11:47:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HCWyWnip; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S236884AbhERXcI (ORCPT + 99 others); Tue, 18 May 2021 19:32:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231521AbhERXcH (ORCPT ); Tue, 18 May 2021 19:32:07 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8402C061573 for ; Tue, 18 May 2021 16:30:48 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id i17so11958981wrq.11 for ; Tue, 18 May 2021 16:30:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dB5AZpFDnjZnCDVY6EBk4qG0EF9TZ3zY3Xl36EaiD58=; b=HCWyWnipiDG/MI4w05WoFcFXiK7TIRM2s5AZySf50hADftHFa0C/YxNZaWNiaOAA1J JVhoVrPYXBcsFY7WdYrvk2OAPdAVH1xLCL+tGJUapuvoZU7VndDnN5Yk2rCQeIyT2juE rCCwG7rhS80YJPTck2ZqjiAIombL9CbzlCeLfUjfkRRm19seREKYo81nFyZUxw1JQfnI Z8Fk2Ne6BGjA8d77z77jJDuFce9/aZ1yg0FlfV2NIGOapd9TOc14KCwDpEMbXEhMIspl gnuXsUalIS0pusuucuNUwOrlumA8xSAolX64pSAY0SSjTIhBQkBK8ZR+D0HEm2KC+Q82 PG+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dB5AZpFDnjZnCDVY6EBk4qG0EF9TZ3zY3Xl36EaiD58=; b=b5M15peI8GtZ/KpSFUofB3EdKjbVCUh2kSloVVJg6HraB/uWPt2g0v44TqJgpJlKCT zNxxuKt1Tz12Qd3Cut0jT89HQFwBKwHy36ymKWnZl4A8g9SY9Ttq20nrH5S/ZzxLr4fP zO9mgeExlhYhJMszdec434g9sBQSQTzzRIsADzFaAoAuLxIqXq3ZxBpK3HDZ0mU38zYm IkylQXKPCSNPhlDQrRpr/4Mx4oqSu07iresVul+0zrQynaa/PxSsUIJECCEWZj9mngUr 1E4AWdktIhbx/5YAVS/3nM0n/bc0GS0IXdHkLUJzjSBf88aFhKiOAI6Lh9WHZDW54MIf 0B0Q== X-Gm-Message-State: AOAM532zSRvyJnfRmk0X3k3WDkH976LLF96R44bKF/nSIzBiPC5ushB5 dSbWK9I82EM+w0r3gDMTbtOAz2pSPymRuK2ipLcBzw== X-Received: by 2002:adf:f54b:: with SMTP id j11mr5158668wrp.376.1621380647471; Tue, 18 May 2021 16:30:47 -0700 (PDT) MIME-Version: 1.0 References: <20210517140931.2559364-1-tmricht@linux.ibm.com> In-Reply-To: <20210517140931.2559364-1-tmricht@linux.ibm.com> From: Ian Rogers Date: Tue, 18 May 2021 16:30:35 -0700 Message-ID: Subject: Re: [PATCH] perf test: Test libpfm4 support (63) reports error To: Thomas Richter Cc: LKML , linux-perf-users , Arnaldo Carvalho de Melo , Stephane Eranian , svens@linux.ibm.com, Vasily Gorbik , sumanthk@linux.ibm.com, hca@linux.ibm.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 17, 2021 at 7:12 AM Thomas Richter wrote: > > Compiling perf with make LIBPFM4=1 includes libpfm support and > enables test case 63 'Test libpfm4 support'. This test reports an error > on all platforms for subtest 63.2 'test groups of --pfm-events'. > The reported error message is 'nested event groups not supported' The parsing test checks broken and working strings and so errors are always going to be reported, but agreed this error is wrong. > # ./perf test -F 63 > 63: Test libpfm4 support : > 63.1: test of individual --pfm-events : > Error: > failed to parse event stereolab : event not found > Error: > failed to parse event stereolab,instructions : event not found > Error: > failed to parse event instructions,stereolab : event not found > Ok > 63.2: test groups of --pfm-events : > Error: > nested event groups not supported <------ Error message here > Error: > failed to parse event {stereolab} : event not found > Error: > failed to parse event {instructions,cycles},{instructions,stereolab} :\ > event not found > Ok > # > > This patch addresses the error message 'nested event groups not supported'. > The root cause is function parse_libpfm_events_option() which parses the > event string '{},{instructions}' and can not handle a leading empty > group notation '{},...'. > > The code detects the first (empty) group indicator '{' but does not > terminate group processing on the following group closing character '}'. > So when the second group indicator '{' is detected, the code assumes > a nested group and returns an error. > > With the error message fixed, also change the expected event number to > one for the test case to succeed. > > While at it also fix a memory leak. In good case the function does not > free the duplicated string given as first parameter. > > Output after: > # ./perf test -F 63 > 63: Test libpfm4 support : > 63.1: test of individual --pfm-events : > Error: > failed to parse event stereolab : event not found > Error: > failed to parse event stereolab,instructions : event not found > Error: > failed to parse event instructions,stereolab : event not found > Ok > 63.2: test groups of --pfm-events : > Error: > failed to parse event {stereolab} : event not found > Error: > failed to parse event {instructions,cycles},{instructions,stereolab} : \ > event not found > Ok > # > Error message 'nested event groups not supported' is gone. Acked-By: Ian Rogers I wonder if we should add some coverage for the error cases to the pfm test with something like the following. Thanks, Ian --- a/tools/perf/tests/pfm.c +++ b/tools/perf/tests/pfm.c @@ -155,6 +155,16 @@ static int test__pfm_group(void) .nr_events = 3, .nr_groups = 1, }, + { + .events = "instructions}", + .nr_events = 1, + .nr_groups = 0, + }, + { + .events = "{{instructions}}", + .nr_events = 0, + .nr_groups = 0, + }, }; for (i = 0; i < ARRAY_SIZE(table); i++) { > Signed-off-by: Thomas Richter > Acked-By: Sumanth Korikkar > --- > tools/perf/tests/pfm.c | 4 ++-- > tools/perf/util/pfm.c | 11 ++++++++++- > 2 files changed, 12 insertions(+), 3 deletions(-) > > diff --git a/tools/perf/tests/pfm.c b/tools/perf/tests/pfm.c > index 76a53126efdf..d4b0ef74defc 100644 > --- a/tools/perf/tests/pfm.c > +++ b/tools/perf/tests/pfm.c > @@ -131,8 +131,8 @@ static int test__pfm_group(void) > }, > { > .events = "{},{instructions}", > - .nr_events = 0, > - .nr_groups = 0, > + .nr_events = 1, > + .nr_groups = 1, > }, > { > .events = "{instructions},{instructions}", > diff --git a/tools/perf/util/pfm.c b/tools/perf/util/pfm.c > index d735acb6c29c..6eef6dfeaa57 100644 > --- a/tools/perf/util/pfm.c > +++ b/tools/perf/util/pfm.c > @@ -62,8 +62,16 @@ int parse_libpfm_events_option(const struct option *opt, const char *str, > } > > /* no event */ > - if (*q == '\0') > + if (*q == '\0') { > + if (*sep == '}') { > + if (grp_evt < 0) { > + ui__error("cannot close a non-existing event group\n"); > + goto error; > + } > + grp_evt--; > + } > continue; > + } > > memset(&attr, 0, sizeof(attr)); > event_attr_init(&attr); > @@ -107,6 +115,7 @@ int parse_libpfm_events_option(const struct option *opt, const char *str, > grp_evt = -1; > } > } > + free(p_orig); > return 0; > error: > free(p_orig); > -- > 2.31.1 >