• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ARMmbed / mbed-os-tools / #457

24 Aug 2024 09:15PM UTC coverage: 0.0% (-59.9%) from 59.947%
#457

push

coveralls-python

web-flow
Merge 7c6dbce13 into c467d6f14

0 of 4902 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/mbed_os_tools/test/host_tests_conn_proxy/conn_primitive_fastmodel.py
1
# Copyright (c) 2018, Arm Limited and affiliates.
2
# SPDX-License-Identifier: Apache-2.0
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16
import telnetlib
×
17
import socket
×
18
from .conn_primitive import ConnectorPrimitive, ConnectorPrimitiveException
×
19

20

21
class FastmodelConnectorPrimitive(ConnectorPrimitive):
×
22
    def __init__(self, name, config):
×
23
        ConnectorPrimitive.__init__(self, name)
×
24
        self.config          = config
×
25
        self.fm_config      = config.get('fm_config', None)
×
26
        self.platform_name   = config.get('platform_name', None)
×
27
        self.image_path      = config.get('image_path', None)
×
28
        self.polling_timeout = int(config.get('polling_timeout', 60))
×
29

30
        # FastModel Agent tool-kit
31
        self.fm_agent_module = None
×
32
        self.resource = None
×
33

34
        # Initialize FastModel
35
        if self.__fastmodel_init():
×
36

37
            # FastModel Launch load and run, equivalent to DUT connection, flashing and reset...
38
            self.__fastmodel_launch()
×
39
            self.__fastmodel_load(self.image_path)
×
40
            self.__fastmodel_run()
×
41

42

43
    def __fastmodel_init(self):
×
44
        """! Initialize models using fm_agent APIs """
45
        self.logger.prn_inf("Initializing FastModel...")
×
46

47
        try:
×
48
            self.fm_agent_module = __import__("fm_agent")
×
49
        except ImportError as e:
×
50
            self.logger.prn_err("unable to load mbed-fastmodel-agent module. Check if the module install correctly.")
×
51
            self.fm_agent_module = None
×
52
            self.logger.prn_err("Importing failed : %s" % str(e))
×
53
            raise ConnectorPrimitiveException("Importing failed : %s" % str(e))
×
54
        try:
×
55
            self.resource = self.fm_agent_module.FastmodelAgent(logger=self.logger)
×
56
            self.resource.setup_simulator(self.platform_name,self.fm_config)
×
57
            if self.__resource_allocated():
×
58
                pass
×
59
        except self.fm_agent_module.SimulatorError as e:
×
60
            self.logger.prn_err("module fm_agent, create() failed: %s"% str(e))
×
61
            raise ConnectorPrimitiveException("FastModel Initializing failed as throw SimulatorError!")
×
62

63
        return True
×
64

65
    def __fastmodel_launch(self):
×
66
        """! launch the FastModel"""
67
        self.logger.prn_inf("Launching FastModel...")
×
68
        try:
×
69
            if not self.resource.start_simulator():
×
70
                raise ConnectorPrimitiveException("FastModel running failed, run_simulator() return False!")
×
71
        except self.fm_agent_module.SimulatorError as e:
×
72
            self.logger.prn_err("start_simulator() failed: %s"% str(e))
×
73
            raise ConnectorPrimitiveException("FastModel launching failed as throw FastModelError!")
×
74

75
    def __fastmodel_run(self):
×
76
        """! Use fm_agent API to run the FastModel """
77
        self.logger.prn_inf("Running FastModel...")
×
78
        try:
×
79
            if not self.resource.run_simulator():
×
80
                raise ConnectorPrimitiveException("FastModel running failed, run_simulator() return False!")
×
81
        except self.fm_agent_module.SimulatorError as e:
×
82
            self.logger.prn_err("run_simulator() failed: %s"% str(e))
×
83
            raise ConnectorPrimitiveException("FastModel running failed as throw SimulatorError!")
×
84

85
    def __fastmodel_load(self, filename):
×
86
        """! Use fm_agent API to load image to FastModel, this is functional equivalent to flashing DUT"""
87
        self.logger.prn_inf("loading FastModel with image '%s'..."% filename)
×
88
        try:
×
89
            if not self.resource.load_simulator(filename):
×
90
                raise ConnectorPrimitiveException("FastModel loading failed, load_simulator() return False!")
×
91
        except self.fm_agent_module.SimulatorError as e:
×
92
            self.logger.prn_err("run_simulator() failed: %s"% str(e))
×
93
            raise ConnectorPrimitiveException("FastModel loading failed as throw SimulatorError!")
×
94

95
    def __resource_allocated(self):
×
96
        """! Check whether FastModel resource been allocated
97
           @return True or throw an exception
98
        """
99
        if self.resource:
×
100
            return True
×
101
        else:
102
            self.logger.prn_err("FastModel resource not available!")
×
103
            return False
×
104

105
    def read(self, count):
×
106
        """! Read data from DUT, count is not used for FastModel"""
107
        date = str()
×
108
        if self.__resource_allocated():
×
109
            try:
×
110
                data = self.resource.read()
×
111
            except self.fm_agent_module.SimulatorError as e:
×
112
                self.logger.prn_err("FastmodelConnectorPrimitive.read() failed: %s"% str(e))
×
113
            else:
114
                return data
×
115
        else:
116
            return False
×
117
    def write(self, payload, log=False):
×
118
        """! Write 'payload' to DUT"""
119
        if self.__resource_allocated():
×
120
            if log:
×
121
                self.logger.prn_txd(payload)
×
122
            try:
×
123
                self.resource.write(payload)
×
124
            except self.fm_agent_module.SimulatorError as e:
×
125
                self.logger.prn_err("FastmodelConnectorPrimitive.write() failed: %s"% str(e))
×
126
            else:
127
                return True
×
128
        else:
129
            return False
×
130

131
    def flush(self):
×
132
        """! flush not supported in FastModel_module"""
133
        pass
×
134

135
    def connected(self):
×
136
        """! return whether FastModel is connected """
137
        if self.__resource_allocated():
×
138
            return self.resource.is_simulator_alive
×
139
        else:
140
            return False
×
141

142
    def finish(self):
×
143
        """! shutdown the FastModel and release the allocation """
144
        if self.__resource_allocated():
×
145
            try:
×
146
                self.resource.shutdown_simulator()
×
147
                self.resource = None
×
148
            except self.fm_agent_module.SimulatorError as e:
×
149
                self.logger.prn_err("FastmodelConnectorPrimitive.finish() failed: %s"% str(e))
×
150

151
    def reset(self):
×
152
        if self.__resource_allocated():
×
153
            try:
×
154
                if not self.resource.reset_simulator():
×
155
                    self.logger.prn_err("FastModel reset failed, reset_simulator() return False!")
×
156
            except self.fm_agent_module.SimulatorError as e:
×
157
                self.logger.prn_err("FastmodelConnectorPrimitive.reset() failed: %s"% str(e))
×
158

159
    def __del__(self):
×
160
        self.finish()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc