diff --git a/Makefile b/Makefile index 4f9cba8..e1e70fc 100644 --- a/Makefile +++ b/Makefile @@ -105,17 +105,17 @@ report: valgrind: FLAGS += $(DEBUG_FLAGS) valgrind: build valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose \ - $(OUT) -s -o $(BIN_DIR)/%d :: 64536 2> $(BIN_DIR)/valgrind.txt + $(OUT) -o $(BIN_DIR)/%d :: 64536 2> $(BIN_DIR)/valgrind.txt helgrind: FLAGS += $(DEBUG_FLAGS) helgrind: build valgrind --tool=helgrind \ - $(OUT) -s -n 12 -N 4 -o $(BIN_DIR)/%d :: 64536 2> $(BIN_DIR)/helgrind.txt + $(OUT) -o $(BIN_DIR)/%d :: 64536 2> $(BIN_DIR)/helgrind.txt memcheck: FLAGS += $(DEBUG_FLAGS) memcheck: build valgrind --tool=memcheck --track-origins=yes \ - $(OUT) -n 12 -N 4 -o $(BIN_DIR)/%d :: 64536 2> $(BIN_DIR)/memcheck.txt + $(OUT) -o $(BIN_DIR)/%d :: 64536 2> $(BIN_DIR)/memcheck.txt callgrind: FLAGS += -O3 -ggdb callgrind: build diff --git a/headers/errors.h b/headers/errors.h index 051d5dc..d83a8f3 100644 --- a/headers/errors.h +++ b/headers/errors.h @@ -6,106 +6,106 @@ typedef enum Errors { /** An argument was NULL */ - NULL_ARGUMENT, + NULL_ARGUMENT = 0, /** An item was already allocated */ - ALREADY_ALLOCATED, + ALREADY_ALLOCATED = 1, /** An item was already deallocated */ - ALREADY_DEALLOCATED, + ALREADY_DEALLOCATED = 2, /** Failed to allocate (malloc/calloc) */ - FAILED_TO_ALLOCATE, + FAILED_TO_ALLOCATE = 3, /** Failed to copy (memcpy) */ - FAILED_TO_COPY, + FAILED_TO_COPY = 4, /** Failed to open (fopen/socket) */ - FAILED_TO_OPEN, + FAILED_TO_OPEN = 5, /** The length of an incoming packet is too short to be decoded (corruption) */ - PACKET_TOO_SHORT, + PACKET_TOO_SHORT = 6, /** The length of an incoming packet is too long (corruption) */ - PACKET_TOO_LONG, + PACKET_TOO_LONG = 7, /** The length encoded in a packet is higher than 512 */ - PACKET_INCORRECT_LENGTH, + PACKET_INCORRECT_LENGTH = 8, /** The packet type is wrong (i.e packet->type = IGNORE) */ - TYPE_IS_WRONG, + TYPE_IS_WRONG = 9, /** Packet truncated of not of type dATA */ - NON_DATA_TRUNCATED, + NON_DATA_TRUNCATED = 10, /** CRC1 validation failed */ - CRC_VALIDATION_FAILED, + CRC_VALIDATION_FAILED = 11, /** CRC2 validation failed */ - PAYLOAD_VALIDATION_FAILED, + PAYLOAD_VALIDATION_FAILED = 12, /** Payload is longer than 512 bytes */ - PAYLOAD_TOO_LONG, + PAYLOAD_TOO_LONG = 13, /** Failed to compile output file format REGEX */ - REGEX_COMPILATION_FAILED, + REGEX_COMPILATION_FAILED = 14, /** Missing an option value */ - CLI_O_VALUE_MISSING, + CLI_O_VALUE_MISSING = 15, /** Unknown option */ - CLI_UNKNOWN_OPTION, + CLI_UNKNOWN_OPTION = 16, /** Missing the IP filter */ - CLI_IP_MISSING, + CLI_IP_MISSING = 17, /** Missing the port */ - CLI_PORT_MISSING, + CLI_PORT_MISSING = 18, /** Too many arguments on the CLI */ - CLI_TOO_MANY_ARGUMENTS, + CLI_TOO_MANY_ARGUMENTS = 19, /** Output file format validation failed (did not pass regex) */ - CLI_FORMAT_VALIDATION_FAILED, + CLI_FORMAT_VALIDATION_FAILED = 20, /** IP format invalid */ - CLI_IP_INVALID, + CLI_IP_INVALID = 21, /** Maximum value invalid */ - CLI_MAX_INVALID, + CLI_MAX_INVALID = 22, /** Port invalid (invalid value/range) */ - CLI_PORT_INVALID, + CLI_PORT_INVALID = 23, /** Number of handlers/receivers invalid */ - CLI_HANDLE_INVALID, + CLI_HANDLE_INVALID = 24, /** Maximum window size invalid */ - CLI_WINDOW_INVALID, + CLI_WINDOW_INVALID = 25, /** Failed to convert form a string to an int */ - STR2INT_INCONVERTIBLE, + STR2INT_INCONVERTIBLE = 26, /** Failed to convert form a string to an int (overflow) */ - STR2INT_OVERFLOW, + STR2INT_OVERFLOW = 27, /** Failed to convert form a string to an int (underflow) */ - STR2INT_UNDERFLOW, + STR2INT_UNDERFLOW = 28, /** Failed to convert form a string to an int (not the whole string) */ - STR2INT_NOT_END, + STR2INT_NOT_END = 29, /** Failed to create a pthread_mutex_t */ - FAILED_TO_INIT_MUTEX, + FAILED_TO_INIT_MUTEX = 30, /** Failed to create a pthread_cond_t */ - FAILED_TO_INIT_COND, + FAILED_TO_INIT_COND = 31, /** Failed to resize (hashtable) */ - FAILED_TO_RESIZE, + FAILED_TO_RESIZE = 32, /** Unknown/internal error */ - UNKNOWN + UNKNOWN = 255 } errors_t; diff --git a/headers/global.h b/headers/global.h index 971c529..0cef756 100644 --- a/headers/global.h +++ b/headers/global.h @@ -76,8 +76,12 @@ #define false 0 typedef int bool; +/** Converts from an DEFINE to a string, used for CLI */ +#define STR_HELPER(x) #x +#define STR(x) STR_HELPER(x) + /** Minimum size of a packet (in bytes) */ -#define MIN_PACKET_SIZE 11 +#define MIN_PACKET_SIZE 11 /** Maximum size of a packet (in bytes) */ #define MAX_PACKET_SIZE 528 @@ -88,23 +92,19 @@ typedef int bool; /** Maximum size of a receive window */ #define MAX_WINDOW_SIZE 31 -/** Maximum size of a receive window as a string */ -#define MAX_WINDOW_SIZE_STR "31" - /** Maximum size of a buffer */ -#define MAX_BUFFER_SIZE 32 +#define MAX_BUFFER_SIZE 32 -/** Default concurrent capacity as string */ -#define DEFAULT_MAX_CAPACITY_STR "100" +#define DEFAULT_MAX_CAPACITY 100 -/** Default number of receiver thread as string */ -#define DEFAULT_RECEIVER_NUM_STR "1" +/** Default output file name format as string */ +#define DEFAULT_OUT_FORMAT "%d" -/** Default number of handler thread as string */ -#define DEFAULT_HANDLER_NUM_STR "2" +/** Default number of handlers */ +#define DEFAULT_HANDLER_COUNT 2 -/** Default output file name format as string */ -#define DEFAULT_OUT_FORMAT "%d" +/** Default number of receivers */ +#define DEFAULT_RECEIVER_COUNT 1 #ifndef GETSET diff --git a/headers/lookup.h b/headers/lookup.h index 7e7fb1c..157667a 100644 --- a/headers/lookup.h +++ b/headers/lookup.h @@ -10,13 +10,14 @@ * A window lookup table used to check if a seqnum * is in a particular window. The way to check if * it is in the window is by doing : + * * ```c * sequences[window_low][seqnum] * ``` * * Where `window_low` is the lowest seqnum present * in the window and `seqnum` is the sequence number - * of check. + * to check. * * The value is `1` if it is in the window and `0` * otherwise. diff --git a/src/cli.c b/src/cli.c index b33833d..c763a5c 100644 --- a/src/cli.c +++ b/src/cli.c @@ -8,19 +8,19 @@ int parse_receiver(int argc, char *argv[], config_rcv_t *config) { int c; /** Maximum number of active connections */ - char *m = DEFAULT_MAX_CAPACITY_STR; + char *m = STR(DEFAULT_MAX_CAPACITY); /** Maximum number of packets received in a single syscall */ - char *W = MAX_WINDOW_SIZE_STR; + char *W = STR(MAX_BUFFER_SIZE); /** Maximum advertised window size */ - char *w = MAX_WINDOW_SIZE_STR; + char *w = STR(MAX_WINDOW_SIZE); /** Number of handler thread */ - char *n = DEFAULT_HANDLER_NUM_STR; + char *n = STR(DEFAULT_HANDLER_COUNT); /** Number of receiver thread */ - char *N = DEFAULT_RECEIVER_NUM_STR; + char *N = STR(DEFAULT_RECEIVER_COUNT); /** Output file format */ char *o = DEFAULT_OUT_FORMAT; diff --git a/tests/buffer_test.c b/tests/buffer_test.c index af32497..eda3707 100644 --- a/tests/buffer_test.c +++ b/tests/buffer_test.c @@ -1,9 +1,11 @@ #include "./headers/buffer_test.h" +#define INCREMENT 1 + void test_fill_and_empty() { int i = 0; int j = 0; - for (j = 0; j < 256; j += 16) { + for (j = 0; j < 256; j += INCREMENT) { buf_t *buf = malloc( sizeof(buf_t)); int alloc = initialize_buffer(buf, &allocate_packet); CU_ASSERT(alloc == 0); diff --git a/tests/ht_test.c b/tests/ht_test.c index 3e732aa..0aff671 100644 --- a/tests/ht_test.c +++ b/tests/ht_test.c @@ -14,7 +14,7 @@ void test_ht_put_and_get() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; - uint16_t i; + int i; for (i = 0; i < N; i++) { client_t *client = malloc(sizeof(client_t)); memset(client, 0, sizeof(client_t)); diff --git a/tests/stream_test.c b/tests/stream_test.c index c18fdb7..3419b3d 100644 --- a/tests/stream_test.c +++ b/tests/stream_test.c @@ -14,10 +14,10 @@ void test_single() { CU_ASSERT(initialize_node(node, empty_allocator) == 0); CU_ASSERT(stream_enqueue(&stream, node, false) == true); - //CU_ASSERT(stream.length == 1); + CU_ASSERT(stream.length == 1); CU_ASSERT(stream_pop(&stream, false) != NULL); - //CU_ASSERT(stream.length == 0); + CU_ASSERT(stream.length == 0); dealloc_stream(&stream); @@ -39,7 +39,7 @@ void test_many() { CU_ASSERT(stream_enqueue(&stream, node, false) == true); - //CU_ASSERT(stream.length == i + 1); + CU_ASSERT(stream.length == i + 1); } for (i = 0; i < 1024; i++) { @@ -50,7 +50,7 @@ void test_many() { deallocate_node(node); } - //CU_ASSERT(stream.length == 1023 - i); + CU_ASSERT(stream.length == 1023 - i); } dealloc_stream(&stream);