blob: 93d58ed7d289295fff65d85487e54f12f7f172d9 [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# FUNCintent Results 20 Builds (https://jenkins.onosproject.org/view/QA/job/postjob-VM/lastSuccessfulBuild/artifact/FUNCintent_master_20-builds_graph.jpg):
22# Rscript trendIndividualTest.R <url> <port> <username> <pass> FUNCintent master 20 /path/to/save/directory/
23
24
25# **********************************************************
26# STEP 1: Data management.
27# **********************************************************
28
29print( "**********************************************************" )
30print( "STEP 1: Data management." )
31print( "**********************************************************" )
32
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
37# Args 1 through 6 reside in fundamentalGraphData.R
38buildsToShow <- 7
39save_directory <- 8
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." )
59
60if ( length( args ) != save_directory ){
61 specialArgs <- c( "#-builds-to-show" )
62 usage( "trendIndividualTest.R", specialArgs )
63 quit( status = 1 )
64}
65
66# -------------------------------
67# Create Title and Graph Filename
68# -------------------------------
69
70print( "Creating title of graph." )
71
72title <- paste( args[ graph_title ],
73 " - ",
74 args[ branch_name ],
75 " \n Results of Last ",
76 args[ buildsToShow ],
77 " Builds",
78 sep="" )
79
80print( "Creating graph filename." )
81
82outputFile <- paste( args[ save_directory ],
83 args[ graph_title ],
84 "_",
85 args[ branch_name ],
86 "_",
87 args[ buildsToShow ],
88 "-builds_graph.jpg",
89 sep="" )
90
91# ------------------
92# SQL Initialization
93# ------------------
94
95print( "Initializing SQL" )
96
97con <- initSQL( args[ database_host ],
98 args[ database_port ],
99 args[ database_u_id ],
100 args[ database_pw ] )
101
102# ---------------------
103# Test Case SQL Command
104# ---------------------
105print( "Generating Test Case SQL command." )
106
107command <- simpleSQLCommand( args[ graph_title ], args[ branch_name ], args[ buildsToShow ] )
108
109fileData <- retrieveData( con, command )
110
111# **********************************************************
112# STEP 2: Organize data.
113# **********************************************************
114
115print( "**********************************************************" )
116print( "STEP 2: Organize Data." )
117print( "**********************************************************" )
118
119# -------------------------------------------------------
120# Combining Passed, Failed, and Planned Data
121# -------------------------------------------------------
122
123print( "Combining Passed, Failed, and Planned Data." )
124
125requiredColumns <- c( "num_failed", "num_passed", "num_planned" )
126
127tryCatch( categories <- c( fileData[ requiredColumns] ),
128 error = function( e ) {
129 print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." )
130 print( "Required columns: " )
131 print( requiredColumns )
132 print( "Actual columns: " )
133 print( names( fileData ) )
134 print( "Error dump:" )
135 print( e )
136 quit( status = 1 )
137 }
138 )
139
140# --------------------
141# Construct Data Frame
142# --------------------
143
144print( "Constructing data frame from combined data." )
145
146dataFrame <- melt( categories )
147
148# Rename column names in dataFrame
149colnames( dataFrame ) <- c( "Tests",
150 "Status" )
151
152# Add build dates to the dataFrame
153dataFrame$build <- fileData$build
154
155# Format data frame so that the data is in the same order as it appeared in the file.
156dataFrame$Status <- as.character( dataFrame$Status )
157dataFrame$Status <- factor( dataFrame$Status, levels = unique( dataFrame$Status ) )
158
159# Add planned, passed, and failed results to the dataFrame (for the fill below the lines)
160dataFrame$num_planned <- fileData$num_planned
161dataFrame$num_passed <- fileData$num_passed
162dataFrame$num_failed <- fileData$num_failed
163
164# Adding a temporary reversed iterative list to the dataFrame so that there are no gaps in-between build numbers.
165dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) )
166
167# Omit any data that doesn't exist
168dataFrame <- na.omit( dataFrame )
169
170print( "Data Frame Results:" )
171print( dataFrame )
172
173# **********************************************************
174# STEP 3: Generate graphs.
175# **********************************************************
176
177print( "**********************************************************" )
178print( "STEP 3: Generate Graph." )
179print( "**********************************************************" )
180
181# -------------------
182# Main Plot Generated
183# -------------------
184
185print( "Creating main plot." )
186
187mainPlot <- ggplot( data = dataFrame, aes( x = iterative,
188 y = Tests,
189 color = Status ) )
190
191# -------------------
192# Main Plot Formatted
193# -------------------
194
195print( "Formatting main plot." )
196
197# geom_ribbon is used so that there is a colored fill below the lines. These values shouldn't be changed.
198failedColor <- geom_ribbon( aes( ymin = 0,
199 ymax = dataFrame$num_failed ),
200 fill = webColor( "red" ),
201 linetype = 0,
202 alpha = 0.07 )
203
204passedColor <- geom_ribbon( aes( ymin = 0,
205 ymax = dataFrame$num_passed ),
206 fill = webColor( "green" ),
207 linetype = 0,
208 alpha = 0.05 )
209
210plannedColor <- geom_ribbon( aes( ymin = 0,
211 ymax = dataFrame$num_planned ),
212 fill = webColor( "blue" ),
213 linetype = 0,
214 alpha = 0.01 )
215
216# Colors for the lines
217lineColors <- scale_color_manual( values=c( webColor( "red" ),
218 webColor( "green" ),
219 webColor( "blue" ) ) )
220
221# ------------------------------
222# Fundamental Variables Assigned
223# ------------------------------
224
225print( "Generating fundamental graph data." )
226
227defaultTextSize()
228
229xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative,
230 label = dataFrame$build )
231yScaleConfig <- scale_y_continuous( breaks = seq( 0, max( dataFrame$Tests ),
232 by = ceiling( max( dataFrame$Tests ) / 10 ) ) )
233
234xLabel <- xlab( "Build Number" )
235yLabel <- ylab( "Test Cases" )
236
237legendLabels <- scale_colour_discrete( labels = c( "Failed Cases",
238 "Passed Cases",
239 "Planned Cases" ) )
240
241title <- labs( title = title, subtitle = lastUpdatedLabel() )
242
243# Store plot configurations as 1 variable
244fundamentalGraphData <- mainPlot +
245 plannedColor +
246 passedColor +
247 failedColor +
248 xScaleConfig +
249 yScaleConfig +
250 xLabel +
251 yLabel +
252 lineColors +
253 legendLabels +
254 graphTheme() + # from fundamentalGraphData.R
255 title
256
257# ----------------------------
258# Generating Line Graph Format
259# ----------------------------
260
261print( "Generating line graph." )
262
263lineGraphFormat <- geom_line( size = 1.1 )
264pointFormat <- geom_point( size = 3 )
265
266result <- fundamentalGraphData +
267 lineGraphFormat +
268 pointFormat
269
270# -----------------------
271# Exporting Graph to File
272# -----------------------
273
274saveGraph( outputFile ) # from saveGraph.R