You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by pe...@apache.org on 2016/12/15 21:28:09 UTC
incubator-mynewt-newt git commit: MYNEWT-139: mynewtmgr cli to
execute device tests
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop e7971e974 -> e1b064e8a
MYNEWT-139: mynewtmgr cli to execute device tests
Add "run test [testname | all] [token]" and "run list" commands to newtmgr.
"run list" lists all the registered test suites on device
"run test" takes a specific test or defaults to running all tests.
Optional "token" argument allows log messages to have the specified token
added. Use "run test all token" to run all tests by default.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/e1b064e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/e1b064e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/e1b064e8
Branch: refs/heads/develop
Commit: e1b064e8ade01c65e49c73c885fb2eb1cc3b4665
Parents: e7971e9
Author: Peter Snyder <pe...@apache.org>
Authored: Thu Dec 15 13:24:18 2016 -0800
Committer: Peter Snyder <pe...@apache.org>
Committed: Thu Dec 15 13:24:18 2016 -0800
----------------------------------------------------------------------
newtmgr/cli/commands.go | 2 +-
newtmgr/cli/runtest.go | 151 ++++++++++++++++++++++++++-------------
newtmgr/protocol/defs.go | 2 +-
newtmgr/protocol/runtest.go | 122 +++++++++++++++++++++++++------
4 files changed, 205 insertions(+), 72 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e1b064e8/newtmgr/cli/commands.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/commands.go b/newtmgr/cli/commands.go
index 39ede96..021a9f0 100644
--- a/newtmgr/cli/commands.go
+++ b/newtmgr/cli/commands.go
@@ -67,7 +67,7 @@ func Commands() *cobra.Command {
nmCmd.AddCommand(dTimeCmd())
nmCmd.AddCommand(resetCmd())
nmCmd.AddCommand(crashCmd())
- nmCmd.AddCommand(runtestCmd())
+ nmCmd.AddCommand(runCmd())
return nmCmd
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e1b064e8/newtmgr/cli/runtest.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/runtest.go b/newtmgr/cli/runtest.go
index b7a83a3..47f0c87 100644
--- a/newtmgr/cli/runtest.go
+++ b/newtmgr/cli/runtest.go
@@ -21,72 +21,125 @@ package cli
import (
"fmt"
- "time"
"github.com/spf13/cobra"
- "mynewt.apache.org/newt/newtmgr/config"
"mynewt.apache.org/newt/newtmgr/protocol"
- "mynewt.apache.org/newt/newtmgr/transport"
)
-func runtestRunCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
+func runCmd() *cobra.Command {
+ runCmd := &cobra.Command{
+ Use: "run",
+ Short: "Run procedures on remote device",
+ Run: func(cmd *cobra.Command, args []string) {
+ cmd.HelpFunc()(cmd, args)
+ },
}
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
+ runtestEx :=" newtmgr -c conn run test all 201612161220"
- conn, err := transport.NewConnWithTimeout(profile, time.Second*1)
- if err != nil {
- nmUsage(cmd, err)
+ runTestCmd := &cobra.Command{
+ Use: "test [all | testname] [token]",
+ Short: "Run commands on remote device - \"token\" output on log messages",
+ Example: runtestEx,
+ Run: runTestCmd,
}
- defer conn.Close()
+ runCmd.AddCommand(runTestCmd)
- runner, err := protocol.NewCmdRunner(conn)
- if err != nil {
- nmUsage(cmd, err)
+ runListCmd := &cobra.Command{
+ Use: "list",
+ Short: "List registered commands on remote device",
+ Run: runListCmd,
}
+ runCmd.AddCommand(runListCmd)
- runtest, err := protocol.RunTest()
- if err != nil {
- nmUsage(cmd, err)
- }
+ return runCmd
+}
- nmr, err := runtest.EncodeWriteRequest()
- if err != nil {
- nmUsage(cmd, err)
- }
+func runTestCmd(cmd *cobra.Command, args []string) {
+ runner, err := getTargetCmdRunner()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+ defer runner.Conn.Close()
- if err := runner.WriteReq(nmr); err != nil {
- nmUsage(cmd, err)
- }
+ req, err := protocol.NewRunTestReq()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
- rsp, err := runner.ReadResp()
- if err == nil {
- cRsp, err := protocol.DecodeRunTestResponse(rsp.Data)
- if err != nil {
- nmUsage(cmd, err)
- }
- if cRsp.Err != 0 {
- fmt.Printf("Failed, error:%d\n", cRsp.Err)
- }
- }
- fmt.Println("Done")
+ if len(args) > 0 {
+ req.Testname = args[0]
+ if len(args) > 1 {
+ req.Token = args[1]
+ } else {
+ req.Token = ""
+ }
+ } else {
+ /*
+ * If nothing specified, turn on "all" by default
+ * There is no default token.
+ */
+ req.Testname = "all"
+ req.Token = ""
+ }
+
+ nmr, err := req.Encode()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ if err := runner.WriteReq(nmr); err != nil {
+ nmUsage(cmd, err)
+ }
+
+ rsp, err := runner.ReadResp()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ decodedResponse, err := protocol.DecodeRunTestResponse(rsp.Data)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ if decodedResponse.ReturnCode != 0 {
+ fmt.Printf("Return Code = %d\n", decodedResponse.ReturnCode)
+ }
}
-func runtestCmd() *cobra.Command {
- runtestEx := " runtest "
+func runListCmd(cmd *cobra.Command, args []string) {
+ runner, err := getTargetCmdRunner()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
- runtestCmd := &cobra.Command{
- Use: "runtest ",
- Short: "Initiate named test on remote endpoint using newtmgr (named test not yet supported)",
- Example: runtestEx,
- Run: runtestRunCmd,
- }
+ defer runner.Conn.Close()
+ req, err := protocol.NewRunListReq()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ nmr, err := req.Encode()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ if err := runner.WriteReq(nmr); err != nil {
+ nmUsage(cmd, err)
+ }
+
+ rsp, err := runner.ReadResp()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ decodedResponse, err := protocol.DecodeRunListResponse(rsp.Data)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
- return runtestCmd
+ fmt.Println(decodedResponse.List)
+ if decodedResponse.ReturnCode != 0 {
+ fmt.Printf("Return Code = %d\n", decodedResponse.ReturnCode)
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e1b064e8/newtmgr/protocol/defs.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/defs.go b/newtmgr/protocol/defs.go
index 8212d7f..7cdedd3 100644
--- a/newtmgr/protocol/defs.go
+++ b/newtmgr/protocol/defs.go
@@ -26,7 +26,7 @@ const (
NMGR_GROUP_ID_LOGS = 4
NMGR_GROUP_ID_CRASH = 5
NMGR_GROUP_ID_SPLIT = 6
- NMGR_GROUP_ID_RUNTEST = 7
+ NMGR_GROUP_ID_RUN = 7
NMGR_GROUP_ID_PERUSER = 64
)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e1b064e8/newtmgr/protocol/runtest.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/runtest.go b/newtmgr/protocol/runtest.go
index 4f5693f..218ef86 100644
--- a/newtmgr/protocol/runtest.go
+++ b/newtmgr/protocol/runtest.go
@@ -26,43 +26,123 @@ import (
"mynewt.apache.org/newt/util"
)
-type Test struct {
- Err int `codec:"rc,omitempty"`
-}
+const (
+ RUN_NMGR_OP_TEST = 0
+ RUN_NMGR_OP_LIST = 1
+)
-func RunTest() (*Test, error) {
- c := &Test{ }
- return c, nil
+/*
+ * run test [all | testname] [token]
+ * max testname and token size is 32 bytes
+ *
+ * This is written with the idea to provide a more extensible RPC mechanism however
+ * the "test" commands constrains the remote calls to those registered to
+ * test infrastructure.
+ */
+type RunTestReq struct {
+ Testname string `codec:"testname"`
+ Token string `codec:"token"`
}
-func (c *Test) EncodeWriteRequest() (*NmgrReq, error) {
- data := make([]byte, 0)
- enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
- enc.Encode(c)
+func NewRunTestReq() (*RunTestReq, error) {
+ s := &RunTestReq{}
- fmt.Printf("runtest\n")
- nmr, err := NewNmgrReq()
+ return s, nil
+}
+
+func (sr *RunTestReq) Encode() (*NmgrReq, error) {
+ nmr, err := NewNmgrReq()
if err != nil {
return nil, err
}
nmr.Op = NMGR_OP_WRITE
nmr.Flags = 0
- nmr.Group = NMGR_GROUP_ID_RUNTEST
- nmr.Id = 0
- nmr.Len = uint16(len(data))
+ nmr.Group = NMGR_GROUP_ID_RUN
+ nmr.Id = RUN_NMGR_OP_TEST
+ req := &RunTestReq{
+ Testname: sr.Testname,
+ Token: sr.Token,
+ }
+
+ data := make([]byte, 0)
+ enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
+
+ enc.Encode(req)
nmr.Data = data
+ nmr.Len = uint16(len(data))
+
+ return nmr, nil
+}
- return nmr, nil
+type RunTestRsp struct {
+ ReturnCode int `codec:"rc"`
}
-func DecodeRunTestResponse(data []byte) (*Test, error) {
- c := &Test{}
+func DecodeRunTestResponse(data []byte) (*RunTestRsp, error) {
+ var resp RunTestRsp
dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
- if err := dec.Decode(&c); err != nil {
+ err := dec.Decode(&resp)
+ if err != nil {
return nil, util.NewNewtError(fmt.Sprintf("Invalid response: %s",
- err.Error()))
+ err.Error()))
}
- return c, nil
+
+ return &resp, nil
+}
+
+/*
+ * run list
+ * Returns the list of tests that have been registered on the device.
+ */
+type RunListReq struct {
+}
+
+type RunListRsp struct {
+ ReturnCode int `codec:"rc"`
+ List []string `codec:"run_list"`
+}
+
+func NewRunListReq() (*RunListReq, error) {
+ s := &RunListReq{}
+
+ return s, nil
+}
+
+func (sr *RunListReq) Encode() (*NmgrReq, error) {
+ nmr, err := NewNmgrReq()
+ if err != nil {
+ return nil, err
+ }
+
+ nmr.Op = NMGR_OP_READ
+ nmr.Flags = 0
+ nmr.Group = NMGR_GROUP_ID_RUN
+ nmr.Id = RUN_NMGR_OP_LIST
+
+ req := &RunListReq{}
+
+ data := make([]byte, 0)
+ enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
+ enc.Encode(req)
+
+ nmr.Data = data
+ nmr.Len = uint16(len(data))
+
+ return nmr, nil
+}
+
+func DecodeRunListResponse(data []byte) (*RunListRsp, error) {
+ var resp RunListRsp
+
+ dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
+ err := dec.Decode(&resp)
+ if err != nil {
+ return nil,
+ util.NewNewtError(fmt.Sprintf("Invalid incoming cbor: %s",
+ err.Error()))
+ }
+
+ return &resp, nil
}