iree-org / iree

A retargetable MLIR-based machine learning compiler and runtime toolkit.
http://iree.dev/
Apache License 2.0
2.85k stars 620 forks source link

[compiler] Restructure unittests for iree/compiler. #19237

Closed hanhanW closed 17 hours ago

hanhanW commented 1 day ago

According to googletest primer, most users should not need to write their own main function and instead link with gtest_main (as opposed to with gtest), which defines a suitable entry point. The revision implements a main testing function for all the unittests under iree/compiler/. See https://google.github.io/googletest/primer.html#writing-the-main-function for more details.

IREE has few unit tests in comiler/. Similar to runtime/, the revision creates a gtest_main.cc which defines the main function. Thus, all the unit tests no longer need to define their own main function.

Inlining LLVM unit test guide to distinguish what is expected to test with unit tests:

In general unit tests are reserved for targeting the support library and other generic data structure, we prefer relying on regression tests for testing transformations and analysis on the IR.

Note: it is not shared with the runtime one because the runtime/compiler tests should not depend on each other. A potential refactoring is moving them to iree/testing/* and all the unit tests can depend on it.

hanhanW commented 1 day ago

In this PR, we have two unit test files locating at different directories:

I think we could put them under the same "unittests" directory, so it could be:

What do you think?

hanhanW commented 18 hours ago

Okay, I'm going to land the change and unblock my work, because it looks like an improvement to me. I'm happy to address any post-commits.

ScottTodd commented 18 hours ago

Note: it is not shared with the runtime one because the runtime/compiler tests should not depend on each other. A potential refactoring is moving them to iree/testing/* and all the unit tests can depend on it.

We can keep them separate. It isn't much code to duplicate.