diff --git a/libs/utils/env.py b/libs/utils/env.py index 90766fd3587afb7a905ba3450874e86d5cb0c09c..42b8d9d91004bc70da4b8197e52ced912f3d2888 100644 --- a/libs/utils/env.py +++ b/libs/utils/env.py @@ -532,7 +532,8 @@ class TestEnv(ShareState): self.target = devlib.LocalLinuxTarget( platform = platform, load_default_modules = False, - modules = self.__modules) + modules = self.__modules, + connection_settings = {'unrooted': True}) else: raise ValueError('Config error: not supported [platform] type {}'\ .format(platform_type)) diff --git a/libs/utils/executor.py b/libs/utils/executor.py index 41706699c10616ba3c74341af22e912535b8e1f6..f5e1f1a328a81e5b01b99a90c4fc7972e3be21e9 100644 --- a/libs/utils/executor.py +++ b/libs/utils/executor.py @@ -195,6 +195,7 @@ class Executor(): # Initialize globals self._default_cgroup = None self._cgroup = None + self._old_selinux_mode = None # Setup logging self._log = logging.getLogger('Executor') @@ -335,26 +336,30 @@ class Executor(): self._log.debug('Setup RT-App run folder [%s]...', self.te.run_dir) self.target.execute('[ -d {0} ] || mkdir {0}'\ .format(self.te.run_dir)) - self.target.execute( + + if self.target.is_rooted: + self.target.execute( 'grep schedtest /proc/mounts || '\ ' mount -t tmpfs -o size=1024m {} {}'\ .format('schedtest', self.te.run_dir), as_root=True) - # tmpfs mounts have an SELinux context with "tmpfs" as the type (while - # other files we create have "shell_data_file"). That prevents non-root - # users from creating files in tmpfs mounts. For now, just put SELinux - # in permissive mode to get around that. - try: - # First, save the old SELinux mode - self._old_selinux_mode = self.target.execute('getenforce') - self._log.warning('Setting target SELinux in permissive mode') - self.target.execute('setenforce 0', as_root=True) - except TargetError: - # Probably the target doesn't have SELinux, or there are no - # contexts set up. No problem. - self._log.warning("Couldn't set SELinux in permissive mode. " - "This is probably fine.") - self._old_selinux_mode = None + + # tmpfs mounts have an SELinux context with "tmpfs" as the type + # (while other files we create have "shell_data_file"). That + # prevents non-root users from creating files in tmpfs mounts. For + # now, just put SELinux in permissive mode to get around that. + try: + # First, save the old SELinux mode + self._old_selinux_mode = self.target.execute('getenforce') + except TargetError: + # Probably the target doesn't have SELinux. No problem. + pass + else: + + self._log.warning('Setting target SELinux in permissive mode') + self.target.execute('setenforce 0', as_root=True) + else: + self._log.warning('Not mounting tmpfs because no root') def _setup_cpufreq(self, tc): if 'cpufreq' not in tc: diff --git a/tests/lisa/test_executor.py b/tests/lisa/test_executor.py new file mode 100644 index 0000000000000000000000000000000000000000..910e9c11ad0c6d82243261e709b69c6a3768adac --- /dev/null +++ b/tests/lisa/test_executor.py @@ -0,0 +1,91 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (C) 2017, ARM Limited and contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import logging +import shutil +import os +from unittest import TestCase + +from env import TestEnv +from executor import Executor + +class SetUpTarget(TestCase): + @classmethod + def setUpClass(cls): + cls._log = logging.getLogger('TestExecutor') + + def setUp(self): + self.res_dir='test_{}'.format(self.__class__.__name__) + self.te = TestEnv( + target_conf={ + 'platform': 'host', + # With no cpufreq (see below), we won't be able to do + # calibration. Provide dummy. + 'rtapp-calib': {c: 100 for c in range(64)} + }, + test_conf={ + 'results_dir': self.res_dir, + # Don't load cpufreq, it won't work when platform=host + 'exclude_modules': ['cpufreq'], + }, + force_new=True) + +class TestMagicSmoke(SetUpTarget): + def test_files_created(self): + """Test that we can run experiments and get output files""" + conf_name = 'myconf' + wl_name = 'mywl' + + results_dir = os.path.join(self.te.LISA_HOME, 'results', self.res_dir, + 'rtapp:{}:{}'.format(conf_name, wl_name)) + if os.path.isdir(results_dir): + shutil.rmtree(results_dir) + + experiments_conf = { + 'confs': [{ + 'tag': conf_name + }], + "wloads" : { + wl_name : { + "type" : "rt-app", + "conf" : { + "class" : "profile", + "params" : { + "mytask" : { + "kind" : "Periodic", + "params" : { + "duty_cycle_pct": 10, + "duration_s": 0.2, + }, + }, + }, + }, + }, + }, + } + + executor = Executor(self.te, experiments_conf) + executor.run() + + self.assertTrue( + os.path.isdir(results_dir), + 'Expected to find a directory at {}'.format(results_dir)) + + result_1_dir = os.path.join(results_dir, '1') + self.assertTrue( + os.path.isdir(result_1_dir), + 'Expected to find a directory at {}'.format(result_1_dir))