def run(self): dir_path = self.get_ref_path('', extra=True) for file in sorted(os.scandir(dir_path), key=lambda e: e.name.lower()): if '.rdc' not in file.name: continue # Ensure we are deterministic at least from run to run by seeding with the path random.seed(file.name) self.filename = file.name rdtest.log.print("Opening '{}'.".format(file.name)) try: self.controller = rdtest.open_capture(file.path) except RuntimeError as err: rdtest.log.print("Skipping. Can't open {}: {}".format(file.path, err)) continue section_name = 'Iterating {}'.format(file.name) rdtest.log.begin_section(section_name) self.iter_test() rdtest.log.end_section(section_name) self.controller.Shutdown() rdtest.log.success("Iterated all files")
def run(self): dir_path = self.get_ref_path('', extra=True) for file in os.scandir(dir_path): if '.rdc' not in file.name: continue # Ensure we are deterministic at least from run to run by seeding with the path random.seed(file.name) rdtest.log.print('Iterating {}'.format(file.name)) try: self.controller = rdtest.open_capture(file.path) except RuntimeError as err: rdtest.log.print("Skipping. Can't open {}: {}".format(file.path, err)) continue self.iter_test() self.controller.Shutdown() rdtest.log.success("Iterated {}".format(file.name)) rdtest.log.success("Iterated all files")
def run(self): self.capture_filename = self.get_capture() self.check(os.path.exists(self.capture_filename), "Didn't generate capture in make_capture") rdtest.log.print("Loading capture") memory_before: int = rd.GetCurrentProcessMemoryUsage() start_time = time.time() self.controller = rdtest.open_capture(self.capture_filename, opts=self.get_replay_options()) duration = time.time() - start_time memory_after: int = rd.GetCurrentProcessMemoryUsage() memory_increase = memory_after - memory_before rdtest.log.print("Loaded capture in {:02} seconds, consuming {} bytes of memory".format(duration, memory_increase)) if memory_increase > 1200*1000*1000: raise rdtest.TestFailureException("Memory usage is too high".format(duration)) else: rdtest.log.success("Memory usage is OK") if rd.IsReleaseBuild(): if duration >= 2.5: raise rdtest.TestFailureException("Time to load is too high") rdtest.log.success("Time to load is OK") else: rdtest.log.print("Not checking time to load in non-release build") if self.controller is not None: self.controller.Shutdown()
def iter_test(self, path): try: self.controller = rdtest.open_capture(path) except RuntimeError as err: rdtest.log.print("Skipping. Can't open {}: {}".format(path, err)) return # Handy tweaks when running locally to disable certain things action_chance = 0.1 # Chance of doing anything at all do_image_save = 0.25 # Chance of saving images of the outputs do_vert_debug = 1.0 # Chance of debugging a vertex (if valid) do_pixel_debug = 1.0 # Chance of doing pixel history at the current event and debugging a pixel (if valid) actions = { 'Image Save': {'chance': do_image_save, 'func': self.image_save}, 'Vertex Debug': {'chance': do_vert_debug, 'func': self.vert_debug}, 'Pixel History & Debug': {'chance': do_pixel_debug, 'func': self.pixel_debug}, } # To choose an action, if we're going to do one, we take random in range(0, choice_max) then check each action # type in turn to see which part of the range we landed in choice_max = 0 for action in actions: choice_max += actions[action]['chance'] draw = self.get_first_draw() last_draw = self.get_last_draw() while draw: rdtest.log.print("{}/{} - {}".format(draw.eventId, last_draw.eventId, draw.name)) self.controller.SetFrameEvent(draw.eventId, False) rdtest.log.print("Set event") # If we should take an action at this event if random.random() < action_chance: c = random.random() * choice_max for action in actions: chance = actions[action]['chance'] if c < chance: rdtest.log.print("Performing action '{}'".format(action)) actions[action]['func'](draw) break else: c -= chance draw = draw.next self.controller.Shutdown()
def repeat_load(self, path): memory_peak = memory_baseline = 0 for i in range(20): rdtest.log.print("Loading for iteration {}".format(i)) try: controller = rdtest.open_capture(path) except RuntimeError as err: rdtest.log.print("Skipping. Can't open {}: {}".format( path, err)) return # Do nothing, just ensure it's loaded memory_usage: int = psutil.Process(os.getpid()).memory_info().rss # We measure the baseline memory usage during the second peak to avoid any persistent caches etc that might # not be full if i == 1: memory_baseline = memory_usage memory_peak = max(memory_peak, memory_usage) controller.Shutdown() pct_over = 'N/A' if memory_baseline > 0: pct_over = '{:.2f}%'.format( (memory_usage / memory_baseline) * 100) rdtest.log.success( "Succeeded iteration {}, memory usage was {} ({} of baseline)". format(i, memory_usage, pct_over)) pct_over = '{:.2f}%'.format((memory_peak / memory_baseline) * 100) msg = 'peak memory usage was {}, {} compared to baseline {}'.format( memory_peak, pct_over, memory_baseline) if memory_baseline * 1.25 < memory_peak: raise rdtest.TestFailureException(msg) else: rdtest.log.success(msg)
def repeat_load(self, path): memory_usage = memory_baseline = 0 for i in range(20): rdtest.log.print("Loading for iteration {}".format(i+1)) try: controller = rdtest.open_capture(path) except RuntimeError as err: rdtest.log.print("Skipping. Can't open {}: {}".format(path, err)) return rdtest.log.print("Loaded capture.") # Do nothing, just ensure it's loaded memory_usage: int = rd.GetCurrentProcessMemoryUsage() # We measure the baseline memory usage during the second peak to avoid any persistent caches etc that might # not be full if i == 2: memory_baseline = memory_usage controller.Shutdown() pct_over = 'N/A' if memory_baseline > 0: pct_over = '{:.2f}%'.format((memory_usage / memory_baseline)*100) rdtest.log.success("Succeeded iteration {}, memory usage was {} ({} of baseline)" .format(i+1, memory_usage, pct_over)) pct_over = '{:.2f}%'.format((memory_usage / memory_baseline)*100) msg = 'final memory usage was {}, {} compared to baseline {}'.format(memory_usage, pct_over, memory_baseline) if memory_baseline * 1.25 < memory_usage: raise rdtest.TestFailureException(msg) else: rdtest.log.success(msg)