From 8570a32e92e10f6a7f08ea4409b03b54bd992d5d Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 25 Jan 2008 14:33:58 +0200 Subject: ubi-tests: stylistic amendments Signed-off-by: Artem Bityutskiy --- tests/ubi-tests/common.c | 14 +- tests/ubi-tests/io_basic.c | 89 ++++++------- tests/ubi-tests/io_paral.c | 178 +++++++++++++------------ tests/ubi-tests/io_read.c | 300 ++++++++++++++++++++---------------------- tests/ubi-tests/io_update.c | 4 +- tests/ubi-tests/mkvol_bad.c | 75 +++++------ tests/ubi-tests/mkvol_basic.c | 79 ++++++----- tests/ubi-tests/mkvol_paral.c | 66 +++++----- tests/ubi-tests/rsvol.c | 207 ++++++++++++++--------------- 9 files changed, 492 insertions(+), 520 deletions(-) (limited to 'tests') diff --git a/tests/ubi-tests/common.c b/tests/ubi-tests/common.c index 1343ec1..a5064fb 100644 --- a/tests/ubi-tests/common.c +++ b/tests/ubi-tests/common.c @@ -166,11 +166,11 @@ int __check_volume(libubi_t libubi, struct ubi_dev_info *dev_info, req->vol_type, vol_info.type); return -1; } - if (strlen(req->name) != strlen(&vol_info.name[0]) || - strcmp(req->name, &vol_info.name[0]) != 0) { + if (strlen(req->name) != strlen(vol_info.name) || + strcmp(req->name, vol_info.name) != 0) { __err_msg(test, func, line, "bad name: requested \"%s\", got \"%s\"", - req->name, &vol_info.name[0]); + req->name, vol_info.name); return -1; } if (vol_info.corrupted) { @@ -239,8 +239,8 @@ int __check_vol_patt(libubi_t libubi, struct ubi_dev_info *dev_info, while (bytes < vol_info.data_bytes) { int i; - memset(&buf[0], ~byte, 512); - ret = read(fd, &buf[0], 512); + memset(buf, ~byte, 512); + ret = read(fd, buf, 512); if (ret == -1) { __failed(test, func, line, "read"); __err_msg(test, func, line, "bytes = %lld, ret = %d", @@ -307,10 +307,10 @@ int __update_vol_patt(libubi_t libubi, const char *test, const char *func, goto close; } - memset(&buf[0], byte, 512); + memset(buf, byte, 512); while (written != bytes) { - ret = write(fd, &buf[0], 512); + ret = write(fd, buf, 512); if (ret == -1) { __failed(test, func, line, "write"); __err_msg(test, func, line, "written = %lld, ret = %d", diff --git a/tests/ubi-tests/io_basic.c b/tests/ubi-tests/io_basic.c index 26544cc..256b71b 100644 --- a/tests/ubi-tests/io_basic.c +++ b/tests/ubi-tests/io_basic.c @@ -36,44 +36,6 @@ static libubi_t libubi; static struct ubi_dev_info dev_info; const char *node; -static int test_basic(int type); -static int test_aligned(int type); - -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_basic(UBI_DYNAMIC_VOLUME)) - goto close; - if (test_basic(UBI_STATIC_VOLUME)) - goto close; - if (test_aligned(UBI_DYNAMIC_VOLUME)) - goto close; - if (test_aligned(UBI_STATIC_VOLUME)) - goto close; - - libubi_close(libubi); - return 0; - -close: - libubi_close(libubi); - return 1; -} - /** * test_basic - check basic volume read and update capabilities. * @@ -98,16 +60,16 @@ static int test_basic(int type) return -1; } - sprintf(&vol_node[0], UBI_VOLUME_PATTERN, dev_info.dev_num, req.vol_id); + sprintf(vol_node, UBI_VOLUME_PATTERN, dev_info.dev_num, req.vol_id); /* Make sure newly created volume contains only 0xFF bytes */ - if (check_vol_patt(&vol_node[0], 0xFF)) + if (check_vol_patt(vol_node, 0xFF)) goto remove; /* Write 0xA5 bytes to the volume */ - if (update_vol_patt(&vol_node[0], dev_info.avail_bytes, 0xA5)) + if (update_vol_patt(vol_node, dev_info.avail_bytes, 0xA5)) goto remove; - if (check_vol_patt(&vol_node[0], 0xA5)) + if (check_vol_patt(vol_node, 0xA5)) goto remove; if (ubi_rmvol(libubi, node, req.vol_id)) { @@ -156,16 +118,16 @@ static int test_aligned(int type) return -1; } - sprintf(&vol_node[0], UBI_VOLUME_PATTERN, dev_info.dev_num, req.vol_id); + sprintf(vol_node, UBI_VOLUME_PATTERN, dev_info.dev_num, req.vol_id); /* Make sure newly created volume contains only 0xFF bytes */ - if (check_vol_patt(&vol_node[0], 0xFF)) + if (check_vol_patt(vol_node, 0xFF)) goto remove; /* Write 0xA5 bytes to the volume */ - if (update_vol_patt(&vol_node[0], req.bytes, 0xA5)) + if (update_vol_patt(vol_node, req.bytes, 0xA5)) goto remove; - if (check_vol_patt(&vol_node[0], 0xA5)) + if (check_vol_patt(vol_node, 0xA5)) goto remove; if (ubi_rmvol(libubi, node, req.vol_id)) { @@ -180,3 +142,38 @@ remove: ubi_rmvol(libubi, node, req.vol_id); return -1; } + +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_basic(UBI_DYNAMIC_VOLUME)) + goto close; + if (test_basic(UBI_STATIC_VOLUME)) + goto close; + if (test_aligned(UBI_DYNAMIC_VOLUME)) + goto close; + if (test_aligned(UBI_STATIC_VOLUME)) + goto close; + + libubi_close(libubi); + return 0; + +close: + libubi_close(libubi); + return 1; +} diff --git a/tests/ubi-tests/io_paral.c b/tests/ubi-tests/io_paral.c index 3d1b901..7b0c3d9 100644 --- a/tests/ubi-tests/io_paral.c +++ b/tests/ubi-tests/io_paral.c @@ -42,8 +42,6 @@ const char *node; static int iterations = ITERATIONS; int total_bytes; -static void * the_thread(void *ptr); - static long long memory_limit(void) { long long result = 0; @@ -57,93 +55,6 @@ static long long memory_limit(void) return result * 1024 / 4; } -int main(int argc, char * const argv[]) -{ - int i, ret; - pthread_t threads[THREADS_NUM]; - struct ubi_mkvol_request req; - long long mem_limit; - - 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; - } - - req.alignment = 1; - mem_limit = memory_limit(); - if (mem_limit && mem_limit < dev_info.avail_bytes) - total_bytes = req.bytes = - (mem_limit / dev_info.leb_size / THREADS_NUM) - * dev_info.leb_size; - else - total_bytes = req.bytes = - ((dev_info.avail_lebs - 3) / THREADS_NUM) - * dev_info.leb_size; - for (i = 0; i < THREADS_NUM; i++) { - char name[100]; - - req.vol_id = i; - sprintf(&name[0], TESTNAME":%d", i); - req.name = &name[0]; - req.vol_type = (i & 1) ? UBI_STATIC_VOLUME : UBI_DYNAMIC_VOLUME; - - if (ubi_mkvol(libubi, node, &req)) { - failed("ubi_mkvol"); - goto remove; - } - } - - /* Create one volume with static data to make WL work more */ - req.vol_id = THREADS_NUM; - req.name = TESTNAME ":static"; - req.vol_type = UBI_DYNAMIC_VOLUME; - req.bytes = 3*dev_info.leb_size; - if (ubi_mkvol(libubi, node, &req)) { - failed("ubi_mkvol"); - goto remove; - } - - for (i = 0; i < THREADS_NUM; i++) { - ret = pthread_create(&threads[i], NULL, &the_thread, (void*)i); - if (ret) { - failed("pthread_create"); - goto remove; - } - } - - for (i = 0; i < THREADS_NUM; i++) - pthread_join(threads[i], NULL); - - for (i = 0; i <= THREADS_NUM; i++) { - if (ubi_rmvol(libubi, node, i)) { - failed("ubi_rmvol"); - goto remove; - } - } - - libubi_close(libubi); - return 0; - -remove: - for (i = 0; i <= THREADS_NUM; i++) - ubi_rmvol(libubi, node, i); - -close: - libubi_close(libubi); - return 1; -} - /** * the_thread - the testing thread. * @@ -162,7 +73,7 @@ static void * the_thread(void *ptr) goto free; } - sprintf(&vol_node[0], UBI_VOLUME_PATTERN, dev_info.dev_num, vol_id); + sprintf(vol_node, UBI_VOLUME_PATTERN, dev_info.dev_num, vol_id); while (iter--) { int i, ret, written = 0, rd = 0; @@ -249,3 +160,90 @@ free: free(rbuf); return NULL; } + +int main(int argc, char * const argv[]) +{ + int i, ret; + pthread_t threads[THREADS_NUM]; + struct ubi_mkvol_request req; + long long mem_limit; + + 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; + } + + req.alignment = 1; + mem_limit = memory_limit(); + if (mem_limit && mem_limit < dev_info.avail_bytes) + total_bytes = req.bytes = + (mem_limit / dev_info.leb_size / THREADS_NUM) + * dev_info.leb_size; + else + total_bytes = req.bytes = + ((dev_info.avail_lebs - 3) / THREADS_NUM) + * dev_info.leb_size; + for (i = 0; i < THREADS_NUM; i++) { + char name[100]; + + req.vol_id = i; + sprintf(name, TESTNAME":%d", i); + req.name = name; + req.vol_type = (i & 1) ? UBI_STATIC_VOLUME : UBI_DYNAMIC_VOLUME; + + if (ubi_mkvol(libubi, node, &req)) { + failed("ubi_mkvol"); + goto remove; + } + } + + /* Create one volume with static data to make WL work more */ + req.vol_id = THREADS_NUM; + req.name = TESTNAME ":static"; + req.vol_type = UBI_DYNAMIC_VOLUME; + req.bytes = 3*dev_info.leb_size; + if (ubi_mkvol(libubi, node, &req)) { + failed("ubi_mkvol"); + goto remove; + } + + for (i = 0; i < THREADS_NUM; i++) { + ret = pthread_create(&threads[i], NULL, &the_thread, (void*)i); + if (ret) { + failed("pthread_create"); + goto remove; + } + } + + for (i = 0; i < THREADS_NUM; i++) + pthread_join(threads[i], NULL); + + for (i = 0; i <= THREADS_NUM; i++) { + if (ubi_rmvol(libubi, node, i)) { + failed("ubi_rmvol"); + goto remove; + } + } + + libubi_close(libubi); + return 0; + +remove: + for (i = 0; i <= THREADS_NUM; i++) + ubi_rmvol(libubi, node, i); + +close: + libubi_close(libubi); + return 1; +} diff --git a/tests/ubi-tests/io_read.c b/tests/ubi-tests/io_read.c index 3fccf93..57a8da7 100644 --- a/tests/ubi-tests/io_read.c +++ b/tests/ubi-tests/io_read.c @@ -35,42 +35,24 @@ static libubi_t libubi; static struct ubi_dev_info dev_info; const char *node; +static int fd; -static int test_static(void); -static int test_read(int type); - -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_static()) - goto close; - if (test_read(UBI_DYNAMIC_VOLUME)) - goto close; - if (test_read(UBI_STATIC_VOLUME)) - goto close; - - libubi_close(libubi); - return 0; +/* Data lengthes to test, @io - minimal I/O unit size, @s - eraseblock size */ +#define LENGTHES(io, s) \ + {1, (io), (io)+1, 2*(io), 3*(io)-1, 3*(io), \ + PAGE_SIZE-1, PAGE_SIZE-(io), 2*PAGE_SIZE, 2*PAGE_SIZE-(io), \ + (s)/2-1, (s)/2, (s)/2+1, (s)-1, (s), (s)+1, 2*(s)-(io), 2*(s), \ + 2*(s)+(io), 3*(s), 3*(s)+(io)}; -close: - libubi_close(libubi); - return 1; -} +/* + * Offsets to test, @io - minimal I/O unit size, @s - eraseblock size, @sz - + * volume size. + */ +#define OFFSETS(io, s, sz) \ + {0, (io)-1, (io), (io)+1, 2*(io)-1, 2*(io), 3*(io)-1, 3*(io), \ + PAGE_SIZE-1, PAGE_SIZE-(io), 2*PAGE_SIZE, 2*PAGE_SIZE-(io), \ + (s)/2-1, (s)/2, (s)/2+1, (s)-1, (s), (s)+1, 2*(s)-(io), 2*(s), \ + 2*(s)+(io), 3*(s), (sz)-(s)-1, (sz)-(io)-1, (sz)-PAGE_SIZE-1}; /** * test_static - test static volume-specific features. @@ -97,7 +79,7 @@ static int test_static(void) return -1; } - sprintf(&vol_node[0], UBI_VOLUME_PATTERN, dev_info.dev_num, req.vol_id); + sprintf(vol_node, UBI_VOLUME_PATTERN, dev_info.dev_num, req.vol_id); fd = open(vol_node, O_RDWR); if (fd == -1) { @@ -118,7 +100,7 @@ static int test_static(void) } /* Ensure read returns EOF */ - ret = read(fd, &buf[0], 1); + ret = read(fd, buf, 1); if (ret < 0) { failed("read"); goto close; @@ -133,7 +115,7 @@ static int test_static(void) goto close; } - ret = write(fd, &buf[0], 10); + ret = write(fd, buf, 10); if (ret < 0) { failed("write"); goto close; @@ -147,7 +129,7 @@ static int test_static(void) failed("seek"); goto close; } - ret = read(fd, &buf[0], 20); + ret = read(fd, buf, 20); if (ret < 0) { failed("read"); goto close; @@ -172,81 +154,73 @@ remove: return -1; } -static int test_read1(struct ubi_vol_info *vol_info); - -/** - * test_read - test UBI volume reading from different offsets. - * - * @type volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME) - * - * Thus function returns %0 in case of success and %-1 in case of failure. +/* + * A helper function for test_read2(). */ -static int test_read(int type) +static int test_read3(const struct ubi_vol_info *vol_info, int len, off_t off) { - const char *name = TESTNAME ":test_read()"; - int alignments[] = ALIGNMENTS(dev_info.leb_size); - char vol_node[strlen(UBI_VOLUME_PATTERN) + 100]; - struct ubi_mkvol_request req; - int i; - - for (i = 0; i < sizeof(alignments)/sizeof(int); i++) { - int leb_size; - struct ubi_vol_info vol_info; + int i, len1; + unsigned char ck_buf[len], buf[len]; + off_t new_off; - req.vol_id = UBI_VOL_NUM_AUTO; - req.vol_type = type; - req.name = name; + if (off + len > vol_info->data_bytes) + len1 = vol_info->data_bytes - off; + else + len1 = 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; + if (lseek(fd, off, SEEK_SET) != off) { + failed("seek"); + err_msg("len = %d", len); + return -1; + } + if (read(fd, buf, len) != len1) { + failed("read"); + err_msg("len = %d", len); + return -1; + } - leb_size = dev_info.leb_size - dev_info.leb_size % req.alignment; - req.bytes = MIN_AVAIL_EBS * leb_size; + new_off = lseek(fd, 0, SEEK_CUR); + if (new_off != off + len1) { + if (new_off == -1) + failed("lseek"); + else + err_msg("read %d bytes from %lld, but resulting " + "offset is %lld", len1, (long long) off, (long long) new_off); + return -1; + } - if (ubi_mkvol(libubi, node, &req)) { - failed("ubi_mkvol"); - return -1; - } + for (i = 0; i < len1; i++) + ck_buf[i] = (unsigned char)(off + i); - sprintf(&vol_node[0], UBI_VOLUME_PATTERN, dev_info.dev_num, - req.vol_id); + if (memcmp(buf, ck_buf, len1)) { + err_msg("incorrect data read from offset %lld", + (long long)off); + err_msg("len = %d", len); + return -1; + } - if (ubi_get_vol_info(libubi, vol_node, &vol_info)) { - failed("ubi_get_vol_info"); - goto remove; - } + return 0; +} - if (test_read1(&vol_info)) { - err_msg("alignment = %d", req.alignment); - goto remove; - } +/* + * A helper function for test_read1(). + */ +static int test_read2(const struct ubi_vol_info *vol_info, int len) +{ + int i; + off_t offsets[] = OFFSETS(dev_info.min_io_size, vol_info->leb_size, + vol_info->data_bytes); - if (ubi_rmvol(libubi, node, req.vol_id)) { - failed("ubi_rmvol"); + for (i = 0; i < sizeof(offsets)/sizeof(off_t); i++) { + if (test_read3(vol_info, len, offsets[i])) { + err_msg("offset = %d", offsets[i]); return -1; } } return 0; - -remove: - ubi_rmvol(libubi, node, req.vol_id); - return -1; } -static int test_read2(const struct ubi_vol_info *vol_info, int len); - -static int fd; - -/* Data lengthes to test, @io - minimal I/O unit size, @s - eraseblock size */ -#define LENGTHES(io, s) \ - {1, (io), (io)+1, 2*(io), 3*(io)-1, 3*(io), \ - PAGE_SIZE-1, PAGE_SIZE-(io), 2*PAGE_SIZE, 2*PAGE_SIZE-(io), \ - (s)/2-1, (s)/2, (s)/2+1, (s)-1, (s), (s)+1, 2*(s)-(io), 2*(s), \ - 2*(s)+(io), 3*(s), 3*(s)+(io)}; - /* * A helper function for test_read(). */ @@ -256,7 +230,7 @@ static int test_read1(struct ubi_vol_info *vol_info) char vol_node[strlen(UBI_VOLUME_PATTERN) + 100]; int lengthes[] = LENGTHES(dev_info.min_io_size, vol_info->leb_size); - 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); fd = open(vol_node, O_RDWR); @@ -280,7 +254,7 @@ static int test_read1(struct ubi_vol_info *vol_info) for (i = 0; i < 512; i++) buf[i] = (unsigned char)(written + i); - ret = write(fd, &buf[0], 512); + ret = write(fd, buf, 512); if (ret == -1) { failed("write"); err_msg("written = %d, ret = %d", written, ret); @@ -318,81 +292,97 @@ close: return -1; } -static int test_read3(const struct ubi_vol_info *vol_info, int len, off_t off); - -/* - * Offsets to test, @io - minimal I/O unit size, @s - eraseblock size, @sz - - * volume size. - */ -#define OFFSETS(io, s, sz) \ - {0, (io)-1, (io), (io)+1, 2*(io)-1, 2*(io), 3*(io)-1, 3*(io), \ - PAGE_SIZE-1, PAGE_SIZE-(io), 2*PAGE_SIZE, 2*PAGE_SIZE-(io), \ - (s)/2-1, (s)/2, (s)/2+1, (s)-1, (s), (s)+1, 2*(s)-(io), 2*(s), \ - 2*(s)+(io), 3*(s), (sz)-(s)-1, (sz)-(io)-1, (sz)-PAGE_SIZE-1}; - -/* - * A helper function for test_read1(). +/** + * test_read - test UBI volume reading from different offsets. + * + * @type volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME) + * + * Thus function returns %0 in case of success and %-1 in case of failure. */ -static int test_read2(const struct ubi_vol_info *vol_info, int len) +static int test_read(int type) { + const char *name = TESTNAME ":test_read()"; + int alignments[] = ALIGNMENTS(dev_info.leb_size); + char vol_node[strlen(UBI_VOLUME_PATTERN) + 100]; + struct ubi_mkvol_request req; int i; - off_t offsets[] = OFFSETS(dev_info.min_io_size, vol_info->leb_size, - vol_info->data_bytes); - for (i = 0; i < sizeof(offsets)/sizeof(off_t); i++) { - if (test_read3(vol_info, len, offsets[i])) { - err_msg("offset = %d", offsets[i]); + for (i = 0; i < sizeof(alignments)/sizeof(int); i++) { + int leb_size; + struct ubi_vol_info vol_info; + + 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, 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_read1(&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; } -/* - * A helper function for test_read2(). - */ -static int test_read3(const struct ubi_vol_info *vol_info, int len, off_t off) +int main(int argc, char * const argv[]) { - int i, len1; - unsigned char ck_buf[len], buf[len]; - off_t new_off; + if (initial_check(argc, argv)) + return 1; - if (off + len > vol_info->data_bytes) - len1 = vol_info->data_bytes - off; - else - len1 = len; + node = argv[1]; - if (lseek(fd, off, SEEK_SET) != off) { - failed("seek"); - err_msg("len = %d", len); - return -1; - } - if (read(fd, &buf[0], len) != len1) { - failed("read"); - err_msg("len = %d", len); - return -1; + libubi = libubi_open(); + if (libubi == NULL) { + failed("libubi_open"); + return 1; } - new_off = lseek(fd, 0, SEEK_CUR); - if (new_off != off + len1) { - if (new_off == -1) - failed("lseek"); - else - err_msg("read %d bytes from %lld, but resulting " - "offset is %lld", len1, (long long) off, (long long) new_off); - return -1; + if (ubi_get_dev_info(libubi, node, &dev_info)) { + failed("ubi_get_dev_info"); + goto close; } - for (i = 0; i < len1; i++) - ck_buf[i] = (unsigned char)(off + i); - - if (memcmp(&buf[0], &ck_buf[0], len1)) { - err_msg("incorrect data read from offset %lld", - (long long)off); - err_msg("len = %d", len); - return -1; - } + if (test_static()) + goto close; + if (test_read(UBI_DYNAMIC_VOLUME)) + goto close; + if (test_read(UBI_STATIC_VOLUME)) + goto close; + libubi_close(libubi); return 0; + +close: + libubi_close(libubi); + return 1; } diff --git a/tests/ubi-tests/io_update.c b/tests/ubi-tests/io_update.c index abb6a72..d433239 100644 --- a/tests/ubi-tests/io_update.c +++ b/tests/ubi-tests/io_update.c @@ -246,8 +246,8 @@ int main(int argc, char * const argv[]) if (test_update(UBI_DYNAMIC_VOLUME)) goto close; -// if (test_update(UBI_STATIC_VOLUME)) -// goto close; + if (test_update(UBI_STATIC_VOLUME)) + goto close; libubi_close(libubi); return 0; diff --git a/tests/ubi-tests/mkvol_bad.c b/tests/ubi-tests/mkvol_bad.c index 5f2ddf0..2e3c450 100644 --- a/tests/ubi-tests/mkvol_bad.c +++ b/tests/ubi-tests/mkvol_bad.c @@ -32,41 +32,6 @@ static libubi_t libubi; static struct ubi_dev_info dev_info; const char *node; -static int test_mkvol(void); -static int test_rmvol(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_mkvol()) - goto close; - - if (test_rmvol()) - goto close; - - libubi_close(libubi); - return 0; - -close: - libubi_close(libubi); - return 1; -} - /** * test_mkvol - test that UBI mkvol ioctl rejects bad input parameters. * @@ -161,10 +126,10 @@ static int test_mkvol(void) { char name[UBI_VOL_NAME_MAX + 5]; - memset(&name[0], 'x', UBI_VOL_NAME_MAX + 1); + memset(name, 'x', UBI_VOL_NAME_MAX + 1); name[UBI_VOL_NAME_MAX + 1] = '\0'; - req.name = &name[0]; + req.name = name; ret = ubi_mkvol(libubi, node, &req); if (check_failed(ret, EINVAL, "ubi_mkvol", "name_len = %d", UBI_VOL_NAME_MAX + 1)) @@ -225,8 +190,8 @@ static int test_mkvol(void) req.bytes = 1; req.vol_type = UBI_STATIC_VOLUME; - sprintf(&nm[0], "%s:%d", name, i); - req.name = &nm[0]; + sprintf(nm, "%s:%d", name, i); + req.name = nm; if (ubi_mkvol(libubi, node, &req)) { /* @@ -302,3 +267,35 @@ static int test_rmvol(void) return 0; } + +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_mkvol()) + goto close; + + if (test_rmvol()) + goto close; + + libubi_close(libubi); + return 0; + +close: + libubi_close(libubi); + return 1; +} diff --git a/tests/ubi-tests/mkvol_basic.c b/tests/ubi-tests/mkvol_basic.c index f9f1c69..880c149 100644 --- a/tests/ubi-tests/mkvol_basic.c +++ b/tests/ubi-tests/mkvol_basic.c @@ -31,45 +31,6 @@ static libubi_t libubi; static struct ubi_dev_info dev_info; const char *node; -static int mkvol_basic(void); -static int mkvol_alignment(void); -static int mkvol_multiple(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 (mkvol_basic()) - goto close; - - if (mkvol_alignment()) - goto close; - - if (mkvol_multiple()) - goto close; - - libubi_close(libubi); - return 0; - -close: - libubi_close(libubi); - return 1; -} - /** * mkvol_alignment - create volumes with different alignments. * @@ -209,8 +170,8 @@ static int mkvol_multiple(void) req.bytes = 1; req.vol_type = UBI_STATIC_VOLUME; - sprintf(&nm[0], "%s:%d", name, i); - req.name = &nm[0]; + sprintf(nm, "%s:%d", name, i); + req.name = nm; if (ubi_mkvol(libubi, node, &req)) { if (errno == ENFILE) { @@ -251,3 +212,39 @@ remove: ubi_rmvol(libubi, node, i); return -1; } + +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 (mkvol_basic()) + goto close; + + if (mkvol_alignment()) + goto close; + + if (mkvol_multiple()) + goto close; + + libubi_close(libubi); + return 0; + +close: + libubi_close(libubi); + return 1; +} + diff --git a/tests/ubi-tests/mkvol_paral.c b/tests/ubi-tests/mkvol_paral.c index faf085c..74be5fa 100644 --- a/tests/ubi-tests/mkvol_paral.c +++ b/tests/ubi-tests/mkvol_paral.c @@ -36,7 +36,38 @@ static struct ubi_dev_info dev_info; const char *node; static int iterations = ITERATIONS; -static void * the_thread(void *ptr); +/** + * the_thread - the testing thread. + * + * @ptr thread number + */ +static void * the_thread(void *ptr) +{ + int n = (int)ptr, iter = iterations; + struct ubi_mkvol_request req; + const char *name = TESTNAME ":the_thread()"; + char nm[strlen(name) + 50]; + + req.alignment = 1; + req.bytes = dev_info.avail_bytes/ITERATIONS; + req.vol_type = UBI_DYNAMIC_VOLUME; + sprintf(nm, "%s:%d", name, n); + req.name = nm; + + while (iter--) { + req.vol_id = UBI_VOL_NUM_AUTO; + if (ubi_mkvol(libubi, node, &req)) { + failed("ubi_mkvol"); + return NULL; + } + if (ubi_rmvol(libubi, node, req.vol_id)) { + failed("ubi_rmvol"); + return NULL; + } + } + + return NULL; +} int main(int argc, char * const argv[]) { @@ -77,36 +108,3 @@ close: libubi_close(libubi); return 1; } - -/** - * the_thread - the testing thread. - * - * @ptr thread number - */ -static void * the_thread(void *ptr) -{ - int n = (int)ptr, iter = iterations; - struct ubi_mkvol_request req; - const char *name = TESTNAME ":the_thread()"; - char nm[strlen(name) + 50]; - - req.alignment = 1; - req.bytes = dev_info.avail_bytes/ITERATIONS; - req.vol_type = UBI_DYNAMIC_VOLUME; - sprintf(&nm[0], "%s:%d", name, n); - req.name = &nm[0]; - - while (iter--) { - req.vol_id = UBI_VOL_NUM_AUTO; - if (ubi_mkvol(libubi, node, &req)) { - failed("ubi_mkvol"); - return NULL; - } - if (ubi_rmvol(libubi, node, req.vol_id)) { - failed("ubi_rmvol"); - return NULL; - } - } - - return NULL; -} diff --git a/tests/ubi-tests/rsvol.c b/tests/ubi-tests/rsvol.c index d05d05a..8ec93bc 100644 --- a/tests/ubi-tests/rsvol.c +++ b/tests/ubi-tests/rsvol.c @@ -36,44 +36,6 @@ static libubi_t libubi; static struct ubi_dev_info dev_info; const char *node; -static int test_basic(int type); -static int test_rsvol(int type); - -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_basic(UBI_DYNAMIC_VOLUME)) - goto close; - if (test_basic(UBI_STATIC_VOLUME)) - goto close; - if (test_rsvol(UBI_DYNAMIC_VOLUME)) - goto close; - if (test_rsvol(UBI_STATIC_VOLUME)) - goto close; - - libubi_close(libubi); - return 0; - -close: - libubi_close(libubi); - return 1; -} - /** * test_basic - check volume re-size capability. * @@ -136,70 +98,6 @@ remove: return -1; } -static int test_rsvol1(struct ubi_vol_info *vol_info); - -/** - * test_rsvol - test UBI volume re-size. - * - * @type volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME) - * - * Thus function returns %0 in case of success and %-1 in case of failure. - */ -static int test_rsvol(int type) -{ - const char *name = TESTNAME "test_rsvol:()"; - int alignments[] = ALIGNMENTS(dev_info.leb_size); - char vol_node[strlen(UBI_VOLUME_PATTERN) + 100]; - struct ubi_mkvol_request req; - int i; - - for (i = 0; i < sizeof(alignments)/sizeof(int); i++) { - int leb_size; - struct ubi_vol_info vol_info; - - 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_rsvol1(&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; -} - /* * Helper function for test_rsvol(). */ @@ -237,7 +135,7 @@ static int test_rsvol1(struct ubi_vol_info *vol_info) } /* Write data to the volume */ - 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); fd = open(vol_node, O_RDWR); @@ -256,7 +154,7 @@ static int test_rsvol1(struct ubi_vol_info *vol_info) for (i = 0; i < bytes; i++) buf[i] = (unsigned char)i; - ret = write(fd, &buf[0], bytes); + ret = write(fd, buf, bytes); if (ret != bytes) { failed("write"); goto close; @@ -287,8 +185,8 @@ static int test_rsvol1(struct ubi_vol_info *vol_info) failed("seek"); goto close; } - memset(&buf[0], 0, bytes); - ret = read(fd, &buf[0], bytes); + memset(buf, 0, bytes); + ret = read(fd, buf, bytes); if (ret != bytes) { failed("read"); goto close; @@ -308,3 +206,100 @@ close: close(fd); return -1; } + +/** + * test_rsvol - test UBI volume re-size. + * + * @type volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME) + * + * Thus function returns %0 in case of success and %-1 in case of failure. + */ +static int test_rsvol(int type) +{ + const char *name = TESTNAME "test_rsvol:()"; + int alignments[] = ALIGNMENTS(dev_info.leb_size); + char vol_node[strlen(UBI_VOLUME_PATTERN) + 100]; + struct ubi_mkvol_request req; + int i; + + for (i = 0; i < sizeof(alignments)/sizeof(int); i++) { + int leb_size; + struct ubi_vol_info vol_info; + + 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, 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_rsvol1(&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; +} + +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_basic(UBI_DYNAMIC_VOLUME)) + goto close; + if (test_basic(UBI_STATIC_VOLUME)) + goto close; + if (test_rsvol(UBI_DYNAMIC_VOLUME)) + goto close; + if (test_rsvol(UBI_STATIC_VOLUME)) + goto close; + + libubi_close(libubi); + return 0; + +close: + libubi_close(libubi); + return 1; +} -- cgit v1.2.3