I’d like to do some unit test with MLIR .
use Catch2 in MLIR
someOp->print(os);
REQUIRE( Os.str == SomeAsm );
But when i try to do this:
mlir::MLIRContext context;
mlir::OpBuilder builder(&context);
auto theModule = mlir::ModuleOp::create(builder.getUnknownLoc());
theModule.push_back(builder.create<FooOp>(loc()));
Context is empty, Cuz I just want to instantiate A single Op class.
I get
SIGABRT - Abort (abnormal termination) signal
Is there any function I can use?
Building with assert enabled would probably produce a nicer error here, I’d recommend that while developing. Instead of just suggesting a solution, what error do you get on which line if you test in a debug build? (llvm-project/OperationSupportTest.cpp at main · llvm/llvm-project · GitHub is a little bit lower level and testing something else, but could also be useful)
1 Like
In general if you have a SIGABRT it is because of an assertions failure, isn’t there a message before that? If assertions are enabled, you’ll first hit the fact that you haven’t loaded the dialect for FooOp
in the Context, you can make it work by calling context.allowUnregisteredDialects();
.
Nothing before that SIGABRT.
I added this call
mlir::MLIRContext context;
context.getOrLoadDialect<mlir::toy::ToyDialect>();
SIGABRT is still there.
Which OS are you running on?
Also can you run this in a debugger and report a backtrace? (if you can build in Debug build that’d help I think).
Ubuntu 16.04 and Clang++12
#0 0x00007ffff66d1438 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1 0x00007ffff66d303a in __GI_abort () at abort.c:89
#2 0x0000000000538996 in llvm::report_fatal_error(llvm::Twine const&, bool) ()
#3 0x0000000000538afe in llvm::report_fatal_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) ()
#4 0x0000000000414fd9 in mlir::OpBuilder::create<mlir::toy::FooOp> (this=0x7fffffffcc98, location=...)
at llvm-project/mlir/include/mlir/IR/Builders.h:399
#5 0x0000000000414946 in ::____C_A_T_C_H____T_E_S_T__ () at mlir_dialect_test.cpp:34
when I debug again, I get a Message,
“LLVM ERROR: Building op toy. foo
but it isn’t registered in this MLIRContext”.
It is the first time I get this message.
I think Catch2 hooks the error message, It is an odd behave.
That’s what I was expecting before 
At least now you know what the issue is!
I don’t know what Cactch2
, but these errors are emitted on stderr in general: llvm-project/ErrorHandling.cpp at main · llvm/llvm-project · GitHub
Thanks a lot. And I registered Toy like
context.getOrLoadDialect<mlir::toy::ToyDialect>()
I still get
LLVM ERROR: Building op toy. foo
but it isn’t registered in this MLIRContext
Is the toy dialect registering this operation though?
1 Like
Registered. I rewrite context and register the toy dialect, IT WORKS!
And It finally solved.
Thx all of you.
Thx for all your answers! It’s was helpful, i have made it! :X
2 Likes