Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / tests / unit / inference_engine_tests / alocator_tests.cpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #include <gtest/gtest.h>
6 #include <gmock/gmock-spec-builders.h>
7
8 #include "ie_allocator.hpp"
9
10 using namespace ::testing;
11 using namespace std;
12 using namespace InferenceEngine;
13
14 class SystemAllocatorTests: public ::testing::Test {
15 protected:
16     virtual void TearDown() {
17     }
18
19     virtual void SetUp() {
20         allocator = details::shared_from_irelease(CreateDefaultAllocator());
21     }
22     std::shared_ptr<IAllocator> allocator;
23 public:
24
25 };
26
27 TEST_F(SystemAllocatorTests, canAllocate) {
28     void* handle = allocator->alloc(100);
29     EXPECT_NE(nullptr, handle);
30     allocator->free(handle);
31 }
32
33 TEST_F(SystemAllocatorTests, canLockAllocatedMemory) {
34     //large block such as 10k will result in sigsegv if not allocated
35     void * handle  = allocator->alloc(10000);
36     char * ptr = (char *)allocator->lock(handle);
37     ptr [9999] = 11;
38     ASSERT_EQ(ptr[9999], 11);
39     allocator->unlock(ptr);
40     allocator->free(handle);
41 }