validate.cpp 1.4 KB
Newer Older
Paul's avatar
Paul committed
1
#include <migraph/program.hpp>
Paul's avatar
Paul committed
2
#include <migraph/instruction.hpp>
Paul's avatar
Paul committed
3
4
#include <basic_ops.hpp>
#include <test.hpp>
5
#include <rob.hpp>
Paul's avatar
Paul committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

void simple_test()
{
    migraph::program p;

    auto one = p.add_literal(1);
    auto two = p.add_literal(2);
    p.add_instruction(sum_op{}, one, two);
    EXPECT(bool{p.validate() == p.end()});
    auto result = p.eval({});
    EXPECT(result == migraph::literal{3});
    EXPECT(result != migraph::literal{4});
}

void out_of_order()
{
    migraph::program p;

    auto one = p.add_literal(1);
    auto two = p.add_literal(2);
    auto ins = p.add_instruction(sum_op{}, one, two);
    p.move_instruction(two, p.end());
    EXPECT(bool{p.validate() == ins});
}

Paul's avatar
Paul committed
31
32
33
34
35
36
37
38
39
40
41
void incomplete_args()
{
    migraph::program p;

    auto one = p.add_literal(1);
    auto two = p.add_literal(2);
    auto ins = p.add_instruction(sum_op{}, one, two);
    ins->clear_arguments();
    EXPECT(bool{p.validate() == ins});
}

Paul's avatar
Paul committed
42
43
44
45
MIGRAPH_ROB(access_ins_arguments,
            std::vector<migraph::instruction_ref>,
            migraph::instruction,
            arguments)
46

Paul's avatar
Paul committed
47
48
49
50
51
52
53
void invalid_args()
{
    migraph::program p;

    auto one = p.add_literal(1);
    auto two = p.add_literal(2);
    auto ins = p.add_instruction(sum_op{}, one, two);
54
    access_ins_arguments(*ins).clear();
Paul's avatar
Paul committed
55
56
57
    EXPECT(bool{p.validate() == p.begin()});
}

Paul's avatar
Paul committed
58
59
int main()
{
Paul's avatar
Paul committed
60
61
    simple_test();
    out_of_order();
Paul's avatar
Paul committed
62
63
    incomplete_args();
    invalid_args();
Paul's avatar
Paul committed
64
}