[CRIU] [PATCH 3/4] criu2text: add test

Ruslan Kuprieiev kupruser at gmail.com
Fri Sep 19 06:53:12 PDT 2014


Dump loop.sh, convert images into text format and back.
Compare those images with original ones using cmp.

Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 tools/criu2text/Makefile        |  7 ++++++-
 tools/criu2text/test/.gitignore |  3 +++
 tools/criu2text/test/Makefile   | 14 ++++++++++++++
 tools/criu2text/test/loop.sh    |  4 ++++
 tools/criu2text/test/test.sh    | 25 +++++++++++++++++++++++++
 5 files changed, 52 insertions(+), 1 deletion(-)
 create mode 100644 tools/criu2text/test/.gitignore
 create mode 100644 tools/criu2text/test/Makefile
 create mode 100755 tools/criu2text/test/loop.sh
 create mode 100644 tools/criu2text/test/test.sh

diff --git a/tools/criu2text/Makefile b/tools/criu2text/Makefile
index 986f426..597f71e 100644
--- a/tools/criu2text/Makefile
+++ b/tools/criu2text/Makefile
@@ -1,7 +1,8 @@
-.PHONY: all clean protobuf
+.PHONY: all clean protobuf test
 
 PROTOBUF_DIR	= ../../protobuf
 MAGIC_C_HEADER	= ../../include/magic.h
+CRIU		= ../../criu
 
 all: magic.py protobuf
 
@@ -11,5 +12,9 @@ magic.py: $(MAGIC_C_HEADER) protobuf
 protobuf:
 	protoc -I=$(PROTOBUF_DIR) --python_out=./ $(PROTOBUF_DIR)/*.proto
 
+test: protobuf magic.py
+	make -C test CRIU=$(realpath $(CRIU))
+
 clean:
+	make -C test clean
 	rm -rf *.pyc *_pb2.py __pycache__ magic.py
diff --git a/tools/criu2text/test/.gitignore b/tools/criu2text/test/.gitignore
new file mode 100644
index 0000000..4323d15
--- /dev/null
+++ b/tools/criu2text/test/.gitignore
@@ -0,0 +1,3 @@
+images_img
+images_text
+images_text_img
diff --git a/tools/criu2text/test/Makefile b/tools/criu2text/test/Makefile
new file mode 100644
index 0000000..947472d
--- /dev/null
+++ b/tools/criu2text/test/Makefile
@@ -0,0 +1,14 @@
+all: images_img test
+
+images_img:
+	mkdir $@
+	setsid ./loop.sh < /dev/null &> /dev/null & \
+	$(CRIU) dump -v4 -o dump.log -D $@ -t $${!} --shell-job
+
+test: images_img
+	mkdir -p images_text
+	mkdir -p images_text_img
+	bash test.sh
+
+clean:
+	rm -rf images_img images_text images_text_img
diff --git a/tools/criu2text/test/loop.sh b/tools/criu2text/test/loop.sh
new file mode 100755
index 0000000..0ab34ce
--- /dev/null
+++ b/tools/criu2text/test/loop.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+while :; do
+	sleep 1
+done
diff --git a/tools/criu2text/test/test.sh b/tools/criu2text/test/test.sh
new file mode 100644
index 0000000..f17a362
--- /dev/null
+++ b/tools/criu2text/test/test.sh
@@ -0,0 +1,25 @@
+images_list=$(cd images_img; ls -1 *.img)
+
+function _exit {
+	if [ $? -ne 0 ]; then
+		echo "FAIL"
+		exit -1
+	fi
+}
+
+for x in $images_list
+do
+	echo "===  $x"
+	if [[ $x == pages* ]]; then
+		echo "skip"
+		continue
+	fi
+
+	echo " -- to text"
+	../criu2text to-text images_img/"$x" -o images_text/ || _exit $?
+	echo " -- to img"
+	../criu2text to-img images_text/"$x" -o images_text_img/ || _exit $?
+	echo " -- cmp"
+	cmp images_img/"$x" images_text_img/"$x" || _exit $?
+	echo "=== done"
+done
-- 
1.9.3



More information about the CRIU mailing list