mbed-drivers
test_env.h
1 /*
2  * Copyright (c) 2013-2016, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef TEST_ENV_H_
18 #define TEST_ENV_H_
19 
20 #warning mbed-drivers/test_env.h is deprecated. Please use greentea-client/test_env.h instead.
21 
22 #include <stdio.h>
23 #include "mbed.h"
24 
25 #define NL "\n"
26 #define RCNL "\r\n"
27 
28 // Const strings used in test_end
29 extern const char* TEST_ENV_START;
30 extern const char* TEST_ENV_SUCCESS;
31 extern const char* TEST_ENV_FAILURE;
32 extern const char* TEST_ENV_MEASURE;
33 extern const char* TEST_ENV_END;
34 
35 // Test result related notification functions
36 void notify_start();
37 void notify_completion(bool success);
38 bool notify_completion_str(bool success, char* buffer);
39 void notify_performance_coefficient(const char* measurement_name, const int value);
40 void notify_performance_coefficient(const char* measurement_name, const unsigned int value);
41 void notify_performance_coefficient(const char* measurement_name, const double value);
42 
43 // Host test auto-detection API
44 void notify_host_test_name(const char *host_test);
45 void notify_timeout(int timeout);
46 void notify_test_id(const char *test_id);
47 void notify_test_description(const char *description);
48 
49 // Code Coverage API
50 void notify_coverage_start(const char *path);
51 void notify_coverage_end();
52 
53 // Host test auto-detection API
54 #define MBED_HOSTTEST_START(TESTID) notify_test_id(TESTID); notify_start()
55 #define MBED_HOSTTEST_SELECT(NAME) notify_host_test_name(#NAME)
56 #define MBED_HOSTTEST_TIMEOUT(SECONDS) notify_timeout(SECONDS)
57 #define MBED_HOSTTEST_DESCRIPTION(DESC) notify_test_description(#DESC)
58 #define MBED_HOSTTEST_RESULT(RESULT) notify_completion(RESULT)
59 #define MBED_HOSTTEST_ASSERT(cond) \
60  do { \
61  if (!(cond)) { \
62  printf("HOSTTEST ASSERTION FAILED: '%s' in %s, line %d\r\n", #cond, __FILE__, __LINE__); \
63  notify_completion(false); \
64  } \
65  } while(false)
66 
84 // Test functionality useful during testing
85 unsigned int testenv_randseed();
86 
87 // Macros, unit test like to provide basic comparisons
88 #define TESTENV_STRCMP(GIVEN,EXPECTED) (strcmp(GIVEN,EXPECTED) == 0)
89 
90 // macros passed via test suite
91 #ifndef TEST_SUITE_TARGET_NAME
92 #define TEST_SUITE_TARGET_NAME "Unknown"
93 #endif
94 
95 #ifndef TEST_SUITE_TEST_ID
96 #define TEST_SUITE_TEST_ID "Unknown"
97 #endif
98 
99 #ifndef TEST_SUITE_UUID
100 #define TEST_SUITE_UUID "Unknown"
101 #endif
102 
103 #endif