Skip to content

Commit 2c3dacb

Browse files
drobnikrppt
authored andcommitted
memblock tests: Split up reset_memblock function
All memblock data structure fields are reset in one function. In some test cases, it's preferred to reset memory region arrays without modifying other values like allocation direction flag. Extract two functions from reset_memblock, so it's possible to reset different parts of memblock: - reset_memblock_regions - reset region arrays and their counters - reset_memblock_attributes - set other fields to their default values Update checks in basic_api.c to use new definitions. Remove reset_memblock call from memblock_initialization_check, so the true initial values are tested. Signed-off-by: Karolina Drobnik <[email protected]> Signed-off-by: Mike Rapoport <[email protected]> Link: https://lore.kernel.org/r/5cc1ba9a0ade922dbf4ba450165b81a9ed17d4a9.1646055639.git.karolinadrobnik@gmail.com
1 parent 2a7ceac commit 2c3dacb

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

tools/testing/memblock/tests/basic_api.c

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
static int memblock_initialization_check(void)
1010
{
11-
reset_memblock();
12-
1311
assert(memblock.memory.regions);
1412
assert(memblock.memory.cnt == 1);
1513
assert(memblock.memory.max == EXPECTED_MEMBLOCK_REGIONS);
@@ -43,7 +41,7 @@ static int memblock_add_simple_check(void)
4341
.size = SZ_4M
4442
};
4543

46-
reset_memblock();
44+
reset_memblock_regions();
4745
memblock_add(r.base, r.size);
4846

4947
assert(rgn->base == r.base);
@@ -72,7 +70,7 @@ static int memblock_add_node_simple_check(void)
7270
.size = SZ_16M
7371
};
7472

75-
reset_memblock();
73+
reset_memblock_regions();
7674
memblock_add_node(r.base, r.size, 1, MEMBLOCK_HOTPLUG);
7775

7876
assert(rgn->base == r.base);
@@ -110,7 +108,7 @@ static int memblock_add_disjoint_check(void)
110108
.size = SZ_8K
111109
};
112110

113-
reset_memblock();
111+
reset_memblock_regions();
114112
memblock_add(r1.base, r1.size);
115113
memblock_add(r2.base, r2.size);
116114

@@ -151,7 +149,7 @@ static int memblock_add_overlap_top_check(void)
151149

152150
total_size = (r1.base - r2.base) + r1.size;
153151

154-
reset_memblock();
152+
reset_memblock_regions();
155153
memblock_add(r1.base, r1.size);
156154
memblock_add(r2.base, r2.size);
157155

@@ -190,7 +188,7 @@ static int memblock_add_overlap_bottom_check(void)
190188

191189
total_size = (r2.base - r1.base) + r2.size;
192190

193-
reset_memblock();
191+
reset_memblock_regions();
194192
memblock_add(r1.base, r1.size);
195193
memblock_add(r2.base, r2.size);
196194

@@ -225,7 +223,7 @@ static int memblock_add_within_check(void)
225223
.size = SZ_1M
226224
};
227225

228-
reset_memblock();
226+
reset_memblock_regions();
229227
memblock_add(r1.base, r1.size);
230228
memblock_add(r2.base, r2.size);
231229

@@ -249,7 +247,7 @@ static int memblock_add_twice_check(void)
249247
.size = SZ_2M
250248
};
251249

252-
reset_memblock();
250+
reset_memblock_regions();
253251

254252
memblock_add(r.base, r.size);
255253
memblock_add(r.base, r.size);
@@ -290,7 +288,7 @@ static int memblock_reserve_simple_check(void)
290288
.size = SZ_128M
291289
};
292290

293-
reset_memblock();
291+
reset_memblock_regions();
294292
memblock_reserve(r.base, r.size);
295293

296294
assert(rgn->base == r.base);
@@ -321,7 +319,7 @@ static int memblock_reserve_disjoint_check(void)
321319
.size = SZ_512M
322320
};
323321

324-
reset_memblock();
322+
reset_memblock_regions();
325323
memblock_reserve(r1.base, r1.size);
326324
memblock_reserve(r2.base, r2.size);
327325

@@ -364,7 +362,7 @@ static int memblock_reserve_overlap_top_check(void)
364362

365363
total_size = (r1.base - r2.base) + r1.size;
366364

367-
reset_memblock();
365+
reset_memblock_regions();
368366
memblock_reserve(r1.base, r1.size);
369367
memblock_reserve(r2.base, r2.size);
370368

@@ -404,7 +402,7 @@ static int memblock_reserve_overlap_bottom_check(void)
404402

405403
total_size = (r2.base - r1.base) + r2.size;
406404

407-
reset_memblock();
405+
reset_memblock_regions();
408406
memblock_reserve(r1.base, r1.size);
409407
memblock_reserve(r2.base, r2.size);
410408

@@ -440,7 +438,7 @@ static int memblock_reserve_within_check(void)
440438
.size = SZ_64K
441439
};
442440

443-
reset_memblock();
441+
reset_memblock_regions();
444442
memblock_reserve(r1.base, r1.size);
445443
memblock_reserve(r2.base, r2.size);
446444

@@ -465,7 +463,7 @@ static int memblock_reserve_twice_check(void)
465463
.size = SZ_2M
466464
};
467465

468-
reset_memblock();
466+
reset_memblock_regions();
469467

