summaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/directio
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-05-19 21:57:59 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-05-20 12:38:48 +0000
commit64500ab17deb86b394edc81f4ad42b5a2c43fe30 (patch)
tree64334ba1513b697dacd5068981a8ee5b7ad92f3b /vespalib/src/tests/directio
parentcfa6ec5cdbd1cf39558d3f85101de05230d6c225 (diff)
Fold staging_vespalib into vespalib
Diffstat (limited to 'vespalib/src/tests/directio')
-rw-r--r--vespalib/src/tests/directio/.gitignore1
-rw-r--r--vespalib/src/tests/directio/CMakeLists.txt8
-rw-r--r--vespalib/src/tests/directio/directio.cpp57
3 files changed, 66 insertions, 0 deletions
diff --git a/vespalib/src/tests/directio/.gitignore b/vespalib/src/tests/directio/.gitignore
new file mode 100644
index 00000000000..ad19022dfc3
--- /dev/null
+++ b/vespalib/src/tests/directio/.gitignore
@@ -0,0 +1 @@
+vespalib_directio_test_app
diff --git a/vespalib/src/tests/directio/CMakeLists.txt b/vespalib/src/tests/directio/CMakeLists.txt
new file mode 100644
index 00000000000..41a8dca85b9
--- /dev/null
+++ b/vespalib/src/tests/directio/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(vespalib_directio_test_app TEST
+ SOURCES
+ directio.cpp
+ DEPENDS
+ vespalib
+)
+vespa_add_test(NAME vespalib_directio_test_app COMMAND vespalib_directio_test_app)
diff --git a/vespalib/src/tests/directio/directio.cpp b/vespalib/src/tests/directio/directio.cpp
new file mode 100644
index 00000000000..77374f6f926
--- /dev/null
+++ b/vespalib/src/tests/directio/directio.cpp
@@ -0,0 +1,57 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/vespalib/stllike/string.h>
+#include <vespa/vespalib/util/size_literals.h>
+#include <vespa/vespalib/data/databuffer.h>
+#include <vespa/fastos/file.h>
+
+using namespace vespalib;
+
+TEST("that DirectIOException propagates the correct information.") {
+ const char *msg("The buffer");
+ DirectIOException e("file.a", msg, 10, 3);
+ EXPECT_EQUAL(10u, e.getLength());
+ EXPECT_EQUAL(3u, e.getOffset());
+ EXPECT_EQUAL(msg, e.getBuffer());
+ EXPECT_EQUAL(0u, string(e.what()).find("DirectIO failed for file 'file.a' buffer="));
+ EXPECT_EQUAL(string("file.a"), e.getFileName());
+}
+
+TEST("that DirectIOException is thrown on unaligned buf.") {
+ FastOS_File f("vespalib_directio_test_app");
+ f.EnableDirectIO();
+ EXPECT_TRUE(f.OpenReadOnly());
+ DataBuffer buf(10000, 4_Ki);
+ bool caught(false);
+ try {
+ f.ReadBuf(buf.getFree()+1, 4_Ki, 0);
+ } catch (const DirectIOException & e) {
+ EXPECT_EQUAL(4_Ki, e.getLength());
+ EXPECT_EQUAL(0u, e.getOffset());
+ EXPECT_EQUAL(buf.getFree()+1, e.getBuffer());
+ EXPECT_EQUAL(string(f.GetFileName()), e.getFileName());
+ caught = true;
+ }
+ EXPECT_TRUE(caught);
+}
+
+TEST("that DirectIOException is thrown on unaligned offset.") {
+ FastOS_File f("vespalib_directio_test_app");
+ f.EnableDirectIO();
+ EXPECT_TRUE(f.OpenReadOnly());
+ DataBuffer buf(10000, 4_Ki);
+ bool caught(false);
+ try {
+ f.ReadBuf(buf.getFree(), 4_Ki, 1);
+ } catch (const DirectIOException & e) {
+ EXPECT_EQUAL(4_Ki, e.getLength());
+ EXPECT_EQUAL(1u, e.getOffset());
+ EXPECT_EQUAL(buf.getFree(), e.getBuffer());
+ EXPECT_EQUAL(string(f.GetFileName()), e.getFileName());
+ caught = true;
+ }
+ EXPECT_TRUE(caught);
+}
+
+TEST_MAIN() { TEST_RUN_ALL(); }