root/branches/newmole/scripts/nightly_run_tsuite.pl

Revision 688, 16.0 kB (checked in by peter, 2 years ago)

Merge changes from mainline upto r685 (second installment).

Mop up a few remaining issues.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1#!perl -w
2# this is main script and must end last since it checks all sims
3# the number to skip - will go from next to end
4# slave will do this many, master will skip this many
5#>>chng 06 aug 29, from 67 to 62, master found 8 undone model on a backup night
6$nmod_calc = 55;
7
8# NB this script uses mks version of tar - renamed to mks_tar
9
10# this is the perl script that is automatically run every night to verify cloudy
11# it ends with sending an email message announcing success or failure - this needs
12# to be modified of deleted if you are not me
13
14# the variable $exe must be set below to point to a valid cloudy executable
15# for the OS in use
16
17# bring in the perl module that includes copy
18use File::Copy;
19
20$TRUE = 1;
21$FALSE = 0;
22
23# if true then always recompute even when exe is older than results
24$lgForceCompute = $TRUE;
25# if false then only recompute when newer exe than results
26$lgForceCompute = $FALSE;
27
28# will we send stderr to a file or the screen?
29$lgSTDERR2FILE = $TRUE;
30
31# flag to remember if this is my win nt machine, set true below if nt and machine name correct
32$lgWinNT = $FALSE;
33
34# option to turn on logging print informatoin
35$lgLOGGING = $TRUE;
36
37# sest this true to only run script without exe cloudy or doing backups
38# does not do backups, does not execute cloudy, but does generate *.out names
39$lgDO_NO_WORK = $FALSE;
40
41# find the name of machine processor, write into file machine.txt.
42system "uname -a >machine.txt";
43
44# open file named machine.txt with file handle MA;
45open(MA,"machine.txt");
46
47# copy file to perl special variable $_ (It will be used to check
48# expression below)
49$_ =<MA>;
50
51# For different processor, give different option to complie program
52if (/sparc/)
53{
54#       for sparc
55        $exe = "/homes/home37/feng/cloudy/trunk/sparc/cloudy_sparc.exe";
56}
57elsif (/alpha/)
58{
59#       for alpha
60        $exe = "/homes/home37/feng/cloudy/trunk/alpha/cloudy_alpha.exe";
61}
62elsif (/Linux/)
63{
64#       for Linux machine
65        $exe = "/home/feng/Perl/object/cloudy_linux.exe";
66}
67elsif(/spp/)
68{
69#       for spp machine
70        $in_dir = "/users/gary/cloudy/tsuite";
71        $exe = "/users2/zfeng1/cloudy/object/cloudy_spp.exe";   
72}
73#     check for both nt and name since bash shell does not say windows
74elsif (/Windows_NT/ || /NIMBUS/  || /LENTICULAR/ || /cumulus/)
75{
76#       nt
77        # the disk drive
78        $c = "c";
79        # input and output directories
80        # $in_dir = "$c:/projects/cloudy/tsuite/short/";
81        # $out_dir = "$c:/projects/cloudy/tsuite/short/";
82        $script_dir = "$c:/projects/cloudy/trunk/scripts/";
83        $in_dir = "$c:/projects/cloudy/trunk/tsuite/auto/";
84        $out_dir = "$c:/projects/cloudy/trunk/tsuite/auto/";
85
86        # the exe file name for the fast (release) version - faster but no asserts
87        $exe = "$c:/projects/cloudy/trunk/release/trunk.exe";
88        # the exe file name for the debug version - this has asserts and is safer
89        $exe = "$c:/projects/Cloudy/trunk_net/Debug/trunk_net.exe";
90        $exe = "$c:\\projects\\Cloudy\\trunk\\current_net\\Debug\\current_net.exe";
91        $exe = "$c:/projects/cloudy/trunk/debug/trunk.exe";
92
93#       $source = "$c:/projects/cloudy/trunk/source/";
94#       the "current" project directory
95        $current= "$c:/projects/cloudy/trunk/";
96#       $data = "c:/projects/cloudy/trunk/data/";
97
98        if(/Windows_NT/ || /NIMBUS/ || /LENTICULAR/ || /NUMBUS/ || /cumulus/ )
99        {
100           # remember if this is my win nt machine
101           $lgWinNT = $TRUE;
102        }
103}
104else 
105{
106#       exit if not in the above machine
107        print STDERR "This machine is not on the list so EXIT !!!";
108        exit;
109}
110
111# file containing any errors, also used for timestamp
112$errors = "$out_dir"."errors.txt";
113# this file exists while long checking runs with purify are in pregress
114$blockrun = "$out_dir"."blockfile.txt";
115$log_file = "$out_dir"."autorun.log";
116# file with list of PROBLEM and DEBUG strings
117$problem_file = "$out_dir"."problems.txt";
118
119# option to write STDERR to file instead of screen
120if( $lgSTDERR2FILE )
121{
122        open( STDERR , ">$out_dir"."stderr.log" );
123}
124
125if( $lgLOGGING )
126{
127        open( ioLOG , ">$log_file" );
128        printf( ioLOG "logging file opened\n");
129}
130
131# does $exe exist?
132if( !open(EXEFILE, "$exe") )
133{
134        if( $lgLOGGING )
135        {
136                printf( ioLOG "executable did not exist so exiting without running.\n" );
137        }
138        printf( STDERR "executable did not exist so exiting without running.\n" );
139        exit;
140}
141
142if( $lgLOGGING )
143{
144        printf( ioLOG "opened the executable %s\n" , "$exe" );
145}
146
147# copy exec here so that scripts that follow an use it
148system("copy c:\\projects\\cloudy\\trunk\\debug\\trunk.exe . ");
149
150
151# see if errors.txt exists, if it does, and younger than exe file, just quit
152# $lgForceCompute set above, option to force recomputing model
153if( !$lgForceCompute  )
154{
155        if( -e $errors )
156        {
157                if( $lgLOGGING )
158                {
159                        printf( ioLOG "errors file exits so checking timestamp\n" );
160                }
161                # is age of errors file smaler than exe file?
162                if( (-M $errors) < (-M EXEFILE ) )
163                {
164                        if( $lgLOGGING )
165                        {
166                                printf( ioLOG "errors file younger than exe so exiting\n" );
167                        }
168                        # no need to run tests, just quit
169                        exit;
170                }
171                # this file created when purify test is running
172                if( -e $blockrun )
173                {
174                   if( $lgLOGGING )
175                   {
176                           printf( ioLOG "blocking file exists so exiting\n" );
177                   }
178                   # no need to run tests, just quit
179                   exit;
180                }
181        }
182}
183
184# backup source, data, exe files
185backup_old_files();
186
187# run the models
188run_cloudy();
189
190# look for errors, this creates errors.txt, which we will copy to gradj
191check_output();
192
193# send mail announcing results,
194# if no problem occur then also execute last_good.pl, copying files to last_good directory
195send_mail();
196
197# check whether exectime has changed
198# system("perl extime.pl");
199# finally, check whether iter/zone has changed
200# system("perl \"$script_dir\".\"ir_extime.pl\" ");
201system("perl \"$script_dir\"ir_extime.pl ");
202
203if( $lgLOGGING )
204{
205        printf( ioLOG "nightly_run_tsuite.pl terminates\n" );
206}
207
208exit;
209
210#===========================================================
211#
212#          sub backup_old_files()
213#
214#===========================================================
215sub backup_old_files
216{
217        if( $lgLOGGING )
218        {
219                printf( ioLOG "backup_old_files entered\n" );
220        }
221        # return if not on cumulus
222        if( !$lgWinNT )
223        {
224                if( $lgLOGGING )
225                {
226                        printf(ioLOG  "backup_old_files returns since not on cumulus\n" );
227                }
228                return;
229        }
230        # option to not actually do anything (for debugging)
231        if( $lgDO_NO_WORK )
232        {
233                return;
234        }
235        # move to the output directory
236        if( !chdir( $out_dir ) )
237        {
238                printf(" invalid directory for output of test suite\n");
239                printf(" was ==%s==\n",$out_dir );
240                if( $lgLOGGING )
241                {
242                        printf(ioLOG " invalid directory for output of test suite\n");
243                        printf(ioLOG " was ==%s==\n",$out_dir );
244                }
245                exit(1);
246        }
247
248        # make successive backups of all cloudy executables
249        if( -e "cloudy_bk6.exe" )
250        {
251                rename( "cloudy_bk6.exe" , "cloudy_bk7.exe" );
252        }
253        if( -e "cloudy_bk5.exe" )
254        {
255                rename( "cloudy_bk5.exe" , "cloudy_bk6.exe" );
256        }
257        if( -e "cloudy_bk4.exe" )
258        {
259                rename( "cloudy_bk4.exe" , "cloudy_bk5.exe" );
260        }
261        if( -e "cloudy_bk3.exe" )
262        {
263                rename( "cloudy_bk3.exe" , "cloudy_bk4.exe" );
264        }
265        if( -e "cloudy_bk2.exe" )
266        {
267                rename( "cloudy_bk2.exe" , "cloudy_bk3.exe" );
268        }
269        if( -e "cloudy_bk1.exe" )
270        {
271                rename( "cloudy_bk1.exe" , "cloudy_bk2.exe" );
272        }
273        if( -e "cloudy_bak.exe" )
274        {
275                rename( "cloudy_bak.exe" , "cloudy_bk1.exe" );
276        }
277        if( -e "cloudy.exe" )
278        {
279                rename( "cloudy.exe" , "cloudy_bak.exe" );
280        }
281        # finally copy exe file here
282        copy( $exe , "cloudy.exe" );
283
284        # now make backups of all output files
285        while(defined($output= glob("*.out")) )
286        {
287                # get basename
288                $output =~ s/.out//gi;
289                if( -e "$output".".bk6" )
290                {
291                        rename( "$output".".bk6" , "$output".".bk7" );
292                }
293                if( -e "$output".".bk5" )
294                {
295                        rename( "$output".".bk5" , "$output".".bk6" );
296                }
297                if( -e "$output".".bk4" )
298                {
299                        rename( "$output".".bk4" , "$output".".bk5" );
300                }
301                if( -e "$output".".bk3" )
302                {
303                        rename( "$output".".bk3" , "$output".".bk4" );
304                }
305                if( -e "$output".".bk2" )
306                {
307                        rename( "$output".".bk2" , "$output".".bk3" );
308                }
309                if( -e "$output".".bk1" )
310                {
311                        rename( "$output".".bk1" , "$output".".bk2" );
312                }
313                if( -e "$output".".bak" )
314                {
315                        rename( "$output".".bak" , "$output".".bk1" );
316                }
317                if( -e "$output".".out" )
318                {
319                        rename( "$output".".out" , "$output".".bak" );
320                }
321        }
322
323        # demote all old copies of source files
324        if( -e "source_bk6.tar" )
325        {
326                rename( "source_bk6.tar" , "source_bk7.tar" );
327        }
328        if( -e "source_bk5.tar" )
329        {
330                rename( "source_bk5.tar" , "source_bk6.tar" );
331        }
332        if( -e "source_bk4.tar" )
333        {
334                rename( "source_bk4.tar" , "source_bk5.tar" );
335        }
336        if( -e "source_bk3.tar" )
337        {
338                rename( "source_bk3.tar" , "source_bk4.tar" );
339        }
340        if( -e "source_bk2.tar" )
341        {
342                rename( "source_bk2.tar" , "source_bk3.tar" );
343        }
344        if( -e "source_bk1.tar" )
345        {
346                rename( "source_bk1.tar" , "source_bk2.tar" );
347        }
348        if( -e "source_bak.tar" )
349        {
350                rename( "source_bak.tar" , "source_bk1.tar" );
351        }
352        if( -e "source.tar" )
353        {
354                rename( "source.tar" , "source_bak.tar" );
355        }
356
357        # demote all old copies of tsuite files
358        if( -e "tsuite_bk6.tar" )
359        {
360                rename( "tsuite_bk6.tar" , "tsuite_bk7.tar" );
361        }
362        if( -e "tsuite_bk5.tar" )
363        {
364                rename( "tsuite_bk5.tar" , "tsuite_bk6.tar" );
365        }
366        if( -e "tsuite_bk4.tar" )
367        {
368                rename( "tsuite_bk4.tar" , "tsuite_bk5.tar" );
369        }
370        if( -e "tsuite_bk3.tar" )
371        {
372                rename( "tsuite_bk3.tar" , "tsuite_bk4.tar" );
373        }
374        if( -e "tsuite_bk2.tar" )
375        {
376                rename( "tsuite_bk2.tar" , "tsuite_bk3.tar" );
377        }
378        if( -e "tsuite_bk1.tar" )
379        {
380                rename( "tsuite_bk1.tar" , "tsuite_bk2.tar" );
381        }
382        if( -e "tsuite_bak.tar" )
383        {
384                rename( "tsuite_bak.tar" , "tsuite_bk1.tar" );
385        }
386        if( -e "tsuite.tar" )
387        {
388                rename( "tsuite.tar" , "tsuite_bak.tar" );
389        }
390        system(
391           "tar_mks -cvf tsuite.tar *.in");
392
393
394        # demote all old copies of data files
395        if( -e "data_bk6.tar" )
396        {
397                rename( "data_bk6.tar" , "data_bk7.tar" );
398        }
399        if( -e "data_bk5.tar" )
400        {
401                rename( "data_bk5.tar" , "data_bk6.tar" );
402        }
403        if( -e "data_bk4.tar" )
404        {
405                rename( "data_bk4.tar" , "data_bk5.tar" );
406        }
407        if( -e "data_bk3.tar" )
408        {
409                rename( "data_bk3.tar" , "data_bk4.tar" );
410        }
411        if( -e "data_bk2.tar" )
412        {
413                rename( "data_bk2.tar" , "data_bk3.tar" );
414        }
415        if( -e "data_bk1.tar" )
416        {
417                rename( "data_bk1.tar" , "data_bk2.tar" );
418        }
419        if( -e "data_bak.tar" )
420        {
421                rename( "data_bak.tar" , "data_bk1.tar" );
422        }
423        if( -e "data.tar" )
424        {
425                rename( "data.tar" , "data_bak.tar" );
426        }
427
428        # move to the cloudy current directory, one level above data, source, tsuite
429        if( !chdir( $current ) )
430        {
431                printf(" invalid directory for current project\n");
432                printf(" was ==%s==\n",$out_dir );
433                if( $lgLOGGING )
434                {
435                        printf(ioLOG " invalid directory for current project\n");
436                        printf(ioLOG " was ==%s==\n",$out_dir );
437                }
438                exit(1);
439        }
440        # now make backup copy of source
441        system(
442        "tar_mks -cvf \"$out_dir\"\"source.tar\" source/*.*");
443        # now make backup copy of data -
444        # NB bad style - but this group of files should be kept parallel with those done in unix/copy_files
445        # that script creates the ftp site data files, not this script
446        system(
447        "tar_mks -cvf \"$out_dir\"\"data.tar\" data/*.dat data/*.ini data/*.in data/*.rfi data/*.szd data/*.opc data/*.txt");
448
449        if( $lgLOGGING )
450        {
451                printf( ioLOG  "backup_old_files exits\n" );
452       
453        }
454        # move back to auto dir
455        # move to the output directory
456        if( !chdir( $out_dir ) )
457        {
458                printf(" invalid directory for output of test suite\n");
459                printf(" was ==%s==\n",$out_dir );
460                if( $lgLOGGING )
461                {
462                        printf(ioLOG " invalid directory for output of test suite\n");
463                        printf(ioLOG " was ==%s==\n",$out_dir );
464                }
465                exit(1);
466        }
467}
468
469sub run_cloudy
470{
471
472        $nMod = 0;
473        $nskip = $nmod_calc;
474        # move to the output directory
475        if( !chdir( $out_dir ) )
476        {
477                printf(" invalid directory for output of test suite\n");
478                printf(" was ==%s==\n",$out_dir );
479                exit(1);
480        }
481        if( $lgLOGGING )
482        {
483                printf( ioLOG "run_cloudy about to glob input files in dir %s\n", $in_dir );
484        }
485
486        while( defined( $input = glob("$in_dir*.in") ) )
487        {
488           if ( $nMod>=$nskip )
489           {
490                # copy input file to fileout to exit it
491                $output = $input;
492                # change input dir name to output
493                $output =~ s/$in_dir/$out_dir/gi;
494                # change .in to .out
495                $output =~ s/\.in/.out/gi;
496                # $output = "$out_dir"."$output";
497                if( $lgLOGGING )
498                {
499                        printf(  ioLOG "from %s \n  to %s \n", $input , $output );
500                }
501                # option to not do anything (for testing )
502                if( !$lgDO_NO_WORK )
503                {
504                   #>> chng 06 may 20 from -n 5 to -n 2 to be slightly higher prioritys
505                   #>>chng 06 jun 01, rm nice to raise priority - svn eats exe
506                   # system "nice -n 2 $exe < $input  > $output ";
507                   system "$exe < $input  > $output ";
508                }
509           }
510           ++$nMod;
511        }
512
513}
514
515
516#===========================================================
517#          check_output()
518#===========================================================
519sub check_output
520{
521
522        #find "BOTCH " and "W-" string in all the output file and write
523        #corresponding line into messages file.
524        if( $lgLOGGING )
525        {
526                printf( ioLOG "check_output entered\n");
527        }
528
529        system "grep Botch  $out_dir*.out >$errors";
530        system "grep W-  $out_dir*.out >> $errors";
531
532        if( !open( ioERRORS , ">>$errors" ) )
533        {
534                die( "could not open errors.txt" );
535        }
536
537        # check  output file to see whether they contain "Cloudy ends:"
538        # string and write corresponding line into checkend.txt file.
539        # if size of file $out_dir/checkend.txt is zero, then program crashed. 
540
541        $checkend = "$out_dir"."checkend.txt";
542        while(defined($input= glob("$out_dir*.in")) )
543        {
544
545                # form name of output file
546                $output = $input;
547                $output =~ s/\.in/\.out/gi;
548                system "grep 'ChkAssert'  $output > $checkend ";
549                # check whether output file exists and has zero size (string did not occur)
550                if(-z "$checkend")
551                {
552                        printf( ioERRORS "%s did not end or had no asserts\n", $output);     
553                }
554        }
555
556         # check whether any models were skipped because they were renamed *.skip
557         system "ls \"$out_dir*.skip\" > skip.txt" ;
558         # skipfile will have non-zero length if *.skip returned any names
559         if( -s "skip.txt" )
560         {
561            print STDERR "\n\n some files were skipped by renmaing to .skip - list is in skip.txt\n" ;
562            system "echo some files were skipped by renmaing to .skip - list is in skip.txt >> checkall.txt ";
563         }
564
565        if( $lgLOGGING )
566        {
567                printf( ioLOG "check_output exits\n");
568        }
569        close( ioERRORS);
570
571        # finally copy errors.txt (which we hope is empty) to gradj
572        copy( $errors , "u:/pub/gary/bleeding_edge/last/errors.txt" );
573
574        # search for PROBLEM in any file
575        if( -e $problem_file )
576        {
577           unlink( $problem_file );
578        }
579        # find all PROBLEMs
580        system( "grep \"PROBLEM\" *.out > $problem_file" );
581        # now look for debug print strings and cat to end
582        system( "grep \"DEBUG\" *.out >> $problem_file" );
583        # now copy this file to the gradj site
584        copy( $problem_file , "u:/pub/gary/bleeding_edge/last/problems.txt" );
585
586}
587
588#=============================================================
589#             send_mail(),
590#=============================================================
591
592sub send_mail
593{
594
595
596        # does errors exist and have non-zero size?
597        if( -s "$errors" )
598        {
599                #$DevMailer->{Body} = "problems were found\r\nLine 2\r\n";
600                #$DevMailer->{Body} = $DevMailer->{Body} . "Line 3\r\n";
601                system("c:\\u\\blat\\blat.exe errors.txt -t gary\@pa.uky.edu -s \"Cloudy had problems on the pc\" " );
602        }
603        else
604        {
605                 open( ioEMAIL , ">message.txt" );
606     
607                 printf( ioEMAIL " test suite ran OK on my pc\n"); 
608                 printf( ioEMAIL " no crashes or asserts were found on the pc\r\n" ) ;
609                 printf( ioEMAIL " contents of last dir being copied to last_good\r\n" ) ;
610                 close( ioEMAIL );
611#               $DevMailer->{Subject} = "test suite successfully run"; 
612#               $DevMailer->{Body} = "no problems were found\r\n";
613                system("c:\\u\\blat\\blat.exe message.txt -t gary\@pa.uky.edu -s \"test suite successfully run\" " );
614
615                # copy files to last_good location, since we just ran cleanly
616                system( "perl \"$script_dir\"promote_last_good.pl" );
617        }
618
619        # now check for problems that occurred
620        if( -s "$problem_file" )
621        {
622                system("c:\\u\\blat\\blat.exe problems.txt -t gary\@pa.uky.edu -s \"PROBLEM or DEBUG string was printed on PC\" " );
623        }
624 }
Note: See TracBrowser for help on using the browser.