public function generate_download_object_list($do_file_checks = true) { $download_xml_file = $this->test_profile->get_file_download_spec(); if ($download_xml_file != null) { $xml_parser = new pts_test_downloads_nye_XmlReader($download_xml_file); $package_url = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/URL'); $package_md5 = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/MD5'); $package_sha256 = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/SHA256'); $package_filename = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/FileName'); $package_filesize = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/FileSize'); $package_platform = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/PlatformSpecific'); $package_architecture = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/ArchitectureSpecific'); foreach (array_keys($package_url) as $i) { if (!empty($package_platform[$i]) && $do_file_checks) { $platforms = pts_strings::comma_explode($package_platform[$i]); if (!in_array(phodevi::operating_system(), $platforms) && !(phodevi::is_bsd() && in_array('Linux', $platforms) && (pts_client::executable_in_path('kldstat') && strpos(shell_exec('kldstat -n linux 2>&1'), 'linux.ko') != false))) { // This download does not match the operating system continue; } } if (!empty($package_architecture[$i]) && $do_file_checks) { $architectures = pts_strings::comma_explode($package_architecture[$i]); if (phodevi::cpu_arch_compatible($architectures) == false) { // This download does not match the CPU architecture continue; } } $this->test_files[] = new pts_test_file_download($package_url[$i], $package_filename[$i], $package_filesize[$i], $package_md5[$i], $package_sha256[$i], $package_platform[$i], $package_architecture[$i]); } } }
public static function validate_test_profile(&$test_profile) { if ($test_profile->get_file_location() == null) { echo PHP_EOL . 'ERROR: The file location of the XML test profile source could not be determined.' . PHP_EOL; return false; } // Validate the XML against the XSD Schemas libxml_clear_errors(); // Now re-create the pts_test_profile object around the rewritten XML $test_profile = new pts_test_profile($test_profile->get_identifier()); $valid = $test_profile->validate(); if ($valid == false) { echo PHP_EOL . 'Errors occurred parsing the main XML.' . PHP_EOL; pts_validation::process_libxml_errors(); return false; } // Rewrite the main XML file to ensure it is properly formatted, elements are ordered according to the schema, etc... $test_profile_writer = new pts_test_profile_writer(); $test_profile_writer->rebuild_test_profile($test_profile); $test_profile_writer->save_xml($test_profile->get_file_location()); // Now re-create the pts_test_profile object around the rewritten XML $test_profile = new pts_test_profile($test_profile->get_identifier()); $valid = $test_profile->validate(); if ($valid == false) { echo PHP_EOL . 'Errors occurred parsing the main XML.' . PHP_EOL; pts_validation::process_libxml_errors(); return false; } else { echo PHP_EOL . 'Test Profile XML Is Valid.' . PHP_EOL; } // Validate the downloads file $download_xml_file = $test_profile->get_file_download_spec(); if (empty($download_xml_file) == false) { $writer = new pts_test_profile_downloads_writer(); $writer->rebuild_download_file($test_profile); $writer->save_xml($download_xml_file); $downloads_parser = new pts_test_downloads_nye_XmlReader($download_xml_file); $valid = $downloads_parser->validate(); if ($valid == false) { echo PHP_EOL . 'Errors occurred parsing the downloads XML.' . PHP_EOL; pts_validation::process_libxml_errors(); return false; } else { echo PHP_EOL . 'Test Downloads XML Is Valid.' . PHP_EOL; } // Validate the individual download files echo PHP_EOL . 'Testing File Download URLs.' . PHP_EOL; $files_missing = 0; $file_count = 0; foreach (pts_test_install_request::read_download_object_list($test_profile) as $download) { foreach ($download->get_download_url_array() as $url) { $stream_context = pts_network::stream_context_create(); stream_context_set_params($stream_context, array('notification' => 'pts_stream_status_callback')); $file_pointer = fopen($url, 'r', false, $stream_context); if ($file_pointer == false) { echo 'File Missing: ' . $download->get_filename() . ' / ' . $url . PHP_EOL; $files_missing++; } else { fclose($file_pointer); } $file_count++; } } if ($files_missing > 0) { return false; } } // Validate the parser file $parser_file = $test_profile->get_file_parser_spec(); if (empty($parser_file) == false) { $writer = self::rebuild_result_parser_file($parser_file); $writer->saveXMLFile($parser_file); $parser = new pts_parse_results_nye_XmlReader($parser_file); $valid = $parser->validate(); if ($valid == false) { echo PHP_EOL . 'Errors occurred parsing the results parser XML.' . PHP_EOL; pts_validation::process_libxml_errors(); return false; } else { echo PHP_EOL . 'Test Results Parser XML Is Valid.' . PHP_EOL; } } // Make sure no extra files are in there $allowed_files = pts_validation::test_profile_permitted_files(); foreach (pts_file_io::glob($test_profile->get_resource_dir() . '*') as $tp_file) { if (!is_file($tp_file) || !in_array(basename($tp_file), $allowed_files)) { echo PHP_EOL . basename($tp_file) . ' is not allowed in the test package.' . PHP_EOL; return false; } } return true; }