summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/lib/netlist/plib/ptests.h50
-rw-r--r--src/lib/netlist/prg/nltool.cpp4
-rw-r--r--src/lib/netlist/tests/test_pfunction.cpp25
3 files changed, 50 insertions, 29 deletions
diff --git a/src/lib/netlist/plib/ptests.h b/src/lib/netlist/plib/ptests.h
index 1f4bbd5e866..7369e74a20d 100644
--- a/src/lib/netlist/plib/ptests.h
+++ b/src/lib/netlist/plib/ptests.h
@@ -14,20 +14,27 @@
#include <vector>
#include <iostream>
#include <functional>
+#include <exception>
-#define EXPECT_EQ(exp1, exp2) PINT_EXPECT(eq, exp1, exp2)
-#define EXPECT_NE(exp1, exp2) PINT_EXPECT(ne, exp1, exp2)
-#define EXPECT_GT(exp1, exp2) PINT_EXPECT(gt, exp1, exp2)
-#define EXPECT_LT(exp1, exp2) PINT_EXPECT(lt, exp1, exp2)
-#define EXPECT_GE(exp1, exp2) PINT_EXPECT(ge, exp1, exp2)
-#define EXPECT_LE(exp1, exp2) PINT_EXPECT(le, exp1, exp2)
+#if defined(__clang__)
+#pragma clang diagnostic ignored "-Wglobal-constructors"
+#endif
-#define EXPECT_TRUE(exp1) PINT_EXPECT(eq, exp1, true)
-#define EXPECT_FALSE(exp1) PINT_EXPECT(eq, exp1, false)
+#define PEXPECT_EQ(exp1, exp2) PINT_EXPECT(eq, exp1, exp2)
+#define PEXPECT_NE(exp1, exp2) PINT_EXPECT(ne, exp1, exp2)
+#define PEXPECT_GT(exp1, exp2) PINT_EXPECT(gt, exp1, exp2)
+#define PEXPECT_LT(exp1, exp2) PINT_EXPECT(lt, exp1, exp2)
+#define PEXPECT_GE(exp1, exp2) PINT_EXPECT(ge, exp1, exp2)
+#define PEXPECT_LE(exp1, exp2) PINT_EXPECT(le, exp1, exp2)
-#define TEST(name, desc) PINT_TEST(name, desc)
-#define TEST_F(name, desc) PINT_TEST_F(name, desc, name)
-#define RUN_ALL_TESTS() plib::testing::run_all_tests()
+#define PEXPECT_TRUE(exp1) PINT_EXPECT(eq, exp1, true)
+#define PEXPECT_FALSE(exp1) PINT_EXPECT(eq, exp1, false)
+
+#define PEXPECT_THROW(exp, excep) PINT_EXPECT_THROW(exp, excep)
+
+#define PTEST(name, desc) PINT_TEST(name, desc)
+#define PTEST_F(name, desc) PINT_TEST_F(name, desc, name)
+#define PRUN_ALL_TESTS() plib::testing::run_all_tests()
#define PINT_TEST(name, desc) PINT_TEST_F(name, desc, plib::testing::Test)
@@ -37,12 +44,22 @@
void desc (); \
void run() override { desc (); } \
}; \
- plib::testing::reg_entry<name ## _ ## desc> name ## _ ## desc ## _reg(#name, #desc); \
+ extern const plib::testing::reg_entry<name ## _ ## desc> name ## _ ## desc ## _reg; \
+ const plib::testing::reg_entry<name ## _ ## desc> name ## _ ## desc ## _reg(#name, #desc); \
void name ## _ ## desc :: desc ()
#define PINT_EXPECT(comp, exp1, exp2) \
if (!plib::testing::internal_assert(plib::testing::comp_ ## comp (), # exp1, # exp2, exp1, exp2)) \
- std::cout << __FILE__ << ":" << __LINE__ << ":1: error: test failed\n";
+ std::cout << __FILE__ << ":" << __LINE__ << ":1: error: test failed\n"
+
+#define PINT_EXPECT_THROW(exp, excep) \
+ if (const char *ptest_f = __FILE__) \
+ { \
+ try { exp; std::cout << ptest_f << ":" << __LINE__ << ":1: error: no " #excep " exception thrown\n";} \
+ catch (excep &) { std::cout << "\tOK: got " #excep " for " # exp "\n";} \
+ catch (std::exception &ptest_e) { std::cout << ptest_f << ":" << __LINE__ << ":1: error: unexpected exception thrown: " << ptest_e.what() << "\n"; } \
+ catch (...) { std::cout << ptest_f << ":" << __LINE__ << ":1: error: unexpected exception thrown\n"; } \
+ } else do {} while (0)
namespace plib
{
@@ -67,7 +84,7 @@ namespace testing
registry().push_back(this);
}
virtual ~reg_entry_base() = default;
- virtual Test *create() { return nullptr; }
+ virtual Test *create() const { return nullptr; }
std::string name;
std::string desc;
@@ -84,7 +101,7 @@ namespace testing
{
using reg_entry_base::reg_entry_base;
- virtual Test *create() override { return new T(); }
+ virtual Test *create() const override { return new T(); }
};
template <typename C, typename T1, typename T2>
@@ -104,6 +121,9 @@ namespace testing
static inline int run_all_tests()
{
+ std::cout << "======================================\n";
+ std::cout << "Running " << reg_entry_base::registry().size() << " tests\n";
+ std::cout << "======================================\n";
for (auto &e : reg_entry_base::registry())
{
std::cout << e->name << "::" << e->desc << ":\n";
diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp
index a4946c00d3e..7b18b00d77d 100644
--- a/src/lib/netlist/prg/nltool.cpp
+++ b/src/lib/netlist/prg/nltool.cpp
@@ -439,7 +439,7 @@ void tool_app_t::run_with_progress(netlist_tool_t &nt, netlist::netlist_time_ext
else
{
nt.exec().process_queue(next_sec - now);
- pout("progress {1:4}s : {2}\r", elapsed_sec, pstring(elapsed_sec, '*'));
+ pout("progress {1:4}s : {2}\r", elapsed_sec, pstring(gsl::narrow_cast<std::size_t>(elapsed_sec), '*'));
pout.flush();
}
now = nt.exec().time();
@@ -1276,7 +1276,7 @@ int tool_app_t::execute()
convert();
else if (cmd == "tests")
{
- return RUN_ALL_TESTS();
+ return PRUN_ALL_TESTS();
}
else
{
diff --git a/src/lib/netlist/tests/test_pfunction.cpp b/src/lib/netlist/tests/test_pfunction.cpp
index c82617659ec..cb0cad8e188 100644
--- a/src/lib/netlist/tests/test_pfunction.cpp
+++ b/src/lib/netlist/tests/test_pfunction.cpp
@@ -10,11 +10,12 @@
#include "plib/ptests.h"
#include "plib/pfunction.h"
+#include "plib/pexception.h"
#define PFUNCEXPECT(formula, val) \
- EXPECT_EQ(val, plib::pfunction<double>(formula)())
+ PEXPECT_EQ(val, plib::pfunction<double>(formula)())
-TEST(pfunction, operators)
+PTEST(pfunction, operators)
{
PFUNCEXPECT("1==1", 1.0);
PFUNCEXPECT("1 *0 == 2-1-1", 1.0);
@@ -25,30 +26,30 @@ TEST(pfunction, operators)
PFUNCEXPECT("1>=0", 1.0);
PFUNCEXPECT("1<=1", 1.0);
PFUNCEXPECT("1>=1", 1.0);
- EXPECT_EQ(1.0, plib::pfunction<double>("0!=a", {"a"})({1.0}));
+ PEXPECT_EQ(1.0, plib::pfunction<double>("0!=a", {"a"})({1.0}));
}
-TEST(pfunction, func_if)
+PTEST(pfunction, func_if)
{
PFUNCEXPECT("if(1>0, 2, 0)", 2.0);
PFUNCEXPECT("if(0>1, 2, 3)", 3.0);
PFUNCEXPECT("if(sin(1)>0, 2, 3)", 3.0); // fail
- EXPECT_EQ( 1.0, plib::pfunction<double>("if(A2>2.5, 0-A1, (0.07-(0.005*A1))*if(A0>2.5,1,0-1))", {"A0","A1","A2"})({1.0,-1.0,3.0}));
- EXPECT_EQ(-0.065, plib::pfunction<double>("if(A2>2.5, 0-A1, (0.07-(0.005*A1))*if(A0>2.5,1,0-1))", {"A0","A1","A2"})({1.0,1.0,1.0}));
- EXPECT_EQ( 0.065, plib::pfunction<double>("if(A2>2.5, 0-A1, (0.07-(0.005*A1))*if(A0>2.5,1,0-1))", {"A0","A1","A2"})({3.0,1.0,1.0}));
- //EXPECT(plib::pfunction<double>("if(A2>2.5, A1, if(A0>2.5,1,(0-1)))", {"A0","A1","A2"})({1.0,1.0,1.0}), -1.0)
- //PFUNCEXPECT("-1>-2", 1.0)
- EXPECT_TRUE(1.0 == plib::pfunction<double>("0!=a", {"a"})({1.0}));
+ PEXPECT_EQ( 1.0, plib::pfunction<double>("if(A2>2.5, 0-A1, (0.07-(0.005*A1))*if(A0>2.5,1,0-1))", {"A0","A1","A2"})({1.0,-1.0,3.0}));
+ PEXPECT_EQ(-0.065, plib::pfunction<double>("if(A2>2.5, 0-A1, (0.07-(0.005*A1))*if(A0>2.5,1,0-1))", {"A0","A1","A2"})({1.0,1.0,1.0}));
+ PEXPECT_EQ( 0.065, plib::pfunction<double>("if(A2>2.5, 0-A1, (0.07-(0.005*A1))*if(A0>2.5,1,0-1))", {"A0","A1","A2"})({3.0,1.0,1.0}));
+ PEXPECT_TRUE(1.0 == plib::pfunction<double>("0!=a", {"a"})({1.0}));
}
-TEST(pfunction, unary_minus)
+PTEST(pfunction, unary_minus)
{
PFUNCEXPECT("-1>-2", 1.0);
PFUNCEXPECT("(-3)*(-4)", 12.0);
PFUNCEXPECT("(-3)*-4", 12.0);
PFUNCEXPECT("-3*-4", 12.0);
- EXPECT_EQ( -3.0, plib::pfunction<double>("-A0", {"A0"})({3.0}));
+ PEXPECT_EQ( -3.0, plib::pfunction<double>("-A0", {"A0"})({3.0}));
PFUNCEXPECT("3*-trunc(3.2)", -9.0);
PFUNCEXPECT("3*-(3*2)", -18.0);
PFUNCEXPECT("3*-(2*1)^2", -12.0);
+ PEXPECT_THROW(plib::pfunction<double>("(3, 4)")(), plib::pexception);
+ PEXPECT_THROW(plib::pfunction<double>("(3)")(), plib::pexception); // fail
}