Re-enable io tests
authorTed Percival <ted@tedp.id.au>
Thu, 23 Mar 2017 18:30:38 +0000 (11:30 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 23 Mar 2017 18:37:27 +0000 (11:37 -0700)
Summary:
Looks like some tests for the `io` directory were left behind when they were moved out of experimental. Re-enabled them in the new location, except for the compression test because it takes a lot longer. It's still built and can be executed manually.

Also added some preprocessor guards around compression codecs that might not be compiled in (and therefore fail during test SetUp).

Depends on #547 because the path to gtest appears in the new Makefile.am's `CPPFLAGS`.
Closes https://github.com/facebook/folly/pull/550

Reviewed By: yfeldblum

Differential Revision: D4631244

Pulled By: Orvid

fbshipit-source-id: 496b2c272e4f7293822f159776a02f7dd0c9e04d

.gitignore
folly/Makefile.am
folly/configure.ac
folly/experimental/io/test/Makefile.am
folly/io/Compression.cpp
folly/io/test/CompressionTest.cpp
folly/io/test/Makefile.am [new file with mode: 0644]
folly/test/.gitignore [deleted file]

index 9674945fede9d6306699c30bde350d098e26177c..775b535bf6b4cc867e9338126f568e0b042f4a56 100644 (file)
@@ -13,11 +13,13 @@ aclocal.m4
 autom4te.cache
 build-aux
 libtool
-folly/test/gtest-1.*
+folly/test/gtest
 folly/folly-config.h
-folly/test/*_benchmark
-folly/test/*_test
-folly/test/*_test_using_jemalloc
+folly/**/test/*_benchmark
+folly/**/test/*.log
+folly/**/test/*_test
+folly/**/test/*_test_using_jemalloc
+folly/**/test/*.trs
 folly/config.*
 folly/configure
 folly/libfolly.pc
index ba3a9abf835aba55136a3e6140605232bf3c9479..16ea751f2f6f30e2c7d91bcd36b15c93e70ac12f 100644 (file)
@@ -1,7 +1,7 @@
 if FOLLY_TESTMAIN
-SUBDIRS = . experimental init test
+SUBDIRS = . experimental init test io/test experimental/io/test
 else
-SUBDIRS = . test
+SUBDIRS = . experimental test io/test experimental/io/test
 endif
 
 ACLOCAL_AMFLAGS = -I m4
index 0ee732e54b142424e0403df6f05bb93202172cea..db8ff1b92982355192298b33ea86084640ce37a1 100644 (file)
@@ -610,10 +610,12 @@ FB_FILTER_PKG_LIBS([$AM_LDFLAGS $LIBS])
 
 # Output
 AC_CONFIG_FILES([Makefile
+                 io/test/Makefile
                  libfolly.pc
                  test/Makefile
                  test/function_benchmark/Makefile
                  experimental/Makefile
+                 experimental/io/test/Makefile
                  experimental/symbolizer/Makefile
                  init/Makefile])
 AC_OUTPUT
index b6c5f4f5bde87993185edeb46826dff470143e15..a835e841b2c2cd4a842ab9256c34f356147ba96c 100644 (file)
@@ -1,12 +1,12 @@
 ACLOCAL_AMFLAGS = -I m4
 
-TESTS = iobuf_test \
-        iobuf_cursor_test
+CPPFLAGS = -I$(top_srcdir)/test/gtest/googletest/include
+ldadd = $(top_builddir)/test/libfollytestmain.la
 
-check_PROGRAMS = $(TESTS)
+check_PROGRAMS = \
+       fs_util_test
 
-iobuf_test_SOURCES = IOBufTest.cpp
-iobuf_test_LDADD = $(top_builddir)/libfollyio.la
+TESTS = $(check_PROGRAMS)
 
-iobuf_cursor_test_SOURCES = IOBufCursorTest.cpp
-iobuf_cursor_test_LDADD = $(top_builddir)/libfollyio.la $(top_builddir)/libfollybenchmark.la
+fs_util_test_SOURCES = FsUtilTest.cpp
+fs_util_test_LDADD = $(ldadd)
index c626be74b3949e21adfe39fe9ce7eb0aafd112c9..d618da0c51c6e88ea2855093d90fe25d95c284ab 100644 (file)
@@ -1190,7 +1190,7 @@ std::unique_ptr<IOBuf> ZSTDCodec::doUncompress(
 }  // namespace
 
 typedef std::unique_ptr<Codec> (*CodecFactory)(int, CodecType);
-static CodecFactory
+static constexpr CodecFactory
     codecFactories[static_cast<size_t>(CodecType::NUM_CODEC_TYPES)] = {
         nullptr, // USER_DEFINED
         NoCompressionCodec::create,
index 46f40731bc4d3dd443d0077977bbac4f4754473b..e468287fba3df514571302aeed0a4375bfafb535 100644 (file)
@@ -120,17 +120,53 @@ constexpr size_t dataSizeLog2 = 27;  // 128MiB
 RandomDataHolder randomDataHolder(dataSizeLog2);
 ConstantDataHolder constantDataHolder(dataSizeLog2);
 
+// The intersection of the provided codecs & those that are compiled in.
+static std::vector<CodecType> supportedCodecs(std::vector<CodecType> const& v) {
+  std::vector<CodecType> supported;
+
+  std::copy_if(
+      std::begin(v),
+      std::end(v),
+      std::back_inserter(supported),
+      hasCodec);
+
+  return supported;
+}
+
+// All compiled-in compression codecs.
+static std::vector<CodecType> availableCodecs() {
+  std::vector<CodecType> codecs;
+
+  for (size_t i = 0; i < static_cast<size_t>(CodecType::NUM_CODEC_TYPES); ++i) {
+    auto type = static_cast<CodecType>(i);
+    if (hasCodec(type)) {
+      codecs.push_back(type);
+    }
+  }
+
+  return codecs;
+}
+
 TEST(CompressionTestNeedsUncompressedLength, Simple) {
-  EXPECT_FALSE(getCodec(CodecType::NO_COMPRESSION)->needsUncompressedLength());
-  EXPECT_TRUE(getCodec(CodecType::LZ4)->needsUncompressedLength());
-  EXPECT_FALSE(getCodec(CodecType::SNAPPY)->needsUncompressedLength());
-  EXPECT_FALSE(getCodec(CodecType::ZLIB)->needsUncompressedLength());
-  EXPECT_FALSE(getCodec(CodecType::LZ4_VARINT_SIZE)->needsUncompressedLength());
-  EXPECT_TRUE(getCodec(CodecType::LZMA2)->needsUncompressedLength());
-  EXPECT_FALSE(getCodec(CodecType::LZMA2_VARINT_SIZE)
-    ->needsUncompressedLength());
-  EXPECT_FALSE(getCodec(CodecType::ZSTD)->needsUncompressedLength());
-  EXPECT_FALSE(getCodec(CodecType::GZIP)->needsUncompressedLength());
+  static const struct { CodecType type; bool needsUncompressedLength; }
+    expectations[] = {
+      { CodecType::NO_COMPRESSION, false },
+      { CodecType::LZ4, true },
+      { CodecType::SNAPPY, false },
+      { CodecType::ZLIB, false },
+      { CodecType::LZ4_VARINT_SIZE, false },
+      { CodecType::LZMA2, true },
+      { CodecType::LZMA2_VARINT_SIZE, false },
+      { CodecType::ZSTD, false },
+      { CodecType::GZIP, false },
+    };
+
+  for (auto const& test : expectations) {
+    if (hasCodec(test.type)) {
+      EXPECT_EQ(getCodec(test.type)->needsUncompressedLength(),
+                test.needsUncompressedLength);
+    }
+  }
 }
 
 class CompressionTest
@@ -236,16 +272,7 @@ INSTANTIATE_TEST_CASE_P(
     testing::Combine(
         testing::Values(0, 1, 12, 22, 25, 27),
         testing::Values(1, 2, 3, 8, 65),
-        testing::Values(
-            CodecType::NO_COMPRESSION,
-            CodecType::LZ4,
-            CodecType::SNAPPY,
-            CodecType::ZLIB,
-            CodecType::LZ4_VARINT_SIZE,
-            CodecType::LZMA2,
-            CodecType::LZMA2_VARINT_SIZE,
-            CodecType::ZSTD,
-            CodecType::GZIP)));
+        testing::ValuesIn(availableCodecs())));
 
 class CompressionVarintTest
     : public testing::TestWithParam<std::tr1::tuple<int, CodecType>> {
@@ -301,9 +328,10 @@ INSTANTIATE_TEST_CASE_P(
     CompressionVarintTest,
     testing::Combine(
         testing::Values(0, 1, 12, 22, 25, 27),
-        testing::Values(
+        testing::ValuesIn(supportedCodecs({
             CodecType::LZ4_VARINT_SIZE,
-            CodecType::LZMA2_VARINT_SIZE)));
+            CodecType::LZMA2_VARINT_SIZE,
+            }))));
 
 class CompressionCorruptionTest : public testing::TestWithParam<CodecType> {
  protected:
@@ -357,11 +385,13 @@ TEST_P(CompressionCorruptionTest, ConstantData) {
 INSTANTIATE_TEST_CASE_P(
     CompressionCorruptionTest,
     CompressionCorruptionTest,
-    testing::Values(
+    testing::ValuesIn(
         // NO_COMPRESSION can't detect corruption
         // LZ4 can't detect corruption reliably (sigh)
-        CodecType::SNAPPY,
-        CodecType::ZLIB));
+        supportedCodecs({
+            CodecType::SNAPPY,
+            CodecType::ZLIB,
+            })));
 
 }}}  // namespaces
 
diff --git a/folly/io/test/Makefile.am b/folly/io/test/Makefile.am
new file mode 100644 (file)
index 0000000..7c469e3
--- /dev/null
@@ -0,0 +1,35 @@
+ACLOCAL_AMFLAGS = -I m4
+
+CPPFLAGS = -I$(top_srcdir)/test/gtest/googletest/include
+ldadd = $(top_builddir)/test/libfollytestmain.la
+
+# compression_test takes several minutes, so it's not run automatically.
+TESTS = \
+       iobuf_test \
+       iobuf_cursor_test \
+       iobuf_queue_test \
+       record_io_test \
+       shutdown_socket_set_test
+
+check_PROGRAMS = $(TESTS) \
+                compression_test
+
+iobuf_test_SOURCES = IOBufTest.cpp
+iobuf_test_LDADD = $(ldadd)
+
+iobuf_cursor_test_SOURCES = IOBufCursorTest.cpp
+iobuf_cursor_test_LDADD = $(ldadd)
+
+compression_test_SOURCES = CompressionTest.cpp
+compression_test_LDADD = $(top_builddir)/libfolly.la \
+                        $(top_builddir)/test/libgtest.la \
+                        $(top_builddir)/libfollybenchmark.la
+
+iobuf_queue_test_SOURCES = IOBufQueueTest.cpp
+iobuf_queue_test_LDADD = $(ldadd)
+
+record_io_test_SOURCES = RecordIOTest.cpp
+record_io_test_LDADD = $(ldadd)
+
+shutdown_socket_set_test_SOURCES = ShutdownSocketSetTest.cpp
+shutdown_socket_set_test_LDADD = $(ldadd)
diff --git a/folly/test/.gitignore b/folly/test/.gitignore
deleted file mode 100644 (file)
index baa95bc..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-*.log
-*.trs
-gtest*/*