PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/phoronix-test-suite/pts-core/commands/interactive.php

#
PHP | 271 lines | 217 code | 31 blank | 23 comment | 41 complexity | 94405d8b53f8e23f29258370aee064c9 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /*
  3. Phoronix Test Suite
  4. URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
  5. Copyright (C) 2011, Phoronix Media
  6. Copyright (C) 2011, Michael Larabel
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 3 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. class interactive implements pts_option_interface
  19. {
  20. const doc_section = 'System';
  21. const doc_description = 'A simple text-driven interactive interface to the Phoronix Test Suite.';
  22. public static function run($r)
  23. {
  24. $is_moscow = pts_flags::os_identifier_hash() == 'b28d6a7148b34595c5b397dfcf5b12ac7932b3dc';
  25. if($is_moscow)
  26. {
  27. // Auto mount?
  28. $drives = pts_file_io::glob('/dev/sda*');
  29. sort($drives);
  30. if(false && count($drives) > 0 && !is_dir('/media/pts-auto-mount') && is_writable('/media/'))
  31. {
  32. $last_drive = array_pop($drives);
  33. echo PHP_EOL . 'Attempting to auto-mount drive: ' . $last_drive . PHP_EOL;
  34. mkdir('/media/pts-auto-mount');
  35. exec('mount ' . $last_drive . ' /media/pts-auto-mount');
  36. putenv('PTS_TEST_INSTALL_ROOT_PATH=/media/pts-auto-mount/');
  37. }
  38. // Auto save results
  39. $test_results_name = phodevi::read_property('motherboard', 'serial-number');
  40. if($test_results_name == null)
  41. {
  42. $test_results_name = phodevi::read_name('motherboard');
  43. }
  44. if($test_results_name == null)
  45. {
  46. $test_results_name = phodevi::read_property('system', 'vendor-identifier');
  47. }
  48. putenv('TEST_RESULTS_NAME=' . str_replace(' ', null, $test_results_name));
  49. putenv('TEST_RESULTS_IDENTIFIER=' . $test_results_name);
  50. putenv('TEST_RESULTS_DESCRIPTION=Tests using ' . phodevi::read_property('system', 'operating-system') . ' on ' . date('d F Y') . ' of ' . $test_results_name . '.');
  51. self::select_drive_mount();
  52. }
  53. pts_openbenchmarking_client::refresh_repository_lists();
  54. pts_client::$display->generic_heading('Interactive Benchmarking');
  55. echo 'System Hardware:' . PHP_EOL . phodevi::system_hardware(true) . (phodevi::read_property('motherboard', 'serial-number') != null ? PHP_EOL . 'System Serial Number: ' . phodevi::read_property('motherboard', 'serial-number') : null) . PHP_EOL . PHP_EOL . PHP_EOL;
  56. $reboot_on_exit = pts_flags::is_live_cd() && pts_client::user_home_directory() == '/root/';
  57. do
  58. {
  59. $options = array(
  60. 'RUN_TEST' => 'Run A Test',
  61. 'RUN_SUITE' => 'Run A Suite [A Collection Of Tests]',
  62. 'RUN_SYSTEM_TEST' => 'Run Complex System Test',
  63. 'SHOW_INFO' => 'Show System Hardware / Software Information',
  64. 'SHOW_SENSORS' => 'Show Auto-Detected System Sensors',
  65. 'SET_RUN_COUNT' => 'Set Test Run Repetition'
  66. );
  67. if($is_moscow)
  68. {
  69. unset($options['RUN_SUITE']);
  70. // $options['SELECT_DRIVE_MOUNT'] = 'Select Disk Drive To Use For Testing';
  71. }
  72. if(count(pts_client::saved_test_results()) > 0)
  73. {
  74. $options['BACKUP_RESULTS_TO_USB'] = 'Backup Results To Media Storage';
  75. }
  76. $options['EXIT'] = ($reboot_on_exit ? 'Exit & Reboot' : 'Exit');
  77. $response = pts_user_io::prompt_text_menu('Select Task', $options, false, true);
  78. switch($response)
  79. {
  80. case 'RUN_TEST':
  81. $supported_tests = pts_openbenchmarking_client::available_tests();
  82. $supported_tests = pts_types::identifiers_to_test_profile_objects($supported_tests, false, true);
  83. $longest_title_length = 0;
  84. foreach($supported_tests as $i => &$test_profile)
  85. {
  86. if($test_profile->get_title() == null || pts_test_run_manager::test_profile_system_compatibility_check($test_profile) == false)
  87. {
  88. unset($supported_tests[$i]);
  89. continue;
  90. }
  91. if($is_moscow && pts_test_install_request::test_files_available_locally($test_profile) == false)
  92. {
  93. // Don't show tests where files need to be downloaded
  94. unset($supported_tests[$i]);
  95. continue;
  96. }
  97. $longest_title_length = max($longest_title_length, strlen($test_profile->get_title()));
  98. }
  99. $t = array();
  100. foreach($supported_tests as $i => &$test_profile)
  101. {
  102. if($test_profile instanceof pts_test_profile)
  103. {
  104. $t[$test_profile->get_identifier()] = sprintf('%-' . ($longest_title_length + 1) . 'ls - %-10ls', $test_profile->get_title(), $test_profile->get_test_hardware_type());
  105. }
  106. }
  107. $supported_tests = $t;
  108. asort($supported_tests);
  109. $tests_to_run = pts_user_io::prompt_text_menu('Select Test', $supported_tests, true, true);
  110. $tests_to_run = explode(',', $tests_to_run);
  111. pts_test_installer::standard_install($tests_to_run);
  112. $run_manager = pts_test_run_manager::standard_run($tests_to_run, (pts_c::defaults_mode | pts_c::auto_mode));
  113. if($run_manager != false)
  114. {
  115. pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $run_manager->get_file_name() . '/index.html', null, true, true);
  116. }
  117. break;
  118. case 'RUN_SUITE':
  119. $possible_suites = pts_openbenchmarking_client::available_suites();
  120. foreach(array_map('strtolower', pts_types::subsystem_targets()) as $subsystem)
  121. {
  122. array_push($possible_suites, 'pts/' . $subsystem);
  123. }
  124. $suites_to_run = pts_user_io::prompt_text_menu('Select Suite', $possible_suites, true);
  125. foreach(explode(',', $suites_to_run) as $suite_to_run)
  126. {
  127. pts_test_installer::standard_install($suite_to_run);
  128. pts_test_run_manager::standard_run($suite_to_run, (pts_c::defaults_mode | pts_c::auto_mode));
  129. }
  130. break;
  131. case 'SELECT_DRIVE_MOUNT':
  132. self::select_drive_mount();
  133. break;
  134. case 'RUN_SYSTEM_TEST':
  135. pts_client::$display->generic_heading('System Test');
  136. $system_tests = array('apache', 'c-ray', 'ramspeed', 'postmark');
  137. pts_test_installer::standard_install($system_tests);
  138. $run_manager = pts_test_run_manager::standard_run($system_tests, (pts_c::defaults_mode | pts_c::auto_mode));
  139. if($run_manager != false)
  140. {
  141. pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $run_manager->get_file_name() . '/index.html', null, true, true);
  142. }
  143. break;
  144. case 'SHOW_INFO':
  145. pts_client::$display->generic_heading('System Software / Hardware Information');
  146. echo 'Hardware:' . PHP_EOL . phodevi::system_hardware(true) . PHP_EOL . PHP_EOL;
  147. echo 'Software:' . PHP_EOL . phodevi::system_software(true) . PHP_EOL . PHP_EOL;
  148. break;
  149. case 'SHOW_SENSORS':
  150. pts_client::$display->generic_heading('Detected System Sensors');
  151. foreach(phodevi::supported_sensors() as $sensor)
  152. {
  153. echo phodevi::sensor_name($sensor) . ': ' . phodevi::read_sensor($sensor) . ' ' . phodevi::read_sensor_unit($sensor) . PHP_EOL;
  154. }
  155. break;
  156. case 'SET_RUN_COUNT':
  157. $run_count = pts_user_io::prompt_user_input('Set the minimum number of times each test should repeat', false);
  158. putenv('FORCE_TIMES_TO_RUN=' . trim($run_count));
  159. break;
  160. case 'BACKUP_RESULTS_TO_USB':
  161. pts_client::$display->generic_heading('Backing Up Test Results');
  162. if($is_moscow)
  163. {
  164. $drives = pts_file_io::glob('/dev/sd*');
  165. sort($drives);
  166. if(count($drives) > 0 && is_writable('/media/'))
  167. {
  168. $select_drive = pts_user_io::prompt_text_menu('Select Drive / Partition To Save Results', $drives);
  169. echo PHP_EOL . 'Attempting to mount: ' . $select_drive . PHP_EOL;
  170. mkdir('/media/00-results-backup');
  171. exec('mount ' . $select_drive . ' /media/00-results-backup');
  172. }
  173. }
  174. foreach(pts_file_io::glob('/media/*') as $media_dir)
  175. {
  176. if(!is_writable($media_dir))
  177. {
  178. echo PHP_EOL . $media_dir . ' is not writable.' . PHP_EOL;
  179. continue;
  180. }
  181. echo PHP_EOL . 'Writing Test Results To: ' . $media_dir . PHP_EOL;
  182. pts_file_io::copy(PTS_SAVE_RESULTS_PATH, $media_dir . '/');
  183. break;
  184. }
  185. if($is_moscow && is_dir('/media/00-results-backup'))
  186. {
  187. exec('umount /media/00-results-backup');
  188. rmdir('/media/00-results-backup');
  189. }
  190. break;
  191. }
  192. echo PHP_EOL . PHP_EOL;
  193. }
  194. while($response != 'EXIT');
  195. if($reboot_on_exit)
  196. {
  197. if(is_dir('/media/pts-auto-mount'))
  198. {
  199. pts_file_io::delete('/media/pts-auto-mount/pts', null, true);
  200. exec('umount /media/pts-auto-mount 2>&1');
  201. }
  202. exec('reboot');
  203. }
  204. }
  205. private static function select_drive_mount()
  206. {
  207. $drives = pts_file_io::glob('/dev/sd*');
  208. if(count($drives) == 0)
  209. {
  210. echo PHP_EOL . 'No Disk Drives Found' . PHP_EOL . PHP_EOL;
  211. }
  212. else
  213. {
  214. array_push($drives, 'No HDD');
  215. $to_mount = pts_user_io::prompt_text_menu('Select Drive / Partition To Mount', $drives);
  216. if($to_mount != 'No HDD')
  217. {
  218. echo PHP_EOL . 'Attempting to mount: ' . $to_mount . PHP_EOL;
  219. exec('umount /media/pts-auto-mount 2>&1');
  220. pts_file_io::delete('/media/pts-auto-mount', null, true);
  221. pts_file_io::mkdir('/media/pts-auto-mount');
  222. echo exec('mount ' . $to_mount . ' /media/pts-auto-mount');
  223. putenv('PTS_TEST_INSTALL_ROOT_PATH=/media/pts-auto-mount/');
  224. }
  225. else
  226. {
  227. if(is_dir('/media/pts-auto-mount'))
  228. {
  229. exec('umount /media/pts-auto-mount');
  230. @rmdir('/media/pts-auto-mount');
  231. }
  232. putenv('PTS_TEST_INSTALL_ROOT_PATH=');
  233. }
  234. }
  235. }
  236. }
  237. ?>