http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_empty_file.c ---------------------------------------------------------------------- diff --git a/sys/config/test-nffs/src/testcases/config_test_empty_file.c b/sys/config/test-nffs/src/testcases/config_test_empty_file.c new file mode 100644 index 0000000..ab16095 --- /dev/null +++ b/sys/config/test-nffs/src/testcases/config_test_empty_file.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_nffs.h" + +TEST_CASE(config_test_empty_file) +{ + int rc; + struct conf_file cf_mfg; + struct conf_file cf_running; + const char cf_mfg_test[] = ""; + const char cf_running_test[] = "\n\n"; + + config_wipe_srcs(); + + cf_mfg.cf_name = "/config/mfg"; + cf_running.cf_name = "/config/running"; + + rc = conf_file_src(&cf_mfg); + TEST_ASSERT(rc == 0); + rc = conf_file_src(&cf_running); + + /* + * No files + */ + conf_load(); + + rc = fs_mkdir("/config"); + TEST_ASSERT(rc == 0); + + rc = fsutil_write_file("/config/mfg", cf_mfg_test, sizeof(cf_mfg_test)); + TEST_ASSERT(rc == 0); + + rc = fsutil_write_file("/config/running", cf_running_test, + sizeof(cf_running_test)); + TEST_ASSERT(rc == 0); + + conf_load(); + config_wipe_srcs(); + ctest_clear_call_state(); +}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_getset_bytes.c ---------------------------------------------------------------------- diff --git a/sys/config/test-nffs/src/testcases/config_test_getset_bytes.c b/sys/config/test-nffs/src/testcases/config_test_getset_bytes.c new file mode 100644 index 0000000..7d684a3 --- /dev/null +++ b/sys/config/test-nffs/src/testcases/config_test_getset_bytes.c @@ -0,0 +1,49 @@ +/** + * 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_bytes) +{ + char orig[32]; + char bytes[32]; + char str[48]; + char *ret; + int j, i; + int tmp; + int rc; + + for (j = 1; j < sizeof(orig); j++) { + for (i = 0; i < j; i++) { + orig[i] = i + j + 1; + } + ret = conf_str_from_bytes(orig, j, str, sizeof(str)); + TEST_ASSERT(ret); + tmp = strlen(str); + TEST_ASSERT(tmp < sizeof(str)); + + memset(bytes, 0, sizeof(bytes)); + tmp = sizeof(bytes); + + tmp = sizeof(bytes); + rc = conf_bytes_from_str(str, bytes, &tmp); + TEST_ASSERT(rc == 0); + TEST_ASSERT(tmp == j); + TEST_ASSERT(!memcmp(orig, bytes, j)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_getset_int.c ---------------------------------------------------------------------- diff --git a/sys/config/test-nffs/src/testcases/config_test_getset_int.c b/sys/config/test-nffs/src/testcases/config_test_getset_int.c new file mode 100644 index 0000000..c1305a2 --- /dev/null +++ b/sys/config/test-nffs/src/testcases/config_test_getset_int.c @@ -0,0 +1,40 @@ +/** + * 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_int) +{ + char name[80]; + char tmp[64], *str; + int rc; + + strcpy(name, "myfoo/mybar"); + rc = conf_set_value(name, "42"); + TEST_ASSERT(rc == 0); + TEST_ASSERT(test_set_called == 1); + TEST_ASSERT(val8 == 42); + ctest_clear_call_state(); + + strcpy(name, "myfoo/mybar"); + str = conf_get_value(name, tmp, sizeof(tmp)); + TEST_ASSERT(str); + TEST_ASSERT(test_get_called == 1); + TEST_ASSERT(!strcmp("42", tmp)); + ctest_clear_call_state(); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_getset_unknown.c ---------------------------------------------------------------------- diff --git a/sys/config/test-nffs/src/testcases/config_test_getset_unknown.c b/sys/config/test-nffs/src/testcases/config_test_getset_unknown.c new file mode 100644 index 0000000..323047f --- /dev/null +++ b/sys/config/test-nffs/src/testcases/config_test_getset_unknown.c @@ -0,0 +1,48 @@ +/** + * 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_unknown) +{ + char name[80]; + char tmp[64], *str; + int rc; + + strcpy(name, "foo/bar"); + rc = conf_set_value(name, "tmp"); + TEST_ASSERT(rc != 0); + TEST_ASSERT(ctest_get_call_state() == 0); + + strcpy(name, "foo/bar"); + str = conf_get_value(name, tmp, sizeof(tmp)); + TEST_ASSERT(str == NULL); + TEST_ASSERT(ctest_get_call_state() == 0); + + strcpy(name, "myfoo/bar"); + rc = conf_set_value(name, "tmp"); + TEST_ASSERT(rc == OS_ENOENT); + TEST_ASSERT(test_set_called == 1); + ctest_clear_call_state(); + + strcpy(name, "myfoo/bar"); + str = conf_get_value(name, tmp, sizeof(tmp)); + TEST_ASSERT(str == NULL); + TEST_ASSERT(test_get_called == 1); + ctest_clear_call_state(); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_insert.c ---------------------------------------------------------------------- diff --git a/sys/config/test-nffs/src/testcases/config_test_insert.c b/sys/config/test-nffs/src/testcases/config_test_insert.c new file mode 100644 index 0000000..125cfb6 --- /dev/null +++ b/sys/config/test-nffs/src/testcases/config_test_insert.c @@ -0,0 +1,27 @@ +/** + * 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_insert) +{ + int rc; + + rc = conf_register(&config_test_handler); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_insert2.c ---------------------------------------------------------------------- diff --git a/sys/config/test-nffs/src/testcases/config_test_insert2.c b/sys/config/test-nffs/src/testcases/config_test_insert2.c new file mode 100644 index 0000000..cf61f98 --- /dev/null +++ b/sys/config/test-nffs/src/testcases/config_test_insert2.c @@ -0,0 +1,27 @@ +/** + * 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_insert2) +{ + int rc; + + rc = conf_register(&c2_test_handler); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_insert3.c ---------------------------------------------------------------------- diff --git a/sys/config/test-nffs/src/testcases/config_test_insert3.c b/sys/config/test-nffs/src/testcases/config_test_insert3.c new file mode 100644 index 0000000..2d321cb --- /dev/null +++ b/sys/config/test-nffs/src/testcases/config_test_insert3.c @@ -0,0 +1,27 @@ +/** + * 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_insert3) +{ + int rc; + + rc = conf_register(&c3_test_handler); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_multiple_in_file.c ---------------------------------------------------------------------- diff --git a/sys/config/test-nffs/src/testcases/config_test_multiple_in_file.c b/sys/config/test-nffs/src/testcases/config_test_multiple_in_file.c new file mode 100644 index 0000000..eccb2c1 --- /dev/null +++ b/sys/config/test-nffs/src/testcases/config_test_multiple_in_file.c @@ -0,0 +1,52 @@ +/** + * 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_multiple_in_file) +{ + int rc; + struct conf_file cf_mfg; + const char cf_mfg_test1[] = + "myfoo/mybar=1\n" + "myfoo/mybar=14"; + const char cf_mfg_test2[] = + "myfoo/mybar=1\n" + "myfoo/mybar=15\n" + "\n"; + + config_wipe_srcs(); + + cf_mfg.cf_name = "/config/mfg"; + rc = conf_file_src(&cf_mfg); + TEST_ASSERT(rc == 0); + + rc = fsutil_write_file("/config/mfg", cf_mfg_test1, sizeof(cf_mfg_test1)); + TEST_ASSERT(rc == 0); + + conf_load(); + TEST_ASSERT(test_set_called); + TEST_ASSERT(val8 == 14); + + rc = fsutil_write_file("/config/mfg", cf_mfg_test2, sizeof(cf_mfg_test2)); + TEST_ASSERT(rc == 0); + + conf_load(); + TEST_ASSERT(test_set_called); + TEST_ASSERT(val8 == 15); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_save_in_file.c ---------------------------------------------------------------------- diff --git a/sys/config/test-nffs/src/testcases/config_test_save_in_file.c b/sys/config/test-nffs/src/testcases/config_test_save_in_file.c new file mode 100644 index 0000000..c6ad07f --- /dev/null +++ b/sys/config/test-nffs/src/testcases/config_test_save_in_file.c @@ -0,0 +1,50 @@ +/** + * 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_save_in_file) +{ + int rc; + struct conf_file cf; + + config_wipe_srcs(); + + rc = fs_mkdir("/config"); + TEST_ASSERT(rc == 0 || rc == FS_EEXIST); + + cf.cf_name = "/config/blah"; + rc = conf_file_src(&cf); + TEST_ASSERT(rc == 0); + rc = conf_file_dst(&cf); + TEST_ASSERT(rc == 0); + + val8 = 8; + rc = conf_save(); + TEST_ASSERT(rc == 0); + + rc = conf_test_file_strstr(cf.cf_name, "myfoo/mybar=8\n"); + TEST_ASSERT(rc == 0); + + val8 = 43; + rc = conf_save(); + TEST_ASSERT(rc == 0); + + rc = conf_test_file_strstr(cf.cf_name, "myfoo/mybar=43\n"); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_save_one_file.c ---------------------------------------------------------------------- diff --git a/sys/config/test-nffs/src/testcases/config_test_save_one_file.c b/sys/config/test-nffs/src/testcases/config_test_save_one_file.c new file mode 100644 index 0000000..feb2376 --- /dev/null +++ b/sys/config/test-nffs/src/testcases/config_test_save_one_file.c @@ -0,0 +1,53 @@ +/** + * 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_save_one_file) +{ + int rc; + struct conf_file cf; + + config_wipe_srcs(); + rc = fs_mkdir("/config"); + TEST_ASSERT(rc == 0 || rc == FS_EEXIST); + + cf.cf_name = "/config/blah"; + rc = conf_file_src(&cf); + TEST_ASSERT(rc == 0); + rc = conf_file_dst(&cf); + TEST_ASSERT(rc == 0); + + val8 = 33; + rc = conf_save(); + TEST_ASSERT(rc == 0); + + rc = conf_save_one("myfoo/mybar", "42"); + TEST_ASSERT(rc == 0); + + rc = conf_load(); + TEST_ASSERT(rc == 0); + TEST_ASSERT(val8 == 42); + + rc = conf_save_one("myfoo/mybar", "44"); + TEST_ASSERT(rc == 0); + + rc = conf_load(); + TEST_ASSERT(rc == 0); + TEST_ASSERT(val8 == 44); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_small_file.c ---------------------------------------------------------------------- diff --git a/sys/config/test-nffs/src/testcases/config_test_small_file.c b/sys/config/test-nffs/src/testcases/config_test_small_file.c new file mode 100644 index 0000000..5b3acc7 --- /dev/null +++ b/sys/config/test-nffs/src/testcases/config_test_small_file.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_nffs.h" + +TEST_CASE(config_test_small_file) +{ + int rc; + struct conf_file cf_mfg; + struct conf_file cf_running; + const char cf_mfg_test[] = "myfoo/mybar=1"; + const char cf_running_test[] = " myfoo/mybar = 8 "; + + config_wipe_srcs(); + + cf_mfg.cf_name = "/config/mfg"; + cf_running.cf_name = "/config/running"; + + rc = conf_file_src(&cf_mfg); + TEST_ASSERT(rc == 0); + rc = conf_file_src(&cf_running); + + rc = fsutil_write_file("/config/mfg", cf_mfg_test, sizeof(cf_mfg_test)); + TEST_ASSERT(rc == 0); + + conf_load(); + TEST_ASSERT(test_set_called); + TEST_ASSERT(val8 == 1); + + ctest_clear_call_state(); + + rc = fsutil_write_file("/config/running", cf_running_test, + sizeof(cf_running_test)); + TEST_ASSERT(rc == 0); + + conf_load(); + TEST_ASSERT(test_set_called); + TEST_ASSERT(val8 == 8); + + ctest_clear_call_state(); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/syscfg.yml ---------------------------------------------------------------------- diff --git a/sys/config/test-nffs/syscfg.yml b/sys/config/test-nffs/syscfg.yml new file mode 100644 index 0000000..19ea6cb --- /dev/null +++ b/sys/config/test-nffs/syscfg.yml @@ -0,0 +1,5 @@ +# Package: sys/config/test-nffs + +syscfg.vals: + CONFIG_NFFS: 1 + CONFIG_FCB_FLASH_AREA: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test/pkg.yml ---------------------------------------------------------------------- diff --git a/sys/config/test/pkg.yml b/sys/config/test/pkg.yml deleted file mode 100644 index 44efb51..0000000 --- a/sys/config/test/pkg.yml +++ /dev/null @@ -1,32 +0,0 @@ -# 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. -# -pkg.name: sys/config/test -pkg.type: unittest -pkg.description: "Config unit tests." -pkg.author: "Apache Mynewt <d...@mynewt.incubator.apache.org>" -pkg.homepage: "http://mynewt.apache.org/" -pkg.keywords: - -pkg.deps: - - test/testutil - - sys/config - -pkg.deps.SELFTEST: - - fs/nffs - - fs/fcb - - sys/console/stub http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test/src/conf_test.c ---------------------------------------------------------------------- diff --git a/sys/config/test/src/conf_test.c b/sys/config/test/src/conf_test.c deleted file mode 100644 index 3c432c4..0000000 --- a/sys/config/test/src/conf_test.c +++ /dev/null @@ -1,953 +0,0 @@ -/** - * 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 <stdio.h> -#include <string.h> - -#include <os/os.h> -#include <testutil/testutil.h> -#include <nffs/nffs.h> -#include <fs/fs.h> -#include <fs/fsutil.h> -#include <fcb/fcb.h> -#include "config/config.h" -#include "config/config_file.h" -#include "config/config_fcb.h" -#include "config_test.h" -#include "config_priv.h" - -static uint8_t val8; -int c2_var_count = 1; -static char val_string[64][CONF_MAX_VAL_LEN]; - -static uint32_t val32; - -static int test_get_called; -static int test_set_called; -static int test_commit_called; -static int test_export_block; - -static char *ctest_handle_get(int argc, char **argv, char *val, - int val_len_max); -static int ctest_handle_set(int argc, char **argv, char *val); -static int ctest_handle_commit(void); -static int ctest_handle_export(void (*cb)(char *name, char *value), - enum conf_export_tgt tgt); -static char *c2_handle_get(int argc, char **argv, char *val, - int val_len_max); -static int c2_handle_set(int argc, char **argv, char *val); -static int c2_handle_export(void (*cb)(char *name, char *value), - enum conf_export_tgt tgt); -static char *c3_handle_get(int argc, char **argv, char *val, - int val_len_max); -static int c3_handle_set(int argc, char **argv, char *val); -static int c3_handle_export(void (*cb)(char *name, char *value), - enum conf_export_tgt tgt); - -struct conf_handler config_test_handler = { - .ch_name = "myfoo", - .ch_get = ctest_handle_get, - .ch_set = ctest_handle_set, - .ch_commit = ctest_handle_commit, - .ch_export = ctest_handle_export -}; - -static char * -ctest_handle_get(int argc, char **argv, char *val, int val_len_max) -{ - test_get_called = 1; - if (argc == 1 && !strcmp(argv[0], "mybar")) { - return conf_str_from_value(CONF_INT8, &val8, val, val_len_max); - } - return NULL; -} - -static int -ctest_handle_set(int argc, char **argv, char *val) -{ - uint8_t newval; - int rc; - - test_set_called = 1; - if (argc == 1 && !strcmp(argv[0], "mybar")) { - rc = CONF_VALUE_SET(val, CONF_INT8, newval); - TEST_ASSERT(rc == 0); - val8 = newval; - return 0; - } - return OS_ENOENT; -} - -static int -ctest_handle_commit(void) -{ - test_commit_called = 1; - return 0; -} - -static int -ctest_handle_export(void (*cb)(char *name, char *value), - enum conf_export_tgt tgt) -{ - char value[32]; - - if (test_export_block) { - return 0; - } - conf_str_from_value(CONF_INT8, &val8, value, sizeof(value)); - cb("myfoo/mybar", value); - - return 0; -} - -struct conf_handler c2_test_handler = { - .ch_name = "2nd", - .ch_get = c2_handle_get, - .ch_set = c2_handle_set, - .ch_commit = NULL, - .ch_export = c2_handle_export -}; - -char * -c2_var_find(char *name) -{ - int idx = 0; - int len; - char *eptr; - - len = strlen(name); - TEST_ASSERT(!strncmp(name, "string", 6)); - TEST_ASSERT(len > 6); - - idx = strtoul(&name[6], &eptr, 10); - TEST_ASSERT(*eptr == '\0'); - TEST_ASSERT(idx < c2_var_count); - return val_string[idx]; -} - -static char * -c2_handle_get(int argc, char **argv, char *val, int val_len_max) -{ - int len; - char *valptr; - - if (argc == 1) { - valptr = c2_var_find(argv[0]); - if (!valptr) { - return NULL; - } - len = strlen(val_string[0]); - if (len > val_len_max) { - len = val_len_max; - } - strncpy(val, valptr, len); - } - return NULL; -} - -static int -c2_handle_set(int argc, char **argv, char *val) -{ - char *valptr; - - if (argc == 1) { - valptr = c2_var_find(argv[0]); - if (!valptr) { - return OS_ENOENT; - } - if (val) { - strncpy(valptr, val, sizeof(val_string[0])); - } else { - memset(valptr, 0, sizeof(val_string[0])); - } - return 0; - } - return OS_ENOENT; -} - -static int -c2_handle_export(void (*cb)(char *name, char *value), - enum conf_export_tgt tgt) -{ - int i; - char name[32]; - - for (i = 0; i < c2_var_count; i++) { - snprintf(name, sizeof(name), "2nd/string%d", i); - cb(name, val_string[i]); - } - return 0; -} - -struct conf_handler c3_test_handler = { - .ch_name = "3", - .ch_get = c3_handle_get, - .ch_set = c3_handle_set, - .ch_commit = NULL, - .ch_export = c3_handle_export -}; - -static char * -c3_handle_get(int argc, char **argv, char *val, int val_len_max) -{ - if (argc == 1 && !strcmp(argv[0], "v")) { - return conf_str_from_value(CONF_INT32, &val32, val, val_len_max); - } - return NULL; -} - -static int -c3_handle_set(int argc, char **argv, char *val) -{ - uint32_t newval; - int rc; - - if (argc == 1 && !strcmp(argv[0], "v")) { - rc = CONF_VALUE_SET(val, CONF_INT32, newval); - TEST_ASSERT(rc == 0); - val32 = newval; - return 0; - } - return OS_ENOENT; -} - -static int -c3_handle_export(void (*cb)(char *name, char *value), - enum conf_export_tgt tgt) -{ - char value[32]; - - conf_str_from_value(CONF_INT32, &val32, value, sizeof(value)); - cb("3/v", value); - - return 0; -} - -static void -ctest_clear_call_state(void) -{ - test_get_called = 0; - test_set_called = 0; - test_commit_called = 0; -} - -static int -ctest_get_call_state(void) -{ - return test_get_called + test_set_called + test_commit_called; -} - -TEST_CASE(config_empty_lookups) -{ - int rc; - char name[80]; - char tmp[64], *str; - - strcpy(name, "foo/bar"); - rc = conf_set_value(name, "tmp"); - TEST_ASSERT(rc != 0); - - strcpy(name, "foo/bar"); - str = conf_get_value(name, tmp, sizeof(tmp)); - TEST_ASSERT(str == NULL); -} - -TEST_CASE(config_test_insert) -{ - int rc; - - rc = conf_register(&config_test_handler); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(config_test_insert2) -{ - int rc; - - rc = conf_register(&c2_test_handler); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(config_test_getset_unknown) -{ - char name[80]; - char tmp[64], *str; - int rc; - - strcpy(name, "foo/bar"); - rc = conf_set_value(name, "tmp"); - TEST_ASSERT(rc != 0); - TEST_ASSERT(ctest_get_call_state() == 0); - - strcpy(name, "foo/bar"); - str = conf_get_value(name, tmp, sizeof(tmp)); - TEST_ASSERT(str == NULL); - TEST_ASSERT(ctest_get_call_state() == 0); - - strcpy(name, "myfoo/bar"); - rc = conf_set_value(name, "tmp"); - TEST_ASSERT(rc == OS_ENOENT); - TEST_ASSERT(test_set_called == 1); - ctest_clear_call_state(); - - strcpy(name, "myfoo/bar"); - str = conf_get_value(name, tmp, sizeof(tmp)); - TEST_ASSERT(str == NULL); - TEST_ASSERT(test_get_called == 1); - ctest_clear_call_state(); -} - -TEST_CASE(config_test_getset_int) -{ - char name[80]; - char tmp[64], *str; - int rc; - - strcpy(name, "myfoo/mybar"); - rc = conf_set_value(name, "42"); - TEST_ASSERT(rc == 0); - TEST_ASSERT(test_set_called == 1); - TEST_ASSERT(val8 == 42); - ctest_clear_call_state(); - - strcpy(name, "myfoo/mybar"); - str = conf_get_value(name, tmp, sizeof(tmp)); - TEST_ASSERT(str); - TEST_ASSERT(test_get_called == 1); - TEST_ASSERT(!strcmp("42", tmp)); - ctest_clear_call_state(); -} - -TEST_CASE(config_test_getset_bytes) -{ - char orig[32]; - char bytes[32]; - char str[48]; - char *ret; - int j, i; - int tmp; - int rc; - - for (j = 1; j < sizeof(orig); j++) { - for (i = 0; i < j; i++) { - orig[i] = i + j + 1; - } - ret = conf_str_from_bytes(orig, j, str, sizeof(str)); - TEST_ASSERT(ret); - tmp = strlen(str); - TEST_ASSERT(tmp < sizeof(str)); - - memset(bytes, 0, sizeof(bytes)); - tmp = sizeof(bytes); - - tmp = sizeof(bytes); - rc = conf_bytes_from_str(str, bytes, &tmp); - TEST_ASSERT(rc == 0); - TEST_ASSERT(tmp == j); - TEST_ASSERT(!memcmp(orig, bytes, j)); - } -} - -TEST_CASE(config_test_commit) -{ - char name[80]; - int rc; - - strcpy(name, "bar"); - rc = conf_commit(name); - TEST_ASSERT(rc); - TEST_ASSERT(ctest_get_call_state() == 0); - - rc = conf_commit(NULL); - TEST_ASSERT(rc == 0); - TEST_ASSERT(test_commit_called == 1); - ctest_clear_call_state(); - - strcpy(name, "myfoo"); - rc = conf_commit(name); - TEST_ASSERT(rc == 0); - TEST_ASSERT(test_commit_called == 1); - ctest_clear_call_state(); -} - -static const struct nffs_area_desc config_nffs[] = { - { 0x00000000, 16 * 1024 }, - { 0x00004000, 16 * 1024 }, - { 0x00008000, 16 * 1024 }, - { 0x0000c000, 16 * 1024 }, - { 0, 0 } -}; - -TEST_CASE(config_setup_nffs) -{ - int rc; - - rc = nffs_init(); - TEST_ASSERT_FATAL(rc == 0); - rc = nffs_format(config_nffs); - TEST_ASSERT_FATAL(rc == 0); -} - -static void config_wipe_srcs(void) -{ - SLIST_INIT(&conf_load_srcs); - conf_save_dst = NULL; -} - -static void config_wipe_fcb(struct flash_area *fa, int cnt) -{ - int i; - - for (i = 0; i < cnt; i++) { - flash_area_erase(&fa[i], 0, fa[i].fa_size); - } -} - -TEST_CASE(config_test_empty_file) -{ - int rc; - struct conf_file cf_mfg; - struct conf_file cf_running; - const char cf_mfg_test[] = ""; - const char cf_running_test[] = "\n\n"; - - config_wipe_srcs(); - - cf_mfg.cf_name = "/config/mfg"; - cf_running.cf_name = "/config/running"; - - rc = conf_file_src(&cf_mfg); - TEST_ASSERT(rc == 0); - rc = conf_file_src(&cf_running); - - /* - * No files - */ - conf_load(); - - rc = fs_mkdir("/config"); - TEST_ASSERT(rc == 0); - - rc = fsutil_write_file("/config/mfg", cf_mfg_test, sizeof(cf_mfg_test)); - TEST_ASSERT(rc == 0); - - rc = fsutil_write_file("/config/running", cf_running_test, - sizeof(cf_running_test)); - TEST_ASSERT(rc == 0); - - conf_load(); - config_wipe_srcs(); - ctest_clear_call_state(); -} - -TEST_CASE(config_test_small_file) -{ - int rc; - struct conf_file cf_mfg; - struct conf_file cf_running; - const char cf_mfg_test[] = "myfoo/mybar=1"; - const char cf_running_test[] = " myfoo/mybar = 8 "; - - config_wipe_srcs(); - - cf_mfg.cf_name = "/config/mfg"; - cf_running.cf_name = "/config/running"; - - rc = conf_file_src(&cf_mfg); - TEST_ASSERT(rc == 0); - rc = conf_file_src(&cf_running); - - rc = fsutil_write_file("/config/mfg", cf_mfg_test, sizeof(cf_mfg_test)); - TEST_ASSERT(rc == 0); - - conf_load(); - TEST_ASSERT(test_set_called); - TEST_ASSERT(val8 == 1); - - ctest_clear_call_state(); - - rc = fsutil_write_file("/config/running", cf_running_test, - sizeof(cf_running_test)); - TEST_ASSERT(rc == 0); - - conf_load(); - TEST_ASSERT(test_set_called); - TEST_ASSERT(val8 == 8); - - ctest_clear_call_state(); -} - -TEST_CASE(config_test_multiple_in_file) -{ - int rc; - struct conf_file cf_mfg; - const char cf_mfg_test1[] = - "myfoo/mybar=1\n" - "myfoo/mybar=14"; - const char cf_mfg_test2[] = - "myfoo/mybar=1\n" - "myfoo/mybar=15\n" - "\n"; - - config_wipe_srcs(); - - cf_mfg.cf_name = "/config/mfg"; - rc = conf_file_src(&cf_mfg); - TEST_ASSERT(rc == 0); - - rc = fsutil_write_file("/config/mfg", cf_mfg_test1, sizeof(cf_mfg_test1)); - TEST_ASSERT(rc == 0); - - conf_load(); - TEST_ASSERT(test_set_called); - TEST_ASSERT(val8 == 14); - - rc = fsutil_write_file("/config/mfg", cf_mfg_test2, sizeof(cf_mfg_test2)); - TEST_ASSERT(rc == 0); - - conf_load(); - TEST_ASSERT(test_set_called); - TEST_ASSERT(val8 == 15); -} - -int -conf_test_file_strstr(const char *fname, char *string) -{ - int rc; - uint32_t len; - uint32_t rlen; - char *buf; - struct fs_file *file; - - rc = fs_open(fname, FS_ACCESS_READ, &file); - if (rc) { - return rc; - } - rc = fs_filelen(file, &len); - fs_close(file); - if (rc) { - return rc; - } - - buf = (char *)malloc(len + 1); - TEST_ASSERT(buf); - - rc = fsutil_read_file(fname, 0, len, buf, &rlen); - TEST_ASSERT(rc == 0); - TEST_ASSERT(rlen == len); - buf[rlen] = '\0'; - - if (strstr(buf, string)) { - return 0; - } else { - return -1; - } -} - -TEST_CASE(config_test_save_in_file) -{ - int rc; - struct conf_file cf; - - config_wipe_srcs(); - - rc = fs_mkdir("/config"); - TEST_ASSERT(rc == 0 || rc == FS_EEXIST); - - cf.cf_name = "/config/blah"; - rc = conf_file_src(&cf); - TEST_ASSERT(rc == 0); - rc = conf_file_dst(&cf); - TEST_ASSERT(rc == 0); - - val8 = 8; - rc = conf_save(); - TEST_ASSERT(rc == 0); - - rc = conf_test_file_strstr(cf.cf_name, "myfoo/mybar=8\n"); - TEST_ASSERT(rc == 0); - - val8 = 43; - rc = conf_save(); - TEST_ASSERT(rc == 0); - - rc = conf_test_file_strstr(cf.cf_name, "myfoo/mybar=43\n"); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(config_test_save_one_file) -{ - int rc; - struct conf_file cf; - - config_wipe_srcs(); - rc = fs_mkdir("/config"); - TEST_ASSERT(rc == 0 || rc == FS_EEXIST); - - cf.cf_name = "/config/blah"; - rc = conf_file_src(&cf); - TEST_ASSERT(rc == 0); - rc = conf_file_dst(&cf); - TEST_ASSERT(rc == 0); - - val8 = 33; - rc = conf_save(); - TEST_ASSERT(rc == 0); - - rc = conf_save_one("myfoo/mybar", "42"); - TEST_ASSERT(rc == 0); - - rc = conf_load(); - TEST_ASSERT(rc == 0); - TEST_ASSERT(val8 == 42); - - rc = conf_save_one("myfoo/mybar", "44"); - TEST_ASSERT(rc == 0); - - rc = conf_load(); - TEST_ASSERT(rc == 0); - TEST_ASSERT(val8 == 44); -} - -struct flash_area fcb_areas[] = { - [0] = { - .fa_off = 0x00000000, - .fa_size = 16 * 1024 - }, - [1] = { - .fa_off = 0x00004000, - .fa_size = 16 * 1024 - }, - [2] = { - .fa_off = 0x00008000, - .fa_size = 16 * 1024 - }, - [3] = { - .fa_off = 0x0000c000, - .fa_size = 16 * 1024 - } -}; - -TEST_CASE(config_test_empty_fcb) -{ - int rc; - struct conf_fcb cf; - - config_wipe_srcs(); - config_wipe_fcb(fcb_areas, sizeof(fcb_areas) / sizeof(fcb_areas[0])); - - cf.cf_fcb.f_sectors = fcb_areas; - cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]); - - rc = conf_fcb_src(&cf); - TEST_ASSERT(rc == 0); - - /* - * No values - */ - conf_load(); - - config_wipe_srcs(); - ctest_clear_call_state(); -} - -TEST_CASE(config_test_save_1_fcb) -{ - int rc; - struct conf_fcb cf; - - config_wipe_srcs(); - - cf.cf_fcb.f_sectors = fcb_areas; - cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]); - - rc = conf_fcb_src(&cf); - TEST_ASSERT(rc == 0); - - rc = conf_fcb_dst(&cf); - TEST_ASSERT(rc == 0); - - val8 = 33; - rc = conf_save(); - TEST_ASSERT(rc == 0); - - val8 = 0; - - rc = conf_load(); - TEST_ASSERT(rc == 0); - TEST_ASSERT(val8 == 33); -} - -static void config_test_fill_area(char test_value[64][CONF_MAX_VAL_LEN], - int iteration) -{ - int i, j; - - for (j = 0; j < 64; j++) { - for (i = 0; i < CONF_MAX_VAL_LEN; i++) { - test_value[j][i] = ((j * 2) + i + iteration) % 10 + '0'; - } - test_value[j][sizeof(test_value[j]) - 1] = '\0'; - } -} - -TEST_CASE(config_test_save_2_fcb) -{ - int rc; - struct conf_fcb cf; - char test_value[64][CONF_MAX_VAL_LEN]; - int i; - - config_wipe_srcs(); - - cf.cf_fcb.f_sectors = fcb_areas; - cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]); - - rc = conf_fcb_src(&cf); - TEST_ASSERT(rc == 0); - - rc = conf_fcb_dst(&cf); - TEST_ASSERT(rc == 0); - - config_test_fill_area(test_value, 0); - memcpy(val_string, test_value, sizeof(val_string)); - - val8 = 42; - rc = conf_save(); - TEST_ASSERT(rc == 0); - - val8 = 0; - memset(val_string[0], 0, sizeof(val_string[0])); - rc = conf_load(); - TEST_ASSERT(rc == 0); - TEST_ASSERT(val8 == 42); - TEST_ASSERT(!strcmp(val_string[0], test_value[0])); - test_export_block = 1; - - /* - * Now add the number of settings to max. Keep adjusting the test_data, - * check that rollover happens when it's supposed to. - */ - c2_var_count = 64; - - for (i = 0; i < 32; i++) { - config_test_fill_area(test_value, i); - memcpy(val_string, test_value, sizeof(val_string)); - - rc = conf_save(); - TEST_ASSERT(rc == 0); - - memset(val_string, 0, sizeof(val_string)); - - val8 = 0; - rc = conf_load(); - TEST_ASSERT(rc == 0); - TEST_ASSERT(!memcmp(val_string, test_value, sizeof(val_string))); - TEST_ASSERT(val8 == 42); - } - c2_var_count = 0; -} - -TEST_CASE(config_test_insert3) -{ - int rc; - - rc = conf_register(&c3_test_handler); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(config_test_save_3_fcb) -{ - int rc; - struct conf_fcb cf; - int i; - - config_wipe_srcs(); - config_wipe_fcb(fcb_areas, sizeof(fcb_areas) / sizeof(fcb_areas[0])); - - cf.cf_fcb.f_sectors = fcb_areas; - cf.cf_fcb.f_sector_cnt = 4; - - rc = conf_fcb_src(&cf); - TEST_ASSERT(rc == 0); - - rc = conf_fcb_dst(&cf); - TEST_ASSERT(rc == 0); - - for (i = 0; i < 4096; i++) { - val32 = i; - - rc = conf_save(); - TEST_ASSERT(rc == 0); - - val32 = 0; - - rc = conf_load(); - TEST_ASSERT(rc == 0); - TEST_ASSERT(val32 == i); - } -} - -TEST_CASE(config_test_compress_reset) -{ - int rc; - struct conf_fcb cf; - struct flash_area *fa; - char test_value[64][CONF_MAX_VAL_LEN]; - int elems[4]; - int i; - - config_wipe_srcs(); - config_wipe_fcb(fcb_areas, sizeof(fcb_areas) / sizeof(fcb_areas[0])); - - cf.cf_fcb.f_sectors = fcb_areas; - cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]); - - rc = conf_fcb_src(&cf); - TEST_ASSERT(rc == 0); - - rc = conf_fcb_dst(&cf); - TEST_ASSERT(rc == 0); - - c2_var_count = 1; - memset(elems, 0, sizeof(elems)); - - for (i = 0; ; i++) { - config_test_fill_area(test_value, i); - memcpy(val_string, test_value, sizeof(val_string)); - - rc = conf_save(); - TEST_ASSERT(rc == 0); - - if (cf.cf_fcb.f_active.fe_area == &fcb_areas[2]) { - /* - * Started using space just before scratch. - */ - break; - } - memset(val_string, 0, sizeof(val_string)); - - rc = conf_load(); - TEST_ASSERT(rc == 0); - TEST_ASSERT(!memcmp(val_string, test_value, CONF_MAX_VAL_LEN)); - } - - fa = cf.cf_fcb.f_active.fe_area; - rc = fcb_append_to_scratch(&cf.cf_fcb); - TEST_ASSERT(rc == 0); - TEST_ASSERT(fcb_free_sector_cnt(&cf.cf_fcb) == 0); - TEST_ASSERT(fa != cf.cf_fcb.f_active.fe_area); - - config_wipe_srcs(); - - memset(&cf, 0, sizeof(cf)); - - cf.cf_fcb.f_sectors = fcb_areas; - cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]); - - rc = conf_fcb_src(&cf); - TEST_ASSERT(rc == 0); - - rc = conf_fcb_dst(&cf); - TEST_ASSERT(rc == 0); - - TEST_ASSERT(fcb_free_sector_cnt(&cf.cf_fcb) == 1); - TEST_ASSERT(fa == cf.cf_fcb.f_active.fe_area); - - c2_var_count = 0; -} - -TEST_CASE(config_test_save_one_fcb) -{ - int rc; - struct conf_fcb cf; - - config_wipe_srcs(); - config_wipe_fcb(fcb_areas, sizeof(fcb_areas) / sizeof(fcb_areas[0])); - - cf.cf_fcb.f_sectors = fcb_areas; - cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]); - - rc = conf_fcb_src(&cf); - TEST_ASSERT(rc == 0); - - rc = conf_fcb_dst(&cf); - TEST_ASSERT(rc == 0); - - val8 = 33; - rc = conf_save(); - TEST_ASSERT(rc == 0); - - rc = conf_save_one("myfoo/mybar", "42"); - TEST_ASSERT(rc == 0); - - rc = conf_load(); - TEST_ASSERT(rc == 0); - TEST_ASSERT(val8 == 42); - - rc = conf_save_one("myfoo/mybar", "44"); - TEST_ASSERT(rc == 0); - - rc = conf_load(); - TEST_ASSERT(rc == 0); - TEST_ASSERT(val8 == 44); -} - -TEST_SUITE(config_test_all) -{ - /* - * Config tests. - */ - config_empty_lookups(); - config_test_insert(); - config_test_getset_unknown(); - config_test_getset_int(); - config_test_getset_bytes(); - - config_test_commit(); - - /* - * NFFS as backing storage. - */ - config_setup_nffs(); - config_test_empty_file(); - config_test_small_file(); - config_test_multiple_in_file(); - - config_test_save_in_file(); - - config_test_save_one_file(); - - /* - * FCB as backing storage. - */ - config_test_empty_fcb(); - config_test_save_1_fcb(); - - config_test_insert2(); - - config_test_save_2_fcb(); - - config_test_insert3(); - config_test_save_3_fcb(); - - config_test_compress_reset(); - - config_test_save_one_fcb(); -} - http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test/src/conf_test.h ---------------------------------------------------------------------- diff --git a/sys/config/test/src/conf_test.h b/sys/config/test/src/conf_test.h deleted file mode 100644 index e88a1f6..0000000 --- a/sys/config/test/src/conf_test.h +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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. - */ - -#ifndef _CONF_TEST_H_ -#define _CONF_TEST_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -void config_test_all(void); - -#ifdef __cplusplus -} -#endif - -#endif /* _CONF_TEST_H_ */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test/src/conf_test_suite.c ---------------------------------------------------------------------- diff --git a/sys/config/test/src/conf_test_suite.c b/sys/config/test/src/conf_test_suite.c deleted file mode 100644 index 65360c3..0000000 --- a/sys/config/test/src/conf_test_suite.c +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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 "syscfg/syscfg.h" -#include "os/os.h" -#include "testutil/testutil.h" -#include "config/config.h" -#include "config_test.h" - -#if MYNEWT_VAL(SELFTEST) - -int -main(int argc, char **argv) -{ - tu_config.tc_print_results = 1; - tu_init(); - - conf_init(); - config_test_all(); - - return tu_any_failed; -} - -#endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test/src/config_test.h ---------------------------------------------------------------------- diff --git a/sys/config/test/src/config_test.h b/sys/config/test/src/config_test.h deleted file mode 100644 index fb515f8..0000000 --- a/sys/config/test/src/config_test.h +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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. - */ -#ifndef _CONFIG_TEST_H_ -#define _CONFIG_TEST_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -int config_test_all(); - -#ifdef __cplusplus -} -#endif - -#endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test/syscfg.yml ---------------------------------------------------------------------- diff --git a/sys/config/test/syscfg.yml b/sys/config/test/syscfg.yml deleted file mode 100644 index f6bcf48..0000000 --- a/sys/config/test/syscfg.yml +++ /dev/null @@ -1,5 +0,0 @@ -# Package: sys/config/test - -syscfg.vals: - CONFIG_NFFS: 1 - CONFIG_FCB: 1 http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/flash_map/test/src/flash_map_test.c ---------------------------------------------------------------------- diff --git a/sys/flash_map/test/src/flash_map_test.c b/sys/flash_map/test/src/flash_map_test.c index d1a5aa2..3409ec8 100644 --- a/sys/flash_map/test/src/flash_map_test.c +++ b/sys/flash_map/test/src/flash_map_test.c @@ -29,126 +29,8 @@ #include "hal/hal_flash.h" #include "hal/hal_flash_int.h" -/* - * Test flash_area_to_sectors() - */ -TEST_CASE(flash_map_test_case_1) -{ - const struct flash_area *fa; - int areas_checked = 0; - int i, j, rc; - const struct hal_flash *hf; - struct flash_area my_secs[32]; - int my_sec_cnt; - uint32_t end; - - sysinit(); - - for (i = 0; i < 8; i++) { - rc = flash_area_open(i, &fa); - if (rc) { - continue; - } - - hf = bsp_flash_dev(fa->fa_device_id); - TEST_ASSERT_FATAL(hf != NULL, "bsp_flash_dev"); - - rc = flash_area_to_sectors(i, &my_sec_cnt, my_secs); - TEST_ASSERT_FATAL(rc == 0, "flash_area_to_sectors failed"); - - end = fa->fa_off; - for (j = 0; j < my_sec_cnt; j++) { - TEST_ASSERT_FATAL(end == my_secs[j].fa_off, "Non contiguous area"); - TEST_ASSERT_FATAL(my_secs[j].fa_device_id == fa->fa_device_id, - "Sectors not in same flash?"); - end = my_secs[j].fa_off + my_secs[j].fa_size; - } - if (my_sec_cnt) { - areas_checked++; - TEST_ASSERT_FATAL(my_secs[my_sec_cnt - 1].fa_off + - my_secs[my_sec_cnt - 1].fa_size == fa->fa_off + fa->fa_size, - "Last sector not in the end"); - } - } - TEST_ASSERT_FATAL(areas_checked != 0, "No flash map areas to check!"); -} - -/* - * Test flash_erase - */ -TEST_CASE(flash_map_test_case_2) -{ - const struct flash_area *fa; - struct flash_area secs[32]; - int sec_cnt; - int i; - int rc; - uint32_t off; - uint8_t wd[256]; - uint8_t rd[256]; - - sysinit(); - - rc = flash_area_open(FLASH_AREA_IMAGE_0, &fa); - TEST_ASSERT_FATAL(rc == 0, "flash_area_open() fail"); - - rc = flash_area_to_sectors(FLASH_AREA_IMAGE_0, &sec_cnt, secs); - TEST_ASSERT_FATAL(rc == 0, "flash_area_to_sectors failed"); - - /* - * First erase the area so it's ready for use. - */ - for (i = 0; i < sec_cnt; i++) { - rc = hal_flash_erase_sector(secs[i].fa_device_id, secs[i].fa_off); - TEST_ASSERT_FATAL(rc == 0, "hal_flash_erase_sector() failed"); - } - TEST_ASSERT_FATAL(rc == 0, "read data != write data"); - - memset(wd, 0xa5, sizeof(wd)); - - /* write stuff to beginning of every sector */ - off = 0; - for (i = 0; i < sec_cnt; i++) { - rc = flash_area_write(fa, off, wd, sizeof(wd)); - TEST_ASSERT_FATAL(rc == 0, "flash_area_write() fail"); - - /* read it back via hal_flash_Read() */ - rc = hal_flash_read(fa->fa_device_id, fa->fa_off + off, rd, sizeof(rd)); - TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail"); - - rc = memcmp(wd, rd, sizeof(wd)); - TEST_ASSERT_FATAL(rc == 0, "read data != write data"); - - /* write stuff to end of area */ - rc = hal_flash_write(fa->fa_device_id, - fa->fa_off + off + secs[i].fa_size - sizeof(wd), wd, sizeof(wd)); - TEST_ASSERT_FATAL(rc == 0, "hal_flash_write() fail"); - - /* and read it back */ - memset(rd, 0, sizeof(rd)); - rc = flash_area_read(fa, off + secs[i].fa_size - sizeof(rd), - rd, sizeof(rd)); - TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail"); - - rc = memcmp(wd, rd, sizeof(rd)); - TEST_ASSERT_FATAL(rc == 0, "read data != write data"); - - off += secs[i].fa_size; - } - /* erase it */ - rc = flash_area_erase(fa, 0, fa->fa_size); - TEST_ASSERT_FATAL(rc == 0, "read data != write data"); - - /* should read back ff all throughout*/ - memset(wd, 0xff, sizeof(wd)); - for (off = 0; off < fa->fa_size; off += sizeof(rd)) { - rc = flash_area_read(fa, off, rd, sizeof(rd)); - TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail"); - - rc = memcmp(wd, rd, sizeof(rd)); - TEST_ASSERT_FATAL(rc == 0, "area not erased"); - } -} +TEST_CASE_DECL(flash_map_test_case_1) +TEST_CASE_DECL(flash_map_test_case_2) TEST_SUITE(flash_map_test_suite) { @@ -157,16 +39,14 @@ TEST_SUITE(flash_map_test_suite) } #if MYNEWT_VAL(SELFTEST) - int main(int argc, char **argv) { - tu_config.tc_print_results = 1; + ts_config.ts_print_results = 1; tu_init(); flash_map_test_suite(); return tu_any_failed; } - #endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/flash_map/test/src/flash_map_test.h ---------------------------------------------------------------------- diff --git a/sys/flash_map/test/src/flash_map_test.h b/sys/flash_map/test/src/flash_map_test.h new file mode 100644 index 0000000..c1d6e8d --- /dev/null +++ b/sys/flash_map/test/src/flash_map_test.h @@ -0,0 +1,44 @@ +/** + * 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. + */ +#ifndef _FLASH_MAP_TEST_H +#define _FLASH_MAP_TEST_H +#include <stdio.h> +#include <string.h> + +#include "sysinit/sysinit.h" +#include "syscfg/syscfg.h" +#include "sysflash/sysflash.h" +#include "os/os.h" +#include "testutil/testutil.h" +#include "flash_map/flash_map.h" +#include "hal/hal_bsp.h" +#include "hal/hal_flash.h" +#include "hal/hal_flash_int.h" + +#ifdef __cplusplus +#extern "C" { +#endif + +/* This space intentionally left blank */ + +#ifdef __cplusplus +} +#endif + +#endif /* _FLASH_MAP_TEST_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/flash_map/test/src/testcases/flash_map_test_case_1.c ---------------------------------------------------------------------- diff --git a/sys/flash_map/test/src/testcases/flash_map_test_case_1.c b/sys/flash_map/test/src/testcases/flash_map_test_case_1.c new file mode 100644 index 0000000..f46ba1e --- /dev/null +++ b/sys/flash_map/test/src/testcases/flash_map_test_case_1.c @@ -0,0 +1,63 @@ +/** + * 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 "flash_map_test.h" + +/* + * Test flash_area_to_sectors() + */ +TEST_CASE(flash_map_test_case_1) +{ + const struct flash_area *fa; + int areas_checked = 0; + int i, j, rc; + const struct hal_flash *hf; + struct flash_area my_secs[32]; + int my_sec_cnt; + uint32_t end; + + sysinit(); + + for (i = 0; i < 8; i++) { + rc = flash_area_open(i, &fa); + if (rc) { + continue; + } + + hf = bsp_flash_dev(fa->fa_device_id); + TEST_ASSERT_FATAL(hf != NULL, "bsp_flash_dev"); + + rc = flash_area_to_sectors(i, &my_sec_cnt, my_secs); + TEST_ASSERT_FATAL(rc == 0, "flash_area_to_sectors failed"); + + end = fa->fa_off; + for (j = 0; j < my_sec_cnt; j++) { + TEST_ASSERT_FATAL(end == my_secs[j].fa_off, "Non contiguous area"); + TEST_ASSERT_FATAL(my_secs[j].fa_device_id == fa->fa_device_id, + "Sectors not in same flash?"); + end = my_secs[j].fa_off + my_secs[j].fa_size; + } + if (my_sec_cnt) { + areas_checked++; + TEST_ASSERT_FATAL(my_secs[my_sec_cnt - 1].fa_off + + my_secs[my_sec_cnt - 1].fa_size == fa->fa_off + fa->fa_size, + "Last sector not in the end"); + } + } + TEST_ASSERT_FATAL(areas_checked != 0, "No flash map areas to check!"); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/flash_map/test/src/testcases/flash_map_test_case_2.c ---------------------------------------------------------------------- diff --git a/sys/flash_map/test/src/testcases/flash_map_test_case_2.c b/sys/flash_map/test/src/testcases/flash_map_test_case_2.c new file mode 100644 index 0000000..559f56d --- /dev/null +++ b/sys/flash_map/test/src/testcases/flash_map_test_case_2.c @@ -0,0 +1,96 @@ +/** + * 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 "flash_map_test.h" + +/* + * Test flash_erase + */ +TEST_CASE(flash_map_test_case_2) +{ + const struct flash_area *fa; + struct flash_area secs[32]; + int sec_cnt; + int i; + int rc; + uint32_t off; + uint8_t wd[256]; + uint8_t rd[256]; + + sysinit(); + + rc = flash_area_open(FLASH_AREA_IMAGE_0, &fa); + TEST_ASSERT_FATAL(rc == 0, "flash_area_open() fail"); + + rc = flash_area_to_sectors(FLASH_AREA_IMAGE_0, &sec_cnt, secs); + TEST_ASSERT_FATAL(rc == 0, "flash_area_to_sectors failed"); + + /* + * First erase the area so it's ready for use. + */ + for (i = 0; i < sec_cnt; i++) { + rc = hal_flash_erase_sector(secs[i].fa_device_id, secs[i].fa_off); + TEST_ASSERT_FATAL(rc == 0, "hal_flash_erase_sector() failed"); + } + TEST_ASSERT_FATAL(rc == 0, "read data != write data"); + + memset(wd, 0xa5, sizeof(wd)); + + /* write stuff to beginning of every sector */ + off = 0; + for (i = 0; i < sec_cnt; i++) { + rc = flash_area_write(fa, off, wd, sizeof(wd)); + TEST_ASSERT_FATAL(rc == 0, "flash_area_write() fail"); + + /* read it back via hal_flash_Read() */ + rc = hal_flash_read(fa->fa_device_id, fa->fa_off + off, rd, sizeof(rd)); + TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail"); + + rc = memcmp(wd, rd, sizeof(wd)); + TEST_ASSERT_FATAL(rc == 0, "read data != write data"); + + /* write stuff to end of area */ + rc = hal_flash_write(fa->fa_device_id, + fa->fa_off + off + secs[i].fa_size - sizeof(wd), wd, sizeof(wd)); + TEST_ASSERT_FATAL(rc == 0, "hal_flash_write() fail"); + + /* and read it back */ + memset(rd, 0, sizeof(rd)); + rc = flash_area_read(fa, off + secs[i].fa_size - sizeof(rd), + rd, sizeof(rd)); + TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail"); + + rc = memcmp(wd, rd, sizeof(rd)); + TEST_ASSERT_FATAL(rc == 0, "read data != write data"); + + off += secs[i].fa_size; + } + /* erase it */ + rc = flash_area_erase(fa, 0, fa->fa_size); + TEST_ASSERT_FATAL(rc == 0, "read data != write data"); + + /* should read back ff all throughout*/ + memset(wd, 0xff, sizeof(wd)); + for (off = 0; off < fa->fa_size; off += sizeof(rd)) { + rc = flash_area_read(fa, off, rd, sizeof(rd)); + TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail"); + + rc = memcmp(wd, rd, sizeof(rd)); + TEST_ASSERT_FATAL(rc == 0, "area not erased"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/log/test/src/log_test.c ---------------------------------------------------------------------- diff --git a/sys/log/test/src/log_test.c b/sys/log/test/src/log_test.c index b0f71ad..ff411e8 100644 --- a/sys/log/test/src/log_test.c +++ b/sys/log/test/src/log_test.c @@ -24,7 +24,7 @@ #include "fcb/fcb.h" #include "log/log.h" -static struct flash_area fcb_areas[] = { +struct flash_area fcb_areas[] = { [0] = { .fa_off = 0x00000000, .fa_size = 16 * 1024 @@ -34,52 +34,18 @@ static struct flash_area fcb_areas[] = { .fa_size = 16 * 1024 } }; -static struct fcb log_fcb; -static struct log my_log; +struct fcb log_fcb; +struct log my_log; -static char *str_logs[] = { +char *str_logs[] = { "testdata", "1testdata2", NULL }; -static int str_idx = 0; -static int str_max_idx = 0; +int str_idx = 0; +int str_max_idx = 0; -TEST_CASE(log_setup_fcb) -{ - int rc; - int i; - - log_fcb.f_sectors = fcb_areas; - log_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]); - log_fcb.f_magic = 0x7EADBADF; - log_fcb.f_version = 0; - - for (i = 0; i < log_fcb.f_sector_cnt; i++) { - rc = flash_area_erase(&fcb_areas[i], 0, fcb_areas[i].fa_size); - TEST_ASSERT(rc == 0); - } - rc = fcb_init(&log_fcb); - TEST_ASSERT(rc == 0); - - log_register("log", &my_log, &log_fcb_handler, &log_fcb); -} - -TEST_CASE(log_append_fcb) -{ - char *str; - - while (1) { - str = str_logs[str_max_idx]; - if (!str) { - break; - } - log_printf(&my_log, 0, 0, str, strlen(str)); - str_max_idx++; - } -} - -static int +int log_test_walk1(struct log *log, void *arg, void *dptr, uint16_t len) { int rc; @@ -107,17 +73,7 @@ log_test_walk1(struct log *log, void *arg, void *dptr, uint16_t len) return 0; } -TEST_CASE(log_walk_fcb) -{ - int rc; - - str_idx = 0; - - rc = log_walk(&my_log, log_test_walk1, NULL); - TEST_ASSERT(rc == 0); -} - -static int +int log_test_walk2(struct log *log, void *arg, void *dptr, uint16_t len) { TEST_ASSERT(0); @@ -135,6 +91,11 @@ TEST_CASE(log_flush_fcb) TEST_ASSERT(rc == 0); } +TEST_CASE_DECL(log_setup_fcb) +TEST_CASE_DECL(log_append_fcb) +TEST_CASE_DECL(log_walk_fcb) +TEST_CASE_DECL(log_flush_fcb) + TEST_SUITE(log_test_all) { log_setup_fcb(); @@ -148,7 +109,7 @@ TEST_SUITE(log_test_all) int main(int argc, char **argv) { - tu_config.tc_print_results = 1; + ts_config.ts_print_results = 1; tu_init(); log_init(); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/log/test/src/log_test.h ---------------------------------------------------------------------- diff --git a/sys/log/test/src/log_test.h b/sys/log/test/src/log_test.h new file mode 100644 index 0000000..36e5bfe --- /dev/null +++ b/sys/log/test/src/log_test.h @@ -0,0 +1,54 @@ +/** + * 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. + */ +#ifndef _LOG_TEST_H +#define _LOG_TEST_H +#include <string.h> + +#include "syscfg/syscfg.h" +#include "os/os.h" +#include "testutil/testutil.h" +#include "fcb/fcb.h" +#include "log/log.h" + +#ifdef __cplusplus +#extern "C" { +#endif + +#define FCB_FLASH_AREAS 2 + +extern struct flash_area fcb_areas[FCB_FLASH_AREAS]; + +extern struct fcb log_fcb; +extern struct log my_log; + +#define FCB_STR_LOGS_CNT 3 + +extern char *str_logs[FCB_STR_LOGS_CNT]; + +extern int str_idx; +extern int str_max_idx; + +int log_test_walk1(struct log *log, void *arg, void *dptr, uint16_t len); +int log_test_walk2(struct log *log, void *arg, void *dptr, uint16_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* _LOG_TEST_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/log/test/src/testcases/log_append_fcb.c ---------------------------------------------------------------------- diff --git a/sys/log/test/src/testcases/log_append_fcb.c b/sys/log/test/src/testcases/log_append_fcb.c new file mode 100644 index 0000000..9db6371 --- /dev/null +++ b/sys/log/test/src/testcases/log_append_fcb.c @@ -0,0 +1,33 @@ +/** + * 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 "log_test.h" + +TEST_CASE(log_append_fcb) +{ + char *str; + + while (1) { + str = str_logs[str_max_idx]; + if (!str) { + break; + } + log_printf(&my_log, 0, 0, str, strlen(str)); + str_max_idx++; + } +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/log/test/src/testcases/log_setup_fcb.c ---------------------------------------------------------------------- diff --git a/sys/log/test/src/testcases/log_setup_fcb.c b/sys/log/test/src/testcases/log_setup_fcb.c new file mode 100644 index 0000000..fde174d --- /dev/null +++ b/sys/log/test/src/testcases/log_setup_fcb.c @@ -0,0 +1,39 @@ +/** + * 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 "log_test.h" + +TEST_CASE(log_setup_fcb) +{ + int rc; + int i; + + log_fcb.f_sectors = fcb_areas; + log_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]); + log_fcb.f_magic = 0x7EADBADF; + log_fcb.f_version = 0; + + for (i = 0; i < log_fcb.f_sector_cnt; i++) { + rc = flash_area_erase(&fcb_areas[i], 0, fcb_areas[i].fa_size); + TEST_ASSERT(rc == 0); + } + rc = fcb_init(&log_fcb); + TEST_ASSERT(rc == 0); + + log_register("log", &my_log, &log_fcb_handler, &log_fcb); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/log/test/src/testcases/log_walk_fcb.c ---------------------------------------------------------------------- diff --git a/sys/log/test/src/testcases/log_walk_fcb.c b/sys/log/test/src/testcases/log_walk_fcb.c new file mode 100644 index 0000000..d3288b6 --- /dev/null +++ b/sys/log/test/src/testcases/log_walk_fcb.c @@ -0,0 +1,29 @@ +/** + * 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 "log_test.h" + +TEST_CASE(log_walk_fcb) +{ + int rc; + + str_idx = 0; + + rc = log_walk(&my_log, log_test_walk1, NULL); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/test/testutil/include/testutil/testutil.h ---------------------------------------------------------------------- diff --git a/test/testutil/include/testutil/testutil.h b/test/testutil/include/testutil/testutil.h index 1579b84..13df0ab 100644 --- a/test/testutil/include/testutil/testutil.h +++ b/test/testutil/include/testutil/testutil.h @@ -29,63 +29,142 @@ extern "C" { #endif -/***************************************************************************** - * Public declarations * - *****************************************************************************/ +/* + * General execution flow of test suites and cases (more to come XXX) + * + * TEST_SUITE + * tu_suite_init + * tu_suite_pre_test + * tu_case_init + * tu_case_pre_test + * TEST_CASE + * tu_case_post_test + * tu_case_pass/tu_case_fail + * tu_case_complete + * tu_suite_post_test + * tu_suite_complete + */ -typedef void tu_case_init_fn_t(void *arg); typedef void tu_case_report_fn_t(char *msg, int msg_len, void *arg); -typedef void tu_suite_init_fn_t(void *arg); -typedef void tu_restart_fn_t(void *arg); - -struct tu_config { - int tc_print_results; - int tc_system_assert; +typedef void tu_suite_restart_fn_t(void *arg); - tu_case_init_fn_t *tc_case_init_cb; - void *tc_case_init_arg; +typedef void tu_pre_test_fn_t(void *arg); +typedef void tu_post_test_fn_t(void *arg); - tu_case_report_fn_t *tc_case_fail_cb; - void *tc_case_fail_arg; +typedef void tu_init_test_fn_t(void *arg); +typedef void tu_pre_test_fn_t(void *arg); +typedef void tu_post_test_fn_t(void *arg); - tu_case_report_fn_t *tc_case_pass_cb; - void *tc_case_pass_arg; +/* + * Private declarations - Test Suite configuration + */ +void tu_suite_set_init_cb(tu_init_test_fn_t *cb, void *cb_arg); +void tu_suite_set_pre_test_cb(tu_pre_test_fn_t *cb, void *cb_arg); +void tu_suite_set_post_test_cb(tu_post_test_fn_t *cb, void *cb_arg); +void tu_suite_set_pass_cb(tu_case_report_fn_t *cb, void *cb_arg); +void tu_suite_set_fail_cb(tu_case_report_fn_t *cb, void *cb_arg); - tu_suite_init_fn_t *tc_suite_init_cb; - void *tc_suite_init_arg; +void tu_suite_init(const char *name); +void tu_suite_pre_test(void); +void tu_suite_post_test(void); +void tu_suite_complete(void); - tu_restart_fn_t *tc_restart_cb; - void *tc_restart_arg; +struct ts_config { + int ts_print_results; + int ts_system_assert; + + /* + * Called prior to the first test in the suite + */ + tu_init_test_fn_t *ts_suite_init_cb; + void *ts_suite_init_arg; + + /* + * Called before every test in the suite + */ + tu_pre_test_fn_t *ts_case_pre_test_cb; + void *ts_case_pre_arg; + + /* + * Called after every test in the suite + */ + tu_post_test_fn_t *ts_case_post_test_cb; + void *ts_case_post_arg; + + /* + * Called after test returns success + */ + tu_case_report_fn_t *ts_case_pass_cb; + void *ts_case_pass_arg; + + /* + * Called after test fails (primarily thoough a failed test assert + */ + tu_case_report_fn_t *ts_case_fail_cb; + void *ts_case_fail_arg; + + /* + * restart after running the test suite + */ + tu_suite_restart_fn_t *ts_restart_cb; + void *ts_restart_arg; }; -extern struct tu_config tu_config; -extern const char *tu_suite_name; -extern const char *tu_case_name; -extern int tu_first_idx; - -typedef void tu_post_test_fn_t(void *arg); - -void tu_suite_set_post_test_cb(tu_post_test_fn_t *cb, void *cb_arg); int tu_parse_args(int argc, char **argv); int tu_init(void); void tu_restart(void); -/***************************************************************************** - * Private declarations * - *****************************************************************************/ +/* + * Public declarations - test case configuration + */ -void tu_suite_complete(void); -void tu_suite_init(const char *name); +void tu_case_set_init_cb(tu_init_test_fn_t *cb, void *cb_arg); +void tu_case_set_pre_cb(tu_pre_test_fn_t *cb, void *cb_arg); +void tu_case_set_post_cb(tu_post_test_fn_t *cb, void *cb_arg); + +struct tc_config { + /* + * Called to initialize the test case + */ + tu_init_test_fn_t *tc_case_init_cb; + void *tc_case_init_arg; + + /* + * Called prior to the test case start + */ + tu_pre_test_fn_t *tc_case_pre_test_cb; + void *tc_case_pre_arg; + + /* + * Called after the test case completes + */ + tu_post_test_fn_t *tc_case_post_test_cb; + void *tc_case_post_arg; +}; void tu_case_init(const char *name); void tu_case_complete(void); +void tu_case_pass(void); +void tu_case_fail(void); void tu_case_fail_assert(int fatal, const char *file, int line, const char *expr, const char *format, ...); void tu_case_write_pass_auto(void); void tu_case_pass_manual(const char *file, int line, const char *format, ...); +void tu_case_pre_test(void); void tu_case_post_test(void); +void tu_case_complete(void); + +extern struct tc_config tc_config; +extern struct tc_config *tc_current_config; +extern struct ts_config ts_config; +extern struct ts_config *ts_current_config; + +extern const char *tu_suite_name; +extern const char *tu_case_name; +extern int tu_first_idx; + extern int tu_any_failed; extern int tu_suite_failed; extern int tu_case_reported; @@ -93,48 +172,57 @@ extern int tu_case_failed; extern int tu_case_idx; extern jmp_buf tu_case_jb; -#define TEST_SUITE(suite_name) \ - static void TEST_SUITE_##suite_name(void); \ - \ - int \ - suite_name(void) \ - { \ - tu_suite_init(#suite_name); \ - TEST_SUITE_##suite_name(); \ - tu_suite_complete(); \ - \ - return tu_suite_failed; \ - } \ - \ - static void \ +#define TEST_SUITE(suite_name) \ +static void \ +TEST_SUITE_##suite_name(void); \ + \ + int \ + suite_name(void) \ + { \ + tu_suite_init(#suite_name); \ + TEST_SUITE_##suite_name(); \ + tu_suite_complete(); \ + \ + return tu_suite_failed; \ + } \ + \ + static void \ TEST_SUITE_##suite_name(void) -/* for creating multiple files with test cases all belonging to the same - * suite */ -#define TEST_CASE_DECL(case_name) int case_name(void); - -#define TEST_CASE(case_name) \ - static void TEST_CASE_##case_name(void); \ - \ - int \ - case_name(void) \ - { \ - if (tu_case_idx >= tu_first_idx) { \ - tu_case_init(#case_name); \ - \ - if (setjmp(tu_case_jb) == 0) { \ - TEST_CASE_##case_name(); \ - tu_case_post_test(); \ - tu_case_write_pass_auto(); \ - } \ - } \ - \ - tu_case_complete(); \ - \ - return tu_case_failed; \ - } \ - \ - static void \ +/* + * for creating multiple files with test cases + * all belonging to the same suite + */ +#define TEST_CASE_DECL(case_name) \ + int case_name(void); + +/* + * Unit test definition. + */ +#define TEST_CASE(case_name) \ + static void TEST_CASE_##case_name(void); \ + \ + int \ + case_name(void) \ + { \ + tu_suite_pre_test(); \ + if (tu_case_idx >= tu_first_idx) { \ + tu_case_init(#case_name); \ + \ + tu_case_pre_test(); \ + if (setjmp(tu_case_jb) == 0) { \ + TEST_CASE_##case_name(); \ + tu_case_post_test(); \ + tu_case_pass(); \ + } \ + tu_case_complete(); \ + } \ + tu_suite_post_test(); \ + \ + return tu_case_failed; \ + } \ + \ + static void \ TEST_CASE_##case_name(void) #define FIRST_AUX(first, ...) first @@ -152,21 +240,22 @@ extern jmp_buf tu_case_jb; #define XSTR(s) STR(s) #define STR(s) #s -#define TEST_ASSERT_FULL(fatal, expr, ...) do \ -{ \ - if (!(expr)) { \ - tu_case_fail_assert((fatal), __FILE__, __LINE__, XSTR(expr), \ - __VA_ARGS__); \ - } \ +#define TEST_ASSERT_FULL(fatal, expr, ...) do \ +{ \ + if (!(expr)) { \ + tu_case_fail_assert((fatal), __FILE__, \ + __LINE__, XSTR(expr), \ + __VA_ARGS__); \ + } \ } while (0) -#define TEST_ASSERT(...) \ +#define TEST_ASSERT(...) \ TEST_ASSERT_FULL(0, FIRST(__VA_ARGS__), REST_OR_0(__VA_ARGS__)) -#define TEST_ASSERT_FATAL(...) \ +#define TEST_ASSERT_FATAL(...) \ TEST_ASSERT_FULL(1, FIRST(__VA_ARGS__), REST_OR_0(__VA_ARGS__)) -#define TEST_PASS(...) \ +#define TEST_PASS(...) \ tu_case_pass_manual(__FILE__, __LINE__, __VA_ARGS__); #if MYNEWT_VAL(TEST) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/test/testutil/src/arch/cortex_m4/testutil_arch_arm.c ---------------------------------------------------------------------- diff --git a/test/testutil/src/arch/cortex_m4/testutil_arch_arm.c b/test/testutil/src/arch/cortex_m4/testutil_arch_arm.c deleted file mode 100644 index 52ace63..0000000 --- a/test/testutil/src/arch/cortex_m4/testutil_arch_arm.c +++ /dev/null @@ -1,27 +0,0 @@ -/** - * 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 "hal/hal_system.h" -#include "testutil_priv.h" - -void -tu_arch_restart(void) -{ - system_reset(); -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/test/testutil/src/arch/sim/testutil_arch_sim.c ---------------------------------------------------------------------- diff --git a/test/testutil/src/arch/sim/testutil_arch_sim.c b/test/testutil/src/arch/sim/testutil_arch_sim.c deleted file mode 100644 index 2d90501..0000000 --- a/test/testutil/src/arch/sim/testutil_arch_sim.c +++ /dev/null @@ -1,30 +0,0 @@ -/** - * 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 "os/os.h" -#include "os/os_arch.h" -#include "os/os_test.h" -#include "testutil_priv.h" - -void -tu_arch_restart(void) -{ - os_arch_os_stop(); - tu_case_abort(); -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/test/testutil/src/arch/sim/tu_args.c ---------------------------------------------------------------------- diff --git a/test/testutil/src/arch/sim/tu_args.c b/test/testutil/src/arch/sim/tu_args.c deleted file mode 100644 index 75a2900..0000000 --- a/test/testutil/src/arch/sim/tu_args.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <errno.h> -#include <unistd.h> - -#include "testutil/testutil.h" - -int -tu_parse_args(int argc, char **argv) -{ - int ch; - - while ((ch = getopt(argc, argv, "s")) != -1) { - switch (ch) { - case 's': - tu_config.tc_system_assert = 1; - break; - - default: - return EINVAL; - } - } - - return 0; -}