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/10/11 21:39:01 UTC
incubator-mynewt-newt git commit: newt - Make the "SELFTEST" setting
global.
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop 6b585caed -> 8c9a814a9
newt - Make the "SELFTEST" setting global.
Prior to this change, SELFTEST was only exported to the package under
test. However, it is useful for other packages to know if the "newt
test" command is being used. Now that tests are in their own pacakges,
there is no risk of conflicting main() functions.
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/8c9a814a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/8c9a814a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/8c9a814a
Branch: refs/heads/develop
Commit: 8c9a814a99b3ef76a34b4892b7c136b95b1164ec
Parents: 6b585ca
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Oct 11 14:34:58 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Oct 11 14:38:52 2016 -0700
----------------------------------------------------------------------
newt/builder/targetbuild.go | 12 +++---
newtmgr/cli/image.go | 44 ++++++++++++++++----
newtmgr/protocol/imagestate.go | 81 +++++++++++++++++++++++++++++--------
3 files changed, 108 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/8c9a814a/newt/builder/targetbuild.go
----------------------------------------------------------------------
diff --git a/newt/builder/targetbuild.go b/newt/builder/targetbuild.go
index ea8c0c8..620ea45 100644
--- a/newt/builder/targetbuild.go
+++ b/newt/builder/targetbuild.go
@@ -123,9 +123,13 @@ func (t *TargetBuilder) ExportCfg() (resolve.CfgResolution, error) {
}
if t.testPkg != nil {
- // Inject the TEST setting into the entire build. This setting
- // exposes unit test code in each package.
+ // A few features are automatically supported when the test command is
+ // used:
+ // * TEST: lets packages know that this is a test app
+ // * SELFTEST: indicates that the "newt test" command is used;
+ // causes a package to define a main() function.
t.injectedSettings["TEST"] = "1"
+ t.injectedSettings["SELFTEST"] = "1"
seeds = append(seeds, t.testPkg)
}
@@ -507,10 +511,6 @@ func (t *TargetBuilder) RelinkLoader() (error, map[string]bool,
}
func (t *TargetBuilder) Test() error {
- // Inject the SELFTEST setting into the package under test. This setting
- // indicates that the package needs to provide its own main().
- t.testPkg.InjectedSettings()["SELFTEST"] = "1"
-
cfgResolution, err := t.ExportCfg()
if err != nil {
return err
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/8c9a814a/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index e025f56..f28da64 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -100,14 +100,38 @@ func imageStateCmd(cmd *cobra.Command, args []string) {
}
defer runner.Conn.Close()
- imageState, err := protocol.NewImageState()
- if err != nil {
- nmUsage(cmd, err)
- }
+ var nmr *protocol.NmgrReq
- nmr, err := imageState.EncodeWriteRequest()
- if err != nil {
- nmUsage(cmd, err)
+ if args[0] == "show" {
+ req := protocol.ImageStateReadReq{}
+ nmr, err = req.Encode()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+ } else if args[0] == "test" {
+ if len(args) < 2 {
+ nmUsage(cmd, nil)
+ }
+
+ req := protocol.ImageStateWriteReq{
+ Hash: args[1],
+ Confirm: false,
+ }
+ nmr, err = req.Encode()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+ } else if args[0] == "confirm" {
+ req := protocol.ImageStateWriteReq{
+ Hash: args[1],
+ Confirm: false,
+ }
+ nmr, err = req.Encode()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+ } else {
+ nmUsage(cmd, nil)
}
if err := runner.WriteReq(nmr); err != nil {
@@ -123,6 +147,10 @@ func imageStateCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
+ if iRsp.ReturnCode != 0 {
+ fmt.Printf("Error executing state command: rc=%d\n", iRsp.ReturnCode)
+ return
+ }
fmt.Println("Images:")
for _, img := range iRsp.Images {
fmt.Printf(" slot=%d\n", img.Slot)
@@ -142,6 +170,8 @@ func imageStateCmd(cmd *cobra.Command, args []string) {
}
}
}
+
+ fmt.Printf("Split status: %s\n", iRsp.SplitStatus.String())
}
func echoOnNmUsage(runner *protocol.CmdRunner, cmderr error, cmd *cobra.Command) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/8c9a814a/newtmgr/protocol/imagestate.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagestate.go b/newtmgr/protocol/imagestate.go
index 4d85ea5..f64ad0f 100644
--- a/newtmgr/protocol/imagestate.go
+++ b/newtmgr/protocol/imagestate.go
@@ -26,26 +26,44 @@ import (
"mynewt.apache.org/newt/util"
)
+//type SplitStatus int
+
+//const (
+//NOT_APPLICABLE SplitStatus = iota
+//NOT_MATCHING
+//MATCHING
+//)
+
type ImageStateEntry struct {
- Slot int `codec:"slot"`
- Version string `codec:"version"`
- Hash string `codec:"hash"`
- Bootable bool `codec:"bootable"`
- Pending bool `codec:"test-pending"`
- Confirmed bool `codec:"confirmed"`
- Active bool `codec:"active"`
+ Slot int `codec:"slot"`
+ Version string `codec:"version"`
+ Hash string `codec:"hash"`
+ Bootable bool `codec:"bootable"`
+ Pending bool `codec:"pending"`
+ Confirmed bool `codec:"confirmed"`
+ Active bool `codec:"active"`
+}
+
+type ImageStateRsp struct {
+ ReturnCode int `codec:"rc"`
+ Images []ImageStateEntry `codec:"images"`
+ SplitStatus SplitStatus `codec:"splitStatus"`
+}
+
+type ImageStateReadReq struct {
}
-type ImageState struct {
- Images []ImageStateEntry `codec:"images"`
+type ImageStateWriteReq struct {
+ Hash string `codec:"hash"`
+ Confirm bool `codec:"confirm"`
}
-func NewImageState() (*ImageState, error) {
- s := &ImageState{}
+func NewImageStateRsp() (*ImageStateRsp, error) {
+ s := &ImageStateRsp{}
return s, nil
}
-func (i *ImageState) EncodeWriteRequest() (*NmgrReq, error) {
+func (i *ImageStateReadReq) Encode() (*NmgrReq, error) {
nmr, err := NewNmgrReq()
if err != nil {
return nil, err
@@ -60,14 +78,45 @@ func (i *ImageState) EncodeWriteRequest() (*NmgrReq, error) {
return nmr, nil
}
-func DecodeImageStateResponse(data []byte) (*ImageState, error) {
- state := &ImageState{}
+func (i *ImageStateWriteReq) Encode() (*NmgrReq, error) {
+ nmr, err := NewNmgrReq()
+ if err != nil {
+ return nil, err
+ }
+
+ clone := ImageStateWriteReq{
+ Confirm: i.Confirm,
+ }
+
+ if i.Hash != "" {
+ clone.Hash, err = HashEncode(i.Hash)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ nmr.Op = NMGR_OP_WRITE
+ nmr.Flags = 0
+ nmr.Group = NMGR_GROUP_ID_IMAGE
+ nmr.Id = IMGMGR_NMGR_OP_STATE
+
+ data := make([]byte, 0)
+ enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+ enc.Encode(clone)
+ nmr.Data = data
+ nmr.Len = uint16(len(data))
+
+ return nmr, nil
+}
+
+func DecodeImageStateResponse(data []byte) (*ImageStateRsp, error) {
+ rsp := &ImageStateRsp{}
dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
- err := dec.Decode(&state)
+ err := dec.Decode(&rsp)
if err != nil {
return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
err.Error()))
}
- return state, nil
+ return rsp, nil
}