44 * @copyright Eta Scale AB. Licensed under the Eta Scale Open Source License. See the LICENSE file for details.
55 */
66
7- #include < iostream>
8- #include < tuple>
9-
7+ // C headers
108#include < limits.h>
119#include < unistd.h>
12-
10+ // C++ headers
11+ #include < iostream>
12+ #include < tuple>
13+ // ArgoDSM headers
1314#include " argo.hpp"
14- #include " allocators/generic_allocator.hpp"
1515#include " allocators/collective_allocator.hpp"
16+ #include " allocators/generic_allocator.hpp"
1617#include " allocators/null_lock.hpp"
1718#include " backend/backend.hpp"
19+ // GoogleTest headers
1820#include " gtest/gtest.h"
1921
2022/* * @brief ArgoDSM memory size */
@@ -29,7 +31,6 @@ extern mem::global_memory_pool<>* default_global_mempool;
2931 * @brief Class for the gtests fixture tests. Will reset the allocators to a clean state for every test
3032 */
3133class AllocatorTest : public testing ::Test {
32-
3334 protected:
3435 AllocatorTest () {
3536 argo::reset ();
@@ -41,13 +42,11 @@ class AllocatorTest : public testing::Test {
4142};
4243
4344
44-
45-
4645/* *
4746 * @brief Unittest that checks that the global address space is at least as large as requested
4847 */
4948TEST_F (AllocatorTest, InitialSize) {
50- ASSERT_GE (default_global_mempool->available (),size - mem::global_memory_pool<>::reserved);
49+ ASSERT_GE (default_global_mempool->available (), size - mem::global_memory_pool<>::reserved);
5150}
5251
5352/* *
@@ -87,7 +86,7 @@ TEST_F(AllocatorTest, Collective200MBTwiceAlloc) {
8786 */
8887TEST_F (AllocatorTest, CollectiveAllocRequestedSize) {
8988 ASSERT_NO_THROW (collective_alloc (size - mem::global_memory_pool<>::reserved));
90- ASSERT_GE (default_global_mempool->available (),std::size_t {0 });
89+ ASSERT_GE (default_global_mempool->available (), std::size_t {0 });
9190}
9291
9392/* *
@@ -97,9 +96,6 @@ TEST_F(AllocatorTest, CollectiveAllocAll) {
9796 ASSERT_NO_THROW (collective_alloc (default_global_mempool->available ()));
9897}
9998
100-
101-
102-
10399/* *
104100 * @brief Unittest that checks that allocating all memory available collectively and then checks that allocating more bytes will throw an exception
105101 */
@@ -109,7 +105,6 @@ TEST_F(AllocatorTest, CollectiveAllocAllAndExceedLimit) {
109105 ASSERT_ANY_THROW (collective_alloc (1 ));
110106}
111107
112-
113108/* *
114109 * @brief Unittest that checks that allocating more memory than what is available collectively
115110 */
@@ -121,21 +116,18 @@ TEST_F(AllocatorTest, CollectiveAllocExceedLimit) {
121116/* *
122117 * @brief Unittest that checks that allocating more memory than what is available collectively
123118 */
124-
125119TEST_F (AllocatorTest, CollectiveAllocLoopExceedLimit) {
126- std::size_t allocsize= 7 ;
127- while (default_global_mempool->available () >= allocsize){
120+ std::size_t allocsize = 7 ;
121+ while (default_global_mempool->available () >= allocsize) {
128122 ASSERT_NO_THROW (collective_alloc (allocsize));
129123 allocsize *= 2 ;
130124 }
131125 ASSERT_NO_THROW (collective_alloc (default_global_mempool->available ()));
132126 ASSERT_ANY_THROW (collective_alloc (1 ));
133127}
134128
135-
136129/* Tests using dynamic allocator */
137130
138-
139131/* *
140132 * @brief Unittest that checks that allocating 0 bytes dynamically by all nodes is allowed
141133 */
@@ -154,7 +146,7 @@ TEST_F(AllocatorTest, DynamicAllocOneByteDynamically) {
154146 * @brief Unittest that checks that allocating a few different sizes by all nodes dynamically
155147 */
156148TEST_F (AllocatorTest, DynamicCommonAlloc) {
157- if (static_cast <unsigned int >(argo::number_of_nodes ())*1111 >= default_global_mempool->available ()){
149+ if (static_cast <unsigned int >(argo::number_of_nodes ())*1111 >= default_global_mempool->available ()) {
158150 ASSERT_NO_THROW (dynamic_alloc (1 ));
159151 ASSERT_NO_THROW (dynamic_alloc (10 ));
160152 ASSERT_NO_THROW (dynamic_alloc (100 ));
@@ -166,36 +158,34 @@ TEST_F(AllocatorTest, DynamicCommonAlloc) {
166158 * @brief Unittest that checks that node 0 allocating the whole requested memory space dynamically - also checks that the remaining memory is non-negative
167159 */
168160TEST_F (AllocatorTest, DynamicAllocRequestedSize) {
169- if (argo::node_id () == 0 ){
161+ if (argo::node_id () == 0 ) {
170162 ASSERT_NO_THROW (dynamic_alloc (size - mem::global_memory_pool<>::reserved));
171163 }
172164 argo::barrier ();
173- ASSERT_GE (default_global_mempool->available (),std::size_t {0 });
165+ ASSERT_GE (default_global_mempool->available (), std::size_t {0 });
174166}
175167
176168/* *
177169 * @brief Unittest that checks that node N-1 allocating all memory available dynamically does not throw exceptions
178170 */
179171TEST_F (AllocatorTest, DynamicAllocAll) {
180- if (argo::node_id () == argo::number_of_nodes ()-1 ){
172+ if (argo::node_id () == argo::number_of_nodes ()-1 ) {
181173 ASSERT_NO_THROW (dynamic_alloc (default_global_mempool->available ()));
182174 }
183175}
184176
185-
186177/* *
187178 * @brief Unittest that checks that node N-1 allocating all memory available dynamically and then checks that allocating more bytes will throw an exception
188179 */
189180TEST_F (AllocatorTest, DynamicAllocAllAndExceedLimit) {
190- if (argo::node_id () == argo::number_of_nodes ()*0 +1 -1 ){
181+ if (argo::node_id () == argo::number_of_nodes ()*0 +1 -1 ) {
191182 ASSERT_NO_THROW (dynamic_alloc (default_global_mempool->available ()));
192183 }
193- // ASSERT_NO_THROW(dynamic_alloc(0)); /* Should always be legal */
184+ // ASSERT_NO_THROW(dynamic_alloc(0)); /* Should always be legal */
194185 argo::barrier ();
195186 ASSERT_ANY_THROW (dynamic_alloc (1 ));
196187}
197188
198-
199189/* *
200190 * @brief Unittest that checks that allocating more memory than what is available dynamically
201191 */
@@ -207,10 +197,9 @@ TEST_F(AllocatorTest, DynamicAllocExceedLimit) {
207197/* *
208198 * @brief Unittest that checks that allocating more memory than what is available dynamically
209199 */
210-
211200TEST_F (AllocatorTest, DynamicAllocLoopExceedLimit) {
212- std::size_t allocsize= 7 ;
213- while (default_global_mempool->available () >= 2 *allocsize && argo::node_id ()== 0 ) {
201+ std::size_t allocsize = 7 ;
202+ while (default_global_mempool->available () >= 2 *allocsize && argo::node_id () == 0 ) {
214203 ASSERT_NO_THROW (dynamic_alloc (allocsize));
215204 allocsize *= 2 ;
216205 }
@@ -221,25 +210,23 @@ TEST_F(AllocatorTest, DynamicAllocLoopExceedLimit) {
221210 argo::barrier ();
222211 ASSERT_ANY_THROW (dynamic_alloc (1 ));
223212 argo::barrier ();
224-
225213}
226214
227215/* *
228216 * @brief Unittest that checks the case of node N-1 allocating all the
229217 * available memory dynamically
230218 */
231219TEST_F (AllocatorTest, DynamicAllocAllNodes) {
232- std::size_t allocsize= 7 ;
220+ std::size_t allocsize = 7 ;
233221
234222 /* Node N-1*/
235223 if (argo::node_id () == argo::number_of_nodes ()-1 ) {
236- while (default_global_mempool->available () > allocsize){
224+ while (default_global_mempool->available () > allocsize) {
237225 ASSERT_NO_THROW (dynamic_alloc (allocsize));
238226 allocsize *= 2 ;
239227 }
240228 ASSERT_NO_THROW (dynamic_alloc (default_global_mempool->available ()));
241229 ASSERT_ANY_THROW (dynamic_alloc (1 ));
242-
243230 }
244231}
245232
@@ -251,12 +238,12 @@ TEST_F(AllocatorTest, DynamicAllocAllNodes) {
251238const int entries = 10 ;
252239
253240/* *
254- *@brief mixes dynamic and collective allocation and stores dynamic arrays in a collective arrays to communicate values, also stresses allocation.
241+ * @brief mixes dynamic and collective allocation and stores dynamic arrays in a collective arrays to communicate values, also stresses allocation.
255242 */
256- TEST_F (AllocatorTest, StoringDynamicArrayInCollective){
243+ TEST_F (AllocatorTest, StoringDynamicArrayInCollective) {
257244 int *dynamic_arr = argo::new_array<int >(entries);
258245
259- for (int i = 0 ; i < entries; i++){
246+ for (int i = 0 ; i < entries; i++) {
260247 dynamic_arr[i] = argo::node_id ()+i*10 ;
261248 }
262249
@@ -265,8 +252,8 @@ TEST_F(AllocatorTest, StoringDynamicArrayInCollective){
265252 collective_arr[argo::node_id ()] = dynamic_arr;
266253 argo::barrier ();
267254
268- for (argo::num_nodes_t i = 0 ; i < argo::number_of_nodes (); i++){
269- for (unsigned int j = 0 ; j < entries; j++){
255+ for (argo::num_nodes_t i = 0 ; i < argo::number_of_nodes (); i++) {
256+ for (unsigned int j = 0 ; j < entries; j++) {
270257 if (argo::node_id () == 0 ) {
271258 ASSERT_TRUE (collective_arr[i][j] == static_cast <int >(i+j*10 ));
272259 }
@@ -278,7 +265,7 @@ TEST_F(AllocatorTest, StoringDynamicArrayInCollective){
278265 argo::delete_array (dynamic_arr);
279266
280267 argo::barrier ();
281- for (int i = 0 ; i < 100 ; i++){
268+ for (int i = 0 ; i < 100 ; i++) {
282269 dynamic_arr = argo::new_array<int >(i*10 );
283270 collective_arr = argo::conew_array<int *>(10 );
284271 argo::delete_array (dynamic_arr);
@@ -293,18 +280,18 @@ TEST_F(AllocatorTest, StoringDynamicArrayInCollective){
293280 int *collective_arr2 = argo::conew_array<int >(entries);
294281
295282 argo::barrier ();
296- for (int i = 0 ; i < entries; i++){
283+ for (int i = 0 ; i < entries; i++) {
297284 dynamic_arr[i] = argo::node_id ()+i*11 ;
298- if ((i%argo::number_of_nodes ()) == argo::node_id ()){
299- collective_arr2[i]= i;
285+ if ((i%argo::number_of_nodes ()) == argo::node_id ()) {
286+ collective_arr2[i] = i;
300287 }
301288 }
302289
303290 collective_arr[argo::node_id ()] = dynamic_arr;
304291 argo::barrier ();
305- for (argo::num_nodes_t i = 0 ; i < argo::number_of_nodes (); i++){
306- for (unsigned int j = 0 ; j < entries; j++){
307- // std::cout << "collective_arr : " << j << "," << i << " => "<< collective_arr[i][j] << " i+j*11 " << i+(j*11)<< std::endl;
292+ for (argo::num_nodes_t i = 0 ; i < argo::number_of_nodes (); i++) {
293+ for (unsigned int j = 0 ; j < entries; j++) {
294+ // std::cout << "collective_arr : " << j << "," << i << " => "<< collective_arr[i][j] << " i+j*11 " << i+(j*11)<< std::endl;
308295 // std::cout << "collective_arr2 : " << j << " => "<< collective_arr2[j] << std::endl;
309296 ASSERT_TRUE (collective_arr[i][j] == static_cast <int >(i+j*11 ));
310297 ASSERT_TRUE (collective_arr2[j] == static_cast <int >(j));
0 commit comments