From patchwork Wed Jun 20 11:31:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 166020 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 41AA2B6FD4 for ; Wed, 20 Jun 2012 21:31:06 +1000 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1ShJ7o-0001ka-TX for incoming@patchwork.ozlabs.org; Wed, 20 Jun 2012 11:31:04 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1ShJ7n-0001kV-5r for fwts-devel@lists.ubuntu.com; Wed, 20 Jun 2012 11:31:03 +0000 Received: from cpc19-craw6-2-0-cust5.croy.cable.virginmedia.com ([77.102.228.6] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ShJ7n-00027h-2a for fwts-devel@lists.ubuntu.com; Wed, 20 Jun 2012 11:31:03 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] lib: fwts_acpi_tables: load tables in deterministically Date: Wed, 20 Jun 2012 12:31:02 +0100 Message-Id: <1340191862-27518-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.7.10.4 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King When loading a bunch of ACPI tables we should load them in some form of deterministic order rather that the random order that they appear in the directory. So, load them in on filename alphasorted order. This allows us to sanely check the tables using fwts-test with some sort of determinism. Signed-off-by: Colin Ian King Acked-by: Keng-Yu Lin Acked-by: Alex Hung --- src/lib/src/fwts_acpi_tables.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c index eabc2ea..513dfff 100644 --- a/src/lib/src/fwts_acpi_tables.c +++ b/src/lib/src/fwts_acpi_tables.c @@ -444,29 +444,34 @@ static uint8_t *fwts_acpi_load_table_from_file(const int fd, size_t *length) static int fwts_acpi_load_tables_from_file(fwts_framework *fw) { - DIR *dir; - struct dirent *direntry; + struct dirent **dir_entries; int count = 0; + int i; - if ((dir = opendir(fw->acpi_table_path)) == NULL) { + /* + * Read in directory in alphabetical name sorted order + * to ensure the tables are always loaded into memory + * in some form of deterministic order + */ + if ((count = scandir(fw->acpi_table_path, &dir_entries, 0, alphasort)) < 0) { fwts_log_error(fw, "Cannot open directory '%s' to read ACPI tables.", fw->acpi_table_path); return FWTS_ERROR; } - while ((direntry = readdir(dir)) != NULL) { - if (strstr(direntry->d_name, ".dat")) { + for (i = 0; i < count; i++) { + if (strstr(dir_entries[i]->d_name, ".dat")) { char path[PATH_MAX]; int fd; + snprintf(path, sizeof(path), "%s/%s", - fw->acpi_table_path, direntry->d_name); + fw->acpi_table_path, dir_entries[i]->d_name); if ((fd = open(path, O_RDONLY)) >= 0) { uint8_t *table; size_t length; char name[PATH_MAX]; - count++; - strcpy(name, direntry->d_name); + strcpy(name, dir_entries[i]->d_name); name[strlen(name)-4] = '\0'; if ((table = fwts_acpi_load_table_from_file(fd, &length)) != NULL) fwts_acpi_add_table(name, table, @@ -475,8 +480,9 @@ static int fwts_acpi_load_tables_from_file(fwts_framework *fw) } else fwts_log_error(fw, "Cannot load ACPI table from file '%s'\n", path); } + free(dir_entries[i]); } - closedir(dir); + free(dir_entries); if (count == 0) { fwts_log_error(fw, "Could not find any APCI tables in directory '%s'.\n", fw->acpi_table_path);