How to run bindings test

Hi there,

Reading through the MLIR bindings and the following FileCheck test exists

# RUN: %PYTHON %s | mlir-opt -split-input-file | FileCheck

# TODO: Move to a test utility class once any of this actually exists.
def print_module(f):
  m = f()
  print("// -----")
  print("// TEST_FUNCTION:", f.__name__)
  print(m.to_asm())
  return f

# CHECK-LABEL: TEST_FUNCTION: create_my_op
@print_module
def create_my_op():
  m = mlir.ir.Module()
  builder = m.new_op_builder()
  # CHECK: mydialect.my_operation ...
  builder.my_op()
  return m

How do I go about running this? I tried just running the section at the start (%PYTHON %s | mlir-opt -split-input-file | FileCheck), but get

$ %PYTHON %s | mlir-opt -split-input-file | FileCheck
<check-file> not specified
%PYTHON: command not found

Thanks

Use llvm-lit. For example, $LLVM_DIR/build/bin/llvm-lit mlir/test/python/pass_manager.py. It performs the substitution of %PYTHON according to the configuration that you can find in llvm-project/lit.cfg.py at main · llvm/llvm-project · GitHub.

That’s super helpful thank you!

I ran the example syntax you mentioned above, however the test fails:

-- Testing: 1 tests, 1 workers --
FAIL: MLIR :: python/pass_manager.py (1 of 1)
********************
Failed Tests (1):
  MLIR :: python/pass_manager.py


Testing Time: 0.58s
  Failed: 1

Any ideas why?

Never mind, running the test with -v to show a larger description of the error fixed it:)

Thanks for your help!

1 Like