Skip to content

Commit 8e1c391

Browse files
authored
Tests and version added (#3554)
* Tests and version added
1 parent 3529ade commit 8e1c391

File tree

4 files changed

+98
-17
lines changed

4 files changed

+98
-17
lines changed

src/graph_export/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ ovms_cc_library(
3131
"@ovms//src:libovmslocalfilesystem",
3232
"@com_github_tencent_rapidjson//:rapidjson",
3333
"@ovms//src:libovmsschema",
34+
"@ovms//src:libovms_version",
3435
] + select({
3536
"//:not_disable_mediapipe": [
3637
"@mediapipe//mediapipe/framework/port:parse_text_proto",

src/graph_export/graph_export.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "../status.hpp"
3939
#include "../stringutils.hpp"
4040
#include "../schema.hpp"
41+
#include "../version.hpp"
4142

4243
#if (MEDIAPIPE_DISABLE == 0)
4344
#pragma warning(push)
@@ -51,8 +52,11 @@
5152
#endif
5253
namespace ovms {
5354

55+
static const std::string OVMS_VERSION_GRAPH_LINE = std::string("# File created with: ") + PROJECT_NAME + std::string(" ") + PROJECT_VERSION + std::string("\n");
56+
5457
static Status createTextGenerationGraphTemplate(const std::string& directoryPath, const TextGenGraphSettingsImpl& graphSettings) {
5558
std::ostringstream oss;
59+
oss << OVMS_VERSION_GRAPH_LINE;
5660
// clang-format off
5761
oss << R"(
5862
input_stream: "HTTP_REQUEST_PAYLOAD:input"
@@ -142,6 +146,7 @@ static Status createTextGenerationGraphTemplate(const std::string& directoryPath
142146

143147
static Status createRerankGraphTemplate(const std::string& directoryPath, const RerankGraphSettingsImpl& graphSettings) {
144148
std::ostringstream oss;
149+
oss << OVMS_VERSION_GRAPH_LINE;
145150
// Windows path creation - graph parser needs forward slashes in paths
146151
std::string graphOkPath = graphSettings.modelPath;
147152
if (FileSystem::getOsSeparator() != "/") {
@@ -185,6 +190,7 @@ node {
185190

186191
static Status createEmbeddingsGraphTemplate(const std::string& directoryPath, const EmbeddingsGraphSettingsImpl& graphSettings) {
187192
std::ostringstream oss;
193+
oss << OVMS_VERSION_GRAPH_LINE;
188194
// Windows path creation - graph parser needs forward slashes in paths
189195
std::string graphOkPath = graphSettings.modelPath;
190196
if (FileSystem::getOsSeparator() != "/") {
@@ -231,6 +237,7 @@ node {
231237

232238
static Status createImageGenerationGraphTemplate(const std::string& directoryPath, const ImageGenerationGraphSettingsImpl& graphSettings) {
233239
std::ostringstream oss;
240+
oss << OVMS_VERSION_GRAPH_LINE;
234241
// clang-format off
235242
oss << R"(
236243
input_stream: "HTTP_REQUEST_PAYLOAD:input"

src/test/graph_export_test.cpp

Lines changed: 82 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
#include <gtest/gtest.h>
2121

2222
#include "test_utils.hpp"
23-
#include "../filesystem.hpp"
24-
#include "../status.hpp"
2523
#include "../capi_frontend/server_settings.hpp"
2624
#include "../graph_export/graph_export.hpp"
25+
#include "../filesystem.hpp"
26+
#include "../status.hpp"
27+
#include "../version.hpp"
2728

2829
const std::string expectedOneSettingPluginGraphContents = R"(
2930
input_stream: "HTTP_REQUEST_PAYLOAD:input"
@@ -313,8 +314,77 @@ class GraphCreationTest : public TestWithTempDir {
313314
void TearDown() {
314315
TestWithTempDir::TearDown();
315316
}
317+
318+
// Removes # OpenVINO Model Server REPLACE_PROJECT_VERSION comment added for debug purpose in graph export at the begging of graph.pbtxt
319+
// This string differs per build and setup
320+
std::string removeVersionString(std::string input) {
321+
return input.erase(0, input.find("\n") + 1);
322+
}
323+
324+
std::string getVersionString() {
325+
std::stringstream expected;
326+
expected << "# File created with: " << PROJECT_NAME << " " << PROJECT_VERSION << std::endl;
327+
return expected.str();
328+
}
316329
};
317330

331+
TEST_F(GraphCreationTest, positiveDefaultWithVersionString) {
332+
ovms::HFSettingsImpl hfSettings;
333+
std::string graphPath = ovms::FileSystem::appendSlash(this->directoryPath) + "graph.pbtxt";
334+
std::unique_ptr<ovms::GraphExport> graphExporter = std::make_unique<ovms::GraphExport>();
335+
auto status = graphExporter->createServableConfig(this->directoryPath, hfSettings);
336+
ASSERT_EQ(status, ovms::StatusCode::OK);
337+
338+
std::string graphContents = GetFileContents(graphPath);
339+
std::string expected = getVersionString() + expectedDefaultGraphContents;
340+
ASSERT_EQ(expected, graphContents) << graphContents;
341+
}
342+
343+
TEST_F(GraphCreationTest, positiveReranktWithVersionString) {
344+
ovms::HFSettingsImpl hfSettings;
345+
hfSettings.task = ovms::RERANK_GRAPH;
346+
ovms::RerankGraphSettingsImpl rerankGraphSettings;
347+
hfSettings.graphSettings = std::move(rerankGraphSettings);
348+
std::string graphPath = ovms::FileSystem::appendSlash(this->directoryPath) + "graph.pbtxt";
349+
std::unique_ptr<ovms::GraphExport> graphExporter = std::make_unique<ovms::GraphExport>();
350+
auto status = graphExporter->createServableConfig(this->directoryPath, hfSettings);
351+
ASSERT_EQ(status, ovms::StatusCode::OK);
352+
353+
std::string graphContents = GetFileContents(graphPath);
354+
std::string expected = getVersionString() + expectedRerankGraphContentsDefault;
355+
ASSERT_EQ(expected, graphContents) << graphContents;
356+
}
357+
358+
TEST_F(GraphCreationTest, positiveEmbeddingsWithVersionString) {
359+
ovms::HFSettingsImpl hfSettings;
360+
hfSettings.task = ovms::EMBEDDINGS_GRAPH;
361+
ovms::EmbeddingsGraphSettingsImpl embeddingsGraphSettings;
362+
hfSettings.graphSettings = std::move(embeddingsGraphSettings);
363+
std::string graphPath = ovms::FileSystem::appendSlash(this->directoryPath) + "graph.pbtxt";
364+
std::unique_ptr<ovms::GraphExport> graphExporter = std::make_unique<ovms::GraphExport>();
365+
auto status = graphExporter->createServableConfig(this->directoryPath, hfSettings);
366+
ASSERT_EQ(status, ovms::StatusCode::OK);
367+
368+
std::string graphContents = GetFileContents(graphPath);
369+
std::string expected = getVersionString() + expectedEmbeddingsGraphContentsDefault;
370+
ASSERT_EQ(expected, graphContents) << graphContents;
371+
}
372+
373+
TEST_F(GraphCreationTest, positiveImageGenWithVersionString) {
374+
ovms::HFSettingsImpl hfSettings;
375+
hfSettings.task = ovms::IMAGE_GENERATION_GRAPH;
376+
ovms::ImageGenerationGraphSettingsImpl imageGenerationGraphSettings;
377+
hfSettings.graphSettings = std::move(imageGenerationGraphSettings);
378+
std::string graphPath = ovms::FileSystem::appendSlash(this->directoryPath) + "graph.pbtxt";
379+
std::unique_ptr<ovms::GraphExport> graphExporter = std::make_unique<ovms::GraphExport>();
380+
auto status = graphExporter->createServableConfig(this->directoryPath, hfSettings);
381+
ASSERT_EQ(status, ovms::StatusCode::OK);
382+
383+
std::string graphContents = GetFileContents(graphPath);
384+
std::string expected = getVersionString() + expectedImageGenerationGraphContentsDefault;
385+
ASSERT_EQ(expected, graphContents) << graphContents;
386+
}
387+
318388
TEST_F(GraphCreationTest, positiveDefault) {
319389
ovms::HFSettingsImpl hfSettings;
320390
std::string graphPath = ovms::FileSystem::appendSlash(this->directoryPath) + "graph.pbtxt";
@@ -323,7 +393,7 @@ TEST_F(GraphCreationTest, positiveDefault) {
323393
ASSERT_EQ(status, ovms::StatusCode::OK);
324394

325395
std::string graphContents = GetFileContents(graphPath);
326-
ASSERT_EQ(expectedDefaultGraphContents, graphContents) << graphContents;
396+
ASSERT_EQ(expectedDefaultGraphContents, removeVersionString(graphContents)) << graphContents;
327397
}
328398

329399
TEST_F(GraphCreationTest, rerankPositiveNonDefault) {
@@ -338,13 +408,12 @@ TEST_F(GraphCreationTest, rerankPositiveNonDefault) {
338408
hfSettings.graphSettings = std::move(rerankGraphSettings);
339409

340410
std::string graphPath = ovms::FileSystem::appendSlash(this->directoryPath) + "graph.pbtxt";
341-
std::string subconfigPath = ovms::FileSystem::appendSlash(this->directoryPath) + "subconfig.json";
342411
std::unique_ptr<ovms::GraphExport> graphExporter = std::make_unique<ovms::GraphExport>();
343412
auto status = graphExporter->createServableConfig(this->directoryPath, hfSettings);
344413
ASSERT_EQ(status, ovms::StatusCode::OK);
345414

346415
std::string graphContents = GetFileContents(graphPath);
347-
ASSERT_EQ(expectedRerankGraphContentsNonDefault, graphContents) << graphContents;
416+
ASSERT_EQ(expectedRerankGraphContentsNonDefault, removeVersionString(graphContents)) << graphContents;
348417
}
349418

350419
TEST_F(GraphCreationTest, rerankPositiveDefault) {
@@ -354,13 +423,12 @@ TEST_F(GraphCreationTest, rerankPositiveDefault) {
354423
hfSettings.graphSettings = std::move(rerankGraphSettings);
355424

356425
std::string graphPath = ovms::FileSystem::appendSlash(this->directoryPath) + "graph.pbtxt";
357-
std::string subconfigPath = ovms::FileSystem::appendSlash(this->directoryPath) + "subconfig.json";
358426
std::unique_ptr<ovms::GraphExport> graphExporter = std::make_unique<ovms::GraphExport>();
359427
auto status = graphExporter->createServableConfig(this->directoryPath, hfSettings);
360428
ASSERT_EQ(status, ovms::StatusCode::OK);
361429

362430
std::string graphContents = GetFileContents(graphPath);
363-
ASSERT_EQ(expectedRerankGraphContentsDefault, graphContents) << graphContents;
431+
ASSERT_EQ(expectedRerankGraphContentsDefault, removeVersionString(graphContents)) << graphContents;
364432
}
365433

366434
TEST_F(GraphCreationTest, rerankCreatedPbtxtInvalid) {
@@ -372,7 +440,6 @@ TEST_F(GraphCreationTest, rerankCreatedPbtxtInvalid) {
372440
rerankGraphSettings.numStreams = 2;
373441
hfSettings.graphSettings = std::move(rerankGraphSettings);
374442
std::string graphPath = ovms::FileSystem::appendSlash(this->directoryPath) + "graph.pbtxt";
375-
std::string subconfigPath = ovms::FileSystem::appendSlash(this->directoryPath) + "subconfig.json";
376443
std::unique_ptr<ovms::GraphExport> graphExporter = std::make_unique<ovms::GraphExport>();
377444
auto status = graphExporter->createServableConfig(this->directoryPath, hfSettings);
378445
#if (MEDIAPIPE_DISABLE == 0)
@@ -399,7 +466,7 @@ TEST_F(GraphCreationTest, embeddingsPositiveNonDefault) {
399466
ASSERT_EQ(status, ovms::StatusCode::OK);
400467

401468
std::string graphContents = GetFileContents(graphPath);
402-
ASSERT_EQ(expectedEmbeddingsGraphContents, graphContents) << graphContents;
469+
ASSERT_EQ(expectedEmbeddingsGraphContents, removeVersionString(graphContents)) << graphContents;
403470
}
404471

405472
TEST_F(GraphCreationTest, embeddingsPositiveDefault) {
@@ -413,7 +480,7 @@ TEST_F(GraphCreationTest, embeddingsPositiveDefault) {
413480
ASSERT_EQ(status, ovms::StatusCode::OK);
414481

415482
std::string graphContents = GetFileContents(graphPath);
416-
ASSERT_EQ(expectedEmbeddingsGraphContentsDefault, graphContents) << graphContents;
483+
ASSERT_EQ(expectedEmbeddingsGraphContentsDefault, removeVersionString(graphContents)) << graphContents;
417484
}
418485

419486
TEST_F(GraphCreationTest, embeddingsCreatedPbtxtInvalid) {
@@ -450,7 +517,7 @@ TEST_F(GraphCreationTest, positivePluginConfigAll) {
450517
ASSERT_EQ(status, ovms::StatusCode::OK);
451518

452519
std::string graphContents = GetFileContents(graphPath);
453-
ASSERT_EQ(expectedFullPluginGraphContents, graphContents) << graphContents;
520+
ASSERT_EQ(expectedFullPluginGraphContents, removeVersionString(graphContents)) << graphContents;
454521
}
455522

456523
TEST_F(GraphCreationTest, positiveWithParsersAndToolGuidedGeneration) {
@@ -468,7 +535,7 @@ TEST_F(GraphCreationTest, positiveWithParsersAndToolGuidedGeneration) {
468535
ASSERT_EQ(status, ovms::StatusCode::OK);
469536

470537
std::string graphContents = GetFileContents(graphPath);
471-
ASSERT_EQ(expectedGraphContentsWithResponseParser, graphContents) << graphContents;
538+
ASSERT_EQ(expectedGraphContentsWithResponseParser, removeVersionString(graphContents)) << graphContents;
472539
}
473540

474541
TEST_F(GraphCreationTest, positivePluginConfigOne) {
@@ -483,7 +550,7 @@ TEST_F(GraphCreationTest, positivePluginConfigOne) {
483550
ASSERT_EQ(status, ovms::StatusCode::OK);
484551

485552
std::string graphContents = GetFileContents(graphPath);
486-
ASSERT_EQ(expectedOneSettingPluginGraphContents, graphContents) << graphContents;
553+
ASSERT_EQ(expectedOneSettingPluginGraphContents, removeVersionString(graphContents)) << graphContents;
487554
}
488555

489556
TEST_F(GraphCreationTest, negativeCreateFileWrongDirectoryPaths) {
@@ -551,7 +618,7 @@ TEST_F(GraphCreationTest, imageGenerationPositiveDefault) {
551618
ASSERT_EQ(status, ovms::StatusCode::OK);
552619

553620
std::string graphContents = GetFileContents(graphPath);
554-
ASSERT_EQ(expectedImageGenerationGraphContentsDefault, graphContents) << graphContents;
621+
ASSERT_EQ(expectedImageGenerationGraphContentsDefault, removeVersionString(graphContents)) << graphContents;
555622
}
556623

557624
TEST_F(GraphCreationTest, imageGenerationPositiveFull) {
@@ -572,5 +639,5 @@ TEST_F(GraphCreationTest, imageGenerationPositiveFull) {
572639
ASSERT_EQ(status, ovms::StatusCode::OK);
573640

574641
std::string graphContents = GetFileContents(graphPath);
575-
ASSERT_EQ(expectedImageGenerationGraphContents, graphContents) << graphContents;
642+
ASSERT_EQ(expectedImageGenerationGraphContents, removeVersionString(graphContents)) << graphContents;
576643
}

src/test/pull_hf_model_test.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ class HfDownloaderPullHfModel : public TestWithTempDir {
107107
RemoveReadonlyFileAttributeFromDir(this->directoryPath);
108108
TestWithTempDir::TearDown();
109109
}
110+
111+
// Removes # OpenVINO Model Server REPLACE_PROJECT_VERSION comment added for debug purpose in graph export at the begging of graph.pbtxt
112+
// This string differs per build and setup
113+
std::string removeVersionString(std::string input) {
114+
return input.erase(0, input.find("\n") + 1);
115+
}
110116
};
111117

112118
const std::string expectedGraphContents = R"(
@@ -163,7 +169,7 @@ TEST_F(HfDownloaderPullHfModel, PositiveDownload) {
163169
ASSERT_EQ(std::filesystem::file_size(modelPath), 52417240);
164170
std::string graphContents = GetFileContents(graphPath);
165171

166-
ASSERT_EQ(expectedGraphContents, graphContents) << graphContents;
172+
ASSERT_EQ(expectedGraphContents, removeVersionString(graphContents)) << graphContents;
167173
}
168174

169175
TEST_F(HfDownloaderPullHfModel, PositiveDownloadAndStart) {
@@ -181,7 +187,7 @@ TEST_F(HfDownloaderPullHfModel, PositiveDownloadAndStart) {
181187
ASSERT_EQ(std::filesystem::file_size(modelPath), 52417240);
182188
std::string graphContents = GetFileContents(graphPath);
183189

184-
ASSERT_EQ(expectedGraphContents, graphContents) << graphContents;
190+
ASSERT_EQ(expectedGraphContents, removeVersionString(graphContents)) << graphContents;
185191
}
186192

187193
class TestOptimumDownloader : public ovms::OptimumDownloader {

0 commit comments

Comments
 (0)