Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH] syslog11: fix console loglevel changed after test
@ 2022-06-27  7:40 Hongchen Zhang
  2022-07-18  9:04 ` Cyril Hrubis
  0 siblings, 1 reply; 3+ messages in thread
From: Hongchen Zhang @ 2022-06-27  7:40 UTC (permalink / raw)
  To: Cyril Hrubis, Jan Stancek; +Cc: Lingling Li, ltp, Hongchen Zhang

the console loglevel is force to be 7(LOGLEVEL_DEFAULT) after test,
which is not the desired behavior.So we reset the console loglevel
to its original value after the test body.The method what we take
is just same as commit:
a2ff1c2d141d ("kmsg01: set/restore console log level").

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

diff --git a/testcases/kernel/syscalls/syslog/syslog11.c b/testcases/kernel/syscalls/syslog/syslog11.c
index b9540ef..78a7cc4 100644
--- a/testcases/kernel/syscalls/syslog/syslog11.c
+++ b/testcases/kernel/syscalls/syslog/syslog11.c
@@ -84,6 +84,11 @@ struct test_case_t {		/* test case structure */
 	char *desc;		/* Test description */
 };
 
+#define PRINTK "/proc/sys/kernel/printk"
+#define CONSOLE_LOGLEVEL_QUIET   4
+
+static int console_loglevel = -1;
+
 char *TCID = "syslog11";
 static int testno;
 static char buf;
@@ -195,6 +200,11 @@ void setup(void)
 		tst_brkm(TBROK, NULL, "nobody user id doesn't exist");
 	}
 
+	if (access(PRINTK, F_OK) == 0) {
+		SAFE_FILE_SCANF(NULL, PRINTK, "%d", &console_loglevel);
+		SAFE_FILE_PRINTF(NULL, PRINTK, "%d", CONSOLE_LOGLEVEL_QUIET);
+	}
+
 	/* Pause if that option was specified
 	 * TEST_PAUSE contains the code to fork the test with the -c option.
 	 */
@@ -208,5 +218,6 @@ void setup(void)
  */
 void cleanup(void)
 {
-
+	if (console_loglevel != -1)
+		SAFE_FILE_PRINTF(NULL, PRINTK, "%d", console_loglevel);
 }
-- 
1.8.3.1


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

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

* Re: [LTP] [PATCH] syslog11: fix console loglevel changed after test
  2022-06-27  7:40 [LTP] [PATCH] syslog11: fix console loglevel changed after test Hongchen Zhang
@ 2022-07-18  9:04 ` Cyril Hrubis
  2022-07-18 13:11   ` Hongchen Zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Cyril Hrubis @ 2022-07-18  9:04 UTC (permalink / raw)
  To: Hongchen Zhang; +Cc: ltp, Lingling Li

Hi!
> the console loglevel is force to be 7(LOGLEVEL_DEFAULT) after test,
> which is not the desired behavior.So we reset the console loglevel
> to its original value after the test body.The method what we take
> is just same as commit:
> a2ff1c2d141d ("kmsg01: set/restore console log level").

First of all the test is mess, it would be nice to clean it up first and
convert it to the new library.

> Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
> Signed-off-by: Lingling Li <lilingling@loongson.cn>
> ---
>  testcases/kernel/syscalls/syslog/syslog11.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/testcases/kernel/syscalls/syslog/syslog11.c b/testcases/kernel/syscalls/syslog/syslog11.c
> index b9540ef..78a7cc4 100644
> --- a/testcases/kernel/syscalls/syslog/syslog11.c
> +++ b/testcases/kernel/syscalls/syslog/syslog11.c
> @@ -84,6 +84,11 @@ struct test_case_t {		/* test case structure */
>  	char *desc;		/* Test description */
>  };
>  
> +#define PRINTK "/proc/sys/kernel/printk"
> +#define CONSOLE_LOGLEVEL_QUIET   4
> +
> +static int console_loglevel = -1;
> +
>  char *TCID = "syslog11";
>  static int testno;
>  static char buf;
> @@ -195,6 +200,11 @@ void setup(void)
>  		tst_brkm(TBROK, NULL, "nobody user id doesn't exist");
>  	}
>  
> +	if (access(PRINTK, F_OK) == 0) {
> +		SAFE_FILE_SCANF(NULL, PRINTK, "%d", &console_loglevel);
> +		SAFE_FILE_PRINTF(NULL, PRINTK, "%d", CONSOLE_LOGLEVEL_QUIET);

Do we need to set the loglevel at the start of the test here?

> +	}
> +
>  	/* Pause if that option was specified
>  	 * TEST_PAUSE contains the code to fork the test with the -c option.
>  	 */
> @@ -208,5 +218,6 @@ void setup(void)
>   */
>  void cleanup(void)
>  {
> -
> +	if (console_loglevel != -1)
> +		SAFE_FILE_PRINTF(NULL, PRINTK, "%d", console_loglevel);
>  }
> -- 
> 1.8.3.1
> 

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH] syslog11: fix console loglevel changed after test
  2022-07-18  9:04 ` Cyril Hrubis
