blob: 0b731b57a3721dbca00f3ad1beb281e26e106340 [file] [log] [blame]
Jeremy Ronquillo478a8c12018-01-08 13:59:47 -08001# Copyright 2018 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,
21# please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu
22
23# **********************************************************
24# STEP 1: Data management.
25# **********************************************************
26
27print( "**********************************************************" )
28print( "STEP 1: Data management." )
29print( "**********************************************************" )
30
31# Command line arguments are read. Args include the database credentials, test name, branch name, and the directory to output files.
32print( "Reading commmand-line args." )
33args <- commandArgs( trailingOnly=TRUE )
34
35databaseHost <- 1
36databasePort <- 2
37databaseUserID <- 3
38databasePassword <- 4
39testSuiteName <- 5
40branchName <- 6
41testsToInclude <- 7
42buildToShow <- 8
43isDisplayingPlan <- 9
44saveDirectory <- 10
45
46# ----------------
47# Import Libraries
48# ----------------
49
50print( "Importing libraries." )
51library( ggplot2 )
52library( reshape2 )
53library( RPostgreSQL )
54
55# -------------------
56# Check CLI Arguments
57# -------------------
58
59print( "Verifying CLI args." )
60
61if ( is.na( args[ saveDirectory ] ) ){
62
63 print( paste( "Usage: Rscript testCategoryPiePassFail.R",
64 "<database-host>",
65 "<database-port>",
66 "<database-user-id>",
67 "<database-password>",
68 "<test-suite-name>",
69 "<branch-name>",
70 "<tests-to-include-(as-one-string)>",
71 "<build-to-show>",
72 "<is-displaying-plan>",
73 "<directory-to-save-graphs>",
74 sep=" " ) )
75
76 quit( status = 1 ) # basically exit(), but in R
77}
78
79# ------------------
80# SQL Initialization
81# ------------------
82
83print( "Initializing SQL" )
84
85con <- dbConnect( dbDriver( "PostgreSQL" ),
86 dbname = "onostest",
87 host = args[ databaseHost ],
88 port = strtoi( args[ databasePort ] ),
89 user = args[ databaseUserID ],
90 password = args[ databasePassword ] )
91
92# ---------------------
93# Test Case SQL Command
94# ---------------------
95
96print( "Generating Test Case SQL command." )
97
98tests <- "'"
99for ( test in as.list( strsplit( args[ testsToInclude ], "," )[[1]] ) ){
100 tests <- paste( tests, test, "','", sep="" )
101}
102tests <- substr( tests, 0, nchar( tests ) - 2 )
103
104fileBuildToShow <- args[ buildToShow ]
105operator <- "= "
106buildTitle <- ""
107if ( args[ buildToShow ] == "latest" ){
108 buildTitle <- "\nLatest Test Results"
109 operator <- ">= "
110 args[ buildToShow ] <- "1000"
111} else {
112 buildTitle <- paste( " \n Build #", args[ buildToShow ], sep="" )
113}
114
115command <- paste( "SELECT * ",
116 "FROM executed_test_tests a ",
117 "WHERE ( SELECT COUNT( * ) FROM executed_test_tests b ",
118 "WHERE b.branch='",
119 args[ branchName ],
120 "' AND b.actual_test_name IN (",
121 tests,
122 ") AND a.actual_test_name = b.actual_test_name AND a.date <= b.date AND b.build ", operator,
123 args[ buildToShow ],
124 " ) = ",
125 1,
126 " AND a.branch='",
127 args[ branchName ],
128 "' AND a.actual_test_name IN (",
129 tests,
130 ") AND a.build ", operator,
131 args[ buildToShow ],
132 " ORDER BY a.actual_test_name DESC, a.date DESC",
133 sep="")
134
135print( "Sending SQL command:" )
136print( command )
137
138dbResult <- dbGetQuery( con, command )
139
140print( "dbResult:" )
141print( dbResult )
142
143# -------------------------------
144# Create Title and Graph Filename
145# -------------------------------
146
147print( "Creating title of graph." )
148
149typeOfPieTitle <- "Executed Results"
150typeOfPieFile <- "_passfail"
151isPlannedPie <- FALSE
152if ( args[ isDisplayingPlan ] == "y" ){
153 typeOfPieTitle <- "Test Execution"
154 typeOfPieFile <- "_executed"
155 isPlannedPie <- TRUE
156}
157
158title <- paste( args[ testSuiteName ],
159 " Tests: Summary of ",
160 typeOfPieTitle,
161 "",
162 " - ",
163 args[ branchName ],
164 buildTitle,
165 sep="" )
166
167print( "Creating graph filename." )
168
169outputFile <- paste( args[ saveDirectory ],
170 args[ testSuiteName ],
171 "_",
172 args[ branchName ],
173 "_build-",
174 fileBuildToShow,
175 typeOfPieFile,
176 "_pieChart.jpg",
177 sep="" )
178
179# **********************************************************
180# STEP 2: Organize data.
181# **********************************************************
182
183print( "**********************************************************" )
184print( "STEP 2: Organize Data." )
185print( "**********************************************************" )
186
187t <- subset( dbResult, select=c( "actual_test_name", "num_passed", "num_failed", "num_planned" ) )
188
189executedTests <- sum( t$num_passed ) + sum( t$num_failed )
190
191# --------------------
192# Construct Data Frame
193# --------------------
194
195print( "Constructing Data Frame." )
196
197if ( isPlannedPie ){
198
199 nonExecutedTests <- sum( t$num_planned ) - executedTests
200 totalTests <- sum( t$num_planned )
201
202 executedPercent <- round( executedTests / totalTests * 100, digits = 2 )
203 nonExecutedPercent <- 100 - executedPercent
204
205 dfData <- c( nonExecutedPercent, executedPercent )
206
207 labels <- c( "Executed Test Cases", "Skipped Test Cases" )
208
209 dataFrame <- data.frame(
210 rawData <- dfData,
211 displayedData <- c( paste( nonExecutedPercent, "%\n", nonExecutedTests, " / ", totalTests, " Tests", sep="" ), paste( executedPercent, "%\n", executedTests, " / ", totalTests," Tests", sep="" ) ),
212 names <- factor( rev( labels ), levels = labels ) )
213} else {
214
215 sumPassed <- sum( t$num_passed )
216 sumFailed <- sum( t$num_failed )
217 sumExecuted <- sumPassed + sumFailed
218
219 percentPassed <- sumPassed / sumExecuted
220 percentFailed <- sumFailed / sumExecuted
221
222 dfData <- c( percentFailed, percentPassed )
223 labels <- c( "Failed Test Cases", "Passed Test Cases" )
224
225 dataFrame <- data.frame(
226 rawData <- dfData,
227 displayedData <- c( paste( round( percentFailed * 100, 2 ), "%\n", sumFailed, " / ", sumExecuted, " Tests", sep="" ), paste( round( percentPassed * 100, 2 ), "%\n", sumPassed, " / ", sumExecuted, " Tests", sep="" ) ),
228 names <- factor( labels, levels = rev( labels ) ) )
229}
230
231print( "Data Frame Results:" )
232print( dataFrame )
233
234# **********************************************************
235# STEP 3: Generate graphs.
236# **********************************************************
237
238print( "**********************************************************" )
239print( "STEP 3: Generate Graph." )
240print( "**********************************************************" )
241
242# -------------------
243# Main Plot Generated
244# -------------------
245
246print( "Creating main plot." )
247# Create the primary plot here.
248# ggplot contains the following arguments:
249# - data: the data frame that the graph will be based off of
250# - aes: the asthetics of the graph which require:
251# - x: x-axis values (usually iterative, but it will become build # later)
252# - y: y-axis values (usually tests)
253# - color: the category of the colored lines (usually status of test)
254
255mainPlot <- ggplot( data = dataFrame,
256 aes( x = "", y=rawData, fill = names ) )
257
258# -------------------
259# Main Plot Formatted
260# -------------------
261
262print( "Formatting main plot." )
263
264# ------------------------------
265# Fundamental Variables Assigned
266# ------------------------------
267
268print( "Generating fundamental graph data." )
269
270theme_set( theme_grey( base_size = 26 ) ) # set the default text size of the graph.
271
272imageWidth <- 12
273imageHeight <- 10
274imageDPI <- 200
275
276# Set other graph configurations here.
277theme <- theme( plot.title = element_text( hjust = 0.5, size = 30, face ='bold' ),
278 axis.text.x = element_blank(),
279 axis.title.x = element_blank(),
280 axis.title.y = element_blank(),
281 axis.ticks = element_blank(),
282 panel.border = element_blank(),
283 panel.grid=element_blank(),
284 legend.position = "bottom",
285 legend.text = element_text( size = 22 ),
286 legend.title = element_blank(),
287 legend.key.size = unit( 1.5, 'lines' ),
288 plot.subtitle = element_text( size=16, hjust=1.0 ) )
289
290subtitle <- paste( "Last Updated: ", format( Sys.time(), format = "%b %d, %Y at %I:%M %p %Z" ), sep="" )
291
292title <- labs( title = title, subtitle = subtitle )
293
294# Store plot configurations as 1 variable
295fundamentalGraphData <- mainPlot +
296 theme +
297 title
298
299# ----------------------------
300# Generating Line Graph Format
301# ----------------------------
302
303print( "Generating line graph." )
304
305if ( isPlannedPie ){
306 executedColor <- "#00A5FF" # Blue
307 nonExecutedColor <- "#CCCCCC" # Gray
308 pieColors <- scale_fill_manual( values = c( executedColor, nonExecutedColor ) )
309} else {
310 passColor <- "#16B645" # Green
311 failColor <- "#E02020" # Red
312 pieColors <- scale_fill_manual( values = c( passColor, failColor ) )
313}
314
315pieFormat <- geom_bar( width = 1, stat = "identity" )
316pieLabels <- geom_text( aes( y = rawData / length( rawData ) + c( 0, cumsum( rawData )[ -length( rawData ) ] ) ),
317 label = dataFrame$displayedData,
318 size = 7, fontface = "bold" )
319
320
321result <- fundamentalGraphData +
322 pieFormat + coord_polar( "y" ) + pieLabels + pieColors
323# -----------------------
324# Exporting Graph to File
325# -----------------------
326
327print( paste( "Saving result graph to", outputFile ) )
328
329tryCatch( ggsave( outputFile,
330 width = imageWidth,
331 height = imageHeight,
332 dpi = imageDPI ),
333 error = function( e ){
334 print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
335 print( e )
336 quit( status = 1 )
337 }
338 )
339
340print( paste( "[SUCCESS] Successfully wrote result graph out to", outputFile ) )
341quit( status = 0 )