[Intel-gfx] [PATCH i-g-t 2/3] tests/drv_module_reload_basic: Convert sh script to C version.
Chris Wilson
chris at chris-wilson.co.uk
Thu Oct 20 19:52:23 UTC 2016
On Thu, Oct 20, 2016 at 10:36:48PM +0300, Marius Vlad wrote:
> +static const char *tests[] = {
> + "gem_alive", "gem_exec_store"
> +};
gem_alive is just a single ioctl query, simpler and move obvious to do
it inline. Then remove tests/gem_alive.c, but it may live on as
tools/gem_alive.c (or better yet tools/gem_info.c).
gem_exec_store is a couple of ioctls...
A rewritten C test should not be i915 specific if we can help it. The
core of it can be driver agnostic (same steps required to unbind from
console and reload after all).
> +
> +static int
> +reload(const char *opts_i915)
> +{
> + kick_fbcon(0);
> +
> + if (opts_i915)
> + igt_info("Reloading i915 with %s\n\n", opts_i915);
> +
> + if (igt_lsmod_has_module("snd_hda_intel")) {
> + if (igt_pkill(SIGTERM, "alsactl") == -1) {
> + return IGT_EXIT_FAILURE;
> + }
> + if (igt_rmmod("snd_hda_intel", false) == -1)
> + return IGT_EXIT_FAILURE;
> + }
> +
> + /* gen5 */
> + if (igt_lsmod_has_module("intel_ips")) {
> + igt_rmmod("intel_ips", false);
> + }
> +
> + if (igt_rmmod("i915", false) == -1) {
> + return IGT_EXIT_SKIP;
> + }
Ugh. These names leave much to be desired.
igt_kmod_load()
igt_kmod_unload()
igt_kmod_is_loaded() (can return refcnt >= 0 and -1 for unloaded)
> +
> + igt_info("i915.ko has been unloaded!\n");
> +
> + if (igt_lsmod_has_module("intel-gtt")) {
> + igt_rmmod("intel-gtt", false);
> + }
> +
> + igt_rmmod("drm_kms_helper", false);
> + igt_rmmod("drm", false);
> +
> + if (igt_lsmod_has_module("i915")) {
> + igt_info("WARNING: i915.ko still loaded!\n");
> + return IGT_EXIT_FAILURE;
> + } else {
> + igt_info("module successfully unloaded\n");
> + }
> +
> + /* we do not have automatic loading of dependencies */
> + igt_insmod("drm", NULL);
> + igt_insmod("drm_kms_helper", NULL);
> +
> + if (igt_insmod("i915", opts_i915) == -1) {
> + igt_info("Could not load i915\n");
> + return IGT_EXIT_FAILURE;
> + }
> +
> + kick_fbcon(1);
> +
> + if (igt_insmod("snd_hda_intel", NULL) == -1)
> + return IGT_EXIT_FAILURE;
> +
> + return IGT_EXIT_SUCCESS;
> +}
> +
> +static void
> +igt_execv(char **argv)
> +{
> + igt_fork(child, 1) {
> + if (execv(argv[0], argv) < 0) {
> + igt_info("Failed to exec %s\n",
> + argv[0]);
> + exit(IGT_EXIT_FAILURE);
> + }
> + }
> + igt_waitchildren();
> +}
> +
> +static void
> +finish_load(char *dirname)
> +{
> + char buf[PATH_MAX];
> + char *__argv[2] = { buf, NULL };
> +
> + memset(buf, 0, PATH_MAX);
> + snprintf(buf, sizeof(buf), "%s/%s", dirname, tests[0]);
> +
> + igt_execv(__argv);
> +
> + memset(buf, 0, sizeof(buf));
> + snprintf(buf, sizeof(buf), "%s/%s", dirname, tests[1]);
> +
> + igt_execv(__argv);
> +}
> +
> +int main(int argc, char *argv[])
igt_main
{
--
Chris Wilson, Intel Open Source Technology Centre
More information about the Intel-gfx
mailing list