-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spin_targets: Add new test case to test actual targets
Spin Linux, LocalLinux and Android targets and run a basic test on them. Signed-off-by: Metin Kaya <[email protected]>
- Loading branch information
Showing
1 changed file
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2024 ARM Limited | ||
# | ||
# 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. | ||
# | ||
|
||
""" | ||
Module for testing different targets. | ||
Forked from tests/test_target.py. | ||
""" | ||
|
||
import os | ||
from unittest import TestCase | ||
from devlib import AndroidTarget, LinuxTarget, LocalLinuxTarget | ||
from devlib.utils.misc import get_random_string | ||
from devlib.exception import TargetStableError | ||
|
||
|
||
class TestReadTreeValues(TestCase): | ||
""" Class testing Target.read_tree_values_flat() """ | ||
|
||
def test_read_multiline_values(self): | ||
""" Test Target.read_tree_values_flat() """ | ||
|
||
def run_test(target): | ||
data = { | ||
'test1': '1', | ||
'test2': '2\n\n', | ||
'test3': '3\n\n4\n\n', | ||
} | ||
|
||
print(f'{method_name}: target={target.__class__.__name__} os={target.os} ' \ | ||
f'hostname={target.hostname}') | ||
|
||
dirname = os.path.join(target.working_directory, | ||
f'devlib-test-{get_random_string(12)}') | ||
print(f'{method_name}: creating {dirname}...') | ||
target.makedirs(dirname) | ||
|
||
try: | ||
for key, value in data.items(): | ||
path = os.path.join(dirname, key) | ||
print(f'{method_name}: writing {value!r} to {path}...') | ||
target.write_value(path, value, verify=False, | ||
as_root=target.conn.connected_as_root) | ||
|
||
print(f'{method_name}: reading values from target...') | ||
raw_result = target.read_tree_values_flat(dirname) | ||
result = {os.path.basename(k): v for k, v in raw_result.items()} | ||
except Exception as ex: | ||
raise TargetStableError('Error while processing the tree!') from ex | ||
finally: | ||
print(f'{method_name}: removing {dirname}...') | ||
target.remove(dirname) | ||
|
||
self.assertEqual({k: v.strip() | ||
for k, v in data.items()}, | ||
result) | ||
|
||
print(f'{method_name}: removing {target.working_directory}...') | ||
target.remove(target.working_directory) | ||
|
||
def create_targets(): | ||
targets = [] | ||
|
||
a_target = AndroidTarget(connection_settings={'device': 'emulator-5554'}, | ||
working_directory='/data/local/tmp/devlib-target') | ||
targets.append(a_target) | ||
|
||
l_target = LinuxTarget(connection_settings={'host': 'example.com', | ||
'username': 'username', | ||
'password': 'password'}, | ||
working_directory='/tmp/devlib-target') | ||
targets.append(l_target) | ||
|
||
ll_target = LocalLinuxTarget(connection_settings={'unrooted': True}, | ||
working_directory='/tmp/devlib-target') | ||
targets.append(ll_target) | ||
|
||
return targets | ||
|
||
method_name = self.__class__.test_read_multiline_values.__qualname__ | ||
|
||
targets = create_targets() | ||
for target in targets: | ||
run_test(target) | ||
|