Added fko-wrapper that the test suite will be able to use for valgrind operations
authorMichael Rash <mbr@cipherdyne.org>
Thu, 21 Feb 2013 02:00:46 +0000 (21:00 -0500)
committerMichael Rash <mbr@cipherdyne.org>
Thu, 21 Feb 2013 02:00:46 +0000 (21:00 -0500)
The fko_wrapper.c code is designed to call libfko functions multiple times in
order to allow valgrind to test re-execution conditions.  This ensures that
libfko code frees memory from previous calls before leaking memory.

test/fko-wrapper/fko_wrapper.c [new file with mode: 0644]
test/fko-wrapper/run_valgrind.sh [new file with mode: 0755]

diff --git a/test/fko-wrapper/fko_wrapper.c b/test/fko-wrapper/fko_wrapper.c
new file mode 100644 (file)
index 0000000..b284776
--- /dev/null
@@ -0,0 +1,74 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "fko_limits.h"
+#include "fwknop.h"
+#include "fko.h"
+
+#define ENABLE_GPG_TESTS 0
+
+int main(void) {
+
+    fko_ctx_t  ctx = NULL;
+    int        i;
+
+    for (i=0; i<5; i++) {
+        /* call fko_new() several times without also calling fko_destroy() */
+        printf("fko_new(): %d\n", fko_new(&ctx));
+    }
+
+    for (i=0; i<5; i++) {
+        printf("fko_set_spa_client_timeout(30): %d\n",
+                fko_set_spa_client_timeout(ctx, 30));
+    }
+
+    for (i=0; i<5; i++) {
+        printf("fko_set_spa_message_type(FKO_COMMAND_MSG): %d\n",
+                fko_set_spa_message_type(ctx, FKO_COMMAND_MSG));
+    }
+
+    for (i=0; i<5; i++) {
+        printf("fko_set_spa_message_type(FKO_ACCESS_MSG): %d\n",
+                fko_set_spa_message_type(ctx, FKO_ACCESS_MSG));
+    }
+
+    for (i=0; i<5; i++) {
+        printf("fko_set_timestamp(%d): %d\n",
+                i, fko_set_timestamp(ctx, i));
+    }
+
+    for (i=0; i<5; i++) {
+        printf("fko_set_spa_message(1.1.1.1,tcp/22): %d\n",
+                fko_set_spa_message(ctx, "1.1.1.1,tcp/22"));
+    }
+
+    for (i=0; i<5; i++) {
+        printf("fko_set_spa_nat_access(1.2.3.4,1234): %d\n",
+                fko_set_spa_nat_access(ctx, "1.2.3.4,1234"));
+    }
+
+    for (i=0; i<5; i++) {
+        printf("fko_set_username(someuser): %d\n",
+                fko_set_username(ctx, "someuser"));
+    }
+
+    for (i=0; i<5; i++) {
+        printf("fko_set_spa_encryption_type(FKO_ENCRYPTION_GPG): %d\n",
+                fko_set_spa_encryption_type(ctx, FKO_ENCRYPTION_GPG));
+    }
+
+    if (ENABLE_GPG_TESTS) {
+        for (i=0; i<5; i++) {
+            printf("fko_set_gpg_home_dir(/home/mbr/.gnupg): %d\n",
+                    fko_set_gpg_home_dir(ctx, "/home/mbr/.gnupg"));
+        }
+
+        for (i=0; i<5; i++) {
+            printf("fko_set_gpg_recipient(1234asdf): %d\n",
+                fko_set_gpg_recipient(ctx, "1234asdf"));
+        }
+    }
+
+    fko_destroy(ctx);
+
+    return 0;
+}
diff --git a/test/fko-wrapper/run_valgrind.sh b/test/fko-wrapper/run_valgrind.sh
new file mode 100755 (executable)
index 0000000..22c79c9
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+LD_LIBRARY_PATH=../../lib/.libs valgrind --leak-check=full --show-reachable=yes --track-origins=yes ./fko_wrapper