This is an archive of the discontinued LLVM Phabricator instance.

[test] Add lit helper for windows paths
ClosedPublic

Authored by keith on Oct 8 2021, 12:09 PM.

Details

Summary

This adds 2 new lit helpers %{fsroot} and %{fssep}, these allow
writing tests that correctly handle slashes on Windows. In the case of
tests like clang/test/CodeGen/debug-prefix-map.c, these are unable to
correctly test behavior on both platforms, unless they fork and add OS
requirements, because the relevant logic hits host specific codepaths
like checking if paths are absolute.

Diff Detail

Event Timeline

keith requested review of this revision.Oct 8 2021, 12:09 PM
keith created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptOct 8 2021, 12:09 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rmaz added inline comments.Oct 8 2021, 2:19 PM
clang/test/lit.cfg.py
60

c:\?

keith updated this revision to Diff 378380.Oct 8 2021, 4:33 PM

Fix tests

keith added inline comments.Oct 8 2021, 4:34 PM
clang/test/lit.cfg.py
60

Do you mean lowercase or a single slash? I see ~2x the number of uppercase vs lowercase in this codebase now, and the second is just because of escaping

rmaz added inline comments.Oct 11 2021, 9:03 AM
clang/test/lit.cfg.py
60

I meant the single slash, yes, wasn't sure if it needed to be escaped or not

keith updated this revision to Diff 378725.Oct 11 2021, 10:28 AM
keith marked 2 inline comments as done.

Allow empty leading on windows

This behavior is currently broken, the directory should never be / or C:\ but the logic is broken and only handles /

Wouldn't this one also be solved pretty much the same, but differently, by changing if (llvm::sys::path::is_absolute(RemappedFile)) { into is_absolute_gnu? Since we're remapping debug paths, it's plausible that the target path can be a different style (when cross compiling, where debug prefix remapping is kinda important), and then it's probably good to use a more lax definition of whether a path is absolute. (Alternatively, we maybe should try to detect the kind of path used and use the appropriate style as argument to is_absolute, but I don't think that necessarily helps here.)

(Overall I think it might be good to have the native separators and root available for tests though, even if this particular test might make sense both as-is and with native separators.)

keith added a comment.Oct 19 2021, 2:18 PM

Wouldn't this one also be solved pretty much the same, but differently, by changing if (llvm::sys::path::is_absolute(RemappedFile)) { into is_absolute_gnu?

I think it could but also users could still remap to native window's paths, so likely we'd want this test as well I think either way?

Since we're remapping debug paths, it's plausible that the target path can be a different style (when cross compiling, where debug prefix remapping is kinda important), and then it's probably good to use a more lax definition of whether a path is absolute. (Alternatively, we maybe should try to detect the kind of path used and use the appropriate style as argument to is_absolute, but I don't think that necessarily helps here.)

Good point here, I could definitely see wanting to support the entire matrix of host windows paths vs not, and target windows paths vs not, but I think that would require significantly more changes for other places that call llvm::sys::path::* APIs and also use the default native argument (I'm not sure how difficult this would be, but it would require a bit of auditing)

Wouldn't this one also be solved pretty much the same, but differently, by changing if (llvm::sys::path::is_absolute(RemappedFile)) { into is_absolute_gnu?

I think it could but also users could still remap to native window's paths, so likely we'd want this test as well I think either way?

I guess this might be a good addition as a new test, yeah, but I think it would be good to keep this test as is too, and change the code to use is_absolute_gnu (and fix up the test reference here to expect an empty directory in the output).

Since we're remapping debug paths, it's plausible that the target path can be a different style (when cross compiling, where debug prefix remapping is kinda important), and then it's probably good to use a more lax definition of whether a path is absolute. (Alternatively, we maybe should try to detect the kind of path used and use the appropriate style as argument to is_absolute, but I don't think that necessarily helps here.)

Good point here, I could definitely see wanting to support the entire matrix of host windows paths vs not, and target windows paths vs not, but I think that would require significantly more changes for other places that call llvm::sys::path::* APIs and also use the default native argument (I'm not sure how difficult this would be, but it would require a bit of auditing)

I would expect that to mostly work so far, except for corner cases like these. Auditing probably doesn't hurt if one wants to spend the effort, otherwise I'd just expect it to work and try it out and see if one runs into any issues somewhere, if someone has such a usecase.

Wouldn't this one also be solved pretty much the same, but differently, by changing if (llvm::sys::path::is_absolute(RemappedFile)) { into is_absolute_gnu?

I think it could but also users could still remap to native window's paths, so likely we'd want this test as well I think either way?

I guess this might be a good addition as a new test, yeah, but I think it would be good to keep this test as is too, and change the code to use is_absolute_gnu (and fix up the test reference here to expect an empty directory in the output).

Since we're remapping debug paths, it's plausible that the target path can be a different style (when cross compiling, where debug prefix remapping is kinda important), and then it's probably good to use a more lax definition of whether a path is absolute. (Alternatively, we maybe should try to detect the kind of path used and use the appropriate style as argument to is_absolute, but I don't think that necessarily helps here.)

