]> git.ipfire.org Git - people/ms/strongswan.git/commitdiff
unit-tests: Use progressive testing of transforms with test vectors
authorMartin Willi <martin@revosec.ch>
Mon, 13 Apr 2015 16:23:58 +0000 (18:23 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 15 Apr 2015 12:38:43 +0000 (14:38 +0200)
This allows us to show which transform from which plugin failed. Also, we use
the new cleanup handler functionality that allows proper deinitialization on
failure or timeout.

src/libstrongswan/tests/suites/test_vectors.c

index 65924800b060cc5a542b4c4d774abd3930d4d823..34e4a99a6feef66ff6a38adb502034c5c0f66092 100644 (file)
 #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,8 @@ 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, 8);
        suite_add_tcase(s, tc);