1 #include <iostream>
2
3 #include "HalideRuntime.h"
4 #include "RunGen.h"
5
6 #include "example.h"
7
8 using namespace Halide::RunGen;
9 using namespace Halide::Runtime;
10
check(bool b,const char * msg="Failure!")11 void check(bool b, const char *msg = "Failure!") {
12 if (!b) {
13 std::cerr << msg << "\n";
14 exit(1);
15 }
16 }
17
halide_register_argv_and_metadata(int (* filter_argv_call)(void **),const struct halide_filter_metadata_t * filter_metadata,const char * const * extra_key_value_pairs)18 extern "C" void halide_register_argv_and_metadata(
19 int (*filter_argv_call)(void **),
20 const struct halide_filter_metadata_t *filter_metadata,
21 const char *const *extra_key_value_pairs) {
22
23 check(filter_argv_call == example_argv);
24 check(filter_metadata == example_metadata());
25 check(extra_key_value_pairs == nullptr);
26 }
27
28 namespace {
29
30 std::ostream *capture_cout = nullptr;
31 std::ostream *capture_cerr = nullptr;
32
33 bool log_info = false;
34 bool log_warn = true;
35
do_log_cout(const std::string & s)36 void do_log_cout(const std::string &s) {
37 *capture_cout << s;
38 }
39
do_log_cerr(const std::string & s)40 void do_log_cerr(const std::string &s) {
41 *capture_cerr << s;
42 }
43
do_log_info(const std::string & s)44 void do_log_info(const std::string &s) {
45 if (log_info) {
46 do_log_cerr(s);
47 }
48 }
49
do_log_warn(const std::string & s)50 void do_log_warn(const std::string &s) {
51 if (log_warn) {
52 do_log_cerr("Warning: " + s);
53 }
54 }
55
do_log_fail(const std::string & s)56 void do_log_fail(const std::string &s) {
57 do_log_cerr(s);
58 abort();
59 }
60
61 } // namespace
62
63 namespace Halide {
64 namespace RunGen {
65
log()66 Logger log() {
67 return {do_log_cout, do_log_info, do_log_warn, do_log_fail};
68 }
69
70 } // namespace RunGen
71 } // namespace Halide
72
main(int argc,char ** argv)73 int main(int argc, char **argv) {
74 RunGen r(example_argv, example_metadata());
75
76 check(r.get_halide_argv_call() == example_argv);
77 check(r.get_halide_metadata() == example_metadata());
78
79 {
80 std::ostringstream out, err;
81 capture_cout = &out;
82 capture_cerr = &err;
83
84 r.describe();
85
86 check(err.str() == "");
87
88 const char *expected_out = R"DESC(Filter name: "example"
89 Input "runtime_factor" is of type float32
90 Output "output" is of type Buffer<int32> with 3 dimensions
91 )DESC";
92 check(out.str() == expected_out);
93 }
94
95 // TODO: add more here; all this does is verify that we can instantiate correctly
96 // and that 'describe' parses the metadata as expected.
97
98 std::cout << "Success!\n";
99 return 0;
100 }
101