From patchwork Thu Jun 4 14:31:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paulo Zanoni X-Patchwork-Id: 6547651 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7BEAD9F1CC for ; Thu, 4 Jun 2015 14:32:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 68FCE207E6 for ; Thu, 4 Jun 2015 14:32:06 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 584C0205FC for ; Thu, 4 Jun 2015 14:32:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E8DA66EB67; Thu, 4 Jun 2015 07:32:04 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qg0-f51.google.com (mail-qg0-f51.google.com [209.85.192.51]) by gabe.freedesktop.org (Postfix) with ESMTP id 7EC926EAD1 for ; Thu, 4 Jun 2015 07:32:02 -0700 (PDT) Received: by qgep100 with SMTP id p100so17470760qge.3 for ; Thu, 04 Jun 2015 07:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+S3BmTVfUyNfInZWe7SjS85Y7Ld1UJnmhHFBr7hdv9w=; b=BLaX7p+6FyO5aRiRWeH5r2vG75RkMrdSOyIf3jCNbzpRqb/7TP/BXBCl73S/JhS/Mg clIgdM+CNQbEKF/Iioskl0/zUw98vzOqObsep407ATWtDiKkCzF5BGY3FkubTw5492cI XPLGwnbcxgU0a83iBb7svQbzxjCBk23kf6THRut0Xv5802Odldx6e3Tj6cFJnmlm6kTT Fj4th76+sFbN4DnI97x+0yQvfHgjF+DMwgYnnttelRKIa5VWg4VrHkHQaBOQhIjrTAKI CpTEQgohgt6YPCGaLXWHxapBl2aqSGiR5tPPwDoRG+F2jLDQwvc/IiPcxNXinXk1Cnjj X5SQ== X-Received: by 10.140.239.129 with SMTP id k123mr44590727qhc.66.1433428322072; Thu, 04 Jun 2015 07:32:02 -0700 (PDT) Received: from localhost.localdomain ([177.92.20.165]) by mx.google.com with ESMTPSA id f33sm2445470qkf.7.2015.06.04.07.32.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Jun 2015 07:32:01 -0700 (PDT) From: Paulo Zanoni To: intel-gfx@lists.freedesktop.org Date: Thu, 4 Jun 2015 11:31:04 -0300 Message-Id: <1433428266-1867-2-git-send-email-przanoni@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1433428266-1867-1-git-send-email-przanoni@gmail.com> References: <1433428266-1867-1-git-send-email-przanoni@gmail.com> Cc: Paulo Zanoni Subject: [Intel-gfx] [PATCH igt 2/4] lib/igt_aux: add functions to manipulate i915.ko parameters 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: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Paulo Zanoni Some i915.ko features have very nice IGT tests, which are never executed because the features are disabled by default. This leads to unnoticed regressions both in the Kernel and in the IGT tests. We have seen this multiple times, for example, on FBC and PSR. We want to be able to run IGT and actually test these disabled-by-default features in order to make sure we at least don't break them even more. Sometimes they may be disabled for some specific reason, and we don't want to increase the set of reasons without noticing. To help solving this problem, this commit adds some helper functions that should make it easier to change certain i915.ko parameters and then restore their original values at the end of the test. With this, I'm hoping QA will be able to detect any regressions and automatically bisect them - or, with PRTS, reject the patches before they are even merged. Signed-off-by: Paulo Zanoni --- lib/igt_aux.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_aux.h | 4 ++ 2 files changed, 138 insertions(+) diff --git a/lib/igt_aux.c b/lib/igt_aux.c index d5c70fa..5392e1a 100644 --- a/lib/igt_aux.c +++ b/lib/igt_aux.c @@ -735,3 +735,137 @@ void igt_unlock_mem(void) free(locked_mem); locked_mem = NULL; } + + +#define MODULE_PARAM_DIR "/sys/module/i915/parameters/" +#define PARAM_NAME_MAX_SZ 32 +#define PARAM_VALUE_MAX_SZ 16 +#define PARAM_FILE_PATH_MAX_SZ (strlen(MODULE_PARAM_DIR) + PARAM_NAME_MAX_SZ) + +struct module_param_data { + char name[PARAM_NAME_MAX_SZ]; + char original_value[PARAM_VALUE_MAX_SZ]; + + struct module_param_data *next; +}; +struct module_param_data *module_params = NULL; + +static void igt_module_param_exit_handler(int sig) +{ + const size_t dir_len = strlen(MODULE_PARAM_DIR); + char file_path[PARAM_FILE_PATH_MAX_SZ]; + struct module_param_data *data; + int fd; + + /* We don't need to assert string sizes on this function since they were + * already checked before being stored on the lists. Besides, + * igt_assert() is not AS-Safe. */ + strcpy(file_path, MODULE_PARAM_DIR); + + for (data = module_params; data != NULL; data = data->next) { + strcpy(file_path + dir_len, data->name); + + fd = open(file_path, O_RDWR); + if (fd >= 0) { + write(fd, data->original_value, + strlen(data->original_value)); + close(fd); + } + } + /* free() is not AS-Safe, so we can't call it here. */ +} + +/** + * igt_save_module_param: + * @name: name of the i915.ko module parameter + * @file_path: full sysfs file path for the parameter + * + * Reads the current value of an i915.ko module parameter, saves it on an array, + * then installs an exit handler to restore it when the program exits. + * + * It is safe to call this function multiple times for the same parameter. + * + * Notice that this function is called by igt_set_module_param(), so that one - + * or one of its wrappers - is the only function the test programs need to call. + */ +static void igt_save_module_param(const char *name, const char *file_path) +{ + struct module_param_data *data; + size_t n; + int fd; + + /* Check if this parameter is already saved. */ + for (data = module_params; data != NULL; data = data->next) + if (strncmp(data->name, name, PARAM_NAME_MAX_SZ) == 0) + return; + + if (!module_params) + igt_install_exit_handler(igt_module_param_exit_handler); + + data = calloc(1, sizeof (*data)); + igt_assert(data); + + strncpy(data->name, name, PARAM_NAME_MAX_SZ); + + fd = open(file_path, O_RDONLY); + igt_assert(fd >= 0); + + n = read(fd, data->original_value, PARAM_VALUE_MAX_SZ); + igt_assert_f(n > 0 && n < PARAM_VALUE_MAX_SZ, + "Need to increase PARAM_VALUE_MAX_SZ\n"); + + igt_assert(close(fd) == 0); + + data->next = module_params; + module_params = data; +} + +/** + * igt_set_module_param: + * @name: i915.ko parameter name + * @val: i915.ko parameter value + * + * This function sets the desired value for the given i915.ko parameter. It also + * takes care of saving and restoring the values that were already set before + * the test was run by calling igt_save_module_param(). + * + * Please consider using igt_set_module_param_int() for the integer and bool + * parameters. + */ +void igt_set_module_param(const char *name, const char *val) +{ + char file_path[PARAM_FILE_PATH_MAX_SZ]; + size_t len = strlen(val); + int fd; + + igt_assert_f(strlen(name) < PARAM_NAME_MAX_SZ, + "Need to increase PARAM_NAME_MAX_SZ\n"); + strcpy(file_path, MODULE_PARAM_DIR); + strcpy(file_path + strlen(MODULE_PARAM_DIR), name); + + igt_save_module_param(name, file_path); + + fd = open(file_path, O_RDWR); + igt_assert(write(fd, val, len) == len); + igt_assert(close(fd) == 0); +} + +/** + * igt_set_module_param_int: + * @name: i915.ko parameter name + * @val: i915.ko parameter value + * + * This is a wrapper for igt_set_module_param() that takes an integer instead of + * a string. Please see igt_set_module_param(). + */ +void igt_set_module_param_int(const char *name, int val) +{ + char str[PARAM_VALUE_MAX_SZ]; + int n; + + n = snprintf(str, PARAM_VALUE_MAX_SZ, "%d\n", val); + igt_assert_f(n < PARAM_VALUE_MAX_SZ, + "Need to increase PARAM_VALUE_MAX_SZ\n"); + + igt_set_module_param(name, str); +} diff --git a/lib/igt_aux.h b/lib/igt_aux.h index b2dc267..9ea50de 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -145,4 +145,8 @@ void igt_unlock_mem(void); ret_; \ }) + +void igt_set_module_param(const char *name, const char *val); +void igt_set_module_param_int(const char *name, int val); + #endif /* IGT_AUX_H */