from _core.constants import DeviceLabelType
from _core.constants import SchedulerType
from _core.constants import HostDrivenTestType
from _core.constants import ListenerType
from _core.executor.concurrent import Concurrent
from _core.executor.concurrent import DriversThread
from _core.executor.concurrent import QueueMonitorThread
from _core.executor.source import TestSetSource
from _core.executor.source import find_test_descriptors
from _core.executor.source import find_testdict_descriptors
from _core.logger import platform_logger
from _core.logger import add_task_file_handler
from _core.logger import remove_task_file_handler

__all__ = ["Scheduler"]
LOG = platform_logger("Scheduler")


@Plugin(type=Plugin.SCHEDULER, id=SchedulerType.scheduler)
class Scheduler(object):
    """
    The Scheduler is the main entry point for client code that wishes to
    discover and execute tests.
    """
    # factory params
    is_execute = True
    terminate_result = queue.Queue()
    upload_address = ""
    task_type = ""
    task_name = ""
    mode = ""
Exemple #2
0
from _core.constants import SchedulerType
from _core.constants import ToolCommandType
from _core.environment.manager_env import EnvironmentManager
from _core.exception import ParamError
from _core.exception import ExecuteTerminate
from _core.executor.request import Task
from _core.executor.scheduler import Scheduler
from _core.logger import platform_logger
from _core.plugin import Plugin
from _core.plugin import get_plugin
from _core.utils import SplicingAction
from _core.utils import get_instance_name

__all__ = ["Console"]

LOG = platform_logger("Console")
try:
    if platform.system() != 'Windows':
        import readline
except ModuleNotFoundError:
    LOG.warning("readline module is not exist.")


class Console(object):
    """
    Class representing an console for executing test.
    Main xDevice console providing user with the interface to interact
    """
    __instance = None

    def __new__(cls, *args, **kwargs):
import os
import shutil
import time
import zipfile
from ast import literal_eval

from _core.logger import platform_logger
from _core.report.encrypt import check_pub_key_exist
from _core.report.encrypt import do_rsa_encrypt
from _core.report.encrypt import get_file_summary
from _core.report.reporter_helper import DataHelper
from _core.report.reporter_helper import VisionHelper
from _core.report.reporter_helper import ReportConstant

LOG = platform_logger("ResultReporter")


class ResultReporter:
    def __init__(self, report_path, task_info):
        self.report_path = report_path
        self.task_info = task_info
        self.data_helper = DataHelper()
        self.vision_helper = VisionHelper()
        self.summary_data_path = os.path.join(
            self.report_path, ReportConstant.summary_data_report)
        self.exec_info = task_info

    def generate_reports(self):
        LOG.info("")
        LOG.info("**************************************************")
from _core.plugin import Plugin
from _core.plugin import get_plugin
from _core.logger import platform_logger
from _core.report.reporter_helper import DataHelper
from _core.testkit.json_parser import JsonParser
from _core.testkit.kit_lite import DeployKit
from _core.utils import get_config_value
from _core.utils import get_kit_instances
from _core.utils import check_result_report
from _core.utils import get_device_log_file
from _core.utils import get_filename_extension
from _core.utils import get_file_absolute_path
from _core.utils import get_test_component_version

__all__ = ["CppTestDriver", "CTestDriver", "init_remote_server"]
LOG = platform_logger("DriversLite")
FAILED_RUN_TEST_ATTEMPTS = 2


def get_nfs_server(request):
    config_manager = UserConfigManager(env=request.config.test_environment)
    remote_info = config_manager.get_user_config("testcases/server",
                                                 filter_name="NfsServer")
    if not remote_info:
        err_msg = "The name of remote nfs server does not match"
        LOG.error(err_msg)
        raise TypeError(err_msg)
    return remote_info


def init_remote_server(lite_instance, request=None):
from _core.constants import CKit
from _core.constants import ComType
from _core.constants import DeviceLiteKernel
from _core.constants import DeviceTestType
from _core.exception import LiteDeviceMountError
from _core.exception import ParamError
from _core.interface import ITestKit
from _core.utils import get_config_value
from _core.utils import get_file_absolute_path
from _core.utils import get_local_ip
from _core.utils import get_test_component_version
from _core.exception import LiteDeviceConnectError
from _core.constants import DeviceLabelType

__all__ = ["DeployKit", "MountKit", "RootFsKit", "QueryKit"]
LOG = platform_logger("KitLite")

RESET_CMD = "0xEF, 0xBE, 0xAD, 0xDE, 0x0C, 0x00, 0x87, 0x78, 0x00, 0x00, " \
            "0x61, 0x94"


