12extern int delete_module(
const char*,
unsigned int);
14static int expect_error(
const char* name,
unsigned int flags,
int expected) {
16 int result = delete_module(name, flags);
17 if (result != -1 || errno != expected) {
18 fprintf(stderr,
"delete_module flags=%x returned %d errno=%d expected=%d\n", flags, result,
26 setvbuf(stdout, NULL, _IONBF, 0);
28 puts(
"MODULE-CONTRACT: BEGIN");
30 fputs(
"MODULE-CONTRACT: FAIL requires root\n", stderr);
34 memset(longName,
'x',
sizeof(longName));
35 longName[
sizeof(longName) - 1] = 0;
36 if (expect_error(NULL, 0, EFAULT) || expect_error(
"", 0, ENOENT) ||
37 expect_error(longName, 0, ENOENT) || expect_error(
"missing-module", 0, ENOENT) ||
38 expect_error(
"module-unload-fixture", 1, EINVAL) ||
39 expect_error(
"module-unload-fixture", O_TRUNC, EOPNOTSUPP) ||
40 expect_error(
"posix", O_NONBLOCK, EBUSY) || expect_error(
"linker", O_NONBLOCK, EBUSY) ||
41 expect_error(
"vfs", O_NONBLOCK, EWOULDBLOCK)) {
42 puts(
"MODULE-CONTRACT: FAIL input-and-policy");
45 puts(
"MODULE-CONTRACT: PASS input-and-policy");
51 _exit(expect_error(
"module-unload-fixture", O_NONBLOCK, EPERM));
54 if (child < 0 || waitpid(child, &status, 0) != child || !WIFEXITED(status) ||
55 WEXITSTATUS(status)) {
56 puts(
"MODULE-CONTRACT: FAIL credentials");
59 puts(
"MODULE-CONTRACT: PASS credentials");
62 if (delete_module(
"module-unload-fixture", O_NONBLOCK)) {
63 fprintf(stderr,
"MODULE-CONTRACT: FAIL unload errno=%d\n", errno);
66 puts(
"MODULE-CONTRACT: PASS unload");
67 if (expect_error(
"module-unload-fixture", 0, ENOENT)) {
68 puts(
"MODULE-CONTRACT: FAIL repeated-unload");
71 puts(
"MODULE-CONTRACT: PASS repeated-unload");
72 puts(
"MODULE-CONTRACT: END PASS");