1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
5 #include "tests_common.hpp"
6 #include "mock_allocator.hpp"
10 class LockedMemoryTest : public TestsCommon {
12 unique_ptr<MockAllocator> createMockAllocator() {
13 return unique_ptr<MockAllocator>(new MockAllocator());
17 using namespace InferenceEngine;
18 using namespace ::testing;
21 TEST_F(LockedMemoryTest, canUnlockMemoryAfterUsage) {
23 auto allocator = createMockAllocator();
25 char array [] = {1,2,3};
27 EXPECT_CALL(*allocator.get(), lock((void*)1, _)).WillRepeatedly(Return((void*)array));
28 EXPECT_CALL(*allocator.get(), unlock(_)).Times(1);
30 auto x = LockedMemory<char>(allocator.get(), (void *) 1, 1);
31 //force locking of memory
37 TEST_F(LockedMemoryTest, canReadFromLockedMemory) {
39 auto allocator = createMockAllocator();
41 char array [] = {1,2,3,4,5};
43 EXPECT_CALL(*allocator.get(), lock((void*)1, _)).WillRepeatedly(Return((void*)array));
44 EXPECT_CALL(*allocator.get(), unlock(_)).Times(1);
46 auto x = LockedMemory<char>(allocator.get(), (void *) 1, 0);
47 //we are getting first element
53 TEST_F(LockedMemoryTest, canWriteToLockedMemory) {
55 auto allocator = createMockAllocator();
57 char array [] = {1,2,3,4,5};
59 EXPECT_CALL(*allocator.get(), lock((void*)1, _)).WillRepeatedly(Return((void*)array));
60 EXPECT_CALL(*allocator.get(), unlock(_)).Times(1);
62 auto x = LockedMemory<char>(allocator.get(), (void *) 1, 0);
64 //we are getting first element
65 ASSERT_EQ(std::distance(array, &x[0]), 0);
68 EXPECT_EQ(array[0], 5);