def test_metadata(branch, build_flags, arch_32): """Instantiate a Fetcher (which downloads metadata from TaskCluster) and check that the build is recent""" # BuildFlags(asan, debug, fuzzing, coverage) # Fetcher(target, branch, build, flags, arch_32) with requests_mock.Mocker() as req_mock: req_mock.register_uri(requests_mock.ANY, requests_mock.ANY, content=callback) for as_args in (True, False): # try as API and as command line if as_args: args = [ "--" + name for arg, name in zip( build_flags, fuzzfetch.BuildFlags._fields) if arg ] if arch_32: args.append("--32") fetcher = fuzzfetch.Fetcher.from_args(["--" + branch] + args)[0] else: if branch == "esr": branch = "esr52" fetcher = fuzzfetch.Fetcher("firefox", branch, "latest", build_flags, arch_32) log.debug("succeeded creating Fetcher") log.debug("buildid: %s", fetcher.build_id) log.debug("hgrev: %s", fetcher.changeset) # check that build is not too old # if branch.startswith("esr"): # max_age = (3 * 24 + 1) * 60 * 60 # 3d # elif branch == "release": # max_age = (7 * 24 + 1) * 60 * 60 # 1w # else: # max_age = (24 + 1) * 60 * 60 # 1d time_obj = time.strptime(fetcher.build_id, "%Y%m%d%H%M%S") # timestamp = calendar.timegm(time_obj) # assert timestamp > time.time() - max_age, \ # "%s is more than %s old" % (fetcher.build_id, format_elapsed(max_age)) # yyyy-mm-dd is also accepted as a build input date_str = "%d-%02d-%02d" % (time_obj.tm_year, time_obj.tm_mon, time_obj.tm_mday) if as_args: fuzzfetch.Fetcher.from_args( ["--" + branch, "--build", date_str] + args) else: fuzzfetch.Fetcher("firefox", branch, date_str, build_flags) # hg rev is also accepted as a build input rev = fetcher.changeset if as_args: fuzzfetch.Fetcher.from_args(["--" + branch, "--build", rev] + args) else: fuzzfetch.Fetcher("firefox", branch, rev, build_flags)
def test_metadata(branch, build_flags, os_, cpu): """Instantiate a Fetcher (which downloads metadata from TaskCluster) and check that the build is recent. """ # BuildFlags(asan, debug, fuzzing, coverage, valgrind) # Fetcher(target, branch, build, flags, arch_32) # Set freeze_time to a date ahead of the latest mock build platform_ = fuzzfetch.fetch.Platform(os_, cpu) for as_args in (True, False): # try as API and as command line if as_args: args = [ "--" + name for arg, name in zip(build_flags, fuzzfetch.BuildFlags._fields) if arg ] fetcher = fuzzfetch.Fetcher.from_args( ["--" + branch, "--cpu", cpu, "--os", os_] + args)[0] else: if branch.startswith("esr"): branch = fuzzfetch.Fetcher.resolve_esr(branch) fetcher = fuzzfetch.Fetcher("firefox", branch, "latest", build_flags, platform_) LOG.debug("succeeded creating Fetcher") LOG.debug("buildid: %s", fetcher.id) LOG.debug("hgrev: %s", fetcher.changeset) time_obj = time.strptime(fetcher.id, "%Y%m%d%H%M%S") # yyyy-mm-dd is also accepted as a build input date_str = "%d-%02d-%02d" % ( time_obj.tm_year, time_obj.tm_mon, time_obj.tm_mday, ) if as_args: fuzzfetch.Fetcher.from_args([ "--" + branch, "--cpu", cpu, "--os", os_, "--build", date_str ] + args) else: fuzzfetch.Fetcher("firefox", branch, date_str, build_flags, platform_) # hg rev is also accepted as a build input rev = fetcher.changeset if as_args: fuzzfetch.Fetcher.from_args( ["--" + branch, "--cpu", cpu, "--os", os_, "--build", rev] + args) else: fuzzfetch.Fetcher("firefox", branch, rev, build_flags, platform_)
def test_metadata(branch, build_flags, os_, cpu): """Instantiate a Fetcher (which downloads metadata from TaskCluster) and check that the build is recent""" # BuildFlags(asan, debug, fuzzing, coverage, valgrind) # Fetcher(target, branch, build, flags, arch_32) with requests_mock.Mocker() as req_mock: req_mock.register_uri(requests_mock.ANY, requests_mock.ANY, content=callback) platform_ = fuzzfetch.fetch.Platform(os_, cpu) for as_args in (True, False): # try as API and as command line if as_args: args = [ "--" + name for arg, name in zip( build_flags, fuzzfetch.BuildFlags._fields) if arg ] fetcher = fuzzfetch.Fetcher.from_args( ["--" + branch, '--cpu', cpu, '--os', os_] + args)[0] else: if branch == "esr": branch = "esr52" fetcher = fuzzfetch.Fetcher("firefox", branch, "latest", build_flags, platform_) log.debug("succeeded creating Fetcher") log.debug("buildid: %s", fetcher.build_id) log.debug("hgrev: %s", fetcher.changeset) time_obj = time.strptime(fetcher.build_id, "%Y%m%d%H%M%S") # yyyy-mm-dd is also accepted as a build input date_str = "%d-%02d-%02d" % (time_obj.tm_year, time_obj.tm_mon, time_obj.tm_mday) if as_args: fuzzfetch.Fetcher.from_args([ "--" + branch, '--cpu', cpu, '--os', os_, "--build", date_str ] + args) else: fuzzfetch.Fetcher("firefox", branch, date_str, build_flags, platform_) # hg rev is also accepted as a build input rev = fetcher.changeset if as_args: fuzzfetch.Fetcher.from_args( ["--" + branch, '--cpu', cpu, '--os', os_, "--build", rev] + args) else: fuzzfetch.Fetcher("firefox", branch, rev, build_flags, platform_)
def get_coverage_build(dirpath, rev): """Gets a coverage build from a specified server. Args: dirpath (Path): Directory in which build is to be downloaded in. rev (str): Mercurial hash of the required revision Returns: Path: Path to the js coverage build """ RUN_COV_LOG.info( "Obtaining coverage build zip file from TaskCluster, into %s", str(dirpath)) extract_folder = dirpath / "cov-build" extract_folder.mkdir(parents=True, exist_ok=True) # Ensure this dir has been created # Use fuzzfetch to obtain build instead of wget build_flags = fuzzfetch.BuildFlags(asan=False, debug=False, fuzzing=True, coverage=True, valgrind=False) platform_ = fuzzfetch.fetch.Platform() obtained_build = fuzzfetch.Fetcher("js", "central", rev, build_flags, platform_) obtained_build.extract_build(str(extract_folder)) RUN_COV_LOG.info("Coverage build zip file extracted to this folder: %s", extract_folder.resolve()) js_cov_bin_name = f'js{".exe" if platform.system() == "Windows" else ""}' js_cov_bin = extract_folder / "dist" / "bin" / js_cov_bin_name Path.chmod(js_cov_bin, Path.stat(js_cov_bin).st_mode | 0o111) # Ensure the js binary is executable assert js_cov_bin.is_file() # Check that the binary is non-debug. assert not queryBuildConfiguration(js_cov_bin, "debug") assert queryBuildConfiguration(js_cov_bin, "coverage") js_cov_fmconf = extract_folder / "dist" / "bin" / f"{js_cov_bin_name}.fuzzmanagerconf" assert js_cov_fmconf.is_file() # Check that a coverage build with *.gcno files are present js_cov_unified_gcno = extract_folder / "js" / "src" / "Unified_cpp_js_src0.gcno" assert js_cov_unified_gcno.is_file() return js_cov_bin
def test_hash_resolution(): """ Test shortened hashes are resolved """ flags = fuzzfetch.BuildFlags( asan=False, tsan=False, debug=False, fuzzing=False, coverage=False, valgrind=False, ) rev = "d1001fea6e4c66b98bb4983df49c6e47d2db5ceb" build = fuzzfetch.Fetcher("firefox", "central", rev[:12], flags) assert build.changeset == rev
def test_nearest_retrieval(requested, expected, direction, is_namespace): """ Attempt to retrieve a build near the supplied build_id """ flags = fuzzfetch.BuildFlags( asan=False, tsan=False, debug=False, fuzzing=False, coverage=False, valgrind=False, ) # Set freeze_time to a date ahead of the latest mock build with freeze_time("2020-08-05"): LOG.debug("looking for nearest to %s", requested) if is_namespace: if fuzzfetch.BuildTask.RE_DATE.match(requested): date = requested.replace("-", ".") build_id = ( "gecko.v2.mozilla-central.pushdate.%s.firefox.linux64-opt" % date) else: build_id = ( "gecko.v2.mozilla-central.revision.%s.firefox.linux64-opt" % requested) else: build_id = requested build = fuzzfetch.Fetcher("firefox", "central", build_id, flags, nearest=direction) if fuzzfetch.BuildTask.RE_DATE.match(expected): build_date = datetime.strftime(build.datetime, "%Y-%m-%d") assert build_date == expected else: assert fuzzfetch.BuildTask.RE_REV.match(expected) assert build.changeset == expected