FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
runAgentFunc.php
1 #!/usr/bin/php
2 <?php
3 /*
4  Copyright (C) 2011-2013 Hewlett-Packard Development Company, L.P.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
31 require_once('../lib/bootstrap.php');
32 require_once('../lib/common-Test.php');
33 require_once('../lib/createRC.php');
34 
35 global $failures;
36 
37 if ( !defined('TESTROOT') ) {
38  $TESTROOT = dirname(getcwd());
39  $_ENV['TESTROOT'] = $TESTROOT;
40  putenv("TESTROOT=$TESTROOT");
41  define('TESTROOT',$TESTROOT);
42 }
43 
44 /* when a Jenkins job executes, it sets some environment variables that are
45  available to this script. $WORKSPACE is set to the absolute path of the
46  Jenkins workspace (where the subversion working copy is checked out to) */
47 $WORKSPACE = NULL;
48 
49 if ( array_key_exists('WORKSPACE', $_ENV) ) {
50  $WORKSPACE = $_ENV['WORKSPACE'];
51 }
52 
53 $func = TESTROOT . "/functional";
54 
55 if ( @chdir($func) === FALSE ) {
56 
57  echo "FATAL!, could not cd to:\n$func\n";
58  exit(1);
59 
60 }
61 
62 createRC();
63 $sysConf = array();
64 $sysConf = bootstrap();
65 putenv("SYSCONFDIR={$GLOBALS['SYSCONFDIR']}");
66 $_ENV['SYSCONFDIR'] = $GLOBALS['SYSCONFDIR'];
67 
68 $modules = array();
69 $funcList = array();
70 
71 // get the list of functional tests to run
72 $modules = parse_ini_file('../dataFiles/funcTests.ini',1);
73 foreach ($modules as $key => $value) {
74  $funcList[] = $key;
75 }
76 
77 // @todo fix this, I don't think you need to check for workspace.
78 if ( is_null($WORKSPACE) ) {
79  // back to fossology/src
80  backToParent('../..');
81 }
82 else {
83  if (@chdir($WORKSPACE . "/src") === FALSE)
84  {
85  echo "FATAL! " . __FILE__ . " could not cd to " . $WORKSPACE . "/src\n";
86  exit(1);
87  }
88 }
89 
90 /* store the current working directory, from which each test will begin */
91 $original_directory = getcwd();
92 
93 $failures = 0;
94 
95 foreach ( $funcList as $funcTest ) {
96 
97  /* start off each test in the original directory */
98  chdir($original_directory);
99 
100  echo "\n";
101  echo "$funcTest\n";
102 
103  /* check the first three characters of the subdirectory for 'lib' or 'cli' */
104  $other = substr($funcTest, 0, 3);
105 
106  /* for the special case of subdirectories in src/lib/ and src/cli,
107  the tests will be defined in a tests/ subdirectory. For example:
108  src/lib/c/tests/
109  src/lib/php/tests/
110  cli/tests/ */
111  if($other == 'lib' || $other == 'cli') {
112 
113  if(@chdir($funcTest . '/tests') === FALSE) {
114 
115  echo "Error! cannot cd to " . $funcTest . "/tests, skipping test\n";
116  $failures++;
117  continue;
118 
119  }
120  }
121 
122  /* for normal agents, the tests will be defined in an agent_tests/Functional
123  subdirectory */
124  else {
125 
126  if(@chdir($funcTest . '/agent_tests/Functional') === FALSE) {
127 
128  echo "Error! cannot cd to " . $funcTest . "/agent_tests/Functional, skipping test\n";
129  $failures++;
130  continue;
131 
132  }
133  }
134 
135  $Make = new RunTest($funcTest);
136  $runResults = $Make->MakeTest();
137  //debugprint($runResults, "run results for $funcTest\n");
138 
139  if($funcTest == 'nomos')
140  {
141  $diffResult = array();
142  foreach ($Make->makeOutput as $makeOutput)
143  if((strpos($makeOutput, '< File')!=false) || (strpos($makeOutput, '> File')!=false))
144  {
145  $diffResult[] = $makeOutput;
146  }
147  if(count($diffResult)!=0)
148  {
149  //echo "Nomos result have " . count($diffResult) . " difference!\n";
150  //print_r($diffResult);
151  foreach($diffResult as $diff)
152  echo substr($diff, strpos($diff, '=> ')+3) . "\n";
153  $runResults['nomosfunc'] = count($diffResult);
154  }
155 
157  exec("cp ./nomos-regression-test.html ".TESTROOT. "/reports/functional/");
158  }
159  $Make->printResults($runResults);
160 
161  if ( !processXUnit($funcTest) ) {
162  echo "Error! could not create html report for $funcTest at\n" .
163  __FILE__ . " on " . __LINE__ . "\n";
164  }
165  continue;
166 
167 } // foreach ( $funcList as $funcTest )
168 
169 if($failures) {
170  exit(1);
171 }
172 
173 exit(0);
174 
175 ?>
class for making an agent unit or functional test
bootstrap($sysconfdir="")
Bootstrap the fossology php library.
Definition: migratetest.php:93