xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/syslog/syslog11.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-only
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
4*49cdfc7eSAndroid Build Coastguard Worker  * Author: Madhu T L <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker  */
6*49cdfc7eSAndroid Build Coastguard Worker 
7*49cdfc7eSAndroid Build Coastguard Worker /*
8*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
9*49cdfc7eSAndroid Build Coastguard Worker  *
10*49cdfc7eSAndroid Build Coastguard Worker  * Verify that, syslog(2) is successful for type ranging from 1 to 8
11*49cdfc7eSAndroid Build Coastguard Worker  */
12*49cdfc7eSAndroid Build Coastguard Worker 
13*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
14*49cdfc7eSAndroid Build Coastguard Worker 
15*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
16*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/syscalls.h"
17*49cdfc7eSAndroid Build Coastguard Worker #include "tst_safe_macros.h"
18*49cdfc7eSAndroid Build Coastguard Worker 
19*49cdfc7eSAndroid Build Coastguard Worker struct tcase {
20*49cdfc7eSAndroid Build Coastguard Worker 	int type;
21*49cdfc7eSAndroid Build Coastguard Worker 	char *buf;
22*49cdfc7eSAndroid Build Coastguard Worker 	int len;
23*49cdfc7eSAndroid Build Coastguard Worker 	char *desc;
24*49cdfc7eSAndroid Build Coastguard Worker };
25*49cdfc7eSAndroid Build Coastguard Worker 
26*49cdfc7eSAndroid Build Coastguard Worker static char buf;
27*49cdfc7eSAndroid Build Coastguard Worker 
28*49cdfc7eSAndroid Build Coastguard Worker #define syslog(arg1, arg2, arg3) tst_syscall(__NR_syslog, arg1, arg2, arg3)
29*49cdfc7eSAndroid Build Coastguard Worker 
30*49cdfc7eSAndroid Build Coastguard Worker static struct tcase tcases[] = {
31*49cdfc7eSAndroid Build Coastguard Worker 	/* Type 0 and 1 are currently not implemented, always returns success */
32*49cdfc7eSAndroid Build Coastguard Worker 	{0, &buf, 0, "type 0/Close the log"},
33*49cdfc7eSAndroid Build Coastguard Worker 	{1, &buf, 0, "type 1/Open the log"},
34*49cdfc7eSAndroid Build Coastguard Worker 	{2, &buf, 0, "type 2/Read from the log"},
35*49cdfc7eSAndroid Build Coastguard Worker 	{3, &buf, 0, "type 3/Read ring buffer"},
36*49cdfc7eSAndroid Build Coastguard Worker 	/*
37*49cdfc7eSAndroid Build Coastguard Worker 	 * Next two lines will clear dmesg.
38*49cdfc7eSAndroid Build Coastguard Worker 	 * Uncomment if that is okay. -Robbie Williamson
39*49cdfc7eSAndroid Build Coastguard Worker 	 */
40*49cdfc7eSAndroid Build Coastguard Worker 	/*
41*49cdfc7eSAndroid Build Coastguard Worker 	 * { 4, &buf, 0, "type 4/Read and clear ring buffer" },
42*49cdfc7eSAndroid Build Coastguard Worker 	 * { 5, &buf, 0, "type 5/Clear ring buffer" },
43*49cdfc7eSAndroid Build Coastguard Worker 	 */
44*49cdfc7eSAndroid Build Coastguard Worker 	{8, NULL, 1, "type 8/Set log level to 1"},
45*49cdfc7eSAndroid Build Coastguard Worker 	{8, NULL, 7, "type 8/Set log level to 7(default)"},
46*49cdfc7eSAndroid Build Coastguard Worker 	{6, NULL, 0, "type 6/Disable printk's to console"},
47*49cdfc7eSAndroid Build Coastguard Worker 	{7, NULL, 0, "type 7/Enable printk's to console"},
48*49cdfc7eSAndroid Build Coastguard Worker };
49*49cdfc7eSAndroid Build Coastguard Worker 
run(unsigned int n)50*49cdfc7eSAndroid Build Coastguard Worker static void run(unsigned int n)
51*49cdfc7eSAndroid Build Coastguard Worker {
52*49cdfc7eSAndroid Build Coastguard Worker 	struct tcase *tc = &tcases[n];
53*49cdfc7eSAndroid Build Coastguard Worker 
54*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_PASS(syslog(tc->type, tc->buf, tc->len),
55*49cdfc7eSAndroid Build Coastguard Worker 			"syslog() with %s", tc->desc);
56*49cdfc7eSAndroid Build Coastguard Worker }
57*49cdfc7eSAndroid Build Coastguard Worker 
58*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
59*49cdfc7eSAndroid Build Coastguard Worker 	.test = run,
60*49cdfc7eSAndroid Build Coastguard Worker 	.save_restore = (const struct tst_path_val[]) {
61*49cdfc7eSAndroid Build Coastguard Worker 		{"/proc/sys/kernel/printk", NULL, TST_SR_TBROK},
62*49cdfc7eSAndroid Build Coastguard Worker 		{}
63*49cdfc7eSAndroid Build Coastguard Worker 	},
64*49cdfc7eSAndroid Build Coastguard Worker 	.needs_root = 1,
65*49cdfc7eSAndroid Build Coastguard Worker 	.tcnt = ARRAY_SIZE(tcases),
66*49cdfc7eSAndroid Build Coastguard Worker };
67