1 # Copyright 2015 Intel Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 """Class wrapper for controlling a TestPMD instance.
17 Wraps ``testpmd`` process.
25 from conf import settings
26 from tools import tasks
28 _TESTPMD_PROMPT = 'Done'
30 _TESTPMD_BIN = os.path.join(
31 settings.getValue('RTE_SDK'), settings.getValue('RTE_TARGET'),
34 _LOG_FILE_VSWITCHD = os.path.join(
35 settings.getValue('LOG_DIR'), settings.getValue('LOG_FILE_VSWITCHD'))
37 class TestPMDProcess(tasks.Process):
38 """Class wrapper for controlling a TestPMD instance.
40 Wraps ``testpmd`` process.
42 _logfile = _LOG_FILE_VSWITCHD
43 _proc_name = 'testpmd'
45 def __init__(self, timeout=30, testpmd_args=None, expected_cmd=None):
46 """Initialise the wrapper with a specific start timeout and extra
49 :param timeout: Timeout to wait for application to start.
50 :param testpmd_args: Command line parameters for testpmd.
54 self._logger = logging.getLogger(__name__)
55 self._timeout = timeout
56 self._expect = expected_cmd
58 self._expect = _TESTPMD_PROMPT
59 testpmd_args = testpmd_args or []
60 self._cmd = ['sudo', '-E', _TESTPMD_BIN] + testpmd_args
65 """ Start ``testpmd`` instance.
68 :raises: pexpect.EOF, pexpect.TIMEOUT
72 super(TestPMDProcess, self).start()
74 except (pexpect.EOF, pexpect.TIMEOUT) as exc:
75 logging.error("TestPMD start failed.")
78 def kill(self, signal='-15', sleep=2):
79 """Kill ``testpmd`` instance if it is alive.
83 self._logger.info('Killing testpmd...')
85 super(TestPMDProcess, self).kill(signal, sleep)
89 def send(self, cmd, delay=0):
91 Send ``cmd`` with no wait.
93 Useful for asynchronous commands.
95 :param cmd: Command to send to guest.
96 :param timeout: Delay to wait after sending command before returning.
100 self._logger.debug(cmd)
101 self._child.sendline(cmd)
104 def wait(self, msg=_TESTPMD_PROMPT, timeout=30):
108 :param msg: Message to wait for from guest.
109 :param timeout: Time to wait for message.
113 self._child.expect(msg, timeout=timeout)