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 2D570A0579; Wed, 18 Mar 2020 20:06:57 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1A01C1C1AD; Wed, 18 Mar 2020 20:03:44 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id BE0BE1C125 for ; Wed, 18 Mar 2020 20:03:42 +0100 (CET) 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 02IJ0rld010845; Wed, 18 Mar 2020 12:03:42 -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=phhAYL5hE5CZIqStrIqmvjPGiX6VwrnsOIOQMGRHTqs=; b=neaqktlY1/SMMdVcQ4hTdjp38xPRUHe0wV5kFaIcQ/jpU+0ffQWbYi7GJTZRZ6mic5hB VK11ZQX0WmKIoQDXZZ2Fqrkt/+XQWVHSgw1P9FlCq2Ix+15eIQJtKRF08Eowo5ksVSTK jVqK+x8B4JElHltPwd1T1otJnhhq1sN7eNN6TrZKBA97a7p0fwSQE68fswmY86ohUUHN /45z+yzf1eHZ/cZVSP6/HIgjXdL3/XSLkQjih2XvVpPjrQGqyXhOuSf1C61hJ8ira59d aZppPJzge8Gl4xzhl6S+uLmT1C9r81GdkWZhqWYu4HPtFbKQbiygnb8vOsJpII8OdA1U gg== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0a-0016f401.pphosted.com with ESMTP id 2yu8pqm4f8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 18 Mar 2020 12:03:41 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 18 Mar 2020 12:03:40 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 18 Mar 2020 12:03:40 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 7F0F53F703F; Wed, 18 Mar 2020 12:03:38 -0700 (PDT) From: To: CC: , , , , , Date: Thu, 19 Mar 2020 00:32:35 +0530 Message-ID: <20200318190241.3150971-27-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200318190241.3150971-1-jerinj@marvell.com> References: <20200318190241.3150971-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.645 definitions=2020-03-18_07:2020-03-18, 2020-03-18 signatures=0 Subject: [dpdk-dev] [PATCH v1 26/32] 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 1f080d162..8374c5399 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 0a2ce710f..68c1b56df 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..7065b072a --- /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_e 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_e 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, NULL); + if (rc < 0 && rc != -EACCES) + goto failed; + + rc = rte_trace_pattern("app.dpdk.test*", false, NULL); + if (rc < 0 && rc != -EACCES) + goto failed; + + rc = rte_trace_regexp("app.dpdk.test", true, NULL); + if (rc < 0 && rc != -EACCES) + goto failed; + + rc = rte_trace_regexp("app.dpdk.test", false, NULL); + 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_e 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_from_name("app.dpdk.test.emerg"); + if (trace == NULL) + goto fail; + trace = rte_trace_from_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