You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/01/22 12:26:24 UTC

[GitHub] mkiiskila closed pull request #745: sys/config; fill in support functions regarding INT64 types.

mkiiskila closed pull request #745: sys/config; fill in support functions regarding INT64 types.
URL: https://github.com/apache/mynewt-core/pull/745
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/sys/config/src/config.c b/sys/config/src/config.c
index 4dc00e32f..693309308 100644
--- a/sys/config/src/config.c
+++ b/sys/config/src/config.c
@@ -120,6 +120,7 @@ int
 conf_value_from_str(char *val_str, enum conf_type type, void *vp, int maxlen)
 {
     int32_t val;
+    int64_t val64;
     char *eptr;
 
     if (!val_str) {
@@ -153,6 +154,13 @@ conf_value_from_str(char *val_str, enum conf_type type, void *vp, int maxlen)
             *(int32_t *)vp = val;
         }
         break;
+    case CONF_INT64:
+        val64 = strtoll(val_str, &eptr, 0);
+        if (*eptr != '\0') {
+            goto err;
+        }
+        *(int64_t *)vp = val64;
+        break;
     case CONF_STRING:
         val = strlen(val_str);
         if (val + 1 > maxlen) {
@@ -208,6 +216,9 @@ conf_str_from_value(enum conf_type type, void *vp, char *buf, int buf_len)
         }
         snprintf(buf, buf_len, "%ld", (long)val);
         return buf;
+    case CONF_INT64:
+        snprintf(buf, buf_len, "%lld", *(long long *)vp);
+        return buf;
     default:
         return NULL;
     }
diff --git a/sys/config/test-fcb/src/conf_test_fcb.c b/sys/config/test-fcb/src/conf_test_fcb.c
index 106ddd755..fabad344b 100644
--- a/sys/config/test-fcb/src/conf_test_fcb.c
+++ b/sys/config/test-fcb/src/conf_test_fcb.c
@@ -36,6 +36,7 @@ int c2_var_count = 1;
 char val_string[CONF_TEST_FCB_VAL_STR_CNT][CONF_MAX_VAL_LEN];
 
 uint32_t val32;
+uint64_t val64;
 
 int test_get_called;
 int test_set_called;
@@ -74,6 +75,9 @@ ctest_handle_get(int argc, char **argv, char *val, int val_len_max)
     if (argc == 1 && !strcmp(argv[0], "mybar")) {
         return conf_str_from_value(CONF_INT8, &val8, val, val_len_max);
     }
+    if (argc == 1 && !strcmp(argv[0], "mybar64")) {
+        return conf_str_from_value(CONF_INT64, &val64, val, val_len_max);
+    }
     return NULL;
 }
 
@@ -81,6 +85,7 @@ int
 ctest_handle_set(int argc, char **argv, char *val)
 {
     uint8_t newval;
+    uint64_t newval64;
     int rc;
 
     test_set_called = 1;
@@ -90,6 +95,12 @@ ctest_handle_set(int argc, char **argv, char *val)
         val8 = newval;
         return 0;
     }
+    if (argc == 1 && !strcmp(argv[0], "mybar64")) {
+        rc = CONF_VALUE_SET(val, CONF_INT64, newval64);
+        TEST_ASSERT(rc == 0);
+        val64 = newval64;
+        return 0;
+    }
     return OS_ENOENT;
 }
 
@@ -112,6 +123,9 @@ ctest_handle_export(void (*cb)(char *name, char *value),
     conf_str_from_value(CONF_INT8, &val8, value, sizeof(value));
     cb("myfoo/mybar", value);
 
+    conf_str_from_value(CONF_INT64, &val64, value, sizeof(value));
+    cb("myfoo/mybar64", value);
+
     return 0;
 }
 
@@ -308,6 +322,7 @@ TEST_CASE_DECL(config_test_insert)
 TEST_CASE_DECL(config_test_getset_unknown)
 TEST_CASE_DECL(config_test_getset_int)
 TEST_CASE_DECL(config_test_getset_bytes)
+TEST_CASE_DECL(config_test_getset_int64)
 TEST_CASE_DECL(config_test_commit)
 TEST_CASE_DECL(config_test_empty_fcb)
 TEST_CASE_DECL(config_test_save_1_fcb)
@@ -328,6 +343,7 @@ TEST_SUITE(config_test_all)
     config_test_getset_unknown();
     config_test_getset_int();
     config_test_getset_bytes();
+    config_test_getset_int64();
 
     config_test_commit();
 
