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 | # 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 | |
| 28 | print( "**********************************************************" ) |
| 29 | print( "STEP 1: Data management." ) |
| 30 | print( "**********************************************************" ) |
| 31 | |
| 32 | tests_to_include <- 7 |
| 33 | builds_to_show <- 8 |
| 34 | save_directory <- 9 |
| 35 | |
| 36 | # ---------------- |
| 37 | # Import Libraries |
| 38 | # ---------------- |
| 39 | |
| 40 | print( "Importing libraries." ) |
| 41 | library( ggplot2 ) |
| 42 | library( reshape2 ) |
| 43 | library( RPostgreSQL ) |
Devin Lim | 324806b | 2018-05-11 15:36:52 -0700 | [diff] [blame] | 44 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" ) |
| 45 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" ) |
| 46 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" ) |
| 47 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 48 | |
| 49 | # ------------------- |
| 50 | # Check CLI Arguments |
| 51 | # ------------------- |
| 52 | |
| 53 | print( "Verifying CLI args." ) |
| 54 | |
| 55 | args <- commandArgs( trailingOnly=TRUE ) |
| 56 | |
| 57 | if ( 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 | |
| 68 | print( "Creating title of graph." ) |
| 69 | |
| 70 | title <- 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 | |
| 78 | print( "Creating graph filename." ) |
| 79 | |
| 80 | outputFile <- 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 | |
| 91 | print( "Initializing SQL" ) |
| 92 | |
| 93 | con <- 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 | |
| 102 | print( "Generating Test Case SQL command." ) |
| 103 | |
| 104 | command <- generateMultiTestMultiBuildSQLCommand( args[ branch_name ], |
| 105 | args[ tests_to_include ], |
| 106 | args[ builds_to_show ] ) |
| 107 | |
| 108 | dbResult <- retrieveData( con, command ) |
| 109 | maxBuild <- max( dbResult[ 'build' ] ) - strtoi( args[ builds_to_show ] ) |
| 110 | dbResult <- dbResult[ which( dbResult[,4] > maxBuild ), ] |
| 111 | |
| 112 | # ********************************************************** |
| 113 | # STEP 2: Organize data. |
| 114 | # ********************************************************** |
| 115 | |
| 116 | print( "**********************************************************" ) |
| 117 | print( "STEP 2: Organize Data." ) |
| 118 | print( "**********************************************************" ) |
| 119 | |
| 120 | t <- subset( dbResult, select=c( "actual_test_name", "build", "num_failed" ) ) |
| 121 | t$num_failed <- ceiling( t$num_failed / ( t$num_failed + 1 ) ) |
| 122 | t$num_planned <- 1 |
| 123 | |
| 124 | fileData <- aggregate( t$num_failed, by=list( Category=t$build ), FUN=sum ) |
| 125 | colnames( fileData ) <- c( "build", "num_failed" ) |
| 126 | |
| 127 | fileData$num_planned <- ( aggregate( t$num_planned, by=list( Category=t$build ), FUN=sum ) )$x |
| 128 | fileData$num_passed <- fileData$num_planned - fileData$num_failed |
| 129 | |
| 130 | print(fileData) |
| 131 | |
| 132 | # -------------------- |
| 133 | # Construct Data Frame |
| 134 | # -------------------- |
| 135 | # |
| 136 | |
| 137 | dataFrame <- melt( subset( fileData, select=c( "num_failed", "num_passed", "num_planned" ) ) ) |
| 138 | dataFrame$build <- fileData$build |
| 139 | colnames( dataFrame ) <- c( "status", "results", "build" ) |
| 140 | |
| 141 | dataFrame$num_failed <- fileData$num_failed |
| 142 | dataFrame$num_passed <- fileData$num_passed |
| 143 | dataFrame$num_planned <- fileData$num_planned |
| 144 | dataFrame$iterative <- seq( 1, nrow( fileData ), by = 1 ) |
| 145 | |
| 146 | print( "Data Frame Results:" ) |
| 147 | print( dataFrame ) |
| 148 | |
| 149 | # ********************************************************** |
| 150 | # STEP 3: Generate graphs. |
| 151 | # ********************************************************** |
| 152 | |
| 153 | print( "**********************************************************" ) |
| 154 | print( "STEP 3: Generate Graph." ) |
| 155 | print( "**********************************************************" ) |
| 156 | |
| 157 | # ------------------- |
| 158 | # Main Plot Generated |
| 159 | # ------------------- |
| 160 | |
| 161 | print( "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 | |
| 170 | mainPlot <- ggplot( data = dataFrame, aes( x = iterative, |
| 171 | y = results, |
| 172 | color = status ) ) |
| 173 | |
| 174 | # ------------------- |
| 175 | # Main Plot Formatted |
| 176 | # ------------------- |
| 177 | |
| 178 | print( "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. |
| 181 | failedColor <- geom_ribbon( aes( ymin = 0, |
| 182 | ymax = dataFrame$num_failed ), |
| 183 | fill = webColor( "red" ), |
| 184 | linetype = 0, |
| 185 | alpha = 0.07 ) |
| 186 | |
| 187 | passedColor <- geom_ribbon( aes( ymin = 0, |
| 188 | ymax = dataFrame$num_passed ), |
| 189 | fill = webColor( "light_blue" ), |
| 190 | linetype = 0, |
| 191 | alpha = 0.05 ) |
| 192 | |
| 193 | plannedColor <- 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 |
| 200 | lineColors <- 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 | |
| 211 | print( "Generating fundamental graph data." ) |
| 212 | |
| 213 | defaultTextSize() |
| 214 | |
| 215 | xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, |
| 216 | label = dataFrame$build ) |
| 217 | yScaleConfig <- scale_y_continuous( breaks = seq( 0, max( dataFrame$results ), |
| 218 | by = ceiling( max( dataFrame$results ) / 10 ) ) ) |
| 219 | |
| 220 | xLabel <- xlab( "Build Number" ) |
| 221 | yLabel <- ylab( "Tests" ) |
| 222 | |
| 223 | theme <- graphTheme() |
| 224 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 225 | title <- labs( title = title, subtitle = lastUpdatedLabel( Sys.time() ) ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 226 | |
| 227 | # Store plot configurations as 1 variable |
| 228 | fundamentalGraphData <- 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 | |
| 244 | print( "Generating line graph." ) |
| 245 | |
| 246 | lineGraphFormat <- geom_line( size = 1.1 ) |
| 247 | pointFormat <- geom_point( size = 3 ) |
| 248 | |
| 249 | result <- fundamentalGraphData + |
| 250 | lineGraphFormat + |
| 251 | pointFormat |
| 252 | |
| 253 | # ----------------------- |
| 254 | # Exporting Graph to File |
| 255 | # ----------------------- |
| 256 | |
| 257 | saveGraph( outputFile ) |