Browse files

Refactored assertions to make sure assertions in tests are never remo…

…ved.
  • Loading branch information...
1 parent 5397014 commit 99035a1c10afaef5a7bd70c3f6ccbd24260ba0c7 Caleb James DeLisle committed May 4, 2012
Showing with 209 additions and 177 deletions.
  1. +5 −5 admin/Admin.c
  2. +6 −6 admin/test/Admin_test.c
  3. +1 −1 admin/test/CMakeLists.txt
  4. +1 −1 benc/serialization/standard/test/CMakeLists.txt
  5. +2 −2 cjdroute.c
  6. +1 −1 crypto/Crypto.c
  7. +16 −16 crypto/CryptoAuth.c
  8. +1 −1 crypto/CryptoAuth_benchmark.c
  9. +1 −0 crypto/test/CMakeLists.txt
  10. +5 −5 crypto/test/CryptoAuth_test.c
  11. +15 −15 crypto/test/CryptoAuth_unit_test.c
  12. +2 −2 crypto/test/ReplayProtector_test.c
  13. +1 −1 dht/Address.h
  14. +4 −4 dht/AddressMapper.h
  15. +2 −2 dht/DHTModuleRegistry.c
  16. +1 −1 dht/dhtcore/NodeHeader.h
  17. +5 −5 dht/dhtcore/NodeStore.c
  18. +1 −1 dht/dhtcore/SearchStore.c
  19. +1 −1 dht/dhtcore/test/CMakeLists.txt
  20. +14 −14 dht/dhtcore/test/RouterModule_test_disabled.c
  21. +1 −3 dht/test/CMakeLists.txt
  22. +8 −8 interface/InterfaceController.c
  23. +2 −2 interface/UDPInterface.c
  24. +1 −0 interface/test/CMakeLists.txt
  25. +3 −3 interface/test/InterfaceController_test.c
  26. +1 −1 io/test/CMakeLists.txt
  27. +2 −2 io/test/FileReader_test.c
  28. +1 −0 memory/test/CMakeLists.txt
  29. +6 −6 memory/test/MallocAllocator_test.c
  30. +4 −4 net/Ducttape.c
  31. +2 −2 net/SwitchPinger.c
  32. +3 −3 switch/SwitchCore.c
  33. +1 −1 switch/test/CMakeLists.txt
  34. +3 −3 switch/test/LabelSplicer_test.c
  35. +1 −1 test/CMakeLists.txt
  36. +42 −12 util/Assert.h
  37. +1 −1 util/Bits.h
  38. +4 −4 util/test/Base32_test.c
  39. +4 −4 util/test/Bits_test.c
  40. +1 −0 util/test/CMakeLists.txt
  41. +4 −4 util/test/Checksum_test.c
  42. +1 −1 util/test/Endian_benchmark.c
  43. +11 −11 util/test/Endian_test.c
  44. +4 −4 util/test/Hex_test.c
  45. +3 −3 wire/Control.h
  46. +5 −5 wire/Headers.h
  47. +5 −5 wire/Message.h
View
10 admin/Admin.c
@@ -34,7 +34,7 @@
#include "util/Time.h"
#include "util/Timeout.h"
-#include <assert.h>
+#include "util/Assert.h"
#include <crypto_hash_sha256.h>
#include <event2/event.h>
#include <errno.h>
@@ -127,7 +127,7 @@ static bool checkArgs(Dict* args, struct Function* func, String* txid, struct Ad
struct Allocator* alloc = BufferAllocator_new(buffer, 1024);
while (entry != NULL) {
String* key = (String*) entry->key;
- assert(entry->val->type == Object_DICT);
+ Assert_true(entry->val->type == Object_DICT);
Dict* value = entry->val->as.dictionary;
entry = entry->next;
if (*Dict_getInt(value, String_CONST("required")) == 0) {
@@ -328,7 +328,7 @@ static void incomingFromParent(evutil_socket_t socket, short eventType, void* vc
return;
}
- Assert_assertTrue(TXID_LEN == 4);
+ Assert_compileTime(TXID_LEN == 4);
uint32_t connNumber;
Bits_memcpyConst(&connNumber, context->buffer, TXID_LEN);
@@ -365,7 +365,7 @@ static void incomingFromClient(evutil_socket_t socket, short eventType, void* vc
if (result > 0) {
- Assert_assertTrue(TXID_LEN == 4);
+ Assert_compileTime(TXID_LEN == 4);
uint32_t connNumber = conn - context->connections;
Bits_memcpyConst(buf, &connNumber, TXID_LEN);
@@ -552,7 +552,7 @@ void Admin_sendMessage(Dict* message, String* txid, struct Admin* admin)
if (!admin) {
return;
}
- assert(txid);
+ Assert_true(txid);
uint8_t buff[MAX_API_REQUEST_SIZE + TXID_LEN];
View
12 admin/test/Admin_test.c
@@ -25,7 +25,7 @@
#include "exception/AbortHandler.h"
#include <event2/event.h>
-#include <assert.h>
+#include "util/Assert.h"
struct Context {
struct Admin* admin;
@@ -65,17 +65,17 @@ int main()
String* retPassword;
Admin_getConnectInfo(&addrPtr, &addrLen, &retPassword, admin);
- assert(String_equals(password, retPassword));
+ Assert_always(String_equals(password, retPassword));
struct AdminClient* client =
AdminClient_new(addrPtr, addrLen, retPassword, eventBase, &logger, alloc);
- assert(client);
+ Assert_always(client);
struct AdminClient_Result* res =
AdminClient_rpcCall(String_CONST("adminFunc"), NULL, client, alloc);
- assert(!res->err);
- assert(Dict_getInt(res->responseDict, String_CONST("called!")));
- assert(ctx.called);
+ Assert_always(!res->err);
+ Assert_always(Dict_getInt(res->responseDict, String_CONST("called!")));
+ Assert_always(ctx.called);
}
View
2 admin/test/CMakeLists.txt
@@ -14,7 +14,7 @@ cmake_minimum_required(VERSION 2.4)
string(REGEX REPLACE "^.*/" "" main_dir_name ${CMAKE_SOURCE_DIR})
string(REPLACE ${CMAKE_SOURCE_DIR} ${main_dir_name} this_dir ${CMAKE_CURRENT_SOURCE_DIR})
message("-- Tests to run for " ${this_dir})
-add_definitions(-g)
+add_definitions(-g -DTEST)
# Anything in this dir which ends with "test.c" is considered a test.
View
2 benc/serialization/standard/test/CMakeLists.txt
@@ -16,7 +16,7 @@ include_directories(${CMAKE_SOURCE_DIR})
string(REGEX REPLACE "^.*/" "" main_dir_name ${CMAKE_SOURCE_DIR})
string(REPLACE ${CMAKE_SOURCE_DIR} ${main_dir_name} this_dir ${CMAKE_CURRENT_SOURCE_DIR})
message("-- Tests to run for " ${this_dir})
-add_definitions(-g)
+add_definitions(-g -DTEST)
# Anything in this dir which ends with "test.c" is considered a test.
file(GLOB tests "*test.c")
View
4 cjdroute.c
@@ -49,7 +49,7 @@
#include "crypto_scalarmult_curve25519.h"
#include <stdint.h>
-#include <assert.h>
+#include "util/Assert.h"
#include <unistd.h>
#include <stdio.h>
@@ -498,7 +498,7 @@ int main(int argc, char** argv)
fprintf(stderr, "Log_LEVEL = KEYS, EXPECT TO SEE PRIVATE KEYS IN YOUR LOGS!\n");
#endif
Crypto_init();
- assert(argc > 0);
+ Assert_true(argc > 0);
if (argc == 2) { // one argument
if (strcmp(argv[1], "--help") == 0) {
View
2 crypto/Crypto.c
@@ -16,7 +16,7 @@
#include "memory/Allocator.h"
#include "memory/BufferAllocator.h"
-#include <assert.h>
+#include "util/Assert.h"
#include <stdio.h>
#include <event2/util.h>
View
32 crypto/CryptoAuth.c
@@ -38,7 +38,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
-#include <assert.h>
+#include "util/Assert.h"
#include <event2/event.h>
/** The constant used in nacl. */
@@ -215,7 +215,7 @@ static inline int decryptRndNonce(uint8_t nonce[24],
if (msg->length < 16) {
return -1;
}
- assert(msg->padding >= 16);
+ Assert_true(msg->padding >= 16);
uint8_t* startAt = msg->bytes - 16;
uint8_t paddingSpace[16];
Bits_memcpyConst(paddingSpace, startAt, 16);
@@ -243,7 +243,7 @@ static inline void encryptRndNonce(uint8_t nonce[24],
struct Message* msg,
uint8_t secret[32])
{
- assert(msg->padding >= 32);
+ Assert_true(msg->padding >= 32);
uint8_t* startAt = msg->bytes - 32;
// This function trashes 16 bytes of the padding so we will put it back
uint8_t paddingSpace[16];
@@ -359,14 +359,14 @@ static uint8_t genReverseHandshake(struct Message* message,
Log_debug(wrapper->context->logger, "Buffered a message.\n");
wrapper->bufferedMessage =
Message_clone(message, wrapper->externalInterface.allocator);
- assert(wrapper->nextNonce == 0);
+ Assert_true(wrapper->nextNonce == 0);
} else {
Log_debug(wrapper->context->logger,
"Expelled a message because a session has not yet been setup.\n");
Message_copyOver(wrapper->bufferedMessage,
message,
wrapper->externalInterface.allocator);
- assert(wrapper->nextNonce == 0);
+ Assert_true(wrapper->nextNonce == 0);
}
wrapper->hasBufferedMessage = true;
@@ -384,7 +384,7 @@ static uint8_t genReverseHandshake(struct Message* message,
static uint8_t encryptHandshake(struct Message* message, struct CryptoAuth_Wrapper* wrapper)
{
- assert(message->padding >= sizeof(union Headers_CryptoAuth) || !"not enough padding");
+ Assert_true(message->padding >= sizeof(union Headers_CryptoAuth) || !"not enough padding");
Message_shift(message, sizeof(union Headers_CryptoAuth));
@@ -433,8 +433,8 @@ static uint8_t encryptHandshake(struct Message* message, struct CryptoAuth_Wrapp
Bits_memcpyConst(wrapper->tempKey, header->handshake.encryptedTempKey, 32);
}
#ifdef Log_DEBUG
- assert(!Bits_isZero(header->handshake.encryptedTempKey, 32));
- assert(!Bits_isZero(wrapper->secret, 32));
+ Assert_true(!Bits_isZero(header->handshake.encryptedTempKey, 32));
+ Assert_true(!Bits_isZero(wrapper->secret, 32));
#endif
} else if (wrapper->nextNonce == 3) {
// Dupe key
@@ -473,10 +473,10 @@ static uint8_t encryptHandshake(struct Message* message, struct CryptoAuth_Wrapp
wrapper->isInitiator = true;
wrapper->nextNonce = 1;
#ifdef Log_DEBUG
- assert(!Bits_isZero(header->handshake.encryptedTempKey, 32));
+ Assert_true(!Bits_isZero(header->handshake.encryptedTempKey, 32));
uint8_t myTempPubKey[32];
crypto_scalarmult_curve25519_base(myTempPubKey, wrapper->secret);
- assert(!memcmp(header->handshake.encryptedTempKey, myTempPubKey, 32));
+ Assert_true(!memcmp(header->handshake.encryptedTempKey, myTempPubKey, 32));
#endif
} else {
if (wrapper->nextNonce == 2) {
@@ -523,7 +523,7 @@ static uint8_t encryptHandshake(struct Message* message, struct CryptoAuth_Wrapp
nonceHex, sharedSecretHex, cipherHex);
#endif
#ifdef Log_DEBUG
- assert(!Bits_isZero(header->handshake.encryptedTempKey, 32));
+ Assert_true(!Bits_isZero(header->handshake.encryptedTempKey, 32));
#endif
// Shift it back -- encryptRndNonce adds 16 bytes of authenticator.
@@ -535,7 +535,7 @@ static uint8_t encryptHandshake(struct Message* message, struct CryptoAuth_Wrapp
static inline uint8_t encryptMessage(struct Message* message,
struct CryptoAuth_Wrapper* wrapper)
{
- assert(message->padding >= 36 || !"not enough padding");
+ Assert_true(message->padding >= 36 || !"not enough padding");
encrypt(wrapper->nextNonce,
message,
@@ -569,7 +569,7 @@ static uint8_t sendMessage(struct Message* message, struct Interface* interface)
}
#ifdef Log_DEBUG
- assert(!((uintptr_t)message->bytes % 4) || !"alignment fault");
+ Assert_true(!((uintptr_t)message->bytes % 4) || !"alignment fault");
#endif
// nextNonce 0: sending hello, we are initiating connection.
@@ -788,7 +788,7 @@ static uint8_t decryptHandshake(struct CryptoAuth_Wrapper* wrapper,
Bits_memcpyConst(wrapper->tempKey, header->handshake.encryptedTempKey, 32);
#ifdef Log_DEBUG
- assert(!Bits_isZero(header->handshake.encryptedTempKey, 32));
+ Assert_true(!Bits_isZero(header->handshake.encryptedTempKey, 32));
#endif
#ifdef Log_KEYS
uint8_t tempKeyHex[65];
@@ -834,9 +834,9 @@ static uint8_t receiveMessage(struct Message* received, struct Interface* interf
Log_debug(wrapper->context->logger, "Dropped runt");
return Error_UNDERSIZE_MESSAGE;
}
- assert(received->padding >= 12 || "need at least 12 bytes of padding in incoming message");
+ Assert_true(received->padding >= 12 || "need at least 12 bytes of padding in incoming message");
#ifdef Log_DEBUG
- assert(!((uintptr_t)received->bytes % 4) || !"alignment fault");
+ Assert_true(!((uintptr_t)received->bytes % 4) || !"alignment fault");
#endif
Message_shift(received, -4);
View
2 crypto/CryptoAuth_benchmark.c
@@ -23,7 +23,7 @@
#include "util/Time.h"
#include "wire/Error.h"
-#include <assert.h>
+#include "util/Assert.h"
#include <stdio.h>
#include <event2/event.h>
View
1 crypto/test/CMakeLists.txt
@@ -15,6 +15,7 @@ string(REGEX REPLACE "^.*/" "" main_dir_name ${CMAKE_SOURCE_DIR})
string(REPLACE ${CMAKE_SOURCE_DIR} ${main_dir_name} this_dir ${CMAKE_CURRENT_SOURCE_DIR})
message("-- Tests to run for " ${this_dir})
remove_definitions(-Werror)
+add_definitions(-DTEST)
#allow us to test internal CryptoAuth.c functions.
add_library(exports Exports.c)
View
10 crypto/test/CryptoAuth_test.c
@@ -22,7 +22,7 @@
#include "util/Endian.h"
#include "wire/Error.h"
-#include <assert.h>
+#include "util/Assert.h"
#include <stdio.h>
#include <event2/event.h>
@@ -64,7 +64,7 @@ static uint8_t sendMessageToIf2(struct Message* message, struct Interface* iface
{
uint32_t nonce = Endian_bigEndianToHost32(((uint32_t*)message->bytes)[0]);
printf("sent message --> nonce=%d\n", nonce);
- assert(message->length + message->padding <= BUFFER_SIZE);
+ Assert_always(message->length + message->padding <= BUFFER_SIZE);
if2->receiveMessage(message, if2);
return Error_NONE;
}
@@ -73,7 +73,7 @@ static uint8_t sendMessageToIf1(struct Message* message, struct Interface* iface
{
uint32_t nonce = Endian_bigEndianToHost32(((uint32_t*)message->bytes)[0]);
printf("sent message <-- nonce=%d\n", nonce);
- assert(message->length + message->padding <= BUFFER_SIZE);
+ Assert_always(message->length + message->padding <= BUFFER_SIZE);
if1->receiveMessage(message, if1);
return Error_NONE;
}
@@ -142,7 +142,7 @@ static int sendToIf1(const char* x)
if1Msg = NULL;
MK_MSG(x);
cif2->sendMessage(&msg, cif2);
- assert(if1Msg);
+ Assert_always(if1Msg);
if (strcmp((char*)if1Msg, x) != 0) {
printf("expected %s, got %s\n", x, (char*)if1Msg);
return -1;
@@ -155,7 +155,7 @@ static int sendToIf2(const char* x)
if2Msg = NULL;
MK_MSG(x);
cif1->sendMessage(&msg, cif1);
- assert(if2Msg);
+ Assert_always(if2Msg);
if (strcmp((char*)if2Msg, x) != 0) {
printf("expected %s, got %s\n", x, (char*)if2Msg);
return -1;
View
30 crypto/test/CryptoAuth_unit_test.c
@@ -25,7 +25,7 @@
#include "wire/Error.h"
#include "wire/Message.h"
-#include <assert.h>
+#include "util/Assert.h"
#include <stdio.h>
#include <event2/event.h>
@@ -61,10 +61,10 @@ void encryptRndNonceTest()
Hex_encode(output, 57, m.bytes, m.length);
//printf("\n%s\n%s\n", (char*) expected, (char*) output);
- assert(!memcmp(expected, output, 56));
+ Assert_always(!memcmp(expected, output, 56));
- assert(!Exports_decryptRndNonce(nonce, &m, secret));
- assert(m.length == 12 && !memcmp(m.bytes, "hello world", m.length));
+ Assert_always(!Exports_decryptRndNonce(nonce, &m, secret));
+ Assert_always(m.length == 12 && !memcmp(m.bytes, "hello world", m.length));
}
void createNew()
@@ -75,7 +75,7 @@ void createNew()
/*for (int i = 0; i < 32; i++) {
printf("%.2x", ca->publicKey[i]);
}*/
- assert(memcmp(ca->publicKey, publicKey, 32) == 0);
+ Assert_always(memcmp(ca->publicKey, publicKey, 32) == 0);
}
static uint8_t receiveMessage(struct Message* message, struct Interface* iface)
@@ -136,7 +136,7 @@ struct CryptoAuth_Wrapper* setUp(uint8_t* myPrivateKey,
void testHello(uint8_t* password, uint8_t* expectedOutput)
{
- assert(strlen((char*)expectedOutput) == 264);
+ Assert_always(strlen((char*)expectedOutput) == 264);
struct Message* outMessage;
struct CryptoAuth_Wrapper* wrapper =
setUp(NULL, (uint8_t*) "wxyzabcdefghijklmnopqrstuv987654", password, &outMessage);
@@ -151,7 +151,7 @@ void testHello(uint8_t* password, uint8_t* expectedOutput)
Exports_encryptHandshake(&msg, wrapper);
uint8_t actual[265];
- assert(Hex_encode(actual, 265, outMessage->bytes, outMessage->length) > 0);
+ Assert_always(Hex_encode(actual, 265, outMessage->bytes, outMessage->length) > 0);
//printf("%s", actual);
if (memcmp(actual, expectedOutput, 264)) {
printf("Test failed.\n"
@@ -195,7 +195,7 @@ void receiveHelloWithNoAuth()
"29ea3e12";
uint8_t message[132];
- assert(Hex_decode(message, 132, messageHex, strlen((char*)messageHex)) > 0);
+ Assert_always(Hex_decode(message, 132, messageHex, strlen((char*)messageHex)) > 0);
struct Message incoming = {
.length = 132,
.padding = 0,
@@ -210,9 +210,9 @@ void receiveHelloWithNoAuth()
Exports_receiveMessage(&incoming, &(struct Interface) { .receiverContext = wrapper } );
- assert(finalOut);
- assert(finalOut->length == 12);
- assert(memcmp(hello, finalOut->bytes, 12) == 0);
+ Assert_always(finalOut);
+ Assert_always(finalOut->length == 12);
+ Assert_always(memcmp(hello, finalOut->bytes, 12) == 0);
//printf("bytes=%s length=%u\n", finalOut->bytes, finalOut->length);
}
@@ -253,7 +253,7 @@ void repeatHello()
Exports_encryptHandshake(&msg2, &wrapper);
// Check the nonce
- assert(!memcmp(msg2.bytes, "\0\0\0\1", 4));
+ Assert_always(!memcmp(msg2.bytes, "\0\0\0\1", 4));
ca = CryptoAuth_new(NULL, allocator, privateKey, eventBase, &logger);
struct Message* finalOut = NULL;
@@ -268,9 +268,9 @@ void repeatHello()
Exports_receiveMessage(out, &(struct Interface) { .receiverContext = &wrapper2 } );
- assert(finalOut);
- assert(finalOut->length == 12);
- assert(memcmp(hello, finalOut->bytes, 12) == 0);
+ Assert_always(finalOut);
+ Assert_always(finalOut->length == 12);
+ Assert_always(memcmp(hello, finalOut->bytes, 12) == 0);
//printf("bytes=%s length=%u\n", finalOut->bytes, finalOut->length);
}
View
4 crypto/test/ReplayProtector_test.c
@@ -15,7 +15,7 @@
#include "crypto/ReplayProtector.h"
#include "crypto/Crypto.h"
-#include <assert.h>
+#include "util/Assert.h"
#include <stdint.h>
int main()
@@ -36,7 +36,7 @@ int main()
for (uint32_t i = 0; i < outIdx; i++) {
for (uint32_t j = i + 1; j < outIdx; j++) {
- assert(out[i] != out[j]);
+ Assert_always(out[i] != out[j]);
}
}
View
2 dht/Address.h
@@ -48,7 +48,7 @@ struct Address
uint64_t path;
};
#define Address_SIZE (Address_SEARCH_TARGET_SIZE + Address_KEY_SIZE + Address_NETWORK_ADDR_SIZE)
-Assert_assertTrue(sizeof(struct Address) == Address_SIZE);
+Assert_compileTime(sizeof(struct Address) == Address_SIZE);
static inline uint32_t Address_getPrefix(struct Address* addr)
{
View
8 dht/AddressMapper.h
@@ -17,7 +17,7 @@
#include "util/Bits.h"
-#include <assert.h>
+#include "util/Assert.h"
#include <inttypes.h>
#include <string.h>
@@ -54,7 +54,7 @@ static inline int AddressMapper_indexOf(uint64_t label, struct AddressMapper* ma
Bits_memcpyConst(map->addresses[i - 1], address, 16);
i--;
}
- assert(!memcmp(map->canary, "\0\0\0", 3));
+ Assert_true(!memcmp(map->canary, "\0\0\0", 3));
map->accessNumber++;
return i;
}
@@ -76,7 +76,7 @@ static inline int AddressMapper_remove(int index, struct AddressMapper* map)
Bits_memcpyConst(map->addresses[index], map->addresses[i], 16);
map->labels[index] = map->labels[i];
map->labels[i] = 0L;
- assert(!memcmp(map->canary, "\0\0\0", 3));
+ Assert_true(!memcmp(map->canary, "\0\0\0", 3));
return 0;
}
}
@@ -96,7 +96,7 @@ static inline int AddressMapper_put(uint64_t label, uint8_t address[16], struct
}
Bits_memcpyConst(map->addresses[i], address, 16);
map->labels[i] = label;
- assert(!memcmp(map->canary, "\0\0\0", 3));
+ Assert_true(!memcmp(map->canary, "\0\0\0", 3));
return i;
}
View
4 dht/DHTModuleRegistry.c
@@ -22,7 +22,7 @@
#include "benc/serialization/BencSerializer.h"
#include "benc/serialization/standard/StandardBencSerializer.h"
-#include <assert.h>
+#include "util/Assert.h"
#include <string.h>
#define DEBUG2(x, y)
@@ -83,7 +83,7 @@ void DHTModuleRegistry_handleIncoming(struct DHTMessage* message,
static int dhtModuleHandleOutgoing(struct DHTModule* module, struct DHTMessage* message)
{
- assert(module != NULL);
+ Assert_true(module != NULL);
if (module->handleOutgoing) {
DEBUG2(">> calling: %s->handleOutgoing\n", module->name);
return module->handleOutgoing(message, module->context);
View
2 dht/dhtcore/NodeHeader.h
@@ -37,6 +37,6 @@ struct NodeHeader
/** The number interface of the next hop to get to this node. */
uint32_t switchIndex;
};
-Assert_assertTrue(sizeof(struct NodeHeader) == 12);
+Assert_compileTime(sizeof(struct NodeHeader) == 12);
#endif
View
10 dht/dhtcore/NodeStore.c
@@ -33,7 +33,7 @@
#include "switch/NumberCompress.h"
#include "switch/LabelSplicer.h"
-#include <assert.h>
+#include "util/Assert.h"
#include <stdbool.h>
#include <stdio.h>
@@ -107,7 +107,7 @@ static inline void replaceNode(struct Node* const nodeToReplace,
headerToReplace->switchIndex = getSwitchIndex(addr);
store->labelSum -= Bits_log2x64(nodeToReplace->address.path);
store->labelSum += Bits_log2x64(addr->path);
- assert(store->labelSum > 0);
+ Assert_true(store->labelSum > 0);
Bits_memcpyConst(&nodeToReplace->address, addr, sizeof(struct Address));
}
@@ -142,7 +142,7 @@ struct Node* NodeStore_addNode(struct NodeStore* store,
Log_critical1(store->logger,
"tried to insert address %s which does not begin with 0xFC.\n",
address);
- assert(false);
+ Assert_true(false);
}
uint32_t pfx = Address_getPrefix(addr);
@@ -198,7 +198,7 @@ struct Node* NodeStore_addNode(struct NodeStore* store,
else if (store->headers[i].addressPrefix == pfx) {
uint8_t realAddr[16];
AddressCalc_addressForPublicKey(realAddr, addr->key);
- assert(!memcmp(realAddr, addr->ip6.bytes, 16));
+ Assert_true(!memcmp(realAddr, addr->ip6.bytes, 16));
}
#endif
}
@@ -402,7 +402,7 @@ struct Node* NodeStore_getNodeByNetworkAddr(uint64_t path, struct NodeStore* sto
void NodeStore_remove(struct Node* node, struct NodeStore* store)
{
- assert(node >= store->nodes && node < store->nodes + store->size);
+ Assert_true(node >= store->nodes && node < store->nodes + store->size);
#ifdef Log_DEBUG
uint8_t addr[60];
View
2 dht/dhtcore/SearchStore.c
@@ -200,7 +200,7 @@ static String* tidForSearchNodeIndex(const struct SearchNodeIndex* index,
// Make sure the above computations are run at compile time.
// Only works if using -O3 and obviously not platform independent.
- //assert(__builtin_constant_p(totalBytes));
+ //Assert_true(__builtin_constant_p(totalBytes));
uint32_t out = (index->node << maxSearchBits) | index->search;
View
2 dht/dhtcore/test/CMakeLists.txt
@@ -14,7 +14,7 @@ cmake_minimum_required(VERSION 2.4)
string(REGEX REPLACE "^.*/" "" main_dir_name ${CMAKE_SOURCE_DIR})
string(REPLACE ${CMAKE_SOURCE_DIR} ${main_dir_name} this_dir ${CMAKE_CURRENT_SOURCE_DIR})
message("-- Tests to run for " ${this_dir})
-add_definitions(-g)
+add_definitions(-g -DTEST)
# Anything in this dir which ends with "test.c" is considered a test.
file(GLOB tests "*test.c")
View
28 dht/dhtcore/test/RouterModule_test_disabled.c
@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
-#include <assert.h>
+#include "util/Assert.h"
#include <string.h>
#include <stdio.h>
#include <event2/event.h>
@@ -64,8 +64,8 @@ void testQuery(struct DHTMessage** outMessagePtr,
DHTModules_handleIncoming(&message, registry);
struct DHTMessage* outMessage = *outMessagePtr;
- assert(outMessage != NULL);
- assert(outMessage->replyTo != NULL);
+ Assert_always(outMessage != NULL);
+ Assert_always(outMessage->replyTo != NULL);
// Another hack because the output contains nulls, see: #define ADD_NODE()
for (int i = 0; i < outMessage->length; i++) {
@@ -92,8 +92,8 @@ void testQuery(struct DHTMessage** outMessagePtr,
"4:txid" "2:aa"
"e";
- assert(outMessage->length == strlen(expectedResponse));
- assert(memcmp(outMessage->bytes, expectedResponse, strlen(expectedResponse)) == 0);
+ Assert_always(outMessage->length == strlen(expectedResponse));
+ Assert_always(memcmp(outMessage->bytes, expectedResponse, strlen(expectedResponse)) == 0);
}
bool testSearch_callback(void* context, struct DHTMessage* message)
@@ -119,7 +119,7 @@ void testSearch(struct DHTMessage** outMessagePtr,
routerModule);
struct DHTMessage* outMessage = *outMessagePtr;
- assert(outMessage != NULL);
+ Assert_always(outMessage != NULL);
// Need to be able to work around the fact that the string contains nulls.
#define EXPECTED_OUTPUT(tid) \
@@ -135,13 +135,13 @@ void testSearch(struct DHTMessage** outMessagePtr,
//printf("\n%s\n", outMessage->bytes);
//printf("\n%s\n", outMessage->peerAddress);
- assert(outMessage->length == strlen(EXPECTED_OUTPUT("xx")));
- assert(memcmp(outMessage->bytes, EXPECTED_OUTPUT("8\x00"), outMessage->length) == 0);
- //assert(strcmp(outMessage->address->networkAddress, " 00014 ") == 0);
+ Assert_always(outMessage->length == strlen(EXPECTED_OUTPUT("xx")));
+ Assert_always(memcmp(outMessage->bytes, EXPECTED_OUTPUT("8\x00"), outMessage->length) == 0);
+ //Assert_always(strcmp(outMessage->address->networkAddress, " 00014 ") == 0);
// In a normal DHT, 00014 is the closest node, however, 00011 has sent us a message in
// testQuery() and thus his reach is 1 and he beats all other nodes which are 0-reach.
// Search queries are allowed to select nodes which are further from the target than us.
- assert(strcmp((char*) &outMessage->address->networkAddress_be, " 00011 ") == 0);
+ Assert_always(strcmp((char*) &outMessage->address->networkAddress_be, " 00011 ") == 0);
#undef EXPECTED_OUTPUT
@@ -175,7 +175,7 @@ void testSearch(struct DHTMessage** outMessagePtr,
DHTModules_handleIncoming(&message, registry);
// Make sure the callback was called.
- assert(callbackMessage != NULL);
+ Assert_always(callbackMessage != NULL);
// Make sure the node was promoted for it's fine service :P
struct Address addr;
@@ -184,12 +184,12 @@ void testSearch(struct DHTMessage** outMessagePtr,
struct Node* node1 =
NodeStore_getNode(routerModule->nodeStore, &addr);
//printf("node reach = %d", node1->reach);
- assert(node1->reach == 1601894175);
+ Assert_always(node1->reach == 1601894175);
/* outMessage = *outMessagePtr;
- assert(outMessage != NULL);
+ Assert_always(outMessage != NULL);
- assert(strcmp("000022", outMessage->peerAddress) == 0);*/
+ Assert_always(strcmp("000022", outMessage->peerAddress) == 0);*/
}
int main()
View
4 dht/test/CMakeLists.txt
@@ -14,9 +14,7 @@ cmake_minimum_required(VERSION 2.4)
string(REGEX REPLACE "^.*/" "" main_dir_name ${CMAKE_SOURCE_DIR})
string(REPLACE ${CMAKE_SOURCE_DIR} ${main_dir_name} this_dir ${CMAKE_CURRENT_SOURCE_DIR})
message("-- Tests to run for " ${this_dir})
-add_definitions(-g)
-
-# don't ask
+add_definitions(-g -DTEST)
# Anything in this dir which ends with "test.c" is considered a test.
file(GLOB tests "*test.c")
View
16 interface/InterfaceController.c
@@ -125,7 +125,7 @@ static inline struct Endpoint* moveEndpointIfNeeded(struct Endpoint* ep,
for (int i = 0; i < MAX_INTERFACES; i++) {
struct Endpoint* thisEp = &ic->endpoints[i];
if (thisEp >= ep) {
- assert(i == 0 || thisEp == ep);
+ Assert_true(i == 0 || thisEp == ep);
break;
}
if (thisEp->external == NULL) {
@@ -167,8 +167,8 @@ static uint8_t receivedAfterCryptoAuth(struct Message* msg, struct Interface* cr
static uint8_t sendFromSwitch(struct Message* msg, struct Interface* switchIf)
{
struct Endpoint* ep = switchIf->senderContext;
- assert(ep->switchIf.senderContext == ep);
- assert(ep->internal.sendMessage);
+ Assert_true(ep->switchIf.senderContext == ep);
+ Assert_true(ep->internal.sendMessage);
return ep->cryptoAuthIf->sendMessage(msg, ep->cryptoAuthIf);
}
@@ -178,7 +178,7 @@ static void closeInterface(void* vendpoint)
struct InterfaceController* ic = toClose->internal.senderContext;
int index = InterfaceMap_indexOf(toClose->key, ic->imap);
- assert(index >= 0);
+ Assert_true(index >= 0);
InterfaceMap_remove(index, ic->imap);
// flag the entry as nolonger used.
@@ -196,7 +196,7 @@ static uint8_t sendMessage(struct Message* message, struct Interface* iface)
Message_shift(message, InterfaceController_KEY_SIZE);
Bits_memcpyConst(message->bytes, ep->key, InterfaceController_KEY_SIZE);
- assert(ep->external);
+ Assert_true(ep->external);
return ep->external->sendMessage(message, ep->external);
}
@@ -207,9 +207,9 @@ static inline struct Endpoint* getEndpoint(uint8_t key[InterfaceController_KEY_S
if (index > -1) {
struct Endpoint* ep = endpointForInternalInterface(ic->imap->interfaces[index]);
#ifdef Log_DEBUG
- assert(ep->external || !"Entry was not removed from the map but was null.");
- assert(&ep->internal == ic->imap->interfaces[index]);
- assert(!memcmp(key, ep->key, InterfaceController_KEY_SIZE));
+ Assert_true(ep->external || !"Entry was not removed from the map but was null.");
+ Assert_true(&ep->internal == ic->imap->interfaces[index]);
+ Assert_true(!memcmp(key, ep->key, InterfaceController_KEY_SIZE));
#endif
return ep;
}
View
4 interface/UDPInterface.c
@@ -26,7 +26,7 @@
#include "wire/Message.h"
#include "wire/Error.h"
-#include <assert.h>
+#include "util/Assert.h"
#include <event2/event.h>
#include <arpa/inet.h>
#include <sys/types.h>
@@ -117,7 +117,7 @@ static inline void keyForSockaddr(uint8_t key[InterfaceController_KEY_SIZE],
static uint8_t sendMessage(struct Message* message, struct Interface* iface)
{
struct UDPInterface* context = iface->senderContext;
- assert(&context->interface == iface);
+ Assert_true(&context->interface == iface);
struct sockaddr_in sin;
sockaddrForKey(&sin, message->bytes, context);
View
1 interface/test/CMakeLists.txt
@@ -14,6 +14,7 @@ cmake_minimum_required(VERSION 2.4)
string(REGEX REPLACE "^.*/" "" main_dir_name ${CMAKE_SOURCE_DIR})
string(REPLACE ${CMAKE_SOURCE_DIR} ${main_dir_name} this_dir ${CMAKE_CURRENT_SOURCE_DIR})
message("-- Tests to run for " ${this_dir})
+add_definitions(-DTEST)
# Anything in this dir which ends with "test.c" is considered a test.
file(GLOB tests "*test.c")
View
6 interface/test/InterfaceController_test.c
@@ -91,8 +91,8 @@ static int reconnectionNewEndpointTest(struct InterfaceController* ifController,
icIface.receiveMessage(outgoing, &icIface);
message = *fromSwitchPtr;
- assert(message);
- assert(message->length == 24);
+ Assert_always(message);
+ Assert_always(message->length == 24);
Hex_encode(hexBuffer, 1025, message->bytes, message->length);
printf("%s\n", hexBuffer);
@@ -121,7 +121,7 @@ static int reconnectionNewEndpointTest(struct InterfaceController* ifController,
}
// make sure the interface has been switched back into position 0.
- assert(!strcmp((char*)hexBuffer, "00000000000000000000000068656c6c6f20776f726c6400"));
+ Assert_always(!strcmp((char*)hexBuffer, "00000000000000000000000068656c6c6f20776f726c6400"));
return 0;
}
View
2 io/test/CMakeLists.txt
@@ -14,7 +14,7 @@ cmake_minimum_required(VERSION 2.4)
string(REGEX REPLACE "^.*/" "" main_dir_name ${CMAKE_SOURCE_DIR})
string(REPLACE ${CMAKE_SOURCE_DIR} ${main_dir_name} this_dir ${CMAKE_CURRENT_SOURCE_DIR})
message("-- Tests to run for " ${this_dir})
-add_definitions(-g)
+add_definitions(-g -DTEST)
# Anything in this dir which ends with "test.c" is considered a test.
file(GLOB tests "*test.c")
View
4 io/test/FileReader_test.c
@@ -44,13 +44,13 @@ int main()
r->skip(300, r);
r->read(buffer2+128+128+256, 128, r);
- assert(r->bytesRead(r) == 128+128+128+512+256+300+128);
+ Assert_always(r->bytesRead(r) == 128+128+128+512+256+300+128);
uint8_t* ptr1 = buffer1;
uint8_t* ptr2 = buffer2;
#define SKIP(x) ptr1 += x
- #define CMP(x) assert(!memcmp(ptr1, ptr2, x)); ptr1 += x; ptr2 += x
+ #define CMP(x) Assert_always(!memcmp(ptr1, ptr2, x)); ptr1 += x; ptr2 += x
CMP(128);
SKIP(128);
View
1 memory/test/CMakeLists.txt
@@ -15,6 +15,7 @@ string(REGEX REPLACE "^.*/" "" main_dir_name ${CMAKE_SOURCE_DIR})
string(REPLACE ${CMAKE_SOURCE_DIR} ${main_dir_name} this_dir ${CMAKE_CURRENT_SOURCE_DIR})
message("-- Tests to run for " ${this_dir})
remove_definitions(-Werror)
+add_definitions(-DTEST)
# Anything in this dir which ends with "test.c" is considered a test.
file(GLOB tests "*test.c")
View
12 memory/test/MallocAllocator_test.c
@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <assert.h>
+#include "util/Assert.h"
#include <string.h>
#include <stdint.h>
#include <stdio.h>
@@ -28,21 +28,21 @@ int main()
struct Allocator* alloc = MallocAllocator_new(2048);
size_t bytesUsed;
- assert((bytesUsed = MallocAllocator_bytesAllocated(alloc)) == 0);
+ Assert_always((bytesUsed = MallocAllocator_bytesAllocated(alloc)) == 0);
alloc->malloc(25, alloc);
bytesUsed += 25 + ALLOCATION_SIZE;
- assert(MallocAllocator_bytesAllocated(alloc) == bytesUsed);
+ Assert_always(MallocAllocator_bytesAllocated(alloc) == bytesUsed);
struct Allocator* child = alloc->child(alloc);
bytesUsed += ALLOCATION_SIZE + ALLOCATOR_SIZE;
- assert(MallocAllocator_bytesAllocated(alloc) == bytesUsed);
+ Assert_always(MallocAllocator_bytesAllocated(alloc) == bytesUsed);
child->malloc(30, child);
bytesUsed += 30 + ALLOCATION_SIZE;
- assert(MallocAllocator_bytesAllocated(alloc) == bytesUsed);
+ Assert_always(MallocAllocator_bytesAllocated(alloc) == bytesUsed);
child->free(child);
bytesUsed -= 30 + ALLOCATION_SIZE;
bytesUsed -= ALLOCATION_SIZE + ALLOCATOR_SIZE;
- assert(MallocAllocator_bytesAllocated(alloc) == bytesUsed);
+ Assert_always(MallocAllocator_bytesAllocated(alloc) == bytesUsed);
}
View
8 net/Ducttape.c
@@ -38,7 +38,7 @@
#include "crypto_stream_salsa20.h"
-#include <assert.h>
+#include "util/Assert.h"
#include <stdint.h>
#include <event2/event.h>
#include <setjmp.h>
@@ -484,7 +484,7 @@ static inline uint8_t outgoingFromMe(struct Message* message, struct Ducttape* c
// be flipped to send it back to the other node.
if (isForMe(message, context)) {
struct Headers_IP6Header* ip6 = (struct Headers_IP6Header*) message->bytes;
- assert(context->ip6Header == ip6);
+ Assert_true(context->ip6Header == ip6);
Bits_memcpyConst(ip6->destinationAddr, ip6->sourceAddr, 16);
Bits_memcpyConst(ip6->sourceAddr, &context->myAddr.ip6.bytes, 16);
// It came from me...
@@ -519,7 +519,7 @@ static uint8_t incomingFromCryptoAuth(struct Message* message, struct Interface*
} else if (layer == OUTER_LAYER) {
return incomingFromRouter(message, context);
}
- assert(false);
+ Assert_true(false);
return 0;
}
@@ -533,7 +533,7 @@ static uint8_t outgoingFromCryptoAuth(struct Message* message, struct Interface*
} else if (layer == OUTER_LAYER) {
return sendToSwitch(message, context->switchHeader, context);
}
- assert(false);
+ Assert_true(false);
return 0;
}
View
4 net/SwitchPinger.c
@@ -60,7 +60,7 @@ static uint8_t receiveMessage(struct Message* msg, struct Interface* iface)
struct SwitchPinger* ctx = iface->receiverContext;
struct Headers_SwitchHeader* switchHeader = (struct Headers_SwitchHeader*) msg->bytes;
ctx->incomingLabel = Endian_bigEndianToHost64(switchHeader->label_be);
- assert(Headers_getMessageType(switchHeader) == Headers_SwitchHeader_TYPE_CONTROL);
+ Assert_true(Headers_getMessageType(switchHeader) == Headers_SwitchHeader_TYPE_CONTROL);
Message_shift(msg, -Headers_SwitchHeader_SIZE);
struct Control* ctrl = (struct Control*) msg->bytes;
if (ctrl->type_be == Control_PONG_be) {
@@ -112,7 +112,7 @@ static void sendPing(String* data, void* sendPingContext)
.bytes = &buffer[BUFFER_SZ - (data->len + 8 - (data->len % 8))]
};
msg.padding = msg.bytes - buffer;
- assert(data->len < (BUFFER_SZ / 2));
+ Assert_true(data->len < (BUFFER_SZ / 2));
Bits_memcpy(msg.bytes, data->bytes, data->len);
Message_shift(&msg, Control_HEADER_SIZE);
View
6 switch/SwitchCore.c
@@ -94,7 +94,7 @@ struct ErrorPacket {
struct Headers_SwitchHeader switchHeader;
struct Control ctrl;
};
-Assert_assertTrue(sizeof(struct ErrorPacket) == Headers_SwitchHeader_SIZE + sizeof(struct Control));
+Assert_compileTime(sizeof(struct ErrorPacket) == Headers_SwitchHeader_SIZE + sizeof(struct Control));
static inline void sendError(struct SwitchInterface* interface,
struct Message* cause,
@@ -226,8 +226,8 @@ void SwitchCore_swapInterfaces(struct Interface* if1, struct Interface* if2)
struct SwitchInterface* si1 = (struct SwitchInterface*) if1->receiverContext;
struct SwitchInterface* si2 = (struct SwitchInterface*) if2->receiverContext;
- assert(if1->allocator->notOnFree(si1->onFree, if1->allocator));
- assert(if2->allocator->notOnFree(si2->onFree, if2->allocator));
+ Assert_true(if1->allocator->notOnFree(si1->onFree, if1->allocator));
+ Assert_true(if2->allocator->notOnFree(si2->onFree, if2->allocator));
struct SwitchInterface si3;
Bits_memcpyConst(&si3, si1, sizeof(struct SwitchInterface));
View
2 switch/test/CMakeLists.txt
@@ -14,7 +14,7 @@ cmake_minimum_required(VERSION 2.4)
string(REGEX REPLACE "^.*/" "" main_dir_name ${CMAKE_SOURCE_DIR})
string(REPLACE ${CMAKE_SOURCE_DIR} ${main_dir_name} this_dir ${CMAKE_CURRENT_SOURCE_DIR})
message("-- Tests to run for " ${this_dir})
-add_definitions(-g)
+add_definitions(-g -DTEST)
# Anything in this dir which ends with "test.c" is considered a test.
file(GLOB tests "*test.c")
View
6 switch/test/LabelSplicer_test.c
@@ -15,7 +15,7 @@
#include "switch/LabelSplicer.h"
#include "util/Endian.h"
-#include <assert.h>
+#include "util/Assert.h"
#include <stdio.h>
#include <inttypes.h>
@@ -35,12 +35,12 @@ static void splice()
printf("Splicing %" PRIu64 " with %" PRIu64 " yields %" PRIu64 ", expecting %" PRIu64 "\n",
goHere, viaHere, out, expected);
- assert(expected == out);
+ Assert_always(expected == out);
}
static void isOneHop()
{
- assert(LabelSplicer_isOneHop(4));
+ Assert_always(LabelSplicer_isOneHop(4));
}
int main()
View
2 test/CMakeLists.txt
@@ -14,7 +14,7 @@ cmake_minimum_required(VERSION 2.4)
string(REGEX REPLACE "^.*/" "" main_dir_name ${CMAKE_SOURCE_DIR})
string(REPLACE ${CMAKE_SOURCE_DIR} ${main_dir_name} this_dir ${CMAKE_CURRENT_SOURCE_DIR})
message("-- Tests to run for " ${this_dir})
-add_definitions(-g)
+add_definitions(-g -DTEST)
add_library(TestFramework TestFramework.c)
target_link_libraries(TestFramework
View
54 util/Assert.h
@@ -12,21 +12,51 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef Assert_H
+ // This is needed every time the file is pulled in to prevent struct name collisions.
+ #define Assert_COUNTER2 Assert_COUNTER
+ #undef Assert_COUNTER
+ #define Assert_COUNTER Assert_GLUE(Assert_COUNTER2, x)
+#else
+#define Assert_H
+
+#include "util/Log.h"
+#include <stdio.h>
+
+/* Internals */
+#define Assert_COUNTER x
+#define Assert_UNIQUE_NAME Assert_MAKE_NAME(Assert_COUNTER, __LINE__)
+#define Assert_MAKE_NAME(x, y) Assert_MAKE_NAME2(x, y)
+#define Assert_MAKE_NAME2(x, y) Assert_testStruct_ ## x ## y
+#define Assert_GLUE(x, y) x ## y
+#define Assert_STRING(x) #x
+
+static inline void Assert_internal(const char* expr, int isTrue, const char* file, int line)
+{
+ if (!isTrue) {
+ fprintf(stderr, "%s:%d Assertion failed: %s", file, line, expr);
+ abort();
+ }
+}
/**
- * Prevent compilation if assertion is false.
+ * Assert_compileTime()
+ *
+ * Prevent compilation if assertion is false or not a compile time constant.
* Thanks to http://www.jaggersoft.com/pubs/CVu11_3.html
*/
-#ifdef Assert_COUNTER
- #define Assert_COUNTER2 Assert_COUNTER
- #undef Assert_COUNTER
- #define Assert_COUNTER Assert_GLUE(Assert_COUNTER2, x)
+#define Assert_compileTime(isTrue) struct Assert_UNIQUE_NAME { unsigned int assertFailed : (isTrue); }
+
+
+/** Runtime assertion which is always applied. */
+#define Assert_always(expr) Assert_internal(Assert_STRING(expr), (expr) ? 1 : 0, __FILE__, __LINE__)
+
+/** Include normal assertions if debug logging is enabled since it has a preformance hit already. */
+#ifndef Log_DEBUG
+ #define Assert_true(expr)
#else
- #define Assert_COUNTER x
- #define Assert_UNIQUE_NAME Assert_MAKE_NAME(Assert_COUNTER, __LINE__)
- #define Assert_MAKE_NAME(x, y) Assert_MAKE_NAME2(x, y)
- #define Assert_MAKE_NAME2(x, y) Assert_testStruct_ ## x ## y
- #define Assert_GLUE(x, y) x ## y
- #define Assert_assertTrue(isTrue) \
- struct Assert_UNIQUE_NAME { unsigned int assertFailed : (isTrue); }
+ #define Assert_true(expr) Assert_always(expr)
+#endif
+
+
#endif
View
2 util/Bits.h
@@ -126,7 +126,7 @@ static inline void* Bits_memcpyDebug(void* out,
*/
#ifdef HAS_BUILTIN_CONSTANT_P
#define Bits_memcpyConst(a, b, c) \
- Assert_assertTrue(__builtin_constant_p(c) == 1); \
+ Assert_compileTime(__builtin_constant_p(c) == 1); \
Bits_memcpy(a, b, c)
#else
#define Bits_memcpyConst(a, b, c) Bits_memcpy(a, b, c)
View
8 util/test/Base32_test.c
@@ -16,7 +16,7 @@
#include "util/Base32.h"
#include <stdio.h>
-#include <assert.h>
+#include "util/Assert.h"
int main()
{
@@ -26,12 +26,12 @@ int main()
uint8_t base32[64];
memset(base32, 0, 64);
- assert(Base32_encode(base32, 64, bytes, 32) == 52);
+ Assert_always(Base32_encode(base32, 64, bytes, 32) == 52);
//printf("base32 encoded: %s\n", base32);
uint8_t bytes2[32];
- assert(Base32_decode(bytes2, 32, base32, 52) == 32);
+ Assert_always(Base32_decode(bytes2, 32, base32, 52) == 32);
- assert(memcmp(bytes, bytes2, 32) == 0);
+ Assert_always(memcmp(bytes, bytes2, 32) == 0);
}
View
8 util/test/Bits_test.c
@@ -16,14 +16,14 @@
#include "util/Bits.h"
#include <stdio.h>
-#include <assert.h>
+#include "util/Assert.h"
int main()
{
uint64_t x;
randombytes((uint8_t*) &x, 8);
- assert(Bits_bitReverse64(Bits_bitReverse64(x)) == x);
- assert(Bits_bitReverse64(1) == ((uint64_t)1)<<63);
- assert(Bits_bitReverse64(0) == 0);
+ Assert_always(Bits_bitReverse64(Bits_bitReverse64(x)) == x);
+ Assert_always(Bits_bitReverse64(1) == ((uint64_t)1)<<63);
+ Assert_always(Bits_bitReverse64(0) == 0);
}
View
1 util/test/CMakeLists.txt
@@ -15,6 +15,7 @@ string(REGEX REPLACE "^.*/" "" main_dir_name ${CMAKE_SOURCE_DIR})
string(REPLACE ${CMAKE_SOURCE_DIR} ${main_dir_name} this_dir ${CMAKE_CURRENT_SOURCE_DIR})
message("-- Tests to run for " ${this_dir})
remove_definitions(-Werror)
+add_definitions(-DTEST)
# Anything in this dir which ends with "test.c" is considered a test.
file(GLOB tests "*_test.c")
View
8 util/test/Checksum_test.c
@@ -17,7 +17,7 @@
#include "util/Hex.h"
#include "util/Checksum.h"
-#include <assert.h>
+#include "util/Assert.h"
#include <stdio.h>
@@ -45,7 +45,7 @@ void checksumAlgorithmTest()
uint16_t calcatedSum = Checksum_engine(packet, 20);
//printf("%2x == %2x", checksum, calcatedSum);
- assert(checksum == calcatedSum);
+ Assert_always(checksum == calcatedSum);
}
@@ -78,7 +78,7 @@ void udp6ChecksumTest()
uint16_t calcatedSum = Checksum_udpIp6(&packet[8], &packet[40], 25);
//printf("%2x == %2x", udp6Checksum, calcatedSum);
- assert(udp6Checksum == calcatedSum);
+ Assert_always(udp6Checksum == calcatedSum);
}
@@ -113,7 +113,7 @@ void icmp6ChecksumTest()
uint16_t calcatedSum = Checksum_icmp6(&packet[8], &packet[40], 64);
//printf("%2x == %2x", checksum, calcatedSum);
- assert(checksum == calcatedSum);
+ Assert_always(checksum == calcatedSum);
}
View
2 util/test/Endian_benchmark.c
@@ -17,7 +17,7 @@
#include "util/Time.h"
#include <stdio.h>
-#include <assert.h>
+#include "util/Assert.h"
int main()
{
View
22 util/test/Endian_test.c
@@ -15,7 +15,7 @@
#include "util/Endian.h"
#include <stdio.h>
-#include <assert.h>
+#include "util/Assert.h"
void printInfo()
{
@@ -41,17 +41,17 @@ int main()
volatile uint16_t sc = 0xbeca;
if (!Endian_isBigEndian()) {
- assert(c == Endian_bigEndianToHost16(sc));
- assert(a == Endian_bigEndianToHost32(sa));
- assert(a == Endian_littleEndianToHost32(a));
- assert(b == Endian_bigEndianToHost64(sb));
+ Assert_always(c == Endian_bigEndianToHost16(sc));
+ Assert_always(a == Endian_bigEndianToHost32(sa));
+ Assert_always(a == Endian_littleEndianToHost32(a));
+ Assert_always(b == Endian_bigEndianToHost64(sb));
} else {
- assert(c == Endian_bigEndianToHost16(c));
- assert(a == Endian_bigEndianToHost32(a));
- assert(a == Endian_littleEndianToHost32(sa));
- assert(b == Endian_bigEndianToHost64(b));
+ Assert_always(c == Endian_bigEndianToHost16(c));
+ Assert_always(a == Endian_bigEndianToHost32(a));
+ Assert_always(a == Endian_littleEndianToHost32(sa));
+ Assert_always(b == Endian_bigEndianToHost64(b));
}
- assert(b == Endian_byteSwap64(sb));
- assert(a == Endian_byteSwap32(sa));
+ Assert_always(b == Endian_byteSwap64(sb));
+ Assert_always(a == Endian_byteSwap32(sa));
}
View
8 util/test/Hex_test.c
@@ -16,7 +16,7 @@
#include "util/Hex.h"
#include <stdio.h>
-#include <assert.h>
+#include "util/Assert.h"
int main()
{
@@ -25,12 +25,12 @@ int main()
uint8_t hex[64] = {0};
- assert(Hex_encode(hex, 65, bytes, 32) == 64);
+ Assert_always(Hex_encode(hex, 65, bytes, 32) == 64);
//printf("hex encoded: %s\n", hex);
uint8_t bytes2[32];
- assert(Hex_decode(bytes2, 32, hex, 64) == 32);
+ Assert_always(Hex_decode(bytes2, 32, hex, 64) == 32);
- assert(memcmp(bytes, bytes2, 32) == 0);
+ Assert_always(memcmp(bytes, bytes2, 32) == 0);
}
View
6 wire/Control.h
@@ -32,7 +32,7 @@ struct Control_Error
/** The header of the packet which caused the error. */
struct Headers_SwitchHeader cause;
};
-Assert_assertTrue(sizeof(struct Control_Error) == Control_Error_MIN_SIZE);
+Assert_compileTime(sizeof(struct Control_Error) == Control_Error_MIN_SIZE);
/**
@@ -50,7 +50,7 @@ struct Control_Ping
*/
uint8_t data[Control_Ping_MIN_SIZE];
};
-Assert_assertTrue(sizeof(struct Control_Ping) == Control_Ping_MIN_SIZE);
+Assert_compileTime(sizeof(struct Control_Ping) == Control_Ping_MIN_SIZE);
/**
@@ -116,6 +116,6 @@ struct Control
} content;
};
// Control_Error is the largest structure and thus defines the length of the "content" union.
-Assert_assertTrue(sizeof(struct Control) == Control_HEADER_SIZE + Control_Error_MIN_SIZE);
+Assert_compileTime(sizeof(struct Control) == Control_HEADER_SIZE + Control_Error_MIN_SIZE);
#endif
View
10 wire/Headers.h
@@ -54,7 +54,7 @@ struct Headers_SwitchHeader
uint32_t lowBits_be;
};
#define Headers_SwitchHeader_SIZE 12
-Assert_assertTrue(sizeof(struct Headers_SwitchHeader) == Headers_SwitchHeader_SIZE);
+Assert_compileTime(sizeof(struct Headers_SwitchHeader) == Headers_SwitchHeader_SIZE);
static inline uint32_t Headers_getMessageType(const struct Headers_SwitchHeader* header)
@@ -117,7 +117,7 @@ union Headers_AuthChallenge
};
/** Total size of the auth structure. */
#define Headers_AuthChallenge_SIZE 12
-Assert_assertTrue(sizeof(union Headers_AuthChallenge) == Headers_AuthChallenge_SIZE);
+Assert_compileTime(sizeof(union Headers_AuthChallenge) == Headers_AuthChallenge_SIZE);
/** The number of bytes from the beginning which identify the auth for looking up the secret. */
#define Headers_AuthChallenge_KEYSIZE 8
@@ -278,7 +278,7 @@ union Headers_CryptoAuth
} handshake;
};
#define Headers_CryptoAuth_SIZE 120
-Assert_assertTrue(sizeof(union Headers_CryptoAuth) == Headers_CryptoAuth_SIZE);
+Assert_compileTime(sizeof(union Headers_CryptoAuth) == Headers_CryptoAuth_SIZE);
struct Headers_IP6Header
{
@@ -296,14 +296,14 @@ struct Headers_IP6Header
uint8_t destinationAddr[16];
};
#define Headers_IP6Header_SIZE 40
-Assert_assertTrue(sizeof(struct Headers_IP6Header) == Headers_IP6Header_SIZE);
+Assert_compileTime(sizeof(struct Headers_IP6Header) == Headers_IP6Header_SIZE);
struct Headers_UDPHeader {
uint32_t sourceAndDestPorts;
uint16_t length_be;
uint16_t checksum_be;
};
#define Headers_UDPHeader_SIZE 8
-Assert_assertTrue(sizeof(struct Headers_UDPHeader) == Headers_UDPHeader_SIZE);
+Assert_compileTime(sizeof(struct Headers_UDPHeader) == Headers_UDPHeader_SIZE);
#endif
View
10 wire/Message.h
@@ -15,7 +15,7 @@
#ifndef Message_H
#define Message_H
-#include <assert.h>
+#include "util/Assert.h"
#include <stdbool.h>
#include <stdint.h>
@@ -68,13 +68,13 @@ static inline void Message_copyOver(struct Message* output,
*/
static inline bool Message_shift(struct Message* toShift, int32_t amount)
{
- assert(toShift->padding >= amount);
- assert((amount >= 0) ? (UINT16_MAX - toShift->length >= amount) : (toShift->length >= -amount));
-assert(toShift->length < 60000);
+ Assert_true(toShift->padding >= amount);
+ Assert_true((amount >= 0) ? (UINT16_MAX - toShift->length >= amount) : (toShift->length >= -amount));
+Assert_true(toShift->length < 60000);
toShift->length += amount;
toShift->bytes -= amount;
toShift->padding -= amount;
-assert(toShift->length < 60000);
+Assert_true(toShift->length < 60000);
return true;
}

0 comments on commit 99035a1

Please sign in to comment.