Skip to content

[libcxx][docs] Make test name pattern documentation more obvious #73136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 10, 2024

Conversation

hawkinsw
Copy link
Contributor

As a new contributor, I found it hard to find the documentation for the meaning of the names of different tests and how those names translate to Lit.

This makes that documentation more explicit.

@hawkinsw hawkinsw self-assigned this Nov 22, 2023
@hawkinsw hawkinsw requested a review from a team as a code owner November 22, 2023 15:14
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Nov 22, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 22, 2023

@llvm/pr-subscribers-libcxx

Author: Will Hawkins (hawkinsw)

Changes

As a new contributor, I found it hard to find the documentation for the meaning of the names of different tests and how those names translate to Lit.

This makes that documentation more explicit.


Full diff: https://github.com/llvm/llvm-project/pull/73136.diff

1 Files Affected:

  • (modified) libcxx/docs/TestingLibcxx.rst (+42-7)
diff --git a/libcxx/docs/TestingLibcxx.rst b/libcxx/docs/TestingLibcxx.rst
index 44f3904f4e426a0..5783cc6a21922cc 100644
--- a/libcxx/docs/TestingLibcxx.rst
+++ b/libcxx/docs/TestingLibcxx.rst
@@ -330,13 +330,48 @@ additional headers.
           taken to make it work in earlier language versions.
 
 
-Additional reading
-------------------
-
-The function ``CxxStandardLibraryTest`` in the file
-``libcxx/utils/libcxx/test/format.py`` has documentation about writing test. It
-explains the difference between the test named  ``foo.pass.cpp`` and named
-``foo.verify.cpp`` are.
+Test names
+----------
+
+The names of test files have meaning for the libcxx-specific configuration of 
+Lit. A complete description can be found in the docstring for the function 
+``CxxStandardLibraryTest`` in the file ``libcxx/utils/libcxx/test/format.py``.
+
+For quick reference, here is an overview of some of the most useful patterns:
+
+.. list-table:: Lit Meaning of libcxx Test Filenames
+   :widths: 25 75
+   :header-rows: 1
+
+   * - Name Pattern
+     - Meaning
+   * - ``FOO.pass.cpp``
+     - Compiles, links and runs successfully
+   * - ``FOO.pass.mm``
+     - Same as ``FOO.pass.cpp``, but for Objective-C++
+
+   * - ``FOO.compile.pass.cpp``
+     - Compiles successfully, link and run not attempted
+   * - ``FOO.compile.pass.mm``
+     - Same as ``FOO.compile.pass.cpp``, but for Objective-C++
+   * - ``FOO.compile.fail.cpp``
+     - Does not compile successfully
+
+   * - ``FOO.link.pass.cpp``
+     - Compiles and links successfully, run not attempted
+   * - ``FOO.link.pass.mm``
+     - Same as ``FOO.link.pass.cpp``, but for Objective-C++
+   * - ``FOO.link.fail.cpp``
+     - Compiles successfully, but fails to link
+
+   * - ``FOO.sh.<anything>``
+     - A builtin Lit Shell test
+
+   * - ``FOO.gen.<anything>``
+     - A ``.sh`` test that generates one or more Lit tests on the fly. Executing this test must generate one or more files as expected by LLVM split-file, and each generated file leads to a separate Lit test that runs that file as defined by the test format. This can be used to generate multiple Lit tests from a single source file, which is useful for testing repetitive properties in the library.  Be careful not to abuse this since this is not a replacement for usual code reuse techniques.
+
+   * - ``FOO.verify.cpp``
+     - Compiles with clang-verify. This type of test is automatically marked as UNSUPPORTED if the compiler does not support clang-verify.
 
 Benchmarks
 ==========

@hawkinsw hawkinsw requested a review from ldionne November 22, 2023 15:20
@hawkinsw
Copy link
Contributor Author

Great! Thank you for the "go ahead". I will send along some fixups and re-request review when it is ready!

@hawkinsw
Copy link
Contributor Author

I have updated to consolidate all documentation about the file name pattern semantics to docs/TestingLibcxx.rst. In the future, I would like to expand the testing documentation to include information about how to write a builtin Lit shell test (including the valid commands, how to use pipelines, valid substitutions, etc). @ldionne : If you would prefer to wait for that additional documentation before merging this PR, that is great by me. If not, I will make a separate PR.

Copy link
Member

@mordante mordante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, I have grepped for this information a number times. Having it on the website gives it a better visibility.

LGTM modulo some comments. Please wait for @ldionne to review this too.