Good point here, I could definitely see wanting to support the entire matrix of host windows paths vs not, and target windows paths vs not, but I think that would require significantly more changes for other places that call llvm::sys::path::* APIs and also use the default native argument (I'm not sure how difficult this would be, but it would require a bit of auditing)

I would expect that to mostly work so far, except for corner cases like these. Auditing probably doesn't hurt if one wants to spend the effort, otherwise I'd just expect it to work and try it out and see if one runs into any issues somewhere, if someone has such a usecase.

Yep this makes sense. I would rather not scope that into this if that's ok. Since this test was already invalid and broken (actual fix in https://reviews.llvm.org/D111579) I would rather land these and then take that on to unblock my original use case (https://reviews.llvm.org/D111587) if I can find some more time

mstorsjo added a subscriber: rnk.Oct 25 2021, 12:19 PM

Yep this makes sense. I would rather not scope that into this if that's ok. Since this test was already invalid and broken (actual fix in https://reviews.llvm.org/D111579) I would rather land these and then take that on to unblock my original use case (https://reviews.llvm.org/D111587) if I can find some more time

Ok, fair enough - I guess that sounds reasonable, so that'd be a +1 from me to this patch. Ideally it'd be good to find someone more authoritative around clang and these areas than me, but I guess reviewer attention is scarce and hard to come by. @rnk - does this seem sensible to you?

Let's give it a little more time for someone else to comment on it, otherwise I guess I could approve it...

Then for the future cleanup, one might be able to stop using the native substitutions, by keeping one test entirely using possibly-foreign posix style forward slashes, and one using the windows style paths (with that test possibly limited to only executed when on windows, if necessary - but being able to map things to a windows path while cross compiling is good too).

keith added a reviewer: rnk.Nov 18 2021, 5:43 PM
rnk added a comment.Nov 22 2021, 11:29 AM

These seem like generic substitutions that would be useful to anyone writing lit tests. We already have %{pathsep}:
https://llvm.org/docs/CommandGuide/lit.html#substitutions

These should live there as well, and be documented similarly, I think.

compnerd requested changes to this revision.Jan 4 2022, 7:56 AM
compnerd added inline comments.
clang/test/lit.cfg.py
60

This isn't really a separator, this is the root itself. I think that it makes sense to name it accordingly. Please do not hard code this to C:\. There is no guarantee that the root is C:\.

This revision now requires changes to proceed.Jan 4 2022, 7:56 AM
ormris removed a subscriber: ormris.Jan 18 2022, 10:17 AM
keith added inline comments.Jan 28 2022, 3:49 PM
clang/test/lit.cfg.py
60

Yea I didn't like the original naming here either, any suggestions? I avoid path in these because of the existing pathsep, maybe fsroot and fssep?

What are you suggesting in place of hardcoding C:\? I don't think we could detect what folks are using in the tests, so it does seem like it would be up for individual tests to do this however it makes sense. It appears that there are a few hundred uses of this in tests today, does that break in general if you're using another drive?

keith updated this revision to Diff 411573.Feb 25 2022, 9:01 PM

Move config to llvm lit config, add docs

Herald added a project: Restricted Project. · View Herald TranscriptFeb 25 2022, 9:01 PM
keith retitled this revision from [clang][test] Add lit helper for windows paths to [test] Add lit helper for windows paths.Feb 25 2022, 9:02 PM
keith edited the summary of this revision. (Show Details)
rnk added inline comments.Feb 28 2022, 12:19 PM
llvm/docs/TestingGuide.rst
577 ↗(On Diff #411573)

Stray backticks in "Expands"?

llvm/utils/lit/lit/TestRunner.py
1124 ↗(On Diff #411573)

It is pretty common to run the LLVM test suite on secondary drives, especially on buildbot VMs, to separate build disk usage from the root partition. Can we have two separators, ${srcroot} and ${tmproot} that expand to the drive letter of the source and temp path base? That seems like it would be general and implementable.

probinson added inline comments.
llvm/utils/lit/lit/TestRunner.py
1124 ↗(On Diff #411573)

+1. I don't even do builds on C: drive, on one of my machines.

keith updated this revision to Diff 411921.Feb 28 2022, 4:05 PM
keith marked 3 inline comments as done.
keith edited the summary of this revision. (Show Details)

Use the actual drive on windows, split out into fssrcroot and fstmproot

keith added inline comments.Feb 28 2022, 4:31 PM
llvm/utils/lit/lit/TestRunner.py
1124 ↗(On Diff #411573)

Updated, I kept the fs prefixing thinking that srcroot and tmproot might be too confusable as an alternative to %t and friends, let me know what you think!

keith added a comment.Feb 28 2022, 4:31 PM

For reference here's an example of a test that uses this https://reviews.llvm.org/D111579

rnk accepted this revision.Feb 28 2022, 4:49 PM

lgtm

keith added a comment.Mar 13 2022, 7:44 PM

@compnerd can you re-review here? I think I covered your feedback, let me know!

Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2022, 7:44 PM
compnerd accepted this revision.Mar 14 2022, 4:30 PM

Seems reasonable, though I'm not a fan of the variable names - they seem a bit difficult to read due to no separation (e.g., %fs-src-root or %fs_src_root vs %fssrcroot)

This revision is now accepted and ready to land.Mar 14 2022, 4:30 PM
keith updated this revision to Diff 415290.Mar 14 2022, 6:08 PM

Update substitutions to use dashes

This revision was landed with ongoing or failed builds.Mar 14 2022, 8:06 PM
This revision was automatically updated to reflect the committed changes.