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