1
- /* Hello World Example
2
-
3
- This example code is in the Public Domain (or CC0 licensed, at your option.)
4
-
5
- Unless required by applicable law or agreed to in writing, this
6
- software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
7
- CONDITIONS OF ANY KIND, either express or implied.
8
- */
1
+ // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
9
14
#include < stdio.h>
10
15
#include " unity.h"
11
16
#include " test_fixtures.hpp"
@@ -25,6 +30,8 @@ void test_Page_load_reading_header_fails()
25
30
26
31
TEST_ASSERT_EQUAL (Page::PageState::INVALID, page.state ());
27
32
TEST_ASSERT_EQUAL (ESP_ERR_INVALID_ARG, page.load (&mock, 0 ));
33
+
34
+ Mockesp_partition_Verify ();
28
35
}
29
36
30
37
void test_Page_load_reading_data_fails ()
@@ -39,6 +46,8 @@ void test_Page_load_reading_data_fails()
39
46
40
47
TEST_ASSERT_EQUAL (Page::PageState::INVALID, page.state ());
41
48
TEST_ASSERT_EQUAL (ESP_FAIL, page.load (&mock, 0 ));
49
+
50
+ Mockesp_partition_Verify ();
42
51
}
43
52
44
53
void test_Page_load__uninitialized_page_has_0xfe ()
@@ -57,6 +66,8 @@ void test_Page_load__uninitialized_page_has_0xfe()
57
66
TEST_ASSERT_EQUAL (ESP_OK, page.load (&fix.part_mock , 0 ));
58
67
59
68
TEST_ASSERT_EQUAL (Page::PageState::CORRUPT, page.state ());
69
+
70
+ Mockesp_partition_Verify ();
60
71
}
61
72
62
73
void test_Page_load__initialized_corrupt_header ()
@@ -74,6 +85,60 @@ void test_Page_load__initialized_corrupt_header()
74
85
TEST_ASSERT_EQUAL (ESP_OK, page.load (&fix.part_mock , 0 ));
75
86
76
87
TEST_ASSERT_EQUAL (Page::PageState::CORRUPT, page.state ());
88
+
89
+ Mockesp_partition_Verify ();
90
+ }
91
+
92
+ void test_Page_load__corrupt_entry_table ()
93
+ {
94
+ PartitionMockFixture fix;
95
+
96
+ // valid header
97
+ uint8_t raw_header_valid [32 ] = {0xfe , 0xff , 0xff , 0xff , 0x00 , 0x00 , 0x00 , 0x00 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
98
+ 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xc2 , 0x16 , 0xdd , 0xdc };
99
+
100
+ // entry table with one entry
101
+ uint8_t raw_entry_table [32 ];
102
+
103
+ uint8_t ns_entry [32 ] = {0x00 , 0x01 , 0x01 , 0xff , 0x68 , 0xc5 , 0x3f , 0x0b , ' t' , ' e' , ' s' , ' t' , ' _' , ' n' , ' s' , ' \0 ' ,
104
+ ' \0 ' , ' \0 ' , ' \0 ' , ' \0 ' , ' \0 ' , ' \0 ' , ' \0 ' , ' \0 ' , 1 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff };
105
+
106
+ uint8_t raw_header[4 ] = {0xff , 0xff , 0xff , 0xff };
107
+ std::fill_n (raw_entry_table, sizeof (raw_entry_table)/sizeof (raw_entry_table[0 ]), 0 );
108
+ raw_entry_table[0 ] = 0xfa ;
109
+
110
+ // read page header
111
+ esp_partition_read_raw_ExpectAnyArgsAndReturn (ESP_OK);
112
+ esp_partition_read_raw_ReturnArrayThruPtr_dst (raw_header_valid, 32 );
113
+
114
+ // read entry table
115
+ esp_partition_read_raw_ExpectAnyArgsAndReturn (ESP_OK);
116
+ esp_partition_read_raw_ReturnArrayThruPtr_dst (raw_entry_table, 32 );
117
+
118
+ // read next free entry's header
119
+ esp_partition_read_raw_ExpectAnyArgsAndReturn (ESP_OK);
120
+ esp_partition_read_raw_ReturnArrayThruPtr_dst (raw_header, 4 );
121
+
122
+ // read namespace entry
123
+ esp_partition_read_ExpectAnyArgsAndReturn (ESP_OK);
124
+ esp_partition_read_ReturnArrayThruPtr_dst (ns_entry, 32 );
125
+
126
+ // we expect a raw word write from the partition in order to change the entry bits to erased (0)
127
+ esp_partition_write_raw_ExpectAndReturn (&fix.part_mock .partition , 32 , nullptr , 4 , ESP_OK);
128
+ esp_partition_write_raw_IgnoreArg_src ();
129
+
130
+ // corrupt entry table as well as crc of corresponding item
131
+ raw_entry_table[0 ] = 0xf6 ;
132
+
133
+ Page page;
134
+
135
+ // Page::load() should return ESP_OK, but state has to be corrupt
136
+ TEST_ASSERT_EQUAL (ESP_OK, page.load (&fix.part_mock , 0 ));
137
+
138
+ TEST_ASSERT_EQUAL (Page::PageState::ACTIVE, page.state ());
139
+ TEST_ASSERT_EQUAL (1 , page.getUsedEntryCount ());
140
+
141
+ Mockesp_partition_Verify ();
77
142
}
78
143
79
144
void test_Page_load_success ()
@@ -881,6 +946,7 @@ int main(int argc, char **argv)
881
946
RUN_TEST (test_Page_load_reading_data_fails);
882
947
RUN_TEST (test_Page_load__uninitialized_page_has_0xfe);
883
948
RUN_TEST (test_Page_load__initialized_corrupt_header);
949
+ RUN_TEST (test_Page_load__corrupt_entry_table);
884
950
RUN_TEST (test_Page_load_success);
885
951
RUN_TEST (test_Page_load_full_page);
886
952
RUN_TEST (test_Page_load__seq_number_0);
@@ -929,6 +995,6 @@ int main(int argc, char **argv)
929
995
RUN_TEST (test_Page_calcEntries__active_wo_blob);
930
996
RUN_TEST (test_Page_calcEntries__active_with_blob);
931
997
RUN_TEST (test_Page_calcEntries__invalid);
932
- UNITY_END ();
933
- return 0 ;
998
+ int failures = UNITY_END ();
999
+ return failures ;
934
1000
}
0 commit comments