All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v4 1/2] syslog11: convert to new LTP API
@ 2022-07-19 11:05 Hongchen Zhang
  2022-07-19 11:05 ` [LTP] [PATCH v4 2/2] syslog11: save and restore console log level Hongchen Zhang
  2022-07-19 11:42 ` [LTP] [PATCH v4 1/2] syslog11: convert to new LTP API Cyril Hrubis
  0 siblings, 2 replies; 5+ messages in thread
From: Hongchen Zhang @ 2022-07-19 11:05 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: Hongchen Zhang, ltp, Lingling Li

convert to use new LTP API for syslog11.

the non-root user read with EPERM is covered in syslog12.c, so it's
fine to drop it from this test.

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
---
 testcases/kernel/syscalls/syslog/syslog11.c | 234 +++++-----------------------
 1 file changed, 42 insertions(+), 192 deletions(-)

diff --git a/testcases/kernel/syscalls/syslog/syslog11.c b/testcases/kernel/syscalls/syslog/syslog11.c
index b9540ef..8a19a2a 100644
--- a/testcases/kernel/syscalls/syslog/syslog11.c
+++ b/testcases/kernel/syscalls/syslog/syslog11.c
@@ -1,212 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * Author: Madhu T L <madhu.tarikere@wipro.com>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER   : syslog11
- *
- *    EXECUTED BY       : root / superuser
- *
- *    TEST TITLE        : Basic tests for syslog(2)
- *
- *    TEST CASE TOTAL   : 11
- *
- *    AUTHOR            : Madhu T L <madhu.tarikere@wipro.com>
- *
- *    SIGNALS
- *      Uses SIGUSR1 to pause before test if option set.
- *      (See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	Verify that, syslog(2) is successful for type ranging from 1 to 8
- *
- *	Setup:
- *	  Setup signal handling.
- *	  Test caller is superuser
- *	  Check existence of user nobody
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	 Loop if the proper options are given.
- *	  Execute system call
- *	  Check return value, if not successful,
- *		 Issue FAIL message
- *	  Otherwise,
- *		Issue PASS message
- *
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  syslog11 [-c n] [-e] [-f] [-h] [-i n] [-I x] [-p] [-P x] [-t]
- *		where,  -c n : Run n copies concurrently.
- *			-e   : Turn on errno logging.
- *			-f   : Turn off functional testing
- *			-h   : Show help screen
- *			-i n : Execute test n times.
- *			-I x : Execute test for x seconds.
- *			-p   : Pause for SIGUSR1 before starting
- *			-P x : Pause for x seconds between iterations.
- *			-t   : Turn on syscall timing.
+
+/*
+ * [Description]
+ * Verify that, syslog(2) is successful for type ranging from 1 to 8
  *
- ****************************************************************/
+ */
 
 #include <errno.h>
-#include <pwd.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <linux/unistd.h>
-#include <sys/syscall.h>
-#include "test.h"
-#include "safe_macros.h"
 
-#define UNEXP_RET_VAL	-1
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "tst_safe_macros.h"
 
-struct test_case_t {		/* test case structure */
-	int type;		/* 1st arg. */
-	char *buf;		/* 2nd arg. */
-	int len;		/* 3rd arg. */
-	int (*setup) (void);	/* Individual setup routine */
-	void (*cleanup) (void);	/* Individual cleanup routine */
-	char *desc;		/* Test description */
+struct tcase {
+	int type;
+	char *buf;
+	int len;
+	char *desc;
 };
 
-char *TCID = "syslog11";
-static int testno;
 static char buf;
-static struct passwd *ltpuser;
-
-static void setup(void);
-static void cleanup(void);
-static int setup1(void);
-static void cleanup1(void);
 
-#define syslog(arg1, arg2, arg3) syscall(__NR_syslog, arg1, arg2, arg3)
+#define syslog(arg1, arg2, arg3) tst_syscall(__NR_syslog, arg1, arg2, arg3)
 
-static struct test_case_t tdat[] = {
+static struct tcase tcases[] = {
 	/* Type 0 and 1 are currently not implemented, always returns success */
-	{0, &buf, 0, NULL, NULL, "type 0/Close the log"},
-	{1, &buf, 0, NULL, NULL, "type 1/Open the log"},
-	{2, &buf, 0, NULL, NULL, "type 2/Read from the log"},
-	{3, &buf, 0, NULL, NULL, "type 3/Read ring buffer"},
-	{3, &buf, 0, setup1, cleanup1, "type 3/Read ring buffer for non-root "
-	 "user"},
-	/* Next two lines will clear dmesg. Uncomment if that is okay. -Robbie Williamson */
-	/*    { 4, &buf, 0, NULL, NULL, "type 4/Read and clear ring buffer" },            */
-	/*    { 5, &buf, 0, NULL, NULL, "type 5/Clear ring buffer" },                     */
-
-	{8, NULL, 1, NULL, NULL, "type 8/Set log level to 1"},
-	{8, NULL, 7, NULL, NULL, "type 8/Set log level to 7(default)"},
-	{6, NULL, 0, NULL, NULL, "type 6/Disable printk's to console"},
-	{7, NULL, 0, NULL, NULL, "type 7/Enable printk's to console"},
+	{0, &buf, 0, "type 0/Close the log"},
+	{1, &buf, 0, "type 1/Open the log"},
+	{2, &buf, 0, "type 2/Read from the log"},
+	{3, &buf, 0, "type 3/Read ring buffer"},
+	/*
+	 * Next two lines will clear dmesg.
+	 * Uncomment if that is okay. -Robbie Williamson
+	 */
+	/*
+	 * { 4, &buf, 0, "type 4/Read and clear ring buffer" },
+	 * { 5, &buf, 0, "type 5/Clear ring buffer" },
+	 */
+	{8, NULL, 1, "type 8/Set log level to 1"},
+	{8, NULL, 7, "type 8/Set log level to 7(default)"},
+	{6, NULL, 0, "type 6/Disable printk's to console"},
+	{7, NULL, 0, "type 7/Enable printk's to console"},
 };
 
-int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
-
-int main(int argc, char **argv)
+static void run(unsigned int n)
 {
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		for (testno = 0; testno < TST_TOTAL; ++testno) {
+	struct tcase *tc = &tcases[n];
 
-			if (tdat[testno].setup && tdat[testno].setup()) {
-				/* Setup failed, skip this testcase */
-				continue;
-			}
-
-			TEST(syslog(tdat[testno].type, tdat[testno].buf,
-				    tdat[testno].len));
-
-			if (TEST_RETURN == UNEXP_RET_VAL) {
-				if (TEST_ERRNO == EPERM && geteuid() != 0) {
-					tst_resm(TPASS,
-						 "syslog() passed for %s (non-root EPERM is OK)",
-						 tdat[testno].desc);
-				} else {
-					tst_resm(TFAIL,
-						 "syslog() failed for %s: errno "
-						 "%d (%s)", tdat[testno].desc,
-						 TEST_ERRNO, strerror(errno));
-				}
-			} else {
-				tst_resm(TPASS, "syslog() successful for %s",
-					 tdat[testno].desc);
-			}
-
-			if (tdat[testno].cleanup) {
-				tdat[testno].cleanup();
-			}
-		}
-	}
-	cleanup();
-
-	tst_exit();
-}
-
-int setup1(void)
-{
-	/* Change effective user id to nodody */
-	if (seteuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TBROK, "seteuid failed to set the effective"
-			 " uid to %d", ltpuser->pw_uid);
-		return 1;
-	}
-	return 0;
+	TST_EXP_PASS(syslog(tc->type, tc->buf, tc->len),
+			"syslog() with %s", tc->desc);
 }
 
-void cleanup1(void)
-{
-	/* Change effective user id to root */
-	SAFE_SETEUID(NULL, 0);
-}
-
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
-{
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/* Check for nobody_uid user id */
-	if ((ltpuser = getpwnam("nobody")) == NULL) {
-		tst_brkm(TBROK, NULL, "nobody user id doesn't exist");
-	}
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -c option.
-	 */
-	TEST_PAUSE;
-}
-
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.test = run,
+	.needs_root = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+};
-- 
1.8.3.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v4 2/2] syslog11: save and restore console log level
  2022-07-19 11:05 [LTP] [PATCH v4 1/2] syslog11: convert to new LTP API Hongchen Zhang
