diff options
| author | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2012-11-16 09:56:52 +0200 | 
|---|---|---|
| committer | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2012-11-16 10:09:54 +0200 | 
| commit | 7343528e5821c69224000ed7cfd3e8aaf47b7a93 (patch) | |
| tree | 8f283ceefef028996c0ce1b5de9bf5214ed8752c /tests/ubi-tests | |
| parent | 98ed9f3360bb5cbfb02d2cb82ee3167fce437772 (diff) | |
ubi-tests: switch to using common.h from the top level
Sorry, the commit is huge, I just did not have time to split it.
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'tests/ubi-tests')
| -rw-r--r-- | tests/ubi-tests/helpers.c | 38 | ||||
| -rw-r--r-- | tests/ubi-tests/helpers.h | 38 | ||||
| -rw-r--r-- | tests/ubi-tests/integ.c | 2 | ||||
| -rw-r--r-- | tests/ubi-tests/io_basic.c | 7 | ||||
| -rw-r--r-- | tests/ubi-tests/io_paral.c | 36 | ||||
| -rw-r--r-- | tests/ubi-tests/io_read.c | 41 | ||||
| -rw-r--r-- | tests/ubi-tests/io_update.c | 23 | ||||
| -rw-r--r-- | tests/ubi-tests/mkvol_bad.c | 9 | ||||
| -rw-r--r-- | tests/ubi-tests/mkvol_basic.c | 19 | ||||
| -rw-r--r-- | tests/ubi-tests/mkvol_paral.c | 5 | ||||
| -rw-r--r-- | tests/ubi-tests/rsvol.c | 19 | ||||
| -rw-r--r-- | tests/ubi-tests/volrefcnt.c | 9 | 
12 files changed, 124 insertions, 122 deletions
| diff --git a/tests/ubi-tests/helpers.c b/tests/ubi-tests/helpers.c index dec9d23..fadde13 100644 --- a/tests/ubi-tests/helpers.c +++ b/tests/ubi-tests/helpers.c @@ -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; diff --git a/tests/ubi-tests/helpers.h b/tests/ubi-tests/helpers.h index ae9d030..d7d6d9c 100644 --- a/tests/ubi-tests/helpers.h +++ b/tests/ubi-tests/helpers.h @@ -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); diff --git a/tests/ubi-tests/integ.c b/tests/ubi-tests/integ.c index 7ef3cf2..733f367 100644 --- a/tests/ubi-tests/integ.c +++ b/tests/ubi-tests/integ.c @@ -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; diff --git a/tests/ubi-tests/io_basic.c b/tests/ubi-tests/io_basic.c index 8adb8e1..3a296b4 100644 --- a/tests/ubi-tests/io_basic.c +++ b/tests/ubi-tests/io_basic.c @@ -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); diff --git a/tests/ubi-tests/io_paral.c b/tests/ubi-tests/io_paral.c index 4764255..becbb52 100644 --- a/tests/ubi-tests/io_paral.c +++ b/tests/ubi-tests/io_paral.c @@ -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) diff --git a/tests/ubi-tests/io_read.c b/tests/ubi-tests/io_read.c index 27d4d58..673624f 100644 --- a/tests/ubi-tests/io_read.c +++ b/tests/ubi-tests/io_read.c @@ -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;  		} diff --git a/tests/ubi-tests/io_update.c b/tests/ubi-tests/io_update.c index 27ece52..29dd125 100644 --- a/tests/ubi-tests/io_update.c +++ b/tests/ubi-tests/io_update.c @@ -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;  			}  		} diff --git a/tests/ubi-tests/mkvol_bad.c b/tests/ubi-tests/mkvol_bad.c index 2292df6..27f4795 100644 --- a/tests/ubi-tests/mkvol_bad.c +++ b/tests/ubi-tests/mkvol_bad.c @@ -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); diff --git a/tests/ubi-tests/mkvol_basic.c b/tests/ubi-tests/mkvol_basic.c index 1a02c47..cda7241 100644 --- a/tests/ubi-tests/mkvol_basic.c +++ b/tests/ubi-tests/mkvol_basic.c @@ -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;  		}  	} diff --git a/tests/ubi-tests/mkvol_paral.c b/tests/ubi-tests/mkvol_paral.c index 4a6ae46..95b5e10 100644 --- a/tests/ubi-tests/mkvol_paral.c +++ b/tests/ubi-tests/mkvol_paral.c @@ -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; diff --git a/tests/ubi-tests/rsvol.c b/tests/ubi-tests/rsvol.c index 50d6429..60badb0 100644 --- a/tests/ubi-tests/rsvol.c +++ b/tests/ubi-tests/rsvol.c @@ -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;  		} diff --git a/tests/ubi-tests/volrefcnt.c b/tests/ubi-tests/volrefcnt.c index 1700ab7..591a55a 100644 --- a/tests/ubi-tests/volrefcnt.c +++ b/tests/ubi-tests/volrefcnt.c @@ -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; | 
