Blame testsuite/test-modprobe.c

Packit Service 68b988
/*
Packit Service 68b988
 * Copyright (C) 2012-2013  ProFUSION embedded systems
Packit Service 68b988
 *
Packit Service 68b988
 * This program is free software; you can redistribute it and/or
Packit Service 68b988
 * modify it under the terms of the GNU Lesser General Public
Packit Service 68b988
 * License as published by the Free Software Foundation; either
Packit Service 68b988
 * version 2.1 of the License, or (at your option) any later version.
Packit Service 68b988
 *
Packit Service 68b988
 * This program is distributed in the hope that it will be useful,
Packit Service 68b988
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 68b988
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 68b988
 * Lesser General Public License for more details.
Packit Service 68b988
 *
Packit Service 68b988
 * You should have received a copy of the GNU Lesser General Public
Packit Service 68b988
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit Service 68b988
 */
Packit Service 68b988
Packit Service 68b988
#include <errno.h>
Packit Service 68b988
#include <inttypes.h>
Packit Service 68b988
#include <stddef.h>
Packit Service 68b988
#include <stdio.h>
Packit Service 68b988
#include <stdlib.h>
Packit Service 68b988
#include <string.h>
Packit Service 68b988
#include <unistd.h>
Packit Service 68b988
Packit Service 68b988
#include "testsuite.h"
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_show_depends(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"--show-depends", "mod-loop-a",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_show_depends,
Packit Service 68b988
	.description = "check if output for modprobe --show-depends is correct for loaded modules",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "4.4.4",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/show-depends",
Packit Service 68b988
	},
Packit Service 68b988
	.output = {
Packit Service 68b988
		.out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct.txt",
Packit Service 68b988
	});
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_show_depends2(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"--show-depends", "mod-simple",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_show_depends2,
Packit Service 68b988
	.description = "check if output for modprobe --show-depends is correct",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "4.4.4",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/show-depends",
Packit Service 68b988
	},
Packit Service 68b988
	.output = {
Packit Service 68b988
		.out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct-mod-simple.txt",
Packit Service 68b988
	});
Packit Service 68b988
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_show_alias_to_none(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"--show-depends", "--ignore-install", "--quiet", "mod-simple",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_show_alias_to_none,
Packit Service 68b988
	.description = "check if modprobe --show-depends doesn't explode with an alias to nothing",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "4.4.4",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/alias-to-none",
Packit Service 68b988
	},
Packit Service 68b988
	.output = {
Packit Service 68b988
		.out = TESTSUITE_ROOTFS "test-modprobe/alias-to-none/correct.txt",
Packit Service 68b988
	},
Packit Service 68b988
	.modules_loaded = "",
Packit Service 68b988
	);
Packit Service 68b988
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_builtin(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"unix",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_builtin,
Packit Service 68b988
	.description = "check if modprobe return 0 for builtin",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "4.4.4",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin",
Packit Service 68b988
	});
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_builtin_lookup_only(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"-R", "unix",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_builtin_lookup_only,
Packit Service 68b988
	.description = "check if modprobe -R correctly returns the builtin module",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "4.4.4",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin",
Packit Service 68b988
	},
Packit Service 68b988
	.output = {
Packit Service 68b988
		.out = TESTSUITE_ROOTFS "test-modprobe/builtin/correct.txt",
Packit Service 68b988
	});
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_softdep_loop(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"mod-loop-b",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_softdep_loop,
Packit Service 68b988
	.description = "check if modprobe breaks softdep loop",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "4.4.4",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/softdep-loop",
Packit Service 68b988
		[TC_INIT_MODULE_RETCODES] = "",
Packit Service 68b988
	},
Packit Service 68b988
	.modules_loaded = "mod-loop-a,mod-loop-b",
Packit Service 68b988
	);
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_install_cmd_loop(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"mod-loop-a",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_install_cmd_loop,
Packit Service 68b988
	.description = "check if modprobe breaks install-commands loop",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "4.4.4",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/install-cmd-loop",
Packit Service 68b988
		[TC_INIT_MODULE_RETCODES] = "",
Packit Service 68b988
	},
Packit Service 68b988
	.env_vars = (const struct keyval[]) {
Packit Service 68b988
		{ "MODPROBE", ABS_TOP_BUILDDIR "/tools/modprobe" },
Packit Service 68b988
		{ }
Packit Service 68b988
		},
Packit Service 68b988
	.modules_loaded = "mod-loop-b,mod-loop-a",
