diff options
author | ngie <ngie@FreeBSD.org> | 2014-12-31 20:13:31 +0000 |
---|---|---|
committer | ngie <ngie@FreeBSD.org> | 2014-12-31 20:13:31 +0000 |
commit | b429a2bfd1380c777b9d59e54e17886b3855073e (patch) | |
tree | f5eb9fb5c3b79a2f3a7cba500581d24f4676622d /contrib/netbsd-tests/modules | |
parent | 155ee9c2f7fcb97a502844e0ca346b9f919b8cb2 (diff) | |
download | FreeBSD-src-b429a2bfd1380c777b9d59e54e17886b3855073e.zip FreeBSD-src-b429a2bfd1380c777b9d59e54e17886b3855073e.tar.gz |
MFC r272343,r272458,r272890,r272891,r272901,r272902,r272903,r272905,r272908,r272909,r272910,r272914,r272915,r272979,r272980,r273010,r273011,r273012,r273015,r273017,r273019,r273020,r273021,r273022,r273023,r273024,r273025,r273389,r273390,r273391,r273393,r273395,r273396,r273397,r273410,r273516,r273517,r273520,r273521,r273522,r273523,r273524,r273525,r273526,r273527,r273528,r273529,r273530,r273533,r273534,r273535,r273536,r273537,r273538,r273539,r273540,r273572,r273574,r273578,r273579,r273591,r273592,r273928,r273933,r273935,r273936,r273937,r273938,r273942,r273943,r273945,r273946,r273947,r273948,r273949,r273950,r273951,r273952,r274061,r274062,r274066,r274067,r274072,r274074,r274079,r274090,r274142,r274143,r274571,r274572,r274573,r274574,r274575,r274576,r274577,r274579,r274597,r274598,r274599,r274600,r274601,r274626,r275033,r276046,r276430:
r272343:
r272458:
Import the NetBSD test suite from ^/vendor/NetBSD/tests/09.30.2014_20.45 ,
minus the vendor Makefiles
Provide directions for how to bootstrap the vendor sources in
FREEBSD-upgrade
MFC after 2 weeks
Discussed with: rpaulo
Sponsored by: EMC / Isilon Storage Division
r272890:
Only build/run hsearch_basic and hsearch_r_basic on NetBSD
hdestroy1 is not present on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r272891:
Expect SIGSEGV in lib/libc/stdlib/t_getenv:setenv_basic
See bin/189805 for more details
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r272901:
Disable tests that don't pass on FreeBSD due to missing support in
humanize_number(3). Bringing in additional revisions from NetBSD's
humanize_number(3) will fix the tests
Account for the fact that util.h on NetBSD is libutil.h on FreeBSD
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r272902:
Add missing #include <sys/time.h> for gettimeofday
Sponsored by: EMC / Isilon Storage Division
r272903:
FreeBSD returns ENOTTY instead of EBADF in ttyname_r; mark it as an expected
failure
PR: 191936
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r272905:
FreeBSD doesn't support strings greater than MAXHOSTNAMELEN-1 in
{get,set}{domain,host}name. Adjust the tests to not exceed that
value when testing out the code
Add a positive and negative test for MAXHOSTNAMELEN-1 and
MAXHOSTNAMELEN, respectively
PR: 181127
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r272908:
Disable the invalid pointer test on FreeBSD
FreeBSD segfaults on invalid pointers passed to getcwd because it throbs the
address passed in in libc, whereas NetBSD just passes the information off to
the syscall, which allows the kernel to return EFAULT on bad pointers.
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r272909:
Handle getting/setting niceness/priority correctly on FreeBSD vs NetBSD
This might be fallout from PR: 189821
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r272910:
SIGPWR does not exist on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r272914:
Skip over t_spawn_open_nonexistent_diag because it requires NetBSD specific
additions to posix_spawn
Sponsored by: EMC / Isilon Storage Division
r272915:
Port the testcase to FreeBSD
- Make #include path to h_macros.h a non-relative path
- __gl_stat_t is synonymous with struct stat on FreeBSD
- FreeBSD doesn't have _DIRENT_RECLEN
- Skip over glob_star on FreeBSD (testcase doesn't pass)
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r272979:
Only #include <sys/tls.h> on NetBSD
Sponsored by: EMC / Isilon Storage Division
r272980:
#include libutil.h for fparseln on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r273010:
Implement 64MB memory limit for test to ensure that it fails reliably in
600 seconds; it would previously fail inconsistently when run in some virtual
machine configurations
This patch might need to be reverted or revisited later (see the attached PR
for more details)
PR: 169302
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273011:
Fix compilation errors with missing wide-type headers and fix compilation
warnings with -Wformat
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273012:
- Add libutil #include for fparseln
- Change ATF_REQUIRE_EQ_MSG to ATF_CHECK_EQ_MSG to gather all failing results
possible (currently 12 with leftassoc)
- Mark leftassoc "atf_tc_expect_fail" on FreeBSD (PR coming soon after further
analysis is done on the code)
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273015:
Expect nice_err to fail on FreeBSD with unprivileged users
PR: 189821
Sponsored by: EMC / Isilon Storage Division
r273017:
Add #include <stdio.h> for printf
Sponsored by: EMC / Isilon Storage Division
r273019:
Do initial port of contrib/netbsd-tests/lib/libc/locale
t_io:
- Expect failures potentially related to implementation-specific knowledge of
the zh_TW.Big5 locale [*]
t_mbrtowc:
- Handle unknown locales more gracefully (do not test if the locale doesn't
exist)
- Expect failure with mbrtowc_internal dealing with Japanese locales
(potentially related to implementation detail knowledge of the ja_* locales) [*].
t_mbstowcs, t_mbtowc, t_wctomb:
- Handle unknown locales more gracefully (do not test if the locale doesn't
exist)
t_wcstod:
- Treat FreeBSD like NetBSD and Linux in the XXX: FIXME section
[*] More investigation is required to determine the root cause of the failures
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273020:
memmem with NUL length "needle" (aka small) strings on FreeBSD/OSX returns
NULL instead of the "haystack" value (aka big)
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273021:
Use 1 as a random seed, as recommended in srandom(3). Adjust the random values
accordingly
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273022:
Add #include <stdio.h> to get sys_nerr definition
Sponsored by: EMC / Isilon Storage Division
r273023:
__isnanl is automatically picked according to data type in <math.h>. There
isn't a need for the explicit __isnanl test
Sponsored by: EMC / Isilon Storage Division
r273024:
Only test the return value in mktime_negyear
Testing for the errno is an optional requirement according to POSIX, and
FreeBSD doesn't document that errno would be set on failure with mktime
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273025:
Change ATF_REQUIRE_MSG calls to ATF_CHECK_MSG to get as many errors as possible
t_strptime:common..
- Expect the testcase body as a whole to fail. Multiple PRs will be filed to
track the issues (there are 18 check failures)
t_strptime:day..
- %EA and %OA seem to be case insensitive on FreeBSD
r273389:
Port lib/libc/gen/t_siginfo to FreeBSD
- mcontext_t on FreeBSD doesn't have a __gregs field (it's split out on FreeBSD
into separate fields). In order to avoid muddying the test code with MD code,
the debugging trace info has not been implemented
- FreeBSD does not implement the si_stime and si_utime fields in siginfo_t, so
omit the debugging code that dumps the values
- sys/inttypes.h doesn't exist on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r273390:
libutil.h is required for fparseln on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r273391:
Add missing #include for sys/stat.h for fchmod
Sponsored by: EMC / Isilon Storage Division
r273393:
Port t_write to FreeBSD
- Mark the signo variable for the signal handle __unused
- Use limits.h instead of sys/syslimits.h (the latter does not
exist on FreeBSD)
Sponsored by: EMC / Isilon Storage Division
r273395:
Mark osi __unused so this compiles cleanly on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r273396:
unlink("/") fails with EISDIR instead of EBUSY on FreeBSD; test for that
instead
Sponsored by: EMC / Isilon Storage Division
r273397:
Port t_chroot to FreeBSD
- Add missing #include sys/stat.h for mkdir(2)
- Omit the fchroot(2) tests because the support is not present on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r273410:
Add sys/socket.h #include for bind(2), et al
Sponsored by: EMC / Isilon Storage Division
r273516:
Add netinet/in.h for struct sockaddr_in
Sponsored by: EMC / Isilon Storage Division
r273517:
Expect getgroups_err to fail on FreeBSD
PR: 189941
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273520:
Port t_pipe2.c to FreeBSD
- Omit the pipe2_nosigpipe testcase on FreeBSD (FreeBSD doesn't have
O_NOSIGPIPE).
- Convert "fcntl(n, F_CLOSEM)" to "closefrom(n)".
- Save and restore the resource limit on the number of files (RLIMIT_NOFILE).
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273521:
Convert "fcntl(n, F_CLOSEM)" to "closefrom(n)"
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273522:
- Mark unused parameters __unused in handler
- Call sigqueue with getpid() instead of 0 -- the latter idiom appears to only
be valid on NetBSD
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273523:
Add limits.h #include for LINE_MAX
Sponsored by: EMC / Isilon Storage Division
r273524:
Add sys/socket.h #include for struct sockaddr_in
Sponsored by: EMC / Isilon Storage Division
r273525:
Port t_mmap.c to FreeBSD
- Add needed headers for the testcases
- Omit mmap_block on non-NetBSD OSes
- Use "security.bsd.map_at_zero" instead of "vm.user_va0_disable"
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273526:
Omit the pollts testcases on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r273527:
Omit all of the testcases as revoke(2) is only implemented on devfs(5)
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273528:
Mark signo __unused in handler(..)
Sponsored by: EMC / Isilon Storage Division
r273529:
- Omit the poll testcases on FreeBSD (they require pollts)
- Add necessary headers for the testcases
Sponsored by: EMC / Isilon Storage Division
r273530:
Add limits.h #include for INT_MAX
Sponsored by: EMC / Isilon Storage Division
r273533:
Use <atf_srcdir>/truncate_test.root_owned instead of /usr/bin/fpr as fpr does
not exist on FreeBSD
truncate_test.root_owned will be generated at build time and owned by root
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273534:
- Mark sig/signo __unused
- Do not provide a relative path via #include "h_macros.h"
Sponsored by: EMC / Isilon Storage Division
r273535:
- Omit setrlimit_nthr testcase on FreeBSD (requires lwp.h, et al)
- Expect overflow with rlim_max at INT64_MAX, not UINT64_MAX (rlim_t is int64_t
on FreeBSD)
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273536:
Add limits.h #include for SSIZE_MAX
Sponsored by: EMC / Isilon Storage Division
r273537:
Add limits.h #include for SSIZE_MAX
Sponsored by: EMC / Isilon Storage Division
r273538:
Fix a typo (__FreeBSD__ -> __NetBSD__ when omitting setrlimit_nthr)
r273539:
Mark signum __unused
Sponsored by: EMC / Isilon Storage Division
r273540:
Omit the mprotect_exec testcase on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r273572:
- Ignore EINVAL check with mknod(path, S_IFCHR, -1) as the testcase is always
executed on a non-devfs filesystem
- Expect mknod(path, S_IFREG, 0) to fail on FreeBSD
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273574:
- Test for EINVAL requirement when passing an invalid flag in to msync(2)
- Expect ENOMEM instead of EFAULT when msync'ing a previously munmap'ed region
on FreeBSD
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273578:
- Add inttypes.h and stdint.h in lieu of int_limits.h from NetBSD
- Use #include "h_macros.h" instead of relative path analog
Sponsored by: EMC / Isilon Storage Division
r273579:
- Mark signo __unused in the signal handler function
- Effectively #if 0 out some code that does not fail on FreeBSD
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273591:
Correct my previous commit:
- getrusage_utime_back succeeds reliably on FreeBSD
- getrusage_utime_zero passes/fails in a seemingly non-deterministic manner.
Skip it for now (and fix it later)
In the initial port of this testcase to FreeBSD, the results failed reliably
in the same manner as it does on NetBSD
Sponsored by: EMC / Isilon Storage Division
r273592:
- Add sys/types.h for the APIs in sys/sysctl.h
- Poke at VM_MIN_ADDRESS in machine/vmparam.h because FreeBSD doesn't have a
vm.minaddress sysctl analog
- Expect ENOMEM instead of EAGAIN in mlock_limits
- Provide mlock an mmap'ed page twice to simulate MAP_WIRED on NetBSD
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273928:
Put mtree test files into a subdirectory.
Kyua 0.11 points TMPDIR to the test's work directory, and atf_check creates
auxiliary files in TMPDIR. This confuses a couple of mtree tests that were
using the work directory's root to validate the contents of the directory.
Fix the two affected tests by creating an auxiliary directory to use for
the mtree tests. (Kyua should probably do this on its own; filed bug #133
upstream to take a look at this.)
r273933:
Don't prune duplicate services in the expected output from /etc/services on
FreeBSD
Submitted by: pho
r273935:
Port tests to FreeBSD/Linux
Some of the testcases don't work outside of NetBSD, and the behavior of
ether_aton_r differs between FreeBSD, Linux, and NetBSD, and the calls to the
API need to be massaged for FreeBSD and Linux.
Submitted by: pho
r273936:
Port lib/libc/net/h_dns_server to FreeBSD
Submitted by: pho
r273937:
Port lib/libc/sys/t_dup to FreeBSD/Linux
- The requirements differ between FreeBSD/Linux when dealing with oldd/newd
being equal (both fail with EINVAL, not EBADF)
- Add an EBADF testcase
- Fix compilation issues on clang
In collaboration with: pho
r273938:
getitimer on FreeBSD returns the last set time instead of the remaining time;
test for that instead
Submitted by: pho
r273942:
Skip :sethostname_basic because it messes up the test host's hostname
Convert code from #if defined(__FreeBSD__) to #ifdef __FreeBSD__
r273943:
Port t_kevent to FreeBSD
Submitted by: pho
r273945:
Port t_mincore to FreeBSD
Mark :mincore_resid as atf_tc_expect_fail on FreeBSD because of new bug
discovered in running the tests (it succeeded from earlier on in the year to
September/October on FreeBSD, at least)
Submitted by: pho
r273946:
Port h_atexit to FreeBSD
__cxa_atexit varies between FreeBSD and NetBSD, and thus we must use pointers
instead of static fields in the BSS. More extensive discussion is included in
the source code
In collaboration with: kib
Submitted by: pho
r273947:
Expect :snprintf_posarg_error to blow up with a SIGSEGV on !NetBSD OSes
r273948:
Disable testcases 12 and 15-22 on FreeBSD
Submitted by: pho
r273949:
Add new atf_tc_expect_fail to fflush_err; this is a new (within the past couple months) bug
r273950:
Skip :fopen_regular on !NetBSD because it's a NetBSD specific test
Submitted by: pho
r273951:
Expect :sscanf_whitespace to fail on !NetBSD OSes
Submitted by: pho
r273952:
Port h_hash and t_sha2 to FreeBSD
t_sha2 contains dirty copy-paste hacks that need to be fixed with the openssh
OpenBSD compat layer
Submitted by: pho
r274061:
Port t_db.sh to FreeBSD
- The blocksize on FreeBSD is 32kB, not 64kB
- Add some detection for MK_DICT == no; /nonexistent is echoed along with
atf_skip to ensure that the test will fail if dict(..) is called in the
non-final stage of the pipeline
Submitted by: pho
r274062:
inet_network on FreeBSD returns NULL when provided "0x" to inet_network
Submitted by: pho
r274066:
Port lib/libc/ssp to FreeBSD
In most cases, the buffers and data were resized, but when dealing with the
helpers, some of the code was adjusted to fail more reliably
Submitted by: pho
r274067:
rpc_control on FreeBSD is a public-ish API (not prefixed with __), not private
like NetBSD
Submitted by: pho
r274072:
Finish off lib/libc/stdlib/t_strtod.c port by checking for "y" twice on
FreeBSD, and always assume long long double exists on FreeBSD
Submitted by: pho
r274074:
Add Makefile snippet to ease porting NetBSD testcases to FreeBSD from
contrib/netbsd-tests
This Makefile snippet handles polluting testcases with -lnetbsd, specific
headers for ATF version differences, and does necessary rewriting for the
testcases to match the format discussed on the TestSuite wiki page
(t_<foo> -> <foo>_test)
One must define SRCTOP (inspired by projects/bmake), OBJTOP, and TESTSRC
(e.g. contrib/netbsd-tests/lib/libc/gen) to use the Makefile snippet
Test programs are specific either via NETBSD_ATF_TESTS_C or NETBSD_ATF_TESTS_SH
C++ analogs aren't currently implemented.
The imported testcases will be cleaned up to use this Makefile snippet pseudo
"API".
r274079:
Import proper fix for misc/49356 (/usr/include/atf-c/config.h) after atf-c/config.h
was removed from the build
Pointyhat to: me (again, for not running make delete-old after running test builds)
r274090:
Fix the Jenkins test run by skipping the negative testcases earlier
The problem is that lib.libc.locale.t_io:bad_big5_wprintf was printing out
illegal Unicode characters, which causes XML parsers to bail immediately, e.g.
% kyua report-junit > ~/report.junit
% python2 -c 'import xml.dom.minidom as md; md.parse("/home/ngie/report.junit")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/xml/dom/minidom.py", line 1918, in parse
return expatbuilder.parse(file)
File "/usr/local/lib/python2.7/xml/dom/expatbuilder.py", line 924, in parse
result = builder.parseFile(fp)
File "/usr/local/lib/python2.7/xml/dom/expatbuilder.py", line 207, in parseFile
parser.Parse(buffer, 0)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 27137, column 13
r274142:
Remove expected failure from lib.libc.sys.t_mincore:mincore_resid
The failure was added based on observation seen on 11.0-CURRENT @ r273153, not
based on internal testing at EMC/Isilon
PR: 194829
Tested with the following configuration:
- amd64/i386
- 11.0-CURRENT @ r273153
- 100 times in a tight loop as root with the following commands...
-- kyua test lib/libc
-- kyua test lib/libc/sys
-- kyua test lib/libc/sys/mincore_test
r274143:
Expect lib.libc.sys.getcontext_test.setcontext_link to fail on amd64; add
additional debugging to make the underlying problem more visible
Calling setcontext(2) on amd64 as shown in the test program is failing on
amd64, not i386, with a return code of -1 and an errno of EINVAL
Further investigation is being done in the PR to determine the root cause for
the failure
PR: 194828
Tested with the following configuration:
- amd64/i386
- 11.0-CURRENT @ r273153
- 100 times in a tight loop as root with the following commands...
-- kyua test lib/libc
-- kyua test lib/libc/sys
-- kyua test lib/libc/sys/getcontext_test
r274571:
Use _exit instead of exit so the file descriptors aren't flushed twice in the
child processes
Submitted by: pho
r274572:
Only expect timeouts on powerpc with NetBSD
Submitted by: pho
r274573:
Expect :pthread_detach to fail with EINVAL instead of ESRCH on FreeBSD
PR: 191906
In collaboration with: pho
r274574:
Add pthread_np.h #include and initialize the pthread attribute on FreeBSD
Submitted by: pho
r274575:
#ifdef out a printf on !NetBSD that causes the testcase to fail when comparing
the output from the helper program
Submitted by: pho
r274576:
Port helper program to FreeBSD, similar to ../../lib/libc/stdlib/h_atexit.c
Submitted by: pho
In collaboration with: kib
r274577:
Add missing sys/time.h #include for timespecsub macro in lib/libnetbsd/sys/time.h
r274579:
Call sem_unlink on semaphores before attempting to create them
Due to the lack of uniqueness in the semaphore name, and the fact that the
tests don't have cleanup routines, an interrupted test can leave a semaphore
"laying around", causing all subsequent attempts to run the test to fail
I will file a NetBSD PR for this issue soon
r274597:
Skip the long-double epsilon checks on FreeBSD/i386
Sponsored by: EMC / Isilon Storage Division
r274598:
Reset errno to 0 before running scalbn to be sure that the tested errno is
valid
Sponsored by: EMC / Isilon Storage Division
r274599:
Alias isinff to isinf on FreeBSD
isinf on FreeBSD automatically picks the appropriate type per math.h
Sponsored by: EMC / Isilon Storage Division
r274600:
- Expect exp2_powers to fail on FreeBSD/i386
- Expect exp2_values to fail on FreeBSD due to the small epsilon
Sponsored by: EMC / Isilon Storage Division
r274601:
- Skip over the testcases that call cbrtl on platforms where LDBL_PREC == 53
(arm, mips, powerpc). This fixes the build on these platforms, based on some
ad hoc tinderbox runs I did a while ago
- Skip cast the arguments to powl as long double so powl properly interprets
those arugments at compile-time when picking the type
Sponsored by: EMC / Isilon Storage Division
r274626:
Mechanically replace #if defined(__FreeBSD__) and #if defined(__NetBSD__) with
their #ifdef equivalents for everything changed in contrib/netbsd-tests. There
are some items from the vendor tree that use #if defined(__FreeBSD__) or
#if defined(__NetBSD__) which are being left alone
Requested by: bde, rpaulo
Sponsored by: EMC / Isilon Storage Division
r275033:
Only pass 6 arguments to the 'run' function on amd64. amd64's
makecontext on FreeBSD only supports a maximum of 6 arguments. This
fixes the setcontext_link test on amd64.
PR: 194828
r276046:
Add __FreeBSD_version guards around hsearch_r to ease MFCing the code to
stable/10
It was added when __FreeBSD_version was ~1100027
r276430:
Expect access_test:access_inval to fail before __FreeBSD_version == 1100033
This will allow me to MFC the test, as jilles@ requested that I don't MFC the
access(2) KBI change to 10-STABLE in r271655
Diffstat (limited to 'contrib/netbsd-tests/modules')
-rw-r--r-- | contrib/netbsd-tests/modules/k_helper/k_helper.c | 202 | ||||
-rw-r--r-- | contrib/netbsd-tests/modules/k_helper2/k_helper2.c | 115 | ||||
-rw-r--r-- | contrib/netbsd-tests/modules/k_helper3/k_helper3.c | 102 | ||||
-rw-r--r-- | contrib/netbsd-tests/modules/k_uvm/k_uvm.c | 113 | ||||
-rwxr-xr-x | contrib/netbsd-tests/modules/t_abi_uvm.sh | 70 | ||||
-rw-r--r-- | contrib/netbsd-tests/modules/t_builtin.c | 194 | ||||
-rw-r--r-- | contrib/netbsd-tests/modules/t_modctl.c | 493 | ||||
-rwxr-xr-x | contrib/netbsd-tests/modules/t_modload.sh | 205 |
8 files changed, 1494 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/modules/k_helper/k_helper.c b/contrib/netbsd-tests/modules/k_helper/k_helper.c new file mode 100644 index 0000000..6a54ccd --- /dev/null +++ b/contrib/netbsd-tests/modules/k_helper/k_helper.c @@ -0,0 +1,202 @@ +/* $NetBSD: k_helper.c,v 1.6 2012/06/03 10:59:44 dsl Exp $ */ +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: k_helper.c,v 1.6 2012/06/03 10:59:44 dsl Exp $"); + +#include <sys/param.h> +#include <sys/kernel.h> +#include <sys/module.h> +#include <sys/sysctl.h> + +#include <prop/proplib.h> + +MODULE(MODULE_CLASS_MISC, k_helper, NULL); + +/* --------------------------------------------------------------------- */ +/* Sysctl interface to query information about the module. */ +/* --------------------------------------------------------------------- */ + +/* TODO: Change the integer variables below that represent booleans to + * bools, once sysctl(8) supports CTLTYPE_BOOL nodes. */ + +static struct sysctllog *clogp; +static int present = 1; +static int prop_str_ok; +static char prop_str_val[128]; +static int prop_int_ok; +static int64_t prop_int_val; +static int prop_int_load; + +#define K_HELPER 0x12345678 +#define K_HELPER_PRESENT 0 +#define K_HELPER_PROP_STR_OK 1 +#define K_HELPER_PROP_STR_VAL 2 +#define K_HELPER_PROP_INT_OK 3 +#define K_HELPER_PROP_INT_VAL 4 +#define K_HELPER_PROP_INT_LOAD 5 + +SYSCTL_SETUP(sysctl_k_helper_setup, "sysctl k_helper subtree setup") +{ + + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, "k_helper", NULL, + NULL, 0, NULL, 0, + CTL_VENDOR, K_HELPER, CTL_EOL); + + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_INT, "present", + SYSCTL_DESCR("Whether the module was loaded or not"), + NULL, 0, &present, 0, + CTL_VENDOR, K_HELPER, K_HELPER_PRESENT, CTL_EOL); + + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_INT, "prop_str_ok", + SYSCTL_DESCR("String property's validity"), + NULL, 0, &prop_str_ok, 0, + CTL_VENDOR, K_HELPER, K_HELPER_PROP_STR_OK, CTL_EOL); + + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_STRING, "prop_str_val", + SYSCTL_DESCR("String property's value"), + NULL, 0, prop_str_val, 0, + CTL_VENDOR, K_HELPER, K_HELPER_PROP_STR_VAL, CTL_EOL); + + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_INT, "prop_int_ok", + SYSCTL_DESCR("String property's validity"), + NULL, 0, &prop_int_ok, 0, + CTL_VENDOR, K_HELPER, K_HELPER_PROP_INT_OK, CTL_EOL); + + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_QUAD, "prop_int_val", + SYSCTL_DESCR("String property's value"), + NULL, 0, &prop_int_val, 0, + CTL_VENDOR, K_HELPER, K_HELPER_PROP_INT_VAL, CTL_EOL); + + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_INT, "prop_int_load", + SYSCTL_DESCR("Status of recursive modload"), + NULL, 0, &prop_int_load, 0, + CTL_VENDOR, K_HELPER, K_HELPER_PROP_INT_LOAD, CTL_EOL); +} + +/* --------------------------------------------------------------------- */ +/* Module management. */ +/* --------------------------------------------------------------------- */ + +static +int +k_helper_init(prop_dictionary_t props) +{ + prop_object_t p; + + p = prop_dictionary_get(props, "prop_str"); + if (p == NULL) + prop_str_ok = 0; + else if (prop_object_type(p) != PROP_TYPE_STRING) + prop_str_ok = 0; + else { + const char *msg = prop_string_cstring_nocopy(p); + if (msg == NULL) + prop_str_ok = 0; + else { + strlcpy(prop_str_val, msg, sizeof(prop_str_val)); + prop_str_ok = 1; + } + } + if (!prop_str_ok) + strlcpy(prop_str_val, "", sizeof(prop_str_val)); + + p = prop_dictionary_get(props, "prop_int"); + if (p == NULL) + prop_int_ok = 0; + else if (prop_object_type(p) != PROP_TYPE_NUMBER) + prop_int_ok = 0; + else { + prop_int_val = prop_number_integer_value(p); + prop_int_ok = 1; + } + if (!prop_int_ok) + prop_int_val = -1; + + p = prop_dictionary_get(props, "prop_recurse"); + if (p != NULL && prop_object_type(p) == PROP_TYPE_STRING) { + const char *recurse_name = prop_string_cstring_nocopy(p); + if (recurse_name != NULL) + prop_int_load = module_load(recurse_name, + MODCTL_NO_PROP, NULL, MODULE_CLASS_ANY); + else + prop_int_load = -1; + } else + prop_int_load = -2; + + sysctl_k_helper_setup(&clogp); + + return 0; +} + +static +int +k_helper_fini(void *arg) +{ + + sysctl_teardown(&clogp); + + return 0; +} + +static +int +k_helper_modcmd(modcmd_t cmd, void *arg) +{ + int ret; + + switch (cmd) { + case MODULE_CMD_INIT: + ret = k_helper_init(arg); + break; + + case MODULE_CMD_FINI: + ret = k_helper_fini(arg); + break; + + case MODULE_CMD_STAT: + default: + ret = ENOTTY; + } + + return ret; +} diff --git a/contrib/netbsd-tests/modules/k_helper2/k_helper2.c b/contrib/netbsd-tests/modules/k_helper2/k_helper2.c new file mode 100644 index 0000000..286b25a --- /dev/null +++ b/contrib/netbsd-tests/modules/k_helper2/k_helper2.c @@ -0,0 +1,115 @@ +/* $NetBSD: k_helper2.c,v 1.2 2010/11/03 16:10:23 christos Exp $ */ +/* + * Copyright (c) 2010 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: k_helper2.c,v 1.2 2010/11/03 16:10:23 christos Exp $"); + +#include <sys/param.h> +#include <sys/kernel.h> +#include <sys/module.h> +#include <sys/sysctl.h> + +#include <prop/proplib.h> + +MODULE(MODULE_CLASS_MISC, k_helper2, NULL); + +/* --------------------------------------------------------------------- */ +/* Sysctl interface to query information about the module. */ +/* --------------------------------------------------------------------- */ + +/* TODO: Change the integer variables below that represent booleans to + * bools, once sysctl(8) supports CTLTYPE_BOOL nodes. */ + +static struct sysctllog *clogp; +static int present = 1; + +#define K_HELPER2 0x23456781 +#define K_HELPER_PRESENT 0 + +SYSCTL_SETUP(sysctl_k_helper2_setup, "sysctl k_helper subtree setup") +{ + + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, "k_helper2", NULL, + NULL, 0, NULL, 0, + CTL_VENDOR, K_HELPER2, CTL_EOL); + + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_INT, "present", + SYSCTL_DESCR("Whether the module was loaded or not"), + NULL, 0, &present, 0, + CTL_VENDOR, K_HELPER2, K_HELPER_PRESENT, CTL_EOL); +} + +/* --------------------------------------------------------------------- */ +/* Module management. */ +/* --------------------------------------------------------------------- */ + +static +int +k_helper2_init(prop_dictionary_t props) +{ + sysctl_k_helper2_setup(&clogp); + + return 0; +} + +static +int +k_helper2_fini(void *arg) +{ + + sysctl_teardown(&clogp); + + return 0; +} + +static +int +k_helper2_modcmd(modcmd_t cmd, void *arg) +{ + int ret; + + switch (cmd) { + case MODULE_CMD_INIT: + ret = k_helper2_init(arg); + break; + + case MODULE_CMD_FINI: + ret = k_helper2_fini(arg); + break; + + case MODULE_CMD_STAT: + default: + ret = ENOTTY; + } + + return ret; +} diff --git a/contrib/netbsd-tests/modules/k_helper3/k_helper3.c b/contrib/netbsd-tests/modules/k_helper3/k_helper3.c new file mode 100644 index 0000000..4e0984d --- /dev/null +++ b/contrib/netbsd-tests/modules/k_helper3/k_helper3.c @@ -0,0 +1,102 @@ +/* $NetBSD: k_helper3.c,v 1.3 2012/04/17 21:39:19 martin Exp $ */ + +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jukka Ruohonen. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include <sys/cdefs.h> +__RCSID("$NetBSD: k_helper3.c,v 1.3 2012/04/17 21:39:19 martin Exp $"); + +#include <sys/module.h> + +#include <assert.h> +#include <errno.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <prop/proplib.h> + +static int load(const char *, ...); + +/* + * A program that loads a module and returns the errno(2) from modctl(8). + */ +int +main(int argc, char *argv[]) +{ + assert(argc == 3); + + return load(argv[1], argv[2]); +} + +static __printflike(1, 2) int +load(const char *fmt, ...) +{ + char filename[MAXPATHLEN], *propsstr, *shortname, *dot; + prop_dictionary_t props; + modctl_load_t ml; + int serrno, rv; + va_list ap; + + props = prop_dictionary_create(); + propsstr = prop_dictionary_externalize(props); + assert(propsstr != NULL); + prop_object_release(props); + + va_start(ap, fmt); + (void)vsnprintf(filename, sizeof(filename), fmt, ap); + va_end(ap); + + ml.ml_filename = filename; + ml.ml_flags = 0; + ml.ml_props = propsstr; + ml.ml_propslen = strlen(propsstr); + + printf("Loading module %s\n", filename); + errno = serrno = 0; + + rv = modctl(MODCTL_LOAD, &ml); + + if (rv != 0) + serrno = errno; + + shortname = strrchr(filename, '/'); + if (shortname != NULL) + shortname++; + else + shortname = filename; + dot = strrchr(shortname, '.'); + if (dot) + *dot = 0; + (void)modctl(MODCTL_UNLOAD, shortname); + + free(propsstr); + + return serrno; +} diff --git a/contrib/netbsd-tests/modules/k_uvm/k_uvm.c b/contrib/netbsd-tests/modules/k_uvm/k_uvm.c new file mode 100644 index 0000000..7f8d3b0 --- /dev/null +++ b/contrib/netbsd-tests/modules/k_uvm/k_uvm.c @@ -0,0 +1,113 @@ +/* $NetBSD: k_uvm.c,v 1.1 2012/02/17 22:36:50 jmmv Exp $ */ +/* + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: k_uvm.c,v 1.1 2012/02/17 22:36:50 jmmv Exp $"); + +#include <sys/param.h> +#include <sys/kernel.h> +#include <sys/module.h> +#include <sys/sysctl.h> + +MODULE(MODULE_CLASS_MISC, k_uvm, NULL); + +/* --------------------------------------------------------------------- */ +/* Sysctl interface to query information about the module. */ +/* --------------------------------------------------------------------- */ + +static struct sysctllog *clogp; +static int page_size; + +#define K_UVM 0x12345678 +#define K_UVM_VALUE 0 + +SYSCTL_SETUP(sysctl_k_uvm_setup, "sysctl k_uvm subtree setup") +{ + + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, "k_uvm", NULL, + NULL, 0, NULL, 0, + CTL_VENDOR, K_UVM, CTL_EOL); + + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_INT, "page_size", + SYSCTL_DESCR("Value of PAGE_SIZE"), + NULL, 0, &page_size, 0, + CTL_VENDOR, K_UVM, K_UVM_VALUE, CTL_EOL); +} + +/* --------------------------------------------------------------------- */ +/* Module management. */ +/* --------------------------------------------------------------------- */ + +static +int +k_uvm_init(prop_dictionary_t props) +{ + + page_size = PAGE_SIZE; + + sysctl_k_uvm_setup(&clogp); + + return 0; +} + +static +int +k_uvm_fini(void *arg) +{ + + sysctl_teardown(&clogp); + + return 0; +} + +static +int +k_uvm_modcmd(modcmd_t cmd, void *arg) +{ + int ret; + + switch (cmd) { + case MODULE_CMD_INIT: + ret = k_uvm_init(arg); + break; + + case MODULE_CMD_FINI: + ret = k_uvm_fini(arg); + break; + + case MODULE_CMD_STAT: + default: + ret = ENOTTY; + } + + return ret; +} diff --git a/contrib/netbsd-tests/modules/t_abi_uvm.sh b/contrib/netbsd-tests/modules/t_abi_uvm.sh new file mode 100755 index 0000000..b855bc8 --- /dev/null +++ b/contrib/netbsd-tests/modules/t_abi_uvm.sh @@ -0,0 +1,70 @@ +# $NetBSD: t_abi_uvm.sh,v 1.3 2012/04/20 05:41:25 jruoho Exp $ +# +# Copyright (c) 2012 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +atf_test_case PAGE_SIZE cleanup +PAGE_SIZE_head() { + atf_set "descr" "Ensures that modules have access to PAGE_SIZE" + atf_set "require.user" "root" +} +PAGE_SIZE_body() { + + # XXX: Adjust when modctl(8) fails consistently. + # + $(atf_get_srcdir)/k_helper3 \ + "%s/k_helper/k_helper.kmod" $(atf_get_srcdir) + + if [ $? -eq 1 ] || [ $? -eq 78 ]; then + atf_skip "host does not support modules" + fi + + if modload $(atf_get_srcdir)/k_uvm/k_uvm.kmod; then + : + else + case "$(uname -m)" in + macppc) + atf_expect_fail "PR port-macppc/46041" + ;; + esac + atf_fail "Failed to load k_uvm; missing uvmexp_pagesize?" + fi + + kernel_pagesize="$(sysctl -n hw.pagesize || echo fail1)" + module_pagesize="$(sysctl -n vendor.k_uvm.page_size || echo fail2)" + echo "Kernel PAGE_SIZE: ${kernel_pagesize}" + echo "Module PAGE_SIZE: ${module_pagesize}" + atf_check_equal "${kernel_pagesize}" "${module_pagesize}" + + atf_check -s eq:0 -o empty -e empty modunload k_uvm +} +PAGE_SIZE_cleanup() { + modunload k_uvm >/dev/null 2>&1 || true +} + +atf_init_test_cases() +{ + atf_add_test_case PAGE_SIZE +} diff --git a/contrib/netbsd-tests/modules/t_builtin.c b/contrib/netbsd-tests/modules/t_builtin.c new file mode 100644 index 0000000..0d9a3f0 --- /dev/null +++ b/contrib/netbsd-tests/modules/t_builtin.c @@ -0,0 +1,194 @@ +/* $NetBSD: t_builtin.c,v 1.2 2010/11/03 16:10:23 christos Exp $ */ + +/*- + * Copyright (c) 2010 The NetBSD Foundation, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <sys/module.h> +#include <sys/mount.h> + +#include <atf-c.h> +#include <fcntl.h> +#include <stdbool.h> + +#include <miscfs/kernfs/kernfs.h> + +#include <rump/rump.h> +#include <rump/rump_syscalls.h> + +#include "../h_macros.h" + +#define MYMP "/mnt" +#define HZFILE MYMP "/hz" + +static char kernfs[] = "kernfs"; + +static bool +check_kernfs(void) +{ + char buf[16]; + bool rv = true; + int fd; + + fd = rump_sys_open(HZFILE, O_RDONLY); + if (fd == -1) + return false; + if (rump_sys_read(fd, buf, sizeof(buf)) < 1) + rv = false; + RL(rump_sys_close(fd)); + + return rv; +} + +ATF_TC(disable); +ATF_TC_HEAD(disable, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Tests that builtin modules can " + "be disabled"); +} + +ATF_TC_BODY(disable, tc) +{ + + rump_init(); + RL(rump_sys_mkdir(MYMP, 0777)); + RL(rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0)); + ATF_REQUIRE(check_kernfs()); + RL(rump_sys_unmount(MYMP, 0)); + RL(rump_sys_modctl(MODCTL_UNLOAD, kernfs)); +} + +ATF_TC(noauto); +ATF_TC_HEAD(noauto, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests that disabled builtin modules " + "will not autoload"); +} + +ATF_TC_BODY(noauto, tc) +{ + + rump_init(); + RL(rump_sys_mkdir(MYMP, 0777)); + + RL(rump_sys_modctl(MODCTL_UNLOAD, kernfs)); + + ATF_REQUIRE_ERRNO(ENODEV, + rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0) == -1); +} + +ATF_TC(forcereload); +ATF_TC_HEAD(forcereload, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests that disabled builtin modules " + "can be force-reloaded"); +} + +ATF_TC_BODY(forcereload, tc) +{ + struct modctl_load mod; + + rump_init(); + RL(rump_sys_mkdir(MYMP, 0777)); + + RL(rump_sys_modctl(MODCTL_UNLOAD, kernfs)); + ATF_REQUIRE_ERRNO(ENODEV, + rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0) == -1); + + memset(&mod, 0, sizeof(mod)); + mod.ml_filename = kernfs; + mod.ml_flags = MODCTL_LOAD_FORCE; + + RL(rump_sys_modctl(MODCTL_LOAD, &mod)); + + RL(rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0)); + ATF_REQUIRE(check_kernfs()); + RL(rump_sys_unmount(MYMP, 0)); +} + +ATF_TC(disabledstat); +ATF_TC_HEAD(disabledstat, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests that disabled builtin modules " + "show up in modstat with refcount -1"); +} + +ATF_TC_BODY(disabledstat, tc) +{ + struct modstat ms[128]; + struct iovec iov; + size_t i; + bool found = false; + + rump_init(); + RL(rump_sys_mkdir(MYMP, 0777)); + + RL(rump_sys_modctl(MODCTL_UNLOAD, kernfs)); + + iov.iov_base = ms; + iov.iov_len = sizeof(ms); + RL(rump_sys_modctl(MODCTL_STAT, &iov)); + + for (i = 0; i < __arraycount(ms); i++) { + if (strcmp(ms[i].ms_name, kernfs) == 0) { + ATF_REQUIRE_EQ(ms[i].ms_refcnt, (u_int)-1); + found = 1; + break; + } + } + ATF_REQUIRE(found); +} + +ATF_TC(busydisable); +ATF_TC_HEAD(busydisable, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests that busy builtin modules " + "cannot be disabled"); +} + +ATF_TC_BODY(busydisable, tc) +{ + + rump_init(); + RL(rump_sys_mkdir(MYMP, 0777)); + RL(rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0)); + ATF_REQUIRE(check_kernfs()); + ATF_REQUIRE_ERRNO(EBUSY, + rump_sys_modctl(MODCTL_UNLOAD, kernfs) == -1); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, disable); + ATF_TP_ADD_TC(tp, noauto); + ATF_TP_ADD_TC(tp, forcereload); + ATF_TP_ADD_TC(tp, disabledstat); + ATF_TP_ADD_TC(tp, busydisable); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/modules/t_modctl.c b/contrib/netbsd-tests/modules/t_modctl.c new file mode 100644 index 0000000..50cd907 --- /dev/null +++ b/contrib/netbsd-tests/modules/t_modctl.c @@ -0,0 +1,493 @@ +/* $NetBSD: t_modctl.c,v 1.12 2012/08/20 08:07:52 martin Exp $ */ +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.12 2012/08/20 08:07:52 martin Exp $"); + +#include <sys/module.h> +#include <sys/sysctl.h> + +#include <assert.h> +#include <errno.h> +#include <stdarg.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <prop/proplib.h> + +#include <atf-c.h> + +enum presence_check { both_checks, stat_check, sysctl_check }; + +static void check_permission(void); +static bool get_modstat_info(const char *, modstat_t *); +static bool get_sysctl(const char *, void *buf, const size_t); +static bool k_helper_is_present_stat(void); +static bool k_helper_is_present_sysctl(void); +static bool k_helper_is_present(enum presence_check); +static int load(prop_dictionary_t, bool, const char *, ...); +static int unload(const char *, bool); +static void unload_cleanup(const char *); + +/* --------------------------------------------------------------------- */ +/* Auxiliary functions */ +/* --------------------------------------------------------------------- */ + +/* + * A function checking wether we are allowed to load modules currently + * (either the kernel is not modular, or securelevel may prevent it) + */ +static void +check_permission(void) +{ + int err; + + err = modctl(MODCTL_EXISTS, 0); + if (err == 0) return; + if (errno == ENOSYS) + atf_tc_skip("Kernel does not have 'options MODULAR'."); + else if (errno == EPERM) + atf_tc_skip("Module loading administratively forbidden"); + ATF_REQUIRE_EQ_MSG(errno, 0, "unexpected error %d from " + "modctl(MODCTL_EXISTS, 0)", errno); +} + +static bool +get_modstat_info(const char *name, modstat_t *msdest) +{ + bool found; + size_t len; + struct iovec iov; + modstat_t *ms; + + check_permission(); + for (len = 4096; ;) { + iov.iov_base = malloc(len); + iov.iov_len = len; + + errno = 0; + + if (modctl(MODCTL_STAT, &iov) != 0) { + int err = errno; + fprintf(stderr, "modctl(MODCTL_STAT) failed: %s\n", + strerror(err)); + atf_tc_fail("Failed to query module status"); + } + if (len >= iov.iov_len) + break; + free(iov.iov_base); + len = iov.iov_len; + } + + found = false; + len = iov.iov_len / sizeof(modstat_t); + for (ms = (modstat_t *)iov.iov_base; len != 0 && !found; + ms++, len--) { + if (strcmp(ms->ms_name, name) == 0) { + if (msdest != NULL) + *msdest = *ms; + found = true; + } + } + + free(iov.iov_base); + + return found; +} + +/* + * Queries a sysctl property. + */ +static bool +get_sysctl(const char *name, void *buf, const size_t len) +{ + size_t len2 = len; + printf("Querying sysctl variable: %s\n", name); + int ret = sysctlbyname(name, buf, &len2, NULL, 0); + if (ret == -1 && errno != ENOENT) { + fprintf(stderr, "sysctlbyname(2) failed: %s\n", + strerror(errno)); + atf_tc_fail("Failed to query %s", name); + } + return ret != -1; +} + +/* + * Returns a boolean indicating if the k_helper module was loaded + * successfully. This implementation uses modctl(2)'s MODCTL_STAT + * subcommand to do the check. + */ +static bool +k_helper_is_present_stat(void) +{ + + return get_modstat_info("k_helper", NULL); +} + +/* + * Returns a boolean indicating if the k_helper module was loaded + * successfully. This implementation uses the module's sysctl + * installed node to do the check. + */ +static bool +k_helper_is_present_sysctl(void) +{ + size_t present; + + return get_sysctl("vendor.k_helper.present", &present, + sizeof(present)); +} + +/* + * Returns a boolean indicating if the k_helper module was loaded + * successfully. The 'how' parameter specifies the implementation to + * use to do the check. + */ +static bool +k_helper_is_present(enum presence_check how) +{ + bool found; + + switch (how) { + case both_checks: + found = k_helper_is_present_stat(); + ATF_CHECK(k_helper_is_present_sysctl() == found); + break; + + case stat_check: + found = k_helper_is_present_stat(); + break; + + case sysctl_check: + found = k_helper_is_present_sysctl(); + break; + + default: + found = false; + assert(found); + } + + return found; +} + +/* + * Loads the specified module from a file. If fatal is set and an error + * occurs when loading the module, an error message is printed and the + * test case is aborted. + */ +static __printflike(3, 4) int +load(prop_dictionary_t props, bool fatal, const char *fmt, ...) +{ + int err; + va_list ap; + char filename[MAXPATHLEN], *propsstr; + modctl_load_t ml; + + check_permission(); + if (props == NULL) { + props = prop_dictionary_create(); + propsstr = prop_dictionary_externalize(props); + ATF_CHECK(propsstr != NULL); + prop_object_release(props); + } else { + propsstr = prop_dictionary_externalize(props); + ATF_CHECK(propsstr != NULL); + } + + va_start(ap, fmt); + vsnprintf(filename, sizeof(filename), fmt, ap); + va_end(ap); + + ml.ml_filename = filename; + ml.ml_flags = 0; + ml.ml_props = propsstr; + ml.ml_propslen = strlen(propsstr); + + printf("Loading module %s\n", filename); + errno = err = 0; + + if (modctl(MODCTL_LOAD, &ml) == -1) { + err = errno; + fprintf(stderr, "modctl(MODCTL_LOAD, %s), failed: %s\n", + filename, strerror(err)); + if (fatal) + atf_tc_fail("Module load failed"); + } + + free(propsstr); + + return err; +} + +/* + * Unloads the specified module. If silent is true, nothing will be + * printed and no errors will be raised if the unload was unsuccessful. + */ +static int +unload(const char *name, bool fatal) +{ + int err; + + check_permission(); + printf("Unloading module %s\n", name); + errno = err = 0; + + if (modctl(MODCTL_UNLOAD, __UNCONST(name)) == -1) { + err = errno; + fprintf(stderr, "modctl(MODCTL_UNLOAD, %s) failed: %s\n", + name, strerror(err)); + if (fatal) + atf_tc_fail("Module unload failed"); + } + return err; +} + +/* + * A silent version of unload, to be called as part of the cleanup + * process only. + */ +static void +unload_cleanup(const char *name) +{ + + (void)modctl(MODCTL_UNLOAD, __UNCONST(name)); +} + +/* --------------------------------------------------------------------- */ +/* Test cases */ +/* --------------------------------------------------------------------- */ + +ATF_TC_WITH_CLEANUP(cmd_load); +ATF_TC_HEAD(cmd_load, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command"); + atf_tc_set_md_var(tc, "require.user", "root"); +} +ATF_TC_BODY(cmd_load, tc) +{ + char longname[MAXPATHLEN]; + size_t i; + + ATF_CHECK(load(NULL, false, " ") == ENOENT); + ATF_CHECK(load(NULL, false, "non-existent.o") == ENOENT); + + for (i = 0; i < MAXPATHLEN - 1; i++) + longname[i] = 'a'; + longname[MAXPATHLEN - 1] = '\0'; + ATF_CHECK(load(NULL, false, "%s", longname) == ENAMETOOLONG); + + ATF_CHECK(!k_helper_is_present(stat_check)); + load(NULL, true, "%s/k_helper/k_helper.kmod", + atf_tc_get_config_var(tc, "srcdir")); + printf("Checking if load was successful\n"); + ATF_CHECK(k_helper_is_present(stat_check)); +} +ATF_TC_CLEANUP(cmd_load, tc) +{ + unload_cleanup("k_helper"); +} + +ATF_TC_WITH_CLEANUP(cmd_load_props); +ATF_TC_HEAD(cmd_load_props, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command, " + "providing extra load-time properties"); + atf_tc_set_md_var(tc, "require.user", "root"); +} +ATF_TC_BODY(cmd_load_props, tc) +{ + prop_dictionary_t props; + + printf("Loading module without properties\n"); + props = prop_dictionary_create(); + load(props, true, "%s/k_helper/k_helper.kmod", + atf_tc_get_config_var(tc, "srcdir")); + prop_object_release(props); + { + int ok; + ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok", + &ok, sizeof(ok))); + ATF_CHECK(!ok); + } + unload("k_helper", true); + + printf("Loading module with a string property\n"); + props = prop_dictionary_create(); + prop_dictionary_set(props, "prop_str", + prop_string_create_cstring("1st string")); + load(props, true, "%s/k_helper/k_helper.kmod", + atf_tc_get_config_var(tc, "srcdir")); + prop_object_release(props); + { + int ok; + ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok", + &ok, sizeof(ok))); + ATF_CHECK(ok); + + char val[128]; + ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_val", + &val, sizeof(val))); + ATF_CHECK(strcmp(val, "1st string") == 0); + } + unload("k_helper", true); + + printf("Loading module with a different string property\n"); + props = prop_dictionary_create(); + prop_dictionary_set(props, "prop_str", + prop_string_create_cstring("2nd string")); + load(props, true, "%s/k_helper/k_helper.kmod", + atf_tc_get_config_var(tc, "srcdir")); + prop_object_release(props); + { + int ok; + ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok", + &ok, sizeof(ok))); + ATF_CHECK(ok); + + char val[128]; + ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_val", + &val, sizeof(val))); + ATF_CHECK(strcmp(val, "2nd string") == 0); + } + unload("k_helper", true); +} +ATF_TC_CLEANUP(cmd_load_props, tc) +{ + unload_cleanup("k_helper"); +} + +ATF_TC_WITH_CLEANUP(cmd_load_recurse); +ATF_TC_HEAD(cmd_load_recurse, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command, " + "with recursive module_load()"); + atf_tc_set_md_var(tc, "require.user", "root"); +} +ATF_TC_BODY(cmd_load_recurse, tc) +{ + prop_dictionary_t props; + char filename[MAXPATHLEN]; + + printf("Loading module with request to load another module\n"); + props = prop_dictionary_create(); + snprintf(filename, sizeof(filename), "%s/k_helper2/k_helper2.kmod", + atf_tc_get_config_var(tc, "srcdir")); + prop_dictionary_set(props, "prop_recurse", + prop_string_create_cstring(filename)); + load(props, true, "%s/k_helper/k_helper.kmod", + atf_tc_get_config_var(tc, "srcdir")); + { + int ok; + ATF_CHECK(get_sysctl("vendor.k_helper.prop_int_load", + &ok, sizeof(ok))); + ATF_CHECK(ok == 0); + ATF_CHECK(get_sysctl("vendor.k_helper2.present", + &ok, sizeof(ok))); + ATF_CHECK(ok); + } + unload("k_helper", true); + unload("k_helper2", true); +} +ATF_TC_CLEANUP(cmd_load_recurse, tc) +{ + unload_cleanup("k_helper"); + unload_cleanup("k_helper2"); +} + +ATF_TC_WITH_CLEANUP(cmd_stat); +ATF_TC_HEAD(cmd_stat, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_STAT command"); + atf_tc_set_md_var(tc, "require.user", "root"); +} +ATF_TC_BODY(cmd_stat, tc) +{ + ATF_CHECK(!k_helper_is_present(both_checks)); + + load(NULL, true, "%s/k_helper/k_helper.kmod", + atf_tc_get_config_var(tc, "srcdir")); + ATF_CHECK(k_helper_is_present(both_checks)); + { + modstat_t ms; + ATF_CHECK(get_modstat_info("k_helper", &ms)); + + ATF_CHECK(ms.ms_class == MODULE_CLASS_MISC); + ATF_CHECK(ms.ms_source == MODULE_SOURCE_FILESYS); + ATF_CHECK(ms.ms_refcnt == 0); + } + unload("k_helper", true); + + ATF_CHECK(!k_helper_is_present(both_checks)); +} +ATF_TC_CLEANUP(cmd_stat, tc) +{ + unload_cleanup("k_helper"); +} + +ATF_TC_WITH_CLEANUP(cmd_unload); +ATF_TC_HEAD(cmd_unload, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_UNLOAD command"); + atf_tc_set_md_var(tc, "require.user", "root"); +} +ATF_TC_BODY(cmd_unload, tc) +{ + load(NULL, true, "%s/k_helper/k_helper.kmod", + atf_tc_get_config_var(tc, "srcdir")); + + ATF_CHECK(unload("", false) == ENOENT); + ATF_CHECK(unload("non-existent.kmod", false) == ENOENT); + ATF_CHECK(unload("k_helper.kmod", false) == ENOENT); + + ATF_CHECK(k_helper_is_present(stat_check)); + unload("k_helper", true); + printf("Checking if unload was successful\n"); + ATF_CHECK(!k_helper_is_present(stat_check)); +} +ATF_TC_CLEANUP(cmd_unload, tc) +{ + unload_cleanup("k_helper"); +} + +/* --------------------------------------------------------------------- */ +/* Main */ +/* --------------------------------------------------------------------- */ + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, cmd_load); + ATF_TP_ADD_TC(tp, cmd_load_props); + ATF_TP_ADD_TC(tp, cmd_stat); + ATF_TP_ADD_TC(tp, cmd_load_recurse); + ATF_TP_ADD_TC(tp, cmd_unload); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/modules/t_modload.sh b/contrib/netbsd-tests/modules/t_modload.sh new file mode 100755 index 0000000..561bb6f --- /dev/null +++ b/contrib/netbsd-tests/modules/t_modload.sh @@ -0,0 +1,205 @@ +# $NetBSD: t_modload.sh,v 1.13 2012/04/20 05:41:25 jruoho Exp $ +# +# Copyright (c) 2008 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +check_sysctl() { + echo "${1} = ${2}" >expout + atf_check -s eq:0 -o file:expout -e empty sysctl ${1} +} + +atf_test_case plain cleanup +plain_head() { + atf_set "descr" "Test load without arguments" + atf_set "require.user" "root" +} +plain_body() { + + # XXX: Adjust when modctl(8) fails consistently. + # + $(atf_get_srcdir)/k_helper3 \ + "%s/k_helper/k_helper.kmod" $(atf_get_srcdir) + + if [ $? -eq 1 ] || [ $? -eq 78 ]; then + atf_skip "host does not support modules" + fi + + cat >experr <<EOF +modload: No such file or directory +EOF + atf_check -s eq:1 -o empty -e ignore modload non-existent.o + + atf_check -s eq:0 -o empty -e empty \ + modload $(atf_get_srcdir)/k_helper/k_helper.kmod + check_sysctl vendor.k_helper.present 1 + check_sysctl vendor.k_helper.prop_int_ok 0 + check_sysctl vendor.k_helper.prop_str_ok 0 + atf_check -s eq:0 -o empty -e empty modunload k_helper + touch done +} +plain_cleanup() { + test -f done || modunload k_helper >/dev/null 2>&1 +} + +atf_test_case bflag cleanup +bflag_head() { + atf_set "descr" "Test the -b flag" + atf_set "require.user" "root" +} +bflag_body() { + echo "Checking error conditions" + + atf_check -s eq:1 -o empty -e save:stderr \ + modload -b foo k_helper.kmod + atf_check -s eq:0 -o ignore -e empty \ + grep 'Invalid parameter.*foo' stderr + + atf_check -s eq:1 -o empty -e save:stderr \ + modload -b foo= k_helper.kmod + atf_check -s eq:0 -o ignore -e empty \ + grep 'Invalid boolean value' stderr + + atf_check -s eq:1 -o empty -e save:stderr \ + modload -b foo=bar k_helper.kmod + atf_check -s eq:0 -o ignore -e empty \ + grep 'Invalid boolean value.*bar' stderr + + atf_check -s eq:1 -o empty -e save:stderr \ + modload -b foo=falsea k_helper.kmod + atf_check -s eq:0 -o ignore -e empty \ + grep 'Invalid boolean value.*falsea' stderr + + atf_check -s eq:1 -o empty -e save:stderr \ + modload -b foo=truea k_helper.kmod + atf_check -s eq:0 -o ignore -e empty \ + grep 'Invalid boolean value.*truea' stderr + + # TODO Once sysctl(8) supports CTLTYPE_BOOL nodes. + #echo "Checking valid values" +} +bflag_cleanup() { + modunload k_helper >/dev/null 2>&1 || true +} + +atf_test_case iflag cleanup +iflag_head() { + atf_set "descr" "Test the -i flag" + atf_set "require.user" "root" +} +iflag_body() { + + # XXX: Adjust when modctl(8) fails consistently. + # + $(atf_get_srcdir)/k_helper3 \ + "%s/k_helper/k_helper.kmod" $(atf_get_srcdir) + + if [ $? -eq 1 ] || [ $? -eq 78 ]; then + atf_skip "host does not support modules" + fi + + echo "Checking error conditions" + + atf_check -s eq:1 -o empty -e save:stderr modload -i foo \ + k_helper/k_helper.kmod + atf_check -s eq:0 -o ignore -e empty \ + grep 'Invalid parameter.*foo' stderr + + atf_check -s eq:1 -o empty -e save:stderr modload -i foo= \ + k_helper/k_helper.kmod + atf_check -s eq:0 -o ignore -e empty \ + grep 'Invalid integer value' stderr + + atf_check -s eq:1 -o empty -e save:stderr \ + modload -i foo=bar k_helper/k_helper.kmod + atf_check -s eq:0 -o ignore -e empty \ + grep 'Invalid integer value.*bar' stderr + + atf_check -s eq:1 -o empty -e save:stderr \ + modload -i foo=123a k_helper/k_helper.kmod + atf_check -s eq:0 -o ignore -e empty \ + grep 'Invalid integer value.*123a' stderr + + echo "Checking valid values" + + for v in 5 10; do + atf_check -s eq:0 -o empty -e empty \ + modload -i prop_int="${v}" \ + $(atf_get_srcdir)/k_helper/k_helper.kmod + check_sysctl vendor.k_helper.prop_int_ok 1 + check_sysctl vendor.k_helper.prop_int_val "${v}" + atf_check -s eq:0 -o empty -e empty modunload k_helper + done + touch done +} +iflag_cleanup() { + test -f done || modunload k_helper >/dev/null 2>&1 +} + +atf_test_case sflag cleanup +sflag_head() { + atf_set "descr" "Test the -s flag" + atf_set "require.user" "root" +} +sflag_body() { + + # XXX: Adjust when modctl(8) fails consistently. + # + $(atf_get_srcdir)/k_helper3 \ + "%s/k_helper/k_helper.kmod" $(atf_get_srcdir) + + if [ $? -eq 1 ] || [ $? -eq 78 ]; then + atf_skip "host does not support modules" + fi + + echo "Checking error conditions" + + atf_check -s eq:1 -o empty -e save:stderr modload -s foo \ + k_helper/k_helper.kmod + atf_check -s eq:0 -o ignore -e empty \ + grep 'Invalid parameter.*foo' stderr + + echo "Checking valid values" + + for v in '1st string' '2nd string'; do + atf_check -s eq:0 -o empty -e empty \ + modload -s prop_str="${v}" \ + $(atf_get_srcdir)/k_helper/k_helper.kmod + check_sysctl vendor.k_helper.prop_str_ok 1 + check_sysctl vendor.k_helper.prop_str_val "${v}" + atf_check -s eq:0 -o empty -e empty modunload k_helper + done + touch done +} +sflag_cleanup() { + test -f done || modunload k_helper >/dev/null 2>&1 +} + +atf_init_test_cases() +{ + atf_add_test_case plain + atf_add_test_case bflag + atf_add_test_case iflag + atf_add_test_case sflag +} |