How to use matisk class

Best Phoronix-test-suite code snippet using matisk

matisk.php

Source:matisk.php Github

copy

Full Screen

...14 GNU General Public License for more details.15 You should have received a copy of the GNU General Public License16 along with this program. If not, see <http://www.gnu.org/licenses/>.17*/18class matisk extends pts_module_interface19{20 const module_name = 'MATISK';21 const module_version = '1.2.0';22 const module_description = 'My Automated Test Infrastructure Setup Kit';23 const module_author = 'Michael Larabel';24 // For values array template [0] = default value [1] = description25 private static $ini_struct = array(26 'workload' =>27 array(28 'save_results' => array(true, 'A boolean value of whether to save the test results.'),29 'suite' => array(null, 'A string that is an XML test suite for the Phoronix Test Suite. If running a custom collection of tests/suites, first run phoronix-test-suite build-suite.'),30 'save_name' => array(null, 'The string to save the test results as.'),31 'description' => array(null, 'The test description string.'),32 'result_identifier' => array(null, 'The test result identifier string, unless using contexts.')33 ),34 'installation' =>35 array(36 'install_check' => array(true, 'Check to see that all tests/suites are installed prior to execution.'),37 'force_install' => array(false, 'Force all tests/suites to be re-installed each time prior to execution.'),38 'external_download_cache' => array(null, 'The option to specify a non-standard PTS External Dependencies download cache directory.'),39 'block_phodevi_caching' => array(false, 'If Phodevi should not be caching any hardware/software information.')40 ),41 'general' =>42 array(43 'upload_to_openbenchmarking' => array(false, 'A boolean value whether to automatically upload the test result to OpenBenchmarking.org'), // Automatic upload to OpenBenchmarking?44 // 'open_browser' => false, // Automatically launch web browser to show the results?45 ),46 'environmental_variables' =>47 array(48 'EXAMPLE_VAR' => array('EXAMPLE', 'The environmental_variables section allows key = value pairs of environmental variables to be set by default.')49 ),50 'set_context' =>51 array(52 'The pre_install or pre_run fields must be used when using the MATISK context testing functionality. The set_context fields must specify an executable file for setting the context of the system. Passed as the first argument to the respective file is the context string defined by the contexts section of this file. If any of the set_context scripts emit an exit code of 8, the testing process will abort immediately. If any of the set_context scripts emit an exit code of 9, the testing process will skip executing the suite on the current context.',53 'pre_install' => array(null, 'An external file to be used for setting the system context prior to test installation.'),54 'pre_run' => array(null, 'An external file to be used for setting the system context prior to test execution.'),55 // 'interim_run' => array(null, 'An external file to be used for setting the system context in between tests in the execution queue.'),56 'post_install' => array(null, 'An external file to be used for setting the system context after the test installation.'),57 'post_run' => array(null, 'An external file to be used for setting the system context after all tests have been executed.'),58 'reboot_support' => array(false, 'If any of the context scripts cause the system to reboot, set this value to true and the Phoronix Test Suite will attempt to automatically recover itself upon reboot.'),59 'context' => array(array(), 'An array of context values.'),60 'external_contexts' => array(null, 'An external file for loading a list of contexts, if not loading the list of contexts via the context array in this file. If the external file is a script it will be executed and the standard output will be used for parsing the contexts.'),61 'external_contexts_delimiter' => array('EOL', 'The delimiter for the external_contexts contexts list. Special keyword: EOL will use a line break as the delimiter and TAB will use a tab as a delimiter.'),62 'reverse_context_order' => array(false, 'A boolean value of whether to reverse the order (from bottom to top) for the execution of a list of contexts.'),63 'log_context_outputs' => array(false, 'A boolean value of whether to log the output of the set-context scripts to ~/.phoronix-test-suite/modules-data/matisk/')64 )65 );66 private static $context = null;67 private static $ini = array();68 private static $matisk_config_dir = null;69 private static $skip_test_set = false;70 public static function module_info()71 {72 return null;73 }74 public static function user_commands()75 {76 return array('run' => 'run_matisk', 'template' => 'template');77 }78 public static function template()79 {80 echo PHP_EOL . '; Sample INI Configuration Template For Phoronix Test Suite MATISK' . PHP_EOL . '; http://www.phoronix-test-suite.com/' . PHP_EOL . PHP_EOL;81 foreach(self::$ini_struct as $section => $items)82 {83 echo PHP_EOL . '[' . $section . ']' . PHP_EOL;84 foreach($items as $key => $r)85 {86 if(!is_array($r))87 {88 echo PHP_EOL . '; ' . wordwrap($r, 80, PHP_EOL . '; ', true) . PHP_EOL . PHP_EOL;89 continue;90 }91 list($default_value, $description) = $r;92 if($description != null)93 {94 echo '; ' . wordwrap($description, 80, PHP_EOL . '; ', true);95 if($default_value !== null && $default_value != array())96 {97 echo ' The default value is ';98 if($default_value === true || $default_value === false)99 {100 echo $default_value === true ? 'TRUE' : 'FALSE';101 }102 else103 {104 echo $default_value;105 }106 echo '.';107 }108 echo PHP_EOL;109 }110 if(is_array($default_value))111 {112 $default_value = isset($default_value[0]) ? $default_value[0] : null;113 echo $key . '[] = ' . $default_value . PHP_EOL;114 echo $key . '[] = ' . $default_value;115 }116 else117 {118 echo $key . ' = ';119 if($default_value === true || $default_value === false)120 {121 echo $default_value === true ? 'TRUE' : 'FALSE';122 }123 else124 {125 echo $default_value;126 }127 }128 echo PHP_EOL . PHP_EOL;129 }130 }131 }132 private static function find_file($file)133 {134 if(is_file($file))135 {136 $file = $file;137 }138 else if(is_file(self::$matisk_config_dir . $file))139 {140 $file = self::$matisk_config_dir . $file;141 }142 else143 {144 $file = false;145 }146 return $file;147 }148 public static function run_matisk($args)149 {150 echo PHP_EOL . 'MATISK For The Phoronix Test Suite' . PHP_EOL;151 if(!isset($args[0]) || !is_file($args[0]))152 {153 echo PHP_EOL . 'You must specify a MATISK INI file to load.' . PHP_EOL . PHP_EOL;154 return false;155 }156 self::$matisk_config_dir = dirname($args[0]) . '/';157 pts_file_io::mkdir(pts_module::save_dir());158 $ini = parse_ini_file($args[0], true);159 foreach(self::$ini_struct as $section => $items)160 {161 foreach($items as $key => $r)162 {163 if(is_array($r) && !isset($ini[$section][$key]))164 {165 $ini[$section][$key] = $r[0];166 }167 }168 }169 // Checks170 if(pts_test_suite::is_suite($ini['workload']['suite']) == false)171 {172 // See if the XML suite-definition was just tossed into the same directory173 if(($xml_file = self::find_file($ini['workload']['suite'] . '.xml')) !== false)174 {175 pts_file_io::mkdir(PTS_TEST_SUITE_PATH . 'local/' . $ini['workload']['suite']);176 copy($xml_file, PTS_TEST_SUITE_PATH . 'local/' . $ini['workload']['suite'] . '/suite-definition.xml');177 }178 if(pts_test_suite::is_suite($ini['workload']['suite']) == false)179 {180 echo PHP_EOL . 'A test suite must be specified to execute. If a suite needs to be constructed, run: ' . PHP_EOL . 'phoronix-test-suite build-suite' . PHP_EOL . PHP_EOL;181 return false;182 }183 }184 if($ini['set_context']['external_contexts'] != null)185 {186 switch($ini['set_context']['external_contexts_delimiter'])187 {188 case 'EOL':189 case '':190 $ini['set_context']['external_contexts_delimiter'] = PHP_EOL;191 break;192 case 'TAB':193 $ini['set_context']['external_contexts_delimiter'] = "\t";194 break;195 }196 if(($ff = self::find_file($ini['set_context']['external_contexts'])))197 {198 if(is_executable($ff))199 {200 $ini['set_context']['context'] = shell_exec($ff . ' 2> /dev/null');201 }202 else203 {204 $ini['set_context']['context'] = file_get_contents($ff);205 }206 }207 else208 {209 // Hopefully it's a command to execute then...210 $ini['set_context']['context'] = shell_exec($ini['set_context']['external_contexts'] . ' 2> /dev/null');211 }212 $ini['set_context']['context'] = explode($ini['set_context']['external_contexts_delimiter'], $ini['set_context']['context']);213 }214 else if($ini['set_context']['context'] != null && !is_array($ini['set_context']['context']))215 {216 $ini['set_context']['context'] = array($ini['set_context']['context']);217 }218 if(is_array($ini['set_context']['context']) && count($ini['set_context']['context']) > 0)219 {220 foreach($ini['set_context']['context'] as $i => $context)221 {222 if($context == null)223 {224 unset($ini['set_context']['context'][$i]);225 }226 }227 // Context testing228 if(count($ini['set_context']['context']) > 0 && $ini['set_context']['pre_run'] == null && $ini['set_context']['pre_install'] == null)229 {230 echo PHP_EOL . 'The pre_run or pre_install set_context fields must be set in order to set the system\'s context.' . PHP_EOL;231 return false;232 }233 if($ini['set_context']['reverse_context_order'])234 {235 $ini['set_context']['context'] = array_reverse($ini['set_context']['context']);236 }237 }238 if(pts_strings::string_bool($ini['workload']['save_results']))239 {240 if($ini['workload']['save_name'] == null)241 {242 echo PHP_EOL . 'The save_name field cannot be left empty when saving the test results.' . PHP_EOL;243 return false;244 }245 /*246 if($ini['workload']['result_identifier'] == null)247 {248 echo PHP_EOL . 'The result_identifier field cannot be left empty when saving the test results.' . PHP_EOL;249 return false;250 }251 */252 }253 if(!empty($ini['environmental_variables']) && is_array($ini['environmental_variables']))254 {255 foreach($ini['environmental_variables'] as $key => $value)256 {257 putenv(trim($key) . '=' . trim($value));258 }259 }260 if(empty($ini['set_context']['context']))261 {262 $ini['set_context']['context'] = array($ini['workload']['result_identifier']);263 }264 if(pts_strings::string_bool($ini['set_context']['log_context_outputs']))265 {266 pts_file_io::mkdir(pts_module::save_dir() . $ini['workload']['save_name']);267 }268 $spent_context_file = pts_module::save_dir() . $ini['workload']['save_name'] . '.spent-contexts';269 if(!is_file($spent_context_file))270 {271 touch($spent_context_file);272 }273 else274 {275 // If recovering from an existing run, don't rerun contexts that were already executed276 $spent_contexts = pts_file_io::file_get_contents($spent_context_file);277 $spent_contexts = explode(PHP_EOL, $spent_contexts);278 foreach($spent_contexts as $sc)279 {280 if(($key = array_search($sc, $ini['set_context']['context'])) !== false)281 {282 unset($ini['set_context']['context'][$key]);283 }284 }285 }286 if($ini['set_context']['reboot_support'] && phodevi::is_linux())287 {288 // In case a set-context involves a reboot, auto-recover289 $xdg_config_home = is_dir('/etc/xdg/autostart') && is_writable('/etc/xdg/autostart') ? '/etc/xdg/autostart' : pts_client::read_env('XDG_CONFIG_HOME');290 if($xdg_config_home == false)291 {292 $xdg_config_home = pts_client::user_home_directory() . '.config';293 }294 if($xdg_config_home != false && is_dir($xdg_config_home))295 {296 $autostart_dir = $xdg_config_home . '/autostart/';297 pts_file_io::mkdir($xdg_config_home . '/autostart/');298 }299 file_put_contents($xdg_config_home . '/autostart/phoronix-test-suite-matisk.desktop', '300[Desktop Entry]301Name=Phoronix Test Suite Matisk Recovery302GenericName=Phoronix Test Suite303Comment=Matisk Auto-Recovery Support304Exec=gnome-terminal -e \'phoronix-test-suite matisk ' . $args[0] . '\'305Icon=phoronix-test-suite306Type=Application307Encoding=UTF-8308Categories=System;Monitor;');309 }310 if($ini['installation']['block_phodevi_caching'])311 {312 // Block Phodevi caching if changing out system components and there is a chance one of the strings of changed contexts might be cached (e.g. OpenGL user-space driver)313 phodevi::$allow_phodevi_caching = false;314 }315 if(phodevi::system_uptime() < 60)316 {317 echo PHP_EOL . 'Sleeping 45 seconds while waiting for the system to settle...' . PHP_EOL;318 sleep(45);319 }320 self::$ini = $ini;321 $total_context_count = count(self::$ini['set_context']['context']);322 while(($context = array_shift(self::$ini['set_context']['context'])) !== null)323 {324 echo PHP_EOL . ($total_context_count - count(self::$ini['set_context']['context'])) . ' of ' . $total_context_count . ' in test execution queue [' . $context . ']' . PHP_EOL . PHP_EOL;325 self::$context = $context;326 if(pts_strings::string_bool(self::$ini['installation']['install_check']) || $ini['set_context']['pre_install'] != null)327 {328 self::process_user_config_external_hook_process('pre_install');329 $force_install = false;330 $no_prompts = true;331 if(pts_strings::string_bool(self::$ini['installation']['force_install']))332 {333 $force_install = true;334 }335 if(self::$ini['installation']['external_download_cache'] != null)336 {337 pts_test_install_manager::add_external_download_cache(self::$ini['installation']['external_download_cache']);338 }339 // Do the actual test installation340 pts_test_installer::standard_install(self::$ini['workload']['suite'], $force_install, $no_prompts);341 self::process_user_config_external_hook_process('post_install');342 }343 $batch_mode = false;344 $auto_mode = true;345 $test_run_manager = new pts_test_run_manager($batch_mode, $auto_mode);346 if($test_run_manager->initial_checks(self::$ini['workload']['suite']) == false)347 {348 return false;349 }350 if(self::$skip_test_set == false)351 {352 self::process_user_config_external_hook_process('pre_run');353 // Load the tests to run354 if($test_run_manager->load_tests_to_run(self::$ini['workload']['suite']) == false)355 {356 return false;357 }358 // Save results?359 $result_identifier = $ini['workload']['result_identifier'];360 if($result_identifier == null)361 {362 $result_identifier = '$MATISK_CONTEXT';363 }364 // Allow $MATIISK_CONTEXT as a valid user variable to pass it...365 $result_identifier = str_replace('$MATISK_CONTEXT', self::$context, $result_identifier);366 $test_run_manager->set_save_name(self::$ini['workload']['save_name']);367 $test_run_manager->set_results_identifier($result_identifier);368 $test_run_manager->set_description(self::$ini['workload']['description']);369 // Don't upload results unless it's the last in queue where the context count is now 0370 $test_run_manager->auto_upload_to_openbenchmarking((count(self::$ini['set_context']['context']) == 0 && self::$ini['general']['upload_to_openbenchmarking']));371 // Run the actual tests372 $test_run_manager->pre_execution_process();373 $test_run_manager->call_test_runs();374 $test_run_manager->post_execution_process();375 }376 self::$skip_test_set = false;377 file_put_contents($spent_context_file, self::$context . PHP_EOL, FILE_APPEND);378 pts_file_io::unlink(pts_module::save_dir() . self::$context . '.last-call');379 self::process_user_config_external_hook_process('post_run');380 }381 unlink($spent_context_file);382 isset($xdg_config_home) && pts_file_io::unlink($xdg_config_home . '/autostart/phoronix-test-suite-matisk.desktop');383 }384 protected static function process_user_config_external_hook_process($process)385 {386 // Check to not run the same process387 $last_call_file = pts_module::save_dir() . self::$context . '.last-call';388 if(is_file($last_call_file))389 {390 $check = pts_file_io::file_get_contents($last_call_file);391 if($process == $check)392 {393 unlink($last_call_file);394 return false;395 }396 }...

