"...resnet50_tensorflow.git" did not exist on "7b6c8999c48024789e30a41afee8b4d5b6b4fcb9"
Commit 9b3bc656 authored by Paul's avatar Paul
Browse files

Add initial test driver

parent c0bcc6fc
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <unordered_map>
#include <vector>
#ifndef MIGRAPH_GUARD_TEST_TEST_HPP #ifndef MIGRAPH_GUARD_TEST_TEST_HPP
#define MIGRAPH_GUARD_TEST_TEST_HPP #define MIGRAPH_GUARD_TEST_TEST_HPP
...@@ -154,11 +156,75 @@ bool throws(F f, const std::string& msg = "") ...@@ -154,11 +156,75 @@ bool throws(F f, const std::string& msg = "")
} }
} }
template <class T> using string_map = std::unordered_map<std::string, std::vector<std::string>>;
void run_test()
template <class Keyword>
string_map parse(std::vector<std::string> as, Keyword keyword)
{
string_map result;
std::string flag;
for(auto&& x : as)
{
auto f = keyword(x);
if(f.empty())
{
result[flag].push_back(x);
}
else
{
flag = f.front();
result[flag]; // Ensure the flag exists
}
}
return result;
}
inline auto& get_test_cases()
{
static std::vector<std::pair<std::string, std::function<void()>>> cases;
return cases;
}
inline void add_test_case(std::string name, std::function<void()> f)
{
get_test_cases().emplace_back(name, f);
}
struct auto_register
{
auto_register(std::string name, std::function<void()> f)
{
add_test_case(name, f);
}
};
inline void run_test_case(std::string name, std::function<void()> f)
{ {
T t = {}; std::cout << "[ RUN ] " << name << std::endl;
t.run(); f();
std::cout << "[ COMPLETE ] " << name << std::endl;
}
inline void run(int argc, const char* argv[])
{
std::vector<std::string> as(argv + 1, argv + argc);
auto args = parse(as, [](auto&&) -> std::vector<std::string> {
return {};
});
auto cases = args[""];
if(cases.empty())
{
for(auto&& tc:get_test_cases())
run_test_case(tc.first, tc.second);
}
else
{
std::unordered_map<std::string, std::function<void()>> m(get_test_cases().begin(), get_test_cases().end());
for(auto&& name:cases)
run_test_case(name, m[name]);
}
} }
} // namespace test } // namespace test
...@@ -179,4 +245,14 @@ void run_test() ...@@ -179,4 +245,14 @@ void run_test()
// NOLINTNEXTLINE // NOLINTNEXTLINE
#define STATUS(...) EXPECT((__VA_ARGS__) == 0) #define STATUS(...) EXPECT((__VA_ARGS__) == 0)
#define TEST_CASE(...) \
void __VA_ARGS__ (); \
static test::auto_register __VA_ARGS__ ## _register = test::auto_register(#__VA_ARGS__, &__VA_ARGS__); \
void __VA_ARGS__ ()
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wglobal-constructors"
#endif
#endif #endif
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <string> #include <string>
#include "test.hpp" #include "test.hpp"
void literal_test() TEST_CASE(literal_test)
{ {
EXPECT(migraph::literal{1} == migraph::literal{1}); EXPECT(migraph::literal{1} == migraph::literal{1});
EXPECT(migraph::literal{1} != migraph::literal{2}); EXPECT(migraph::literal{1} != migraph::literal{2});
...@@ -25,7 +25,7 @@ void literal_test() ...@@ -25,7 +25,7 @@ void literal_test()
EXPECT(l4.empty()); EXPECT(l4.empty());
} }
void literal_os1() TEST_CASE(literal_os1)
{ {
migraph::literal l{1}; migraph::literal l{1};
std::stringstream ss; std::stringstream ss;
...@@ -33,7 +33,7 @@ void literal_os1() ...@@ -33,7 +33,7 @@ void literal_os1()
EXPECT(ss.str() == "1"); EXPECT(ss.str() == "1");
} }
void literal_os2() TEST_CASE(literal_os2)
{ {
migraph::literal l{}; migraph::literal l{};
std::stringstream ss; std::stringstream ss;
...@@ -41,7 +41,7 @@ void literal_os2() ...@@ -41,7 +41,7 @@ void literal_os2()
EXPECT(ss.str().empty()); EXPECT(ss.str().empty());
} }
void literal_os3() TEST_CASE(literal_os3)
{ {
migraph::shape s{migraph::shape::int64_type, {3}}; migraph::shape s{migraph::shape::int64_type, {3}};
migraph::literal l{s, {1, 2, 3}}; migraph::literal l{s, {1, 2, 3}};
...@@ -50,9 +50,11 @@ void literal_os3() ...@@ -50,9 +50,11 @@ void literal_os3()
EXPECT(ss.str() == "1, 2, 3"); EXPECT(ss.str() == "1, 2, 3");
} }
int main() int main(int argc, const char* argv[]) { test::run(argc, argv); }
{
literal_test(); // int main()
literal_os1(); // {
literal_os2(); // literal_test();
} // literal_os1();
// literal_os2();
// }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment