blob: 92c3924c342828def45be382ca65fbe2ce8de257 [file] [log] [blame]
Brian Silvermanf5f8d8e2015-12-06 18:39:12 -05001#include "aos/testing/test_shm.h"
2
3#include <sys/mman.h>
4
5#include "aos/common/queue.h"
6#include "aos/common/logging/logging.h"
7#include "aos/testing/test_logging.h"
8
9namespace aos {
10namespace testing {
11namespace {
12
13const size_t kCoreSize = 0x100000;
14
15} // namespace
16
17TestSharedMemory::TestSharedMemory() {
18 global_core = &global_core_data_;
19 global_core->owner = true;
20 // Use mmap(2) manually instead of through malloc(3) so that we can pass
21 // MAP_SHARED which allows forked processes to communicate using the
22 // "shared" memory.
23 void *memory = mmap(NULL, kCoreSize, PROT_READ | PROT_WRITE,
24 MAP_SHARED | MAP_ANONYMOUS, -1, 0);
25 CHECK_NE(memory, MAP_FAILED);
26
27 aos_core_use_address_as_shared_mem(memory, kCoreSize);
28
29 ::aos::testing::EnableTestLogging();
30}
31
32TestSharedMemory::~TestSharedMemory() {
33 PCHECK(munmap(global_core->mem_struct, kCoreSize));
34 global_core = NULL;
35}
36
37} // namespace testing
38} // namespace aos