Skip to content

Commit

Permalink
[LETEST-4712] Cleanup static analysis in public/legato/basics/develop…
Browse files Browse the repository at this point in the history
…/definitionFiles

Resolves: LETEST-4712
Change-Id: I539cfcc360d3a9c1e66cb63f90924ea72f7be25c
  • Loading branch information
Pham Minh Tien authored and Wilson (Wei Chao) Lin committed Jun 25, 2020
1 parent 47f2823 commit ea104c1
Show file tree
Hide file tree
Showing 9 changed files with 1,182 additions and 1,240 deletions.
72 changes: 34 additions & 38 deletions legato/basics/develop/definitionFiles/host/test_adef_binding.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
""" @package applicationModule Application Definition Files test
"""@package applicationModule Application Definition Files test.
Set of functions to test the Legato application definition files
Set of functions to test the Legato application definition files.
"""
import pytest
import os
import time
import swilog
import pytest

__copyright__ = 'Copyright (C) Sierra Wireless Inc.'
# =================================================================================================
__copyright__ = "Copyright (C) Sierra Wireless Inc."
# ====================================================================================
# Constants and Globals
# =================================================================================================
# ====================================================================================
# Determine the resources folder (legato apps)
TEST_RESOURCES = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'resources')
TEST_RESOURCES = os.path.join(os.path.abspath(os.path.dirname(__file__)), "resources")


# =================================================================================================
# ====================================================================================
# Functions
# =================================================================================================
# ====================================================================================
def verify_run_correctly(legato, should_fail=False):
"""
Verify the application is running properly or not
"""Verify the application is running properly or not.
Args:
legato: fixture to call useful functions regarding legato
should_fail: the application is run properly or not
"""
expected = not should_fail

expected = True if should_fail is False else False
rsp = legato.find_in_target_log("Message received: USER1")
if rsp != expected:
swilog.error("USER1 binding")
Expand All @@ -39,18 +36,21 @@ def verify_run_correctly(legato, should_fail=False):
swilog.error("USER2 binding")


# =================================================================================================
# ====================================================================================
# Local fixtures
# =================================================================================================
@pytest.fixture(params=[("binded", "", False, False),
("unbinded", "", True, False),
("wrongbind", "", True, False),
("dupbinding", "", True, False),
("client", "server", False, False),
("requires", "", False, True)])
# ====================================================================================
@pytest.fixture(
params=[
("binded", "", False, False),
("unbinded", "", True, False),
("wrongbind", "", True, False),
("dupbinding", "", True, False),
("client", "server", False, False),
("requires", "", False, True),
]
)
def init_cleanup_test(legato, request, tmpdir):
"""
Initial and clean up the test.
"""Init and clean up the test.
Args:
legato: fixture to call useful functions regarding legato
Expand All @@ -64,7 +64,6 @@ def init_cleanup_test(legato, request, tmpdir):
make_should_fail: expected status of the building application result
run_fail: expected status that the application is run
properly or not
"""
app_name = request.param[0]
app_name2 = request.param[1]
Expand All @@ -90,19 +89,18 @@ def init_cleanup_test(legato, request, tmpdir):
legato.clean(app_name2)


# =================================================================================================
# ====================================================================================
# Test functions
# =================================================================================================
def L_ADEF_0001(legato, tmpdir, init_cleanup_test):
"""
Verify that applications are built and run properly or not
# ====================================================================================
@pytest.mark.usefixtures("tmpdir")
def L_ADEF_0001(legato, init_cleanup_test):
"""Verify that applications are built and run properly or not.
Args:
legato: fixture to call useful functions regarding legato
tmpdir: fixture to provide a temporary directory
unique to the test invocation
init_cleanup_test: fixture to init and clean up the test
"""
# Read returned values from the fixture
app_name = init_cleanup_test[0]
Expand All @@ -117,17 +115,15 @@ def L_ADEF_0001(legato, tmpdir, init_cleanup_test):
test_path = "%s/adef/binding" % TEST_RESOURCES

# Make the first application
legato.make(os.path.join(test_path, app_name),
"",
should_fail=make_should_fail)
legato.make(os.path.join(test_path, app_name), "", should_fail=make_should_fail)

# Make the second application
if app_name2 != "":
legato.make(os.path.join(test_path, app_name2),
"",
should_fail=make_should_fail)
legato.make(
os.path.join(test_path, app_name2), "", should_fail=make_should_fail
)

if make_should_fail is True:
if make_should_fail:
swilog.info("Make app failed as expected.")
return

