From 0a8bccaa82e4d74f310aa3e92108145d48944080 Mon Sep 17 00:00:00 2001
From: Lukasz Dorau <lukasz.dorau@intel.com>
Date: Thu, 9 Apr 2015 11:18:02 +0200
Subject: [PATCH] obj: add pool descriptor's unit tests

---
 src/test/Makefile                 |  1 +
 src/test/obj_basic/.gitignore     |  1 +
 src/test/obj_basic/Makefile       | 44 ++++++++++++++++++
 src/test/obj_basic/README         | 16 +++++++
 src/test/obj_basic/TEST0          | 53 +++++++++++++++++++++
 src/test/obj_basic/TEST1          | 56 ++++++++++++++++++++++
 src/test/obj_basic/obj_basic.c    | 77 +++++++++++++++++++++++++++++++
 src/test/obj_basic/out0.log.match |  3 ++
 src/test/obj_basic/out1.log.match |  3 ++
 9 files changed, 254 insertions(+)
 create mode 100644 src/test/obj_basic/.gitignore
 create mode 100644 src/test/obj_basic/Makefile
 create mode 100644 src/test/obj_basic/README
 create mode 100755 src/test/obj_basic/TEST0
 create mode 100755 src/test/obj_basic/TEST1
 create mode 100644 src/test/obj_basic/obj_basic.c
 create mode 100644 src/test/obj_basic/out0.log.match
 create mode 100644 src/test/obj_basic/out1.log.match

diff --git a/src/test/Makefile b/src/test/Makefile
index 77f3ea4ba..4c2eeb1d9 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -44,6 +44,7 @@ TEST = blk_nblock\
        log_basic\
        log_recovery\
        log_walker\
+       obj_basic\
        pmem_isa_proc\
        pmem_is_pmem\
        pmem_is_pmem_proc\
