blob: 3f2d8279af3f7f77cb9e2cd669ac2a1992795040 [file] [log] [blame]
# Copyright 2017 Open Networking Foundation (ONF)
#
# Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
# the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
# or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
#
# TestON is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# TestON is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with TestON. If not, see <http://www.gnu.org/licenses/>.
#
# If you have any questions, or if you don't understand R,
# please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu
# This is the R script that generates the FUNC, HA, and various USECASE result graphs.
# **********************************************************
# STEP 1: Data management.
# **********************************************************
print( "STEP 1: Data management." )
# Command line arguments are read. Args include the database credentials, test name, branch name, and the directory to output files.
print( "Reading commmand-line args." )
args <- commandArgs( trailingOnly=TRUE )
# Import libraries to be used for graphing and organizing data, respectively.
# Find out more about ggplot2: https://github.com/tidyverse/ggplot2
# reshape2: https://github.com/hadley/reshape
# RPostgreSQL: https://code.google.com/archive/p/rpostgresql/
print( "Importing libraries." )
library( ggplot2 )
library( reshape2 )
library( RPostgreSQL )
# Check if sufficient args are provided.
if ( is.na( args[ 8 ] ) ){
print( "Usage: Rscript testCaseGraphGenerator.R <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <#-builds-to-show> <directory-to-save-graphs>" )
q() # basically exit(), but in R
}
# Filenames for the output graph include the testname, branch, and the graph type.
outputFile <- paste( args[ 8 ], args[ 5 ], sep="" )
outputFile <- paste( outputFile, args[ 6 ], sep="_" )
outputFile <- paste( outputFile, args[ 7 ], sep="_" )
outputFile <- paste( outputFile, "builds", sep="-" )
outputFile <- paste( outputFile, "_graph.jpg", sep="" )
# From RPostgreSQL
print( "Reading from databases." )
con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 1 ], port=strtoi( args[ 2 ] ), user=args[ 3 ],password=args[ 4 ] )
print( "Creating SQL command." )
# Creating SQL command based on command line args.
command <- paste( "SELECT * FROM executed_test_tests WHERE actual_test_name='", args[ 5 ], sep="" )
command <- paste( command, "' AND branch='", sep="" )
command <- paste( command, args[ 6 ], sep="" )
command <- paste( command, "' ORDER BY date DESC LIMIT ", sep="" )
command <- paste( command, args[ 7 ], sep="" )
fileData <- dbGetQuery( con, command )
# Title of graph based on command line args.
title <- paste( args[ 5 ], args[ 6 ], sep=" - " )
title <- paste( title, "Results of Last ", sep=" \n " )
title <- paste( title, args[ 7 ], sep="" )
title <- paste( title, " Builds", sep="" )
# **********************************************************
# STEP 2: Organize data.
# **********************************************************
print( "STEP 2: Organize data." )
# Create lists c() and organize data into their corresponding list.
print( "Sorting data into new data frame." )
categories <- c( fileData[ 'num_failed' ], fileData[ 'num_passed' ], fileData[ 'num_planned' ] )
# Parse lists into data frames.
# This is where reshape2 comes in. Avgs list is converted to data frame.
dataFrame <- melt( categories )
dataFrame$build <- fileData$build
colnames( dataFrame ) <- c( "Tests", "Status", "Build" )
# Format data frame so that the data is in the same order as it appeared in the file.
dataFrame$Status <- as.character( dataFrame$Status )
dataFrame$Status <- factor( dataFrame$Status, levels=unique( dataFrame$Status ) )
# Add planned, passed, and failed results to the dataFrame (for the fill below the lines)
dataFrame$num_planned <- fileData$num_planned
dataFrame$num_passed <- fileData$num_passed
dataFrame$num_failed <- fileData$num_failed
# Adding a temporary reversed iterative list to the dataFrame so that there are no gaps in-between build numbers.
dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
print( "Data Frame Results:" )
print( dataFrame )
# **********************************************************
# STEP 3: Generate graphs.
# **********************************************************
print( "STEP 3: Generate graphs." )
print( "Creating main plot." )
# Create the primary plot here.
# ggplot contains the following arguments:
# - data: the data frame that the graph will be based off of
# - aes: the asthetics of the graph which require:
# - x: x-axis values (usually iterative, but it will become build # later)
# - y: y-axis values (usually tests)
# - color: the category of the colored lines (usually status of test)
theme_set( theme_grey( base_size = 26 ) ) # set the default text size of the graph.
mainPlot <- ggplot( data = dataFrame, aes( x = iterative, y = Tests, color = Status ) )
print( "Formatting main plot." )
# geom_ribbon is used so that there is a colored fill below the lines. These values shouldn't be changed.
failedColor <- geom_ribbon( aes( ymin = 0, ymax = dataFrame$num_failed ), fill = "red", linetype = 0, alpha = 0.07 )
passedColor <- geom_ribbon( aes( ymin = 0, ymax = dataFrame$num_passed ), fill = "green", linetype = 0, alpha = 0.05 )
plannedColor <- geom_ribbon( aes( ymin = 0, ymax = dataFrame$num_planned ), fill = "blue", linetype = 0, alpha = 0.01 )
colors <- scale_color_manual( values=c( "#E80000", "#00B208", "#00A5FF") )
xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, label = dataFrame$Build )
yScaleConfig <- scale_y_continuous( breaks = seq( 0, max( dataFrame$Tests ), by = ceiling( max( dataFrame$Tests ) / 10 ) ) )
xLabel <- xlab( "Build Number" )
yLabel <- ylab( "Test Cases" )
fillLabel <- labs( fill="Type" )
legendLabels <- scale_colour_discrete( labels = c( "Failed Cases", "Passed Cases", "Planned Cases" ) )
centerTitle <- theme( plot.title=element_text( hjust = 0.5 ) ) # To center the title text
theme <- theme( plot.title = element_text( size = 32, face='bold' ), axis.text.x = element_text( angle = 0, size = 14 ), legend.position="bottom", legend.text=element_text( size=18, face="bold" ), legend.title = element_blank() )
# Store plot configurations as 1 variable
fundamentalGraphData <- mainPlot + plannedColor + passedColor + failedColor + xScaleConfig + yScaleConfig + xLabel + yLabel + fillLabel + colors + legendLabels + centerTitle + theme
print( "Generating line graph." )
lineGraphFormat <- geom_line( size = 1.1 )
pointFormat <- geom_point( size = 3 )
title <- ggtitle( title )
result <- fundamentalGraphData + lineGraphFormat + pointFormat + title
# Save graph to file
print( paste( "Saving result graph to", outputFile ) )
ggsave( outputFile, width = 15, height = 10, dpi = 200 )
print( paste( "Successfully wrote result graph out to", outputFile ) )