rambrain
testManagedMemory.cpp
Go to the documentation of this file.
1 /* rambrain - a dynamical physical memory extender
2  * Copyright (C) 2015 M. Imgrund, A. Arth
3  * mimgrund (at) mpifr-bonn.mpg.de
4  * arth (at) usm.uni-muenchen.de
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <gtest/gtest.h>
21 #include "managedMemory.h"
22 #include "dummyManagedMemory.h"
23 #include "cyclicManagedMemory.h"
24 
25 using namespace rambrain;
29 TEST ( managedMemory, Unit_DefaultManagerPresent )
30 {
31  EXPECT_TRUE ( managedMemory::defaultManager != NULL );
32 }
33 
37 TEST ( managedMemory, Unit_DefaultManagerPresentAfterAllocation )
38 {
40  delete mm;
41 
42  EXPECT_TRUE ( managedMemory::defaultManager != NULL );
43 }
44 
48 TEST ( managedMemory, Unit_BaseMemoryUsage )
49 {
50  unsigned int mem = 1000u;
52 
53  EXPECT_EQ ( mem, managedMemory::defaultManager->getMemoryLimit() );
54  EXPECT_EQ ( 0u, managedMemory::defaultManager->getUsedMemory() );
55  EXPECT_EQ ( 0u, managedMemory::defaultManager->getSwappedMemory() );
56 }
57 
61 TEST ( managedMemory, DISABLED_VersionInfo )
62 {
64 }
65 
69 TEST ( managedMemory, Unit_FallbackToDefaultManagerChain )
70 {
72 
74  managedDummySwap *swap2 = new managedDummySwap ( 10 );
75  cyclicManagedMemory *man2 = new cyclicManagedMemory ( swap2, 10 );
77 
78  ASSERT_EQ ( man3, managedMemory::defaultManager );
79 
80  delete man3;
81  ASSERT_EQ ( man2, managedMemory::defaultManager );
82 
83  delete man2;
84  delete swap2;
85  ASSERT_EQ ( man1, managedMemory::defaultManager );
86 
87  delete man1;
88  ASSERT_EQ ( fallbackManager, managedMemory::defaultManager );
89 }
90 
94 TEST ( managedMemory, DISABLED_Unit_FallbackToDefaultManagerChainWrongOrder )
95 {
97 
99  managedDummySwap *swap2 = new managedDummySwap ( 10 );
100  cyclicManagedMemory *man2 = new cyclicManagedMemory ( swap2, 10 );
102 
103  ASSERT_EQ ( man3, managedMemory::defaultManager );
104 
105  delete man3;
106  ASSERT_EQ ( man2, managedMemory::defaultManager );
107 
108  delete man1;
109  ASSERT_EQ ( man2, managedMemory::defaultManager );
110 
111  delete man2;
112  delete swap2;
113  ASSERT_EQ ( man1, managedMemory::defaultManager );
114 
115  // The state of the system is now broken, since man1 does not exist anymore; Can never fall back to fallbackManager
116 }
static void versionInfo()
prints out a GIT version info and a diff on this version at compile time
static managedMemory * defaultManager
TEST(managedMemory, Unit_DefaultManagerPresent)
a dummy managed Memory that basically does nothing and throws on everything.
scheduler working with a double linked cycle. Details see paper.
bool setMemoryLimit(global_bytesize size)
dynamically adjusts allowed ram usage
A dummy swap that just copies swapped out chunks to a different location in ram.
Backend class to handle raw memory and interaction/storage with managedSwap.
Definition: managedMemory.h:68