Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/include/cuopt/linear_programming/cuopt_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ cuopt_int_t cuOptGetErrorStatus(cuOptSolution solution, cuopt_int_t* error_statu
* @param[out] error_string_ptr - A pointer to a char that on output will contain the
* error string.
*
* @param[in] error_string_size - Size of the char buffer/
* @param[in] error_string_size - Size of the char buffer. Must be positive.
*
* @return A status code indicating success or failure.
*/
Expand Down
1 change: 1 addition & 0 deletions cpp/src/pdlp/cuopt_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,7 @@ cuopt_int_t cuOptGetErrorString(cuOptSolution solution,
{
if (solution == nullptr) { return CUOPT_INVALID_ARGUMENT; }
if (error_string_ptr == nullptr) { return CUOPT_INVALID_ARGUMENT; }
if (error_string_size <= 0) { return CUOPT_INVALID_ARGUMENT; }
solution_and_stream_view_t* solution_and_stream_view =
static_cast<solution_and_stream_view_t*>(solution);
std::string error_string = solution_and_stream_view->get_solution()->get_error_status().what();
Expand Down
24 changes: 24 additions & 0 deletions cpp/tests/linear_programming/c_api_tests/c_api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <string>

#include <cuopt/linear_programming/cuopt_c.h>
#include <cuopt/error.hpp>
#include <cuopt/linear_programming/cpu_optimization_problem_solution.hpp>
#include <pdlp/cuopt_c_internal.hpp>

#include <utilities/common_utils.hpp>
Expand Down Expand Up @@ -107,6 +109,28 @@ TEST(c_api, solve_time_bb_preemption)

TEST(c_api, bad_parameter_name) { EXPECT_EQ(test_bad_parameter_name(), CUOPT_INVALID_ARGUMENT); }

TEST(c_api, error_string_invalid_buffer_size)
{
using cuopt::linear_programming::cpu_lp_solution_t;
using cuopt::linear_programming::memory_backend_t;
using cuopt::linear_programming::pdlp_termination_status_t;
using cuopt::linear_programming::solution_and_stream_view_t;

constexpr const char* error_message = "validation failed";

solution_and_stream_view_t solution_handle(false, memory_backend_t::CPU);
solution_handle.lp_solution_interface_ptr = new cpu_lp_solution_t<cuopt_int_t, cuopt_float_t>(
pdlp_termination_status_t::NumericalError,
cuopt::logic_error(error_message, cuopt::error_type_t::ValidationError));

char error_string[32] = {};
EXPECT_EQ(cuOptGetErrorString(&solution_handle, error_string, 0), CUOPT_INVALID_ARGUMENT);
EXPECT_EQ(cuOptGetErrorString(&solution_handle, error_string, -1), CUOPT_INVALID_ARGUMENT);
EXPECT_EQ(cuOptGetErrorString(&solution_handle, error_string, sizeof(error_string)),
CUOPT_SUCCESS);
EXPECT_STREQ(error_string, error_message);
}

TEST(c_api, mip_get_callbacks_only) { EXPECT_EQ(test_mip_get_callbacks_only(), CUOPT_SUCCESS); }

TEST(c_api, mip_get_set_callbacks) { EXPECT_EQ(test_mip_get_set_callbacks(), CUOPT_SUCCESS); }
Expand Down