Debian Codegraph @

message/message_test.go

raw symbols SCIP
1 // Copyright 2016 VMware, Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package message
16
17 import (
18 "os"
19 "testing"
20
21 "github.com/vmware/vmw-guestinfo/internal"
22 "github.com/vmware/vmw-guestinfo/vmcheck"
23 )
24
25 const rpciProtocolNum uint32 = 0x49435052
26 const tcloProtocol uint32 = 0x4f4c4354
27
28 func TestOpenClose(t *testing.T) {
29 l := DefaultLogger.(*logger)
30 l.DebugLevel = true
31
32 isVm, err := vmcheck.IsVirtualWorld(true)
33 if err != nil || !isVm {
34 t.Skip("Not in a virtual world")
35 return
36 }
37
38 ch, err := NewChannel(rpciProtocolNum)
39 internal.AssertNotNil(t, ch)
40 internal.AssertNoError(t, err)
41
42 // check low bandwidth
43 ch.forceLowBW = true
44 err = ch.Send([]byte("info-get guestinfo.doesnotexistdoesnotexit"))
45 internal.AssertNoError(t, err)
46
47 b, err := ch.Receive()
48 internal.AssertNoError(t, err)
49 internal.AssertNotNil(t, b)
50
51 internal.AssertEqual(t, "0 No value found", string(b))
52
53 internal.AssertNoError(t, ch.Close())
54
55 // check high bandwidth
56 ch, err = NewChannel(rpciProtocolNum)
57 internal.AssertNotNil(t, ch)
58 internal.AssertNoError(t, err)
59
60 err = ch.Send([]byte("info-get guestinfo.doesnotexistdoesnotexit"))
61 internal.AssertNoError(t, err)
62
63 b, err = ch.Receive()
64 internal.AssertNoError(t, err)
65 internal.AssertNotNil(t, b)
66
67 internal.AssertEqual(t, "0 No value found", string(b))
68
69 internal.AssertNoError(t, ch.Close())
70 }
71
72 // Test we can reply to the rpcin
73 func TestReset(t *testing.T) {
74 l := DefaultLogger.(*logger)
75 l.DebugLevel = true
76
77 isVm, err := vmcheck.IsVirtualWorld(true)
78 if err != nil || !isVm {
79 t.Skip("Not in a virtual world")
80 return
81 }
82
83 if os.Getenv("TEST_TOOLBOX") == "" {
84 t.Skip("Skipping toolbox test")
85 return
86 }
87
88 ch, err := NewChannel(tcloProtocol)
89 internal.AssertNotNil(t, ch)
90 defer ch.Close()
91 internal.AssertNoError(t, err)
92
93 var buf []byte
94
95 for {
96 _ = ch.Send(buf)
97 request, _ := ch.Receive()
98
99 if len(request) == 0 {
100 continue
101 }
102
103 if string(request) == "reset" {
104 break
105 }
106 }
107
108 reply := "OK ATR toolbox"
109 err = ch.Send([]byte(reply))
110 internal.AssertNoError(t, err)
111 }