diff --git a/Makefile b/Makefile index 77ec1fd..af3fe0a 100644 --- a/Makefile +++ b/Makefile @@ -249,7 +249,7 @@ tests: test $(info ===========================) $(info Running all found tests... ) $(info ===========================) - for test in $(TESTBINS) ; do ./$(TESTBIN)$$test ; done + for test in $(TESTBINS) ; do time ./$(TESTBIN)$$test ; done .PHONY: debug debug: CFLAGS+= -ggdb3 diff --git a/tests/02ITest002.c b/tests/02ITest002.c index 9d6ab05..e8f67f5 100644 --- a/tests/02ITest002.c +++ b/tests/02ITest002.c @@ -109,13 +109,11 @@ void *producer(void *arg) { // Let's test if the value we have retrieved is correct: printf("Produced Event %*d: ID (%*d) - Message: %s\n", 2, i, 2, item.eventID, item.msg); - evt_counter++; fflush(stdout); + evt_counter++; } printf("Producer done. Produced %d events.\n", evt_counter); - testID++; - fflush(stdout); pthread_exit(NULL); @@ -131,34 +129,36 @@ void *consumer(void *arg) { fflush(stdout); uint32_t i; - for (i = 0; i < MAX_ITEMS; i++) + for (i = 0; i < MAX_ITEMS;) { - while (vect_is_empty(v)) - ; + // For beginners: this is how in C we convert back a void * into the original dtata_type + StackItem *item = (StackItem *)malloc(sizeof(StackItem *)); + int fetched_item = 0; + vect_lock(v); // Let's retrieve the value from the vector correctly: - // For beginners: this is how in C we convert back a void * into the original dtata_type - StackItem *item = (StackItem *)malloc(sizeof(StackItem *)); if (!vect_is_empty(v)) + { item = (StackItem *)vect_pop(v); + fetched_item = 1; + } vect_unlock(v); - if (item != NULL) + if ( fetched_item == 1 ) { // Let's test if the value we have retrieved is correct: printf("Consumed Event %*d: ID (%*d) - Message: %s\n", 2, i, 2, item->eventID, item->msg); - evt_counter++; fflush(stdout); + evt_counter++; + i++; } free(item); } printf("Consumer done. Consumed %d events.\n", evt_counter); - testID++; - fflush(stdout); pthread_exit(NULL); diff --git a/tests/02ITest003.c b/tests/02ITest003.c index b7431f6..0826e84 100644 --- a/tests/02ITest003.c +++ b/tests/02ITest003.c @@ -106,13 +106,11 @@ void *producer(void *arg) { // Let's test if the value we have retrieved is correct: printf("Produced Event %*d: ID (%*d) - Message: %s\n", 2, i, 2, item.eventID, item.msg); - evt_counter++; fflush(stdout); + evt_counter++; } printf("Producer done. Produced %d events.\n", evt_counter); - testID++; - fflush(stdout); pthread_exit(NULL); @@ -128,32 +126,34 @@ void *consumer(void *arg) { fflush(stdout); uint32_t i; - for (i = 0; i < MAX_ITEMS; i++) { - while (vect_is_empty(v)) - ; + for (i = 0; i < MAX_ITEMS;) { + // For beginners: this is how in C we convert back a void * into the original dtata_type + QueueItem *item = (QueueItem *)malloc(sizeof(QueueItem *)); + int fetched_item = 0; vect_lock(v); // Let's retrieve the value from the vector correctly: - // For beginners: this is how in C we convert back a void * into the original dtata_type - QueueItem *item = (QueueItem *)malloc(sizeof(QueueItem *)); if (!vect_is_empty(v)) + { item = (QueueItem *)vect_remove_front(v); + fetched_item=1; + } vect_unlock(v); - if ( item != NULL ) { + if ( fetched_item == 1 ) { // Let's test if the value we have retrieved is correct: printf("Consumed Event %*d: ID (%*d) - Message: %s\n", 2, i, 2, item->eventID, item->msg); - evt_counter++; fflush(stdout); + evt_counter++; + i++; } + free(item); } printf("Consumer done. Consumed %d events.\n", evt_counter); - testID++; - fflush(stdout); pthread_exit(NULL); diff --git a/tests/02ITest004.c b/tests/02ITest004.c index 290fb78..2a07f6a 100644 --- a/tests/02ITest004.c +++ b/tests/02ITest004.c @@ -116,9 +116,10 @@ void *producer(void *arg) { // Let's test if the value we have retrieved is correct: printf("T %*i produced Event %*d: ID (%*d) - Message: %s\n", 2, id, 2, i, 3, item.eventID, item.msg); - evt_counter++; fflush(stdout); + evt_counter++; } + printf("Producer thread %i done. Produced %d events.\n", id, evt_counter); fflush(stdout); @@ -157,8 +158,8 @@ void *consumer(void *arg) { { // Let's test if the value we have retrieved is correct: printf("T %*i consumed Event %*d: ID (%*d) - Message: %s\n", 2, id, 2, i, 3, item->eventID, item->msg); - evt_counter++; fflush(stdout); + evt_counter++; i++; }