Skip to content

Commit

Permalink
fix curio test with ffiselect
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed May 24, 2024
1 parent bf519de commit 60fbf37
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions itests/curio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"flag"
"fmt"
"github.com/filecoin-project/lotus/lib/ffiselect"
"net"
"os"
"path"
Expand Down Expand Up @@ -99,6 +100,7 @@ func TestCurioHappyPath(t *testing.T) {
kit.LatestActorsAt(-1),
kit.WithSectorIndexDB(),
kit.PresealSectors(32),
kit.ThroughRPC(),
)

esemble.Start()
Expand Down Expand Up @@ -293,6 +295,8 @@ func createCliContext(dir string) (*cli.Context, error) {
}

func ConstructCurioTest(ctx context.Context, t *testing.T, dir string, db *harmonydb.DB, full v1api.FullNode, maddr address.Address, cfg *config.CurioConfig) (api.Curio, func(), jsonrpc.ClientCloser, <-chan struct{}) {
ffiselect.IsTest = true

cctx, err := createCliContext(dir)
require.NoError(t, err)

Expand Down
5 changes: 5 additions & 0 deletions lib/ffiselect/ffiselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/filecoin-project/lotus/lib/ffiselect/ffidirect"
)

var IsTest = false
var IsCuda = build.IsOpencl != "1"

// Get all devices from ffi
Expand Down Expand Up @@ -60,6 +61,10 @@ func call(logctx []any, fn string, args ...interface{}) ([]interface{}, error) {
ch <- dOrdinal
}()

if IsTest {
return callTest(logctx, fn, args...)
}

p, err := os.Executable()
if err != nil {
return nil, err
Expand Down
27 changes: 27 additions & 0 deletions lib/ffiselect/testffi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ffiselect

import (
"reflect"

"github.com/samber/lo"
"golang.org/x/xerrors"

"github.com/filecoin-project/lotus/lib/ffiselect/ffidirect"
)

func callTest(logctx []any, fn string, rawargs ...interface{}) ([]interface{}, error) {
args := lo.Map(rawargs, func(arg any, i int) reflect.Value {
return reflect.ValueOf(arg)
})

resAry := reflect.ValueOf(ffidirect.FFI{}).MethodByName(fn).Call(args)
res := lo.Map(resAry, func(res reflect.Value, i int) any {
return res.Interface()
})

if res[len(res)-1].(ffidirect.ErrorString) != "" {
return nil, xerrors.Errorf("callTest error: %s", res[len(res)-1].(ffidirect.ErrorString))
}

return res, nil
}
2 changes: 2 additions & 0 deletions lib/harmony/harmonydb/harmonydb.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ func (db *DB) upgrade() error {
return err
}

logger.Infow("Upgrading", "file", name, "size", len(file))

for _, s := range parseSQLStatements(string(file)) { // Implement the changes.
if len(strings.TrimSpace(s)) == 0 {
continue
Expand Down

0 comments on commit 60fbf37

Please sign in to comment.