summaryrefslogtreecommitdiffstats
path: root/src/include/assert.h
blob: b9137fc4f2f47c4e2eb2d8642c63a1f72bd5c813 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef _ASSERT_H
#define _ASSERT_H

/** @file
 *
 * Assertions
 *
 * This file provides two assertion macros: assert() (for run-time
 * assertions) and linker_assert() (for link-time assertions).
 *
 */

/**
 * Assert a condition at run-time.
 *
 * If the condition is not true, a debug message will be printed.
 * Assertions only take effect in debug-enabled builds (see DBG()).
 *
 * @todo Make an assertion failure abort the program
 *
 */
#define assert( condition ) 						   \
	do { 								   \
		if ( ! (condition) ) { 					   \
			printf ( "assert(%s) failed at %s line %d [%s]\n", \
				 #condition, __FILE__, __LINE__,	   \
				 __FUNCTION__ );			   \
		} 							   \
	} while ( 0 )

/**
 * Assert a condition at link-time.
 *
 * If the condition is not true, the link will fail with an unresolved
 * symbol (error_symbol).
 *
 * This macro is gPXE-specific.  Do not use this macro in code
 * intended to be portable.
 *
 */
#define linker_assert( condition, error_symbol )	\
        if ( ! (condition) ) {				\
                extern void error_symbol ( void );	\
                error_symbol();				\
        }

#ifdef NDEBUG
#undef assert
#define assert(x) do {} while ( 0 )
#endif

#endif /* _ASSERT_H */