GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: TESTS/TEST_TENSOR_MESSAGE/main.cpp Lines: 122 122 100.0 %
Date: 2026-03-27 22:08:32 Branches: 136 136 100.0 %

Line Branch Exec Source
1
/***************************************
2
	Auteur : Pierre Aubert
3
	Mail : pierre.aubert@lapp.in2p3.fr
4
	Licence : CeCILL-C
5
****************************************/
6
7
#include <sstream>
8
#include "PTensor.h"
9
#include "tensor_check.h"
10
11
///Test the Tensor with one dimension
12
/**	@param testName : name of the test
13
 * 	@param mode : allocation mode
14
 * 	@param nbElement : number of element of the tensor
15
 * 	@return true on success, false otherwise
16
*/
17
template<typename T>
18
132
bool testMessageTensor1d(const std::string & testName, AllocMode::AllocMode mode, size_t nbElement){
19
264
	PTensor<T> tensor(mode, nbElement);
20
12276
	for(size_t i(0lu); i < nbElement; ++i){
21
12144
		tensor.setValue(i, (T)(2lu*i + 1lu));
22
	}
23
264
	std::vector<char> messageData(data_size(tensor));
24
132
	char* iterMsg = (char*)messageData.data();
25
132
	bool b(true);
26
132
	b &= data_message_save(iterMsg, tensor);			//Save the message
27
28
264
	PTensor<T> loadTensor;
29
30
132
	char* loadIterMsg = (char*)messageData.data();
31
132
	b &= data_message_load(loadIterMsg, loadTensor);		//Load the message
32
33
132
	std::stringstream str;
34
132
	str << (int)mode;
35

132
	b &= checkTensor(testName + " " + str.str(), tensor, loadTensor);
36


132
	std::cout << "testMessageTensor1d("<<testName<<" " << str.str() <<") : b = " << b << std::endl;
37
264
	return b;
38
}
39
40
///Test the Tensor with one dimension
41
/**	@param testName : name of the test
42
 * 	@param nbElement : number of element of the tensor
43
 * 	@return true on success, false otherwise
44
*/
45
template<typename T>
46
44
bool testMessageModeTensor1d(const std::string & testName, size_t nbElement){
47
44
	bool b(true);
48
44
	b &= testMessageTensor1d<T>(testName, AllocMode::NONE, nbElement);
49
44
	b &= testMessageTensor1d<T>(testName, AllocMode::ALIGNED, nbElement);
50
44
	b &= testMessageTensor1d<T>(testName, AllocMode::PADDING, nbElement);
51
44
	return b;
52
}
53
54
///Test the Tensor with one dimension
55
/**	@param nbElement : number of element of the tensor
56
 * 	@return true on success, false otherwise
57
*/
58
2
bool testMessageTensor1(size_t nbElement){
59
2
	bool b(true);
60
2
	b &= testMessageModeTensor1d<bool>("bool", nbElement);
61
2
	b &= testMessageModeTensor1d<char>("char", nbElement);
62
2
	b &= testMessageModeTensor1d<short>("short", nbElement);
63
2
	b &= testMessageModeTensor1d<int>("int", nbElement);
64
2
	b &= testMessageModeTensor1d<long int>("long int", nbElement);
65
66
2
	b &= testMessageModeTensor1d<unsigned char>("unsigned char", nbElement);
67
2
	b &= testMessageModeTensor1d<unsigned short>("unsigned short", nbElement);
68
2
	b &= testMessageModeTensor1d<unsigned int>("unsigned int", nbElement);
69
2
	b &= testMessageModeTensor1d<long unsigned int>("long unsigned int", nbElement);
70
71
2
	b &= testMessageModeTensor1d<float>("float", nbElement);
72
2
	b &= testMessageModeTensor1d<double>("double", nbElement);
73
74
2
	return b;
75
}
76
77
78
///Test the Tensor with one dimension
79
/**	@param testName : name of the test
80
 * 	@param mode : allocation mode
81
 * 	@param nbRow : number of rows of the tensor
82
 * 	@param nbCol : number of columns of the tensor
83
 * 	@return true on success, false otherwise
84
*/
85
template<typename T>
86
264
bool testMessageTensor2d(const std::string & testName, AllocMode::AllocMode mode, size_t nbRow, size_t nbCol){
87
528
	PTensor<T> tensor(mode, nbRow, nbCol);
88
23298
	for(size_t i(0lu); i < nbRow; ++i){
89
975018
		for(size_t j(0lu); j < nbCol; ++j){
90
951984
			tensor.setValue(i, j, (T)(2lu*(i*nbCol + j) + 1lu));
91
		}
92
	}
93
94
528
	std::vector<char> messageData(data_size(tensor));
95
264
	char* iterMsg = (char*)messageData.data();
96
264
	bool b(true);
97
264
	b &= data_message_save(iterMsg, tensor);			//Save the message
98
99
528
	PTensor<T> loadTensor;
100
101
264
	char* loadIterMsg = (char*)messageData.data();
102
264
	b &= data_message_load(loadIterMsg, loadTensor);		//Load the message
103
104
264
	std::stringstream str;
105
264
	str << (int)mode;
106

264
	b &= checkTensor(testName + " " + str.str(), tensor, loadTensor);
107


264
	std::cout << "testMessageTensor2d("<<testName<<" " << str.str() <<") : b = " << b << std::endl;
108
528
	return b;
109
}
110
111
///Test the Tensor with one dimension
112
/**	@param testName : name of the test
113
 * 	@param nbRow : number of rows of the tensor
114
 * 	@param nbCol : number of columns of the tensor
115
 * 	@return true on success, false otherwise
116
*/
117
template<typename T>
118
88
bool testMessageModeTensor2d(const std::string & testName, size_t nbRow, size_t nbCol){
119
88
	bool b(true);
120
88
	b &= testMessageTensor2d<T>(testName, AllocMode::NONE, nbRow, nbCol);
121
88
	b &= testMessageTensor2d<T>(testName, AllocMode::ALIGNED, nbRow, nbCol);
122
88
	b &= testMessageTensor2d<T>(testName, AllocMode::PADDING, nbRow, nbCol);
123
88
	return b;
124
}
125
126
///Test the Tensor with one dimension
127
/**	@param nbRow : number of rows of the tensor
128
 * 	@param nbCol : number of columns of the tensor
129
 * 	@return true on success, false otherwise
130
*/
131
4
bool testMessageTensor2(size_t nbRow, size_t nbCol){
132
4
	bool b(true);
133
4
	b &= testMessageModeTensor2d<bool>("bool", nbRow, nbCol);
134
4
	b &= testMessageModeTensor2d<char>("char", nbRow, nbCol);
135
4
	b &= testMessageModeTensor2d<short>("short", nbRow, nbCol);
136
4
	b &= testMessageModeTensor2d<int>("int", nbRow, nbCol);
137
4
	b &= testMessageModeTensor2d<long int>("long int", nbRow, nbCol);
138
139
4
	b &= testMessageModeTensor2d<unsigned char>("unsigned char", nbRow, nbCol);
140
4
	b &= testMessageModeTensor2d<unsigned short>("unsigned short", nbRow, nbCol);
141
4
	b &= testMessageModeTensor2d<unsigned int>("unsigned int", nbRow, nbCol);
142
4
	b &= testMessageModeTensor2d<long unsigned int>("long unsigned int", nbRow, nbCol);
143
144
4
	b &= testMessageModeTensor2d<float>("float", nbRow, nbCol);
145
4
	b &= testMessageModeTensor2d<double>("double", nbRow, nbCol);
146
147
4
	return b;
148
}
149
150
///Test the Tensor with one dimension
151
/**	@param testName : name of the test
152
 * 	@param mode : allocation mode
153
 * 	@param nbSlice : number of slices of the tensor
154
 * 	@param nbRow : number of rows of the tensor
155
 * 	@param nbCol : number of columns of the tensor
156
 * 	@return true on success, false otherwise
157
*/
158
template<typename T>
159
264
bool testMessageTensor3d(const std::string & testName, AllocMode::AllocMode mode, size_t nbSlice, size_t nbRow, size_t nbCol){
160
528
	PTensor<T> tensor(mode, nbSlice, nbRow, nbCol);
161
100254
	for(size_t i(0lu); i < nbSlice*nbRow; ++i){
162
4126782
		for(size_t j(0lu); j < nbCol; ++j){
163
4026792
			tensor.setValue(i, j, (T)(2lu*(i*nbCol + j) + 1lu));
164
		}
165
	}
166
528
	std::vector<char> messageData(data_size(tensor));
167
264
	char* iterMsg = (char*)messageData.data();
168
264
	bool b(true);
169
264
	b &= data_message_save(iterMsg, tensor);			//Save the message
170
171
528
	PTensor<T> loadTensor;
172
173
264
	char* loadIterMsg = (char*)messageData.data();
174
264
	b &= data_message_load(loadIterMsg, loadTensor);		//Load the message
175
176
264
	std::stringstream str;
177
264
	str << (int)mode;
178

264
	b &= checkTensor(testName + " " + str.str(), tensor, loadTensor);
179


264
	std::cout << "testMessageTensor3d("<<testName<<" " << str.str() <<") : b = " << b << std::endl;
180
528
	return b;
181
}
182
183
///Test the Tensor with one dimension
184
/**	@param testName : name of the test
185
 * 	@param nbSlice : number of slices of the tensor
186
 * 	@param nbRow : number of rows of the tensor
187
 * 	@param nbCol : number of columns of the tensor
188
 * 	@return true on success, false otherwise
189
*/
190
template<typename T>
191
88
bool testMessageModeTensor3d(const std::string & testName, size_t nbSlice, size_t nbRow, size_t nbCol){
192
88
	bool b(true);
193
88
	b &= testMessageTensor3d<T>(testName, AllocMode::NONE, nbSlice, nbRow, nbCol);
194
88
	b &= testMessageTensor3d<T>(testName, AllocMode::ALIGNED, nbSlice, nbRow, nbCol);
195
88
	b &= testMessageTensor3d<T>(testName, AllocMode::PADDING, nbSlice, nbRow, nbCol);
196
88
	return b;
197
}
198
199
///Test the Tensor with one dimension
200
/**	@param nbSlice : number of slices of the tensor
201
 * 	@param nbRow : number of rows of the tensor
202
 * 	@param nbCol : number of columns of the tensor
203
 * 	@return true on success, false otherwise
204
*/
205
4
bool testMessageTensor3(size_t nbSlice, size_t nbRow, size_t nbCol){
206
4
	bool b(true);
207
4
	b &= testMessageModeTensor3d<bool>("bool", nbSlice, nbRow, nbCol);
208
4
	b &= testMessageModeTensor3d<char>("char", nbSlice, nbRow, nbCol);
209
4
	b &= testMessageModeTensor3d<short>("short", nbSlice, nbRow, nbCol);
210
4
	b &= testMessageModeTensor3d<int>("int", nbSlice, nbRow, nbCol);
211
4
	b &= testMessageModeTensor3d<long int>("long int", nbSlice, nbRow, nbCol);
212
213
4
	b &= testMessageModeTensor3d<unsigned char>("unsigned char", nbSlice, nbRow, nbCol);
214
4
	b &= testMessageModeTensor3d<unsigned short>("unsigned short", nbSlice, nbRow, nbCol);
215
4
	b &= testMessageModeTensor3d<unsigned int>("unsigned int", nbSlice, nbRow, nbCol);
216
4
	b &= testMessageModeTensor3d<long unsigned int>("long unsigned int", nbSlice, nbRow, nbCol);
217
218
4
	b &= testMessageModeTensor3d<float>("float", nbSlice, nbRow, nbCol);
219
4
	b &= testMessageModeTensor3d<double>("double", nbSlice, nbRow, nbCol);
220
221
4
	return b;
222
}
223
224
1
int main(int argc, char** argv){
225
1
	bool b(testMessageTensor1(42lu));
226
1
	b &= testMessageTensor1(142lu);
227
1
	b &= testMessageTensor2(42lu, 21lu);
228
1
	b &= testMessageTensor2(142lu, 21lu);
229
1
	b &= testMessageTensor2(23lu, 64lu);
230
1
	b &= testMessageTensor2(142lu, 64lu);
231
232
1
	b &= testMessageTensor3(3lu, 42lu, 21lu);
233
1
	b &= testMessageTensor3(5lu, 142lu, 21lu);
234
1
	b &= testMessageTensor3(11lu, 23lu, 64lu);
235
1
	b &= testMessageTensor3(3lu, 142lu, 64lu);
236
237
1
	return b - 1;
238
}
239
240