Skip to content

CTest: File IO tests fail because tmp directory isn't cleaned up #731

Closed

Description

@GMNGeoffrey

If you run the file_io tests once, they pass, but on the second time they fail because there are some asserts in there that the file being created doesn't already exist. It looks like ctest isn't cleaning up its temp directories

ctest -R iree_base_file_io_test -V

https://sourcegraph.com/github.com/google/iree/-/blob/iree/base/file_io_test.cc#L42

Activity

  1. GMNGeoffrey commented on Feb 11, 2020

    @GMNGeoffrey
    MemberAuthor

    Oh actually we're just assuming TEST_TMPDIR exists, which it totally doesn't in ctest. Duh... Ok I think that's also why the CLI smoke tests are failing.

  2. GMNGeoffrey commented on Feb 11, 2020

    @GMNGeoffrey
    MemberAuthor

    So I've been looking into how to do this and it seems weirdly hard to have cmake tests execute in temporary directories that it cleans up. There doesn't even seem to be a native facility for executing a command before or after each test.

    We could, of course, solve this locally by making each test responsible for its own setup and teardown. That pushes a lot of responsibility onto the test though and will just result in weird failures if people forget (which they're likely to, since it's not the standard, at least with bazel).

    Avenues I've explored:

    1. CTEST_CUSTOM_[PRE|POST]_TEST. I think it executes before and after all tests, not each test. Also I couldn't get it to work at all, even when just running a single test, or even provide a failure message. http://stackoverflow.com/q/55621174 and https://gitlab.kitware.com/cmake/community/-/wikis/doc/ctest/Testing-With-CTest#customizing-ctest
    2. CMake fixtures, which are extra tests that are configured to run before or after a certain set of tests. Only run once, not per test. Would require creating a new fixture and fixture cleanup for each test, tripling the number of tests. I think workable, but super gross. https://cmake.org/cmake/help/latest/prop_test/FIXTURES_REQUIRED.html#prop_test:FIXTURES_REQUIRED

    @marbre do you have any experience with doing this in cmake?

  3. GMNGeoffrey commented on Feb 11, 2020

    @GMNGeoffrey
    MemberAuthor

    Currently exploring

    1. Have a custom shell script that executes all our tests.
  4. marbre commented on Feb 12, 2020

    @marbre
    Member

    You actually solved it with #741 the way I always handled it, except that I used python scripts :)

  5. GMNGeoffrey commented on Feb 12, 2020

    @GMNGeoffrey
    MemberAuthor

    You actually solved it with #741 the way I always handled it, except that I used python scripts :)

    Good to hear :-) My mistake was assuming that this should be supported natively in the test runner. The actual script is not bad at all.

  6. marbre commented on Feb 12, 2020

    @marbre
    Member

    Using a script probably gives you much more flexibility than ctest could :-) The only question remaining is, if we really want to create a test directory for every test or if we should only create those for tests making use of it.

  7. ScottTodd commented on Feb 12, 2020

    @ScottTodd
    Member

    It also generally seems like Bazel takes more opinions than ctest on the role of a test runner and build system (see https://docs.bazel.build/versions/2.0.0/test-encyclopedia.html).

  8. GMNGeoffrey commented on Feb 12, 2020

    @GMNGeoffrey
    MemberAuthor

    Yeah unless the cost becomes an issue, I'd prefer to let each test (binary, not method) assume it gets a writable scratch directory that is initially empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions