From 36ce07093b68b07513149577c209ae7a57ab356b Mon Sep 17 00:00:00 2001 From: Gabriele Contini <contini.mailing@gmail.com> Date: 周日, 15 3月 2020 16:26:21 +0800 Subject: [PATCH] Merge branch 'feature/pc_identifiers' into develop issues #2 #3 #14 #49 --- test/library/os/execution_environment_test.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 48 insertions(+), 0 deletions(-) diff --git a/test/library/os/execution_environment_test.cpp b/test/library/os/execution_environment_test.cpp new file mode 100644 index 0000000..b604d11 --- /dev/null +++ b/test/library/os/execution_environment_test.cpp @@ -0,0 +1,48 @@ +#define BOOST_TEST_MODULE network_test +#include <string> +#include <iostream> +#include <boost/test/unit_test.hpp> + +#include <licensecc_properties.h> +#include <licensecc_properties_test.h> +#include "../../../src/library/base/StringUtils.h" +#include "../../../src/library/os/network.hpp" +#include "../../../src/library/os/execution_environment.hpp" + +namespace license { +namespace os { +namespace test { + +using namespace license::os; +using namespace std; + +// To test if virtualization is detected correctly define an env variable VIRT_ENV +// otherwise the test is skipped +BOOST_AUTO_TEST_CASE(test_virtualization) { + const char *env = getenv("VIRTUAL_ENV"); + os::ExecutionEnvironment exec_env; + bool docker = false; + if (env != nullptr) { + os::VIRTUALIZATION virt = exec_env.getVirtualization(); + if (strcmp(env, "CONTAINER") == 0 || (docker = (strcmp(env, "DOCKER") == 0))) { + BOOST_CHECK_MESSAGE(virt == VIRTUALIZATION::CONTAINER, "container detected"); + BOOST_CHECK_MESSAGE(exec_env.is_container(), "container detected"); + if (docker) { + BOOST_CHECK_MESSAGE(exec_env.is_docker(), "docker detected"); + } + } else if (strcmp(env, "VM") == 0) { + BOOST_CHECK_MESSAGE(virt == VIRTUALIZATION::VM, "VM detected"); + BOOST_CHECK_MESSAGE(!exec_env.is_container(), "VM is not a container"); + BOOST_CHECK_MESSAGE(!exec_env.is_docker(), "VM is not a docker"); + } else if (strcmp(env, "NONE") == 0) { + BOOST_CHECK_EQUAL(virt, VIRTUALIZATION::NONE); + BOOST_CHECK_MESSAGE(!exec_env.is_container(), "not a container"); + BOOST_CHECK_MESSAGE(!exec_env.is_docker(), "not a docker"); + } else { + BOOST_FAIL(string("value ") + env + " not supported: VM,DOCKER,CONTAINER,NONE"); + } + } +} +} // namespace test +} // namespace os +} // namespace license -- Gitblit v1.9.1