470468
memblock_reserve(r.base, r.size);
471469
memblock_reserve(r.base, r.size);
@@ -511,7 +509,7 @@ static int memblock_remove_simple_check(void)
511509
.size = SZ_4M
512510
};
513511

514-
reset_memblock();
512+
reset_memblock_regions();
515513
memblock_add(r1.base, r1.size);
516514
memblock_add(r2.base, r2.size);
517515
memblock_remove(r1.base, r1.size);
@@ -545,7 +543,7 @@ static int memblock_remove_absent_check(void)
545543
.size = SZ_1G
546544
};
547545

548-
reset_memblock();
546+
reset_memblock_regions();
549547
memblock_add(r1.base, r1.size);
550548
memblock_remove(r2.base, r2.size);
551549

@@ -585,7 +583,7 @@ static int memblock_remove_overlap_top_check(void)
585583
r2_end = r2.base + r2.size;
586584
total_size = r1_end - r2_end;
587585

588-
reset_memblock();
586+
reset_memblock_regions();
589587
memblock_add(r1.base, r1.size);
590588
memblock_remove(r2.base, r2.size);
591589

@@ -623,7 +621,7 @@ static int memblock_remove_overlap_bottom_check(void)
623621

624622
total_size = r2.base - r1.base;
625623

626-
reset_memblock();
624+
reset_memblock_regions();
627625
memblock_add(r1.base, r1.size);
628626
memblock_remove(r2.base, r2.size);
629627

@@ -665,7 +663,7 @@ static int memblock_remove_within_check(void)
665663
r2_size = (r1.base + r1.size) - (r2.base + r2.size);
666664
total_size = r1_size + r2_size;
667665

668-
reset_memblock();
666+
reset_memblock_regions();
669667
memblock_add(r1.base, r1.size);
670668
memblock_remove(r2.base, r2.size);
671669

@@ -715,7 +713,7 @@ static int memblock_free_simple_check(void)
715713
.size = SZ_1M
716714
};
717715

718-
reset_memblock();
716+
reset_memblock_regions();
719717
memblock_reserve(r1.base, r1.size);
720718
memblock_reserve(r2.base, r2.size);
721719
memblock_free((void *)r1.base, r1.size);
@@ -749,7 +747,7 @@ static int memblock_free_absent_check(void)
749747
.size = SZ_128M
750748
};
751749

752-
reset_memblock();
750+
reset_memblock_regions();
753751
memblock_reserve(r1.base, r1.size);
754752
memblock_free((void *)r2.base, r2.size);
755753

@@ -787,7 +785,7 @@ static int memblock_free_overlap_top_check(void)
787785

788786
total_size = (r1.size + r1.base) - (r2.base + r2.size);
789787

790-
reset_memblock();
788+
reset_memblock_regions();
791789
memblock_reserve(r1.base, r1.size);
792790
memblock_free((void *)r2.base, r2.size);
793791

@@ -824,7 +822,7 @@ static int memblock_free_overlap_bottom_check(void)
824822

825823
total_size = r2.base - r1.base;
826824

827-
reset_memblock();
825+
reset_memblock_regions();
828826
memblock_reserve(r1.base, r1.size);
829827
memblock_free((void *)r2.base, r2.size);
830828

@@ -867,7 +865,7 @@ static int memblock_free_within_check(void)
867865
r2_size = (r1.base + r1.size) - (r2.base + r2.size);
868866
total_size = r1_size + r2_size;
869867

870-
reset_memblock();
868+
reset_memblock_regions();
871869
memblock_reserve(r1.base, r1.size);
872870
memblock_free((void *)r2.base, r2.size);
873871

tools/testing/memblock/tests/common.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@
55
#define INIT_MEMBLOCK_REGIONS 128
66
#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS
77

8-
void reset_memblock(void)
8+
void reset_memblock_regions(void)
99
{
1010
memset(memblock.memory.regions, 0,
1111
memblock.memory.cnt * sizeof(struct memblock_region));
12-
memset(memblock.reserved.regions, 0,
13-
memblock.reserved.cnt * sizeof(struct memblock_region));
14-
1512
memblock.memory.cnt = 1;
1613
memblock.memory.max = INIT_MEMBLOCK_REGIONS;
17-
memblock.memory.name = "memory";
1814
memblock.memory.total_size = 0;
1915

16+
memset(memblock.reserved.regions, 0,
17+
memblock.reserved.cnt * sizeof(struct memblock_region));
2018
memblock.reserved.cnt = 1;
2119
memblock.reserved.max = INIT_MEMBLOCK_RESERVED_REGIONS;
22-
memblock.reserved.name = "reserved";
2320
memblock.reserved.total_size = 0;
21+
}
2422

23+
void reset_memblock_attributes(void)
24+
{
25+
memblock.memory.name = "memory";
26+
memblock.reserved.name = "reserved";
2527
memblock.bottom_up = false;
2628
memblock.current_limit = MEMBLOCK_ALLOC_ANYWHERE;
2729
}

tools/testing/memblock/tests/common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct region {
1010
phys_addr_t size;
1111
};
1212

13-
void reset_memblock(void);
13+
void reset_memblock_regions(void);
14+
void reset_memblock_attributes(void);
1415

1516
#endif

0 commit comments

Comments
 (0)