ewmscp  ..
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
baseTest Class Referenceabstract
Inheritance diagram for baseTest:
[legend]
Collaboration diagram for baseTest:
[legend]

Public Member Functions

 baseTest (const std::string &aName, const std::string &aDescription, const decltype(parameters)&aParameters, const decltype(options)&aOptions={})
 
virtual void execute (const std::vector< std::string > &remainingOptions)=0
 
void ensuredWrite (int fd, const std::string &data)
 
void ensuredRead (int fd, std::string &data)
 
void Execute (const std::vector< std::string > &remainingOptions)
 

Static Public Member Functions

static std::map< std::string, baseTest * > & getList ()
 
static void setUpOptions ()
 
static const std::string & getDescriptions ()
 

Protected Attributes

std::string name
 
std::string description
 
std::list< std::pair< std::string, std::string > > parameters
 
std::list< std::pair< options::base &, std::string > > options
 
std::set< std::string > createdFiles
 

Static Protected Attributes

static options::single< unsigned int > repeat
 
static options::single< bool > cleanup
 
static options::single< bool > urandom
 
static options::single< bool > einsZweiDrei
 
static options::single< std::string > contentFile
 
static options::single< size_t > size
 
static options::single< unsigned int > blocks
 
static options::single< std::string > content
 
static options::single< bool > truncate
 
static options::single< std::chrono::duration< double > > time
 
static options::single< unsigned long > syncus
 
static options::single< unsigned long > skewus
 
static std::string descriptions = "\npossible actions and their parameters:\n"
 

Detailed Description

Definition at line 35 of file fileOpsTests.cpp.

Constructor & Destructor Documentation

◆ baseTest()

baseTest::baseTest ( const std::string &  aName,
const std::string &  aDescription,
const decltype(parameters)&  aParameters,
const decltype(options)&  aOptions = {} 
)
inline

Definition at line 68 of file fileOpsTests.cpp.

71  {}):
72  name(aName),
73  description(aDescription),
74  parameters(aParameters),
75  options(aOptions) {
76  getList().emplace(name, this);
77 
78  descriptions += name;
79  descriptions += ": ";
81  descriptions += "\n";
82  if (!options.empty()) {
83  descriptions += "\toptions:\n";
84  for (const auto& opt : options) {
85  descriptions += "\t\t";
86  descriptions += opt.first.fGetLongName();
87  descriptions += ": ";
88  descriptions += opt.second;
89  descriptions += "\n";
90  }
91  }
92  descriptions += "\tparameters:\n";
93  for (const auto& par : parameters) {
94  descriptions += "\t\t";
95  descriptions += par.first;
96  descriptions += ": ";
97  descriptions += par.second;
98  descriptions += "\n";
99  }
100  };

Member Function Documentation

◆ ensuredRead()

void baseTest::ensuredRead ( int  fd,
std::string &  data 
)
inline

Definition at line 122 of file fileOpsTests.cpp.

122  {
123  auto bytesToRead = data.size();
124  auto ptr = const_cast<char*>(data.data()); // c++17 legalizes this...
125  while (bytesToRead > 0) {
126  auto result = read(fd, ptr, bytesToRead);
127  if (result == -1 && errno == EINTR) {
128  continue;
129  }
130  throwcall::badval(result, -1, "read ", bytesToRead, " from fd ", fd);
131  bytesToRead -= result;
132  }
133  }

References throwcall::badval().

Referenced by Execute(), and simpleRead::execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ensuredWrite()

void baseTest::ensuredWrite ( int  fd,
const std::string &  data 
)
inline

Definition at line 106 of file fileOpsTests.cpp.

106  {
107  auto bytesToWrite = data.size();
108  auto ptr = data.data();
109  while (bytesToWrite > 0) {
110  auto result = write(fd, ptr, bytesToWrite);
111  if (result == -1) {
112  if (errno == EINTR) {
113  continue;
114  } else {
115  throwcall::badval(result, -1, "write ", bytesToWrite, " to fd ", fd);
116  }
117  } else {
118  bytesToWrite -= result;
119  }
120  }
121  }

References throwcall::badval().

Referenced by tmpFile::execute(), vimWrite::execute(), appendBlocks::execute(), simpleWrite::execute(), cpWrite::execute(), sparseWrite::execute(), sparseWrite2::execute(), findMinHoleSize::execute(), createUnlinkCreate::execute(), closeMvUpdate::execute(), createUnlinkClose::execute(), uglyNames::execute(), and uglyPaths::execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Execute()

