Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
9b3bc656
Commit
9b3bc656
authored
Nov 06, 2018
by
Paul
Browse files
Add initial test driver
parent
c0bcc6fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
14 deletions
+92
-14
test/include/test.hpp
test/include/test.hpp
+80
-4
test/literal_test.cpp
test/literal_test.cpp
+12
-10
No files found.
test/include/test.hpp
View file @
9b3bc656
...
...
@@ -3,6 +3,8 @@
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <unordered_map>
#include <vector>
#ifndef MIGRAPH_GUARD_TEST_TEST_HPP
#define MIGRAPH_GUARD_TEST_TEST_HPP
...
...
@@ -154,11 +156,75 @@ bool throws(F f, const std::string& msg = "")
}
}
template
<
class
T
>
void
run_test
()
using
string_map
=
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
string
>>
;
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
=
{};
t
.
run
();
std
::
cout
<<
"[ RUN ] "
<<
name
<<
std
::
endl
;
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
...
...
@@ -179,4 +245,14 @@ void run_test()
// NOLINTNEXTLINE
#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
test/literal_test.cpp
View file @
9b3bc656
...
...
@@ -4,7 +4,7 @@
#include <string>
#include "test.hpp"
void
literal_test
(
)
TEST_CASE
(
literal_test
)
{
EXPECT
(
migraph
::
literal
{
1
}
==
migraph
::
literal
{
1
});
EXPECT
(
migraph
::
literal
{
1
}
!=
migraph
::
literal
{
2
});
...
...
@@ -25,7 +25,7 @@ void literal_test()
EXPECT
(
l4
.
empty
());
}
void
literal_os1
(
)
TEST_CASE
(
literal_os1
)
{
migraph
::
literal
l
{
1
};
std
::
stringstream
ss
;
...
...
@@ -33,7 +33,7 @@ void literal_os1()
EXPECT
(
ss
.
str
()
==
"1"
);
}
void
literal_os2
(
)
TEST_CASE
(
literal_os2
)
{
migraph
::
literal
l
{};
std
::
stringstream
ss
;
...
...
@@ -41,7 +41,7 @@ void literal_os2()
EXPECT
(
ss
.
str
().
empty
());
}
void
literal_os3
(
)
TEST_CASE
(
literal_os3
)
{
migraph
::
shape
s
{
migraph
::
shape
::
int64_type
,
{
3
}};
migraph
::
literal
l
{
s
,
{
1
,
2
,
3
}};
...
...
@@ -50,9 +50,11 @@ void literal_os3()
EXPECT
(
ss
.
str
()
==
"1, 2, 3"
);
}
int
main
()
{
literal_test
();
literal_os1
();
literal_os2
();
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
// int main()
// {
// literal_test();
// literal_os1();
// literal_os2();
// }
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment