From 01773048c0fd0defd0a06c1f7d24eb63c813cf69 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Fri, 7 Jun 2019 14:09:47 +0200 Subject: [PATCH] LMM Testing: - Refactoring - Add lmm_basic.cpp to the compilation chain --- teshsuite/surf/lmm_usage/lmm_basic.cpp | 50 ++++++++++++-------------- tools/cmake/Tests.cmake | 3 +- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/teshsuite/surf/lmm_usage/lmm_basic.cpp b/teshsuite/surf/lmm_usage/lmm_basic.cpp index 9129ce6a66..3d05676e11 100644 --- a/teshsuite/surf/lmm_usage/lmm_basic.cpp +++ b/teshsuite/surf/lmm_usage/lmm_basic.cpp @@ -1,42 +1,38 @@ +/* Copyright (c) 2019. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + #include "src/include/catch.hpp" #include "src/kernel/lmm/maxmin.hpp" #include "src/surf/surf_interface.hpp" #include "xbt/log.h" -#define DOUBLE_PRECISION 0.00001 - -// Namespace shortcut namespace lmm = simgrid::kernel::lmm; -// XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example"); -// XBT_INFO("V1=%g V2=%g V3=%g",V1->get_value(),V2->get_value(),V3->get_value()); - -TEST_CASE("Test on small systems", "[lmm-small-systems]") +TEST_CASE("kernel::lmm Test on small systems", "[kernel-lmm-small-sys]") { lmm::System* Sys = lmm::make_new_maxmin_system(false); - SECTION("Check variables weight (sharing_weight)") + SECTION("Basic variable weight") { - - // Create constraint - lmm::Constraint* C = Sys->constraint_new(nullptr, 10); - - // Create the 3 variables (with increasing weight from 1 to 3) - lmm::Variable* V1 = - Sys->variable_new(nullptr, 1, 0.0, 1); // id=nullptr, weight_value=1, bound=0, number_of_constraints=1 - lmm::Variable* V2 = Sys->variable_new(nullptr, 2, 0.0, 1); - lmm::Variable* V3 = Sys->variable_new(nullptr, 3, 0.0, 1); - - // Link Variables to Constraint with constant weight 1 - Sys->expand(C, V1, 1); - Sys->expand(C, V2, 1); - Sys->expand(C, V3, 1); - + /* + * System under consideration: + * 1\times\rho_1^{1} + 1\times\rho_2^{2} + 1\times\rho_3^{3} \le 10 + */ + + lmm::Constraint* sys_cnst = Sys->constraint_new(nullptr, 10); + lmm::Variable* sys_var_1 = Sys->variable_new(nullptr, 1, 0.0, 1); + lmm::Variable* sys_var_2 = Sys->variable_new(nullptr, 2, 0.0, 1); + lmm::Variable* sys_var_3 = Sys->variable_new(nullptr, 3, 0.0, 1); + + Sys->expand(sys_cnst, sys_var_1, 1); + Sys->expand(sys_cnst, sys_var_2, 1); + Sys->expand(sys_cnst, sys_var_3, 1); Sys->solve(); - // Compare with theorical values - REQUIRE(double_equals(V1->get_value(), 5.45455, DOUBLE_PRECISION)); - REQUIRE(double_equals(V2->get_value(), 2.72727, DOUBLE_PRECISION)); - REQUIRE(double_equals(V3->get_value(), 1.81818, DOUBLE_PRECISION)); + REQUIRE(double_equals(sys_var_1->get_value(), 5.45455, sg_maxmin_precision)); + REQUIRE(double_equals(sys_var_2->get_value(), 2.72727, sg_maxmin_precision)); + REQUIRE(double_equals(sys_var_3->get_value(), 1.81818, sg_maxmin_precision)); } } diff --git a/tools/cmake/Tests.cmake b/tools/cmake/Tests.cmake index 2988ed0f95..085a6359b5 100644 --- a/tools/cmake/Tests.cmake +++ b/tools/cmake/Tests.cmake @@ -100,7 +100,8 @@ set(UNIT_TESTS src/xbt/unit-tests_main.cpp src/xbt/config_test.cpp src/xbt/dict_test.cpp src/xbt/dynar_test.cpp - src/xbt/xbt_str_test.cpp) + src/xbt/xbt_str_test.cpp + teshsuite/surf/lmm_usage/lmm_basic.cpp) if (SIMGRID_HAVE_MC) set(UNIT_TESTS ${UNIT_TESTS} src/mc/sosp/Snapshot_test.cpp src/mc/sosp/PageStore_test.cpp) else() -- 2.20.1