aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2007-06-18 16:35:23 +0300
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2007-06-18 16:35:23 +0300
commit47812a77cf2d0eaab9daf066ef86c5b4fc0f9347 (patch)
treeacaf10dbd4849a74e8480475c4507f6be3b892aa
parent80cecea79cf13075d136e73067aa40439539bb0f (diff)
UBI: fix tests
This patch fixes UBI tests and adds udev problems solution description. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
-rwxr-xr-xubi-utils/scripts/mkdevs.pl32
-rw-r--r--ubi-utils/src/libubi.c7
-rw-r--r--ubi-utils/tests/README.udev19
-rw-r--r--ubi-utils/tests/mkvol_bad.c21
-rw-r--r--ubi-utils/tests/mkvol_basic.c10
-rw-r--r--ubi-utils/tests/rsvol.c4
6 files changed, 72 insertions, 21 deletions
diff --git a/ubi-utils/scripts/mkdevs.pl b/ubi-utils/scripts/mkdevs.pl
new file mode 100755
index 0000000..f0fd464
--- /dev/null
+++ b/ubi-utils/scripts/mkdevs.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/perl -w
+
+#
+# Author: Artem B. Bityutskiy <dedekind@oktetlabs.ru>
+#
+# A small scrip which creates UBI device nodes in /dev. UBI allocates
+# major number dynamically, so the script looks at /proc/devices to find
+# out UBI's major number.
+#
+
+
+my $proc = '/proc/devices';
+my $regexp = '(\d+) (ubi\d+)$';
+
+
+open FILE, "<", $proc or die "Cannot open $proc file: $!\n";
+my @file = <FILE>;
+close FILE;
+
+foreach (@file) {
+ next if not m/$regexp/g;
+ print "found $2\n";
+
+ system("rm -rf /dev/$2");
+ system("mknod /dev/$2 c $1 0");
+
+ for (my $i = 0; $i < 128; $i += 1) {
+ system("rm -rf /dev/$2_$i");
+ my $j = $i + 1;
+ system("mknod /dev/$2_$i c $1 $j");
+ }
+}
diff --git a/ubi-utils/src/libubi.c b/ubi-utils/src/libubi.c
index 17ab4ee..06cf52a 100644
--- a/ubi-utils/src/libubi.c
+++ b/ubi-utils/src/libubi.c
@@ -272,10 +272,14 @@ int ubi_mkvol(libubi_t desc, const char *node, struct ubi_mkvol_request *req)
return -1;
ret = ioctl(fd, UBI_IOCMKVOL, &r);
-
if (!ret)
req->vol_id = r.vol_id;
+#if 1
+ /* This is a hack to work around udev problems */
+ system("udevsettle");
+#endif
+
close(fd);
return ret;
}
@@ -455,7 +459,6 @@ int ubi_get_vol_info1(libubi_t desc, int dev_num, int vol_id,
return -1;
info->name[ret - 1] = '\0';
-
return 0;
}
diff --git a/ubi-utils/tests/README.udev b/ubi-utils/tests/README.udev
new file mode 100644
index 0000000..a4ff9c5
--- /dev/null
+++ b/ubi-utils/tests/README.udev
@@ -0,0 +1,19 @@
+There is a problem with udev: when a volume is created, there is a delay
+before corresponding /dev/ubiX_Y device node is created by udev, so some
+tests fail because of this. The symptom is error messages like
+"cannot open /dev/ubi0_0".
+
+One possible solution of this problem is to pre-create UBI device and volume
+nodes. there is even a script which may be used for this in ubi-utils/scripts/.
+But this is not enough because udev will still remove and re-create the nodes
+and tests will still fail. So you need to stop removing device nodes using
+the following udev rule:
+
+ KERNEL=="ubi*_*", ACTION=="remove", OPTIONS+="ignore_device"
+
+In our Ubuntu distribution we put that to new file:
+/etc/udev/rules.d/50-local.rules
+
+Another possibility is to call udevsettle utility in libubi after the volume
+has been created See src/libubi.c - the call is there but is commented out.
+This is anyway an ugly hack, but works, although makes the tests slower.
diff --git a/ubi-utils/tests/mkvol_bad.c b/ubi-utils/tests/mkvol_bad.c
index 58ac4e1..023b06b 100644
--- a/ubi-utils/tests/mkvol_bad.c
+++ b/ubi-utils/tests/mkvol_bad.c
@@ -148,7 +148,7 @@ static int test_mkvol(void)
/* Bad vol_type */
req.alignment = 1;
- req.bytes = dev_info.avail_bytes;
+ req.bytes = dev_info.eb_size;
req.vol_type = UBI_DYNAMIC_VOLUME + UBI_STATIC_VOLUME;
ret = ubi_mkvol(libubi, node, &req);
if (check_failed(ret, EINVAL, "ubi_mkvol", "vol_type = %d",
@@ -229,25 +229,18 @@ static int test_mkvol(void)
req.name = &nm[0];
if (ubi_mkvol(libubi, node, &req)) {
+ /*
+ * Note, because of gluebi we may be unable to create
+ * dev_info.max_vol_count devices (MTD restrictions).
+ */
+ if (errno == ENFILE)
+ break;
failed("ubi_mkvol");
err_msg("vol_id %d", i);
goto remove;
}
}
- req.vol_id = UBI_VOL_NUM_AUTO;
- req.name = TESTNAME ":impossible";
- ret = ubi_mkvol(libubi, node, &req);
- if (check_failed(ret, ENOSPC, "ubi_mkvol", "volume %d created",
- req.vol_id))
- goto remove;
-
- req.vol_id = dev_info.max_vol_count;
- ret = ubi_mkvol(libubi, node, &req);
- if (check_failed(ret, EINVAL, "ubi_mkvol", "volume %d created",
- req.vol_id))
- goto remove;
-
for (i = 0; i < dev_info.max_vol_count + 1; i++)
ubi_rmvol(libubi, node, i);
diff --git a/ubi-utils/tests/mkvol_basic.c b/ubi-utils/tests/mkvol_basic.c
index 2c6a512..e2120e9 100644
--- a/ubi-utils/tests/mkvol_basic.c
+++ b/ubi-utils/tests/mkvol_basic.c
@@ -197,11 +197,11 @@ remove:
static int mkvol_multiple(void)
{
struct ubi_mkvol_request req;
- int i, ret;
+ int i, ret, max = dev_info.max_vol_count;
const char *name = TESTNAME ":mkvol_multiple()";
/* Create maximum number of volumes */
- for (i = 0; i < dev_info.max_vol_count; i++) {
+ for (i = 0; i < max; i++) {
char nm[strlen(name) + 50];
req.vol_id = UBI_VOL_NUM_AUTO;
@@ -213,6 +213,10 @@ static int mkvol_multiple(void)
req.name = &nm[0];
if (ubi_mkvol(libubi, node, &req)) {
+ if (errno == ENFILE) {
+ max = i;
+ break;
+ }
failed("ubi_mkvol");
err_msg("vol_id %d", i);
goto remove;
@@ -224,7 +228,7 @@ static int mkvol_multiple(void)
}
}
- for (i = 0; i < dev_info.max_vol_count; i++) {
+ for (i = 0; i < max; i++) {
struct ubi_vol_info vol_info;
if (ubi_rmvol(libubi, node, i)) {
diff --git a/ubi-utils/tests/rsvol.c b/ubi-utils/tests/rsvol.c
index 51fa069..7a9e5ea 100644
--- a/ubi-utils/tests/rsvol.c
+++ b/ubi-utils/tests/rsvol.c
@@ -243,7 +243,7 @@ static int test_rsvol1(struct ubi_vol_info *vol_info)
fd = open(vol_node, O_RDWR);
if (fd == -1) {
failed("open");
- err_msg("cannot open \"%s\"\n", node);
+ err_msg("cannot open \"%s\"\n", vol_node);
return -1;
}
@@ -278,7 +278,7 @@ static int test_rsvol1(struct ubi_vol_info *vol_info)
fd = open(vol_node, O_RDWR);
if (fd == -1) {
failed("open");
- err_msg("cannot open \"%s\"\n", node);
+ err_msg("cannot open \"%s\"\n", vol_node);
return -1;
}