From patchwork Fri Sep 11 15:39:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Zwisler X-Patchwork-Id: 7162381 Return-Path: X-Original-To: patchwork-linux-nvdimm@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 26CC09F326 for ; Fri, 11 Sep 2015 15:39:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 898FD207AA for ; Fri, 11 Sep 2015 15:39:48 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8ABC620789 for ; Fri, 11 Sep 2015 15:39:47 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6B34D1831E4; Fri, 11 Sep 2015 08:39:47 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by ml01.01.org (Postfix) with ESMTP id 9AEEC1831B9 for ; Fri, 11 Sep 2015 08:39:46 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 11 Sep 2015 08:39:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,511,1437462000"; d="scan'208";a="802504592" Received: from theros.lm.intel.com ([10.232.112.176]) by orsmga002.jf.intel.com with ESMTP; 11 Sep 2015 08:39:45 -0700 From: Ross Zwisler To: linux-nvdimm@lists.01.org Subject: [PATCH v2] ndctl: add unit test for presence of PCOMMIT Date: Fri, 11 Sep 2015 09:39:39 -0600 Message-Id: <1441985979-2963-1-git-send-email-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 2.1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 Fail our BAT test if run on systems without proper PCOMMIT support. PCOMMIT is required on non-ADR x86 systems that want to use the PMEM API. Signed-off-by: Ross Zwisler --- Makefile.am | 10 ++++++--- builtin-bat.c | 6 ++++++ lib/test-pcommit.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ test-pcommit.h | 4 ++++ 4 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 lib/test-pcommit.c create mode 100644 test-pcommit.h diff --git a/Makefile.am b/Makefile.am index 8b07408..e5b4b49 100644 --- a/Makefile.am +++ b/Makefile.am @@ -77,7 +77,8 @@ endif if ENABLE_DESTRUCTIVE ndctl_SOURCES += lib/blk_namespaces.c \ - lib/pmem_namespaces.c + lib/pmem_namespaces.c \ + lib/test-pcommit.c ndctl_SOURCES += builtin-bat.c endif @@ -115,13 +116,16 @@ TESTS = lib/test-libndctl lib/test-dpa-alloc lib/test-parent-uuid check_PROGRAMS = lib/test-libndctl lib/test-dpa-alloc lib/test-parent-uuid if ENABLE_DESTRUCTIVE -TESTS += lib/test-blk-ns lib/test-pmem-ns -check_PROGRAMS += lib/test-blk-ns lib/test-pmem-ns +TESTS += lib/test-blk-ns lib/test-pmem-ns lib/test-pcommit +check_PROGRAMS += lib/test-blk-ns lib/test-pmem-ns lib/test-pcommit endif lib_test_libndctl_SOURCES = lib/test-libndctl.c lib/test-core.c lib_test_libndctl_LDADD = lib/libndctl.la $(UUID_LIBS) $(KMOD_LIBS) +lib_test_pcommit_SOURCES = lib/test-pcommit.c +lib_test_pcommit_LDADD = lib/libndctl.la $(KMOD_LIBS) + lib_test_blk_ns_SOURCES = lib/blk_namespaces.c lib_test_blk_ns_LDADD = lib/libndctl.la $(KMOD_LIBS) diff --git a/builtin-bat.c b/builtin-bat.c index 4c6ee64..e79a55d 100644 --- a/builtin-bat.c +++ b/builtin-bat.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -25,6 +26,11 @@ int cmd_bat(int argc, const char **argv) if (argc) usage_with_options(u, options); + rc = test_pcommit(); + fprintf(stderr, "test_pcommit: %s\n", rc ? "FAIL" : "PASS"); + if (rc) + return rc; + rc = test_blk_namespaces(loglevel); fprintf(stderr, "test_blk_namespaces: %s\n", rc ? "FAIL" : "PASS"); if (rc) diff --git a/lib/test-pcommit.c b/lib/test-pcommit.c new file mode 100644 index 0000000..f40052f --- /dev/null +++ b/lib/test-pcommit.c @@ -0,0 +1,63 @@ +/* + * test-pcommit: Make sure PCOMMIT is supported by the platform. + * + * Copyright (c) 2015, Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU Lesser General Public License, + * version 2.1, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for + * more details. + */ +#include +#include +#include +#include + +#define err(msg)\ + fprintf(stderr, "%s:%d: %s (%s)\n", __func__, __LINE__, msg, strerror(errno)) + +int test_pcommit(void) +{ + const char *pcommit = "pcommit"; + const char *flags = "flags"; + const int buffer_size = 1024; + + char buffer[buffer_size]; + FILE *cpuinfo; + char *token; + + cpuinfo = fopen("/proc/cpuinfo", "r"); + if (!cpuinfo) { + err("open"); + return EBADF; + } + + while (fgets(buffer, buffer_size, cpuinfo)) { + token = strtok(buffer, " :"); + + if (token && + strncmp(token, flags, strlen(flags)) != 0) + continue; + + while (token != NULL) { + token = strtok(NULL, " "); + if (token && + strncmp(token, pcommit, strlen(pcommit)) == 0) { + fclose(cpuinfo); + return 0; + } + } + } + + fclose(cpuinfo); + return ENOTSUP; +} + +int __attribute__((weak)) main(int argc, char *argv[]) +{ + return test_pcommit(); +} diff --git a/test-pcommit.h b/test-pcommit.h new file mode 100644 index 0000000..27e788d --- /dev/null +++ b/test-pcommit.h @@ -0,0 +1,4 @@ +#ifndef __TEST_PCOMMIT__ +#define __TEST_PCOMMIT__ +int test_pcommit(void); +#endif