source: PSPA/madxPSPA/testing/MadBuildAndTest.pl @ 430

Last change on this file since 430 was 430, checked in by touze, 11 years ago

import madx-5.01.00

File size: 4.9 KB
Line 
1#!/usr/bin/perl
2
3# retreive directory hosting the Mad program from the command line
4$thisProgramName = $0;
5$_ = $thisProgramName;
6/^([\w\d\-_.\/]+)\/MadBuildAndTest.pl/;
7
8if ($1 ne "") {
9        $hostDirectory = $1;
10} else {
11        $hostDirectory = ".";
12}
13chdir($hostDirectory);
14
15open REPORT_FILE, ">MadBuildAndTest_Report.txt";
16my $now = localtime;
17print REPORT_FILE "MadBuildAndTest.pl report from $now\n";
18       
19my $releaseTag;
20my $runTest;
21my $debugMode;
22       
23my $argsNumber = $#ARGV+1;
24       
25if ($argsNumber>0){
26        $debugMode = 1;
27} else {
28        $debugMode = 0;
29}
30       
31
32
33if ($debugMode==0){
34        # should also retreive the latest release tag
35        print REPORT_FILE "entering MadTrigTest.pl\n";
36        my @return = `./MadTrigTest.pl`; # extracts MAD's CVS repository with no tag
37        print REPORT_FILE "MadTrigTest.pl completed\n";
38
39        foreach $retString (@return){
40                my $recognized = 0;
41                if ($retString =~ /^trigger[\s\t]*=[\s\t]*([\w\-]+)$/){
42                        $runTest = $1;
43                        $recognized = 1;
44                }
45                if ($retString =~ /^releaseTag[\s\t]*=[\s\t]*([\w\-\d_]+)$/){
46                        $releaseTag = $1;
47                        $recognized = 1;
48                }
49                if ($recognized == 0 ) {
50                        print REPORT_FILE "Unknown string $retString returned by ./MadTrigTest.pl\n";
51                }
52        }
53} else {
54        # expect "debug=madX-x_yy_zz" where madX-x_yy_zz is the release tag
55        $firstArg = $ARGV[0];
56        if ($firstArg =~ /debug=(madX\-\d_\d\d_\d\d)/){
57                $releaseTag = $1;
58                $runTest = 'run-test';
59        } else {
60                print "Expect either no argument (automatic trigger)or argument of form:\n";
61                print "\tdebug=madX-x_yy_zz\n";
62                # no need to kill the child process: it was not yet forked
63                # print "Kill the child process\n";
64                #kill 9, $child_pid; # kill the child process
65                print REPORT_FILE "Exit!\n";
66                exit;
67        }
68}
69
70my $child_pid;
71
72if ($runTest eq "run-test") {
73        $child_pid = fork();
74} else {
75        print REPORT_FILE "No new release detected => no need to run the test-suite\n";
76        close REPORT_FILE;
77        exit;
78}
79
80
81if (not defined $child_pid){
82        print "no system resources to fork process\n";
83        exit;
84}
85
86if ($child_pid==0){
87    # this child process
88    # refresh the AFS token every 6 hours. Otherwise the token
89    # would expire after 25 hours.
90    # (note this trick works for up to 10 days according to IT support)
91    my $start = localtime;
92    open TICKETS_HISTORY, ">MadBuildAndTest_Tickets_History.txt"; # first time opening
93    print TICKETS_HISTORY "Tracking AFS/Kerberos tickets refreshing since $start\n";
94    close TICKETS_HISTORY; # will be successively opened and closed to force flushing
95
96  INFINITE_LOOP:
97    open TICKETS_HISTORY, ">>MadBuildAndTest_Tickets_History.txt"; # append   
98    my @tokens = `/usr/bin/tokens`;     # provide path to cope with reduced acron environment
99    my @klist = `/usr/sue/bin/klist`;   # provide path to cope with reduced acron environment
100    my $now = localtime;
101    print TICKETS_HISTORY "\n\nAFS and Kerberos tickets on $now\n";
102    print TICKETS_HISTORY "======================= running tokens\n";
103    print TICKETS_HISTORY @tokens;
104    print TICKETS_HISTORY "======================= running klist\n";
105    print TICKETS_HISTORY @klist;
106    print TICKETS_HISTORY "now trying to invoke 'kinit -R' and 'aklog'\n";
107    close TICKETS_HISTORY; # open / close in place of flushing
108    sleep 21600; # 6 hours
109    `/usr/sue/bin/kinit -R`;    # provide path to cope with reduced acron environment
110    `/usr/bin/aklog`;           # provide path to cope with reduced acron environment
111    # could also set enviromment variables within perl,
112    # as done within MadBuild.pl for flexlm for instance...
113   
114    # check if the child process' parent is dead, it should also kill itself
115    $parent_pid = getppid(); # get parent process' pid
116    $cnt = kill 0, $parent_pid;
117    if ($cnt == 0){
118        exit;
119    }   
120    goto INFINITE_LOOP;
121}
122
123if ($child_pid) {
124        # non-zero pid means we are in the parent process, which received the child's pid
125
126        # print REPORT_FILE "\$runTest is '$runTest', and \$releaseTag is '$releaseTag'\n";
127
128        # at this stage ./MadCvsExtract/madx dir created locally
129        # (currently overwritten by MadBuild.pl)
130   
131   
132        # first create the work-log report
133        `./MadWorkReport.pl`; # creates and deletes a CVS extract locally
134
135        # the build-and-test procedure always applies to the last release
136        # even if CVS commits took place afterwards.
137
138        # irrespective of which directory MadTrigTest.pl ended in,
139        # MadBuild.pl starts from the location set by calling MadBuildAndTest.pl program
140       
141        print REPORT_FILE "entering MadBuild.pl\n";     
142        `./MadBuild.pl $releaseTag`; # issues e-mail upon completion
143        print REPORT_FILE "MadBuild.pl completed\n";
144       
145        # irrespective of which directory MadBuild.pl ended in,
146        # MadTest.pl starts from the location set by calling MadBuildAndTest.pl program
147       
148        print REPORT_FILE "entering MadTest.pl\n";
149        `./MadTest.pl ./MadCvsExtract/madX`; # issues e-mail upon completion
150        print REPORT_FILE "MadTest.pl completed\n";
151
152        close REPORT_FILE;
153       
154        # kill the child process in charge of refreshing the AFS token every 6 hours   
155        kill 9, $child_pid; # kill the child process
156
157} # parent-process
Note: See TracBrowser for help on using the repository browser.