From 1afd2f61b6dc772f73ce9d707192ad68c546217c Mon Sep 17 00:00:00 2001 From: BenceJanosSzabo <bence.janos.szabo@ericsson.com> Date: Mon, 12 Dec 2016 10:06:26 +0100 Subject: [PATCH] Allowed float special values in module parameters (artf635316) Change-Id: I77c9cf3eab7969e7389045c51eddbb428acf7e9a Signed-off-by: BenceJanosSzabo <bence.janos.szabo@ericsson.com> --- core/config_process.l | 13 +- mctr2/cli/config_read.l | 13 +- .../cfgFile/module_parameters/Makefile | 2 +- .../module_parameters/special_values/Makefile | 65 +++++ .../special_values/SpecialValues.cfg | 71 +++++ .../special_values/SpecialValues.ttcn | 253 ++++++++++++++++++ 6 files changed, 412 insertions(+), 5 deletions(-) create mode 100644 regression_test/cfgFile/module_parameters/special_values/Makefile create mode 100644 regression_test/cfgFile/module_parameters/special_values/SpecialValues.cfg create mode 100644 regression_test/cfgFile/module_parameters/special_values/SpecialValues.ttcn diff --git a/core/config_process.l b/core/config_process.l index bf2acbd46..7f3265ae6 100644 --- a/core/config_process.l +++ b/core/config_process.l @@ -34,6 +34,7 @@ #include <deque> #include <string> +#include <math.h> #include "../common/cfg_process_utils.hh" #include "../common/Path2.hh" @@ -90,7 +91,7 @@ LINECOMMENT ("//"|"#")[^\r\n]*{NEWLINE} NUMBER 0|([1-9][0-9]*) -FLOAT [+-]?({NUMBER}\.[0-9]+)|((({NUMBER}(\.[0-9]+)?)|(\.[0-9]+))[Ee][+-]?{NUMBER}) +FLOAT [+-]?({NUMBER}\.[0-9]+)|((({NUMBER}(\.[0-9]+)?)|(\.[0-9]+))[Ee][+-]?{NUMBER})|infinity|not_a_number BIN 0|1 BITSTRING '{BIN}*'B @@ -330,7 +331,15 @@ TTCNSTRINGPARSING_COMPONENT "$#&&&(#TTCNSTRINGPARSING_COMPONENT$#&&^#% " } {FLOAT} { - yylval.float_val = atof(yytext); + if (!strcmp(yytext, "not_a_number")) { +#ifdef NAN + yylval.float_val = NAN; +#else + yylval.float_val = INFINITY + (-INFINITY); +#endif + } else { + yylval.float_val = atof(yytext); + } if (YY_START == SC_MODULE_PARAMETERS || YY_START == SC_CHAR_KEYWORD) { // return a different token for module parameters so it doesn't conflict with references return MPFloat; diff --git a/mctr2/cli/config_read.l b/mctr2/cli/config_read.l index 18b8de8af..cc70a5fa6 100644 --- a/mctr2/cli/config_read.l +++ b/mctr2/cli/config_read.l @@ -35,6 +35,7 @@ #include <deque> #include <string> +#include <math.h> #include <openssl/crypto.h> #include <openssl/bn.h> @@ -89,7 +90,7 @@ LINECOMMENT ("//"|"#")[^\r\n]*{NEWLINE} NUMBER 0|([1-9][0-9]*) -FLOAT [+-]?({NUMBER}\.[0-9]+)|((({NUMBER}(\.[0-9]+)?)|(\.[0-9]+))[Ee][+-]?{NUMBER}) +FLOAT [+-]?({NUMBER}\.[0-9]+)|((({NUMBER}(\.[0-9]+)?)|(\.[0-9]+))[Ee][+-]?{NUMBER})|infinity|not_a_number BIN 0|1 BITSTRING '{BIN}*'B @@ -360,7 +361,15 @@ UID [uU][+]?[0-9A-Fa-f]{1,8} } {FLOAT} { - yylval.float_val = atof(yytext); + if (!strcmp(yytext, "not_a_number")) { +#ifdef NAN + yylval.float_val = NAN; +#else + yylval.float_val = INFINITY + (-INFINITY); +#endif + } else { + yylval.float_val = atof(yytext); + } if (YY_START == SC_MODULE_PARAMETERS || YY_START == SC_CHAR_KEYWORD) { RETURN(MPFloat); } diff --git a/regression_test/cfgFile/module_parameters/Makefile b/regression_test/cfgFile/module_parameters/Makefile index c07ff498e..ba46e6111 100644 --- a/regression_test/cfgFile/module_parameters/Makefile +++ b/regression_test/cfgFile/module_parameters/Makefile @@ -16,7 +16,7 @@ include $(TOPDIR)/Makefile.regression unexport ABS_SRC unexport SRCDIR -DIRS := assignment concat +DIRS := assignment concat special_values ifdef RT2 DIRS += references nested endif diff --git a/regression_test/cfgFile/module_parameters/special_values/Makefile b/regression_test/cfgFile/module_parameters/special_values/Makefile new file mode 100644 index 000000000..07863c8a6 --- /dev/null +++ b/regression_test/cfgFile/module_parameters/special_values/Makefile @@ -0,0 +1,65 @@ +############################################################################## +# 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 +# +############################################################################## +TOPDIR := ../../../ +include $(TOPDIR)/Makefile.regression + +FILES := SpecialValues.ttcn SpecialValues.cfg +RUNNABLE := SpecialValues +CFG := SpecialValues.cfg +DIR_SINGLE := dir_single_mode +DIR_PARALLEL := dir_parallel_mode +GENERATED_DIRS := $(DIR_SINGLE) $(DIR_PARALLEL) + +COVERAGE_FLAG := +ifeq ($(COVERAGE), yes) + COVERAGE_FLAG += -C +endif + +ifdef DYN +ifeq ($(PLATFORM), WIN32) + export PATH+=:$(TTCN3_DIR)/lib:$(ABS_SRC)/$(DIR_SINGLE):$(ABS_SRC)/$(DIR_PARALLEL): +else + export LD_LIBRARY_PATH+=:$(ABS_SRC)/$(DIR_SINGLE):$(ABS_SRC)/$(DIR_PARALLEL): +endif +endif + +MAKE_PROG := $(MAKE) + +# List of fake targets: +.PHONY: all clean run run_single run_parallel runall + +all: $(GENERATED_DIRS) + +dir_single_mode: + mkdir $@ + cd $@ && for file in $(FILES); do ln -s ../$$file || exit; done + cd $@ && $(TTCN3_DIR)/bin/ttcn3_makefilegen $(COVERAGE_FLAG) $(SPLIT_FLAG) $(RT2_FLAG) -s ./* && $(MAKE_PROG) + +dir_parallel_mode: + mkdir $@ + cd $@ && for file in $(FILES); do ln -s ../$$file || exit; done + cd $@ && $(TTCN3_DIR)/bin/ttcn3_makefilegen $(COVERAGE_FLAG) $(SPLIT_FLAG) $(RT2_FLAG) ./* && $(MAKE_PROG) + +run: $(GENERATED_DIRS) + cd $(DIR_SINGLE) && ./$(RUNNABLE) $(CFG) + cd $(DIR_PARALLEL) && $(TTCN3_DIR)/bin/ttcn3_start $(RUNNABLE) $(CFG) + +# To run all tests, possibly in parallel +run_single: $(DIR_SINGLE) + cd $(DIR_SINGLE) && ./$(RUNNABLE) $(CFG) +run_parallel: $(DIR_PARALLEL) + cd $(DIR_PARALLEL) && $(TTCN3_DIR)/bin/ttcn3_start $(RUNNABLE) $(CFG) +runall: run_single run_parallel + +clean distclean: + rm -rf $(GENERATED_DIRS) + diff --git a/regression_test/cfgFile/module_parameters/special_values/SpecialValues.cfg b/regression_test/cfgFile/module_parameters/special_values/SpecialValues.cfg new file mode 100644 index 000000000..c28d3724c --- /dev/null +++ b/regression_test/cfgFile/module_parameters/special_values/SpecialValues.cfg @@ -0,0 +1,71 @@ +############################################################################### +# 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: +# Bence Janos Szabo +# +############################################################################### +[MODULE_PARAMETERS] + +inf1 := infinity; +inf2 := infinity + 1.0; +inf3 := infinity - 1.0; +inf4 := 1.0 + infinity; +inf5 := infinity * 2.0; +inf6 := infinity / 2.0; +inf7 := 2.0 * infinity; +inf8 := infinity + infinity; +inf9 := infinity - -infinity; +inf10 := infinity * infinity; +inf11 := -infinity * -1.0; +inf12 := -infinity * -infinity; + +neginf1 := -infinity; +neginf2 := -infinity + 1.0; +neginf3 := -infinity - 1.0; +neginf4 := 1.0 + -infinity; +neginf5 := 1.0 - infinity; +neginf6 := -infinity * 2.0; +neginf7 := -infinity / 2.0; +neginf8 := 2.0 * -infinity; +neginf9 := -infinity + -infinity; +neginf10 := -infinity * infinity; +neginf11 := infinity * -infinity; +neginf12 := infinity * -1.0; + +zero1 := 2.0 / infinity; +zero2 := 2.0 / -infinity; + +nan1 := not_a_number; +nan2 := not_a_number + 1.0; +nan3 := not_a_number - 1.0; +nan4 := 1.0 + not_a_number; +nan5 := 1.0 - not_a_number; +nan6 := not_a_number * 2.0; +nan7 := not_a_number / 2.0; +nan8 := 2.0 * not_a_number; +nan9 := 2.0 / not_a_number; +nan10 := not_a_number + not_a_number; +nan11 := not_a_number - not_a_number; +nan12 := not_a_number * not_a_number; +nan13 := not_a_number / not_a_number; +nan14 := infinity / infinity; +nan15 := -infinity / infinity; +nan16 := infinity / -infinity; +nan17 := -infinity / -infinity; +nan18 := not_a_number + infinity; +nan19 := not_a_number - infinity; +nan20 := not_a_number * infinity; +nan21 := not_a_number / infinity; +nan22 := not_a_number + -infinity; +nan23 := not_a_number - -infinity; +nan24 := not_a_number * -infinity; +nan25 := not_a_number / -infinity; + + +[EXECUTE] +SpecialValues.control diff --git a/regression_test/cfgFile/module_parameters/special_values/SpecialValues.ttcn b/regression_test/cfgFile/module_parameters/special_values/SpecialValues.ttcn new file mode 100644 index 000000000..ec2281ca8 --- /dev/null +++ b/regression_test/cfgFile/module_parameters/special_values/SpecialValues.ttcn @@ -0,0 +1,253 @@ +/****************************************************************************** + * 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 SpecialValues { + +type component EmptyCT {} + +modulepar float inf1, inf2, inf3, inf4, inf5, inf6, inf7, inf8, inf9, inf10, inf11, inf12; + +modulepar float neginf1, neginf2, neginf3, neginf4, neginf5, neginf6, neginf7, neginf8, neginf9, neginf10, neginf11, neginf12; + +modulepar float zero1, zero2; + +modulepar float nan1, nan2, nan3, nan4, nan5, nan6, nan7, nan8, nan9, nan10, nan11, nan12, nan13, nan14, nan15, nan16, nan17, nan18, nan19, nan20, nan21, nan22, nan23, nan24, nan25; + + +testcase tc_moduleparam_inf() runs on EmptyCT { + if (inf1 != infinity) { + setverdict(fail, match(inf1, infinity)); + } + + if (inf2 != infinity) { + setverdict(fail, match(inf2, infinity)); + } + + if (inf3 != infinity) { + setverdict(fail, match(inf3, infinity)); + } + + if (inf4 != infinity) { + setverdict(fail, match(inf4, infinity)); + } + + if (inf5 != infinity) { + setverdict(fail, match(inf5, infinity)); + } + + if (inf6 != infinity) { + setverdict(fail, match(inf6, infinity)); + } + + if (inf7 != infinity) { + setverdict(fail, match(inf7, infinity)); + } + + if (inf8 != infinity) { + setverdict(fail, match(inf8, infinity)); + } + + if (inf9 != infinity) { + setverdict(fail, match(inf9, infinity)); + } + + if (inf10 != infinity) { + setverdict(fail, match(inf10, infinity)); + } + + if (inf11 != infinity) { + setverdict(fail, match(inf11, infinity)); + } + + if (inf12 != infinity) { + setverdict(fail, match(inf12, infinity)); + } + + setverdict(pass); +} + +testcase tc_moduleparam_neginf() runs on EmptyCT { + if (neginf1 != -infinity) { + setverdict(fail, match(neginf1, -infinity)); + } + + if (neginf2 != -infinity) { + setverdict(fail, match(neginf2, -infinity)); + } + + if (neginf3 != -infinity) { + setverdict(fail, match(neginf3, -infinity)); + } + + if (neginf4 != -infinity) { + setverdict(fail, match(neginf4, -infinity)); + } + + if (neginf5 != -infinity) { + setverdict(fail, match(neginf5, -infinity)); + } + + if (neginf6 != -infinity) { + setverdict(fail, match(neginf6, -infinity)); + } + + if (neginf7 != -infinity) { + setverdict(fail, match(neginf7, -infinity)); + } + + if (neginf8 != -infinity) { + setverdict(fail, match(neginf8, -infinity)); + } + + if (neginf9 != -infinity) { + setverdict(fail, match(neginf9, -infinity)); + } + + if (neginf10 != -infinity) { + setverdict(fail, match(neginf10, -infinity)); + } + + if (neginf11 != -infinity) { + setverdict(fail, match(neginf11, -infinity)); + } + + if (neginf12 != -infinity) { + setverdict(fail, match(neginf12, -infinity)); + } + + setverdict(pass); +} + +testcase tc_moduleparam_zero() runs on EmptyCT { + if (zero1 != 0.000000) { + setverdict(fail, match(zero1, 0.000000)); + } + + if (zero2 != -0.000000) { + setverdict(fail, match(zero2, -0.000000)); + } + + setverdict(pass); +} + +testcase tc_moduleparam_nan() runs on EmptyCT { + if (nan1 != not_a_number) { + setverdict(fail, match(nan1, not_a_number)); + } + + if (nan2 != not_a_number) { + setverdict(fail, match(nan2, not_a_number)); + } + + if (nan3 != not_a_number) { + setverdict(fail, match(nan3, not_a_number)); + } + + if (nan4 != not_a_number) { + setverdict(fail, match(nan4, not_a_number)); + } + + if (nan5 != not_a_number) { + setverdict(fail, match(nan5, not_a_number)); + } + + if (nan6 != not_a_number) { + setverdict(fail, match(nan6, not_a_number)); + } + + if (nan7 != not_a_number) { + setverdict(fail, match(nan7, not_a_number)); + } + + if (nan8 != not_a_number) { + setverdict(fail, match(nan8, not_a_number)); + } + + if (nan9 != not_a_number) { + setverdict(fail, match(nan9, not_a_number)); + } + + if (nan10 != not_a_number) { + setverdict(fail, match(nan10, not_a_number)); + } + + if (nan11 != not_a_number) { + setverdict(fail, match(nan11, not_a_number)); + } + + if (nan12 != not_a_number) { + setverdict(fail, match(nan12, not_a_number)); + } + + if (nan13 != not_a_number) { + setverdict(fail, match(nan13, not_a_number)); + } + + if (nan14 != not_a_number) { + setverdict(fail, match(nan14, not_a_number)); + } + + if (nan15 != not_a_number) { + setverdict(fail, match(nan15, not_a_number)); + } + + if (nan16 != not_a_number) { + setverdict(fail, match(nan16, not_a_number)); + } + + if (nan17 != not_a_number) { + setverdict(fail, match(nan17, not_a_number)); + } + + if (nan18 != not_a_number) { + setverdict(fail, match(nan18, not_a_number)); + } + + if (nan19 != not_a_number) { + setverdict(fail, match(nan19, not_a_number)); + } + + if (nan20 != not_a_number) { + setverdict(fail, match(nan20, not_a_number)); + } + + if (nan21 != not_a_number) { + setverdict(fail, match(nan21, not_a_number)); + } + + if (nan22 != not_a_number) { + setverdict(fail, match(nan22, not_a_number)); + } + + if (nan23 != not_a_number) { + setverdict(fail, match(nan23, not_a_number)); + } + + if (nan24 != not_a_number) { + setverdict(fail, match(nan24, not_a_number)); + } + + if (nan25 != not_a_number) { + setverdict(fail, match(nan25, not_a_number)); + } + setverdict(pass); + +} + + +control { + execute(tc_moduleparam_inf()); + execute(tc_moduleparam_neginf()); + execute(tc_moduleparam_zero()); + execute(tc_moduleparam_nan()); +} + +} -- GitLab