From d8072a9492a1e2072ca774e031e734e7b62c84c2 Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Fri, 9 Feb 2024 06:56:08 -0500 Subject: [PATCH] tests: posix: add a compile-and-run-only test for syslog Ensure that we have code coverage for syslog and that it can compiles and run with regular tests. Signed-off-by: Christopher Friedt --- tests/posix/common/src/syslog.c | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/posix/common/src/syslog.c diff --git a/tests/posix/common/src/syslog.c b/tests/posix/common/src/syslog.c new file mode 100644 index 00000000000000..87b1ac5ac1a1ad --- /dev/null +++ b/tests/posix/common/src/syslog.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024, Meta + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#undef LOG_ERR +#include + +#define N_PRIOS 8 +/* avoid clashing with Zephyr's LOG_ERR() */ +#define _LOG_ERR 3 + +ZTEST(syslog, test_syslog) +{ + int prios[N_PRIOS] = { + LOG_EMERG, LOG_ALERT, LOG_CRIT, _LOG_ERR, + LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG, + }; + + openlog("syslog", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_LOCAL7); + (void)setlogmask(LOG_MASK(-1)); + + for (size_t i = 0; i < N_PRIOS; ++i) { + syslog(i, "syslog priority %d", prios[i]); + } + + closelog(); + + /* yield briefly to logging thread */ + usleep(100000); +} + +ZTEST_SUITE(syslog, NULL, NULL, NULL, NULL, NULL);