Expand Down
41 changes: 18 additions & 23 deletions legato/basics/develop/definitionFiles/host/test_adef_link.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,62 @@
""" @package applicationModule Application Definition Files test
"""@package applicationModule Application Definition Files test.
Set of functions to test the Legato application definition files
Set of functions to test the Legato application definition files.
"""
import os
import pytest
import swilog

__copyright__ = 'Copyright (C) Sierra Wireless Inc.'
# ==================================================================================================
__copyright__ = "Copyright (C) Sierra Wireless Inc."
# ====================================================================================
# Constants and Globals
# ==================================================================================================
# ====================================================================================
# Determine the resources folder (legato apps)
TEST_RESOURCES = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'resources')
TEST_RESOURCES = os.path.join(os.path.abspath(os.path.dirname(__file__)), "resources")

APP_NAME = "link_app"
APP_PATH = "%s/adef/link" % TEST_RESOURCES


# ==================================================================================================
# ====================================================================================
# Functions
# ==================================================================================================
# ====================================================================================
def verify_run_correctly(legato):
"""
Verify the application is run correctly
"""Verify the application is run correctly.
Args:
legato: fixture to call useful functions regarding legato
"""

rsp = legato.find_in_target_log("Server started")
if rsp is True:
if rsp:
swilog.info("Server started.")
else:
swilog.error("Server did not start.")

rsp = legato.find_in_target_log("foo_f is called")
if rsp is True:
if rsp:
swilog.info("C1 started and successfully called foo_f on the server.")
else:
swilog.error("C1 may not have called.")

rsp = legato.find_in_target_log("bar_f is called")
if rsp is True:
if rsp:
swilog.info("C2 started and successfully called bar_f on the server.")
else:
swilog.error("C2 may not have called bar_f on the server.")


# ==================================================================================================
# ====================================================================================
# Test functions
# ==================================================================================================
def L_ADEF_0006(legato, app_leg):
"""
check link (Validate defect #2472)
# ====================================================================================
@pytest.mark.usefixtures("app_leg")
def L_ADEF_0006(legato):
"""Check link (Validate defect #2472).
Args:
legato: fixture to call useful functions regarding legato
app_leg: fixture to make install application
and cleanup it after the test
"""

verify_run_correctly(legato)

failed_testcases_list = swilog.get_error_list()
Expand Down
46 changes: 20 additions & 26 deletions legato/basics/develop/definitionFiles/host/test_adef_version.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
""" @package applicationModule Application Definition Files test
"""@package applicationModule Application Definition Files test.
Set of functions to test the Legato application definition files
Set of functions to test the Legato application definition files.
"""
import pytest
import os
import swilog
import pytest

__copyright__ = 'Copyright (C) Sierra Wireless Inc.'
# =================================================================================================
__copyright__ = "Copyright (C) Sierra Wireless Inc."
# ====================================================================================
# Constants and Globals
# =================================================================================================
# ====================================================================================
# Determine the resources folder (legato apps)
TEST_RESOURCES = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'resources')
TEST_RESOURCES = os.path.join(os.path.abspath(os.path.dirname(__file__)), "resources")
APP_NAME = "version"
VERSION = "14.07.0"
VERSION_APPEND = "Beta.rc1"


# =================================================================================================
# ====================================================================================
# Local fixtures
# =================================================================================================
# ====================================================================================
@pytest.fixture(params=["", VERSION_APPEND])
def init_cleanup_app_version(request, legato, tmpdir):
"""
Make application with append version
Install application
"""Make application with append version Install application.
Clean up after the test.
Args:
Expand All @@ -34,15 +32,14 @@ def init_cleanup_app_version(request, legato, tmpdir):
tmpdir: fixture to provide a temporary directory
unique to the test invocation
"""

version_append = request.param

# Go to temp directory
os.chdir(str(tmpdir))

make_option = "--append-to-version=%s" % version_append \
if version_append != "" \
else ""
make_option = (
"--append-to-version=%s" % version_append if version_append != "" else ""
)
app_path = "%s/adef/version" % TEST_RESOURCES

# Make and install application
Expand All @@ -53,26 +50,23 @@ def init_cleanup_app_version(request, legato, tmpdir):
legato.clean(APP_NAME)


# =================================================================================================
# ====================================================================================
# Test functions
# =================================================================================================
# ====================================================================================
def L_ADEF_0004(legato, init_cleanup_app_version):
"""
Test append version in application definition files
"""Test append version in application definition files.
Args:
legato: fixture to call useful functions regarding legato
init_cleanup_app_version: fixture to initial and cleanup the test
"""

version_append = init_cleanup_app_version["version_append"]
extra = "no" if version_append == "" else ""

swilog.step("Test %s appended" % extra)

version_to_check = "%s" % VERSION \
if version_append == "" \
else "%s.%s" % (VERSION, version_append)
version_to_check = (
"%s" % VERSION if version_append == "" else "%s.%s" % (VERSION, version_append)
)

legato.verify_app_version(APP_NAME, APP_NAME + " " + version_to_check)
Loading

0 comments on commit ea104c1

Please sign in to comment.