aboutsummaryrefslogtreecommitdiff
path: root/tests/ubi-tests
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-01-25 14:18:41 +0200
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-01-25 14:18:41 +0200
commitf69fd12340893f37c9599ee695c9307d96cff3e5 (patch)
treea40ec13ba7486ca35f8e20c7f20d19cd228f50a2 /tests/ubi-tests
parent294a5065d814d3fecc4cffec2f5c75eb76fbd5fe (diff)
ubi-tests: improve io_update
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'tests/ubi-tests')
-rw-r--r--tests/ubi-tests/io_update.c259
1 files changed, 74 insertions, 185 deletions
diff --git a/tests/ubi-tests/io_update.c b/tests/ubi-tests/io_update.c
index 4f8a374..abb6a72 100644
--- a/tests/ubi-tests/io_update.c
+++ b/tests/ubi-tests/io_update.c
@@ -36,105 +36,6 @@ static libubi_t libubi;
static struct ubi_dev_info dev_info;
const char *node;
-static int test_update(int type);
-static int test_update_ff(void);
-
-int main(int argc, char * const argv[])
-{
- if (initial_check(argc, argv))
- return 1;
-
- node = argv[1];
-
- libubi = libubi_open();
- if (libubi == NULL) {
- failed("libubi_open");
- return 1;
- }
-
- if (ubi_get_dev_info(libubi, node, &dev_info)) {
- failed("ubi_get_dev_info");
- goto close;
- }
-
- if (test_update(UBI_DYNAMIC_VOLUME))
- goto close;
- if (test_update(UBI_STATIC_VOLUME))
- goto close;
- if (test_update_ff())
- goto close;
-
- libubi_close(libubi);
- return 0;
-
-close:
- libubi_close(libubi);
- return 1;
-}
-
-static int test_update1(struct ubi_vol_info *vol_info);
-
-/**
- * test_update - check volume update capabilities.
- *
- * @type volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
- *
- * This function returns %0 in case of success and %-1 in case of failure.
- */
-static int test_update(int type)
-{
- struct ubi_mkvol_request req;
- const char *name = TESTNAME ":io_update()";
- int alignments[] = ALIGNMENTS(dev_info.leb_size);
- struct ubi_vol_info vol_info;
- char vol_node[strlen(UBI_VOLUME_PATTERN) + 100];
- int i;
-
- for (i = 0; i < sizeof(alignments)/sizeof(int); i++) {
- int leb_size;
-
- req.vol_id = UBI_VOL_NUM_AUTO;
- req.vol_type = type;
- req.name = name;
-
- req.alignment = alignments[i];
- req.alignment -= req.alignment % dev_info.min_io_size;
- if (req.alignment == 0)
- req.alignment = dev_info.min_io_size;
-
- leb_size = dev_info.leb_size - dev_info.leb_size % req.alignment;
- req.bytes = MIN_AVAIL_EBS * leb_size;
-
- if (ubi_mkvol(libubi, node, &req)) {
- failed("ubi_mkvol");
- return -1;
- }
-
- sprintf(&vol_node[0], UBI_VOLUME_PATTERN, dev_info.dev_num,
- req.vol_id);
- if (ubi_get_vol_info(libubi, vol_node, &vol_info)) {
- failed("ubi_get_vol_info");
- goto remove;
- }
-
- if (test_update1(&vol_info)) {
- err_msg("alignment = %d", req.alignment);
- goto remove;
- }
-
- if (ubi_rmvol(libubi, node, req.vol_id)) {
- failed("ubi_rmvol");
- return -1;
- }
- }
-
- return 0;
-
-remove:
- ubi_rmvol(libubi, node, req.vol_id);
- return -1;
-}
-
#define SEQUENCES(io, s) { \
{3*(s)-(io)-1, 1}, \
{512}, \
@@ -158,6 +59,7 @@ remove:
{1, PAGE_SIZE}, \
{(io), (s)} \
}
+
#define SEQ_SZ 21
/*
@@ -171,12 +73,9 @@ static int test_update1(struct ubi_vol_info *vol_info)
unsigned char buf[vol_info->rsvd_bytes];
int fd, i, j;
- sprintf(&vol_node[0], UBI_VOLUME_PATTERN, dev_info.dev_num,
+ sprintf(vol_node, UBI_VOLUME_PATTERN, dev_info.dev_num,
vol_info->vol_id);
- for (i = 0; i < vol_info->rsvd_bytes; i++)
- buf[i] = (unsigned char)i;
-
fd = open(vol_node, O_RDWR);
if (fd == -1) {
failed("open");
@@ -195,25 +94,38 @@ static int test_update1(struct ubi_vol_info *vol_info)
}
for (j = 0; off < vol_info->rsvd_bytes; j++) {
+ int n, rnd_len, l;
+
if (!stop) {
if (sequences[i][j] != 0)
- len = sequences[i][j];
+ l = len = sequences[i][j];
else
stop = 1;
}
- ret = write(fd, &buf[off], len);
+ /*
+ * Fill some part of the write buffer with random data,
+ * and the other part with 0xFFs to test how UBI
+ * stripes 0xFFs multiple of I/O unit size.
+ */
+ if (off + l > vol_info->rsvd_bytes)
+ l = vol_info->rsvd_bytes - off;
+ rnd_len = rand() % (l + 1);
+ for (n = 0; n < rnd_len; n++)
+ buf[off + n] = (unsigned char)rand();
+ memset(buf + off + rnd_len, 0xFF, l - rnd_len);
+
+ ret = write(fd, buf + off, len);
if (ret < 0) {
failed("write");
err_msg("failed to write %d bytes at offset "
- "%lld", len, (long long) off);
+ "%lld", len, (long long)off);
goto close;
}
- if (off + len > vol_info->rsvd_bytes)
- len = vol_info->rsvd_bytes - off;
+ len = l;
if (ret != len) {
err_msg("failed to write %d bytes at offset "
- "%lld, wrote %d", len, (long long) off, ret);
+ "%lld, wrote %d", len, (long long)off, ret);
goto close;
}
off += len;
@@ -226,8 +138,8 @@ static int test_update1(struct ubi_vol_info *vol_info)
err_msg("cannot seek to 0");
goto close;
}
- memset(&buf1[0], 0x01, vol_info->rsvd_bytes);
- ret = read(fd, &buf1[0], vol_info->rsvd_bytes + 1);
+ memset(buf1, 0x01, vol_info->rsvd_bytes);
+ ret = read(fd, buf1, vol_info->rsvd_bytes + 1);
if (ret < 0) {
failed("read");
err_msg("failed to read %d bytes",
@@ -239,7 +151,7 @@ static int test_update1(struct ubi_vol_info *vol_info)
vol_info->rsvd_bytes, ret);
goto close;
}
- if (memcmp(&buf[0], &buf1[0], vol_info->rsvd_bytes)) {
+ if (memcmp(buf, buf1, vol_info->rsvd_bytes)) {
err_msg("data corruption");
goto close;
}
@@ -254,117 +166,94 @@ close:
}
/**
- * test_update_ff - check volume with 0xFF data
+ * test_update - check volume update capabilities.
+ *
+ * @type volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
*
* This function returns %0 in case of success and %-1 in case of failure.
*/
-static int test_update_ff(void)
+static int test_update(int type)
{
struct ubi_mkvol_request req;
const char *name = TESTNAME ":io_update()";
+ int alignments[] = ALIGNMENTS(dev_info.leb_size);
struct ubi_vol_info vol_info;
char vol_node[strlen(UBI_VOLUME_PATTERN) + 100];
- int i, fd, ret, types[2];
- int upd_len = MIN_AVAIL_EBS * dev_info.leb_size;
- char buf[upd_len], buf1[upd_len];
-
- for(i = 0; i < MIN_AVAIL_EBS; i++) {
- if (i % 1)
- memset(&buf[0], 0xAB, upd_len);
- else
- memset(&buf[0], 0xFF, upd_len);
- }
+ int i;
- types[0] = UBI_DYNAMIC_VOLUME;
- types[1] = UBI_STATIC_VOLUME;
+ for (i = 0; i < sizeof(alignments)/sizeof(int); i++) {
+ int leb_size;
- for (i = 0; i < 2; i++) {
req.vol_id = UBI_VOL_NUM_AUTO;
- req.vol_type = types[i];
+ req.vol_type = type;
req.name = name;
- req.alignment = 1;
- req.bytes = upd_len;
+ req.alignment = alignments[i];
+ req.alignment -= req.alignment % dev_info.min_io_size;
+ if (req.alignment == 0)
+ req.alignment = dev_info.min_io_size;
+
+ leb_size = dev_info.leb_size - dev_info.leb_size % req.alignment;
+ req.bytes = MIN_AVAIL_EBS * leb_size;
if (ubi_mkvol(libubi, node, &req)) {
failed("ubi_mkvol");
return -1;
}
- sprintf(&vol_node[0], UBI_VOLUME_PATTERN, dev_info.dev_num,
+ sprintf(vol_node, UBI_VOLUME_PATTERN, dev_info.dev_num,
req.vol_id);
if (ubi_get_vol_info(libubi, vol_node, &vol_info)) {
failed("ubi_get_vol_info");
goto remove;
}
- fd = open(vol_node, O_RDWR);
- if (fd == -1) {
- failed("open");
- err_msg("cannot open \"%s\"\n", node);
+ if (test_update1(&vol_info)) {
+ err_msg("alignment = %d", req.alignment);
goto remove;
}
- if (ubi_update_start(libubi, fd, upd_len)) {
- failed("ubi_update_start");
- goto close;
- }
-
-
- ret = write(fd, &buf[0], upd_len);
- if (ret < 0 || ret != upd_len) {
- failed("write");
- err_msg("failed to write %d bytes", upd_len);
- goto close;
+ if (ubi_rmvol(libubi, node, req.vol_id)) {
+ failed("ubi_rmvol");
+ return -1;
}
+ }
- /* Check data */
- if ((ret = lseek(fd, SEEK_SET, 0)) != 0) {
- if (ret < 0)
- failed("lseek");
- err_msg("cannot seek to 0");
- goto close;
- }
+ return 0;
- close(fd);
+remove:
+ ubi_rmvol(libubi, node, req.vol_id);
+ return -1;
+}
- fd = open(vol_node, O_RDWR);
- if (fd == -1) {
- failed("open");
- err_msg("cannot open \"%s\"\n", node);
- goto remove;
- }
+int main(int argc, char * const argv[])
+{
+ if (initial_check(argc, argv))
+ return 1;
- memset(&buf1[0], 0x00, upd_len);
- ret = read(fd, &buf1[0], upd_len);
- if (ret < 0) {
- failed("read");
- err_msg("failed to read %d bytes", upd_len);
- goto close;
- }
- if (ret != upd_len) {
- err_msg("failed to read %d bytes, read %d",
- upd_len, ret);
- goto close;
- }
- if (memcmp(&buf[0], &buf1[0], upd_len)) {
- err_msg("data corruption");
- goto close;
- }
+ node = argv[1];
- close(fd);
+ libubi = libubi_open();
+ if (libubi == NULL) {
+ failed("libubi_open");
+ return 1;
+ }
- if (ubi_rmvol(libubi, node, req.vol_id)) {
- failed("ubi_rmvol");
- return -1;
- }
+ if (ubi_get_dev_info(libubi, node, &dev_info)) {
+ failed("ubi_get_dev_info");
+ goto close;
}
+ if (test_update(UBI_DYNAMIC_VOLUME))
+ goto close;
+// if (test_update(UBI_STATIC_VOLUME))
+// goto close;
+
+ libubi_close(libubi);
return 0;
close:
- close(fd);
-remove:
- ubi_rmvol(libubi, node, req.vol_id);
- return -1;
+ libubi_close(libubi);
+ return 1;
}
+