@Plugin(type=Plugin.TEST_KIT, id=CKit.deploy)
class DeployKit(ITestKit):
    def __init__(self):
        self.burn_file = ""
        self.burn_command = ""
        self.timeout = ""
        self.paths = ""

    def __check_config__(self, config):
        self.timeout = str(
Exemple #6
0
# 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 os
import time
from enum import Enum
from threading import RLock

from _core.logger import platform_logger
from _core.report.encrypt import check_pub_key_exist
from _core.report.reporter_helper import DataHelper
from _core.report.reporter_helper import ReportConstant

LOG = platform_logger("SuiteReporter")
SUITE_REPORTER_LOCK = RLock()


class ResultCode(Enum):
    UNKNOWN = -1010
    PASSED = 0
    FAILED = 1
    SKIPPED = 2


class SuiteReporter:
    suite_list = []
    suite_report_result = []
    failed_case_list = []
#

import datetime
import os

from _core.exception import ParamError
from _core.executor.source import TestSource
from _core.logger import platform_logger
from _core.plugin import Config
from _core.plugin import Plugin
from _core.plugin import get_plugin
from _core.testkit.json_parser import JsonParser
from _core.utils import get_kit_instances

__all__ = ["Descriptor", "Task", "Request"]
LOG = platform_logger("Request")


class Descriptor:
    """
    The descriptor for a test or suite
    """
    def __init__(self, uuid=None, name=None, source=None, container=False):
        self.unique_id = uuid
        self.display_name = name
        self.tags = {}
        self.source = source
        self.parent = None
        self.children = []
        self.container = container
from _core.constants import DeviceOsType
from _core.constants import ComType
from _core.constants import DeviceLabelType
from _core.environment.dmlib_lite import LiteHelper
from _core.exception import LiteDeviceConnectError
from _core.exception import ParamError
from _core.exception import DeviceError
from _core.interface import IDevice
from _core.exception import ExecuteTerminate
from _core.logger import platform_logger
from _core.environment.manager_env import DeviceAllocationState
from _core.plugin import Plugin
from _core.utils import exec_cmd

LOG = platform_logger("DeviceLite")
TIMEOUT = 90
HDC = "litehdc.exe"


def get_hdc_path():
    from xdevice import Variables
    user_path = os.path.join(Variables.exec_dir, "resource/tools")
    top_user_path = os.path.join(Variables.top_dir, "config")
    config_path = os.path.join(Variables.res_dir, "config")
    paths = [user_path, top_user_path, config_path]

    file_path = ""
    for path in paths:
        if os.path.exists(os.path.abspath(os.path.join(path, HDC))):
            file_path = os.path.abspath(os.path.join(path, HDC))
Exemple #9
0
# limitations under the License.
#

import os
import shutil
import threading
import time
from concurrent.futures import ThreadPoolExecutor
from concurrent.futures import wait

from _core.executor.request import Request
from _core.logger import platform_logger
from _core.plugin import Config
from _core.utils import get_instance_name

LOG = platform_logger("Concurrent")


class Concurrent:
    @classmethod
    def executor_callback(cls, worker):
        worker_exception = worker.exception()
        if worker_exception:
            LOG.error("Worker return exception: {}".format(worker_exception))

    @classmethod
    def concurrent_execute(cls, func, params_list, max_size=8):
        """
        Provider the ability to execute target function concurrently
        :param func: target function name
        :param params_list: the list of params in these target functions
from _core.plugin import Plugin
from _core.constants import ListenerType
from _core.interface import LifeCycle
from _core.interface import IListener
from _core.logger import platform_logger
from _core.report.result_reporter import ResultReporter
from _core.report.suite_reporter import SuiteReporter
from _core.report.suite_reporter import ResultCode
from _core.report.encrypt import check_pub_key_exist

__all__ = ["LogListener", "ReportListener", "UploadListener",
           "CollectingTestListener", "CollectingLiteGTestListener",
           "CaseResult", "SuiteResult", "SuitesResult", "StateRecorder",
           "TestDescription"]

LOG = platform_logger("Listener")


@dataclass
class CaseResult:
    index = ""
    code = ResultCode.FAILED.value
    test_name = None
    test_class = None
    stacktrace = ""
    run_time = 0
    is_completed = False
    num_tests = 0
    current = 0

    def is_running(self):
Exemple #11
0
import time

from _core.config.config_manager import UserConfigManager
from _core.constants import DeviceOsType
from _core.constants import ManagerType
from _core.environment.manager_env import DeviceAllocationState
from _core.exception import LiteDeviceConnectError
from _core.exception import ParamError
from _core.plugin import Plugin
from _core.plugin import get_plugin
from _core.interface import IDeviceManager
from _core.logger import platform_logger

__all__ = ["ManagerLite"]

LOG = platform_logger("ManagerLite")


@Plugin(type=Plugin.MANAGER, id=ManagerType.lite_device)
class ManagerLite(IDeviceManager):
    """
    Class representing device manager
    managing the set of available devices for testing
    """
    def __init__(self):
        self.devices_list = []

    def init_environment(self, environment=""):
        device_lite = get_plugin(plugin_type=Plugin.DEVICE,
                                 plugin_id=DeviceOsType.lite)[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 json
import os

from _core.exception import ParamError
from _core.logger import platform_logger
from _core.plugin import Config

__all__ = ["JsonParser"]
LOG = platform_logger("JsonParser")


class JsonParser:
    """
    This class parses json files or string, sample:
    {
        "description": "Config for lite cpp test cases",
        "environment": [
            {
                "type": "device",
                "label": "ipcamera"
            }
        ],
        "kits": [
            {
_CTEST_END_TEST_RUN_TAG = "Framework finished."
_CTEST_SUITE_TEST_RUN_TAG = "Start to run test suite:"
_CTEST_SUITE_TIME_RUN_TAG = "Run test suite "
_CTEST_SETUP_TAG = "setup"
_CTEST_RUN_TAG = "-----------------------"

_TEST_PASSED_LOWER = "test pass"

_COMPILE_PASSED = "compile PASSED"
_COMPILE_PARA = r"(.* compile .*)"

_PRODUCT_PARA = r"(.*The .* is .*)"
_PRODUCT_PARA_START = r"To Obtain Product Params Start"
_PRODUCT_PARA_END = r"To Obtain Product Params End"

LOG = platform_logger("ParserLite")


@Plugin(type=Plugin.PARSER, id=ParserType.cpp_test_lite)
class CppTestParserLite(IParser):
    def __init__(self):
        self.state_machine = StateRecorder()
        self.suite_name = ""
        self.listeners = []
        self.product_params = {}
        self.is_params = False

    def get_suite_name(self):
        return self.suite_name

    def get_listeners(self):
Exemple #14
0
from _core.constants import DeviceLabelType
from _core.driver.drivers_lite import init_remote_server
from _core.exception import DeviceError
from _core.exception import ParamError
from _core.exception import ReportException
from _core.exception import ExecuteTerminate
from _core.interface import IDriver
from _core.logger import platform_logger
from _core.plugin import Plugin
from _core.testkit.json_parser import JsonParser
from _core.utils import get_config_value
from _core.utils import get_kit_instances
from _core.utils import check_result_report
from _core.report.suite_reporter import SuiteReporter

LOG = platform_logger("DeviceTest")


def start_task(test_file, configs, device, logger):
    from xdevice import Variables
    # insert& devicetest path for loading devicetest module
    devicetest_module = os.path.join(Variables.modules_dir, "_devicetest")
    if os.path.exists(devicetest_module):
        sys.path.insert(1, devicetest_module)

    if configs["testcases_path"]:
        sys.path.insert(1, configs["testcases_path"])

    from _devicetest.devicetest.main import DeviceTest
    device_test = DeviceTest(test_list=test_file, configs=configs,
                             devices=[device], log=logger)
from _core.exception import LiteDeviceExecuteCommandError
from _core.logger import platform_logger

__all__ = ["generate_report", "LiteHelper"]

CPP_TEST_STANDARD_SIGN = "[==========]"
CPP_TEST_END_SIGN = "Global test environment tear-down"
CPP_SYS_STANDARD_SIGN = " #"
CPP_ERR_MESSAGE = "[ERR]No such file or directory: "

TIMEOUT = 90
CTEST_STANDARD_SIGN = "Start to run test suite"
AT_CMD_ENDS = "OK"
CTEST_END_SIGN = "Framework finished."
PATTERN = re.compile(r'\x1B(\[([0-9]{1,2}(;[0-9]{1,2})*)?m)*')
LOG = platform_logger("DmlibLite")


def check_read_test_end(result=None, input_command=None):
    if input_command not in result:
        return False
    index = result.find(input_command) + len(input_command)
    result_output = result[index:]
    if input_command.startswith("./"):
        if result_output.find(CPP_TEST_STANDARD_SIGN) != -1:
            if result_output.count(CPP_TEST_STANDARD_SIGN) == 2 or \
                    result_output.find(CPP_TEST_END_SIGN) != -1:
                return True
        if result_output.find(CPP_TEST_STANDARD_SIGN) == -1 and \
                ("test pass" in result_output.lower() or
                 "test fail" in result_output.lower()):
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os
import hashlib

from _core.logger import platform_logger

__all__ = [
    "check_pub_key_exist", "do_rsa_encrypt", "do_rsa_decrypt",
    "generate_key_file", "get_file_summary"
]

PUBLIC_KEY_FILE = "config/pub.key"
LOG = platform_logger("Encrypt")


def check_pub_key_exist():
    from xdevice import Variables
    if Variables.report_vars.pub_key_file is not None:
        if Variables.report_vars.pub_key_file == "":
            return False
        if not os.path.exists(Variables.report_vars.pub_key_file):
            Variables.report_vars.pub_key_file = None
            return False
        return True

    pub_key_path = os.path.join(Variables.exec_dir, PUBLIC_KEY_FILE)
    if os.path.exists(pub_key_path):
        Variables.report_vars.pub_key_file = pub_key_path
#
#     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 os
import xml.etree.ElementTree as ElementTree

from _core.logger import platform_logger

LOG = platform_logger("ResourceManager")
DEFAULT_TIMEOUT = "300"


class ResourceManager(object):
    def __init__(self):
        pass

    def get_resource_data(self, xml_filepath, target_name):
        data_dic = {}
        if os.path.exists(xml_filepath):
            data_dic = self._parse_test_xml_file(xml_filepath, target_name)
        return data_dic

    def _parse_test_xml_file(self, filepath, targetname):
        data_dic = {}
import argparse
import subprocess
import signal
import uuid
import json
from tempfile import NamedTemporaryFile

from _core.executor.listener import SuiteResult
from _core.driver.parser_lite import ShellHandler
from _core.exception import ParamError
from _core.logger import platform_logger
from _core.report.suite_reporter import SuiteReporter
from _core.plugin import get_plugin
from _core.plugin import Plugin

LOG = platform_logger("Utils")


def get_filename_extension(file_path):
    _, fullname = os.path.split(file_path)
    filename, ext = os.path.splitext(fullname)
    return filename, ext


def unique_id(type_name, value):
    return "{}_{}_{:0>8}".format(type_name, value,
                                 str(uuid.uuid1()).split("-")[0])


def start_standing_subprocess(cmd, pipe=subprocess.PIPE, return_result=False):
    """Starts a non-blocking subprocess that is going to continue running after
Exemple #19
0
TEST_TYPE_DICT = {"DEX": DeviceTestType.dex_test,
                  "HAP": DeviceTestType.hap_test,
                  "APK": DeviceTestType.hap_test,
                  "PYT": HostDrivenTestType.device_test,
                  "JST": DeviceTestType.jsunit_test,
                  "CXX": DeviceTestType.cpp_test,
                  "BIN": DeviceTestType.lite_cpp_test}
EXT_TYPE_DICT = {".dex": DeviceTestType.dex_test,
                 ".hap": DeviceTestType.hap_test,
                 ".apk": DeviceTestType.hap_test,
                 ".py": HostDrivenTestType.device_test,
                 ".js": DeviceTestType.jsunit_test,
                 ".bin": DeviceTestType.lite_cpp_test,
                 "default": DeviceTestType.cpp_test}
MODULE_CONFIG_SUFFIX = ".json"
LOG = platform_logger("TestSource")


def find_test_descriptors(config):
    if config.testfile == "" and config.testlist == "" and config.task == "":
        return None

    # get test sources
    testcases_dirs = _get_testcases_dirs(config)
    test_sources = _get_test_sources(config, testcases_dirs)
    LOG.debug("test sources: %s", test_sources)

    # normalize test sources
    test_sources = _normalize_test_sources(testcases_dirs, test_sources)

    # make test descriptors
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os
import platform
import time
from ast import literal_eval
from dataclasses import dataclass
from xml.etree import ElementTree

from _core.logger import platform_logger
from _core.report.encrypt import check_pub_key_exist
from _core.report.encrypt import do_rsa_encrypt

LOG = platform_logger("ReporterHelper")


@dataclass
class ReportConstant:
    # report name constants
    summary_data_report = "summary_report.xml"
    summary_vision_report = "summary_report.html"
    details_vision_report = "details_report.html"
    failures_vision_report = "failures_report.html"
    summary_ini = "summary.ini"
    summary_report_hash = "summary_report.hash"
    title_name = "title_name"
    summary_title = "Summary Report"
    details_title = "Details Report"
    failures_title = "Failures Report"