Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp10532ybg; Tue, 2 Jun 2020 14:50:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyXQWXKFIM1FhTfKoluACMcjEGtWWarEZotQ57maJODN68Tms8LVTxP+orF3VyT75HxB2x X-Received: by 2002:aa7:d5c7:: with SMTP id d7mr28898466eds.11.1591134615427; Tue, 02 Jun 2020 14:50:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591134615; cv=none; d=google.com; s=arc-20160816; b=W9+AsWeVkG00K4zctgA7BfjwoOlBkPqf6g0AME2LfoOUqpvUu22Ed3vtaFW1XJh9Iz gEZGuR9WsGKe0mubON2Ox9y0V/Qm/lV8TK88Ta6Hi/ata8QdARW599djb0dmVO0EOej+ Mq/7cWRJgB/Eb94J++hQhTZ+RWIEkIY3Folsta788xHnIs/3UM0+9NTiGTuBeaVQWjkb gbyMdZLuaZ+B+l26XHqQdIpbDBlf9YaEbRYBQTlx9OuK9Lois6TQ1TrJO6kmtRjAQli4 kZzv8V2XmiAZNVV5WAWD1wMK9V9is/5nq1DRVwe0kbPMq2kI3TCnkklkue/TW5VBu0+V s9OQ== 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=PYvNzgC5CbX9jtDV03IjvSSMe+wNl9j1mOtqWA5Pubg=; b=MpUL0UIpAq5ythcBFTllzxCUwIKmvfEQcTwmKzQVRqxr5bcIdgNYLhs+1JH/YW/qpD HZqEFD613V+K0PkBF1ZfkNj0ik6yL6A7UVBowEAH6Ji7+6A/C/FDDz3TQcExAQIACUNd cBvzLu+iwwxzf1kLUSbZw7pep50lML7HcPv8pYDq8Xc4lHYO65bvf2/pqGUfkQ2DnMq5 CEBx/ZIP6G070LHbpOEfnC4REiEDzhiNUrEWs+bTtj2CKstb707nX/qdx0X9Bl47Nd85 rq/kguv9qUNucfaUW2VHTy/hKVGRXArx7RAxdABPXQCDk2LBWWerRYkN6kN4Ot2q6QDE VmVA== 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 va29si84063ejb.235.2020.06.02.14.49.51; Tue, 02 Jun 2020 14:50:15 -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 S1728299AbgFBVsA convert rfc822-to-8bit (ORCPT + 99 others); Tue, 2 Jun 2020 17:48:00 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:23027 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728272AbgFBVr6 (ORCPT ); Tue, 2 Jun 2020 17:47:58 -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-380-O5EWrYMkOCis49jRWf6ldQ-1; Tue, 02 Jun 2020 17:47:55 -0400 X-MC-Unique: O5EWrYMkOCis49jRWf6ldQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A16B1083E80; Tue, 2 Jun 2020 21:47:54 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id E553178EF7; Tue, 2 Jun 2020 21:47:51 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Ian Rogers , lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Stephane Eranian , Andi Kleen Subject: [PATCH 03/13] perf tests: Factor check_parse_id function Date: Tue, 2 Jun 2020 23:47:31 +0200 Message-Id: <20200602214741.1218986-4-jolsa@kernel.org> In-Reply-To: <20200602214741.1218986-1-jolsa@kernel.org> References: <20200602214741.1218986-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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. Acked-by: Ian Rogers Signed-off-by: Jiri Olsa --- tools/perf/tests/pmu-events.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 894282be073f..8d852f6d2092 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,18 @@ 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; + 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 = { 0 }; + + 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 +422,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 +482,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