@@ -24,6 +24,10 @@ static void init_test_buf(uint8_t *buf, size_t len, uint8_t offset)
24
24
}
25
25
}
26
26
27
+ static void reset_history (void * fixture )
28
+ {
29
+ z_shell_history_purge (& history );
30
+ }
27
31
/**
28
32
* Function tests getting line from history and compares it against expected
29
33
* result.
@@ -54,7 +58,6 @@ static void test_get(bool ok, bool up, uint8_t *exp_buf, uint16_t exp_len)
54
58
/* Test put line to history and get it.
55
59
*
56
60
* Test steps:
57
- * - initialize history.
58
61
* - put line to the history.
59
62
* - read line and verify that it is the one that was put.
60
63
*/
@@ -64,15 +67,11 @@ ZTEST(shell_test, test_history_add_get)
64
67
65
68
init_test_buf (exp_buf , sizeof (exp_buf ), 0 );
66
69
67
- z_shell_history_init (& history );
68
-
69
70
test_get (false, true, NULL , 0 );
70
71
71
72
z_shell_history_put (& history , exp_buf , 20 );
72
73
73
74
test_get (true, true, exp_buf , 20 );
74
-
75
- z_shell_history_purge (& history );
76
75
}
77
76
78
77
/* Test verifies that after purging there is no line in the history. */
@@ -82,20 +81,18 @@ ZTEST(shell_test, test_history_purge)
82
81
83
82
init_test_buf (exp_buf , sizeof (exp_buf ), 0 );
84
83
85
- z_shell_history_init ( & history );
84
+
86
85
87
86
z_shell_history_put (& history , exp_buf , 20 );
88
87
z_shell_history_put (& history , exp_buf , 20 );
89
88
90
89
z_shell_history_purge (& history );
91
-
92
90
test_get (false, true, NULL , 0 );
93
91
}
94
92
95
93
/* Test browsing history.
96
94
*
97
95
* Test steps:
98
- * - initialize history.
99
96
* - put lines 1,2,3 to history.
100
97
* - get in up direction a line and verify that it's the last one added (3).
101
98
* - get next line in up direction and verify that it's line 2.
@@ -117,7 +114,7 @@ ZTEST(shell_test, test_history_get_up_and_down)
117
114
init_test_buf (exp2_buf , sizeof (exp2_buf ), 10 );
118
115
init_test_buf (exp3_buf , sizeof (exp3_buf ), 20 );
119
116
120
- z_shell_history_init ( & history );
117
+
121
118
122
119
z_shell_history_put (& history , exp1_buf , 20 );
123
120
z_shell_history_put (& history , exp2_buf , 15 );
@@ -131,8 +128,6 @@ ZTEST(shell_test, test_history_get_up_and_down)
131
128
test_get (true, false, exp2_buf , 15 ); /* down - 2 */
132
129
test_get (true, false, exp3_buf , 20 ); /* down - 3 */
133
130
test_get (false, false, NULL , 0 ); /* down - nothing */
134
-
135
- z_shell_history_purge (& history );
136
131
}
137
132
138
133
/* Function for getting maximal buffer size that can be stored in the history */
@@ -143,7 +138,7 @@ static int get_max_buffer_len(void)
143
138
int len = sizeof (buf );
144
139
uint16_t out_len ;
145
140
146
- z_shell_history_init ( & history );
141
+
147
142
148
143
do {
149
144
z_shell_history_put (& history , buf , len );
@@ -160,7 +155,6 @@ static int get_max_buffer_len(void)
160
155
/* Test verifies that line that cannot fit into history buffer is not stored.
161
156
*
162
157
* Test steps:
163
- * - initialize history.
164
158
* - put buffer that is bigger than history overall capacity.
165
159
* - verify that history is empty.
166
160
* - put short line followed by line that is close to max.
@@ -172,7 +166,7 @@ ZTEST(shell_test, test_too_long_line_not_stored)
172
166
int max_len = get_max_buffer_len ();
173
167
174
168
init_test_buf (exp1_buf , sizeof (exp1_buf ), 0 );
175
- z_shell_history_init ( & history );
169
+
176
170
177
171
z_shell_history_put (& history , exp1_buf , max_len + 1 );
178
172
@@ -185,15 +179,12 @@ ZTEST(shell_test, test_too_long_line_not_stored)
185
179
/* Test that long entry evicts older entry. */
186
180
test_get (true, true, exp1_buf , max_len - 10 );
187
181
test_get (false, true, NULL , 0 ); /* only one entry */
188
-
189
- z_shell_history_purge (& history );
190
182
}
191
183
192
184
/* Test verifies that same line as the previous one is not stored in the
193
185
* history.
194
186
*
195
187
* Test steps:
196
- * - initialize history.
197
188
* - put same line twice.
198
189
* - verify that only one line is in the history.
199
190
*/
@@ -202,22 +193,19 @@ ZTEST(shell_test, test_no_duplicates_in_a_row)
202
193
uint8_t exp1_buf [HIST_BUF_SIZE ];
203
194
204
195
init_test_buf (exp1_buf , sizeof (exp1_buf ), 0 );
205
- z_shell_history_init ( & history );
196
+
206
197
207
198
z_shell_history_put (& history , exp1_buf , 20 );
208
199
z_shell_history_put (& history , exp1_buf , 20 );
209
200
210
201
test_get (true, true, exp1_buf , 20 );
211
202
/* only one line stored. */
212
203
test_get (false, true, NULL , 0 );
213
-
214
- z_shell_history_purge (& history );
215
204
}
216
205
217
206
/* Test storing long lines in the history.
218
207
*
219
208
* * Test steps:
220
- * - initialize history.
221
209
* - Put max length line 1 in history.
222
210
* - Verify that it is present.
223
211
* - Put max length line 2 in history.
@@ -236,8 +224,6 @@ ZTEST(shell_test, test_storing_long_buffers)
236
224
init_test_buf (exp2_buf , sizeof (exp2_buf ), 10 );
237
225
init_test_buf (exp3_buf , sizeof (exp3_buf ), 20 );
238
226
239
- z_shell_history_init (& history );
240
-
241
227
z_shell_history_put (& history , exp1_buf , max_len );
242
228
test_get (true, true, exp1_buf , max_len );
243
229
test_get (false, true, NULL , 0 ); /* only one entry */
@@ -249,8 +235,6 @@ ZTEST(shell_test, test_storing_long_buffers)
249
235
z_shell_history_put (& history , exp3_buf , max_len );
250
236
test_get (true, true, exp3_buf , max_len );
251
237
test_get (false, true, NULL , 0 ); /* only one entry */
252
-
253
- z_shell_history_purge (& history );
254
238
}
255
239
256
- ZTEST_SUITE (shell_test , NULL , NULL , NULL , NULL , NULL );
240
+ ZTEST_SUITE (shell_test , NULL , NULL , NULL , reset_history , NULL );
0 commit comments