FOSSology  4.4.0
Open Source License Compliance by Open Source Software
runAgentFunc.php
1 #!/usr/bin/php
2 <?php
3 /*
4  SPDX-FileCopyrightText: © 2011-2013 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
20 require_once('../lib/bootstrap.php');
21 require_once('../lib/common-Test.php');
22 require_once('../lib/createRC.php');
23 
24 global $failures;
25 
26 if ( !defined('TESTROOT') ) {
27  $TESTROOT = dirname(getcwd());
28  $_ENV['TESTROOT'] = $TESTROOT;
29  putenv("TESTROOT=$TESTROOT");
30  define('TESTROOT',$TESTROOT);
31 }
32 
33 /* when a Jenkins job executes, it sets some environment variables that are
34  available to this script. $WORKSPACE is set to the absolute path of the
35  Jenkins workspace (where the subversion working copy is checked out to) */
36 $WORKSPACE = NULL;
37 
38 if ( array_key_exists('WORKSPACE', $_ENV) ) {
39  $WORKSPACE = $_ENV['WORKSPACE'];
40 }
41 
42 $func = TESTROOT . "/functional";
43 
44 if ( @chdir($func) === FALSE ) {
45 
46  echo "FATAL!, could not cd to:\n$func\n";
47  exit(1);
48 
49 }
50 
51 createRC();
52 $sysConf = array();
53 $sysConf = bootstrap();
54 putenv("SYSCONFDIR={$GLOBALS['SYSCONFDIR']}");
55 $_ENV['SYSCONFDIR'] = $GLOBALS['SYSCONFDIR'];
56 
57 $modules = array();
58 $funcList = array();
59 
60 // get the list of functional tests to run
61 $modules = parse_ini_file('../dataFiles/funcTests.ini',1);
62 foreach ($modules as $key => $value) {
63  $funcList[] = $key;
64 }
65 
66 // @todo fix this, I don't think you need to check for workspace.
67 if ( is_null($WORKSPACE) ) {
68  // back to fossology/src
69  backToParent('../..');
70 }
71 else {
72  if (@chdir($WORKSPACE . "/src") === FALSE)
73  {
74  echo "FATAL! " . __FILE__ . " could not cd to " . $WORKSPACE . "/src\n";
75  exit(1);
76  }
77 }
78 
79 /* store the current working directory, from which each test will begin */
80 $original_directory = getcwd();
81 
82 $failures = 0;
83 
84 foreach ( $funcList as $funcTest ) {
85 
86  /* start off each test in the original directory */
87  chdir($original_directory);
88 
89  echo "\n";
90  echo "$funcTest\n";
91 
92  /* check the first three characters of the subdirectory for 'lib' or 'cli' */
93  $other = substr($funcTest, 0, 3);
94 
95  /* for the special case of subdirectories in src/lib/ and src/cli,
96  the tests will be defined in a tests/ subdirectory. For example:
97  src/lib/c/tests/
98  src/lib/php/tests/
99  cli/tests/ */
100  if($other == 'lib' || $other == 'cli') {
101 
102  if(@chdir($funcTest . '/tests') === FALSE) {
103 
104  echo "Error! cannot cd to " . $funcTest . "/tests, skipping test\n";
105  $failures++;
106  continue;
107 
108  }
109  }
110 
111  /* for normal agents, the tests will be defined in an agent_tests/Functional
112  subdirectory */
113  else {
114 
115  if(@chdir($funcTest . '/agent_tests/Functional') === FALSE) {
116 
117  echo "Error! cannot cd to " . $funcTest . "/agent_tests/Functional, skipping test\n";
118  $failures++;
119  continue;
120 
121  }
122  }
123 
124  $Make = new RunTest($funcTest);
125  $runResults = $Make->MakeTest();
126  //debugprint($runResults, "run results for $funcTest\n");
127 
128  if($funcTest == 'nomos')
129  {
130  $diffResult = array();
131  foreach ($Make->makeOutput as $makeOutput)
132  if((strpos($makeOutput, '< File')!=false) || (strpos($makeOutput, '> File')!=false))
133  {
134  $diffResult[] = $makeOutput;
135  }
136  if(count($diffResult)!=0)
137  {
138  //echo "Nomos result have " . count($diffResult) . " difference!\n";
139  //print_r($diffResult);
140  foreach($diffResult as $diff)
141  echo substr($diff, strpos($diff, '=> ')+3) . "\n";
142  $runResults['nomosfunc'] = count($diffResult);
143  }
144 
146  exec("cp ./nomos-regression-test.html ".TESTROOT. "/reports/functional/");
147  }
148  $Make->printResults($runResults);
149 
150  if ( !processXUnit($funcTest) ) {
151  echo "Error! could not create html report for $funcTest at\n" .
152  __FILE__ . " on " . __LINE__ . "\n";
153  }
154  continue;
155 
156 } // foreach ( $funcList as $funcTest )
157 
158 if($failures) {
159  exit(1);
160 }
161 
162 exit(0);
class for making an agent unit or functional test
bootstrap($sysconfdir="")
Bootstrap the fossology php library.
Definition: migratetest.php:82