Skip to content

Commit

Permalink
New feature: delete the most recent pass/fail record for each case us…
Browse files Browse the repository at this point in the history
…ing option -z
  • Loading branch information
texadactyl committed Jul 15, 2024
1 parent 6aa1ea8 commit c36b609
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 18 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This file is a version history of jacotest amendments. Entries appear in versio
| `Date` | `Version` | `Contents` |
| :------------: | :---: | :--- |
|<img width=90/>|<img width=60/>|<img width=600/>|
| 2024-07-15 | 3.4.0 | New feature: delete the most recent pass/fail record for each case using option -z. |
| 2024-07-10 | 3.3.6 | Fixed stringer-1 whitespace issue. |
| 2024-07-05 | 3.3.5 | Removed utilities directory as they are no longer in use. |
| | | Ditto for directories py and misc.java. |
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.3.6
v3.4.0
24 changes: 17 additions & 7 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ func showHelp() {
fmt.Printf("\nUsage: %s [-h] [-c] [-x] [-r {1,2}] [-M] [-v] [-t NSECS] [ -j { openjdk | jacobin } ]\n\nwhere\n", suffix)
fmt.Printf("\t-h : This display.\n")
fmt.Printf("\t-c : Compile the test cases.\n")
fmt.Printf("\t-x : Execute all test cases.\n")
fmt.Printf("\t Specifying -x implies parameter -r 1.\n")
fmt.Printf("\t-r 1 : Print the last two test case results if there was a change (pass/fail).\n")
fmt.Printf("\t-r 2 : Print the test case results where current failures passed sometime previously.\n")
fmt.Printf("\t-t : This is the timeout value in seconds (deadline) in executing all test cases. Default: 120.\n")
fmt.Printf("\t-j : This is the JVM to use in executing all test cases. Default: jacobin.\n")
fmt.Printf("\t Specifying -j implies parameters -x and -r 1.\n")
fmt.Printf("\t-v : Verbose logging.\n")
fmt.Printf("\t-x : Execute all test cases.\n")
fmt.Printf("\t Specifying -x implies parameter -r 1.\n")
fmt.Printf("\t-z : Remove the most recent test case result.\n")
fmt.Printf("\t-M : Generate a run report suitable for viewing on github (normally, not produced).\n\n")
ShowExecInfo()
os.Exit(0)
Expand Down Expand Up @@ -66,7 +67,8 @@ func main() {
var wString string
flagVerbose := false
flagExecute := false
flagLastTwo := false
flagTwoMostRecent := false
flagDeleteMostRecent := false
flagFailedPassed := false
flagCompile := false
flagMdReport := false
Expand Down Expand Up @@ -104,7 +106,7 @@ func main() {

case "-x":
flagExecute = true
flagLastTwo = true
flagTwoMostRecent = true

case "-r":
ii++
Expand All @@ -115,7 +117,7 @@ func main() {
arg := Args[ii]
switch arg {
case "1":
flagLastTwo = true
flagTwoMostRecent = true
case "2":
flagFailedPassed = true
default:
Expand All @@ -129,7 +131,7 @@ func main() {
case "-M":
flagMdReport = true
flagExecute = true
flagLastTwo = true
flagTwoMostRecent = true

case "-v":
flagVerbose = true
Expand Down Expand Up @@ -157,6 +159,9 @@ func main() {
showHelp()
}

case "-z": // Delete the most recent test result for each test case.
flagDeleteMostRecent = true

default:
LogError(fmt.Sprintf("Unrecognizable argument: %s", Args[ii]))
showHelp()
Expand Down Expand Up @@ -364,10 +369,15 @@ func main() {
} // if flagExecute || flagCompile

// Print the last 2 report?
if flagLastTwo {
if flagTwoMostRecent {
DBPrtChanges()
}

// Delete the most recent test result for each test case?
if flagDeleteMostRecent {
DBDeleteMostRecent()
}

// Print the failed-passed report?
if flagFailedPassed {
DBPrtLastPass()
Expand Down
80 changes: 70 additions & 10 deletions src/sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const driverDatabase = "sqlite"

// Assigned and used at run-time
var pathDatabase string
var sqliteDatabase *sql.DB
var dbHandle *sql.DB

/*
Internal function to run an SQL statement and handle any errors.
Expand All @@ -53,9 +53,9 @@ func sqlFunc(text string) error {
Logger(msg)
}

statement, err := sqliteDatabase.Prepare(text) // Prepare SQL Statement
statement, err := dbHandle.Prepare(text) // Prepare SQL Statement
if err != nil {
FmtFatal("sqlFunc: sqliteDatabase.Prepare failed", text, err)
FmtFatal("sqlFunc: dbHandle.Prepare failed", text, err)
}

_, err = statement.Exec() // Execute SQL Statements
Expand All @@ -80,9 +80,9 @@ func sqlQuery(text string) *sql.Rows {
Logger(msg)
}

rows, err := sqliteDatabase.Query(text)
rows, err := dbHandle.Query(text)
if err != nil {
FmtFatal("sqlQuery: sqliteDatabase.Query failed", text, err)
FmtFatal("sqlQuery: dbHandle.Query failed", text, err)
}

return rows
Expand Down Expand Up @@ -158,7 +158,7 @@ func DBOpen(flagVerbose bool) {
if sqlTracing {
Logger("DBOpen: database file inaccessible: " + err.Error())
}
sqliteDatabase, err = sql.Open(driverDatabase, pathDatabase)
dbHandle, err = sql.Open(driverDatabase, pathDatabase)
if err != nil {
FmtFatal("DBOpen: sql.Open(create) failed", pathDatabase, err)
}
Expand All @@ -174,12 +174,12 @@ func DBOpen(flagVerbose bool) {
if sqlTracing {
Logger("DBOpen database file exists")
}
sqliteDatabase, err = sql.Open(driverDatabase, pathDatabase)
dbHandle, err = sql.Open(driverDatabase, pathDatabase)
if err != nil {
FmtFatal("DBOpen: sql.Open(pre-existing) failed", pathDatabase, err)
}

// sqliteDatabase stays open until process exit
// dbHandle stays open until process exit

// TODO: Validate database

Expand All @@ -190,15 +190,15 @@ func DBOpen(flagVerbose bool) {
}

/*
DBClose - Store a PASSED jacotest test case result.Close the database
DBClose - Close the database.
*/
func DBClose() {

if sqlTracing {
Logger("DBClose: Begin")
}

err := sqliteDatabase.Close()
err := dbHandle.Close()
if err != nil {
FmtFatal("DBClose: sql.Close failed", pathDatabase, err)
}
Expand Down Expand Up @@ -462,3 +462,63 @@ func DBPrtLastPass() {
}
Logger(msg)
}

/*
DBDeleteMostRecent - Delete the most recent logged pass/fail record for each test case.
*/
func DBDeleteMostRecent() {

// Query descending test case, date, and time.
sqlSelect := "SELECT test_case, jvm, date_utc desc, time_utc FROM " + tableHistory + " NOLOCK ORDER BY test_case, date_utc DESC, time_utc DESC"

// Set up for DELETE operaations.
deleteFormat := "DELETE FROM " + tableHistory + " WHERE test_case = '%s' AND jvm='%s' AND date_utc = '%s' AND time_utc = '%s'"
var deleteList []string

// Most current result record w.r.t. date and time
var prvTestCase = ""
var curTestCase, curJvm, curDateUTC, curTimeUTC string

// Get all the history table rows.
rows := sqlQuery(sqlSelect)

// High level scan.
for rows.Next() {

// Get next history row by test case and going back in time.
err := rows.Scan(&curTestCase, &curJvm, &curDateUTC, &curTimeUTC)
if err != nil {
FmtFatal("DBDeleteMostRecent: rows.Scan failed", pathDatabase, err)
}

// Same test case as last test case? The first time, the current fields are spaces.
// So, the next test always fails on the very first row.
if curTestCase != prvTestCase {
// No, this is a new one.
// TODO: Delete DB record.
sqlDelete := fmt.Sprintf(deleteFormat, curTestCase, curJvm, curDateUTC, curTimeUTC)
deleteList = append(deleteList, sqlDelete)
// Make it the previous and continue.
prvTestCase = curTestCase
}

}

// Close and re-open database.
DBClose()
DBOpen(sqlTracing)

// For each delete statement, execute it.
counter := 0
for _, sqlStmt := range deleteList {
err := sqlFunc(sqlStmt)
if err != nil {
FmtFatal("DBDeleteMostRecent: DELETE failed", pathDatabase, err)
}
counter += 1
}

msg := fmt.Sprintf("Removed %d test case result records", counter)
Logger(msg)

}

0 comments on commit c36b609

Please sign in to comment.