diff --git a/sys/config/test-fcb/src/conf_test_fcb.h b/sys/config/test-fcb/src/conf_test_fcb.h
index 1a4548ca9..a5338ff0e 100644
--- a/sys/config/test-fcb/src/conf_test_fcb.h
+++ b/sys/config/test-fcb/src/conf_test_fcb.h
@@ -34,8 +34,8 @@
 extern "C" {
 #endif
 
-uint8_t val8;
-int c2_var_count;
+extern uint8_t val8;
+extern int c2_var_count;
 
 #define CONF_TEST_FCB_VAL_STR_CNT   64
 
@@ -45,12 +45,13 @@ extern char val_string[CONF_TEST_FCB_VAL_STR_CNT][CONF_MAX_VAL_LEN];
 
 extern struct flash_area fcb_areas[CONF_TEST_FCB_FLASH_CNT];
 
-uint32_t val32;
+extern uint32_t val32;
+extern uint64_t val64;
 
-int test_get_called;
-int test_set_called;
-int test_commit_called;
-int test_export_block;
+extern int test_get_called;
+extern int test_set_called;
+extern int test_commit_called;
+extern int test_export_block;
 
 void ctest_clear_call_state(void);
 int ctest_get_call_state(void);
@@ -77,11 +78,11 @@ int c3_handle_set(int argc, char **argv, char *val);
 int c3_handle_export(void (*cb)(char *name, char *value),
                      enum conf_export_tgt tgt);
 
-struct conf_handler config_test_handler;
+extern struct conf_handler config_test_handler;
 
-struct conf_handler c2_test_handler;
+extern struct conf_handler c2_test_handler;
 
-struct conf_handler c3_test_handler;
+extern struct conf_handler c3_test_handler;
 
 #ifdef __cplusplus
 }
diff --git a/sys/config/test-fcb/src/testcases/config_test_getset_int64.c b/sys/config/test-fcb/src/testcases/config_test_getset_int64.c
new file mode 100644
index 000000000..1cea1663d
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_test_getset_int64.c
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+#include "conf_test_fcb.h"
+
+TEST_CASE(config_test_getset_int64)
+{
+    char name[80];
+    char tmp[64], *str;
+    int rc;
+    int64_t cmp;
+
+    strcpy(name, "myfoo/mybar64");
+    rc = conf_set_value(name, "-9218247941279444428");
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(test_set_called == 1);
+    cmp = 0x8012345678901234;
+    TEST_ASSERT(memcmp(&val64, &cmp, sizeof(val64)) == 0);
+    ctest_clear_call_state();
+
+    strcpy(name, "myfoo/mybar64");
+    str = conf_get_value(name, tmp, sizeof(tmp));
+    TEST_ASSERT(str);
+    TEST_ASSERT(test_get_called == 1);
+    TEST_ASSERT(!strcmp("-9218247941279444428", tmp));
+    ctest_clear_call_state();
+
+    strcpy(name, "myfoo/mybar64");
+    rc = conf_set_value(name, "1");
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(test_set_called == 1);
+    TEST_ASSERT(val64 == 1);
+    ctest_clear_call_state();
+
+    strcpy(name, "myfoo/mybar64");
+    str = conf_get_value(name, tmp, sizeof(tmp));
+    TEST_ASSERT(str);
+    TEST_ASSERT(test_get_called == 1);
+    TEST_ASSERT(!strcmp("1", tmp));
+    ctest_clear_call_state();
+}
diff --git a/sys/config/test-nffs/src/conf_test_nffs.c b/sys/config/test-nffs/src/conf_test_nffs.c
index c07e7e94e..420f1ae0c 100644
--- a/sys/config/test-nffs/src/conf_test_nffs.c
+++ b/sys/config/test-nffs/src/conf_test_nffs.c
@@ -34,6 +34,7 @@ int c2_var_count = 1;
 char val_string[64][CONF_MAX_VAL_LEN];
 
 uint32_t val32;
+uint64_t val64;
 
 int test_get_called;
 int test_set_called;
@@ -72,6 +73,9 @@ ctest_handle_get(int argc, char **argv, char *val, int val_len_max)
     if (argc == 1 && !strcmp(argv[0], "mybar")) {
         return conf_str_from_value(CONF_INT8, &val8, val, val_len_max);
     }
+    if (argc == 1 && !strcmp(argv[0], "mybar64")) {
+        return conf_str_from_value(CONF_INT64, &val64, val, val_len_max);
+    }
     return NULL;
 }
 
@@ -79,6 +83,7 @@ int
 ctest_handle_set(int argc, char **argv, char *val)
 {
     uint8_t newval;
+    uint64_t newval64;
     int rc;
 
     test_set_called = 1;
@@ -88,6 +93,12 @@ ctest_handle_set(int argc, char **argv, char *val)
         val8 = newval;
         return 0;
     }
