"maint/gemm_v2/latency_mha_fwd_bhsd.py" did not exist on "354e9aff0aead49b2e57ac803765515f1f5091b5"
test.hpp 1.87 KB
Newer Older
Paul's avatar
Paul committed
1
2
3
4
5
6

#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>

Paul's avatar
Paul committed
7
#ifndef GUARD_TEST_TEST_HPP
Paul's avatar
Paul committed
8
#define RTG_GUARD_TEST_TEST_HPP
Paul's avatar
Paul committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

inline void failed(const char* msg, const char* file, int line)
{
    std::cout << "FAILED: " << msg << ": " << file << ": " << line << std::endl;
}

[[gnu::noreturn]] inline void failed_abort(const char* msg, const char* file, int line)
{
    failed(msg, file, line);
    std::abort();
}

template <class TLeft, class TRight>
inline void expect_equality(const TLeft& left,
                            const TRight& right,
                            const char* left_s,
                            const char* riglt_s,
                            const char* file,
                            int line)
{
    if(left == right)
        return;

    std::cout << "FAILED: " << left_s << "(" << left << ") == " << riglt_s << "(" << right
              << "): " << file << ':' << line << std::endl;
    std::abort();
}

Paul's avatar
Paul committed
37
// NOLINTNEXTLINE
Paul's avatar
Paul committed
38
39
40
#define CHECK(...)     \
    if(!(__VA_ARGS__)) \
    failed(#__VA_ARGS__, __FILE__, __LINE__)
Paul's avatar
Paul committed
41
// NOLINTNEXTLINE
Paul's avatar
Paul committed
42
43
44
#define EXPECT(...)    \
    if(!(__VA_ARGS__)) \
    failed_abort(#__VA_ARGS__, __FILE__, __LINE__)
Paul's avatar
Paul committed
45
// NOLINTNEXTLINE
Paul's avatar
Paul committed
46
#define EXPECT_EQUAL(LEFT, RIGHT) expect_equality(LEFT, RIGHT, #LEFT, #RIGHT, __FILE__, __LINE__)
Paul's avatar
Paul committed
47
// NOLINTNEXTLINE
Paul's avatar
Paul committed
48
49
#define STATUS(...) EXPECT((__VA_ARGS__) == 0)

Paul's avatar
Paul committed
50
// NOLINTNEXTLINE
Paul's avatar
Paul committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#define FAIL(...) failed(__VA_ARGS__, __FILE__, __LINE__)

template <class F>
bool throws(F f)
{
    try
    {
        f();
        return false;
    }
    catch(...)
    {
        return true;
    }
}

template <class F, class Exception>
bool throws(F f, std::string msg = "")
{
    try
    {
        f();
        return false;
    }
    catch(const Exception& ex)
    {
        return std::string(ex.what()).find(msg) != std::string::npos;
    }
}

template <class T>
void run_test()
{
    T t = {};
    t.run();
}

#endif