Skip to content

Commit f08c3cd

Browse files
committed
SFDP: TestEraseTypeAlgorithm: Move setup into test case
The test data `struct mbed::sfdp_smptbl_info smptbl` is only relevant to `TestEraseTypeAlgorithm` and not shared with other test cases.
1 parent 6510992 commit f08c3cd

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

storage/blockdevice/tests/UNITTESTS/SFDP/test_sfdp.cpp

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2020 ARM Limited
1+
/* Copyright (c) 2020-2021 ARM Limited
22
* SPDX-License-Identifier: Apache-2.0
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,35 +19,6 @@
1919
#include "blockdevice/internal/SFDP.h"
2020

2121
class TestSFDP : public testing::Test {
22-
protected:
23-
struct mbed::sfdp_smptbl_info smptbl;
24-
25-
/**
26-
* Construct Mbed OS SFDP info.
27-
* Normally this is parsed from the flash-chips's
28-
* raw SFDP table bytes, but for unit test we construct
29-
* SFDP info manually
30-
*/
31-
virtual void SetUp()
32-
{
33-
// The mock flash supports 4KB, 32KB and 64KB erase types
34-
smptbl.erase_type_size_arr[0] = 4 * 1024;
35-
smptbl.erase_type_size_arr[1] = 32 * 1024;
36-
smptbl.erase_type_size_arr[2] = 64 * 1024;
37-
38-
// The mock flash has three regions, with address ranges:
39-
// * 0 to 64KB - 1B
40-
// * 64KB to 256KB - 1B
41-
// * 256KB to 1024KB - 1B
42-
smptbl.region_high_boundary[0] = 64 * 1024 - 1;
43-
smptbl.region_high_boundary[1] = 256 * 1024 - 1;
44-
smptbl.region_high_boundary[2] = 1024 * 1024 - 1;
45-
46-
// Bitfields indicating which regions support which erase types
47-
smptbl.region_erase_types_bitfld[0] = 0b0001; // 4KB only
48-
smptbl.region_erase_types_bitfld[1] = 0b0111; // 64KB, 32KB, 4KB
49-
smptbl.region_erase_types_bitfld[2] = 0b0110; // 64KB, 32KB
50-
}
5122
};
5223

5324
/**
@@ -63,6 +34,25 @@ TEST_F(TestSFDP, TestEraseTypeAlgorithm)
6334
int region = 1;
6435
int type;
6536

37+
// The mock flash supports 4KB, 32KB and 64KB erase types
38+
struct mbed::sfdp_smptbl_info smptbl;
39+
smptbl.erase_type_size_arr[0] = 4 * 1024;
40+
smptbl.erase_type_size_arr[1] = 32 * 1024;
41+
smptbl.erase_type_size_arr[2] = 64 * 1024;
42+
43+
// The mock flash has three regions, with address ranges:
44+
// * 0 to 64KB - 1B
45+
// * 64KB to 256KB - 1B
46+
// * 256KB to 1024KB - 1B
47+
smptbl.region_high_boundary[0] = 64 * 1024 - 1;
48+
smptbl.region_high_boundary[1] = 256 * 1024 - 1;
49+
smptbl.region_high_boundary[2] = 1024 * 1024 - 1;
50+
51+
// Bitfields indicating which regions support which erase types
52+
smptbl.region_erase_types_bitfld[0] = 0b0001; // 4KB only
53+
smptbl.region_erase_types_bitfld[1] = 0b0111; // 64KB, 32KB, 4KB
54+
smptbl.region_erase_types_bitfld[2] = 0b0110; // 64KB, 32KB
55+
6656
// Expected outcome:
6757
// * The starting position 92KB is 4KB-aligned
6858
// * The next position 96KB (92KB + 4KB) is 32KB-aligned

0 commit comments

Comments
 (0)