FOSSology  4.4.0
Open Source License Compliance by Open Source Software
SchedulerTestRunnerScheduler.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 include_once(__DIR__.'/SchedulerTestRunner.php');
14 
20 {
24  private $testDb;
25 
26  public function __construct(TestPgDb $testDb)
27  {
28  $this->testDb = $testDb;
29  }
30 
31  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
32  {
33  $sysConf = $this->testDb->getFossSysConf();
34 
35  $agentName = "ojo";
36 
37  $agentDir = dirname(__DIR__, 4).'/build/src/ojo';
38  $execDir = "$agentDir/agent";
39  system("install -D $agentDir/VERSION $sysConf/mods-enabled/$agentName/VERSION");
40  system("install -D $agentDir/agent/$agentName $sysConf/mods-enabled/$agentName/agent/$agentName");
41  $pCmd = "echo $uploadId | $execDir/$agentName --userID=$userId --groupID=$groupId --jobId=$jobId --scheduler_start -c $sysConf $args";
42  $pipeFd = popen($pCmd, "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 $pCmd";
54  }
55 
56  unlink("$sysConf/mods-enabled/$agentName/VERSION");
57  unlink("$sysConf/mods-enabled/$agentName/agent/$agentName");
58  rmdir("$sysConf/mods-enabled/$agentName/agent/");
59  rmdir("$sysConf/mods-enabled/$agentName");
60  rmdir("$sysConf/mods-enabled");
61  unlink($sysConf."/fossology.conf");
62 
63  return array($success, $output, $retCode);
64  }
65 }
run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
Function to run agent from scheduler.
int Test
Definition: util.c:20