Repository: microsoft/onnxruntime
File: onnxruntime/test/framework/ep_compatibility_test.cc (C++)

Code before:
      selected.push_back(d);
      break;
    }
  }

  ASSERT_FALSE(selected.empty());

  // Pick a status that the CPU EP would never return to ensure the value is set correctly.
  OrtCompiledModelCompatibility status = OrtCompiledModelCompatibility_EP_SUPPORTED_PREFER_RECOMPILATION;
  ASSERT_NO_FATAL_FAILURE({
    status = Ort::GetModelCompatibilityForEpDevices(selected, "arbitrary-compat-string");
  });

  ASSERT_TRUE(status == OrtCompiledModelCompatibility_EP_NOT_APPLICABLE);
}

// -----------------------------
// GetCompatibilityInfoFromModel Tests
// -----------------------------

TEST(EpCompatibilityCapiTest, GetCompatibilityInfoFromModel_InvalidArgs) {
  const OrtApi* api = OrtGetApiBase()->GetApi(ORT_API_VERSION);
  ASSERT_NE(api, nullptr);

  OrtAllocator* allocator = nullptr;
  api->GetAllocatorWithDefaultOptions(&allocator);
  ASSERT_NE(allocator, nullptr);

  char* compat_info = nullptr;

  // model_path == nullptr
  OrtStatus* st = api->GetCompatibilityInfoFromModel(nullptr, "TestEP", allocator, &compat_info);
  ASSERT_NE(st, nullptr);
  EXPECT_EQ(api->GetErrorCode(st), ORT_INVALID_ARGUMENT);
  api->ReleaseStatus(st);

  // ep_type == nullptr
  st = api->GetCompatibilityInfoFromModel(ORT_TSTR("test.onnx"), nullptr, allocator, &compat_info);
  ASSERT_NE(st, nullptr);
  EXPECT_EQ(api->GetErrorCode(st), ORT_INVALID_ARGUMENT);
  api->ReleaseStatus(st);

  // ep_type == empty string
  st = api->GetCompatibilityInfoFromModel(ORT_TSTR("test.onnx"), "", allocator, &compat_info);
  ASSERT_NE(st, nullptr);
  EXPECT_EQ(api->GetErrorCode(st), ORT_INVALID_ARGUMENT);
  api->ReleaseStatus(st);

  // allocator == nullptr
  st = api->GetCompatibilityInfoFromModel(ORT_TSTR("test.onnx"), "TestEP", nullptr, &compat_info);
  ASSERT_NE(st, nullptr);

Review comment (bug):
in general, the returned `OrtStatus*` should be released with `ReleaseStatus()` if it is not nullptr. the other code in this test does that.

Code after:
      selected.push_back(d);
      break;
    }
  }

  ASSERT_FALSE(selected.empty());

  // Pick a status that the CPU EP would never return to ensure the value is set correctly.
  OrtCompiledModelCompatibility status = OrtCompiledModelCompatibility_EP_SUPPORTED_PREFER_RECOMPILATION;
  ASSERT_NO_FATAL_FAILURE({
    status = Ort::GetModelCompatibilityForEpDevices(selected, "arbitrary-compat-string");
  });

  ASSERT_TRUE(status == OrtCompiledModelCompatibility_EP_NOT_APPLICABLE);
}

// -----------------------------
// GetCompatibilityInfoFromModel Tests
// -----------------------------

TEST(EpCompatibilityCapiTest, GetCompatibilityInfoFromModel_InvalidArgs) {
  const OrtApi* api = OrtGetApiBase()->GetApi(ORT_API_VERSION);
  ASSERT_NE(api, nullptr);

  OrtAllocator* allocator = nullptr;
  ASSERT_EQ(api->GetAllocatorWithDefaultOptions(&allocator), nullptr);
  ASSERT_NE(allocator, nullptr);

  char* compat_info = nullptr;

  // model_path == nullptr
  OrtStatus* st = api->GetCompatibilityInfoFromModel(nullptr, "TestEP", allocator, &compat_info);
  ASSERT_NE(st, nullptr);
  EXPECT_EQ(api->GetErrorCode(st), ORT_INVALID_ARGUMENT);
  api->ReleaseStatus(st);

  // ep_type == nullptr
  st = api->GetCompatibilityInfoFromModel(ORT_TSTR("test.onnx"), nullptr, allocator, &compat_info);
  ASSERT_NE(st, nullptr);
  EXPECT_EQ(api->GetErrorCode(st), ORT_INVALID_ARGUMENT);
  api->ReleaseStatus(st);

  // ep_type == empty string
  st = api->GetCompatibilityInfoFromModel(ORT_TSTR("test.onnx"), "", allocator, &compat_info);
  ASSERT_NE(st, nullptr);
  EXPECT_EQ(api->GetErrorCode(st), ORT_INVALID_ARGUMENT);
  api->ReleaseStatus(st);

  // allocator == nullptr
  st = api->GetCompatibilityInfoFromModel(ORT_TSTR("test.onnx"), "TestEP", nullptr, &compat_info);
  ASSERT_NE(st, nullptr);