summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2022-04-06 12:18:08 +0000
committerHåvard Pettersen <havardpe@oath.com>2022-04-08 13:45:13 +0000
commit9fbcf76d088740aacf535e6482f86c833cfae871 (patch)
treec62dcd0f9cdcee9876b37c60f741958c14147f80 /vespalib
parent69454cef2fe53694eb5541e5f622a4e973c081bf (diff)
remove FastOS_Application
fixup (per application): - maybe ignore SIGPIPE - wire argc/argv untangle Vespa Test Framework strip down deprecated TestApp
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/btree/btree-scan-speed/btree_scan_speed_test.cpp14
-rw-r--r--vespalib/src/tests/btree/iteratespeed.cpp17
-rw-r--r--vespalib/src/vespa/vespalib/testkit/test_macros.h25
-rw-r--r--vespalib/src/vespa/vespalib/testkit/test_master.cpp2
-rw-r--r--vespalib/src/vespa/vespalib/testkit/testapp.cpp23
-rw-r--r--vespalib/src/vespa/vespalib/testkit/testapp.h166
-rw-r--r--vespalib/src/vespa/vespalib/util/backtrace.cpp4
7 files changed, 42 insertions, 209 deletions
diff --git a/vespalib/src/tests/btree/btree-scan-speed/btree_scan_speed_test.cpp b/vespalib/src/tests/btree/btree-scan-speed/btree_scan_speed_test.cpp
index e2df9996dcb..352ef5ef70a 100644
--- a/vespalib/src/tests/btree/btree-scan-speed/btree_scan_speed_test.cpp
+++ b/vespalib/src/tests/btree/btree-scan-speed/btree_scan_speed_test.cpp
@@ -17,8 +17,6 @@
#include <vespa/vespalib/util/time.h>
#include <vector>
-#include <vespa/fastos/app.h>
-
using vespalib::btree::BTree;
using vespalib::btree::BTreeNode;
using vespalib::btree::BTreeTraits;
@@ -29,11 +27,12 @@ enum class ScanMethod
FUNCTOR
};
-class ScanSpeed : public FastOS_Application
+class ScanSpeed
{
template <typename Traits>
void work_loop(ScanMethod scan_method);
- int Main() override;
+public:
+ int main();
};
@@ -162,7 +161,7 @@ ScanSpeed::work_loop(ScanMethod scan_method)
int
-ScanSpeed::Main()
+ScanSpeed::main()
{
using SmallTraits = BTreeTraits<4, 4, 31, false>;
using DefTraits = vespalib::btree::BTreeDefaultTraits;
@@ -179,4 +178,7 @@ ScanSpeed::Main()
return 0;
}
-FASTOS_MAIN(ScanSpeed);
+int main(int, char **) {
+ ScanSpeed app;
+ return app.main();
+}
diff --git a/vespalib/src/tests/btree/iteratespeed.cpp b/vespalib/src/tests/btree/iteratespeed.cpp
index 92a756a6eaa..fceaf01a785 100644
--- a/vespalib/src/tests/btree/iteratespeed.cpp
+++ b/vespalib/src/tests/btree/iteratespeed.cpp
@@ -17,7 +17,6 @@
#include <vespa/vespalib/util/rand48.h>
#include <vespa/vespalib/util/time.h>
-#include <vespa/fastos/app.h>
#include <unistd.h>
#include <vespa/log/log.h>
@@ -32,14 +31,15 @@ enum class IterateMethod
LAMBDA
};
-class IterateSpeed : public FastOS_Application
+class IterateSpeed
{
template <typename Traits, IterateMethod iterateMethod>
void
workLoop(int loops, bool enableForward, bool enableBackwards,
bool enableLambda, int leafSlots);
void usage();
- int Main() override;
+public:
+ int main(int argc, char **argv);
};
@@ -134,7 +134,7 @@ IterateSpeed::usage()
}
int
-IterateSpeed::Main()
+IterateSpeed::main(int argc, char **argv)
{
int c;
int loops = 1;
@@ -142,7 +142,7 @@ IterateSpeed::Main()
bool forwards = false;
bool lambda = false;
int leafSlots = 0;
- while ((c = getopt(_argc, _argv, "F:bc:fl")) != -1) {
+ while ((c = getopt(argc, argv, "F:bc:fl")) != -1) {
switch (c) {
case 'F':
leafSlots = atoi(optarg);
@@ -203,6 +203,7 @@ IterateSpeed::Main()
}
-FASTOS_MAIN(vespalib::btree::IterateSpeed);
-
-
+int main(int argc, char **argv) {
+ vespalib::btree::IterateSpeed app;
+ return app.main(argc, argv);
+}
diff --git a/vespalib/src/vespa/vespalib/testkit/test_macros.h b/vespalib/src/vespa/vespalib/testkit/test_macros.h
index ebf3e06d283..41816e13c2d 100644
--- a/vespalib/src/vespa/vespalib/testkit/test_macros.h
+++ b/vespalib/src/vespa/vespalib/testkit/test_macros.h
@@ -4,7 +4,6 @@
#include "test_master.h"
#include "test_comparators.h"
-#include <vespa/fastos/app.h>
#define TEST_STR(str) #str
#define TEST_CAT_IMPL(a, b) a ## b
@@ -18,22 +17,14 @@
#define TEST_TRACE() TEST_MASTER.trace(__FILE__, __LINE__)
#define TEST_THREAD(name) TEST_MASTER.setThreadName(name)
#define TEST_BARRIER() TEST_MASTER.awaitThreadBarrier(__FILE__, __LINE__)
-#define TEST_MAIN() \
- void test_kit_main(); \
- struct TestKitApp : FastOS_Application \
- { \
- int Main() override; \
- }; \
- int main(int argc, char **argv) \
- { \
- TestKitApp app; \
- return app.Entry(argc, argv); \
- } \
- int TestKitApp::Main() { \
- TEST_MASTER.init(__FILE__); \
- test_kit_main(); \
- return (TEST_MASTER.fini() ? 0 : 1); \
- } \
+#define TEST_MAIN() \
+ void test_kit_main(); \
+ int main(int, char **) \
+ { \
+ TEST_MASTER.init(__FILE__); \
+ test_kit_main(); \
+ return (TEST_MASTER.fini() ? 0 : 1); \
+ } \
void test_kit_main()
//-----------------------------------------------------------------------------
diff --git a/vespalib/src/vespa/vespalib/testkit/test_master.cpp b/vespalib/src/vespa/vespalib/testkit/test_master.cpp
index 64282d23d6a..434d08d6c7a 100644
--- a/vespalib/src/vespa/vespalib/testkit/test_master.cpp
+++ b/vespalib/src/vespa/vespalib/testkit/test_master.cpp
@@ -2,6 +2,7 @@
#include "test_master.h"
#include <vespa/vespalib/util/barrier.h>
+#include <vespa/vespalib/util/signalhandler.h>
#include <cstring>
#include <cassert>
@@ -176,6 +177,7 @@ void
TestMaster::init(const char *name)
{
lock_guard guard(_lock);
+ SignalHandler::PIPE.ignore();
_name = skip_path(name);
fprintf(stderr, "%s: info: running test suite '%s'\n", _name.c_str(), _name.c_str());
}
diff --git a/vespalib/src/vespa/vespalib/testkit/testapp.cpp b/vespalib/src/vespa/vespalib/testkit/testapp.cpp
index 4a7f0fd20e7..34d7e4eaa0e 100644
--- a/vespalib/src/vespa/vespalib/testkit/testapp.cpp
+++ b/vespalib/src/vespa/vespalib/testkit/testapp.cpp
@@ -4,25 +4,14 @@
namespace vespalib {
-TestMaster &TestApp::master(TestMaster::master);
-
-TestApp::TestApp()
- : FastOS_Application(),
- _name("<unnamed>")
-{ }
-
-TestApp::~TestApp() { }
-
-void
-TestApp::ReportInit(const char *name)
+int
+TestApp::Entry(int argc, char **argv)
{
- _name = name;
+ _argc = argc;
+ _argv = argv;
+ return Main();
}
-bool
-TestApp::ReportConclusion()
-{
- return true;
-}
+TestApp::~TestApp() = default;
} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/testkit/testapp.h b/vespalib/src/vespa/vespalib/testkit/testapp.h
index 8ffb9958555..bfa322ccac5 100644
--- a/vespalib/src/vespa/vespalib/testkit/testapp.h
+++ b/vespalib/src/vespa/vespalib/testkit/testapp.h
@@ -2,13 +2,9 @@
#pragma once
#include "test_kit.h"
-#include <vespa/fastos/app.h>
-#undef TEST_MASTER
-#define TEST_MASTER vespalib::TestApp::master
-
-#define TEST_INIT(name) do { ReportInit(name); TEST_MASTER.init(name); } while(false)
-#define TEST_DONE() do { ReportConclusion(); return TEST_MASTER.fini() ? 0 : 1; } while(false)
+#define TEST_INIT(name) do { TEST_MASTER.init(name); } while(false)
+#define TEST_DONE() do { return TEST_MASTER.fini() ? 0 : 1; } while(false)
#define TEST_APPHOOK(app) \
int main(int argc, char **argv) \
@@ -25,163 +21,15 @@
namespace vespalib {
-/**
- * @brief TestApp is used to create executable unit tests
- *
- * TestApp is a subclass of FastOS_Application that is tailored to
- * create small executable programs containing unit tests. The idea is
- * that you create a class that subclasses TestApp and use a set of
- * macros to test your code. It is similar to the concept used in
- * cppunit except that your tests become programs rather than library
- * code.
- *
- * Below follows an explanation of all the available macros. Note that
- * while you can also invoke the methods in this class directly, most
- * tests will only need to use macros. Also, some features like
- * grabbing the text making up a boolean expression, the file name and
- * the line number of a statement is only possible with macros.
- *
- * <table>
- * <tr><td><b>TEST_INIT(name)</b></td><td>
- * Invokes the ReportInit method. <i>name</i> is the name of this
- * test.
- * </td></tr>
- * <tr><td><b>TEST_GROUP(val)</b></td><td>
- * Invokes the SetGroupModulo method. <i>val</i> is an integer
- * defining the number of successful tests that may be logged at
- * once. If <i>val</i> is 0, all consecutive successful test cases
- * will be reported at once. If <i>val</i> is 1, all tests will be
- * reported by separate log messages (this is the default).
- * </td></tr>
- * <tr><td><b>TEST_DEBUG(lhsFile, rhsFile)</b></td><td>
- * Invokes the OpenDebugFiles method. <i>lhs</i> and <i>rhs</i> are
- * file names for files where we want the left hand side and right
- * hand side values to be stored. Diffing these files will simplify
- * debugging of failed tests.
- * </td></tr>
- * <tr><td><b>TEST_PUSH_STATE(msg)</b></td><td>
- * Invokes the PushState function. <i>msg</i> is pushed on the
- * internal state stack together with the current file and line
- * number. The state stack is dumped when a test fails, unless the
- * DumpState function is overridden.
- * </td></tr>
- * <tr><td><b>TEST_POP_STATE()</b></td><td>
- * Invokes the PopState function. The topmost item on the state stack
- * will be popped. If the state stack is empty, nothing will happen.
- * </td></tr>
- * <tr><td><b>TEST_DO(statement)</b></td><td>
- * Pushes <i>statement</i> on the state stack, performs
- * <i>statement</i> and finally pops the state stack. The intended
- * use is to wrap function calls within TEST_DO in order to produce
- * something that looks like a stack trace when the state stack is
- * dumped.
- * </td></tr>
- * <tr><td><b>EXPECT_TRUE(rc)</b></td><td>
- * Test that <i>rc</i> evaluates to true. <i>rc</i> must be an
- * expression that can be evaluated as a boolean. This automatically
- * creates a test case. The macro invokes the ReportTestResult
- * method.
- * </td></tr>
- * <tr><td><b>ASSERT_TRUE(rc)</b></td><td>
- * Does the same as EXPECT_TRUE except that the application is
- * aborted if the test fails. This macro may be used to test that
- * setup vital to the rest of the tests does not fail.
- * </td></tr>
- * <tr><td><b>EXPECT_EQUAL(a, b)</b></td><td>
- * Test that <i>a</i> == <i>b</i>.
- * </td></tr>
- * <tr><td><b>EXPECT_NOT_EQUAL(a, b)</b></td><td>
- * Test that <i>a</i> != <i>b</i>.
- * </td></tr>
- * <tr><td><b>EXPECT_LESS(a, b)</b></td><td>
- * Test that <i>a</i> &lt; <i>b</i>.
- * </td></tr>
- * <tr><td><b>EXPECT_LESS_EQUAL(a, b)</b></td><td>
- * Test that <i>a</i> &lt;= <i>b</i>.
- * </td></tr>
- * <tr><td><b>EXPECT_GREATER(a, b)</b></td><td>
- * Test that <i>a</i> &gt; <i>b</i>.
- * </td></tr>
- * <tr><td><b>EXPECT_GREATER_EQUAL(a, b)</b></td><td>
- * Test that <i>a</i> &gt;= <i>b</i>.
- * </td></tr>
- * <tr><td><b>TEST_FLUSH()</b></td><td>
- * Invokes the FlushReport method. This is used to force the logging
- * of successful test cases that are waiting to be logged due to
- * grouping (see TEST_GROUP).
- * </td></tr>
- * <tr><td><b>TEST_DONE()</b></td><td>
- * Invokes the ReportConclusion method and returns 0 if all test
- * cases passed, 1 otherwise. This should be the last thing in your
- * Main method.
- * </td></tr>
- * <tr><td><b>TEST_APPHOOK(app)</b></td><td>
- * Creates the code needed to run the class <i>app</i> that must be
- * a subclass of FastOS_Application. This will create a canonical
- * main method launching your fastos application.
- * </td></tr>
- * <tr><td><b>TEST_SETUP(test)</b></td><td>
- * Does the same as TEST_APPHOOK, but also creates a simple class
- * named <i>test</i> that is a subclass of TestApp and contains only
- * the Main method. If you want to add some helper methods to your
- * test, use TEST_APPHOOK, otherwise use this one.
- * </td></tr>
- * <tr><td><b>TEST_THREADS()</b></td><td>
- * This macro is used in tests that require thread support. If no
- * thread support is available (fastos was compiled without
- * threads), this macro will invoke the ReportNoThreads and call the
- * TEST_DONE macro to exit the test. If thread support is available
- * this macro does nothing.
- * </td></tr>
- * </table>
- *
- * Simple test example:
- * <pre>
- * \#include <vespa/vespalib/testkit/testapp.h>
- *
- * TEST_SETUP(Test)
- *
- * int
- * Test::Main()
- * {
- * TEST_INIT("true_test");
- * EXPECT_TRUE(true);
- * TEST_DONE();
- * }
- * </pre>
- **/
-class TestApp : public FastOS_Application
+class TestApp
{
-private:
- std::string _name;
-
public:
- static TestMaster &master;
+ int _argc = 0;
+ char **_argv = nullptr;
- TestApp();
+ virtual int Main() = 0;
+ int Entry(int argc, char **argv);
virtual ~TestApp();
-
- /**
- * @brief Obtain the name of this test
- *
- * @return test name
- **/
- const char *GetName() { return _name.c_str(); }
-
- /**
- * @brief Report test initialization
- *
- * @param name the name of this test
- **/
- virtual void ReportInit(const char *name);
-
- /**
- * @brief Report test summary
- *
- * @return true if all test cases passed
- **/
- virtual bool ReportConclusion();
};
} // namespace vespalib
-
diff --git a/vespalib/src/vespa/vespalib/util/backtrace.cpp b/vespalib/src/vespa/vespalib/util/backtrace.cpp
index 2241c292565..a020f6c33c0 100644
--- a/vespalib/src/vespa/vespalib/util/backtrace.cpp
+++ b/vespalib/src/vespa/vespalib/util/backtrace.cpp
@@ -13,9 +13,9 @@ namespace {
/**
* Convert input line of form eg.
- * ./exception_test(_ZN27FastOS_ApplicationInterface5EntryEiPPc+0x0) [0x1234]
+ * ./exception_test(_ZN11Application5entryEiPPc+0x0) [0x1234]
* to its demangled form
- * ./exception_test(FastOS_ApplicationInterface::Entry(int, char**)+0x0) [0x1234]
+ * ./exception_test(Application::entry(int, char**)+0x0) [0x1234]
*
* Assumes everything between '(' and '+' is a mangled function signature.
*