FOSSology  4.4.0
Open Source License Compliance by Open Source Software
SchedulerTestRunnerCli.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2019 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Ojo\Test;
9 
11 
12 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
13 
19 {
23  private $testDb;
24 
25  public function __construct(TestPgDb $testDb)
26  {
27  $this->testDb = $testDb;
28  }
29 
30  public function run($args)
31  {
32  $sysConf = $this->testDb->getFossSysConf();
33 
34  $agentName = "ojo";
35 
36  $agentDir = dirname(__DIR__, 4).'/build/src/ojo';
37  $execDir = "$agentDir/agent";
38  system("install -D $agentDir/VERSION $sysConf/mods-enabled/$agentName/VERSION");
39 
40  $curdir = getcwd();
41  chdir(__DIR__);
42  $pipeFd = popen($cmd = "$execDir/$agentName $args", "r");
43  $success = $pipeFd !== false;
44 
45  $output = "";
46  $retCode = -1;
47  if ($success) {
48  while (($buffer = fgets($pipeFd, 4096)) !== false) {
49  $output .= $buffer;
50  }
51  $retCode = pclose($pipeFd);
52  } else {
53  print "failed opening pipe to $cmd";
54  }
55  chdir($curdir);
56 
57  unlink("$sysConf/mods-enabled/$agentName/VERSION");
58  rmdir("$sysConf/mods-enabled/$agentName");
59  rmdir("$sysConf/mods-enabled");
60 
61  return array($success, $output, $retCode);
62  }
63 }
int Test
Definition: util.c:20