+    if (argc == 1 && !strcmp(argv[0], "mybar64")) {
+        rc = CONF_VALUE_SET(val, CONF_INT64, newval64);
+        TEST_ASSERT(rc == 0);
+        val64 = newval64;
+        return 0;
+    }
     return OS_ENOENT;
 }
 
@@ -110,6 +121,9 @@ ctest_handle_export(void (*cb)(char *name, char *value),
     conf_str_from_value(CONF_INT8, &val8, value, sizeof(value));
     cb("myfoo/mybar", value);
 
+    conf_str_from_value(CONF_INT64, &val64, value, sizeof(value));
+    cb("myfoo/mybar64", value);
+
     return 0;
 }
 
@@ -317,6 +331,7 @@ TEST_CASE_DECL(config_test_insert)
 TEST_CASE_DECL(config_test_getset_unknown)
 TEST_CASE_DECL(config_test_getset_int)
 TEST_CASE_DECL(config_test_getset_bytes)
+TEST_CASE_DECL(config_test_getset_int64)
 TEST_CASE_DECL(config_test_commit)
 TEST_CASE_DECL(config_setup_nffs)
 TEST_CASE_DECL(config_test_empty_file)
@@ -335,6 +350,7 @@ TEST_SUITE(config_test_all)
     config_test_getset_unknown();
     config_test_getset_int();
     config_test_getset_bytes();
+    config_test_getset_int64();
 
     config_test_commit();
 
diff --git a/sys/config/test-nffs/src/conf_test_nffs.h b/sys/config/test-nffs/src/conf_test_nffs.h
index 4dfba7791..44ce61436 100644
--- a/sys/config/test-nffs/src/conf_test_nffs.h
+++ b/sys/config/test-nffs/src/conf_test_nffs.h
@@ -37,16 +37,17 @@
 extern "C" {
 #endif
 
-uint8_t val8;
-int c2_var_count;
-char val_string[64][CONF_MAX_VAL_LEN];
+extern uint8_t val8;
+extern int c2_var_count;
+extern char val_string[64][CONF_MAX_VAL_LEN];
 
-uint32_t val32;
+extern uint32_t val32;
+extern uint32_t val64;
 
-int test_get_called;
-int test_set_called;
-int test_commit_called;
-int test_export_block;
+extern int test_get_called;
+extern int test_set_called;
+extern int test_commit_called;
+extern int test_export_block;
 
 char *ctest_handle_get(int argc, char **argv, char *val, int val_len_max);
 int ctest_handle_set(int argc, char **argv, char *val);
@@ -70,11 +71,11 @@ int c3_handle_set(int argc, char **argv, char *val);
 int c3_handle_export(void (*cb)(char *name, char *value),
                      enum conf_export_tgt tgt);
 
-struct conf_handler config_test_handler;
+extern struct conf_handler config_test_handler;
 
-struct conf_handler c2_test_handler;
+extern struct conf_handler c2_test_handler;
 
-struct conf_handler c3_test_handler;
+extern struct conf_handler c3_test_handler;
 
 extern struct nffs_area_desc config_nffs[];
 
diff --git a/sys/config/test-nffs/src/testcases/config_test_getset_int64.c b/sys/config/test-nffs/src/testcases/config_test_getset_int64.c
new file mode 100644
index 000000000..a52d61938
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_test_getset_int64.c
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+#include "conf_test_nffs.h"
+
+TEST_CASE(config_test_getset_int64)
+{
+    char name[80];
+    char tmp[64], *str;
+    int rc;
+    int64_t cmp;
+
+    strcpy(name, "myfoo/mybar64");
+    rc = conf_set_value(name, "-9218247941279444428");
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(test_set_called == 1);
+    cmp = 0x8012345678901234;
+    TEST_ASSERT(memcmp(&val64, &cmp, sizeof(val64)) == 0);
+    ctest_clear_call_state();
+
+    strcpy(name, "myfoo/mybar64");
+    str = conf_get_value(name, tmp, sizeof(tmp));
+    TEST_ASSERT(str);
+    TEST_ASSERT(test_get_called == 1);
+    TEST_ASSERT(!strcmp("-9218247941279444428", tmp));
+    ctest_clear_call_state();
+
+    strcpy(name, "myfoo/mybar64");
+    rc = conf_set_value(name, "1");
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(test_set_called == 1);
+    TEST_ASSERT(val64 == 1);
+    ctest_clear_call_state();
+
+    strcpy(name, "myfoo/mybar64");
+    str = conf_get_value(name, tmp, sizeof(tmp));
+    TEST_ASSERT(str);
+    TEST_ASSERT(test_get_called == 1);
+    TEST_ASSERT(!strcmp("1", tmp));
+    ctest_clear_call_state();
+
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services