[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH nbdkit v2 4/4] info: Add tests for time, uptime and conntime modes.



---
 tests/Makefile.am           |  6 ++++
 tests/test-info-conntime.sh | 65 +++++++++++++++++++++++++++++++++++
 tests/test-info-time.sh     | 68 +++++++++++++++++++++++++++++++++++++
 tests/test-info-uptime.sh   | 65 +++++++++++++++++++++++++++++++++++
 4 files changed, 204 insertions(+)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5a65db7..abcce94 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -76,6 +76,9 @@ EXTRA_DIST = \
 	test-info-address.sh \
 	test-info-base64.sh \
 	test-info-raw.sh \
+	test-info-time.sh \
+	test-info-uptime.sh \
+	test-info-conntime.sh \
 	test-ip.sh \
 	test-iso.sh \
 	test-layers.sh \
@@ -542,6 +545,9 @@ TESTS += \
 	test-info-address.sh \
 	test-info-base64.sh \
 	test-info-raw.sh \
+	test-info-time.sh \
+	test-info-uptime.sh \
+	test-info-conntime.sh \
 	$(NULL)
 
 # iso plugin test.
diff --git a/tests/test-info-conntime.sh b/tests/test-info-conntime.sh
new file mode 100755
index 0000000..046d1a1
--- /dev/null
+++ b/tests/test-info-conntime.sh
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+# nbdkit
+# Copyright (C) 2018-2019 Red Hat Inc.
+#
+# 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 Red Hat 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 RED HAT 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 RED HAT 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.
+
+# Test the info plugin with mode=conntime.
+
+source ./functions.sh
+set -e
+set -x
+
+requires nbdsh --version
+
+sock=`mktemp -u`
+files="info-conntime.out info-conntime.pid $sock"
+rm -f $files
+cleanup_fn rm -f $files
+
+# Run nbdkit.
+start_nbdkit -P info-conntime.pid -U $sock info mode=conntime
+
+export sock
+nbdsh -c - <<'EOF'
+import os
+import time
+
+h.connect_unix (os.environ["sock"])
+
+size = h.get_size ()
+assert size == 12
+
+buf = h.pread (size, 0)
+secs = int.from_bytes (buf[0:8], byteorder='big')
+usecs = int.from_bytes (buf[8:12], byteorder='big')
+print ("%d, %d" % (secs, usecs))
+
+assert abs (secs) <= 60
+EOF
diff --git a/tests/test-info-time.sh b/tests/test-info-time.sh
new file mode 100755
index 0000000..c3e82e8
--- /dev/null
+++ b/tests/test-info-time.sh
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+# nbdkit
+# Copyright (C) 2018-2019 Red Hat Inc.
+#
+# 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 Red Hat 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 RED HAT 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 RED HAT 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.
+
+# Test the info plugin with mode=time.
+
+source ./functions.sh
+set -e
+set -x
+
+requires nbdsh --version
+
+sock=`mktemp -u`
+files="info-time.out info-time.pid $sock"
+rm -f $files
+cleanup_fn rm -f $files
+
+# Run nbdkit.
+start_nbdkit -P info-time.pid -U $sock info mode=time
+
+export sock
+nbdsh -c - <<'EOF'
+import os
+import time
+
+h.connect_unix (os.environ["sock"])
+
+size = h.get_size ()
+assert size == 12
+
+buf = h.pread (size, 0)
+secs = int.from_bytes (buf[0:8], byteorder='big')
+usecs = int.from_bytes (buf[8:12], byteorder='big')
+print ("%d, %d" % (secs, usecs))
+
+# Assume it's correct if it's within 60 seconds of
+# our time.  Obviously it should be much closer.
+expected = int (time.time ())
+assert abs (secs - expected) <= 60
+EOF
diff --git a/tests/test-info-uptime.sh b/tests/test-info-uptime.sh
new file mode 100755
index 0000000..ccae4fc
--- /dev/null
+++ b/tests/test-info-uptime.sh
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+# nbdkit
+# Copyright (C) 2018-2019 Red Hat Inc.
+#
+# 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 Red Hat 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 RED HAT 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 RED HAT 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.
+
+# Test the info plugin with mode=uptime.
+
+source ./functions.sh
+set -e
+set -x
+
+requires nbdsh --version
+
+sock=`mktemp -u`
+files="info-uptime.out info-uptime.pid $sock"
+rm -f $files
+cleanup_fn rm -f $files
+
+# Run nbdkit.
+start_nbdkit -P info-uptime.pid -U $sock info mode=uptime
+
+export sock
+nbdsh -c - <<'EOF'
+import os
+import time
+
+h.connect_unix (os.environ["sock"])
+
+size = h.get_size ()
+assert size == 12
+
+buf = h.pread (size, 0)
+secs = int.from_bytes (buf[0:8], byteorder='big')
+usecs = int.from_bytes (buf[8:12], byteorder='big')
+print ("%d, %d" % (secs, usecs))
+
+assert abs (secs) <= 60
+EOF
-- 
2.23.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]