Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Devlib Test Suite

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
types: [opened, synchronize, reopened, ready_for_review]
schedule:
- cron: 0 2 * * *
# Allows runing this workflow manually from the Actions tab
workflow_dispatch:

jobs:
Run-PyTest-Tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: git-bash
uses: pkg-src/github-action-git-bash@v1.1
- name: Install dependencies
run: |
python -m pip install --upgrade pip
cd $GITHUB_WORKSPACE && pip install .[test]
pip install pytest
- name: Run pytest tests
run: |
pytest
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
'doc': ['sphinx'],
'monsoon': ['python-gflags'],
'acme': ['pandas', 'numpy'],
'test': ['pytest'],
},
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
Expand Down
140 changes: 140 additions & 0 deletions tests/test_local_linux_target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import os
import tempfile
import pytest

from devlib import LocalLinuxTarget


@pytest.fixture(scope="class")
def target():
target = LocalLinuxTarget(connection_settings={'unrooted': True})
yield target
target.disconnect()


class TestLocalLinuxMethods:
'''
Verify basic functionality of LocalTarget and LocalConnection
'''

def test_connection(self, target):
target.check_connection()

def test_echo(self, target):
expected = 'A TEST STRING'
assert target.execute('echo {}'.format(expected)).strip() == expected

def test_busybox_echo(self, target):
assert target.file_exists(target.busybox)
expected = 'A TEST STRING'
assert target.execute('{} echo {}'.format(target.busybox, expected)).strip() == expected

def test_background_command(self, target):
expected = 'A TEST STRING'
bg_cmd = target.background('echo {}'.format(expected))
assert bg_cmd
bg_cmd.wait()
assert bg_cmd.stdout.read().strip().decode('utf-8') == expected

def test_get_work_directory(self, target):
assert target.get_workpath('test')

def test_push(self, target):
with tempfile.NamedTemporaryFile() as src_file:
dst = target.get_workpath('test')
target.push(src_file.name, dst)
assert target.file_exists(dst)
target.remove(dst)

def test_pull(self, target):
src = target.get_workpath('test')
target.execute('touch {}'.format(src))
dst = tempfile.NamedTemporaryFile().name
target.pull(src, dst)
assert os.path.exists(dst)
os.remove(dst)
target.remove(dst)

def test_installation(self, target):
bin_name = 'test_binary'
with tempfile.NamedTemporaryFile() as src_file:
path = target.install(src_file.name, with_name=bin_name)
assert path
assert target.is_installed(bin_name)
target.uninstall(bin_name)

def test_shutils_setup(self, target):
assert target.shutils

def test_directories_exists(self, target):
assert target.directory_exists(target.working_directory)
assert target.directory_exists(target.executables_directory)


class TestLocalTargetAttributes:

'''
Exercise target attributes, we don't know the machine the
tests will be running on, only root status, so just check the
call executes correctly.
'''

def test_core_name(self, target):
assert target.core_names

def test_clusters(self, target):
assert target.core_names

def test_is_connected(self, target):
assert target.is_connected

def test_not_connected_as_root(self, target):
assert not target.connected_as_root

def test_is_unrooted(self, target):
assert not target.is_rooted

def test_needs_su(self, target):
assert not target.needs_su

def test_kernel_version(self, target):
assert target.kernel_version

def test_hostid(self, target):
assert target.hostid is not None

def test_hostname(self, target):
assert target.hostname is not None

def test_os_version(self, target):
assert target.os_version is not None

def test_model(self, target):
target.model # Likely to be None

def test_abi(self, target):
assert target.abi is not None

def test_cpuinfo(self, target):
assert target.cpuinfo is not None

def test_number_of_cpus(self, target):
assert target.number_of_cpus is not None

def test_number_of_nodes(self, target):
assert target.number_of_nodes is not None

def test_list_nodes_cpus(self, target):
assert target.list_nodes_cpus is not None

def test_config(self, target):
assert target.config is not None

def test_user(self, target):
assert target.user is not None

def test_page_size_kb(self, target):
assert target.user is not None

def test_page_size_kb(self, target):
assert target.user is not None