@@ -37,20 +37,32 @@ using namespace utest::v1;
37
37
38
38
// Simple test which read/writes blocks on a sliced block device
39
39
void test_slicing () {
40
+ uint8_t *dummy = new (std::nothrow) uint8_t [BLOCK_COUNT * BLOCK_SIZE];
41
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory for test" );
42
+ delete[] dummy;
43
+
44
+ int err;
45
+
40
46
HeapBlockDevice bd (BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
41
- uint8_t *write_block = new uint8_t [BLOCK_SIZE];
42
- uint8_t *read_block = new uint8_t [BLOCK_SIZE];
43
47
44
- // Test with first slice of block device
45
48
SlicingBlockDevice slice1 (&bd, 0 , (BLOCK_COUNT/2 )*BLOCK_SIZE);
49
+ SlicingBlockDevice slice2 (&bd, -(BLOCK_COUNT/2 )*BLOCK_SIZE);
46
50
47
- int err = slice1.init ();
51
+ // Test with first slice of block device
52
+ err = slice1.init ();
48
53
TEST_ASSERT_EQUAL (0 , err);
49
54
50
55
TEST_ASSERT_EQUAL (BLOCK_SIZE, slice1.get_program_size ());
51
56
TEST_ASSERT_EQUAL (BLOCK_SIZE, slice1.get_erase_size (BLOCK_SIZE));
52
57
TEST_ASSERT_EQUAL ((BLOCK_COUNT/2 )*BLOCK_SIZE, slice1.size ());
53
58
59
+ uint8_t *write_block = new (std::nothrow) uint8_t [BLOCK_SIZE];
60
+ uint8_t *read_block = new (std::nothrow) uint8_t [BLOCK_SIZE];
61
+ if (!write_block || !read_block) {
62
+ printf (" Not enough memory for test" );
63
+ goto end;
64
+ }
65
+
54
66
// Fill with random sequence
55
67
srand (1 );
56
68
for (int i = 0 ; i < BLOCK_SIZE; i++) {
@@ -85,8 +97,6 @@ void test_slicing() {
85
97
86
98
87
99
// Test with second slice of block device
88
- SlicingBlockDevice slice2 (&bd, -(BLOCK_COUNT/2 )*BLOCK_SIZE);
89
-
90
100
err = slice2.init ();
91
101
TEST_ASSERT_EQUAL (0 , err);
92
102
@@ -122,24 +132,38 @@ void test_slicing() {
122
132
TEST_ASSERT_EQUAL (0xff & rand (), read_block[i]);
123
133
}
124
134
125
- delete[] write_block;
126
- delete[] read_block;
127
135
err = slice2.deinit ();
128
136
TEST_ASSERT_EQUAL (0 , err);
137
+
138
+ end:
139
+ delete[] write_block;
140
+ delete[] read_block;
129
141
}
130
142
131
143
// Simple test which read/writes blocks on a chain of block devices
132
144
void test_chaining () {
145
+ uint8_t *dummy = new (std::nothrow) uint8_t [BLOCK_COUNT * BLOCK_SIZE];
146
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory for test" );
147
+ delete[] dummy;
148
+
149
+ int err;
150
+
133
151
HeapBlockDevice bd1 ((BLOCK_COUNT/2 )*BLOCK_SIZE, BLOCK_SIZE);
134
152
HeapBlockDevice bd2 ((BLOCK_COUNT/2 )*BLOCK_SIZE, BLOCK_SIZE);
135
- uint8_t *write_block = new uint8_t [BLOCK_SIZE];
136
- uint8_t *read_block = new uint8_t [BLOCK_SIZE];
137
153
138
154
// Test with chain of block device
139
155
BlockDevice *bds[] = {&bd1, &bd2};
140
156
ChainingBlockDevice chain (bds);
141
157
142
- int err = chain.init ();
158
+ uint8_t *write_block = new (std::nothrow) uint8_t [BLOCK_SIZE];
159
+ uint8_t *read_block = new (std::nothrow) uint8_t [BLOCK_SIZE];
160
+
161
+ if (!write_block || !read_block) {
162
+ printf (" Not enough memory for test" );
163
+ goto end;
164
+ }
165
+
166
+ err = chain.init ();
143
167
TEST_ASSERT_EQUAL (0 , err);
144
168
145
169
TEST_ASSERT_EQUAL (BLOCK_SIZE, chain.get_program_size ());
@@ -178,27 +202,41 @@ void test_chaining() {
178
202
TEST_ASSERT_EQUAL (0xff & rand (), read_block[i]);
179
203
}
180
204
181
- delete[] write_block;
182
- delete[] read_block;
183
205
err = chain.deinit ();
184
206
TEST_ASSERT_EQUAL (0 , err);
207
+
208
+ end:
209
+ delete[] write_block;
210
+ delete[] read_block;
185
211
}
186
212
187
213
// Simple test which read/writes blocks on a chain of block devices
188
214
void test_profiling () {
189
- HeapBlockDevice bd ( BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE) ;
190
- uint8_t *write_block = new uint8_t [BLOCK_SIZE] ;
191
- uint8_t *read_block = new uint8_t [BLOCK_SIZE] ;
215
+ uint8_t *dummy = new (std::nothrow) uint8_t [ BLOCK_COUNT * BLOCK_SIZE] ;
216
+ TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory for test " ) ;
217
+ delete[] dummy ;
192
218
219
+ int err;
220
+ bd_size_t read_count, program_count, erase_count;
221
+
222
+ HeapBlockDevice bd (BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
193
223
// Test under profiling
194
224
ProfilingBlockDevice profiler (&bd);
195
225
196
- int err = profiler.init ();
226
+ err = profiler.init ();
197
227
TEST_ASSERT_EQUAL (0 , err);
198
228
199
229
TEST_ASSERT_EQUAL (BLOCK_SIZE, profiler.get_erase_size ());
200
230
TEST_ASSERT_EQUAL (BLOCK_COUNT*BLOCK_SIZE, profiler.size ());
201
231
232
+ uint8_t *write_block = new (std::nothrow) uint8_t [BLOCK_SIZE];
233
+ uint8_t *read_block = new (std::nothrow) uint8_t [BLOCK_SIZE];
234
+
235
+ if (!write_block || !read_block) {
236
+ printf (" Not enough memory for test" );
237
+ goto end;
238
+ }
239
+
202
240
// Fill with random sequence
203
241
srand (1 );
204
242
for (int i = 0 ; i < BLOCK_SIZE; i++) {
@@ -231,18 +269,20 @@ void test_profiling() {
231
269
TEST_ASSERT_EQUAL (0xff & rand (), read_block[i]);
232
270
}
233
271
234
- delete[] write_block;
235
- delete[] read_block;
236
272
err = profiler.deinit ();
237
273
TEST_ASSERT_EQUAL (0 , err);
238
274
239
275
// Check that profiled operations match expectations
240
- bd_size_t read_count = profiler.get_read_count ();
276
+ read_count = profiler.get_read_count ();
241
277
TEST_ASSERT_EQUAL (BLOCK_SIZE, read_count);
242
- bd_size_t program_count = profiler.get_program_count ();
278
+ program_count = profiler.get_program_count ();
243
279
TEST_ASSERT_EQUAL (BLOCK_SIZE, program_count);
244
- bd_size_t erase_count = profiler.get_erase_count ();
280
+ erase_count = profiler.get_erase_count ();
245
281
TEST_ASSERT_EQUAL (BLOCK_SIZE, erase_count);
282
+
283
+ end:
284
+ delete[] write_block;
285
+ delete[] read_block;
246
286
}
247
287
248
288
0 commit comments