This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Use pseudo-terminal in LIT tests so color output from compiler error messages is captured.
AbandonedPublic

Authored by EricWF on Oct 27 2014, 6:43 PM.

Details

Summary

Change LibcxxTestFormat's execute_command method so it uses a pseudo-terminal when invoking the compiler commands. This means that clang will output color diagnostics and LIT will capture these diagnostics.

Diff Detail

Event Timeline

EricWF updated this revision to Diff 15513.Oct 27 2014, 6:43 PM
EricWF retitled this revision from to [libcxx] Use pseudo-terminal in LIT tests so color output from compiler error messages is captured..
EricWF updated this object.
EricWF edited the test plan for this revision. (Show Details)
EricWF added a subscriber: Unknown Object (MLST).
ddunbar edited edge metadata.Oct 27 2014, 6:47 PM

But what if Lit isn't running in a device capable of color output? Won't
this add a bunch of ugly ASCII codes?

I think what tools like Ninja do is to also optionally strip the color
codes in that case (
https://github.com/martine/ninja/blob/master/src/util.cc#L384).

  • Daniel

But what if Lit isn't running in a device capable of color output? Won't
this add a bunch of ugly ASCII codes?

Wouldn't clang refrain from outputting color codes to begin with?
Do you know of any way to detect this?

I think what tools like Ninja do is to also optionally strip the color
codes in that case (
https://github.com/martine/ninja/blob/master/src/util.cc#L384).

Not much you can do about that. At least the colored output makes it one step further.

Thanks for the input.

Bearing in mind this isn't a domain I know much about...

EricWF updated this revision to Diff 15514.Oct 27 2014, 8:00 PM
EricWF edited edge metadata.

Only use pseudo-terminal if sys.stdout.isatty() is true. Otherwise fall back to the old method.

silvas added a subscriber: silvas.Oct 27 2014, 8:07 PM

FWIW, Ninja found that it wasn't tenable to use this approach. Some discussion here: https://github.com/martine/ninja/issues/174

Not sure if any of the concerns apply to lit.

In D6010#9, @silvas wrote:

FWIW, Ninja found that it wasn't tenable to use this approach. Some discussion here: https://github.com/martine/ninja/issues/174

Not sure if any of the concerns apply to lit.

Their main concern was that providing a pseudo-terminal might confuse some commands like SVN it if tries to spin up an editor.
Since we know exactly what types of command will be run this isn't a concern.

Thanks for the input.

Ok, so on the structure of the patch:

  1. It would be nice if this functionality wasn't in the Libcxx test format,

but a utility that was part of lit proper.

  1. This: --

+ out = LibcxxTestFormat._read_and_close_pty(out_pty)

+ err = LibcxxTestFormat._read_and_close_pty(err_pty)

is not safe, if a command writes enough output to stderr that the pipe is
full it will block, and then the system will be deadlocked since it will
never finish writing to stdout. Also, you probably shouldn't assume that
all data is returned in a single .read() call (even though that is likely
true). See notes in subprocess module, e.g.,
https://docs.python.org/2/library/subprocess.html#subprocess.Popen.communicate
.

  • Daniel
EricWF abandoned this revision.Nov 6 2014, 11:44 AM

I'm abandoning this revision because I'm going to try and put this functionality in LIT proper. I have a working implementation that addresses @ddunbar's concerns that I will submit next week.