FOSSology  4.4.0
Open Source License Compliance by Open Source Software
TestRun.php
1 <?php
2 /*
3 SPDX-FileCopyrightText: © 2008 Hewlett-Packard Development Company, L.P.
4 
5 SPDX-License-Identifier: GPL-2.0-only
6 */
17 class TestRun
18 {
19  public $srcPath;
20  private $NotRunning = FALSE;
21  private $Running = TRUE;
22  private $schedulerPid = -1;
23 
38  public function __construct($srcPath = NULL) {
39 
40  if (empty($srcPath)) {
41  // default
42  $this->srcPath = '/home/fosstester/fossology';
43  }
44  else
45  {
46  $scrPath = rtrim($srcPath, '/');
47  $this->srcPath = $srcPath . "/fossology";
48  }
49  return;
50  }
59  protected function checkFop()
60  {
61  $fMatches = array();
62  $eMatches = array();
63  $fatalPat = '/FATAL/';
64  $errPat = '/error/i';
65 
66  $fMatches = preg_grep($fatalPat, file('fop.out'));
67  $eMatches = preg_grep($errPat, file('fop.out'));
68  if(empty($fMatches) && empty($eMatches))
69  {
70  print "DEBUG: returning false, matched arrays are:\n";
71  print_r($fMatches) . "\n";
72  print_r($eMatches) . "\n";
73  return(FALSE);
74  }
75  else
76  {
77  return(TRUE);
78  }
79  }
80 
87  public function checkOutTot() {
88 
89  $Tot = 'svn co https://fossology.svn.sourceforge.net/svnroot/fossology/trunk/fossology';
90 
91  /* remove fossology from the path so we don't get fossology/fossology */
92  $home = rtrim($this->srcPath, '/fossology');
93 
94  if (chdir($home)) {
95  $last = exec($Tot, $output, $rtn);
96  //print "checkout results are, last and output:$last\n";
97  //print_r($output) . "\n";
98  if ($rtn != 0) {
99  print "ERROR! Could not check out FOSSology sources at\n$Tot\n";
100  print "Error was: $output\n";
101  return (FALSE);
102  }
103  }
104  else {
105  print "ERROR! could not cd to $home\n";
106  return (FALSE);
107  }
108  return(TRUE);
109  }
117  private function checkScheduler() {
118  $pLast = NULL;
119  $pLast = exec('ps -ef | grep scheduler | grep -v grep', $results, $rtn);
120  //print "DB: CKS: pLast is:$pLast\n";
121  if (empty($pLast)) {
122  return ($this->NotRunning);
123  }
124  else {
125  return ($this->Running);
126  }
127  }
128  private function getSchedPid() {
129 
130  $parts = array();
131  $psLast = NULL;
132  $cmd = 'ps -ef | grep fossology-scheduler | grep -v grep';
133  $psLast = exec($cmd, $results, $rtn);
134  // scheduler is not running.
135  if($psLast == "")
136  {
137  return(NULL);
138  }
139  $parts = explode(' ', $psLast);
140  //print "parts is:\n"; print_r($parts) . "\n";
141  return ($parts[5]);
142  }
143  public function foPostinstall() {
144 
145  if (!chdir($this->srcPath)) {
146  print "Error can't cd to $this->srcPath\n";
147  }
148  $foLast = exec('sudo /usr/local/lib/fossology/fo-postinstall > fop.out 2>&1', $results, $rtn);
149 
150  // remove this check as fo-postinstall reports true (0) when there are errors
151  // if ($rtn == 0) {
152  if ($this->checkFop() === FALSE)
153  {
154  return (TRUE);
155  }
156  else {$cmd = 'ps -ef | grep fossology-scheduler | grep -v grep';
157  return (FALSE);
158  }
159  }
160  public function makeInstall() {
161  if (!chdir($this->srcPath)) {
162  print "Error can't cd to $this->srcPath\n";
163  }
164  $miLast = exec('sudo make install > make-install.out 2>&1', $results, $rtn);
165  if ($rtn == 0) {
166  if (array_search('Error', $results)) {
167  // TODO: write results out to: make-install.out
168  //print "Found Error string in the Make output\n";
169  return (FALSE);
170  }
171  else {
172  return (TRUE);
173  }
174  }
175  else {
176  return (FALSE);
177  }
178  }
179  public function makeSrcs() {
180 
181  if (!chdir($this->srcPath)) {
182  print "Error can't cd to $this->srcPath\n";
183  }
184  $mcLast = exec('make clean > make-clean.out 2>&1', $results, $rtn);
185  //print "results of the make clean are:$rtn, $mcLast\n";
186  $makeLast = exec('make > make.out 2>&1', $results, $rtn);
187  //print "results of the make are:$rtn, $makeLast\n"; print_r($results) . "\n";
188  if ($rtn == 0) {
189  //print "results of the make are:\n"; print_r($results) . "\n";
190  if (array_search('Error', $results)) {
191  //print "Found Error string in the Make output\n";
192  // TODO: write results out to: make.out
193  return (FALSE);
194  }
195  else {
196  return (TRUE);
197  }
198  }
199  else {
200  return (FALSE);
201  }
202  } // makeSrcs
203 
204  public function schedulerTest() {
205  $StLast = exec('sudo /usr/local/lib/fossology/fossology-scheduler -t -L stdout > ST.out 2>&1', $results, $rtn);
206  if ($rtn != 0) {
207  if (array_search('FATAL', $results)) {
208  return (FALSE);
209  }
210  return (FALSE);
211  }
212  return (TRUE);
213  }
214  public function setSrcPath($path) {
215  }
223  public function startScheduler() {
224  if ($this->checkScheduler() === $this->Running) {
225  return ($this->Running);
226  }
227  else {
228  $stdStart = exec("sudo /etc/init.d/fossology start > /dev/null 2>&1 &", $results, $rtn);
229  sleep(5);
230  if ($this->checkScheduler() === $this->Running) {
231  return ($this->Running);
232  }
233  else {
234  return ($this->NotRunning);
235  }
236  }
237  }
247  public function stopScheduler() {
248  if ($this->checkScheduler() === $this->NotRunning) {
249  return (TRUE);
250  }
251  else {
252  $stdStop = exec('sudo /etc/init.d/fossology stop 2>&1', $results, $rtn);
253  }
254  // still running, kill with -9
255  if ($this->checkScheduler() === $this->Running) {
256  $this->schedulerPid = $this->getSchedPid();
257  // no pid? Must be stopped, not running
258  if($this->schdulerPid === NULL)
259  {
260  return(TRUE);
261  }
262  $killLast = exec("sudo kill -9 $this->schedulerPid 2>&1", $results, $rtn);
263  }
264  return (TRUE);
265  }
273  public function svnUpdate() {
274  if (!chdir($this->srcPath)) {
275  print "Error can't cd to $this->srcPath\n";
276  }
277  $svnLast = exec('svn update', $results, $rtn);
278  if ($rtn != 0) {
279  return (FALSE);
280  }
281  else {
282  return (TRUE);
283  }
284  }
285 }
checkScheduler()
Definition: TestRun.php:117
__construct($srcPath=NULL)
Definition: TestRun.php:38
startScheduler()
Definition: TestRun.php:223
checkOutTot()
check out the top of trunk fossology sources. Uses attribute set by the constructor.
Definition: TestRun.php:87
svnUpdate()
Definition: TestRun.php:273
stopScheduler()
Definition: TestRun.php:247
checkFop()
checks the output file from a fo-postinstall for the strings FATAL, error and Error....
Definition: TestRun.php:59