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 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 146 | latestBuildDate <- fileData$date[1] |
| 147 | |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 148 | dataFrame <- melt( categories ) |
| 149 | |
| 150 | # Rename column names in dataFrame |
| 151 | colnames( dataFrame ) <- c( "Tests", |
| 152 | "Status" ) |
| 153 | |
| 154 | # Add build dates to the dataFrame |
| 155 | dataFrame$build <- fileData$build |
| 156 | |
| 157 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 158 | dataFrame$Status <- as.character( dataFrame$Status ) |
| 159 | dataFrame$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) |
| 162 | dataFrame$num_planned <- fileData$num_planned |
| 163 | dataFrame$num_passed <- fileData$num_passed |
| 164 | dataFrame$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. |
| 167 | dataFrame$iterative <- rev( seq( 1, nrow( fileData ), by = 1 ) ) |
| 168 | |
| 169 | # Omit any data that doesn't exist |
| 170 | dataFrame <- na.omit( dataFrame ) |
| 171 | |
| 172 | print( "Data Frame Results:" ) |
| 173 | print( dataFrame ) |
| 174 | |
| 175 | # ********************************************************** |
| 176 | # STEP 3: Generate graphs. |
| 177 | # ********************************************************** |
| 178 | |
| 179 | print( "**********************************************************" ) |
| 180 | print( "STEP 3: Generate Graph." ) |
| 181 | print( "**********************************************************" ) |
| 182 | |
| 183 | # ------------------- |
| 184 | # Main Plot Generated |
| 185 | # ------------------- |
| 186 | |
| 187 | print( "Creating main plot." ) |
| 188 | |
| 189 | mainPlot <- ggplot( data = dataFrame, aes( x = iterative, |
| 190 | y = Tests, |
| 191 | color = Status ) ) |
| 192 | |
| 193 | # ------------------- |
| 194 | # Main Plot Formatted |
| 195 | # ------------------- |
| 196 | |
| 197 | print( "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. |
| 200 | failedColor <- geom_ribbon( aes( ymin = 0, |
| 201 | ymax = dataFrame$num_failed ), |
| 202 | fill = webColor( "red" ), |
| 203 | linetype = 0, |
| 204 | alpha = 0.07 ) |
| 205 | |
| 206 | passedColor <- geom_ribbon( aes( ymin = 0, |
| 207 | ymax = dataFrame$num_passed ), |
| 208 | fill = webColor( "green" ), |
| 209 | linetype = 0, |
| 210 | alpha = 0.05 ) |
| 211 | |
| 212 | plannedColor <- 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 |
| 219 | lineColors <- scale_color_manual( values=c( webColor( "red" ), |
| 220 | webColor( "green" ), |
| 221 | webColor( "blue" ) ) ) |
| 222 | |
| 223 | # ------------------------------ |
| 224 | # Fundamental Variables Assigned |
| 225 | # ------------------------------ |
| 226 | |
| 227 | print( "Generating fundamental graph data." ) |
| 228 | |
| 229 | defaultTextSize() |
| 230 | |
| 231 | xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, |
| 232 | label = dataFrame$build ) |
| 233 | yScaleConfig <- scale_y_continuous( breaks = seq( 0, max( dataFrame$Tests ), |
| 234 | by = ceiling( max( dataFrame$Tests ) / 10 ) ) ) |
| 235 | |
| 236 | xLabel <- xlab( "Build Number" ) |
| 237 | yLabel <- ylab( "Test Cases" ) |
| 238 | |
| 239 | legendLabels <- scale_colour_discrete( labels = c( "Failed Cases", |
| 240 | "Passed Cases", |
| 241 | "Planned Cases" ) ) |
| 242 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 243 | title <- labs( title = title, subtitle = lastUpdatedLabel( latestBuildDate ) ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 244 | |
| 245 | # Store plot configurations as 1 variable |
| 246 | fundamentalGraphData <- 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 | |
| 263 | print( "Generating line graph." ) |
| 264 | |
| 265 | lineGraphFormat <- geom_line( size = 1.1 ) |
| 266 | pointFormat <- geom_point( size = 3 ) |
| 267 | |
| 268 | result <- fundamentalGraphData + |
| 269 | lineGraphFormat + |
| 270 | pointFormat |
| 271 | |
| 272 | # ----------------------- |
| 273 | # Exporting Graph to File |
| 274 | # ----------------------- |
| 275 | |
| 276 | saveGraph( outputFile ) # from saveGraph.R |