qmp: support command 'query-qmp-schema'

The upper hyervisor manager application maybe need to wait some
QMP event to control boot sequence, but the event we wanted maybe
not exist in some older version, so we need query all QMP ABI and
check the event is supported or not.

related: kata-containers/runtime#1918

Signed-off-by: Ning Bo <ning.bo9@zte.com.cn>
This commit is contained in:
Ning Bo
2019-08-01 09:05:27 +08:00
parent e0505242c0
commit 79e0d5333d
2 changed files with 71 additions and 0 deletions

View File

@@ -1588,3 +1588,38 @@ func TestMainLoopEventBeforeGreeting(t *testing.T) {
q.Shutdown()
<-disconnectedCh
}
func TestQMPExecQueryQmpSchema(t *testing.T) {
connectedCh := make(chan *QMPVersion)
disconnectedCh := make(chan struct{})
buf := newQMPTestCommandBuffer(t)
schemaInfo := []SchemaInfo{
{
MetaType: "command",
Name: "object-add",
},
{
MetaType: "event",
Name: "VSOCK_RUNNING",
},
}
buf.AddCommand("query-qmp-schema", nil, "return", schemaInfo)
cfg := QMPConfig{
Logger: qmpTestLogger{},
MaxCapacity: 1024,
}
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
checkVersion(t, connectedCh)
info, err := q.ExecQueryQmpSchema(context.Background())
if err != nil {
t.Fatalf("Unexpected error: %v\n", err)
}
if len(schemaInfo) != 2 {
t.Fatalf("Expected schema infos length equals to 2\n")
}
if reflect.DeepEqual(info, schemaInfo) == false {
t.Fatalf("Expected %v equals to %v\n", info, schemaInfo)
}
q.Shutdown()
<-disconnectedCh
}