diff --git a/api.php b/api.php index 934de5b8bab7fbfe9a931495ae67654082f91052..a8fa6f3d38d397d0821fad7485578366990e8d81 100644 --- a/api.php +++ b/api.php @@ -82,10 +82,24 @@ $arg_allFiles = $body[$s_arg_allFiles]; # check/ensure the iteration dir for the current iteration -$hardGlobalTimeoutInMs = $config[$s_arg_hardGlobalTimeoutInMs]; +$hardGlobalTimeoutInMs = $config[$s_arg_hardTimeoutInMs]; if ($hardGlobalTimeoutInMs === NULL) { - output($status_code_InternalServerError, 'could not read global hard timeout from config'); + output($status_code_InternalServerError, 'could not read global hard timeout in ms from config'); + exit(1); +} + +$hardMemoryLimitInKb = $config[$s_arg_hardMemoryLimitInKb]; + +if ($hardMemoryLimitInKb === NULL) { + output($status_code_InternalServerError, 'could not read global hard memory limit in kb from config'); + exit(1); +} + +$hardDiskSpaceLimitInKb = $config[$s_arg_hardDiskSpaceLimitInKb]; + +if ($hardDiskSpaceLimitInKb === NULL) { + output($status_code_InternalServerError, 'could not read global hard disk space limit in kb from config'); exit(1); } @@ -171,10 +185,6 @@ $sql = "SELECT * FROM `" . $config['dbTableName'] . "`;"; $allRows = executeSqlAndReturnValue($conn, $sql, []); $compileCmd = NULL; $execCmd = NULL; -//get the hard limits -$hardTimeoutInMs = 1000; -$hardMemoryLimitInKb = 1000; -$hardDiskSpaceLimitInKb = 1000; $sourceFileExtensions = []; foreach ($allRows as $row) { @@ -183,9 +193,6 @@ foreach ($allRows as $row) { //ok found p lang commands $compileCmd = $row[$s_compileCommand]; $execCmd = $row[$s_executeCommand]; - $hardTimeoutInMs = $row[$s_hardTimeoutInMs]; - $hardMemoryLimitInKb = $row[$s_hardMemoryLimitInKb]; - $hardDiskSpaceLimitInKb = $row[$s_hardDiskSpaceLimitInKb]; $sourceFileExtensions = json_decode($row[$s_source_file_extensions], TRUE); @@ -460,20 +467,20 @@ foreach ($testCases as $test) { # ensure the hard limits - $min_timeout = $hardTimeoutInMs; + $min_timeout = $hardGlobalTimeoutInMs; + if ($arg_timeout) { - $min_timeout = min($arg_timeout, $hardTimeoutInMs); + $min_timeout = min($arg_timeout, $hardGlobalTimeoutInMs); } - $min_timeout = min($min_timeout, $hardGlobalTimeoutInMs); - - $min_memoryLimit = $hardMemoryLimitInKb; + if ($arg_MemoryLimit) { $min_memoryLimit = min($arg_MemoryLimit, $hardMemoryLimitInKb); } $min_diskSpaceLimit = $hardDiskSpaceLimitInKb; + if ($arg_DiskSpaceLimit) { $min_diskSpaceLimit = min($arg_DiskSpaceLimit, $hardDiskSpaceLimitInKb); } diff --git a/bootstrap.php b/bootstrap.php index 5876a6eedba4bb0d1db3065e47c55147853f37f5..1c45700c05fbc5490784fb1e86ee3ceca5021169 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -59,7 +59,10 @@ if (count($allRows) === 0) { $row = $allRows[0]; $config['workingDirFullPath'] = $row['workingDirFullPath']; -$config['hardGlobalTimeoutInMs'] = $row['hardGlobalTimeoutInMs']; + +$config[$s_arg_hardTimeoutInMs] = $row[$s_arg_hardTimeoutInMs]; +$config[$s_arg_hardMemoryLimitInKb] = $row[$s_arg_hardMemoryLimitInKb]; +$config[$s_arg_hardDiskSpaceLimitInKb] = $row[$s_arg_hardDiskSpaceLimitInKb]; $config['maxParallelTests'] = $row['maxParallelTests']; $config['maxNumberOfTestsWithOneRequest'] = $row['maxNumberOfTestsWithOneRequest']; diff --git a/constants.php b/constants.php index 8fa2af315d42f506466270343e0b5776c597f958..10c589bbe29f638426ab20b67f98317a268bd687 100644 --- a/constants.php +++ b/constants.php @@ -34,7 +34,9 @@ $s_lastRunDate = 'lastRunDate'; $s_lastRunDir = 'lastRunDir'; $s_arg_dbTransactionTableName = 'dbTransactionTableName'; -$s_arg_hardGlobalTimeoutInMs = 'hardGlobalTimeoutInMs'; +$s_arg_hardTimeoutInMs = 'hardTimeoutInMs'; +$s_arg_hardMemoryLimitInKb = 'hardMemoryLimitInKb'; +$s_arg_hardDiskSpaceLimitInKb = 'hardDiskSpaceLimitInKb'; $s_arg_maxParallelTests = 'maxParallelTests'; $timeZone = date_default_timezone_get(); #'Europe/Berlin'; #date_default_timezone_get(); //'Europe/Berlin' diff --git a/helpers.php b/helpers.php index ab48153fdc0e4f1f6ed2a3257d883217986e05a7..2c2ad5dce4a56d358adbcd3bf23aef3933e472ea 100644 --- a/helpers.php +++ b/helpers.php @@ -143,7 +143,7 @@ function checkNextDir($hardGlobalTimeoutInMs) global $s_config_workingDirFullPath; // global $default_changeDirIntervalInS; global $status_code_FileSystemIssue; - global $s_arg_hardGlobalTimeoutInMs ; + global $s_arg_hardTimeoutInMs ; global $status_code_InternalServerError; $jsonContent = file_get_contents($s_timestampFile); diff --git a/readme.md b/readme.md index 5700b0c6c6e038a5216e29546b31936aa3001d1f..6d9aee9f72368789c276197e1d12d4000df478cf 100644 --- a/readme.md +++ b/readme.md @@ -268,7 +268,6 @@ To add a new programming language (plang) you need to add the appropriate comman The plang is then known to the test server and can be used (if you use e.g. syndrom client-server then that server needs to be configured separately to handle/know the new plang). -TODO yapex in system setting unter plangs ergänzen ## database scheme / table /commands The Server needs a table where the commands are stored. @@ -282,16 +281,13 @@ In the dir *backupDb* are some examples that can be imported to a MySql Db. The database needs to contain a table to store this commands (for config see section config.json file, you can specify the table name there but the table needs to exists already). The table needs to have the following scheme -internalName (primary key) | compile | exec | hardTimeoutInMs | hardMemoryLimitInKb | hardDiskSpaceLimitInKb | extensions +internalName (primary key) | compile | exec | extensions --- | --- | --- | --- | --- | --- | --- -(string) | (string) | (string) | (int) | (int) | (int) | (json Array) +(string) | (string) | (string) | (json Array) * **internalName** - the internal name of the programming language (**this is the primary key**) * **compile** - the command (shell/cmd) to execute the compiler (or do a syntax check for most interpreted languages) * **exec** - the command (shell/cmd) to execute the users program (some languages requires virtual machines to execute the intermediate code) -* **hardTimeoutInMs** - the hard timeout in ms (if the request contains a timeoutInMs > hardTimeoutInMs then the hardTimeoutInMs is taken) -* **hardMemoryLimitInKb** - the hard memory limit in kb (if the request contains a memoryLimitInKb > hardMemoryLimitInKb then the hardMemoryLimitInKb is taken) -* **hardMaxDiskSpaceLimitInKb** - the hard max disk space limit in kb (if the request contains a maxDiskSpaceInKb > hardDiskSpaceLimitInKb then the hardDiskSpaceLimitInKb is taken) * **extensions** - the extensions of the source files (used to identify source code files so that asset files can be ignored) (a json array so e.g. `["cpp", "h"]`) The commands will probably require the users files (code). This files can be accessed by special strings (the special strings will be replaces by the value) (all absolute paths includes the file names) @@ -324,18 +320,18 @@ The commands will probably require the users files (code). This files can be acc 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 ---- | --- | --- | --- | --- | --- | --- -csharp | \\"C:\Program Files (x86)\Mono\bin\mcs.bat\\" \\"#5\\" | \\"C:\Program Files (x86)\Mono\bin\mono\\" \\"#4.exe\\" | 1000 | 1000 | 1000 | ["cs"] -java | \\"C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1.4\jdk1.8.0_65\bin\javac\\" \\"-encoding\\" \\"UTF8\\" \\"#5\\" | \\"C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1.4\jdk1.8.0_65\bin\java\\" \\"-cp\\" \\"#1\\" \\"#2\\" | 1000 | 1000 | 1000 | ["java"] -python | \\"python\\" \\"-m\\" \\"py_compile\\" \\"#5\\" | \\"python\\" \\"#5\\" | 1000 | 1000 | 1000 | ["py"] -php | \\"C:\xampp\php3\php.exe\\" \\"-l\\" \\"#5\\" | \\"C:\xampp\php3\php.exe\\" \\"#5\\" | 1000 | 1000 | 1000 | ["php"] +internalName (primary key) | compile | exec | extensions +--- | --- | --- | --- +csharp | \\"C:\Program Files (x86)\Mono\bin\mcs.bat\\" \\"#5\\" | \\"C:\Program Files (x86)\Mono\bin\mono\\" \\"#4.exe\\" | ["cs"] +java | \\"C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1.4\jdk1.8.0_65\bin\javac\\" \\"-encoding\\" \\"UTF8\\" \\"#5\\" | \\"C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1.4\jdk1.8.0_65\bin\java\\" \\"-cp\\" \\"#1\\" \\"#2\\" | ["java"] +python | \\"python\\" \\"-m\\" \\"py_compile\\" \\"#5\\" | \\"python\\" \\"#5\\" | ["py"] +php | \\"C:\xampp\php3\php.exe\\" \\"-l\\" \\"#5\\" | \\"C:\xampp\php3\php.exe\\" \\"#5\\" | ["php"] #### Example (linux) -internalName (primary key) | compile | exec | hardTimeoutInMs | hardMemoryLimitInKb | hardDiskSpaceLimitInKb | extensions ---- | --- | --- | --- | --- | --- | --- -java | \\"javac\\" \\"-encoding\\" \\"UTF8\\" \\"#5\\" | \\"java\\" \\"-Dfile.encoding=UTF8\\" \\"-cp\\" \\"#1\\" \\"#2\\" | 1000 | 1000 | 1000 | ["java"] -python | \\"python\\" \\"-m\\" \\"py_compile\\" \\"#5\\" | \\"python\\" \\"#5\\" | 1000 | 1000 | 1000 | ["py"] +internalName (primary key) | compile | exec | extensions +--- | --- | --- | --- +java | \\"javac\\" \\"-encoding\\" \\"UTF8\\" \\"#5\\" | \\"java\\" \\"-Dfile.encoding=UTF8\\" \\"-cp\\" \\"#1\\" \\"#2\\" | ["java"] +python | \\"python\\" \\"-m\\" \\"py_compile\\" \\"#5\\" | \\"python\\" \\"#5\\" | ["py"] **Reminder** do not forget to escape evey path and arguments! @@ -367,7 +363,9 @@ where '1480443681' ist the seconds-part if microtime() timestamp '0-04701800' is Columns (the same as in the local config except the db specific settings) * id (we should have a primary key) (number) the number does not matter * workingDirFullPath -* hardGlobalTimeoutInMs +* hardTimeoutInMs +* hardMemoryLimitInKb +* hardMaxDiskSpaceLimitInKb * maxParallelTests * maxNumberOfTestsWithOneRequest * runner (in the db the `"` don't need to be escaped) @@ -380,9 +378,9 @@ Columns (the same as in the local config except the db specific settings) #### Example -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:/ +id | workingDirFullPath | hardTimeoutInMs | hardMemoryLimitInKb | hardMaxDiskSpaceLimitInKb | maxParallelTests | maxNumberOfTestsWithOneRequest |runner | showTestRunnerDebugOutput | maxLinesToRead | maxErrLinesToRead | maxLinesToWrite | environmentVars +--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- +1 | /Users/janis/Documents/Test/ | 4000 | 2000 | 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:/ @@ -404,7 +402,10 @@ A json object with the following properties (order does not matter) * **dbTransactionTableName** : (string) the table used for the transaction (to ensure the maxParallelTests) * **workingDirFullPath** : (string) the path to the directory where the user programs will be tested/saved/executed -* **hardGlobalTimeoutInMs** : (int) the global timeout for all programming languages (used to create if we can create a new root directory) +* **hardTimeoutInMs** : (int) the global timeout for all programming languages (used to create if we can create a new root directory) +* **hardMemoryLimitInKb** - the hard memory limit in kb +* **hardMaxDiskSpaceLimitInKb** - the hard max disk space limit in kb + * **maxParallelTests**: (int) the max amount of parallel running tests, if more tests are requested they are rejected with an busy error (use this with the hard limits in the db to calculate the max ressource usage), **set this to 0 or a negative value to no limit the amount of parallel tests** * **maxNumberOfTestsWithOneRequest**: (int) the number of tests that can be run with one request (only the first X tests will be executed ... the other will be ignored), this is used to limit the time a user can occupy the test server @@ -453,7 +454,9 @@ If the config table has more than 1 row, the first row is taken! "dbTableName": "plangs", "dbTransactionTableName": "transactions", "maxParallelTests": 50, - "hardGlobalTimeoutInMs": 2000, + "hardTimeoutInMs": 4000, + "hardMemoryLimitInKb": 2000, + "hardMaxDiskSpaceLimitInKb": 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", diff --git a/runRemote.sh b/runRemote.sh index 96427efd9c856c414e13b7ebf5df617a5c7c48db..68b8888d693bf934dad3846eac8b38e8e94cd45c 100644 --- a/runRemote.sh +++ b/runRemote.sh @@ -1,2 +1,2 @@ # see http://localhost/phpmyadmin -php -S 192.168.30.58:8080 -t ./ \ No newline at end of file +php -S 192.168.30.58:8081 -t ./ \ No newline at end of file diff --git a/stats/private.php b/stats/private.php index 6597bbe6328945e1486217f1cefed88185aaea05..7a0c9e204c17239cba016e32f1be8fc70c9dc03d 100644 --- a/stats/private.php +++ b/stats/private.php @@ -13,7 +13,11 @@ require_once __DIR__.'/../constants.php'; $response = array( "workingDirFullPath" => $config["workingDirFullPath"], - "hardGlobalTimeoutInMs" => $config["hardGlobalTimeoutInMs"], + + "hardTimeoutInMs" => $config[$s_arg_hardTimeoutInMs], + "hardMemoryLimitInKb" => $config[$s_arg_hardMemoryLimitInKb], + "hardDiskSpaceLimitInKb" => $config[$s_arg_hardDiskSpaceLimitInKb], + "maxParallelTests" => $config["maxParallelTests"], "maxNumberOfTestsWithOneRequest" => $config["maxNumberOfTestsWithOneRequest"], //"runner" => $config["runner"], //maybe not needed diff --git a/stats/public.php b/stats/public.php index d7e60b659deebd9b568cfb3ae34d35f656684774..234d00d8507f11bae5ef0884c915de310d3bfaaa 100644 --- a/stats/public.php +++ b/stats/public.php @@ -13,7 +13,10 @@ require_once __DIR__.'/../constants.php'; $response = array( - "hardGlobalTimeoutInMs" => $config["hardGlobalTimeoutInMs"], + "hardTimeoutInMs" => $config[$s_arg_hardTimeoutInMs], + "hardMemoryLimitInKb" => $config[$s_arg_hardMemoryLimitInKb], + "hardDiskSpaceLimitInKb" => $config[$s_arg_hardDiskSpaceLimitInKb], + "maxNumberOfTestsWithOneRequest" => $config["maxNumberOfTestsWithOneRequest"], "maxLinesToRead" => $config["maxLinesToRead"], "maxErrLinesToRead" => $config["maxErrLinesToRead"],