This is an archive of the discontinued LLVM Phabricator instance.

[lit] Factor out listdir logic shared by different test formats.
ClosedPublic

Authored by dlj on Jun 29 2017, 6:02 PM.

Details

Summary

The lit test formats use largely the same logic for discovering tests. There are
some superficial differences in the logic, which seem reasonable enough to
handle in a single routine.

At a high level, the common goal is "look for files that end with one of these
suffixes, and skip anything starting with a dot." The balance of the logic
specific to ShTest and GoogleTest collapses quite a bit, so that
getTestsInDirectory is only a couple of lines around a call to the new function.

Diff Detail

Repository
rL LLVM

Event Timeline

dlj created this revision.Jun 29 2017, 6:02 PM
modocache added inline comments.Jun 29 2017, 6:18 PM
utils/lit/lit/util.py
139 ↗(On Diff #104800)

Note that this is a subtle change in behavior from os.path.splitext(). Consider a file without an extension, such as TARGETS:

>>> os.path.splitext('TARGETS')
('TARGETS', '')

The previous logic, which used os.path.splitext(), would not include the file, even if 'TARGETS' were included as a suffix. This new logic would include it, since TARGETS.endswith('TARGETS') returns True.

I'm not sure if any consumers of lit rely on this behavior... but if you didn't intend to make a change, perhaps keep the old behavior for now?

dlj set the repository for this revision to rL LLVM.Jun 29 2017, 6:39 PM
dlj added inline comments.Jun 29 2017, 6:52 PM
utils/lit/lit/util.py
139 ↗(On Diff #104800)

Yup, you are correct... I think this is OK as-is, though, since splitext includes the trailing dot:

In [2]: os.path.splitext('TARGETS')
Out[2]: ('TARGETS', '')

In [3]: os.path.splitext('x.TARGETS')
Out[3]: ('x', '.TARGETS')

Any existing suffixes in lit configs would need to have a dot in order to match. For example:

https://reviews.llvm.org/diffusion/L/browse/lld/trunk/test/lit.cfg;306779$48

That anchors the suffix for both the endswith() and splitext() cases... so if the previous behaviour was to match TARGETS as a suffix, it would have needed to be specified as ".TARGETS" in order to work.

It's possible there are such bugs, but all my test counts locally line up before and after. (And I'll double-check again, just to be sure.) I believe the only cases where the behaviour would actually differ is if the old pattern had a latent bug.

modocache accepted this revision.Jun 30 2017, 2:19 PM
modocache added inline comments.
utils/lit/lit/util.py
139 ↗(On Diff #104800)

Ah OK. Great idea to make sure the test counts match. That sounds fine to me -- thanks!

This revision is now accepted and ready to land.Jun 30 2017, 2:19 PM
This revision was automatically updated to reflect the committed changes.
grimar added a subscriber: grimar.EditedJul 3 2017, 7:25 AM

Hi !

This (r306895) causes check-lld failtures under windows for me:

24>  Traceback (most recent call last):
24>    File "C:/access_softek/llvm/utils/lit/lit.py", line 6, in <module>
24>      main()
24>    File "C:\access_softek\llvm\utils\lit\lit\main.py", line 161, in main
24>      main_with_tmp(builtinParameters)
24>    File "C:\access_softek\llvm\utils\lit\lit\main.py", line 344, in main_with_tmp
24>      lit.discovery.find_tests_for_inputs(litConfig, inputs))
24>    File "C:\access_softek\llvm\utils\lit\lit\discovery.py", line 222, in find_tests_for_inputs
24>      test_suite_cache, local_config_cache)[1])
24>    File "C:\access_softek\llvm\utils\lit\lit\discovery.py", line 186, in getTestsInSuite
24>      for res in subiter:
24>    File "C:\access_softek\llvm\utils\lit\lit\discovery.py", line 144, in getTestsInSuite
24>      litConfig, lc):
24>    File "C:\access_softek\llvm\utils\lit\lit\formats\googletest.py", line 85, in getTestsInDirectory
24>      suffixes={self.test_suffix}):
24>    File "C:\access_softek\llvm\utils\lit\lit\util.py", line 136, in listdir_files
24>      for filename in os.listdir(dirname):
24>  WindowsError: [Error 3] : 'C:\\access_softek\\c_make_build_dir_x64\\tools\\lld\\unittests\\debug/*.*'

I think issue is that C:\\access_softek\\c_make_build_dir_x64\\tools\\lld\\unittests\\debug folder not exist.
I added some traces (D34944) and compared output from windows and ubuntu runs of check-lld:
(under ubuntu it works fine)

Ubuntu:

/home/umb/LLVM/llvm/tools/lld/test
Subdirs: .
BuildMode: .
Source: /home/umb/LLVM/llvm-build/tools/lld/unittests
Subdir: .
/home/umb/LLVM/llvm-build/tools/lld/unittests/.

Windows:

24>  BuildMode: Debug
24>  Subdirs: Debug
24>  Source: C:\access_softek\c_make_build_dir_x64\tools\lld\unittests
24>  Subdir: debug
24>  Dirname: C:\access_softek\c_make_build_dir_x64\tools\lld\unittests\debug

"BuildMode" above is config.llvm_build_mode.

So looks in my windows case config.llvm_build_mode is not ".", but "Debug" and is added to the path here and that is the reason of failture.
Not sure why Buildmode is "." under ubuntu though and where it comes from.

grimar added a comment.Jul 3 2017, 7:56 AM

Ah, I just noticed the D34853, it fixes the issue I am observing.

Ah, I just noticed the D34853, it fixes the issue I am observing.

Hi,

I have also hit this issue. I don't think that D34853 is the correct solution (see my comment in that review).

I think the easiest fix (and it's the workaround I currently have in place) is to test that the directory exists in GoogleTest.getTestsInDirectory before calling lit.util.listdir_files. I will put together a patch and review for this fix.

Cheers,
Andrew