File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / charon-tkm / tests / tests.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 3 09:46:45 2020 UTC (4 years, 3 months ago) by misho
Branches: strongswan, MAIN
CVS tags: v5_9_2p0, v5_8_4p7, HEAD
Strongswan

    1: /*
    2:  * Copyright (C) 2013 Tobias Brunner
    3:  * Copyright (C) 2012-2014 Reto Buerki
    4:  * Copyright (C) 2012 Adrian-Ken Rueegsegger
    5:  * HSR Hochschule fuer Technik Rapperswil
    6:  *
    7:  * This program is free software; you can redistribute it and/or modify it
    8:  * under the terms of the GNU General Public License as published by the
    9:  * Free Software Foundation; either version 2 of the License, or (at your
   10:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
   11:  *
   12:  * This program is distributed in the hope that it will be useful, but
   13:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   14:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   15:  * for more details.
   16:  */
   17: 
   18: #include <tests/test_runner.h>
   19: 
   20: #include <library.h>
   21: #include <daemon.h>
   22: 
   23: #include "tkm.h"
   24: #include "tkm_nonceg.h"
   25: #include "tkm_diffie_hellman.h"
   26: #include "tkm_kernel_ipsec.h"
   27: 
   28: /* declare test suite constructors */
   29: #define TEST_SUITE(x) test_suite_t* x();
   30: #define TEST_SUITE_DEPEND(x, ...) TEST_SUITE(x)
   31: #include "tests.h"
   32: #undef TEST_SUITE
   33: #undef TEST_SUITE_DEPEND
   34: 
   35: static test_configuration_t tests[] = {
   36: #define TEST_SUITE(x) \
   37: 	{ .suite = x, },
   38: #define TEST_SUITE_DEPEND(x, type, ...) \
   39: 	{ .suite = x, .feature = PLUGIN_DEPENDS(type, __VA_ARGS__) },
   40: #include "tests.h"
   41: 	{ .suite = NULL, }
   42: };
   43: 
   44: static bool tkm_initialized = false;
   45: 
   46: static bool test_runner_init(bool init)
   47: {
   48: 	bool result = TRUE;
   49: 
   50: 	if (init)
   51: 	{
   52: 		libcharon_init();
   53: 		lib->settings->set_int(lib->settings,
   54: 							   "test-runner.filelog.stdout.default", 0);
   55: 		charon->load_loggers(charon);
   56: 
   57: 		/* Register TKM specific plugins */
   58: 		static plugin_feature_t features[] = {
   59: 			PLUGIN_REGISTER(NONCE_GEN, tkm_nonceg_create),
   60: 				PLUGIN_PROVIDE(NONCE_GEN),
   61: 			PLUGIN_CALLBACK(kernel_ipsec_register, tkm_kernel_ipsec_create),
   62: 				PLUGIN_PROVIDE(CUSTOM, "kernel-ipsec"),
   63: 		};
   64: 		lib->plugins->add_static_features(lib->plugins, "tkm-tests", features,
   65: 										  countof(features), TRUE, NULL, NULL);
   66: 
   67: 		lib->settings->set_int(lib->settings, "%s.dh_mapping.%d", 1,
   68: 							   lib->ns, MODP_3072_BIT);
   69: 		lib->settings->set_int(lib->settings, "%s.dh_mapping.%d", 2,
   70: 							   lib->ns, MODP_4096_BIT);
   71: 		register_dh_mapping();
   72: 
   73: 		plugin_loader_add_plugindirs(BUILDDIR "/src/libstrongswan/plugins",
   74: 									 PLUGINS);
   75: 		plugin_loader_add_plugindirs(BUILDDIR "/src/libcharon/plugins",
   76: 									 PLUGINS);
   77: 		if (charon->initialize(charon, PLUGINS))
   78: 		{
   79: 			if (!tkm_initialized)
   80: 			{
   81: 				if (!tkm_init())
   82: 				{
   83: 					return FALSE;
   84: 				}
   85: 				tkm_initialized = true;
   86: 			}
   87: 			return TRUE;
   88: 		}
   89: 		result = FALSE;
   90: 	}
   91: 
   92: 	destroy_dh_mapping();
   93: 	libcharon_deinit();
   94: 	return result;
   95: }
   96: 
   97: int main(int argc, char *argv[])
   98: {
   99: 	bool result;
  100: 
  101: 	/* disable leak detective because of how tkm_init/deinit is called, which
  102: 	 * does not work otherwise due to limitations of the external libraries */
  103: 	setenv("LEAK_DETECTIVE_DISABLE", "1", 1);
  104: 
  105: 	result = test_runner_run("tkm", tests, test_runner_init);
  106: 	tkm_deinit();
  107: 
  108: 	return result;
  109: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>