1 /**********************************************************************
2 * Copyright (c) 2013, 2014 Pieter Wuille *
3 * Distributed under the MIT software license, see the accompanying *
4 * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
5 **********************************************************************/
7 #ifndef _SECP256K1_UTIL_H_
8 #define _SECP256K1_UTIL_H_
10 #if defined HAVE_CONFIG_H
11 #include "libsecp256k1-config.h"
19 #define TEST_FAILURE(msg) do { \
20 fprintf(stderr, "%s\n", msg); \
24 #define TEST_FAILURE(msg) do { \
25 fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, msg); \
30 #ifndef HAVE_BUILTIN_EXPECT
31 #define EXPECT(x,c) __builtin_expect((x),(c))
33 #define EXPECT(x,c) (x)
37 #define CHECK(cond) do { \
38 if (EXPECT(!(cond), 0)) { \
39 TEST_FAILURE("test condition failed"); \
43 #define CHECK(cond) do { \
44 if (EXPECT(!(cond), 0)) { \
45 TEST_FAILURE("test condition failed: " #cond); \
50 /* Like assert(), but safe to use on expressions with side effects. */
52 #define DEBUG_CHECK CHECK
54 #define DEBUG_CHECK(cond) do { (void)(cond); } while(0)
57 /* Like DEBUG_CHECK(), but when VERIFY is defined instead of NDEBUG not defined. */
59 #define VERIFY_CHECK CHECK
61 #define VERIFY_CHECK(cond) do { (void)(cond); } while(0)