[lvm-devel] master - test: Implement a file-backed IO sink in the runner.
Petr Rockai
mornfall at fedoraproject.org
Thu Feb 5 13:41:00 UTC 2015
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f53fcc0746184d2d221a3c37e71769b4accabf19
Commit: f53fcc0746184d2d221a3c37e71769b4accabf19
Parent: bdd0bc83ebc3b753b45f2e7465a40c2b6b7bac27
Author: Petr Rockai <prockai at redhat.com>
AuthorDate: Fri Jun 27 00:53:36 2014 +0200
Committer: Petr Rockai <prockai at redhat.com>
CommitterDate: Thu Feb 5 13:47:17 2015 +0100
test: Implement a file-backed IO sink in the runner.
---
test/lib/io.h | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/test/lib/io.h b/test/lib/io.h
index 28e40d8..c96382c 100644
--- a/test/lib/io.h
+++ b/test/lib/io.h
@@ -95,6 +95,8 @@ struct FdSink : Sink {
}
virtual void sync() {
+ if ( killed )
+ return;
while ( !stream.empty() )
outline( true );
}
@@ -107,6 +109,26 @@ struct FdSink : Sink {
FdSink( int _fd ) : fd( _fd ), killed( false ) {}
};
+struct FileSink : FdSink {
+ std::string file;
+ FileSink( std::string n ) : FdSink( -1 ), file( n ) {}
+
+ void sync() {
+ if ( fd < 0 && !killed ) {
+ fd = open( file.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644 );
+ if ( fd < 0 )
+ killed = true;
+ }
+ FdSink::sync();
+ }
+ ~FileSink() {
+ if ( fd >= 0 ) {
+ fsync( fd );
+ close( fd );
+ }
+ }
+};
+
struct Observer : Sink {
Observer() {}
void push( std::string ) {}
More information about the lvm-devel
mailing list