diff --git a/tests/meson.build b/tests/meson.build
index 5a2a499461..efbe99f55e 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -695,7 +695,6 @@ if conf.has('WITH_LIBVIRTD')
'virsh-read-bufsiz',
'virsh-read-non-seekable',
'virsh-self-test',
- 'virsh-snapshot',
'virsh-uriprecedence',
'virt-admin-self-test',
]
diff --git a/tests/virsh-snapshot b/tests/virsh-snapshot
deleted file mode 100755
index b09273917b..0000000000
--- a/tests/virsh-snapshot
+++ /dev/null
@@ -1,233 +0,0 @@
-#!/bin/sh
-# simple testing of snapshot APIs on test driver
-
-# Copyright (C) 2019 Red Hat, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see
-# .
-
-. "$(dirname $0)/test-lib.sh"
-
-test_expensive
-
-if test "$VERBOSE" = yes; then
- set -x
- $abs_top_builddir/tools/virsh --version
-fi
-
-fail=0
-
-mock_xdg_ || framework_failure
-
-# The test driver loses states between restarts, so we perform a script
-# with some convenient markers for later post-processing of output.
-$abs_top_builddir/tools/virsh --connect test:///default >out 2>err '
- # Create a series of snapshots, with names that intentionally sort
- # differently by topology than by name. Use revert to create fanout.
- snapshot-create-as test s1
- snapshot-create-as test s1
- snapshot-create-as test s3
- snapshot-create-as test s2
- snapshot-revert test s3
- snapshot-create-as test s6
- snapshot-create-as test s5
- snapshot-revert test s6
- snapshot-create-as test s4
- snapshot-revert test s1
- snapshot-create-as test s7
- snapshot-create-as test s8
- # checkpoints cannot be created while snapshots exist
- echo --err marker
- checkpoint-create-as test c1
- echo --err marker
- # Checking tree view (siblings sorted alphabetically)
- snapshot-list test --tree
- # Current was last one created, but we can change that
- snapshot-current test --name
- snapshot-current test s1
- snapshot-current test --name
- # Deleting current root leads to multiple roots, demonstrate list filtering
- snapshot-delete test --current
- echo --err marker
- snapshot-current test --name
- echo --err marker
- snapshot-list test --roots
- snapshot-list test --leaves
- snapshot-list test --parent --no-leaves
- snapshot-list test --from s3
- snapshot-list test --from s3 --descendants --name
- # More fun with delete flags, current node moves up to remaining parent
- snapshot-current test s4
- snapshot-delete test --children-only s6
- snapshot-current test --name
- snapshot-delete test --children s7
- snapshot-current test --name
- snapshot-delete test s6
- snapshot-current test --name
- # Now the tree is linear, so we have an unambiguous topological order
- snapshot-list test --name
- snapshot-list test --name --topological
- # Capture some XML for later redefine
- echo ""
- snapshot-dumpxml test s3
- echo ""
- snapshot-dumpxml test s2
- echo ""
- # All done
-' || fail=1
-
-# First part is expected output, --tree results in trailing spaces,
-# and snapshot-list produces timestamps
-sed 's/ *$//; s/[0-9-]\{10\} [0-9:.]* .[0-9]\{4\}/TIMESTAMP/;
- /MarkerA/,/MarkerC/d' < out > out.cooked || fail=1
-# Second part holds domain snapshot XMLs
-sed -n '/MarkerA/,/MarkerB/p' < out > s3.xml || fail=1
-sed -n '/MarkerB/,/MarkerC/p' < out > s2.xml || fail=1
-
-cat <<\EOF > exp || fail=1
-Domain snapshot s1 created
-
-Domain snapshot s3 created
-Domain snapshot s2 created
-Domain snapshot s3 reverted
-
-Domain snapshot s6 created
-Domain snapshot s5 created
-Domain snapshot s6 reverted
-
-Domain snapshot s4 created
-Domain snapshot s1 reverted
-
-Domain snapshot s7 created
-Domain snapshot s8 created
-
-
-
-s1
- |
- +- s3
- | |
- | +- s2
- | +- s6
- | |
- | +- s4
- | +- s5
- |
- +- s7
- |
- +- s8
-
-
-s8
-Snapshot s1 set as current
-s1
-Domain snapshot s1 deleted
-
-
-
-
- Name Creation Time State
----------------------------------------------
- s3 TIMESTAMP running
- s7 TIMESTAMP running
-
- Name Creation Time State
----------------------------------------------
- s2 TIMESTAMP running
- s4 TIMESTAMP running
- s5 TIMESTAMP running
- s8 TIMESTAMP running
-
- Name Creation Time State Parent
-------------------------------------------------------
- s3 TIMESTAMP running
- s6 TIMESTAMP running s3
- s7 TIMESTAMP running
-
- Name Creation Time State
----------------------------------------------
- s2 TIMESTAMP running
- s6 TIMESTAMP running
-
-s2
-s4
-s5
-s6
-
-Snapshot s4 set as current
-Domain snapshot s6 children deleted
-
-s6
-Domain snapshot s7 deleted
-
-s6
-Domain snapshot s6 deleted
-
-s3
-s2
-s3
-
-s3
-s2
-
-EOF
-compare exp out.cooked || fail=1
-
-cat < exp || fail=1
-error: operation failed: domain moment s1 already exists
-error: marker
-error: Operation not supported: cannot create checkpoint while snapshot exists
-error: marker
-error: marker
-error: domain 'test' has no current snapshot
-error: marker
-EOF
-compare exp err || fail=1
-
-# Restore state with redefine
-$abs_top_builddir/tools/virsh -c test:///default >out 2>err '
- # Redefine must be in topological order; this will fail
- snapshot-create test --redefine s2.xml --validate
- echo --err marker
- # This is the right order
- snapshot-create test --redefine s3.xml --validate
- snapshot-create test --redefine s2.xml --current --validate
- snapshot-info test --current
-' || fail=1
-
-cat <<\EOF > exp || fail=1
-
-
-Domain snapshot s3 created from 's3.xml'
-Domain snapshot s2 created from 's2.xml'
-Name: s2
-Domain: test
-Current: yes
-State: running
-Location: internal
-Parent: s3
-Children: 0
-Descendants: 0
-Metadata: yes
-
-EOF
-compare exp out || fail=1
-
-cat < exp || fail=1
-error: invalid argument: parent s3 for moment s2 not found
-error: marker
-EOF
-compare exp err || fail=1
-
-(exit $fail); exit $fail
diff --git a/tests/virshtest.c b/tests/virshtest.c
index aa10691f63..0250535119 100644
--- a/tests/virshtest.c
+++ b/tests/virshtest.c
@@ -218,6 +218,16 @@ mymain(void)
DO_TEST_FULL("domain-id-overflow", NULL, VIRSH_CUSTOM, "-q", "domname", "4294967298");
DO_TEST_FULL("schedinfo-invalid-argument", NULL, VIRSH_DEFAULT, "schedinfo", "1", "--set", "j=k");
+ DO_TEST_SCRIPT("snapshot", "
+ s2
+ running
+
+ s3
+
+ 1234
+
+
+
+
+
+ test
+ 6695eb01-f6a4-8304-79aa-97f2502e193f
+ 8388608
+ 2097152
+ 2
+
+ hvm
+
+
+
+ destroy
+ restart
+ destroy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/virshtestdata/snapshot-s3.xml b/tests/virshtestdata/snapshot-s3.xml
new file mode 100644
index 0000000000..80d65074e1
--- /dev/null
+++ b/tests/virshtestdata/snapshot-s3.xml
@@ -0,0 +1,40 @@
+
+ s3
+ running
+ 5678
+
+
+
+
+
+ test
+ 6695eb01-f6a4-8304-79aa-97f2502e193f
+ 8388608
+ 2097152
+ 2
+
+ hvm
+
+
+
+ destroy
+ restart
+ destroy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/virshtestdata/snapshot.in b/tests/virshtestdata/snapshot.in
new file mode 100755
index 0000000000..9e73db7ba7
--- /dev/null
+++ b/tests/virshtestdata/snapshot.in
@@ -0,0 +1,54 @@
+echo Create a series of snapshots, with names that intentionally sort
+echo differently by topology than by name. Use revert to create fanout.
+snapshot-create-as test s1
+snapshot-create-as test s1
+snapshot-create-as test s3
+snapshot-create-as test s2
+snapshot-revert test s3
+snapshot-create-as test s6
+snapshot-create-as test s5
+snapshot-revert test s6
+snapshot-create-as test s4
+snapshot-revert test s1
+snapshot-create-as test s7
+snapshot-create-as test s8
+
+echo checkpoints cannot be created while snapshots exist
+checkpoint-create-as test c1
+
+echo Checking tree view (siblings sorted alphabetically)
+snapshot-list test --tree
+
+echo Current was last one created, but we can change that
+snapshot-current test --name
+snapshot-current test s1
+snapshot-current test --name
+
+echo Deleting current root leads to multiple roots, demonstrate list filtering
+snapshot-delete test --current
+snapshot-current test --name
+
+echo list roots
+snapshot-list test --roots --name
+echo list leaves
+snapshot-list test --leaves --name
+echo list no-leaves
+snapshot-list test --parent --no-leaves --name
+echo list from
+snapshot-list test --from s3 --name
+snapshot-list test --from s3 --descendants --name
+
+echo More fun with delete flags, current node moves up to remaining parent
+snapshot-current test s4
+snapshot-delete test --children-only s6
+snapshot-current test --name
+snapshot-delete test --children s7
+snapshot-current test --name
+snapshot-delete test s6
+snapshot-current test --name
+
+echo Now the tree is linear, so we have an unambiguous topological order
+snapshot-list test --name
+snapshot-list test --name --topological
+snapshot-dumpxml test s3
+snapshot-dumpxml test s2
diff --git a/tests/virshtestdata/snapshot.out b/tests/virshtestdata/snapshot.out
new file mode 100644
index 0000000000..03268415d7
--- /dev/null
+++ b/tests/virshtestdata/snapshot.out
@@ -0,0 +1,173 @@
+Create a series of snapshots, with names that intentionally sort
+differently by topology than by name. Use revert to create fanout.
+Domain snapshot s1 created
+error: operation failed: domain moment s1 already exists
+
+Domain snapshot s3 created
+Domain snapshot s2 created
+Domain snapshot s3 reverted
+
+Domain snapshot s6 created
+Domain snapshot s5 created
+Domain snapshot s6 reverted
+
+Domain snapshot s4 created
+Domain snapshot s1 reverted
+
+Domain snapshot s7 created
+Domain snapshot s8 created
+checkpoints cannot be created while snapshots exist
+error: Operation not supported: cannot create checkpoint while snapshot exists
+
+Checking tree view (siblings sorted alphabetically)
+s1
+ |
+ +- s3
+ | |
+ | +- s2
+ | +- s6
+ | |
+ | +- s4
+ | +- s5
+ |
+ +- s7
+ |
+ +- s8
+
+
+Current was last one created, but we can change that
+s8
+Snapshot s1 set as current
+s1
+Deleting current root leads to multiple roots, demonstrate list filtering
+Domain snapshot s1 deleted
+
+error: domain 'test' has no current snapshot
+
+list roots
+s3
+s7
+
+list leaves
+s2
+s4
+s5
+s8
+
+list no-leaves
+s3
+s6 s3
+s7
+
+list from
+s2
+s6
+
+s2
+s4
+s5
+s6
+
+More fun with delete flags, current node moves up to remaining parent
+Snapshot s4 set as current
+Domain snapshot s6 children deleted
+
+s6
+Domain snapshot s7 deleted
+
+s6
+Domain snapshot s6 deleted
+
+s3
+Now the tree is linear, so we have an unambiguous topological order
+s2
+s3
+
+s3
+s2
+
+
+ s3
+ running
+
+
+
+
+
+
+ test
+ 6695eb01-f6a4-8304-79aa-97f2502e193f
+ 8388608
+ 2097152
+ 2
+
+ hvm
+
+
+
+ destroy
+ restart
+ destroy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ s2
+ running
+
+ s3
+
+
+
+
+
+
+
+ test
+ 6695eb01-f6a4-8304-79aa-97f2502e193f
+ 8388608
+ 2097152
+ 2
+
+ hvm
+
+
+
+ destroy
+ restart
+ destroy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+