aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/libqtest.c45
-rwxr-xr-xtests/qemu-iotests/04028
-rwxr-xr-xtests/qemu-iotests/0712
4 files changed, 37 insertions, 39 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 1aed2249ff..9ba9d96b6b 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -4,6 +4,7 @@ check-qint
check-qjson
check-qlist
check-qstring
+check-qom-interface
test-aio
test-bitops
test-throttle
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 359d571a06..c9a4f89451 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -43,9 +43,8 @@ struct QTestState
int qmp_fd;
bool irq_level[MAX_IRQ];
GString *rx;
- gchar *pid_file; /* QEMU PID file */
int child_pid; /* Child process created to execute QEMU */
- char *socket_path, *qmp_socket_path;
+ pid_t qemu_pid; /* QEMU process spawned by our child */
};
#define g_assert_no_errno(ret) do { \
@@ -90,13 +89,13 @@ static int socket_accept(int sock)
return ret;
}
-static pid_t qtest_qemu_pid(QTestState *s)
+static pid_t read_pid_file(const char *pid_file)
{
FILE *f;
char buffer[1024];
pid_t pid = -1;
- f = fopen(s->pid_file, "r");
+ f = fopen(pid_file, "r");
if (f) {
if (fgets(buffer, sizeof(buffer), f)) {
pid = atoi(buffer);
@@ -110,6 +109,8 @@ QTestState *qtest_init(const char *extra_args)
{
QTestState *s;
int sock, qmpsock, i;
+ gchar *socket_path;
+ gchar *qmp_socket_path;
gchar *pid_file;
gchar *command;
const char *qemu_binary;
@@ -120,12 +121,12 @@ QTestState *qtest_init(const char *extra_args)
s = g_malloc(sizeof(*s));
- s->socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
- s->qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
+ socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
+ qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
pid_file = g_strdup_printf("/tmp/qtest-%d.pid", getpid());
- sock = init_socket(s->socket_path);
- qmpsock = init_socket(s->qmp_socket_path);
+ sock = init_socket(socket_path);
+ qmpsock = init_socket(qmp_socket_path);
pid = fork();
if (pid == 0) {
@@ -136,8 +137,8 @@ QTestState *qtest_init(const char *extra_args)
"-pidfile %s "
"-machine accel=qtest "
"-display none "
- "%s", qemu_binary, s->socket_path,
- s->qmp_socket_path, pid_file,
+ "%s", qemu_binary, socket_path,
+ qmp_socket_path, pid_file,
extra_args ?: "");
execlp("/bin/sh", "sh", "-c", command, NULL);
exit(1);
@@ -145,9 +146,12 @@ QTestState *qtest_init(const char *extra_args)
s->fd = socket_accept(sock);
s->qmp_fd = socket_accept(qmpsock);
+ unlink(socket_path);
+ unlink(qmp_socket_path);
+ g_free(socket_path);
+ g_free(qmp_socket_path);
s->rx = g_string_new("");
- s->pid_file = pid_file;
s->child_pid = pid;
for (i = 0; i < MAX_IRQ; i++) {
s->irq_level[i] = false;
@@ -157,8 +161,12 @@ QTestState *qtest_init(const char *extra_args)
qtest_qmp_discard_response(s, "");
qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
+ s->qemu_pid = read_pid_file(pid_file);
+ unlink(pid_file);
+ g_free(pid_file);
+
if (getenv("QTEST_STOP")) {
- kill(qtest_qemu_pid(s), SIGSTOP);
+ kill(s->qemu_pid, SIGSTOP);
}
return s;
@@ -168,21 +176,14 @@ void qtest_quit(QTestState *s)
{
int status;
- pid_t pid = qtest_qemu_pid(s);
- if (pid != -1) {
- kill(pid, SIGTERM);
- waitpid(pid, &status, 0);
+ if (s->qemu_pid != -1) {
+ kill(s->qemu_pid, SIGTERM);
+ waitpid(s->qemu_pid, &status, 0);
}
close(s->fd);
close(s->qmp_fd);
g_string_free(s->rx, true);
- unlink(s->pid_file);
- unlink(s->socket_path);
- unlink(s->qmp_socket_path);
- g_free(s->pid_file);
- g_free(s->socket_path);
- g_free(s->qmp_socket_path);
g_free(s);
}
diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040
index 72eaad5b08..734b6a6bb4 100755
--- a/tests/qemu-iotests/040
+++ b/tests/qemu-iotests/040
@@ -35,12 +35,8 @@ test_img = os.path.join(iotests.test_dir, 'test.img')
class ImageCommitTestCase(iotests.QMPTestCase):
'''Abstract base class for image commit test cases'''
- def assert_no_active_commit(self):
- result = self.vm.qmp('query-block-jobs')
- self.assert_qmp(result, 'return', [])
-
def run_commit_test(self, top, base):
- self.assert_no_active_commit()
+ self.assert_no_active_block_jobs()
result = self.vm.qmp('block-commit', device='drive0', top=top, base=base)
self.assert_qmp(result, 'return', {})
@@ -59,7 +55,7 @@ class ImageCommitTestCase(iotests.QMPTestCase):
self.assert_qmp(event, 'data/len', self.image_len)
self.vm.qmp('block-job-complete', device='drive0')
- self.assert_no_active_commit()
+ self.assert_no_active_block_jobs()
self.vm.shutdown()
class TestSingleDrive(ImageCommitTestCase):
@@ -91,19 +87,19 @@ class TestSingleDrive(ImageCommitTestCase):
self.assert_qmp(result, 'error/class', 'DeviceNotFound')
def test_top_same_base(self):
- self.assert_no_active_commit()
+ self.assert_no_active_block_jobs()
result = self.vm.qmp('block-commit', device='drive0', top='%s' % backing_img, base='%s' % backing_img)
self.assert_qmp(result, 'error/class', 'GenericError')
self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % backing_img)
def test_top_invalid(self):
- self.assert_no_active_commit()
+ self.assert_no_active_block_jobs()
result = self.vm.qmp('block-commit', device='drive0', top='badfile', base='%s' % backing_img)
self.assert_qmp(result, 'error/class', 'GenericError')
self.assert_qmp(result, 'error/desc', 'Top image file badfile not found')
def test_base_invalid(self):
- self.assert_no_active_commit()
+ self.assert_no_active_block_jobs()
result = self.vm.qmp('block-commit', device='drive0', top='%s' % mid_img, base='badfile')
self.assert_qmp(result, 'error/class', 'GenericError')
self.assert_qmp(result, 'error/desc', 'Base \'badfile\' not found')
@@ -114,13 +110,13 @@ class TestSingleDrive(ImageCommitTestCase):
self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed"))
def test_top_and_base_reversed(self):
- self.assert_no_active_commit()
+ self.assert_no_active_block_jobs()
result = self.vm.qmp('block-commit', device='drive0', top='%s' % backing_img, base='%s' % mid_img)
self.assert_qmp(result, 'error/class', 'GenericError')
self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % mid_img)
def test_top_omitted(self):
- self.assert_no_active_commit()
+ self.assert_no_active_block_jobs()
result = self.vm.qmp('block-commit', device='drive0')
self.assert_qmp(result, 'error/class', 'GenericError')
self.assert_qmp(result, 'error/desc', "Parameter 'top' is missing")
@@ -181,19 +177,19 @@ class TestRelativePaths(ImageCommitTestCase):
self.assert_qmp(result, 'error/class', 'DeviceNotFound')
def test_top_same_base(self):
- self.assert_no_active_commit()
+ self.assert_no_active_block_jobs()
result = self.vm.qmp('block-commit', device='drive0', top='%s' % self.mid_img, base='%s' % self.mid_img)
self.assert_qmp(result, 'error/class', 'GenericError')
self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % self.mid_img)
def test_top_invalid(self):
- self.assert_no_active_commit()
+ self.assert_no_active_block_jobs()
result = self.vm.qmp('block-commit', device='drive0', top='badfile', base='%s' % self.backing_img)
self.assert_qmp(result, 'error/class', 'GenericError')
self.assert_qmp(result, 'error/desc', 'Top image file badfile not found')
def test_base_invalid(self):
- self.assert_no_active_commit()
+ self.assert_no_active_block_jobs()
result = self.vm.qmp('block-commit', device='drive0', top='%s' % self.mid_img, base='badfile')
self.assert_qmp(result, 'error/class', 'GenericError')
self.assert_qmp(result, 'error/desc', 'Base \'badfile\' not found')
@@ -204,7 +200,7 @@ class TestRelativePaths(ImageCommitTestCase):
self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', self.backing_img_abs).find("verification failed"))
def test_top_and_base_reversed(self):
- self.assert_no_active_commit()
+ self.assert_no_active_block_jobs()
result = self.vm.qmp('block-commit', device='drive0', top='%s' % self.backing_img, base='%s' % self.mid_img)
self.assert_qmp(result, 'error/class', 'GenericError')
self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % self.mid_img)
@@ -229,7 +225,7 @@ class TestSetSpeed(ImageCommitTestCase):
os.remove(backing_img)
def test_set_speed(self):
- self.assert_no_active_commit()
+ self.assert_no_active_block_jobs()
self.vm.pause_drive('drive0')
result = self.vm.qmp('block-commit', device='drive0', top=mid_img, speed=1024 * 1024)
diff --git a/tests/qemu-iotests/071 b/tests/qemu-iotests/071
index 2a22546e1a..dbc07c6c4f 100755
--- a/tests/qemu-iotests/071
+++ b/tests/qemu-iotests/071
@@ -38,7 +38,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
. ./common.rc
. ./common.filter
-_supported_fmt generic
+_supported_fmt qcow2
_supported_proto generic
_supported_os Linux