blob: dfe190cba58ade36a9a11045c86291d74275ce96 [file] [log] [blame]
Gilles Peskinea1bb3f82020-03-24 18:20:59 +01001#!/usr/bin/env python3
2
Azim Khan951a2c82018-06-29 03:47:08 +01003# Greentea host test script for Mbed TLS on-target test suite testing.
Azim Khanf0e42fb2017-08-02 14:47:13 +01004#
Azim Khan8d686bf2018-07-04 23:29:46 +01005# Copyright (C) 2018, Arm Limited, All Rights Reserved
Bence Szépkútif744bd72020-06-05 13:02:18 +02006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7#
8# This file is provided under the Apache License 2.0, or the
9# GNU General Public License v2.0 or later.
10#
11# **********
12# Apache License 2.0:
Azim Khanf0e42fb2017-08-02 14:47:13 +010013#
14# Licensed under the Apache License, Version 2.0 (the "License"); you may
15# not use this file except in compliance with the License.
16# You may obtain a copy of the License at
17#
18# http://www.apache.org/licenses/LICENSE-2.0
19#
20# Unless required by applicable law or agreed to in writing, software
21# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23# See the License for the specific language governing permissions and
24# limitations under the License.
25#
Bence Szépkútif744bd72020-06-05 13:02:18 +020026# **********
27#
28# **********
29# GNU General Public License v2.0 or later:
30#
31# This program is free software; you can redistribute it and/or modify
32# it under the terms of the GNU General Public License as published by
33# the Free Software Foundation; either version 2 of the License, or
34# (at your option) any later version.
35#
36# This program is distributed in the hope that it will be useful,
37# but WITHOUT ANY WARRANTY; without even the implied warranty of
38# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39# GNU General Public License for more details.
40#
41# You should have received a copy of the GNU General Public License along
42# with this program; if not, write to the Free Software Foundation, Inc.,
43# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
44#
45# **********
46#
Azim Khanb31aa442018-07-03 11:57:54 +010047# This file is part of Mbed TLS (https://tls.mbed.org)
Azim Khanf0e42fb2017-08-02 14:47:13 +010048
49
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +010050"""
Azim Khan8d686bf2018-07-04 23:29:46 +010051Mbed TLS on-target test suite tests are implemented as Greentea
Azim Khan951a2c82018-06-29 03:47:08 +010052tests. Greentea tests are implemented in two parts: target test and
53host test. Target test is a C application that is built for the
54target platform and executes on the target. Host test is a Python
55class derived from mbed_host_tests.BaseHostTest. Target communicates
Azim Khan8d686bf2018-07-04 23:29:46 +010056with the host over serial for the test data and sends back the result.
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +010057
Azim Khanb31aa442018-07-03 11:57:54 +010058Python tool mbedgt (Greentea) is responsible for flashing the test
Azim Khan8d686bf2018-07-04 23:29:46 +010059binary on to the target and dynamically loading this host test module.
Azim Khan951a2c82018-06-29 03:47:08 +010060
Azim Khan8d686bf2018-07-04 23:29:46 +010061Greentea documentation can be found here:
62https://github.com/ARMmbed/greentea
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +010063"""
64
Azim Khanf0e42fb2017-08-02 14:47:13 +010065
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +010066import re
67import os
Azim Khan663d4702017-07-07 15:40:26 +010068import binascii
Gilles Peskineafd19dd2019-02-25 21:39:42 +010069
70from mbed_host_tests import BaseHostTest, event_callback # pylint: disable=import-error
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +010071
72
Azim Khanb98e6ee2018-06-28 17:11:33 +010073class TestDataParserError(Exception):
74 """Indicates error in test data, read from .data file."""
75 pass
76
77
Gilles Peskinea1bb3f82020-03-24 18:20:59 +010078class TestDataParser:
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +010079 """
Azim Khan951a2c82018-06-29 03:47:08 +010080 Parses test name, dependencies, test function name and test parameters
81 from the data file.
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +010082 """
83
84 def __init__(self):
85 """
86 Constructor
87 """
88 self.tests = []
89
90 def parse(self, data_file):
91 """
Azim Khanf0e42fb2017-08-02 14:47:13 +010092 Data file parser.
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +010093
Azim Khanf0e42fb2017-08-02 14:47:13 +010094 :param data_file: Data file path
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +010095 """
Azim Khanb31aa442018-07-03 11:57:54 +010096 with open(data_file, 'r') as data_f:
97 self.__parse(data_f)
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +010098
99 @staticmethod
Azim Khanb31aa442018-07-03 11:57:54 +0100100 def __escaped_split(inp_str, split_char):
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100101 """
Azim Khanb31aa442018-07-03 11:57:54 +0100102 Splits inp_str on split_char except when escaped.
Azim Khanf0e42fb2017-08-02 14:47:13 +0100103
Azim Khanb31aa442018-07-03 11:57:54 +0100104 :param inp_str: String to split
105 :param split_char: Split character
Azim Khanf0e42fb2017-08-02 14:47:13 +0100106 :return: List of splits
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100107 """
Ron Eldor111ba0e2018-11-18 17:05:05 +0200108 split_colon_fn = lambda x: re.sub(r'\\' + split_char, split_char, x)
Azim Khanb31aa442018-07-03 11:57:54 +0100109 if len(split_char) > 1:
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100110 raise ValueError('Expected split character. Found string!')
Ron Eldor56b6e522019-05-29 17:17:10 +0300111 out = list(map(split_colon_fn, re.split(r'(?<!\\)' + split_char, inp_str)))
Ron Eldor7c52e222019-06-25 14:52:19 +0300112 out = [x for x in out if x]
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100113 return out
114
Azim Khanb31aa442018-07-03 11:57:54 +0100115 def __parse(self, data_f):
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100116 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100117 Parses data file using supplied file object.
118
Azim Khanb31aa442018-07-03 11:57:54 +0100119 :param data_f: Data file object
Azim Khanf0e42fb2017-08-02 14:47:13 +0100120 :return:
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100121 """
Ron Eldorb43fe572019-06-03 11:38:42 +0300122 for line in data_f:
123 line = line.strip()
Azim Khanb31aa442018-07-03 11:57:54 +0100124 if not line:
Ron Eldorb43fe572019-06-03 11:38:42 +0300125 continue
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100126 # Read test name
127 name = line
128
129 # Check dependencies
Azim Khanb31aa442018-07-03 11:57:54 +0100130 dependencies = []
Ron Eldorb43fe572019-06-03 11:38:42 +0300131 line = next(data_f).strip()
Azim Khanb31aa442018-07-03 11:57:54 +0100132 match = re.search('depends_on:(.*)', line)
133 if match:
134 dependencies = [int(x) for x in match.group(1).split(':')]
Ron Eldorb43fe572019-06-03 11:38:42 +0300135 line = next(data_f).strip()
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100136
137 # Read test vectors
Azim Khan663d4702017-07-07 15:40:26 +0100138 line = line.replace('\\n', '\n')
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100139 parts = self.__escaped_split(line, ':')
Azim Khanb31aa442018-07-03 11:57:54 +0100140 function_name = int(parts[0])
141 args = parts[1:]
142 args_count = len(args)
143 if args_count % 2 != 0:
Ron Eldor111ba0e2018-11-18 17:05:05 +0200144 err_str_fmt = "Number of test arguments({}) should be even: {}"
145 raise TestDataParserError(err_str_fmt.format(args_count, line))
Azim Khanb31aa442018-07-03 11:57:54 +0100146 grouped_args = [(args[i * 2], args[(i * 2) + 1])
Ron Eldor56b6e522019-05-29 17:17:10 +0300147 for i in range(int(len(args)/2))]
Azim Khanb31aa442018-07-03 11:57:54 +0100148 self.tests.append((name, function_name, dependencies,
149 grouped_args))
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100150
151 def get_test_data(self):
152 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100153 Returns test data.
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100154 """
155 return self.tests
156
157
158class MbedTlsTest(BaseHostTest):
159 """
Azim Khanb31aa442018-07-03 11:57:54 +0100160 Host test for Mbed TLS unit tests. This script is loaded at
161 run time by Greentea for executing Mbed TLS test suites. Each
Azim Khan951a2c82018-06-29 03:47:08 +0100162 communication from the target is received in this object as
163 an event, which is then handled by the event handler method
164 decorated by the associated event. Ex: @event_callback('GO').
165
166 Target test sends requests for dispatching next test. It reads
167 tests from the intermediate data file and sends test function
168 identifier, dependency identifiers, expression identifiers and
Azim Khanb31aa442018-07-03 11:57:54 +0100169 the test data in binary form. Target test checks dependencies
Azim Khan951a2c82018-06-29 03:47:08 +0100170 , evaluate integer constant expressions and dispatches the test
Azim Khan8d686bf2018-07-04 23:29:46 +0100171 function with received test parameters. After test function is
172 finished, target sends the result. This class handles the result
173 event and prints verdict in the form that Greentea understands.
Azim Khan951a2c82018-06-29 03:47:08 +0100174
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100175 """
Azim Khan951a2c82018-06-29 03:47:08 +0100176 # status/error codes from suites/helpers.function
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100177 DEPENDENCY_SUPPORTED = 0
178 KEY_VALUE_MAPPING_FOUND = DEPENDENCY_SUPPORTED
179 DISPATCH_TEST_SUCCESS = DEPENDENCY_SUPPORTED
180
Azim Khan951a2c82018-06-29 03:47:08 +0100181 KEY_VALUE_MAPPING_NOT_FOUND = -1 # Expression Id not found.
182 DEPENDENCY_NOT_SUPPORTED = -2 # Dependency not supported.
183 DISPATCH_TEST_FN_NOT_FOUND = -3 # Test function not found.
184 DISPATCH_INVALID_TEST_DATA = -4 # Invalid parameter type.
185 DISPATCH_UNSUPPORTED_SUITE = -5 # Test suite not supported/enabled.
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100186
187 def __init__(self):
188 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100189 Constructor initialises test index to 0.
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100190 """
191 super(MbedTlsTest, self).__init__()
192 self.tests = []
193 self.test_index = -1
194 self.dep_index = 0
Ron Eldor8672cb72018-11-13 18:42:35 +0200195 self.suite_passed = True
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100196 self.error_str = dict()
Azim Khanb31aa442018-07-03 11:57:54 +0100197 self.error_str[self.DEPENDENCY_SUPPORTED] = \
198 'DEPENDENCY_SUPPORTED'
199 self.error_str[self.KEY_VALUE_MAPPING_NOT_FOUND] = \
200 'KEY_VALUE_MAPPING_NOT_FOUND'
201 self.error_str[self.DEPENDENCY_NOT_SUPPORTED] = \
202 'DEPENDENCY_NOT_SUPPORTED'
203 self.error_str[self.DISPATCH_TEST_FN_NOT_FOUND] = \
204 'DISPATCH_TEST_FN_NOT_FOUND'
205 self.error_str[self.DISPATCH_INVALID_TEST_DATA] = \
206 'DISPATCH_INVALID_TEST_DATA'
207 self.error_str[self.DISPATCH_UNSUPPORTED_SUITE] = \
208 'DISPATCH_UNSUPPORTED_SUITE'
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100209
210 def setup(self):
211 """
Azim Khan951a2c82018-06-29 03:47:08 +0100212 Setup hook implementation. Reads test suite data file and parses out
213 tests.
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100214 """
215 binary_path = self.get_config_item('image_path')
216 script_dir = os.path.split(os.path.abspath(__file__))[0]
217 suite_name = os.path.splitext(os.path.basename(binary_path))[0]
Ron Eldorc242eea2018-11-05 16:22:36 +0200218 data_file = ".".join((suite_name, 'datax'))
Azim Khan951a2c82018-06-29 03:47:08 +0100219 data_file = os.path.join(script_dir, '..', 'mbedtls',
220 suite_name, data_file)
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100221 if os.path.exists(data_file):
222 self.log("Running tests from %s" % data_file)
223 parser = TestDataParser()
224 parser.parse(data_file)
225 self.tests = parser.get_test_data()
226 self.print_test_info()
227 else:
228 self.log("Data file not found: %s" % data_file)
229 self.notify_complete(False)
230
231 def print_test_info(self):
232 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100233 Prints test summary read by Greentea to detect test cases.
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100234 """
235 self.log('{{__testcase_count;%d}}' % len(self.tests))
236 for name, _, _, _ in self.tests:
237 self.log('{{__testcase_name;%s}}' % name)
238
239 @staticmethod
Azim Khanb31aa442018-07-03 11:57:54 +0100240 def align_32bit(data_bytes):
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100241 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100242 4 byte aligns input byte array.
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100243
244 :return:
245 """
Azim Khanb31aa442018-07-03 11:57:54 +0100246 data_bytes += bytearray((4 - (len(data_bytes))) % 4)
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100247
Azim Khand59391a2017-06-01 14:04:17 +0100248 @staticmethod
249 def hex_str_bytes(hex_str):
250 """
251 Converts Hex string representation to byte array
252
Azim Khanf0e42fb2017-08-02 14:47:13 +0100253 :param hex_str: Hex in string format.
254 :return: Output Byte array
Azim Khand59391a2017-06-01 14:04:17 +0100255 """
Azim Khanb98e6ee2018-06-28 17:11:33 +0100256 if hex_str[0] != '"' or hex_str[len(hex_str) - 1] != '"':
257 raise TestDataParserError("HEX test parameter missing '\"':"
258 " %s" % hex_str)
Azim Khand59391a2017-06-01 14:04:17 +0100259 hex_str = hex_str.strip('"')
Azim Khanb98e6ee2018-06-28 17:11:33 +0100260 if len(hex_str) % 2 != 0:
261 raise TestDataParserError("HEX parameter len should be mod of "
262 "2: %s" % hex_str)
Azim Khand59391a2017-06-01 14:04:17 +0100263
Azim Khanb31aa442018-07-03 11:57:54 +0100264 data_bytes = binascii.unhexlify(hex_str)
265 return data_bytes
Azim Khand59391a2017-06-01 14:04:17 +0100266
Azim Khan663d4702017-07-07 15:40:26 +0100267 @staticmethod
Azim Khanb31aa442018-07-03 11:57:54 +0100268 def int32_to_big_endian_bytes(i):
Azim Khan663d4702017-07-07 15:40:26 +0100269 """
Azim Khanb31aa442018-07-03 11:57:54 +0100270 Coverts i to byte array in big endian format.
Azim Khan663d4702017-07-07 15:40:26 +0100271
Azim Khanf0e42fb2017-08-02 14:47:13 +0100272 :param i: Input integer
273 :return: Output bytes array in big endian or network order
Azim Khan663d4702017-07-07 15:40:26 +0100274 """
Azim Khanb31aa442018-07-03 11:57:54 +0100275 data_bytes = bytearray([((i >> x) & 0xff) for x in [24, 16, 8, 0]])
276 return data_bytes
Azim Khan663d4702017-07-07 15:40:26 +0100277
Azim Khanb31aa442018-07-03 11:57:54 +0100278 def test_vector_to_bytes(self, function_id, dependencies, parameters):
Azim Khan663d4702017-07-07 15:40:26 +0100279 """
280 Converts test vector into a byte array that can be sent to the target.
281
Azim Khanf0e42fb2017-08-02 14:47:13 +0100282 :param function_id: Test Function Identifier
Azim Khanb31aa442018-07-03 11:57:54 +0100283 :param dependencies: Dependency list
Azim Khanf0e42fb2017-08-02 14:47:13 +0100284 :param parameters: Test function input parameters
285 :return: Byte array and its length
Azim Khan663d4702017-07-07 15:40:26 +0100286 """
Azim Khanb31aa442018-07-03 11:57:54 +0100287 data_bytes = bytearray([len(dependencies)])
288 if dependencies:
289 data_bytes += bytearray(dependencies)
290 data_bytes += bytearray([function_id, len(parameters)])
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100291 for typ, param in parameters:
Gilles Peskine399b82f2020-03-24 18:36:56 +0100292 if typ in ('int', 'exp'):
Ron Eldor7c52e222019-06-25 14:52:19 +0300293 i = int(param, 0)
Ron Eldorb43fe572019-06-03 11:38:42 +0300294 data_bytes += b'I' if typ == 'int' else b'E'
Azim Khanb31aa442018-07-03 11:57:54 +0100295 self.align_32bit(data_bytes)
296 data_bytes += self.int32_to_big_endian_bytes(i)
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100297 elif typ == 'char*':
298 param = param.strip('"')
299 i = len(param) + 1 # + 1 for null termination
Ron Eldorb43fe572019-06-03 11:38:42 +0300300 data_bytes += b'S'
Azim Khanb31aa442018-07-03 11:57:54 +0100301 self.align_32bit(data_bytes)
302 data_bytes += self.int32_to_big_endian_bytes(i)
Ron Eldor9d40da22019-06-03 13:39:21 +0300303 data_bytes += bytearray(param, encoding='ascii')
Ron Eldorb43fe572019-06-03 11:38:42 +0300304 data_bytes += b'\0' # Null terminate
Azim Khand59391a2017-06-01 14:04:17 +0100305 elif typ == 'hex':
Azim Khanb31aa442018-07-03 11:57:54 +0100306 binary_data = self.hex_str_bytes(param)
Ron Eldorb43fe572019-06-03 11:38:42 +0300307 data_bytes += b'H'
Azim Khanb31aa442018-07-03 11:57:54 +0100308 self.align_32bit(data_bytes)
309 i = len(binary_data)
310 data_bytes += self.int32_to_big_endian_bytes(i)
311 data_bytes += binary_data
312 length = self.int32_to_big_endian_bytes(len(data_bytes))
313 return data_bytes, length
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100314
315 def run_next_test(self):
316 """
Azim Khan951a2c82018-06-29 03:47:08 +0100317 Fetch next test information and execute the test.
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100318
319 """
320 self.test_index += 1
321 self.dep_index = 0
322 if self.test_index < len(self.tests):
Azim Khanb31aa442018-07-03 11:57:54 +0100323 name, function_id, dependencies, args = self.tests[self.test_index]
324 self.run_test(name, function_id, dependencies, args)
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100325 else:
Ron Eldor8672cb72018-11-13 18:42:35 +0200326 self.notify_complete(self.suite_passed)
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100327
Azim Khanb31aa442018-07-03 11:57:54 +0100328 def run_test(self, name, function_id, dependencies, args):
Azim Khan663d4702017-07-07 15:40:26 +0100329 """
Azim Khan951a2c82018-06-29 03:47:08 +0100330 Execute the test on target by sending next test information.
Azim Khan663d4702017-07-07 15:40:26 +0100331
Azim Khanf0e42fb2017-08-02 14:47:13 +0100332 :param name: Test name
333 :param function_id: function identifier
Azim Khanb31aa442018-07-03 11:57:54 +0100334 :param dependencies: Dependencies list
Azim Khanf0e42fb2017-08-02 14:47:13 +0100335 :param args: test parameters
Azim Khan663d4702017-07-07 15:40:26 +0100336 :return:
337 """
338 self.log("Running: %s" % name)
339
Azim Khanb31aa442018-07-03 11:57:54 +0100340 param_bytes, length = self.test_vector_to_bytes(function_id,
341 dependencies, args)
Darryl Green349a0792019-12-17 10:17:20 +0000342 self.send_kv(
343 ''.join('{:02x}'.format(x) for x in length),
344 ''.join('{:02x}'.format(x) for x in param_bytes)
345 )
Azim Khan663d4702017-07-07 15:40:26 +0100346
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100347 @staticmethod
348 def get_result(value):
Azim Khanf0e42fb2017-08-02 14:47:13 +0100349 """
350 Converts result from string type to integer
351 :param value: Result code in string
Azim Khan8d686bf2018-07-04 23:29:46 +0100352 :return: Integer result code. Value is from the test status
353 constants defined under the MbedTlsTest class.
Azim Khanf0e42fb2017-08-02 14:47:13 +0100354 """
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100355 try:
356 return int(value)
357 except ValueError:
Azim Khanb31aa442018-07-03 11:57:54 +0100358 ValueError("Result should return error number. "
359 "Instead received %s" % value)
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100360
361 @event_callback('GO')
Azim Khanb31aa442018-07-03 11:57:54 +0100362 def on_go(self, _key, _value, _timestamp):
Azim Khanf0e42fb2017-08-02 14:47:13 +0100363 """
Azim Khan951a2c82018-06-29 03:47:08 +0100364 Sent by the target to start first test.
Azim Khanf0e42fb2017-08-02 14:47:13 +0100365
Azim Khanb31aa442018-07-03 11:57:54 +0100366 :param _key: Event key
367 :param _value: Value. ignored
368 :param _timestamp: Timestamp ignored.
Azim Khanf0e42fb2017-08-02 14:47:13 +0100369 :return:
370 """
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100371 self.run_next_test()
372
373 @event_callback("R")
Azim Khanb31aa442018-07-03 11:57:54 +0100374 def on_result(self, _key, value, _timestamp):
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100375 """
Azim Khan951a2c82018-06-29 03:47:08 +0100376 Handle result. Prints test start, finish required by Greentea
377 to detect test execution.
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100378
Azim Khanb31aa442018-07-03 11:57:54 +0100379 :param _key: Event key
Azim Khanf0e42fb2017-08-02 14:47:13 +0100380 :param value: Value. ignored
Azim Khanb31aa442018-07-03 11:57:54 +0100381 :param _timestamp: Timestamp ignored.
Azim Khanf0e42fb2017-08-02 14:47:13 +0100382 :return:
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100383 """
384 int_val = self.get_result(value)
Azim Khanb31aa442018-07-03 11:57:54 +0100385 name, _, _, _ = self.tests[self.test_index]
Azim Khan5e7f8df2017-05-31 20:33:39 +0100386 self.log('{{__testcase_start;%s}}' % name)
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100387 self.log('{{__testcase_finish;%s;%d;%d}}' % (name, int_val == 0,
388 int_val != 0))
Ron Eldor8672cb72018-11-13 18:42:35 +0200389 if int_val != 0:
390 self.suite_passed = False
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100391 self.run_next_test()
392
393 @event_callback("F")
Azim Khanb31aa442018-07-03 11:57:54 +0100394 def on_failure(self, _key, value, _timestamp):
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100395 """
Azim Khanf0e42fb2017-08-02 14:47:13 +0100396 Handles test execution failure. That means dependency not supported or
397 Test function not supported. Hence marking test as skipped.
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100398
Azim Khanb31aa442018-07-03 11:57:54 +0100399 :param _key: Event key
Azim Khanf0e42fb2017-08-02 14:47:13 +0100400 :param value: Value. ignored
Azim Khanb31aa442018-07-03 11:57:54 +0100401 :param _timestamp: Timestamp ignored.
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100402 :return:
403 """
404 int_val = self.get_result(value)
Mohammad Azim Khan7a0d84f2017-04-01 03:18:20 +0100405 if int_val in self.error_str:
406 err = self.error_str[int_val]
407 else:
408 err = 'Unknown error'
409 # For skip status, do not write {{__testcase_finish;...}}
410 self.log("Error: %s" % err)
411 self.run_next_test()