Cleanup sched/process.c
v2 cover Cleanup sched/process.c
Hi,
changes v1->v2:
* split 1 commit into 2, use freopen() as suggested by Li
* 4 more commits for further cleanup
Petr Vorel (7):
sched/process.c: Replace errfp with stderr sched/process.c: Open debugfp with freopen() ci/alpine: Enable process.c
sched/process.c: Log into cwd, add *.log suffix sched/.gitignore: Ignore logs sched/process.c: Remove non-Linux code sched/process.c: Remove useless TRUE FALSE definitions
ci/alpine.sh | 1 - .../kernel/sched/process_stress/.gitignore | 1 + .../kernel/sched/process_stress/Makefile | 2 - .../kernel/sched/process_stress/process.c | 118 ++++-------------- 4 files changed, 23 insertions(+), 99 deletions(-)
Signature · 1 line
2.33.0
PATCH v2 1/7 sched/process.c: Replace errfp with stderr
From: Petr Vorel <[email protected]>
As comment suggest it's indeed not needed :).
--- .../kernel/sched/process_stress/process.c | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-)
testcases/kernel/sched/process_stress/process.c +10 -12
@@ -142,10 +142,8 @@ timer_t timer; /* timer structure */Pinfo *shmaddr;/* Start address of shared memory */ #ifndef _LINUX -FILE *errfp = stderr;/* error file pointer, probably not necessary */ FILE *debugfp = stderr;/* debug file pointer, used if AUSDEBUG set */ #else -#define errfp stderr#define debugfp stderr#endif
@@ -201,12 +199,12 @@ void print_shm(void)return ;for (pinfo = shmaddr, i =0 ; i < nodesum; i++, pinfo++) { -fprintf (errfp, +fprintf (stderr,"slot: %-4d pid: %-6d ppid: %-6d msg: %-2d err: %-2d lst:" , i, pinfo->pid, pinfo->ppid, pinfo->msg, pinfo->err);for (j =0 , listp = pinfo->list; j <BVAL ; j++, listp++) -fprintf (errfp," %d" , *listp); -fprintf (errfp,"\n" ); +fprintf (stderr," %d" , *listp); +fprintf (stderr,"\n" ); } }
@@ -276,13 +274,13 @@ void rm_msgqueue(void)/* remove message queue id. */ if (msgctl (msgid,IPC_RMID ,NULL ) && errno !=EINVAL ) { -fprintf (errfp,"msgctl failed msgid: errno %d\n" , errno); +fprintf (stderr,"msgctl failed msgid: errno %d\n" , errno);perror ("msgctl failed" ); }/* remove message queue id. */ if (msgctl (msgerr,IPC_RMID ,NULL ) && errno !=EINVAL ) { -fprintf (errfp,"msgctl failed msgerr: errno %d\n" , errno); +fprintf (stderr,"msgctl failed msgerr: errno %d\n" , errno);perror ("msgctl failed" ); } }
@@ -297,7 +295,7 @@ void rm_shmseg(void)/* remove shared memory id (and shared memory segment). */ if (shmctl (shmid,IPC_RMID ,NULL ) && errno !=EINVAL ) { -fprintf (errfp,"shmctl failed: errno %d\n" , errno); +fprintf (stderr,"shmctl failed: errno %d\n" , errno);perror ("shmctl failed" ); } }
@@ -313,13 +311,13 @@ void rm_semseg(void)/* remove sem_lock semaphore id */ semarg.val =0 ;/* to fix problem with 4th arg of semctl in 64 bits MARIOG */ if (semctl (sem_lock,0 ,IPC_RMID , semarg.val) && errno !=EINVAL ) { -fprintf (errfp,"semctl failed: errno %d\n" , errno); +fprintf (stderr,"semctl failed: errno %d\n" , errno);perror ("semctl failed" ); }/* remove sem_count semaphore id. */ semarg.val =0 ;/* to fix problem with 4th arg of semctl in 64 bits MARIOG */ if (semctl (sem_count,0 ,IPC_RMID , semarg.val) && errno !=EINVAL ) { -fprintf (errfp,"semctl failed: errno %d\n" , errno); +fprintf (stderr,"semctl failed: errno %d\n" , errno);perror ("semctl failed" ); } }
@@ -1094,7 +1092,7 @@ void messenger(void)case SIGALRM :/* a process is hung, we will terminate */ killpg (procgrp, sig); -fprintf (errfp, +fprintf (stderr,"ALERT! ALERT! WE HAVE TIMED OUT\n" );fprintf (stderr," SEVERE : SIGALRM: A process timed out, we failed\n" );
@@ -1109,7 +1107,7 @@ void messenger(void)default :/* somebody sent a signal, we will terminate */ killpg (procgrp, sig); -fprintf (errfp, +fprintf (stderr,"We received signal %d\n" , sig); fprintf(stderr, " SEVERE : signal %d received, A proc was killed\n",
Signature · 1 line
2.33.0
PATCH v2 2/7 sched/process.c: Open debugfp with freopen()
In reply to Petr VorelFrom: Petr Vorel <[email protected]>
i.e. use the recommended way.
This fixes compilation on MUSL which does not like assignment to stderr:
process.c:551:14: error: assignment of read-only variable 'stderr'
551 | debugfp = fopen(foo, "a+");
| ^
Also drop debugfp definition. It'd be more obvious to use FILE pointer for logging, but some debug functions are intended to use to log into both stderr and into the log files (or at least logging is before stderr is redirected into the log files), thus use stderr as file descriptor.
Although not sure why part of the code is logged into stdout and other part into file, let's keep it.
--- testcases/kernel/sched/process_stress/process.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
testcases/kernel/sched/process_stress/process.c +7 -8
@@ -141,12 +141,6 @@ timer_t timer; /* timer structure */Pinfo *shmaddr;/* Start address of shared memory */ -#ifndef _LINUX -FILE *debugfp = stderr;/* debug file pointer, used if AUSDEBUG set */ -#else -#define debugfp stderr -#endif -struct envstruct *edat = envdata;/* pointer to environment data */ /* external function declarations */
@@ -260,7 +254,7 @@ void debugout(char *fmt, ...)if (AUSDEBUG ) {va_start (args, fmt); -vfprintf (debugfp, fmt, args); +vfprintf (stderr, fmt, args);va_end (args); } }
@@ -546,7 +540,12 @@ int spawn(int val)if (!pid) {/* CHILD */ if (AUSDEBUG ) {sprintf (foo,"%sslot%d" ,SLOTDIR , tval); - debugfp =fopen (foo,"a+" ); + +if ((freopen (foo,"w" , stderr)) ==NULL ) { +fprintf (stderr,"freopen(%s, w, stderr) failed: %s (%d)\n" , + foo,strerror (errno), errno); +exit (1 ); + } } pinfo =put_proc_info (tval);
Signature · 1 line
2.33.0
PATCH v2 3/7 ci/alpine: Enable process.c
In reply to Petr VorelFrom: Petr Vorel <[email protected]>
Fixed in 2 previous commits.
--- ci/alpine.sh | 1 - 1 file changed, 1 deletion(-)
ci/alpine.sh +0 -1
@@ -33,7 +33,6 @@ cat /etc/os-release echo "WARNING: remove unsupported tests (until they're fixed)" cd $(dirname $0)/.. rm -rfv \ - testcases/kernel/sched/process_stress/process.c \ testcases/kernel/syscalls/confstr/confstr01.c \ testcases/kernel/syscalls/fmtmsg/fmtmsg01.c \ testcases/kernel/syscalls/getcontext/getcontext01.c \
Signature · 1 line
2.33.0
PATCH v2 4/7 sched/process.c: Log into cwd, add *.log suffix
In reply to Petr Vorelprocess.c hanged if run with debugging (-D) and log directory (slot/) wasn't created before.
As nothing depends on this path, log into cwd, for clarity add .log suffix.
--- testcases/kernel/sched/process_stress/process.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
testcases/kernel/sched/process_stress/process.c +1 -2
@@ -52,7 +52,6 @@#define TNDX 3#define MAXBVAL 70#define MAXDVAL 11 -#define SLOTDIR "./slot/"#ifdef _LINUX/* LINUX #defnes */
@@ -539,7 +538,7 @@ int spawn(int val) pid =fork ();if (!pid) {/* CHILD */ if (AUSDEBUG ) { -sprintf (foo,"%sslot%d" ,SLOTDIR , tval); +sprintf (foo,"slot%d.log" , tval);if ((freopen (foo,"w" , stderr)) ==NULL ) { fprintf(stderr, "freopen(%s, w, stderr) failed: %s (%d)\n",
Signature · 1 line
2.33.0
PATCH v2 5/7 sched/.gitignore: Ignore logs
In reply to Petr Vorel--- testcases/kernel/sched/process_stress/.gitignore | 1 + 1 file changed, 1 insertion(+)
testcases/kernel/sched/process_stress/.gitignore +1 -0
@@ -1 +1,2 @@ /process +/*.log
Signature · 1 line
2.33.0
PATCH v2 6/7 sched/process.c: Remove non-Linux code
In reply to Petr Vorelas we don't care about other platforms.
Also remove -D_LINUX definition from Makefile.
--- .../kernel/sched/process_stress/Makefile | 2 - .../kernel/sched/process_stress/process.c | 67 +------------------ 2 files changed, 2 insertions(+), 67 deletions(-)
testcases/kernel/sched/process_stress/Makefile +0 -2
@@ -24,6 +24,4 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/env_pre.mk -CPPFLAGS += -D_LINUX - include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/sched/process_stress/process.c +2 -65
146 lines not on this page · raw message
Signature · 1 line
2.33.0
PATCH v2 7/7 sched/process.c: Remove useless TRUE FALSE definitions
In reply to Petr VorelFALSE is not used at all and replace TRUE with 1 (there is no point trying to use true from <stdbool.h> just for while).
--- testcases/kernel/sched/process_stress/process.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
testcases/kernel/sched/process_stress/process.c +2 -9
@@ -46,13 +46,6 @@#define MAXBVAL 70#define MAXDVAL 11 -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -#ifdef DEBUG #define prtln () printf("At line number: %d\n", __LINE__); \ fflush(NULL)
@@ -200,7 +193,7 @@ int send_message(int id, mtyp_t type, char *text)strcpy (sndbuf.mtext, text); sndbuf.mtyp = type; -while (TRUE) { +while (1 ) { rc =msgsnd (id, &sndbuf,sizeof (struct messagebuf ),IPC_NOWAIT );if (rc ==-1 && errno ==EAGAIN ) { debugout("msgqueue %d of mtyp %d not ready to send\n",
@@ -992,7 +985,7 @@ void messenger(void)* Infinite loop used to receive error messages from children and * to terminate process tree. */ -while (TRUE) { +while (1 ) { rc =msgrcv (msgerr, &rcvbuf,sizeof (struct messagebuf ),0 ,0 );if (rc ==-1 ) {switch (errno) {
Signature · 1 line
2.33.0
v2 cover Cleanup sched/process.c
In reply to Petr VorelHi Petr,
The patchset clean-up looks good.
But I just wondering, is there a run test file to perform this test case? I greped the runtest/* but find no file currently includes this:(.
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20210913/2b40c896/attachment.htm>
v2 cover Cleanup sched/process.c
Hi Li,
Quoted 4 lines
Hi Petr,
The patchset clean-up looks good.
Reviewed-by Li Wang <[email protected]>
Thanks!
Quoted 2 lines
But I just wondering, is there a run test file to perform this test case? I greped the runtest/* but find no file currently includes this:(.
IMHO it's in sched:
$ git grep -w process runtest/ runtest/sched:hackbench01 hackbench 50 process 1000
Kind regards,
Petr
v2 cover Cleanup sched/process.c
Quoted 7 lines
Quoted 2 lines
But I just wondering, is there a run test file to perform this test case? I greped the runtest/* but find no file currently includes this:(.
IMHO it's in sched:
$ git grep -w process runtest/ runtest/sched:hackbench01 hackbench 50 process 1000
Hmm, here "process" is only a parameter to hackbench01, it has no direct relevance to the process_stress/process.c.
After checking the history a while, I think that process_stress/process.c is an independent test and obsoleted for a quite long time, maybe we can add online back to runtest/sched file or just let is there until someone converting to the new API.
commit 576f1ee560b2370818b49366bad581952af3dd70
Author: robbiew <robbiew> Date: Fri Feb 1 16:39:39 2002 +0000
Removed a test that was not correctly running.
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20210913/29480597/attachment.htm>
v2 cover Cleanup sched/process.c
Quoted 16 lines
Quoted 6 lines
Quoted 2 lines
But I just wondering, is there a run test file to perform this test case? I greped the runtest/* but find no file currently includes this:(.
IMHO it's in sched:
$ git grep -w process runtest/ runtest/sched:hackbench01 hackbench 50 process 1000Hmm, here "process" is only a parameter to hackbench01, it has no direct relevance to the
process_stress/process.c.After checking the history a while, I think that
process_stress/process.cis an independent test and obsoleted for a quite long time, maybe we can add online back to runtest/sched file or just let is there until someone converting to the new API.
Quoted 5 lines
commit
576f1ee560b2370818b49366bad581952af3dd70Author: robbiew <robbiew> Date: Fri Feb 1 16:39:39 2002 +0000Removed a test that was not correctly running.
Ah, good catch! I didn't check it's not a binary which would be required. I'll recheck it once again and send a patch to remove it then.
Kind regards,
Petr
v2 cover Cleanup sched/process.c
Quoted 3 lines
Ah, good catch! I didn't check it's not a binary which would be required. I'll recheck it once again and send a patch to remove it then.
Agree, it has obsoleted 20 years, I guess it probably not much sense to keep it.
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20210913/d6384927/attachment.htm>