Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 1 | # Copyright 2018 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 | # ALL tests (https://jenkins.onosproject.org/view/QA/job/postjob-VM/lastSuccessfulBuild/artifact/ALL_master_build-latest_test-suite-summary.jpg): |
| 22 | # Rscript histogramMultipleTestGroups.R <url> <port> <username> <pass> ALL master "FUNCbgpls,FUNCflow,FUNCformCluster,FUNCgroup,FUNCintent,FUNCintentRest,FUNCipv6Intent,FUNCnetCfg,FUNCnetconf,FUNCoptical,FUNCovsdbtest,FUNCvirNetNB,HAbackupRecover,HAclusterRestart,HAfullNetPartition,HAkillNodes,HAsanity,HAscaling,HAsingleInstanceRestart,HAstopNodes,HAswapNodes,HAupgrade,HAupgradeRollback,PLATdockertest,USECASE_SdnipFunction,USECASE_SdnipFunctionCluster,VPLSBasic,VPLSfailsafe" latest /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 | # Command line arguments are read. Args include the database credentials, test name, branch name, and the directory to output files. |
| 33 | print( "Reading commmand-line args." ) |
| 34 | args <- commandArgs( trailingOnly=TRUE ) |
| 35 | |
| 36 | testsToInclude <- 7 |
| 37 | build_to_show <- 8 |
| 38 | save_directory <- 9 |
| 39 | |
| 40 | # ---------------- |
| 41 | # Import Libraries |
| 42 | # ---------------- |
| 43 | |
| 44 | print( "Importing libraries." ) |
| 45 | library( ggplot2 ) |
| 46 | library( reshape2 ) |
| 47 | library( RPostgreSQL ) |
Devin Lim | 324806b | 2018-05-11 15:36:52 -0700 | [diff] [blame] | 48 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" ) |
| 49 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" ) |
| 50 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" ) |
| 51 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 52 | |
| 53 | # ------------------- |
| 54 | # Check CLI Arguments |
| 55 | # ------------------- |
| 56 | |
| 57 | print( "Verifying CLI args." ) |
| 58 | |
| 59 | if ( length( args ) != save_directory ){ |
| 60 | specialArgs <- c( "tests-to-include-(as-one-string-sep-groups-by-semicolon-title-as-first-group-item-sep-by-dash)", |
| 61 | "build-to-show" ) |
| 62 | usage( "histogramMultipleTestGroups.R", specialArgs ) |
| 63 | quit( status = 1 ) |
| 64 | } |
| 65 | |
| 66 | # ------------------ |
| 67 | # SQL Initialization |
| 68 | # ------------------ |
| 69 | |
| 70 | print( "Initializing SQL" ) |
| 71 | |
| 72 | con <- initSQL( args[ database_host ], |
| 73 | args[ database_port ], |
| 74 | args[ database_u_id ], |
| 75 | args[ database_pw ] ) |
| 76 | |
| 77 | # --------------------- |
| 78 | # Test Case SQL Command |
| 79 | # --------------------- |
| 80 | |
| 81 | print( "Generating Test Case SQL command." ) |
| 82 | |
| 83 | sqlCommands <- generateGroupedTestSingleBuildSQLCommand( args[ branch_name ], |
| 84 | args[ testsToInclude ], |
| 85 | args[ build_to_show ] ) |
| 86 | |
| 87 | titles <- getTitlesFromGroupTest( args[ branch_name ], |
| 88 | args[ testsToInclude ] ) |
| 89 | |
| 90 | dbResults <- list() |
| 91 | i <- 1 |
| 92 | for ( command in sqlCommands ){ |
| 93 | dbResults[[i]] <- retrieveData( con, command ) |
| 94 | i <- i + 1 |
| 95 | } |
| 96 | |
| 97 | print( "dbResult:" ) |
| 98 | print( dbResults ) |
| 99 | |
| 100 | # ------------------------------- |
| 101 | # Create Title and Graph Filename |
| 102 | # ------------------------------- |
| 103 | |
| 104 | print( "Creating title of graph." ) |
| 105 | |
| 106 | titlePrefix <- paste( args[ graph_title ], " ", sep="" ) |
| 107 | if ( args[ graph_title ] == "ALL" ){ |
| 108 | titlePrefix <- "" |
| 109 | } |
| 110 | |
| 111 | if ( args[ build_to_show ] == "latest" ){ |
| 112 | buildTitle <- "\nLatest Test Results" |
| 113 | filebuild_to_show <- "latest" |
| 114 | } else { |
| 115 | buildTitle <- paste( " \n Build #", args[ build_to_show ], sep="" ) |
| 116 | filebuild_to_show <- args[ build_to_show ] |
| 117 | } |
| 118 | |
| 119 | title <- paste( titlePrefix, |
| 120 | "Summary of Test Suites - ", |
| 121 | args[ branch_name ], |
| 122 | buildTitle, |
| 123 | sep="" ) |
| 124 | |
| 125 | print( "Creating graph filename." ) |
| 126 | |
| 127 | outputFile <- paste( args[ save_directory ], |
| 128 | args[ graph_title ], |
| 129 | "_", |
| 130 | args[ branch_name ], |
| 131 | "_build-", |
| 132 | filebuild_to_show, |
| 133 | "_test-suite-summary.jpg", |
| 134 | sep="" ) |
| 135 | |
| 136 | # ********************************************************** |
| 137 | # STEP 2: Organize data. |
| 138 | # ********************************************************** |
| 139 | |
| 140 | print( "**********************************************************" ) |
| 141 | print( "STEP 2: Organize Data." ) |
| 142 | print( "**********************************************************" ) |
| 143 | |
| 144 | passNum <- list() |
| 145 | failNum <- list() |
| 146 | exeNum <- list() |
| 147 | skipNum <- list() |
| 148 | totalNum <- list() |
| 149 | |
| 150 | passPercent <- list() |
| 151 | failPercent <- list() |
| 152 | exePercent <- list() |
| 153 | nonExePercent <- list() |
| 154 | |
| 155 | actualPassPercent <- list() |
| 156 | actualFailPercent <- list() |
| 157 | |
| 158 | appName <- c() |
| 159 | afpName <- c() |
| 160 | nepName <- c() |
| 161 | |
| 162 | tmpPos <- c() |
| 163 | tmpCases <- c() |
| 164 | |
| 165 | for ( i in 1:length( dbResults ) ){ |
| 166 | t <- dbResults[[i]] |
| 167 | |
| 168 | passNum[[i]] <- sum( t$num_passed ) |
| 169 | failNum[[i]] <- sum( t$num_failed ) |
| 170 | exeNum[[i]] <- passNum[[i]] + failNum[[i]] |
| 171 | totalNum[[i]] <- sum( t$num_planned ) |
| 172 | skipNum[[i]] <- totalNum[[i]] - exeNum[[i]] |
| 173 | |
| 174 | passPercent[[i]] <- passNum[[i]] / exeNum[[i]] |
| 175 | failPercent[[i]] <- failNum[[i]] / exeNum[[i]] |
| 176 | exePercent[[i]] <- exeNum[[i]] / totalNum[[i]] |
| 177 | nonExePercent[[i]] <- ( 1 - exePercent[[i]] ) * 100 |
| 178 | |
| 179 | actualPassPercent[[i]] <- passPercent[[i]] * exePercent[[i]] * 100 |
| 180 | actualFailPercent[[i]] <- failPercent[[i]] * exePercent[[i]] * 100 |
| 181 | |
| 182 | appName <- c( appName, "Passed" ) |
| 183 | afpName <- c( afpName, "Failed" ) |
| 184 | nepName <- c( nepName, "Skipped/Unexecuted" ) |
| 185 | |
| 186 | tmpPos <- c( tmpPos, 100 - ( nonExePercent[[i]] / 2 ), actualPassPercent[[i]] + actualFailPercent[[i]] - ( actualFailPercent[[i]] / 2 ), actualPassPercent[[i]] - ( actualPassPercent[[i]] / 2 ) ) |
| 187 | tmpCases <- c( tmpCases, skipNum[[i]], failNum[[i]], passNum[[i]] ) |
| 188 | } |
| 189 | |
| 190 | relativePosLength <- length( dbResults ) * 3 |
| 191 | |
| 192 | relativePos <- c() |
| 193 | relativeCases <- c() |
| 194 | |
| 195 | for ( i in 1:3 ){ |
| 196 | relativePos <- c( relativePos, tmpPos[ seq( i, relativePosLength, 3 ) ] ) |
| 197 | relativeCases <- c( relativeCases, tmpCases[ seq( i, relativePosLength, 3 ) ] ) |
| 198 | } |
| 199 | names( actualPassPercent ) <- appName |
| 200 | names( actualFailPercent ) <- afpName |
| 201 | names( nonExePercent ) <- nepName |
| 202 | |
| 203 | labels <- paste( titles, "\n", totalNum, " Test Cases", sep="" ) |
| 204 | |
| 205 | # -------------------- |
| 206 | # Construct Data Frame |
| 207 | # -------------------- |
| 208 | |
| 209 | print( "Constructing Data Frame" ) |
| 210 | |
| 211 | dataFrame <- melt( c( nonExePercent, actualFailPercent, actualPassPercent ) ) |
| 212 | dataFrame$title <- seq( 1, length( dbResults ), by = 1 ) |
| 213 | colnames( dataFrame ) <- c( "perc", "key", "suite" ) |
| 214 | |
| 215 | dataFrame$xtitles <- labels |
| 216 | dataFrame$relativePos <- relativePos |
| 217 | dataFrame$relativeCases <- relativeCases |
| 218 | dataFrame$valueDisplay <- c( paste( round( dataFrame$perc, digits = 2 ), "% - ", relativeCases, " Tests", sep="" ) ) |
| 219 | |
| 220 | dataFrame$key <- factor( dataFrame$key, levels=unique( dataFrame$key ) ) |
| 221 | |
| 222 | dataFrame$willDisplayValue <- dataFrame$perc > 15.0 / length( dbResults ) |
| 223 | |
| 224 | for ( i in 1:nrow( dataFrame ) ){ |
| 225 | if ( relativeCases[[i]] == "1" ){ |
| 226 | dataFrame[ i, "valueDisplay" ] <- c( paste( round( dataFrame$perc[[i]], digits = 2 ), "% - ", relativeCases[[i]], " Test", sep="" ) ) |
| 227 | } |
| 228 | if ( !dataFrame[ i, "willDisplayValue" ] ){ |
| 229 | dataFrame[ i, "valueDisplay" ] <- "" |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | print( "Data Frame Results:" ) |
| 234 | print( dataFrame ) |
| 235 | |
| 236 | # ********************************************************** |
| 237 | # STEP 3: Generate graphs. |
| 238 | # ********************************************************** |
| 239 | |
| 240 | print( "**********************************************************" ) |
| 241 | print( "STEP 3: Generate Graph." ) |
| 242 | print( "**********************************************************" ) |
| 243 | |
| 244 | # ------------------- |
| 245 | # Main Plot Generated |
| 246 | # ------------------- |
| 247 | |
| 248 | print( "Creating main plot." ) |
| 249 | |
| 250 | mainPlot <- ggplot( data = dataFrame, aes( x = suite, |
| 251 | y = perc, |
| 252 | fill = key ) ) |
| 253 | |
| 254 | # ------------------------------ |
| 255 | # Fundamental Variables Assigned |
| 256 | # ------------------------------ |
| 257 | |
| 258 | print( "Generating fundamental graph data." ) |
| 259 | |
| 260 | theme_set( theme_grey( base_size = 26 ) ) # set the default text size of the graph. |
| 261 | |
| 262 | xScaleConfig <- scale_x_continuous( breaks = dataFrame$suite, |
| 263 | label = dataFrame$xtitles ) |
| 264 | yScaleConfig <- scale_y_continuous( breaks = seq( 0, 100, |
| 265 | by = 10 ) ) |
| 266 | |
| 267 | xLabel <- xlab( "" ) |
| 268 | yLabel <- ylab( "Total Test Cases (%)" ) |
| 269 | |
| 270 | theme <- graphTheme() + theme( axis.text.x = element_text( angle = 0, size = 25 - 1.25 * length( dbResults ) ) ) |
| 271 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 272 | title <- labs( title = title, subtitle = lastUpdatedLabel( Sys.time() ) ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 273 | |
| 274 | # Store plot configurations as 1 variable |
| 275 | fundamentalGraphData <- mainPlot + |
| 276 | xScaleConfig + |
| 277 | yScaleConfig + |
| 278 | xLabel + |
| 279 | yLabel + |
| 280 | theme + |
| 281 | title |
| 282 | |
| 283 | # --------------------------- |
| 284 | # Generating Bar Graph Format |
| 285 | # --------------------------- |
| 286 | |
| 287 | print( "Generating bar graph." ) |
| 288 | |
| 289 | unexecutedColor <- webColor( "gray" ) # Gray |
| 290 | failedColor <- webColor( "red" ) # Red |
| 291 | passedColor <- webColor( "green" ) # Green |
| 292 | |
| 293 | colors <- scale_fill_manual( values=c( if ( "Skipped/Unexecuted" %in% dataFrame$key ){ unexecutedColor }, |
| 294 | if ( "Failed" %in% dataFrame$key ){ failedColor }, |
| 295 | if ( "Passed" %in% dataFrame$key ){ passedColor } ) ) |
| 296 | |
| 297 | barGraphFormat <- geom_bar( stat = "identity", width = 0.8 ) |
| 298 | |
| 299 | barGraphValues <- geom_text( aes( x = dataFrame$suite, |
| 300 | y = dataFrame$relativePos, |
| 301 | label = format( paste( dataFrame$valueDisplay ) ) ), |
| 302 | size = 15.50 / length( dbResults ) + 2.33, fontface = "bold" ) |
| 303 | |
| 304 | result <- fundamentalGraphData + |
| 305 | colors + |
| 306 | barGraphFormat + |
| 307 | barGraphValues |
| 308 | |
| 309 | # ----------------------- |
| 310 | # Exporting Graph to File |
| 311 | # ----------------------- |
| 312 | |
| 313 | saveGraph( outputFile ) # from saveGraph.R |