X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fut_test.go;h=5072cf4fbc96d8af3d8b00849a2898277b3bf28f;hb=de457a14f98c546fdb009e9915745ef398388ddd;hp=7d27412ba925a9412da2dfa8a783e136bc5f15a0;hpb=896c3acac45d9e23300072e0cf544bf728396066;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/ut_test.go b/pkg/control/ut_test.go index 7d27412..5072cf4 100644 --- a/pkg/control/ut_test.go +++ b/pkg/control/ut_test.go @@ -20,11 +20,14 @@ package control import ( + "os" + "testing" + "time" + "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub" "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststubdummy" "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststube2ap" - "os" - "testing" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" ) //----------------------------------------------------------------------------- @@ -32,10 +35,15 @@ import ( //----------------------------------------------------------------------------- func CaseBegin(desc string) *teststub.TestWrapper { tent := teststub.NewTestWrapper(desc) - tent.Logger.Info(desc) + tent.Info(desc) return tent } +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +const teststubPortSeed int = 55555 + //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- @@ -49,7 +57,7 @@ var mainCtrl *testingSubmgrControl var dummystub *teststubdummy.RmrDummyStub -func ut_test_init() { +func ut_test_init() func() { tent := CaseBegin("ut_test_init") //--------------------------------- @@ -96,7 +104,7 @@ func ut_test_init() { defer os.Remove(cfgfilename) os.Setenv("CFG_FILE", cfgfilename) */ - tent.Logger.Info("Using cfg file %s", os.Getenv("CFG_FILE")) + tent.Info("Using cfg file %s", os.Getenv("CFG_FILE")) //--------------------------------- // Static routetable for rmr @@ -106,87 +114,119 @@ func ut_test_init() { // If XID is not matching xapp stub will just // drop message. (Messages 12011, 12012, 12021, 12022) // - // NOTE2: 55555 message type is for stub rmr connectivity probing + // NOTE2: teststubPortSeed message type is for stub rmr connectivity probing // // NOTE3: Ports per entity: // - // Port Entity + // Entity // ------------------- - // 14560 submgr - // 15560 e2term1 stub - // 15660 e2term2 stub - // 13560 xapp1 stub - // 13660 xapp2 stub - // 16560 dummy stub - // + + mainsrc := teststub.RmrSrcId{xapp.RmrEndpoint{"localhost", 14560}} + xapp1src := teststub.RmrSrcId{xapp.RmrEndpoint{"localhost", 13560}} + xapp2src := teststub.RmrSrcId{xapp.RmrEndpoint{"localhost", 13660}} + e2term1src := teststub.RmrSrcId{xapp.RmrEndpoint{"localhost", 15560}} + e2term2src := teststub.RmrSrcId{xapp.RmrEndpoint{"localhost", 15660}} + dummysrc := teststub.RmrSrcId{xapp.RmrEndpoint{"localhost", 16560}} + //--------------------------------- rt := &teststub.RmrRouteTable{} - rt.AddRoute(12010, "", -1, "localhost:14560") - rt.AddRoute(12010, "localhost:14560", -1, "%meid") - rt.AddRoute(12011, "localhost:15560", -1, "localhost:14560") - rt.AddRoute(12012, "localhost:15560", -1, "localhost:14560") - rt.AddRoute(12011, "localhost:15660", -1, "localhost:14560") - rt.AddRoute(12012, "localhost:15660", -1, "localhost:14560") - rt.AddRoute(12011, "localhost:14560", -1, "localhost:13660;localhost:13560") - rt.AddRoute(12012, "localhost:14560", -1, "localhost:13660;localhost:13560") - rt.AddRoute(12020, "", -1, "localhost:14560") - rt.AddRoute(12020, "localhost:14560", -1, "%meid") - rt.AddRoute(12021, "localhost:15560", -1, "localhost:14560") - rt.AddRoute(12022, "localhost:15560", -1, "localhost:14560") - rt.AddRoute(12021, "localhost:15660", -1, "localhost:14560") - rt.AddRoute(12022, "localhost:15660", -1, "localhost:14560") - rt.AddRoute(12021, "localhost:14560", -1, "localhost:13660;localhost:13560") - rt.AddRoute(12022, "localhost:14560", -1, "localhost:13660;localhost:13560") - rt.AddRoute(55555, "", -1, "localhost:13660;localhost:13560;localhost:15560;localhost:15660;localhost:16560") - - rt.AddMeid("localhost:15560", []string{"RAN_NAME_1", "RAN_NAME_2"}) - rt.AddMeid("localhost:15660", []string{"RAN_NAME_11", "RAN_NAME_12"}) - - rtfilename, _ := teststub.CreateTmpFile(rt.GetTable()) - defer os.Remove(rtfilename) - tent.Logger.Info("table[%s]", rt.GetTable()) + rt.AddRoute(12010, "", -1, mainsrc.String()) + rt.AddRoute(12010, mainsrc.String(), -1, "%meid") + rt.AddRoute(12011, e2term1src.String(), -1, mainsrc.String()) + rt.AddRoute(12012, e2term1src.String(), -1, mainsrc.String()) + rt.AddRoute(12011, e2term2src.String(), -1, mainsrc.String()) + rt.AddRoute(12012, e2term2src.String(), -1, mainsrc.String()) + rt.AddRoute(12011, mainsrc.String(), -1, xapp2src.String()+";"+xapp1src.String()) + rt.AddRoute(12012, mainsrc.String(), -1, xapp2src.String()+";"+xapp1src.String()) + rt.AddRoute(12020, "", -1, mainsrc.String()) + rt.AddRoute(12020, mainsrc.String(), -1, "%meid") + rt.AddRoute(12021, e2term1src.String(), -1, mainsrc.String()) + rt.AddRoute(12022, e2term1src.String(), -1, mainsrc.String()) + rt.AddRoute(12021, e2term2src.String(), -1, mainsrc.String()) + rt.AddRoute(12022, e2term2src.String(), -1, mainsrc.String()) + rt.AddRoute(12021, mainsrc.String(), -1, xapp2src.String()+";"+xapp1src.String()) + rt.AddRoute(12022, mainsrc.String(), -1, xapp2src.String()+";"+xapp1src.String()) + rt.AddRoute(teststubPortSeed, "", -1, xapp2src.String()+";"+xapp1src.String()+";"+e2term1src.String()+";"+e2term2src.String()+";"+dummysrc.String()) + + rt.AddMeid(e2term1src.String(), []string{"RAN_NAME_1", "RAN_NAME_2"}) + rt.AddMeid(e2term2src.String(), []string{"RAN_NAME_11", "RAN_NAME_12"}) + + rt.Enable() + tent.Info("rttable[%s]", rt.Table()) + //--------------------------------- // //--------------------------------- - tent.Logger.Info("### submgr ctrl run ###") - mainCtrl = createSubmgrControl(rtfilename, "14560") + tent.Info("### submgr ctrl run ###") + mainCtrl = createSubmgrControl(mainsrc, teststub.RmrRtgSvc{}) + + // + // Tweak to get around with fact that alarm package alternates RMR_SEED_RT environment variable + // + //xapp-frame inits alarms when readycb is coming from xapps rmr + //alarm will make new rmr instance and overrides RMR_SEED_RT and RMR_RTG_SVC + //env variables. Re-create rt info. + for i := 0; i < int(10)*2; i++ { + if os.Getenv("RMR_SEED_RT") == rt.FileName() { + tent.Info("Waiting that alarm alternates RMR_SEED_RT=%s", os.Getenv("RMR_SEED_RT")) + time.Sleep(500 * time.Millisecond) + } else { + tent.Info("Alarm has alternated RMR_SEED_RT=%s, so waiting 0.5 secs before restoring it", os.Getenv("RMR_SEED_RT")) + time.Sleep(500 * time.Millisecond) + rt.Enable() + tent.Info("rttable[%s]", rt.Table()) + break + } + } + + if os.Getenv("RMR_SEED_RT") != rt.FileName() { + tent.Error("Unittest timing issue with alarm RMR_SEED_RT=%s", os.Getenv("RMR_SEED_RT")) + os.Exit(1) + } //--------------------------------- // //--------------------------------- - tent.Logger.Info("### xapp1 stub run ###") - xappConn1 = teststube2ap.CreateNewE2Stub("xappstub1", rtfilename, "13560", "RMRXAPP1STUB", 55555) + tent.Info("### xapp1 stub run ###") + xappConn1 = teststube2ap.CreateNewE2Stub("xappstub1", xapp1src, teststub.RmrRtgSvc{}, "RMRXAPP1STUB", teststubPortSeed, "RAN_NAME_1", "localhost", 13560, 8080) //--------------------------------- // //--------------------------------- - tent.Logger.Info("### xapp2 stub run ###") - xappConn2 = teststube2ap.CreateNewE2Stub("xappstub2", rtfilename, "13660", "RMRXAPP2STUB", 55555) + tent.Info("### xapp2 stub run ###") + xappConn2 = teststube2ap.CreateNewE2Stub("xappstub2", xapp2src, teststub.RmrRtgSvc{}, "RMRXAPP2STUB", teststubPortSeed, "RAN_NAME_2", "localhost", 13660, 8080) //--------------------------------- // //--------------------------------- - tent.Logger.Info("### e2term1 stub run ###") - e2termConn1 = teststube2ap.CreateNewE2termStub("e2termstub1", rtfilename, "15560", "RMRE2TERMSTUB1", 55555) + tent.Info("### e2term1 stub run ###") + e2termConn1 = teststube2ap.CreateNewE2termStub("e2termstub1", e2term1src, teststub.RmrRtgSvc{}, "RMRE2TERMSTUB1", teststubPortSeed) //--------------------------------- // //--------------------------------- - tent.Logger.Info("### e2term2 stub run ###") - e2termConn2 = teststube2ap.CreateNewE2termStub("e2termstub2", rtfilename, "15660", "RMRE2TERMSTUB2", 55555) + tent.Info("### e2term2 stub run ###") + e2termConn2 = teststube2ap.CreateNewE2termStub("e2termstub2", e2term2src, teststub.RmrRtgSvc{}, "RMRE2TERMSTUB2", teststubPortSeed) //--------------------------------- // Just to test dummy stub //--------------------------------- - tent.Logger.Info("### dummy stub run ###") - dummystub = teststubdummy.CreateNewRmrDummyStub("dummystub", rtfilename, "16560", "DUMMYSTUB", 55555) + tent.Info("### dummy stub run ###") + dummystub = teststubdummy.CreateNewRmrDummyStub("dummystub", dummysrc, teststub.RmrRtgSvc{}, "DUMMYSTUB", teststubPortSeed) //--------------------------------- // Testing message sending //--------------------------------- - if teststub.RmrStubControlWaitAlive(10, 55555, mainCtrl.c) == false { + if teststub.RmrStubControlWaitAlive(10, teststubPortSeed, mainCtrl.c.RMRClient, tent) == false { + os.Exit(1) + } + + if os.Getenv("RMR_SEED_RT") != rt.FileName() { + tent.Error("Unittest timing issue with alarm RMR_SEED_RT=%s", os.Getenv("RMR_SEED_RT")) os.Exit(1) } + + return func() { rt.Disable() } } //----------------------------------------------------------------------------- @@ -194,7 +234,8 @@ func ut_test_init() { //----------------------------------------------------------------------------- func TestMain(m *testing.M) { CaseBegin("TestMain start") - ut_test_init() + cleanfn := ut_test_init() code := m.Run() + cleanfn() os.Exit(code) }