From c36b6097d289df699baacd3bddf7bf7d2c40eb25 Mon Sep 17 00:00:00 2001 From: Richard Elkins Date: Mon, 15 Jul 2024 11:36:46 -0500 Subject: [PATCH] New feature: delete the most recent pass/fail record for each case using option -z --- HISTORY.md | 1 + VERSION.txt | 2 +- src/main.go | 24 ++++++++++----- src/sqlite3.go | 80 +++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 89 insertions(+), 18 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 06d9540..5fe0cfe 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,7 @@ This file is a version history of jacotest amendments. Entries appear in versio | `Date` | `Version` | `Contents` | | :------------: | :---: | :--- | |||| +| 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. | diff --git a/VERSION.txt b/VERSION.txt index 96a1b83..c219f72 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -v3.3.6 +v3.4.0 diff --git a/src/main.go b/src/main.go index 4662fd7..2bc0903 100644 --- a/src/main.go +++ b/src/main.go @@ -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) @@ -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 @@ -104,7 +106,7 @@ func main() { case "-x": flagExecute = true - flagLastTwo = true + flagTwoMostRecent = true case "-r": ii++ @@ -115,7 +117,7 @@ func main() { arg := Args[ii] switch arg { case "1": - flagLastTwo = true + flagTwoMostRecent = true case "2": flagFailedPassed = true default: @@ -129,7 +131,7 @@ func main() { case "-M": flagMdReport = true flagExecute = true - flagLastTwo = true + flagTwoMostRecent = true case "-v": flagVerbose = true @@ -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() @@ -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() diff --git a/src/sqlite3.go b/src/sqlite3.go index d4047b0..78dfddb 100644 --- a/src/sqlite3.go +++ b/src/sqlite3.go @@ -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. @@ -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 @@ -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 @@ -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) } @@ -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 @@ -190,7 +190,7 @@ func DBOpen(flagVerbose bool) { } /* -DBClose - Store a PASSED jacotest test case result.Close the database +DBClose - Close the database. */ func DBClose() { @@ -198,7 +198,7 @@ func DBClose() { Logger("DBClose: Begin") } - err := sqliteDatabase.Close() + err := dbHandle.Close() if err != nil { FmtFatal("DBClose: sql.Close failed", pathDatabase, err) } @@ -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) + +}