forked from BorderCloud/TFT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestJmeter.php
65 lines (55 loc) · 2.28 KB
/
TestJmeter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
class TestJmeter extends AbstractTest
{
public $URLJmeterTestPlan = "";
function __construct($URLJmeterTestPlan)
{
parent::__construct();
$this->URLJmeterTestPlan = $URLJmeterTestPlan;
}
function doTestPlan()
{
global $JMETER, $modeDebug, $modeVerbose, $listTestSuite, $TESTENDPOINT_HOSTNAME, $TESTENDPOINT_PORT, $TESTENDPOINT_PATH;
$message = "";
$test = false;
$fileJmeterTestPlan = "";
foreach ($listTestSuite as $URL => $folder) {
if (0 === strpos($this->URLJmeterTestPlan, $URL)) {
$fileJmeterTestPlan = str_replace($URL, $folder, $this->URLJmeterTestPlan);
}
}
if (empty($fileJmeterTestPlan)) {
$this->AddFail($this->URLJmeterTestPlan. " is unknown in the testsuite of the config.ini.");
return;
}
if (!file_exists($fileJmeterTestPlan)) {
$this->AddFail("File of this Jmeter Test plan doesn't exist.");
return;
}
$resultFile = str_replace(".jmx", ".jtl", $fileJmeterTestPlan);
//TODO example to install jmeter with export PATH=$PATH:/home/LOGIN/dev/apache-jmeter-4.0/bin/
$command = 'export JVM_ARGS="-Dnashorn.args=--no-deprecation-warning" ;' . //hide warnings
$JMETER." -n -t $fileJmeterTestPlan -JHOSTNAME=$TESTENDPOINT_HOSTNAME -JPORT=$TESTENDPOINT_PORT -JPATH=$TESTENDPOINT_PATH -l $resultFile --forceDeleteResultFile";
$output = shell_exec($command);
//print_r($output);
if (!file_exists($resultFile)) {
$this->AddFail("ERROR IN JMETER TEST : \n >>> " . $command . "\n" . $output . "\n");
return;
} else {
//$this->AddFail(file_get_contents($resultFile));
$report = file_get_contents($resultFile);
if ($modeVerbose || $modeDebug) {
print_r("JMETER TEST OK of " . $this->URLJmeterTestPlan . " :\n" . $report);
}
if (strpos($report, 'ERROR') !== false) {
$this->AddFail("ERROR IN JMETER TEST of " . $this->URLJmeterTestPlan . " :\n" . $report);
return;
}
}
if ($test) {
echo $message;
print_r($this->_fails);
exit();
}
}
}