@ 2022-07-19 11:05 ` Hongchen Zhang
  2022-07-19 11:45   ` Cyril Hrubis
  2022-07-19 11:42 ` [LTP] [PATCH v4 1/2] syslog11: convert to new LTP API Cyril Hrubis
  1 sibling, 1 reply; 5+ messages in thread
From: Hongchen Zhang @ 2022-07-19 11:05 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: Hongchen Zhang, ltp, Lingling Li

the console loglevel is forced to be 7(LOGLEVEL_DEFAULT) after test,
which is not the desired behavior.So we save and restore the console
loglevel using the .save_restore interface.

Signed-off-by: Lingling Li <lilingling@loongson.cn>
Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
---
 testcases/kernel/syscalls/syslog/syslog11.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/testcases/kernel/syscalls/syslog/syslog11.c b/testcases/kernel/syscalls/syslog/syslog11.c
index 8a19a2a..e60bd2b 100644
--- a/testcases/kernel/syscalls/syslog/syslog11.c
+++ b/testcases/kernel/syscalls/syslog/syslog11.c
@@ -57,6 +57,10 @@ static void run(unsigned int n)
 
 static struct tst_test test = {
 	.test = run,
+	.save_restore = (const struct tst_path_val[]) {
+		{"!/proc/sys/kernel/printk", NULL},
+		{NULL, NULL}
+	},
 	.needs_root = 1,
 	.tcnt = ARRAY_SIZE(tcases),
 };
-- 
1.8.3.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH v4 1/2] syslog11: convert to new LTP API
  2022-07-19 11:05 [LTP] [PATCH v4 1/2] syslog11: convert to new LTP API Hongchen Zhang
  2022-07-19 11:05 ` [LTP] [PATCH v4 2/2] syslog11: save and restore console log level Hongchen Zhang
