Skip to content
Snippets Groups Projects
Commit d5502b8e authored by Janis Daniel Dähne's avatar Janis Daniel Dähne
Browse files

- added option to set environment variables in the config (also in the config table)

- added some catches for main test executing calls
parent 23357edf
No related branches found
No related tags found
No related merge requests found
......@@ -324,7 +324,13 @@ foreach ($testCases as $test) {
$showTestRunnerDebugOutput = $config['showTestRunnerDebugOutput'];
}
$_result = do_compile($arg_mainFileNameWithExtension, $fullWorkingDirPath, $compileCmd, $sourceFileExtensions, $requestDistinctionString, $showTestRunnerDebugOutput);
try {
$_result = do_compile($arg_mainFileNameWithExtension, $fullWorkingDirPath, $compileCmd, $sourceFileExtensions, $requestDistinctionString, $showTestRunnerDebugOutput);
}catch (Exception $e) {
//critical error, abort execution (all other tests are likely to fail)
output($status_code_InternalServerError, "error executing regex test: " . $e->getMessage());
goto handleCleanup;
}
$result = array(
$s_testServerCode => $status_code_Ok,
......@@ -351,9 +357,16 @@ foreach ($testCases as $test) {
$showTestRunnerDebugOutput = $config['showTestRunnerDebugOutput'];
}
//no need to write any files ... can all be handled in memory
//$_result = do_regexTest_json($arg_allFiles, $testContent);
$_result = do_regexTest_format2($arg_allFiles, $testContent, $showTestRunnerDebugOutput);
try {
//no need to write any files ... can all be handled in memory
//$_result = do_regexTest_json($arg_allFiles, $testContent);
$_result = do_regexTest_format2($arg_allFiles, $testContent, $showTestRunnerDebugOutput);
} catch (Exception $e) {
//critical error, abort execution (all other tests are likely to fail)
output($status_code_InternalServerError, "error executing regex test: " . $e->getMessage());
goto handleCleanup;
}
$result = array(
$s_testServerCode => $status_code_Ok,
......@@ -366,6 +379,7 @@ foreach ($testCases as $test) {
$s_protocol => formatOutput($_result[$s_output]) # the conversation protocol
);
array_push($testResults, $result);
} else if ($arg_command === $s_command_blackBoxTest || $arg_command === $s_command_justRunTest) {
if ($isDebug) {
......@@ -509,14 +523,20 @@ foreach ($testCases as $test) {
$showTestRunnerDebugOutput = $config['showTestRunnerDebugOutput'];
}
$_result = do_blackBoxTest($arg_mainFileNameWithExtension, $test, $fullWorkingDirPath,
$min_timeout, $min_memoryLimit, $min_diskSpaceLimit,
$compileCmd, $execCmd, $sourceFileExtensions, $needCompilation,
$maxLinesToRead, $maxErrLinesToRead, $maxLinesToWrite,
($arg_command === $s_command_justRunTest),
$requestDistinctionString,
$showTestRunnerDebugOutput
);
try {
$_result = do_blackBoxTest($arg_mainFileNameWithExtension, $test, $fullWorkingDirPath,
$min_timeout, $min_memoryLimit, $min_diskSpaceLimit,
$compileCmd, $execCmd, $sourceFileExtensions, $needCompilation,
$maxLinesToRead, $maxErrLinesToRead, $maxLinesToWrite,
($arg_command === $s_command_justRunTest),
$requestDistinctionString,
$showTestRunnerDebugOutput
);
} catch (Exception $e) {
//critical error, abort execution (all other tests are likely to fail)
output($status_code_InternalServerError, "error executing black box test: " . $e->getMessage());
goto handleCleanup;
}
}
......
......@@ -69,5 +69,14 @@ $config['maxLinesToRead'] = $row['maxLinesToRead'];
$config['maxErrLinesToRead'] = $row['maxErrLinesToRead'];
$config['maxLinesToWrite'] = $row['maxLinesToWrite'];
$config['showTestRunnerDebugOutput'] = $row['showTestRunnerDebugOutput'] === '1';
$config['environmentVars'] = $row['environmentVars'];
//parse environmentVars
if (isset($config['environmentVars'])) {
$keyValuePairs = explode("\n", $config['environmentVars']);
$config['environmentVarsParsed'] = $keyValuePairs;
} else {
$config['environmentVarsParsed'] = NULL;
}
return $config;
\ No newline at end of file
......@@ -3,7 +3,7 @@
# variables
//use this to know which version we published
$versionString = '1.0.0';
$versionString = '1.0.1';
$rootDirNameToUseString = 'work';
$isDebug = false; //logs debug to STDOUT
......
......@@ -120,8 +120,11 @@ function do_blackBoxTest($mainFileNameWithExtension, $test, $fullWorkingDirPath,
$time_pre = microtime(true);
}
$env = $config['environmentVarsParsed'];
# without bypass_shell it won't work on windows
$process = proc_open($longCmd, $pipesDescriptor, $pipes, NULL, NULL, array('bypass_shell' => TRUE));
$process = proc_open($longCmd, $pipesDescriptor, $pipes, $fullWorkingDirPath, $env, array('bypass_shell' => TRUE));
// $state = proc_get_status($process);
// warn('open pid: ' . $state['pid']);
......@@ -150,7 +153,7 @@ function do_blackBoxTest($mainFileNameWithExtension, $test, $fullWorkingDirPath,
}
if ($isDebug && (isset($errorOutput) && trim($errorOutput)!=='')) {
debug("error during execution of the test runner: " . $errorOutput);
debug("error during execution of the (blackbox) test runner: " . $errorOutput);
}
......
......@@ -21,6 +21,7 @@ function do_compile($mainFileNameWithExtension, $fullWorkingDirPath, $compileCmd
)
{
global $isDebug;
global $config;
global $s_output;
global $s_return_val;
......@@ -41,16 +42,18 @@ function do_compile($mainFileNameWithExtension, $fullWorkingDirPath, $compileCmd
. ' "' . ($showTestRunnerDebugOutput === TRUE ? 1 : 0) . '"' # arg[6] showTestRunnerDebugOutput
;
exec($longCmd, $output, $return_var);
/* could also be used...proc_open only works if bypass_shell is true??
$env = $config['environmentVarsParsed'];
// exec($longCmd, $output, $return_var);
/* could also be used...proc_open only works if bypass_shell is true?? */
$descriptorspec = array(
0 => array('pipe', 'r'), # stdin is a pipe that the child will read from
1 => array('pipe', 'w'), # stdout is a pipe that the child will write to
2 => array("pipe", "w")
);
$process = proc_open($longCmd, $descriptorspec, $pipes, NULL, NULL, array('bypass_shell' => TRUE));
$process = proc_open($longCmd, $descriptorspec, $pipes, $fullWorkingDirPath, $env, array('bypass_shell' => TRUE));
if (is_resource($process)) {
......@@ -62,7 +65,10 @@ function do_compile($mainFileNameWithExtension, $fullWorkingDirPath, $compileCmd
$return_var = proc_close($process);
}
*/
if ($isDebug && (isset($errorOutput) && trim($errorOutput)!=='')) {
debug("error during execution of the (compile) test runner: " . $errorOutput);
}
return array(
$s_return_val => $return_var,
......
......@@ -278,6 +278,8 @@ The commands will probably require the users files (code). This files can be acc
- all files need an extension else they are ignored
- if the main file has no extension then code 100 is returned and the program is not compiled/executed
- any `compile` and `exec` commands will be interpret by the test server (the unix user who executes the test server) so when you
e.g. set `compile` to `\"echo\" \"$PATH\"` then `$PATH` will be resolved by the unix user and the test runner gets `/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games...`
#### Example (windows)
internalName (primary key) | compile | exec | hardTimeoutInMs | hardMemoryLimitInKb | hardDiskSpaceLimitInKb | extensions
......@@ -331,12 +333,14 @@ Columns (the same as in the local config except the db specific settings)
* maxLinesToRead
* maxErrLinesToRead
* maxLinesToWrite
* environmentVars
#### Example
id | workingDirFullPath | hardGlobalTimeoutInMs | maxParallelTests | maxNumberOfTestsWithOneRequest |runner | showTestRunnerDebugOutput | maxLinesToRead | maxErrLinesToRead | maxLinesToWrite
--- | --- | --- | --- | --- | --- | --- | --- | ---
1 | /Users/janis/Documents/Test/ | 2000 | 10 | 15 | "/Users/janis/Misc/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java" -Dfile.encoding=UTF8 -cp "/Users/janis/Documents/Projects/SyndromAll/Syndrom_DefaultTestRunnerFullThreaded/out" Main | 0 | 500 | 500 | 500
id | workingDirFullPath | hardGlobalTimeoutInMs | maxParallelTests | maxNumberOfTestsWithOneRequest |runner | showTestRunnerDebugOutput | maxLinesToRead | maxErrLinesToRead | maxLinesToWrite | environmentVars
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
1 | /Users/janis/Documents/Test/ | 2000 | 10 | 15 | "/Users/janis/Misc/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java" -Dfile.encoding=UTF8 -cp "/Users/janis/Documents/Projects/SyndromAll/Syndrom_DefaultTestRunnerFullThreaded/out" Main | 0 | 500 | 500 | 500 | USER=yapextester\nHOME=/home/yapextester\nPWD=\nLANG=de_DE.UTF-8\nPATH=/usr/local/bin:/usr/bin:/bin:/
......@@ -378,8 +382,20 @@ A json object with the following properties (order does not matter)
* **dbConfigName** : (string) -''- but for the config table
* **dbConfigUser** : (string) -''- but for the config table
* **dbConfigPw** : (string) -''- but for the config table
* **dbConfigTableName**: (string) the table name with the configuration (the *dbServer* and *dbName* options are used)
* **dbConfigTableName**: (string) the table name with the configuration (the *dbServer* and *dbName* options are used)
* **environmentVars** : (string, \n separated, key value pairs are separated by = OR NULL) the environment variables for the test runner. All environment vars are cleared and only these are set (even if this is the empty string). The special delimiters `\n` and `=` must not be used inside keys or values.
The test runner is called and these environment variables are set.
You can use `"path""` to escape paths or other strings
It is recommended that you at least specify the following: `PWD, USER, HOME ,PATH`
* `USER` is the executing user e.g. `yapextester`
* `HOME` is the home path for the executing user e.g. `/home/yapextester`
* `PWD` is the current path e.g. `/opt/yapex/TestServer` or empty (string)
* `LANG` the lang to use (e.g. for default formatting) e.g. `de_DE.UTF-8`
* `PATH` are the paths that unix/windows should include when searching for e.g. programs `/usr/local/bin:/usr/bin:/bin:/`
**Note** that this is for linux, windows handles environment variables differently (e.g. other multi value separator than `:`)
The test server splits in `\n` and uses these lines as input for proc_open
* If the value is `NULL` then the environment variables from the php process are used. However, e.g. fast process manager (fpm) for php will discard environment variables by default. So the result might be different than expected.
If the test server cannot connect to the db then an error (db issue) is returned (so the local config is NOT used!)
......@@ -398,7 +414,9 @@ If the config table has more than 1 row, the first row is taken!
"maxParallelTests": 50,
"hardGlobalTimeoutInMs": 2000,
"maxNumberOfTestsWithOneRequest": 20,
"runner": "\"C:\\Program Files (x86)\\JetBrains\\IntelliJ IDEA 14.1.4\\jdk1.8.0_65\\bin\\java\" -cp \"C:\\Users\\theju\\Documents\\WebProjects\\SyndromeAll\\DefaultTestRunner\\out\\production\\DefaultTestRunner\" Main"
"runner": "\"C:\\Program Files (x86)\\JetBrains\\IntelliJ IDEA 14.1.4\\jdk1.8.0_65\\bin\\java\" -cp \"C:\\Users\\theju\\Documents\\WebProjects\\SyndromeAll\\DefaultTestRunner\\out\\production\\DefaultTestRunner\" Main",
"environmentVars": "USER=yapextester\nHOME=/home/yapextester\nPWD=\nLANG=de_DE.UTF-8\nPATH=/usr/local/bin:/usr/bin:/bin:/"
}
```
......
......@@ -19,6 +19,7 @@ $response = array(
"maxLinesToRead" => $config["maxLinesToRead"],
"maxErrLinesToRead" => $config["maxErrLinesToRead"],
"maxLinesToWrite" => $config["maxLinesToWrite"],
"showTestRunnerDebugOutput" => $config["showTestRunnerDebugOutput"],
"dbServer" => $config["dbServer"],
"dbName" => $config["dbName"],
......@@ -26,6 +27,8 @@ $response = array(
"useConfigFromDb" => $config["useConfigFromDb"],
"dbConfigServer" => $config["dbConfigServer"],
"dbConfigName" => $config["dbConfigName"],
"environmentVars" => $config["environmentVars"],
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment