a30b1067d98d09fc0510f473131c534d69669bd6
[strongswan.git] / src / libstrongswan / tests / test_runner.c
1 /*
2 * Copyright (C) 2013 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include <unistd.h>
17
18 #include "test_runner.h"
19
20 #include <library.h>
21 #include <plugins/plugin_feature.h>
22
23 int main()
24 {
25 SRunner *sr;
26 int nf;
27
28 /* test cases are forked and there is no cleanup, so disable leak detective.
29 * if test_suite.h is included leak detective is enabled in test cases */
30 setenv("LEAK_DETECTIVE_DISABLE", "1", 1);
31 /* redirect all output to stderr (to redirect make's stdout to /dev/null) */
32 dup2(2, 1);
33
34 library_init(NULL);
35
36 /* use non-blocking RNG to generate keys fast */
37 lib->settings->set_default_str(lib->settings,
38 "libstrongswan.plugins.random.random",
39 lib->settings->get_str(lib->settings,
40 "libstrongswan.plugins.random.urandom", "/dev/urandom"));
41
42 if (!lib->plugins->load(lib->plugins, NULL, PLUGINS))
43 {
44 library_deinit();
45 return EXIT_FAILURE;
46 }
47
48 sr = srunner_create(NULL);
49 srunner_add_suite(sr, bio_reader_suite_create());
50 srunner_add_suite(sr, bio_writer_suite_create());
51 srunner_add_suite(sr, chunk_suite_create());
52 srunner_add_suite(sr, enum_suite_create());
53 srunner_add_suite(sr, enumerator_suite_create());
54 srunner_add_suite(sr, linked_list_suite_create());
55 srunner_add_suite(sr, linked_list_enumerator_suite_create());
56 srunner_add_suite(sr, hashtable_suite_create());
57 srunner_add_suite(sr, identification_suite_create());
58 srunner_add_suite(sr, threading_suite_create());
59 srunner_add_suite(sr, utils_suite_create());
60 srunner_add_suite(sr, vectors_suite_create());
61 if (lib->plugins->has_feature(lib->plugins,
62 PLUGIN_DEPENDS(PRIVKEY_GEN, KEY_RSA)))
63 {
64 srunner_add_suite(sr, rsa_suite_create());
65 }
66 if (lib->plugins->has_feature(lib->plugins,
67 PLUGIN_DEPENDS(PRIVKEY_GEN, KEY_ECDSA)))
68 {
69 srunner_add_suite(sr, ecdsa_suite_create());
70 }
71
72 srunner_run_all(sr, CK_NORMAL);
73 nf = srunner_ntests_failed(sr);
74
75 srunner_free(sr);
76 library_deinit();
77
78 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
79 }