public static function run($r)
 {
     $result_file = false;
     if (count($r) != 0) {
         $result_file = $r[0];
     }
     $suite_name = pts_user_io::prompt_user_input('Enter name of suite');
     $suite_test_type = pts_user_io::prompt_text_menu('Select test type', pts_types::subsystem_targets());
     $suite_maintainer = pts_user_io::prompt_user_input('Enter suite maintainer name');
     $suite_description = pts_user_io::prompt_user_input('Enter suite description');
     $suite_writer = new pts_test_suite_writer();
     $suite_writer->add_suite_information($suite_name, '1.0.0', $suite_maintainer, $suite_test_type, $suite_description);
     // Read results file
     $result_file = new pts_result_file($result_file);
     foreach ($result_file->get_result_objects() as $result_object) {
         $suite_writer->add_to_suite_from_result_object($result_object);
     }
     // Finish it off
     $suite_identifier = pts_test_run_manager::clean_save_name($suite_name);
     mkdir(PTS_TEST_SUITE_PATH . 'local/' . $suite_identifier);
     $save_to = PTS_TEST_SUITE_PATH . 'local/' . $suite_identifier . '/suite-definition.xml';
     if ($suite_writer->save_xml($save_to) != false) {
         echo PHP_EOL . PHP_EOL . 'Saved To: ' . $save_to . PHP_EOL . 'To run this suite, type: phoronix-test-suite benchmark ' . $suite_identifier . PHP_EOL . PHP_EOL;
     }
 }
 public static function run($r)
 {
     pts_client::$display->generic_heading('Test Suite Creation');
     $suite_name = pts_user_io::prompt_user_input('Enter name of suite');
     $suite_test_type = pts_user_io::prompt_text_menu('Select test type', pts_types::subsystem_targets());
     $suite_maintainer = pts_user_io::prompt_user_input('Enter suite maintainer name');
     $suite_description = pts_user_io::prompt_user_input('Enter suite description');
     $possible_suites = pts_openbenchmarking::available_suites();
     $possible_tests = pts_openbenchmarking::available_tests();
     $suite_writer = new pts_test_suite_writer();
     $suite_writer->add_suite_information($suite_name, '1.0.0', $suite_maintainer, $suite_test_type, $suite_description);
     foreach ($r as $test_object) {
         $test_object = pts_types::identifier_to_object($test_object);
         if ($test_object instanceof pts_test_profile) {
             list($args, $description) = pts_test_run_options::prompt_user_options($test_object);
             for ($i = 0; $i < count($args); $i++) {
                 // Not binding the test profile version to this suite, otherwise change false to true
                 $suite_writer->add_to_suite($test_object->get_identifier(false), $args[$i], $description[$i]);
             }
         } else {
             if ($test_object instanceof pts_test_suite) {
                 $suite_writer->add_to_suite($test_object->get_identifier(), null, null);
             }
         }
     }
     $input_option = null;
     do {
         switch ($input_option) {
             case 'Add Test':
                 $test_to_add = pts_user_io::prompt_text_menu('Enter test name', $possible_tests);
                 $test_profile = new pts_test_profile($test_to_add);
                 list($args, $description) = pts_test_run_options::prompt_user_options($test_profile);
                 for ($i = 0; $i < count($args); $i++) {
                     $suite_writer->add_to_suite($test_to_add, $args[$i], $description[$i]);
                 }
                 break;
             case 'Add Sub-Suite':
                 $suite_to_add = pts_user_io::prompt_text_menu('Enter test suite', $possible_suites);
                 $suite_writer->add_to_suite($suite_to_add, null, null);
                 break;
         }
         echo PHP_EOL . 'Available Options:' . PHP_EOL;
         $input_option = pts_user_io::prompt_text_menu('Select next operation', array('Add Test', 'Add Sub-Suite', 'Save & Exit'));
     } while ($input_option != 'Save & Exit');
     $suite_identifier = $suite_writer->clean_save_name_string($suite_name);
     $save_to = PTS_TEST_SUITE_PATH . 'local/' . $suite_identifier . '/suite-definition.xml';
     mkdir(dirname($save_to));
     if ($suite_writer->save_xml($save_to) != false) {
         echo PHP_EOL . PHP_EOL . 'Saved To: ' . $save_to . PHP_EOL . 'To run this suite, type: phoronix-test-suite benchmark ' . $suite_identifier . PHP_EOL . PHP_EOL;
     }
 }
