@@ -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)
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <syslog.h>
+#include <test-pcommit.h>
#include <test-blk-namespaces.h>
#include <test-pmem-namespaces.h>
#include <util/parse-options.h>
@@ -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)
new file mode 100644
@@ -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 <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <test-pcommit.h>
+
+#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();
+}
new file mode 100644
@@ -0,0 +1,4 @@
+#ifndef __TEST_PCOMMIT__
+#define __TEST_PCOMMIT__
+int test_pcommit(void);
+#endif
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 <ross.zwisler@linux.intel.com> --- 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