This is an archive of the discontinued LLVM Phabricator instance.

[gwp_asan] Employ EXPECT_DEATH for zxtest compatibility
ClosedPublic

Authored by Caslyn on Mar 29 2023, 5:03 PM.

Details

Summary

Employ a similar tactic introduced by https://reviews.llvm.org/D94362
for gwp_asan tests. zxtest ASSERT_DEATH syntax differs from gtest in
that it expects a lambda.

zxtest does not have EXPECT_DEATH, so it introduced for Fuchsia builds
and wraps the expression with a lambda to create a compatible syntax
between zxtest and gtest for death tests.

An example of where this compatiblity is needed is in
never_allocated.cpp.

Diff Detail

Event Timeline

Caslyn created this revision.Mar 29 2023, 5:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2023, 5:03 PM
Herald added a subscriber: Enna1. · View Herald Transcript
Caslyn requested review of this revision.Mar 29 2023, 5:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2023, 5:03 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
hctim added inline comments.Mar 30 2023, 10:42 AM
compiler-rt/lib/gwp_asan/tests/harness.h
20

Y?

21–25

are there scenarios when ASSERT_DEATH is not defined? seems odd.

Caslyn added inline comments.Mar 30 2023, 3:18 PM
compiler-rt/lib/gwp_asan/tests/harness.h
20

The second arg to zxtest's ASSERT_DEATH differs from gtest in that it is only used as an (optional) message arg for debugging if the crash did not happen. Since it doesn't do any regex matching on the exception, Y loses its meaning in this way, and an empty string is passed. We could omit the second arg to this call altogether - though the reason it's added is to have some parity with the implementation for scudo tests (https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test.h#L23).

21–25

That's a good question - I can only think if zxtest removes it from its API. @mcgrathr, does this existence check for zxtest's ASSERT_DEATH in scudo/gwp_asan do anything for us?

hctim added inline comments.Mar 30 2023, 3:21 PM
compiler-rt/lib/gwp_asan/tests/harness.h
20

ah, yeah i forgot that fuchsia does the sane thing with crashes (registering an external death-handling process) rather than signal handlers, where you can check for an expected bit of text.

Caslyn added inline comments.Apr 5 2023, 8:45 AM
compiler-rt/lib/gwp_asan/tests/harness.h
21–25

gentle ping @mcgrathr

Caslyn updated this revision to Diff 514740.Apr 18 2023, 2:06 PM

Removed unnecessary ASSERT_DEATH existance check

Caslyn marked an inline comment as done.Apr 18 2023, 2:07 PM
Caslyn added inline comments.
compiler-rt/lib/gwp_asan/tests/harness.h
21–25

In the interest of moving this CL forward to unblock Fuchsia's gwp-asan rolls, removed the existence check.

hctim accepted this revision.Apr 18 2023, 2:44 PM

LGTM w/ nit.

compiler-rt/lib/gwp_asan/tests/harness.h
18
// zxtest defines a different ASSERT_DEATH, taking a lambda and an error message
// if death didn't occur, versus gtest taking a statement and a string to search
// for in the dying process. zxtest doesn't define an EXPECT_DEATH, so we use
// that in the tests below (which works as intended for gtest), and we define
// EXPECT_DEATH as a wrapper for zxtest's ASSERT_DEATH. Note that zxtest drops
// the functionality for checking for a particular message in death.

Clarifies:

  1. What the args are in zxtest (which aren't clear to us not familiar with zxtest),
  2. How we can abuse gtest defining EXPECT_DEATH but we can wrap it under zxtest, and
  3. We ignore the error message on zxtest.
This revision is now accepted and ready to land.Apr 18 2023, 2:44 PM
Caslyn updated this revision to Diff 514750.Apr 18 2023, 2:56 PM
Caslyn marked an inline comment as done.

Amend comment

This revision was landed with ongoing or failed builds.Apr 18 2023, 2:58 PM
This revision was automatically updated to reflect the committed changes.