Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
49336675
Commit
49336675
authored
Jun 12, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expand CLI options to allow running all tests
parent
516362bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
109 additions
and
41 deletions
+109
-41
main.go
cmd/ethtest/main.go
+109
-41
No files found.
cmd/ethtest/main.go
View file @
49336675
...
@@ -22,14 +22,60 @@
...
@@ -22,14 +22,60 @@
package
main
package
main
import
(
import
(
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path/filepath"
"github.com/codegangsta/cli"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/tests"
"github.com/ethereum/go-ethereum/tests"
)
)
var
(
continueOnError
=
false
testExtension
=
".json"
defaultTest
=
"all"
defaultDir
=
"."
allTests
=
[]
string
{
"BlockTests"
,
"StateTests"
,
"TransactionTests"
,
"VMTests"
}
TestFlag
=
cli
.
StringFlag
{
Name
:
"test"
,
Usage
:
"Test type (string): VMTests, TransactionTests, StateTests, BlockTests"
,
Value
:
defaultTest
,
}
FileFlag
=
cli
.
StringFlag
{
Name
:
"file"
,
Usage
:
"Test file or directory. Directories are searched for .json files 1 level deep"
,
Value
:
defaultDir
,
EnvVar
:
"ETHEREUM_TEST_PATH"
,
}
ContinueOnErrorFlag
=
cli
.
BoolFlag
{
Name
:
"continue"
,
Usage
:
"Continue running tests on error (true) or exit immediately (false)"
,
}
)
func
runTest
(
test
,
file
string
)
error
{
// glog.Infoln("runTest", test, file)
var
err
error
switch
test
{
case
"bc"
,
"BlockTest"
,
"BlockTests"
,
"BlockChainTest"
:
err
=
tests
.
RunBlockTest
(
file
)
case
"st"
,
"state"
,
"StateTest"
,
"StateTests"
:
err
=
tests
.
RunStateTest
(
file
)
case
"tx"
,
"TransactionTest"
,
"TransactionTests"
:
err
=
tests
.
RunTransactionTests
(
file
)
case
"vm"
,
"VMTest"
,
"VMTests"
:
err
=
tests
.
RunVmTest
(
file
)
default
:
err
=
fmt
.
Errorf
(
"Invalid test type specified:"
,
test
)
}
return
err
}
func
getFiles
(
path
string
)
([]
string
,
error
)
{
func
getFiles
(
path
string
)
([]
string
,
error
)
{
// glog.Infoln("getFiles ", path)
var
files
[]
string
var
files
[]
string
f
,
err
:=
os
.
Open
(
path
)
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -48,8 +94,9 @@ func getFiles(path string) ([]string, error) {
...
@@ -48,8 +94,9 @@ func getFiles(path string) ([]string, error) {
files
=
make
([]
string
,
len
(
fi
))
files
=
make
([]
string
,
len
(
fi
))
for
i
,
v
:=
range
fi
{
for
i
,
v
:=
range
fi
{
// only go 1 depth and leave directory entires blank
// only go 1 depth and leave directory entires blank
if
!
v
.
IsDir
()
{
if
!
v
.
IsDir
()
&&
v
.
Name
()[
len
(
v
.
Name
())
-
len
(
testExtension
)
:
len
(
v
.
Name
())]
==
testExtension
{
files
[
i
]
=
path
+
v
.
Name
()
files
[
i
]
=
filepath
.
Join
(
path
,
v
.
Name
())
// glog.Infoln(files[i])
}
}
}
}
case
mode
.
IsRegular
()
:
case
mode
.
IsRegular
()
:
...
@@ -60,54 +107,75 @@ func getFiles(path string) ([]string, error) {
...
@@ -60,54 +107,75 @@ func getFiles(path string) ([]string, error) {
return
files
,
nil
return
files
,
nil
}
}
func
main
(
)
{
func
runSuite
(
c
*
cli
.
Context
)
{
glog
.
SetToStderr
(
tru
e
)
flagTest
:=
c
.
GlobalString
(
TestFlag
.
Nam
e
)
var
continueOnError
bool
=
false
flagFile
:=
c
.
GlobalString
(
FileFlag
.
Name
)
// vm.Debug = true
continueOnError
=
c
.
GlobalBool
(
ContinueOnErrorFlag
.
Name
)
if
len
(
os
.
Args
)
<
2
{
var
tests
[]
string
glog
.
Exit
(
"Must specify test type"
)
}
testtype
:=
os
.
Args
[
1
]
if
flagTest
==
defaultTest
{
var
pattern
string
tests
=
allTests
if
len
(
os
.
Args
)
>
2
{
}
else
{
pattern
=
os
.
Args
[
2
]
tests
=
[]
string
{
flagTest
}
}
}
files
,
err
:=
getFiles
(
pattern
)
for
_
,
curTest
:=
range
tests
{
if
err
!=
nil
{
// glog.Infoln("runSuite", curTest, flagFile)
glog
.
Fatal
(
err
)
var
err
error
}
var
files
[]
string
if
flagTest
==
defaultTest
{
files
,
err
=
getFiles
(
filepath
.
Join
(
flagFile
,
curTest
))
for
_
,
testfile
:=
range
files
{
}
else
{
// Skip blank entries
files
,
err
=
getFiles
(
flagFile
)
if
len
(
testfile
)
==
0
{
continue
}
}
// TODO allow io.Reader to be passed so Stdin can be piped
if
err
!=
nil
{
// RunVmTest(strings.NewReader(os.Args[2]))
glog
.
Fatalln
(
err
)
// RunVmTest(os.Stdin)
var
err
error
switch
testtype
{
case
"vm"
,
"VMTests"
:
err
=
tests
.
RunVmTest
(
testfile
)
case
"state"
,
"StateTest"
:
err
=
tests
.
RunStateTest
(
testfile
)
case
"tx"
,
"TransactionTests"
:
err
=
tests
.
RunTransactionTests
(
testfile
)
case
"bc"
,
"BlockChainTest"
:
err
=
tests
.
RunBlockTest
(
testfile
)
default
:
glog
.
Fatalln
(
"Invalid test type specified"
)
}
}
if
err
!=
nil
{
if
len
(
files
)
==
0
{
if
continueOnError
{
glog
.
Warningln
(
"No files matched path"
)
glog
.
Errorln
(
err
)
}
}
else
{
for
_
,
testfile
:=
range
files
{
glog
.
Fatalln
(
err
)
// Skip blank entries
if
len
(
testfile
)
==
0
{
continue
}
// TODO allow io.Reader to be passed so Stdin can be piped
// RunVmTest(strings.NewReader(os.Args[2]))
// RunVmTest(os.Stdin)
err
:=
runTest
(
curTest
,
testfile
)
if
err
!=
nil
{
if
continueOnError
{
glog
.
Errorln
(
err
)
}
else
{
glog
.
Fatalln
(
err
)
}
}
}
}
}
}
}
}
}
func
main
()
{
glog
.
SetToStderr
(
true
)
// vm.Debug = true
app
:=
cli
.
NewApp
()
app
.
Name
=
"ethtest"
app
.
Usage
=
"go-ethereum test interface"
app
.
Action
=
runSuite
app
.
Flags
=
[]
cli
.
Flag
{
TestFlag
,
FileFlag
,
ContinueOnErrorFlag
,
}
if
err
:=
app
.
Run
(
os
.
Args
);
err
!=
nil
{
glog
.
Fatalln
(
err
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment