13fa38318SNico Weber //===-- bytemap_test.cpp ----------------------------------------*- C++ -*-===// 23fa38318SNico Weber // 33fa38318SNico Weber // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 43fa38318SNico Weber // See https://llvm.org/LICENSE.txt for license information. 53fa38318SNico Weber // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 63fa38318SNico Weber // 73fa38318SNico Weber //===----------------------------------------------------------------------===// 83fa38318SNico Weber 9*0d3d4d3bSKostya Kortchinsky #include "tests/scudo_unit_test.h" 10*0d3d4d3bSKostya Kortchinsky 113fa38318SNico Weber #include "bytemap.h" 123fa38318SNico Weber 13*0d3d4d3bSKostya Kortchinsky #include <pthread.h> 143fa38318SNico Weber #include <string.h> 153fa38318SNico Weber testMap(T & Map,scudo::uptr Size)163fa38318SNico Webertemplate <typename T> void testMap(T &Map, scudo::uptr Size) { 173fa38318SNico Weber Map.init(); 183fa38318SNico Weber for (scudo::uptr I = 0; I < Size; I += 7) 193fa38318SNico Weber Map.set(I, (I % 100) + 1); 203fa38318SNico Weber for (scudo::uptr J = 0; J < Size; J++) { 213fa38318SNico Weber if (J % 7) 223fa38318SNico Weber EXPECT_EQ(Map[J], 0); 233fa38318SNico Weber else 243fa38318SNico Weber EXPECT_EQ(Map[J], (J % 100) + 1); 253fa38318SNico Weber } 263fa38318SNico Weber } 273fa38318SNico Weber TEST(ScudoByteMapTest,FlatByteMap)283fa38318SNico WeberTEST(ScudoByteMapTest, FlatByteMap) { 293fa38318SNico Weber const scudo::uptr Size = 1U << 10; 303fa38318SNico Weber scudo::FlatByteMap<Size> Map; 313fa38318SNico Weber testMap(Map, Size); 323fa38318SNico Weber Map.unmapTestOnly(); 333fa38318SNico Weber } 34