annotate mlir/test/APITest.h @ 180:680fa57a2f20

fix compile errors.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 30 May 2020 17:44:06 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===- Test.h - Simple macros for API unit tests ----------------*- C++ -*-===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8 //
anatofuz
parents:
diff changeset
9 // This file define simple macros for declaring test functions and running them.
anatofuz
parents:
diff changeset
10 // The actual checking must be performed on the outputs with FileCheck.
anatofuz
parents:
diff changeset
11 //
anatofuz
parents:
diff changeset
12 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 #ifndef MLIR_TEST_TEST_H_
anatofuz
parents:
diff changeset
15 #define MLIR_TEST_TEST_H_
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 #include <functional>
anatofuz
parents:
diff changeset
18 #include <vector>
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 namespace test_detail {
anatofuz
parents:
diff changeset
21 // Returns a mutable list of known test functions. Used internally by test
anatofuz
parents:
diff changeset
22 // macros to add and run tests. This function is static to ensure it creates a
anatofuz
parents:
diff changeset
23 // new list in each test file.
anatofuz
parents:
diff changeset
24 static std::vector<std::function<void()>> &tests() {
anatofuz
parents:
diff changeset
25 static std::vector<std::function<void()>> list;
anatofuz
parents:
diff changeset
26 return list;
anatofuz
parents:
diff changeset
27 }
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 // Test registration class. Used internally by test macros to register tests
anatofuz
parents:
diff changeset
30 // during static allocation.
anatofuz
parents:
diff changeset
31 struct TestRegistration {
anatofuz
parents:
diff changeset
32 explicit TestRegistration(std::function<void()> func) {
anatofuz
parents:
diff changeset
33 test_detail::tests().push_back(func);
anatofuz
parents:
diff changeset
34 }
anatofuz
parents:
diff changeset
35 };
anatofuz
parents:
diff changeset
36 } // end namespace test_detail
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 /// Declares a test function with the given name and adds it to the list of
anatofuz
parents:
diff changeset
39 /// known tests. The body of the function must follow immediately. Example:
anatofuz
parents:
diff changeset
40 ///
anatofuz
parents:
diff changeset
41 /// TEST_FUNC(mytest) {
anatofuz
parents:
diff changeset
42 /// // CHECK: expected-output-here
anatofuz
parents:
diff changeset
43 /// emitSomethingToStdOut();
anatofuz
parents:
diff changeset
44 /// }
anatofuz
parents:
diff changeset
45 ///
anatofuz
parents:
diff changeset
46 #define TEST_FUNC(name) \
anatofuz
parents:
diff changeset
47 void name(); \
anatofuz
parents:
diff changeset
48 static test_detail::TestRegistration name##Registration(name); \
anatofuz
parents:
diff changeset
49 void name()
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 /// Runs all registered tests. Example:
anatofuz
parents:
diff changeset
52 ///
anatofuz
parents:
diff changeset
53 /// int main() {
anatofuz
parents:
diff changeset
54 /// RUN_TESTS();
anatofuz
parents:
diff changeset
55 /// return 0;
anatofuz
parents:
diff changeset
56 /// }
anatofuz
parents:
diff changeset
57 #define RUN_TESTS \
anatofuz
parents:
diff changeset
58 []() { \
anatofuz
parents:
diff changeset
59 for (auto f : test_detail::tests()) \
anatofuz
parents:
diff changeset
60 f(); \
anatofuz
parents:
diff changeset
61 }
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 #endif // MLIR_TEST_TEST_H_