t_modautoload.c revision 1.5
11.5Sozaki/* $NetBSD: t_modautoload.c,v 1.5 2016/09/14 03:19:11 ozaki-r Exp $ */ 21.1Spooka 31.1Spooka#include <sys/types.h> 41.1Spooka#include <sys/mount.h> 51.1Spooka#include <sys/module.h> 61.1Spooka#include <sys/dirent.h> 71.1Spooka#include <sys/sysctl.h> 81.1Spooka 91.1Spooka#include <atf-c.h> 101.1Spooka#include <err.h> 111.1Spooka#include <errno.h> 121.1Spooka#include <fcntl.h> 131.1Spooka#include <stdio.h> 141.1Spooka#include <unistd.h> 151.1Spooka#include <string.h> 161.1Spooka#include <stdlib.h> 171.1Spooka 181.1Spooka#include <rump/rump.h> 191.1Spooka#include <rump/rump_syscalls.h> 201.1Spooka 211.1Spooka#include <miscfs/kernfs/kernfs.h> 221.1Spooka 231.1Spooka#include "../../h_macros.h" 241.1Spooka 251.1SpookaATF_TC(modautoload); 261.1SpookaATF_TC_HEAD(modautoload, tc) 271.1Spooka{ 281.1Spooka 291.1Spooka atf_tc_set_md_var(tc, "descr", "tests that kernel module " 301.1Spooka "autoload works in rump"); 311.1Spooka} 321.1Spooka 331.1Spookastatic void 341.1Spookamountkernfs(void) 351.1Spooka{ 361.3Spgoyette bool old_autoload, new_autoload; 371.3Spgoyette size_t old_len, new_len; 381.3Spgoyette int error; 391.1Spooka 401.2Spooka if (!rump_nativeabi_p()) 411.2Spooka atf_tc_skip("host kernel modules not supported"); 421.1Spooka 431.1Spooka rump_init(); 441.1Spooka 451.1Spooka if (rump_sys_mkdir("/kern", 0777) == -1) 461.1Spooka atf_tc_fail_errno("mkdir /kern"); 471.3Spgoyette 481.4Spgoyette new_autoload = true; 491.5Sozaki old_len = sizeof(old_autoload); 501.3Spgoyette new_len = sizeof(new_autoload); 511.3Spgoyette error = sysctlbyname("kern.module.autoload", 521.3Spgoyette &old_autoload, &old_len, 531.3Spgoyette &new_autoload, new_len); 541.3Spgoyette if (error != 0) 551.3Spgoyette atf_tc_fail_errno("could not enable module autoload"); 561.3Spgoyette 571.1Spooka if (rump_sys_mount(MOUNT_KERNFS, "/kern", 0, NULL, 0) == -1) 581.1Spooka atf_tc_fail_errno("could not mount kernfs"); 591.1Spooka} 601.1Spooka 611.1Spooka/* 621.1Spooka * Why use kernfs here? It talks to plenty of other parts with the 631.1Spooka * kernel (e.g. vfs_attach() in modcmd), but is still easy to verify 641.1Spooka * it's working correctly. 651.1Spooka */ 661.1Spooka 671.1Spooka#define MAGICNUM 1323 681.1SpookaATF_TC_BODY(modautoload, tc) 691.1Spooka{ 701.1Spooka extern int rumpns_hz; 711.1Spooka char buf[64]; 721.1Spooka int fd; 731.1Spooka 741.1Spooka mountkernfs(); 751.1Spooka rumpns_hz = MAGICNUM; 761.1Spooka if ((fd = rump_sys_open("/kern/hz", O_RDONLY)) == -1) 771.1Spooka atf_tc_fail_errno("open /kern/hz"); 781.1Spooka if (rump_sys_read(fd, buf, sizeof(buf)) <= 0) 791.1Spooka atf_tc_fail_errno("read"); 801.1Spooka ATF_REQUIRE(atoi(buf) == MAGICNUM); 811.1Spooka} 821.1Spooka 831.1SpookaATF_TP_ADD_TCS(tp) 841.1Spooka{ 851.1Spooka ATF_TP_ADD_TC(tp, modautoload); 861.1Spooka 871.1Spooka return atf_no_error(); 881.1Spooka} 89