Skip to content

Commit

Permalink
Prevent power measurement errors failing any tests
Browse files Browse the repository at this point in the history
Signed-off-by: Samuli Leivo <[email protected]>
  • Loading branch information
leivos-unikie committed Dec 4, 2024
1 parent de2b0a7 commit 6bbfd46
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Robot-Framework/config/variables.robot
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Set Variables
Set Global Variable ${ADMIN_VM} admin-vm
Set Global Variable @{VMS} ${GUI_VM} ${CHROME_VM} ${GALA_VM} ${ZATHURA_VM} ${COMMS_VM} ${BUSINESS_VM} ${ADMIN_VM}

Set Global Variable ${RPI_IP_ADDRESS} ${config['addresses']['measurement_agent']['device_ip_address']}
Run Keyword And Ignore Error Set Global Variable ${RPI_IP_ADDRESS} ${config['addresses']['measurement_agent']['device_ip_address']}

IF $BUILD_ID != '${EMPTY}'
${config}= Read Config ../config/${BUILD_ID}.json
Expand Down
68 changes: 53 additions & 15 deletions Robot-Framework/resources/power_meas_keywords.resource
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,37 @@ Library SSHLibrary
Library DateTime

*** Variables ***
${ssh_measurement} ${EMPTY}
${SSH_MEASUREMENT} ${EMPTY}
${start_timestamp} ${EMPTY}


*** Keywords ***

Check variable availability ${variable}
${value}= Get Variable Value ${variable}
IF """${value}""" != 'None'
RETURN ${True}
ELSE
RETURN ${False}
END

Start power measurement
[Documentation] Connect to the measurement agent and run script to start collecting measurement results
[Arguments] ${id}=power_data ${timeout}=200
Connect to measurement agent
${availability} Check variable availability ${RPI_IP_ADDRESS}
IF ${availability}==False
Log To Console Power measurement agent IP address not defined. Ignoring all power measurement related keywords.
Set Global Variable ${SSH_MEASUREMENT} ${EMPTY}
RETURN
END
${status} ${connection} Run Keyword And Ignore Error Connect to measurement agent
IF $status!='PASS'
Set Global Variable ${SSH_MEASUREMENT} ${EMPTY}
Power measurement agent not found. Ignoring all power measurement related keywords.
RETURN
END
# Multiple logging processes not allowed (for now)
Stop recording power
Start recording power ${id} ${timeout}
Start recording power ${id} ${timeout}

Connect to measurement agent
[Documentation] Set up SSH connection to the measurement agent
Expand All @@ -29,44 +47,60 @@ Connect to measurement agent
${connection}= Open Connection ${IP} port=${PORT} prompt=\$ timeout=15
${output}= Login username=${LOGIN_PI} password=${PASSWORD_PI}
Should Contain ${output} ${target_output}
Set Global Variable ${ssh_measurement} ${connection}
RETURN ${ssh_measurement}
Set Global Variable ${SSH_MEASUREMENT} ${connection}
RETURN ${SSH_MEASUREMENT}

Start recording power
[Arguments] ${file_name} ${timeout}
Log To Console Starting to record power measurements
Run Keyword And Ignore Error Execute Command nohup python /home/ghaf/ghaf/ghaf-power-measurement/measure_power.py ${file_name}.csv ${timeout} > output.log 2>&1 & timeout=3

Stop recording power
IF ${SSH_MEASUREMENT} == ${EMPTY}
Log To Console No connection to power measurement device. Ignoring all power measurement related keywords.
RETURN
END
Log To Console Stopping power recording
Run Keyword And Ignore Error Execute Command pkill python timeout=3

Get power record
[Arguments] ${file_name}=power_data.csv
Connect to measurement agent
SSHLibrary.Get File /home/ghaf/ghaf/power_data/${file_name} ../../../power_measurements/
IF ${SSH_MEASUREMENT} == ${EMPTY}
Log To Console No connection to power measurement device. Ignoring all power measurement related keywords.
RETURN
END
Run Keyword And Ignore Error Connect to measurement agent
Run Keyword And Ignore Error SSHLibrary.Get File /home/ghaf/ghaf/power_data/${file_name} ../../../power_measurements/

Save power measurement interval
[Documentation] Extract measurement data within given time interval
[Arguments] ${file_name} ${start_time} ${end_time}
IF ${SSH_MEASUREMENT} == ${EMPTY}
Log To Console No connection to power measurement device. Ignoring all power measurement related keywords.
RETURN
END
Log To Console Extract power data from given time interval
${time_interval} DateTime.Subtract Date From Date ${end_time} ${start_time} exclude_millis=True
IF ${time_interval} < 0
Log To Console Invalid timestamp critera for extracting power data
RETURN
END
Extract time interval ../../../power_measurements/${file_name} ${start_time} ${end_time}
Run Keyword And Ignore Error Extract time interval ../../../power_measurements/${file_name} ${start_time} ${end_time}

Generate power plot
[Documentation] Extract power data from start_timestamp to current time.
... Plot power vs time and save to png file.
[Arguments] ${id} ${test_name}
IF ${SSH_MEASUREMENT} == ${EMPTY}
Log To Console No connection to power measurement device. Ignoring all power measurement related keywords.
RETURN
END
${end_timestamp} Get current timestamp
Switch Connection ${ssh_measurement}
Get power record ${id}.csv
Save power measurement interval ${id}.csv '${start_timestamp}' '${end_timestamp}'
Generate graph power_interval.csv ${test_name}
Log <img src="power_test.png" alt="Power plot" width="1200"> HTML
Switch Connection ${SSH_MEASUREMENT}
Run Keyword And Ignore Error Get power record ${id}.csv
Run Keyword And Ignore Error Save power measurement interval ${id}.csv '${start_timestamp}' '${end_timestamp}'
Run Keyword And Ignore Error Generate graph power_interval.csv ${test_name}
Run Keyword And Ignore Error Log <img src="power_test.png" alt="Power plot" width="1200"> HTML

Set start timestamp
${current_time} DateTime.Get Current Date exclude_millis=yes
Expand All @@ -79,5 +113,9 @@ Get current timestamp

Log average power
[Arguments] ${file_name}
${mean_P} Mean power ${file_name}
IF ${SSH_MEASUREMENT} == ${EMPTY}
Log To Console No connection to power measurement device. Ignoring all power measurement related keywords.
RETURN
END
${keyword_status} ${mean_P} Run Keyword And Ignore Error Mean power ${file_name}
# TODO: With the statistics tools of performance testing also average power values could be plotted and monitored

0 comments on commit 6bbfd46

Please sign in to comment.