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

1 Like

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 https://github.com/llvm/llvm-project/blob/main/mlir/test/lit.cfg.py#L72.

1 Like

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!

2 Likes

Hi all, running the mlir binding tests gives me an UNSUPPORTED error message. verbose flag doesn’t provide any further information. Here is the command I run and it’s output:

build/bin/llvm-lit -v mlir/test/python/pass_manager.py
-- Testing: 1 tests, 1 workers --
UNSUPPORTED: MLIR :: python/pass_manager.py (1 of 1)

Testing Time: 0.10s
  Unsupported: 1

Does anyone know what causes this and how to fix it?

I suspect you don’t have the bindings enabled? See: MLIR Python Bindings - MLIR

1 Like

that did it, thank you!