Best Phoronix-test-suite code snippet using pts_openbenchmarking.download_test_profile
pts_openbenchmarking.php
Source:pts_openbenchmarking.php  
...365			$last_cache_times[$repo_name] = time();366		}367		return $index_file;368	}369	public static function download_test_profile($qualified_identifier)370	{371		if(is_file(PTS_TEST_PROFILE_PATH . $qualified_identifier . '/test-definition.xml'))372		{373			return true;374		}375		$file = PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip';376		if(!is_file($file))377		{378			$cache_locations = array('/var/cache/phoronix-test-suite/openbenchmarking.org/');379			foreach($cache_locations as $cache_location)380			{381				// Assuming if file is present that the SHA1 checksum is fine382				// otherwise add: && ($hash_check == null || sha1_file($cache_location . $qualified_identifier . '.zip') == $hash_check)383				if(is_file($cache_location . $qualified_identifier . '.zip'))384				{385					copy($cache_location . $qualified_identifier . '.zip', $file);386					break;387				}388			}389		}390		if(!is_file($file))391		{392			if(pts_network::internet_support_available())393			{394				$hash_json = pts_openbenchmarking::make_openbenchmarking_request('test_hash', array('i' => $qualified_identifier));395				$hash_json = json_decode($hash_json, true);396				$hash_check = isset($hash_json['openbenchmarking']['test']['hash']) ? $hash_json['openbenchmarking']['test']['hash'] : null;  // should also check for ['openbenchmarking']['test']['error'] problems397				$test_profile = pts_openbenchmarking::make_openbenchmarking_request('download_test', array('i' => $qualified_identifier));398				if($test_profile != null && ($hash_check == null || $hash_check == sha1($test_profile)))399				{400					// save it401					file_put_contents($file, $test_profile);402					$hash_check = null;403				}404			}405			if(!is_file($file) && $test_profile = self::phoromatic_server_ob_cache_request('test', substr($qualified_identifier, 0, strpos($qualified_identifier, '/')), substr($qualified_identifier, strpos($qualified_identifier, '/') + 1)))406			{407				if($b64 = base64_decode($test_profile))408				{409					$test_profile = $b64;410				}411				file_put_contents($file, $test_profile);412			}413			if(PTS_IS_CLIENT && !is_file($file))414			{415				trigger_error('Network support is needed to obtain ' . $qualified_identifier . ' data.' . PHP_EOL, E_USER_ERROR);416				return false;417			}418		}419		if(!is_file(PTS_TEST_PROFILE_PATH . $qualified_identifier . '/test-definition.xml') && is_file($file))420		{421			// extract it422			pts_file_io::mkdir(PTS_TEST_PROFILE_PATH . dirname($qualified_identifier));423			pts_file_io::mkdir(PTS_TEST_PROFILE_PATH . $qualified_identifier);424			pts_compression::zip_archive_extract($file, PTS_TEST_PROFILE_PATH . $qualified_identifier);425			if(is_file(PTS_TEST_PROFILE_PATH . $qualified_identifier . '/test-definition.xml'))426			{427				return true;428			}429			else430			{431				unlink($file);432				return false;433			}434		}435		return false;436	}437	public static function phoromatic_server_ob_cache_request($type_request, $repo = null, $test = null)438	{439		if(PTS_IS_CLIENT == false)440		{441			return null;442		}443		$archived_servers = pts_client::available_phoromatic_servers();444		foreach($archived_servers as $archived_server)445		{446			$cache = pts_network::http_get_contents('http://' . $archived_server['ip'] . ':' . $archived_server['http_port'] . '/openbenchmarking-cache.php?' . $type_request . '&repo=' . $repo . '&test=' . $test);447			if(!empty($cache))448			{449				return $cache;450			}451		}452		return null;453	}454	public static function available_tests($download_tests = true, $all_versions = false, $append_versions = false, $show_deprecated_tests = false)455	{456		$available_tests = array();457		foreach(self::linked_repositories() as $repo)458		{459			$repo_index = pts_openbenchmarking::read_repository_index($repo);460			if(isset($repo_index['tests']) && is_array($repo_index['tests']))461			{462				foreach(array_keys($repo_index['tests']) as $identifier)463				{464					if(!$show_deprecated_tests && isset($repo_index['tests'][$identifier]['status']) && $repo_index['tests'][$identifier]['status'] == 'Deprecated')465					{466						continue;467					}468					if($all_versions)469					{470						$versions = $repo_index['tests'][$identifier]['versions'];471						$append_versions = true;472					}473					else474					{475						// Just get the latest version by default476						$versions = array(array_shift($repo_index['tests'][$identifier]['versions']));477					}478					foreach($versions as $version)479					{480						if($download_tests)481						{482							if(self::download_test_profile($repo . '/' . $identifier . '-' . $version) == false)483							{484								continue;485							}486						}487						$available_tests[] = $repo . '/' . $identifier . ($append_versions ? '-' . $version : null);488					}489				}490			}491		}492		$available_tests = array_unique($available_tests);493		return $available_tests;494	}495	public static function available_suites($download_suites = true)496	{497		$available_suites = array();498		foreach(self::linked_repositories() as $repo)499		{500			$repo_index = pts_openbenchmarking::read_repository_index($repo);501			if(isset($repo_index['suites']) && is_array($repo_index['suites']))502			{503				foreach(array_keys($repo_index['suites']) as $identifier)504				{505					if($download_suites && pts_network::internet_support_available())506					{507						$version = array_shift($repo_index['suites'][$identifier]['versions']);508						if(self::download_test_suite($repo . '/' . $identifier . '-' . $version) == false)509						{510							continue;511						}512					}513					$available_suites[] = $repo . '/' . $identifier;514				}515			}516		}517		return $available_suites;518	}519	public static function download_test_suite($qualified_identifier)520	{521		if(is_file(PTS_TEST_SUITE_PATH . $qualified_identifier . '/suite-definition.xml'))522		{523			return true;524		}525		$file = PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip';526		if(pts_network::internet_support_available())527		{528			$hash_json = pts_openbenchmarking::make_openbenchmarking_request('suite_hash', array('i' => $qualified_identifier));529			$hash_json = json_decode($hash_json, true);530			$hash_check = isset($hash_json['openbenchmarking']['suite']['hash']) ? $hash_json['openbenchmarking']['suite']['hash'] : null;  // should also check for ['openbenchmarking']['suite']['error'] problems531		}532		if(!is_file($file))533		{534			if(pts_network::internet_support_available())535			{536				$test_suite = pts_openbenchmarking::make_openbenchmarking_request('download_suite', array('i' => $qualified_identifier));537				if($test_suite != null && ($hash_check == null || $hash_check == sha1($test_suite)))538				{539					// save it540					file_put_contents($file, $test_suite);541					$hash_check = null;542				}543				else if(is_file('/var/cache/phoronix-test-suite/openbenchmarking.org/' . $qualified_identifier . '.zip') && ($hash_check == null || sha1_file('/var/cache/phoronix-test-suite/openbenchmarking.org/' . $qualified_identifier . '.zip') == $hash_check))544				{545					copy('/var/cache/phoronix-test-suite/openbenchmarking.org/' . $qualified_identifier . '.zip', $file);546				}547			}548			if(!is_file($file) && $test_suite = self::phoromatic_server_ob_cache_request('suite', substr($qualified_identifier, 0, strpos($qualified_identifier, '/')), substr($qualified_identifier, strpos($qualified_identifier, '/') + 1)))549			{550				if($b64 = base64_decode($test_suite))551				{552					$test_suite = $b64;553				}554				file_put_contents($file, $test_suite);555			}556			if(PTS_IS_CLIENT && !is_file($file))557			{558				trigger_error('Network support is needed to obtain ' . $qualified_identifier . ' data.' . PHP_EOL, E_USER_ERROR);559				return false;560			}561		}562		if(!is_file(PTS_TEST_SUITE_PATH . $qualified_identifier . '/suite-definition.xml') && is_file($file) && ($hash_check == null || (is_file($file) && sha1_file($file) == $hash_check)))563		{564			// extract it565			pts_file_io::mkdir(PTS_TEST_SUITE_PATH . dirname($qualified_identifier));566			pts_file_io::mkdir(PTS_TEST_SUITE_PATH . $qualified_identifier);567			pts_compression::zip_archive_extract($file, PTS_TEST_SUITE_PATH . $qualified_identifier);568			if(is_file(PTS_TEST_SUITE_PATH . $qualified_identifier . '/suite-definition.xml'))569			{570				return true;571			}572			else573			{574				unlink($file);575				return false;576			}577		}578		return false;579	}580	protected static function check_only_type_compare($check_only_type, $is_type)581	{582		return $check_only_type == false || $check_only_type === $is_type;583	}584	public static function evaluate_string_to_qualifier($supplied, $bind_version = true, $check_only_type = false)585	{586		$qualified = false;587		$c_repo = null;588		$repos = self::linked_repositories();589		if(($c = strpos($supplied, '/')) !== false)590		{591			// A repository was explicitly defined592			$c_repo = substr($supplied, 0, $c);593			$test = substr($supplied, ($c + 1));594			// If it's in the linked repo list it should have refreshed when starting client595			if(!in_array($c_repo, $repos))596			{597				// Pull in this repository's index598				pts_openbenchmarking::refresh_repository_lists($repos);599			}600			$repos = array($c_repo);601		}602		else603		{604			// If it's in the linked repo list it should have refreshed when starting client605			$test = $supplied;606		}607		if(($c = strrpos($test, '-')) !== false)608		{609			$version = substr($test, ($c + 1));610			// TODO: functionalize this and read against types.xsd611			if(isset($version[2]) && !isset($version[8]) && pts_strings::string_only_contains($version, (pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DECIMAL)))612			{613				$test = substr($test, 0, $c);614			}615			else616			{617				$version = null;618			}619		}620		else621		{622			$version = null;623		}624		if($test == null)625			return false;626		foreach($repos as $repo)627		{628			if($repo == 'local')629			{630				if(self::check_only_type_compare($check_only_type, 'test'))631				{632					if(is_file(PTS_TEST_PROFILE_PATH . $repo . '/' . $test . '/test-definition.xml'))633					{634						return $repo . '/' . $test; // ($bind_version ? '-' . $version : null)635					}636					else if(is_file(PTS_TEST_PROFILE_PATH . $repo . '/' . $test . '-' . $version . '/test-definition.xml'))637					{638						return $repo . '/' . $test . '-' . $version; // ($bind_version ? '-' . $version : null)639					}640				}641				if(self::check_only_type_compare($check_only_type, 'suite'))642				{643					if(is_file(PTS_TEST_SUITE_PATH . $repo . '/' . $test . '/suite-definition.xml'))644					{645						return $repo . '/' . $test; // ($bind_version ? '-' . $version : null)646					}647					else if(is_file(PTS_TEST_SUITE_PATH . $repo . '/' . $test . '-' . $version . '/suite-definition.xml'))648					{649						return $repo . '/' . $test . '-' . $version; // ($bind_version ? '-' . $version : null)650					}651				}652			}653			$repo_index = pts_openbenchmarking::read_repository_index($repo);654			if(is_array($repo_index) && isset($repo_index['tests'][$test]) && self::check_only_type_compare($check_only_type, 'test'))655			{656				// The test profile at least exists657				// Looking for a particular test profile version?658				if($version != null)659				{660					if(!in_array($version, $repo_index['tests'][$test]['versions']))661					{662						// Grep to see if the version passed was e.g. 1.3 instead of 1.3.3663						$versions = $repo_index['tests'][$test]['versions'];664						sort($versions);665						foreach(array_reverse($versions) as $check_version)666						{667							if(strstr($check_version, $version) != false)668							{669								$version = $check_version;670								break;671							}672						}673					}674					if(in_array($version, $repo_index['tests'][$test]['versions']))675					{676						pts_openbenchmarking::download_test_profile($repo . '/' . $test . '-' . $version);677						return $repo . '/' . $test . ($bind_version ? '-' . $version : null);678					}679				}680				else681				{682					// Assume to use the latest version unless something else is installed683					$available_versions = $repo_index['tests'][$test]['versions'];684					$version = $available_versions[0]; // the latest version available685					if(PTS_IS_CLIENT && pts_client::current_command() == 'pts_test_run_manager')686					{687						// Check to see if an older version of the test profile is currently installed to ru nthat since no version specified688						foreach($available_versions as $i => $v)689						{690							if(is_file(pts_client::test_install_root_path() . $repo . '/' . $test . '-' . $v . '/pts-install.xml'))691							{692								$version = $v;693								if($i > 0)694								{695									// It's not the latest test profile version available696									trigger_error($repo . '/' . $test . ': The latest test profile version available for upgrade is ' . $available_versions[0] . ' but version ' . $version . ' is the latest currently installed.', E_USER_WARNING);697								}698								break;699							}700						}701					}702					pts_openbenchmarking::download_test_profile($repo . '/' . $test . '-' . $version);703					return $repo . '/' . $test . ($bind_version ? '-' . $version : null);704				}705			}706			if(is_array($repo_index) && isset($repo_index['suites'][$test]) && self::check_only_type_compare($check_only_type, 'suite'))707			{708				// The test profile at least exists709				// Looking for a particular test profile version?710				if($version != null)711				{712					if(!in_array($version, $repo_index['suites'][$test]['versions']))713					{714						// Grep to see if the version passed was e.g. 1.3 instead of 1.3.3715						$versions = $repo_index['suites'][$test]['versions'];716						sort($versions);...make_openbenchmarking_cache.php
Source:make_openbenchmarking_cache.php  
...45			foreach($repo_index['tests'][$test]['versions'] as $version)46			{47				$qualified_identifier = $repo . '/' . $test . '-' . $version;48				echo $qualified_identifier;49				$success = pts_openbenchmarking::download_test_profile($repo . '/' . $test . '-' . $version);50				if($success && is_file(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip'))51				{52					$file_size = round(filesize(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip') / 1024, 2);53					$info = $file_size . 'KB - ' . sha1_file(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip');54					$r_size = $terminal_width - strlen($qualified_identifier) - 3 - strlen($info);55					if($r_size > 0)56					{57						echo ' ' . str_repeat('.', $terminal_width - strlen($qualified_identifier) - 3 - strlen($info)) . ' ' . $info . PHP_EOL;58					}59					$total_cache_count++;60					$total_cache_size += $file_size;61				}62			}63			echo PHP_EOL;...download_test_profile
Using AI Code Generation
1$openbenchmarking = new pts_openbenchmarking();2$openbenchmarking->download_test_profile('pts/test-profiles', 'test-profile-name');3$openbenchmarking = new pts_openbenchmarking();4$openbenchmarking->download_test_profile('pts/test-profiles', 'test-profile-name', 'test-profile-version');5$openbenchmarking = new pts_openbenchmarking();6$openbenchmarking->download_test_profile('pts/test-profiles', 'test-profile-name', 'test-profile-version', 'test-profile-identifier');7$openbenchmarking = new pts_openbenchmarking();8$openbenchmarking->download_test_profile('pts/test-profiles', 'test-profile-name', 'test-profile-version', 'test-profile-identifier', 'test-profile-identifier2');9$openbenchmarking = new pts_openbenchmarking();10$openbenchmarking->download_test_profile('pts/test-profiles', 'test-profile-name', 'test-profile-version', 'test-profile-identifier', 'test-profile-identifier2', 'test-profile-identifier3');11$openbenchmarking = new pts_openbenchmarking();12$openbenchmarking->download_test_profile('pts/test-profiles', 'test-profile-name', 'test-profile-version', 'test-profile-identifier', 'test-profile-identifier2', 'test-profile-identifier3', 'test-profile-identifier4');13$openbenchmarking = new pts_openbenchmarking();14$openbenchmarking->download_test_profile('pts/test-profiles', 'test-profile-name', 'test-profile-version', 'test-profile-identifier', 'test-profile-identifier2', 'test-profile-identifier3', 'test-profile-identifier4', 'test-profile-identifier5');download_test_profile
Using AI Code Generation
1$openbenchmarking = new pts_openbenchmarking();2$openbenchmarking->download_test_profile('pts/test-profiles', 'test-profile-name', '1.0.0');3$openbenchmarking = new pts_openbenchmarking();4$openbenchmarking->download_test_profile('pts/test-profiles', 'test-profile-name');5$openbenchmarking = new pts_openbenchmarking();6$openbenchmarking->download_test_profile('pts/test-profiles', 'test-profile-name', '1.0.0', '/home/username/Downloads');7$openbenchmarking = new pts_openbenchmarking();8$openbenchmarking->download_test_profile('pts/test-profiles', 'test-profile-name', '1.0.0', '/home/username/Downloads', 'test-profile-name-1.0.0.tar.gz');9$openbenchmarking = new pts_openbenchmarking();10$openbenchmarking->download_test_profile('pts/test-profiles', 'test-profile-name', '1.0.0', '/home/username/Downloads', 'test-profile-name-1.0.0.tar.gz', true);11$openbenchmarking = new pts_openbenchmarking();12$openbenchmarking->download_test_profile('pts/test-profiles', 'test-profile-name', '1.0.0', '/home/username/Downloads', 'test-profile-name-1.0.0.tar.gz', true, true);13$openbenchmarking = new pts_openbenchmarking();14$openbenchmarking->download_test_profile('pts/test-profiles', 'test-profile-name', '1.0.0', '/home/username/Downloads', 'test-profile-name-1.0.0.tar.gz', true, true, 'username');download_test_profile
Using AI Code Generation
1include_once('pts_openbenchmarking.php');2$pts_obj = new pts_openbenchmarking();3$pts_obj->download_test_profile('pts/parsec-1.0.1', 'parsec-1.0.1', 'parsec-1.0.1.tar.gz');4download_test_profile($test_profile_identifier, $test_profile_name, $test_profile_save_name)5include_once('pts_openbenchmarking.php');6$pts_obj = new pts_openbenchmarking();7echo $pts_obj->download_test_profile('pts/parsec-1.0.1', 'parsec-1.0.1', 'parsec-1.0.1.tar.gz');8download_test_result($test_result_identifier, $test_result_name, $test_result_save_name)9include_once('pts_openbenchmarking.php');download_test_profile
Using AI Code Generation
1require_once('pts-core/pts-core.php');2$openbenchmarking = new pts_openbenchmarking();3$openbenchmarking->download_test_profile('test-name', 'test-version');4exit;5require_once('pts-core/pts-core.php');6$openbenchmarking = new pts_openbenchmarking();7$openbenchmarking->download_test_profile('test-name', 'test-version', 'test-identifier');8exit;9require_once('pts-core/pts-core.php');10$openbenchmarking = new pts_openbenchmarking();11$openbenchmarking->download_test_profile('test-name', 'test-version', 'test-identifier', 'test-identifier-hash');12exit;13require_once('pts-core/pts-core.php');14$openbenchmarking = new pts_openbenchmarking();15$openbenchmarking->download_test_profile('test-name', 'test-version', 'test-identifier', 'test-identifier-hash', 'test-identifier-hash-type');16exit;17require_once('pts-core/pts-core.php');18$openbenchmarking = new pts_openbenchmarking();19$openbenchmarking->download_test_profile('test-name', 'test-version', 'test-identifier', 'test-identifier-hash', 'test-identifier-hash-type', 'test-identifier-hash-size');20exit;21require_once('pts-core/pts-core.php');22$openbenchmarking = new pts_openbenchmarking();23$openbenchmarking->download_test_profile('test-name', 'test-version', 'test-identifier', 'test-identifier-hash', 'test-identifier-hash-type', 'test-identifier-hash-size', 'test-identifier-hash-time');24exit;25require_once('pts-core/pts-core.php');26$openbenchmarking = new pts_openbenchmarking();27$openbenchmarking->download_test_profile('test-name', 'test-version', 'test-identifierdownload_test_profile
Using AI Code Generation
1$pts_openbenchmarking = new pts_openbenchmarking();2$pts_openbenchmarking->download_test_profile('pts/test-profiles', 'test-profiles', 'test-profiles', 'test-profiles', 'test-profiles');3$pts_openbenchmarking = new pts_openbenchmarking();4$pts_openbenchmarking->download_test_profile('pts/test-profiles', 'test-profiles', 'test-profiles', 'test-profiles', 'test-profiles');5$pts_openbenchmarking = new pts_openbenchmarking();6$pts_openbenchmarking->download_test_profile('pts/test-profiles', 'test-profiles', 'test-profiles', 'test-profiles', 'test-profiles');7$pts_openbenchmarking = new pts_openbenchmarking();8$pts_openbenchmarking->download_test_profile('pts/test-profiles', 'test-profiles', 'test-profiles', 'test-profiles', 'test-profiles');9$pts_openbenchmarking = new pts_openbenchmarking();10$pts_openbenchmarking->download_test_profile('pts/test-profiles', 'test-profiles', 'test-profiles', 'test-profiles', 'test-profiles');11$pts_openbenchmarking = new pts_openbenchmarking();12$pts_openbenchmarking->download_test_profile('pts/test-profiles', 'test-profiles', 'test-profiles', 'test-profiles', 'test-profiles');13$pts_openbenchmarking = new pts_openbenchmarking();14$pts_openbenchmarking->download_test_profile('pts/test-profiles', 'test-profiles', 'test-profiles', 'test-profiles', 'test-profiles');15$pts_openbenchmarking = new pts_openbenchmarking();download_test_profile
Using AI Code Generation
1include('pts-core/pts_openbenchmarking.php');2$pts_ob = new pts_openbenchmarking();3$pts_ob->download_test_profile('pts/test-profiles/test-profiles/pts/test-profiles/test-profiles/test-profile-1.xml');4include('pts-core/pts_openbenchmarking.php');5$pts_ob = new pts_openbenchmarking();6$pts_ob->download_test_profile('pts/test-profiles/test-profiles/pts/test-profiles/test-profiles/test-profile-2.xml');7include('pts-core/pts_openbenchmarking.php');8$pts_ob = new pts_openbenchmarking();9$pts_ob->download_test_profile('pts/test-profiles/test-profiles/pts/test-profiles/test-profiles/test-profile-3.xml');10include('pts-core/download_test_profile
Using AI Code Generation
1require_once('pts_openbenchmarking.php');2pts_openbenchmarking::download_test_profile('pts/test-profiles', 'test-profile');3require_once('pts_openbenchmarking.php');4pts_openbenchmarking::download_test_profiles('pts/test-profiles', array('test-profile1', 'test-profile2', 'test-profile3'));5require_once('pts_openbenchmarking.php');6pts_openbenchmarking::download_test_profile('pts/test-profiles', 'test-profile', '/home/username/');7require_once('pts_openbenchmarking.php');8pts_openbenchmarking::download_test_profiles('pts/test-profiles', array('test-profile1', 'test-profile2', 'test-profile3'), '/home/username/');9require_once('pts_openbenchmarking.php');10pts_openbenchmarking::download_test_profile('pts/test-profiles', 'test-profile', '/home/username/', true);11require_once('pts_openbenchmarking.php');12pts_openbenchmarking::download_test_profiles('pts/test-profiles', array('test-profile1', 'test-profile2', 'test-profile3'), '/home/username/', true);download_test_profile
Using AI Code Generation
1$test_profile = pts_openbenchmarking::download_test_profile("test1");2$test_profile = pts_openbenchmarking::download_test_profile("test2");3$test_profile = pts_openbenchmarking::download_test_profile("test3");4$test_profile = pts_openbenchmarking::download_test_profile("test1");5$test_profile = pts_openbenchmarking::download_test_profile("test2");6$test_profile = pts_openbenchmarking::download_test_profile("test3");7$test_profile = pts_openbenchmarking::download_test_profile("test1");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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with download_test_profile on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!
