def _do_test(self, task, exp_phases): rtapp = RTA(self.target, name='test', calibration=self.calibration) rtapp.conf(kind='profile', params={'my_task': task.get()}, run_dir=self.target_run_dir) with open(rtapp.json) as f: conf = json.load(f, object_pairs_hook=OrderedDict) # Check that the configuration looks like we expect it to phases = conf['tasks']['my_task']['phases'].values() self.assertEqual(len(phases), len(exp_phases), 'Wrong number of phases') for phase, exp_phase in zip(phases, exp_phases): self.assertDictEqual(phase, exp_phase) # Try running the workload and check that it produces the expected log # files rtapp.run(out_dir=self.host_out_dir) rtapp_cmds = [ c for c in self.target.executed_commands if 'rt-app' in c ] self.assertListEqual(rtapp_cmds, [self.get_expected_command(rtapp)]) self.assert_output_file_exists('output.log') self.assert_output_file_exists('test_00.json') self.assert_output_file_exists('rt-app-my_task-0.log') self.assert_can_read_logfile(exp_tasks=['my_task'])
def __init__(self, name, test_env, cpus, period_ms=100, duty_cycle_pct=50, duration_s=1, kind='profile', num_tasks=1): super(Task, self).__init__("task") self.name = name self.period_ms = period_ms self.duty_cycle_pct = duty_cycle_pct self.duration_s = duration_s self.cpus = cpus allowed_kinds = ['profile', 'custom'] if kind not in allowed_kinds: raise ValueError('{} not allowed, kind can be one of {}' .format(kind, allowed_kinds)) self.kind = kind self.num_tasks = num_tasks # Create rt-app workload t = Periodic(period_ms=period_ms, duty_cycle_pct=duty_cycle_pct, duration_s=duration_s).get() self.wload = RTA(test_env.target, name, test_env.calibration()) if num_tasks > 1: conf_params = {name + "_{}".format(i): t for i in xrange(num_tasks)} else: conf_params = {name: t} self.wload.conf(kind=kind, params=conf_params, run_dir=test_env.target.working_directory)
def run_workload(cls): big_cpu = cls.env.target.bl.bigs[0] big_cpufreq = "/sys/devices/system/cpu/cpu{}/cpufreq".format(big_cpu) max_freq_path = os.path.join(big_cpufreq, "scaling_max_freq") available_freqs_path = os.path.join(big_cpufreq, "scaling_available_frequencies") available_freqs_str = cls.env.target.read_value(available_freqs_path) available_freqs = available_freqs_str.split() min_frequency = available_freqs[0] max_frequency = available_freqs[-1] wload = RTA(cls.env.target, "busy_threads", calibration=cls.env.calibration()) wload.conf(kind="profile", params=cls.params) phase_duration = WORKLOAD_DURATION_S / 3. cls.env.ftrace.start() wload.run(out_dir=cls.env.res_dir, background=True) time.sleep(phase_duration) cls.env.target.write_value(max_freq_path, min_frequency) time.sleep(phase_duration) cls.env.target.write_value(max_freq_path, max_frequency) time.sleep(phase_duration) cls.env.ftrace.stop() cls.env.ftrace.get_trace(cls.trace_file)
def _get_calib_conf(self, calibration): rtapp = RTA(self.target, name='test', calibration=calibration) rtapp.conf(kind='profile', params={'t1': Periodic().get()}, run_dir=self.target_run_dir) with open(rtapp.json) as f: return json.load(f)['global']['calibration']
def run_workload(cls): wload = RTA(cls.env.target, "wake_migration", calibration=cls.env.calibration()) wload.conf(kind="profile", params=cls.params) cls.env.ftrace.start() wload.run(out_dir=cls.env.res_dir, background=False) cls.env.ftrace.stop() trace = cls.env.ftrace.get_trace(cls.trace_file)
def populate_params(cls): cls.rtapp = RTA(cls.target,cls.rta_name) cls.rtapp.conf( kind='profile', params={ cls.task_name: Periodic( period_ms=40, duty_cycle_pct=1, duration_s=2, cpus=cls.test_cpu, ).get(), }, run_dir='/tmp' )
def _test_custom_smoke(self, calibration): """ Test RTA custom workload Creates an rt-app workload using 'custom' and checks that the json roughly matches the file we provided. If we have root, attempts to run the workload. """ json_path = os.path.join(os.getenv('LISA_HOME'), 'assets', 'mp3-short.json') rtapp = RTA(self.target, name='test', calibration=calibration) # Configure this RTApp instance to: rtapp.conf(kind='custom', params=json_path, duration=5, run_dir=self.target_run_dir) with open(rtapp.json) as f: conf = json.load(f) # Convert k to str because the json loader gives us unicode strings tasks = set([str(k) for k in conf['tasks'].keys()]) self.assertSetEqual( tasks, set([ 'AudioTick', 'AudioOut', 'AudioTrack', 'mp3.decoder', 'OMXCall' ])) # Would like to try running the workload but mp3-short.json has nonzero # 'priority' fields, and we probably don't have permission for that # unless we're root. if self.target.is_rooted: rtapp.run(out_dir=self.host_out_dir) rtapp_cmds = [ c for c in self.target.executed_commands if 'rt-app' in c ] self.assertListEqual(rtapp_cmds, [self.get_expected_command(rtapp)]) self.assert_output_file_exists('output.log') self.assert_output_file_exists('test_00.json')
def test_profile_periodic_smoke(self): """ Smoketest Periodic rt-app workload Creates a workload using Periodic, tests that the JSON has the expected content, then tests that it can be run. """ rtapp = RTA(self.target, name='test', calibration=self.calibration) rtapp.conf(kind='profile', params={ 'task_p20': Periodic( period_ms=100, duty_cycle_pct=20, duration_s=1, ).get(), }, run_dir=self.target_run_dir) with open(rtapp.json) as f: conf = json.load(f) [phase] = conf['tasks']['task_p20']['phases'].values() self.assertDictEqual( phase, { 'loop': 10, 'run': 20000, 'timer': { 'period': 100000, 'ref': 'task_p20' } }) rtapp.run(out_dir=self.host_out_dir) rtapp_cmds = [ c for c in self.target.executed_commands if 'rt-app' in c ] self.assertListEqual(rtapp_cmds, [self.get_expected_command(rtapp)]) self.assert_output_file_exists('output.log') self.assert_output_file_exists('test_00.json') self.assert_output_file_exists('rt-app-task_p20-0.log') self.assert_can_read_logfile(exp_tasks=['task_p20'])
def run_workload(cls): big_cpu = cls.env.target.bl.bigs[0] big_cpufreq = "/sys/devices/system/cpu/cpu{}/cpufreq".format(big_cpu) max_freq_path = os.path.join(big_cpufreq, "scaling_max_freq") available_freqs_path = os.path.join(big_cpufreq, "scaling_available_frequencies") available_freqs_str = cls.env.target.read_value(available_freqs_path) available_freqs = available_freqs_str.split() min_frequency = available_freqs[0] max_frequency = available_freqs[-1] wload = RTA(cls.env.target, "busy_threads", calibration=cls.env.calibration()) wload.conf(kind="profile", params=cls.params) phase_duration = WORKLOAD_DURATION_S / 3. cls.env.ftrace.start() wload.run(out_dir=cls.env.res_dir, background=True) time.sleep(phase_duration) # Writing values on the target can take a non-negligible amount of time. # To prevent this from shifting the transitions between # constrained/unconstrained phases, measure this write latency and # reduce our sleep time by that amount. def write_and_sleep(max_freq): time_before = time.time() cls.env.target.write_value(max_freq_path, max_freq) write_latency = time.time() - time_before if (write_latency > phase_duration): raise ValueError( "Latency of Target.write_value greater than phase duration! " "Increase WORKLOAD_DURATION_S or speed up target connection") time.sleep(phase_duration - write_latency) write_and_sleep(min_frequency) write_and_sleep(max_frequency) cls.env.ftrace.stop() cls.env.ftrace.get_trace(cls.trace_file)
def test_composition(self): """ Test RTA task composition with __add__ Creates a composed workload by +-ing RTATask objects, tests that the JSON has the expected content, then tests running the workload """ rtapp = RTA(self.target, name='test', calibration=self.calibration) light = Periodic(duty_cycle_pct=10, duration_s=1.0, period_ms=10) start_pct = 10 end_pct = 90 delta_pct = 20 num_ramp_phases = ((end_pct - start_pct) / delta_pct) + 1 ramp = Ramp(start_pct=start_pct, end_pct=end_pct, delta_pct=delta_pct, time_s=1, period_ms=50) heavy = Periodic(duty_cycle_pct=90, duration_s=0.1, period_ms=100) lrh_task = light + ramp + heavy rtapp.conf(kind='profile', params={'task_ramp': lrh_task.get()}, run_dir=self.target_run_dir) with open(rtapp.json) as f: conf = json.load(f, object_pairs_hook=OrderedDict) phases = conf['tasks']['task_ramp']['phases'].values() exp_phases = [ # Light phase: { "loop": 100, "run": 1000, "timer": { "period": 10000, "ref": "task_ramp" } }, # Ramp phases: { "loop": 20, "run": 5000, "timer": { "period": 50000, "ref": "task_ramp" } }, { "loop": 20, "run": 15000, "timer": { "period": 50000, "ref": "task_ramp" } }, { "loop": 20, "run": 25000, "timer": { "period": 50000, "ref": "task_ramp" } }, { "loop": 20, "run": 35000, "timer": { "period": 50000, "ref": "task_ramp" } }, { "loop": 20, "run": 45000, "timer": { "period": 50000, "ref": "task_ramp" } }, # Heavy phase: { "loop": 1, "run": 90000, "timer": { "period": 100000, "ref": "task_ramp" } } ] self.assertListEqual(phases, exp_phases) rtapp.run(out_dir=self.host_out_dir) rtapp_cmds = [ c for c in self.target.executed_commands if 'rt-app' in c ] self.assertListEqual(rtapp_cmds, [self.get_expected_command(rtapp)]) self.assert_output_file_exists('output.log') self.assert_output_file_exists('test_00.json') self.assert_output_file_exists('rt-app-task_ramp-0.log') self.assert_can_read_logfile(exp_tasks=['task_ramp'])