Page MenuHomePhabricator

PPCallbacksTest expansion - part 1

Authored by jtsoftware on Oct 17 2013, 4:12 PM.



This patch implements a test mechanism for the PPCallbacks mechanism that I've added to the existing tests. It's based on creating a derivation of PPCallbacks that records information passed to each callback in a high-level string format, for later comparison against an array of expected patterns. It allows testing of both the callback order as well as the callback argument content.

This patch provides the basic mechanism, but only implements two new test functions using it, for just the macro-based and conditional-based callbacks, as a proof of concept. If you approve this basic mechanism, I will add additional tests covering other callbacks and situations in subsequent patches.

Diff Detail

Event Timeline

Turning the preprocessor decisions into a serialized textual format is a great idea!

Though this seems like it would be better done as an independent tool. I.e. one that reads its file on stdin (or as an argument) and prints out this information, for use in conjunction with FileCheck. That would allow idiomatic LLVM FileCheck testing similar to:

; RUN: opt < %s -sroa -S | FileCheck %s

(that was from llvm/test/Transforms/SROA/basictest.ll but there are innumerable other examples).

so the usage would be something like:

; RUN: pp-trace < %s | FileCheck %s

That would also completely offload the burden of the pattern matching/specification to FileCheck, and integrate with developers' existing familiarity with FileCheck.

Also, I'm not a huge fan of this ad-hoc serialization. Could you please use YAMLIO and have the output be YAML? YAMLIO is really simple to use once you get the hang of it. Look at LLVM's r183711 for a pretty minimal example; the code there only uses it for input, but YAMLIO is inherently bidirectional so output is just a matter of using << rather than >>. Feel free to ask me questions too.

YAML output would be *amazing*, since then it would be possible to write ad-hoc simple tools in any language (I'm thinking in particular scripting languages), for e.g. quickly checking assumptions, scoping out the prevalence of a particular pattern, etc.. Many languages have YAML parsers, and turning YAML into equivalent JSON is like a 10-line Python program, and then every language can access it.

kimgr added a comment.Oct 18 2013, 7:32 AM

I don't know my way around FileCheck, so I can't spek to the benefit for testing (it sounds nice, though), but a standalone tool would be useful for learning and troubleshooting, PPCallbacks just like -ast-dump is for AST traversals. I literally started writing one a few nights ago, but I never have enough free time to finish anything :-/

I would appreciate it, is what I'm trying to say.

Sean, John,

jtsoftware abandoned this revision.May 5 2014, 6:22 PM

I created the tool pptrace as a basis for doing these kinds of tests instead.