]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Unit tests: Update
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 24 May 2021 18:30:01 +0000 (13:30 -0500)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 24 May 2021 18:30:01 +0000 (13:30 -0500)
src/log.c
test/README.md
test/impersonator.c
test/rtr/pdu_test.c
test/thread_pool_test.c

index 501946df7eed8ced07d0ae1b7b2a37b384ce3d10..b52ad6ba82b9fdfe4a334dd7ee5aabc50045757a 100644 (file)
--- 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. */
 }
index 34dcbc6fd786d56f77cfd5bd201e3883ddbf5a13..79b2f12968846587b3714ef01162d74532b4b767 100644 (file)
@@ -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
index a22323150542d92bf7aa8301fdbc0cc7f3b09097..6684e2eb1c1a8ca24b41f317980d0ea2cf88786b 100644 (file)
@@ -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)
index 1ea515287cf9f579f6c48c3c48b5840770659ff4..14606be1725a0bde2a1b65e2308815cefee0b14d 100644 (file)
@@ -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;
 }
 
index de511f5a1b462d08217d054e6f56cae2fae38aab..c9c526bdd8305f3f76eefe89848c9c94dab6b844 100644 (file)
@@ -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) */