* Re: [PATCH 00/27] mtd-utils: make integck test independent
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
@ 2011-04-13 15:16 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 01/27] fs-tests: integck: shrink dir_entry_info structure size Artem Bityutskiy
` (26 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:16 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
On Wed, 2011-04-13 at 18:18 +0300, Artem Bityutskiy wrote:
> Hi, here is a patch-set which makes the integck test independent on the
> common code which tests in tests/fs-tests/ directory share. You may be
> wondering why the hack you need this :-) The explanation is rather long.
Note, I realize that some patches are not ideal and contain unrelated
changes, that's because I tried to save time - after all, there are may
be a couple of guys who use integck and care about it.
Also, forgot to mention that there are just random clean-ups and
improvements in the series. For the same time saving reasons I did not
bother to separate them out. Simply because I do not think anyway really
cares and would benefit from this.
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH 00/27] mtd-utils: make integck test independent
@ 2011-04-13 15:18 Artem Bityutskiy
2011-04-13 15:16 ` Artem Bityutskiy
` (27 more replies)
0 siblings, 28 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
Hi, here is a patch-set which makes the integck test independent on the
common code which tests in tests/fs-tests/ directory share. You may be
wondering why the hack you need this :-) The explanation is rather long.
Q: Why you need to have integck independent?
A: Well, first of all I think integck is the only cool and useful test
in the whole fs-tests directory. To other ones are not really useful.
And I do not want to touch them at all.
I plan to improve integck later, and this is preparation work. My
improvements require nice error handling - not just dying in CHECK()
macro. Do do this, I'll need to touch a lot of that common code. But
since it is shared, I may brake some of the other tests if I touch it.
Thus, I want to have integck independent on the other tests as the
first step. And this patch-set is actually the preparation to the
further planned work.
Q: So what are you going to do next?
A: Next I want to make all functions return error nicely (and free resources)
if a write or any other FS modification operation fails. Currently the
integck test just exits.
Q: Why you need that?
A: To test UBIFS with the power-cut emulation feature on. UBIFS can emulate
power cuts, which means that integck may get an error at any time. In this
case the test should be able to re-mount the tested file-system, check that
fsync()'ed files are correct, and continue the testing. So nice error handling
is just a preparation work.
And longer term this is needed for unstable bits testing. I have UBI patches
which emulates power cuts and unstable bits, and UBIFS is supposed to handle
them nicely. But it does not currently. And to fix UBI/UBIFS i need a good
test which is able to recover when a power cut is emulated and which is able
to check integrity of those files which were fsync()'ed before the emulated
power cut. But this is long-term plan. Hopefully I'll be able to finish
this, but any help will be appreciated.
So, for now just these small preparations.
Artem.
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH 01/27] fs-tests: integck: shrink dir_entry_info structure size
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
2011-04-13 15:16 ` Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 02/27] fs-tests: integck: shrink file_info " Artem Bityutskiy
` (25 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Turn "int checked" flag into 'char' flag to lessen memory
consumption a bit. Indeed, the test allocates a lot of these
data objects, so the size decrease from 36 to 32 bytes on
32-bit platforms is good to have.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 88def58..c00e67e 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -89,14 +89,14 @@ struct dir_entry_info /* Each entry in a directory has one of these */
struct dir_entry_info *prev_link; /* List of hard links for same file */
char *name;
struct dir_info *parent; /* Parent directory */
- char type; /* f => file, d => dir, s => symlink */
- int checked; /* Temporary flag used when checking */
union {
struct file_info *file;
struct dir_info *dir;
struct symlink_info *symlink;
void *target;
};
+ char type; /* f => file, d => dir, s => symlink */
+ char checked; /* Temporary flag used when checking */
};
struct fd_info /* We keep a number of files open */
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 02/27] fs-tests: integck: shrink file_info structure size
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
2011-04-13 15:16 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 01/27] fs-tests: integck: shrink dir_entry_info structure size Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 03/27] fs-tests: integck: srink file_info structure even more Artem Bityutskiy
` (24 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
We do not have to store boolean flags in 'int' variables which
consume 4 bytes each, we can store those in bit-fields instead.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index c00e67e..f203e3a 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -58,10 +58,10 @@ struct file_info /* Each file has one of these */
/* Record in order all writes to the file */
struct fd_info *fds; /* All open file descriptors for this file */
struct dir_entry_info *links;
- int link_count;
off_t length;
- int deleted; /* File has been deleted but is still open */
- int no_space_error; /* File has incurred a ENOSPC error */
+ int link_count;
+ unsigned int deleted:1; /* File has been deleted but is still open */
+ unsigned int no_space_error:1; /* File has incurred a ENOSPC error */
uint64_t check_run_no; /* Run number used when checking */
};
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 03/27] fs-tests: integck: srink file_info structure even more
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (2 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 02/27] fs-tests: integck: shrink file_info " Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 04/27] fs-tests: integck: abuse random_offset field nicer Artem Bityutskiy
` (23 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
The 'check_run_no' field does not have to be 64-bit, it can be
32-bit instead and we can save 4 bytes per object. Actually, it
could also be 16-bit, and we could make link_count 16-bit as well,
but that would need a bit more work.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index f203e3a..0ff94c5 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -60,9 +60,9 @@ struct file_info /* Each file has one of these */
struct dir_entry_info *links;
off_t length;
int link_count;
+ unsigned int check_run_no; /* Run number used when checking */
unsigned int deleted:1; /* File has been deleted but is still open */
unsigned int no_space_error:1; /* File has incurred a ENOSPC error */
- uint64_t check_run_no; /* Run number used when checking */
};
struct symlink_info /* Each symlink has one of these */
@@ -134,7 +134,7 @@ static int can_mmap = 0; /* Can write via mmap */
static long mem_page_size; /* Page size for mmap */
-static uint64_t check_run_no;
+static unsigned int check_run_no;
/*
* Allocate a buffer of 'size' bytes and fill it with zeroes.
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 04/27] fs-tests: integck: abuse random_offset field nicer
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (3 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 03/27] fs-tests: integck: srink file_info structure even more Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 05/27] fs-tests: integck: shrink write_info even more Artem Bityutskiy
` (22 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Currently integck uses the 'random_offset' filed to store the new file
length sometimes, thus abusing this field. But we can do this nicer -
introduce an anonymous union and add 'new_length' filed which will be
used instead of 'random_offset' to make the code look nicer.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 0ff94c5..eff7274 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -44,7 +44,10 @@ struct write_info /* Record of random data written into a file */
off_t offset; /* Where in the file the data was written */
size_t size; /* Number of bytes written */
unsigned random_seed; /* Seed for rand() to create random data */
- off_t random_offset; /* Call rand() this number of times first */
+ union {
+ off_t random_offset; /* Call rand() this number of times first */
+ off_t new_length; /* For truncation records new file length */
+ };
int trunc; /* Records a truncation (raw_writes only) */
};
@@ -568,7 +571,7 @@ static void file_info_display(struct file_info *file)
while (w) {
if (w->trunc)
normsg(" Trunc from %u to %u",
- (unsigned) w->offset, (unsigned) w->random_offset);
+ (unsigned) w->offset, (unsigned) w->new_length);
else
normsg(" Offset: %u Size: %u Seed: %u R.Off: %u",
(unsigned) w->offset, (unsigned) w->size,
@@ -920,7 +923,7 @@ static void file_truncate_info(struct file_info *file, size_t new_length)
w = zalloc(sizeof(struct write_info));
w->next = file->raw_writes;
w->offset = file->length;
- w->random_offset = new_length; /* Abuse random_offset */
+ w->new_length = new_length;
w->trunc = 1;
file->raw_writes = w;
/* Update file length */
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 05/27] fs-tests: integck: shrink write_info even more
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (4 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 04/27] fs-tests: integck: abuse random_offset field nicer Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 06/27] fs-tests: integck: change tests defaults Artem Bityutskiy
` (21 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
The 'struct write_info' data strucutre records information about
truncation, and has a separate integer field to specify if this is
a truncation or not. But it is too wasteful because we have huge
amount of these objects.
But it is easy to notice that the 'random_seed' field is not used
for truncation records, so we can use that as the truncation flag.
This patch introduces MAX_RANDOM_SEED macro and when the 'random_seed'
field is greater than that, we treat it as the truncation flag.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 25 ++++++++++++++++++-------
1 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index eff7274..92e37a1 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -35,6 +35,8 @@
#define PROGRAM_NAME "integck"
#include "common.h"
+#define MAX_RANDOM_SEED 10000000
+
/* Structures to store data written to the test file system,
so that we can check whether the file system is correct. */
@@ -42,13 +44,14 @@ struct write_info /* Record of random data written into a file */
{
struct write_info *next;
off_t offset; /* Where in the file the data was written */
- size_t size; /* Number of bytes written */
- unsigned random_seed; /* Seed for rand() to create random data */
union {
off_t random_offset; /* Call rand() this number of times first */
off_t new_length; /* For truncation records new file length */
};
- int trunc; /* Records a truncation (raw_writes only) */
+ size_t size; /* Number of bytes written */
+ unsigned int random_seed; /* Seed for rand() to create random data. If
+ greater than MAX_RANDOM_SEED then this is
+ a truncation record (raw_writes only) */
};
struct dir_entry_info;
@@ -140,6 +143,14 @@ static long mem_page_size; /* Page size for mmap */
static unsigned int check_run_no;
/*
+ * Is this 'struct write_info' actually holds information about a truncation?
+ */
+static int is_truncation(struct write_info *w)
+{
+ return w->random_seed > MAX_RANDOM_SEED;
+}
+
+/*
* Allocate a buffer of 'size' bytes and fill it with zeroes.
*/
static void *zalloc(size_t size)
@@ -569,7 +580,7 @@ static void file_info_display(struct file_info *file)
wcnt = 0;
w = file->raw_writes;
while (w) {
- if (w->trunc)
+ if (is_truncation(w))
normsg(" Trunc from %u to %u",
(unsigned) w->offset, (unsigned) w->new_length);
else
@@ -834,7 +845,7 @@ static void file_mmap_write(struct file_info *file)
offset = w->offset + tests_random_no(w->size - size);
/* Write it */
- seed = tests_random_no(10000000);
+ seed = tests_random_no(MAX_RANDOM_SEED);
srand(seed);
waddr = addr + (offset - offs);
for (i = 0; i < size; i++)
@@ -860,7 +871,7 @@ static void file_write(struct file_info *file, int fd)
}
get_offset_and_size(file, &offset, &size);
- seed = tests_random_no(10000000);
+ seed = tests_random_no(MAX_RANDOM_SEED);
actual = file_write_data(file, fd, offset, size, seed);
if (offset + actual <= file->length && shrink)
@@ -924,7 +935,7 @@ static void file_truncate_info(struct file_info *file, size_t new_length)
w->next = file->raw_writes;
w->offset = file->length;
w->new_length = new_length;
- w->trunc = 1;
+ w->random_seed = MAX_RANDOM_SEED + 1;
file->raw_writes = w;
/* Update file length */
file->length = new_length;
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 06/27] fs-tests: integck: change tests defaults
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (5 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 05/27] fs-tests: integck: shrink write_info even more Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 07/27] fs-tests: integck: implement own parameters parsing Artem Bityutskiy
` (20 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Currently integck assumes that by default the file-system cannot
do shared writable mmap-ing and does not preserve accurate file
size after ENOSPC errors. And then it overrides these default
settings if this is UBIFS.
But it seems that only JFFS2 has those limitations. So make the
defaults to be the opposite and override them for JFFS2 only.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 17 ++++++++++-------
1 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 92e37a1..ea3684b 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -133,10 +133,10 @@ static uint64_t initial_free_space = 0; /* Free space on file system when
test starts */
static unsigned log10_initial_free_space = 0; /* log10 of initial_free_space */
-static int check_nospc_files = 0; /* Also check data in files that incurred a
+static int check_nospc_files = 1; /* Also check data in files that incurred a
"no space" error */
-static int can_mmap = 0; /* Can write via mmap */
+static int can_mmap = 1; /* Can write via mmap */
static long mem_page_size; /* Page size for mmap */
@@ -2027,16 +2027,19 @@ int main(int argc, char *argv[])
integck_get_description(), "n");
if (!run_test)
return 1;
+
/* Change directory to the file system and check it is ok for testing */
tests_check_test_file_system();
+
/*
- * We expect accurate file size from ubifs even after "no space"
- * errors. And we can mmap.
+ * JFFS2 does not support shared writable mmap and it may report
+ * incorrect file size after "no space" errors.
*/
- if (strcmp(tests_file_system_type, "ubifs") == 0) {
- check_nospc_files = 1;
- can_mmap = 1;
+ if (strcmp(tests_file_system_type, "jffs2") == 0) {
+ check_nospc_files = 0;
+ can_mmap = 0;
}
+
/* Do the actual test */
integck();
return 0;
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 07/27] fs-tests: integck: implement own parameters parsing
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (6 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 06/27] fs-tests: integck: change tests defaults Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 08/27] fs-tests: integck: clean-up copy_string Artem Bityutskiy
` (19 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Instead of using shared command line arguments parsing routine
implement own. The reason is that I want to add more parameters,
which are integck-specific. Also, longer-term plan is to make
integck independent of the common tests.c file.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 112 ++++++++++++++++++++++++++----------
1 files changed, 81 insertions(+), 31 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index ea3684b..281de81 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -29,14 +29,24 @@
#include <errno.h>
#include <limits.h>
#include <dirent.h>
+#include <getopt.h>
#include <sys/mman.h>
#include "tests.h"
+#define PROGRAM_VERSION "1.1"
#define PROGRAM_NAME "integck"
#include "common.h"
#define MAX_RANDOM_SEED 10000000
+/* The variables below are set by command line arguments */
+static struct {
+ long repeat_cnt;
+ const char *mount_point;
+} args = {
+ .repeat_cnt = 1,
+};
+
/* Structures to store data written to the test file system,
so that we can check whether the file system is correct. */
@@ -235,7 +245,7 @@ static char *dir_path(struct dir_info *parent, const char *name)
char *path;
if (!parent)
- return cat_paths(tests_file_system_mount_dir, name);
+ return cat_paths(args.mount_point, name);
parent_path = dir_path(parent->parent, parent->name);
path = cat_paths(parent_path, name);
free(parent_path);
@@ -1968,8 +1978,7 @@ void integck(void)
dir_check(top_dir);
check_deleted_files();
- for (rpt = 0; tests_repeat_parameter == 0 ||
- rpt < tests_repeat_parameter; ++rpt) {
+ for (rpt = 0; args.repeat_cnt == 0 || rpt < args.repeat_cnt; ++rpt) {
update_test_data();
if (!tests_fs_is_rootfs()) {
@@ -1989,44 +1998,85 @@ void integck(void)
CHECK(rmdir(dir_name) != -1);
}
-/* Title of this test */
+static const char doc[] = PROGRAM_NAME " version " PROGRAM_VERSION
+" - a stress test which checks the file-system integrity.\n"
+"It creates a directory named \"integck_test_dir_pid\", where where pid is the\n"
+"process id. Then it randomly creates and deletes files, directories, symlinks\n"
+"and hardlinks, randomly writes and truncate files, sometimes makes holes in\n"
+"files, sometimes fsync()'s them. Then it un-mounts and re-mounts the test file\n"
+"system and checks the contents - everything (files, dirs, etc) should be there\n"
+"and the contents of the files should be correct.\n"
+"This is repeated a number of times (set with -n, default 1).";
+
+static const char optionsstr[] =
+"-n, --repeat=<count> repeat count, default is 1; zero value - repeat forever\n"
+"-h, -?, --help print help message\n"
+"-V, --version print program version\n";
+
+static const struct option long_options[] = {
+ { .name = "repeat", .has_arg = 1, .flag = NULL, .val = 'n' },
+ { .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' },
+ { .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' },
+ { NULL, 0, NULL, 0},
+};
-const char *integck_get_title(void)
+/*
+ * Parse input command-line options. Returns zero on success and -1 on error.
+ */
+static int parse_opts(int argc, char * const argv[])
{
- return "Test file system integrity";
-}
+ while (1) {
+ int key, error = 0;
-/* Description of this test */
+ key = getopt_long(argc, argv, "n:Vh?", long_options, NULL);
+ if (key == -1)
+ break;
-const char *integck_get_description(void)
-{
- return
- "Create a directory named integck_test_dir_pid " \
- "where pid is the process id. " \
- "Randomly create and delete files and directories. " \
- "Randomly write to and truncate files. " \
- "Un-mount and re-mount test file " \
- "system (if it is not the root file system ). " \
- "Check data. Make more random changes. " \
- "Un-mount and re-mount again. Check again. " \
- "Repeat some number of times. "
- "The repeat count is set by the -n or --repeat option, " \
- "otherwise it defaults to 1. " \
- "A repeat count of zero repeats forever.";
+ switch (key) {
+ case 'n':
+ args.repeat_cnt = simple_strtoul(optarg, &error);
+ if (error || args.repeat_cnt < 0)
+ return errmsg("bad repeat count: \"%s\"", optarg);
+ break;
+ case 'V':
+ fprintf(stderr, "%s\n", PROGRAM_VERSION);
+ exit(EXIT_SUCCESS);
+
+ case 'h':
+ case '?':
+ fprintf(stderr, "%s\n\n", doc);
+ fprintf(stderr, "%s\n", optionsstr);
+ exit(EXIT_SUCCESS);
+
+ case ':':
+ return errmsg("parameter is missing");
+
+ default:
+ fprintf(stderr, "Use -h for help\n");
+ return -1;
+ }
+ }
+
+ if (optind == argc)
+ return errmsg("test file-system was not specified (use -h for help)");
+ else if (optind != argc - 1)
+ return errmsg("more then one test file-system specified (use -h for help)");
+
+ args.mount_point = argv[optind];
+ return 0;
}
int main(int argc, char *argv[])
{
- int run_test;
+ int ret;
- /* Set default test repetition */
- tests_repeat_parameter = 1;
+ ret = parse_opts(argc, argv);
+ if (ret)
+ return EXIT_FAILURE;
- /* Handle common arguments */
- run_test = tests_get_args(argc, argv, integck_get_title(),
- integck_get_description(), "n");
- if (!run_test)
- return 1;
+ /* Temporary hack - will be fixed a bit later */
+ tests_file_system_mount_dir = (void *)args.mount_point;
+ tests_file_system_type = "ubifs";
/* Change directory to the file system and check it is ok for testing */
tests_check_test_file_system();
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 08/27] fs-tests: integck: clean-up copy_string
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (7 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 07/27] fs-tests: integck: implement own parameters parsing Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 09/27] fs-tests: integck: get rid of tests_check_test_file_system Artem Bityutskiy
` (18 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
This is a clean-up patch which:
1. Simplifies copy_string by useng strdup instead of malloc
2. Adds an assertion which checks the input parameter agains NULL,
instead of checking it.
3. Re-names it to dup_string which looks more readable to me.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 46 ++++++++++++++++++-----------------
1 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 281de81..a225042 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -30,6 +30,7 @@
#include <limits.h>
#include <dirent.h>
#include <getopt.h>
+#include <assert.h>
#include <sys/mman.h>
#include "tests.h"
@@ -172,15 +173,16 @@ static void *zalloc(size_t size)
return buf;
}
-static char *copy_string(const char *s)
+/*
+ * Duplicate a string.
+ */
+static char *dup_string(const char *s)
{
char *str;
- if (!s)
- return NULL;
- str = malloc(strlen(s) + 1);
+ assert(s != NULL);
+ str = strdup(s);
CHECK(str != NULL);
- strcpy(str, s);
return str;
}
@@ -190,9 +192,9 @@ static char *cat_strings(const char *a, const char *b)
size_t sz;
if (a && !b)
- return copy_string(a);
+ return dup_string(a);
if (b && !a)
- return copy_string(b);
+ return dup_string(b);
if (!a && !b)
return NULL;
sz = strlen(a) + strlen(b) + 1;
@@ -211,9 +213,9 @@ static char *cat_paths(const char *a, const char *b)
size_t na, nb;
if (a && !b)
- return copy_string(a);
+ return dup_string(a);
if (b && !a)
- return copy_string(b);
+ return dup_string(b);
if (!a && !b)
return NULL;
@@ -301,7 +303,7 @@ static void add_dir_entry(struct dir_info *parent, char type, const char *name,
entry = zalloc(sizeof(struct dir_entry_info));
entry->type = type;
- entry->name = copy_string(name);
+ entry->name = dup_string(name);
entry->parent = parent;
entry->next = parent->first;
@@ -324,7 +326,7 @@ static void add_dir_entry(struct dir_info *parent, char type, const char *name,
entry->dir = dir;
dir->entry = entry;
- dir->name = copy_string(name);
+ dir->name = dup_string(name);
dir->parent = parent;
} else if (entry->type == 's') {
struct symlink_info *symlink = target;
@@ -377,7 +379,7 @@ static struct dir_info *dir_new(struct dir_info *parent, const char *name)
free(path);
dir = zalloc(sizeof(struct dir_info));
- dir->name = copy_string(name);
+ dir->name = dup_string(name);
dir->parent = parent;
if (parent)
add_dir_entry(parent, 'd', name, dir);
@@ -435,7 +437,7 @@ static struct file_info *file_new(struct dir_info *parent, const char *name)
free(path);
file = zalloc(sizeof(struct file_info));
- file->name = copy_string(name);
+ file->name = dup_string(name);
add_dir_entry(parent, 'f', name, file);
@@ -1210,7 +1212,7 @@ static char *symlink_path(const char *path, const char *target_pathname)
size_t len, totlen, tarlen;
if (target_pathname[0] == '/')
- return copy_string(target_pathname);
+ return dup_string(target_pathname);
p = strrchr(path, '/');
len = p - path;
len += 1;
@@ -1479,7 +1481,7 @@ static char *pick_rename_name(struct dir_info **parent,
*rename_entry = NULL;
if (grow || tests_random_no(20) < 10)
- return copy_string(make_name(dir));
+ return dup_string(make_name(dir));
r = tests_random_no(dir->number_of_entries);
entry = dir->first;
@@ -1491,14 +1493,14 @@ static char *pick_rename_name(struct dir_info **parent,
entry = dir->first;
if (!entry ||
(entry->type == 'd' && entry->dir->number_of_entries != 0))
- return copy_string(make_name(dir));
+ return dup_string(make_name(dir));
if ((isdir && entry->type != 'd') ||
(!isdir && entry->type == 'd'))
- return copy_string(make_name(dir));
+ return dup_string(make_name(dir));
*rename_entry = entry;
- return copy_string(entry->name);
+ return dup_string(entry->name);
}
static void rename_entry(struct dir_entry_info *entry)
@@ -1593,13 +1595,13 @@ static char *relative_path(const char *path1, const char *path2)
len2 = strlen(p2);
up = str_count(p1, '/');
if (up == 0 && len2 != 0)
- return copy_string(p2);
+ return dup_string(p2);
if (up == 0 && len2 == 0) {
p2 = strrchr(path2, '/');
- return copy_string(p2);
+ return dup_string(p2);
}
if (up == 1 && len2 == 0)
- return copy_string(".");
+ return dup_string(".");
if (len2 == 0)
up -= 1;
len = up * 3 + len2 + 1;
@@ -1651,7 +1653,7 @@ static char *pick_symlink_target(const char *symlink_path)
static void symlink_new(struct dir_info *dir, const char *name_)
{
struct symlink_info *s;
- char *path, *target, *name = copy_string(name_);
+ char *path, *target, *name = dup_string(name_);
path = dir_path(dir, name);
target = pick_symlink_target(path);
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 09/27] fs-tests: integck: get rid of tests_check_test_file_system
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (8 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 08/27] fs-tests: integck: clean-up copy_string Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 10/27] fs-tests: integck: make integck function return error Artem Bityutskiy
` (17 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Stop using the shared 'tests_check_test_file_system()' function but
instead, use own independed version of this function. This is another
step forward the goal to make integck independent of the common
shared code.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 70 ++++++++++++++++++++++++++++++++---
1 files changed, 64 insertions(+), 6 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index a225042..ebe4995 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -31,7 +31,10 @@
#include <dirent.h>
#include <getopt.h>
#include <assert.h>
+#include <mntent.h>
#include <sys/mman.h>
+#include <sys/vfs.h>
+#include <sys/mount.h>
#include "tests.h"
#define PROGRAM_VERSION "1.1"
@@ -48,6 +51,17 @@ static struct {
.repeat_cnt = 1,
};
+/*
+ * The below data structure describes the tested file-system.
+ *
+ * max_name_len: maximum file name length
+ * fstype: file-system type (e.g., "ubifs")
+ */
+static struct {
+ int max_name_len;
+ const char *fstype;
+} fsinfo;
+
/* Structures to store data written to the test file system,
so that we can check whether the file system is correct. */
@@ -1383,7 +1397,7 @@ static char *make_name(struct dir_info *dir)
do {
found = 0;
if (tests_random_no(5) == 1) {
- int i, n = tests_random_no(tests_max_fname_len) + 1;
+ int i, n = tests_random_no(fsinfo.max_name_len) + 1;
CHECK(n > 0 && n < 256);
for (i = 0; i < n; i++)
@@ -2000,6 +2014,43 @@ void integck(void)
CHECK(rmdir(dir_name) != -1);
}
+/*
+ * Fill 'fsinfo' with information about the tested file-system.
+ */
+static void get_tested_fs_info(void)
+{
+ struct statfs fs_info;
+ struct mntent *mntent;
+ const char *mp;
+ FILE *f;
+
+ CHECK(statfs(args.mount_point, &fs_info) == 0);
+
+ fsinfo.max_name_len = fs_info.f_namelen;
+
+ mp = "/proc/mounts";
+ f = fopen(mp, "rb");
+ if (!f) {
+ mp = "/etc/mtab";
+ f = fopen(mp, "rb");
+ }
+ CHECK(f != NULL);
+
+ while (1) {
+ mntent = getmntent(f);
+ if (!mntent) {
+ errmsg("cannot find file-system info");
+ CHECK(0);
+ }
+
+ if (!strcmp(mntent->mnt_dir, args.mount_point))
+ break;
+ }
+ fclose(f);
+
+ fsinfo.fstype = dup_string(mntent->mnt_type);
+}
+
static const char doc[] = PROGRAM_NAME " version " PROGRAM_VERSION
" - a stress test which checks the file-system integrity.\n"
"It creates a directory named \"integck_test_dir_pid\", where where pid is the\n"
@@ -2023,10 +2074,13 @@ static const struct option long_options[] = {
};
/*
- * Parse input command-line options. Returns zero on success and -1 on error.
+ * Parse and validate input command-line options. Returns zero on success and
+ * -1 on error.
*/
static int parse_opts(int argc, char * const argv[])
{
+ struct stat st;
+
while (1) {
int key, error = 0;
@@ -2065,6 +2119,11 @@ static int parse_opts(int argc, char * const argv[])
return errmsg("more then one test file-system specified (use -h for help)");
args.mount_point = argv[optind];
+
+ if (chdir(args.mount_point) != 0 || lstat(args.mount_point, &st) != 0)
+ return errmsg("invalid test file system mount directory: %s",
+ args.mount_point);
+
return 0;
}
@@ -2076,12 +2135,11 @@ int main(int argc, char *argv[])
if (ret)
return EXIT_FAILURE;
+ get_tested_fs_info();
+
/* Temporary hack - will be fixed a bit later */
tests_file_system_mount_dir = (void *)args.mount_point;
- tests_file_system_type = "ubifs";
-
- /* Change directory to the file system and check it is ok for testing */
- tests_check_test_file_system();
+ tests_file_system_type = (void *)fsinfo.fstype;
/*
* JFFS2 does not support shared writable mmap and it may report
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 10/27] fs-tests: integck: make integck function return error
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (9 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 09/27] fs-tests: integck: get rid of tests_check_test_file_system Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 11/27] fs-tests: integck: move mem_page_size to fsinfo Artem Bityutskiy
` (16 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Turn the 'void integck(void)' function into 'static int integck(void)'.
We need to teach the test to gracefully handle some error cases like
'EROFS' instead of failing and exiting straight away. And the ground
work for this is making all functions return errors. This is the first
tiny step in this direction.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index ebe4995..3ee20b2 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -1951,7 +1951,7 @@ static void update_test_data(void)
do_an_operation();
}
-void integck(void)
+static int integck(void)
{
pid_t pid;
int64_t rpt;
@@ -1978,7 +1978,7 @@ void integck(void)
top_dir = dir_new(NULL, dir_name);
if (!top_dir)
- return;
+ return -1;
srand(pid);
@@ -2012,6 +2012,8 @@ void integck(void)
close_open_files();
tests_clear_dir(dir_name);
CHECK(rmdir(dir_name) != -1);
+
+ return 0;
}
/*
@@ -2151,6 +2153,9 @@ int main(int argc, char *argv[])
}
/* Do the actual test */
- integck();
- return 0;
+ ret = integck();
+ if (ret)
+ return EXIT_FAILURE;
+
+ return EXIT_SUCCESS;
}
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 11/27] fs-tests: integck: move mem_page_size to fsinfo
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (10 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 10/27] fs-tests: integck: make integck function return error Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 12/27] fs-tests: integck: move more variables " Artem Bityutskiy
` (15 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
The fsinfo structure will aggregate all the information about the
tested file-system. Move 'mem_page_size' which we use for 'mmap()'
there as well.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 3ee20b2..e7a3547 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -55,10 +55,12 @@ static struct {
* The below data structure describes the tested file-system.
*
* max_name_len: maximum file name length
+ * page_size: memory page size to use with 'mmap()'
* fstype: file-system type (e.g., "ubifs")
*/
static struct {
int max_name_len;
+ int page_size;
const char *fstype;
} fsinfo;
@@ -163,8 +165,6 @@ static int check_nospc_files = 1; /* Also check data in files that incurred a
static int can_mmap = 1; /* Can write via mmap */
-static long mem_page_size; /* Page size for mmap */
-
static unsigned int check_run_no;
/*
@@ -846,7 +846,7 @@ static void file_mmap_write(struct file_info *file)
for (i = 0; w && w->next && i < r; i++)
w = w->next;
- offs = (w->offset / mem_page_size) * mem_page_size;
+ offs = (w->offset / fsinfo.page_size) * fsinfo.page_size;
len = w->size + (w->offset - offs);
if (len > 1 << 24)
len = 1 << 24;
@@ -1958,9 +1958,6 @@ static int integck(void)
uint64_t z;
char dir_name[256];
- /* Get memory page size for mmap */
- mem_page_size = sysconf(_SC_PAGE_SIZE);
- CHECK(mem_page_size > 0);
/* Make our top directory */
pid = getpid();
normsg("pid is %u", (unsigned) pid);
@@ -2051,6 +2048,10 @@ static void get_tested_fs_info(void)
fclose(f);
fsinfo.fstype = dup_string(mntent->mnt_type);
+
+ /* Get memory page size for 'mmap()' */
+ fsinfo.page_size = sysconf(_SC_PAGE_SIZE);
+ CHECK(fsinfo.page_size > 0);
}
static const char doc[] = PROGRAM_NAME " version " PROGRAM_VERSION
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 12/27] fs-tests: integck: move more variables to fsinfo
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (11 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 11/27] fs-tests: integck: move mem_page_size to fsinfo Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 13/27] fs-tests: integck: add own get_free_space function Artem Bityutskiy
` (14 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Aggregate all the information about the tested file-system in
the fsinf object for better readability and cleanness. Move
'can_mmap' and 'check_nospc_files' there as well.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 45 ++++++++++++++++++++----------------
1 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index e7a3547..e29db49 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -56,13 +56,21 @@ static struct {
*
* max_name_len: maximum file name length
* page_size: memory page size to use with 'mmap()'
+ * nospc_size_ok: file size is updated even if the write operation failed with
+ * ENOSPC error
+ * can_mmap: file-system supports share writable 'mmap()' operation
* fstype: file-system type (e.g., "ubifs")
*/
static struct {
int max_name_len;
int page_size;
+ unsigned int nospc_size_ok:1;
+ unsigned int can_mmap:1;
const char *fstype;
-} fsinfo;
+} fsinfo = {
+ .nospc_size_ok = 1,
+ .can_mmap = 1,
+};
/* Structures to store data written to the test file system,
so that we can check whether the file system is correct. */
@@ -160,11 +168,6 @@ static uint64_t initial_free_space = 0; /* Free space on file system when
test starts */
static unsigned log10_initial_free_space = 0; /* log10 of initial_free_space */
-static int check_nospc_files = 1; /* Also check data in files that incurred a
- "no space" error */
-
-static int can_mmap = 1; /* Can write via mmap */
-
static unsigned int check_run_no;
/*
@@ -810,7 +813,7 @@ static int file_ftruncate(struct file_info *file, int fd, off_t new_length)
CHECK(errno = ENOSPC);
file->no_space_error = 1;
/* Delete errored files */
- if (!check_nospc_files)
+ if (!fsinfo.nospc_size_ok)
file_delete(file);
return 0;
}
@@ -891,7 +894,8 @@ static void file_write(struct file_info *file, int fd)
unsigned seed;
int truncate = 0;
- if (can_mmap && !full && !file->deleted && tests_random_no(100) == 1) {
+ if (fsinfo.can_mmap && !full && !file->deleted &&
+ tests_random_no(100) == 1) {
file_mmap_write(file);
return;
}
@@ -910,7 +914,7 @@ static void file_write(struct file_info *file, int fd)
file_write_info(file, offset, actual, seed);
/* Delete errored files */
- if (!check_nospc_files && file->no_space_error) {
+ if (!fsinfo.nospc_size_ok && file->no_space_error) {
file_delete(file);
return;
}
@@ -1173,7 +1177,7 @@ static void file_check(struct file_info *file, int fd)
struct stat st;
/* Do not check files that have errored */
- if (!check_nospc_files && file->no_space_error)
+ if (!fsinfo.nospc_size_ok && file->no_space_error)
return;
/* Do not check the same file twice */
if (file->check_run_no == check_run_no)
@@ -1856,7 +1860,7 @@ static void operate_on_an_open_file(void)
}
}
/* Close any open files that have errored */
- if (!check_nospc_files) {
+ if (!fsinfo.nospc_size_ok) {
ofi = open_files;
while (ofi) {
if (ofi->fdi->file->no_space_error) {
@@ -2052,6 +2056,16 @@ static void get_tested_fs_info(void)
/* Get memory page size for 'mmap()' */
fsinfo.page_size = sysconf(_SC_PAGE_SIZE);
CHECK(fsinfo.page_size > 0);
+
+ /*
+ * JFFS2 does not support shared writable mmap and it may report
+ * incorrect file size after "no space" errors.
+ */
+ if (strcmp(fsinfo.fstype, "jffs2") == 0) {
+ fsinfo.nospc_size_ok = 0;
+ fsinfo.can_mmap = 0;
+ }
+
}
static const char doc[] = PROGRAM_NAME " version " PROGRAM_VERSION
@@ -2144,15 +2158,6 @@ int main(int argc, char *argv[])
tests_file_system_mount_dir = (void *)args.mount_point;
tests_file_system_type = (void *)fsinfo.fstype;
- /*
- * JFFS2 does not support shared writable mmap and it may report
- * incorrect file size after "no space" errors.
- */
- if (strcmp(tests_file_system_type, "jffs2") == 0) {
- check_nospc_files = 0;
- can_mmap = 0;
- }
-
/* Do the actual test */
ret = integck();
if (ret)
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 13/27] fs-tests: integck: add own get_free_space function
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (12 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 12/27] fs-tests: integck: move more variables " Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 14/27] fs-tests: integck: move log10_initial_free to fsinfo Artem Bityutskiy
` (13 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Do not use the shared 'tests_get_free_space' function but use own
implementation instead. This is another step to make integck independent
on the common infrastructure.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 20 ++++++++++++++++----
1 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index e29db49..bfedeb2 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -35,6 +35,7 @@
#include <sys/mman.h>
#include <sys/vfs.h>
#include <sys/mount.h>
+#include <sys/statvfs.h>
#include "tests.h"
#define PROGRAM_VERSION "1.1"
@@ -258,6 +259,17 @@ static char *cat_paths(const char *a, const char *b)
return str;
}
+/*
+ * Get the free space for the tested file system.
+ */
+static uint64_t get_free_space(void)
+{
+ struct statvfs st;
+
+ CHECK(statvfs(args.mount_point, &st) != -1);
+ return (uint64_t)st.f_bavail * (uint64_t)st.f_frsize;
+}
+
static char *dir_path(struct dir_info *parent, const char *name)
{
char *parent_path;
@@ -834,7 +846,7 @@ static void file_mmap_write(struct file_info *file)
if (!file->links)
return;
- free_space = tests_get_free_space();
+ free_space = get_free_space();
if (!free_space)
return;
/* Randomly pick a written area of the file */
@@ -1911,7 +1923,7 @@ static void create_test_data(void)
uint64_t total;
for (i = 0; i < 10; ++i)
do_an_operation();
- free = tests_get_free_space();
+ free = get_free_space();
total = tests_get_total_space();
if ((free * 100) / total >= 10)
break;
@@ -1942,7 +1954,7 @@ static void update_test_data(void)
uint64_t total;
for (i = 0; i < 10; ++i)
do_an_operation();
- free = tests_get_free_space();
+ free = get_free_space();
total = tests_get_total_space();
if ((free * 100) / total >= 50)
break;
@@ -1972,7 +1984,7 @@ static int integck(void)
CHECK(chdir("..") != -1);
CHECK(rmdir(dir_name) != -1);
}
- initial_free_space = tests_get_free_space();
+ initial_free_space = get_free_space();
log10_initial_free_space = 0;
for (z = initial_free_space; z >= 10; z /= 10)
++log10_initial_free_space;
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 14/27] fs-tests: integck: move log10_initial_free to fsinfo
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (13 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 13/27] fs-tests: integck: add own get_free_space function Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 15/27] fs-tests: integck: remove trailing backslashes from mount point Artem Bityutskiy
` (12 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Similarly to the previous patches, move the log10_initial_free variable
to the fsinfo data structure.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 19 ++++++++-----------
1 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index bfedeb2..910f22a 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -57,6 +57,8 @@ static struct {
*
* max_name_len: maximum file name length
* page_size: memory page size to use with 'mmap()'
+ * log10_initial_free: logarighm base 10 of the initial amount of free space in
+ * the tested file-system
* nospc_size_ok: file size is updated even if the write operation failed with
* ENOSPC error
* can_mmap: file-system supports share writable 'mmap()' operation
@@ -65,6 +67,7 @@ static struct {
static struct {
int max_name_len;
int page_size;
+ unsigned int log10_initial_free;
unsigned int nospc_size_ok:1;
unsigned int can_mmap:1;
const char *fstype;
@@ -165,10 +168,6 @@ static int shrink = 0; /* Should we try to shrink files and directories */
static int full = 0; /* Flag that the file system is full */
static uint64_t operation_count = 0; /* Number of operations used to fill
up the file system */
-static uint64_t initial_free_space = 0; /* Free space on file system when
- test starts */
-static unsigned log10_initial_free_space = 0; /* log10 of initial_free_space */
-
static unsigned int check_run_no;
/*
@@ -804,9 +803,9 @@ static void get_offset_and_size(struct file_info *file,
*offset = file->length;
/* Distribute the size logarithmically */
if (tests_random_no(1000) == 0)
- r = tests_random_no(log10_initial_free_space + 2);
+ r = tests_random_no(fsinfo.log10_initial_free + 2);
else
- r = tests_random_no(log10_initial_free_space);
+ r = tests_random_no(fsinfo.log10_initial_free);
n = 1;
while (r--)
n *= 10;
@@ -1971,7 +1970,6 @@ static int integck(void)
{
pid_t pid;
int64_t rpt;
- uint64_t z;
char dir_name[256];
/* Make our top directory */
@@ -1984,10 +1982,6 @@ static int integck(void)
CHECK(chdir("..") != -1);
CHECK(rmdir(dir_name) != -1);
}
- initial_free_space = get_free_space();
- log10_initial_free_space = 0;
- for (z = initial_free_space; z >= 10; z /= 10)
- ++log10_initial_free_space;
top_dir = dir_new(NULL, dir_name);
if (!top_dir)
@@ -2038,6 +2032,7 @@ static void get_tested_fs_info(void)
struct mntent *mntent;
const char *mp;
FILE *f;
+ uint64_t z;
CHECK(statfs(args.mount_point, &fs_info) == 0);
@@ -2078,6 +2073,8 @@ static void get_tested_fs_info(void)
fsinfo.can_mmap = 0;
}
+ for (z = get_free_space(); z >= 10; z /= 10)
+ fsinfo.log10_initial_free += 1;
}
static const char doc[] = PROGRAM_NAME " version " PROGRAM_VERSION
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 15/27] fs-tests: integck: remove trailing backslashes from mount point
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (14 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 14/27] fs-tests: integck: move log10_initial_free to fsinfo Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 16/27] fs-tests: integck: do not use tests_cat_pid Artem Bityutskiy
` (11 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
The test is not working if the user specified mount point with a trailing
back-slash at the end. Note, this had not worked before my changes as well.
Fix this.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 19 ++++++++++++++-----
1 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 910f22a..546077c 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -63,6 +63,7 @@ static struct {
* ENOSPC error
* can_mmap: file-system supports share writable 'mmap()' operation
* fstype: file-system type (e.g., "ubifs")
+ * mount_point: tested file-system mount point path
*/
static struct {
int max_name_len;
@@ -71,6 +72,7 @@ static struct {
unsigned int nospc_size_ok:1;
unsigned int can_mmap:1;
const char *fstype;
+ const char *mount_point;
} fsinfo = {
.nospc_size_ok = 1,
.can_mmap = 1,
@@ -265,7 +267,7 @@ static uint64_t get_free_space(void)
{
struct statvfs st;
- CHECK(statvfs(args.mount_point, &st) != -1);
+ CHECK(statvfs(fsinfo.mount_point, &st) != -1);
return (uint64_t)st.f_bavail * (uint64_t)st.f_frsize;
}
@@ -275,7 +277,7 @@ static char *dir_path(struct dir_info *parent, const char *name)
char *path;
if (!parent)
- return cat_paths(args.mount_point, name);
+ return cat_paths(fsinfo.mount_point, name);
parent_path = dir_path(parent->parent, parent->name);
path = cat_paths(parent_path, name);
free(parent_path);
@@ -2033,9 +2035,16 @@ static void get_tested_fs_info(void)
const char *mp;
FILE *f;
uint64_t z;
+ char *p;
- CHECK(statfs(args.mount_point, &fs_info) == 0);
+ /* Remove trailing '/' symbols from the mount point */
+ p = dup_string(args.mount_point);
+ fsinfo.mount_point = p;
+ p += strlen(p);
+ while (*--p == '/');
+ *(p + 1) = '\0';
+ CHECK(statfs(fsinfo.mount_point, &fs_info) == 0);
fsinfo.max_name_len = fs_info.f_namelen;
mp = "/proc/mounts";
@@ -2053,7 +2062,7 @@ static void get_tested_fs_info(void)
CHECK(0);
}
- if (!strcmp(mntent->mnt_dir, args.mount_point))
+ if (!strcmp(mntent->mnt_dir, fsinfo.mount_point))
break;
}
fclose(f);
@@ -2164,7 +2173,7 @@ int main(int argc, char *argv[])
get_tested_fs_info();
/* Temporary hack - will be fixed a bit later */
- tests_file_system_mount_dir = (void *)args.mount_point;
+ tests_file_system_mount_dir = (void *)fsinfo.mount_point;
tests_file_system_type = (void *)fsinfo.fstype;
/* Do the actual test */
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 16/27] fs-tests: integck: do not use tests_cat_pid
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (15 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 15/27] fs-tests: integck: remove trailing backslashes from mount point Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 17/27] fs-tests: integck: clean up test directory creation Artem Bityutskiy
` (10 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Do not use the shared 'tests_cat_pid' function but use a simple
sprintf instead. This is another step to make integck independent
of the common code.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 546077c..c21b488 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -1970,14 +1970,14 @@ static void update_test_data(void)
static int integck(void)
{
- pid_t pid;
+ unsigned int pid;
int64_t rpt;
char dir_name[256];
/* Make our top directory */
pid = getpid();
- normsg("pid is %u", (unsigned) pid);
- tests_cat_pid(dir_name, "integck_test_dir_", pid);
+ normsg("pid is %u", pid);
+ CHECK(sprintf(dir_name, "integck_test_dir_%u", pid) > 0);
if (chdir(dir_name) != -1) {
/* Remove it if it is already there */
tests_clear_dir(".");
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 17/27] fs-tests: integck: clean up test directory creation
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (16 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 16/27] fs-tests: integck: do not use tests_cat_pid Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 18/27] fs-tests: integck: do not use tests_clear_dir Artem Bityutskiy
` (9 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Move the test directory name to the fsinfo structure and do few
other cleanups while on it.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 34 ++++++++++++++++++++++------------
1 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index c21b488..ed02b56 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -44,6 +44,9 @@
#define MAX_RANDOM_SEED 10000000
+/* The pattern for the top directory where we run the test */
+#define TEST_DIR_PATTERN "integck_test_dir_%u"
+
/* The variables below are set by command line arguments */
static struct {
long repeat_cnt;
@@ -64,6 +67,7 @@ static struct {
* can_mmap: file-system supports share writable 'mmap()' operation
* fstype: file-system type (e.g., "ubifs")
* mount_point: tested file-system mount point path
+ * test_dir: the directory on the tested file-system where we test
*/
static struct {
int max_name_len;
@@ -73,6 +77,7 @@ static struct {
unsigned int can_mmap:1;
const char *fstype;
const char *mount_point;
+ const char *test_dir;
} fsinfo = {
.nospc_size_ok = 1,
.can_mmap = 1,
@@ -1970,27 +1975,21 @@ static void update_test_data(void)
static int integck(void)
{
- unsigned int pid;
int64_t rpt;
- char dir_name[256];
/* Make our top directory */
- pid = getpid();
- normsg("pid is %u", pid);
- CHECK(sprintf(dir_name, "integck_test_dir_%u", pid) > 0);
- if (chdir(dir_name) != -1) {
+ if (chdir(fsinfo.test_dir) != -1) {
/* Remove it if it is already there */
tests_clear_dir(".");
CHECK(chdir("..") != -1);
- CHECK(rmdir(dir_name) != -1);
+ CHECK(rmdir(fsinfo.test_dir) != -1);
}
- top_dir = dir_new(NULL, dir_name);
+ top_dir = dir_new(NULL, fsinfo.test_dir);
if (!top_dir)
return -1;
- srand(pid);
-
+ srand(getpid());
create_test_data();
if (!tests_fs_is_rootfs()) {
@@ -2019,8 +2018,8 @@ static int integck(void)
/* Tidy up by removing everything */
close_open_files();
- tests_clear_dir(dir_name);
- CHECK(rmdir(dir_name) != -1);
+ tests_clear_dir(fsinfo.test_dir);
+ CHECK(rmdir(fsinfo.test_dir) != -1);
return 0;
}
@@ -2036,6 +2035,7 @@ static void get_tested_fs_info(void)
FILE *f;
uint64_t z;
char *p;
+ unsigned int pid;
/* Remove trailing '/' symbols from the mount point */
p = dup_string(args.mount_point);
@@ -2084,6 +2084,16 @@ static void get_tested_fs_info(void)
for (z = get_free_space(); z >= 10; z /= 10)
fsinfo.log10_initial_free += 1;
+
+ /* Pick the test directory name */
+ p = malloc(sizeof(TEST_DIR_PATTERN) + 20);
+ CHECK(p != NULL);
+ pid = getpid();
+ CHECK(sprintf(p, "integck_test_dir_%u", pid) > 0);
+ fsinfo.test_dir = p;
+
+ normsg("pid %u, testing \"%s\" at \"%s\"",
+ pid, fsinfo.fstype, fsinfo.mount_point);
}
static const char doc[] = PROGRAM_NAME " version " PROGRAM_VERSION
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 18/27] fs-tests: integck: do not use tests_clear_dir
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (17 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 17/27] fs-tests: integck: clean up test directory creation Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 19/27] fs-tests: integck: do not use space after cast Artem Bityutskiy
` (8 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Do not use shared 'tests_clear_dir()' function which removes a directory
tree recursively, but instead use own implementation. This is because
I'm trying to make integck independend on the shared code because I
need this to do further improvements.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 54 ++++++++++++++++++++++++++++++------
1 files changed, 45 insertions(+), 9 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index ed02b56..4806acd 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -1942,6 +1942,42 @@ static void create_test_data(void)
do_an_operation();
}
+/*
+ * Recursively remove a directory, just like "rm -rf" shell command.
+ */
+void rm_minus_rf_dir(const char *dir_name)
+{
+ DIR *dir;
+ struct dirent *entry;
+ char buf[PATH_MAX];
+
+ dir = opendir(dir_name);
+ CHECK(dir != NULL);
+ CHECK(getcwd(buf, PATH_MAX) != NULL);
+ CHECK(chdir(dir_name) == 0);
+
+ for (;;) {
+ errno = 0;
+ entry = readdir(dir);
+ if (!entry) {
+ CHECK(errno == 0);
+ break;
+ }
+
+ if (strcmp(entry->d_name, ".") &&
+ strcmp(entry->d_name, "..")) {
+ if (entry->d_type == DT_DIR)
+ rm_minus_rf_dir(entry->d_name);
+ else
+ CHECK(unlink(entry->d_name) == 0);
+ }
+ }
+
+ CHECK(chdir(buf) == 0);
+ CHECK(closedir(dir) == 0);
+ CHECK(rmdir(dir_name) == 0);
+}
+
static void update_test_data(void)
{
uint64_t i, n;
@@ -1977,19 +2013,17 @@ static int integck(void)
{
int64_t rpt;
- /* Make our top directory */
- if (chdir(fsinfo.test_dir) != -1) {
+ /* Create our top directory */
+ if (chdir(fsinfo.test_dir) == 0) {
/* Remove it if it is already there */
- tests_clear_dir(".");
- CHECK(chdir("..") != -1);
- CHECK(rmdir(fsinfo.test_dir) != -1);
+ CHECK(chdir("..") == 0);
+ rm_minus_rf_dir(fsinfo.test_dir);
}
- top_dir = dir_new(NULL, fsinfo.test_dir);
+ top_dir = dir_new(NULL, fsinfo.test_dir);
if (!top_dir)
return -1;
- srand(getpid());
create_test_data();
if (!tests_fs_is_rootfs()) {
@@ -2018,8 +2052,7 @@ static int integck(void)
/* Tidy up by removing everything */
close_open_files();
- tests_clear_dir(fsinfo.test_dir);
- CHECK(rmdir(fsinfo.test_dir) != -1);
+ rm_minus_rf_dir(fsinfo.test_dir);
return 0;
}
@@ -2186,6 +2219,9 @@ int main(int argc, char *argv[])
tests_file_system_mount_dir = (void *)fsinfo.mount_point;
tests_file_system_type = (void *)fsinfo.fstype;
+ /* Seed the random generator with out PID */
+ srand(getpid());
+
/* Do the actual test */
ret = integck();
if (ret)
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 19/27] fs-tests: integck: do not use space after cast
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (18 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 18/27] fs-tests: integck: do not use tests_clear_dir Artem Bityutskiy
@ 2011-04-13 15:18 ` Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 20/27] fs-tests: integck: prefer to check for success Artem Bityutskiy
` (7 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:18 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Since we are kernel people lets use the style we are accustomed
to - no space between the cast and the variable: (type)a, not (type) a.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 36 ++++++++++++++++++------------------
1 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 4806acd..284a5fc 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -604,7 +604,7 @@ static void file_info_display(struct file_info *file)
normsg(" Directory: %s", entry->parent->name);
entry = entry->next_link;
}
- normsg(" Length: %u", (unsigned) file->length);
+ normsg(" Length: %u", (unsigned)file->length);
normsg(" File was open: %s",
(file->fds == NULL) ? "false" : "true");
normsg(" File was deleted: %s",
@@ -616,8 +616,8 @@ static void file_info_display(struct file_info *file)
w = file->writes;
while (w) {
normsg(" Offset: %u Size: %u Seed: %u R.Off: %u",
- (unsigned) w->offset, (unsigned) w->size,
- (unsigned) w->random_seed, (unsigned) w->random_offset);
+ (unsigned)w->offset, (unsigned)w->size,
+ (unsigned)w->random_seed, (unsigned)w->random_offset);
wcnt += 1;
w = w->next;
}
@@ -629,11 +629,11 @@ static void file_info_display(struct file_info *file)
while (w) {
if (is_truncation(w))
normsg(" Trunc from %u to %u",
- (unsigned) w->offset, (unsigned) w->new_length);
+ (unsigned)w->offset, (unsigned)w->new_length);
else
normsg(" Offset: %u Size: %u Seed: %u R.Off: %u",
- (unsigned) w->offset, (unsigned) w->size,
- (unsigned) w->random_seed, (unsigned) w->random_offset);
+ (unsigned)w->offset, (unsigned)w->size,
+ (unsigned)w->random_seed, (unsigned)w->random_offset);
wcnt += 1;
w = w->next;
}
@@ -668,7 +668,7 @@ static size_t file_write_data( struct file_info *file,
char buf[BUFFER_SIZE];
srand(seed);
- CHECK(lseek(fd, offset, SEEK_SET) != (off_t) -1);
+ CHECK(lseek(fd, offset, SEEK_SET) != (off_t)-1);
remains = size;
actual = 0;
written = BUFFER_SIZE;
@@ -1057,7 +1057,7 @@ static void file_rewrite_data(int fd, struct write_info *w, char *buf)
srand(w->random_seed);
for (r = 0; r < w->random_offset; ++r)
rand();
- CHECK(lseek(fd, w->offset, SEEK_SET) != (off_t) -1);
+ CHECK(lseek(fd, w->offset, SEEK_SET) != (off_t)-1);
remains = w->size;
written = BUFFER_SIZE;
while (remains) {
@@ -1095,7 +1095,7 @@ static void save_file(int fd, struct file_info *file)
CHECK(w_fd != -1);
/* Start at the beginning */
- CHECK(lseek(fd, 0, SEEK_SET) != (off_t) -1);
+ CHECK(lseek(fd, 0, SEEK_SET) != (off_t)-1);
for (;;) {
ssize_t r = read(fd, buf, BUFFER_SIZE);
@@ -1127,7 +1127,7 @@ static void file_check_hole( struct file_info *file,
size_t remains, block, i;
char buf[BUFFER_SIZE];
- CHECK(lseek(fd, offset, SEEK_SET) != (off_t) -1);
+ CHECK(lseek(fd, offset, SEEK_SET) != (off_t)-1);
remains = size;
while (remains) {
if (remains > BUFFER_SIZE)
@@ -1139,8 +1139,8 @@ static void file_check_hole( struct file_info *file,
if (buf[i] != 0) {
errmsg("file_check_hole failed at %u checking "
"hole at %u size %u",
- (unsigned) (size - remains + i),
- (unsigned) offset, (unsigned) size);
+ (unsigned)(size - remains + i),
+ (unsigned)offset, (unsigned)size);
file_info_display(file);
save_file(fd, file);
}
@@ -1161,7 +1161,7 @@ static void file_check_data( struct file_info *file,
srand(w->random_seed);
for (r = 0; r < w->random_offset; ++r)
rand();
- CHECK(lseek(fd, w->offset, SEEK_SET) != (off_t) -1);
+ CHECK(lseek(fd, w->offset, SEEK_SET) != (off_t)-1);
remains = w->size;
while (remains) {
if (remains > BUFFER_SIZE)
@@ -1170,12 +1170,12 @@ static void file_check_data( struct file_info *file,
block = remains;
CHECK(read(fd, buf, block) == block);
for (i = 0; i < block; ++i) {
- char c = (char) rand();
+ char c = (char)rand();
if (buf[i] != c) {
errmsg("file_check_data failed at %u checking "
"data at %u size %u",
- (unsigned) (w->size - remains + i),
- (unsigned) w->offset, (unsigned) w->size);
+ (unsigned)(w->size - remains + i),
+ (unsigned)w->offset, (unsigned)w->size);
file_info_display(file);
save_file(fd, file);
}
@@ -1213,7 +1213,7 @@ static void file_check(struct file_info *file, int fd)
pos = lseek(fd, 0, SEEK_END);
if (pos != file->length) {
errmsg("file_check failed checking length expected %u actual %u\n",
- (unsigned) file->length, (unsigned) pos);
+ (unsigned)file->length, (unsigned)pos);
file_info_display(file);
save_file(fd, file);
}
@@ -1426,7 +1426,7 @@ static char *make_name(struct dir_info *dir)
name[i] = 'a' + tests_random_no(26);
name[i] = '\0';
} else
- sprintf(name, "%u", (unsigned) tests_random_no(1000000));
+ sprintf(name, "%u", (unsigned)tests_random_no(1000000));
for (entry = dir->first; entry; entry = entry->next) {
if (strcmp(entry->name, name) == 0) {
found = 1;
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 20/27] fs-tests: integck: prefer to check for success
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (19 preceding siblings ...)
2011-04-13 15:18 ` [PATCH 19/27] fs-tests: integck: do not use space after cast Artem Bityutskiy
@ 2011-04-13 15:19 ` Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 21/27] fs-tests: integck: do not use tests_fs_is_rootfs Artem Bityutskiy
` (6 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:19 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Many of standard C libraries return 0 on success and -1 on failure.
Currently integck mostly checks for failure by comparing with -1, like:
CHECK(fsync(fd) != -1) /* Don't die if not failure */
but in some places the check is like
CHECK(fsync(fd) == 0) /* Don't die if success */
This patch harmonizes this an makes integck to use the second style
which seems to be more logical. Besides, the binary is smaller in
this case:
[dedekind@eru fs-tests (master)]$ size integrity/integck-old
text data bss dec hex filename
44677 1200 37408 83285 14555 integrity/integck
[dedekind@eru fs-tests (master)]$ size integrity/integck-new
text data bss dec hex filename
44661 1200 37408 83269 14545 integrity/integck
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 48 ++++++++++++++++++------------------
1 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 284a5fc..92571d1 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -272,7 +272,7 @@ static uint64_t get_free_space(void)
{
struct statvfs st;
- CHECK(statvfs(fsinfo.mount_point, &st) != -1);
+ CHECK(statvfs(fsinfo.mount_point, &st) == 0);
return (uint64_t)st.f_bavail * (uint64_t)st.f_frsize;
}
@@ -405,7 +405,7 @@ static struct dir_info *dir_new(struct dir_info *parent, const char *name)
char *path;
path = dir_path(parent, name);
- if (mkdir(path, 0777) == -1) {
+ if (mkdir(path, 0777) != 0) {
CHECK(errno == ENOSPC);
full = 1;
free(path);
@@ -447,7 +447,7 @@ static void dir_remove(struct dir_info *dir)
remove_dir_entry(dir->entry);
/* Remove directory itself */
path = dir_path(dir->parent, dir->name);
- CHECK(rmdir(path) != -1);
+ CHECK(rmdir(path) == 0);
free(dir);
}
@@ -494,7 +494,7 @@ static void link_new(struct dir_info *parent, const char *name,
path = dir_path(parent, name);
target = dir_path(entry->parent, entry->name);
ret = link(target, path);
- if (ret == -1) {
+ if (ret != 0) {
CHECK(errno == ENOSPC);
free(target);
free(path);
@@ -532,7 +532,7 @@ static void file_unlink(struct dir_entry_info *entry)
remove_dir_entry(entry);
/* Unlink the file */
- CHECK(unlink(path) != -1);
+ CHECK(unlink(path) == 0);
free(path);
/* Free struct file_info if file is not open and not linked */
@@ -827,7 +827,7 @@ static void file_truncate_info(struct file_info *file, size_t new_length);
static int file_ftruncate(struct file_info *file, int fd, off_t new_length)
{
- if (ftruncate(fd, new_length) == -1) {
+ if (ftruncate(fd, new_length) != 0) {
CHECK(errno = ENOSPC);
file->no_space_error = 1;
/* Delete errored files */
@@ -880,7 +880,7 @@ static void file_mmap_write(struct file_info *file)
/* mmap it */
addr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offs);
- CHECK(close(fd) != -1);
+ CHECK(close(fd) == 0);
CHECK(addr != MAP_FAILED);
/* Randomly select a part of the mmapped area to write */
@@ -899,7 +899,7 @@ static void file_mmap_write(struct file_info *file)
waddr[i] = rand();
/* Unmap it */
- CHECK(munmap(addr, len) != -1);
+ CHECK(munmap(addr, len) == 0);
/* Record what was written */
file_write_info(file, offset, size, seed);
@@ -953,7 +953,7 @@ static void file_write_file(struct file_info *file)
fd = open(path, O_WRONLY);
CHECK(fd != -1);
file_write(file, fd);
- CHECK(close(fd) != -1);
+ CHECK(close(fd) == 0);
free(path);
}
@@ -1008,7 +1008,7 @@ static void file_truncate_file(struct file_info *file)
fd = open(path, O_WRONLY);
CHECK(fd != -1);
file_truncate(file, fd);
- CHECK(close(fd) != -1);
+ CHECK(close(fd) == 0);
free(path);
}
@@ -1019,7 +1019,7 @@ static void file_close(struct fd_info *fdi)
struct fd_info **prev;
/* Close file */
- CHECK(close(fdi->fd) != -1);
+ CHECK(close(fdi->fd) == 0);
/* Remove struct fd_info */
open_file_remove(fdi);
file = fdi->file;
@@ -1104,7 +1104,7 @@ static void save_file(int fd, struct file_info *file)
break;
CHECK(write(w_fd, buf, r) == r);
}
- CHECK(close(w_fd) != -1);
+ CHECK(close(w_fd) == 0);
/* Open file to save contents to */
strcpy(name, "/tmp/");
@@ -1117,7 +1117,7 @@ static void save_file(int fd, struct file_info *file)
for (w = file->writes; w; w = w->next)
file_rewrite_data(w_fd, w, buf);
- CHECK(close(w_fd) != -1);
+ CHECK(close(w_fd) == 0);
}
static void file_check_hole( struct file_info *file,
@@ -1228,10 +1228,10 @@ static void file_check(struct file_info *file, int fd)
}
if (file->length > pos)
file_check_hole(file, fd, pos, file->length - pos);
- CHECK(fstat(fd, &st) != -1);
+ CHECK(fstat(fd, &st) == 0);
CHECK(file->link_count == st.st_nlink);
if (open_and_close) {
- CHECK(close(fd) != -1);
+ CHECK(close(fd) == 0);
free(path);
}
entry = file->links;
@@ -1270,7 +1270,7 @@ void symlink_check(const struct symlink_info *symlink)
int ret1, ret2;
path = dir_path(symlink->entry->parent, symlink->entry->name);
- CHECK(lstat(path, &st1) != -1);
+ CHECK(lstat(path, &st1) == 0);
CHECK(S_ISLNK(st1.st_mode));
CHECK(st1.st_nlink == 1);
len = readlink(path, buf, 8192);
@@ -1283,7 +1283,7 @@ void symlink_check(const struct symlink_info *symlink)
target = symlink_path(path, symlink->target_pathname);
ret2 = stat(target, &st2);
CHECK(ret1 == ret2);
- if (ret1 != -1) {
+ if (ret1 == 0) {
CHECK(st1.st_dev == st2.st_dev);
CHECK(st1.st_ino == st2.st_ino);
}
@@ -1368,7 +1368,7 @@ static void dir_check(struct dir_info *dir)
break;
}
}
- CHECK(closedir(d) != -1);
+ CHECK(closedir(d) == 0);
CHECK(checked == dir->number_of_entries);
/* Now check each entry */
@@ -1386,7 +1386,7 @@ static void dir_check(struct dir_info *dir)
entry = entry->next;
}
- CHECK(stat(path, &st) != -1);
+ CHECK(stat(path, &st) == 0);
CHECK(link_count == st.st_nlink);
free(entry_array);
@@ -1579,7 +1579,7 @@ static void rename_entry(struct dir_entry_info *entry)
return;
ret = rename(path, to);
- if (ret == -1) {
+ if (ret != 0) {
if (errno == ENOSPC)
full = 1;
CHECK(errno == ENOSPC || errno == EBUSY);
@@ -1693,7 +1693,7 @@ static void symlink_new(struct dir_info *dir, const char *name_)
path = dir_path(dir, name);
target = pick_symlink_target(path);
- if (symlink(target, path) == -1) {
+ if (symlink(target, path) != 0) {
CHECK(errno == ENOSPC || errno == ENAMETOOLONG);
if (errno == ENOSPC)
full = 1;
@@ -1718,7 +1718,7 @@ static void symlink_remove(struct symlink_info *symlink)
remove_dir_entry(symlink->entry);
- CHECK(unlink(path) != -1);
+ CHECK(unlink(path) == 0);
free(path);
}
@@ -1853,9 +1853,9 @@ static void operate_on_open_file(struct fd_info *fdi)
file_write(fdi->file, fdi->fd);
if (r >= 999) {
if (tests_random_no(100) >= 50)
- CHECK(fsync(fdi->fd) != -1);
+ CHECK(fsync(fdi->fd) == 0);
else
- CHECK(fdatasync(fdi->fd) != -1);
+ CHECK(fdatasync(fdi->fd) == 0);
}
}
}
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 21/27] fs-tests: integck: do not use tests_fs_is_rootfs
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (20 preceding siblings ...)
2011-04-13 15:19 ` [PATCH 20/27] fs-tests: integck: prefer to check for success Artem Bityutskiy
@ 2011-04-13 15:19 ` Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 22/27] fs-tests: integck: do not use tests_remount Artem Bityutskiy
` (5 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:19 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Do not use the shared 'tests_fs_is_rootfs()' function - introduce
'fsinfo.is_rootfs' flag and utilize it instead. This is another step
forward the goal to make integck independent of the common code.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 92571d1..7a4bcdc 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -65,6 +65,7 @@ static struct {
* nospc_size_ok: file size is updated even if the write operation failed with
* ENOSPC error
* can_mmap: file-system supports share writable 'mmap()' operation
+ * is_rootfs: the tested file-system the root file-system
* fstype: file-system type (e.g., "ubifs")
* mount_point: tested file-system mount point path
* test_dir: the directory on the tested file-system where we test
@@ -75,6 +76,7 @@ static struct {
unsigned int log10_initial_free;
unsigned int nospc_size_ok:1;
unsigned int can_mmap:1;
+ unsigned int is_rootfs:1;
const char *fstype;
const char *mount_point;
const char *test_dir;
@@ -2026,7 +2028,7 @@ static int integck(void)
create_test_data();
- if (!tests_fs_is_rootfs()) {
+ if (fsinfo.is_rootfs) {
close_open_files();
tests_remount(); /* Requires root access */
}
@@ -2039,7 +2041,7 @@ static int integck(void)
for (rpt = 0; args.repeat_cnt == 0 || rpt < args.repeat_cnt; ++rpt) {
update_test_data();
- if (!tests_fs_is_rootfs()) {
+ if (!fsinfo.is_rootfs) {
close_open_files();
tests_remount(); /* Requires root access */
}
@@ -2069,6 +2071,7 @@ static void get_tested_fs_info(void)
uint64_t z;
char *p;
unsigned int pid;
+ struct stat st1, st2;
/* Remove trailing '/' symbols from the mount point */
p = dup_string(args.mount_point);
@@ -2127,6 +2130,11 @@ static void get_tested_fs_info(void)
normsg("pid %u, testing \"%s\" at \"%s\"",
pid, fsinfo.fstype, fsinfo.mount_point);
+
+ CHECK(stat(fsinfo.mount_point, &st1) == 0);
+ CHECK(stat("/", &st2) != -1);
+ if (st1.st_dev == st2.st_dev)
+ fsinfo.is_rootfs = 1;
}
static const char doc[] = PROGRAM_NAME " version " PROGRAM_VERSION
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 22/27] fs-tests: integck: do not use tests_remount
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (21 preceding siblings ...)
2011-04-13 15:19 ` [PATCH 21/27] fs-tests: integck: do not use tests_fs_is_rootfs Artem Bityutskiy
@ 2011-04-13 15:19 ` Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 23/27] fs-tests: integck: do not use tests_get_total_space Artem Bityutskiy
` (4 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:19 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Implement our own version of 'tests_remount()' instead of depending
on the common implementation.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 167 +++++++++++++++++++++++++++++++++++-
1 files changed, 165 insertions(+), 2 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 7a4bcdc..9bf42af 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -67,6 +67,11 @@ static struct {
* can_mmap: file-system supports share writable 'mmap()' operation
* is_rootfs: the tested file-system the root file-system
* fstype: file-system type (e.g., "ubifs")
+ * fsdev: the underlying device mounted by the tested file-system
+ * mount_opts: non-standard mount options of the tested file-system (non-standard
+ * options are stored in string form as a comma-separated list)
+ * mount_flags: standard mount options of the tested file-system (standard
+ * options as stored as a set of flags)
* mount_point: tested file-system mount point path
* test_dir: the directory on the tested file-system where we test
*/
@@ -78,6 +83,9 @@ static struct {
unsigned int can_mmap:1;
unsigned int is_rootfs:1;
const char *fstype;
+ const char *fsdev;
+ const char *mount_opts;
+ unsigned long mount_flags;
const char *mount_point;
const char *test_dir;
} fsinfo = {
@@ -2011,6 +2019,98 @@ static void update_test_data(void)
do_an_operation();
}
+/**
+ * Re-mount the test file-system. This function randomly select how to
+ * re-mount.
+ */
+void remount_tested_fs(void)
+{
+ char *wd_save;
+ int ret;
+ unsigned long flags;
+ unsigned int rorw1, um, um_ro, um_rorw, rorw2;
+
+ /* Save current working directory */
+ wd_save = malloc(PATH_MAX + 1);
+ CHECK(wd_save != NULL);
+ CHECK(getcwd(wd_save, PATH_MAX + 1) != NULL);
+
+ /* Temporarily change working directory to '/' */
+ CHECK(chdir("/") == 0);
+
+ /* Choose what to do */
+ rorw1 = rand() & 1;
+ um = rand() & 1;
+ um_ro = rand() & 1;
+ um_rorw = rand() & 1;
+ rorw2 = rand() & 1;
+
+ if (rorw1 + um + rorw2 == 0)
+ um = 1;
+
+ if (rorw1) {
+ flags = fsinfo.mount_flags | MS_RDONLY | MS_REMOUNT;
+ ret = mount(fsinfo.fsdev, fsinfo.mount_point, fsinfo.fstype,
+ flags, fsinfo.mount_opts);
+ CHECK(ret == 0);
+
+ flags = fsinfo.mount_flags | MS_REMOUNT;
+ flags &= ~((unsigned long)MS_RDONLY);
+ ret = mount(fsinfo.fsdev, fsinfo.mount_point, fsinfo.fstype,
+ flags, fsinfo.mount_opts);
+ CHECK(ret == 0);
+ }
+
+ if (um) {
+ if (um_ro) {
+ flags = fsinfo.mount_flags | MS_RDONLY | MS_REMOUNT;
+ ret = mount(fsinfo.fsdev, fsinfo.mount_point,
+ fsinfo.fstype, flags, fsinfo.mount_opts);
+ CHECK(ret == 0);
+ }
+
+ CHECK(umount(fsinfo.mount_point) != -1);
+
+ if (!um_rorw) {
+ ret = mount(fsinfo.fsdev, fsinfo.mount_point,
+ fsinfo.fstype, fsinfo.mount_flags,
+ fsinfo.mount_opts);
+ CHECK(ret == 0);
+ } else {
+ ret = mount(fsinfo.fsdev, fsinfo.mount_point,
+ fsinfo.fstype, fsinfo.mount_flags | MS_RDONLY,
+ fsinfo.mount_opts);
+ CHECK(ret == 0);
+
+ flags = fsinfo.mount_flags | MS_REMOUNT;
+ flags &= ~((unsigned long)MS_RDONLY);
+ ret = mount(fsinfo.fsdev, fsinfo.mount_point,
+ fsinfo.fstype, flags, fsinfo.mount_opts);
+ CHECK(ret == 0);
+ }
+ }
+
+ if (rorw2) {
+ flags = fsinfo.mount_flags | MS_RDONLY | MS_REMOUNT;
+ ret = mount(fsinfo.fsdev, fsinfo.mount_point, fsinfo.fstype,
+ flags, fsinfo.mount_opts);
+ CHECK(ret == 0);
+
+ flags = fsinfo.mount_flags | MS_REMOUNT;
+ flags &= ~((unsigned long)MS_RDONLY);
+ ret = mount(fsinfo.fsdev, fsinfo.mount_point, fsinfo.fstype,
+ flags, fsinfo.mount_opts);
+ CHECK(ret == 0);
+ }
+
+ /* Restore the previous working directory */
+ CHECK(chdir(wd_save) == 0);
+ free(wd_save);
+}
+
+/*
+ * Perform the test. Returns zero on success and -1 on failure.
+ */
static int integck(void)
{
int64_t rpt;
@@ -2030,7 +2130,7 @@ static int integck(void)
if (fsinfo.is_rootfs) {
close_open_files();
- tests_remount(); /* Requires root access */
+ remount_tested_fs();
}
/* Check everything */
@@ -2043,7 +2143,7 @@ static int integck(void)
if (!fsinfo.is_rootfs) {
close_open_files();
- tests_remount(); /* Requires root access */
+ remount_tested_fs();
}
/* Check everything */
@@ -2060,6 +2160,67 @@ static int integck(void)
}
/*
+ * This is a helper function for 'get_tested_fs_info()'. It parses file-system
+ * mount options string, extracts standard mount options from there, and saves
+ * them in the 'fsinfo.mount_flags' variable, and non-standard mount options
+ * are saved in the 'fsinfo.mount_opts' variable. The reason for this is that
+ * we want to preserve mount options when unmounting the file-system and
+ * mounting it again. This is because we cannot pass standard mount optins
+ * (like sync, ro, etc) as a string to the 'mount()' function, because it
+ * fails. It accepts standard mount options only as flags. And only the
+ * FS-specific mount options are accepted in form of a string.
+ */
+static void parse_mount_options(const char *mount_opts)
+{
+ char *tmp, *opts, *p;
+ const char *opt;
+
+ /*
+ * We are going to use 'strtok()' which modifies the original string,
+ * so duplicate it.
+ */
+ tmp = dup_string(mount_opts);
+ p = opts = calloc(1, strlen(mount_opts) + 1);
+ CHECK(opts != NULL);
+
+ opt = strtok(tmp, ",");
+ while (opt) {
+ if (!strcmp(opt, "rw"))
+ ;
+ else if (!strcmp(opt, "ro"))
+ fsinfo.mount_flags |= MS_RDONLY;
+ else if (!strcmp(opt, "dirsync"))
+ fsinfo.mount_flags |= MS_DIRSYNC;
+ else if (!strcmp(opt, "noatime"))
+ fsinfo.mount_flags |= MS_NOATIME;
+ else if (!strcmp(opt, "nodiratime"))
+ fsinfo.mount_flags |= MS_NODIRATIME;
+ else if (!strcmp(opt, "noexec"))
+ fsinfo.mount_flags |= MS_NOEXEC;
+ else if (!strcmp(opt, "nosuid"))
+ fsinfo.mount_flags |= MS_NOSUID;
+ else if (!strcmp(opt, "relatime"))
+ fsinfo.mount_flags |= MS_RELATIME;
+ else if (!strcmp(opt, "sync"))
+ fsinfo.mount_flags |= MS_SYNCHRONOUS;
+ else {
+ int len = strlen(opt);
+
+ if (p != opts)
+ *p++ = ',';
+ memcpy(p, opt, len);
+ p += len;
+ *p = '\0';
+ }
+
+ opt = strtok(NULL, ",");
+ }
+
+ free(tmp);
+ fsinfo.mount_opts = opts;
+}
+
+/*
* Fill 'fsinfo' with information about the tested file-system.
*/
static void get_tested_fs_info(void)
@@ -2104,6 +2265,8 @@ static void get_tested_fs_info(void)
fclose(f);
fsinfo.fstype = dup_string(mntent->mnt_type);
+ fsinfo.fsdev = strdup(mntent->mnt_fsname);
+ parse_mount_options(mntent->mnt_opts);
/* Get memory page size for 'mmap()' */
fsinfo.page_size = sysconf(_SC_PAGE_SIZE);
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 23/27] fs-tests: integck: do not use tests_get_total_space
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (22 preceding siblings ...)
2011-04-13 15:19 ` [PATCH 22/27] fs-tests: integck: do not use tests_remount Artem Bityutskiy
@ 2011-04-13 15:19 ` Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 24/27] fs-tests: integck: do not use global common variables Artem Bityutskiy
` (3 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:19 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Do not use the common tests_get_total_space but extend our own
get_free_space function and make it return both free and total
amount of space.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 9bf42af..a53be64 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -278,12 +278,15 @@ static char *cat_paths(const char *a, const char *b)
/*
* Get the free space for the tested file system.
*/
-static uint64_t get_free_space(void)
+static void get_fs_space(uint64_t *total, uint64_t *free)
{
struct statvfs st;
CHECK(statvfs(fsinfo.mount_point, &st) == 0);
- return (uint64_t)st.f_bavail * (uint64_t)st.f_frsize;
+ if (total)
+ *total = (uint64_t)st.f_blocks * (uint64_t)st.f_frsize;
+ if (free)
+ *free = (uint64_t)st.f_bavail * (uint64_t)st.f_frsize;
}
static char *dir_path(struct dir_info *parent, const char *name)
@@ -862,7 +865,7 @@ static void file_mmap_write(struct file_info *file)
if (!file->links)
return;
- free_space = get_free_space();
+ get_fs_space(NULL, &free_space);
if (!free_space)
return;
/* Randomly pick a written area of the file */
@@ -1939,8 +1942,7 @@ static void create_test_data(void)
uint64_t total;
for (i = 0; i < 10; ++i)
do_an_operation();
- free = get_free_space();
- total = tests_get_total_space();
+ get_fs_space(&total, &free);
if ((free * 100) / total >= 10)
break;
}
@@ -2006,8 +2008,7 @@ static void update_test_data(void)
uint64_t total;
for (i = 0; i < 10; ++i)
do_an_operation();
- free = get_free_space();
- total = tests_get_total_space();
+ get_fs_space(&total, &free);
if ((free * 100) / total >= 50)
break;
}
@@ -2281,7 +2282,8 @@ static void get_tested_fs_info(void)
fsinfo.can_mmap = 0;
}
- for (z = get_free_space(); z >= 10; z /= 10)
+ get_fs_space(NULL, &z);
+ for (; z >= 10; z /= 10)
fsinfo.log10_initial_free += 1;
/* Pick the test directory name */
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 24/27] fs-tests: integck: do not use global common variables
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (23 preceding siblings ...)
2011-04-13 15:19 ` [PATCH 23/27] fs-tests: integck: do not use tests_get_total_space Artem Bityutskiy
@ 2011-04-13 15:19 ` Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 25/27] fs-tests: integck: do not use tests_random_no Artem Bityutskiy
` (2 subsequent siblings)
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:19 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Do not use the 'tests_file_system_mount_dir' and 'tests_file_system_type'
variables because we do not depend on them any longer.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 4 ----
1 files changed, 0 insertions(+), 4 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index a53be64..5cb7bca 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -2388,10 +2388,6 @@ int main(int argc, char *argv[])
get_tested_fs_info();
- /* Temporary hack - will be fixed a bit later */
- tests_file_system_mount_dir = (void *)fsinfo.mount_point;
- tests_file_system_type = (void *)fsinfo.fstype;
-
/* Seed the random generator with out PID */
srand(getpid());
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 25/27] fs-tests: integck: do not use tests_random_no
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (24 preceding siblings ...)
2011-04-13 15:19 ` [PATCH 24/27] fs-tests: integck: do not use global common variables Artem Bityutskiy
@ 2011-04-13 15:19 ` Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 26/27] fs-tests: integck: implement own version of CHECK Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 27/27] fs-tests: integck: do not expect max name length to be 256 Artem Bityutskiy
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:19 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Do not use the shared 'tests_random_no()' function but use our own
simple implementation instead. We do not need those rather complex
and difficult to understand computations.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 119 +++++++++++++++++++----------------
1 files changed, 65 insertions(+), 54 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 5cb7bca..2dbe9de 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -196,6 +196,17 @@ static int is_truncation(struct write_info *w)
}
/*
+ * Return a random number between 0 and max - 1.
+ */
+static unsigned int random_no(unsigned int max)
+{
+ assert(max < RAND_MAX);
+ if (max == 0)
+ return 0;
+ return rand() % max;
+}
+
+/*
* Allocate a buffer of 'size' bytes and fill it with zeroes.
*/
static void *zalloc(size_t size)
@@ -567,11 +578,11 @@ static void file_unlink(struct dir_entry_info *entry)
static struct dir_entry_info *pick_entry(struct file_info *file)
{
struct dir_entry_info *entry;
- size_t r;
+ unsigned int r;
if (!file->link_count)
return NULL;
- r = tests_random_no(file->link_count);
+ r = random_no(file->link_count);
entry = file->links;
while (entry && r--)
entry = entry->next_link;
@@ -660,7 +671,7 @@ static struct fd_info *file_open(struct file_info *file)
char *path;
path = dir_path(file->links->parent, file->links->name);
- if (tests_random_no(100) == 1)
+ if (random_no(100) == 1)
flags |= O_SYNC;
fd = open(path, flags);
CHECK(fd != -1);
@@ -806,30 +817,30 @@ static void get_offset_and_size(struct file_info *file,
off_t *offset,
size_t *size)
{
- size_t r, n;
+ unsigned int r, n;
- r = tests_random_no(100);
+ r = random_no(100);
if (r == 0 && grow)
/* 1 time in 100, when growing, write off the end of the file */
- *offset = file->length + tests_random_no(10000000);
+ *offset = file->length + random_no(10000000);
else if (r < 4)
/* 3 (or 4) times in 100, write at the beginning of file */
*offset = 0;
else if (r < 52 || !grow)
/* 48 times in 100, write into the file */
- *offset = tests_random_no(file->length);
+ *offset = random_no(file->length);
else
/* 48 times in 100, write at the end of the file */
*offset = file->length;
/* Distribute the size logarithmically */
- if (tests_random_no(1000) == 0)
- r = tests_random_no(fsinfo.log10_initial_free + 2);
+ if (random_no(1000) == 0)
+ r = random_no(fsinfo.log10_initial_free + 2);
else
- r = tests_random_no(fsinfo.log10_initial_free);
+ r = random_no(fsinfo.log10_initial_free);
n = 1;
while (r--)
n *= 10;
- *size = tests_random_no(n);
+ *size = random_no(n);
if (!grow && *offset + *size > file->length)
*size = file->length - *offset;
if (*size == 0)
@@ -875,7 +886,7 @@ static void file_mmap_write(struct file_info *file)
write_cnt += 1;
w = w->next;
}
- r = tests_random_no(write_cnt);
+ r = random_no(write_cnt);
w = file->writes;
for (i = 0; w && w->next && i < r; i++)
w = w->next;
@@ -897,15 +908,15 @@ static void file_mmap_write(struct file_info *file)
CHECK(addr != MAP_FAILED);
/* Randomly select a part of the mmapped area to write */
- size = tests_random_no(w->size);
+ size = random_no(w->size);
if (size > free_space)
size = free_space;
if (size == 0)
size = 1;
- offset = w->offset + tests_random_no(w->size - size);
+ offset = w->offset + random_no(w->size - size);
/* Write it */
- seed = tests_random_no(MAX_RANDOM_SEED);
+ seed = random_no(MAX_RANDOM_SEED);
srand(seed);
waddr = addr + (offset - offs);
for (i = 0; i < size; i++)
@@ -926,19 +937,19 @@ static void file_write(struct file_info *file, int fd)
int truncate = 0;
if (fsinfo.can_mmap && !full && !file->deleted &&
- tests_random_no(100) == 1) {
+ random_no(100) == 1) {
file_mmap_write(file);
return;
}
get_offset_and_size(file, &offset, &size);
- seed = tests_random_no(MAX_RANDOM_SEED);
+ seed = random_no(MAX_RANDOM_SEED);
actual = file_write_data(file, fd, offset, size, seed);
if (offset + actual <= file->length && shrink)
/* 1 time in 100, when shrinking
truncate after the write */
- if (tests_random_no(100) == 0)
+ if (random_no(100) == 0)
truncate = 1;
if (actual != 0)
@@ -1006,7 +1017,7 @@ static void file_truncate(struct file_info *file, int fd)
{
size_t new_length;
- new_length = tests_random_no(file->length);
+ new_length = random_no(file->length);
if (file_ftruncate(file, fd, new_length))
file_truncate_info(file, new_length);
@@ -1431,15 +1442,15 @@ static char *make_name(struct dir_info *dir)
do {
found = 0;
- if (tests_random_no(5) == 1) {
- int i, n = tests_random_no(fsinfo.max_name_len) + 1;
+ if (random_no(5) == 1) {
+ int i, n = random_no(fsinfo.max_name_len) + 1;
CHECK(n > 0 && n < 256);
for (i = 0; i < n; i++)
- name[i] = 'a' + tests_random_no(26);
+ name[i] = 'a' + random_no(26);
name[i] = '\0';
} else
- sprintf(name, "%u", (unsigned)tests_random_no(1000000));
+ sprintf(name, "%u", random_no(1000000));
for (entry = dir->first; entry; entry = entry->next) {
if (strcmp(entry->name, name) == 0) {
found = 1;
@@ -1456,9 +1467,9 @@ static struct file_info *pick_file(void)
for (;;) {
struct dir_entry_info *entry;
- size_t r;
+ unsigned int r;
- r = tests_random_no(dir->number_of_entries);
+ r = random_no(dir->number_of_entries);
entry = dir->first;
while (entry && r) {
entry = entry->next;
@@ -1482,13 +1493,13 @@ static struct dir_info *pick_dir(void)
{
struct dir_info *dir = top_dir;
- if (tests_random_no(40) >= 30)
+ if (random_no(40) >= 30)
return dir;
for (;;) {
struct dir_entry_info *entry;
size_t r;
- r = tests_random_no(dir->number_of_entries);
+ r = random_no(dir->number_of_entries);
entry = dir->first;
while (entry && r) {
entry = entry->next;
@@ -1514,7 +1525,7 @@ static struct dir_info *pick_dir(void)
if (!entry)
return dir;
dir = entry->dir;
- if (tests_random_no(40) >= 30)
+ if (random_no(40) >= 30)
return dir;
}
}
@@ -1524,15 +1535,15 @@ static char *pick_rename_name(struct dir_info **parent,
{
struct dir_info *dir = pick_dir();
struct dir_entry_info *entry;
- size_t r;
+ unsigned int r;
*parent = dir;
*rename_entry = NULL;
- if (grow || tests_random_no(20) < 10)
+ if (grow || random_no(20) < 10)
return dup_string(make_name(dir));
- r = tests_random_no(dir->number_of_entries);
+ r = random_no(dir->number_of_entries);
entry = dir->first;
while (entry && r) {
entry = entry->next;
@@ -1673,15 +1684,15 @@ static char *pick_symlink_target(const char *symlink_path)
{
struct dir_info *dir;
struct dir_entry_info *entry;
- size_t r;
char *path, *rel_path;
+ unsigned int r;
dir = pick_dir();
- if (tests_random_no(100) < 10)
+ if (random_no(100) < 10)
return dir_path(dir, make_name(dir));
- r = tests_random_no(dir->number_of_entries);
+ r = random_no(dir->number_of_entries);
entry = dir->first;
while (entry && r) {
entry = entry->next;
@@ -1692,7 +1703,7 @@ static char *pick_symlink_target(const char *symlink_path)
if (!entry)
return dir_path(dir, make_name(dir));
path = dir_path(dir, entry->name);
- if (tests_random_no(20) < 10)
+ if (random_no(20) < 10)
return path;
rel_path = relative_path(symlink_path, path);
free(path);
@@ -1742,20 +1753,20 @@ static void operate_on_file(struct file_info *file);
static void operate_on_entry(struct dir_entry_info *entry)
{
/* 1 time in 1000 rename */
- if (tests_random_no(1000) == 0) {
+ if (random_no(1000) == 0) {
rename_entry(entry);
return;
}
if (entry->type == 's') {
symlink_check(entry->symlink);
/* If shrinking, 1 time in 50, remove a symlink */
- if (shrink && tests_random_no(50) == 0)
+ if (shrink && random_no(50) == 0)
symlink_remove(entry->symlink);
return;
}
if (entry->type == 'd') {
/* If shrinking, 1 time in 50, remove a directory */
- if (shrink && tests_random_no(50) == 0) {
+ if (shrink && random_no(50) == 0) {
dir_remove(entry->dir);
return;
}
@@ -1763,13 +1774,13 @@ static void operate_on_entry(struct dir_entry_info *entry)
}
if (entry->type == 'f') {
/* If shrinking, 1 time in 10, remove a file */
- if (shrink && tests_random_no(10) == 0) {
+ if (shrink && random_no(10) == 0) {
file_delete(entry->file);
return;
}
/* If not growing, 1 time in 10, unlink a file with links > 1 */
if (!grow && entry->file->link_count > 1 &&
- tests_random_no(10) == 0) {
+ random_no(10) == 0) {
file_unlink_file(entry->file);
return;
}
@@ -1780,11 +1791,11 @@ static void operate_on_entry(struct dir_entry_info *entry)
/* Randomly select something to do with a directory */
static void operate_on_dir(struct dir_info *dir)
{
- size_t r;
struct dir_entry_info *entry;
struct file_info *file;
+ unsigned int r;
- r = tests_random_no(14);
+ r = random_no(14);
if (r == 0 && grow)
/* When growing, 1 time in 14 create a file */
file_new(dir, make_name(dir));
@@ -1794,12 +1805,12 @@ static void operate_on_dir(struct dir_info *dir)
else if (r == 2 && grow && (file = pick_file()) != NULL)
/* When growing, 1 time in 14 create a hard link */
link_new(dir, make_name(dir), file);
- else if (r == 3 && grow && tests_random_no(5) == 0)
+ else if (r == 3 && grow && random_no(5) == 0)
/* When growing, 1 time in 70 create a symbolic link */
symlink_new(dir, make_name(dir));
else {
/* Otherwise randomly select an entry to operate on */
- r = tests_random_no(dir->number_of_entries);
+ r = random_no(dir->number_of_entries);
entry = dir->first;
while (entry && r) {
entry = entry->next;
@@ -1819,24 +1830,24 @@ static void operate_on_file(struct file_info *file)
return;
}
/* Try to keep about 20 files open */
- if (open_files_count < 20 && tests_random_no(2) == 0) {
+ if (open_files_count < 20 && random_no(2) == 0) {
file_open(file);
return;
}
/* Try to keep up to 40 files open */
- if (open_files_count < 40 && tests_random_no(20) == 0) {
+ if (open_files_count < 40 && random_no(20) == 0) {
file_open(file);
return;
}
/* Occasionly truncate */
- if (shrink && tests_random_no(100) == 0) {
+ if (shrink && random_no(100) == 0) {
file_truncate_file(file);
return;
}
/* Mostly just write */
file_write_file(file);
/* Once in a while check it too */
- if (tests_random_no(100) == 1) {
+ if (random_no(100) == 1) {
int fd = -2;
if (file->links)
@@ -1853,9 +1864,9 @@ static void operate_on_file(struct file_info *file)
/* Randomly select something to do with an open file */
static void operate_on_open_file(struct fd_info *fdi)
{
- size_t r;
+ unsigned int r;
- r = tests_random_no(1000);
+ r = random_no(1000);
if (shrink && r < 5)
file_truncate(fdi->file, fdi->fd);
else if (r < 21)
@@ -1865,7 +1876,7 @@ static void operate_on_open_file(struct fd_info *fdi)
else {
file_write(fdi->file, fdi->fd);
if (r >= 999) {
- if (tests_random_no(100) >= 50)
+ if (random_no(100) >= 50)
CHECK(fsync(fdi->fd) == 0);
else
CHECK(fdatasync(fdi->fd) == 0);
@@ -1876,7 +1887,7 @@ static void operate_on_open_file(struct fd_info *fdi)
/* Select an open file at random */
static void operate_on_an_open_file(void)
{
- size_t r;
+ unsigned int r;
struct open_file_info *ofi;
/* When shrinking, close all open files 1 time in 128 */
@@ -1904,7 +1915,7 @@ static void operate_on_an_open_file(void)
ofi = ofi->next;
}
}
- r = tests_random_no(open_files_count);
+ r = random_no(open_files_count);
for (ofi = open_files; ofi; ofi = ofi->next, --r)
if (!r) {
operate_on_open_file(ofi->fdi);
@@ -1915,7 +1926,7 @@ static void operate_on_an_open_file(void)
static void do_an_operation(void)
{
/* Half the time operate on already open files */
- if (tests_random_no(100) < 50)
+ if (random_no(100) < 50)
operate_on_dir(top_dir);
else
operate_on_an_open_file();
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 26/27] fs-tests: integck: implement own version of CHECK
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (25 preceding siblings ...)
2011-04-13 15:19 ` [PATCH 25/27] fs-tests: integck: do not use tests_random_no Artem Bityutskiy
@ 2011-04-13 15:19 ` Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 27/27] fs-tests: integck: do not expect max name length to be 256 Artem Bityutskiy
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:19 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Remove the final dependency on the common code - the CHECK() macro.
Now we are finally independent. The reason we needed this is that
we are going to improve integck to handle errors more gracefully,
in order to support failure testing better. And this requires changes
in the common code, but it is ancient and shared by many tests, and
we do not want to touch it. So we better make integck independent
and concentrate on integck only.
This patch also removes Makefile dependencies. And while on it, remove
the broken 'tests' target.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/Makefile | 7 -------
tests/fs-tests/integrity/integck.c | 17 ++++++++++++++++-
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/tests/fs-tests/integrity/Makefile b/tests/fs-tests/integrity/Makefile
index 364a732..03652a2 100644
--- a/tests/fs-tests/integrity/Makefile
+++ b/tests/fs-tests/integrity/Makefile
@@ -13,12 +13,5 @@ TARGETS = integck
all: $(TARGETS)
-$(TARGETS): ../lib/tests.o
-
-../lib/tests.o: ../lib/tests.h
-
clean:
rm -f *.o $(TARGETS)
-
-tests: all
- ./integck
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 2dbe9de..387874c 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -36,7 +36,6 @@
#include <sys/vfs.h>
#include <sys/mount.h>
#include <sys/statvfs.h>
-#include "tests.h"
#define PROGRAM_VERSION "1.1"
#define PROGRAM_NAME "integck"
@@ -47,6 +46,22 @@
/* The pattern for the top directory where we run the test */
#define TEST_DIR_PATTERN "integck_test_dir_%u"
+/*
+ * Check if a condition is true and die if not.
+ */
+#define stringify1(x) #x
+#define stringify(x) stringify1(x)
+#define CHECK(cond) do { \
+ if (!(cond)) { \
+ int _err = errno; \
+ fflush(stdout); \
+ errmsg("condition '%s' failed at %s:%d\n", \
+ stringify(cond), __FILE__, __LINE__); \
+ errmsg("error %d (%s)\n", _err, strerror(_err)); \
+ exit(EXIT_FAILURE); \
+ } \
+} while(0)
+
/* The variables below are set by command line arguments */
static struct {
long repeat_cnt;
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 27/27] fs-tests: integck: do not expect max name length to be 256
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
` (26 preceding siblings ...)
2011-04-13 15:19 ` [PATCH 26/27] fs-tests: integck: implement own version of CHECK Artem Bityutskiy
@ 2011-04-13 15:19 ` Artem Bityutskiy
27 siblings, 0 replies; 29+ messages in thread
From: Artem Bityutskiy @ 2011-04-13 15:19 UTC (permalink / raw)
To: MTD list; +Cc: Adrian Hunter
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
The 'make_name()' function assumes that the maxumum file name length
is 256 bytes, which is wrong. This patch fixes this.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
tests/fs-tests/integrity/integck.c | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 387874c..61fb12c 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -203,6 +203,11 @@ static uint64_t operation_count = 0; /* Number of operations used to fill
static unsigned int check_run_no;
/*
+ * A buffer which is used by 'make_name()' to return the generated random name.
+ */
+static char *random_name_buf;
+
+/*
* Is this 'struct write_info' actually holds information about a truncation?
*/
static int is_truncation(struct write_info *w)
@@ -1451,7 +1456,6 @@ static void close_open_files(void)
static char *make_name(struct dir_info *dir)
{
- static char name[256];
struct dir_entry_info *entry;
int found;
@@ -1460,20 +1464,20 @@ static char *make_name(struct dir_info *dir)
if (random_no(5) == 1) {
int i, n = random_no(fsinfo.max_name_len) + 1;
- CHECK(n > 0 && n < 256);
for (i = 0; i < n; i++)
- name[i] = 'a' + random_no(26);
- name[i] = '\0';
+ random_name_buf[i] = 'a' + random_no(26);
+ random_name_buf[i] = '\0';
} else
- sprintf(name, "%u", random_no(1000000));
+ sprintf(random_name_buf, "%u", random_no(1000000));
for (entry = dir->first; entry; entry = entry->next) {
- if (strcmp(entry->name, name) == 0) {
+ if (strcmp(entry->name, random_name_buf) == 0) {
found = 1;
break;
}
}
} while (found);
- return name;
+
+ return random_name_buf;
}
static struct file_info *pick_file(void)
@@ -2417,6 +2421,9 @@ int main(int argc, char *argv[])
/* Seed the random generator with out PID */
srand(getpid());
+ random_name_buf = malloc(fsinfo.max_name_len + 1);
+ CHECK(random_name_buf != NULL);
+
/* Do the actual test */
ret = integck();
if (ret)
--
1.7.2.3
^ permalink raw reply related [flat|nested] 29+ messages in thread
end of thread, other threads:[~2011-04-13 15:19 UTC | newest]
Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-13 15:18 [PATCH 00/27] mtd-utils: make integck test independent Artem Bityutskiy
2011-04-13 15:16 ` Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 01/27] fs-tests: integck: shrink dir_entry_info structure size Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 02/27] fs-tests: integck: shrink file_info " Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 03/27] fs-tests: integck: srink file_info structure even more Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 04/27] fs-tests: integck: abuse random_offset field nicer Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 05/27] fs-tests: integck: shrink write_info even more Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 06/27] fs-tests: integck: change tests defaults Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 07/27] fs-tests: integck: implement own parameters parsing Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 08/27] fs-tests: integck: clean-up copy_string Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 09/27] fs-tests: integck: get rid of tests_check_test_file_system Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 10/27] fs-tests: integck: make integck function return error Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 11/27] fs-tests: integck: move mem_page_size to fsinfo Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 12/27] fs-tests: integck: move more variables " Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 13/27] fs-tests: integck: add own get_free_space function Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 14/27] fs-tests: integck: move log10_initial_free to fsinfo Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 15/27] fs-tests: integck: remove trailing backslashes from mount point Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 16/27] fs-tests: integck: do not use tests_cat_pid Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 17/27] fs-tests: integck: clean up test directory creation Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 18/27] fs-tests: integck: do not use tests_clear_dir Artem Bityutskiy
2011-04-13 15:18 ` [PATCH 19/27] fs-tests: integck: do not use space after cast Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 20/27] fs-tests: integck: prefer to check for success Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 21/27] fs-tests: integck: do not use tests_fs_is_rootfs Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 22/27] fs-tests: integck: do not use tests_remount Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 23/27] fs-tests: integck: do not use tests_get_total_space Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 24/27] fs-tests: integck: do not use global common variables Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 25/27] fs-tests: integck: do not use tests_random_no Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 26/27] fs-tests: integck: implement own version of CHECK Artem Bityutskiy
2011-04-13 15:19 ` [PATCH 27/27] fs-tests: integck: do not expect max name length to be 256 Artem Bityutskiy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).