2014-11-15 15:28:10 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* Copyright (c) 2013, 2014 Pieter Wuille *
|
|
|
|
* Distributed under the MIT software license, see the accompanying *
|
|
|
|
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
|
|
|
|
**********************************************************************/
|
2013-05-09 15:24:32 +02:00
|
|
|
|
2013-04-20 23:34:41 +02:00
|
|
|
#ifndef _SECP256K1_UTIL_H_
|
|
|
|
#define _SECP256K1_UTIL_H_
|
|
|
|
|
2014-08-18 23:07:46 +02:00
|
|
|
#if defined HAVE_CONFIG_H
|
|
|
|
#include "libsecp256k1-config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-10-31 03:15:25 -07:00
|
|
|
#include <stdlib.h>
|
2014-08-18 23:07:46 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2014-11-17 13:16:47 +01:00
|
|
|
#ifdef DETERMINISTIC
|
|
|
|
#define TEST_FAILURE(msg) do { \
|
|
|
|
fprintf(stderr, "%s\n", msg); \
|
|
|
|
abort(); \
|
|
|
|
} while(0);
|
|
|
|
#else
|
2014-08-18 23:07:46 +02:00
|
|
|
#define TEST_FAILURE(msg) do { \
|
|
|
|
fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, msg); \
|
|
|
|
abort(); \
|
|
|
|
} while(0)
|
2014-11-17 13:16:47 +01:00
|
|
|
#endif
|
2014-08-18 23:07:46 +02:00
|
|
|
|
|
|
|
#ifndef HAVE_BUILTIN_EXPECT
|
|
|
|
#define EXPECT(x,c) __builtin_expect((x),(c))
|
|
|
|
#else
|
|
|
|
#define EXPECT(x,c) (x)
|
|
|
|
#endif
|
|
|
|
|
2014-11-17 13:16:47 +01:00
|
|
|
#ifdef DETERMINISTIC
|
|
|
|
#define CHECK(cond) do { \
|
|
|
|
if (EXPECT(!(cond), 0)) { \
|
|
|
|
TEST_FAILURE("test condition failed"); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
#else
|
2014-08-18 23:07:46 +02:00
|
|
|
#define CHECK(cond) do { \
|
|
|
|
if (EXPECT(!(cond), 0)) { \
|
|
|
|
TEST_FAILURE("test condition failed: " #cond); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2014-11-17 13:16:47 +01:00
|
|
|
#endif
|
2014-08-18 23:07:46 +02:00
|
|
|
|
2014-11-15 15:28:10 +00:00
|
|
|
/* Like assert(), but safe to use on expressions with side effects. */
|
2014-08-18 23:07:46 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
#define DEBUG_CHECK CHECK
|
|
|
|
#else
|
2014-11-04 13:14:47 -08:00
|
|
|
#define DEBUG_CHECK(cond) do { (void)(cond); } while(0)
|
2014-08-18 23:07:46 +02:00
|
|
|
#endif
|
|
|
|
|
2014-11-15 15:28:10 +00:00
|
|
|
/* Like DEBUG_CHECK(), but when VERIFY is defined instead of NDEBUG not defined. */
|
2014-08-18 23:07:46 +02:00
|
|
|
#ifdef VERIFY
|
|
|
|
#define VERIFY_CHECK CHECK
|
|
|
|
#else
|
2014-11-04 13:14:47 -08:00
|
|
|
#define VERIFY_CHECK(cond) do { (void)(cond); } while(0)
|
2014-08-18 23:07:46 +02:00
|
|
|
#endif
|
|
|
|
|
2013-04-20 23:34:41 +02:00
|
|
|
#endif
|