t_modautoload.c revision 1.4
11.4Spgoyette/* $NetBSD: t_modautoload.c,v 1.4 2015/12/27 08:21:44 pgoyette 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.3Spgoyette new_len = sizeof(new_autoload); 501.3Spgoyette error = sysctlbyname("kern.module.autoload", 511.3Spgoyette &old_autoload, &old_len, 521.3Spgoyette &new_autoload, new_len); 531.3Spgoyette if (error != 0) 541.3Spgoyette atf_tc_fail_errno("could not enable module autoload"); 551.3Spgoyette 561.1Spooka if (rump_sys_mount(MOUNT_KERNFS, "/kern", 0, NULL, 0) == -1) 571.1Spooka atf_tc_fail_errno("could not mount kernfs"); 581.1Spooka} 591.1Spooka 601.1Spooka/* 611.1Spooka * Why use kernfs here? It talks to plenty of other parts with the 621.1Spooka * kernel (e.g. vfs_attach() in modcmd), but is still easy to verify 631.1Spooka * it's working correctly. 641.1Spooka */ 651.1Spooka 661.1Spooka#define MAGICNUM 1323 671.1SpookaATF_TC_BODY(modautoload, tc) 681.1Spooka{ 691.1Spooka extern int rumpns_hz; 701.1Spooka char buf[64]; 711.1Spooka int fd; 721.1Spooka 731.1Spooka mountkernfs(); 741.1Spooka rumpns_hz = MAGICNUM; 751.1Spooka if ((fd = rump_sys_open("/kern/hz", O_RDONLY)) == -1) 761.1Spooka atf_tc_fail_errno("open /kern/hz"); 771.1Spooka if (rump_sys_read(fd, buf, sizeof(buf)) <= 0) 781.1Spooka atf_tc_fail_errno("read"); 791.1Spooka ATF_REQUIRE(atoi(buf) == MAGICNUM); 801.1Spooka} 811.1Spooka 821.1SpookaATF_TP_ADD_TCS(tp) 831.1Spooka{ 841.1Spooka ATF_TP_ADD_TC(tp, modautoload); 851.1Spooka 861.1Spooka return atf_no_error(); 871.1Spooka} 88