This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Fix broken (flaky) unittests based on FlagParser.
ClosedPublic

Authored by etienneb on Jun 30 2016, 8:03 AM.

Details

Summary

The FlagParser is populating a static global class with the
unrecognized flags when parsing. That global class has a
dcheck that limit the number of unrecognized flag to 20.

class UnknownFlags {
  static const int kMaxUnknownFlags = 20;
  const char *unknown_flags_[kMaxUnknownFlags];
  int n_unknown_flags_;

  [...]

  void Report() {
    if (!n_unknown_flags_) return;
    Printf("WARNING: found %d unrecognized flag(s):\n", n_unknown_flags_);
    for (int i = 0; i < n_unknown_flags_; ++i)
      Printf("    %s\n", unknown_flags_[i]);
    n_unknown_flags_ = 0;
  }
};

UnknownFlags unknown_flags;

Unittests based on that class must reset the counter 'n_unknown_flags_' or
the next usage of that class may fail arbitrary. This can be done by
reporting the pending unknown flags.

Diff Detail

Event Timeline

etienneb updated this revision to Diff 62365.Jun 30 2016, 8:03 AM
etienneb retitled this revision from to [compiler-rt] Fix broken (flaky) unittests based on FlagParser..
etienneb updated this object.
etienneb added a reviewer: rnk.
rnk accepted this revision.Jun 30 2016, 8:07 AM
rnk edited edge metadata.

lgtm This will cause stderr spew in the tests for unknown flags, but that seems OK.

This revision is now accepted and ready to land.Jun 30 2016, 8:07 AM
In D21896#471316, @rnk wrote:

lgtm This will cause stderr spew in the tests for unknown flags, but that seems OK.

Yes. But it's not too noisy.

Note: Google Test filter = SanitizerCommon.*Flags
[==========] Running 6 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 6 tests from SanitizerCommon
[ RUN      ] SanitizerCommon.BooleanFlags
[       OK ] SanitizerCommon.BooleanFlags (0 ms)
[ RUN      ] SanitizerCommon.IntFlags
[       OK ] SanitizerCommon.IntFlags (8 ms)
[ RUN      ] SanitizerCommon.StrFlags
WARNING: found 2 unrecognized flag(s):
    --flag_name
    zzzzzzz
[       OK ] SanitizerCommon.StrFlags (0 ms)
[ RUN      ] SanitizerCommon.MultipleFlags
[       OK ] SanitizerCommon.MultipleFlags (0 ms)
[ RUN      ] SanitizerCommon.CommonSuffixFlags
[       OK ] SanitizerCommon.CommonSuffixFlags (0 ms)
[ RUN      ] SanitizerCommon.CommonFlags
[       OK ] SanitizerCommon.CommonFlags (0 ms)
[----------] 6 tests from SanitizerCommon (8 ms total)

[----------] Global test environment tear-down
[==========] 6 tests from 1 test case ran. (8 ms total)
[  PASSED  ] 6 tests.
etienneb closed this revision.Jun 30 2016, 8:18 AM