1// Copyright 2014 The Chromium Authors. All rights reserved.
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 "crazy_linker_ashmem.h"
6
7#include <sys/mman.h>
8
9#include <minitest/minitest.h>
10
11namespace crazy {
12
13TEST(AshmemRegion, Construction) {
14  AshmemRegion region;
15  EXPECT_EQ(-1, region.fd());
16}
17
18TEST(AshmemRegion, Allocate) {
19  AshmemRegion region;
20  const size_t kSize = 4096 * 10;
21  EXPECT_TRUE(region.Allocate(kSize, __FUNCTION__));
22  void* map = ::mmap(NULL,
23                     kSize,
24                     PROT_READ | PROT_WRITE,
25                     MAP_ANONYMOUS | MAP_SHARED,
26                     region.fd(),
27                     0);
28  EXPECT_NE(MAP_FAILED, map);
29
30  for (size_t n = 0; n < kSize; ++n) {
31    TEST_TEXT << "Checking region[" << n << "]";
32    EXPECT_EQ(0, ((char*)map)[n]);
33  }
34
35  EXPECT_EQ(0, ::munmap(map, kSize));
36}
37
38}  // namespace crazy
39