File: crit-test.sh

package info (click to toggle)
golang-github-checkpoint-restore-go-criu 7.2.0%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 1,796 kB
  • sloc: makefile: 231; ansic: 195; python: 137; sh: 110
file content (87 lines) | stat: -rwxr-xr-x 2,239 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash

set -x

CRIT=../../crit/bin/crit
TEST_IMG_DIR=test-imgs/loop

function gen_img_list {
	images_list=$(find "$TEST_IMG_DIR" -regex '^[^\.]*\.img$')
	if [ -z "$images_list" ]; then
		echo "Failed to generate images"
		exit 1
	fi
}

function recode_test {
	for x in $images_list
	do
		echo "=== $x"
		if [[ $x == *pages* ]]; then
			echo "=== SKIP"
			continue
		fi

		echo "  -- to json"
		$CRIT decode -i "$x" -o "$x"".json" --pretty || exit $?
		echo "  -- to img"
		$CRIT encode -i "$x"".json" -o "$x"".json.img" || exit $?
		echo "  -- cmp"
		cmp "$x" "$x"".json.img" || exit $?

		echo "=== done"
	done
}

function command_test {
	PROTO_IN="$TEST_IMG_DIR"/inventory.img
	JSON_IN=$(mktemp -p "$TEST_IMG_DIR" tmp.XXXXXXXXXX.json)
	OUT=$(mktemp -p "$TEST_IMG_DIR" tmp.XXXXXXXXXX.img)

	# prepare
	$CRIT decode -i "$PROTO_IN" -o "$JSON_IN"

	# proto in - json out decode
	$CRIT decode -i "$PROTO_IN" || exit 1
	$CRIT decode -i "$PROTO_IN" -o "$OUT" || exit 1
	$CRIT decode -i "$PROTO_IN" > "$OUT" || exit 1
	$CRIT decode < "$PROTO_IN" || exit 1
	$CRIT decode -o "$OUT" < "$PROTO_IN" || exit 1
	$CRIT decode < "$PROTO_IN" > "$OUT" || exit 1

	# json in - proto out decode -> should fail
	$CRIT decode -i "$JSON_IN" || true
	$CRIT decode -i "$JSON_IN" -o "$OUT" || true
	$CRIT decode -i "$JSON_IN" > "$OUT" || true

	# json in - proto out encode
	$CRIT encode -i "$JSON_IN" || exit 1
	$CRIT encode -i "$JSON_IN" -o "$OUT" || exit 1
	$CRIT encode -i "$JSON_IN" > "$OUT" || exit 1
	$CRIT encode < "$JSON_IN" || exit 1
	$CRIT encode -o "$OUT" < "$JSON_IN" || exit 1
	$CRIT encode < "$JSON_IN" > "$OUT" || exit 1

	# proto in - json out encode -> should fail
	$CRIT encode -i "$PROTO_IN" || true
	$CRIT encode -i "$PROTO_IN" -o "$OUT" || true
	$CRIT encode -i "$PROTO_IN" > "$OUT" || true

	# test info and show commands
	$CRIT info "$PROTO_IN" || exit 1
	$CRIT show "$PROTO_IN" || exit 1

	# explore image directory
	$CRIT x "$TEST_IMG_DIR" ps || exit 1
	$CRIT x "$TEST_IMG_DIR" fd || exit 1
	$CRIT x "$TEST_IMG_DIR" mem || exit 1
	$CRIT x "$TEST_IMG_DIR" rss || exit 1
	$CRIT x "$TEST_IMG_DIR" sk || exit 1
}

echo "Generating image list..."
gen_img_list
echo "Testing recode..."
recode_test
echo "Testing commands..."
command_test