void baseTest::Execute ( const std::vector< std::string > &  remainingOptions)
inline

Definition at line 134 of file fileOpsTests.cpp.

134  {
135 
136  if (size > 0) {
137  content.resize(size);
138  }
139 
140  if (urandom) {
141  auto fd = throwcall::badval(open("/dev/urandom", O_RDONLY), -1, "open /dev/urandom");
142  ensuredRead(fd, content);
143  throwcall::good0(close(fd), "close /dev/urandom");
144  }
145  if (einsZweiDrei) {
146  auto s = content.size();
147  content.clear();
148  content.reserve(s);
149  for (unsigned i = 0; true; i++) {
150  auto number = std::to_string(i);
151  if (content.size() + number.size() < content.capacity()) {
152  content += number;
153  if (content.size() < content.capacity()) {
154  content.push_back('\n');
155  }
156  } else {
157  break;
158  }
159  }
160  while (content.size() < content.capacity()) {
161  content.push_back('+');
162  }
163  }
164  if (!contentFile.empty()) {
165  auto fd = throwcall::badval(open(contentFile.c_str(), O_RDONLY), -1, "open ", contentFile);
166  struct stat statData;
167  throwcall::good0(fstat(fd, &statData), "stat ", contentFile);
168  content.resize(statData.st_size);
169  ensuredRead(fd, content);
170  }
171 
172  std::vector<clockType::duration> times;
173  times.reserve(repeat);
174 
175  for (unsigned i = 0; i < repeat; i++) {
176  if (syncus > 0) {
177  auto now = std::chrono::system_clock::now();
178  auto seconds = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
179  auto divresult = std::div(seconds, syncus);
180  auto then = std::chrono::system_clock::time_point(std::chrono::microseconds(divresult.quot * syncus + syncus + (i % syncus) * skewus));
181  std::this_thread::sleep_until(then);
182  }
183  auto tStart = clockType::now();
184  execute(remainingOptions);
185  auto tStop = clockType::now();
186  auto dt = tStop - tStart;
187  times.push_back(dt);
188  }
189  if (cleanup) {
190  for (const auto& file : createdFiles) {
191  std::cout << "removing " << file << "\n";
192  throwcall::good0(unlink(file.c_str()), "unlink ", file);
193  }
194  }
195 
196  if (repeat == 1) {
197  std::cout << "took " << times.at(0) << "s\n";
198  } else {
199  auto minMax = std::minmax_element(times.begin(), times.end());
200  std::cout << "minimum time: " << *(minMax.first) << "s\n";
201  std::cout << "maximum time: " << *(minMax.second) << "s\n";
202  auto sum = std::accumulate(times.begin(), times.end(), clockType::duration::zero());
203  auto mean = std::chrono::duration_cast<std::chrono::duration<double>>(sum).count() / repeat;
204  std::cout << "average time: " << mean << "s\n";
205  std::map<double, unsigned long> histogram;
206  unsigned bins = 10;
207  auto range = std::chrono::duration_cast<std::chrono::duration<double>>(*(minMax.second) - * (minMax.first)).count();
208  auto lowBorder = std::chrono::duration_cast<std::chrono::duration<double>>(*(minMax.first)).count();
209  if (mean < lowBorder + range / 10) { // use log bins
210  auto border = lowBorder;
211  histogram[border] = 0;
212  auto factor = std::pow(std::chrono::duration_cast<std::chrono::duration<double>>(*(minMax.second)).count() / lowBorder,
213  1.0 / bins);
214  for (unsigned i = 0; i < bins; i++) {
215  border *= factor;
216  histogram[border] = 0;
217  }
218  } else { // use lin bins
219  lowBorder -= range / (2 * bins);
220  if (lowBorder < 0) {
221  lowBorder = 0;
222  }
223  for (unsigned i = 0; i < bins + 1; i++) {
224  histogram[lowBorder + i * range / bins] = 0;
225  }
226  }
227  for (auto t : times) {
228  auto bin = histogram.begin();
229  for (auto testBin = bin; testBin != histogram.end(); ++testBin) {
230  if (std::chrono::duration_cast<std::chrono::duration<double>>(t).count() < testBin->first) {
231  break;
232  }
233  bin = testBin;
234  }
235  bin->second++;
236  }
237  for (auto& bin : histogram) {
238  std::cout << bin.first << ": " << bin.second << "\n";
239  }
240  }
241  }