diff --git a/src/test/obj_basic/.gitignore b/src/test/obj_basic/.gitignore
new file mode 100644
index 000000000..cb670a5a3
--- /dev/null
+++ b/src/test/obj_basic/.gitignore
@@ -0,0 +1 @@
+obj_basic
diff --git a/src/test/obj_basic/Makefile b/src/test/obj_basic/Makefile
new file mode 100644
index 000000000..f4db53311
--- /dev/null
+++ b/src/test/obj_basic/Makefile
@@ -0,0 +1,44 @@
+#
+# Copyright (c) 2015, Intel Corporation
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
+#       distribution.
+#
+#     * Neither the name of Intel Corporation nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+#
+# src/test/obj_basic/Makefile -- build obj_basic unit test
+#
+TARGET = obj_basic
+OBJS = obj_basic.o
+
+LIBPMEM=y
+LIBPMEMOBJ=y
+
+include ../Makefile.inc
+
+obj_basic.o: obj_basic.c
diff --git a/src/test/obj_basic/README b/src/test/obj_basic/README
new file mode 100644
index 000000000..c65a9fb15
--- /dev/null
+++ b/src/test/obj_basic/README
@@ -0,0 +1,16 @@
+Linux NVM Library
+
+This is src/test/obj_basic/README.
+
+This directory contains a unit test for:
+- pmemobj_create
+- pmemobj_open
+
+The program in obj_basic.c takes a file name and an operation encoded
+by a character as arguments. For example:
+
+	./obj_basic file1 c
+
+The following characters and operations can be used:
+	c - pmemobj_create
+	o - pmemobj_open
diff --git a/src/test/obj_basic/TEST0 b/src/test/obj_basic/TEST0
new file mode 100755
index 000000000..132fa2f87
--- /dev/null
+++ b/src/test/obj_basic/TEST0
@@ -0,0 +1,53 @@
+#!/bin/bash -e
+#
+# Copyright (c) 2015, Intel Corporation
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
+#       distribution.
+#
+#     * Neither the name of Intel Corporation nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+#
+# src/test/obj_basic/TEST0 -- unit test for pmemobj_create
+#
+export UNITTEST_NAME=obj_basic/TEST0
+export UNITTEST_NUM=0
+
+# standard unit test setup
+. ../unittest/unittest.sh
+
+setup
+
+rm -f $DIR/testfile1
+
+expect_normal_exit ./obj_basic$EXESUFFIX $DIR/testfile1 c
+
+rm $DIR/testfile1
+
+check
+
+pass
diff --git a/src/test/obj_basic/TEST1 b/src/test/obj_basic/TEST1
new file mode 100755
index 000000000..242d18a2c
--- /dev/null
+++ b/src/test/obj_basic/TEST1
@@ -0,0 +1,56 @@
+#!/bin/bash -e
+#
+# Copyright (c) 2015, Intel Corporation
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
+#       distribution.
+#
+#     * Neither the name of Intel Corporation nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+#
+# src/test/obj_basic/TEST1 -- unit test for:
+# - pmemobj_create
+# - pmemobj_open
+#
+export UNITTEST_NAME=obj_basic/TEST1
+export UNITTEST_NUM=1
+
+# standard unit test setup
+. ../unittest/unittest.sh
+
+setup
+
+rm -f $DIR/testfile1
+
+expect_normal_exit ./obj_basic$EXESUFFIX $DIR/testfile1 c
+expect_normal_exit ./obj_basic$EXESUFFIX $DIR/testfile1 o
+
+rm $DIR/testfile1
+
+check
+
+pass
diff --git a/src/test/obj_basic/obj_basic.c b/src/test/obj_basic/obj_basic.c
new file mode 100644
index 000000000..d83b7c1c4
--- /dev/null
+++ b/src/test/obj_basic/obj_basic.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2015, Intel Corporation
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * obj_basic.c -- unit test for pmemobj_create and pmemobj_open
+ *
+ * usage: obj_basic file operation:...
+ *
+ * operations are 'c' or 'o'
+ *
+ */
+
+#include "unittest.h"
+
+#define	LAYOUT_NAME "basic"
+
+int
+main(int argc, char *argv[])
+{
+	START(argc, argv, "obj_basic");
+
+	if (argc != 3)
+		FATAL("usage: %s file-name op:c|o", argv[0]);
+
+	const char *path = argv[1];
+	PMEMobjpool *pop = NULL;
+
+	if (strchr("co", argv[2][0]) == NULL || argv[2][1] != '\0')
+		FATAL("op must be c or o");
+
+	switch (argv[2][0]) {
+		case 'c':
+			if ((pop = pmemobj_create(path, LAYOUT_NAME,
+							PMEMOBJ_MIN_POOL,
+							S_IRWXU)) == NULL)
+				FATAL("!pmemobj_create: %s", path);
+			break;
+
+		case 'o':
+			if ((pop = pmemobj_open(path, LAYOUT_NAME)) == NULL)
+				FATAL("!pmemobj_open: %s", path);
+			break;
+	}
+
+	pmemobj_close(pop);
+
+	DONE(NULL);
+}
diff --git a/src/test/obj_basic/out0.log.match b/src/test/obj_basic/out0.log.match
new file mode 100644
index 000000000..5527da120
--- /dev/null
+++ b/src/test/obj_basic/out0.log.match
@@ -0,0 +1,3 @@
+obj_basic/TEST0: START: obj_basic
+ ./obj_basic$(nW) $(nW)/testfile1 c
+obj_basic/TEST0: Done
diff --git a/src/test/obj_basic/out1.log.match b/src/test/obj_basic/out1.log.match
new file mode 100644
index 000000000..2e024169b
--- /dev/null
+++ b/src/test/obj_basic/out1.log.match
@@ -0,0 +1,3 @@
+obj_basic/TEST1: START: obj_basic
+ ./obj_basic$(nW) $(nW)/testfile1 o
+obj_basic/TEST1: Done
-- 
GitLab