aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ubi-tests/Makefile6
-rw-r--r--tests/ubi-tests/rmvol.c308
-rwxr-xr-xtests/ubi-tests/runtests.sh2
-rw-r--r--tests/ubi-tests/volrefcnt.c122
4 files changed, 126 insertions, 312 deletions
diff --git a/tests/ubi-tests/Makefile b/tests/ubi-tests/Makefile
index a15d93c..157aa55 100644
--- a/tests/ubi-tests/Makefile
+++ b/tests/ubi-tests/Makefile
@@ -5,7 +5,7 @@ UBIUTILS_PATH=../../ubi-utils/
CC := $(CROSS)gcc
-TESTS=io_update rmvol integ io_paral io_read io_basic \
+TESTS=io_update volrefcnt integ io_paral io_read io_basic \
mkvol_basic mkvol_bad mkvol_paral rsvol
HELPER_NAMES=ubiupdatevol
@@ -15,13 +15,13 @@ HELPERS=$(addprefix helpers/, $(HELPER_NAMES))
# it removes the. If you want to prevent the removal, uncomment the below
#.SECONDARY: $(addsuffix .o, $(TESTS)) $(addsuffix .o, $(HELPERS))
-CFLAGS += -Wall -I$(LIBUBI_HEADER_PATH) -L $(LIBUBI_PATH) -O0 -ggdb
+CFLAGS += -Wall -I$(LIBUBI_HEADER_PATH) -L. -O2
all: ubi-utils libubi $(TESTS) $(HELPERS)
# Compile ubilib with the udevsettle hack
libubi: $(LIBUBI_SRC_PATH)/libubi.c $(LIBUBI_HEADER_PATH)/libubi.h $(LIBUBI_SRC_PATH)/libubi_int.h
- $(CC) $(CFLAGS) -I $(LIBUBI_SRC_PATH) -DUDEV_SETTLE_HACK -c $(LIBUBI_SRC_PATH)/libubi.c -o libubi.o
+ $(CC) $(CFLAGS) -I $(LIBUBI_SRC_PATH) -I../../include -DUDEV_SETTLE_HACK -c $(LIBUBI_SRC_PATH)/libubi.c -o libubi.o
ar cr libubi.a libubi.o
# The below cancels existing implicite rule to make programs from .c files,
diff --git a/tests/ubi-tests/rmvol.c b/tests/ubi-tests/rmvol.c
deleted file mode 100644
index 6c52319..0000000
--- a/tests/ubi-tests/rmvol.c
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * Copyright (c) Nokia Corporation, 2007
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Author: Artem B. Bityutskiy
- *
- * Test volume reference counting - create a volume, open a sysfs file
- * belonging to the volume, delete the volume but do not close the file, make
- * sure the file cannot be read, make sure the volume cannot be open, close the
- * file, make sure the volume disappeard, make sure its sysfs subtree
- * disappeared.
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include "libubi.h"
-#define TESTNAME "rmvol"
-#include "common.h"
-
-#define SYSFS_FILE "/sys/class/ubi/ubi%d_%d/usable_leb_size"
-
-int main(int argc, char * const argv[])
-{
- int ret, fd;
- char fname[sizeof(SYSFS_FILE) + 20];
- const char *node;
- libubi_t libubi;
- struct ubi_dev_info dev_info;
- struct ubi_mkvol_request req;
- char tmp[100];
-
- if (initial_check(argc, argv))
- return 1;
-
- node = argv[1];
-
- libubi = libubi_open();
- if (libubi == NULL) {
- failed("libubi_open");
- return 1;
- }
-
- if (ubi_get_dev_info(libubi, node, &dev_info)) {
- failed("ubi_get_dev_info");
- goto out_libubi;
- }
-
- /* Create a small dynamic volume */
- req.vol_id = UBI_VOL_NUM_AUTO;
- req.alignment = dev_info.min_io_size;
- req.bytes = dev_info.leb_size;
- req.vol_type = UBI_DYNAMIC_VOLUME;
- req.name = "rmvol";
-
- if (ubi_mkvol(libubi, node, &req)) {
- failed("ubi_mkvol");
- perror("ubi_mkvol");
- goto out_libubi;
- }
-
- /* Open volume-related sysfs file */
- sprintf(fname, SYSFS_FILE, dev_info.dev_num, req.vol_id);
- fd = open(fname, O_RDONLY);
- if (fd == -1) {
- failed("open");
- perror("open");
- goto out_rmvol;
- }
-
- /* Remove the volume, but do not close the file */
- if (ubi_rmvol(libubi, node, req.vol_id)) {
- failed("ubi_rmvol");
- perror("ubi_rmvol");
- goto out_close;
- }
-
- /* Try to read from the file, this should fail */
- ret = read(fd, tmp, 100);
- if (ret != -1) {
- failed("read");
- err_msg("read returned %d, expected -1", ret);
- goto out_close;
- }
-
- /* Close the file and try to open it again, should fail */
- close(fd);
- fd = open(fname, O_RDONLY);
- if (fd != -1) {
- failed("open");
- err_msg("opened %s again, open returned %d, expected -1",
- fname, fd);
- goto out_libubi;
- }
-
- libubi_close(libubi);
- return 0;
-
-out_rmvol:
- ubi_rmvol(libubi, node, req.vol_id);
-out_libubi:
- libubi_close(libubi);
- return 1;
-
-out_close:
- close(fd);
- libubi_close(libubi);
- return 1;
-}
-
-#if 0
-/**
- * mkvol_alignment - create volumes with different alignments.
- *
- * Thus function returns %0 in case of success and %-1 in case of failure.
- */
-static int mkvol_alignment(void)
-{
- struct ubi_mkvol_request req;
- int i, vol_id, ebsz;
- const char *name = TESTNAME ":mkvol_alignment()";
- int alignments[] = ALIGNMENTS(dev_info.leb_size);
-
- for (i = 0; i < sizeof(alignments)/sizeof(int); i++) {
- req.vol_id = UBI_VOL_NUM_AUTO;
-
- /* Alignment should actually be multiple of min. I/O size */
- req.alignment = alignments[i];
- req.alignment -= req.alignment % dev_info.min_io_size;
- if (req.alignment == 0)
- req.alignment = dev_info.min_io_size;
-
- /* Bear in mind alignment reduces EB size */
- ebsz = dev_info.leb_size - dev_info.leb_size % req.alignment;
- req.bytes = dev_info.avail_lebs * ebsz;
-
- req.vol_type = UBI_DYNAMIC_VOLUME;
- req.name = name;
-
- if (ubi_mkvol(libubi, node, &req)) {
- failed("ubi_mkvol");
- err_msg("alignment %d", req.alignment);
- return -1;
- }
-
- vol_id = req.vol_id;
- if (check_volume(vol_id, &req))
- goto remove;
-
- if (ubi_rmvol(libubi, node, vol_id)) {
- failed("ubi_rmvol");
- return -1;
- }
- }
-
- return 0;
-
-remove:
- ubi_rmvol(libubi, node, vol_id);
- return -1;
-}
-
-/**
- * mkvol_basic - simple test that checks basic volume creation capability.
- *
- * Thus function returns %0 in case of success and %-1 in case of failure.
- */
-static int mkvol_basic(void)
-{
- struct ubi_mkvol_request req;
- struct ubi_vol_info vol_info;
- int vol_id, ret;
- const char *name = TESTNAME ":mkvol_basic()";
-
- /* Create dynamic volume of maximum size */
- req.vol_id = UBI_VOL_NUM_AUTO;
- req.alignment = 1;
- req.bytes = dev_info.avail_bytes;
- req.vol_type = UBI_DYNAMIC_VOLUME;
- req.name = name;
-
- if (ubi_mkvol(libubi, node, &req)) {
- failed("ubi_mkvol");
- return -1;
- }
-
- vol_id = req.vol_id;
- if (check_volume(vol_id, &req))
- goto remove;
-
- if (ubi_rmvol(libubi, node, vol_id)) {
- failed("ubi_rmvol");
- return -1;
- }
-
- /* Create static volume of maximum size */
- req.vol_id = UBI_VOL_NUM_AUTO;
- req.alignment = 1;
- req.bytes = dev_info.avail_bytes;
- req.vol_type = UBI_STATIC_VOLUME;
- req.name = name;
-
- if (ubi_mkvol(libubi, node, &req)) {
- failed("ubi_mkvol");
- return -1;
- }
-
- vol_id = req.vol_id;
- if (check_volume(vol_id, &req))
- goto remove;
-
- if (ubi_rmvol(libubi, node, vol_id)) {
- failed("ubi_rmvol");
- return -1;
- }
-
- /* Make sure volume does not exist */
- ret = ubi_get_vol_info1(libubi, dev_info.dev_num, vol_id, &vol_info);
- if (ret == 0) {
- err_msg("removed volume %d exists", vol_id);
- goto remove;
- }
-
- return 0;
-
-remove:
- ubi_rmvol(libubi, node, vol_id);
- return -1;
-}
-
-/**
- * mkvol_multiple - test multiple volumes creation
- *
- * Thus function returns %0 if the test passed and %-1 if not.
- */
-static int mkvol_multiple(void)
-{
- struct ubi_mkvol_request req;
- int i, ret, max = dev_info.max_vol_count;
- const char *name = TESTNAME ":mkvol_multiple()";
-
- /* Create maximum number of volumes */
- for (i = 0; i < max; i++) {
- char nm[strlen(name) + 50];
-
- req.vol_id = UBI_VOL_NUM_AUTO;
- req.alignment = 1;
- req.bytes = 1;
- req.vol_type = UBI_STATIC_VOLUME;
-
- sprintf(&nm[0], "%s:%d", name, i);
- 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;
- }
-
- if (check_volume(req.vol_id, &req)) {
- err_msg("vol_id %d", i);
- goto remove;
- }
- }
-
- for (i = 0; i < max; i++) {
- struct ubi_vol_info vol_info;
-
- if (ubi_rmvol(libubi, node, i)) {
- failed("ubi_rmvol");
- return -1;
- }
-
- /* Make sure volume does not exist */
- ret = ubi_get_vol_info1(libubi, dev_info.dev_num, i, &vol_info);
- if (ret == 0) {
- err_msg("removed volume %d exists", i);
- goto remove;
- }
- }
-
- return 0;
-
-remove:
- for (i = 0; i < dev_info.max_vol_count + 1; i++)
- ubi_rmvol(libubi, node, i);
- return -1;
-}
-#endif
diff --git a/tests/ubi-tests/runtests.sh b/tests/ubi-tests/runtests.sh
index 7072e03..fa10c3e 100755
--- a/tests/ubi-tests/runtests.sh
+++ b/tests/ubi-tests/runtests.sh
@@ -2,7 +2,7 @@
ubidev="$1"
tests="mkvol_basic mkvol_bad mkvol_paral rsvol io_basic io_read io_update
-io_paral rmvol"
+io_paral volrefcnt"
if test -z "$ubidev";
then
diff --git a/tests/ubi-tests/volrefcnt.c b/tests/ubi-tests/volrefcnt.c
new file mode 100644
index 0000000..a56deae
--- /dev/null
+++ b/tests/ubi-tests/volrefcnt.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) Nokia Corporation, 2007
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Author: Artem B. Bityutskiy
+ *
+ * Test volume reference counting - create a volume, open a sysfs file
+ * belonging to the volume, delete the volume but do not close the file, make
+ * sure the file cannot be read, close the file, make sure the volume
+ * disappeard, make sure its sysfs subtree disappeared.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "libubi.h"
+#define TESTNAME "rmvol"
+#include "common.h"
+
+#define SYSFS_FILE "/sys/class/ubi/ubi%d_%d/usable_eb_size"
+
+int main(int argc, char * const argv[])
+{
+ int ret, fd;
+ char fname[sizeof(SYSFS_FILE) + 20];
+ const char *node;
+ libubi_t libubi;
+ struct ubi_dev_info dev_info;
+ struct ubi_mkvol_request req;
+ char tmp[100];
+
+ if (initial_check(argc, argv))
+ return 1;
+
+ node = argv[1];
+
+ libubi = libubi_open();
+ if (libubi == NULL) {
+ failed("libubi_open");
+ return 1;
+ }
+
+ if (ubi_get_dev_info(libubi, node, &dev_info)) {
+ failed("ubi_get_dev_info");
+ goto out_libubi;
+ }
+
+ /* Create a small dynamic volume */
+ req.vol_id = UBI_VOL_NUM_AUTO;
+ req.alignment = dev_info.min_io_size;
+ req.bytes = dev_info.leb_size;
+ req.vol_type = UBI_DYNAMIC_VOLUME;
+ req.name = "rmvol";
+
+ if (ubi_mkvol(libubi, node, &req)) {
+ failed("ubi_mkvol");
+ goto out_libubi;
+ }
+
+ /* Open volume-related sysfs file */
+ sprintf(fname, SYSFS_FILE, dev_info.dev_num, req.vol_id);
+ fd = open(fname, O_RDONLY);
+ if (fd == -1) {
+ err_msg("cannot open %s", fname);
+ failed("open");
+ goto out_rmvol;
+ }
+
+ /* Remove the volume, but do not close the file */
+ if (ubi_rmvol(libubi, node, req.vol_id)) {
+ failed("ubi_rmvol");
+ perror("ubi_rmvol");
+ goto out_close;
+ }
+
+ /* Try to read from the file, this should fail */
+ ret = read(fd, tmp, 100);
+ if (ret != -1) {
+ err_msg("read returned %d, expected -1", ret);
+ failed("read");
+ goto out_close;
+ }
+
+ /* Close the file and try to open it again, should fail */
+ close(fd);
+ fd = open(fname, O_RDONLY);
+ if (fd != -1) {
+ err_msg("opened %s again, open returned %d, expected -1",
+ fname, fd);
+ failed("open");
+ goto out_libubi;
+ }
+
+ libubi_close(libubi);
+ return 0;
+
+out_rmvol:
+ ubi_rmvol(libubi, node, req.vol_id);
+out_libubi:
+ libubi_close(libubi);
+ return 1;
+
+out_close:
+ close(fd);
+ libubi_close(libubi);
+ return 1;
+}