Page MenuHome

guardedalloc_test: Do overflow tests without allocation
Needs ReviewPublic

Authored by Ankit Meel (ankitm) on Mar 14 2021, 4:09 PM.

Details

Summary

Fix T84637
See T84637#1134707 and T84637#1135324

  • Replace allocation tests with direct tests of MEM_size_safe_multiply.
  • Disable death tests on macOS with ASan. Release builds will check if abort occurs or not, upon integer overflow.

Diff Detail

Repository
rB Blender
Branch
alloc (branched from master)
Build Status
Buildable 13797
Build 13797: arc lint + arc unit

Event Timeline

Ankit Meel (ankitm) requested review of this revision.Mar 14 2021, 4:09 PM
Ankit Meel (ankitm) created this revision.

Would be nice to test the actual allocations functions, but I can't think of a batter solution than this.

About the names, perhaps use safe_multiply_pass and safe_multiply_fail.

This revision is now accepted and ready to land.Mar 15 2021, 2:58 PM

Rename
LockFreeAllocatorTest to AllocatorTest,
LockfreeIntegerOverflow to IntegerOverflow, (as lock-free is not a highlight here.)
multiply_pass to safe_multiply_pass,
multiply_fail to safe_multiply_fail,

Remove the base class include since test fixture is not used.

Remove GCC pragma now that there are no allocations.

Update top level comment.

  • Typos in last update
Sergey Sharybin (sergey) requested changes to this revision.Mar 22 2021, 10:41 AM
Sergey Sharybin (sergey) added inline comments.
intern/guardedalloc/tests/guardedalloc_overflow_test.cc
67

total_size is size_t, so using boolean-typed EXPECT_TRUE seems meaningless to me.
Either explicitly check for EXPECT_GT(total_size, 0) or check for an exact value with EXPECT_EQ().

This revision now requires changes to proceed.Mar 22 2021, 10:41 AM

fix EXPECT_TRUE
Re-add EXPECT_EXIT tests but disable on mac.

If the EXPECT_EXIT can not be trusted on some platform/configuration this is to be checked with the upstream gtest library.

If the EXPECT_EXIT can not be trusted on some platform/configuration this is to be checked with the upstream gtest library.

It's not that EXPECT_EXIT can't be trusted, it's that it tests for exit with SIGABRT specifically and that the signal you get from a failing malloc (with asan) is not well-defined.

Maybe the best solution is to add a EXIT_ANY_SIGNAL_PREDICATE that does not test for abort specifically.

... that the signal you get from a failing malloc (with asan) ..

The malloc is not relevant here.. Even if MallocArray function is edited to be empty (do nothing), the test will fail. AFAIK, it's due to fork(). See T84637#1135324
Also, these tests are the integer overflow ones. The malloc would not be called even if the fork issue is resolved (like in builds without asan). The abort happens before malloc. https://developer.blender.org/diffusion/B/browse/master/intern/guardedalloc/intern/mallocn_guarded_impl.c$480-489

Ok, I think that may be a bug in asan/ubsan, or some odd behavior.

Perhaps we should then change ABORT_PREDICATE to check for either SIGBART or SIGILL on macOS.

  • Disable tests if apple and asan enabled.

It'd be slightly deceptive to see a test pass without it even running.
Here's a compromise to disable the test on macOS if Asan is enabled.

Ankit Meel (ankitm) edited the summary of this revision. (Show Details)Mar 29 2021, 7:55 PM