Page MenuHome

GTest/Allocator: make integer-overflow tests pass on ASan-enabled builds
AbandonedPublic

Authored by Ankit Meel (ankitm) on Dec 13 2020, 12:15 PM.

Details

Summary

In the integer overflow tests, Guarded allocator and
lockfree allocator will return null. That is expected.
But ASan will interfere and abort the process with
message to the effect of _failed to allocate memory_.

So set allocator_may_return_null to true only for guardedalloc_test
executable.

Diff Detail

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

Event Timeline

Ankit Meel (ankitm) requested review of this revision.Dec 13 2020, 12:15 PM
Ankit Meel (ankitm) created this revision.
yourhero (yourhero) retitled this revision from GTest/Allocator: make integer-overflow tests pass on ASan-enabled builds to GTest/Allocator: make integer-overflow tests pass on ASan-enabled builds PLEASE.Dec 13 2020, 10:30 PM
Robert Guetzkow (rjg) retitled this revision from GTest/Allocator: make integer-overflow tests pass on ASan-enabled builds PLEASE to GTest/Allocator: make integer-overflow tests pass on ASan-enabled builds.Dec 14 2020, 12:00 AM
Ankit Meel (ankitm) edited the summary of this revision. (Show Details)Dec 14 2020, 10:52 AM
Ankit Meel (ankitm) edited the summary of this revision. (Show Details)

I do not think the overflow test is properly structured. From my understanding is that the actual intent is to verify MEM_size_safe_multiply is working correct. So, test should directly test MEM_size_safe_multiply(). Making a pass/fail decision based on an indirect indication is not really nice.

build_files/cmake/Modules/GTestAddTests.cmake
63

Not sure why stating "BLENDER" brings value here.
Same applies to cases below.

build_files/cmake/macros.cmake
464

If we go way of silencing warning using environment variable, the environment variable is to be provided by the call where guardedalloc test is added.

Sergey Sharybin (sergey) requested changes to this revision.Jan 8 2021, 4:32 PM
This revision now requires changes to proceed.Jan 8 2021, 4:32 PM
build_files/cmake/Modules/GTestAddTests.cmake
63

That's because the file is a modified copy of a standard GTest file. At the top it states:

# Changes made to this script have been marked with "BLENDER".
Ankit Meel (ankitm) marked 3 inline comments as done.
  • Set envs at call site.

If we go way of silencing warning

That is for you (plural) to decide, I'm just making it work somehow.

@Sybren A. Stüvel (sybren), Eeeh. That's kind of annoying :(

I would say that tests needs to be simple and reliable. Those ASAN flags manipulation doesn't seem to be really robust.

Unless there is really good reason to really do allocation overflow test, I'd say test MEM_size_safe_multiply() and don't do overflow allocation from tests.

@Sybren A. Stüvel (sybren), Eeeh. That's kind of annoying :(

It is, indeed. We could also rename the file, remove the entire idea of keeping track of our changes w.r.t. upstream, and just consider the file "ours". That's out of scope of this patch, though.

I would say that tests needs to be simple and reliable. Those ASAN flags manipulation doesn't seem to be really robust.

Unless there is really good reason to really do allocation overflow test, I'd say test MEM_size_safe_multiply() and don't do overflow allocation from tests.

I don't have an opinion here.

Sybren A. Stüvel (sybren) requested changes to this revision.Jan 18 2021, 11:28 AM

Even when we keep the allocation overflow tests, I don't think the approach in this patch is the correct one for setting environment variables. The way CMake is structured makes it possible to set such variables on a target separate from the definition of the target. For example, look at how LSAN_OPTIONS is set in build_files/cmake/Modules/GTestTesting.cmake:

set_tests_properties(${TARGET_NAME} PROPERTIES ENVIRONMENT LSAN_OPTIONS=exitcode=0)

This can be called at any time after the target has been defined. This means that it's not necessary to add yet another option to the blender_add_test_executable() function and all its invocations, just to have one specific test add one specific environment variable.

This revision now requires changes to proceed.Jan 18 2021, 11:28 AM

For example, look at how LSAN_OPTIONS is set in build_files/cmake/Modules/GTestTesting.cmake:

@Sybren A. Stüvel (sybren) That works because the test target is added before set_tests_properties using add_test.
For GTest, targets are created when ctest is invoked using the "discover" method.
Process is something like (as I understand it) configure -> build test executables -> invoke ctest: ctest -N -> test targets are created -> list of tests is shown.
Since target doesn't exist at configure time, properties cannot be set then.

The ASAN documentation states:

you could also embed default flags in the source code by implementing __asan_default_options function:

const char *__asan_default_options() {
  return "verbosity=1:malloc_context_size=20";
}

I think it would be a cleaner solution to have the offending test built as a separate executable that contains this function. That way the change required would be more localized.