blob: f8ec1450a4c38a29ce7e74e3da33693bbeba6fea [file] [log] [blame]
Jeremy Ronquillo6df87812017-08-28 16:17:36 +00001# Copyright 2017 Open Networking Foundation (ONF)
2#
3# Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
4# the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
5# or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
6#
7# TestON is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 2 of the License, or
10# (at your option) any later version.
11#
12# TestON is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with TestON. If not, see <http://www.gnu.org/licenses/>.
19#
20# If you have any questions, or if you don't understand R,
Jeremy Ronquillob6268842017-10-03 13:02:58 -070021# please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000022
Jeremy Ronquillob6268842017-10-03 13:02:58 -070023# This is the R script that generates the FUNC, HA, and various USECASE result graphs.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000024
25# **********************************************************
26# STEP 1: Data management.
27# **********************************************************
28
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070029print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000030print( "STEP 1: Data management." )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070031print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000032
33# Command line arguments are read. Args include the database credentials, test name, branch name, and the directory to output files.
34print( "Reading commmand-line args." )
35args <- commandArgs( trailingOnly=TRUE )
36
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070037# ----------------
38# Import Libraries
39# ----------------
40
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000041print( "Importing libraries." )
42library( ggplot2 )
43library( reshape2 )
44library( RPostgreSQL )
45
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070046# -------------------
47# Check CLI Arguments
48# -------------------
49
50print( "Verifying CLI args." )
51
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000052if ( is.na( args[ 8 ] ) ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070053
54 print( paste( "Usage: Rscript testCaseGraphGenerator.R",
55 "<database-host>",
56 "<database-port>",
57 "<database-user-id>",
58 "<database-password>",
59 "<test-name>", # part of the output filename
60 "<branch-name>", # for sql and output filename
61 "<#-builds-to-show>", # for sql and output filename
62 "<directory-to-save-graphs>",
63 sep=" " ) )
64
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000065 q() # basically exit(), but in R
66}
67
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070068# -------------------------------
69# Create Title and Graph Filename
70# -------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000071
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070072print( "Creating title of graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000073
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070074title <- paste( args[ 5 ],
75 " - ",
76 args[ 6 ],
77 " \n Results of Last ",
78 args[ 7 ],
79 " Builds",
80 sep="" )
81
82print( "Creating graph filename." )
83
84outputFile <- paste( args[ 8 ],
85 args[ 5 ],
86 "_",
87 args[ 6 ],
88 "_",
89 args[ 7 ],
90 "-builds_graph.jpg",
91 sep="" )
92
93# ------------------
94# SQL Initialization
95# ------------------
96
97print( "Initializing SQL" )
98
99con <- dbConnect( dbDriver( "PostgreSQL" ),
100 dbname = "onostest",
101 host = args[ 1 ],
102 port = strtoi( args[ 2 ] ),
103 user = args[ 3 ],
104 password = args[ 4 ] )
105
106# ---------------------
107# Test Case SQL Command
108# ---------------------
109print( "Generating Test Case SQL command." )
110
111command <- paste( "SELECT * FROM executed_test_tests WHERE actual_test_name='",
112 args[ 5 ],
113 "' AND branch='",
114 args[ 6 ],
115 "' ORDER BY date DESC LIMIT ",
116 args[ 7 ],
117 sep="" )
118
119print( "Sending SQL command:" )
120print( command )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000121fileData <- dbGetQuery( con, command )
122
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000123
124# **********************************************************
125# STEP 2: Organize data.
126# **********************************************************
127
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700128print( "**********************************************************" )
129print( "STEP 2: Organize Data." )
130print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000131
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700132# -------------------------------------------------------
133# Combining Passed, Failed, and Planned Data
134# -------------------------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000135
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700136print( "Combining Passed, Failed, and Planned Data." )
137
138categories <- c( fileData[ 'num_failed' ],
139 fileData[ 'num_passed' ],
140 fileData[ 'num_planned' ] )
141
142# --------------------
143# Construct Data Frame
144# --------------------
145
146print( "Constructing data frame from combined data." )
147
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000148dataFrame <- melt( categories )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700149
150# Rename column names in dataFrame
151colnames( dataFrame ) <- c( "Tests",
152 "Status" )
153
154# Add build dates to the dataFrame
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000155dataFrame$build <- fileData$build
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000156
157# Format data frame so that the data is in the same order as it appeared in the file.
158dataFrame$Status <- as.character( dataFrame$Status )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700159dataFrame$Status <- factor( dataFrame$Status, levels = unique( dataFrame$Status ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000160
161# Add planned, passed, and failed results to the dataFrame (for the fill below the lines)
162dataFrame$num_planned <- fileData$num_planned
163dataFrame$num_passed <- fileData$num_passed
164dataFrame$num_failed <- fileData$num_failed
165
166# Adding a temporary reversed iterative list to the dataFrame so that there are no gaps in-between build numbers.
167dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
168
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700169# Omit any data that doesn't exist
170dataFrame <- na.omit( dataFrame )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700171
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000172print( "Data Frame Results:" )
173print( dataFrame )
174
175# **********************************************************
176# STEP 3: Generate graphs.
177# **********************************************************
178
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700179print( "**********************************************************" )
180print( "STEP 3: Generate Graph." )
181print( "**********************************************************" )
182
183# -------------------
184# Main Plot Generated
185# -------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000186
187print( "Creating main plot." )
188# Create the primary plot here.
189# ggplot contains the following arguments:
190# - data: the data frame that the graph will be based off of
191# - aes: the asthetics of the graph which require:
192# - x: x-axis values (usually iterative, but it will become build # later)
193# - y: y-axis values (usually tests)
194# - color: the category of the colored lines (usually status of test)
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700195
196mainPlot <- ggplot( data = dataFrame, aes( x = iterative,
197 y = Tests,
198 color = Status ) )
199
200# -------------------
201# Main Plot Formatted
202# -------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000203
204print( "Formatting main plot." )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700205
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000206# geom_ribbon is used so that there is a colored fill below the lines. These values shouldn't be changed.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700207failedColor <- geom_ribbon( aes( ymin = 0,
208 ymax = dataFrame$num_failed ),
209 fill = "red",
210 linetype = 0,
211 alpha = 0.07 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000212
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700213passedColor <- geom_ribbon( aes( ymin = 0,
214 ymax = dataFrame$num_passed ),
215 fill = "green",
216 linetype = 0,
217 alpha = 0.05 )
Jeremy Ronquilloe9063762017-10-17 15:36:09 -0700218
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700219plannedColor <- geom_ribbon( aes( ymin = 0,
220 ymax = dataFrame$num_planned ),
221 fill = "blue",
222 linetype = 0,
223 alpha = 0.01 )
224
225# Colors for the lines
226lineColors <- scale_color_manual( values=c( "#E80000", # red
227 "#00B208", # green
228 "#00A5FF") ) # blue
229
230# ------------------------------
231# Fundamental Variables Assigned
232# ------------------------------
233
234print( "Generating fundamental graph data." )
235
236theme_set( theme_grey( base_size = 26 ) ) # set the default text size of the graph.
237
238xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative,
239 label = dataFrame$Build )
240yScaleConfig <- scale_y_continuous( breaks = seq( 0, max( dataFrame$Tests ),
241 by = ceiling( max( dataFrame$Tests ) / 10 ) ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000242
243xLabel <- xlab( "Build Number" )
244yLabel <- ylab( "Test Cases" )
Jeremy Ronquilloe9063762017-10-17 15:36:09 -0700245
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700246imageWidth <- 15
247imageHeight <- 10
248imageDPI <- 200
249
250legendLabels <- scale_colour_discrete( labels = c( "Failed Cases",
251 "Passed Cases",
252 "Planned Cases" ) )
253
254# Set other graph configurations here.
255theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face ='bold' ),
256 axis.text.x = element_text( angle = 0, size = 14 ),
257 legend.position = "bottom",
258 legend.text = element_text( size = 22 ),
259 legend.title = element_blank(),
260 legend.key.size = unit( 1.5, 'lines' ) )
261
262title <- ggtitle( title )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000263
264# Store plot configurations as 1 variable
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700265fundamentalGraphData <- mainPlot +
266 plannedColor +
267 passedColor +
268 failedColor +
269 xScaleConfig +
270 yScaleConfig +
271 xLabel +
272 yLabel +
273 lineColors +
274 legendLabels +
275 theme +
276 title
277
278# ----------------------------
279# Generating Line Graph Format
280# ----------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000281
282print( "Generating line graph." )
283
284lineGraphFormat <- geom_line( size = 1.1 )
285pointFormat <- geom_point( size = 3 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000286
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700287result <- fundamentalGraphData +
288 lineGraphFormat +
289 pointFormat
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000290
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700291# -----------------------
292# Exporting Graph to File
293# -----------------------
294
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000295print( paste( "Saving result graph to", outputFile ) )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700296
297ggsave( outputFile,
298 width = imageWidth,
299 height = imageHeight,
300 dpi = imageDPI )
301
302print( paste( "[SUCCESS] Successfully wrote result graph out to", outputFile ) )