Add unit test for C# setting of session options config entry. (#5073)

Make error message slightly more user friendly.
This commit is contained in:
Scott McKay 2020-09-07 20:15:33 +10:00 committed by GitHub
parent 5d60d57ce2
commit 36dc057913
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -84,6 +84,11 @@ namespace Microsoft.ML.OnnxRuntime.Tests
Assert.Throws<OnnxRuntimeException>(() => { opt.GraphOptimizationLevel = (GraphOptimizationLevel)10; });
opt.AddSessionConfigEntry("key", "value");
var ex = Assert.Throws<OnnxRuntimeException>(() => { opt.AddSessionConfigEntry("", "invalid key"); });
Assert.Contains("[ErrorCode:InvalidArgument] Config key is empty", ex.Message);
opt.AppendExecutionProvider_CPU(1);
#if USE_DNNL
opt.AppendExecutionProvider_Dnnl(0);

View file

@ -28,11 +28,11 @@ const std::string SessionOptions::GetConfigOrDefault(const std::string& config_k
Status SessionOptions::AddConfigEntry(const char* config_key, const char* config_value) noexcept {
std::string key(config_key);
if (key.empty() || key.length() > 128)
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "config_key is empty or longer than maximum length 128");
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Config key is empty or longer than maximum length 128");
std::string val(config_value);
if (val.length() > 1024)
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "config_value is longer than maximum length 1024");
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Config value is longer than maximum length 1024");
auto iter = session_configurations.find(config_key);
if (iter != session_configurations.cend()) {