@ 2022-07-19 11:42 ` Cyril Hrubis
  2022-07-19 11:54   ` Hongchen Zhang
  1 sibling, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2022-07-19 11:42 UTC (permalink / raw)
  To: Hongchen Zhang; +Cc: ltp, Lingling Li

Hi!
> +// SPDX-License-Identifier: GPL-2.0

It's GPL-2.0-only see: https://spdx.org/licenses/

I've fixed that and pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH v4 2/2] syslog11: save and restore console log level
  2022-07-19 11:05 ` [LTP] [PATCH v4 2/2] syslog11: save and restore console log level Hongchen Zhang
@ 2022-07-19 11:45   ` Cyril Hrubis
  0 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2022-07-19 11:45 UTC (permalink / raw)
  To: Hongchen Zhang; +Cc: ltp, Lingling Li

Hi!
> Signed-off-by: Lingling Li <lilingling@loongson.cn>
> Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
> ---
>  testcases/kernel/syscalls/syslog/syslog11.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/testcases/kernel/syscalls/syslog/syslog11.c b/testcases/kernel/syscalls/syslog/syslog11.c
> index 8a19a2a..e60bd2b 100644
> --- a/testcases/kernel/syscalls/syslog/syslog11.c
> +++ b/testcases/kernel/syscalls/syslog/syslog11.c
> @@ -57,6 +57,10 @@ static void run(unsigned int n)
>  
>  static struct tst_test test = {
>  	.test = run,
> +	.save_restore = (const struct tst_path_val[]) {
> +		{"!/proc/sys/kernel/printk", NULL},
> +		{NULL, NULL}

I've changed this {NULL, NULL} to just {} in order to fix warnings
reported by 'make check-syslog11' and pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH v4 1/2] syslog11: convert to new LTP API
  2022-07-19 11:42 ` [LTP] [PATCH v4 1/2] syslog11: convert to new LTP API Cyril Hrubis
@ 2022-07-19 11:54   ` Hongchen Zhang
  0 siblings, 0 replies; 5+ messages in thread
From: Hongchen Zhang @ 2022-07-19 11:54 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp, Lingling Li

On 2022/7/19 下午7:42, Cyril Hrubis wrote:
> Hi!
>> +// SPDX-License-Identifier: GPL-2.0
> 
> It's GPL-2.0-only see: https://spdx.org/licenses/
> 
> I've fixed that and pushed, thanks.
> 
Hi Cyril,

Thanks for your patiently review,I will pay attention to this
in the future.

Best Regards,
Hongchen Zhang


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-07-19 11:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19 11:05 [LTP] [PATCH v4 1/2] syslog11: convert to new LTP API Hongchen Zhang
2022-07-19 11:05 ` [LTP] [PATCH v4 2/2] syslog11: save and restore console log level Hongchen Zhang
2022-07-19 11:45   ` Cyril Hrubis
2022-07-19 11:42 ` [LTP] [PATCH v4 1/2] syslog11: convert to new LTP API Cyril Hrubis
2022-07-19 11:54   ` Hongchen Zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.