Shift the exception tracer benchmark and test into the test directory
authorChristopher Dykes <cdykes@fb.com>
Wed, 21 Jun 2017 18:22:23 +0000 (11:22 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 21 Jun 2017 18:42:36 +0000 (11:42 -0700)
Summary: Tests and benchmarks don't belong in the same directory as source code.

Reviewed By: yfeldblum

Differential Revision: D5288080

fbshipit-source-id: 865c6dfbeff751bda49870e5284e168d33aff256

folly/experimental/exception_tracer/ExceptionTracerBenchmark.cpp [deleted file]
folly/experimental/exception_tracer/ExceptionTracerTest.cpp [deleted file]
folly/experimental/exception_tracer/test/ExceptionTracerBenchmark.cpp [new file with mode: 0644]
folly/experimental/exception_tracer/test/ExceptionTracerTest.cpp [new file with mode: 0644]

diff --git a/folly/experimental/exception_tracer/ExceptionTracerBenchmark.cpp b/folly/experimental/exception_tracer/ExceptionTracerBenchmark.cpp
deleted file mode 100644 (file)
index 2e7b88c..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2017 Facebook, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdexcept>
-#include <thread>
-#include <vector>
-
-#include <glog/logging.h>
-
-#include <folly/Benchmark.h>
-#include <folly/experimental/exception_tracer/ExceptionTracer.h>
-#include <folly/portability/GFlags.h>
-
-void recurse(int level) {
-  if (level == 0) {
-    throw std::runtime_error("");
-  }
-  recurse(level - 1);
-  folly::doNotOptimizeAway(0);  // prevent tail recursion
-}
-
-void loop(int iters) {
-  for (int i = 0; i < iters * 100; ++i) {
-    try {
-      recurse(100);
-    } catch (const std::exception& e) {
-      folly::exception_tracer::getCurrentExceptions();
-    }
-  }
-}
-
-BENCHMARK(ExceptionTracer, iters) {
-  std::vector<std::thread> threads;
-  constexpr size_t kNumThreads = 10;
-  threads.resize(10);
-  for (auto& t : threads) {
-    t = std::thread([iters] () { loop(iters); });
-  }
-  for (auto& t : threads) {
-    t.join();
-  }
-}
-
-int main(int argc, char* argv[]) {
-  gflags::ParseCommandLineFlags(&argc, &argv, true);
-  google::InitGoogleLogging(argv[0]);
-  folly::runBenchmarks();
-  return 0;
-}
diff --git a/folly/experimental/exception_tracer/ExceptionTracerTest.cpp b/folly/experimental/exception_tracer/ExceptionTracerTest.cpp
deleted file mode 100644 (file)
index f636692..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright 2017 Facebook, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <iostream>
-#include <stdexcept>
-
-#include <folly/experimental/exception_tracer/ExceptionTracer.h>
-
-[[noreturn]] void bar() {
-  throw std::runtime_error("hello");
-}
-
-void dumpExceptions(const char* prefix) {
-  std::cerr << "--- " << prefix << "\n";
-  auto exceptions = ::folly::exception_tracer::getCurrentExceptions();
-  for (auto& exc : exceptions) {
-    std::cerr << exc << "\n";
-  }
-}
-
-void foo() {
-  try {
-    try {
-      bar();
-    } catch (const std::exception& e) {
-      dumpExceptions("foo: simple catch");
-      bar();
-    }
-  } catch (const std::exception& e) {
-    dumpExceptions("foo: catch, exception thrown from previous catch block");
-  }
-}
-
-[[noreturn]] void baz() {
-  try {
-    try {
-      bar();
-    } catch (...) {
-      dumpExceptions("baz: simple catch");
-      throw;
-    }
-  } catch (const std::exception& e) {
-    dumpExceptions("baz: catch rethrown exception");
-    throw "hello";
-  }
-}
-
-void testExceptionPtr1() {
-  std::exception_ptr exc;
-  try {
-    bar();
-  } catch (...) {
-    exc = std::current_exception();
-  }
-
-  try {
-    std::rethrow_exception(exc);
-  } catch (...) {
-    dumpExceptions("std::rethrow_exception 1");
-  }
-}
-
-void testExceptionPtr2() {
-  std::exception_ptr exc;
-  try {
-    throw std::out_of_range("x");
-  } catch (...) {
-    exc = std::current_exception();
-  }
-
-  try {
-    std::rethrow_exception(exc);
-  } catch (...) {
-    dumpExceptions("std::rethrow_exception 2");
-  }
-}
-
-int main(int /* argc */, char* /* argv */ []) {
-  foo();
-  testExceptionPtr1();
-  testExceptionPtr2();
-  baz();
-  // no return because baz() is [[noreturn]]
-}
diff --git a/folly/experimental/exception_tracer/test/ExceptionTracerBenchmark.cpp b/folly/experimental/exception_tracer/test/ExceptionTracerBenchmark.cpp
new file mode 100644 (file)
index 0000000..2e7b88c
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2017 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdexcept>
+#include <thread>
+#include <vector>
+
+#include <glog/logging.h>
+
+#include <folly/Benchmark.h>
+#include <folly/experimental/exception_tracer/ExceptionTracer.h>
+#include <folly/portability/GFlags.h>
+
+void recurse(int level) {
+  if (level == 0) {
+    throw std::runtime_error("");
+  }
+  recurse(level - 1);
+  folly::doNotOptimizeAway(0);  // prevent tail recursion
+}
+
+void loop(int iters) {
+  for (int i = 0; i < iters * 100; ++i) {
+    try {
+      recurse(100);
+    } catch (const std::exception& e) {
+      folly::exception_tracer::getCurrentExceptions();
+    }
+  }
+}
+
+BENCHMARK(ExceptionTracer, iters) {
+  std::vector<std::thread> threads;
+  constexpr size_t kNumThreads = 10;
+  threads.resize(10);
+  for (auto& t : threads) {
+    t = std::thread([iters] () { loop(iters); });
+  }
+  for (auto& t : threads) {
+    t.join();
+  }
+}
+
+int main(int argc, char* argv[]) {
+  gflags::ParseCommandLineFlags(&argc, &argv, true);
+  google::InitGoogleLogging(argv[0]);
+  folly::runBenchmarks();
+  return 0;
+}
diff --git a/folly/experimental/exception_tracer/test/ExceptionTracerTest.cpp b/folly/experimental/exception_tracer/test/ExceptionTracerTest.cpp
new file mode 100644 (file)
index 0000000..e0fe233
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2017-present Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <iostream>
+#include <stdexcept>
+
+#include <folly/experimental/exception_tracer/ExceptionTracer.h>
+
+[[noreturn]] void bar() {
+  throw std::runtime_error("hello");
+}
+
+void dumpExceptions(const char* prefix) {
+  std::cerr << "--- " << prefix << "\n";
+  auto exceptions = ::folly::exception_tracer::getCurrentExceptions();
+  for (auto& exc : exceptions) {
+    std::cerr << exc << "\n";
+  }
+}
+
+void foo() {
+  try {
+    try {
+      bar();
+    } catch (const std::exception& e) {
+      dumpExceptions("foo: simple catch");
+      bar();
+    }
+  } catch (const std::exception& e) {
+    dumpExceptions("foo: catch, exception thrown from previous catch block");
+  }
+}
+
+[[noreturn]] void baz() {
+  try {
+    try {
+      bar();
+    } catch (...) {
+      dumpExceptions("baz: simple catch");
+      throw;
+    }
+  } catch (const std::exception& e) {
+    dumpExceptions("baz: catch rethrown exception");
+    throw "hello";
+  }
+}
+
+void testExceptionPtr1() {
+  std::exception_ptr exc;
+  try {
+    bar();
+  } catch (...) {
+    exc = std::current_exception();
+  }
+
+  try {
+    std::rethrow_exception(exc);
+  } catch (...) {
+    dumpExceptions("std::rethrow_exception 1");
+  }
+}
+
+void testExceptionPtr2() {
+  std::exception_ptr exc;
+  try {
+    throw std::out_of_range("x");
+  } catch (...) {
+    exc = std::current_exception();
+  }
+
+  try {
+    std::rethrow_exception(exc);
+  } catch (...) {
+    dumpExceptions("std::rethrow_exception 2");
+  }
+}
+
+int main(int /* argc */, char* /* argv */ []) {
+  foo();
+  testExceptionPtr1();
+  testExceptionPtr2();
+  baz();
+  // no return because baz() is [[noreturn]]
+}