FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
SchedulerTestRunnerCli.php
1 <?php
2 /*
3 Copyright (C) 2014, Siemens AG
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 */
18 
19 namespace Fossology\Decider\Test;
20 
22 
23 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
24 include_once(__DIR__.'/SchedulerTestRunner.php');
25 
31 {
33  private $testDb;
34 
35  public function __construct(TestPgDb $testDb)
36  {
37  $this->testDb = $testDb;
38  }
39 
44  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
45  {
46  $sysConf = $this->testDb->getFossSysConf();
47 
48  $agentName = "decider";
49 
50  $agentDir = dirname(dirname(__DIR__));
51  $execDir = "$agentDir/agent";
52  system("install -D $agentDir/VERSION $sysConf/mods-enabled/$agentName/VERSION");
53 
54  $pipeFd = popen($cmd = "echo $uploadId | $execDir/$agentName --userID=$userId --groupID=$groupId --jobId=$jobId --scheduler_start -c $sysConf $args", "r");
55  $success = $pipeFd !== false;
56 
57  $output = "";
58  $retCode = -1;
59  if ($success) {
60  while (($buffer = fgets($pipeFd, 4096)) !== false) {
61  $output .= $buffer;
62  }
63  $retCode = pclose($pipeFd);
64  } else {
65  print "failed opening pipe to $cmd";
66  }
67 
68  unlink("$sysConf/mods-enabled/$agentName/VERSION");
69  rmdir("$sysConf/mods-enabled/$agentName");
70  rmdir("$sysConf/mods-enabled");
71 
72  return array($success, $output, $retCode);
73  }
74 }
run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
Get the arguments required by agent to run and try to run the agent.