FOSSology  4.4.0
Open Source License Compliance by Open Source Software
SchedulerTestRunnerCli.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Decider\Test;
9 
11 
12 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
13 include_once(__DIR__.'/SchedulerTestRunner.php');
14 
20 {
22  private $testDb;
23 
24  public function __construct(TestPgDb $testDb)
25  {
26  $this->testDb = $testDb;
27  }
28 
33  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
34  {
35  $sysConf = $this->testDb->getFossSysConf();
36 
37  $agentName = "decider";
38 
39  $agentDir = dirname(__DIR__, 2);
40  $baseDir = dirname(__DIR__, 4);
41  $execDir = "$agentDir/agent";
42  system("install -D $baseDir/build/src/decider/VERSION $sysConf/mods-enabled/$agentName/VERSION");
43 
44  $pipeFd = popen($cmd = "echo $uploadId | $execDir/$agentName --userID=$userId --groupID=$groupId --jobId=$jobId --scheduler_start -c $sysConf $args", "r");
45  $success = $pipeFd !== false;
46 
47  $output = "";
48  $retCode = -1;
49  if ($success) {
50  while (($buffer = fgets($pipeFd, 4096)) !== false) {
51  $output .= $buffer;
52  }
53  $retCode = pclose($pipeFd);
54  } else {
55  print "failed opening pipe to $cmd";
56  }
57 
58  unlink("$sysConf/mods-enabled/$agentName/VERSION");
59  rmdir("$sysConf/mods-enabled/$agentName");
60  rmdir("$sysConf/mods-enabled");
61 
62  return array($success, $output, $retCode);
63  }
64 }
run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
Get the arguments required by agent to run and try to run the agent.