hexdump in test cases?

For lld to mimic the darwin linker it needs to support an option that dumps a binary file which contains a list of the input and output files. This file is used by Xcode to dynamically update its dependency graph.

I’m a bit stumped on how to test this. Some ideas I have:

* Use REQUIRES: shell, then run hexdump and FileCheck that (is hexdump output consistent on all *nix platforms?)

* Use REQUIRES: shell, then run sed or perl to format the file with lines and opcode values and FileCheck that (is sed/perl on all platforms?)

* Since lit uses Python, it seems like I should be able to use python to transform the file into something FileCheck can process. But I don’t know how to invoke python from a RUN: line in a cross platform way.

* Add a C tool to llvm that dumps out a dependency file in a human and FileCheck readable way. Seems like overkill to add a directory to llvm/tools/ that contains a tool only useful for dumping a Xcode file. Comparing the file bytes is all I really need.

* Write an llvm-hexdump tool in llvm/tools/ and use that in my test case.

Thoughts?

-Nick

For lld to mimic the darwin linker it needs to support an option that
dumps a binary file which contains a list of the input and output files.
This file is used by Xcode to dynamically update its dependency graph.

I’m a bit stumped on how to test this. Some ideas I have:

* Use REQUIRES: shell, then run hexdump and FileCheck that (is hexdump
output consistent on all *nix platforms?)

I doubt that hexdump output is consistent across all Unix systems.

* Use REQUIRES: shell, then run sed or perl to format the file with lines
and opcode values and FileCheck that (is sed/perl on all platforms?)

* Since lit uses Python, it seems like I should be able to use python to
transform the file into something FileCheck can process. But I don’t know
how to invoke python from a RUN: line in a cross platform way.

I don't see any reason to use Perl, because it may not be available on some
platforms, and Perl and Python are mostly functionally equivalent.

I'd do with Python. I'd write a binary-to-text converter as a Python
script, put it into test/ directory, and then let lit to run the script by
appending a magic comment to the script like this:

  # RUN: lld -flavor darwin -output %t.binary ...
  # python %s %t.binary | FileCheck %s

I know how to make this work on unix based systems. But, will adding:

RUN: python %s/path/to/hexdump.py %t

work on Windows? The lit infrastructure does a lot to make the RUN lines work like a very limited shell even on Windows.

-Nick

I didn't actually tried that myself yet, but there are files that contains
'RUN: python' in llvm test directory.