Skip to content

Commit 016bb87

Browse files
authored
Code style changes to the ArgoDSM tests (#121)
Apply code style changes based on cpplint's feedback. Additionally, make consistent the number of lines between the test class and the first test, in between the individual tests, and between the last test and `main` consistent across the test files as follows: * 2 newlines between the test class and the first test. * 1 newline in between the individual tests. * 2 newlines between the last test and `main`. Finally, fix Doxygen documentation and indentation of OpenMP pragmas.
1 parent bdc6514 commit 016bb87

10 files changed

Lines changed: 213 additions & 206 deletions

File tree

tests/allocators.cpp

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
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
*/
3133
class 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
*/
4948
TEST_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
*/
8887
TEST_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-
125119
TEST_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
*/
156148
TEST_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
*/
168160
TEST_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
*/
179171
TEST_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
*/
189180
TEST_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-
211200
TEST_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
*/
231219
TEST_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) {
251238
const 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));

tests/api.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
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-
7+
// C headers
98
#include <limits.h>
109
#include <unistd.h>
11-
10+
// C++ headers
11+
#include <iostream>
12+
// ArgoDSM headers
1213
#include "argo.hpp"
1314
#include "allocators/collective_allocator.hpp"
1415
#include "backend/backend.hpp"
15-
#include "env/env.hpp"
1616
#include "data_distribution/data_distribution.hpp"
17+
#include "env/env.hpp"
18+
// GoogleTest headers
1719
#include "gtest/gtest.h"
1820

1921
/** @brief ArgoDSM memory size */
@@ -36,7 +38,6 @@ constexpr char c_const = 'a';
3638
* @brief Class for the gtests fixture tests. Will reset the allocators to a clean state for every test
3739
*/
3840
class APITest : public testing::Test {
39-
4041
protected:
4142
APITest() {
4243
argo::reset();
@@ -48,7 +49,6 @@ class APITest : public testing::Test {
4849
};
4950

5051

51-
5252
/**
5353
* @brief Unittest that checks correctness of the
5454
* argo::is_argo_address(T* addr) API function.
@@ -79,24 +79,22 @@ TEST_F(APITest, GetHomeNode) {
7979
char* end = start + argo::backend::global_size();
8080

8181
/* Touch an equal (+/- 1) number of pages per node */
82-
for(std::size_t s=page_size*node_id;
83-
s<alloc_size-1;
84-
s+=page_size*num_nodes) {
82+
for(std::size_t s = page_size*node_id; s < alloc_size-1; s += page_size*num_nodes) {
8583
tmp[s] = c_const;
8684
}
8785
argo::barrier();
8886

8987
/* Test that the number of pages owned by each node is equal (+/- 1) */
9088
std::size_t counter = 0;
9189
std::vector<std::size_t> node_counters(num_nodes);
92-
for(char* c = start; c<end; c+=page_size) {
90+
for(char* c = start; c < end; c += page_size) {
9391
node_counters[argo::get_homenode(c)]++;
9492
counter++;
9593
}
9694
std::size_t pages_per_node = counter/num_nodes;
9795
for(std::size_t& count : node_counters) {
9896
// The owner of the reserved internal page will own
99-
// one more page, some other node will own one less
97+
// one more page, some other node will own one less
10098
ASSERT_TRUE((count >= pages_per_node-1) && (count <= pages_per_node+1));
10199
}
102100
}
@@ -112,13 +110,14 @@ TEST_F(APITest, GetBlockSize) {
112110
std::size_t size_per_node = argo::backend::global_size()/argo::number_of_nodes();
113111
if(dd::is_cyclic_policy()) {
114112
ASSERT_EQ(api_block_size, env_block_size*page_size);
115-
}else if(dd::is_first_touch_policy()){
113+
} else if (dd::is_first_touch_policy()) {
116114
ASSERT_EQ(api_block_size, page_size);
117-
}else{
115+
} else {
118116
ASSERT_EQ(api_block_size, size_per_node);
119117
}
120118
}
121119

120+
122121
/**
123122
* @brief The main function that runs the tests
124123
* @param argc Number of command line arguments

0 commit comments

Comments
 (0)