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 scripts: |
| 21 | # |
| 22 | # ALL tests with pass/fail (https://jenkins.onosproject.org/view/QA/job/postjob-VM/lastSuccessfulBuild/artifact/ALL_master_build-latest_executed_pieChart.jpg): |
| 23 | # Rscript pieMultipleTests.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 y /path/to/save/directory/ |
| 24 | # |
| 25 | # ALL tests with execution result (https://jenkins.onosproject.org/view/QA/job/postjob-VM/lastSuccessfulBuild/artifact/ALL_master_build-latest_passfail_pieChart.jpg): |
| 26 | # Rscript pieMultipleTests.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 n /path/to/save/directory/ |
| 27 | |
| 28 | # ********************************************************** |
| 29 | # STEP 1: Data management. |
| 30 | # ********************************************************** |
| 31 | |
| 32 | print( "**********************************************************" ) |
| 33 | print( "STEP 1: Data management." ) |
| 34 | print( "**********************************************************" ) |
| 35 | |
| 36 | tests_to_include <- 7 |
| 37 | build_to_show <- 8 |
| 38 | is_displaying_plan <- 9 |
| 39 | save_directory <- 10 |
| 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 | args <- commandArgs( trailingOnly=TRUE ) |
| 60 | |
| 61 | if ( is.na( args[ save_directory ] ) ){ |
| 62 | |
| 63 | # Check if sufficient args are provided. |
| 64 | if ( length( args ) != save_directory ){ |
| 65 | specialArgs <- c( "tests-to-include", |
| 66 | "build-to-show", |
| 67 | "is-displaying-plan" ) |
| 68 | usage( "trendSCPF.R", specialArgs ) |
| 69 | quit( status = 1 ) |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | # ------------------ |
| 74 | # SQL Initialization |
| 75 | # ------------------ |
| 76 | |
| 77 | print( "Initializing SQL" ) |
| 78 | |
| 79 | con <- dbConnect( dbDriver( "PostgreSQL" ), |
| 80 | dbname = "onostest", |
| 81 | host = args[ database_host ], |
| 82 | port = strtoi( args[ database_port ] ), |
| 83 | user = args[ database_u_id ], |
| 84 | password = args[ database_pw ] ) |
| 85 | |
| 86 | # --------------------- |
| 87 | # Test Case SQL Command |
| 88 | # --------------------- |
| 89 | |
| 90 | print( "Generating Test Case SQL command." ) |
| 91 | |
| 92 | command <- generateMultiTestSingleBuildSQLCommand( args[ branch_name ], |
| 93 | args[ tests_to_include ], |
| 94 | args[ build_to_show ] ) |
| 95 | |
| 96 | dbResult <- retrieveData( con, command ) |
| 97 | |
| 98 | print( "dbResult:" ) |
| 99 | print( dbResult ) |
| 100 | |
| 101 | # ------------------------------- |
| 102 | # Create Title and Graph Filename |
| 103 | # ------------------------------- |
| 104 | |
| 105 | print( "Creating title of graph." ) |
| 106 | |
| 107 | typeOfPieTitle <- "Executed Results" |
| 108 | typeOfPieFile <- "_passfail" |
| 109 | isPlannedPie <- FALSE |
| 110 | if ( args[ is_displaying_plan ] == "y" ){ |
| 111 | typeOfPieTitle <- "Test Execution" |
| 112 | typeOfPieFile <- "_executed" |
| 113 | isPlannedPie <- TRUE |
| 114 | } |
| 115 | |
| 116 | if ( args[ build_to_show ] == "latest" ){ |
| 117 | buildTitle <- "\nLatest Test Results" |
| 118 | filebuild_to_show <- "latest" |
| 119 | } else { |
| 120 | buildTitle <- paste( " \n Build #", args[ build_to_show ], sep="" ) |
| 121 | filebuild_to_show <- args[ build_to_show ] |
| 122 | } |
| 123 | |
| 124 | title <- paste( args[ graph_title ], |
| 125 | " Tests: Summary of ", |
| 126 | typeOfPieTitle, |
| 127 | "", |
| 128 | " - ", |
| 129 | args[ branch_name ], |
| 130 | buildTitle, |
| 131 | sep="" ) |
| 132 | |
| 133 | print( "Creating graph filename." ) |
| 134 | |
| 135 | outputFile <- paste( args[ save_directory ], |
| 136 | args[ graph_title ], |
| 137 | "_", |
| 138 | args[ branch_name ], |
| 139 | "_build-", |
| 140 | filebuild_to_show, |
| 141 | typeOfPieFile, |
| 142 | "_pieChart.jpg", |
| 143 | sep="" ) |
| 144 | |
| 145 | # ********************************************************** |
| 146 | # STEP 2: Organize data. |
| 147 | # ********************************************************** |
| 148 | |
| 149 | print( "**********************************************************" ) |
| 150 | print( "STEP 2: Organize Data." ) |
| 151 | print( "**********************************************************" ) |
| 152 | |
| 153 | t <- subset( dbResult, select=c( "actual_test_name", "num_passed", "num_failed", "num_planned" ) ) |
| 154 | |
| 155 | executedTests <- sum( t$num_passed ) + sum( t$num_failed ) |
| 156 | |
| 157 | # -------------------- |
| 158 | # Construct Data Frame |
| 159 | # -------------------- |
| 160 | |
| 161 | print( "Constructing Data Frame." ) |
| 162 | |
| 163 | if ( isPlannedPie ){ |
| 164 | nonExecutedTests <- sum( t$num_planned ) - executedTests |
| 165 | totalTests <- sum( t$num_planned ) |
| 166 | |
| 167 | executedPercent <- round( executedTests / totalTests * 100, digits = 2 ) |
| 168 | nonExecutedPercent <- 100 - executedPercent |
| 169 | |
| 170 | dfData <- c( nonExecutedPercent, executedPercent ) |
| 171 | |
| 172 | labels <- c( "Executed Test Cases", "Skipped Test Cases" ) |
| 173 | |
| 174 | dataFrame <- data.frame( |
| 175 | rawData <- dfData, |
| 176 | displayedData <- c( paste( nonExecutedPercent, "%\n", nonExecutedTests, " / ", totalTests, " Tests", sep="" ), paste( executedPercent, "%\n", executedTests, " / ", totalTests," Tests", sep="" ) ), |
| 177 | names <- factor( rev( labels ), levels = labels ) ) |
| 178 | } else { |
| 179 | sumPassed <- sum( t$num_passed ) |
| 180 | sumFailed <- sum( t$num_failed ) |
| 181 | sumExecuted <- sumPassed + sumFailed |
| 182 | |
| 183 | percentPassed <- sumPassed / sumExecuted |
| 184 | percentFailed <- sumFailed / sumExecuted |
| 185 | |
| 186 | dfData <- c( percentFailed, percentPassed ) |
| 187 | labels <- c( "Failed Test Cases", "Passed Test Cases" ) |
| 188 | |
| 189 | dataFrame <- data.frame( |
| 190 | rawData <- dfData, |
| 191 | displayedData <- c( paste( round( percentFailed * 100, 2 ), "%\n", sumFailed, " / ", sumExecuted, " Tests", sep="" ), paste( round( percentPassed * 100, 2 ), "%\n", sumPassed, " / ", sumExecuted, " Tests", sep="" ) ), |
| 192 | names <- factor( labels, levels = rev( labels ) ) ) |
| 193 | } |
| 194 | |
| 195 | print( "Data Frame Results:" ) |
| 196 | print( dataFrame ) |
| 197 | |
| 198 | # ********************************************************** |
| 199 | # STEP 3: Generate graphs. |
| 200 | # ********************************************************** |
| 201 | |
| 202 | print( "**********************************************************" ) |
| 203 | print( "STEP 3: Generate Graph." ) |
| 204 | print( "**********************************************************" ) |
| 205 | |
| 206 | # ------------------- |
| 207 | # Main Plot Generated |
| 208 | # ------------------- |
| 209 | |
| 210 | print( "Creating main plot." ) |
| 211 | # Create the primary plot here. |
| 212 | # ggplot contains the following arguments: |
| 213 | # - data: the data frame that the graph will be based off of |
| 214 | # - aes: the asthetics of the graph which require: |
| 215 | # - x: x-axis values (usually iterative, but it will become build # later) |
| 216 | # - y: y-axis values (usually tests) |
| 217 | # - color: the category of the colored lines (usually status of test) |
| 218 | |
| 219 | mainPlot <- ggplot( data = dataFrame, |
| 220 | aes( x = "", y=rawData, fill = names ) ) |
| 221 | |
| 222 | # ------------------- |
| 223 | # Main Plot Formatted |
| 224 | # ------------------- |
| 225 | |
| 226 | print( "Formatting main plot." ) |
| 227 | |
| 228 | # ------------------------------ |
| 229 | # Fundamental Variables Assigned |
| 230 | # ------------------------------ |
| 231 | |
| 232 | print( "Generating fundamental graph data." ) |
| 233 | |
| 234 | defaultTextSize() |
| 235 | |
| 236 | # Set other graph configurations here. |
| 237 | theme <- graphTheme() + |
| 238 | theme( axis.text.x = element_blank(), |
| 239 | axis.title.x = element_blank(), |
| 240 | axis.title.y = element_blank(), |
| 241 | axis.ticks = element_blank(), |
| 242 | panel.border = element_blank(), |
| 243 | panel.grid=element_blank(), |
| 244 | legend.position = "bottom" ) |
| 245 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 246 | title <- labs( title = title, subtitle = lastUpdatedLabel( Sys.time() ) ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 247 | |
| 248 | # Store plot configurations as 1 variable |
| 249 | fundamentalGraphData <- mainPlot + |
| 250 | theme + |
| 251 | title |
| 252 | |
| 253 | # ---------------------------- |
| 254 | # Generating Line Graph Format |
| 255 | # ---------------------------- |
| 256 | |
| 257 | print( "Generating line graph." ) |
| 258 | |
| 259 | if ( isPlannedPie ){ |
| 260 | executedColor <- webColor( "light_blue" ) |
| 261 | nonExecutedColor <- webColor( "gray" ) |
| 262 | pieColors <- scale_fill_manual( values = c( executedColor, nonExecutedColor ) ) |
| 263 | } else { |
| 264 | passColor <- webColor( "green" ) |
| 265 | failColor <- webColor( "red" ) |
| 266 | pieColors <- scale_fill_manual( values = c( passColor, failColor ) ) |
| 267 | } |
| 268 | |
| 269 | pieFormat <- geom_bar( width = 1, stat = "identity" ) |
| 270 | pieLabels <- geom_text( aes( y = rawData / length( rawData ) + c( 0, cumsum( rawData )[ -length( rawData ) ] ) ), |
| 271 | label = dataFrame$displayedData, |
| 272 | size = 7, fontface = "bold" ) |
| 273 | |
| 274 | |
| 275 | result <- fundamentalGraphData + |
| 276 | pieFormat + coord_polar( "y" ) + pieLabels + pieColors |
| 277 | |
| 278 | # ----------------------- |
| 279 | # Exporting Graph to File |
| 280 | # ----------------------- |
| 281 | |
| 282 | saveGraph( outputFile ) |