From: Cyril Hrubis <chrubis@suse.cz>
To: Krzysztof Dynowski <k.dynowski@samsung.com>
Cc: "ltp@lists.linux.it" <ltp@lists.linux.it>
Subject: Re: [LTP] Make global vars/funcs static, where possible #879
Date: Wed, 3 Nov 2021 14:03:11 +0100 [thread overview]
Message-ID: <YYKIj/LE2jv4yL5x@yuki> (raw)
In-Reply-To: <20211103113400eucms1p132b09d599216a0b3c42f24fd670d0c40@eucms1p1>
Hi!
First of all the mine type for the attachment is still wrong, it should
be text/plain.
> -char *TCID = "abs01";
> -int local_flag = PASSED;
> -int block_number;
> -FILE *temp;
> -int TST_TOTAL = 1;
> +static const char *TCID = "abs01";
Actually this is wrong, the test library makes use fo the TCID so it's
not supposed to be static.
> +static int local_flag = PASSED;
> +static int block_number;
> +static FILE *temp;
> +static int TST_TOTAL = 1;
Same for the TST_TOTAL. See lib/tst_res.c line 123.
> static void setup(void);
> static int blenter(void);
> diff --git a/testcases/misc/math/atof/atof01.c
> b/testcases/misc/math/atof/atof01.c
> index 98d085abb..67d904810 100644
> --- a/testcases/misc/math/atof/atof01.c
> +++ b/testcases/misc/math/atof/atof01.c
> @@ -49,16 +49,16 @@
> /***** *****/
> #define ERR 0.0000001
>
> -double pi;
> +static double pi;
>
> /*char progname[]= "atof1()"; */
> /** LTP Port **/
> -char *TCID = "atof01"; /* Test program identifier */
> +static const char *TCID = "atof01"; /* Test program
> identifier */
>
> -int local_flag = PASSED;
> -int block_number;
> -FILE *temp;
> -int TST_TOTAL = 1;
> +static int local_flag = PASSED;
> +static int block_number;
> +static FILE *temp;
> +static int TST_TOTAL = 1;
>
> static void setup(void);
> static void blenter(void);
> diff --git a/testcases/misc/math/float/main.c
> b/testcases/misc/math/float/main.c
> index 7285141a4..fecc154e5 100644
> --- a/testcases/misc/math/float/main.c
> +++ b/testcases/misc/math/float/main.c
> @@ -29,13 +29,13 @@
>
> #define SAFE_FREE(p) { if (p) { free(p); (p)=NULL; } }
> /* LTP status reporting */
> -char *TCID; /* Test program identifier. */
> -int TST_TOTAL = 1; /* Total number of test cases. */
> +static char *TCID; /* Test program identifier.
> */
> +static int TST_TOTAL = 1; /* Total number of test cases.
> */
>
> /* To avoid extensive modifications to the code, use this bodge */
> #define exit(x) myexit(x)
>
> -void myexit(int x)
> +static void myexit(int x)
> {
> if (x)
> tst_resm(TFAIL, "Test failed");
> @@ -44,45 +44,45 @@ void myexit(int x)
> tst_exit();
> }
>
> -TH_DATA *pcom;
> -TH_DATA **tabcom;
> -TH_DATA **tabcour;
> +static TH_DATA *pcom;
> +static TH_DATA **tabcom;
> +static TH_DATA **tabcour;
> #ifndef PATH_MAX
> #define PATH_MAX 1024
> #endif
> -char datadir[PATH_MAX]; /* DATA directory */
> +static char datadir[PATH_MAX]; /* DATA directory */
>
> #ifndef PTHREAD_THREADS_MAX
> #define PTHREAD_THREADS_MAX 1024
> #endif
> #define DEFAULT_NUM_THREADS 20
> -int num_threads = DEFAULT_NUM_THREADS;
> -int num_loops = 500;
> +static int num_threads = DEFAULT_NUM_THREADS;
> +static int num_loops = 500;
>
> -int sig_cancel = 0; /* flag set by handle_signals to tell
> initial thread
> +static int sig_cancel = 0; /* flag set by handle_signals
> to tell initial thread
> to stop creating new threads (signal
> caught) */
>
> -int indice = 0; /* # of threads created, to be
> canceled by handle_signals
> +static int indice = 0; /* # of threads created, to be
> canceled by handle_signals
> or waited for by initial thread */
>
> -pthread_mutex_t sig_mutex;
> -pthread_t *threads;
> +static pthread_mutex_t sig_mutex;
> +static pthread_t *threads;
>
> -int debug = 0;
> -int true = 1;
> +static int debug = 0;
> +static int is_true = 1;
>
> static void *handle_signals(void *);
>
> static void sys_error(const char *, int);
>
> -const double EPS = 0.1e-300;
> +static const double EPS = 0.1e-300;
>
> -const int nb_func = NB_FUNC;
> +static const int nb_func = NB_FUNC;
>
> -int generate(char *datadir, char *bin_path)
> +static int generate(char *datadir, char *bin_path)
> {
> char *cmdline;
> - char *fmt = "cd %s; %s/%s %s";
> + const char *fmt = "cd %s; %s/%s %s";
>
> cmdline = malloc(2 * strlen(bin_path) + strlen(datadir) +
> strlen(GENERATOR) + strlen(fmt));
> if (cmdline == NULL)
> @@ -229,7 +229,7 @@ int main(int argc, char *argv[])
>
> indice = 0;
> for (i = 0; i < nb_func; i++) {
> -
> + tst_resm(TINFO, " > running test %d", i+1);
> for (th_num = 0; th_num < num_threads; th_num++) {
>
> /* allocate struct of commucation with the
> thread */
> @@ -237,7 +237,7 @@ int main(int argc, char *argv[])
> if (pcom == NULL)
> tst_brkm(TFAIL | TERRNO, cleanup,
> "calloc failed");
> - *tabcour = (TH_DATA *) pcom;
> + *tabcour = pcom;
> tabcour++;
> /*
> * update structure of communication
> @@ -252,7 +252,7 @@ int main(int argc, char *argv[])
> goto finished;
> }
> retval = pthread_create(&threads[indice],
> &newattr,
> - thread_code, (void
> *)pcom);
> + thread_code, pcom);
> if (retval != 0)
> sys_error("main : create FAILED",
> __LINE__);
> indice++;
> diff --git a/testcases/misc/math/float/tfloat.h
> b/testcases/misc/math/float/tfloat.h
> index 50cb73d10..438bbe728 100644
> --- a/testcases/misc/math/float/tfloat.h
> +++ b/testcases/misc/math/float/tfloat.h
> @@ -53,11 +53,7 @@
> #define FUNC_LDEXP 7
> #define FUNC_GAM 8
>
> -extern void * thread_code(void *);
> -
> -/* global variables, constants or initialized by main() */
> -extern const double EPS; /* 0.1e-300 */
> -extern int true, num_threads;
And these three constansts seem to be shared between thread_code.c and
main.c. I guess that proper fix would be to propagate them to the
TH_DATA structure.
> +static void * thread_code(void *);
>
> /*
> * TH_DATA structures
> @@ -102,6 +98,4 @@ typedef struct {
> TH_FUNC th_func;
> } TH_DATA;
>
> -extern const TH_FUNC th_func[];
This one as well, appears to be shared between different C source files.
> #endif /* ifndef _TFLOAT_H */
> diff --git a/testcases/misc/math/float/thread_code.c
> b/testcases/misc/math/float/thread_code.c
> index ca18cef1e..125a60c15 100644
> --- a/testcases/misc/math/float/thread_code.c
> +++ b/testcases/misc/math/float/thread_code.c
> @@ -274,7 +274,7 @@ static void compute_ldexp(TH_DATA * th_data, double
> *din, double *dex,
> * pointer to a TH_DATA structure.
> *
> */
> -void *thread_code(void *arg)
> +static void *thread_code(void *arg)
> {
> TH_DATA *th_data = (TH_DATA *) arg;
> size_t fsize, fsize2, fsize3;
> diff --git a/testcases/misc/math/fptests/fptest01.c
> b/testcases/misc/math/fptests/fptest01.c
> index 2072dced6..76d5b0121 100644
> --- a/testcases/misc/math/fptests/fptest01.c
> +++ b/testcases/misc/math/fptests/fptest01.c
> @@ -61,8 +61,8 @@
> /** LTP Port **/
> #include "test.h"
>
> -char *TCID = "fptest01"; /* Test program identifier. */
> -int TST_TOTAL = 1; /* Total number of test cases. */
> +static const char *TCID = "fptest01"; /* Test program identifier.
> */
> +static int TST_TOTAL = 1; /* Total number of test cases.
> */
> /**************/
>
> struct event {
> @@ -79,19 +79,19 @@ static int addevent(int, int, double);
> static void gaussinit(double, double);
> static double gauss(void);
>
> -struct event eventtab[EVENTMX];
> -struct event rtrevent;
> -int waiting[EVENTMX]; /* array of waiting processors */
> -int nwaiting; /* number of waiting processors */
> -double global_time; /* global clock */
> -double lsttime; /* time used for editing */
> -double dtc, dts, alpha; /* timing parameters */
> -int nproc; /* number of processors */
> -int barcnt; /* number of processors ATBARRIER */
> -int ncycle; /* number of cycles completed */
> -int ncycmax; /* number of cycles to run */
> -int critfree; /* TRUE if critical section not
> occupied */
> -int gcount; /* # calls to gauss */
> +static struct event eventtab[EVENTMX];
> +static struct event rtrevent;
> +static int waiting[EVENTMX]; /* array of waiting processors
> */
> +static int nwaiting; /* number of waiting processors
> */
> +static double global_time; /* global clock */
> +static double lsttime; /* time used for editing */
> +static double dtc, dts, alpha; /* timing parameters */
> +static int nproc; /* number of processors */
> +static int barcnt; /* number of processors
> ATBARRIER */
> +static int ncycle; /* number of cycles completed
> */
> +static int ncycmax; /* number of cycles to run */
> +static int critfree; /* TRUE if critical section not
> occupied */
> +static int gcount; /* # calls to gauss */
>
> static struct event *nextevent(void);
>
> diff --git a/testcases/misc/math/fptests/fptest02.c
> b/testcases/misc/math/fptests/fptest02.c
> index e6b49feb9..5bb849d65 100644
> --- a/testcases/misc/math/fptests/fptest02.c
> +++ b/testcases/misc/math/fptests/fptest02.c
> @@ -61,8 +61,8 @@
> /** LTP Port **/
> #include "test.h"
>
> -char *TCID = "fptest02"; /* Test program identifier. */
> -int TST_TOTAL = 1; /* Total number of test cases. */
> +static const char *TCID = "fptest02"; /* Test program identifier.
> */
> +static int TST_TOTAL = 1; /* Total number of test cases.
> */
> /**************/
>
> struct event {
> @@ -79,18 +79,18 @@ static int addevent(int, int, double);
> static void gaussinit(double, double, int);
> static double gauss(void);
>
> -struct event eventtab[EVENTMX];
> -struct event rtrevent;
> -int waiting[EVENTMX]; /* array of waiting processors */
> -int nwaiting; /* number of waiting processors */
> -double sgtime; /* global clock */
> -double lsttime; /* time used for editing */
> -double dtc, dts, alpha; /* timing parameters */
> -int nproc; /* number of processors */
> -int barcnt; /* number of processors ATBARRIER */
> -int ncycle; /* number of cycles completed */
> -int ncycmax; /* number of cycles to run */
> -int critfree; /* TRUE if critical section not
> occupied */
> +static struct event eventtab[EVENTMX];
> +static struct event rtrevent;
> +static int waiting[EVENTMX]; /* array of waiting processors
> */
> +static int nwaiting; /* number of waiting processors
> */
> +static double sgtime; /* global clock */
> +static double lsttime; /* time used for editing */
> +static double dtc, dts, alpha; /* timing parameters */
> +static int nproc; /* number of processors */
> +static int barcnt; /* number of processors
> ATBARRIER */
> +static int ncycle; /* number of cycles completed
> */
> +static int ncycmax; /* number of cycles to run */
> +static int critfree; /* TRUE if critical section not
> occupied */
>
> static struct event *nextevent(void );
>
> diff --git a/testcases/misc/math/nextafter/nextafter01.c
> b/testcases/misc/math/nextafter/nextafter01.c
> index f4b212d4d..6faa4a7a5 100644
> --- a/testcases/misc/math/nextafter/nextafter01.c
> +++ b/testcases/misc/math/nextafter/nextafter01.c
> @@ -43,16 +43,16 @@
> #define FAILED 0
> #define PASSED 1
>
> -char *TCID = "nextafter01";
> +static const char *TCID = "nextafter01";
>
> -int local_flag = PASSED;
> -int block_number;
> -FILE *temp;
> -int TST_TOTAL = 1;
> +static int local_flag = PASSED;
> +static int block_number;
> +static FILE *temp;
> +static int TST_TOTAL = 1;
>
> -void setup();
> -void blenter();
> -void blexit();
> +static void setup();
> +static void blenter();
> +static void blexit();
>
> /*--------------------------------------------------------------*/
> int main()
> --
> 2.25.1
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2021-11-03 13:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20211103090509eucms1p3879e480f890ad8e00a40febd3cf98279@eucms1p1>
2021-11-03 11:34 ` [LTP] Make global vars/funcs static, where possible #879 Krzysztof Dynowski
2021-11-03 13:03 ` Cyril Hrubis [this message]
[not found] <CGME20211103090509eucms1p3879e480f890ad8e00a40febd3cf98279@eucms1p3>
2021-11-03 9:05 ` Krzysztof Dynowski
2021-11-03 9:19 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YYKIj/LE2jv4yL5x@yuki \
--to=chrubis@suse.cz \
--cc=k.dynowski@samsung.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox