1 /* $NetBSD: t_basic.c,v 1.4 2017/01/13 21:30:40 christos Exp $ */
5 #include <sys/module.h>
6 #include <sys/dirent.h>
7 #include <sys/sysctl.h>
18 #include <rump/rump.h>
19 #include <rump/rump_syscalls.h>
21 #include <miscfs/kernfs/kernfs.h>
26 ATF_TC_HEAD(getdents, tc)
29 atf_tc_set_md_var(tc, "descr", "kernfs directory contains files");
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)
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?
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");
72 ATF_TC_HEAD(hostname, tc)
75 atf_tc_set_md_var(tc, "descr", "/kern/hostname changes hostname");
81 static char buf[8192];
86 mib[1] = KERN_HOSTNAME;
88 if (rump_sys___sysctl(mib, 2, buf, &blen, NULL, 0) == -1)
89 atf_tc_fail_errno("sysctl gethostname");
94 #define NEWHOSTNAME "turboton roos-berg"
95 ATF_TC_BODY(hostname, tc)
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();
108 if (rump_sys_read(fd, buf, sizeof(buf)) == -1)
109 atf_tc_fail_errno("read hostname");
110 p = strchr(buf, '\n');
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");
129 ATF_TP_ADD_TC(tp, hostname);
130 ATF_TP_ADD_TC(tp, getdents);
132 return atf_no_error();