You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/11/10 22:38:37 UTC

[25/50] incubator-mynewt-newt git commit: MYNEWT-139: Add runtest command to newtmgr

MYNEWT-139: Add runtest command to newtmgr

Add runtest command to launch test on target devices.
This is a partial checkin which simply allows the tests to run,
future enhancements should include specifying which test suite to run.


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/a1cb7024
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/a1cb7024
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/a1cb7024

Branch: refs/heads/master
Commit: a1cb7024e927c7f17601dbc120ca0c5c08acf49c
Parents: c30dc2d
Author: Peter Snyder <pe...@apache.org>
Authored: Tue Nov 1 16:02:00 2016 -0700
Committer: Peter Snyder <pe...@apache.org>
Committed: Tue Nov 1 16:04:13 2016 -0700

----------------------------------------------------------------------
 newtmgr/cli/commands.go     |  1 +
 newtmgr/cli/runtest.go      | 92 ++++++++++++++++++++++++++++++++++++++++
 newtmgr/protocol/defs.go    |  1 +
 newtmgr/protocol/runtest.go | 68 +++++++++++++++++++++++++++++
 4 files changed, 162 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a1cb7024/newtmgr/cli/commands.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/commands.go b/newtmgr/cli/commands.go
index bbcb4a1..39ede96 100644
--- a/newtmgr/cli/commands.go
+++ b/newtmgr/cli/commands.go
@@ -67,6 +67,7 @@ func Commands() *cobra.Command {
 	nmCmd.AddCommand(dTimeCmd())
 	nmCmd.AddCommand(resetCmd())
 	nmCmd.AddCommand(crashCmd())
+	nmCmd.AddCommand(runtestCmd())
 
 	return nmCmd
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a1cb7024/newtmgr/cli/runtest.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/runtest.go b/newtmgr/cli/runtest.go
new file mode 100644
index 0000000..b7a83a3
--- /dev/null
+++ b/newtmgr/cli/runtest.go
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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)
+	}
+
+	profile, err := cpm.GetConnProfile(ConnProfileName)
+	if err != nil {
+		nmUsage(cmd, err)
+	}
+
+	conn, err := transport.NewConnWithTimeout(profile, time.Second*1)
+	if err != nil {
+		nmUsage(cmd, err)
+	}
+	defer conn.Close()
+
+	runner, err := protocol.NewCmdRunner(conn)
+	if err != nil {
+		nmUsage(cmd, err)
+	}
+
+	runtest, err := protocol.RunTest()
+	if err != nil {
+		nmUsage(cmd, err)
+	}
+
+	nmr, err := runtest.EncodeWriteRequest()
+	if err != nil {
+		nmUsage(cmd, err)
+	}
+
+	if err := runner.WriteReq(nmr); 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")
+}
+
+func runtestCmd() *cobra.Command {
+	runtestEx := "   runtest "
+
+	runtestCmd := &cobra.Command{
+		Use:     "runtest ",
+		Short:   "Initiate named test on remote endpoint using newtmgr (named test not yet supported)",
+		Example: runtestEx,
+		Run:     runtestRunCmd,
+	}
+
+	return runtestCmd
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a1cb7024/newtmgr/protocol/defs.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/defs.go b/newtmgr/protocol/defs.go
index 6724661..8212d7f 100644
--- a/newtmgr/protocol/defs.go
+++ b/newtmgr/protocol/defs.go
@@ -26,6 +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_PERUSER = 64
 )
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a1cb7024/newtmgr/protocol/runtest.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/runtest.go b/newtmgr/protocol/runtest.go
new file mode 100644
index 0000000..4f5693f
--- /dev/null
+++ b/newtmgr/protocol/runtest.go
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package protocol
+
+import (
+	"fmt"
+
+	"github.com/ugorji/go/codec"
+	"mynewt.apache.org/newt/util"
+)
+
+type Test struct {
+	Err       int    `codec:"rc,omitempty"`
+}
+
+func RunTest() (*Test, error) {
+	c := &Test{ }
+	return c, nil
+}
+
+func (c *Test) EncodeWriteRequest() (*NmgrReq, error) {
+	data := make([]byte, 0)
+	enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
+	enc.Encode(c)
+
+	fmt.Printf("runtest\n")
+	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.Data = data
+
+	return nmr, nil
+}
+
+func DecodeRunTestResponse(data []byte) (*Test, error) {
+	c := &Test{}
+
+	dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
+	if err := dec.Decode(&c); err != nil {
+		return nil, util.NewNewtError(fmt.Sprintf("Invalid response: %s",
+			err.Error()))
+	}
+	return c, nil
+}