function phoromatic_pre_seed_tests_to_install(&$json, $phoromatic_account_settings, &$sys_row)
{
    $suite_writer = new pts_test_suite_writer();
    $suite_writer->add_suite_information('Pre-Seed', '1.0.0', 'Phoromatic', 'System', 'An automated Phoromatic test schedule.');
    $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_schedules_tests WHERE AccountID = :account_id');
    $stmt->bindValue(':account_id', ACCOUNT_ID);
    $result = $stmt->execute();
    $test_count = 0;
    while ($row = $result->fetchArray()) {
        $suite_writer->add_to_suite($row['TestProfile'], null, null);
        $test_count++;
    }
    if ($test_count == 0) {
        return false;
    }
    $json['phoromatic']['task'] = 'install';
    $json['phoromatic']['test_suite'] = $suite_writer->get_xml();
    $json['phoromatic']['settings'] = $phoromatic_account_settings;
    $json['phoromatic']['pre_set_sys_env_vars'] = $sys_row['SystemVariables'];
    echo json_encode($json);
    return true;
}
    public static function render_page_process($PATH)
    {
        if (isset($_POST['suite_title'])) {
            //	echo '<pre>';
            //	var_dump($_POST);
            //	echo '</pre>';
            if (strlen($_POST['suite_title']) < 3) {
                echo '<h2>Suite title must be at least three characters.</h2>';
            }
            //echo 'TEST SUITE: ' . $_POST['suite_title'] . '<br />';
            //echo 'TEST SUITE: ' . $_POST['suite_description'] . '<br />';
            $tests = array();
            foreach ($_POST['test_add'] as $i => $test_identifier) {
                $test_prefix = $_POST['test_prefix'][$i];
                $args = array();
                $args_name = array();
                foreach ($_POST as $i => $v) {
                    if (strpos($i, $test_prefix) !== false && substr($i, -9) != '_selected') {
                        if (strpos($v, '||') !== false) {
                            $opts = explode('||', $v);
                            $a = array();
                            $d = array();
                            foreach ($opts as $opt) {
                                $t = explode('::', $opt);
                                array_push($a, $t[1]);
                                array_push($d, $t[0]);
                            }
                            array_push($args, $a);
                            array_push($args_name, $d);
                        } else {
                            array_push($args, array($v));
                            array_push($args_name, array($_POST[$i . '_selected']));
                        }
                    }
                }
                $test_args = array();
                $test_args_description = array();
                pts_test_run_options::compute_all_combinations($test_args, null, $args, 0);
                pts_test_run_options::compute_all_combinations($test_args_description, null, $args_name, 0, ' - ');
                foreach (array_keys($test_args) as $i) {
                    array_push($tests, array('test' => $test_identifier, 'description' => $test_args_description[$i], 'args' => $test_args[$i]));
                }
            }
            if (count($tests) < 1) {
                echo '<h2>You must add at least one test to the suite.</h2>';
            }
            $suite_writer = new pts_test_suite_writer();
            $version_bump = 0;
            do {
                $suite_version = '1.' . $version_bump . '.0';
                $suite_id = $suite_writer->clean_save_name_string($_POST['suite_title']) . '-' . $suite_version;
                $suite_dir = phoromatic_server::phoromatic_account_suite_path($_SESSION['AccountID'], $suite_id);
                $version_bump++;
            } while (is_dir($suite_dir));
            pts_file_io::mkdir($suite_dir);
            $save_to = $suite_dir . '/suite-definition.xml';
            $suite_writer->add_suite_information($_POST['suite_title'], $suite_version, $_SESSION['UserName'], 'System', $_POST['suite_description']);
            foreach ($tests as $m) {
                $suite_writer->add_to_suite($m['test'], $m['args'], $m['description']);
            }
            $suite_writer->save_xml($save_to);
            echo '<h2>Saved As ' . $suite_id . '</h2>';
        }
        echo phoromatic_webui_header_logged_in();
        $main = '<h1>Local Suites</h1><p>Find already created local test suites by your account/group via the <a href="/?local_suites">local suites</a> page.</p>';
        if (!PHOROMATIC_USER_IS_VIEWER) {
            $main .= '<h1>Build Suite</h1><p>A test suite in the realm of the Phoronix Test Suite, OpenBenchmarking.org, and Phoromatic is <strong>a collection of test profiles with predefined settings</strong>. Establishing a test suite makes it easy to run repetitive testing on the same set of test profiles by simply referencing the test suite name.</p>';
            $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="build_suite" id="build_suite" method="post" onsubmit="return validate_suite();">
			<h3>Title:</h3>
			<p><input type="text" name="suite_title" /></p>
			<h3>Description:</h3>
			<p><textarea name="suite_description" id="suite_description" cols="60" rows="2"></textarea></p>
			<h3>Tests In Schedule:</h3>
			<p><div id="test_details"></div></p>
			<h3>Add Another Test</h3>';
            $main .= '<select name="add_to_suite_select_test" id="add_to_suite_select_test" onchange="phoromatic_build_suite_test_details();">';
            $dc = pts_strings::add_trailing_slash(pts_client::parse_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)));
            $dc_exists = is_file($dc . 'pts-download-cache.json');
            foreach (pts_openbenchmarking::available_tests(false, true) as $test) {
                $cache_checked = false;
                if ($dc_exists) {
                    $cache_json = file_get_contents($dc . 'pts-download-cache.json');
                    $cache_json = json_decode($cache_json, true);
                    if ($cache_json && isset($cache_json['phoronix-test-suite']['cached-tests'])) {
                        $cache_checked = true;
                        if (!in_array($test, $cache_json['phoronix-test-suite']['cached-tests'])) {
                            continue;
                        }
                    }
                }
                if (!$cache_checked && phoromatic_server::read_setting('show_local_tests_only') && pts_test_install_request::test_files_in_cache($test, true, true) == false) {
                    continue;
                }
                $main .= '<option value="' . $test . '">' . $test . '</option>';
            }
            $main .= '</select>';
            $main .= '<p align="right"><input name="submit" value="Create Suite" type="submit" onclick="return pts_rmm_validate_suite();" /></p>';
        }
        echo '<div id="pts_phoromatic_main_area">' . $main . '</div>';
        echo phoromatic_webui_footer();
    }