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/xapp-frame/pkg/xapp"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
31 type testingSubmgrControl struct {
36 func createSubmgrControl(desc string, rtfile string, port string) *testingSubmgrControl {
37 mainCtrl = &testingSubmgrControl{}
38 mainCtrl.testingRmrControl.init(desc, rtfile, port)
39 mainCtrl.c = NewControl()
40 xapp.SetReadyCB(mainCtrl.ReadyCB, nil)
41 go xapp.RunWithParams(mainCtrl.c, false)
46 func (mc *testingSubmgrControl) wait_registry_empty(t *testing.T, secs int) bool {
49 for ; i <= secs*2; i++ {
50 cnt = len(mc.c.registry.register)
54 time.Sleep(500 * time.Millisecond)
56 testError(t, "(general) no registry empty within %d secs: %d", secs, cnt)
60 func (mc *testingSubmgrControl) wait_subs_clean(t *testing.T, e2SubsId uint32, secs int) bool {
61 var subs *Subscription
63 for ; i <= secs*2; i++ {
64 subs = mc.c.registry.GetSubscription(e2SubsId)
68 time.Sleep(500 * time.Millisecond)
71 testError(t, "(general) no clean within %d secs: %s", secs, subs.String())
73 testError(t, "(general) no clean within %d secs: subs(N/A)", secs)
78 func (mc *testingSubmgrControl) wait_subs_trans_clean(t *testing.T, e2SubsId uint32, secs int) bool {
79 var trans TransactionIf
81 for ; i <= secs*2; i++ {
82 subs := mc.c.registry.GetSubscription(e2SubsId)
86 trans = subs.GetTransaction()
90 time.Sleep(500 * time.Millisecond)
93 testError(t, "(general) no clean within %d secs: %s", secs, trans.String())
95 testError(t, "(general) no clean within %d secs: trans(N/A)", secs)
100 func (mc *testingSubmgrControl) get_subid(t *testing.T) uint32 {
101 mc.c.registry.mutex.Lock()
102 defer mc.c.registry.mutex.Unlock()
103 return mc.c.registry.subIds[0]
106 func (mc *testingSubmgrControl) wait_subid_change(t *testing.T, origSubId uint32, secs int) (uint32, bool) {
108 for ; i <= secs*2; i++ {
109 mc.c.registry.mutex.Lock()
110 currSubId := mc.c.registry.subIds[0]
111 mc.c.registry.mutex.Unlock()
112 if currSubId != origSubId {
113 return currSubId, true
115 time.Sleep(500 * time.Millisecond)
117 testError(t, "(general) no subId change within %d secs", secs)
121 func (mc *testingSubmgrControl) get_msgcounter(t *testing.T) uint64 {
122 return mc.c.msgCounter
125 func (mc *testingSubmgrControl) wait_msgcounter_change(t *testing.T, orig uint64, secs int) (uint64, bool) {
127 for ; i <= secs*2; i++ {
128 curr := mc.c.msgCounter
132 time.Sleep(500 * time.Millisecond)
134 testError(t, "(general) no msg counter change within %d secs", secs)