Home | History | Annotate | Line # | Download | only in rumpkern
t_modcmd.c revision 1.2.2.2
      1 /*	$NetBSD: t_modcmd.c,v 1.2.2.2 2009/05/13 19:19:34 jym Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2009 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
     17  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     18  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
     21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     23  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
     25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #include <sys/types.h>
     31 #include <sys/mount.h>
     32 
     33 #include <rump/rump.h>
     34 #include <rump/rump_syscalls.h>
     35 
     36 #include <fs/tmpfs/tmpfs_args.h>
     37 
     38 #include <atf-c.h>
     39 #include <dlfcn.h>
     40 #include <err.h>
     41 #include <errno.h>
     42 #include <stdio.h>
     43 #include <stdlib.h>
     44 #include <string.h>
     45 #include <unistd.h>
     46 #include <util.h>
     47 
     48 #include "../../h_macros.h"
     49 
     50 /*
     51  * We verify that modules can be loaded and unloaded.
     52  * tmpfs was chosen because it does not depend on an image.
     53  */
     54 
     55 ATF_TC(cmsg_modcmd);
     56 ATF_TC_HEAD(cmsg_modcmd, tc)
     57 {
     58 	atf_tc_set_md_var(tc, "descr", "Checks that loading and unloading "
     59 	    "a module (vfs/tmpfs) is possible");
     60 }
     61 
     62 #define TMPFSMODULE "librumpfs_tmpfs.so"
     63 ATF_TC_BODY(cmsg_modcmd, tc)
     64 {
     65 	struct tmpfs_args args;
     66 	struct modinfo **mi;
     67 	void *handle;
     68 	int rv;
     69 
     70 	rump_init();
     71 	memset(&args, 0, sizeof(args));
     72 	args.ta_version = TMPFS_ARGS_VERSION;
     73 	args.ta_root_mode = 0777;
     74 
     75 	if (rump_sys_mkdir("/mp", 0777) == -1)
     76 		atf_tc_fail_errno("mkdir mountpoint");
     77 	if (rump_sys_mount(MOUNT_TMPFS, "/mp", 0, &args, sizeof(args)) != -1)
     78 		atf_tc_fail("mount unexpectedly succeeded");
     79 
     80 	handle = dlopen(TMPFSMODULE, RTLD_GLOBAL);
     81 	if (handle == NULL) {
     82 		const char *dlmsg = dlerror();
     83 		atf_tc_fail("cannot open %s: %s", TMPFSMODULE, dlmsg);
     84 	}
     85 	mi = dlsym(handle, "__start_link_set_modules");
     86 	if (mi == NULL)
     87 		atf_tc_fail("cannot find module info");
     88 	if ((rv = rump_module_init(*mi, NULL)) != 0)
     89 		atf_tc_fail("module init failed: %d (%s)", rv, strerror(rv));
     90 
     91 	if (rump_sys_mount(MOUNT_TMPFS, "/mp", 0, &args, sizeof(args)) == -1)
     92 		atf_tc_fail_errno("still cannot mount");
     93 	if (rump_sys_unmount("/mp", 0) == -1)
     94 		atf_tc_fail("cannot unmount");
     95 	if ((rv = rump_module_fini(*mi)) != 0)
     96 		atf_tc_fail("module fini failed: %d (%s)", rv, strerror(rv));
     97 	if (dlclose(handle)) {
     98 		const char *dlmsg = dlerror();
     99 		atf_tc_fail("cannot close %s: %s", TMPFSMODULE, dlmsg);
    100 	}
    101 
    102 	if (rump_sys_mount(MOUNT_TMPFS, "/mp", 0, &args, sizeof(args)) != -1)
    103 		atf_tc_fail("mount unexpectedly succeeded");
    104 }
    105 
    106 ATF_TP_ADD_TCS(tp)
    107 {
    108 	ATF_TP_ADD_TC(tp, cmsg_modcmd);
    109 }
    110