| /////////////////////////////////////////////////////////////////////////////// |
| // // |
| // Copyright (c) 2000-2019 Ericsson Telecom AB // |
| // // |
| // All rights reserved. This program and the accompanying materials // |
| // are made available under the terms of the Eclipse Public License v2.0 // |
| // which accompanies this distribution, and is available at // |
| // https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html // |
| /////////////////////////////////////////////////////////////////////////////// |
| |
| /////////////////////////////////////////////////////////// |
| // Module: TestResultGen |
| // |
| // Purpose: |
| // This module provides definition of the Test Result Generator. |
| // |
| // Module Parameters: |
| // - |
| // |
| // Module depends on: |
| // <TCCFileIO_Functions> |
| // <EPTF_CLL_Common_Definitions> |
| // <EPTF_CLL_Common_Functions> |
| // |
| // Current Owner: |
| // ethjgi |
| // |
| // Last Review Date: |
| // 2010-11-26 |
| // |
| // Detailed Comments: |
| // This module can be used to generate test results in a |
| // common (XML) format. |
| // The format of XML is generated from XSD. |
| // Before the test some TTCN3 modules should be generated by |
| // xsd2ttcn testresults.xsd |
| // |
| // Public functions: |
| // <enc_Testresult> |
| // <dec_Testresult> |
| // <enc_Testresults> |
| // <dec_Testresults> |
| // <f_TestResultGen_appendResult> |
| // <f_TestResultGen_writeResult> |
| // <f_TestResultGen_getCurrentTime> |
| // <f_TestResultGen_getEnvironment> |
| // |
| /////////////////////////////////////////////////////////// |
| module TestResultGen { |
| |
| import from ttcn_ericsson_se_TitanSim_Perftest all; |
| import from TCCFileIO_Functions all; |
| import from EPTF_CLL_Common_Definitions all; |
| import from EPTF_CLL_Common_Functions all; |
| import from EPTF_CLL_Base_Definitions all; |
| import from EPTF_CLL_Base_Functions all; |
| |
| /////////////////////////////////////////////////////////// |
| // Function: enc_Testresult |
| // |
| // Purpose: |
| // Encodes the given test result into octetstring (XML) |
| // |
| // Parameters: |
| // in Testresult p_testresult - The test result to encode |
| // |
| // Return Value: |
| // octetstring - test result encoded to XML |
| // |
| /////////////////////////////////////////////////////////// |
| public external function enc_Testresult (in Testresult p_testresult) return octetstring |
| with {extension "prototype(convert) encode (XER:XER_EXTENDED)"} |
| |
| /////////////////////////////////////////////////////////// |
| // Function: dec_Testresult |
| // |
| // Purpose: |
| // Decodes the given octetstring (XML) into test result |
| // |
| // Parameters: |
| // in octetstring p_oct - valid XML input according to the |
| // testresults.xsd schema |
| // out Testresult p_testresult - The test result decoded |
| // |
| // Return Value: |
| // integer - status code: 0 if decode is successful, nonzero if not |
| // |
| /////////////////////////////////////////////////////////// |
| public external function dec_Testresult (in octetstring p_oct, out Testresult p_testresult) return integer |
| with {extension "prototype(backtrack) decode (XER:XER_EXTENDED) errorbehavior(ALL:WARNING)"} |
| |
| /////////////////////////////////////////////////////////// |
| // Function: enc_Testresults |
| // |
| // Purpose: |
| // Encodes the given test results into octetstring (XML) |
| // |
| // Parameters: |
| // in Testresults p_testresults - The test result to encode |
| // |
| // Return Value: |
| // octetstring - test result encoded to XML |
| // |
| /////////////////////////////////////////////////////////// |
| public external function enc_Testresults (in Testresults p_testresults) return octetstring |
| with {extension "prototype(convert) encode (XER:XER_EXTENDED)"} |
| |
| /////////////////////////////////////////////////////////// |
| // Function: dec_Testresults |
| // |
| // Purpose: |
| // Decodes the given octetstring (XML) into test results |
| // |
| // Parameters: |
| // in octetstring p_oct - valid XML input according to the |
| // testresults.xsd schema |
| // out Testresults p_testresults - The test results decoded |
| // |
| // Return Value: |
| // integer - status code: 0 if decode is successful, nonzero if not |
| // |
| /////////////////////////////////////////////////////////// |
| public external function dec_Testresults (in octetstring p_oct, out Testresults p_testresults) return integer |
| with {extension "prototype(backtrack) decode (XER:XER_EXTENDED) errorbehavior(ALL:WARNING)"} |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_TestResultGen_appendResult |
| // |
| // Purpose: |
| // Reads test results from file, appends given result and writes back to the file |
| // |
| // Parameters: |
| // in charstring pl_filename - the name of the file to append the results to |
| // in Testresult pl_testresult - The test result to add |
| // |
| // Return Value: |
| // boolean - status: true on success, false else |
| // |
| /////////////////////////////////////////////////////////// |
| public function f_TestResultGen_appendResult(in charstring pl_filename, in Testresult pl_testresult) return boolean { |
| var Testresults vl_testresults := {{}}; |
| var integer vl_fd := f_FIO_open_append_rdwr_excl(pl_filename); |
| if (vl_fd == -1) { |
| f_EPTF_Common_warning(%definitionId&": Cannot open file "&pl_filename); |
| return false; |
| } |
| var octetstring vl_data; |
| var integer vl_fileSize := f_FIO_seek_end(vl_fd); |
| f_FIO_seek_home(vl_fd) |
| f_FIO_read_data(vl_fd,vl_data,vl_fileSize); |
| if (vl_fileSize>0 and dec_Testresults(vl_data,vl_testresults)!=0) { |
| f_EPTF_Common_warning(%definitionId&": Cannot decode input file "&pl_filename); |
| f_FIO_close(vl_fd); |
| return false; |
| } |
| vl_testresults.testresult_list[sizeof(vl_testresults.testresult_list)] := pl_testresult; |
| f_FIO_close(vl_fd); |
| vl_fd := f_FIO_open_trunc_rdwr_excl(pl_filename); |
| f_FIO_write_data_flush(vl_fd,enc_Testresults(vl_testresults)); |
| f_FIO_close(vl_fd); |
| return true; |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_TestResultGen_writeResult |
| // |
| // Purpose: |
| // The given result is written into the file |
| // |
| // Parameters: |
| // in charstring pl_filename - the name of the file to write the results into |
| // in Testresult pl_testresult - The test result to write |
| // |
| // Return Value: |
| // boolean - status: true on success, false else |
| // |
| // Detailed Comments: |
| // Truncates file! Previous content is lost!!!!! |
| /////////////////////////////////////////////////////////// |
| public function f_TestResultGen_writeResult(in charstring pl_filename, in Testresult pl_testresult) return boolean { |
| var integer vl_fd := f_FIO_open_trunc_rdwr(pl_filename); |
| if (vl_fd == -1) { |
| f_EPTF_Common_warning(%definitionId&": Cannot open file "&pl_filename); |
| return false; |
| } |
| f_FIO_write_data(vl_fd,enc_Testresults({{pl_testresult}})); |
| f_FIO_close(vl_fd); |
| return true; |
| } |
| |
| // dummy component needed by the external function f_TestResultGen_ExecuteCommand |
| type component TestResultGen_CT extends EPTF_Base_CT{} |
| |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_TestResultGen_getCurrentTime |
| // |
| // Purpose: |
| // Returns the current time in a given string format |
| // |
| // Parameters: |
| // in charstring pl_timeFormat - the format of the time (default: +%Y-%m-%d %H:%M:%S) |
| // |
| // Return Value: |
| // charstring - the current time in the given format |
| // |
| // Detailed Comments: |
| // For more time formats check the unix 'date' command |
| /////////////////////////////////////////////////////////// |
| public function f_TestResultGen_getCurrentTime(in charstring pl_timeFormat := "+%Y-%m-%d_%H-%M-%S") runs on TestResultGen_CT return charstring { |
| var charstring vl_stdout; |
| var charstring vl_stderr; |
| var charstring vl_time := "Unknown"; |
| f_TestResultGen_ExecuteCommand("date '"&pl_timeFormat&"'",vl_stdout,vl_stderr); |
| vl_time := vl_stdout; |
| return vl_time; |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_TestResultGen_ExecuteCommand |
| // |
| // Purpose: |
| // Executes shell command |
| // |
| // Parameters: |
| // pl_command - *in* *charstring* - the name of the script/command to execute |
| // pl_stdOut - *out* *charstring* - standard output |
| // pl_stdErr - *out* *charstring* - standard error |
| // |
| // Return Value: |
| // integer - exit code, zero if execution was successful |
| // |
| // Detailed Comments: |
| // - |
| /////////////////////////////////////////////////////////// |
| private function f_TestResultGen_ExecuteCommand(in charstring pl_command, out charstring pl_stdout, out charstring pl_stderr) runs on TestResultGen_CT return integer { |
| var integer vl_returnCode := 0; |
| vl_returnCode := f_EPTF_Base_executeShell(pl_command, pl_stdout, pl_stderr, pl_enableAlts:=false); |
| |
| // remove "\n" from the end of stdout |
| var integer vl_lengthStdOut := lengthof(pl_stdout); |
| if(vl_lengthStdOut > 0){ |
| if(pl_stdout[vl_lengthStdOut-1] == "\n"){ |
| pl_stdout := substr(pl_stdout, 0, vl_lengthStdOut-1); |
| } |
| } |
| |
| // remove "\n" from the end of stderr |
| var integer vl_lengthStdErr := lengthof(pl_stderr); |
| if(vl_lengthStdErr > 0){ |
| if(pl_stderr[vl_lengthStdErr-1] == "\n"){ |
| pl_stderr := substr(pl_stderr, 0, vl_lengthStdErr-1); |
| } |
| } |
| return vl_returnCode; |
| } |
| |
| |
| // retuns the environment setting in pl_environment |
| /////////////////////////////////////////////////////////// |
| // Function: f_TestResultGen_getCurrentTime |
| // |
| // Purpose: |
| // Returns the environment setting |
| // |
| // Parameters: |
| // out Environment_type pl_environment - the environment data returned |
| // |
| // Return Value: |
| // - |
| // |
| /////////////////////////////////////////////////////////// |
| public function f_TestResultGen_getEnvironment(out Environment_type pl_environment) runs on TestResultGen_CT { |
| var charstring vl_stdout; |
| var charstring vl_stderr; |
| //user |
| f_TestResultGen_ExecuteCommand("echo $USER",vl_stdout,vl_stderr); |
| pl_environment.user := vl_stdout; |
| //host |
| f_TestResultGen_ExecuteCommand("uname -n",vl_stdout,vl_stderr); |
| pl_environment.host := vl_stdout; |
| //kernel |
| f_TestResultGen_ExecuteCommand("uname -sr",vl_stdout,vl_stderr); |
| pl_environment.kernel := vl_stdout; |
| //gcc_version |
| f_TestResultGen_ExecuteCommand("g++ -dumpversion",vl_stdout,vl_stderr); |
| pl_environment.gcc_version := vl_stdout; |
| //titan_version |
| f_TestResultGen_ExecuteCommand("compiler -v 2>&1 | gawk 'BEGIN{FS=\"(: )|(version )\"}/version/ {v=\" v\"$2} /Product/ {p=$2} /Build date/ {d=$2} END{print p v \" built on \" d}'",vl_stdout,vl_stderr); |
| pl_environment.titan_version := vl_stdout; |
| //cpu_info |
| f_TestResultGen_ExecuteCommand("top bd00.50n2|grep Cpu| tail -n1 | sed 's/.*Cpu(s): //g;s/us,.*//g'",vl_stdout,vl_stderr); |
| pl_environment.cpu_info := vl_stdout; |
| //memory_info |
| f_TestResultGen_ExecuteCommand("grep MemTotal /proc/meminfo | awk '{print $2/1024\"MB\" }'",vl_stdout,vl_stderr); |
| pl_environment.memory_info := vl_stdout; |
| //EPTF_DEBUG |
| pl_environment.ePTF_DEBUG := log2str(c_EPTF_Common_debugSwitch); |
| } |
| |
| |
| } // end of module |