Vector Optimized Library of Kernels  2.4
Architecture-tuned implementations of math kernels
filesystem_for_testing.h
Go to the documentation of this file.
1 // Copyright 2017 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // Implements a fake filesystem, useful for tests.
16 #ifndef CPU_FEATURES_TEST_FILESYSTEM_FOR_TESTING_H_
17 #define CPU_FEATURES_TEST_FILESYSTEM_FOR_TESTING_H_
18 
19 #include <memory>
20 #include <string>
21 #include <unordered_map>
22 
23 #include "internal/filesystem.h"
24 
25 namespace cpu_features {
26 
27 class FakeFile {
28  public:
29  explicit FakeFile(int file_descriptor, const char* content);
30  ~FakeFile();
31 
32  void Open();
33  void Close();
34  int Read(int fd, void* buf, size_t count);
35 
36  int GetFileDescriptor() const { return file_descriptor_; }
37 
38  private:
39  const int file_descriptor_;
40  const std::string content_;
41  bool opened_ = false;
42  size_t head_index_ = 0;
43 };
44 
46  public:
47  void Reset();
48  FakeFile* CreateFile(const std::string& filename, const char* content);
49  FakeFile* FindFileOrDie(const int file_descriptor) const;
50  FakeFile* FindFileOrNull(const std::string& filename) const;
51 
52  private:
53  int next_file_descriptor_ = 0;
54  std::unordered_map<std::string, std::unique_ptr<FakeFile>> files_;
55 };
56 
58 
59 } // namespace cpu_features
60 
61 #endif // CPU_FEATURES_TEST_FILESYSTEM_FOR_TESTING_H_
Definition: filesystem_for_testing.h:45
Definition: filesystem_for_testing.h:27
void Close()
Definition: filesystem_for_testing.cc:35
FakeFile * CreateFile(const std::string &filename, const char *content)
Definition: filesystem_for_testing.cc:53
FakeFile * FindFileOrNull(const std::string &filename) const
Definition: filesystem_for_testing.cc:61
FakeFile(int file_descriptor, const char *content)
Definition: filesystem_for_testing.cc:25
string filename
Definition: plot_best_vs_generic.py:31
void Reset()
Definition: filesystem_for_testing.cc:51
void Open()
Definition: filesystem_for_testing.cc:30
FakeFilesystem & GetEmptyFilesystem()
Definition: filesystem_for_testing.cc:79
~FakeFile()
Definition: filesystem_for_testing.cc:28
int Read(int fd, void *buf, size_t count)
Definition: filesystem_for_testing.cc:40
Definition: bit_utils_test.cc:19
int GetFileDescriptor() const
Definition: filesystem_for_testing.h:36
FakeFile * FindFileOrDie(const int file_descriptor) const
Definition: filesystem_for_testing.cc:66