Skip to content

Commit

Permalink
regression and database improvements
Browse files Browse the repository at this point in the history
added Replace() to database package

simplified Regressor interface

playback regressor can now be reduxed

regression Redux() now uses database.Replace() instead of separate
Delete() and Add(). this makes sure that the redux entry gets the same
database key once the redux has completed

removed -dryrun option from REGRESS REDUX

removed regression fails log. it wasn't well developed and not a
particularly useful idea

fixed television.SetSimple(). the signal function was not set correctly
  • Loading branch information
JetSetIlly committed Nov 23, 2024
1 parent 2d1a01d commit f98a775
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 397 deletions.
11 changes: 11 additions & 0 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ func (db Session) SortedKeyList() []int {
return keyList
}

// Replace an entry with another.
func (db *Session) Replace(key int, old Entry, ent Entry) error {
_, ok := db.entries[key]
if !ok {
return fmt.Errorf("database: key not available (%d)", key)
}
delete(db.entries, key)
db.entries[key] = ent
return old.CleanUp()
}

// Add an entry to the db.
func (db *Session) Add(ent Entry) error {
var key int
Expand Down
11 changes: 3 additions & 8 deletions database/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

package database

import (
"fmt"
)

// SelectAll entries in the database. onSelect can be nil.
//
// onSelect() should return true if select process is to continue. Continue
Expand Down Expand Up @@ -68,15 +64,14 @@ func (db Session) SelectKeys(onSelect func(Entry, int) error, keys ...int) (Entr

for i := range keys {
entry = db.entries[keys[i]]
if entry == nil {
continue
}
err := onSelect(entry, keys[i])
if err != nil {
return entry, err
}
}

if entry == nil {
return nil, fmt.Errorf("select empty")
}

return entry, nil
}
6 changes: 3 additions & 3 deletions gopher2600.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,11 +844,11 @@ with the LOG mode. Note that asking for log output will suppress regression prog

func regressRedux(mode string, args []string) error {
var yes bool
var dryRun bool
var verbose bool

flgs := flag.NewFlagSet(mode, flag.ExitOnError)
flgs.BoolVar(&yes, "yes", false, "answer yes to confirmation request")
flgs.BoolVar(&dryRun, "dryrun", false, "do not perform redux, only show what would happen")
flgs.BoolVar(&verbose, "v", false, "output more detail")

// parse args and get copy of remaining arguments
err := flgs.Parse(args)
Expand All @@ -864,7 +864,7 @@ func regressRedux(mode string, args []string) error {
confirmation = os.Stdin
}

return regression.RegressRedux(os.Stdout, confirmation, dryRun, args)
return regression.RegressRedux(os.Stdout, confirmation, verbose, args)
}

func regressCleanup(mode string, args []string) error {
Expand Down
2 changes: 2 additions & 0 deletions hardware/television/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ func (tv *Television) SetSimple(set bool) {
if set {
if tv.simple == nil {
tv.simple = &simple{}
tv.signal = tv.signalSimple
}
} else {
if tv.simple != nil {
tv.simple = nil
tv.signal = tv.signalFull
}
}
}
Expand Down
116 changes: 0 additions & 116 deletions regression/fails.go

This file was deleted.

26 changes: 16 additions & 10 deletions regression/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,14 @@ func (reg LogRegression) String() string {
return s.String()
}

// redux implements the regression.Regressor interface.
func (reg *LogRegression) redux(messages io.Writer, tag string) (Regressor, error) {
old := *reg
return &old, reg.regress(true, messages, tag)
}

// regress implements the regression.Regressor interface.
func (reg *LogRegression) regress(newRegression bool, output io.Writer, msg string) (bool, string, error) {
func (reg *LogRegression) regress(newRegression bool, messages io.Writer, tag string) error {
// make sure logger is clear
logger.Clear()

Expand All @@ -131,20 +137,20 @@ func (reg *LogRegression) regress(newRegression bool, output io.Writer, msg stri
logger.SetEcho(logOutput, false)

// start output with message
output.Write([]byte(msg))
messages.Write([]byte(tag))

// create headless television. we'll use this to initialise the digester
tv, err := television.NewSimpleTelevision(reg.TVtype)
if err != nil {
return false, "", fmt.Errorf("log: %w", err)
return fmt.Errorf("log: %w", err)
}
defer tv.End()
tv.SetFPSCap(false)

// create VCS and attach cartridge
vcs, err := hardware.NewVCS(environment.MainEmulation, tv, nil, nil)
if err != nil {
return false, "", fmt.Errorf("log: %w", err)
return fmt.Errorf("log: %w", err)
}

// we want the machine in a known state. the easiest way to do this is to
Expand All @@ -153,13 +159,13 @@ func (reg *LogRegression) regress(newRegression bool, output io.Writer, msg stri

cartload, err := cartridgeloader.NewLoaderFromFilename(reg.Cartridge, reg.Mapping, "AUTO", nil)
if err != nil {
return false, "", fmt.Errorf("log: %w", err)
return fmt.Errorf("log: %w", err)
}
defer cartload.Close()

err = setup.AttachCartridge(vcs, cartload, true)
if err != nil {
return false, "", fmt.Errorf("log: %w", err)
return fmt.Errorf("log: %w", err)
}

// display ticker for progress meter
Expand All @@ -177,15 +183,15 @@ func (reg *LogRegression) regress(newRegression bool, output io.Writer, msg stri
select {
case <-tck.C:
frame := vcs.TV.GetCoords().Frame
output.Write([]byte(fmt.Sprintf("\r%s [%d/%d (%.1f%%)]", msg, frame, reg.NumFrames, 100*(float64(frame)/float64(reg.NumFrames)))))
messages.Write([]byte(fmt.Sprintf("\r%s [%d/%d (%.1f%%)]", tag, frame, reg.NumFrames, 100*(float64(frame)/float64(reg.NumFrames)))))
default:
}

return govern.Running, nil
})

if err != nil {
return false, "", fmt.Errorf("log: %w", err)
return fmt.Errorf("log: %w", err)
}

// get hash of log output
Expand All @@ -198,8 +204,8 @@ func (reg *LogRegression) regress(newRegression bool, output io.Writer, msg stri

// compare hashes from this run and the specimen run
if reg.digest != fmt.Sprintf("%x", hash) {
return false, "digest mismatch", nil
return fmt.Errorf("digest mismatch")
}

return true, "", nil
return nil
}
Loading

0 comments on commit f98a775

Please sign in to comment.