qtest: implement QTEST_STOP
It is quite difficult to debug qtest test cases without extra wrapper scripts for QEMU or similar. This patch adds a simple environment variable-based trigger that sends a STOP signal to the QEMU instance under test, before attempting to connect to its QMP session. This will block execution of the testcase and give time to attach a debugger to the stopped QEMU process. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
		
							parent
							
								
									610b823ef6
								
							
						
					
					
						commit
						e0fea6b1e4
					
				@ -85,6 +85,22 @@ static int socket_accept(int sock)
 | 
				
			|||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static pid_t qtest_qemu_pid(QTestState *s)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    FILE *f;
 | 
				
			||||||
 | 
					    char buffer[1024];
 | 
				
			||||||
 | 
					    pid_t pid = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    f = fopen(s->pid_file, "r");
 | 
				
			||||||
 | 
					    if (f) {
 | 
				
			||||||
 | 
					        if (fgets(buffer, sizeof(buffer), f)) {
 | 
				
			||||||
 | 
					            pid = atoi(buffer);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    fclose(f);
 | 
				
			||||||
 | 
					    return pid;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QTestState *qtest_init(const char *extra_args)
 | 
					QTestState *qtest_init(const char *extra_args)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QTestState *s;
 | 
					    QTestState *s;
 | 
				
			||||||
@ -136,27 +152,23 @@ QTestState *qtest_init(const char *extra_args)
 | 
				
			|||||||
    qtest_qmp(s, "");
 | 
					    qtest_qmp(s, "");
 | 
				
			||||||
    qtest_qmp(s, "{ 'execute': 'qmp_capabilities' }");
 | 
					    qtest_qmp(s, "{ 'execute': 'qmp_capabilities' }");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (getenv("QTEST_STOP")) {
 | 
				
			||||||
 | 
					        kill(qtest_qemu_pid(s), SIGSTOP);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return s;
 | 
					    return s;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void qtest_quit(QTestState *s)
 | 
					void qtest_quit(QTestState *s)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    FILE *f;
 | 
					    int status;
 | 
				
			||||||
    char buffer[1024];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    f = fopen(s->pid_file, "r");
 | 
					 | 
				
			||||||
    if (f) {
 | 
					 | 
				
			||||||
        if (fgets(buffer, sizeof(buffer), f)) {
 | 
					 | 
				
			||||||
            pid_t pid = atoi(buffer);
 | 
					 | 
				
			||||||
            int status = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pid_t pid = qtest_qemu_pid(s);
 | 
				
			||||||
 | 
					    if (pid != -1) {
 | 
				
			||||||
        kill(pid, SIGTERM);
 | 
					        kill(pid, SIGTERM);
 | 
				
			||||||
        waitpid(pid, &status, 0);
 | 
					        waitpid(pid, &status, 0);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        fclose(f);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    unlink(s->pid_file);
 | 
					    unlink(s->pid_file);
 | 
				
			||||||
    unlink(s->socket_path);
 | 
					    unlink(s->socket_path);
 | 
				
			||||||
    unlink(s->qmp_socket_path);
 | 
					    unlink(s->qmp_socket_path);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user