numam-dpdk/app/test/test_logs.c
Bruce Richardson a9de470cc7 test: move to app directory
Since all other apps have been moved to the "app" folder, the autotest app
remains alone in the test folder. Rather than having an entire top-level
folder for this, we can move it back to where it all started in early
versions of DPDK - the "app/" folder.

This move has a couple of advantages:
* This reduces clutter at the top level of the project, due to one less
  folder.
* It eliminates the separate build task necessary for building the
  autotests using make "make test-build" which means that developers are
  less likely to miss something in their own compilation tests
* It re-aligns the final location of the test binary in the app folder when
  building with make with it's location in the source tree.

For meson builds, the autotest app is different from the other apps in that
it needs a series of different test cases defined for it for use by "meson
test". Therefore, it does not get built as part of the main loop in the
app folder, but gets built separately at the end.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
2019-02-26 15:29:27 +01:00

110 lines
2.7 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2010-2014 Intel Corporation
*/
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <sys/queue.h>
#include <rte_log.h>
#include <rte_memory.h>
#include <rte_launch.h>
#include <rte_eal.h>
#include <rte_per_lcore.h>
#include <rte_lcore.h>
#include "test.h"
/* for legacy log test */
#define RTE_LOGTYPE_TESTAPP1 RTE_LOGTYPE_USER1
#define RTE_LOGTYPE_TESTAPP2 RTE_LOGTYPE_USER2
/*
* Logs
* ====
*
* - Enable log types.
* - Set log level.
* - Send logs with different types and levels, some should not be displayed.
*/
static int
test_legacy_logs(void)
{
printf("== static log types\n");
/* set logtype level low to so we can test global level */
rte_log_set_level(RTE_LOGTYPE_TESTAPP1, RTE_LOG_DEBUG);
rte_log_set_level(RTE_LOGTYPE_TESTAPP2, RTE_LOG_DEBUG);
/* log in error level */
rte_log_set_global_level(RTE_LOG_ERR);
RTE_LOG(ERR, TESTAPP1, "error message\n");
RTE_LOG(CRIT, TESTAPP1, "critical message\n");
/* log in critical level */
rte_log_set_global_level(RTE_LOG_CRIT);
RTE_LOG(ERR, TESTAPP2, "error message (not displayed)\n");
RTE_LOG(CRIT, TESTAPP2, "critical message\n");
/* bump up single log type level above global to test it */
rte_log_set_level(RTE_LOGTYPE_TESTAPP2, RTE_LOG_EMERG);
/* log in error level */
rte_log_set_global_level(RTE_LOG_ERR);
RTE_LOG(ERR, TESTAPP1, "error message\n");
RTE_LOG(ERR, TESTAPP2, "error message (not displayed)\n");
return 0;
}
static int
test_logs(void)
{
int logtype1, logtype2;
int ret;
printf("== dynamic log types\n");
logtype1 = rte_log_register("logtype1");
if (logtype1 < 0) {
printf("Cannot register logtype1\n");
return -1;
}
logtype2 = rte_log_register("logtype2");
if (logtype2 < 0) {
printf("Cannot register logtype2\n");
return -1;
}
/* 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);
/* log in error level */
rte_log_set_global_level(RTE_LOG_ERR);
rte_log(RTE_LOG_ERR, logtype1, "error message\n");
rte_log(RTE_LOG_CRIT, logtype1, "critical message\n");
/* log in critical level */
rte_log_set_global_level(RTE_LOG_CRIT);
rte_log(RTE_LOG_ERR, logtype2, "error message (not displayed)\n");
rte_log(RTE_LOG_CRIT, logtype2, "critical message\n");
/* bump up single log type level above global to test it */
rte_log_set_level(logtype2, RTE_LOG_EMERG);
/* log in error level */
rte_log_set_global_level(RTE_LOG_ERR);
rte_log(RTE_LOG_ERR, logtype1, "error message\n");
rte_log(RTE_LOG_ERR, logtype2, "error message (not displayed)\n");
ret = test_legacy_logs();
if (ret < 0)
return ret;
return 0;
}
REGISTER_TEST_COMMAND(logs_autotest, test_logs);