This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] [test] Fix dsl.sh.py to work on Windows.
AbandonedPublic

Authored by mstorsjo on Feb 25 2022, 1:25 AM.

Details

Reviewers
Quuxplusone
ldionne
Mordante
Group Reviewers
Restricted Project
Summary

Convert CRLF to LF in the output of tested commands. D120623 fixes the same issue differently.

Diff Detail

Event Timeline

mstorsjo created this revision.Feb 25 2022, 1:25 AM
mstorsjo requested review of this revision.Feb 25 2022, 1:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 25 2022, 1:25 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
libcxx/test/libcxx/selftest/dsl/dsl.sh.py
252–253

Please remove the comment, and just mention it (including that URL) in the commit message.

libcxx/utils/libcxx/test/dsl.py
178–180

I'm mildly confused how the re.search on line 174 could ever succeed, if out always contains \r\n in place of \n. Patterns treat \n as magic, maybe?
If we were trying to deal with \r\n in generated files, we'd do, like,

with open(out_path, 'w', newline='\n') as f:
                         ^^^^^^^^^^^^

I'd like (you) to explore whether we can similarly push the \r\n handling all the way down into the library layer here. Should we delegate the \r\n handling down into _executeScriptInternal? Should we delegate it down into whatever _executeScriptInternal calls? Etc. Maybe it ultimately ends up that all we need to do is change subprocess.call(~~~) into subprocess.call(~~~, translateNewlines=True) or something; that would be awesome.

mstorsjo marked 2 inline comments as done.Feb 26 2022, 2:13 PM
mstorsjo added inline comments.
libcxx/test/libcxx/selftest/dsl/dsl.sh.py
252–253

Ok, will do.

libcxx/utils/libcxx/test/dsl.py
178–180

Yes, that's a bit strange - it'd clearly be better to move the newline fixup before that at least.

I tried moving the fix all the way into llvm/utils/lit/lit/TestRunner.py, into _executeShCmd, by adding universal_newlines=True to the call to subprocess.Popen(). That did indeed also solve the issue for this test, but that did instead break a handful of other tests - e.g. https://github.com/llvm/llvm-project/blob/main/llvm/test/MC/ELF/diff2.s, which runs a process which outputs binary data to stdout (where python fails to interpret the non-ascii chars as text).

So while I guess we should clean up such tests to not do that, I'm not sure if there's any other semi-legitimate case we might be breaking. But we can at least hoist the filtering up to within _executeScriptInternal, directly after the call to lit.TestRunner.executeScriptInternal.

mstorsjo updated this revision to Diff 411644.Feb 26 2022, 2:14 PM
mstorsjo marked 2 inline comments as done.

Removed the verbose bug workaround comment from the code, moved the CRLF filtering up to right after the call to lit.TestRunner.executeScriptInternal.

mstorsjo added inline comments.Feb 26 2022, 2:43 PM
libcxx/utils/libcxx/test/dsl.py
178–180

I posted D120623 as an alternative way of fixing this issue.

My understanding is that the forsurethisisnotanexistinglocale fix is pretty much orthogonal to the rest of this patch, and is uncontroversial. Feel free to land that one-liner (with explanatory commit message as discussed above).

I think what you've got here now (replace('\r\n', '\n') in _executeScriptInternal) is better than what you originally proposed. D120623 also looks reasonable to me (but affects tests that libc++ doesn't own, so make sure you've pinged some people relevant to those tests). However, I think both of these are going to need more eyeballs than mine.

mstorsjo updated this revision to Diff 411699.Feb 27 2022, 12:10 PM

Rebased, after committing acf20001a01119ce02d5f2b0282e5a7c966ca12c on its own. (No action needed here right now, awaiting verdict on D120623 first.)

mstorsjo edited the summary of this revision. (Show Details)Feb 27 2022, 12:12 PM
mstorsjo abandoned this revision.Mar 23 2022, 12:13 AM

Superseded by D120623.

Herald added a project: Restricted Project. · View Herald TranscriptMar 23 2022, 12:13 AM