xref: /OK3568_Linux_fs/external/rockit/tgi/sdk/include/rt_check.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright 2018 Rockchip Electronics Co. LTD
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  * author: rimon.xu@rock-chips.com
17  *   date: 20181102
18  */
19 
20 #ifndef INCLUDE_RT_BASE_RT_CHECK_H_
21 #define INCLUDE_RT_BASE_RT_CHECK_H_
22 
23 #define CHECK_OP(name, op, actual, exp) \
24     do { \
25         if (actual op exp) { \
26             /* TODO */ \
27         } else { \
28             RT_LOGE("%s(%d): %s failed. actual %d vs exp %d\n", \
29                      __FUNCTION__, __LINE__, name, actual, exp); \
30             goto __FAILED; \
31         } \
32     } while (0)
33 
34 #define RET_CHECK_OP(name, op, actual, exp) \
35     do { \
36         if (actual op exp) { \
37             /* TODO */ \
38         } else { \
39             return RT_ERR_UNKNOWN; \
40         } \
41     } while (0)
42 
43 #define RET_CHECK_FUNC(func, type, value) \
44     do { \
45         type ret = func; \
46         if (ret != value) \
47             return ret; \
48     } while (0)
49 
50 #define RET_CHECK_IS_NULL(ptr, ret) \
51     do { \
52         if (ptr == RT_NULL) { \
53             return ret; \
54         } \
55     } while (0)
56 
57 #define CHECK_EQ(actual, exp) CHECK_OP("CHECK_EQ", ==, actual, exp)
58 #define CHECK_UE(actual, exp) CHECK_OP("CHECK_UE", !=, actual, exp)
59 #define CHECK_LE(actual, exp) CHECK_OP("CHECK_LE", <=, actual, exp)
60 #define CHECK_LT(actual, exp) CHECK_OP("CHECK_LT", < , actual, exp)
61 #define CHECK_GE(actual, exp) CHECK_OP("CHECK_GE", >=, actual, exp)
62 #define CHECK_GT(actual, exp) CHECK_OP("CHECK_GT", > , actual, exp)
63 
64 #define RET_CHECK_EQ(actual, exp) RET_CHECK_OP("CHECK_EQ", ==, actual, exp)
65 #define RET_CHECK_UE(actual, exp) RET_CHECK_OP("CHECK_UE", !=, actual, exp)
66 #define RET_CHECK_LE(actual, exp) RET_CHECK_OP("CHECK_LE", <=, actual, exp)
67 #define RET_CHECK_LT(actual, exp) RET_CHECK_OP("CHECK_LT", < , actual, exp)
68 #define RET_CHECK_GE(actual, exp) RET_CHECK_OP("CHECK_GE", >=, actual, exp)
69 #define RET_CHECK_GT(actual, exp) RET_CHECK_OP("CHECK_GT", > , actual, exp)
70 
71 #define FUNC_CHECK(ret) CHECK_OP("FUNC_CHECK", ==, ret, RT_OK)
72 
73 #define CHECK_IS_NULL(value) CHECK_OP("CHECK_IS_NULL", !=, value, RT_NULL)
74 
75 #endif  // INCLUDE_RT_BASE_RT_CHECK_H_
76