From patchwork Thu May 21 07:15:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 474848 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 796B51400B7; Thu, 21 May 2015 17:15:28 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1YvKhT-0004lR-D6; Thu, 21 May 2015 07:15:27 +0000 Received: from ozlabs.org ([103.22.144.67]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1YvKhG-0004jO-L7 for fwts-devel@lists.ubuntu.com; Thu, 21 May 2015 07:15:14 +0000 Received: by ozlabs.org (Postfix, from userid 1023) id A96DB14077C; Thu, 21 May 2015 17:15:12 +1000 (AEST) MIME-Version: 1.0 Subject: [PATCH 1/3] devicetree/dtc: Add initial device tree test Message-Id: <1432192507.646890.191605150773.1.gpush@pablo> To: fwts-devel@lists.ubuntu.com From: Jeremy Kerr Date: Thu, 21 May 2015 15:15:07 +0800 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com Check that we can compile the device tree with dtc. Signed-off-by: Jeremy Kerr --- src/Makefile.am | 1 src/devicetree/dtc/dtc.c | 76 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index 62c63ef..4a2622b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -78,6 +78,7 @@ fwts_SOURCES = main.c \ cpu/nx/nx.c \ cpu/msr/msr.c \ cpu/microcode/microcode.c \ + devicetree/dtc/dtc.c \ dmi/dmicheck/dmicheck.c \ hotkey/hotkey/hotkey.c \ hpet/hpet_check/hpet_check.c \ diff --git a/src/devicetree/dtc/dtc.c b/src/devicetree/dtc/dtc.c new file mode 100644 index 0000000..c1420dc --- /dev/null +++ b/src/devicetree/dtc/dtc.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2014 Jeremy Kerr + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + */ + +#define _GNU_SOURCE +#include +#include + +#include "fwts.h" + +static const char *devicetree_path = "/proc/device-tree"; + +static int dtc_check_valid(fwts_framework *fw) +{ + int rc, status; + char *command; + + rc = asprintf(&command, "dtc -I fs -o /dev/null %s", devicetree_path); + assert(rc > 0); + + rc = fwts_exec(command, &status); + free(command); + + if (rc != FWTS_OK || !WIFEXITED(status) || WEXITSTATUS(status) != 0) { + fwts_failed(fw, LOG_LEVEL_HIGH, "DeviceTreeDtcParseFail", + "dtc reports device tree errors"); + return FWTS_ERROR; + } + + fwts_passed(fw, "dtc test passed"); + return FWTS_OK; +} + +static int dtc_init(fwts_framework *fw) +{ + int rc, status; + + rc = fwts_exec("echo '/dts-v1/; / { };' | dtc -o /dev/null", &status); + + if (rc != FWTS_OK || !WIFEXITED(status) || WEXITSTATUS(status) != 0) { + fwts_aborted(fw, "Failed to run dtc"); + return FWTS_ABORTED; + } + + return FWTS_OK; +} + +static fwts_framework_minor_test dtc_tests[] = { + { dtc_check_valid, "Check device tree validity with dtc" }, + { NULL, NULL }, +}; + +static fwts_framework_ops dtc_ops = { + .description = "Device tree compilation test", + .minor_tests = dtc_tests, + .init = dtc_init, +}; + +FWTS_REGISTER_FEATURES("dtc", &dtc_ops, FWTS_TEST_ANYTIME, + FWTS_FLAG_BATCH, FWTS_FW_FEATURE_DEVICETREE);