The names of test files have meaning for the libcxx-specific configuration of
Lit. A complete description can be found in the docstring for the function
``CxxStandardLibraryTest`` in the file ``libcxx/utils/libcxx/test/format.py``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last sentence seems no longer to be true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry! I had stupidly not committed a change that fixed this!! Should be resolved now!


Lit tests are contained in files that follow a certain pattern. That
pattern determines the semantics of the test. See
libcxx/docs/TestingLibcxx.rst or https://libcxx.llvm.org/TestingLibcxx.html
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would only link to the website and use an anchor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Will do!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All done! Great feedback, thank you!

@hawkinsw
Copy link
Contributor Author

Thanks for working on this, I have grepped for this information a number times. Having it on the website gives it a better visibility.

LGTM modulo some comments. Please wait for @ldionne to review this too.

Thank you for the feedback! I really appreciate it!

@hawkinsw hawkinsw requested a review from mordante November 29, 2023 00:26
Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM w/ comments. It would be nice to move the rest of the documentation for the test format to .rst too, otherwise we'll have things in multiple places which means more likely to forget to update new information everywhere.

Lit tests are contained in files that follow a certain pattern. That
pattern determines the semantics of the test. See
https://libcxx.llvm.org/TestingLibcxx.html#test-names
for a complete description of those semantics.

Substitution requirements
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a follow-up, it would be great to also move this part of the documentation to .rst so that all of the documentation for the file format is in the same place.

@hawkinsw
Copy link
Contributor Author

LGTM w/ comments. It would be nice to move the rest of the documentation for the test format to .rst too, otherwise we'll have things in multiple places which means more likely to forget to update new information everywhere.

Thank you for the review, @ldionne !! I will incorporate your feedback ASAP! The other thing that I would like to add with this PR is documentation on the actual commands available in the lit built-in shell tests. Does that seem reasonable? If so, I will start working on that and try to have something ready for tomorrow!

Thank you again!

@ldionne
Copy link
Member

ldionne commented Dec 13, 2023

The other thing that I would like to add with this PR is documentation on the actual commands available in the lit built-in shell tests.

Which commands do you mean? The actual builtin Lit ShTest commands like RUN? If so, those are already documented in Lit-specific documentation. We should move the documentation for the commands we add in our test format (like ADDITIONAL_COMPILE_FLAGS), though.

@hawkinsw
Copy link
Contributor Author

The other thing that I would like to add with this PR is documentation on the actual commands available in the lit built-in shell tests.

Which commands do you mean? The actual builtin Lit ShTest commands like RUN? If so, those are already documented in Lit-specific documentation. We should move the documentation for the commands we add in our test format (like ADDITIONAL_COMPILE_FLAGS), though.

Great! I will work on that.

