blob: 5cc5c355714248b3de0e5a2cf038284a3fb580a7 [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
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800146latestBuildDate <- fileData$date[1]
147
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800148dataFrame <- melt( categories )
149
150# Rename column names in dataFrame
151colnames( dataFrame ) <- c( "Tests",
152 "Status" )
153
154# Add build dates to the dataFrame
155dataFrame$build <- fileData$build
156
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 )
159dataFrame$Status <- factor( dataFrame$Status, levels = unique( dataFrame$Status ) )
160
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
169# Omit any data that doesn't exist
170dataFrame <- na.omit( dataFrame )
171
172print( "Data Frame Results:" )
173print( dataFrame )
174
175# **********************************************************
176# STEP 3: Generate graphs.
177# **********************************************************
178
179print( "**********************************************************" )
180print( "STEP 3: Generate Graph." )
181print( "**********************************************************" )
182
183# -------------------
184# Main Plot Generated
185# -------------------
186
187print( "Creating main plot." )
188
189mainPlot <- ggplot( data = dataFrame, aes( x = iterative,
190 y = Tests,
191 color = Status ) )
192
193# -------------------
194# Main Plot Formatted
195# -------------------
196
197print( "Formatting main plot." )
198
199# geom_ribbon is used so that there is a colored fill below the lines. These values shouldn't be changed.
200failedColor <- geom_ribbon( aes( ymin = 0,
201 ymax = dataFrame$num_failed ),
202 fill = webColor( "red" ),
203 linetype = 0,
204 alpha = 0.07 )
205
206passedColor <- geom_ribbon( aes( ymin = 0,
207 ymax = dataFrame$num_passed ),
208 fill = webColor( "green" ),
209 linetype = 0,
210 alpha = 0.05 )
211
212plannedColor <- geom_ribbon( aes( ymin = 0,
213 ymax = dataFrame$num_planned ),
214 fill = webColor( "blue" ),
215 linetype = 0,
216 alpha = 0.01 )
217
218# Colors for the lines
219lineColors <- scale_color_manual( values=c( webColor( "red" ),
220 webColor( "green" ),
221 webColor( "blue" ) ) )
222
223# ------------------------------
224# Fundamental Variables Assigned
225# ------------------------------
226
227print( "Generating fundamental graph data." )
228
229defaultTextSize()
230
231xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative,
232 label = dataFrame$build )
233yScaleConfig <- scale_y_continuous( breaks = seq( 0, max( dataFrame$Tests ),
234 by = ceiling( max( dataFrame$Tests ) / 10 ) ) )
235
236xLabel <- xlab( "Build Number" )
237yLabel <- ylab( "Test Cases" )
238
239legendLabels <- scale_colour_discrete( labels = c( "Failed Cases",
240 "Passed Cases",
241 "Planned Cases" ) )
242
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800243title <- labs( title = title, subtitle = lastUpdatedLabel( latestBuildDate ) )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800244
245# Store plot configurations as 1 variable
246fundamentalGraphData <- mainPlot +
247 plannedColor +
248 passedColor +
249 failedColor +
250 xScaleConfig +
251 yScaleConfig +
252 xLabel +
253 yLabel +
254 lineColors +
255 legendLabels +
256 graphTheme() + # from fundamentalGraphData.R
257 title
258
259# ----------------------------
260# Generating Line Graph Format
261# ----------------------------
262
263print( "Generating line graph." )
264
265lineGraphFormat <- geom_line( size = 1.1 )
266pointFormat <- geom_point( size = 3 )
267
268result <- fundamentalGraphData +
269 lineGraphFormat +
270 pointFormat
271
272# -----------------------
273# Exporting Graph to File
274# -----------------------
275
276saveGraph( outputFile ) # from saveGraph.R