blob: 46f671fb7052ffacf0ba046e8fbfd6a51aebc25c [file] [log] [blame]
Jeremy Ronquillodae11042018-02-21 09:21:44 -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# Example scripts:
21#
22# ALL tests with pass/fail (https://jenkins.onosproject.org/view/QA/job/postjob-VM/lastSuccessfulBuild/artifact/ALL_master_build-latest_executed_pieChart.jpg):
23# Rscript pieMultipleTests.R <url> <port> <username> <pass> ALL master "FUNCbgpls,FUNCflow,FUNCformCluster,FUNCgroup,FUNCintent,FUNCintentRest,FUNCipv6Intent,FUNCnetCfg,FUNCnetconf,FUNCoptical,FUNCovsdbtest,FUNCvirNetNB,HAbackupRecover,HAclusterRestart,HAfullNetPartition,HAkillNodes,HAsanity,HAscaling,HAsingleInstanceRestart,HAstopNodes,HAswapNodes,HAupgrade,HAupgradeRollback,PLATdockertest,USECASE_SdnipFunction,USECASE_SdnipFunctionCluster,VPLSBasic,VPLSfailsafe" latest y /path/to/save/directory/
24#
25# ALL tests with execution result (https://jenkins.onosproject.org/view/QA/job/postjob-VM/lastSuccessfulBuild/artifact/ALL_master_build-latest_passfail_pieChart.jpg):
26# Rscript pieMultipleTests.R <url> <port> <username> <pass> ALL master "FUNCbgpls,FUNCflow,FUNCformCluster,FUNCgroup,FUNCintent,FUNCintentRest,FUNCipv6Intent,FUNCnetCfg,FUNCnetconf,FUNCoptical,FUNCovsdbtest,FUNCvirNetNB,HAbackupRecover,HAclusterRestart,HAfullNetPartition,HAkillNodes,HAsanity,HAscaling,HAsingleInstanceRestart,HAstopNodes,HAswapNodes,HAupgrade,HAupgradeRollback,PLATdockertest,USECASE_SdnipFunction,USECASE_SdnipFunctionCluster,VPLSBasic,VPLSfailsafe" latest n /path/to/save/directory/
27
28# **********************************************************
29# STEP 1: Data management.
30# **********************************************************
31
32print( "**********************************************************" )
33print( "STEP 1: Data management." )
34print( "**********************************************************" )
35
36tests_to_include <- 7
37build_to_show <- 8
38is_displaying_plan <- 9
39save_directory <- 10
40
41# ----------------
42# Import Libraries
43# ----------------
44
45print( "Importing libraries." )
46library( ggplot2 )
47library( reshape2 )
48library( RPostgreSQL )
Devin Lim324806b2018-05-11 15:36:52 -070049source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" )
50source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" )
51source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" )
52source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" )
Jeremy Ronquillodae11042018-02-21 09:21:44 -080053
54# -------------------
55# Check CLI Arguments
56# -------------------
57
58print( "Verifying CLI args." )
59args <- commandArgs( trailingOnly=TRUE )
60
61if ( is.na( args[ save_directory ] ) ){
62
63 # Check if sufficient args are provided.
64 if ( length( args ) != save_directory ){
65 specialArgs <- c( "tests-to-include",
66 "build-to-show",
67 "is-displaying-plan" )
68 usage( "trendSCPF.R", specialArgs )
69 quit( status = 1 )
70 }
71}
72
73# ------------------
74# SQL Initialization
75# ------------------
76
77print( "Initializing SQL" )
78
79con <- dbConnect( dbDriver( "PostgreSQL" ),
80 dbname = "onostest",
81 host = args[ database_host ],
82 port = strtoi( args[ database_port ] ),
83 user = args[ database_u_id ],
84 password = args[ database_pw ] )
85
86# ---------------------
87# Test Case SQL Command
88# ---------------------
89
90print( "Generating Test Case SQL command." )
91
92command <- generateMultiTestSingleBuildSQLCommand( args[ branch_name ],
93 args[ tests_to_include ],
94 args[ build_to_show ] )
95
96dbResult <- retrieveData( con, command )
97
98print( "dbResult:" )
99print( dbResult )
100
101# -------------------------------
102# Create Title and Graph Filename
103# -------------------------------
104
105print( "Creating title of graph." )
106
107typeOfPieTitle <- "Executed Results"
108typeOfPieFile <- "_passfail"
109isPlannedPie <- FALSE
110if ( args[ is_displaying_plan ] == "y" ){
111 typeOfPieTitle <- "Test Execution"
112 typeOfPieFile <- "_executed"
113 isPlannedPie <- TRUE
114}
115
116if ( args[ build_to_show ] == "latest" ){
117 buildTitle <- "\nLatest Test Results"
118 filebuild_to_show <- "latest"
119} else {
120 buildTitle <- paste( " \n Build #", args[ build_to_show ], sep="" )
121 filebuild_to_show <- args[ build_to_show ]
122}
123
124title <- paste( args[ graph_title ],
125 " Tests: Summary of ",
126 typeOfPieTitle,
127 "",
128 " - ",
129 args[ branch_name ],
130 buildTitle,
131 sep="" )
132
133print( "Creating graph filename." )
134
135outputFile <- paste( args[ save_directory ],
136 args[ graph_title ],
137 "_",
138 args[ branch_name ],
139 "_build-",
140 filebuild_to_show,
141 typeOfPieFile,
142 "_pieChart.jpg",
143 sep="" )
144
145# **********************************************************
146# STEP 2: Organize data.
147# **********************************************************
148
149print( "**********************************************************" )
150print( "STEP 2: Organize Data." )
151print( "**********************************************************" )
152
153t <- subset( dbResult, select=c( "actual_test_name", "num_passed", "num_failed", "num_planned" ) )
154
155executedTests <- sum( t$num_passed ) + sum( t$num_failed )
156
157# --------------------
158# Construct Data Frame
159# --------------------
160
161print( "Constructing Data Frame." )
162
163if ( isPlannedPie ){
164 nonExecutedTests <- sum( t$num_planned ) - executedTests
165 totalTests <- sum( t$num_planned )
166
167 executedPercent <- round( executedTests / totalTests * 100, digits = 2 )
168 nonExecutedPercent <- 100 - executedPercent
169
170 dfData <- c( nonExecutedPercent, executedPercent )
171
172 labels <- c( "Executed Test Cases", "Skipped Test Cases" )
173
174 dataFrame <- data.frame(
175 rawData <- dfData,
176 displayedData <- c( paste( nonExecutedPercent, "%\n", nonExecutedTests, " / ", totalTests, " Tests", sep="" ), paste( executedPercent, "%\n", executedTests, " / ", totalTests," Tests", sep="" ) ),
177 names <- factor( rev( labels ), levels = labels ) )
178} else {
179 sumPassed <- sum( t$num_passed )
180 sumFailed <- sum( t$num_failed )
181 sumExecuted <- sumPassed + sumFailed
182
183 percentPassed <- sumPassed / sumExecuted
184 percentFailed <- sumFailed / sumExecuted
185
186 dfData <- c( percentFailed, percentPassed )
187 labels <- c( "Failed Test Cases", "Passed Test Cases" )
188
189 dataFrame <- data.frame(
190 rawData <- dfData,
191 displayedData <- c( paste( round( percentFailed * 100, 2 ), "%\n", sumFailed, " / ", sumExecuted, " Tests", sep="" ), paste( round( percentPassed * 100, 2 ), "%\n", sumPassed, " / ", sumExecuted, " Tests", sep="" ) ),
192 names <- factor( labels, levels = rev( labels ) ) )
193}
194
195print( "Data Frame Results:" )
196print( dataFrame )
197
198# **********************************************************
199# STEP 3: Generate graphs.
200# **********************************************************
201
202print( "**********************************************************" )
203print( "STEP 3: Generate Graph." )
204print( "**********************************************************" )
205
206# -------------------
207# Main Plot Generated
208# -------------------
209
210print( "Creating main plot." )
211# Create the primary plot here.
212# ggplot contains the following arguments:
213# - data: the data frame that the graph will be based off of
214# - aes: the asthetics of the graph which require:
215# - x: x-axis values (usually iterative, but it will become build # later)
216# - y: y-axis values (usually tests)
217# - color: the category of the colored lines (usually status of test)
218
219mainPlot <- ggplot( data = dataFrame,
220 aes( x = "", y=rawData, fill = names ) )
221
222# -------------------
223# Main Plot Formatted
224# -------------------
225
226print( "Formatting main plot." )
227
228# ------------------------------
229# Fundamental Variables Assigned
230# ------------------------------
231
232print( "Generating fundamental graph data." )
233
234defaultTextSize()
235
236# Set other graph configurations here.
237theme <- graphTheme() +
238 theme( axis.text.x = element_blank(),
239 axis.title.x = element_blank(),
240 axis.title.y = element_blank(),
241 axis.ticks = element_blank(),
242 panel.border = element_blank(),
243 panel.grid=element_blank(),
244 legend.position = "bottom" )
245
246title <- labs( title = title, subtitle = lastUpdatedLabel() )
247
248# Store plot configurations as 1 variable
249fundamentalGraphData <- mainPlot +
250 theme +
251 title
252
253# ----------------------------
254# Generating Line Graph Format
255# ----------------------------
256
257print( "Generating line graph." )
258
259if ( isPlannedPie ){
260 executedColor <- webColor( "light_blue" )
261 nonExecutedColor <- webColor( "gray" )
262 pieColors <- scale_fill_manual( values = c( executedColor, nonExecutedColor ) )
263} else {
264 passColor <- webColor( "green" )
265 failColor <- webColor( "red" )
266 pieColors <- scale_fill_manual( values = c( passColor, failColor ) )
267}
268
269pieFormat <- geom_bar( width = 1, stat = "identity" )
270pieLabels <- geom_text( aes( y = rawData / length( rawData ) + c( 0, cumsum( rawData )[ -length( rawData ) ] ) ),
271 label = dataFrame$displayedData,
272 size = 7, fontface = "bold" )
273
274
275result <- fundamentalGraphData +
276 pieFormat + coord_polar( "y" ) + pieLabels + pieColors
277
278# -----------------------
279# Exporting Graph to File
280# -----------------------
281
282saveGraph( outputFile )