From patchwork Thu Oct 20 19:36:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marius Vlad X-Patchwork-Id: 9387481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3505B607F0 for ; Thu, 20 Oct 2016 19:30:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22506294CE for ; Thu, 20 Oct 2016 19:30:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1734129BBA; Thu, 20 Oct 2016 19:30:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8D243294CE for ; Thu, 20 Oct 2016 19:30:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 022066EC0F; Thu, 20 Oct 2016 19:30:47 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 48D2B6EC0C for ; Thu, 20 Oct 2016 19:30:40 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP; 20 Oct 2016 12:30:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,372,1473145200"; d="scan'208";a="182028231" Received: from mcvlad-wk.rb.intel.com ([10.237.105.57]) by fmsmga004.fm.intel.com with ESMTP; 20 Oct 2016 12:30:34 -0700 From: Marius Vlad To: intel-gfx@lists.freedesktop.org Date: Thu, 20 Oct 2016 22:36:48 +0300 Message-Id: <20161020193649.11701-3-marius.c.vlad@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161020193649.11701-1-marius.c.vlad@intel.com> References: <20161020193649.11701-1-marius.c.vlad@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t 2/3] tests/drv_module_reload_basic: Convert sh script to C version. X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Marius Vlad --- tests/Makefile.sources | 2 +- tests/drv_module_reload_basic | 97 ----------------------- tests/drv_module_reload_basic.c | 166 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+), 98 deletions(-) delete mode 100755 tests/drv_module_reload_basic create mode 100644 tests/drv_module_reload_basic.c diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 6d081c3..c35ea11 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -211,6 +211,7 @@ TESTS_progs = \ kms_pwrite_crc \ kms_sink_crc_basic \ prime_udl \ + drv_module_reload_basic \ $(NULL) # IMPORTANT: The ZZ_ tests need to be run last! @@ -221,7 +222,6 @@ TESTS_scripts_M = \ TESTS_scripts = \ debugfs_emon_crash \ drv_debugfs_reader \ - drv_module_reload_basic \ kms_sysfs_edid_timing \ sysfs_l3_parity \ test_rte_check \ diff --git a/tests/drv_module_reload_basic b/tests/drv_module_reload_basic deleted file mode 100755 index a8d628d..0000000 --- a/tests/drv_module_reload_basic +++ /dev/null @@ -1,97 +0,0 @@ -#!/bin/bash -# -# Testcase: Reload the drm module -# -# ... we've broken this way too often :( -# - -SOURCE_DIR="$( dirname "${BASH_SOURCE[0]}" )" -. $SOURCE_DIR/drm_lib.sh - -# no other drm service should be running, so we can just unbind - -# return 0 if module by name $1 is loaded according to lsmod -function mod_loaded() -{ - lsmod | grep -w "^$1" &> /dev/null -} - -function reload() { - local snd_hda_intel_unloaded - - echo Reloading i915.ko with $* - - # we must kick away fbcon (but only fbcon) - for vtcon in /sys/class/vtconsole/vtcon*/ ; do - if grep "frame buffer device" $vtcon/name > /dev/null ; then - echo unbinding $vtcon: `cat $vtcon/name` - echo 0 > $vtcon/bind - fi - done - - # The sound driver uses our power well - pkill alsactl - snd_hda_intel_unloaded=0 - if mod_loaded snd_hda_intel; then - rmmod snd_hda_intel && snd_hda_intel_unloaded=1 - fi - - # gen5 only - if mod_loaded intel_ips; then - rmmod intel_ips - fi - rmmod i915 || return $IGT_EXIT_SKIP - #ignore errors in intel-gtt, often built-in - rmmod intel-gtt &> /dev/null - # drm may be used by other devices (nouveau, radeon, udl, etc) - rmmod drm_kms_helper &> /dev/null - rmmod drm &> /dev/null - - if mod_loaded i915; then - echo WARNING: i915.ko still loaded! - return $IGT_EXIT_FAILURE - else - echo module successfully unloaded - fi - - modprobe i915 $* - - if [ -f /sys/class/vtconsole/vtcon1/bind ]; then - echo 1 > /sys/class/vtconsole/vtcon1/bind - fi - - modprobe -q snd_hda_intel || return $snd_hda_intel_unloaded -} - -function finish_load() { - # does the device exist? - if $SOURCE_DIR/gem_alive > /dev/null ; then - echo "module successfully loaded again" - else - echo "failed to reload module successfully" - return $IGT_EXIT_FAILURE - fi - - # then try to run something - if ! $SOURCE_DIR/gem_exec_store > /dev/null ; then - echo "failed to execute a simple batch after reload" - return $IGT_EXIT_FAILURE - fi - - return $IGT_EXIT_SUCCESS -} - -hda_dynamic_debug_enable - -reload || exit $? -finish_load || exit $? - -# Repeat the module reload trying to to generate faults -for i in $(seq 1 4); do - reload inject_load_failure=$i -done - -reload || exit $? -finish_load - -exit $? diff --git a/tests/drv_module_reload_basic.c b/tests/drv_module_reload_basic.c new file mode 100644 index 0000000..d36afde --- /dev/null +++ b/tests/drv_module_reload_basic.c @@ -0,0 +1,166 @@ +/* + * Copyright © 2016 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +#include "igt.h" +#include "igt_debugfs.h" +#include "igt_aux.h" +#include "igt_sysfs.h" +#include "igt_core.h" + +#include +#include +#include +#include +#include + +#include +#include + +static const char *tests[] = { + "gem_alive", "gem_exec_store" +}; + +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; + } + + 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[]) +{ + int i, err; + char buf[64]; + char *prg, *dir; + + prg = strdup(argv[0]); + igt_subtest_init_parse_opts(&argc, argv, "", NULL, + NULL, NULL, NULL); + + + igt_subtest("basic-reload") { + if ((err = reload(NULL))) + igt_fail(err); + } + + igt_subtest("basic-exec") { + dir = dirname(prg); + finish_load(dir); + } + + igt_subtest("basic-reload-inject") { + for (i = 0; i < 4; i++) { + memset(buf, 0, sizeof(buf)); + snprintf(buf, sizeof(buf), "inject_load_failure=%d", i); + reload(buf); + } + } + + igt_subtest("basic-reload-final") + if ((err = reload(NULL))) + igt_fail(err); + + free(prg); + + igt_exit(); +}