1 /* $NetBSD: t_modcmd.c,v 1.3 2009/11/06 15:25:52 pooka Exp $ */
4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
30 #include <sys/types.h>
31 #include <sys/mount.h>
33 #include <rump/rump.h>
34 #include <rump/rump_syscalls.h>
36 #include <fs/tmpfs/tmpfs_args.h>
48 #include "../../h_macros.h"
51 * We verify that modules can be loaded and unloaded.
52 * tmpfs was chosen because it does not depend on an image.
56 ATF_TC_HEAD(cmsg_modcmd
, tc
)
58 atf_tc_set_md_var(tc
, "descr", "Checks that loading and unloading "
59 "a module (vfs/tmpfs) is possible");
62 #define TMPFSMODULE "librumpfs_tmpfs.so"
63 ATF_TC_BODY(cmsg_modcmd
, tc
)
65 struct tmpfs_args args
;
71 memset(&args
, 0, sizeof(args
));
72 args
.ta_version
= TMPFS_ARGS_VERSION
;
73 args
.ta_root_mode
= 0777;
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");
80 handle
= dlopen(TMPFSMODULE
, RTLD_GLOBAL
);
82 const char *dlmsg
= dlerror();
83 atf_tc_fail("cannot open %s: %s", TMPFSMODULE
, dlmsg
);
85 mi
= dlsym(handle
, "__start_link_set_modules");
87 atf_tc_fail("cannot find module info");
88 if ((rv
= rump_pub_module_init(*mi
, NULL
)) != 0)
89 atf_tc_fail("module init failed: %d (%s)", rv
, strerror(rv
));
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_pub_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
);
102 if (rump_sys_mount(MOUNT_TMPFS
, "/mp", 0, &args
, sizeof(args
)) != -1)
103 atf_tc_fail("mount unexpectedly succeeded");
108 ATF_TP_ADD_TC(tp
, cmsg_modcmd
);
110 return atf_no_error();