summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErlang/OTP <otp@erlang.org>2020-12-04 17:35:57 +0100
committerErlang/OTP <otp@erlang.org>2020-12-04 17:35:57 +0100
commit3332c002f11c8c794aee3a94f97b19016edf1abb (patch)
treeb436154949d20460f22aac70a7f57c4352b8dd2f
parent62f602e74037cb4cfae32f36aa2eff9afa5a6f91 (diff)
parent03dc5cca250d8ee8f4f91d9a054291419c7b1ad6 (diff)
downloaderlang-3332c002f11c8c794aee3a94f97b19016edf1abb.tar.gz
Merge branch 'bmk/megaco/20201118/empty_statistics_descriptor/OTP-17012' into maint-22
* bmk/megaco/20201118/empty_statistics_descriptor/OTP-17012: [megaco|test] Add test cases for empty statistics descriptor [megaco] Empty statistics descriptor incorrectly not allowed # Conflicts: # lib/megaco/test/megaco_codec_v3_SUITE.erl
-rw-r--r--lib/megaco/src/text/megaco_text_gen_v3.hrl14
-rw-r--r--lib/megaco/src/text/megaco_text_parser_v3.hrl32
-rw-r--r--lib/megaco/src/text/megaco_text_parser_v3.yrl23
-rw-r--r--lib/megaco/test/megaco_codec_v3_SUITE.erl135
-rw-r--r--lib/megaco/test/megaco_test_lib.erl2
-rw-r--r--lib/megaco/test/megaco_test_msg_v3_lib.erl33
6 files changed, 196 insertions, 43 deletions
diff --git a/lib/megaco/src/text/megaco_text_gen_v3.hrl b/lib/megaco/src/text/megaco_text_gen_v3.hrl
index e440ec6651..8da58fff9a 100644
--- a/lib/megaco/src/text/megaco_text_gen_v3.hrl
+++ b/lib/megaco/src/text/megaco_text_gen_v3.hrl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2005-2019. All Rights Reserved.
+%% Copyright Ericsson AB 2005-2020. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -1152,7 +1152,9 @@ enc_ammDescriptor({Tag, Desc}, State) ->
statisticsDescriptor -> enc_StatisticsDescriptor(Desc, State);
_ ->
error({invalid_ammDescriptor_tag, Tag})
- end.
+ end;
+enc_ammDescriptor(Tag, State) when is_atom(Tag) ->
+ enc_ammDescriptor({Tag, []}, State).
enc_AmmsReply(#'AmmsReply'{terminationID = TIDs,
terminationAudit = asn1_NOVALUE}, State) ->
@@ -3208,14 +3210,20 @@ enc_PackagesItem(Val, State)
enc_StatisticsDescriptor({'StatisticsDescriptor',Val}, State) ->
enc_StatisticsDescriptor(Val, State);
-enc_StatisticsDescriptor(List, State) when is_list(List) ->
+enc_StatisticsDescriptor(List, State)
+ when is_list(List) andalso (List =/= []) ->
[
?StatsToken,
?LBRKT_INDENT(State),
enc_list([{List, fun enc_StatisticsParameter/2}], ?INC_INDENT(State)),
?RBRKT_INDENT(State)
+ ];
+enc_StatisticsDescriptor([], State) ->
+ [
+ ?StatsToken
].
+
enc_StatisticsParameter(Val, State)
when is_record(Val, 'StatisticsParameter') ->
PkgdName = ?META_ENC(statistics, Val#'StatisticsParameter'.statName),
diff --git a/lib/megaco/src/text/megaco_text_parser_v3.hrl b/lib/megaco/src/text/megaco_text_parser_v3.hrl
index 7b8fff2080..9d0afaa11b 100644
--- a/lib/megaco/src/text/megaco_text_parser_v3.hrl
+++ b/lib/megaco/src/text/megaco_text_parser_v3.hrl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2005-2019. All Rights Reserved.
+%% Copyright Ericsson AB 2005-2020. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -1740,6 +1740,36 @@ do_merge_control_streamParms([{SubTag, SD} | T] = All, LCD) ->
do_merge_control_streamParms([], LCD) ->
LCD.
+
+%% This is to get around the two defs:
+%%
+%% statisticsDescriptor = StatsToken [LBRKT statisticsParameter *(COMMA
+%% statisticsParameter) RBRKT]
+%%
+%% and
+%%
+%% auditReturnParameter = (mediaDescriptor / modemDescriptor / muxDescriptor /
+%% eventsDescriptor / signalsDescriptor /
+%% digitMapDescriptor / observedEventsDescriptor /
+%% eventBufferDescriptor / statisticsDescriptor /
+%% packagesDescriptor / errorDescriptor /
+%% auditReturnItem)
+%% auditReturnItem = (MuxToken / ModemToken / MediaToken /
+%% DigitMapToken / StatsToken / ObservedEventsToken /
+%% PackagesToken)
+%%
+%% In both statisticsDescriptor and auditReturnItem the StatsToken
+%% can occure on its owm => conflict
+
+-ifdef(megaco_parser_inline).
+-compile({inline,[{ensure_arp_statisticsDescriptor,1}]}).
+-endif.
+ensure_arp_statisticsDescriptor([]) ->
+ {auditReturnItem, statsToken};
+ensure_arp_statisticsDescriptor(SPs) ->
+ {statisticsDescriptor, SPs}.
+
+
-ifdef(megaco_parser_inline).
-compile({inline,[{merge_terminationStateDescriptor,1}]}).
-endif.
diff --git a/lib/megaco/src/text/megaco_text_parser_v3.yrl b/lib/megaco/src/text/megaco_text_parser_v3.yrl
index 7e382c33da..21283c68f8 100644
--- a/lib/megaco/src/text/megaco_text_parser_v3.yrl
+++ b/lib/megaco/src/text/megaco_text_parser_v3.yrl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2005-2016. All Rights Reserved.
+%% Copyright Ericsson AB 2005-2020. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -760,12 +760,13 @@ auditReturnParameter -> signalsDescriptor : {signalsDescriptor, '$1'} .
auditReturnParameter -> digitMapDescriptor : {digitMapDescriptor, '$1'} .
auditReturnParameter -> observedEventsDescriptor : {observedEventsDescriptor, '$1'} .
auditReturnParameter -> eventBufferDescriptor : {eventBufferDescriptor, '$1'} .
-auditReturnParameter -> statisticsDescriptor : {statisticsDescriptor, '$1'} .
+%% Conflict with 'empty' statisticsDescriptor and auditReturnItem (see below)
+auditReturnParameter -> statisticsDescriptor : ensure_arp_statisticsDescriptor('$1') .
auditReturnParameter -> packagesDescriptor : {packagesDescriptor, '$1'} .
auditReturnParameter -> errorDescriptor : {errorDescriptor, '$1'} .
auditReturnParameter -> auditReturnItem : {auditReturnItem, '$1'} .
-auditDescriptor -> 'AuditToken' 'LBRKT' auditDescriptorBody 'RBRKT' :
+auditDescriptor -> 'AuditToken' 'LBRKT' auditDescriptorBody 'RBRKT' :
merge_auditDescriptor('$3') .
auditDescriptorBody -> auditItem auditItemList : ['$1' | '$2'].
@@ -780,13 +781,16 @@ auditReturnItem -> 'MuxToken' : muxToken .
auditReturnItem -> 'ModemToken' : modemToken .
auditReturnItem -> 'MediaToken' : mediaToken .
auditReturnItem -> 'DigitMapToken' : digitMapToken .
-auditReturnItem -> 'StatsToken' : statsToken .
+%% Conflict with 'empty' statisticsDescriptor:
+%% auditReturnItem -> 'StatsToken' : statsToken .
auditReturnItem -> 'ObservedEventsToken' : observedEventsToken .
auditReturnItem -> 'PackagesToken' : packagesToken .
%% at-most-once, and DigitMapToken and PackagesToken are not allowed
%% in AuditCapabilities command
auditItem -> auditReturnItem : '$1' .
+%% Moved from ari above (conflict with 'empty' statisticsDescriptor)
+auditItem -> 'StatsToken' : statsToken.
auditItem -> 'SignalsToken' : signalsToken.
auditItem -> 'EventBufferToken' : eventBufferToken.
auditItem -> 'EventsToken' : eventsToken .
@@ -1095,11 +1099,13 @@ localParmList -> '$empty': [] .
terminationStateDescriptor -> 'TerminationStateToken'
'LBRKT' terminationStateParm
- terminationStateParms 'RBRKT'
- : merge_terminationStateDescriptor(['$3' | '$4']) .
+ terminationStateParms 'RBRKT' :
+ merge_terminationStateDescriptor(['$3' | '$4']) .
-terminationStateParms -> 'COMMA' terminationStateParm terminationStateParms : ['$2' | '$3'] .
-terminationStateParms -> '$empty' : [] .
+terminationStateParms -> 'COMMA' terminationStateParm terminationStateParms :
+ ['$2' | '$3'] .
+terminationStateParms -> '$empty' :
+ [] .
%% at-most-once per item except for propertyParm
localParm -> 'ReservedGroupToken' 'EQUAL' onOrOff : {group, '$3'} .
@@ -1504,6 +1510,7 @@ statisticsDescriptor -> 'StatsToken'
'LBRKT' statisticsParameter
statisticsParameters 'RBRKT'
: ['$3' | '$4'] .
+statisticsDescriptor -> 'StatsToken' : [] .
statisticsParameters -> 'COMMA' statisticsParameter statisticsParameters : ['$2' | '$3'] .
statisticsParameters -> '$empty' : [] .
diff --git a/lib/megaco/test/megaco_codec_v3_SUITE.erl b/lib/megaco/test/megaco_codec_v3_SUITE.erl
index 3089030aad..56a92b5f0a 100644
--- a/lib/megaco/test/megaco_codec_v3_SUITE.erl
+++ b/lib/megaco/test/megaco_codec_v3_SUITE.erl
@@ -1,8 +1,8 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 2006-2019. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 2006-2020. All Rights Reserved.
+%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
@@ -137,8 +137,10 @@
compact_otp16818_msg34/1,
compact_otp16818_msg35/1,
compact_otp16818_msg36/1,
-
- flex_compact_otp4299_msg1/1,
+ compact_erl1405_msg01/1,
+ compact_erl1405_msg02/1,
+
+ flex_compact_otp4299_msg1/1,
flex_compact_otp7431_msg01/1,
flex_compact_otp7431_msg02/1,
flex_compact_otp7431_msg03/1,
@@ -193,16 +195,18 @@
pretty_otp7671_msg04/1,
pretty_otp7671_msg05/1,
pretty_otp8114_msg01/1,
-
- flex_pretty_otp5042_msg1/1,
- flex_pretty_otp5085_msg1/1,
- flex_pretty_otp5085_msg2/1,
- flex_pretty_otp5085_msg3/1,
- flex_pretty_otp5085_msg4/1,
- flex_pretty_otp5085_msg5/1,
- flex_pretty_otp5085_msg6/1,
- flex_pretty_otp5085_msg7/1,
- flex_pretty_otp5085_msg8/1,
+ pretty_erl1405_msg01/1,
+ pretty_erl1405_msg02/1,
+
+ flex_pretty_otp5042_msg1/1,
+ flex_pretty_otp5085_msg1/1,
+ flex_pretty_otp5085_msg2/1,
+ flex_pretty_otp5085_msg3/1,
+ flex_pretty_otp5085_msg4/1,
+ flex_pretty_otp5085_msg5/1,
+ flex_pretty_otp5085_msg6/1,
+ flex_pretty_otp5085_msg7/1,
+ flex_pretty_otp5085_msg8/1,
flex_pretty_otp5600_msg1/1,
flex_pretty_otp5600_msg2/1,
flex_pretty_otp5601_msg1/1,
@@ -406,7 +410,6 @@ compact_tickets_cases() ->
compact_otp6017_msg01,
compact_otp6017_msg02,
compact_otp6017_msg03,
-
compact_otp16818_msg01,
compact_otp16818_msg02,
compact_otp16818_msg03,
@@ -430,7 +433,9 @@ compact_tickets_cases() ->
compact_otp16818_msg33,
compact_otp16818_msg34,
compact_otp16818_msg35,
- compact_otp16818_msg36
+ compact_otp16818_msg36,
+ compact_erl1405_msg01,
+ compact_erl1405_msg02
].
flex_compact_tickets_cases() ->
@@ -492,7 +497,9 @@ pretty_tickets_cases() ->
pretty_otp7671_msg03,
pretty_otp7671_msg04,
pretty_otp7671_msg05,
- pretty_otp8114_msg01
+ pretty_otp8114_msg01,
+ pretty_erl1405_msg01,
+ pretty_erl1405_msg02
].
flex_pretty_tickets_cases() ->
@@ -2222,7 +2229,6 @@ compact_otp6017_msg(CID) when is_integer(CID) ->
"{SC=root{SV{MT=RS,RE=901}}}}".
-
%% --------------------------------------------------------------
%%
compact_otp16818_msg01(suite) ->
@@ -2554,6 +2560,62 @@ compact_otp16818_msg(X) when is_list(X) ->
"] T=2523{C=-{SC=ROOT{SV{MT=RS,RE=901,PF=ETSI_BGF/2,V=3}}}}".
+%% --------------------------------------------------------------
+
+compact_erl1405_msg01(suite) ->
+ [];
+compact_erl1405_msg01(Config) when is_list(Config) ->
+ put(severity,trc),
+ put(dbg,true),
+ d("compact_erl1405_msg01 -> entry", []),
+ ?ACQUIRE_NODES(1, Config),
+ ok = compact_erl1405(statisticsDescriptor),
+ erase(severity),
+ erase(dbg),
+ ok.
+
+compact_erl1405_msg02(suite) ->
+ [];
+compact_erl1405_msg02(Config) when is_list(Config) ->
+ put(severity,trc),
+ put(dbg,true),
+ d("compact_erl1405_msg02 -> entry", []),
+ ?ACQUIRE_NODES(1, Config),
+ ok = compact_erl1405({statisticsDescriptor, []}),
+ erase(severity),
+ erase(dbg),
+ ok.
+
+compact_erl1405(Descriptor) ->
+ ticket_compact_encode_decode_ok( erl1405_msg(Descriptor) ).
+
+erl1405_msg(Descriptor) ->
+ #'MegacoMessage'{
+ mess = #'Message'{
+ version = ?VERSION,
+ mId = {deviceName, "test"},
+ messageBody = {transactions, [
+ {transactionRequest, #'TransactionRequest'{
+ transactionId = 1,
+ actions = [
+ #'ActionRequest'{
+ contextId = ?megaco_choose_context_id,
+ commandRequests = [
+ #'CommandRequest'{
+ command = {addReq, #'AmmRequest'{
+ terminationID = [#megaco_term_id{id = ["test"]}],
+ descriptors = [Descriptor]
+ }}
+ }
+ ]
+ }
+ ]
+ }}
+ ]}
+ }
+ }.
+
+
%% ==============================================================
%%
%% F l e x C o m p a c t T e s t c a s e s
@@ -4352,7 +4414,6 @@ cmp_otp7671_msg05(#'MegacoMessage'{authHeader = asn1_NOVALUE,
%% --------------------------------------------------------------
%%
-
pretty_otp8114_msg01(suite) ->
[];
pretty_otp8114_msg01(Config) when is_list(Config) ->
@@ -4437,6 +4498,38 @@ otp8114(InitialMessage, Codec, Conf) ->
megaco_codec_test_lib:expect_exec(Instructions, InitialData).
+
+%% --------------------------------------------------------------
+%%
+
+pretty_erl1405_msg01(suite) ->
+ [];
+pretty_erl1405_msg01(Config) when is_list(Config) ->
+ put(severity,trc),
+ put(dbg,true),
+ d("pretty_erl1405_msg01 -> entry", []),
+ ?ACQUIRE_NODES(1, Config),
+ ok = pretty_erl1405(statisticsDescriptor),
+ erase(severity),
+ erase(dbg),
+ ok.
+
+pretty_erl1405_msg02(suite) ->
+ [];
+pretty_erl1405_msg02(Config) when is_list(Config) ->
+ put(severity,trc),
+ put(dbg,true),
+ d("pretty_erl1405_msg02 -> entry", []),
+ ?ACQUIRE_NODES(1, Config),
+ ok = pretty_erl1405({statisticsDescriptor, []}),
+ erase(severity),
+ erase(dbg),
+ ok.
+
+pretty_erl1405(Descriptor) ->
+ ticket_pretty_encode_decode_ok( erl1405_msg(Descriptor) ).
+
+
%% ==============================================================
%%
%% F l e x P r e t t y T e s t c a s e s
@@ -5197,7 +5290,7 @@ msgs7(Encoding) ->
{msg78a07, msg78a07(), Plain, [{dbg,false}],[text,binary,erlang]},
{msg78a08, msg78a08(), Plain, [{dbg,false}],[text,binary,erlang]},
{msg78a09, msg78a09(), Plain, [{dbg,false}],[text,binary,erlang]},
- {msg79a01, msg79a01(), Plain, [{dbg,false}],[text,binary,erlang]}
+ {msg79a01, msg79a01(), Plain, [{dbg,true}],[text,binary,erlang]}
],
[{N,M,F,C}||{N,M,F,C,E} <- Msgs,lists:member(Encoding,E)].
diff --git a/lib/megaco/test/megaco_test_lib.erl b/lib/megaco/test/megaco_test_lib.erl
index bea2b92f46..2bf225dbee 100644
--- a/lib/megaco/test/megaco_test_lib.erl
+++ b/lib/megaco/test/megaco_test_lib.erl
@@ -495,7 +495,7 @@ init_per_suite(Config) ->
end;
(_) ->
false
- end,
+ end,
COND = [
{unix, [{linux, LinuxVersionVerify},
{darwin, DarwinVersionVerify}]},
diff --git a/lib/megaco/test/megaco_test_msg_v3_lib.erl b/lib/megaco/test/megaco_test_msg_v3_lib.erl
index 5264791370..8bb821b475 100644
--- a/lib/megaco/test/megaco_test_msg_v3_lib.erl
+++ b/lib/megaco/test/megaco_test_msg_v3_lib.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2006-2016. All Rights Reserved.
+%% Copyright Ericsson AB 2006-2020. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -3775,8 +3775,16 @@ is_AmmRequest_descriptors(Descs) ->
is_AmmRequest_descriptors([], _) ->
true;
-is_AmmRequest_descriptors([{Tag, _} = Desc|Descs], FoundDescs) ->
- d("is_AmmRequest_descriptors -> entry with"
+is_AmmRequest_descriptors([Desc|Descs], FoundDescs) ->
+ FoundDescs2 = is_AmmRequest_descriptor(Desc, FoundDescs),
+ is_AmmRequest_descriptors(Descs, FoundDescs2);
+is_AmmRequest_descriptors(Descs, _) ->
+ d("is_AmmRequest_descriptors -> entry with WRONG TYPE"
+ "~n Descs: ~p", [Descs]),
+ wrong_type('AmmRequest_descriptors', Descs).
+
+is_AmmRequest_descriptor({Tag, _} = Desc, FoundDescs) when is_atom(Tag) ->
+ d("is_AmmRequest_descriptor -> entry with"
"~n Tag: ~p"
"~n FoundDescs: ~p", [Tag, FoundDescs]),
case lists:member(Tag, FoundDescs) of
@@ -3785,15 +3793,13 @@ is_AmmRequest_descriptors([{Tag, _} = Desc|Descs], FoundDescs) ->
false ->
case is_AmmDescriptor(Desc) of
true ->
- is_AmmRequest_descriptors(Descs, [Tag|FoundDescs]);
+ [Tag|FoundDescs];
false ->
wrong_type('AmmRequest_descriptors', Desc)
end
end;
-is_AmmRequest_descriptors(Descs, _) ->
- d("is_AmmRequest_descriptors -> entry with WRONG TYPE"
- "~n Descs: ~p", [Descs]),
- wrong_type('AmmRequest_descriptors', Descs).
+is_AmmRequest_descriptor(Tag, FoundDescs) when is_atom(Tag) ->
+ is_AmmRequest_descriptor({Tag, []}, FoundDescs).
chk_AmmRequest(R, R) when is_record(R, 'AmmRequest') ->
@@ -3837,7 +3843,11 @@ chk_AmmRequest_descriptors([H|T1], [H|T2]) ->
wrong_type('AmmRequest_descriptors_val', H)
end;
chk_AmmRequest_descriptors([H1|T1], [H2|T2]) ->
- d("chk_AmmRequest_descriptors -> entry when not equal"),
+ d("chk_AmmRequest_descriptors -> entry when not equal: "
+ "~n H1: ~p"
+ "~n T1: ~p"
+ "~n H2: ~p"
+ "~n T2: ~p", [H1, T1, H2, T2]),
validate(fun() -> chk_AmmDescriptor(H1, H2) end,
'AmmRequest_descriptors_val'),
chk_AmmRequest_descriptors(T1, T2);
@@ -3885,6 +3895,11 @@ is_AmmDescriptor_val(statisticsDescriptor, D) ->
chk_AmmDescriptor(D, D) ->
chk_type(fun is_AmmDescriptor_tag/1, 'AmmDescriptor', D);
+%% There are two ways of spec an empty statisticsDescriptor:
+%% * statisticsDescriptor
+%% * {statisticsDescriptor, []}
+chk_AmmDescriptor(Tag, {Tag, []}) when (Tag =:= statisticsDescriptor) ->
+ ok;
chk_AmmDescriptor({Tag, Val1} = Cmd1, {Tag, Val2} = Cmd2) ->
case (is_AmmDescriptor_tag(Tag) andalso
is_AmmDescriptor_val(Tag, Val1) andalso