Refactor TimestampTestUtils
This commit is contained in:
parent
c5ccd9c2d1
commit
b3c5d4b5e3
@ -5,7 +5,7 @@
|
|||||||
#include "testutils/TimestampTestUtils.h"
|
#include "testutils/TimestampTestUtils.h"
|
||||||
|
|
||||||
template<class ConcreteFileSystemTestFixture>
|
template<class ConcreteFileSystemTestFixture>
|
||||||
class FsppDeviceTest_Timestamps: public FsppNodeTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils<fspp::Node> {
|
class FsppDeviceTest_Timestamps: public FsppNodeTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils {
|
||||||
public:
|
public:
|
||||||
void Test_Load_While_Loaded() {
|
void Test_Load_While_Loaded() {
|
||||||
auto node = this->CreateNode("/mynode");
|
auto node = this->CreateNode("/mynode");
|
||||||
@ -20,7 +20,7 @@ public:
|
|||||||
{
|
{
|
||||||
auto node = this->CreateNode("/mynode");
|
auto node = this->CreateNode("/mynode");
|
||||||
oldStat = stat(*node);
|
oldStat = stat(*node);
|
||||||
this->ensureNodeTimestampsAreOld(*node);
|
this->ensureNodeTimestampsAreOld(oldStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->device->Load("/myfile");
|
this->device->Load("/myfile");
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "testutils/TimestampTestUtils.h"
|
#include "testutils/TimestampTestUtils.h"
|
||||||
|
|
||||||
template<class ConcreteFileSystemTestFixture>
|
template<class ConcreteFileSystemTestFixture>
|
||||||
class FsppDirTest_Timestamps: public FileSystemTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils<fspp::Node> {
|
class FsppDirTest_Timestamps: public FileSystemTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils {
|
||||||
public:
|
public:
|
||||||
};
|
};
|
||||||
TYPED_TEST_CASE_P(FsppDirTest_Timestamps);
|
TYPED_TEST_CASE_P(FsppDirTest_Timestamps);
|
||||||
@ -131,7 +131,7 @@ TYPED_TEST_P(FsppDirTest_Timestamps, children_nonempty_inRootDir) {
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
template<class ConcreteFileSystemTestFixture>
|
template<class ConcreteFileSystemTestFixture>
|
||||||
class FsppDirTest_Timestamps_Entries: public FsppNodeTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils<fspp::Node> {
|
class FsppDirTest_Timestamps_Entries: public FsppNodeTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void Test_deleteChild() {
|
void Test_deleteChild() {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "testutils/TimestampTestUtils.h"
|
#include "testutils/TimestampTestUtils.h"
|
||||||
|
|
||||||
template<class ConcreteFileSystemTestFixture>
|
template<class ConcreteFileSystemTestFixture>
|
||||||
class FsppFileTest_Timestamps: public FileSystemTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils<fspp::Node> {
|
class FsppFileTest_Timestamps: public FileSystemTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils {
|
||||||
public:
|
public:
|
||||||
cpputils::unique_ref<fspp::File> CreateFileWithSize(const boost::filesystem::path &path, off_t size) {
|
cpputils::unique_ref<fspp::File> CreateFileWithSize(const boost::filesystem::path &path, off_t size) {
|
||||||
auto file = this->CreateFile(path);
|
auto file = this->CreateFile(path);
|
||||||
|
@ -11,7 +11,7 @@ using namespace cpputils::time;
|
|||||||
using std::function;
|
using std::function;
|
||||||
|
|
||||||
template<class ConcreteFileSystemTestFixture>
|
template<class ConcreteFileSystemTestFixture>
|
||||||
class FsppNodeTest_Timestamps: public FsppNodeTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils<fspp::Node> {
|
class FsppNodeTest_Timestamps: public FsppNodeTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void Test_Create() {
|
void Test_Create() {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "testutils/TimestampTestUtils.h"
|
#include "testutils/TimestampTestUtils.h"
|
||||||
|
|
||||||
template<class ConcreteFileSystemTestFixture>
|
template<class ConcreteFileSystemTestFixture>
|
||||||
class FsppOpenFileTest_Timestamps: public FileSystemTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils<fspp::OpenFile> {
|
class FsppOpenFileTest_Timestamps: public FileSystemTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils {
|
||||||
public:
|
public:
|
||||||
cpputils::unique_ref<fspp::OpenFile> CreateAndOpenFile(const boost::filesystem::path &path) {
|
cpputils::unique_ref<fspp::OpenFile> CreateAndOpenFile(const boost::filesystem::path &path) {
|
||||||
return this->CreateFile(path)->open(O_RDWR);
|
return this->CreateFile(path)->open(O_RDWR);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "testutils/TimestampTestUtils.h"
|
#include "testutils/TimestampTestUtils.h"
|
||||||
|
|
||||||
template<class ConcreteFileSystemTestFixture>
|
template<class ConcreteFileSystemTestFixture>
|
||||||
class FsppSymlinkTest_Timestamps: public FileSystemTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils<fspp::Node> {
|
class FsppSymlinkTest_Timestamps: public FileSystemTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils {
|
||||||
public:
|
public:
|
||||||
};
|
};
|
||||||
TYPED_TEST_CASE_P(FsppSymlinkTest_Timestamps);
|
TYPED_TEST_CASE_P(FsppSymlinkTest_Timestamps);
|
||||||
|
@ -5,47 +5,94 @@
|
|||||||
#include <cpp-utils/system/time.h>
|
#include <cpp-utils/system/time.h>
|
||||||
#include <cpp-utils/system/stat.h>
|
#include <cpp-utils/system/stat.h>
|
||||||
|
|
||||||
template<typename NodeType>
|
|
||||||
class TimestampTestUtils {
|
class TimestampTestUtils {
|
||||||
public:
|
public:
|
||||||
using TimestampUpdateBehavior = std::function<void (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation)>;
|
using TimestampUpdateBehavior = std::function<void (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation)>;
|
||||||
|
|
||||||
static TimestampUpdateBehavior ExpectUpdatesAccessTimestamp;
|
TimestampUpdateBehavior ExpectUpdatesAccessTimestamp = [] (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation) {
|
||||||
static TimestampUpdateBehavior ExpectDoesntUpdateAccessTimestamp;
|
UNUSED(statBeforeOperation);
|
||||||
static TimestampUpdateBehavior ExpectUpdatesModificationTimestamp;
|
UNUSED(timeBeforeOperation);
|
||||||
static TimestampUpdateBehavior ExpectDoesntUpdateModificationTimestamp;
|
UNUSED(timeAfterOperation);
|
||||||
static TimestampUpdateBehavior ExpectUpdatesMetadataTimestamp;
|
EXPECT_LE(timeBeforeOperation, statAfterOperation.st_atim);
|
||||||
static TimestampUpdateBehavior ExpectDoesntUpdateMetadataTimestamp;
|
EXPECT_GE(timeAfterOperation, statAfterOperation.st_atim);
|
||||||
static TimestampUpdateBehavior ExpectDoesntUpdateAnyTimestamps;
|
};
|
||||||
|
|
||||||
void EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(const NodeType &node, std::function<void()> operation, std::initializer_list<TimestampUpdateBehavior> behaviorChecks) {
|
TimestampUpdateBehavior ExpectDoesntUpdateAccessTimestamp = [] (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation) {
|
||||||
ensureNodeTimestampsAreOld(node);
|
UNUSED(timeBeforeOperation);
|
||||||
struct stat oldStat = stat(node);
|
UNUSED(timeAfterOperation);
|
||||||
|
EXPECT_EQ(statBeforeOperation.st_atim, statAfterOperation.st_atim);
|
||||||
|
};
|
||||||
|
|
||||||
|
TimestampUpdateBehavior ExpectUpdatesModificationTimestamp = [] (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation) {
|
||||||
|
UNUSED(statBeforeOperation);
|
||||||
|
EXPECT_LE(timeBeforeOperation, statAfterOperation.st_mtim);
|
||||||
|
EXPECT_GE(timeAfterOperation, statAfterOperation.st_mtim);
|
||||||
|
};
|
||||||
|
|
||||||
|
TimestampUpdateBehavior ExpectDoesntUpdateModificationTimestamp = [] (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation) {
|
||||||
|
UNUSED(timeBeforeOperation);
|
||||||
|
UNUSED(timeAfterOperation);
|
||||||
|
EXPECT_EQ(statBeforeOperation.st_mtim, statAfterOperation.st_mtim);
|
||||||
|
};
|
||||||
|
|
||||||
|
TimestampUpdateBehavior ExpectUpdatesMetadataTimestamp = [] (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation) {
|
||||||
|
UNUSED(statBeforeOperation);
|
||||||
|
EXPECT_LE(timeBeforeOperation, statAfterOperation.st_ctim);
|
||||||
|
EXPECT_GE(timeAfterOperation, statAfterOperation.st_ctim);
|
||||||
|
};
|
||||||
|
|
||||||
|
TimestampUpdateBehavior ExpectDoesntUpdateMetadataTimestamp = [] (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation) {
|
||||||
|
UNUSED(timeBeforeOperation);
|
||||||
|
UNUSED(timeAfterOperation);
|
||||||
|
EXPECT_EQ(statBeforeOperation.st_ctim, statAfterOperation.st_ctim);
|
||||||
|
};
|
||||||
|
|
||||||
|
TimestampUpdateBehavior ExpectDoesntUpdateAnyTimestamps = [this] (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation) {
|
||||||
|
ExpectDoesntUpdateAccessTimestamp(statBeforeOperation, statAfterOperation, timeBeforeOperation, timeAfterOperation);
|
||||||
|
ExpectDoesntUpdateModificationTimestamp(statBeforeOperation, statAfterOperation, timeBeforeOperation, timeAfterOperation);
|
||||||
|
ExpectDoesntUpdateMetadataTimestamp(statBeforeOperation, statAfterOperation, timeBeforeOperation, timeAfterOperation);
|
||||||
|
};
|
||||||
|
|
||||||
|
void EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(std::function<struct stat()> stat, std::function<void()> operation, std::initializer_list<TimestampUpdateBehavior> behaviorChecks) {
|
||||||
|
struct stat oldStat = stat();
|
||||||
|
ensureNodeTimestampsAreOld(oldStat);
|
||||||
timespec timeBeforeOperation = cpputils::time::now();
|
timespec timeBeforeOperation = cpputils::time::now();
|
||||||
operation();
|
operation();
|
||||||
timespec timeAfterOperation = cpputils::time::now();
|
timespec timeAfterOperation = cpputils::time::now();
|
||||||
struct stat newStat = stat(node);
|
struct stat newStat = stat();
|
||||||
for (auto behaviorCheck : behaviorChecks) {
|
for (auto behaviorCheck : behaviorChecks) {
|
||||||
behaviorCheck(oldStat, newStat, timeBeforeOperation, timeAfterOperation);
|
behaviorCheck(oldStat, newStat, timeBeforeOperation, timeAfterOperation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(const fspp::OpenFile &node, std::function<void()> operation, std::initializer_list<TimestampUpdateBehavior> behaviorChecks) {
|
||||||
|
return EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS([&node](){return stat(node);}, operation, behaviorChecks);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(const fspp::Node &node, std::function<void()> operation, std::initializer_list<TimestampUpdateBehavior> behaviorChecks) {
|
||||||
|
return EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS([&node](){return stat(node);}, operation, behaviorChecks);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename NodeType>
|
||||||
void EXPECT_ACCESS_TIMESTAMP_BETWEEN(timespec lowerBound, timespec upperBound, const NodeType &node) {
|
void EXPECT_ACCESS_TIMESTAMP_BETWEEN(timespec lowerBound, timespec upperBound, const NodeType &node) {
|
||||||
EXPECT_LE(lowerBound, stat(node).st_atim);
|
EXPECT_LE(lowerBound, stat(node).st_atim);
|
||||||
EXPECT_GE(upperBound, stat(node).st_atim);
|
EXPECT_GE(upperBound, stat(node).st_atim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename NodeType>
|
||||||
void EXPECT_MODIFICATION_TIMESTAMP_BETWEEN(timespec lowerBound, timespec upperBound, const NodeType &node) {
|
void EXPECT_MODIFICATION_TIMESTAMP_BETWEEN(timespec lowerBound, timespec upperBound, const NodeType &node) {
|
||||||
EXPECT_LE(lowerBound, stat(node).st_mtim);
|
EXPECT_LE(lowerBound, stat(node).st_mtim);
|
||||||
EXPECT_GE(upperBound, stat(node).st_mtim);
|
EXPECT_GE(upperBound, stat(node).st_mtim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename NodeType>
|
||||||
void EXPECT_METADATACHANGE_TIMESTAMP_BETWEEN(timespec lowerBound, timespec upperBound, const NodeType &node) {
|
void EXPECT_METADATACHANGE_TIMESTAMP_BETWEEN(timespec lowerBound, timespec upperBound, const NodeType &node) {
|
||||||
EXPECT_LE(lowerBound, stat(node).st_ctim);
|
EXPECT_LE(lowerBound, stat(node).st_ctim);
|
||||||
EXPECT_GE(upperBound, stat(node).st_ctim);
|
EXPECT_GE(upperBound, stat(node).st_ctim);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stat stat(const NodeType &node) {
|
template<typename NodeType>
|
||||||
|
static struct stat stat(const NodeType &node) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
node.stat(&st);
|
node.stat(&st);
|
||||||
return st;
|
return st;
|
||||||
@ -57,11 +104,11 @@ public:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ensureNodeTimestampsAreOld(const NodeType &node) {
|
void ensureNodeTimestampsAreOld(const struct stat &nodeStat) {
|
||||||
waitUntilClockProgresses();
|
waitUntilClockProgresses();
|
||||||
EXPECT_LT(stat(node).st_atim, cpputils::time::now());
|
EXPECT_LT(nodeStat.st_atim, cpputils::time::now());
|
||||||
EXPECT_LT(stat(node).st_mtim, cpputils::time::now());
|
EXPECT_LT(nodeStat.st_mtim, cpputils::time::now());
|
||||||
EXPECT_LT(stat(node).st_ctim, cpputils::time::now());
|
EXPECT_LT(nodeStat.st_ctim, cpputils::time::now());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -74,55 +121,4 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class NodeType>
|
|
||||||
typename TimestampTestUtils<NodeType>::TimestampUpdateBehavior TimestampTestUtils<NodeType>::ExpectUpdatesAccessTimestamp = [] (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation) {
|
|
||||||
UNUSED(statBeforeOperation);
|
|
||||||
UNUSED(timeBeforeOperation);
|
|
||||||
UNUSED(timeAfterOperation);
|
|
||||||
EXPECT_LE(timeBeforeOperation, statAfterOperation.st_atim);
|
|
||||||
EXPECT_GE(timeAfterOperation, statAfterOperation.st_atim);
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class NodeType>
|
|
||||||
typename TimestampTestUtils<NodeType>::TimestampUpdateBehavior TimestampTestUtils<NodeType>::ExpectDoesntUpdateAccessTimestamp = [] (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation) {
|
|
||||||
UNUSED(timeBeforeOperation);
|
|
||||||
UNUSED(timeAfterOperation);
|
|
||||||
EXPECT_EQ(statBeforeOperation.st_atim, statAfterOperation.st_atim);
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class NodeType>
|
|
||||||
typename TimestampTestUtils<NodeType>::TimestampUpdateBehavior TimestampTestUtils<NodeType>::ExpectUpdatesModificationTimestamp = [] (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation) {
|
|
||||||
UNUSED(statBeforeOperation);
|
|
||||||
EXPECT_LE(timeBeforeOperation, statAfterOperation.st_mtim);
|
|
||||||
EXPECT_GE(timeAfterOperation, statAfterOperation.st_mtim);
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class NodeType>
|
|
||||||
typename TimestampTestUtils<NodeType>::TimestampUpdateBehavior TimestampTestUtils<NodeType>::ExpectDoesntUpdateModificationTimestamp = [] (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation) {
|
|
||||||
UNUSED(timeBeforeOperation);
|
|
||||||
UNUSED(timeAfterOperation);
|
|
||||||
EXPECT_EQ(statBeforeOperation.st_mtim, statAfterOperation.st_mtim);
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class NodeType>
|
|
||||||
typename TimestampTestUtils<NodeType>::TimestampUpdateBehavior TimestampTestUtils<NodeType>::ExpectUpdatesMetadataTimestamp = [] (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation) {
|
|
||||||
UNUSED(statBeforeOperation);
|
|
||||||
EXPECT_LE(timeBeforeOperation, statAfterOperation.st_ctim);
|
|
||||||
EXPECT_GE(timeAfterOperation, statAfterOperation.st_ctim);
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class NodeType>
|
|
||||||
typename TimestampTestUtils<NodeType>::TimestampUpdateBehavior TimestampTestUtils<NodeType>::ExpectDoesntUpdateMetadataTimestamp = [] (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation) {
|
|
||||||
UNUSED(timeBeforeOperation);
|
|
||||||
UNUSED(timeAfterOperation);
|
|
||||||
EXPECT_EQ(statBeforeOperation.st_ctim, statAfterOperation.st_ctim);
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class NodeType>
|
|
||||||
typename TimestampTestUtils<NodeType>::TimestampUpdateBehavior TimestampTestUtils<NodeType>::ExpectDoesntUpdateAnyTimestamps = [] (struct stat statBeforeOperation, struct stat statAfterOperation, timespec timeBeforeOperation, timespec timeAfterOperation) {
|
|
||||||
TimestampTestUtils::ExpectDoesntUpdateAccessTimestamp(statBeforeOperation, statAfterOperation, timeBeforeOperation, timeAfterOperation);
|
|
||||||
TimestampTestUtils::ExpectDoesntUpdateModificationTimestamp(statBeforeOperation, statAfterOperation, timeBeforeOperation, timeAfterOperation);
|
|
||||||
TimestampTestUtils::ExpectDoesntUpdateMetadataTimestamp(statBeforeOperation, statAfterOperation, timeBeforeOperation, timeAfterOperation);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -704,11 +704,9 @@ int Fuse::statfs(const bf::path &path, struct statvfs *fsstat) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
|
||||||
int Fuse::flush(const bf::path &path, fuse_file_info *fileinfo) {
|
int Fuse::flush(const bf::path &path, fuse_file_info *fileinfo) {
|
||||||
#ifdef FSPP_LOG
|
#ifdef FSPP_LOG
|
||||||
//TODO Implement it
|
LOG(WARN) << "flush(" << path << ", _)";
|
||||||
LOG(WARN) << "Called non-implemented flush(" << path << ", _)";
|
|
||||||
#endif
|
#endif
|
||||||
UNUSED(path);
|
UNUSED(path);
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user