Packit Service 68b988
	);
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_param_kcmdline(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"--show-depends", "mod-simple",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_param_kcmdline,
Packit Service 68b988
	.description = "check if params from kcmdline are passed to (f)init_module call",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "4.4.4",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline",
Packit Service 68b988
	},
Packit Service 68b988
	.output = {
Packit Service 68b988
		.out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline/correct.txt",
Packit Service 68b988
	},
Packit Service 68b988
	.modules_loaded = "",
Packit Service 68b988
	);
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_param_kcmdline2(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"-c",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_param_kcmdline2,
Packit Service 68b988
	.description = "check if params with no value are parsed correctly from kcmdline",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "4.4.4",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline2",
Packit Service 68b988
	},
Packit Service 68b988
	.output = {
Packit Service 68b988
		.out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline2/correct.txt",
Packit Service 68b988
	},
Packit Service 68b988
	.modules_loaded = "",
Packit Service 68b988
	);
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_param_kcmdline3(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"-c",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_param_kcmdline3,
Packit Service 68b988
	.description = "check if unrelated strings in kcmdline are correctly ignored",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "4.4.4",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline3",
Packit Service 68b988
	},
Packit Service 68b988
	.output = {
Packit Service 68b988
		.out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline3/correct.txt",
Packit Service 68b988
	},
Packit Service 68b988
	.modules_loaded = "",
Packit Service 68b988
	);
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_param_kcmdline4(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"-c",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_param_kcmdline4,
Packit Service 68b988
	.description = "check if unrelated strings in kcmdline are correctly ignored",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "4.4.4",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline4",
Packit Service 68b988
	},
Packit Service 68b988
	.output = {
Packit Service 68b988
		.out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline4/correct.txt",
Packit Service 68b988
	},
Packit Service 68b988
	.modules_loaded = "",
Packit Service 68b988
	);
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_param_kcmdline5(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"-c",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_param_kcmdline5,
Packit Service 68b988
	.description = "check if params with spaces are parsed correctly from kcmdline",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "4.4.4",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline5",
Packit Service 68b988
	},
Packit Service 68b988
	.output = {
Packit Service 68b988
		.out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline5/correct.txt",
Packit Service 68b988
	},
Packit Service 68b988
	.modules_loaded = "",
Packit Service 68b988
	);
Packit Service 68b988
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_force(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"--force", "mod-simple",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_force,
Packit Service 68b988
	.description = "check modprobe --force",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "4.4.4",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/force",
Packit Service 68b988
		[TC_INIT_MODULE_RETCODES] = "",
Packit Service 68b988
	},
Packit Service 68b988
	.modules_loaded = "mod-simple",
Packit Service 68b988
	);
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_oldkernel(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"mod-simple",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_oldkernel,
Packit Service 68b988
	.description = "check modprobe with kernel without finit_module()",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "3.3.3",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel",
Packit Service 68b988
		[TC_INIT_MODULE_RETCODES] = "",
Packit Service 68b988
	},
Packit Service 68b988
	.modules_loaded = "mod-simple",
Packit Service 68b988
	);
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_oldkernel_force(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"--force", "mod-simple",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_oldkernel_force,
Packit Service 68b988
	.description = "check modprobe --force with kernel without finit_module()",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "3.3.3",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel-force",
Packit Service 68b988
		[TC_INIT_MODULE_RETCODES] = "",
Packit Service 68b988
	},
Packit Service 68b988
	.modules_loaded = "mod-simple",
Packit Service 68b988
	);
Packit Service 68b988
Packit Service 68b988
static noreturn int modprobe_external(const struct test *t)
Packit Service 68b988
{
Packit Service 68b988
	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Packit Service 68b988
	const char *const args[] = {
Packit Service 68b988
		progname,
Packit Service 68b988
		"mod-simple",
Packit Service 68b988
		NULL,
Packit Service 68b988
	};
Packit Service 68b988
Packit Service 68b988
	test_spawn_prog(progname, args);
Packit Service 68b988
	exit(EXIT_FAILURE);
Packit Service 68b988
}
Packit Service 68b988
DEFINE_TEST(modprobe_external,
Packit Service 68b988
	.description = "check modprobe able to load external module",
Packit Service 68b988
	.config = {
Packit Service 68b988
		[TC_UNAME_R] = "4.4.4",
Packit Service 68b988
		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/external",
Packit Service 68b988
		[TC_INIT_MODULE_RETCODES] = "",
Packit Service 68b988
	},
Packit Service 68b988
	.modules_loaded = "mod-simple",
Packit Service 68b988
	);
Packit Service 68b988
Packit Service 68b988
TESTSUITE_MAIN();