From ea20cf62699cf44a092df6ede7c2f481b9ce5b84 Mon Sep 17 00:00:00 2001 From: BenceJanosSzabo <bence.janos.szabo@ericsson.com> Date: Mon, 30 Jan 2017 13:45:49 +0100 Subject: [PATCH] TITAN throws DTE when send operation is applied on non mapped ports (artf817538) Change-Id: I0d7053c65a9a596eea0f997bf570a0cb4e4dbbb9 Signed-off-by: BenceJanosSzabo <bence.janos.szabo@ericsson.com> --- compiler2/ttcn3/port.c | 10 +- .../commMessage/AddressPortNegTest.ttcn | 123 ++++++++++++++++++ regression_test/commMessage/Makefile | 14 +- regression_test/commMessage/config-rt2.cfg | 2 + regression_test/commMessage/config.cfg | 2 + .../commMessage/config_parallel-rt2.cfg | 3 +- .../commMessage/config_parallel.cfg | 2 + 7 files changed, 149 insertions(+), 7 deletions(-) create mode 100644 regression_test/commMessage/AddressPortNegTest.ttcn diff --git a/compiler2/ttcn3/port.c b/compiler2/ttcn3/port.c index 45fba3875..1aa49c95e 100644 --- a/compiler2/ttcn3/port.c +++ b/compiler2/ttcn3/port.c @@ -17,6 +17,7 @@ * Kremer, Peter * Raduly, Csaba * Szabados, Kristof + * Szabo, Bence Janos * Szabo, Janos Zoltan – initial implementation * ******************************************************************************/ @@ -1644,7 +1645,12 @@ void defPortClass(const port_def* pdef, output_struct* output) src = mputstr(src, "TTCN_error(\"Message cannot be sent to system " "on internal port %s.\", port_name);\n"); } else { - src = mputprintf(src, "outgoing_send(send_par%s);\n", + src = mputprintf(src, + "{\n" + // To generate DTE-s if not mapped or connected. + "(void)get_default_destination();\n" + "outgoing_send(send_par%s);\n" + "}\n", pdef->testport_type == ADDRESS ? ", NULL" : ""); } src = mputprintf(src, "else {\n" @@ -1680,6 +1686,8 @@ void defPortClass(const port_def* pdef, output_struct* output) " send_par.log()," " TTCN_Logger::end_event_log2str()));\n" "}\n", class_name, msg->name, pdef->address_name, msg->dispname); + // To generate DTE-s if not mapped or connected. + src = mputstr(src, "(void)get_default_destination();\n"); if (pdef->port_type != USER || (msg->nTargets == 1 && msg->targets[0].mapping_type == M_SIMPLE)) { src = mputstr(src, "outgoing_send(send_par, " diff --git a/regression_test/commMessage/AddressPortNegTest.ttcn b/regression_test/commMessage/AddressPortNegTest.ttcn new file mode 100644 index 000000000..b521902cc --- /dev/null +++ b/regression_test/commMessage/AddressPortNegTest.ttcn @@ -0,0 +1,123 @@ +/****************************************************************************** + * Copyright (c) 2000-2016 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Szabo, Bence Janos + * + ******************************************************************************/ +module AddressPortNegTest { + + type record SIP_address_type + { + charstring host optional, // hostname, IPv4 or IPv6 + integer portField optional, // represented as an integer + boolean tcporudp optional // true if TCP false if UDP + } + + + type SIP_address_type address; + + type port PortType1 message { + inout integer; + } with {extension "address"} + + type port PortType2 message { + inout integer; + } + + type component TestCaseComp { + port PortType1 p1; + } + + type component TestCaseComp2 { + port PortType2 p1; + } + + type component SystemComp { + port PortType1 p1; + } + + + testcase tc_neg_address_port_not_mapped() runs on TestCaseComp system SystemComp { + + var address v_addr := {"Host", 4400, false} + + @try { + p1.send(5) to v_addr; + setverdict(fail, "Send operation succeeded. Expected error."); + } + @catch (msg) { + if (match(msg, pattern "Dynamic test case error: Port p1 has neither connections nor mappings. Message cannot be sent on it.")) { + setverdict(pass); + } + else { + setverdict(fail, "Incorrect error message received (receive test): ", msg); + } + } + + // After map it is good + map(self:p1, system:p1); + p1.send(5) to v_addr; + + setverdict(pass); + } + + + + testcase tc_neg_address_port_not_mapped_system() runs on TestCaseComp system SystemComp { + + @try { + p1.send(5) to system; + setverdict(fail, "Send operation succeeded. Expected error."); + } + @catch (msg) { + if (match(msg, pattern "Dynamic test case error: Port p1 has neither connections nor mappings. Message cannot be sent on it.")) { + setverdict(pass); + } + else { + setverdict(fail, "Incorrect error message received (receive test): ", msg); + } + } + + // After map it is good + map(self:p1, system:p1); + p1.send(5) to system; + + setverdict(pass); + } + + + testcase tc_neg_port_not_mapped_system() runs on TestCaseComp2 system SystemComp { + + @try { + p1.send(5) to system; + setverdict(fail, "Send operation succeeded. Expected error."); + } + @catch (msg) { + if (match(msg, pattern "Dynamic test case error: Port p1 has neither connections nor mappings. Message cannot be sent on it.")) { + setverdict(pass); + } + else { + setverdict(fail, "Incorrect error message received (receive test): ", msg); + } + } + + // After map it is good + map(self:p1, system:p1); + p1.send(5) to system; + + setverdict(pass); + } + + control { + execute(tc_neg_address_port_not_mapped()); + execute(tc_neg_address_port_not_mapped_system()); + + execute(tc_neg_port_not_mapped_system()); + } + +} diff --git a/regression_test/commMessage/Makefile b/regression_test/commMessage/Makefile index ddb1f1a9b..58f4e1cf1 100644 --- a/regression_test/commMessage/Makefile +++ b/regression_test/commMessage/Makefile @@ -27,7 +27,7 @@ include $(TOPDIR)/Makefile.regression TTCN3_LIB = ttcn3$(RT2_SUFFIX)-parallel$(DYNAMIC_SUFFIX) TTCN3_LIB_SINGLE = ttcn3$(RT2_SUFFIX)$(DYNAMIC_SUFFIX) -TTCN3_MODULES = TcommMessage.ttcn HS41022.ttcn +TTCN3_MODULES = TcommMessage.ttcn HS41022.ttcn AddressPortNegTest.ttcn ifdef RT2 TTCN3_MODULES += TmultipleRedirects.ttcn @@ -46,7 +46,11 @@ GENERATED_SOURCES2 := $(foreach file, $(GENERATED_SOURCES:.cc=), $(addprefix $(f GENERATED_SOURCES += $(GENERATED_SOURCES2) endif -OBJECTS = $(GENERATED_SOURCES:.cc=.o) +PORT_SOURCES = PortType1.cc PortType2.cc +PORT_HEADERS = PortType1.hh PortType2.hh + + +OBJECTS = $(GENERATED_SOURCES:.cc=.o) $(PORT_SOURCES:.cc=.o) TARGET = TcommMessage$(EXESUFFIX) TARGET_SINGLE = TcommMessage_single$(EXESUFFIX) @@ -62,12 +66,12 @@ $(TARGET_SINGLE): $(OBJECTS) .cc.o: $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -$(GENERATED_SOURCES) $(GENERATED_HEADERS): $(TTCN3_MODULES) $(ASN1_MODULES) - $(TTCN3_COMPILER) $^ +$(GENERATED_SOURCES) $(GENERATED_HEADERS) $(PORT_SOURCES) $(PORT_HEADERS): $(TTCN3_MODULES) $(ASN1_MODULES) + $(TTCN3_COMPILER) -t $^ clean distclean: -rm -f $(TARGET) $(TARGET_SINGLE) $(OBJECTS) $(GENERATED_HEADERS) \ - $(GENERATED_SOURCES) *.log Makefile.bak + $(GENERATED_SOURCES) $(PORT_HEADERS) $(PORT_SOURCES) *.log Makefile.bak dep: $(GENERATED_SOURCES) makedepend $(CPPFLAGS) $(GENERATED_SOURCES) diff --git a/regression_test/commMessage/config-rt2.cfg b/regression_test/commMessage/config-rt2.cfg index 64b54d60f..453b2ecb9 100644 --- a/regression_test/commMessage/config-rt2.cfg +++ b/regression_test/commMessage/config-rt2.cfg @@ -9,6 +9,7 @@ # Balasko, Jeno # Baranyi, Botond # Dimitrov, Peter +# Szabo, Bence Janos # ############################################################################### [LOGGING] @@ -20,4 +21,5 @@ ConsoleMask := TTCN_ERROR | TTCN_TESTCASE | TTCN_STATISTICS TcommMessage.commMessageInterPTCLocalConnection1 TcommMessage.commMessageInterPTCLocalConnection2 TmultipleRedirects.control +AddressPortNegTest.control diff --git a/regression_test/commMessage/config.cfg b/regression_test/commMessage/config.cfg index 17046784a..7d3abb808 100644 --- a/regression_test/commMessage/config.cfg +++ b/regression_test/commMessage/config.cfg @@ -8,6 +8,7 @@ # Contributors: # Balasko, Jeno # Dimitrov, Peter +# Szabo, Bence Janos # ############################################################################### [LOGGING] @@ -18,4 +19,5 @@ ConsoleMask := TTCN_ERROR | TTCN_TESTCASE | TTCN_STATISTICS [EXECUTE] TcommMessage.commMessageInterPTCLocalConnection1 TcommMessage.commMessageInterPTCLocalConnection2 +AddressPortNegTest.control diff --git a/regression_test/commMessage/config_parallel-rt2.cfg b/regression_test/commMessage/config_parallel-rt2.cfg index d9202831f..f827d4169 100644 --- a/regression_test/commMessage/config_parallel-rt2.cfg +++ b/regression_test/commMessage/config_parallel-rt2.cfg @@ -8,6 +8,7 @@ # Contributors: # Balasko, Jeno # Baranyi, Botond +# Szabo, Bence Janos # ############################################################################### [LOGGING] @@ -19,4 +20,4 @@ ConsoleMask := TTCN_ERROR | TTCN_TESTCASE | TTCN_STATISTICS TcommMessage.control HS41022.control TmultipleRedirects.control - +AddressPortNegTest.control diff --git a/regression_test/commMessage/config_parallel.cfg b/regression_test/commMessage/config_parallel.cfg index 6f2151233..838d92f83 100644 --- a/regression_test/commMessage/config_parallel.cfg +++ b/regression_test/commMessage/config_parallel.cfg @@ -8,6 +8,7 @@ # Contributors: # Balasko, Jeno # Baranyi, Botond +# Szabo, Bence Janos # ############################################################################### [LOGGING] @@ -18,3 +19,4 @@ ConsoleMask := TTCN_ERROR | TTCN_TESTCASE | TTCN_STATISTICS [EXECUTE] TcommMessage.control HS41022.control +AddressPortNegTest.control \ No newline at end of file -- GitLab