References throwcall::badval(), cleanup, content, contentFile, createdFiles, einsZweiDrei, ensuredRead(), execute(), throwcall::good0(), repeat, size, skewus, syncus, and urandom.

Here is the call graph for this function:

◆ execute()

virtual void baseTest::execute ( const std::vector< std::string > &  remainingOptions)
pure virtual

Implemented in uglyPaths, uglyNames, truncateToSize, mmapRead, simpleRead, createUnlinkClose, closeMvUpdate, createUnlinkCreate, appendHole, findMinHoleSize, sparseWrite2, sparseWrite, mmapWrite, directWrite, cpWrite, simpleWrite, appendBlocks, keepOpen, vimWrite, and tmpFile.

Referenced by Execute().

Here is the caller graph for this function:

◆ getDescriptions()

static const std::string& baseTest::getDescriptions ( )
inlinestatic

Definition at line 101 of file fileOpsTests.cpp.

101  {
102  return descriptions;
103  }

References descriptions.

Referenced by main().

Here is the caller graph for this function:

◆ getList()

static std::map<std::string, baseTest*>& baseTest::getList ( )
inlinestatic

Definition at line 58 of file fileOpsTests.cpp.

58  {
59  static std::remove_reference<decltype(getList())>::type list;
60  return list;
61  }

Referenced by main().

Here is the caller graph for this function:

◆ setUpOptions()

static void baseTest::setUpOptions ( )
inlinestatic

Definition at line 62 of file fileOpsTests.cpp.

References content, contentFile, einsZweiDrei, options::base::fForbid(), size, and urandom.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ createdFiles

std::set<std::string> baseTest::createdFiles
protected

◆ description

std::string baseTest::description
protected

Definition at line 38 of file fileOpsTests.cpp.

◆ name

std::string baseTest::name
protected

Definition at line 37 of file fileOpsTests.cpp.

◆ options

std::list<std::pair<options::base&, std::string> > baseTest::options
protected

Definition at line 40 of file fileOpsTests.cpp.

◆ parameters

std::list<std::pair<std::string, std::string> > baseTest::parameters
protected

Definition at line 39 of file fileOpsTests.cpp.


The documentation for this class was generated from the following file:
baseTest::options
std::list< std::pair< options::base &, std::string > > options
Definition: fileOpsTests.cpp:40
baseTest::name
std::string name
Definition: fileOpsTests.cpp:37
baseTest::content
static options::single< std::string > content
Definition: fileOpsTests.cpp:51
throwcall::badval
T badval(T call, t badvalue, const Args &... args)
template function to wrap system calls that return a special bad value on failure
Definition: throwcall.h:54
baseTest::einsZweiDrei
static options::single< bool > einsZweiDrei
Definition: fileOpsTests.cpp:47
baseTest::ensuredRead
void ensuredRead(int fd, std::string &data)
Definition: fileOpsTests.cpp:122
baseTest::contentFile
static options::single< std::string > contentFile
Definition: fileOpsTests.cpp:48
baseTest::skewus
static options::single< unsigned long > skewus
Definition: fileOpsTests.cpp:55
baseTest::createdFiles
std::set< std::string > createdFiles
Definition: fileOpsTests.cpp:42
options
Definition: Options.h:33
baseTest::getList
static std::map< std::string, baseTest * > & getList()
Definition: fileOpsTests.cpp:58
options::base::fForbid
virtual void fForbid(const base *aOtherOption)
forbid aOtherOption when this option is set
Definition: Options.cpp:617
baseTest::description
std::string description
Definition: fileOpsTests.cpp:38
baseTest::execute
virtual void execute(const std::vector< std::string > &remainingOptions)=0
baseTest::urandom
static options::single< bool > urandom
Definition: fileOpsTests.cpp:46
baseTest::repeat
static options::single< unsigned int > repeat
Definition: fileOpsTests.cpp:44
baseTest::size
static options::single< size_t > size
Definition: fileOpsTests.cpp:49
baseTest::descriptions
static std::string descriptions
Definition: fileOpsTests.cpp:56
baseTest::syncus
static options::single< unsigned long > syncus
Definition: fileOpsTests.cpp:54
throwcall::good0
void good0(T call, const Args &... args)
template function to wrap system calls that return 0 on success
Definition: throwcall.h:40
baseTest::cleanup
static options::single< bool > cleanup
Definition: fileOpsTests.cpp:45
baseTest::parameters
std::list< std::pair< std::string, std::string > > parameters
Definition: fileOpsTests.cpp:39