1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <stdint.h> 6 7 #include <memory> 8 9 #include "base/allocator/buildflags.h" 10 #include "base/allocator/partition_allocator/address_pool_manager_bitmap.h" 11 #include "base/allocator/partition_allocator/partition_address_space.h" 12 #include "build/build_config.h" 13 #include "build/buildflag.h" 14 #include "testing/gtest/include/gtest/gtest.h" 15 16 #include "build/rust/tests/test_rust_shared_library/src/lib.rs.h" 17 TEST(RustSharedTest,CppCallingIntoRust_BasicFFI)18TEST(RustSharedTest, CppCallingIntoRust_BasicFFI) { 19 EXPECT_EQ(7, add_two_ints_via_rust(3, 4)); 20 } 21 TEST(RustSharedTest,RustComponentUsesPartitionAlloc)22TEST(RustSharedTest, RustComponentUsesPartitionAlloc) { 23 // Verify that PartitionAlloc is consistently used in C++ and Rust. 24 auto cpp_allocated_int = std::make_unique<int>(); 25 SomeStruct* rust_allocated_ptr = allocate_via_rust().into_raw(); 26 EXPECT_EQ(partition_alloc::IsManagedByPartitionAlloc( 27 reinterpret_cast<uintptr_t>(rust_allocated_ptr)), 28 partition_alloc::IsManagedByPartitionAlloc( 29 reinterpret_cast<uintptr_t>(cpp_allocated_int.get()))); 30 rust::Box<SomeStruct>::from_raw(rust_allocated_ptr); 31 } 32