@ 2022-07-18 13:11   ` Hongchen Zhang
  0 siblings, 0 replies; 3+ messages in thread
From: Hongchen Zhang @ 2022-07-18 13:11 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp, Lingling Li

On 2022/7/18 pm 5:04, Cyril Hrubis wrote:
> Hi!
>> the console loglevel is force to be 7(LOGLEVEL_DEFAULT) after test,
>> which is not the desired behavior.So we reset the console loglevel
>> to its original value after the test body.The method what we take
>> is just same as commit:
>> a2ff1c2d141d ("kmsg01: set/restore console log level").
> 
> First of all the test is mess, it would be nice to clean it up first and
> convert it to the new library.
> 
OK, I will change this test to new API and make a v2 patch.
>> Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
>> Signed-off-by: Lingling Li <lilingling@loongson.cn>
>> ---
>>   testcases/kernel/syscalls/syslog/syslog11.c | 13 ++++++++++++-
>>   1 file changed, 12 insertions(+), 1 deletion(-)
>>
>> diff --git a/testcases/kernel/syscalls/syslog/syslog11.c b/testcases/kernel/syscalls/syslog/syslog11.c
>> index b9540ef..78a7cc4 100644
>> --- a/testcases/kernel/syscalls/syslog/syslog11.c
>> +++ b/testcases/kernel/syscalls/syslog/syslog11.c
>> @@ -84,6 +84,11 @@ struct test_case_t {		/* test case structure */
>>   	char *desc;		/* Test description */
>>   };
>>   
>> +#define PRINTK "/proc/sys/kernel/printk"
>> +#define CONSOLE_LOGLEVEL_QUIET   4
>> +
>> +static int console_loglevel = -1;
>> +
>>   char *TCID = "syslog11";
>>   static int testno;
>>   static char buf;
>> @@ -195,6 +200,11 @@ void setup(void)
>>   		tst_brkm(TBROK, NULL, "nobody user id doesn't exist");
>>   	}
>>   
>> +	if (access(PRINTK, F_OK) == 0) {
>> +		SAFE_FILE_SCANF(NULL, PRINTK, "%d", &console_loglevel);
>> +		SAFE_FILE_PRINTF(NULL, PRINTK, "%d", CONSOLE_LOGLEVEL_QUIET);
> 
> Do we need to set the loglevel at the start of the test here?
> 
OK, I will change to use .save_restore to do this
>> +	}
>> +
>>   	/* Pause if that option was specified
>>   	 * TEST_PAUSE contains the code to fork the test with the -c option.
>>   	 */
>> @@ -208,5 +218,6 @@ void setup(void)
>>    */
>>   void cleanup(void)
>>   {
>> -
>> +	if (console_loglevel != -1)
>> +		SAFE_FILE_PRINTF(NULL, PRINTK, "%d", console_loglevel);
>>   }
>> -- 
>> 1.8.3.1
>>
> 
Thanks.

Hongchen Zhang


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

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-27  7:40 [LTP] [PATCH] syslog11: fix console loglevel changed after test Hongchen Zhang
2022-07-18  9:04 ` Cyril Hrubis
2022-07-18 13:11   ` Hongchen Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox