2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
23 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub"
24 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
32 type testingSubmgrControl struct {
37 func createSubmgrControl(rtfile string, port string) *testingSubmgrControl {
38 mainCtrl = &testingSubmgrControl{}
39 mainCtrl.RmrControl.Init("SUBMGRCTL", rtfile, port)
40 mainCtrl.c = NewControl()
41 xapp.SetReadyCB(mainCtrl.ReadyCB, nil)
42 go xapp.RunWithParams(mainCtrl.c, false)
44 mainCtrl.c.ReadyCB(nil)
48 func (mc *testingSubmgrControl) wait_registry_empty(t *testing.T, secs int) bool {
51 for ; i <= secs*2; i++ {
52 cnt = len(mc.c.registry.register)
56 time.Sleep(500 * time.Millisecond)
58 mc.TestError(t, "(submgr) no registry empty within %d secs: %d", secs, cnt)
62 func (mc *testingSubmgrControl) wait_subs_clean(t *testing.T, e2SubsId uint32, secs int) bool {
63 var subs *Subscription
65 for ; i <= secs*2; i++ {
66 subs = mc.c.registry.GetSubscription(e2SubsId)
70 time.Sleep(500 * time.Millisecond)
73 mc.TestError(t, "(submgr) no clean within %d secs: %s", secs, subs.String())
75 mc.TestError(t, "(submgr) no clean within %d secs: subs(N/A)", secs)
80 func (mc *testingSubmgrControl) wait_subs_trans_clean(t *testing.T, e2SubsId uint32, secs int) bool {
81 var trans TransactionIf
83 for ; i <= secs*2; i++ {
84 subs := mc.c.registry.GetSubscription(e2SubsId)
88 trans = subs.GetTransaction()
92 time.Sleep(500 * time.Millisecond)
95 mc.TestError(t, "(submgr) no clean within %d secs: %s", secs, trans.String())
97 mc.TestError(t, "(submgr) no clean within %d secs: trans(N/A)", secs)
102 func (mc *testingSubmgrControl) get_subid(t *testing.T) uint32 {
103 mc.c.registry.mutex.Lock()
104 defer mc.c.registry.mutex.Unlock()
105 return mc.c.registry.subIds[0]
108 func (mc *testingSubmgrControl) wait_subid_change(t *testing.T, origSubId uint32, secs int) (uint32, bool) {
110 for ; i <= secs*2; i++ {
111 mc.c.registry.mutex.Lock()
112 currSubId := mc.c.registry.subIds[0]
113 mc.c.registry.mutex.Unlock()
114 if currSubId != origSubId {
115 return currSubId, true
117 time.Sleep(500 * time.Millisecond)
119 mc.TestError(t, "(submgr) no subId change within %d secs", secs)
123 func (mc *testingSubmgrControl) get_msgcounter(t *testing.T) uint64 {
124 return mc.c.CntRecvMsg
127 func (mc *testingSubmgrControl) wait_msgcounter_change(t *testing.T, orig uint64, secs int) (uint64, bool) {
129 for ; i <= secs*2; i++ {
130 curr := mc.c.CntRecvMsg
134 time.Sleep(500 * time.Millisecond)
136 mc.TestError(t, "(submgr) no msg counter change within %d secs", secs)