I was talking about documenting the builtin lit "shell" commands (e.g.,

    inproc_builtins = {
        "cd": executeBuiltinCd,
        "export": executeBuiltinExport,
        "echo": executeBuiltinEcho,
        "@echo": executeBuiltinEcho,
        "mkdir": executeBuiltinMkdir,
        "popd": executeBuiltinPopd,
        "pushd": executeBuiltinPushd,
        "rm": executeBuiltinRm,
        ":": executeBuiltinColon,
    }   

and if/how they differ in their meaning from posix (or PowerShell). Those are not documented in the other lit documentation (e.g., https://llvm.org/docs/TestingGuide.html#writing-new-regression-tests) and it was something that I struggled to find. Would you prefer that I send that as PR directly to lit?

I will reflag you for a review when it is ready! Thanks again!

@hawkinsw
Copy link
Contributor Author

The other thing that I would like to add with this PR is documentation on the actual commands available in the lit built-in shell tests.

Which commands do you mean? The actual builtin Lit ShTest commands like RUN? If so, those are already documented in Lit-specific documentation. We should move the documentation for the commands we add in our test format (like ADDITIONAL_COMPILE_FLAGS), though.

I have added documentation for the ADDITIONAL_COMPILE_FLAGS and FILE_DEPENDENCIES directives.

@hawkinsw hawkinsw requested a review from ldionne December 14, 2023 04:02
*all* the files in any specified directories will be placed in the *current working directory* of the test when it executes. All dependency directories and files
specified using relative paths will be anchored to the directory specified by the ``%S`` substitution (i.e., the source directory of the test being executed.).
* - ``ADDITIONAL_COMPILE_FLAGS``
- ``// ADDITIONAL_COMPILE_FLAGS: flag1, flag2, ...``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually whitespace separated now, so this should be ADDITIONAL_COMPILE_FLAGS: flag1 flag2 .... We forgot to update it, let's do it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I got that in the latest fixup.

FOO.verify.cpp - Compiles with clang-verify. This type of test is
automatically marked as UNSUPPORTED if the compiler
does not support Clang-verify.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional supported directives below should go away, since it's now in RST.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All done!!

specified using relative paths will be anchored to the directory specified by the ``%S`` substitution (i.e., the source directory of the test being executed.).
* - ``ADDITIONAL_COMPILE_FLAGS``
- ``// ADDITIONAL_COMPILE_FLAGS: flag1, flag2, ...``
- The additional compiler flags specified using the ``ADDITIONAL_COMPILE_FLAGS`` libc++-specific Lit directive will be added to the invocation of ``clang`` used to build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new documentation is not accurate. They don't apply to Clang only, and they do affect .sh.cpp tests too. I suggest we stick to the previous documentation:

This directive will cause the provided flags to be added to the
%{compile_flags} substitution for the test that contains it. This
allows adding special compilation flags without having to use a
.sh.cpp test, which would be more powerful but perhaps overkill.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that I have properly incorporated this feedback as well! Thanks!

- Usage
* - ``FILE_DEPENDENCIES``
- ``// FILE_DEPENDENCIES: file, directory, /path/to/file, ...``
- The paths given to the ``FILE_DEPENDENCIES`` directive can specify directories or specific files upon which a given test depend. Copies of the files individually specified and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slightly incorrect. This uses the %T substitution, not %S. I suggest keeping the wording in the old documentation, I think it wasn't unclear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I wrote %S was

# For each file dependency in FILE_DEPENDENCIES, inject a command to copy
# that file to the execution directory. Execute the copy from %S to allow
# relative paths from the test directory.

from line 130 of format.py. Sorry!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see -- you're right, this was missing from the old documentation. Maybe something like this?

This directive expresses that the test requires the provided files
or directories in order to run. An example is a test that requires
some test input stored in a data file. When a test file contains
such a directive, the files will collect them and copy them
to the directory represented by %T. The copy is performed from
the directory represented by %S (i.e. the source directory of  the
test being executed), which allows using relative paths to specify
files. After performing the copy, the intent is that %T contains all
the inputs necessary to run the test, such that e.g. execution on a
remote host can be done by simply copying %T to the host.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know what you think about what I am about to commit. I think that your suggestion was great -- the examples really help!

@hawkinsw
Copy link
Contributor Author

@ldionne Thank you for the feedback. I am sorry that there were mistakes. I am sure that the mistakes were all my fault but I didn't intend to change any of the documentation that was previously written. I will address your comments as soon as possible. I am going to be away from my keyboard until Thursday but will work on it ASAP.

@hawkinsw
Copy link
Contributor Author

@mordante In re: #76246 I have added some documentation for the MODULE directive. Let me know if it reads okay!

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor changes to satisfy RST files. Thanks!

- Same as ``FOO.pass.cpp``, but for Objective-C++.

* - ``FOO.compile.pass.cpp``
- Checks whether the C++ code in the file compiles successfully. In general, prefer `compile` tests over `verify` tests,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to use double-backticks here for this to render properly!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this isn't a build error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's valid RST code, it will just render weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course I do!! Sorry. Thank you!

hawkinsw and others added 5 commits January 8, 2024 16:36
As a new contributor, I found it hard to find the documentation for the
meaning of the names of different tests and how those names translate
to Lit.

This makes that documentation more explicit.
Update to consolidate lit test file name pattern semantic documentation to docs/
(Fully) centralize all naming documentation in the rst-based documentation.
Point only to www documentation for test names (per @mordante's excellent feedback)
Be more clear about what type of shell we get when running these tests.

Co-authored-by: Louis Dionne <[email protected]>
hawkinsw and others added 6 commits January 8, 2024 16:36
Make it clearer how the tests are generated by libcxx to drive lit according to the patterns embedded in the filenames that contain tests.

Co-authored-by: Louis Dionne <[email protected]>
Add documentation about ADDITIONAL_COMPILE_FLAGS and FILE_DEPENDENCIES.
Add link to Internals Manual for writing clang-verify tests.
Add recommendation on when to write verify tests.
@hawkinsw hawkinsw requested a review from ldionne January 8, 2024 21:55
@hawkinsw
Copy link
Contributor Author

hawkinsw commented Jan 8, 2024

Can I get one more check, @ldionne ? Thanks -- I'm just a little nervous!

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ldionne ldionne merged commit d301539 into llvm:main Jan 10, 2024
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
…lvm#73136)

As a new contributor, I found it hard to find the documentation for the
meaning of the names of different tests and how those names translate to
Lit. This patch moves the documentation to the RST documentation we
publish on the website instead of leaving it in the source code only.
@hawkinsw hawkinsw deleted the libcxx_test_docs branch January 31, 2024 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants