-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.c
233 lines (186 loc) · 5.51 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
* Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <config.h>
#include <hw_init.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <stdbool.h>
#include <time.h>
#include <unistd.h>
#include <time.h>
#include <usb_msc_lwext4.h>
#include <ext4.h>
#include <ext4_mbr.h>
#include "test_lwext4.h"
/**@brief Read-write size*/
#define READ_WRITE_SZIZE 1024 * 16
/**@brief Delay test (slower LCD scroll)*/
#define TEST_DELAY_MS 1000
/**@brief Input stream name.*/
char input_name[128] = "ext2";
/**@brief Read-write size*/
static int rw_szie = READ_WRITE_SZIZE;
/**@brief Read-write buffer*/
static uint8_t rw_buff[READ_WRITE_SZIZE];
/**@brief Read-write size*/
static int rw_count = 100;
/**@brief Directory test count*/
static int dir_cnt = 100;
/**@brief Static or dynamic cache mode*/
static bool cache_mode = false;
/**@brief Cleanup after test.*/
static bool cleanup_flag = false;
/**@brief Block device stats.*/
static bool bstat = false;
/**@brief Superblock stats.*/
static bool sbstat = false;
/**@brief Block device handle.*/
static struct ext4_blockdev *parent_blockdev;
/**@brief MBR blockdevices.*/
static struct ext4_mbr_bdevs bdevs;
/**@brief Block cache handle.*/
static struct ext4_bcache *bc;
static bool open_filedev(void)
{
parent_blockdev = ext4_usb_msc_get();
if (!parent_blockdev) {
printf("open_filedev: fail\n");
return false;
}
return true;
}
static bool mbr_scan(void)
{
int r;
printf("ext4_mbr\n");
r = ext4_mbr_scan(parent_blockdev, &bdevs);
if (r != EOK) {
printf("ext4_mbr_scan error\n");
return false;
}
int i;
printf("ext4_mbr_scan:\n");
for (i = 0; i < 4; i++) {
printf("mbr_entry %d:\n", i);
if (!bdevs.partitions[i].bdif) {
printf("\tempty/unknown\n");
continue;
}
printf(" offeset: 0x%"PRIx64", %"PRIu64"MB\n",
bdevs.partitions[i].part_offset,
bdevs.partitions[i].part_offset / (1024 * 1024));
printf(" size: 0x%"PRIx64", %"PRIu64"MB\n",
bdevs.partitions[i].part_size,
bdevs.partitions[i].part_size / (1024 * 1024));
}
return true;
}
static bool do_tests(struct ext4_blockdev *part_blockdev)
{
tim_wait_ms(TEST_DELAY_MS);
if (!test_lwext4_mount(part_blockdev, bc))
return false;
tim_wait_ms(TEST_DELAY_MS);
ext4_cache_write_back("/mp/", 1);
test_lwext4_cleanup();
if (sbstat) {
tim_wait_ms(TEST_DELAY_MS);
test_lwext4_mp_stats();
}
tim_wait_ms(TEST_DELAY_MS);
test_lwext4_dir_ls("/mp/");
if (!test_lwext4_dir_test(dir_cnt))
return false;
tim_wait_ms(TEST_DELAY_MS);
if (!test_lwext4_file_test(rw_buff, rw_szie, rw_count))
return false;
if (sbstat) {
tim_wait_ms(TEST_DELAY_MS);
test_lwext4_mp_stats();
}
if (cleanup_flag) {
tim_wait_ms(TEST_DELAY_MS);
test_lwext4_cleanup();
}
if (bstat) {
tim_wait_ms(TEST_DELAY_MS);
test_lwext4_block_stats();
}
ext4_cache_write_back("/mp/", 0);
if (!test_lwext4_umount())
return false;
return true;
}
int main(void)
{
int i;
hw_init();
setbuf(stdout, 0);
printf("connect usb drive...\n");
while (!hw_usb_connected())
hw_usb_process();
printf("usb drive connected\n");
while (!hw_usb_enum_done())
hw_usb_process();
printf("usb drive enum done\n");
hw_led_red(1);
printf("test conditions:\n");
printf(" rw size: %d\n", rw_szie);
printf(" rw count: %d\n", rw_count);
printf(" cache mode: %s\n", cache_mode ? "dynamic" : "static");
if (!open_filedev())
goto Finish;
if (!mbr_scan())
goto Finish;
/*Execute tests for every scaned partition.*/
for (i = 0; i < 4; i++) {
if (!bdevs.partitions[i].bdif)
continue;
printf("do tests for mbr_entry %d:\n", i);
printf(" offeset: 0x%"PRIx64", %"PRIu64"MB\n",
bdevs.partitions[i].part_offset,
bdevs.partitions[i].part_offset / (1024 * 1024));
printf(" size: 0x%"PRIx64", %"PRIu64"MB\n",
bdevs.partitions[i].part_size,
bdevs.partitions[i].part_size / (1024 * 1024));
tim_wait_ms(TEST_DELAY_MS);
if (!do_tests(&bdevs.partitions[i]))
goto Finish;
}
printf("press RESET button to restart\n");
Finish:
while (1) {
tim_wait_ms(500);
hw_led_green(1);
tim_wait_ms(500);
hw_led_green(0);
}
}