ewmscp  ..
Public Member Functions | List of all members
directWrite Class Reference
Inheritance diagram for directWrite:
[legend]
Collaboration diagram for directWrite:
[legend]

Public Member Functions

 directWrite ()
 
void execute (const std::vector< std::string > &remainingOptions) override
 
- Public Member Functions inherited from baseTest
 baseTest (const std::string &aName, const std::string &aDescription, const decltype(parameters)&aParameters, const decltype(options)&aOptions={})
 
void ensuredWrite (int fd, const std::string &data)
 
void ensuredRead (int fd, std::string &data)
 
void Execute (const std::vector< std::string > &remainingOptions)
 

Additional Inherited Members

- Static Public Member Functions inherited from baseTest
static std::map< std::string, baseTest * > & getList ()
 
static void setUpOptions ()
 
static const std::string & getDescriptions ()
 
- Protected Attributes inherited from baseTest
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 inherited from baseTest
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 431 of file fileOpsTests.cpp.

Constructor & Destructor Documentation

◆ directWrite()

directWrite::directWrite ( )
inline

Definition at line 433 of file fileOpsTests.cpp.

433  : baseTest("directWrite",
434  "create a file with O_DIRECT and write into it", {
435  {"file", "path to file"
436  }
437  },
438  {{time, "wait this long between writes"}}) {};

Member Function Documentation

◆ execute()

void directWrite::execute ( const std::vector< std::string > &  remainingOptions)
inlineoverridevirtual

Implements baseTest.

Definition at line 439 of file fileOpsTests.cpp.

439  {
440  auto file = remainingOptions.at(0);
441  // we need a page aligned buffer
442  auto buffer = throwcall::badval(mmap(nullptr, content.size(),
443  PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
444  -1, 0),
445  MAP_FAILED,
446  "mmap ", content.size(), " bytes anonymously");
447  memcpy(buffer, content.data(), content.size());
448  auto fd = throwcall::badval(open(file.c_str(), O_CREAT | O_WRONLY | O_DIRECT, 0744), -1, "open ", file);
449  for (unsigned i = 0; i < blocks; i++) {
450  if (i > 0) {
451  std::this_thread::sleep_for(time);
452  }
453  throwcall::good0(write(fd, buffer, content.size()) - content.size(), "write");
454  }
455  throwcall::good0(close(fd), "close ", file);
456  throwcall::good0(munmap(buffer, content.size()), "munmap buffer");
457  createdFiles.emplace(file);
458  };

References throwcall::badval(), baseTest::blocks, baseTest::content, baseTest::createdFiles, throwcall::good0(), and baseTest::time.

Here is the call graph for this function:

The documentation for this class was generated from the following file:
baseTest::time
static options::single< std::chrono::duration< double > > time
Definition: fileOpsTests.cpp:53
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::createdFiles
std::set< std::string > createdFiles
Definition: fileOpsTests.cpp:42
baseTest::blocks
static options::single< unsigned int > blocks
Definition: fileOpsTests.cpp:50
baseTest::baseTest
baseTest(const std::string &aName, const std::string &aDescription, const decltype(parameters)&aParameters, const decltype(options)&aOptions={})
Definition: fileOpsTests.cpp:68
throwcall::good0
void good0(T call, const Args &... args)
template function to wrap system calls that return 0 on success
Definition: throwcall.h:40