Drop main() prototype. Syncs with NetBSD-8
[minix.git] / tests / fs / kernfs / t_basic.c
blobe5ba4a77e1b710b97596d6432484c1e1f03cff7f
1 /* $NetBSD: t_basic.c,v 1.3 2010/05/31 23:44:54 pooka Exp $ */
3 #include <sys/types.h>
4 #include <sys/mount.h>
5 #include <sys/module.h>
6 #include <sys/dirent.h>
7 #include <sys/sysctl.h>
9 #include <atf-c.h>
10 #include <err.h>
11 #include <errno.h>
12 #include <fcntl.h>
13 #include <stdio.h>
14 #include <unistd.h>
15 #include <string.h>
16 #include <stdlib.h>
18 #include <rump/rump.h>
19 #include <rump/rump_syscalls.h>
21 #include <miscfs/kernfs/kernfs.h>
23 #include "../../h_macros.h"
25 ATF_TC(getdents);
26 ATF_TC_HEAD(getdents, tc)
29 atf_tc_set_md_var(tc, "descr", "kernfs directory contains files");
32 static void
33 mountkernfs(void)
36 rump_init();
38 if (rump_sys_mkdir("/kern", 0777) == -1)
39 atf_tc_fail_errno("mkdir /kern");
40 if (rump_sys_mount(MOUNT_KERNFS, "/kern", 0, NULL, 0) == -1)
41 atf_tc_fail_errno("could not mount kernfs");
44 ATF_TC_BODY(getdents, tc)
46 struct dirent *dent;
47 char buf[8192];
48 int dfd;
50 mountkernfs();
52 if ((dfd = rump_sys_open("/kern", O_RDONLY)) == -1)
53 atf_tc_fail_errno("can't open directory");
54 if (rump_sys_getdents(dfd, buf, sizeof(buf)) == -1)
55 atf_tc_fail_errno("getdents");
58 * Check that we get the first three values (., .., boottime).
59 * Make more complete by autogenerating list from kernfs_vnops.c?
61 dent = (void *)buf;
62 ATF_REQUIRE_STREQ(dent->d_name, ".");
63 dent = _DIRENT_NEXT(dent);
64 ATF_REQUIRE_STREQ(dent->d_name, "..");
65 dent = _DIRENT_NEXT(dent);
66 ATF_REQUIRE_STREQ(dent->d_name, "boottime");
68 /* done */
71 ATF_TC(hostname);
72 ATF_TC_HEAD(hostname, tc)
75 atf_tc_set_md_var(tc, "descr", "/kern/hostname changes hostname");
78 static char *
79 getthehost(void)
81 static char buf[8192];
82 int mib[2];
83 size_t blen;
85 mib[0] = CTL_KERN;
86 mib[1] = KERN_HOSTNAME;
87 blen = sizeof(buf);
88 if (rump_sys___sysctl(mib, 2, buf, &blen, NULL, 0) == -1)
89 atf_tc_fail_errno("sysctl gethostname");
91 return buf;
94 #define NEWHOSTNAME "turboton roos-berg"
95 ATF_TC_BODY(hostname, tc)
97 char buf[8192];
98 char *shost, *p;
99 int fd;
101 mountkernfs();
102 if ((fd = rump_sys_open("/kern/hostname", O_RDWR)) == -1)
103 atf_tc_fail_errno("open hostname");
105 /* check initial match */
106 shost = getthehost();
107 buf[0] = '\0';
108 if (rump_sys_read(fd, buf, sizeof(buf)) == -1)
109 atf_tc_fail_errno("read hostname");
110 p = strchr(buf, '\n');
111 if (p)
112 *p = '\0';
113 ATF_REQUIRE_STREQ_MSG(buf, shost, "initial hostname mismatch");
115 /* check changing hostname works */
116 if (rump_sys_pwrite(fd, NEWHOSTNAME, strlen(NEWHOSTNAME), 0)
117 != strlen(NEWHOSTNAME)) {
118 atf_tc_fail_errno("write new hostname");
121 shost = getthehost();
122 ATF_REQUIRE_STREQ_MSG(NEWHOSTNAME, shost, "modified hostname mismatch");
124 /* done */
127 ATF_TP_ADD_TCS(tp)
129 ATF_TP_ADD_TC(tp, hostname);
130 ATF_TP_ADD_TC(tp, getdents);
132 return atf_no_error();