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(srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc) *testingSubmgrControl {
38 mainCtrl = &testingSubmgrControl{}
39 mainCtrl.RmrControl.Init("SUBMGRCTL", srcId, rtgSvc)
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) get_registry_next_subid(t *testing.T) uint32 {
63 mc.c.registry.mutex.Lock()
64 defer mc.c.registry.mutex.Unlock()
65 return mc.c.registry.subIds[0]
68 func (mc *testingSubmgrControl) wait_registry_next_subid_change(t *testing.T, origSubId uint32, secs int) (uint32, bool) {
70 for ; i <= secs*2; i++ {
71 mc.c.registry.mutex.Lock()
72 currSubId := mc.c.registry.subIds[0]
73 mc.c.registry.mutex.Unlock()
74 if currSubId != origSubId {
75 return currSubId, true
77 time.Sleep(500 * time.Millisecond)
79 mc.TestError(t, "(submgr) no subId change within %d secs", secs)
83 func (mc *testingSubmgrControl) wait_subs_clean(t *testing.T, e2SubsId uint32, secs int) bool {
84 var subs *Subscription
86 for ; i <= secs*2; i++ {
87 subs = mc.c.registry.GetSubscription(e2SubsId)
91 time.Sleep(500 * time.Millisecond)
94 mc.TestError(t, "(submgr) no clean within %d secs: %s", secs, subs.String())
96 mc.TestError(t, "(submgr) no clean within %d secs: subs(N/A)", secs)
101 func (mc *testingSubmgrControl) wait_subs_trans_clean(t *testing.T, e2SubsId uint32, secs int) bool {
102 var trans TransactionIf
104 for ; i <= secs*2; i++ {
105 subs := mc.c.registry.GetSubscription(e2SubsId)
109 trans = subs.GetTransaction()
113 time.Sleep(500 * time.Millisecond)
116 mc.TestError(t, "(submgr) no clean within %d secs: %s", secs, trans.String())
118 mc.TestError(t, "(submgr) no clean within %d secs: trans(N/A)", secs)
123 func (mc *testingSubmgrControl) get_subs_entrypoint_cnt(t *testing.T, origSubId uint32) int {
124 subs := mc.c.registry.GetSubscription(origSubId)
126 mc.TestError(t, "(submgr) no subs %d exists during entrypoint cnt get", origSubId)
129 return subs.EpList.Size()
132 func (mc *testingSubmgrControl) wait_subs_entrypoint_cnt_change(t *testing.T, origSubId uint32, orig int, secs int) (int, bool) {
134 subs := mc.c.registry.GetSubscription(origSubId)
136 mc.TestError(t, "(submgr) no subs %d exists during entrypoint cnt wait", origSubId)
141 for ; i <= secs*2; i++ {
142 curr := subs.EpList.Size()
146 time.Sleep(500 * time.Millisecond)
148 mc.TestError(t, "(submgr) no subs %d entrypoint cnt change within %d secs", origSubId, secs)
153 // Counter check for received message. Note might not be yet handled
155 func (mc *testingSubmgrControl) get_msgcounter(t *testing.T) uint64 {
156 return mc.c.CntRecvMsg
159 func (mc *testingSubmgrControl) wait_msgcounter_change(t *testing.T, orig uint64, secs int) (uint64, bool) {
161 for ; i <= secs*2; i++ {
162 curr := mc.c.CntRecvMsg
166 time.Sleep(500 * time.Millisecond)
168 mc.TestError(t, "(submgr) no msg counter change within %d secs", secs)