From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 31A80A0579; Fri, 9 Apr 2021 13:05:14 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DC316140F28; Fri, 9 Apr 2021 13:05:13 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id 9EE80140F26 for ; Fri, 9 Apr 2021 13:05:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617966311; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QDJAI+JNRqRGIJV2TFM/9KTFcwmjgQX5is2HTwfH9iY=; b=D2PHtBSTDSxqF27+Gj6kzPcUmj7PpsqRTFVxNllssjhEtVGu7eRawcaHsDuDLefZxfQ466 plgIg3viXho+mSEL7pGcf/hoEMiIrEjCfWVVKUWv3UP7+N4xlw6OB84dj1Lin5Ka/7SHVj hvZar1WkAnldExjZQx+fFa5d7ER2UkU= 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-251-Z4HjnF_fNiiUEeBot-qaHw-1; Fri, 09 Apr 2021 07:05:09 -0400 X-MC-Unique: Z4HjnF_fNiiUEeBot-qaHw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5F5061005582; Fri, 9 Apr 2021 11:05:08 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D1B718AAB; Fri, 9 Apr 2021 11:05:05 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: arybchenko@solarflare.com, l.wojciechow@partner.samsung.com, thomas@monjalon.net Date: Fri, 9 Apr 2021 13:04:51 +0200 Message-Id: <20210409110453.20078-2-david.marchand@redhat.com> In-Reply-To: <20210409110453.20078-1-david.marchand@redhat.com> References: <20200626114751.22523-1-david.marchand@redhat.com> <20210409110453.20078-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH v3 1/3] test/log: check levels X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add checks on log levels: - default values for rte_log_register and RTE_LOG_REGISTER, - level changes with rte_log_set_level and consorts Signed-off-by: David Marchand --- Changes since v1: - dropped unrelated change moving logtype1 and logtype2 as global static variables, - dropped __FILE__ + __LINE__ from assert logs, since the macro already logs the line, --- app/test/test_logs.c | 51 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/app/test/test_logs.c b/app/test/test_logs.c index 425ae03cb9..7abb6eeca2 100644 --- a/app/test/test_logs.c +++ b/app/test/test_logs.c @@ -20,6 +20,8 @@ #define RTE_LOGTYPE_TESTAPP1 RTE_LOGTYPE_USER1 #define RTE_LOGTYPE_TESTAPP2 RTE_LOGTYPE_USER2 +RTE_LOG_REGISTER(logtype3, logtype3, ERR) + /* * Logs * ==== @@ -64,6 +66,22 @@ test_logs(void) int logtype1, logtype2; int ret; +#define CHECK_LEVELS(exp1, exp2, exp3) do \ +{ \ + ret = rte_log_get_level(logtype1); \ + TEST_ASSERT_EQUAL(ret, exp1, \ + "invalid level for logtype1 got %d, expecting %d\n", \ + ret, exp1); \ + ret = rte_log_get_level(logtype2); \ + TEST_ASSERT_EQUAL(ret, exp2, \ + "invalid level for logtype2 got %d, expecting %d\n", \ + ret, exp2); \ + ret = rte_log_get_level(logtype3); \ + TEST_ASSERT_EQUAL(ret, exp3, \ + "invalid level for logtype3 got %d, expecting %d\n", \ + ret, exp3); \ +} while (0) + printf("== dynamic log types\n"); logtype1 = rte_log_register("logtype1"); @@ -77,9 +95,36 @@ test_logs(void) return -1; } + ret = rte_log_get_level(logtype1); + TEST_ASSERT_EQUAL(ret, RTE_LOG_INFO, + "invalid default level for logtype1 got %d, expecting %d\n", + ret, RTE_LOG_INFO); + + ret = rte_log_get_level(logtype2); + TEST_ASSERT_EQUAL(ret, RTE_LOG_INFO, + "invalid default level for logtype2 got %d, expecting %d\n", + ret, RTE_LOG_INFO); + + ret = rte_log_get_level(logtype3); + TEST_ASSERT_EQUAL(ret, RTE_LOG_ERR, + "invalid default level for logtype3 got %d, expecting %d\n", + ret, RTE_LOG_ERR); + + rte_log_set_level(logtype1, RTE_LOG_ERR); + CHECK_LEVELS(RTE_LOG_ERR, RTE_LOG_INFO, RTE_LOG_ERR); + + rte_log_set_level_regexp("type$", RTE_LOG_EMERG); + CHECK_LEVELS(RTE_LOG_ERR, RTE_LOG_INFO, RTE_LOG_ERR); + + rte_log_set_level_regexp("type[23]", RTE_LOG_EMERG); + CHECK_LEVELS(RTE_LOG_ERR, RTE_LOG_EMERG, RTE_LOG_EMERG); + + rte_log_set_level_pattern("logtype", RTE_LOG_DEBUG); + CHECK_LEVELS(RTE_LOG_ERR, RTE_LOG_EMERG, RTE_LOG_EMERG); + /* set logtype level low to so we can test global level */ - rte_log_set_level(logtype1, RTE_LOG_DEBUG); - rte_log_set_level(logtype2, RTE_LOG_DEBUG); + rte_log_set_level_pattern("logtype*", RTE_LOG_DEBUG); + CHECK_LEVELS(RTE_LOG_DEBUG, RTE_LOG_DEBUG, RTE_LOG_DEBUG); /* log in error level */ rte_log_set_global_level(RTE_LOG_ERR); @@ -103,6 +148,8 @@ test_logs(void) if (ret < 0) return ret; +#undef CHECK_LEVELS + return 0; } -- 2.23.0