Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 1 | # 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 | |
| 29 | print( "**********************************************************" ) |
| 30 | print( "STEP 1: Data management." ) |
| 31 | print( "**********************************************************" ) |
| 32 | |
| 33 | # Command line arguments are read. Args include the database credentials, test name, branch name, and the directory to output files. |
| 34 | print( "Reading commmand-line args." ) |
| 35 | args <- commandArgs( trailingOnly=TRUE ) |
| 36 | |
| 37 | # Args 1 through 6 reside in fundamentalGraphData.R |
| 38 | buildsToShow <- 7 |
| 39 | save_directory <- 8 |
| 40 | |
| 41 | # ---------------- |
| 42 | # Import Libraries |
| 43 | # ---------------- |
| 44 | |
| 45 | print( "Importing libraries." ) |
| 46 | library( ggplot2 ) |
| 47 | library( reshape2 ) |
| 48 | library( RPostgreSQL ) |
Devin Lim | 324806b | 2018-05-11 15:36:52 -0700 | [diff] [blame] | 49 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" ) |
| 50 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" ) |
| 51 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" ) |
| 52 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 53 | |
| 54 | # ------------------- |
| 55 | # Check CLI Arguments |
| 56 | # ------------------- |
| 57 | |
| 58 | print( "Verifying CLI args." ) |
| 59 | |
| 60 | if ( 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 | |
| 70 | print( "Creating title of graph." ) |
| 71 | |
| 72 | title <- paste( args[ graph_title ], |
| 73 | " - ", |
| 74 | args[ branch_name ], |
| 75 | " \n Results of Last ", |
| 76 | args[ buildsToShow ], |
| 77 | " Builds", |
| 78 | sep="" ) |
| 79 | |
| 80 | print( "Creating graph filename." ) |
| 81 | |
| 82 | outputFile <- 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 | |
| 95 | print( "Initializing SQL" ) |
| 96 | |
| 97 | con <- 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 | # --------------------- |
| 105 | print( "Generating Test Case SQL command." ) |
| 106 | |
| 107 | command <- simpleSQLCommand( args[ graph_title ], args[ branch_name ], args[ buildsToShow ] ) |
| 108 | |
| 109 | fileData <- retrieveData( con, command ) |
| 110 | |
| 111 | # ********************************************************** |
| 112 | # STEP 2: Organize data. |
| 113 | # ********************************************************** |
| 114 | |
| 115 | print( "**********************************************************" ) |
| 116 | print( "STEP 2: Organize Data." ) |
| 117 | print( "**********************************************************" ) |
| 118 | |
| 119 | # ------------------------------------------------------- |
| 120 | # Combining Passed, Failed, and Planned Data |
| 121 | # ------------------------------------------------------- |
| 122 | |
| 123 | print( "Combining Passed, Failed, and Planned Data." ) |
| 124 | |
| 125 | requiredColumns <- c( "num_failed", "num_passed", "num_planned" ) |
| 126 | |
| 127 | tryCatch( 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 | |
| 144 | print( "Constructing data frame from combined data." ) |
| 145 | |
| 146 | dataFrame <- melt( categories ) |
| 147 | |
| 148 | # Rename column names in dataFrame |
| 149 | colnames( dataFrame ) <- c( "Tests", |
| 150 | "Status" ) |
| 151 | |
| 152 | # Add build dates to the dataFrame |
| 153 | dataFrame$build <- fileData$build |
| 154 | |
| 155 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 156 | dataFrame$Status <- as.character( dataFrame$Status ) |
| 157 | dataFrame$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) |
| 160 | dataFrame$num_planned <- fileData$num_planned |
| 161 | dataFrame$num_passed <- fileData$num_passed |
| 162 | dataFrame$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. |
| 165 | dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) ) |
| 166 | |
| 167 | # Omit any data that doesn't exist |
| 168 | dataFrame <- na.omit( dataFrame ) |
| 169 | |
| 170 | print( "Data Frame Results:" ) |
| 171 | print( dataFrame ) |
| 172 | |
| 173 | # ********************************************************** |
| 174 | # STEP 3: Generate graphs. |
| 175 | # ********************************************************** |
| 176 | |
| 177 | print( "**********************************************************" ) |
| 178 | print( "STEP 3: Generate Graph." ) |
| 179 | print( "**********************************************************" ) |
| 180 | |
| 181 | # ------------------- |
| 182 | # Main Plot Generated |
| 183 | # ------------------- |
| 184 | |
| 185 | print( "Creating main plot." ) |
| 186 | |
| 187 | mainPlot <- ggplot( data = dataFrame, aes( x = iterative, |
| 188 | y = Tests, |
| 189 | color = Status ) ) |
| 190 | |
| 191 | # ------------------- |
| 192 | # Main Plot Formatted |
| 193 | # ------------------- |
| 194 | |
| 195 | print( "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. |
| 198 | failedColor <- geom_ribbon( aes( ymin = 0, |
| 199 | ymax = dataFrame$num_failed ), |
| 200 | fill = webColor( "red" ), |
| 201 | linetype = 0, |
| 202 | alpha = 0.07 ) |
| 203 | |
| 204 | passedColor <- geom_ribbon( aes( ymin = 0, |
| 205 | ymax = dataFrame$num_passed ), |
| 206 | fill = webColor( "green" ), |
| 207 | linetype = 0, |
| 208 | alpha = 0.05 ) |
| 209 | |
| 210 | plannedColor <- 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 |
| 217 | lineColors <- scale_color_manual( values=c( webColor( "red" ), |
| 218 | webColor( "green" ), |
| 219 | webColor( "blue" ) ) ) |
| 220 | |
| 221 | # ------------------------------ |
| 222 | # Fundamental Variables Assigned |
| 223 | # ------------------------------ |
| 224 | |
| 225 | print( "Generating fundamental graph data." ) |
| 226 | |
| 227 | defaultTextSize() |
| 228 | |
| 229 | xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, |
| 230 | label = dataFrame$build ) |
| 231 | yScaleConfig <- scale_y_continuous( breaks = seq( 0, max( dataFrame$Tests ), |
| 232 | by = ceiling( max( dataFrame$Tests ) / 10 ) ) ) |
| 233 | |
| 234 | xLabel <- xlab( "Build Number" ) |
| 235 | yLabel <- ylab( "Test Cases" ) |
| 236 | |
| 237 | legendLabels <- scale_colour_discrete( labels = c( "Failed Cases", |
| 238 | "Passed Cases", |
| 239 | "Planned Cases" ) ) |
| 240 | |
| 241 | title <- labs( title = title, subtitle = lastUpdatedLabel() ) |
| 242 | |
| 243 | # Store plot configurations as 1 variable |
| 244 | fundamentalGraphData <- 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 | |
| 261 | print( "Generating line graph." ) |
| 262 | |
| 263 | lineGraphFormat <- geom_line( size = 1.1 ) |
| 264 | pointFormat <- geom_point( size = 3 ) |
| 265 | |
| 266 | result <- fundamentalGraphData + |
| 267 | lineGraphFormat + |
| 268 | pointFormat |
| 269 | |
| 270 | # ----------------------- |
| 271 | # Exporting Graph to File |
| 272 | # ----------------------- |
| 273 | |
| 274 | saveGraph( outputFile ) # from saveGraph.R |