mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
tests/test_target: Test more targets
Test Android and Linux targets as well in addition to LocalLinux target. In order to keep basic verification easy, list complete list of test targets in tests/target_configs.yaml.example and keep the default configuration file for targets simple. Also: - Create a test folder on target's working directory. - Remove all devlib artefacts after execution of the test. - Add logs to show progress of operations. Signed-off-by: Metin Kaya <metin.kaya@arm.com>
This commit is contained in:
parent
295f1269ed
commit
dd84dc7e38
17
tests/target_configs.yaml.example
Normal file
17
tests/target_configs.yaml.example
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
AndroidTarget:
|
||||||
|
entry-0:
|
||||||
|
connection_settings:
|
||||||
|
device: 'emulator-5554'
|
||||||
|
|
||||||
|
LinuxTarget:
|
||||||
|
entry-0:
|
||||||
|
connection_settings:
|
||||||
|
host: 'example.com'
|
||||||
|
username: 'username'
|
||||||
|
password: 'password'
|
||||||
|
|
||||||
|
LocalLinuxTarget:
|
||||||
|
entry-0:
|
||||||
|
connection_settings:
|
||||||
|
unrooted: True
|
||||||
|
|
@ -17,12 +17,11 @@
|
|||||||
"""Module for testing targets."""
|
"""Module for testing targets."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
import tempfile
|
|
||||||
from pprint import pp
|
from pprint import pp
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from devlib import LocalLinuxTarget
|
from devlib import AndroidTarget, LinuxTarget, LocalLinuxTarget
|
||||||
|
from devlib.utils.android import AdbConnection
|
||||||
from devlib.utils.misc import load_struct_from_yaml
|
from devlib.utils.misc import load_struct_from_yaml
|
||||||
|
|
||||||
|
|
||||||
@ -37,6 +36,23 @@ def build_targets():
|
|||||||
|
|
||||||
targets = []
|
targets = []
|
||||||
|
|
||||||
|
if target_configs.get('AndroidTarget') is not None:
|
||||||
|
print('> Android targets:')
|
||||||
|
for entry in target_configs['AndroidTarget'].values():
|
||||||
|
pp(entry)
|
||||||
|
a_target = AndroidTarget(
|
||||||
|
connection_settings=entry['connection_settings'],
|
||||||
|
conn_cls=lambda **kwargs: AdbConnection(adb_as_root=True, **kwargs),
|
||||||
|
)
|
||||||
|
targets.append(a_target)
|
||||||
|
|
||||||
|
if target_configs.get('LinuxTarget') is not None:
|
||||||
|
print('> Linux targets:')
|
||||||
|
for entry in target_configs['LinuxTarget'].values():
|
||||||
|
pp(entry)
|
||||||
|
l_target = LinuxTarget(connection_settings=entry['connection_settings'])
|
||||||
|
targets.append(l_target)
|
||||||
|
|
||||||
if target_configs.get('LocalLinuxTarget') is not None:
|
if target_configs.get('LocalLinuxTarget') is not None:
|
||||||
print('> LocalLinux targets:')
|
print('> LocalLinux targets:')
|
||||||
for entry in target_configs['LocalLinuxTarget'].values():
|
for entry in target_configs['LocalLinuxTarget'].values():
|
||||||
@ -62,15 +78,22 @@ def test_read_multiline_values(target):
|
|||||||
'test3': '3\n\n4\n\n',
|
'test3': '3\n\n4\n\n',
|
||||||
}
|
}
|
||||||
|
|
||||||
tempdir = tempfile.mkdtemp(prefix='devlib-test-')
|
print(f'target={target.__class__.__name__} os={target.os} hostname={target.hostname}')
|
||||||
|
|
||||||
|
with target.make_temp() as tempdir:
|
||||||
|
print(f'Created {tempdir}.')
|
||||||
|
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
path = os.path.join(tempdir, key)
|
path = os.path.join(tempdir, key)
|
||||||
with open(path, 'w', encoding='utf-8') as wfh:
|
print(f'Writing {value!r} to {path}...')
|
||||||
wfh.write(value)
|
target.write_value(path, value, verify=False,
|
||||||
|
as_root=target.conn.connected_as_root)
|
||||||
|
|
||||||
|
print('Reading values from target...')
|
||||||
raw_result = target.read_tree_values_flat(tempdir)
|
raw_result = target.read_tree_values_flat(tempdir)
|
||||||
result = {os.path.basename(k): v for k, v in raw_result.items()}
|
result = {os.path.basename(k): v for k, v in raw_result.items()}
|
||||||
|
|
||||||
shutil.rmtree(tempdir)
|
print(f'Removing {target.working_directory}...')
|
||||||
|
target.remove(target.working_directory)
|
||||||
|
|
||||||
assert {k: v.strip() for k, v in data.items()} == result
|
assert {k: v.strip() for k, v in data.items()} == result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user