]> granicus.if.org Git - strace/commitdiff
test: add mtd/ubi test helpers
authorMike Frysinger <vapier@gentoo.org>
Thu, 2 May 2013 19:44:42 +0000 (15:44 -0400)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 2 May 2013 22:43:47 +0000 (22:43 +0000)
I used these to develop the mtd/ubi ioctl decoders.

* test/.gitignore: Add mtd/ubi.
* test/Makefile: Declare all tests in a PROGS var.
Declare build targets .PHONY.
(all): Depend on $(PROGS) instead of hardcoded list.
(clean): Remove $(PROGS) instead of hardcoded list.
* test/mtd.c: New file.
* test/ubi.c: Likewise.

test/.gitignore
test/Makefile
test/mtd.c [new file with mode: 0644]
test/ubi.c [new file with mode: 0644]

index 7d2cd1e78846054e59880b8cc1add58c0eec20bf..ce242fd3146a93b4eea444806555491ba645a2ac 100644 (file)
@@ -8,3 +8,5 @@ childthread
 sigkill_rain
 wait_must_be_interruptible
 threaded_execve
+mtd
+ubi
index 781e1f68c3bd374cc64a8ea25e0a214ac1055765..97ae746ef56e700ea286544c9378796c68dd5f7d 100644 (file)
@@ -1,14 +1,17 @@
 CFLAGS += -Wall
 
-all: \
+PROGS = \
     vfork fork sig skodic clone leaderkill childthread \
-    sigkill_rain wait_must_be_interruptible threaded_execve
+    sigkill_rain wait_must_be_interruptible threaded_execve \
+    mtd ubi
+
+all: $(PROGS)
 
 leaderkill: LDFLAGS += -pthread
 
 childthread: LDFLAGS += -pthread
 
 clean distclean:
-       rm -f *.o core \
-    vfork fork sig skodic clone leaderkill childthread \
-    sigkill_rain wait_must_be_interruptible threaded_execve
+       rm -f *.o core $(PROGS) *.gdb
+
+.PHONY: all clean distclean
diff --git a/test/mtd.c b/test/mtd.c
new file mode 100644 (file)
index 0000000..b9fc695
--- /dev/null
@@ -0,0 +1,49 @@
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <mtd/mtd-user.h>
+
+int main() {
+       int fd = open("/dev/null", 0);
+       struct mtd_info_user minfo;
+       struct erase_info_user einfo;
+       struct erase_info_user64 einfo64;
+       struct mtd_oob_buf mbuf;
+       struct mtd_oob_buf64 mbuf64;
+       struct region_info_user rinfo;
+       /* struct otp_info oinfo; */
+       struct mtd_ecc_stats estat;
+       struct mtd_write_req mreq;
+       struct nand_oobinfo ninfo;
+       struct nand_ecclayout_user nlay;
+       off_t f = 333;
+
+       memset(&einfo, 0, sizeof(einfo));
+       memset(&einfo64, 0xff, sizeof(einfo64));
+
+       ioctl(fd, MEMGETINFO, &minfo);
+
+       ioctl(fd, MEMERASE, &einfo);
+       ioctl(fd, MEMERASE64, &einfo64);
+
+       ioctl(fd, MEMGETBADBLOCK, &f);
+       int i = 0;
+       ioctl(fd, OTPSELECT, &i);
+       ioctl(fd, MEMSETBADBLOCK, &f);
+
+       ioctl(fd, MEMREADOOB, &mbuf);
+       ioctl(fd, MEMREADOOB64, &mbuf64);
+
+       ioctl(fd, MEMGETREGIONINFO, &rinfo);
+
+       ioctl(fd, ECCGETSTATS, &estat);
+       ioctl(fd, MEMWRITE, &mreq);
+
+       ioctl(fd, MEMGETOOBSEL, &ninfo);
+       ioctl(fd, ECCGETLAYOUT, &nlay);
+
+       return 0;
+}
diff --git a/test/ubi.c b/test/ubi.c
new file mode 100644 (file)
index 0000000..5062c83
--- /dev/null
@@ -0,0 +1,54 @@
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <mtd/ubi-user.h>
+
+#define zero(x) memset(&x, 0, sizeof(x))
+
+int main() {
+       int fd = open("/dev/null", 0);
+       struct ubi_mkvol_req mkvol = {
+               .vol_id = 3,
+               .alignment = 124,
+               .bytes = 1125899906842624ULL,
+               .vol_type = 3,
+               .name_len = 7,
+               .name = "foobar",
+       };
+       struct ubi_rsvol_req rsvol = {
+               .bytes = 1125899906842624ULL,
+               .vol_id = -3,
+       };
+       struct ubi_rnvol_req rnvol = {
+               .count = 300,
+       };
+       struct ubi_attach_req attach;
+       struct ubi_map_req map;
+       struct ubi_set_vol_prop_req prop = {
+               .property = 1,
+               .value = 1125899906842624ULL,
+       };
+       uint64_t bytes = ((uint64_t)1 << 50) | 0x123;
+
+       ioctl(fd, UBI_IOCMKVOL, &mkvol);
+       ioctl(fd, UBI_IOCRSVOL, &rsvol);
+       ioctl(fd, UBI_IOCRNVOL, &rnvol);
+       ioctl(fd, UBI_IOCATT, &attach);
+       ioctl(fd, UBI_IOCVOLUP, &bytes);
+       ioctl(fd, UBI_IOCEBMAP, &map);
+       ioctl(fd, UBI_IOCSETVOLPROP, &prop);
+       zero(prop);
+       ioctl(fd, UBI_IOCSETVOLPROP, &prop);
+       ioctl(fd, UBI_IOCRMVOL, 1);
+       ioctl(fd, UBI_IOCDET, 2);
+       ioctl(fd, UBI_IOCEBER, 3);
+       ioctl(fd, UBI_IOCEBCH, 4);
+       ioctl(fd, UBI_IOCEBUNMAP, 5);
+       ioctl(fd, UBI_IOCEBISMAP, 6);
+
+       return 0;
+}