2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #ifndef __ASSERT_SUPPORT_H_INCLUDED__
16 #define __ASSERT_SUPPORT_H_INCLUDED__
18 #include "storage_class.h"
21 * The following macro can help to test the size of a struct at compile
22 * time rather than at run-time. It does not work for all compilers; see
25 * Depending on the value of 'condition', the following macro is expanded to:
27 * an expression containing an array declaration with negative size,
28 * usually resulting in a compilation error
30 * (void) 1; // C statement with no effect
33 * COMPILATION_ERROR_IF( sizeof(struct host_sp_queues) != SIZE_OF_HOST_SP_QUEUES_STRUCT);
35 * verify that the macro indeed triggers a compilation error with your compiler:
36 * COMPILATION_ERROR_IF( sizeof(struct host_sp_queues) != (sizeof(struct host_sp_queues)+1) );
38 * Not all compilers will trigger an error with this macro; use a search engine to search for
39 * BUILD_BUG_ON to find other methods.
41 #define COMPILATION_ERROR_IF(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
43 /* Compile time assertion */
45 #define CT_ASSERT(cnd) ((void)sizeof(char[(cnd)?1:-1]))
46 #endif /* CT_ASSERT */
50 #define assert(cnd) ((void)0)
56 /* Windows kernel mode compilation */
58 #define assert(cnd) ASSERT(cnd)
60 /* Windows usermode compilation */
64 #elif defined(__KERNEL__)
65 #include <linux/bug.h>
67 /* TODO: it would be cleaner to use this:
68 * #define assert(cnd) BUG_ON(cnd)
69 * but that causes many compiler warnings (==errors) under Android
70 * because it seems that the BUG_ON() macro is not seen as a check by
71 * gcc like the BUG() macro is. */
78 #elif defined(__FIST__) || defined(__GNUC__)
80 /* enable assert for crun */
83 #else /* default for unknown environments */
84 #define assert(cnd) ((void)0)
89 #ifndef PIPE_GENERATION
90 /* Deprecated OP___assert, this is still used in ~1000 places
91 * in the code. This will be removed over time.
92 * The implemenation for the pipe generation tool is in see support.isp.h */
93 #define OP___assert(cnd) assert(cnd)
95 STORAGE_CLASS_INLINE void compile_time_assert (unsigned cond)
97 /* Call undefined function if cond is false */
98 extern void _compile_time_assert (void);
99 if (!cond) _compile_time_assert();
101 #endif /* PIPE_GENERATION */
103 #endif /* __ASSERT_SUPPORT_H_INCLUDED__ */