[parted-devel] [PATCH 2/2] tests: add a test for /dev/md symlink
Brian C. Lane
bcl at redhat.com
Wed Jan 9 00:02:38 UTC 2013
From: "Brian C. Lane" <bcl at redhat.com>
* libparted/tests/symlink.c: Modified to test both /dev/mapper and
/dev/md symlink creation.
* libparted/tests/t3000-symlink.sh: Create /dev/md if it is missing
---
libparted/tests/symlink.c | 41 ++++++++++++++++++++++++++++++----------
libparted/tests/t3000-symlink.sh | 10 ++++++++++
2 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/libparted/tests/symlink.c b/libparted/tests/symlink.c
index 52e99ca..1db92e0 100644
--- a/libparted/tests/symlink.c
+++ b/libparted/tests/symlink.c
@@ -40,17 +40,16 @@ destroy_disk (void)
free (temporary_disk);
}
-START_TEST (test_symlink)
+static void test_disk_symlink (char *ln)
{
- char cwd[256], ln[256] = "/dev/mapper/parted-test-XXXXXX";
+ char cwd[256];
if (!getcwd (cwd, sizeof cwd)) {
fail ("Could not get cwd");
return;
}
- /* Create a symlink under /dev/mapper to our
- temporary disk */
+ /* Create a symlink to our temporary disk using the pattern in ln */
int tmp_fd = mkstemp (ln);
if (tmp_fd == -1) {
fail ("Could not create tempfile");
@@ -98,7 +97,7 @@ START_TEST (test_symlink)
}
/* Do something to our PedDevice, if the symlink was resolved,
- instead of remembering the /dev/mapper/foo name, this will fail */
+ instead of remembering the symlink name, this will fail */
ped_disk_clobber (dev);
exit_destroy_dev:
@@ -106,6 +105,21 @@ exit_destroy_dev:
exit_unlink_ln:
unlink (ln);
}
+
+START_TEST (test_mapper_symlink)
+{
+ char ln[256] = "/dev/mapper/parted-test-XXXXXX";
+
+ test_disk_symlink (ln);
+}
+END_TEST
+
+START_TEST (test_md_symlink)
+{
+ char ln[256] = "/dev/md/parted-test-XXXXXX";
+
+ test_disk_symlink (ln);
+}
END_TEST
int
@@ -114,16 +128,23 @@ main (int argc, char **argv)
set_program_name (argv[0]);
int number_failed;
Suite* suite = suite_create ("Symlink");
- TCase* tcase_symlink = tcase_create ("/dev/mapper symlink");
+ TCase* tcase_mapper_symlink = tcase_create ("/dev/mapper symlink");
+ TCase* tcase_md_symlink = tcase_create ("/dev/md symlink");
/* Fail when an exception is raised */
ped_exception_set_handler (_test_exception_handler);
- tcase_add_checked_fixture (tcase_symlink, create_disk, destroy_disk);
- tcase_add_test (tcase_symlink, test_symlink);
+ tcase_add_checked_fixture (tcase_mapper_symlink, create_disk, destroy_disk);
+ tcase_add_test (tcase_mapper_symlink, test_mapper_symlink);
+ /* Disable timeout for this test */
+ tcase_set_timeout (tcase_mapper_symlink, 0);
+ suite_add_tcase (suite, tcase_mapper_symlink);
+
+ tcase_add_checked_fixture (tcase_md_symlink, create_disk, destroy_disk);
+ tcase_add_test (tcase_md_symlink, test_md_symlink);
/* Disable timeout for this test */
- tcase_set_timeout (tcase_symlink, 0);
- suite_add_tcase (suite, tcase_symlink);
+ tcase_set_timeout (tcase_md_symlink, 0);
+ suite_add_tcase (suite, tcase_md_symlink);
SRunner* srunner = srunner_create (suite);
srunner_run_all (srunner, CK_VERBOSE);
diff --git a/libparted/tests/t3000-symlink.sh b/libparted/tests/t3000-symlink.sh
index 338e44a..3cab8df 100755
--- a/libparted/tests/t3000-symlink.sh
+++ b/libparted/tests/t3000-symlink.sh
@@ -22,6 +22,16 @@
# Need root privileges to create a symlink under /dev/mapper.
require_root_
+# /dev/md/ needs to exist. If it isn't there, create it just for this test
+if [ ! -d /dev/md ]; then
+ mkdir /dev/md
+ REMOVE_DEV_MD=1
+fi
+
symlink || fail=1
+if [ -n "$REMOVE_DEV_MD" ]; then
+ rmdir /dev/md
+fi
+
Exit $fail
--
1.8.0.2
More information about the parted-devel
mailing list