From: Alberto Leiva Popper Date: Mon, 24 May 2021 18:30:01 +0000 (-0500) Subject: Unit tests: Update X-Git-Tag: v1.5.1~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce45444e9fdc1460f81bd534ce0c42b67c533a6a;p=thirdparty%2FFORT-validator.git Unit tests: Update --- diff --git a/src/log.c b/src/log.c index 501946df..b52ad6ba 100644 --- a/src/log.c +++ b/src/log.c @@ -44,8 +44,10 @@ static struct log_config val_config; * * However, fprintf and syslog are rarely enabled at the same time, so I don't * think it's worth it. So I'm reusing the lock. + * + * "log" + "lock" = "logck" */ -static pthread_mutex_t lock; +static pthread_mutex_t logck; /** * Important: -rdynamic needs to be enabled, otherwise this does not print @@ -143,7 +145,7 @@ log_setup(void) init_config(&op_config); init_config(&val_config); - error = pthread_mutex_init(&lock, NULL); + error = pthread_mutex_init(&logck, NULL); if (error) { fprintf(ERR.stream, "pthread_mutex_init() returned %d: %s\n", error, strerror(abs(error))); @@ -238,7 +240,7 @@ void log_teardown(void) { log_disable_syslog(); - pthread_mutex_destroy(&lock); + pthread_mutex_destroy(&logck); } void @@ -286,7 +288,7 @@ lock_mutex(void) { int error; - error = pthread_mutex_lock(&lock); + error = pthread_mutex_lock(&logck); if (error) { /* * Despite being supposed to be impossible, failing to lock the @@ -306,7 +308,7 @@ unlock_mutex(void) { int error; - error = pthread_mutex_unlock(&lock); + error = pthread_mutex_unlock(&logck); if (error) print_stack_trace(strerror(error)); /* Same as above. */ } diff --git a/test/README.md b/test/README.md index 34dcbc6f..79b2f129 100644 --- a/test/README.md +++ b/test/README.md @@ -1,5 +1,16 @@ # Unit Tests -Run with +You need `check` installed: + + sudo apt install check + +Note: If you hadn't installed `check` when you ran `autogen.sh`, you will need to +run it again: + + cd .. + ./autogen.sh + ./configure + +Run the tests with make check diff --git a/test/impersonator.c b/test/impersonator.c index a2232315..6684e2eb 100644 --- a/test/impersonator.c +++ b/test/impersonator.c @@ -260,11 +260,6 @@ incidence_get_action(enum incidence_id id) return INAC_ERROR; } -void print_stack_trace(void) -{ - /* Nothing needed here */ -} - /* Impersonate HTTP config */ char const * config_get_http_user_agent(void) diff --git a/test/rtr/pdu_test.c b/test/rtr/pdu_test.c index 1ea51528..14606be1 100644 --- a/test/rtr/pdu_test.c +++ b/test/rtr/pdu_test.c @@ -74,7 +74,9 @@ int send_error_report_pdu(int fd, uint8_t version, uint16_t code, struct rtr_request const *request, char *message) { - pr_op_info(" Server sent Error Report %u: '%s'", code, message); + pr_op_info(" Server sent Error Report %u: '%s'", code, + /* gcc is complaining about logging NULL messages. WTF */ + (message != NULL) ? message : ""); return 0; } diff --git a/test/thread_pool_test.c b/test/thread_pool_test.c index de511f5a..c9c526bd 100644 --- a/test/thread_pool_test.c +++ b/test/thread_pool_test.c @@ -22,7 +22,7 @@ test_threads_work(unsigned int total_threads) int i; int error; - error = thread_pool_create(total_threads, &pool); + error = thread_pool_create("test pool", total_threads, &pool); ck_assert_int_eq(error, 0); /* Just a dummy array where each thread will modify one slot only */ @@ -33,7 +33,7 @@ test_threads_work(unsigned int total_threads) data[i] = malloc(sizeof(int)); ck_assert_ptr_ne(data[i], NULL); *data[i] = 0; - thread_pool_push(pool, thread_work, data[i]); + thread_pool_push(pool, "test task", thread_work, data[i]); } /* Wait for all to finish (~2 sec) */