]> www.infradead.org Git - mtd-utils.git/commitdiff
ubi-tests: switch to using common.h from the top level
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Fri, 16 Nov 2012 07:56:52 +0000 (09:56 +0200)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Fri, 16 Nov 2012 08:09:54 +0000 (10:09 +0200)
Sorry, the commit is huge, I just did not have time to split it.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
12 files changed:
tests/ubi-tests/helpers.c
tests/ubi-tests/helpers.h
tests/ubi-tests/integ.c
tests/ubi-tests/io_basic.c
tests/ubi-tests/io_paral.c
tests/ubi-tests/io_read.c
tests/ubi-tests/io_update.c
tests/ubi-tests/mkvol_bad.c
tests/ubi-tests/mkvol_basic.c
tests/ubi-tests/mkvol_paral.c
tests/ubi-tests/rsvol.c
tests/ubi-tests/volrefcnt.c

index dec9d2317a5a72408e9eb1064e1985226204cc61..fadde13f2ff6bca6b102a859a6013f165094e3ab 100644 (file)
@@ -54,7 +54,7 @@ int __initial_check(const char *test, int argc, char * const argv[])
         * check this.
         */
        if (argc < 2) {
-               __errmsg(test, __func__, __LINE__,
+               __errorm(test, __func__, __LINE__,
                         "UBI character device node is not specified");
                return -1;
        }
@@ -71,7 +71,7 @@ int __initial_check(const char *test, int argc, char * const argv[])
        }
 
        if (dev_info.avail_lebs < MIN_AVAIL_EBS) {
-               __errmsg(test, __func__, __LINE__,
+               __errorm(test, __func__, __LINE__,
                         "insufficient available eraseblocks %d on UBI "
                         "device, required %d",
                         dev_info.avail_lebs, MIN_AVAIL_EBS);
@@ -79,7 +79,7 @@ int __initial_check(const char *test, int argc, char * const argv[])
        }
 
        if (dev_info.vol_count != 0) {
-               __errmsg(test, __func__, __LINE__,
+               __errorm(test, __func__, __LINE__,
                         "device %s is not empty", argv[1]);
                goto close;
        }
@@ -93,14 +93,14 @@ close:
 }
 
 /**
- * __errmsg - print a message to stderr.
+ * __errorm - print a message to stderr.
  *
  * @test  test name
  * @func  function name
  * @line  line number
  * @fmt   format string
  */
-void __errmsg(const char *test, const char *func, int line,
+void __errorm(const char *test, const char *func, int line,
              const char *fmt, ...)
 {
        va_list args;
@@ -158,31 +158,31 @@ int __check_volume(libubi_t libubi, struct ubi_dev_info *dev_info,
        }
 
        if (req->alignment != vol_info.alignment) {
-               __errmsg(test, func, line,
+               __errorm(test, func, line,
                         "bad alignment: requested %d, got %d",
                         req->alignment, vol_info.alignment);
                return -1;
        }
        if (req->vol_type != vol_info.type) {
-               __errmsg(test, func, line, "bad type: requested %d, got %d",
+               __errorm(test, func, line, "bad type: requested %d, got %d",
                         req->vol_type, vol_info.type);
                return -1;
        }
        if (strlen(req->name) != strlen(vol_info.name) ||
            strcmp(req->name, vol_info.name) != 0) {
-               __errmsg(test, func, line,
+               __errorm(test, func, line,
                         "bad name: requested \"%s\", got \"%s\"",
                         req->name, vol_info.name);
                return -1;
        }
        if (vol_info.corrupted) {
-               __errmsg(test, func, line, "corrupted new volume");
+               __errorm(test, func, line, "corrupted new volume");
                return -1;
        }
 
        leb_size = dev_info->leb_size - (dev_info->leb_size % req->alignment);
        if (leb_size != vol_info.leb_size) {
-               __errmsg(test, func, line,
+               __errorm(test, func, line,
                         "bad usable LEB size %d, should be %d",
                         vol_info.leb_size, leb_size);
                return -1;
@@ -193,7 +193,7 @@ int __check_volume(libubi_t libubi, struct ubi_dev_info *dev_info,
                rsvd_bytes += leb_size - (rsvd_bytes % leb_size);
 
        if (rsvd_bytes != vol_info.rsvd_bytes) {
-               __errmsg(test, func, line,
+               __errorm(test, func, line,
                         "bad reserved bytes %lld, should be %lld",
                         vol_info.rsvd_bytes, rsvd_bytes);
                return -1;
@@ -226,7 +226,7 @@ int __check_vol_patt(libubi_t libubi, const char *test, const char *func,
        fd = open(node, O_RDONLY);
        if (fd == -1) {
                __failed(test, func, line, "open");
-               __errmsg(test, func, line, "cannot open \"%s\"\n", node);
+               __errorm(test, func, line, "cannot open \"%s\"\n", node);
                return -1;
        }
 
@@ -243,13 +243,13 @@ int __check_vol_patt(libubi_t libubi, const char *test, const char *func,
                ret = read(fd, buf, 512);
                if (ret == -1) {
                        __failed(test, func, line, "read");
-                       __errmsg(test, func, line, "bytes = %lld, ret = %d",
+                       __errorm(test, func, line, "bytes = %lld, ret = %d",
                                 bytes, ret);
                        goto close;
                }
 
                if (ret == 0 && bytes + ret < vol_info.data_bytes) {
-                       __errmsg(test, func, line,
+                       __errorm(test, func, line,
                                 "EOF, but read only %lld bytes of %lld",
                                 bytes + ret, vol_info.data_bytes);
                        goto close;
@@ -257,7 +257,7 @@ int __check_vol_patt(libubi_t libubi, const char *test, const char *func,
 
                for (i = 0; i < ret; i++)
                        if (buf[i] != byte) {
-                               __errmsg(test, func, line,
+                               __errorm(test, func, line,
                                         "byte at %lld is not %#x but %#x",
                                         bytes + i, byte, (int)buf[i]);
                                goto close;
@@ -297,13 +297,13 @@ int __update_vol_patt(libubi_t libubi, const char *test, const char *func,
        fd = open(node, O_RDWR);
        if (fd == -1) {
                __failed(test, func, line, "open");
-               __errmsg(test, func, line, "cannot open \"%s\"\n", node);
+               __errorm(test, func, line, "cannot open \"%s\"\n", node);
                return -1;
        }
 
        if (ubi_update_start(libubi, fd, bytes)) {
                __failed(test, func, line, "ubi_update_start");
-               __errmsg(test, func, line, "bytes = %lld", bytes);
+               __errorm(test, func, line, "bytes = %lld", bytes);
                goto close;
        }
 
@@ -313,14 +313,14 @@ int __update_vol_patt(libubi_t libubi, const char *test, const char *func,
                ret = write(fd, buf, 512);
                if (ret == -1) {
                        __failed(test, func, line, "write");
-                       __errmsg(test, func, line, "written = %lld, ret = %d",
+                       __errorm(test, func, line, "written = %lld, ret = %d",
                                 written, ret);
                        goto close;
                }
                written += ret;
 
                if (written > bytes) {
-                       __errmsg(test, func, line, "update length %lld bytes, "
+                       __errorm(test, func, line, "update length %lld bytes, "
                                 "but %lld bytes are already written",
                                 bytes, written);
                        goto close;
index ae9d0308f96b6d79b0b8480af978a6fbc4c91a32..d7d6d9c217bbf60677b14b2a23949123a8f65e39 100644 (file)
@@ -34,52 +34,44 @@ extern "C" {
 #define MIN_AVAIL_EBS 5
 #define PAGE_SIZE 4096
 
-#define min(a, b) ((a) < (b) ? (a) : (b))
-
-/* Normal messages */
-#define normsg(fmt, ...) do {                                                  \
-        printf(TESTNAME ": " fmt "\n", ##__VA_ARGS__);                         \
-} while(0)
-
-#define errmsg(fmt, ...) ({                                                    \
-       __errmsg(TESTNAME, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__);        \
+#define errorm(fmt, ...) ({                                                    \
+       __errorm(PROGRAM_NAME, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__);    \
        -1;                                                                    \
 })
 
 #define failed(name) ({                                                        \
-       __failed(TESTNAME, __FUNCTION__, __LINE__, name);                      \
+       __failed(PROGRAM_NAME, __FUNCTION__, __LINE__, name);                  \
        -1;                                                                    \
 })
 
 #define initial_check(argc, argv)                                              \
-       __initial_check(TESTNAME, argc, argv)
+       __initial_check(PROGRAM_NAME, argc, argv)
 
 #define check_volume(vol_id, req)                                              \
-       __check_volume(libubi, &dev_info, TESTNAME, __FUNCTION__,              \
+       __check_volume(libubi, &dev_info, PROGRAM_NAME, __FUNCTION__,          \
                       __LINE__, vol_id, req)
 
 #define check_vol_patt(node, byte)                                             \
-       __check_vol_patt(libubi, TESTNAME, __FUNCTION__, __LINE__, node, byte)
+       __check_vol_patt(libubi, PROGRAM_NAME, __FUNCTION__, __LINE__, node, byte)
 
 #define update_vol_patt(node, bytes, byte)                                     \
-       __update_vol_patt(libubi, TESTNAME, __FUNCTION__, __LINE__,            \
+       __update_vol_patt(libubi, PROGRAM_NAME, __FUNCTION__, __LINE__,        \
                          node, bytes, byte)
 
 #define check_failed(ret, error, func, fmt, ...) ({                            \
-       int __ret;                                                             \
+       int __ret = 0;                                                         \
                                                                               \
        if (!ret) {                                                            \
-               errmsg("%s() returned success but should have failed", func);  \
-               errmsg(fmt, ##__VA_ARGS__);                                    \
+               errorm("%s() returned success but should have failed", func);  \
+               errorm(fmt, ##__VA_ARGS__);                                    \
                __ret = -1;                                                    \
-       }                                                                      \
-       if (errno != (error)) {                                                \
-               errmsg("%s failed with error %d (%s), expected %d (%s)",       \
+       } else if (errno != (error)) {                                         \
+               errorm("%s failed with error %d (%s), expected %d (%s)",       \
                       func, errno, strerror(errno), error, strerror(error));  \
-               errmsg(fmt, ##__VA_ARGS__);                                    \
+               errorm(fmt, ##__VA_ARGS__);                                    \
                __ret = -1;                                                    \
        }                                                                      \
-       __ret = 0;                                                             \
+       __ret;                                                                 \
 })
 
 /* Alignments to test, @s is eraseblock size */
@@ -92,7 +84,7 @@ extern "C" {
 
 extern int seed_random_generator(void);
 
-extern void __errmsg(const char *test, const char *func, int line,
+extern void __errorm(const char *test, const char *func, int line,
                     const char *fmt, ...);
 extern void __failed(const char *test, const char *func, int line,
                     const char *failed);
index 7ef3cf2e613466980d251bb4e52139a2b068aa98..733f367a329a23b0b0f2585006438c1e44d1f00f 100644 (file)
@@ -14,6 +14,8 @@
 #include <sys/stat.h>
 
 #include "libubi.h"
+#define PROGRAM_NAME "integ"
+#include "common.h"
 #include "helpers.h"
 
 struct erase_block_info;
index 8adb8e18887b2d4b5520d9a1139f8b2cbbc64868..3a296b4831b2dafec5c7926139cb56d552b3357a 100644 (file)
@@ -29,7 +29,8 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include "libubi.h"
-#define TESTNAME "io_basic"
+#define PROGRAM_NAME "io_basic"
+#include "common.h"
 #include "helpers.h"
 
 static libubi_t libubi;
@@ -46,7 +47,7 @@ const char *node;
 static int test_basic(int type)
 {
        struct ubi_mkvol_request req;
-       const char *name = TESTNAME ":test_basic()";
+       const char *name = PROGRAM_NAME ":test_basic()";
        char vol_node[strlen(UBI_VOLUME_PATTERN) + 100];
 
        req.vol_id = UBI_VOL_NUM_AUTO;
@@ -95,7 +96,7 @@ static int test_aligned(int type)
 {
        unsigned int i, ebsz;
        struct ubi_mkvol_request req;
-       const char *name = TESTNAME ":test_aligned()";
+       const char *name = PROGRAM_NAME ":test_aligned()";
        char vol_node[strlen(UBI_VOLUME_PATTERN) + 100];
        int alignments[] = ALIGNMENTS(dev_info.leb_size);
 
index 4764255ec3d94bf3f300589f1e0ec9f3e6c06f00..becbb522cb88cfa123c8665f8767bba16b18fd7d 100644 (file)
@@ -20,7 +20,6 @@
  * This test does a lot of I/O to volumes in parallel.
  */
 
-#define _XOPEN_SOURCE 500
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
@@ -31,7 +30,8 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include "libubi.h"
-#define TESTNAME "io_paral"
+#define PROGRAM_NAME "io_paral"
+#include "common.h"
 #include "helpers.h"
 
 #define THREADS_NUM 4
@@ -59,7 +59,7 @@ static int update_volume(int vol_id, int bytes)
        fd = open(vol_node, O_RDWR);
        if (fd == -1) {
                failed("open");
-               errmsg("cannot open \"%s\"\n", vol_node);
+               errorm("cannot open \"%s\"\n", vol_node);
                return -1;
        }
 
@@ -70,7 +70,7 @@ static int update_volume(int vol_id, int bytes)
        ret = ubi_update_start(libubi, fd, bytes);
        if (ret) {
                failed("ubi_update_start");
-               errmsg("volume id is %d", vol_id);
+               errorm("volume id is %d", vol_id);
                goto err_close;
        }
 
@@ -83,10 +83,10 @@ static int update_volume(int vol_id, int bytes)
                ret = write(fd, wbuf + written, to_write);
                if (ret != to_write) {
                        failed("write");
-                       errmsg("failed to write %d bytes at offset %d "
+                       errorm("failed to write %d bytes at offset %d "
                               "of volume %d", to_write, written,
                               vol_id);
-                       errmsg("update: %d bytes", bytes);
+                       errorm("update: %d bytes", bytes);
                        goto err_close;
                }
 
@@ -98,7 +98,7 @@ static int update_volume(int vol_id, int bytes)
        fd = open(vol_node, O_RDONLY);
        if (fd == -1) {
                failed("open");
-               errmsg("cannot open \"%s\"\n", node);
+               errorm("cannot open \"%s\"\n", node);
                return -1;
        }
 
@@ -112,7 +112,7 @@ static int update_volume(int vol_id, int bytes)
                ret = read(fd, rbuf + rd, to_read);
                if (ret != to_read) {
                        failed("read");
-                       errmsg("failed to read %d bytes at offset %d "
+                       errorm("failed to read %d bytes at offset %d "
                               "of volume %d", to_read, rd, vol_id);
                        goto err_close;
                }
@@ -121,7 +121,7 @@ static int update_volume(int vol_id, int bytes)
        }
 
        if (memcmp(wbuf, rbuf, bytes)) {
-               errmsg("written and read data are different");
+               errorm("written and read data are different");
                goto err_close;
        }
 
@@ -146,13 +146,13 @@ static void *update_thread(void *ptr)
                        ret = ubi_rmvol(libubi, node, vol_id);
                        if (ret) {
                                failed("ubi_rmvol");
-                               errmsg("cannot remove volume %d", vol_id);
+                               errorm("cannot remove volume %d", vol_id);
                                return NULL;
                        }
                        ret = ubi_mkvol(libubi, node, &reqests[vol_id]);
                        if (ret) {
                                failed("ubi_mkvol");
-                               errmsg("cannot create volume %d", vol_id);
+                               errorm("cannot create volume %d", vol_id);
                                return NULL;
                        }
                }
@@ -175,14 +175,14 @@ static void *write_thread(void *ptr)
        fd = open(vol_node, O_RDWR);
        if (fd == -1) {
                failed("open");
-               errmsg("cannot open \"%s\"\n", vol_node);
+               errorm("cannot open \"%s\"\n", vol_node);
                return NULL;
        }
 
        ret = ubi_set_property(fd, UBI_VOL_PROP_DIRECT_WRITE, 1);
        if (ret) {
                failed("ubi_set_property");
-               errmsg("cannot set property for \"%s\"\n", vol_node);
+               errorm("cannot set property for \"%s\"\n", vol_node);
        }
 
        for (i = 0; i < ITERATIONS * VOL_LEBS; i++) {
@@ -192,7 +192,7 @@ static void *write_thread(void *ptr)
                ret = ubi_leb_unmap(fd, leb);
                if (ret) {
                        failed("ubi_leb_unmap");
-                       errmsg("cannot unmap LEB %d", leb);
+                       errorm("cannot unmap LEB %d", leb);
                        break;
                }
 
@@ -203,7 +203,7 @@ static void *write_thread(void *ptr)
                ret = pwrite(fd, wbuf, dev_info.leb_size, offs);
                if (ret != dev_info.leb_size) {
                        failed("pwrite");
-                       errmsg("cannot write %d bytes to offs %lld, wrote %d",
+                       errorm("cannot write %d bytes to offs %lld, wrote %d",
                                dev_info.leb_size, offs, ret);
                        break;
                }
@@ -212,14 +212,14 @@ static void *write_thread(void *ptr)
                ret = pread(fd, rbuf, dev_info.leb_size, offs);
                if (ret != dev_info.leb_size) {
                        failed("read");
-                       errmsg("failed to read %d bytes at offset %d "
+                       errorm("failed to read %d bytes at offset %d "
                               "of volume %d", dev_info.leb_size, offs,
                               vol_id);
                        break;
                }
 
                if (memcmp(wbuf, rbuf, dev_info.leb_size)) {
-                       errmsg("written and read data are different");
+                       errorm("written and read data are different");
                        break;
                }
        }
@@ -259,7 +259,7 @@ int main(int argc, char * const argv[])
                reqests[i].alignment = 1;
                reqests[i].bytes = vol_size;
                reqests[i].vol_id = i;
-               sprintf(vol_name[i], TESTNAME":%d", i);
+               sprintf(vol_name[i], PROGRAM_NAME":%d", i);
                reqests[i].name = vol_name[i];
                reqests[i].vol_type = UBI_DYNAMIC_VOLUME;
                if (i == THREADS_NUM)
index 27d4d5842ee056ee18efb48344876e13fa2e3f23..673624f3ae3ffd9a2e7126fa918bbc1c8f206eb7 100644 (file)
@@ -29,7 +29,8 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include "libubi.h"
-#define TESTNAME "io_basic"
+#define PROGRAM_NAME "io_basic"
+#include "common.h"
 #include "helpers.h"
 
 static libubi_t libubi;
@@ -62,7 +63,7 @@ static int fd;
 static int test_static(void)
 {
        struct ubi_mkvol_request req;
-       const char *name = TESTNAME ":io_basic()";
+       const char *name = PROGRAM_NAME ":io_basic()";
        char vol_node[strlen(UBI_VOLUME_PATTERN) + 100];
        struct ubi_vol_info vol_info;
        int fd, ret;
@@ -84,7 +85,7 @@ static int test_static(void)
        fd = open(vol_node, O_RDWR);
        if (fd == -1) {
                failed("open");
-               errmsg("cannot open \"%s\"\n", node);
+               errorm("cannot open \"%s\"\n", node);
                goto remove;
        }
 
@@ -95,7 +96,7 @@ static int test_static(void)
 
        /* Make sure new static volume contains no data */
        if (vol_info.data_bytes != 0) {
-               errmsg("data_bytes = %lld, not zero", vol_info.data_bytes);
+               errorm("data_bytes = %lld, not zero", vol_info.data_bytes);
                goto close;
        }
 
@@ -106,7 +107,7 @@ static int test_static(void)
                goto close;
        }
        if (ret != 0) {
-               errmsg("read data from free static volume");
+               errorm("read data from free static volume");
                goto close;
        }
 
@@ -121,7 +122,7 @@ static int test_static(void)
                goto close;
        }
        if (ret != 10) {
-               errmsg("written %d bytes", ret);
+               errorm("written %d bytes", ret);
                goto close;
        }
 
@@ -135,7 +136,7 @@ static int test_static(void)
                goto close;
        }
        if (ret != 10) {
-               errmsg("read %d bytes", ret);
+               errorm("read %d bytes", ret);
                goto close;
        }
 
@@ -170,12 +171,12 @@ static int test_read3(const struct ubi_vol_info *vol_info, int len, off_t off)
 
        if (lseek(fd, off, SEEK_SET) != off) {
                failed("seek");
-               errmsg("len = %d", len);
+               errorm("len = %d", len);
                return -1;
        }
        if (read(fd, buf, len) != len1) {
                failed("read");
-               errmsg("len = %d", len);
+               errorm("len = %d", len);
                return -1;
        }
 
@@ -184,7 +185,7 @@ static int test_read3(const struct ubi_vol_info *vol_info, int len, off_t off)
                if (new_off == -1)
                        failed("lseek");
                else
-                       errmsg("read %d bytes from %lld, but resulting "
+                       errorm("read %d bytes from %lld, but resulting "
                               "offset is %lld", len1, (long long) off, (long long) new_off);
                return -1;
        }
@@ -193,9 +194,9 @@ static int test_read3(const struct ubi_vol_info *vol_info, int len, off_t off)
                ck_buf[i] = (unsigned char)(off + i);
 
        if (memcmp(buf, ck_buf, len1)) {
-               errmsg("incorrect data read from offset %lld",
+               errorm("incorrect data read from offset %lld",
                       (long long)off);
-               errmsg("len = %d", len);
+               errorm("len = %d", len);
                return -1;
        }
 
@@ -213,7 +214,7 @@ static int test_read2(const struct ubi_vol_info *vol_info, int len)
 
        for (i = 0; i < sizeof(offsets)/sizeof(off_t); i++) {
                if (test_read3(vol_info, len, offsets[i])) {
-                       errmsg("offset = %d", offsets[i]);
+                       errorm("offset = %d", offsets[i]);
                        return -1;
                }
        }
@@ -236,14 +237,14 @@ static int test_read1(struct ubi_vol_info *vol_info)
        fd = open(vol_node, O_RDWR);
        if (fd == -1) {
                failed("open");
-               errmsg("cannot open \"%s\"\n", node);
+               errorm("cannot open \"%s\"\n", node);
                return -1;
        }
 
        /* Write some pattern to the volume */
        if (ubi_update_start(libubi, fd, vol_info->rsvd_bytes)) {
                failed("ubi_update_start");
-               errmsg("bytes = %lld", vol_info->rsvd_bytes);
+               errorm("bytes = %lld", vol_info->rsvd_bytes);
                goto close;
        }
 
@@ -257,7 +258,7 @@ static int test_read1(struct ubi_vol_info *vol_info)
                ret = write(fd, buf, 512);
                if (ret == -1) {
                        failed("write");
-                       errmsg("written = %d, ret = %d", written, ret);
+                       errorm("written = %d, ret = %d", written, ret);
                        goto close;
                }
                written += ret;
@@ -273,13 +274,13 @@ static int test_read1(struct ubi_vol_info *vol_info)
        fd = open(vol_node, O_RDONLY);
        if (fd == -1) {
                failed("open");
-               errmsg("cannot open \"%s\"\n", node);
+               errorm("cannot open \"%s\"\n", node);
                return -1;
        }
 
        for (i = 0; i < sizeof(lengthes)/sizeof(int); i++) {
                if (test_read2(vol_info, lengthes[i])) {
-                       errmsg("length = %d", lengthes[i]);
+                       errorm("length = %d", lengthes[i]);
                        goto close;
                }
        }
@@ -301,7 +302,7 @@ close:
  */
 static int test_read(int type)
 {
-       const char *name = TESTNAME ":test_read()";
+       const char *name = PROGRAM_NAME ":test_read()";
        int alignments[] = ALIGNMENTS(dev_info.leb_size);
        char vol_node[strlen(UBI_VOLUME_PATTERN) + 100];
        struct ubi_mkvol_request req;
@@ -337,7 +338,7 @@ static int test_read(int type)
                }
 
                if (test_read1(&vol_info)) {
-                       errmsg("alignment = %d", req.alignment);
+                       errorm("alignment = %d", req.alignment);
                        goto remove;
                }
 
index 27ece520dd73ade77cb75266415010cfa41b4827..29dd1257b9ebddcbf5841dc1c1c41a7661608f15 100644 (file)
@@ -31,7 +31,8 @@
 
 #include <libubi.h>
 #include <mtd/ubi-user.h>
-#define TESTNAME "io_update"
+#define PROGRAM_NAME "io_update"
+#include "common.h"
 #include "helpers.h"
 
 static libubi_t libubi;
@@ -84,7 +85,7 @@ static int test_update1(struct ubi_vol_info *vol_info, int leb_change)
        fd = open(vol_node, O_RDWR);
        if (fd == -1) {
                failed("open");
-               errmsg("cannot open \"%s\"\n", node);
+               errorm("cannot open \"%s\"\n", node);
                return -1;
        }
 
@@ -143,13 +144,13 @@ static int test_update1(struct ubi_vol_info *vol_info, int leb_change)
                        ret = write(fd, buf + off, len);
                        if (ret < 0) {
                                failed("write");
-                               errmsg("failed to write %d bytes at offset "
+                               errorm("failed to write %d bytes at offset "
                                       "%lld", len, (long long)off);
                                goto close;
                        }
                        len = l;
                        if (ret != len) {
-                               errmsg("failed to write %d bytes at offset "
+                               errorm("failed to write %d bytes at offset "
                                       "%lld, wrote %d", len, (long long)off, ret);
                                goto close;
                        }
@@ -159,7 +160,7 @@ static int test_update1(struct ubi_vol_info *vol_info, int leb_change)
                /* Check data */
                if ((ret = lseek(fd, 0, SEEK_SET)) != 0) {
                        failed("lseek");
-                       errmsg("cannot seek to 0");
+                       errorm("cannot seek to 0");
                        goto close;
                }
 
@@ -175,15 +176,15 @@ static int test_update1(struct ubi_vol_info *vol_info, int leb_change)
                        ret = read(fd, buf1, test_len);
                if (ret < 0) {
                        failed("read");
-                       errmsg("failed to read %d bytes", test_len);
+                       errorm("failed to read %d bytes", test_len);
                        goto close;
                }
                if (ret != test_len) {
-                       errmsg("failed to read %d bytes, read %d", test_len, ret);
+                       errorm("failed to read %d bytes, read %d", test_len, ret);
                        goto close;
                }
                if (memcmp(buf, buf1, test_len)) {
-                       errmsg("data corruption");
+                       errorm("data corruption");
                        goto close;
                }
        }
@@ -206,7 +207,7 @@ close:
 static int test_update(int type)
 {
        struct ubi_mkvol_request req;
-       const char *name = TESTNAME ":io_update()";
+       const char *name = PROGRAM_NAME ":io_update()";
        int alignments[] = ALIGNMENTS(dev_info.leb_size);
        struct ubi_vol_info vol_info;
        char vol_node[strlen(UBI_VOLUME_PATTERN) + 100];
@@ -240,13 +241,13 @@ static int test_update(int type)
                }
 
                if (test_update1(&vol_info, 0)) {
-                       errmsg("alignment = %d", req.alignment);
+                       errorm("alignment = %d", req.alignment);
                        goto remove;
                }
 
                if (vol_info.type != UBI_STATIC_VOLUME) {
                        if (test_update1(&vol_info, 1)) {
-                               errmsg("alignment = %d", req.alignment);
+                               errorm("alignment = %d", req.alignment);
                                goto remove;
                        }
                }
index 2292df6f8095bf3eba6da3c3d28556b9e7742f77..27f4795ca292a39592374fa0933e458a3868dbea 100644 (file)
@@ -25,7 +25,8 @@
 #include <errno.h>
 #include <stdio.h>
 #include "libubi.h"
-#define TESTNAME "mkvol_bad"
+#define PROGRAM_NAME "mkvol_bad"
+#include "common.h"
 #include "helpers.h"
 
 static libubi_t libubi;
@@ -41,7 +42,7 @@ static int test_mkvol(void)
 {
        int ret, i;
        struct ubi_mkvol_request req;
-       const char *name = TESTNAME ":test_mkvol()";
+       const char *name = PROGRAM_NAME ":test_mkvol()";
 
        req.alignment = 1;
        req.bytes = dev_info.avail_bytes;
@@ -201,7 +202,7 @@ static int test_mkvol(void)
                        if (errno == ENFILE)
                                break;
                        failed("ubi_mkvol");
-                       errmsg("vol_id %d", i);
+                       errorm("vol_id %d", i);
                        goto remove;
                }
        }
@@ -226,7 +227,7 @@ static int test_rmvol(void)
 {
        int ret;
        struct ubi_mkvol_request req;
-       const char *name = TESTNAME ":test_rmvol()";
+       const char *name = PROGRAM_NAME ":test_rmvol()";
 
        /* Bad vol_id */
        ret = ubi_rmvol(libubi, node, -1);
index 1a02c4708fe1fb20dd48d4ec7525216b7b27347e..cda72410e2a93591ff1ead3ac90184039bb4edcf 100644 (file)
@@ -24,7 +24,8 @@
 #include <errno.h>
 #include <string.h>
 #include "libubi.h"
-#define TESTNAME "mkvol_basic"
+#define PROGRAM_NAME "mkvol_basic"
+#include "common.h"
 #include "helpers.h"
 
 static libubi_t libubi;
@@ -40,7 +41,7 @@ static int mkvol_alignment(void)
 {
        struct ubi_mkvol_request req;
        int i, vol_id, ebsz;
-       const char *name = TESTNAME ":mkvol_alignment()";
+       const char *name = PROGRAM_NAME ":mkvol_alignment()";
        int alignments[] = ALIGNMENTS(dev_info.leb_size);
 
        for (i = 0; i < sizeof(alignments)/sizeof(int); i++) {
@@ -61,7 +62,7 @@ static int mkvol_alignment(void)
 
                if (ubi_mkvol(libubi, node, &req)) {
                        failed("ubi_mkvol");
-                       errmsg("alignment %d", req.alignment);
+                       errorm("alignment %d", req.alignment);
                        return -1;
                }
 
@@ -92,7 +93,7 @@ static int mkvol_basic(void)
        struct ubi_mkvol_request req;
        struct ubi_vol_info vol_info;
        int vol_id, ret;
-       const char *name = TESTNAME ":mkvol_basic()";
+       const char *name = PROGRAM_NAME ":mkvol_basic()";
 
        /* Create dynamic volume of maximum size */
        req.vol_id = UBI_VOL_NUM_AUTO;
@@ -139,7 +140,7 @@ static int mkvol_basic(void)
        /* Make sure volume does not exist */
        ret = ubi_get_vol_info1(libubi, dev_info.dev_num, vol_id, &vol_info);
        if (ret == 0) {
-               errmsg("removed volume %d exists", vol_id);
+               errorm("removed volume %d exists", vol_id);
                goto remove;
        }
 
@@ -159,7 +160,7 @@ static int mkvol_multiple(void)
 {
        struct ubi_mkvol_request req;
        int i, ret, max = dev_info.max_vol_count;
-       const char *name = TESTNAME ":mkvol_multiple()";
+       const char *name = PROGRAM_NAME ":mkvol_multiple()";
 
        /* Create maximum number of volumes */
        for (i = 0; i < max; i++) {
@@ -179,12 +180,12 @@ static int mkvol_multiple(void)
                                break;
                        }
                        failed("ubi_mkvol");
-                       errmsg("vol_id %d", i);
+                       errorm("vol_id %d", i);
                        goto remove;
                }
 
                if (check_volume(req.vol_id, &req)) {
-                       errmsg("vol_id %d", i);
+                       errorm("vol_id %d", i);
                        goto remove;
                }
        }
@@ -200,7 +201,7 @@ static int mkvol_multiple(void)
                /* Make sure volume does not exist */
                ret = ubi_get_vol_info1(libubi, dev_info.dev_num, i, &vol_info);
                if (ret == 0) {
-                       errmsg("removed volume %d exists", i);
+                       errorm("removed volume %d exists", i);
                        goto remove;
                }
        }
index 4a6ae465357af1e554f910c281368888eafd0d79..95b5e104ee1598b967543f3e69d7db5f96a52f54 100644 (file)
@@ -25,7 +25,8 @@
 #include <string.h>
 #include <pthread.h>
 #include "libubi.h"
-#define TESTNAME "mkvol_paral"
+#define PROGRAM_NAME "mkvol_paral"
+#include "common.h"
 #include "helpers.h"
 
 #define THREADS_NUM 4
@@ -45,7 +46,7 @@ static void * the_thread(void *ptr)
 {
        int n = (long)ptr, iter = iterations;
        struct ubi_mkvol_request req;
-       const char *name =  TESTNAME ":the_thread()";
+       const char *name =  PROGRAM_NAME ":the_thread()";
        char nm[strlen(name) + 50];
 
        req.alignment = 1;
index 50d642952aa2e41c2c6485df3c1854052c8eec54..60badb0bb4b29c7a52a3b20db832ff533953658a 100644 (file)
@@ -29,7 +29,8 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include "libubi.h"
-#define TESTNAME "rsvol"
+#define PROGRAM_NAME "rsvol"
+#include "common.h"
 #include "helpers.h"
 
 static libubi_t libubi;
@@ -46,7 +47,7 @@ const char *node;
 static int test_basic(int type)
 {
        struct ubi_mkvol_request req;
-       const char *name = TESTNAME ":test_basic()";
+       const char *name = PROGRAM_NAME ":test_basic()";
 
        req.vol_id = UBI_VOL_NUM_AUTO;
        req.alignment = 1;
@@ -123,13 +124,13 @@ static int test_rsvol1(struct ubi_vol_info *vol_info)
        }
 
        if (vol_info1.rsvd_bytes != bytes) {
-               errmsg("rsvd_bytes %lld, must be %lld",
+               errorm("rsvd_bytes %lld, must be %lld",
                       vol_info1.rsvd_bytes, bytes);
                return -1;
        }
 
        if (vol_info1.rsvd_lebs != vol_info->rsvd_lebs - 1) {
-               errmsg("rsvd_lebs %d, must be %d",
+               errorm("rsvd_lebs %d, must be %d",
                       vol_info1.rsvd_lebs, vol_info->rsvd_lebs - 1);
                return -1;
        }
@@ -141,7 +142,7 @@ static int test_rsvol1(struct ubi_vol_info *vol_info)
        fd = open(vol_node, O_RDWR);
        if (fd == -1) {
                failed("open");
-               errmsg("cannot open \"%s\"\n", vol_node);
+               errorm("cannot open \"%s\"\n", vol_node);
                return -1;
        }
 
@@ -176,7 +177,7 @@ static int test_rsvol1(struct ubi_vol_info *vol_info)
        fd = open(vol_node, O_RDWR);
        if (fd == -1) {
                failed("open");
-               errmsg("cannot open \"%s\"\n", vol_node);
+               errorm("cannot open \"%s\"\n", vol_node);
                return -1;
        }
 
@@ -194,7 +195,7 @@ static int test_rsvol1(struct ubi_vol_info *vol_info)
 
        for (i = 0; i < bytes; i++) {
                if (buf[i] != (unsigned char)i) {
-                       errmsg("bad data");
+                       errorm("bad data");
                        goto close;
                }
        }
@@ -216,7 +217,7 @@ close:
  */
 static int test_rsvol(int type)
 {
-       const char *name = TESTNAME "test_rsvol:()";
+       const char *name = PROGRAM_NAME "test_rsvol:()";
        int alignments[] = ALIGNMENTS(dev_info.leb_size);
        char vol_node[strlen(UBI_VOLUME_PATTERN) + 100];
        struct ubi_mkvol_request req;
@@ -252,7 +253,7 @@ static int test_rsvol(int type)
                }
 
                if (test_rsvol1(&vol_info)) {
-                       errmsg("alignment = %d", req.alignment);
+                       errorm("alignment = %d", req.alignment);
                        goto remove;
                }
 
index 1700ab7a4a83f0d0ae4c61cf255ac72c8f7d95a4..591a55a9092fd778ea6821f205a6b36f2dab27c6 100644 (file)
@@ -29,7 +29,8 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include "libubi.h"
-#define TESTNAME "rmvol"
+#define PROGRAM_NAME "rmvol"
+#include "common.h"
 #include "helpers.h"
 
 #define SYSFS_FILE "/sys/class/ubi/ubi%d_%d/usable_eb_size"
@@ -76,7 +77,7 @@ int main(int argc, char * const argv[])
        sprintf(fname, SYSFS_FILE, dev_info.dev_num, req.vol_id);
        fd = open(fname, O_RDONLY);
        if (fd == -1) {
-               errmsg("cannot open %s", fname);
+               errorm("cannot open %s", fname);
                failed("open");
                goto out_rmvol;
        }
@@ -91,7 +92,7 @@ int main(int argc, char * const argv[])
        /* Try to read from the file, this should fail */
        ret = read(fd, tmp, 100);
        if (ret != -1) {
-               errmsg("read returned %d, expected -1", ret);
+               errorm("read returned %d, expected -1", ret);
                failed("read");
                goto out_close;
        }
@@ -100,7 +101,7 @@ int main(int argc, char * const argv[])
        close(fd);
        fd = open(fname, O_RDONLY);
        if (fd != -1) {
-               errmsg("opened %s again, open returned %d, expected -1",
+               errorm("opened %s again, open returned %d, expected -1",
                       fname, fd);
                failed("open");
                goto out_libubi;