Skip to content

Commit

Permalink
Valgrind should be fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
bstellato committed May 17, 2019
1 parent 26d98d6 commit 97c3363
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 86 deletions.
7 changes: 7 additions & 0 deletions .valgrind-suppress.supp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
obj:*
}

{
ignore mkl_get_max_threads
Memcheck:Cond
fun:mkl_serv_domain_get_max_threads
obj:*
}

{
ignore_libiomp_intel
Memcheck:Cond
Expand Down
2 changes: 1 addition & 1 deletion ci/travis/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ${TRAVIS_BUILD_DIR}/build/out/osqp_tester

if [[ $TRAVIS_OS_NAME == "linux" ]]; then
# Check memory with valgrind
valgrind --suppressions=${TRAVIS_BUILD_DIR}/.valgrind-suppress.supp --leak-check=full --gen-suppressions=all --error-exitcode=42 ${TRAVIS_BUILD_DIR}/build/out/osqp_tester
valgrind --suppressions=${TRAVIS_BUILD_DIR}/.valgrind-suppress.supp --leak-check=full --gen-suppressions=all --track-origins=yes --error-exitcode=42 ${TRAVIS_BUILD_DIR}/build/out/osqp_tester
# Perform code coverage
cd ${TRAVIS_BUILD_DIR}/build
lcov --directory . --capture -o coverage.info # capture coverage info
Expand Down
9 changes: 2 additions & 7 deletions src/osqp.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ c_int osqp_setup(OSQPWorkspace** workp, const OSQPData *data, const OSQPSettings
# endif /* ifdef PRINTING */



# if EMBEDDED != 1

// If adaptive rho and automatic interval, but profiling disabled, we need to
Expand Down Expand Up @@ -275,6 +276,7 @@ c_int osqp_setup(OSQPWorkspace** workp, const OSQPData *data, const OSQPSettings


c_int osqp_solve(OSQPWorkspace *work) {

c_int exitflag;
c_int iter;
c_int compute_cost_function; // Boolean whether to compute the cost function
Expand Down Expand Up @@ -402,16 +404,12 @@ c_int osqp_solve(OSQPWorkspace *work) {
#endif /* ifdef PROFILING */


c_print("DEBUG: before check termination\n");

// Can we check for termination ?
can_check_termination = work->settings->check_termination &&
(iter % work->settings->check_termination == 0);

#ifdef PRINTING

c_print("DEBUG: before can print\n");

// Can we print ?
can_print = work->settings->verbose &&
((iter % PRINT_INTERVAL == 0) || (iter == 1));
Expand Down Expand Up @@ -448,8 +446,6 @@ c_int osqp_solve(OSQPWorkspace *work) {
}
#endif /* ifdef PRINTING */

c_print("DEBUG: after can print and check termination\n");
c_print("DEBUG: before adaptive rho interval \n");

#if EMBEDDED != 1
# ifdef PROFILING
Expand Down Expand Up @@ -519,7 +515,6 @@ c_int osqp_solve(OSQPWorkspace *work) {

} // End of ADMM for loop

c_print("DEBUG: after main admm loop\n");

// Update information and check termination condition if it hasn't been done
// during last iteration (max_iter reached or check_termination disabled)
Expand Down
2 changes: 1 addition & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ OSQPSettings* copy_settings(const OSQPSettings *settings) {
new->adaptive_rho = settings->adaptive_rho;
new->adaptive_rho_interval = settings->adaptive_rho_interval;
new->adaptive_rho_tolerance = settings->adaptive_rho_tolerance;
# ifndef PROFILING
# ifdef PROFILING
new->adaptive_rho_fraction = settings->adaptive_rho_fraction;
# endif
# endif // EMBEDDED != 1
Expand Down
139 changes: 70 additions & 69 deletions tests/basic_qp/test_basic_qp.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,72 +37,73 @@ static const char* test_basic_qp_solve()
// Setup correct
mu_assert("Basic QP test solve: Setup error!", exitflag == 0);


// Solve Problem
osqp_solve(work);

// // Compare solver statuses
// mu_assert("Basic QP test solve: Error in solver status!",
// work->info->status_val == sols_data->status_test);
//
// // Compare primal solutions
// mu_assert("Basic QP test solve: Error in primal solution!",
// vec_norm_inf_diff(work->solution->x, sols_data->x_test,
// data->n) < TESTS_TOL);
//
// // Compare dual solutions
// mu_assert("Basic QP test solve: Error in dual solution!",
// vec_norm_inf_diff(work->solution->y, sols_data->y_test,
// data->m) < TESTS_TOL);
//
//
// // Compare objective values
// mu_assert("Basic QP test solve: Error in objective value!",
// c_absval(work->info->obj_val - sols_data->obj_value_test) <
// TESTS_TOL);
//
// // Try to set wrong settings
// mu_assert("Basic QP test solve: Wrong value of rho not caught!",
// osqp_update_rho(work, -0.1) == 1);
//
// mu_assert("Basic QP test solve: Wrong value of max_iter not caught!",
// osqp_update_max_iter(work, -1) == 1);
//
// mu_assert("Basic QP test solve: Wrong value of eps_abs not caught!",
// osqp_update_eps_abs(work, -1.) == 1);
//
// mu_assert("Basic QP test solve: Wrong value of eps_rel not caught!",
// osqp_update_eps_rel(work, -1.) == 1);
//
// mu_assert("Basic QP test solve: Wrong value of eps_prim_inf not caught!",
// osqp_update_eps_prim_inf(work, -0.1) == 1);
//
// mu_assert("Basic QP test solve: Wrong value of eps_dual_inf not caught!",
// osqp_update_eps_dual_inf(work, -0.1) == 1);
//
// mu_assert("Basic QP test solve: Wrong value of alpha not caught!",
// osqp_update_alpha(work, 2.0) == 1);
//
// mu_assert("Basic QP test solve: Wrong value of warm_start not caught!",
// osqp_update_warm_start(work, -1) == 1);
//
// mu_assert("Basic QP test solve: Wrong value of scaled_termination not caught!",
// osqp_update_scaled_termination(work, 2) == 1);
//
// mu_assert("Basic QP test solve: Wrong value of check_termination not caught!",
// osqp_update_check_termination(work, -1) == 1);
//
// mu_assert("Basic QP test solve: Wrong value of delta not caught!",
// osqp_update_delta(work, 0.) == 1);
//
// mu_assert("Basic QP test solve: Wrong value of polish not caught!",
// osqp_update_polish(work, 2) == 1);
//
// mu_assert("Basic QP test solve: Wrong value of polish_refine_iter not caught!",
// osqp_update_polish_refine_iter(work, -1) == 1);
//
// mu_assert("Basic QP test solve: Wrong value of verbose not caught!",
// osqp_update_verbose(work, 2) == 1);
// Compare solver statuses
mu_assert("Basic QP test solve: Error in solver status!",
work->info->status_val == sols_data->status_test);

// Compare primal solutions
mu_assert("Basic QP test solve: Error in primal solution!",
vec_norm_inf_diff(work->solution->x, sols_data->x_test,
data->n) < TESTS_TOL);

// Compare dual solutions
mu_assert("Basic QP test solve: Error in dual solution!",
vec_norm_inf_diff(work->solution->y, sols_data->y_test,
data->m) < TESTS_TOL);


// Compare objective values
mu_assert("Basic QP test solve: Error in objective value!",
c_absval(work->info->obj_val - sols_data->obj_value_test) <
TESTS_TOL);

// Try to set wrong settings
mu_assert("Basic QP test solve: Wrong value of rho not caught!",
osqp_update_rho(work, -0.1) == 1);

mu_assert("Basic QP test solve: Wrong value of max_iter not caught!",
osqp_update_max_iter(work, -1) == 1);

mu_assert("Basic QP test solve: Wrong value of eps_abs not caught!",
osqp_update_eps_abs(work, -1.) == 1);

mu_assert("Basic QP test solve: Wrong value of eps_rel not caught!",
osqp_update_eps_rel(work, -1.) == 1);

mu_assert("Basic QP test solve: Wrong value of eps_prim_inf not caught!",
osqp_update_eps_prim_inf(work, -0.1) == 1);

mu_assert("Basic QP test solve: Wrong value of eps_dual_inf not caught!",
osqp_update_eps_dual_inf(work, -0.1) == 1);

mu_assert("Basic QP test solve: Wrong value of alpha not caught!",
osqp_update_alpha(work, 2.0) == 1);

mu_assert("Basic QP test solve: Wrong value of warm_start not caught!",
osqp_update_warm_start(work, -1) == 1);

mu_assert("Basic QP test solve: Wrong value of scaled_termination not caught!",
osqp_update_scaled_termination(work, 2) == 1);

mu_assert("Basic QP test solve: Wrong value of check_termination not caught!",
osqp_update_check_termination(work, -1) == 1);

mu_assert("Basic QP test solve: Wrong value of delta not caught!",
osqp_update_delta(work, 0.) == 1);

mu_assert("Basic QP test solve: Wrong value of polish not caught!",
osqp_update_polish(work, 2) == 1);

mu_assert("Basic QP test solve: Wrong value of polish_refine_iter not caught!",
osqp_update_polish_refine_iter(work, -1) == 1);

mu_assert("Basic QP test solve: Wrong value of verbose not caught!",
osqp_update_verbose(work, 2) == 1);
//

// Clean workspace
osqp_cleanup(work);
Expand Down Expand Up @@ -569,13 +570,13 @@ static const char* test_basic_qp_time_limit()
static const char* test_basic_qp()
{
mu_run_test(test_basic_qp_solve);
// #ifdef ENABLE_MKL_PARDISO
// mu_run_test(test_basic_qp_solve_pardiso);
// #endif
// mu_run_test(test_basic_qp_update);
// mu_run_test(test_basic_qp_check_termination);
// mu_run_test(test_basic_qp_update_rho);
// mu_run_test(test_basic_qp_time_limit);
#ifdef ENABLE_MKL_PARDISO
mu_run_test(test_basic_qp_solve_pardiso);
#endif
mu_run_test(test_basic_qp_update);
mu_run_test(test_basic_qp_check_termination);
mu_run_test(test_basic_qp_update_rho);
mu_run_test(test_basic_qp_time_limit);

return 0;
}
16 changes: 8 additions & 8 deletions tests/osqp_tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ int tests_run = 0;


static const char* all_tests() {
// mu_run_test(test_lin_alg);
// mu_run_test(test_solve_linsys);
mu_run_test(test_lin_alg);
mu_run_test(test_solve_linsys);
mu_run_test(test_basic_qp);
// mu_run_test(test_basic_qp2);
// mu_run_test(test_non_cvx);
// mu_run_test(test_primal_infeasibility);
// mu_run_test(test_primal_dual_infeasibility);
// mu_run_test(test_unconstrained);
// mu_run_test(test_update_matrices);
mu_run_test(test_basic_qp2);
mu_run_test(test_non_cvx);
mu_run_test(test_primal_infeasibility);
mu_run_test(test_primal_dual_infeasibility);
mu_run_test(test_unconstrained);
mu_run_test(test_update_matrices);
return 0;
}

Expand Down

0 comments on commit 97c3363

Please sign in to comment.