Skip to content

Clean up test RUN commands #346

Open
@kyleheadley

Description

@kyleheadley

Our tests make inconsistent use of certain features of llvm-lit. We could manually update them to be more consistent as we work towards a more general solution for future tests.

  • Add -- to the end of 3c calls (planned to be done in Add -output-dir and other file handling improvements #412)
  • Use -addcr in all 3c calls
  • Remove -fcheckedc-extension from %clang calls because it's the default (but first confirm that we don't foresee the default changing)
  • Use %clang rather than %clang_cc1 (Migrate 3C regression tests from %clang_cc1 to %clang. #596)
  • Stop having -output-postfix=checked write temporary files into clang/test/3C (3C output is not cleaned up when a test fails. #378) (planned to be done in Add -output-dir and other file handling improvements #412)
  • Redirect unused output to temp files (i.e. %t3.unused) rather than /dev/null
  • Name test expected to fail as *_xfail.c rather than *BUG.c
  • *_xfail.c tests should use these conventions as if we expect them to succeed
  • Run clang on converted files (using -f3c-tool if necessary)
  • Include a short explanation of the test
  • Include an explanation why any of the above are not relevant to a particular test
  • Avoid XFAIL in favor of asserting the specific way in which a test is expected to fail due to a known bug. (We may not get rid of all the XFAILs immediately: we may find that XFAIL has benefits in certain cases or just that taking the time to research a particular test is a low priority.)
  • If cd is used in a RUN line, it should generally be the last thing on the line (e.g., mkdir DIR && cd DIR is OK to put on one RUN line to save space, but cd DIR && SOME_OTHER_COMMAND is not). Readers may not be aware that the RUN lines form a single script in which a cd command does affect subsequent RUN lines (unless some special construct such as a subshell is used). // RUN: cd DIR && SOME_OTHER_COMMAND could mislead the reader that we needed to put both on one line because the effect of the cd would otherwise be lost. An exception to this guideline might be if a test needs a long sequence of cd DIR_A; CMD_A; cd DIR_B; CMD_B; ... and the space saving or clarity improvement of putting cd DIR_A; CMD_A on one line is significant. (Note that cd DIR_A; CMD_A is equivalent to cd DIR_A && CMD_A because lit uses the equivalent of set -e). (Guideline proposed by Matt 2021-06-21, open to debate.)

Using -- seems to suppress some output, but the test runner will do this for us. In rare cases it changes the resultant file (#343), and we never run with this option manually.

The two versions of clang are for the driver (%clang) and the front-end (%clang_cc1). The driver will call the front-end with options based on the system, so this should be the default. There may be exceptions if the front-end contains some additional debug options. One option is -verify; it can be used with %clang as -Xclang -verify.

The test generator llvm-lit provides temporary files during a test (%t, we can optionally add a suffix). Using these is preferable to creating files under clang/test/3C (which can foul up version control and future test runs), but lit does not delete %t files automatically, so we still need to delete them ourselves if we want to make sure the test starts in a predictable state and is not affected by previously existing %t files.

While /dev/null is convenient, it is not supported on windows systems. llvm-lit converts it for most cases, but not all.

Some tests do not represent our current output, but a desired future one. We mark these internally and externally with // XFAIL: *, and testname_xfail.c, respectively. They should otherwise be treated as regular tests, since we will get a notification if they succeed (say after a bugfix with wide consequences). At that point we don't want to edit them, just update the failure status.

Running clang is a good secondary test, both for the tool's correct output and for test correctness. It may not be possible in some cases, like -alltypes not yet generating array bounds for all variables. For those, use -f3c-tool, and if it still doesn't compile, leave a note about why and possibly a link to a github issue describing the error.

Explanations help in debugging or updating a test. The specific issue might need setup code that can be changed without affecting the value of the test.

This issue is large and may span multiple pull requests. It may also not all be necessary, as we evaluate our ability to automate testing.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions