diff --git a/lisa/target.py b/lisa/target.py index e9f7891900e0504d567488e2652a990ea3b48b01..b862fa475986c8b66f14d36e218f6e9f22fbf5d6 100644 --- a/lisa/target.py +++ b/lisa/target.py @@ -471,7 +471,10 @@ class Target(Loggable, HideExekallID, Configurable): elif kind == 'host': logger.debug('Setting up localhost Linux target...') devlib_target_cls = devlib.LocalLinuxTarget - conn_settings['unrooted'] = True + # If we are given a password, assume we can use it as a sudo + # password. + conn_settings['unrooted'] = password is None + conn_settings['password'] = password else: raise ValueError('Unsupported platform type {}'.format(kind)) diff --git a/lisa/assets/mp3-short.json b/tests/assets/mp3-short.json similarity index 100% rename from lisa/assets/mp3-short.json rename to tests/assets/mp3-short.json diff --git a/tests/traces/plat_info.yml b/tests/assets/plat_info.yml similarity index 100% rename from tests/traces/plat_info.yml rename to tests/assets/plat_info.yml diff --git a/tests/traces/sched_load/plat_info.yml b/tests/assets/sched_load/plat_info.yml similarity index 100% rename from tests/traces/sched_load/plat_info.yml rename to tests/assets/sched_load/plat_info.yml diff --git a/tests/traces/sched_load/trace.dat b/tests/assets/sched_load/trace.dat similarity index 100% rename from tests/traces/sched_load/trace.dat rename to tests/assets/sched_load/trace.dat diff --git a/tests/traces/sched_load_avg/plat_info.yml b/tests/assets/sched_load_avg/plat_info.yml similarity index 100% rename from tests/traces/sched_load_avg/plat_info.yml rename to tests/assets/sched_load_avg/plat_info.yml diff --git a/tests/traces/sched_load_avg/trace.dat b/tests/assets/sched_load_avg/trace.dat similarity index 100% rename from tests/traces/sched_load_avg/trace.dat rename to tests/assets/sched_load_avg/trace.dat diff --git a/tests/traces/trace.txt b/tests/assets/trace.txt similarity index 100% rename from tests/traces/trace.txt rename to tests/assets/trace.txt diff --git a/tests/test_target.py b/tests/test_target.py index 0371e058ce24de206fb72e79f71ee5fbba06c558..7f0b7c575b4acec65c2c4b0f6ee5813b86fe0144 100644 --- a/tests/test_target.py +++ b/tests/test_target.py @@ -26,7 +26,7 @@ class TargetEnvCheck(TestCase): """ Test that creating a Target from the CLI works """ - args = "--kind host" + args = "--kind host --password 'foobar'" target = Target.from_cli(shlex.split(args)) self.assertNotEqual(target.os, None) diff --git a/tests/test_trace.py b/tests/test_trace.py index cbaa2aa75eff25eacfe6072a4f8ad76a9f48b1ec..6909d9bf10a1f37d51aec0de3ba19e197eb321a9 100644 --- a/tests/test_trace.py +++ b/tests/test_trace.py @@ -26,10 +26,10 @@ from devlib.target import KernelVersion from lisa.trace import Trace from lisa.platforms.platinfo import PlatformInfo -from .utils import StorageTestCase +from .utils import StorageTestCase, ASSET_DIR class TraceTestCase(StorageTestCase): - traces_dir = os.path.join(os.path.dirname(__file__), 'traces') + traces_dir = ASSET_DIR events = [ 'sched_switch', 'sched_wakeup', diff --git a/tests/test_wlgen_rtapp.py b/tests/test_wlgen_rtapp.py index a8e27253681edbf6ea065536ad4509a60e7ad300..96caab1bc9ff7c2114df90939ac81de54fd657f8 100644 --- a/tests/test_wlgen_rtapp.py +++ b/tests/test_wlgen_rtapp.py @@ -22,7 +22,7 @@ import os from lisa.wlgen.rta import RTA, Periodic, Ramp, Step, RunAndSync from lisa.analysis.rta import PerfAnalysis -from .utils import StorageTestCase, create_local_target +from .utils import StorageTestCase, create_local_target, ASSET_DIR class RTABase(StorageTestCase): """ @@ -36,13 +36,13 @@ class RTABase(StorageTestCase): def get_expected_command(self, rta_wload): """Return the rt-app command we should execute when `run` is called""" - rta_path = self.te.target.which('rt-app') + rta_path = self.target.which('rt-app') json_path = os.path.join(rta_wload.run_dir, rta_wload.json) return '{} {} 2>&1'.format(rta_path, json_path) def setUp(self): super().setUp() - self.te = create_local_target() + self.target = create_local_target() def assert_output_file_exists(self, path): """Assert that a file was created""" @@ -58,7 +58,7 @@ class RTABase(StorageTestCase): class TestRTAProfile(RTABase): def _do_test(self, profile, exp_phases): rtapp = RTA.by_profile( - self.te, name='test', profile=profile, res_dir=self.res_dir, + self.target, name='test', profile=profile, res_dir=self.res_dir, calibration=None) with open(rtapp.local_json) as f: @@ -74,7 +74,7 @@ class TestRTAProfile(RTABase): # files rtapp.run() - # rtapp_cmds = [c for c in self.te.target.executed_commands if 'rt-app' in c] + # 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') @@ -251,32 +251,28 @@ class TestRTACustom(RTABase): the workload. """ - #TODO: update the path to mp3-short.json - json_path = os.path.join(os.getenv('LISA_HOME'), - 'lisa', 'assets', 'mp3-short.json') + json_path = os.path.join(ASSET_DIR, 'mp3-short.json') with open(json_path, 'r') as fh: str_conf = fh.read() rtapp = RTA.by_str( - self.te, name='test', str_conf=str_conf, res_dir=self.res_dir, + self.target, name='test', str_conf=str_conf, res_dir=self.res_dir, max_duration_s=5, calibration=calibration) with open(rtapp.local_json, 'r') as fh: conf = json.load(fh) - # Convert k to str because the json loader gives us unicode strings - tasks = set([str(k) for k in list(conf['tasks'].keys())]) self.assertSetEqual( - tasks, + set(conf['tasks'].keys()), 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.te.target.is_rooted: - rtapp.run() + if self.target.is_rooted: + rtapp.run(as_root=True) # rtapp_cmds = [c for c in self.target.executed_commands # if 'rt-app' in c] @@ -287,7 +283,7 @@ class TestRTACustom(RTABase): def test_custom_smoke_calib(self): """Test RTA custom workload (providing calibration)""" - calibration = min(self.te.plat_info['rtapp']['calib'].values()) + calibration = min(self.target.plat_info['rtapp']['calib'].values()) self._test_custom_smoke(calibration) def test_custom_smoke_no_calib(self): @@ -300,7 +296,7 @@ class TestRTACalibrationConf(RTABase): def _get_calib_conf(self, calibration): profile = {"test_task" : Periodic()} rtapp = RTA.by_profile( - self.te, name='test', res_dir=self.res_dir, profile=profile, + self.target, name='test', res_dir=self.res_dir, profile=profile, calibration=calibration) with open(rtapp.local_json) as fh: diff --git a/tests/utils.py b/tests/utils.py index cd4e410ef4e5e75c0ef00a3dc84aec0007edfbea..4afd0d59b0e239a7293e3bcb9093c79ae753acf9 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -18,15 +18,20 @@ from unittest import TestCase import tempfile import shutil +import os.path from devlib.target import KernelVersion from lisa.target import Target, TargetConf from lisa.platforms.platinfo import PlatformInfo +ASSET_DIR = os.path.join(os.path.dirname(__file__), 'assets') HOST_TARGET_CONF = TargetConf({ 'kind': 'host', + # Travis has a passwordless sudo, so we provide an garbage password since + # sudo will accept anything + 'password': 'foobar', # Don't load cpufreq, it usually won't work with CI targets 'devlib': { 'excluded-modules': ['cpufreq', 'hwmon'],