305ddebfe8c5b101474317086d5ae70db8f972ea
[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 /**
24 * Check if the plugin configuration provides a specific feature
25 */
26 static bool has_feature(plugin_feature_t feature)
27 {
28 enumerator_t *plugins, *features;
29 plugin_t *plugin;
30 linked_list_t *list;
31 plugin_feature_t *current;
32 bool found = FALSE;
33
34 plugins = lib->plugins->create_plugin_enumerator(lib->plugins);
35 while (plugins->enumerate(plugins, &plugin, &list))
36 {
37 features = list->create_enumerator(list);
38 while (features->enumerate(features, &current))
39 {
40 if (plugin_feature_matches(&feature, current))
41 {
42 found = TRUE;
43 break;
44 }
45 }
46 features->destroy(features);
47 list->destroy(list);
48 }
49 plugins->destroy(plugins);
50
51 return found;
52 }
53
54 int main()
55 {
56 SRunner *sr;
57 int nf;
58
59 /* test cases are forked and there is no cleanup, so disable leak detective.
60 * if test_suite.h is included leak detective is enabled in test cases */
61 setenv("LEAK_DETECTIVE_DISABLE", "1", 1);
62 /* redirect all output to stderr (to redirect make's stdout to /dev/null) */
63 dup2(2, 1);
64
65 library_init(NULL);
66
67 if (!lib->plugins->load(lib->plugins, NULL, PLUGINS))
68 {
69 library_deinit();
70 return EXIT_FAILURE;
71 }
72
73 sr = srunner_create(NULL);
74 srunner_add_suite(sr, bio_reader_suite_create());
75 srunner_add_suite(sr, bio_writer_suite_create());
76 srunner_add_suite(sr, chunk_suite_create());
77 srunner_add_suite(sr, enum_suite_create());
78 srunner_add_suite(sr, enumerator_suite_create());
79 srunner_add_suite(sr, linked_list_suite_create());
80 srunner_add_suite(sr, linked_list_enumerator_suite_create());
81 srunner_add_suite(sr, hashtable_suite_create());
82 srunner_add_suite(sr, identification_suite_create());
83 srunner_add_suite(sr, threading_suite_create());
84 srunner_add_suite(sr, utils_suite_create());
85 srunner_add_suite(sr, vectors_suite_create());
86 if (has_feature(PLUGIN_DEPENDS(PRIVKEY_GEN, KEY_ECDSA)))
87 {
88 srunner_add_suite(sr, ecdsa_suite_create());
89 }
90
91 srunner_run_all(sr, CK_NORMAL);
92 nf = srunner_ntests_failed(sr);
93
94 srunner_free(sr);
95 library_deinit();
96
97 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
98 }