ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Copyright (c) 2019 AT&T Intellectual Property. |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | *******************************************************************************/ |
ss412g | 697bea2 | 2019-12-24 22:38:19 +0200 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 21 | * platform project (RICP). |
| 22 | */ |
| 23 | |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 24 | package e2pdus |
| 25 | |
| 26 | import ( |
| 27 | "e2mgr/logger" |
| 28 | "fmt" |
| 29 | "strings" |
| 30 | "testing" |
| 31 | ) |
| 32 | |
| 33 | func TestPrepareEndcConfigurationUpdateFailurePDU(t *testing.T) { |
rimverma | 4cd92f9 | 2023-04-25 11:51:14 +0530 | [diff] [blame] | 34 | InfoLevel:= int8(3) |
| 35 | _,err := logger.InitLogger(InfoLevel) |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 36 | if err!=nil{ |
| 37 | t.Errorf("failed to initialize logger, error: %s", err) |
| 38 | } |
| 39 | packedPdu := "402500080000010005400142" |
| 40 | packedEndcConfigurationUpdateFailure := PackedEndcConfigurationUpdateFailure |
| 41 | |
| 42 | tmp := fmt.Sprintf("%x", packedEndcConfigurationUpdateFailure) |
| 43 | if len(tmp) != len(packedPdu) { |
| 44 | t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcConfigurationUpdateFailure)/2) |
| 45 | } |
| 46 | |
| 47 | if strings.Compare(tmp, packedPdu) != 0 { |
| 48 | t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | func TestPrepareEndcConfigurationUpdateFailurePDUFailure(t *testing.T) { |
rimverma | 4cd92f9 | 2023-04-25 11:51:14 +0530 | [diff] [blame] | 53 | InfoLevel:= int8(3) |
| 54 | _, err := logger.InitLogger(InfoLevel) |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 55 | if err != nil { |
| 56 | t.Errorf("failed to initialize logger, error: %s", err) |
| 57 | } |
| 58 | |
| 59 | err = prepareEndcConfigurationUpdateFailurePDU(1, 4096) |
| 60 | if err == nil { |
| 61 | t.Errorf("want: error, got: success.\n") |
| 62 | } |
| 63 | |
| 64 | expected:= "#configuration_update.prepareEndcConfigurationUpdateFailurePDU - failed to build and pack the endc configuration update failure message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big" |
| 65 | if !strings.Contains(err.Error(), expected) { |
| 66 | t.Errorf("want :[%s], got: [%s]\n", expected, err) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | func TestPrepareX2EnbConfigurationUpdateFailurePDU(t *testing.T) { |
rimverma | 4cd92f9 | 2023-04-25 11:51:14 +0530 | [diff] [blame] | 71 | InfoLevel := int8(3) |
| 72 | _,err := logger.InitLogger(InfoLevel) |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 73 | if err!=nil{ |
| 74 | t.Errorf("failed to initialize logger, error: %s", err) |
| 75 | } |
| 76 | packedPdu := "400800080000010005400142" |
| 77 | packedEndcX2ConfigurationUpdateFailure := PackedX2EnbConfigurationUpdateFailure |
| 78 | |
| 79 | tmp := fmt.Sprintf("%x", packedEndcX2ConfigurationUpdateFailure) |
| 80 | if len(tmp) != len(packedPdu) { |
| 81 | t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcX2ConfigurationUpdateFailure)/2) |
| 82 | } |
| 83 | |
| 84 | if strings.Compare(tmp, packedPdu) != 0 { |
| 85 | t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | func TestPrepareX2EnbConfigurationUpdateFailurePDUFailure(t *testing.T) { |
rimverma | 4cd92f9 | 2023-04-25 11:51:14 +0530 | [diff] [blame] | 90 | InfoLevel:= int8(3) |
| 91 | _, err := logger.InitLogger(InfoLevel) |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 92 | if err != nil { |
| 93 | t.Errorf("failed to initialize logger, error: %s", err) |
| 94 | } |
| 95 | |
| 96 | err = prepareX2EnbConfigurationUpdateFailurePDU(1, 4096) |
| 97 | if err == nil { |
| 98 | t.Errorf("want: error, got: success.\n") |
| 99 | } |
| 100 | |
| 101 | expected:= "#configuration_update.prepareX2EnbConfigurationUpdateFailurePDU - failed to build and pack the x2 configuration update failure message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big" |
| 102 | if !strings.Contains(err.Error(), expected) { |
| 103 | t.Errorf("want :[%s], got: [%s]\n", expected, err) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | func TestPrepareEndcConfigurationUpdateAckPDU(t *testing.T) { |
rimverma | 4cd92f9 | 2023-04-25 11:51:14 +0530 | [diff] [blame] | 108 | InfoLevel := int8(3) |
| 109 | _,err := logger.InitLogger(InfoLevel) |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 110 | if err!=nil{ |
| 111 | t.Errorf("failed to initialize logger, error: %s", err) |
| 112 | } |
| 113 | packedPdu := "2025000a00000100f70003000000" |
| 114 | packedEndcConfigurationUpdateAck := PackedEndcConfigurationUpdateAck |
| 115 | |
| 116 | tmp := fmt.Sprintf("%x", packedEndcConfigurationUpdateAck) |
| 117 | if len(tmp) != len(packedPdu) { |
| 118 | t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcConfigurationUpdateAck)/2) |
| 119 | } |
| 120 | |
| 121 | if strings.Compare(tmp, packedPdu) != 0 { |
| 122 | t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | func TestPrepareEndcConfigurationUpdateAckPDUFailure(t *testing.T) { |
rimverma | 4cd92f9 | 2023-04-25 11:51:14 +0530 | [diff] [blame] | 127 | InfoLevel := int8(3) |
| 128 | _, err := logger.InitLogger(InfoLevel) |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 129 | if err != nil { |
| 130 | t.Errorf("failed to initialize logger, error: %s", err) |
| 131 | } |
| 132 | |
| 133 | err = prepareEndcConfigurationUpdateAckPDU(1, 4096) |
| 134 | if err == nil { |
| 135 | t.Errorf("want: error, got: success.\n") |
| 136 | } |
| 137 | |
| 138 | expected:= "#configuration_update.prepareEndcConfigurationUpdateAckPDU - failed to build and pack the endc configuration update ack message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big" |
| 139 | if !strings.Contains(err.Error(), expected) { |
| 140 | t.Errorf("want :[%s], got: [%s]\n", expected, err) |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | func TestPrepareX2EnbConfigurationUpdateAckPDU(t *testing.T) { |
rimverma | 4cd92f9 | 2023-04-25 11:51:14 +0530 | [diff] [blame] | 145 | InfoLevel:= int8(3) |
| 146 | _,err := logger.InitLogger(InfoLevel) |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 147 | if err!=nil{ |
| 148 | t.Errorf("failed to initialize logger, error: %s", err) |
| 149 | } |
| 150 | packedPdu := "200800080000010011400100" |
| 151 | packedEndcX2ConfigurationUpdateAck := PackedX2EnbConfigurationUpdateAck |
| 152 | |
| 153 | tmp := fmt.Sprintf("%x", packedEndcX2ConfigurationUpdateAck) |
| 154 | if len(tmp) != len(packedPdu) { |
| 155 | t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcX2ConfigurationUpdateAck)/2) |
| 156 | } |
| 157 | |
| 158 | if strings.Compare(tmp, packedPdu) != 0 { |
| 159 | t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp) |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | func TestPrepareX2EnbConfigurationUpdateAckPDUFailure(t *testing.T) { |
rimverma | 4cd92f9 | 2023-04-25 11:51:14 +0530 | [diff] [blame] | 164 | InfoLevel:= int8(3) |
| 165 | _, err := logger.InitLogger(InfoLevel) |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 166 | if err != nil { |
| 167 | t.Errorf("failed to initialize logger, error: %s", err) |
| 168 | } |
| 169 | |
| 170 | err = prepareX2EnbConfigurationUpdateAckPDU(1, 4096) |
| 171 | if err == nil { |
| 172 | t.Errorf("want: error, got: success.\n") |
| 173 | } |
| 174 | |
| 175 | expected:= "#configuration_update.prepareX2EnbConfigurationUpdateAckPDU - failed to build and pack the x2 configuration update ack message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big" |
| 176 | if !strings.Contains(err.Error(), expected) { |
| 177 | t.Errorf("want :[%s], got: [%s]\n", expected, err) |
| 178 | } |
rimverma | 4cd92f9 | 2023-04-25 11:51:14 +0530 | [diff] [blame] | 179 | } |