FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
TestRun.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***********************************************************/
28 class TestRun
29 {
30  public $srcPath;
31  private $NotRunning = FALSE;
32  private $Running = TRUE;
33  private $schedulerPid = -1;
34 
49  public function __construct($srcPath = NULL) {
50 
51  if (empty($srcPath)) {
52  // default
53  $this->srcPath = '/home/fosstester/fossology';
54  }
55  else
56  {
57  $scrPath = rtrim($srcPath, '/');
58  $this->srcPath = $srcPath . "/fossology";
59  }
60  return;
61  }
70  protected function checkFop()
71  {
72  $fMatches = array();
73  $eMatches = array();
74  $fatalPat = '/FATAL/';
75  $errPat = '/error/i';
76 
77  $fMatches = preg_grep($fatalPat, file('fop.out'));
78  $eMatches = preg_grep($errPat, file('fop.out'));
79  if(empty($fMatches) && empty($eMatches))
80  {
81  print "DEBUG: returning false, matched arrays are:\n";
82  print_r($fMatches) . "\n";
83  print_r($eMatches) . "\n";
84  return(FALSE);
85  }
86  else
87  {
88  return(TRUE);
89  }
90  }
91 
98  public function checkOutTot() {
99 
100  $Tot = 'svn co https://fossology.svn.sourceforge.net/svnroot/fossology/trunk/fossology';
101 
102  /* remove fossology from the path so we don't get fossology/fossology */
103  $home = rtrim($this->srcPath, '/fossology');
104 
105  if (chdir($home)) {
106  $last = exec($Tot, $output, $rtn);
107  //print "checkout results are, last and output:$last\n";
108  //print_r($output) . "\n";
109  if ($rtn != 0) {
110  print "ERROR! Could not check out FOSSology sources at\n$Tot\n";
111  print "Error was: $output\n";
112  return (FALSE);
113  }
114  }
115  else {
116  print "ERROR! could not cd to $home\n";
117  return (FALSE);
118  }
119  return(TRUE);
120  }
128  private function checkScheduler() {
129  $pLast = NULL;
130  $pLast = exec('ps -ef | grep scheduler | grep -v grep', $results, $rtn);
131  //print "DB: CKS: pLast is:$pLast\n";
132  if (empty($pLast)) {
133  return ($this->NotRunning);
134  }
135  else {
136  return ($this->Running);
137  }
138  }
139  private function getSchedPid() {
140 
141  $parts = array();
142  $psLast = NULL;
143  $cmd = 'ps -ef | grep fossology-scheduler | grep -v grep';
144  $psLast = exec($cmd, $results, $rtn);
145  // scheduler is not running.
146  if($psLast == "")
147  {
148  return(NULL);
149  }
150  $parts = split(' ', $psLast);
151  //print "parts is:\n"; print_r($parts) . "\n";
152  return ($parts[5]);
153  }
154  public function foPostinstall() {
155 
156  if (!chdir($this->srcPath)) {
157  print "Error can't cd to $this->srcPath\n";
158  }
159  $foLast = exec('sudo /usr/local/lib/fossology/fo-postinstall > fop.out 2>&1', $results, $rtn);
160 
161  // remove this check as fo-postinstall reports true (0) when there are errors
162  // if ($rtn == 0) {
163  if ($this->checkFop() === FALSE)
164  {
165  return (TRUE);
166  }
167  else {$cmd = 'ps -ef | grep fossology-scheduler | grep -v grep';
168  return (FALSE);
169  }
170  }
171  public function makeInstall() {
172  if (!chdir($this->srcPath)) {
173  print "Error can't cd to $this->srcPath\n";
174  }
175  $miLast = exec('sudo make install > make-install.out 2>&1', $results, $rtn);
176  if ($rtn == 0) {
177  if (array_search('Error', $results)) {
178  // TODO: write results out to: make-install.out
179  //print "Found Error string in the Make output\n";
180  return (FALSE);
181  }
182  else {
183  return (TRUE);
184  }
185  }
186  else {
187  return (FALSE);
188  }
189  }
190  public function makeSrcs() {
191 
192  if (!chdir($this->srcPath)) {
193  print "Error can't cd to $this->srcPath\n";
194  }
195  $mcLast = exec('make clean > make-clean.out 2>&1', $results, $rtn);
196  //print "results of the make clean are:$rtn, $mcLast\n";
197  $makeLast = exec('make > make.out 2>&1', $results, $rtn);
198  //print "results of the make are:$rtn, $makeLast\n"; print_r($results) . "\n";
199  if ($rtn == 0) {
200  //print "results of the make are:\n"; print_r($results) . "\n";
201  if (array_search('Error', $results)) {
202  //print "Found Error string in the Make output\n";
203  // TODO: write results out to: make.out
204  return (FALSE);
205  }
206  else {
207  return (TRUE);
208  }
209  }
210  else {
211  return (FALSE);
212  }
213  } // makeSrcs
214 
215  public function schedulerTest() {
216  $StLast = exec('sudo /usr/local/lib/fossology/fossology-scheduler -t -L stdout > ST.out 2>&1', $results, $rtn);
217  if ($rtn != 0) {
218  if (array_search('FATAL', $results)) {
219  return (FALSE);
220  }
221  return (FALSE);
222  }
223  return (TRUE);
224  }
225  public function setSrcPath($path) {
226  }
234  public function startScheduler() {
235  if ($this->checkScheduler() === $this->Running) {
236  return ($this->Running);
237  }
238  else {
239  $stdStart = exec("sudo /etc/init.d/fossology start > /dev/null 2>&1 &", $results, $rtn);
240  sleep(5);
241  if ($this->checkScheduler() === $this->Running) {
242  return ($this->Running);
243  }
244  else {
245  return ($this->NotRunning);
246  }
247  }
248  }
258  public function stopScheduler() {
259  if ($this->checkScheduler() === $this->NotRunning) {
260  return (TRUE);
261  }
262  else {
263  $stdStop = exec('sudo /etc/init.d/fossology stop 2>&1', $results, $rtn);
264  }
265  // still running, kill with -9
266  if ($this->checkScheduler() === $this->Running) {
267  $this->schedulerPid = $this->getSchedPid();
268  // no pid? Must be stopped, not running
269  if($this->schdulerPid === NULL)
270  {
271  return(TRUE);
272  }
273  $killLast = exec("sudo kill -9 $this->schedulerPid 2>&1", $results, $rtn);
274  }
275  return (TRUE);
276  }
284  public function svnUpdate() {
285  if (!chdir($this->srcPath)) {
286  print "Error can't cd to $this->srcPath\n";
287  }
288  $svnLast = exec('svn update', $results, $rtn);
289  if ($rtn != 0) {
290  return (FALSE);
291  }
292  else {
293  return (TRUE);
294  }
295  }
296 }
297 ?>
checkOutTot()
check out the top of trunk fossology sources. Uses attribute set by the constructor.
Definition: TestRun.php:98
checkFop()
checks the output file from a fo-postinstall for the strings FATAL, error and Error. Assumes fop.out file is in the cwd.
Definition: TestRun.php:70
stopScheduler()
Definition: TestRun.php:258
__construct($srcPath=NULL)
Definition: TestRun.php:49
startScheduler()
Definition: TestRun.php:234
checkScheduler()
Definition: TestRun.php:128
svnUpdate()
Definition: TestRun.php:284