Commit cb2befc7 authored by Botond Baranyi's avatar Botond Baranyi
Browse files

Added discarding option to 'setstate' operation (bug 531339)



Change-Id: I5c68ac8d9ac01a4f46196ed6444611aa1c811040
Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent edb33cbb
......@@ -5791,6 +5791,7 @@ error:
case 1:
case 2:
case 3:
case 4:
break;
default:
error = true;
......@@ -5799,7 +5800,7 @@ error:
error = true;
}
if (error) {
setstate_op.val->error("The value of the first parameter must be 0, 1, 2 or 3.");
setstate_op.val->error("The value of the first parameter must be 0, 1, 2, 3 or 4.");
}
}
}
......
......@@ -212,7 +212,7 @@ static char *generate_send_mapping(char *src, const port_def *pdef,
}
if (!pdef->legacy && pdef->port_type == USER) {
src = mputprintf(src,
"} else if (port_state == FRAGMENTED) {\n"
"} else if (port_state == FRAGMENTED || port_state == DISCARDED) {\n"
"return;\n"
"} else if (port_state == UNSET) {\n"
"TTCN_error(\"The state of the port %%s remained unset after the mapping function %s finished.\", port_name);\n"
......@@ -418,7 +418,7 @@ static char *generate_incoming_mapping(char *src, const port_def *pdef,
"}");
if (pdef->port_type == USER && !pdef->legacy) {
src = mputprintf(src,
" else if (port_state == FRAGMENTED) {\n"
" else if (port_state == FRAGMENTED || port_state == DISCARDED) {\n"
"delete mapped_par;\n"
"return;\n"
"}"
......
......@@ -1534,6 +1534,9 @@ void LoggerPluginManager::log_setstate(const char *port_name, translation_port_s
case PARTIALLY_TRANSLATED:
setstate.state() = "partially translated";
break;
case DISCARDED:
setstate.state() = "discarded";
break;
default:
TTCN_Logger::fatal_error("LoggerPluginManager::log_setstate(): unexpected port state");
}
......
......@@ -126,9 +126,9 @@ void TTCN_Runtime::set_port_state(const INTEGER& state, const CHARSTRING& info,
if (translation_count > 0) {
if (p != NULL) {
int lowed_end = by_system ? -1 : 0;
if (state < lowed_end || state > 3) {
if (state < lowed_end || state > 4) {
translation_count--;
TTCN_error("The value of the first parameter in the setstate operation must be 0, 1, 2 or 3.");
TTCN_error("The value of the first parameter in the setstate operation must be 0, 1, 2, 3 or 4.");
}
p->change_port_state((translation_port_state)((int)state));
TTCN_Logger::log_setstate(p->get_name(), (translation_port_state)((int)state), info);
......
......@@ -135,7 +135,8 @@ enum translation_port_state {
TRANSLATED = 0,
NOT_TRANSLATED = 1,
FRAGMENTED = 2,
PARTIALLY_TRANSLATED = 3
PARTIALLY_TRANSLATED = 3,
DISCARDED = 4
};
#endif
......@@ -64,7 +64,7 @@ GENERATED_SOURCES += $(GENERATED_SOURCES2)
endif
# C/C++ Source & header files of Test Ports, external functions and
# other modules:
USER_SOURCES = PT2.cc P1.cc P2.cc P3.cc VP1.cc NVP1.cc P1Internal.cc P2Internal.cc P3Internal.cc VP1Internal.cc
USER_SOURCES = PT2.cc PT3.cc P1.cc P2.cc P3.cc P4.cc VP1.cc NVP1.cc P1Internal.cc P2Internal.cc P3Internal.cc VP1Internal.cc
USER_HEADERS = $(USER_SOURCES:.cc=.hh)
# Object files of this project that are needed for the executable test suite:
......
/******************************************************************************
* Copyright (c) 2000-2017 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:
* Botond, Baranyi
*
******************************************************************************/
#include "P4.hh"
#include "PortTranslation.hh"
namespace PortTranslation {
P4_PROVIDER::P4_PROVIDER(const char *par_port_name)
: PORT(par_port_name)
{
}
P4_PROVIDER::~P4_PROVIDER()
{
}
void P4_PROVIDER::set_parameter(const char * /*parameter_name*/,
const char * /*parameter_value*/)
{
}
/*void P4_PROVIDER::Handle_Fd_Event(int fd, boolean is_readable,
boolean is_writable, boolean is_error) {}*/
void P4_PROVIDER::Handle_Fd_Event_Error(int /*fd*/)
{
}
void P4_PROVIDER::Handle_Fd_Event_Writable(int /*fd*/)
{
}
void P4_PROVIDER::Handle_Fd_Event_Readable(int /*fd*/)
{
}
/*void P4_PROVIDER::Handle_Timeout(double time_since_last_call) {}*/
void P4_PROVIDER::user_map(const char * /*system_port*/)
{
}
void P4_PROVIDER::user_unmap(const char * /*system_port*/)
{
}
void P4_PROVIDER::user_start()
{
}
void P4_PROVIDER::user_stop()
{
}
void P4_PROVIDER::outgoing_send(const INTEGER& send_par)
{
// redirect the message back to the port, to test port translation for 'receive' operations
// (these messages should be discarded by the translation function)
incoming_message(send_par);
}
void P4_PROVIDER::outgoing_send(const CHARSTRING& send_par)
{
// redirect the message back to the port, to test port translation for 'receive' operations
// (these messages should be correctly translated and received)
incoming_message(send_par);
}
void P4_PROVIDER::outgoing_send(const BOOLEAN& send_par)
{
// this should've been discarded by the translation function
TTCN_Runtime::setverdict(FAIL, "Sending a boolean value.");
}
} /* end of namespace */
/******************************************************************************
* Copyright (c) 2000-2017 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:
* Botond, Baranyi
*
******************************************************************************/
#ifndef P4_HH
#define P4_HH
#include <TTCN3.hh>
// Note: Header file PortTranslation.hh must not be included into this file!
// (because it includes this file)
// Please add the declarations of message types manually.
namespace PortTranslation {
class P4_PROVIDER : public PORT {
public:
P4_PROVIDER(const char *par_port_name);
~P4_PROVIDER();
void set_parameter(const char *parameter_name,
const char *parameter_value);
private:
/* void Handle_Fd_Event(int fd, boolean is_readable,
boolean is_writable, boolean is_error); */
void Handle_Fd_Event_Error(int fd);
void Handle_Fd_Event_Writable(int fd);
void Handle_Fd_Event_Readable(int fd);
/* void Handle_Timeout(double time_since_last_call); */
protected:
void user_map(const char *system_port);
void user_unmap(const char *system_port);
void user_start();
void user_stop();
void outgoing_send(const INTEGER& send_par);
void outgoing_send(const CHARSTRING& send_par);
void outgoing_send(const BOOLEAN& send_par);
virtual void incoming_message(const INTEGER& incoming_par) = 0;
virtual void incoming_message(const CHARSTRING& incoming_par) = 0;
};
} /* end of namespace */
#endif
/******************************************************************************
* Copyright (c) 2000-2017 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:
* Botond, Baranyi
*
******************************************************************************/
#include "PT3.hh"
namespace PortTranslation {
PT3::PT3(const char *par_port_name)
: PT3_BASE(par_port_name)
{
}
PT3::~PT3()
{
}
void PT3::set_parameter(const char * /*parameter_name*/,
const char * /*parameter_value*/)
{
}
/*void PT3::Handle_Fd_Event(int fd, boolean is_readable,
boolean is_writable, boolean is_error) {}*/
void PT3::Handle_Fd_Event_Error(int /*fd*/)
{
}
void PT3::Handle_Fd_Event_Writable(int /*fd*/)
{
}
void PT3::Handle_Fd_Event_Readable(int /*fd*/)
{
}
/*void PT3::Handle_Timeout(double time_since_last_call) {}*/
void PT3::user_map(const char * /*system_port*/)
{
}
void PT3::user_unmap(const char * /*system_port*/)
{
}
void PT3::user_start()
{
}
void PT3::user_stop()
{
}
void PT3::outgoing_send(const INTEGER& /*send_par*/)
{
}
void PT3::outgoing_send(const CHARSTRING& /*send_par*/)
{
}
void PT3::outgoing_send(const BOOLEAN& /*send_par*/)
{
}
} /* end of namespace */
/******************************************************************************
* Copyright (c) 2000-2017 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:
* Botond, Baranyi
*
******************************************************************************/
#ifndef PT3_HH
#define PT3_HH
#include "PortTranslation.hh"
namespace PortTranslation {
class PT3 : public PT3_BASE {
public:
PT3(const char *par_port_name = NULL);
~PT3();
void set_parameter(const char *parameter_name,
const char *parameter_value);
private:
/* void Handle_Fd_Event(int fd, boolean is_readable,
boolean is_writable, boolean is_error); */
void Handle_Fd_Event_Error(int fd);
void Handle_Fd_Event_Writable(int fd);
void Handle_Fd_Event_Readable(int fd);
/* void Handle_Timeout(double time_since_last_call); */
protected:
void user_map(const char *system_port);
void user_unmap(const char *system_port);
void user_start();
void user_stop();
void outgoing_send(const INTEGER& send_par);
void outgoing_send(const CHARSTRING& send_par);
void outgoing_send(const BOOLEAN& send_par);
};
} /* end of namespace */
#endif
......@@ -201,6 +201,25 @@ module PortTranslation {
} with {
extension "prototype(fast)";
}
function int_to_float_discard(in integer i, out float j) {
port.setstate(4); // discarded
} with {
extension "prototype(fast)";
}
function char_to_hex3(in charstring i, out hexstring j) {
j := oct2hex(char2oct(i));
port.setstate(0); // translated
} with {
extension "prototype(fast)";
}
function bool_to_bool_discard(in boolean i, out boolean j) {
port.setstate(4); // discarded
} with {
extension "prototype(fast)";
}
///////////////////////////////////////////////////////////////////////////////
......@@ -235,6 +254,13 @@ module PortTranslation {
out bitstring, hexstring, integer
inout octetstring
}
type port P4 message {
inout integer, charstring
out boolean
} with {
extension "provider"
}
type port PT2 message map to P1, P2 {
in charstring from charstring with char_to_char()
......@@ -250,10 +276,18 @@ module PortTranslation {
var hexstring buffer := ''H;
var bitstring bit_buffer := ''B;
}
type port PT3 message map to P4 {
in hexstring from charstring with char_to_hex3()
in float from integer with int_to_float_discard()
out integer, charstring
out boolean to boolean with bool_to_bool_discard()
}
type component MyComp {
port PT2 p;
port PT3 p3;
// Extra port types to check if multiple map/unmaps does not make things go bad
port PT2 p11;
......@@ -265,6 +299,7 @@ module PortTranslation {
port P1 p1
port P2 p2
port P3 p3
port P4 p4
// Extra port types to check if multiple map/unmaps does not make things go bad
port P1 p11
......@@ -693,6 +728,16 @@ module PortTranslation {
}
t.stop;
}
// This tests the 'discard' option in the 'setstate' operation when sending
testcase tc_send_discarded() runs on MyComp system System {
map(self:p3, system:p4);
p3.send(true);
// a boolean (true) is sent on the main port, but the translation function discards it,
// so nothing is sent to the provider port (this is tested in the provider port implementation).
setverdict(pass);
}
testcase tc_receive_fragmented() runs on MyComp system System {
map(self:p, system:p1);
......@@ -741,6 +786,38 @@ module PortTranslation {
}
t.stop;
}
// This tests the 'discard' option in the 'setstate' operation when receiving
testcase tc_receive_discarded() runs on MyComp system System {
map(self:p3, system:p4);
p3.send(123);
timer t := 0.5;
t.start;
// an integer (123) is received on the provider port, but the translation function discards it,
// so it does not reach the main port
alt {
[] p3.receive(float: ?) { setverdict(fail, "Test #1 failed. Received float value."); }
[] p3.receive(hexstring: ?) { setverdict(fail, "Test #1 failed. Received hexstring value."); }
[] t.timeout { setverdict(pass); }
}
t.stop;
p3.send(-10);
p3.send("abc");
var hexstring bad;
t.start;
// an integer (-10) and a charstring ("abc") are received on the provider port,
// the translation functions discard the integer and convert the charstring into a hexstring,
// so only the hexstring is received on the main port
alt {
[] p3.receive(hexstring: '616263'H) { setverdict(pass); }
[] p3.receive(hexstring: ?) -> value bad { setverdict(fail, "Test #2 failed. Received invalid hexstring: ", bad); }
[] p3.receive(float: ?) { setverdict(fail, "Test #2 failed. Received float value."); }
[] t.timeout { setverdict(fail, "Test #2 timed out."); }
}
t.stop;
}
control {
execute(tc_send())
......@@ -753,9 +830,13 @@ module PortTranslation {
execute(tc_send_partially_translated());
execute(tc_send_fragmented());
execute(tc_send_discarded());
execute(tc_receive_partially_translated());
execute(tc_receive_fragmented());
execute(tc_receive_discarded());
}
}
......@@ -22,7 +22,7 @@ module Setstate_neg {
}
function int_to_char_bad2(in integer i, out charstring j) {
if (i == 4) {
if (i == 5) {
port.setstate(i);
} else {
port.setstate(1); // Not translated
......@@ -32,7 +32,7 @@ module Setstate_neg {
}
function int_to_char_bad3(in integer i, out charstring j) {
if (i != 5) {
if (i != 6) {
port.setstate(1); // Not translated
}
// otherwise the state will remain unset which will cause an error.
......@@ -75,7 +75,7 @@ module Setstate_neg {
p.send(-1);
setverdict(fail);
} @catch(e) {
if (match(e, "Dynamic test case error: The value of the first parameter in the setstate operation must be 0, 1, 2 or 3.")) {
if (match(e, "Dynamic test case error: The value of the first parameter in the setstate operation must be 0, 1, 2, 3 or 4.")) {
setverdict(pass);
} else {
setverdict(fail);
......@@ -83,10 +83,10 @@ module Setstate_neg {
}
@try {
p.send(4);
p.send(5);
setverdict(fail);
} @catch(e) {
if (match(e, "Dynamic test case error: The value of the first parameter in the setstate operation must be 0, 1, 2 or 3.")) {
if (match(e, "Dynamic test case error: The value of the first parameter in the setstate operation must be 0, 1, 2, 3 or 4.")) {
setverdict(pass);
} else {
setverdict(fail);
......@@ -94,7 +94,7 @@ module Setstate_neg {
}
@try {
p.send(5);
p.send(6);
setverdict(fail);
} @catch(e) {
if (match(e, "Dynamic test case error: The state of the port p remained unset after the mapping function @Setstate_neg.int_to_char_bad3 finished.")) {
......@@ -116,10 +116,10 @@ module Setstate_neg {
}
// Will be successful
p.send(6);
p.send(7);
}
control {
execute(tc_setstate_neg_test());
}
}
\ No newline at end of file
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment