Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP, DNM] Adding test scripts #32

Open
wants to merge 67 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
97241e2
mynewt core mcumgr port
vrahane May 30, 2019
682df33
Custome reader/writer only used for ZEPHYR
vrahane May 30, 2019
43a2a81
Mynewt: Fix Apache Mynewt MCUmgr nuild issues
vrahane May 31, 2019
0a3fbb0
Remove stubs - were causing build issues since the packpages are sepa…
vrahane May 31, 2019
6e4556a
Fix build issues
vrahane Jun 1, 2019
97c6ecd
Fix build issues
vrahane Jun 5, 2019
8aec843
Add img_mgmt pkg_init
vrahane Jun 6, 2019
adb281c
cmd/os_mgmt: Fix mynewt port and misc fixes
vrahane Jun 14, 2019
06ecd3b
log_mgmt: Add fixes from mynewt-core to log_mgmt
vrahane Jun 19, 2019
69f7d69
log_mgmt: log entry encoder needs to be generic
vrahane Jun 20, 2019
a0d3a96
Fix a few bugs with log read handlers
vrahane Jun 21, 2019
a29e222
SMP: make multiple registration for same group possible
vrahane Jun 25, 2019
5d72448
stat_mgmt: Add stat_mgmt support for mynewt
vrahane Jun 26, 2019
6496426
img_mgmt: Make img_mgmt_slot_in_use() a public API
vrahane Jul 27, 2019
675e39b
Added lazy erase support.
mlaz Jul 29, 2019
7f034c4
Fix soft reset logging
mlaz Jul 29, 2019
8914f87
img_mgmt: Mynewt port update
vrahane Jul 30, 2019
724c256
img_mgmt: Fix build
vrahane Jul 31, 2019
f7e2f1c
cmd/img_mgmt: Add doxygen comments for img_mgmt
vrahane Aug 13, 2019
edb23c0
samples/smp_svr: Fix smp_svr for apache-mynewt
vrahane Aug 16, 2019
a826909
smp_srv: Add capability to read UICR
vrahane Aug 19, 2019
e012ffe
cboratttr,cmd/img_mgmt: Fix tests
vrahane Aug 22, 2019
fcd6904
omp: wip - oicmgr + omp_streamer
vrahane Jul 31, 2019
b5d5f49
omp_svr: Add app for omp_svr
vrahane Aug 27, 2019
8be59d9
write map not breaking anymore
mlaz Aug 27, 2019
36ba8d2
omp now working propperly
mlaz Aug 27, 2019
abc5a1a
Add capability to talkt to the omp_svr over BLE
vrahane Aug 27, 2019
7e13d8c
omp_svr: remove redundant code and enable GATT
vrahane Aug 27, 2019
a544bec
omp_svr: Use console for BLE logging and not cbmem
vrahane Aug 28, 2019
2ee4828
Cleanup and rearangemet: added omp/port/mynewt, added struct omp_stat…
mlaz Aug 28, 2019
523f08b
Cleanup on samples/smp_svr
mlaz Aug 28, 2019
7fd945c
Private omp function prototypes now on omp_priv.h
mlaz Aug 28, 2019
92fa6ca
OMP_OIC_RESOURCE_NAME now defined on mynewt-core/oicmgr side
mlaz Aug 28, 2019
436a9d5
Fixed timeout on invalid log show command, omp_process_mgmt_hdr refac…
mlaz Aug 29, 2019
c998c74
Fixed timeout on invalid log show command, omp_process_mgmt_hdr refac…
mlaz Aug 30, 2019
1ae7ca5
omp, mgmt: Changes for backwards compatibility
vrahane Sep 4, 2019
2df6c98
img_mgmt: use IMG_MGMT_DUMMY_HDR and add backwards
vrahane Sep 4, 2019
7a11126
cborattr: Make mbuf APIs non ZEPHYR specific
vrahane Sep 6, 2019
61dd615
log_mgmt: Add backwards compatibility for log_mgmt
vrahane Sep 6, 2019
542db22
log imghash support added
mlaz Sep 10, 2019
33169b7
Sample apps support native BSP.
mlaz Sep 10, 2019
93e47e5
samples: change syscfgs to match mcumgr changes
vrahane Sep 11, 2019
29473a3
cborattr: Add testcases from mynewt-core
vrahane Sep 11, 2019
610a396
cborattr_encode_omit test now runs.
mlaz Sep 11, 2019
4d8078f
adding cborattr dependency on omp
mlaz Sep 12, 2019
635d701
Fix os_mgmt conditional feature enablement
mlaz Sep 13, 2019
3676852
stat_mgmt: fix stat list crash
vrahane Sep 13, 2019
82a1129
stat_mgmt: Fix cbor container issues
vrahane Sep 25, 2019
bd31d22
Fixing log body read size.
mlaz Sep 26, 2019
63e5fb9
log_mgmt: Use log max len for reading log entries
vrahane Sep 26, 2019
43e485f
mynewt_log_mgmt: need to read chunk by chunk
vrahane Sep 26, 2019
a2fd55c
log_mgmt: log entry shld get encoded at the end
vrahane Sep 26, 2019
3ead348
mynewt_log_mgmt:syscfg changes chunked log reads
vrahane Sep 26, 2019
dd0178f
log_mgmt: fix includes
vrahane Sep 26, 2019
a181f39
log_mgmt: errors should be caught per chunk
vrahane Sep 27, 2019
3d9943f
img_mgmt: add img_mgmt logging from mynewt-core
vrahane Sep 28, 2019
ee7c1ac
Closing CBOR containers on error situations before returning.
mlaz Sep 30, 2019
b20765b
Merge pull request #11 from mlaz/mynewt_mcumgr
vrahane Oct 1, 2019
d6a7bcb
log_mgmt: Add watermark support
vrahane Oct 1, 2019
a6adcb2
log_mgmt: entries need to be encoded chunk by chunk
vrahane Oct 2, 2019
59576c1
log_mgmt: add some comments
vrahane Oct 2, 2019
081cad7
cmd/fs fixing package dependency chain
mlaz Oct 2, 2019
8478dcb
cmd: move config headers to include directory
vrahane Oct 2, 2019
bde1003
cborattr: APIs & structs need to be MYNEWT specific
vrahane Oct 2, 2019
ebf9d6e
img_mgmt: coding style changes
vrahane Oct 2, 2019
50e8571
Merge pull request #12 from mlaz/mynewt_mcumgr
vrahane Oct 3, 2019
7fcdfa7
Added a few first test scripts.
mlaz Oct 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cborattr/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE image
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this image
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this image 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.

config CBORATTR_MAX_SIZE
int "Maximum chunk size for image uploads"
default 512
help
The maximum size of a CBOR attribute during decoding
69 changes: 68 additions & 1 deletion cborattr/include/cborattr/cborattr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
#include <ctype.h>
#include <stdio.h>
#include <sys/types.h>
#include "cbor.h"
#include "tinycbor/cbor.h"

#ifdef MYNEWT
#include <os/os_mbuf.h>
#endif

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -117,6 +121,43 @@ struct cbor_attr_t {
bool nodefault;
};

#ifndef __ZEPHYR__
/** An array value to be encoded as CBOR. */
struct cbor_out_arr_val_t {
struct cbor_out_val_t *elems;
size_t len;
};

/** A single value to be encoded as CBOR. */
struct cbor_out_val_t {
/** The type of data. */
CborAttrType type;

/** The data value. */
union {
long long int integer;
long long unsigned int uinteger;
double real;
float fval;
const char *string;
bool boolean;
struct {
const uint8_t *data;
size_t len;
} bytestring;
struct cbor_out_arr_val_t array;
struct cbor_out_attr_t *obj; /* Terminated with a type=0 entry. */
};
};

/** An object key-value pair to be encoded as CBOR. */
struct cbor_out_attr_t {
const char *attribute; /** The attribute name (key). */
struct cbor_out_val_t val; /** The attribute value. */
bool omit; /** Attribute ignored if true. */
};
#endif

/*
* Use the following macros to declare template initializers for
* CborAttrStructObjectType arrays. Writing the equivalents out by hand is
Expand Down Expand Up @@ -144,7 +185,33 @@ int cbor_read_array(struct CborValue *, const struct cbor_array_t *);

int cbor_read_flat_attrs(const uint8_t *data, int len,
const struct cbor_attr_t *attrs);
#ifdef MYNEWT
int cbor_read_mbuf_attrs(struct os_mbuf *m, uint16_t off, uint16_t len,
const struct cbor_attr_t *attrs);

/**
* @brief Encodes a CBOR representation of the specified key-value map.
*
* @param enc The CBOR encoder to write to.
* @param attrs The key-value map to encode.
*
* @return 0 on success; SYS_E[...] error on failure.
*/
int cbor_write_object(struct CborEncoder *enc,
const struct cbor_out_attr_t *attrs);

/**
* @brief Encodes a CBOR representation of the specified key-value map into an
* msys mbuf chain.
*
* @param attrs The key-value map to encode.
* @param out_om On success, points to the populate mbuf chain.
*
* @return 0 on success; SYS_E[...] error on failure.
*/
int cbor_write_object_msys(const struct cbor_out_attr_t *attrs,
struct os_mbuf **out_om);
#endif
#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion cborattr/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:

pkg.deps:
- "encoding/tinycbor"
- "@apache-mynewt-core/encoding/tinycbor"

pkg.cflags.FLOAT_USER: -DFLOAT_SUPPORT
206 changes: 202 additions & 4 deletions cborattr/src/cborattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@

//#include <syscfg/syscfg.h>
#include "cborattr/cborattr.h"
#include "cbor.h"
#include "cbor_buf_reader.h"
#include "tinycbor/cbor.h"
#include "tinycbor/cbor_buf_reader.h"

#ifdef MYNEWT
#include "tinycbor/cbor_mbuf_reader.h"
#include "tinycbor/cbor_mbuf_writer.h"
#include "os/os_mbuf.h"
#define CBORATTR_MAX_SIZE MYNEWT_VAL(CBORATTR_MAX_SIZE)
#else
#define CBORATTR_MAX_SIZE CONFIG_CBORATTR_MAX_SIZE
#endif

#define CBORATTR_MAX_SIZE 512

static int cbor_write_val(struct CborEncoder *enc,
const struct cbor_out_val_t *val);

