From: Artem Bityutskiy <dedekind1@gmail.com>
To: MTD list <linux-mtd@lists.infradead.org>
Cc: Adrian Hunter <adrian.hunter@nokia.com>
Subject: [PATCH 09/27] fs-tests: integck: get rid of tests_check_test_file_system
Date: Wed, 13 Apr 2011 18:18:49 +0300 [thread overview]
Message-ID: <1302707947-6143-10-git-send-email-dedekind1@gmail.com> (raw)
In-Reply-To: <1302707947-6143-1-git-send-email-dedekind1@gmail.com>
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
next prev parent reply other threads:[~2011-04-13 15:16 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Artem Bityutskiy [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1302707947-6143-10-git-send-email-dedekind1@gmail.com \
--to=dedekind1@gmail.com \
--cc=adrian.hunter@nokia.com \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.