summaryrefslogtreecommitdiff
path: root/src/libstrongswan/tests/suites
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/tests/suites')
-rw-r--r--src/libstrongswan/tests/suites/test_chunk.c27
-rw-r--r--src/libstrongswan/tests/suites/test_enum.c10
-rw-r--r--src/libstrongswan/tests/suites/test_threading.c31
-rw-r--r--src/libstrongswan/tests/suites/test_utils.c86
-rw-r--r--src/libstrongswan/tests/suites/test_vectors.c34
5 files changed, 181 insertions, 7 deletions
diff --git a/src/libstrongswan/tests/suites/test_chunk.c b/src/libstrongswan/tests/suites/test_chunk.c
index b5d23658d..312a187ac 100644
--- a/src/libstrongswan/tests/suites/test_chunk.c
+++ b/src/libstrongswan/tests/suites/test_chunk.c
@@ -61,6 +61,32 @@ START_TEST(test_chunk_equals)
END_TEST
/*******************************************************************************
+ * equals_const
+ */
+
+START_TEST(test_chunk_equals_const)
+{
+ chunk_t chunk = chunk_from_str("chunk");
+ chunk_t chunk_a, chunk_b;
+
+ chunk_a = chunk_empty;
+ chunk_b = chunk_empty;
+ ck_assert(!chunk_equals_const(chunk_a, chunk_b));
+
+ chunk_a = chunk;
+ ck_assert(!chunk_equals_const(chunk_a, chunk_b));
+ chunk_b = chunk;
+ ck_assert(chunk_equals_const(chunk_a, chunk_b));
+
+ chunk_b = chunk_from_str("asdf");
+ ck_assert(!chunk_equals_const(chunk_a, chunk_b));
+
+ chunk_b = chunk_from_str("chunk");
+ ck_assert(chunk_equals_const(chunk_a, chunk_b));
+}
+END_TEST
+
+/*******************************************************************************
* chunk_compare test
*/
@@ -1013,6 +1039,7 @@ Suite *chunk_suite_create()
tc = tcase_create("equals");
tcase_add_test(tc, test_chunk_equals);
+ tcase_add_test(tc, test_chunk_equals_const);
suite_add_tcase(s, tc);
tc = tcase_create("chunk_compare");
diff --git a/src/libstrongswan/tests/suites/test_enum.c b/src/libstrongswan/tests/suites/test_enum.c
index 53ebd2931..70bfdb2aa 100644
--- a/src/libstrongswan/tests/suites/test_enum.c
+++ b/src/libstrongswan/tests/suites/test_enum.c
@@ -291,6 +291,15 @@ START_TEST(test_enum_printf_hook_split)
}
END_TEST
+START_TEST(test_enum_printf_hook_null)
+{
+ char buf[16];
+
+ snprintf(buf, sizeof(buf), "%N", NULL, 7);
+ ck_assert_str_eq("(7)", buf);
+}
+END_TEST
+
START_TEST(test_enum_printf_hook_flags)
{
char buf[1024];
@@ -406,6 +415,7 @@ Suite *enum_suite_create()
tc = tcase_create("enum_printf_hook");
tcase_add_loop_test(tc, test_enum_printf_hook_cont, 0, countof(printf_tests_cont));
tcase_add_loop_test(tc, test_enum_printf_hook_split, 0, countof(printf_tests_split));
+ tcase_add_test(tc, test_enum_printf_hook_null);
tcase_add_loop_test(tc, test_enum_printf_hook_flags, 0, countof(printf_tests_flags));
tcase_add_loop_test(tc, test_enum_printf_hook_flags_incomplete, 0, countof(printf_tests_flags_incomplete));
tcase_add_loop_test(tc, test_enum_printf_hook_flags_null, 0, countof(printf_tests_flags_null));
diff --git a/src/libstrongswan/tests/suites/test_threading.c b/src/libstrongswan/tests/suites/test_threading.c
index 55a4cd797..9a9fdd8e9 100644
--- a/src/libstrongswan/tests/suites/test_threading.c
+++ b/src/libstrongswan/tests/suites/test_threading.c
@@ -1517,6 +1517,36 @@ START_TEST(test_cleanup_pop)
}
END_TEST
+static void *cleanup_popall_run(void *data)
+{
+ thread_cleanup_push(cleanup3, data);
+ thread_cleanup_push(cleanup2, data);
+ thread_cleanup_push(cleanup1, data);
+
+ thread_cleanup_popall();
+ return NULL;
+}
+
+START_TEST(test_cleanup_popall)
+{
+ thread_t *threads[THREADS];
+ uintptr_t values[THREADS];
+ int i;
+
+ for (i = 0; i < THREADS; i++)
+ {
+ values[i] = 1;
+ threads[i] = thread_create(cleanup_popall_run, &values[i]);
+ }
+ for (i = 0; i < THREADS; i++)
+ {
+ threads[i]->join(threads[i]);
+ ck_assert_int_eq(values[i], 4);
+ }
+}
+END_TEST
+
+
static thread_value_t *tls[10];
static void *tls_run(void *data)
@@ -1697,6 +1727,7 @@ Suite *threading_suite_create()
tcase_add_test(tc, test_cleanup_exit);
tcase_add_test(tc, test_cleanup_cancel);
tcase_add_test(tc, test_cleanup_pop);
+ tcase_add_test(tc, test_cleanup_popall);
suite_add_tcase(s, tc);
tc = tcase_create("thread local storage");
diff --git a/src/libstrongswan/tests/suites/test_utils.c b/src/libstrongswan/tests/suites/test_utils.c
index 85a854456..b38f2cb52 100644
--- a/src/libstrongswan/tests/suites/test_utils.c
+++ b/src/libstrongswan/tests/suites/test_utils.c
@@ -229,6 +229,41 @@ START_TEST(test_strpfx)
END_TEST
/*******************************************************************************
+ * mallac_align/free_align
+ */
+
+START_TEST(test_malloc_align)
+{
+ void *ptr[128][256];
+ int size, align;
+
+ for (size = 0; size < countof(ptr); size++)
+ {
+ for (align = 0; align < countof(ptr[0]); align++)
+ {
+ ptr[size][align] = malloc_align(size, align);
+ if (align)
+ {
+ ck_assert((uintptr_t)ptr[size][align] % align == 0);
+ }
+ if (size)
+ {
+ ck_assert(ptr[size][align]);
+ memset(ptr[size][align], 0xEF, size);
+ }
+ }
+ }
+ for (size = 0; size < countof(ptr); size++)
+ {
+ for (align = 0; align < countof(ptr[0]); align++)
+ {
+ free_align(ptr[size][align]);
+ }
+ }
+}
+END_TEST
+
+/*******************************************************************************
* memxor
*/
@@ -307,6 +342,48 @@ START_TEST(test_memxor_aligned)
END_TEST
/*******************************************************************************
+ * memeq/const
+ */
+
+static struct {
+ char *a;
+ char *b;
+ size_t n;
+ bool res;
+} memeq_data[] = {
+ {NULL, NULL, 0, TRUE},
+ {"a", "b", 0, TRUE},
+ {"", "", 1, TRUE},
+ {"abcdefgh", "abcdefgh", 8, TRUE},
+ {"a", "b", 1, FALSE},
+ {"A", "a", 1, FALSE},
+ {"\0a", "\0b", 2, FALSE},
+ {"abc", "abd", 3, FALSE},
+ {"abc", "dbd", 3, FALSE},
+ {"abcdefgh", "abcdffgh", 8, FALSE},
+ {"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz",
+ "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", 52, TRUE},
+ {"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz",
+ "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyy", 52, FALSE},
+ {"bbcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz",
+ "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", 52, FALSE},
+};
+
+START_TEST(test_memeq)
+{
+ ck_assert(memeq(memeq_data[_i].a, memeq_data[_i].b,
+ memeq_data[_i].n) == memeq_data[_i].res);
+}
+END_TEST
+
+START_TEST(test_memeq_const)
+{
+ ck_assert(memeq_const(memeq_data[_i].a, memeq_data[_i].b,
+ memeq_data[_i].n) == memeq_data[_i].res);
+}
+END_TEST
+
+/*******************************************************************************
* memstr
*/
@@ -774,11 +851,20 @@ Suite *utils_suite_create()
tcase_add_loop_test(tc, test_strpfx, 0, countof(strpfx_data));
suite_add_tcase(s, tc);
+ tc = tcase_create("malloc_align");
+ tcase_add_test(tc, test_malloc_align);
+ suite_add_tcase(s, tc);
+
tc = tcase_create("memxor");
tcase_add_test(tc, test_memxor);
tcase_add_test(tc, test_memxor_aligned);
suite_add_tcase(s, tc);
+ tc = tcase_create("memeq");
+ tcase_add_loop_test(tc, test_memeq, 0, countof(memeq_data));
+ tcase_add_loop_test(tc, test_memeq_const, 0, countof(memeq_data));
+ suite_add_tcase(s, tc);
+
tc = tcase_create("memstr");
tcase_add_loop_test(tc, test_memstr, 0, countof(memstr_data));
suite_add_tcase(s, tc);
diff --git a/src/libstrongswan/tests/suites/test_vectors.c b/src/libstrongswan/tests/suites/test_vectors.c
index a1205d0be..a35342837 100644
--- a/src/libstrongswan/tests/suites/test_vectors.c
+++ b/src/libstrongswan/tests/suites/test_vectors.c
@@ -19,15 +19,34 @@
#include "test_suite.h"
#include <utils/test.h>
+#include <threading/thread.h>
+#include <crypto/transform.h>
-IMPORT_FUNCTION_FOR_TESTS(crypto, verify_registered_algorithms, u_int,
- crypto_factory_t *factory);
+static transform_type_t tfs[] = {
+ ENCRYPTION_ALGORITHM,
+ AEAD_ALGORITHM,
+ INTEGRITY_ALGORITHM,
+ HASH_ALGORITHM,
+ PSEUDO_RANDOM_FUNCTION,
+ RANDOM_NUMBER_GENERATOR,
+ DIFFIE_HELLMAN_GROUP,
+};
START_TEST(test_vectors)
{
- u_int failed = TEST_FUNCTION(crypto, verify_registered_algorithms,
- lib->crypto);
- fail_if(failed > 0, "%u test vectors failed", failed);
+ enumerator_t *enumerator;
+ char *plugin;
+ bool success;
+ u_int alg;
+
+ enumerator = lib->crypto->create_verify_enumerator(lib->crypto, tfs[_i]);
+ thread_cleanup_push((void*)enumerator->destroy, enumerator);
+ while (enumerator->enumerate(enumerator, &alg, &plugin, &success))
+ {
+ ck_assert_msg(success, "test vector for %N from '%s' plugin failed",
+ transform_get_enum_names(tfs[_i]), alg, plugin);
+ }
+ thread_cleanup_pop(TRUE);
}
END_TEST
@@ -39,8 +58,9 @@ Suite *vectors_suite_create()
s = suite_create("vectors");
- tc = tcase_create("failures");
- tcase_add_test(tc, test_vectors);
+ tc = tcase_create("transforms");
+ tcase_add_loop_test(tc, test_vectors, 0, countof(tfs));
+ tcase_set_timeout(tc, 20);
suite_add_tcase(s, tc);
return s;