Something went wrong on our end
-
Janis Daniel Dähne authoredJanis Daniel Dähne authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
constants.php 9.99 KiB
<?php
# variables
//use this to know which version we published
$versionString = '2.7.0';
$rootDirNameToUseString = 'work';
$isDebug = false; //logs debug to STDOUT
$debugOutputAllReturnOutput = false; //if true && $isDebug every response is also written to STDOUT
$s_testServerCode = 'testServerCode'; # the test server code for one test
$s_testServerMessage = 'testServerMessage'; # the test server message for one test
#result array variables (string indices) the status code of a the result is $status_code_TestRan (if the test has run)
$s_passed = 'passed'; # true = test was successful, false: not
# if the test needed compilation then true: compilation was successful, false: not
# if no compilation was needed then this should always be true
$s_hasCompiled = 'hasCompiled';
$s_programExitCode = 'programExitCode'; # currently not set!!
$s_testResultCode = 'testResultCode'; # the exit code of the runner
$s_protocol = 'protocol'; # the conversation protocol (what happened e.g. input, output ...)
#ensure dirs variables
#only the index string not the actual value
$s_tempDirName = 'tempDirName';
$s_fullWorkingDirPath = 'fullWorkingDirPath';
# the timestamp contains a date that indicates when a new iteration (and a new dir) was used to run the tests
# one iteration lasts for changeDirIntervalInS seconds (set in teh config file) after this time the root dir is deleted
# and all further tests are now ran/run? in the new dir
$s_timestampFile = 'timestemp.json';
$s_lastRunDate = 'lastRunDate';
$s_lastRunDir = 'lastRunDir';
$s_arg_dbTraceTableName = 'dbTraceTableName';
$s_arg_hardTimeoutInMs = 'hardTimeoutInMs';
$s_arg_hardCompileTimeoutInMs = 'hardCompileTimeoutInMs';
$s_arg_hardMemoryLimitInKb = 'hardMemoryLimitInKb';
$s_arg_hardDiskSpaceLimitInKb = 'hardDiskSpaceLimitInKb';
$s_arg_insertTraceLogs = 'insertTraceLogs'; //true/false
$s_output_test_server_version = 'testServerVersion';
$timeZone = date_default_timezone_get(); #'Europe/Berlin'; #date_default_timezone_get(); //'Europe/Berlin'
# regex variables
$regexModeBlacklist = 'blacklist';
$regexModeWhitelist = 'whitelist';
$availableRegexModes = [$regexModeBlacklist, $regexModeWhitelist];
$s_regexMode = 'mode';
$s_regexConnector = 'connector';
$regexAndConnector = '&&'; # connects the regex for on test content
$regexOrConnector = '||'; # connects the regex for on test content
$regexAndInlineConnector = '&&'; # connects the regex expressions for one file
$regexOrInlineConnector = '||'; # connects the regex expressions for one file
$availableRegexConnectors = [$regexAndConnector, $regexOrConnector];
$regexNegatePrefix = '!';
$regexMathAllFilesAttribute = '*';
$responseNewLineString = '\r\n'; //to match interface
$runnerNewLineString = "\\r\\n"; //starting with runner version 2.4
$runnerDebugLogNewLineString = "\\n";
# known error codes
$status_code_Ok = 0;
$status_code_MaxParallelTestsReached = 1; # not used anymore!
$status_code_ArgumentInvalidOrMissing = 2;
$status_code_DbIssue = 3;
$status_code_FileSystemIssue = 4;
$status_code_NoUniqueRequestIdStringProvided = 5; //null or empty
$status_code_InternalServerError = 100;
$s_output = 'output'; # the output from a test method
$s_return_val = 'return_val'; # the return value from a test method (the runner exit code)
$default_not_executed_user_program_exit_code = 0;
#vars for the file array array[$index] -> tuple[$s_fileName] -> fileName, tuple[$s_fileContent] -> fileContent
$s_fileName = 'fileName';
$s_fileContent = 'fileContent';
$s_fileHash = "hash";
#config vars
$jsonConfigFile = 'config.json';
$s_config_workingDirFullPath = 'workingDirFullPath';
#end config vars
#the number of tests that can be run with one request (only the first X tests will be executed ... the other will be ignored)
$s_arg_maxNumberOfTestsWithOneRequest = 'maxNumberOfTestsWithOneRequest';
# the supported test types
$s_command_compile = 'compileTest';
$s_command_blackBoxTest = 'blackBoxTest';
$s_command_compareFilesTest = 'compareFilesTest';
$s_command_regexTest = 'regexTest';
$s_command_justRunTest = 'justRunTest';
$s_supportedCommands = [$s_command_compile, $s_command_blackBoxTest, $s_command_compareFilesTest, $s_command_regexTest, $s_command_justRunTest];
# db table columns
$s_plang_internalName = 'internalName';
$s_compileCommand = 'compile';
$s_executeCommand = 'exec';
$s_hardTimeoutInMs = 'hardTimeoutInMs';
$s_hardMemoryLimitInKb = 'hardMemoryLimitInKb';
$s_hardDiskSpaceLimitInKb = 'hardDiskSpaceLimitInKb';
$s_source_file_extensions = 'extensions';
# the attributes for the json body
$s_arg_pLang = 'pLang'; # the programming language
$s_arg_mainFileNameWithExtension = 'mainFileNameWithExtension'; # the main file name
#NO USED $s_arg_dirName = 'dirName'; # the dir name to use
$s_arg_allFiles = 'allFiles'; # all files to use
$s_arg_characterLimitProtocol = 'characterLimitProtocol'; # the character limit for the test result protocol
# a number to help the this server to separate two requests in case they arrive at the same time (and micro time would return the same value)
$s_requestDistinctionNumber = 'requestDistinctionString';
$s_requestTraceString = 'traceString';
# end variables
$s_requestDeleteTraceLogOlderThanMinutes = 'deleteTraceLogOlderThanMinutes';
# TEST OBJECT field names
$s_test_id = 'testId';
$s_test_content = 'testContent';
$s_test_command = 'command'; # the command to execute see $s_supportedCommands
$s_test_testContents = 'testContents';
$s_test_timeoutInMs = 'timeoutInMs'; # the timeout for the test
$s_test_compileTimeoutInMs = 'compileTimeoutInMs'; # the compile timeout for the test
$s_test_memoryLimitInKb = 'memoryLimitInKb'; # the memory limit for the test
$s_test_diskSpaceLimitInKb = 'maxDiskSpaceInKb'; # the max dis space the test can write to
$s_test_allAssets = 'allAssets'; # the asset files
$s_test_CompilerOptions = 'compilerOptions'; # the compiler options for the test (only for black, compile and compare files test)
$exitCodeOutputPrefix = 'exit:';
$s_user_program_exit_code = 'exit';
$s_runnerVersion = 'runnerVersion';
$s_timeoutInMsUsed = 'timeoutInMsUsed';
$s_compileTimeoutInMsUsed = 'compileTimeoutInMsUsed';
$s_timeForCompiling = 'timeForCompiling';
$s_timeForUserProgram = 'timeForUserProgram';
$s_output_without_header_part = 'stripedOutput';
$s_characterLimitExceeded = 'characterLimitExceeded';
$s_characterLimitUsed = 'characterLimitUsed';
$s_headerKeyCharacterRunnerDebugLog = 'runnerDebugLog';
$s_header_part_separator = "---\\r\\n";
$s_timings_string_separator = "\n";
/**
* outputs a message via echo (if debug is enabled outputs the message to stdout)
* @param $responseCode int the response code to send
* @param $message string the message
* @param $data object the response object to send (can be null)
*/
function output($responseCode, $message, $data = null)
{
global $isDebug;
global $debugOutputAllReturnOutput;
global $s_timings_string_separator;
global $debugTimings;
if ($isDebug && $debugOutputAllReturnOutput) {
fwrite(STDOUT, $message);
}
$responseObj = array(
'responseCode' => $responseCode,
'message' => $message,
'data' => $data,
'debugTimings' => empty($debugTimings) ? NULL : implode($s_timings_string_separator, $debugTimings)
);
$responseString = json_encode($responseObj);
echo $responseString;
}
/**
* outputs a message only if in debug mode
* @param $message string the message
*/
function debug($message)
{
global $isDebug;
if ($isDebug) {
$fe = fopen('php://stdout', 'w');
fwrite($fe, $message . "\n");
fclose($fe);
//fwrite(STDERR, $message);
}
}
/**
* outputs a warning to stdout prefixed with WARNING
* @param $message
*/
function warn($message)
{
$fe = fopen('php://stdout', 'w');
fwrite($fe, "WARNING: " . $message . "\n");
fclose($fe);
//fwrite(STDERR, $message);
}
/**
* creates a test result object
* @param $testServerCode
* @param $testServerMessage
* @param $testId
* @param $passed
* @param $hasCompiled
* @param $programExitCode
* @param $timeForCompiling
* @param $timeForUserProgram
* @param $runnerVersion
* @param $testResultCode
* @param $protocol
* @param $compileTimeoutInMsUsed
* @param $timeoutInMsUsed
* @param $characterLimitExceeded
* @param $characterLimitUsed
* @return array
*/
function create_test_result($testServerCode, $testServerMessage, $testId,
$passed, $hasCompiled, $programExitCode,
$timeForCompiling, $timeForUserProgram, $runnerVersion,
$testResultCode, $protocol,
$compileTimeoutInMsUsed, $timeoutInMsUsed,
$characterLimitExceeded, $characterLimitUsed
)
{
global $s_testServerCode;
global $s_testServerMessage;
global $s_test_id;
global $s_passed;
global $s_hasCompiled;
global $s_programExitCode;
global $s_runnerVersion;
global $s_timeForCompiling;
global $s_timeForUserProgram;
global $s_testResultCode;
global $s_protocol;
global $s_output_test_server_version;
global $s_timeoutInMsUsed;
global $s_compileTimeoutInMsUsed;
global $versionString;
global $s_characterLimitExceeded;
global $s_characterLimitUsed;
return array(
$s_testServerCode => $testServerCode,
$s_testServerMessage => $testServerMessage,
$s_test_id => $testId,
$s_passed => $passed,
$s_hasCompiled => $hasCompiled, // all other errors returned before this line
$s_programExitCode => $programExitCode,
$s_runnerVersion => $runnerVersion,
$s_timeForCompiling => $timeForCompiling,
$s_timeForUserProgram => $timeForUserProgram,
$s_testResultCode => $testResultCode, # this is the result from the test runner program
$s_protocol => $protocol, # the conversation protocol
$s_output_test_server_version => $versionString,
$s_compileTimeoutInMsUsed => $compileTimeoutInMsUsed,
$s_timeoutInMsUsed => $timeoutInMsUsed,
$s_characterLimitExceeded => $characterLimitExceeded,
$s_characterLimitUsed => $characterLimitUsed,
);
}