/* this maps a CborType to a matching CborAtter Type. The mapping is not
* one-to-one because of signedness of integers
Expand Down Expand Up @@ -180,6 +191,7 @@ cbor_internal_read_object(CborValue *root_value,
}
}


if (cbor_value_is_map(root_value)) {
err |= cbor_value_enter_container(root_value, &cur_value);
} else {
Expand Down Expand Up @@ -386,14 +398,18 @@ cbor_read_flat_attrs(const uint8_t *data, int len,
CborError err;

cbor_buf_reader_init(&reader, data, len);
#ifdef __ZEPHYR__
err = cbor_parser_cust_reader_init(&reader.r, 0, &parser, &value);
#else
err = cbor_parser_init(&reader.r, 0, &parser, &value);
#endif
if (err != CborNoError) {
return -1;
}
return cbor_read_object(&value, attrs);
}

#if 0
#ifdef MYNEWT
/*
* Read in cbor key/values from os_mbuf pointed by m, and fill them
* into attrs.
Expand Down Expand Up @@ -421,4 +437,186 @@ cbor_read_mbuf_attrs(struct os_mbuf *m, uint16_t off, uint16_t len,
}
return cbor_read_object(&value, attrs);
}

static int
cbor_write_arr_val(struct CborEncoder *enc,
const struct cbor_out_arr_val_t *arr)
{
struct CborEncoder arr_enc;
size_t i;
int rc;

rc = cbor_encoder_create_array(enc, &arr_enc, arr->len);
if (rc != 0) {
return SYS_ENOMEM;
}

for (i = 0; i < arr->len; i++) {
rc = cbor_write_val(&arr_enc, &arr->elems[i]);
if (rc != 0) {
return SYS_ENOMEM;
}
}

rc = cbor_encoder_close_container(enc, &arr_enc);
if (rc != 0) {
return SYS_ENOMEM;
}

return 0;
}

static int
cbor_write_val(struct CborEncoder *enc, const struct cbor_out_val_t *val)
{
int len;
int rc;

switch (val->type) {
case CborAttrNullType:
rc = cbor_encode_null(enc);
break;

case CborAttrBooleanType:
rc = cbor_encode_boolean(enc, val->boolean);
break;

case CborAttrIntegerType:
rc = cbor_encode_int(enc, val->integer);
break;

case CborAttrUnsignedIntegerType:
rc = cbor_encode_uint(enc, val->uinteger);
break;

#if FLOAT_SUPPORT
case CborAttrFloatType:
rc = cbor_encode_float(enc, val->fval);
break;

case CborAttrDoubleType:
rc = cbor_encode_double(enc, val->real);
break;
#endif

case CborAttrByteStringType:
if (val->bytestring.data == NULL &&
val->bytestring.len != 0) {

return SYS_EINVAL;
}

rc = cbor_encode_byte_string(enc, val->bytestring.data,
val->bytestring.len);
break;

case CborAttrTextStringType:
if (val->string == NULL) {
len = 0;
} else {
len = strlen(val->string);
}
rc = cbor_encode_text_string(enc, val->string, len);
break;

case CborAttrObjectType:
rc = cbor_write_object(enc, val->obj);
break;

case CborAttrArrayType:
rc = cbor_write_arr_val(enc, &val->array);
break;

default:
return SYS_ENOTSUP;
}

if (rc != 0) {
return SYS_ENOMEM;
}

return 0;
}

static int
cbor_write_attr(struct CborEncoder *enc, const struct cbor_out_attr_t *attr)
{
int len;
int rc;

if (attr->omit) {
return 0;
}

if (!attr->attribute) {
rc = SYS_EINVAL;
return rc;
}

len = strlen(attr->attribute);
rc = cbor_encode_text_string(enc, attr->attribute, len);
if (rc != 0) {
return rc;
}

rc = cbor_write_val(enc, &attr->val);
if (rc != 0) {
return rc;
}

return 0;
}

int
cbor_write_object(struct CborEncoder *enc, const struct cbor_out_attr_t *attrs)
{
const struct cbor_out_attr_t *attr;
struct CborEncoder map;
int rc;

rc = cbor_encoder_create_map(enc, &map, CborIndefiniteLength);
if (rc != 0) {
return SYS_ENOMEM;
}

for (attr = attrs; attr->val.type != 0; attr++) {
rc = cbor_write_attr(&map, attr);
if (rc != 0) {
return rc;
}
}

rc = cbor_encoder_close_container(enc, &map);
if (rc != 0) {
return SYS_ENOMEM;
}

return 0;
}

int
cbor_write_object_msys(const struct cbor_out_attr_t *attrs,
struct os_mbuf **out_om)
{
struct cbor_mbuf_writer writer;
struct CborEncoder encoder;
int rc;

*out_om = os_msys_get_pkthdr(0, 0);
if (*out_om == NULL) {
return SYS_ENOMEM;
}

cbor_mbuf_writer_init(&writer, *out_om);
cbor_encoder_init(&encoder, &writer.enc, 0);

rc = cbor_write_object(&encoder, attrs);
if (rc != 0) {
os_mbuf_free_chain(*out_om);
*out_om = NULL;
return rc;
}

return 0;
}
#endif
8 changes: 5 additions & 3 deletions cborattr/test/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:

pkg.deps:
- '@mynewt-mcumgr/ext/tinycbor'
- '@mynewt-mcumgr/cborattr'
- '@apache-mynewt-core/encoding/tinycbor'
- '@apache-mynewt-mcumgr/cborattr'

pkg.deps.SELFTEST:
- sys/console/stub
- '@apache-mynewt-core/sys/console/stub'
- '@apache-mynewt-core/sys/log/full'
- '@apache-mynewt-core/test/testutil'
2 changes: 2 additions & 0 deletions cborattr/test/src/test_cborattr.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ extern "C" {
*/
const uint8_t *test_str1(int *len);

void cborattr_test_util_encode(const struct cbor_out_attr_t *attrs,
const uint8_t *expected, int len);
/*
* Testcases
*/
Expand Down
Loading