1 /*
2  * Copyright (c) 2024, Meta
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/posix/syslog.h>
8 #undef LOG_ERR
9 #include <zephyr/posix/unistd.h>
10 #include <zephyr/ztest.h>
11 
12 #define N_PRIOS 8
13 /* avoid clashing with Zephyr's LOG_ERR() */
14 #define _LOG_ERR 3
15 
ZTEST(syslog,test_syslog)16 ZTEST(syslog, test_syslog)
17 {
18 	int prios[N_PRIOS] = {
19 		LOG_EMERG,   LOG_ALERT,  LOG_CRIT, _LOG_ERR,
20 		LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG,
21 	};
22 
23 	openlog("syslog", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_LOCAL7);
24 	(void)setlogmask(LOG_MASK(-1));
25 
26 	for (size_t i = 0; i < N_PRIOS; ++i) {
27 		syslog(i, "syslog priority %d", prios[i]);
28 	}
29 
30 	closelog();
31 
32 	/* yield briefly to logging thread */
33 	usleep(100000);
34 }
35 
36 ZTEST_SUITE(syslog, NULL, NULL, NULL, NULL, NULL);
37