This is an archive of the discontinued LLVM Phabricator instance.

[lit] Fix discovery test on Windows
AbandonedPublic

Authored by modocache on Dec 13 2016, 12:22 AM.

Details

Summary

Many lit tests fail when run on Windows, because file path
separators are hard-coded as '/', whereas on Windows they're '\'.

Fix one such test, discovery.py, by using FileCheck variables.
As far as I understood, FileCheck does not contain a built-in variable
that matches '/' or '\', so I do this manually.

An alternative approach would be to add such a variable to FileCheck,
but for now this approach seemed less intrusive.

Event Timeline

modocache updated this revision to Diff 81191.Dec 13 2016, 12:22 AM
modocache retitled this revision from to [lit] Fix discovery test on Windows.
modocache updated this object.
modocache added a subscriber: llvm-commits.
modocache planned changes to this revision.Dec 13 2016, 9:25 AM

@ddunbar suggested that this might be better addressed in the lit config logic. I'll try that.

modocache requested a review of this revision.Dec 13 2016, 8:10 PM

Actually, I'm not sure this can be fixed in LitConfig.py. I could force the lit output to always use Unix path separators, even on Windows, but that would be inconvenient for Windows developers that want to copy and paste the paths.

Still, matching SEP like this is gross. Do any reviewers feel strongly about this? Would it be better if I added a way to match path separators to FileCheck itself?

delcypher edited edge metadata.Dec 18 2016, 2:27 AM

Actually, I'm not sure this can be fixed in LitConfig.py. I could force the lit output to always use Unix path separators, even on Windows, but that would be inconvenient for Windows developers that want to copy and paste the paths.

Still, matching SEP like this is gross. Do any reviewers feel strongly about this? Would it be better if I added a way to match path separators to FileCheck itself?

If it's possible I would prefer always using Unix path separators. / is supported as a path separator on Windows (in some cases) . E.g. in cmd.exe I can type

C:\> cd c:/Users/foo
c:\Users\foo>

and the command works correctly. It doesn't always work however so we need to test if lit would perform as expected in the "copy and paste test paths" scenario.

That makes sense, thanks for the feedback @delcypher.

Is there a strong reason you'd prefer / in all cases, though?

I ask because it seems more correct to output paths using each platform's native path separators. Yes, we could modify the logic in LitConfig.py to use "/".join() instead of os.path.join(), and replace \ with / in the paths we output, but that seems like additional complexity for what is, in my opinion, marginal benefit. True, this particular test is uglier because of the difference in path separators, but this and D27908 are the only two tests that need to be modified for this reason. So personally, I think it makes more sense to change the tests, than it does to change lit's behavior.

Thoughts?

That makes sense, thanks for the feedback @delcypher.

Is there a strong reason you'd prefer / in all cases, though?

Simplicity. Although I should also note I am incredibly biased (I have an extreme dislike of Windows) so my opinion on how we should handle Lit's behaviour on Windows should be taken with a grain of salt.

I ask because it seems more correct to output paths using each platform's native path separators. Yes, we could modify the logic in LitConfig.py to use "/".join() instead of os.path.join(), and replace \ with / in the paths we output, but that seems like additional complexity for what is, in my opinion, marginal benefit. True, this particular test is uglier because of the difference in path separators, but this and D27908 are the only two tests that need to be modified for this reason. So personally, I think it makes more sense to change the tests, than it does to change lit's behavior.

Thoughts?

I agree that is more correct (and expected) to use the platform's native path separator, at least from a user perspective. The problem with the changes here though is the test now allows previously forbidden behaviour: We could emit the wrong slashes for the platform (i.e. \ on UNIX like systems and / on Windows) and the test would still pass. I wonder if there is a way we could use lit's ${path_sep} substitution to help us here? I can't see an obvious way to do it because it needs to appear in a RUN: line and would somehow need to be given to FileCheck.

Anyway I feel like I might be holding back progress here. I think it would be better to get all the tests passing so we can run under Windows so we can turn on the build bots and then try to figure out how to improve the tests. If you feel the same way and are happy to look into fixing up the tests after we get the build bots up then I'll be happy to approve this patch and the others that get the tests working under Windows.

@delcypher Sorry for the incredibly late reply to your comment here. You mentioned:

I think it would be better to get all the tests passing so we can run under Windows so we can turn on the build bots and then try to figure out how to improve the tests. If you feel the same way and are happy to look into fixing up the tests after we get the build bots up then I'll be happy to approve this patch and the others that get the tests working under Windows.

What would you think of, instead of fixing all of the Windows tests first, we mark them as XFAIL: windows? That way, we could un-revert rL257221, which makes it much easier to run the lit tests in the first place, and then we can take our time fixing the Windows tests. This would be my preferred order, since debugging some of these WIndows test failures is a pain.

In any case, your reviews certainly weren't holding back progress! On the contrary, I'm sorry I got sidetracked. I'd love to add a check-lit CMake target, and if getting the tests to pass on Windows is a prerequisite for that, I can devote some time to doing so in the next few weeks.

beanz edited edge metadata.Jul 7 2017, 11:13 AM

I think it is better to XFAIL Windows and have test coverage on non-windows systems than to have the tests not running anywhere.

If you XFAIL them though please file a bug on bugzilla, and comment with the bug in the tests near the XFAIL line to make it easier to track.

Awesome, thanks for the suggestion @beanz!

modocache abandoned this revision.Jul 27 2017, 7:48 AM
modocache added a subscriber: rnk.

The equivalent of this change was committed by @rnk in rL309194. I sort of prefer this because it verifies the same separator is used throughout, instead of accepting either. But either way works for me!

rnk added a comment.Jul 27 2017, 10:03 AM

That makes sense, thanks for the feedback @delcypher.

Is there a strong reason you'd prefer / in all cases, though?

I ask because it seems more correct to output paths using each platform's native path separators. Yes, we could modify the logic in LitConfig.py to use "/".join() instead of os.path.join(), and replace \ with / in the paths we output, but that seems like additional complexity for what is, in my opinion, marginal benefit. True, this particular test is uglier because of the difference in path separators, but this and D27908 are the only two tests that need to be modified for this reason. So personally, I think it makes more sense to change the tests, than it does to change lit's behavior.

Thoughts?

I'd be in favor of always using forward slashes in lit output, personally. I just went ahead and committed that to try to get the tests green again. There are fewer and fewer utilities that don't understand forward slashes.