How to use mergeResults method of check_tests class

Best Phoronix-test-suite code snippet using check_tests.mergeResults

check_tests.php

Source:check_tests.php Github

copy

Full Screen

...95 while ($processed < count($available_tests)) {96 // If we have more then $procs running, wait for one to free up before proceeding.97 if ($noOfForks >= $procs) {98 $pid = pcntl_waitpid(0, $status);99 self::mergeResults($pid);100 $noOfForks--;101 }102 // TODO: try to getting a test profile that is currently being worked on. This will prevent potentially103 // downloading the file twice as each process takes a different version of the test profile with the same104 // download. ie create 3 groups, namely done, doing, toDo 105 $currentTest = $available_tests[$processed];106 $pid = pcntl_fork();107 if ($pid === -1) {108 die('Unable to fork.');109 } else if ($pid) {110 // Parent Code111 echo pts_client::cli_colored_text("Testing " . $currentTest . PHP_EOL, 'grey', true);112 $noOfForks++;113 } else {114 // Child Code115 $results = self::processTestFile($currentTest);116 if ($results)117 self::logStatus($results, getmypid());118 exit(0);119 }120 $processed++;121 }122 // Wait for the children to catch up (also prevent command prompt from appearing early)123 while (($pid = pcntl_waitpid(0, $status)) != -1) {124 $status = pcntl_wexitstatus($status);125 self::mergeResults($pid);126 }127 // Clean any temp json files that might remain128 $deleteFiles = self::$JSON_FILE . '.*';129 array_map('unlink', glob($deleteFiles));130 // Count and report on number of downloads131 $noOfDownloads = count(scandir(self::$DOWNLOADED_VENDOR_FILES)) - 2; // remove ./ and ../ from the array count132 // PROD: delete all files... In DEV: comment out to prevent files from downloading with each test run.133 if (file_exists(self::$TESTED_FILES))134 unlink(self::$TESTED_FILES);135 if (is_dir(self::$DOWNLOADED_VENDOR_FILES)) {136 $deleteFiles = self::$DOWNLOADED_VENDOR_FILES . '*';137 array_map('unlink', glob($deleteFiles));138 rmdir(self::$DOWNLOADED_VENDOR_FILES);139 }140 echo PHP_EOL . pts_client::cli_colored_text("Total Tests Performed: " . $processed . PHP_EOL, 'white', true);141 echo pts_client::cli_colored_text("Total Downloads in Cache: " . $noOfDownloads . PHP_EOL, 'white', true);142 echo PHP_EOL . pts_client::cli_colored_text("Test Completed in " . self::timeToString(microtime(true) - $startTime) . "." . PHP_EOL . "Results reported in " . self::$JSON_FILE . PHP_EOL . PHP_EOL, 'green', true);143 }144 /**145 * Given a time in secs, converts time into hours mins secs.146 * 147 * @return string "hours mins secs"148 */149 public static function timeToString($time)150 {151 $hours = floor($time / 3600);152 $time -= $hours * 3600;153 $mins = floor($time / 60);154 $secs = $time - $mins * 60;155 if ($secs < 0)156 $secs = round($secs, 2);157 else158 $secs = floor($secs);159 if ($hours == 0 && $mins == 0)160 return "${secs}s";161 else if ($hours == 0)162 return "${mins}m ${secs}s";163 else164 return "${hours}h ${mins}m ${secs}s";165 }166 /**167 * Extracts the download.xml file for a given Test Profile and returns the results of the168 * checks.169 * In the case that a download.xml file does not exist, the test-profile will not be tested 170 * and the status will be 'Not Tested'171 * 172 * @param $identifier array List of test profiles as string. ie pts/sunflow-1.1.3173 * @return array Test results. See @return in performChecksOnTestProfile174 */175 public static function processTestFile($identifier)176 {177 // Determine if the identifer has is valid before proceeding.178 $testProfileObjects = pts_types::identifiers_to_test_profile_objects($identifier, true, true);179 if (count($testProfileObjects) == 0) {180 echo PHP_EOL . pts_client::cli_colored_text($identifier . " could not be found." . PHP_EOL, 'cyan', true);181 return;182 }183 $packages = array();184 foreach ($testProfileObjects as $testProfile) {185 // need to massage into a format for frontend use.186 $xmlFile = $testProfile->get_downloads();187 if ($xmlFile == null)188 $packages[0] =189 array(190 "identifier" => $identifier, // repeated for front end191 "mirror" => array(192 "status" => 'Not Tested',193 "failures" => "downloads.xml file not found"194 )195 );196 foreach ($xmlFile as $checks) {197 $packages[count($packages)] = self::performChecksOnTestProfile($checks, $identifier);198 }199 }200 return $packages;201 }202 /**203 * 204 * Performs a check on the filename, filesize, sha256 and md5 to ensure the parameters205 * align with the Service Provider.206 *207 * @param $data array Test Results208 * 209 * @return array [210 * 'identifer' => test-profile' // ie pts/aobench-1.0.0211 * 'status' => Passed|Failed // If all tests passed returns Passed, otherwise Failed212 * 'pts-filename' => Name of file // Indicative of which mirror was tested ie aircrack-1.5.2.tar.gz or aircrack-1.5.2-win.zip213 * 'pts-filesize => Size of downloaded file214 * 'pts-sha256 => sha256 checksum215 * 'pts-md5 => md5 checksum216 * 'download-time' => Time to download file (microsecs)217 * 'duplicate' => indicate that the test-profile reused a download from another version that had already been downloaded218 * 'redirect' => The original url in that case of a HTTP Status 302 219 * 220 * // The following will only be populated if the test failed:221 * 'failures' => array [ 222 * <test that failed> => <details on the test(s) that failed> 223 * ]224 * ]225 */226 public static function performChecksOnTestProfile($data, $identifier)227 {228 $filename = $data->get_filename();229 // Extract the following data from the local environment.230 $url = $data->get_download_url_array();231 $filesize = $data->get_filesize();232 $sha256 = $data->get_sha256();233 $md5 = $data->get_md5();234 // Record the local pts values extracted from the download.xml file235 $profileResults = array(236 "identifier" => $identifier,237 "pts-filename" => $filename,238 "pts-filesize" => $filesize,239 "pts-sha256" => $sha256,240 "pts-md5" => $md5,241 );242 $results = array(243 "status" => null244 );245 // Set up a structure that will handle any number of mirrors246 $mirrorCount = 0;247 $mirrorResults = array();248 foreach ($url as $mirror) {249 // Filename is derived from the $URL so no comparison is necessary250 $remote_filename = basename($mirror);251 // Check to see if the URL has already been tested and grab the download.252 $vendorData = self::downloadVendorData($mirror, $remote_filename, $identifier);253 if ($vendorData[self::V_DUPLICATE])254 $results[self::V_DUPLICATE] = $vendorData[self::V_IDENTIFIER] . " copied from " . $vendorData[self::V_URL];255 $results["url"] = $mirror;256 if (array_key_exists(self::V_REDIRECT, $vendorData) && $vendorData[self::V_REDIRECT] != "0")257 $results[self::V_REDIRECT] = $vendorData[self::V_REDIRECT];258 // Initiate where all the Discrepancies reside259 $results['failures'] = array();260 // Determine validity of url. If url d.n.e then all other tests are irrelevant261 if ($vendorData['status'] != '200') {262 $results["failures"]['vendor'] = "HTTP Code: " . $vendorData['status'];263 $results['status'] = "Failed";264 } else {265 // Record the results downloaded from the vendor266 $results["download-time"] = $vendorData[self::V_DOWNLOAD_TIME];267 // Local filesize should be the same as the downloaded bytes. In older versions268 // of test-profiles, the filesize may not be set. This does not constitute a failure.269 $filesize_status = ($filesize > 0) && ($filesize == $vendorData[self::V_DOWNLOAD_SIZE]);270 if (!$filesize_status) {271 $results["failures"]["filesize"] = $vendorData[self::V_DOWNLOAD_SIZE];272 }273 // In some cases the checksum d.n.e and does not constitue a failure, test it only274 // if it exists.275 $sha256_status = true;276 if (!is_null($sha256)) {277 $remote_sha256 = hash_file('sha256', $vendorData[self::V_DOWNLOAD_FILE]);278 $sha256_status = ($sha256 == $remote_sha256);279 if (!$sha256_status) {280 $results["failures"]["sha256"] = $remote_sha256;281 }282 }283 $md5_status = true;284 if (!is_null($md5)) {285 $remote_md5 = md5_file($vendorData[self::V_DOWNLOAD_FILE]);286 $md5_status = ($md5 == $remote_md5);287 if (!$md5_status) {288 $results["failures"]["md5"] = $remote_md5;289 }290 }291 // Return status of all tests292 if ($filesize_status && $sha256_status && $md5_status) {293 $results['status'] = "Passed";294 unset($results["failures"]);295 } else {296 $results['status'] = "Failed";297 }298 }299 // if there are mirrors then save the result for each mirror300 $mirrorResults[$mirrorCount] = $results;301 $mirrorCount++;302 }303 $profileResults["mirror"] = $mirrorResults;304 return $profileResults;305 }306 /**307 * Logs the status of the test to a temp file. 308 * A file is created for each child process. The results are stored as JSON.309 * 310 * @param $results Array Results for each test profile.311 * @param $id integer Suffix $id to file containing the results. ie resultFile.json.id312 * 313 */314 public static function logStatus($results, $id)315 {316 $writeFile = self::$JSON_FILE . '.' . $id;317 if ($results)318 if (!file_put_contents($writeFile, json_encode($results), FILE_APPEND)) {319 echo PHP_EOL . pts_client::cli_colored_text("Failed to write " . $results['test-profile'] . " to file" . $writeFile . PHP_EOL . PHP_EOL, 'red', true);320 }321 }322 /**323 * Merges the results in each temp file into one json file.324 * The temp files are deleted.325 * 326 * @param $id integer The suffix for the temp files created in the method 'logStatus'327 */328 public static function mergeResults($id)329 {330 if (!file_exists(self::$JSON_FILE . '.' . $id)) {331 //echo PHP_EOL . "File " . self::$JSON_FILE . '.' . $id . " could not be merged. Does not exist." . PHP_EOL . PHP_EOL;332 return;333 }334 $mergedArray = json_decode(file_get_contents(self::$JSON_FILE), true);335 if (!$mergedArray)336 $mergedArray = array();337 $dataArray = json_decode(file_get_contents(self::$JSON_FILE . '.' . $id), true);338 $mergedArray[count($mergedArray)] = array(339 "profile-name" => $dataArray[0]['identifier'],340 "packages" => $dataArray341 );342 if (!file_put_contents(self::$JSON_FILE, json_encode($mergedArray))) {...

Full Screen

Full Screen

mergeResults

Using AI Code Generation

copy

Full Screen

1require_once('check_tests.php');2$obj = new check_tests();3$obj->mergeResults();4require_once('check_tests.php');5$obj = new check_tests();6$obj->mergeResults();7require_once('check_tests.php');8$obj = new check_tests();9$obj->mergeResults();10require_once('check_tests.php');11$obj = new check_tests();12$obj->mergeResults();13require_once('check_tests.php');14$obj = new check_tests();15$obj->mergeResults();16require_once('check_tests.php');17$obj = new check_tests();18$obj->mergeResults();19require_once('check_tests.php');20$obj = new check_tests();21$obj->mergeResults();22require_once('check_tests.php');23$obj = new check_tests();24$obj->mergeResults();25require_once('check_tests.php');26$obj = new check_tests();27$obj->mergeResults();28require_once('check_tests.php');29$obj = new check_tests();30$obj->mergeResults();31require_once('check_tests.php');32$obj = new check_tests();33$obj->mergeResults();34require_once('check_tests.php');35$obj = new check_tests();36$obj->mergeResults();37require_once('check_tests.php');38$obj = new check_tests();39$obj->mergeResults();40require_once('check_tests.php');41$obj = new check_tests();

Full Screen

Full Screen

mergeResults

Using AI Code Generation

copy

Full Screen

1require_once 'check_tests.php';2$ct = new check_tests();3$ct->mergeResults();4require_once 'check_tests.php';5$ct = new check_tests();6$ct->mergeResults();7require_once 'check_tests.php';8$ct = new check_tests();9$ct->mergeResults();10require_once 'check_tests.php';11$ct = new check_tests();12$ct->mergeResults();13require_once 'check_tests.php';14$ct = new check_tests();15$ct->mergeResults();16require_once 'check_tests.php';17$ct = new check_tests();18$ct->mergeResults();19require_once 'check_tests.php';20$ct = new check_tests();21$ct->mergeResults();22require_once 'check_tests.php';23$ct = new check_tests();24$ct->mergeResults();25require_once 'check_tests.php';26$ct = new check_tests();27$ct->mergeResults();28require_once 'check_tests.php';29$ct = new check_tests();30$ct->mergeResults();31require_once 'check_tests.php';32$ct = new check_tests();33$ct->mergeResults();34require_once 'check_tests.php';35$ct = new check_tests();36$ct->mergeResults();37require_once 'check_tests.php';38$ct = new check_tests();39$ct->mergeResults();

Full Screen

Full Screen

mergeResults

Using AI Code Generation

copy

Full Screen

1$test = new check_tests();2$test->mergeResults('results.txt', 'results2.txt');3$test->printResults();4$test = new check_tests();5$test->mergeResults('results.txt', 'results3.txt');6$test->printResults();7$test = new check_tests();8$test->mergeResults('results.txt', 'results4.txt');9$test->printResults();10$test = new check_tests();11$test->mergeResults('results.txt', 'results5.txt');12$test->printResults();13$test = new check_tests();14$test->mergeResults('results.txt', 'results6.txt');15$test->printResults();16$test = new check_tests();17$test->mergeResults('results.txt', 'results7.txt');18$test->printResults();19$test = new check_tests();20$test->mergeResults('results.txt', 'results8.txt');21$test->printResults();22$test = new check_tests();23$test->mergeResults('results.txt', 'results9.txt');24$test->printResults();25$test = new check_tests();26$test->mergeResults('results.txt', 'results10.txt');27$test->printResults();28$test = new check_tests();29$test->mergeResults('results.txt', 'results11.txt');30$test->printResults();31$test = new check_tests();32$test->mergeResults('results.txt', 'results12.txt');33$test->printResults();

Full Screen

Full Screen

mergeResults

Using AI Code Generation

copy

Full Screen

1require_once('check_tests.class.php');2$check_tests = new check_tests();3$check_tests->mergeResults();4require_once('check_tests.class.php');5$check_tests = new check_tests();6$check_tests->getResults();7require_once('check_tests.class.php');8$check_tests = new check_tests();9$check_tests->getResults();10require_once('check_tests.class.php');11$check_tests = new check_tests();12$check_tests->getResults();13require_once('check_tests.class.php');14$check_tests = new check_tests();15$check_tests->getResults();16require_once('check_tests.class.php');17$check_tests = new check_tests();

Full Screen

Full Screen

mergeResults

Using AI Code Generation

copy

Full Screen

1require_once('check_tests.php');2$test1 = new check_tests();3$test1->set_test_id('test1');4$test1->set_test_result('pass');5$test2 = new check_tests();6$test2->set_test_id('test2');7$test2->set_test_result('fail');8$test1->mergeResults($test2);9echo "Test 1 result: ".$test1->get_test_result()."10";11echo "Test 2 result: ".$test2->get_test_result()."12";13require_once('check_tests.php');14$test1 = new check_tests();15$test1->set_test_id('test1');16$test1->set_test_result('pass');17$test2 = new check_tests();18$test2->set_test_id('test2');19$test2->set_test_result('fail');20$test1->mergeResults($test2, false);21echo "Test 1 result: ".$test1->get_test_result()."22";23echo "Test 2 result: ".$test2->get_test_result()."24";

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Phoronix-test-suite automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger mergeResults code on LambdaTest Cloud Grid

Execute automation tests with mergeResults on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful