From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B18A6A0562; Fri, 3 Apr 2020 17:42:52 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 15D581C237; Fri, 3 Apr 2020 17:38:40 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 535D81C0C4 for ; Fri, 3 Apr 2020 17:38:39 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 033FacxG029269; Fri, 3 Apr 2020 08:38:38 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=V2QbbHiw6U6McdFymbIuwv9b4X8T9S2NaMUMKREuYXw=; b=sTKTD33Ttc7iA60G9JQsq/IJrZCflqGKAIt13MZQAwYC9jJl17RaU/y5RayQQyQ+hzYn kBFoqrIuNtBrpame/1EtcTFM9Pgaa/oNGNjIIu7BXPy9/xyTjSrC9f8Oy4ho/NkQzxME vtlnZT7cz/qXfgBwxnvPCRFjLJa9gduCxdNzlQ5/CMrJTwuRSKGmkZaSyJJk1DLbjLy0 fP1NdsqtsV3U/3kBy6WDscf526/cRMbW93gHOlHXnzMTlnL10s1zp01JS7OyFbOL2Vx8 Om+PaXbAdNsRCyt7LZMAZUdfVzk0ydcZOSpLMfd3Lb3aJOSjp57gg0fvA9IzSsyDCvNU Qw== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0a-0016f401.pphosted.com with ESMTP id 304855y7j1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 03 Apr 2020 08:38:38 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 3 Apr 2020 08:38:36 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 3 Apr 2020 08:38:37 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id EA52D3F703F; Fri, 3 Apr 2020 08:38:34 -0700 (PDT) From: To: CC: , , , , , Date: Fri, 3 Apr 2020 21:07:03 +0530 Message-ID: <20200403153709.3703448-28-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200403153709.3703448-1-jerinj@marvell.com> References: <20200329144342.1543749-1-jerinj@marvell.com> <20200403153709.3703448-1-jerinj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.676 definitions=2020-04-03_11:2020-04-03, 2020-04-03 signatures=0 Subject: [dpdk-dev] [PATCH v4 27/33] eal/trace: add unit test cases X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" From: Sunil Kumar Kori Example commands to run UT and check the traces with babeltrace viewer. - Delete the existing /root/dpdk-traces/ directory if needed. > sudo rm -rf /root/dpdk-traces/ - Start the dpdk-test > sudo ./build/app/test/dpdk-test -c 0x3 - --trace-level=8 - Run trace_autotest > trace_autotest - View the traces with babletrace viewer. > sudo babeltrace /root/dpdk-traces/ Signed-off-by: Sunil Kumar Kori --- app/test/Makefile | 3 +- app/test/meson.build | 2 + app/test/test_trace.c | 618 +++++++++++++++++++++++++++++++++ app/test/test_trace.h | 52 +++ app/test/test_trace_register.c | 46 +++ 5 files changed, 720 insertions(+), 1 deletion(-) create mode 100644 app/test/test_trace.c create mode 100644 app/test/test_trace.h create mode 100644 app/test/test_trace_register.c diff --git a/app/test/Makefile b/app/test/Makefile index be53d33c3..9fb7b843f 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -148,7 +148,8 @@ SRCS-y += test_alarm.c SRCS-y += test_interrupts.c SRCS-y += test_version.c SRCS-y += test_func_reentrancy.c - +SRCS-y += test_trace.c +SRCS-y += test_trace_register.c SRCS-y += test_service_cores.c ifeq ($(CONFIG_RTE_LIBRTE_PMD_RING),y) diff --git a/app/test/meson.build b/app/test/meson.build index 351d29cb6..4966236e8 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -121,6 +121,8 @@ test_sources = files('commands.c', 'test_timer_racecond.c', 'test_timer_secondary.c', 'test_ticketlock.c', + 'test_trace.c', + 'test_trace_register.c', 'test_version.c', 'virtual_pmd.c' ) diff --git a/app/test/test_trace.c b/app/test/test_trace.c new file mode 100644 index 000000000..c739cfe59 --- /dev/null +++ b/app/test/test_trace.c @@ -0,0 +1,618 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell International Ltd. + */ + +#include +#include + +#include "test.h" +#include "test_trace.h" + +struct tp_config { + int mode; + int level; + bool enabled; +}; + +struct trace_config { + uint32_t level; + enum rte_trace_mode mode; + struct tp_config conf[RTE_LOG_DEBUG + 1]; +}; + +static void +trace_config_save(struct trace_config *conf) +{ + /* Save global config */ + conf->mode = rte_trace_global_mode_get(); + conf->level = rte_trace_global_level_get(); + + /* Save trace specific config */ + conf->conf[RTE_LOG_EMERG].mode = + rte_trace_mode_get(&__app_dpdk_test_emerg); + conf->conf[RTE_LOG_EMERG].level = + rte_trace_level_get(&__app_dpdk_test_emerg); + conf->conf[RTE_LOG_EMERG].enabled = + rte_trace_is_enabled(&__app_dpdk_test_emerg); + + conf->conf[RTE_LOG_ALERT].mode = + rte_trace_mode_get(&__app_dpdk_test_alert); + conf->conf[RTE_LOG_ALERT].level = + rte_trace_level_get(&__app_dpdk_test_alert); + conf->conf[RTE_LOG_ALERT].enabled = + rte_trace_is_enabled(&__app_dpdk_test_alert); + + conf->conf[RTE_LOG_CRIT].mode = + rte_trace_mode_get(&__app_dpdk_test_crit); + conf->conf[RTE_LOG_CRIT].level = + rte_trace_level_get(&__app_dpdk_test_crit); + conf->conf[RTE_LOG_CRIT].enabled = + rte_trace_is_enabled(&__app_dpdk_test_crit); + + conf->conf[RTE_LOG_ERR].mode = + rte_trace_mode_get(&__app_dpdk_test_err); + conf->conf[RTE_LOG_ERR].level = + rte_trace_level_get(&__app_dpdk_test_err); + conf->conf[RTE_LOG_ERR].enabled = + rte_trace_is_enabled(&__app_dpdk_test_err); + + conf->conf[RTE_LOG_WARNING].mode = + rte_trace_mode_get(&__app_dpdk_test_warning); + conf->conf[RTE_LOG_WARNING].level = + rte_trace_level_get(&__app_dpdk_test_warning); + conf->conf[RTE_LOG_WARNING].enabled = + rte_trace_is_enabled(&__app_dpdk_test_warning); + + conf->conf[RTE_LOG_NOTICE].mode = + rte_trace_mode_get(&__app_dpdk_test_notice); + conf->conf[RTE_LOG_NOTICE].level = + rte_trace_level_get(&__app_dpdk_test_notice); + conf->conf[RTE_LOG_NOTICE].enabled = + rte_trace_is_enabled(&__app_dpdk_test_notice); + + conf->conf[RTE_LOG_INFO].mode = + rte_trace_mode_get(&__app_dpdk_test_info); + conf->conf[RTE_LOG_INFO].level = + rte_trace_level_get(&__app_dpdk_test_info); + conf->conf[RTE_LOG_INFO].enabled = + rte_trace_is_enabled(&__app_dpdk_test_info); + + conf->conf[RTE_LOG_DEBUG].mode = + rte_trace_mode_get(&__app_dpdk_test_debug); + conf->conf[RTE_LOG_DEBUG].level = + rte_trace_level_get(&__app_dpdk_test_debug); + conf->conf[RTE_LOG_DEBUG].enabled = + rte_trace_is_enabled(&__app_dpdk_test_debug); +} + +static void +trace_config_restore(struct trace_config *conf) +{ + /* Restore global config */ + rte_trace_global_mode_set(conf->mode); + rte_trace_global_level_set(conf->level); + + /* Restore trace specific config */ + rte_trace_mode_set(&__app_dpdk_test_emerg, + conf->conf[RTE_LOG_EMERG].mode); + rte_trace_level_set(&__app_dpdk_test_emerg, + conf->conf[RTE_LOG_EMERG].level); + if (conf->conf[RTE_LOG_EMERG].enabled) + rte_trace_enable(&__app_dpdk_test_emerg); + else + rte_trace_disable(&__app_dpdk_test_emerg); + + rte_trace_mode_set(&__app_dpdk_test_alert, + conf->conf[RTE_LOG_ALERT].mode); + rte_trace_level_set(&__app_dpdk_test_alert, + conf->conf[RTE_LOG_ALERT].level); + if (conf->conf[RTE_LOG_ALERT].enabled) + rte_trace_enable(&__app_dpdk_test_alert); + else + rte_trace_disable(&__app_dpdk_test_alert); + + rte_trace_mode_set(&__app_dpdk_test_crit, + conf->conf[RTE_LOG_CRIT].mode); + rte_trace_level_set(&__app_dpdk_test_crit, + conf->conf[RTE_LOG_CRIT].level); + if (conf->conf[RTE_LOG_CRIT].enabled) + rte_trace_enable(&__app_dpdk_test_crit); + else + rte_trace_disable(&__app_dpdk_test_crit); + + rte_trace_mode_set(&__app_dpdk_test_err, + conf->conf[RTE_LOG_ERR].mode); + rte_trace_level_set(&__app_dpdk_test_err, + conf->conf[RTE_LOG_ERR].level); + if (conf->conf[RTE_LOG_ERR].enabled) + rte_trace_enable(&__app_dpdk_test_err); + else + rte_trace_disable(&__app_dpdk_test_err); + + rte_trace_mode_set(&__app_dpdk_test_warning, + conf->conf[RTE_LOG_WARNING].mode); + rte_trace_level_set(&__app_dpdk_test_warning, + conf->conf[RTE_LOG_WARNING].level); + if (conf->conf[RTE_LOG_WARNING].enabled) + rte_trace_enable(&__app_dpdk_test_warning); + else + rte_trace_disable(&__app_dpdk_test_warning); + + rte_trace_mode_set(&__app_dpdk_test_notice, + conf->conf[RTE_LOG_NOTICE].mode); + rte_trace_level_set(&__app_dpdk_test_notice, + conf->conf[RTE_LOG_NOTICE].level); + if (conf->conf[RTE_LOG_NOTICE].enabled) + rte_trace_enable(&__app_dpdk_test_notice); + else + rte_trace_disable(&__app_dpdk_test_notice); + + rte_trace_mode_set(&__app_dpdk_test_info, + conf->conf[RTE_LOG_INFO].mode); + rte_trace_level_set(&__app_dpdk_test_info, + conf->conf[RTE_LOG_INFO].level); + if (conf->conf[RTE_LOG_INFO].enabled) + rte_trace_enable(&__app_dpdk_test_info); + else + rte_trace_disable(&__app_dpdk_test_info); + + rte_trace_mode_set(&__app_dpdk_test_debug, + conf->conf[RTE_LOG_DEBUG].mode); + rte_trace_level_set(&__app_dpdk_test_debug, + conf->conf[RTE_LOG_DEBUG].level); + if (conf->conf[RTE_LOG_DEBUG].enabled) + rte_trace_enable(&__app_dpdk_test_debug); + else + rte_trace_disable(&__app_dpdk_test_debug); +} + +static void +emit_trace_points(void) +{ + app_dpdk_test_emerg("app.dpdk.test.emerg"); + app_dpdk_test_alert("app.dpdk.test.alert"); + app_dpdk_test_crit("app.dpdk.test.crit"); + app_dpdk_test_err("app.dpdk.test.err"); + app_dpdk_test_warning("app.dpdk.test.warning"); + app_dpdk_test_notice("app.dpdk.test.notice"); + app_dpdk_test_info("app.dpdk.test.info"); + app_dpdk_test_debug("app.dpdk.test.debug"); +} + +static int32_t +enable_trace_points(void) +{ + int rc; + + rc = rte_trace_enable(&__app_dpdk_test_emerg); + if (rc < 0 && rc != -EACCES) + goto failed; + + rc = rte_trace_enable(&__app_dpdk_test_alert); + if (rc < 0 && rc != -EACCES) + goto failed; + + rc = rte_trace_enable(&__app_dpdk_test_crit); + if (rc < 0 && rc != -EACCES) + goto failed; + + rc = rte_trace_enable(&__app_dpdk_test_err); + if (rc < 0 && rc != -EACCES) + goto failed; + + rc = rte_trace_enable(&__app_dpdk_test_warning); + if (rc < 0 && rc != -EACCES) + goto failed; + + rc = rte_trace_enable(&__app_dpdk_test_notice); + if (rc < 0 && rc != -EACCES) + goto failed; + + rc = rte_trace_enable(&__app_dpdk_test_info); + if (rc < 0 && rc != -EACCES) + goto failed; + + rc = rte_trace_enable(&__app_dpdk_test_debug); + if (rc < 0 && rc != -EACCES) + goto failed; + + return 0; + +failed: + return rc; +} + +static int32_t +disable_trace_points(void) +{ + int rc; + + rc = rte_trace_disable(&__app_dpdk_test_emerg); + if (rc < 0) + goto failed; + + rc = rte_trace_disable(&__app_dpdk_test_alert); + if (rc < 0) + goto failed; + + rc = rte_trace_disable(&__app_dpdk_test_crit); + if (rc < 0) + goto failed; + + rc = rte_trace_disable(&__app_dpdk_test_err); + if (rc < 0) + goto failed; + + rc = rte_trace_disable(&__app_dpdk_test_warning); + if (rc < 0) + goto failed; + + rc = rte_trace_disable(&__app_dpdk_test_notice); + if (rc < 0) + goto failed; + + rc = rte_trace_disable(&__app_dpdk_test_info); + if (rc < 0) + goto failed; + + rc = rte_trace_disable(&__app_dpdk_test_debug); + if (rc < 0) + goto failed; + + return 0; + +failed: + return rc; +} + +static int32_t +reverse_trace_points_mode(void) +{ + enum rte_trace_mode mode[] = {RTE_TRACE_MODE_DISCARD, + RTE_TRACE_MODE_OVERWRITE}; + uint32_t trace_mode; + int rc = -1; + + trace_mode = rte_trace_mode_get(&__app_dpdk_test_emerg); + if (trace_mode == RTE_TRACE_MODE_DISCARD || + trace_mode == RTE_TRACE_MODE_OVERWRITE) { + rc = rte_trace_mode_set(&__app_dpdk_test_emerg, + mode[trace_mode]); + if (rc < 0) + goto failed; + } + + trace_mode = rte_trace_mode_get(&__app_dpdk_test_alert); + if (trace_mode == RTE_TRACE_MODE_DISCARD || + trace_mode == RTE_TRACE_MODE_OVERWRITE) { + rc = rte_trace_mode_set(&__app_dpdk_test_alert, + mode[trace_mode]); + if (rc < 0) + goto failed; + } + + trace_mode = rte_trace_mode_get(&__app_dpdk_test_crit); + if (trace_mode == RTE_TRACE_MODE_DISCARD || + trace_mode == RTE_TRACE_MODE_OVERWRITE) { + rc = rte_trace_mode_set(&__app_dpdk_test_crit, + mode[trace_mode]); + if (rc < 0) + goto failed; + } + + trace_mode = rte_trace_mode_get(&__app_dpdk_test_err); + if (trace_mode == RTE_TRACE_MODE_DISCARD || + trace_mode == RTE_TRACE_MODE_OVERWRITE) { + rc = rte_trace_mode_set(&__app_dpdk_test_err, + mode[trace_mode]); + if (rc < 0) + goto failed; + } + + trace_mode = rte_trace_mode_get(&__app_dpdk_test_warning); + if (trace_mode == RTE_TRACE_MODE_DISCARD || + trace_mode == RTE_TRACE_MODE_OVERWRITE) { + rc = rte_trace_mode_set(&__app_dpdk_test_warning, + mode[trace_mode]); + if (rc < 0) + goto failed; + } + + trace_mode = rte_trace_mode_get(&__app_dpdk_test_notice); + if (trace_mode == RTE_TRACE_MODE_DISCARD || + trace_mode == RTE_TRACE_MODE_OVERWRITE) { + rc = rte_trace_mode_set(&__app_dpdk_test_notice, + mode[trace_mode]); + if (rc < 0) + goto failed; + } + + trace_mode = rte_trace_mode_get(&__app_dpdk_test_info); + if (trace_mode == RTE_TRACE_MODE_DISCARD || + trace_mode == RTE_TRACE_MODE_OVERWRITE) { + rc = rte_trace_mode_set(&__app_dpdk_test_info, + mode[trace_mode]); + if (rc < 0) + goto failed; + } + + trace_mode = rte_trace_mode_get(&__app_dpdk_test_debug); + if (trace_mode == RTE_TRACE_MODE_DISCARD || + trace_mode == RTE_TRACE_MODE_OVERWRITE) { + rc = rte_trace_mode_set(&__app_dpdk_test_debug, + mode[trace_mode]); + if (rc < 0) + goto failed; + } + +failed: + return rc; +} + +static int32_t +reverse_trace_points_level(void) +{ + uint32_t level[] = {0, RTE_LOG_DEBUG, RTE_LOG_INFO, RTE_LOG_NOTICE, + RTE_LOG_WARNING, RTE_LOG_ERR, RTE_LOG_CRIT, + RTE_LOG_ALERT, RTE_LOG_EMERG, 0}; + uint32_t trace_level; + int rc = -1; + + trace_level = rte_trace_level_get(&__app_dpdk_test_emerg); + if (trace_level >= RTE_LOG_EMERG && trace_level <= RTE_LOG_DEBUG) { + rc = rte_trace_level_set(&__app_dpdk_test_emerg, + level[trace_level]); + if (rc < 0) + goto failed; + } + + trace_level = rte_trace_level_get(&__app_dpdk_test_alert); + if (trace_level >= RTE_LOG_EMERG && trace_level <= RTE_LOG_DEBUG) { + rc = rte_trace_level_set(&__app_dpdk_test_alert, + level[trace_level]); + if (rc < 0) + goto failed; + } + + trace_level = rte_trace_level_get(&__app_dpdk_test_crit); + if (trace_level >= RTE_LOG_EMERG && trace_level <= RTE_LOG_DEBUG) { + rc = rte_trace_level_set(&__app_dpdk_test_crit, + level[trace_level]); + if (rc < 0) + goto failed; + } + + trace_level = rte_trace_level_get(&__app_dpdk_test_err); + if (trace_level >= RTE_LOG_EMERG && trace_level <= RTE_LOG_DEBUG) { + rc = rte_trace_level_set(&__app_dpdk_test_err, + level[trace_level]); + if (rc < 0) + goto failed; + } + + trace_level = rte_trace_level_get(&__app_dpdk_test_warning); + if (trace_level >= RTE_LOG_EMERG && trace_level <= RTE_LOG_DEBUG) { + rc = rte_trace_level_set(&__app_dpdk_test_warning, + level[trace_level]); + if (rc < 0) + goto failed; + } + + trace_level = rte_trace_level_get(&__app_dpdk_test_notice); + if (trace_level >= RTE_LOG_EMERG && trace_level <= RTE_LOG_DEBUG) { + rc = rte_trace_level_set(&__app_dpdk_test_notice, + level[trace_level]); + if (rc < 0) + goto failed; + } + + trace_level = rte_trace_level_get(&__app_dpdk_test_info); + if (trace_level >= RTE_LOG_EMERG && trace_level <= RTE_LOG_DEBUG) { + rc = rte_trace_level_set(&__app_dpdk_test_info, + level[trace_level]); + if (rc < 0) + goto failed; + } + + trace_level = rte_trace_level_get(&__app_dpdk_test_debug); + if (trace_level >= RTE_LOG_EMERG && trace_level <= RTE_LOG_DEBUG) { + rc = rte_trace_level_set(&__app_dpdk_test_debug, + level[trace_level]); + if (rc < 0) + goto failed; + } + +failed: + return rc; +} + +static int +test_trace_level(void) +{ + if (enable_trace_points() < 0) + goto failed; + + emit_trace_points(); + + if (reverse_trace_points_level() < 0) + goto failed; + + emit_trace_points(); + + return 0; + +failed: + return -1; +} + +static int32_t +test_trace_points_enable_disable(void) +{ + struct trace_config conf; + int rc; + + trace_config_save(&conf); + + if (enable_trace_points() < 0) + goto failed; + + if (disable_trace_points() < 0) + goto failed; + + rc = rte_trace_pattern("app.dpdk.test*", true); + if (rc < 0 && rc != -EACCES) + goto failed; + + rc = rte_trace_pattern("app.dpdk.test*", false); + if (rc < 0 && rc != -EACCES) + goto failed; + + rc = rte_trace_regexp("app.dpdk.test", true); + if (rc < 0 && rc != -EACCES) + goto failed; + + rc = rte_trace_regexp("app.dpdk.test", false); + if (rc < 0 && rc != -EACCES) + goto failed; + + trace_config_restore(&conf); + test_trace_level(); + trace_config_restore(&conf); + + return TEST_SUCCESS; + +failed: + return TEST_FAILED; +} + +static int32_t +test_trace_points_level_get_set(void) +{ + uint32_t level[] = {0, RTE_LOG_DEBUG, RTE_LOG_INFO, RTE_LOG_NOTICE, + RTE_LOG_WARNING, RTE_LOG_ERR, RTE_LOG_CRIT, + RTE_LOG_ALERT, RTE_LOG_EMERG, 0}; + struct trace_config conf; + uint32_t g_level; + + trace_config_save(&conf); + + /* Validate global trace level */ + g_level = rte_trace_global_level_get(); + if (g_level >= RTE_LOG_EMERG && g_level <= RTE_LOG_DEBUG) + rte_trace_global_level_set(level[g_level]); + + if (reverse_trace_points_level() < 0) + return TEST_FAILED; + + trace_config_restore(&conf); + return TEST_SUCCESS; +} + +static int32_t +test_trace_points_mode_get_set(void) +{ + enum rte_trace_mode mode[] = {RTE_TRACE_MODE_DISCARD, + RTE_TRACE_MODE_OVERWRITE}; + struct trace_config conf; + uint32_t g_mode; + + trace_config_save(&conf); + emit_trace_points(); + + /* Validate global trace mode */ + g_mode = rte_trace_global_mode_get(); + if (g_mode == RTE_TRACE_MODE_DISCARD || + g_mode == RTE_TRACE_MODE_OVERWRITE) + rte_trace_global_mode_set(mode[g_mode]); + + emit_trace_points(); + + if (reverse_trace_points_mode() < 0) + return TEST_FAILED; + + emit_trace_points(); + + trace_config_restore(&conf); + return TEST_SUCCESS; +} + +static int +test_trace_points_lookup(void) +{ + rte_trace_t *trace; + + trace = rte_trace_by_name("app.dpdk.test.emerg"); + if (trace == NULL) + goto fail; + trace = rte_trace_by_name("this_trace_point_does_not_exist"); + if (trace != NULL) + goto fail; + + return TEST_SUCCESS; +fail: + return TEST_FAILED; +} + +static int +test_generic_trace_points(void) +{ + int tmp; + + rte_trace_lib_eal_generic_void(); + rte_trace_lib_eal_generic_u64(0x10000000000000); + rte_trace_lib_eal_generic_u32(0x10000000); + rte_trace_lib_eal_generic_u16(0xffee); + rte_trace_lib_eal_generic_u8(0xc); + rte_trace_lib_eal_generic_i64(-1234); + rte_trace_lib_eal_generic_i32(-1234567); + rte_trace_lib_eal_generic_i16(12); + rte_trace_lib_eal_generic_i8(-3); + rte_trace_lib_eal_generic_int(3333333); + rte_trace_lib_eal_generic_long(333); + rte_trace_lib_eal_generic_float(20.45); + rte_trace_lib_eal_generic_double(20000.5000004); + rte_trace_lib_eal_generic_ptr(&tmp); + rte_trace_lib_eal_generic_str("my string"); + RTE_TRACE_LIB_EAL_GENERIC_FUNC; + + return TEST_SUCCESS; +} + +static struct unit_test_suite trace_tests = { + .suite_name = "trace autotest", + .setup = NULL, + .teardown = NULL, + .unit_test_cases = { + TEST_CASE(test_generic_trace_points), + TEST_CASE(test_trace_points_enable_disable), + TEST_CASE(test_trace_points_level_get_set), + TEST_CASE(test_trace_points_mode_get_set), + TEST_CASE(test_trace_points_lookup), + TEST_CASES_END() + } +}; + +static int +test_trace(void) +{ + return unit_test_suite_runner(&trace_tests); +} + +REGISTER_TEST_COMMAND(trace_autotest, test_trace); + +static int +test_trace_dump(void) +{ + rte_trace_dump(stdout); + return 0; +} + +REGISTER_TEST_COMMAND(trace_dump, test_trace_dump); + +static int +test_trace_metadata_dump(void) +{ + return rte_trace_metadata_dump(stdout); +} + +REGISTER_TEST_COMMAND(trace_metadata_dump, test_trace_metadata_dump); diff --git a/app/test/test_trace.h b/app/test/test_trace.h new file mode 100644 index 000000000..fc1310c73 --- /dev/null +++ b/app/test/test_trace.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell International Ltd. + */ +#include + +RTE_TRACE_POINT( + app_dpdk_test_emerg, + RTE_TRACE_POINT_ARGS(const char *str), + rte_trace_ctf_string(str); +) + +RTE_TRACE_POINT( + app_dpdk_test_alert, + RTE_TRACE_POINT_ARGS(const char *str), + rte_trace_ctf_string(str); +) + +RTE_TRACE_POINT( + app_dpdk_test_crit, + RTE_TRACE_POINT_ARGS(const char *str), + rte_trace_ctf_string(str); +) + +RTE_TRACE_POINT( + app_dpdk_test_err, + RTE_TRACE_POINT_ARGS(const char *str), + rte_trace_ctf_string(str); +) + +RTE_TRACE_POINT( + app_dpdk_test_warning, + RTE_TRACE_POINT_ARGS(const char *str), + rte_trace_ctf_string(str); +) + +RTE_TRACE_POINT( + app_dpdk_test_notice, + RTE_TRACE_POINT_ARGS(const char *str), + rte_trace_ctf_string(str); +) + +RTE_TRACE_POINT( + app_dpdk_test_info, + RTE_TRACE_POINT_ARGS(const char *str), + rte_trace_ctf_string(str); +) + +RTE_TRACE_POINT( + app_dpdk_test_debug, + RTE_TRACE_POINT_ARGS(const char *str), + rte_trace_ctf_string(str); +) diff --git a/app/test/test_trace_register.c b/app/test/test_trace_register.c new file mode 100644 index 000000000..8fb6bf6e1 --- /dev/null +++ b/app/test/test_trace_register.c @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell International Ltd. + */ +#define RTE_TRACE_POINT_REGISTER_SELECT /* Select trace point register macros */ + +#include + +#include "test_trace.h" + +/* Define trace points */ +RTE_TRACE_POINT_DEFINE(app_dpdk_test_emerg); +RTE_TRACE_POINT_DEFINE(app_dpdk_test_alert); +RTE_TRACE_POINT_DEFINE(app_dpdk_test_crit); +RTE_TRACE_POINT_DEFINE(app_dpdk_test_err); +RTE_TRACE_POINT_DEFINE(app_dpdk_test_warning); +RTE_TRACE_POINT_DEFINE(app_dpdk_test_notice); +RTE_TRACE_POINT_DEFINE(app_dpdk_test_info); +RTE_TRACE_POINT_DEFINE(app_dpdk_test_debug); + +RTE_INIT(register_valid_trace_points) +{ + RTE_TRACE_POINT_REGISTER(app_dpdk_test_emerg, + app.dpdk.test.emerg, EMERG); + + RTE_TRACE_POINT_REGISTER(app_dpdk_test_alert, + app.dpdk.test.alert, ALERT); + + RTE_TRACE_POINT_REGISTER(app_dpdk_test_crit, + app.dpdk.test.crit, CRIT); + + RTE_TRACE_POINT_REGISTER(app_dpdk_test_err, + app.dpdk.test.err, ERR); + + RTE_TRACE_POINT_REGISTER(app_dpdk_test_warning, + app.dpdk.test.warning, WARNING); + + RTE_TRACE_POINT_REGISTER(app_dpdk_test_notice, + app.dpdk.test.notice, NOTICE); + + RTE_TRACE_POINT_REGISTER(app_dpdk_test_info, + app.dpdk.test.info, INFO); + + RTE_TRACE_POINT_REGISTER(app_dpdk_test_debug, + app.dpdk.test.debug, DEBUG); +} + -- 2.25.1