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 | # If you have any questions, or if you don't understand R, |
| 21 | # please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu |
| 22 | |
| 23 | pipelineMinValue = 1000 |
| 24 | |
| 25 | initSQL <- function( host, port, user, pass ) { |
| 26 | dbConnect( dbDriver( "PostgreSQL" ), |
| 27 | dbname = "onostest", |
| 28 | host = host, |
| 29 | port = strtoi( port ), |
| 30 | user = user, |
| 31 | password = pass ) |
| 32 | } |
| 33 | |
| 34 | simpleSQLCommand <- function( testName, branch, limit=0 ){ |
| 35 | paste( "SELECT * FROM executed_test_tests WHERE actual_test_name='", |
| 36 | testName, |
| 37 | "' AND branch='", |
| 38 | branch, |
| 39 | "' ORDER BY date DESC ", |
| 40 | if (limit > 0) "LIMIT " else "", |
| 41 | if (limit > 0) limit else "", |
| 42 | sep="" ) |
| 43 | } |
| 44 | |
| 45 | retrieveData <- function( con, sqlCommand ){ |
| 46 | |
| 47 | print( "Sending SQL command:" ) |
| 48 | print( sqlCommand ) |
| 49 | |
| 50 | result <- dbGetQuery( con, sqlCommand ) |
| 51 | |
| 52 | # Check if data has been received |
| 53 | if ( nrow( result ) == 0 ){ |
| 54 | print( "[ERROR]: No data received from the databases. Please double check this by manually running the SQL command." ) |
| 55 | quit( status = 1 ) |
| 56 | } |
| 57 | result |
| 58 | } |
| 59 | |
| 60 | generateMultiTestMultiBuildSQLCommand <- function( branch, testsToInclude, buildsToShow ){ |
| 61 | tests <- getTestList( testsToInclude ) |
| 62 | multiTestSQLCommand( branch, tests, buildsToShow, TRUE ) |
| 63 | } |
| 64 | |
| 65 | generateMultiTestSingleBuildSQLCommand <- function( branch, testsToInclude, buildToShow ){ |
| 66 | tests <- getTestList( testsToInclude ) |
| 67 | operator <- "= " |
| 68 | if ( buildToShow == "latest" ){ |
| 69 | operator <- ">= " |
| 70 | buildToShow <- "1000" |
| 71 | } |
| 72 | |
| 73 | multiTestSQLCommand( branch, tests, buildToShow, FALSE, operator ) |
| 74 | } |
| 75 | |
| 76 | generateGroupedTestSingleBuildSQLCommand <- function( branch, groupsToInclude, buildToShow ){ |
| 77 | operator <- "= " |
| 78 | if( buildToShow == "latest" ){ |
| 79 | operator <- ">= " |
| 80 | buildToShow <- "1000" |
| 81 | } |
| 82 | |
| 83 | tests <- strsplit( groupsToInclude, ";" ) |
| 84 | |
| 85 | sqlCommands <- c() |
| 86 | |
| 87 | for( i in 1:length( tests[[1]] ) ){ |
| 88 | splitTestList <- strsplit( tests[[1]][ i ], "-" ) |
| 89 | testList <- splitTestList[[1]][2] |
| 90 | |
| 91 | testsCommand <- "'" |
| 92 | for ( test in as.list( strsplit( testList, "," )[[1]] ) ){ |
| 93 | testsCommand <- paste( testsCommand, test, "','", sep="" ) |
| 94 | } |
| 95 | testsCommand <- substr( testsCommand, 0, nchar( testsCommand ) - 2 ) |
| 96 | |
| 97 | sqlCommands = c( sqlCommands, multiTestSQLCommand( branch, testsCommand, buildToShow, FALSE, operator ) ) |
| 98 | } |
| 99 | sqlCommands |
| 100 | } |
| 101 | |
| 102 | getTitlesFromGroupTest <- function( branch, groupsToInclude ){ |
| 103 | tests <- strsplit( groupsToInclude, ";" ) |
| 104 | titles <- list() |
| 105 | for( i in 1:length( tests[[1]] ) ){ |
| 106 | splitTestList <- strsplit( tests[[1]][ i ], "-" ) |
| 107 | titles[[i]] <- splitTestList[[1]][1] |
| 108 | } |
| 109 | titles |
| 110 | } |
| 111 | |
| 112 | getTestList <- function( testsToInclude ){ |
| 113 | tests <- "'" |
| 114 | for ( test in as.list( strsplit( testsToInclude, "," )[[1]] ) ){ |
| 115 | tests <- paste( tests, test, "','", sep="" ) |
| 116 | } |
| 117 | tests <- substr( tests, 0, nchar( tests ) - 2 ) |
| 118 | tests |
| 119 | } |
| 120 | |
| 121 | multiTestSQLCommand <- function( branch, tests, builds, isDisplayingMultipleBuilds, operator=">= " ){ |
| 122 | if ( isDisplayingMultipleBuilds ){ |
| 123 | operator2 <- "<=" |
| 124 | multipleBuildsToShow <- builds |
| 125 | singleBuild <- pipelineMinValue |
| 126 | } |
| 127 | else{ |
| 128 | operator2 <- "=" |
| 129 | multipleBuildsToShow <- 1 |
| 130 | singleBuild <- builds |
| 131 | } |
| 132 | |
| 133 | paste( "SELECT * ", |
| 134 | "FROM executed_test_tests a ", |
| 135 | "WHERE ( SELECT COUNT( * ) FROM executed_test_tests b ", |
| 136 | "WHERE b.branch='", |
| 137 | branch, |
| 138 | "' AND b.actual_test_name IN (", |
| 139 | tests, |
| 140 | ") AND a.actual_test_name = b.actual_test_name AND a.date <= b.date AND b.build ", operator, |
| 141 | singleBuild, |
| 142 | " ) ", |
| 143 | operator2, |
| 144 | " ", |
| 145 | multipleBuildsToShow, |
| 146 | " AND a.branch='", |
| 147 | branch, |
| 148 | "' AND a.actual_test_name IN (", |
| 149 | tests, |
| 150 | ") AND a.build ", operator, |
| 151 | singleBuild, |
| 152 | " ORDER BY a.actual_test_name DESC, a.date DESC", |
| 153 | sep="") |
| 154 | } |