While TVM supports a unit test infrastructure backed by gtest for compiler constructs, there is no such unit test infrastructure for the TVM runtime.
This leaves TVM runtime developers with poor choices when it comes to testing. In most cases, developers rely on integration tests using pytest. The downside of this approach is the need for a “full stack” (e.g. codegen) support prior to testing and difficulty in testing corner cases in the runtime code.
This discussion topic proposes a TVM runtime unit test infrastructure backed by gtest. The idea is to use a packed function (rather that gtest_main) to execute all registered tests as follows:
src/runtime/my_runtime/tests/my_runtime_tests.cc
#include "gtest/gtest.h"
TEST(MyRuntimeClass, answer_to_everything) {
MyRuntimeClass x;
ASSERT_EQ(x.GetAnswer(), 42);
}
TVM_REGISTER_GLOBAL("MyRuntime.run_all_tests").set_body([](TVMArgs args, TVMRetValue* rv) {
*rv = RUN_ALL_TESTS();
});
This packed function could be executed through device specific runtime using pytest as follows, using Hexagon as an example:
@requires_hexagon_toolchain
def test_remote_call(hexagon_session):
func = hexagon_session._rpc.get_function("hexagon.run_all_tests")
func()
This change will require linking the TVM runtime to gtest, or similar solution.