15 #include "tensorflow_serving/servables/tensorflow/oss/resource_estimator.h"
20 #include <gmock/gmock.h>
21 #include <gtest/gtest.h>
22 #include "tensorflow/core/lib/core/status_test_util.h"
23 #include "tensorflow/core/platform/path.h"
24 #include "tensorflow_serving/servables/tensorflow/bundle_factory_test_util.h"
25 #include "tensorflow_serving/test_util/test_util.h"
26 #include "tensorflow_serving/util/test_util/mock_file_probing_env.h"
28 namespace tensorflow {
32 using test_util::EqualsProto;
34 using ::testing::DoAll;
35 using ::testing::Return;
36 using ::testing::SetArgPointee;
38 class ResourceEstimatorTest :
public ::testing::Test {
41 export_dir_ =
"/foo/bar";
42 const string child =
"child";
43 const string child_path = io::JoinPath(export_dir_, child);
48 EXPECT_CALL(env_, FileExists(export_dir_))
49 .WillRepeatedly(Return(Status()));
50 EXPECT_CALL(env_, GetChildren(export_dir_, _))
51 .WillRepeatedly(DoAll(SetArgPointee<1>(std::vector<string>({child})),
53 EXPECT_CALL(env_, IsDirectory(child_path))
54 .WillRepeatedly(Return(errors::FailedPrecondition(
"")));
55 EXPECT_CALL(env_, GetFileSize(child_path, _))
57 DoAll(SetArgPointee<1>(file_size_), Return(Status())));
62 test_util::MockFileProbingEnv env_;
65 TEST_F(ResourceEstimatorTest, EstimateResourceFromPathWithFileProbingEnv) {
66 ResourceAllocation actual;
67 TF_ASSERT_OK(EstimateMainRamBytesFromPath(
68 export_dir_,
false, &env_, &actual));
69 ResourceAllocation expected =
70 test_util::GetExpectedResourceEstimate(file_size_);
71 EXPECT_THAT(actual, EqualsProto(expected));
74 TEST_F(ResourceEstimatorTest, EstimateResourceFromValidationResult) {
77 ResourceAllocation actual;
78 TF_ASSERT_OK(EstimateMainRamBytesFromPath(
79 export_dir_,
true, &env_, &actual));
80 ResourceAllocation expected =
81 test_util::GetExpectedResourceEstimate(file_size_);
82 EXPECT_THAT(actual, EqualsProto(expected));