diff --git a/cobc/codegen.c b/cobc/codegen.c index 7e6e26867..2dd0c7520 100644 --- a/cobc/codegen.c +++ b/cobc/codegen.c @@ -4374,24 +4374,24 @@ output_funcall (cb_tree x) output ("cob_prof_enter_procedure (prof_info, %d);", proc_idx); output_newline (); output_prefix (); - output ("cob_prof_fallthrough_label = 0"); + output ("fallthrough_label = 0"); break; case COB_PROF_USE_PARAGRAPH_ENTRY: { int paragraph_idx = CB_INTEGER(p->argv[1])->val; int entry_idx = CB_INTEGER(p->argv[2])->val; - output ("if (!cob_prof_fallthrough_label)"); + output ("if (!fallthrough_label)"); output_block_open (); output_line ("cob_prof_use_paragraph_entry (prof_info, %d, %d);", paragraph_idx, entry_idx); output_block_close (); output_line ("else"); output_block_open (); - output_line ("cob_prof_fallthrough_label = 0;"); + output_line ("fallthrough_label = 0;"); output_block_close (); break; } case COB_PROF_STAYIN_PARAGRAPH: - output ("cob_prof_fallthrough_label = 1"); + output ("fallthrough_label = 1"); break; } return; @@ -13782,7 +13782,7 @@ output_cob_prof_data ( struct cb_program * program ) } output_local ("};\n"); - output_local ("static int cob_prof_fallthrough_label = 0;\n"); + output_local ("static int fallthrough_label = 0;\n"); output_local ("static struct cob_prof_module *prof_info;\n"); output_local ("\n/* End of cob_prof data */\n"); diff --git a/libcob/coblocal.h b/libcob/coblocal.h index 51fe7565b..46dfcc576 100644 --- a/libcob/coblocal.h +++ b/libcob/coblocal.h @@ -583,6 +583,9 @@ COB_HIDDEN int cob_cmps (const unsigned char *, const unsigned char *, COB_HIDDEN FILE * cob_open_logfile (const char *filename); +/* Whether we are in testsuite mode */ +COB_HIDDEN int is_test; + #undef COB_HIDDEN #endif /* COB_LOCAL_H */ diff --git a/libcob/common.c b/libcob/common.c index aa2c2968e..993829896 100644 --- a/libcob/common.c +++ b/libcob/common.c @@ -333,6 +333,8 @@ static const unsigned char *sort_collate = NULL; static const char *cob_source_file = NULL; static unsigned int cob_source_line = 0; +int is_test = 0; + #ifdef HAVE_DESIGNATED_INITS const char *cob_statement_name[STMT_MAX_ENTRY] = { [STMT_UNKNOWN] = "UNKNOWN" @@ -7864,7 +7866,11 @@ cob_expand_env_string (const char *strval) const char *s = NULL; switch ( strval[k+1] ){ case '$': /* Replace $$ with process-id */ - j += sprintf (&env[j], "%d", cob_sys_getpid()); + if (is_test) { + j += sprintf (&env[j], "%d", 123456); + } else { + j += sprintf (&env[j], "%d", cob_sys_getpid()); + } k++; break; case 'f': /* $f is the executable filename */ @@ -10289,6 +10295,8 @@ cob_init (const int argc, char **argv) cob_initialized = 1; + is_test = !!getenv ("COB_IS_RUNNING_IN_TESTMODE"); + #ifdef HAVE_SETLOCALE /* Prime the locale from user settings */ s = setlocale (LC_ALL, ""); diff --git a/libcob/profiling.c b/libcob/profiling.c index c428cc277..7f6285301 100644 --- a/libcob/profiling.c +++ b/libcob/profiling.c @@ -63,8 +63,6 @@ static int current_idx = -1; /* Whether profiling is active or not. */ static int is_active = 0; -/* Whether we are in testsuite mode */ -static int is_test = 0; /* Which clock to use for clock_gettime (if available) */ #ifdef HAVE_CLOCK_GETTIME @@ -155,9 +153,6 @@ prof_init_static () if (!init_done && cobsetptr) { prof_setup_clock (); is_active = cobsetptr->cob_prof_enable; - if (is_active) { - is_test = !!getenv ("COB_IS_RUNNING_IN_TESTMODE"); - } init_done = 1; } } @@ -460,7 +455,7 @@ cob_prof_print_line ( case 'i': if (info){ if (is_test){ - fprintf (file, "%d", 42); + fprintf (file, "%d", 123456); } else { fprintf (file, "%d", cob_sys_getpid()); } diff --git a/tests/testsuite.src/run_misc.at b/tests/testsuite.src/run_misc.at index 1e0534d57..5cfd498f9 100644 --- a/tests/testsuite.src/run_misc.at +++ b/tests/testsuite.src/run_misc.at @@ -14675,26 +14675,26 @@ prog.cob:11: warning: GO TO SECTION '2ND' AT_CHECK([COB_PROF_ENABLE=0 COB_PROF_FILE='prof-$b.csv' $COBCRUN_DIRECT ./prog], [0], [], []) -AT_CHECK([COB_PROF_ENABLE=1 COB_PROF_FILE='prof-$b.csv' COB_PROF_FORMAT=%i,%m,%s,%p,%e,%f,%l,%w,%k,%t,%h,%n,%x $COBCRUN_DIRECT ./prog], [0], [], -[File prof-prog.csv generated +AT_CHECK([COB_PROF_ENABLE=1 COB_PROF_FILE='prof-$$-$b.csv' COB_PROF_FORMAT=%i,%m,%s,%p,%e,%f,%l,%w,%k,%t,%h,%n,%x $COBCRUN_DIRECT ./prog], [0], [], +[File prof-123456-prog.csv generated ]) # note: The time here is actually the number of times the procedure has # been run, to avoid any indeterminism in the running time of the # procedure. -AT_CHECK([cat prof-prog.csv], [0], +AT_CHECK([cat prof-123456-prog.csv], [0], [pid,program-id,section,paragraph,entry,file,line,location,kind,time-ns,time,ncalls,%x -42,prog,,,,prog.cob,4,prog.cob:4,PROGRAM,13000000,0.013 s,1,%x -42,prog,1ST,,,prog.cob,5,prog.cob:5,SECTION,12000000,0.012 s,1,%x -42,prog,1ST,PARA-0001,,prog.cob,6,prog.cob:6,PARAGRAPH,11000000,0.011 s,1,%x -42,prog,1ST,PARA-0002,,prog.cob,8,prog.cob:8,PARAGRAPH,0,0.000 s,0,%x -42,prog,1ST,PARA-0003,,prog.cob,10,prog.cob:10,PARAGRAPH,1000000,0.001 s,1,%x -42,prog,1ST,PARA-0004,,prog.cob,12,prog.cob:12,PARAGRAPH,0,0.000 s,0,%x -42,prog,2ND,,,prog.cob,14,prog.cob:14,SECTION,6000000,0.006 s,1,%x -42,prog,2ND,PARA-0005,,prog.cob,15,prog.cob:15,PARAGRAPH,3000000,0.003 s,1,%x -42,prog,2ND,PARA-0006,,prog.cob,17,prog.cob:17,PARAGRAPH,2000000,0.002 s,2,%x -42,prog,2ND,PARA-0007,,prog.cob,19,prog.cob:19,PARAGRAPH,1000000,0.001 s,1,%x +123456,prog,,,,prog.cob,4,prog.cob:4,PROGRAM,13000000,0.013 s,1,%x +123456,prog,1ST,,,prog.cob,5,prog.cob:5,SECTION,12000000,0.012 s,1,%x +123456,prog,1ST,PARA-0001,,prog.cob,6,prog.cob:6,PARAGRAPH,11000000,0.011 s,1,%x +123456,prog,1ST,PARA-0002,,prog.cob,8,prog.cob:8,PARAGRAPH,0,0.000 s,0,%x +123456,prog,1ST,PARA-0003,,prog.cob,10,prog.cob:10,PARAGRAPH,1000000,0.001 s,1,%x +123456,prog,1ST,PARA-0004,,prog.cob,12,prog.cob:12,PARAGRAPH,0,0.000 s,0,%x +123456,prog,2ND,,,prog.cob,14,prog.cob:14,SECTION,6000000,0.006 s,1,%x +123456,prog,2ND,PARA-0005,,prog.cob,15,prog.cob:15,PARAGRAPH,3000000,0.003 s,1,%x +123456,prog,2ND,PARA-0006,,prog.cob,17,prog.cob:17,PARAGRAPH,2000000,0.002 s,2,%x +123456,prog,2ND,PARA-0007,,prog.cob,19,prog.cob:19,PARAGRAPH,1000000,0.001 s,1,%x ]) AT_CLEANUP