#include "partition_alloc/tagging.h"
#include <cstdint>
#include "partition_alloc/build_config.h"
#include "partition_alloc/buildflags.h"
#include "partition_alloc/page_allocator.h"
#include "partition_alloc/partition_alloc_base/cpu.h"
#include "partition_alloc/partition_alloc_config.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace partition_alloc::internal {
TEST(PartitionAllocMemoryTaggingTest, TagMemoryRangeRandomlySafe) { … }
TEST(PartitionAllocMemoryTaggingTest, TagMemoryRangeIncrementSafe) { … }
#if PA_BUILDFLAG(PA_ARCH_CPU_64_BITS)
TEST(PartitionAllocMemoryTaggingTest, TagMemoryRangeBadSz) { … }
TEST(PartitionAllocMemoryTaggingTest, TagMemoryRangeRandomlyNoSz) { … }
TEST(PartitionAllocMemoryTaggingTest, TagMemoryRangeRandomlyBadAlign) { … }
TEST(PartitionAllocMemoryTaggingTest, TagMemoryRangeIncrementBadSz) { … }
TEST(PartitionAllocMemoryTaggingTest, TagMemoryRangeIncrementNoSz) { … }
TEST(PartitionAllocMemoryTaggingTest, TagMemoryRangeIncrementBadAlign) { … }
#endif
#if PA_BUILDFLAG(HAS_MEMORY_TAGGING)
#if PA_BUILDFLAG(IS_ANDROID)
TEST(PartitionAllocMemoryTaggingTest,
ChangeMemoryTaggingModeForAllThreadsPerProcess) {
base::CPU cpu;
if (!cpu.has_mte()) {
GTEST_SKIP();
}
EXPECT_EQ(GetMemoryTaggingModeForCurrentThread(),
TagViolationReportingMode::kSynchronous);
bool success = ChangeMemoryTaggingModeForAllThreadsPerProcess(
TagViolationReportingMode::kAsynchronous);
EXPECT_TRUE(success);
EXPECT_EQ(GetMemoryTaggingModeForCurrentThread(),
TagViolationReportingMode::kAsynchronous);
success = ChangeMemoryTaggingModeForAllThreadsPerProcess(
TagViolationReportingMode::kSynchronous);
EXPECT_TRUE(success);
EXPECT_EQ(GetMemoryTaggingModeForCurrentThread(),
TagViolationReportingMode::kSynchronous);
}
#endif
TEST(PartitionAllocMemoryTaggingTest, ChangeMemoryTaggingModeForCurrentThread) {
base::CPU cpu;
if (!cpu.has_mte()) {
GTEST_SKIP();
}
TagViolationReportingMode original_mode =
GetMemoryTaggingModeForCurrentThread();
ChangeMemoryTaggingModeForCurrentThread(TagViolationReportingMode::kDisabled);
EXPECT_EQ(GetMemoryTaggingModeForCurrentThread(),
TagViolationReportingMode::kDisabled);
ChangeMemoryTaggingModeForCurrentThread(
TagViolationReportingMode::kSynchronous);
EXPECT_EQ(GetMemoryTaggingModeForCurrentThread(),
TagViolationReportingMode::kSynchronous);
ChangeMemoryTaggingModeForCurrentThread(
TagViolationReportingMode::kAsynchronous);
EXPECT_EQ(GetMemoryTaggingModeForCurrentThread(),
TagViolationReportingMode::kAsynchronous);
ChangeMemoryTaggingModeForCurrentThread(
TagViolationReportingMode::kSynchronous);
EXPECT_EQ(GetMemoryTaggingModeForCurrentThread(),
TagViolationReportingMode::kSynchronous);
ChangeMemoryTaggingModeForCurrentThread(TagViolationReportingMode::kDisabled);
EXPECT_EQ(GetMemoryTaggingModeForCurrentThread(),
TagViolationReportingMode::kDisabled);
ChangeMemoryTaggingModeForCurrentThread(
TagViolationReportingMode::kAsynchronous);
EXPECT_EQ(GetMemoryTaggingModeForCurrentThread(),
TagViolationReportingMode::kAsynchronous);
ChangeMemoryTaggingModeForCurrentThread(original_mode);
}
#endif
}