Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1231928ybg; Tue, 2 Jun 2020 04:53:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLE4DZpiDRjZu3dhcbTa3QsGxgfZl++CPqmbnz2fxQG7qNJEat2B0SVrXW2y4ku7ffW++c X-Received: by 2002:aa7:d35a:: with SMTP id m26mr26087389edr.25.1591098817491; Tue, 02 Jun 2020 04:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591098817; cv=none; d=google.com; s=arc-20160816; b=bxQOOmyEuQxvicm1xeXusMTZ13/ZOE0LlrlOH1VXAEG0rwo1Bo7Eai9hpdS3MgWq8W +2YeS1qt2lpmbKQgwHVe2UciapmSDu3dRokyhxrzCrRkKZhizdAHZ0wBFZ41DAcuJf/f DEADDntsbLmL6y6I0Voyyz6xJjrzhactocuzx3/nnzkXpdNbanj73l6xW7gC5Lo9DVW4 sWIQgcjyAhJ1ThCd9yjkR6CwuFGWM6gfH/nPTH6pEyqx1lf/nIc20KjKv20up9F+3s3m EgpQ+bo9t0m75AOsf1DNId1d7fh+YVjL0+qJnqBQoc1/4RFjZVUJGKc+CkwGqwBvvPK3 rfJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=1vRCBReFv5MNULyKvmVTITCDjh1hqmV6iyHIi5Nio00=; b=yujKlYci59yVIlHr6BatsuuZlzg/Jta0O5+Ep9slXO9B1KLpR5uBe4OcmEy4ckXOd0 NEG614176zcmjFJscqs6kbPeuwEpiTEiKH9CWcCkitM0zMkL6uC0j3WDHWkunU5dopDh URg0DK/+lXg/NyjdM2DHh9pgYkbJmAV48Tn0XXhjiQFtfbjJhPyGEjI+GRbyLoarq11R Mfm2XFP1XISS+rHCbQUAaAAeW+VDv2H+OpH8xCNjP8gzlgNkIC8SDBSA4wYLdmJCgFz2 tKjWWJoHH0Rva1ecNCiRneJ0t4lyuZWKUwXihnNHXzABrFrsGNSQhmQ6upUYrVJ1U8Nv 1hyw== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t5si1325367ejs.458.2020.06.02.04.53.14; Tue, 02 Jun 2020 04:53:37 -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; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727921AbgFBLvR convert rfc822-to-8bit (ORCPT + 99 others); Tue, 2 Jun 2020 07:51:17 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:21573 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727795AbgFBLvN (ORCPT ); Tue, 2 Jun 2020 07:51:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-325-Ubw32I_2PZqfPDCcwadeZA-1; Tue, 02 Jun 2020 07:51:09 -0400 X-MC-Unique: Ubw32I_2PZqfPDCcwadeZA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 650FEBFC0; Tue, 2 Jun 2020 11:51:07 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.195.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FDAB10013D7; Tue, 2 Jun 2020 11:51:04 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Ian Rogers , Stephane Eranian , Andi Kleen Subject: [PATCH 03/13] perf tests: Factor check_parse_id function Date: Tue, 2 Jun 2020 13:50:45 +0200 Message-Id: <20200602115055.1168446-4-jolsa@kernel.org> In-Reply-To: <20200602115055.1168446-1-jolsa@kernel.org> References: <20200602115055.1168446-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Separating the generic part of check_parse_id function, so it can be used in following changes for the new test. Signed-off-by: Jiri Olsa --- tools/perf/tests/pmu-events.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 894282be073f..f65380d2066f 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -390,9 +390,8 @@ static bool is_number(const char *str) return errno == 0 && end_ptr != str; } -static int check_parse_id(const char *id, bool same_cpu, struct pmu_event *pe) +static int check_parse_id(const char *id, struct parse_events_error *error) { - struct parse_events_error error; struct evlist *evlist; int ret; @@ -401,8 +400,19 @@ static int check_parse_id(const char *id, bool same_cpu, struct pmu_event *pe) return 0; evlist = evlist__new(); - memset(&error, 0, sizeof(error)); - ret = parse_events(evlist, id, &error, false); + if (!evlist) + return -ENOMEM; + memset(error, 0, sizeof(*error)); + ret = parse_events(evlist, id, error, false); + evlist__delete(evlist); + return ret; +} + +static int check_parse_cpu(const char *id, bool same_cpu, struct pmu_event *pe) +{ + struct parse_events_error error; + + int ret = check_parse_id(id, &error); if (ret && same_cpu) { pr_warning("Parse event failed metric '%s' id '%s' expr '%s'\n", pe->metric_name, id, pe->metric_expr); @@ -413,7 +423,6 @@ static int check_parse_id(const char *id, bool same_cpu, struct pmu_event *pe) id, pe->metric_name, pe->metric_expr); ret = 0; } - evlist__delete(evlist); free(error.str); free(error.help); free(error.first_str); @@ -474,7 +483,7 @@ static int test_parsing(void) expr__add_id(&ctx, strdup(cur->key), k++); hashmap__for_each_entry((&ctx.ids), cur, bkt) { - if (check_parse_id(cur->key, map == cpus_map, + if (check_parse_cpu(cur->key, map == cpus_map, pe)) ret++; } -- 2.25.4