16 #include "tensorflow_serving/servables/tensorflow/simple_servers.h"
23 #include <gtest/gtest.h>
24 #include "tensorflow/cc/saved_model/loader.h"
25 #include "tensorflow/core/framework/tensor.h"
26 #include "tensorflow/core/framework/tensor_testutil.h"
27 #include "tensorflow/core/lib/core/status.h"
28 #include "tensorflow/core/lib/core/status_test_util.h"
29 #include "tensorflow/core/lib/core/stringpiece.h"
30 #include "tensorflow/core/lib/io/path.h"
31 #include "tensorflow/core/platform/env.h"
32 #include "tensorflow/core/public/session.h"
33 #include "tensorflow_serving/core/servable_handle.h"
34 #include "tensorflow_serving/test_util/test_util.h"
36 namespace tensorflow {
40 class SimpleServersTest :
public ::testing::Test {
43 : test_data_path_(test_util::TensorflowTestSrcDirPath(
44 "cc/saved_model/testdata/half_plus_two")) {}
48 void TestSingleRequest(
const SavedModelBundle& bundle) {
49 const Tensor input = test::AsTensor<float>({100.0f, 42.0f}, {2});
51 const Tensor expected_output =
52 test::AsTensor<float>({100.0f / 2 + 2, 42.0f / 2 + 2}, {2});
57 const std::vector<std::pair<string, Tensor>> inputs = {{
"x", input}};
58 const std::vector<string> output_names = {
"y"};
59 const std::vector<string> empty_targets;
60 std::vector<Tensor> outputs;
63 bundle.session->Run(inputs, output_names, empty_targets, &outputs));
65 ASSERT_EQ(1, outputs.size());
66 const auto& single_output = outputs.at(0);
67 test::ExpectTensorEqual<float>(expected_output, single_output);
71 const string test_data_path_;
74 TEST_F(SimpleServersTest, Basic) {
75 std::unique_ptr<Manager> manager;
76 const Status status = simple_servers::CreateSingleTFModelManagerFromBasePath(
77 test_data_path_, &manager);
81 while (manager->ListAvailableServableIds().empty()) {
82 Env::Default()->SleepForMicroseconds(1000);
84 ServableHandle<SavedModelBundle> bundle;
85 const Status handle_status =
86 manager->GetServableHandle(ServableRequest::Latest(
"default"), &bundle);
87 TF_CHECK_OK(handle_status);
88 TestSingleRequest(*bundle);