forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore check that GRB_LICENSE_FILE and MOSEKLM_LICENSE_FILE are set
- Loading branch information
Jamie Snape
committed
Apr 20, 2018
1 parent
b69410d
commit aa3511f
Showing
5 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <cstdlib> | ||
#include <stdexcept> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "drake/solvers/gurobi_solver.h" | ||
#include "drake/solvers/mathematical_program.h" | ||
|
||
namespace drake { | ||
namespace solvers { | ||
namespace { | ||
|
||
// These tests are deliberately not in gurobi_solver_test.cc to avoid causing | ||
// license issues during tests in that file. | ||
|
||
GTEST_TEST(GrbLicenseFileTest, GrbLicenseFileSet) { | ||
const char* grb_license_file = std::getenv("GRB_LICENSE_FILE"); | ||
ASSERT_STRNE(nullptr, grb_license_file); | ||
|
||
MathematicalProgram program; | ||
// Add a variable to avoid the "Solve" function terminating without calling | ||
// the external Gurobi solver. | ||
const auto x = program.NewContinuousVariables<1>(); | ||
GurobiSolver solver; | ||
|
||
EXPECT_NO_THROW(solver.Solve(program)); | ||
} | ||
|
||
GTEST_TEST(GrbLicenseFileTest, GrbLicenseFileUnset) { | ||
const char* grb_license_file = std::getenv("GRB_LICENSE_FILE"); | ||
ASSERT_STRNE(nullptr, grb_license_file); | ||
|
||
const int unsetenv_result = ::unsetenv("GRB_LICENSE_FILE"); | ||
ASSERT_EQ(0, unsetenv_result); | ||
|
||
MathematicalProgram program; | ||
// Add a variable to avoid the "Solve" function terminating without calling | ||
// the external Gurobi solver. | ||
const auto x = program.NewContinuousVariables<1>(); | ||
GurobiSolver solver; | ||
|
||
try { | ||
solver.Solve(program); | ||
ADD_FAILURE() << "Expected exception of type std::runtime_error."; | ||
} catch (const std::runtime_error& err) { | ||
EXPECT_EQ(err.what(), std::string("Could not locate Gurobi license key " | ||
"file because GRB_LICENSE_FILE environment variable was not set.")); | ||
} catch (...) { | ||
ADD_FAILURE() << "Expected exception of type std::runtime_error."; | ||
} | ||
|
||
const int setenv_result = ::setenv("GRB_LICENSE_FILE", grb_license_file, 1); | ||
ASSERT_EQ(0, setenv_result); | ||
} | ||
|
||
} // namespace | ||
} // namespace solvers | ||
} // namespace drake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <cstdlib> | ||
#include <stdexcept> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "drake/solvers/mathematical_program.h" | ||
#include "drake/solvers/mosek_solver.h" | ||
|
||
namespace drake { | ||
namespace solvers { | ||
namespace { | ||
|
||
// These tests is deliberately not in mosek_solver_test.cc to avoid causing | ||
// license issues during tests in that file. | ||
|
||
GTEST_TEST(MoseklmLicenseFileTest, MoseklmLicenseFileSet) { | ||
const char* moseklm_license_file = std::getenv("MOSEKLM_LICENSE_FILE"); | ||
ASSERT_STRNE(nullptr, moseklm_license_file); | ||
|
||
MathematicalProgram program; | ||
// Add a variable to avoid the "Solve" function terminating without calling | ||
// the external MOSEK solver. | ||
const auto x = program.NewContinuousVariables<1>(); | ||
MosekSolver solver; | ||
|
||
EXPECT_NO_THROW(solver.Solve(program)); | ||
} | ||
|
||
GTEST_TEST(MoseklmLicenseFileTest, MoseklmLicenseFileUnset) { | ||
const char* moseklm_license_file = std::getenv("MOSEKLM_LICENSE_FILE"); | ||
ASSERT_STRNE(nullptr, moseklm_license_file); | ||
|
||
const int unsetenv_result = ::unsetenv("MOSEKLM_LICENSE_FILE"); | ||
ASSERT_EQ(0, unsetenv_result); | ||
|
||
MathematicalProgram program; | ||
// Add a variable to avoid the "Solve" function terminating without calling | ||
// the external MOSEK solver. | ||
const auto x = program.NewContinuousVariables<1>(); | ||
MosekSolver solver; | ||
|
||
try { | ||
solver.Solve(program); | ||
ADD_FAILURE() << "Expected exception of type std::runtime_error."; | ||
} catch (const std::runtime_error& err) { | ||
EXPECT_EQ(err.what(), std::string("Could not locate MOSEK license file " | ||
"because MOSEKLM_LICENSE_FILE environment variable was not set.")); | ||
} catch (...) { | ||
ADD_FAILURE() << "Expected exception of type std::runtime_error."; | ||
} | ||
|
||
const int setenv_result = | ||
::setenv("MOSEKLM_LICENSE_FILE", moseklm_license_file, 1); | ||
ASSERT_EQ(0, setenv_result); | ||
} | ||
|
||
} // namespace | ||
} // namespace solvers | ||
} // namespace drake |