Full Screen

Full Screen

matisk

Using AI Code Generation

copy

Full Screen

1$pts = new PhoronixTestSuite();2$pts->init();3$matisk = new MATISK($pts);4$matisk->init();5$matisk->run();6$matisk->save();7$matisk->clean();8$pts = new PhoronixTestSuite();9$pts->init();10$matisk = new MATISK($pts);11$matisk->init();12$matisk->run();13$matisk->save();14$matisk->clean();15$pts = new PhoronixTestSuite();16$pts->init();17$matisk = new MATISK($pts);18$matisk->init();19$matisk->run();20$matisk->save();21$matisk->clean();22$pts = new PhoronixTestSuite();23$pts->init();24$matisk = new MATISK($pts);25$matisk->init();26$matisk->run();27$matisk->save();28$matisk->clean();29$pts = new PhoronixTestSuite();30$pts->init();31$matisk = new MATISK($pts);32$matisk->init();33$matisk->run();34$matisk->save();35$matisk->clean();36$pts = new PhoronixTestSuite();37$pts->init();38$matisk = new MATISK($pts);39$matisk->init();40$matisk->run();41$matisk->save();42$matisk->clean();43$pts = new PhoronixTestSuite();44$pts->init();45$matisk = new MATISK($pts);46$matisk->init();47$matisk->run();48$matisk->save();49$matisk->clean();

Full Screen

Full Screen

matisk

Using AI Code Generation

copy

Full Screen

1$matisk = new matisk();2$matisk->test();3{4public function test()5{6echo "test";7}8}9$matisk = new matisk();10$matisk->test();11Your name to display (optional):12Your name to display (optional):13include('matisk.php');14$matisk = new matisk();15$matisk->test();16Your name to display (optional):17$matisk = new matisk();18$matisk->test();19Your name to display (optional):

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.

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

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