From c1fec43b553ea93460b58995a1229e84d8bb45b4 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 23 Apr 2008 11:32:31 -0700 Subject: Extend the mmfs basic test to do a couple of ioctls. --- shared-core/mmfs.h | 2 ++ tests/mmfs_basic.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/shared-core/mmfs.h b/shared-core/mmfs.h index 4cad3bdc..bc7e991f 100644 --- a/shared-core/mmfs.h +++ b/shared-core/mmfs.h @@ -25,6 +25,8 @@ * */ +#include + /** @file mmfs.h * This file provides ioctl and ioctl argument definitions for using the * mmfs device. diff --git a/tests/mmfs_basic.c b/tests/mmfs_basic.c index 907dc585..b0ae8905 100644 --- a/tests/mmfs_basic.c +++ b/tests/mmfs_basic.c @@ -27,9 +27,11 @@ #include #include +#include #include #include #include +#include #include #include "mmfs.h" @@ -51,6 +53,65 @@ create_mmfs_device() errx(1, "mknod()"); } +static void +test_bad_unref(int fd) +{ + struct mmfs_unreference_args unref; + int ret; + + printf("Testing error return on bad unreference ioctl.\n"); + + unref.handle = 0x10101010; + ret = ioctl(fd, MMFS_IOCTL_UNREFERENCE, &unref); + + assert(ret == -1 && errno == EINVAL); +} + +static void +test_bad_ioctl(int fd) +{ + int ret; + + printf("Testing error return on bad ioctl.\n"); + + ret = ioctl(fd, _IO(MMFS_IOCTL_BASE, 0xf0), 0); + + assert(ret == -1 && errno == EINVAL); +} + +static void +test_alloc_unref(int fd) +{ + struct mmfs_alloc_args alloc; + struct mmfs_unreference_args unref; + int ret; + + printf("Testing allocating and unreferencing an object.\n"); + + memset(&alloc, 0, sizeof(alloc)); + alloc.size = 16 * 1024; + ret = ioctl(fd, MMFS_IOCTL_ALLOC, &alloc); + assert(ret == 0); + + unref.handle = alloc.handle; + ret = ioctl(fd, MMFS_IOCTL_UNREFERENCE, &unref); +} + +static void +test_alloc_close(int fd) +{ + struct mmfs_alloc_args alloc; + int ret; + + printf("Testing closing with an object allocated.\n"); + + memset(&alloc, 0, sizeof(alloc)); + alloc.size = 16 * 1024; + ret = ioctl(fd, MMFS_IOCTL_ALLOC, &alloc); + assert(ret == 0); + + close(fd); +} int main(int argc, char **argv) { @@ -62,6 +123,11 @@ int main(int argc, char **argv) if (fd == -1) errx(1, "open()"); + test_bad_ioctl(fd); + test_bad_unref(fd); + test_alloc_unref(fd); + test_alloc_close(fd); + close(fd); return 0; -- cgit v1.2.3