// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include <limits> #include "base/check.h" #include "base/run_loop.h" #include "base/test/task_environment.h" #include "build/build_config.h" #include "components/cronet/native/test/test_util.h" #include "cronet_c.h" #include "partition_alloc/buildflags.h" #include "testing/gtest/include/gtest/gtest.h" namespace { class BufferTest : public ::testing::Test { … }; const uint64_t kTestBufferSize = …; // static void BufferTest::BufferCallback_OnDestroy(Cronet_BufferCallbackPtr self, Cronet_BufferPtr buffer) { … } // Test on_destroy that destroys the buffer set in context. void TestRunnable_DestroyBuffer(Cronet_RunnablePtr self) { … } // Example of allocating buffer with reasonable size. TEST_F(BufferTest, TestInitWithAlloc) { … } #if defined(ARCH_CPU_64_BITS) && \ (defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ defined(THREAD_SANITIZER) || \ PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) || BUILDFLAG(IS_CHROMEOS) || \ BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_FUCHSIA)) // - ASAN and MSAN malloc by default triggers crash instead of returning null on // failure. // - PartitionAlloc malloc also crashes on allocation failure by design. // - Fuchsia malloc() also crashes on allocation failure in some kernel builds. // - On Linux and Chrome OS, the allocator shims crash for large allocations, on // purpose. #define MAYBE_TestInitWithHugeAllocFails … #else #define MAYBE_TestInitWithHugeAllocFails … #endif // Verify behaviour when an unsatisfiably huge buffer allocation is requested. // On 32-bit platforms, we want to ensure that a 64-bit range allocation size // is rejected, rather than resulting in a 32-bit truncated allocation. // Some platforms over-commit allocations, so we request an allocation of the // whole 64-bit address-space, which cannot possibly be satisfied in a 32- or // 64-bit process. TEST_F(BufferTest, MAYBE_TestInitWithHugeAllocFails) { … } // Example of initializing buffer with app-allocated data. TEST_F(BufferTest, TestInitWithDataAndCallback) { … } // Example of posting application on_destroy to the executor and passing // buffer to it, expecting buffer to be destroyed and freed. TEST_F(BufferTest, TestCronetBufferAsync) { … } } // namespace