blob: f85477b1f7d2e2588a3f8c706174e9ef0d3959e9 [file] [log] [blame]
Jeremy Ronquillodae11042018-02-21 09:21:44 -08001# 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# Example script:
21# FUNC Test Results Trend (https://jenkins.onosproject.org/view/QA/job/postjob-VM/lastSuccessfulBuild/artifact/FUNC_master_overview.jpg):
22# Rscript trendMultipleTests.R <url> <port> <username> <pass> FUNC master "FUNCflow,FUNCformCluster,FUNCgroup,FUNCintent,FUNCintentRest,FUNCipv6Intent,FUNCnetCfg,FUNCnetconf,FUNCoptical,FUNCovsdbtest" 20 /path/to/save/directory/
23
24# **********************************************************
25# STEP 1: Data management.
26# **********************************************************
27
28print( "**********************************************************" )
29print( "STEP 1: Data management." )
30print( "**********************************************************" )
31
32tests_to_include <- 7
33builds_to_show <- 8
34save_directory <- 9
35
36# ----------------
37# Import Libraries
38# ----------------
39
40print( "Importing libraries." )
41library( ggplot2 )
42library( reshape2 )
43library( RPostgreSQL )
Devin Lim324806b2018-05-11 15:36:52 -070044source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" )
45source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" )
46source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" )
47source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" )
Jeremy Ronquillodae11042018-02-21 09:21:44 -080048
49# -------------------
50# Check CLI Arguments
51# -------------------
52
53print( "Verifying CLI args." )
54
55args <- commandArgs( trailingOnly=TRUE )
56
57if ( length( args ) != save_directory ){
58 specialArgs <- c( "tests-to-include-(as-one-string)",
59 "builds-to-show" )
60 usage( "trendMultipleTests.R", specialArgs )
61 quit( status = 1 )
62}
63
64# -------------------------------
65# Create Title and Graph Filename
66# -------------------------------
67
68print( "Creating title of graph." )
69
70title <- paste( args[ graph_title ],
71 " Test Results Trend - ",
72 args[ branch_name ],
73 " \n Results of Last ",
74 args[ builds_to_show ],
75 " Nightly Builds",
76 sep="" )
77
78print( "Creating graph filename." )
79
80outputFile <- paste( args[ save_directory ],
81 args[ graph_title ],
82 "_",
83 args[ branch_name ],
84 "_overview.jpg",
85 sep="" )
86
87# ------------------
88# SQL Initialization
89# ------------------
90
91print( "Initializing SQL" )
92
93con <- initSQL( args[ database_host ],
94 args[ database_port ],
95 args[ database_u_id ],
96 args[ database_pw ] )
97
98# ---------------------
99# Test Case SQL Command
100# ---------------------
101
102print( "Generating Test Case SQL command." )
103
104command <- generateMultiTestMultiBuildSQLCommand( args[ branch_name ],
105 args[ tests_to_include ],
106 args[ builds_to_show ] )
107
108dbResult <- retrieveData( con, command )
109maxBuild <- max( dbResult[ 'build' ] ) - strtoi( args[ builds_to_show ] )
110dbResult <- dbResult[ which( dbResult[,4] > maxBuild ), ]
111
112# **********************************************************
113# STEP 2: Organize data.
114# **********************************************************
115
116print( "**********************************************************" )
117print( "STEP 2: Organize Data." )
118print( "**********************************************************" )
119
120t <- subset( dbResult, select=c( "actual_test_name", "build", "num_failed" ) )
121t$num_failed <- ceiling( t$num_failed / ( t$num_failed + 1 ) )
122t$num_planned <- 1
123
124fileData <- aggregate( t$num_failed, by=list( Category=t$build ), FUN=sum )
125colnames( fileData ) <- c( "build", "num_failed" )
126
127fileData$num_planned <- ( aggregate( t$num_planned, by=list( Category=t$build ), FUN=sum ) )$x
128fileData$num_passed <- fileData$num_planned - fileData$num_failed
129
130print(fileData)
131
132# --------------------
133# Construct Data Frame
134# --------------------
135#
136
137dataFrame <- melt( subset( fileData, select=c( "num_failed", "num_passed", "num_planned" ) ) )
138dataFrame$build <- fileData$build
139colnames( dataFrame ) <- c( "status", "results", "build" )
140
141dataFrame$num_failed <- fileData$num_failed
142dataFrame$num_passed <- fileData$num_passed
143dataFrame$num_planned <- fileData$num_planned
144dataFrame$iterative <- seq( 1, nrow( fileData ), by = 1 )
145
146print( "Data Frame Results:" )
147print( dataFrame )
148
149# **********************************************************
150# STEP 3: Generate graphs.
151# **********************************************************
152
153print( "**********************************************************" )
154print( "STEP 3: Generate Graph." )
155print( "**********************************************************" )
156
157# -------------------
158# Main Plot Generated
159# -------------------
160
161print( "Creating main plot." )
162# Create the primary plot here.
163# ggplot contains the following arguments:
164# - data: the data frame that the graph will be based off of
165# - aes: the asthetics of the graph which require:
166# - x: x-axis values (usually iterative, but it will become build # later)
167# - y: y-axis values (usually tests)
168# - color: the category of the colored lines (usually status of test)
169
170mainPlot <- ggplot( data = dataFrame, aes( x = iterative,
171 y = results,
172 color = status ) )
173
174# -------------------
175# Main Plot Formatted
176# -------------------
177
178print( "Formatting main plot." )
179
180# geom_ribbon is used so that there is a colored fill below the lines. These values shouldn't be changed.
181failedColor <- geom_ribbon( aes( ymin = 0,
182 ymax = dataFrame$num_failed ),
183 fill = webColor( "red" ),
184 linetype = 0,
185 alpha = 0.07 )
186
187passedColor <- geom_ribbon( aes( ymin = 0,
188 ymax = dataFrame$num_passed ),
189 fill = webColor( "light_blue" ),
190 linetype = 0,
191 alpha = 0.05 )
192
193plannedColor <- geom_ribbon( aes( ymin = 0,
194 ymax = dataFrame$num_planned ),
195 fill = webColor( "black" ),
196 linetype = 0,
197 alpha = 0.01 )
198
199# Colors for the lines
200lineColors <- scale_color_manual( values=c( webColor( "red" ),
201 webColor( "light_blue" ),
202 webColor( "black" )),
203 labels = c( "Containing Failures",
204 "No Failures",
205 "Total Built" ) )
206
207# ------------------------------
208# Fundamental Variables Assigned
209# ------------------------------
210
211print( "Generating fundamental graph data." )
212
213defaultTextSize()
214
215xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative,
216 label = dataFrame$build )
217yScaleConfig <- scale_y_continuous( breaks = seq( 0, max( dataFrame$results ),
218 by = ceiling( max( dataFrame$results ) / 10 ) ) )
219
220xLabel <- xlab( "Build Number" )
221yLabel <- ylab( "Tests" )
222
223theme <- graphTheme()
224
225title <- labs( title = title, subtitle = lastUpdatedLabel() )
226
227# Store plot configurations as 1 variable
228fundamentalGraphData <- mainPlot +
229 plannedColor +
230 passedColor +
231 failedColor +
232 xScaleConfig +
233 yScaleConfig +
234 xLabel +
235 yLabel +
236 theme +
237 title +
238 lineColors
239
240# ----------------------------
241# Generating Line Graph Format
242# ----------------------------
243
244print( "Generating line graph." )
245
246lineGraphFormat <- geom_line( size = 1.1 )
247pointFormat <- geom_point( size = 3 )
248
249result <- fundamentalGraphData +
250 lineGraphFormat +
251 pointFormat
252
253# -----------------------
254# Exporting Graph to File
255# -----------------------
256
257saveGraph( outputFile )