http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_nv_ns_11.c ---------------------------------------------------------------------- diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_ns_11.c b/boot/bootutil/test/src/testcases/boot_test_nv_ns_11.c new file mode 100644 index 0000000..4a43ef2 --- /dev/null +++ b/boot/bootutil/test/src/testcases/boot_test_nv_ns_11.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 "boot_test.h" + +TEST_CASE(boot_test_nv_ns_11) +{ + struct image_header hdr0 = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 5 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 0, 5, 21, 432 }, + }; + + struct image_header hdr1 = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 32 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 1, 2, 3, 432 }, + }; + + struct boot_req req = { + .br_area_descs = boot_test_area_descs, + .br_slot_areas = boot_test_slot_areas, + .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1, + .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH, + .br_img_sz = (384 * 1024), + }; + + boot_test_util_init_flash(); + boot_test_util_write_image(&hdr0, 0); + boot_test_util_write_hash(&hdr0, 0); + boot_test_util_write_image(&hdr1, 1); + boot_test_util_write_hash(&hdr1, 1); + + boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, &hdr1); +}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_revert.c ---------------------------------------------------------------------- diff --git a/boot/bootutil/test/src/testcases/boot_test_revert.c b/boot/bootutil/test/src/testcases/boot_test_revert.c new file mode 100644 index 0000000..d49d42d --- /dev/null +++ b/boot/bootutil/test/src/testcases/boot_test_revert.c @@ -0,0 +1,59 @@ +/** + * 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 "boot_test.h" + +TEST_CASE(boot_test_revert) +{ + struct image_header hdr0 = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 5 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 0, 5, 21, 432 }, + }; + + struct image_header hdr1 = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 32 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 1, 2, 3, 432 }, + }; + + struct boot_req req = { + .br_area_descs = boot_test_area_descs, + .br_slot_areas = boot_test_slot_areas, + .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1, + .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH, + .br_img_sz = (384 * 1024), + }; + + boot_test_util_init_flash(); + boot_test_util_write_image(&hdr0, 0); + boot_test_util_write_hash(&hdr0, 0); + boot_test_util_write_image(&hdr1, 1); + boot_test_util_write_hash(&hdr1, 1); + + /* Indicate that the image in slot 0 is being tested. */ + boot_set_copy_done(); + + boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, &hdr0, &hdr1); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_revert_continue.c ---------------------------------------------------------------------- diff --git a/boot/bootutil/test/src/testcases/boot_test_revert_continue.c b/boot/bootutil/test/src/testcases/boot_test_revert_continue.c new file mode 100644 index 0000000..ec4f56c --- /dev/null +++ b/boot/bootutil/test/src/testcases/boot_test_revert_continue.c @@ -0,0 +1,71 @@ +/** + * 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 "boot_test.h" + +TEST_CASE(boot_test_revert_continue) +{ + struct boot_status status; + int rc; + + struct image_header hdr0 = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 5 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 0, 5, 21, 432 }, + }; + + struct image_header hdr1 = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 32 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 1, 2, 3, 432 }, + }; + + struct boot_req req = { + .br_area_descs = boot_test_area_descs, + .br_slot_areas = boot_test_slot_areas, + .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1, + .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH, + .br_img_sz = (384 * 1024), + }; + + boot_test_util_init_flash(); + boot_test_util_write_image(&hdr0, 0); + boot_test_util_write_hash(&hdr0, 0); + boot_test_util_write_image(&hdr1, 1); + boot_test_util_write_hash(&hdr1, 1); + + boot_test_util_swap_areas(2, 5); + + /* Indicate that the image in slot 0 is being tested. */ + boot_set_copy_done(); + + status.idx = 1; + status.elem_sz = 1; + status.state = 0; + + rc = boot_write_status(&status); + TEST_ASSERT_FATAL(rc == 0); + + boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, &hdr0, &hdr1); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c ---------------------------------------------------------------------- diff --git a/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c b/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c new file mode 100644 index 0000000..38fa8f9 --- /dev/null +++ b/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c @@ -0,0 +1,61 @@ +/** + * 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 "boot_test.h" + +TEST_CASE(boot_test_vb_ns_11) +{ + int rc; + + struct image_header hdr0 = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 5 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 0, 5, 21, 432 }, + }; + + struct image_header hdr1 = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 32 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 1, 2, 3, 432 }, + }; + + struct boot_req req = { + .br_area_descs = boot_test_area_descs, + .br_slot_areas = boot_test_slot_areas, + .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1, + .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH, + .br_img_sz = (384 * 1024), + }; + + boot_test_util_init_flash(); + boot_test_util_write_image(&hdr0, 0); + boot_test_util_write_hash(&hdr0, 0); + boot_test_util_write_image(&hdr1, 1); + boot_test_util_write_hash(&hdr1, 1); + + rc = boot_set_pending(1); + TEST_ASSERT_FATAL(rc == 0); + + boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c ---------------------------------------------------------------------- diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c new file mode 100644 index 0000000..ac31824 --- /dev/null +++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.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 "boot_test.h" + +TEST_CASE(boot_test_vm_ns_01) +{ + int rc; + + struct image_header hdr = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 10 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 1, 2, 3, 432 }, + }; + + struct boot_req req = { + .br_area_descs = boot_test_area_descs, + .br_slot_areas = boot_test_slot_areas, + .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1, + .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH, + .br_img_sz = (384 * 1024), + }; + + boot_test_util_init_flash(); + boot_test_util_write_image(&hdr, 1); + boot_test_util_write_hash(&hdr, 1); + + rc = boot_set_pending(1); + TEST_ASSERT(rc == 0); + + boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, NULL, &hdr); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_vm_ns_10.c ---------------------------------------------------------------------- diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_10.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_10.c new file mode 100644 index 0000000..24c7361 --- /dev/null +++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_10.c @@ -0,0 +1,45 @@ +/** + * 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 "boot_test.h" + +TEST_CASE(boot_test_vm_ns_10) +{ + struct image_header hdr = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 12 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 0, 2, 3, 4 }, + }; + + struct boot_req req = { + .br_area_descs = boot_test_area_descs, + .br_slot_areas = boot_test_slot_areas, + .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1, + .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH, + .br_img_sz = (384 * 1024), + }; + + boot_test_util_init_flash(); + boot_test_util_write_image(&hdr, 0); + boot_test_util_write_hash(&hdr, 0); + + boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c ---------------------------------------------------------------------- diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c new file mode 100644 index 0000000..84e6a91 --- /dev/null +++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c @@ -0,0 +1,61 @@ +/** + * 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 "boot_test.h" + +TEST_CASE(boot_test_vm_ns_11_2areas) +{ + int rc; + + struct image_header hdr0 = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 5 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 0, 5, 21, 432 }, + }; + + struct image_header hdr1 = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 196 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 1, 2, 3, 432 }, + }; + + struct boot_req req = { + .br_area_descs = boot_test_area_descs, + .br_slot_areas = boot_test_slot_areas, + .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1, + .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH, + .br_img_sz = (384 * 1024), + }; + + boot_test_util_init_flash(); + boot_test_util_write_image(&hdr0, 0); + boot_test_util_write_hash(&hdr0, 0); + boot_test_util_write_image(&hdr1, 1); + boot_test_util_write_hash(&hdr1, 1); + + rc = boot_set_pending(1); + TEST_ASSERT(rc == 0); + + boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_a.c ---------------------------------------------------------------------- diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_a.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_a.c new file mode 100644 index 0000000..7ef5196 --- /dev/null +++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_a.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 "boot_test.h" + +TEST_CASE(boot_test_vm_ns_11_a) +{ + struct image_header hdr0 = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 5 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 0, 5, 21, 432 }, + }; + + struct image_header hdr1 = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 32 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 1, 2, 3, 432 }, + }; + + struct boot_req req = { + .br_area_descs = boot_test_area_descs, + .br_slot_areas = boot_test_slot_areas, + .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1, + .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH, + .br_img_sz = (384 * 1024), + }; + + boot_test_util_init_flash(); + boot_test_util_write_image(&hdr0, 0); + boot_test_util_write_hash(&hdr0, 0); + boot_test_util_write_image(&hdr1, 1); + boot_test_util_write_hash(&hdr1, 1); + + boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, &hdr1); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c ---------------------------------------------------------------------- diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c new file mode 100644 index 0000000..f4df74a --- /dev/null +++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c @@ -0,0 +1,61 @@ +/** + * 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 "boot_test.h" + +TEST_CASE(boot_test_vm_ns_11_b) +{ + int rc; + + struct image_header hdr0 = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 5 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 0, 5, 21, 432 }, + }; + + struct image_header hdr1 = { + .ih_magic = IMAGE_MAGIC, + .ih_tlv_size = 4 + 32, + .ih_hdr_size = BOOT_TEST_HEADER_SIZE, + .ih_img_size = 32 * 1024, + .ih_flags = IMAGE_F_SHA256, + .ih_ver = { 1, 2, 3, 432 }, + }; + + struct boot_req req = { + .br_area_descs = boot_test_area_descs, + .br_slot_areas = boot_test_slot_areas, + .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1, + .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH, + .br_img_sz = (384 * 1024), + }; + + boot_test_util_init_flash(); + boot_test_util_write_image(&hdr0, 0); + boot_test_util_write_hash(&hdr0, 0); + boot_test_util_write_image(&hdr1, 1); + boot_test_util_write_hash(&hdr1, 1); + + rc = boot_set_pending(1); + TEST_ASSERT(rc == 0); + + boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/mbedtls_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/mbedtls_test.c b/crypto/mbedtls/test/src/mbedtls_test.c index 85038f8..877452a 100644 --- a/crypto/mbedtls/test/src/mbedtls_test.c +++ b/crypto/mbedtls/test/src/mbedtls_test.c @@ -43,152 +43,24 @@ #include "mbedtls/x509.h" #include "mbedtls/xtea.h" -TEST_CASE(sha1_test) -{ - int rc; - - rc = mbedtls_sha1_self_test(0); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(sha256_test) -{ - int rc; - - rc = mbedtls_sha256_self_test(0); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(sha512_test) -{ - int rc; - - rc = mbedtls_sha512_self_test(1); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(aes_test) -{ - int rc; - - rc = mbedtls_aes_self_test(1); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(arc4_test) -{ - int rc; - - rc = mbedtls_arc4_self_test(1); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(bignum_test) -{ - int rc; - - rc = mbedtls_mpi_self_test(1); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(ccm_test) -{ - int rc; - - rc = mbedtls_ccm_self_test(1); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(dhm_test) -{ - int rc; - - rc = mbedtls_dhm_self_test(1); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(ecp_test) -{ - int rc; - - rc = mbedtls_ecp_self_test(1); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(entropy_test) -{ -#if 0 /* XXX fix this later, no strong entropy source atm */ - int rc; - - rc = mbedtls_entropy_self_test(1); - TEST_ASSERT(rc == 0); -#endif -} - -TEST_CASE(gcm_test) -{ - int rc; - - rc = mbedtls_gcm_self_test(1); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(hmac_drbg_test) -{ - int rc; - - rc = mbedtls_hmac_drbg_self_test(1); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(md5_test) -{ - int rc; - - rc = mbedtls_md5_self_test(1); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(pkcs5_test) -{ - int rc; - - rc = mbedtls_pkcs5_self_test(1); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(ripemd160_test) -{ - int rc; - - rc = mbedtls_ripemd160_self_test(1); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(rsa_test) -{ - int rc; - - rc = mbedtls_rsa_self_test(1); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(x509_test) -{ - int rc; - - rc = mbedtls_x509_self_test(1); - TEST_ASSERT(rc == 0); -} - -TEST_CASE(xtea_test) -{ - int rc; - - rc = mbedtls_xtea_self_test(1); - TEST_ASSERT(rc == 0); -} - +TEST_CASE_DECL(sha1_test) +TEST_CASE_DECL(sha256_test) +TEST_CASE_DECL(sha512_test) +TEST_CASE_DECL(aes_test) +TEST_CASE_DECL(arc4_test) +TEST_CASE_DECL(bignum_test) +TEST_CASE_DECL(ccm_test) +TEST_CASE_DECL(dhm_test) +TEST_CASE_DECL(ecp_test) +TEST_CASE_DECL(entropy_test) +TEST_CASE_DECL(gcm_test) +TEST_CASE_DECL(hmac_drbg_test) +TEST_CASE_DECL(md5_test) +TEST_CASE_DECL(pkcs5_test) +TEST_CASE_DECL(ripemd160_test) +TEST_CASE_DECL(rsa_test) +TEST_CASE_DECL(x509_test) +TEST_CASE_DECL(xtea_test) TEST_SUITE(mbedtls_test_all) { @@ -216,7 +88,7 @@ TEST_SUITE(mbedtls_test_all) int main(int argc, char **argv) { - tu_config.tc_print_results = 1; + ts_config.ts_print_results = 1; tu_init(); mbedtls_test_all(); @@ -225,4 +97,3 @@ main(int argc, char **argv) } #endif - http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/mbedtls_test.h ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/mbedtls_test.h b/crypto/mbedtls/test/src/mbedtls_test.h new file mode 100644 index 0000000..fd82fde --- /dev/null +++ b/crypto/mbedtls/test/src/mbedtls_test.h @@ -0,0 +1,58 @@ +/** + * 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 _MBEDTLS_TEST_H +#define _MBEDTLS_TEST_H +#include <stdio.h> +#include <string.h> + +#include "syscfg/syscfg.h" +#include "testutil/testutil.h" + +#include "mbedtls/mbedtls_test.h" +#include "mbedtls/sha1.h" +#include "mbedtls/sha256.h" +#include "mbedtls/sha512.h" +#include "mbedtls/aes.h" +#include "mbedtls/arc4.h" +#include "mbedtls/bignum.h" +#include "mbedtls/ccm.h" +#include "mbedtls/dhm.h" +#include "mbedtls/ecjpake.h" +#include "mbedtls/ecp.h" +#include "mbedtls/entropy.h" +#include "mbedtls/gcm.h" +#include "mbedtls/hmac_drbg.h" +#include "mbedtls/md5.h" +#include "mbedtls/pkcs5.h" +#include "mbedtls/ripemd160.h" +#include "mbedtls/rsa.h" +#include "mbedtls/x509.h" +#include "mbedtls/xtea.h" + +#ifdef __cplusplus +#extern "C" { +#endif + +/* This space intentionally left blank */ + +#ifdef __cplusplus +} +#endif + +#endif /* _MBEDTLS_TEST_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/aes_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/aes_test.c b/crypto/mbedtls/test/src/testcases/aes_test.c new file mode 100644 index 0000000..828c1cc --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/aes_test.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 "mbedtls_test.h" + +TEST_CASE(aes_test) +{ + int rc; + + rc = mbedtls_aes_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/arc4_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/arc4_test.c b/crypto/mbedtls/test/src/testcases/arc4_test.c new file mode 100644 index 0000000..91655e3 --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/arc4_test.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 "mbedtls_test.h" + +TEST_CASE(arc4_test) +{ + int rc; + + rc = mbedtls_arc4_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/bignum_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/bignum_test.c b/crypto/mbedtls/test/src/testcases/bignum_test.c new file mode 100644 index 0000000..af5b704 --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/bignum_test.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 "mbedtls_test.h" + +TEST_CASE(bignum_test) +{ + int rc; + + rc = mbedtls_mpi_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/ccm_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/ccm_test.c b/crypto/mbedtls/test/src/testcases/ccm_test.c new file mode 100644 index 0000000..efb77a6 --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/ccm_test.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 "mbedtls_test.h" + +TEST_CASE(ccm_test) +{ + int rc; + + rc = mbedtls_ccm_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/dhm_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/dhm_test.c b/crypto/mbedtls/test/src/testcases/dhm_test.c new file mode 100644 index 0000000..6123298 --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/dhm_test.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 "mbedtls_test.h" + +TEST_CASE(dhm_test) +{ + int rc; + + rc = mbedtls_dhm_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/ecp_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/ecp_test.c b/crypto/mbedtls/test/src/testcases/ecp_test.c new file mode 100644 index 0000000..b4a218e --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/ecp_test.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 "mbedtls_test.h" + +TEST_CASE(ecp_test) +{ + int rc; + + rc = mbedtls_ecp_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/entropy_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/entropy_test.c b/crypto/mbedtls/test/src/testcases/entropy_test.c new file mode 100644 index 0000000..7088313 --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/entropy_test.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 "mbedtls_test.h" + +TEST_CASE(entropy_test) +{ +#if 0 /* XXX fix this later, no strong entropy source atm */ + int rc; + + rc = mbedtls_entropy_self_test(1); + TEST_ASSERT(rc == 0); +#endif +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/gcm_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/gcm_test.c b/crypto/mbedtls/test/src/testcases/gcm_test.c new file mode 100644 index 0000000..27e0aea --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/gcm_test.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 "mbedtls_test.h" + +TEST_CASE(gcm_test) +{ + int rc; + + rc = mbedtls_gcm_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/hmac_drbg_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/hmac_drbg_test.c b/crypto/mbedtls/test/src/testcases/hmac_drbg_test.c new file mode 100644 index 0000000..cd1f38c --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/hmac_drbg_test.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 "mbedtls_test.h" + +TEST_CASE(hmac_drbg_test) +{ + int rc; + + rc = mbedtls_hmac_drbg_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/md5_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/md5_test.c b/crypto/mbedtls/test/src/testcases/md5_test.c new file mode 100644 index 0000000..a8bb014 --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/md5_test.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 "mbedtls_test.h" + +TEST_CASE(md5_test) +{ + int rc; + + rc = mbedtls_md5_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/pkcs5_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/pkcs5_test.c b/crypto/mbedtls/test/src/testcases/pkcs5_test.c new file mode 100644 index 0000000..b9565d8 --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/pkcs5_test.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 "mbedtls_test.h" + +TEST_CASE(pkcs5_test) +{ + int rc; + + rc = mbedtls_pkcs5_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/ripemd160_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/ripemd160_test.c b/crypto/mbedtls/test/src/testcases/ripemd160_test.c new file mode 100644 index 0000000..c7c5922 --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/ripemd160_test.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 "mbedtls_test.h" + +TEST_CASE(ripemd160_test) +{ + int rc; + + rc = mbedtls_ripemd160_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/rsa_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/rsa_test.c b/crypto/mbedtls/test/src/testcases/rsa_test.c new file mode 100644 index 0000000..a9442f0 --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/rsa_test.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 "mbedtls_test.h" + +TEST_CASE(rsa_test) +{ + int rc; + + rc = mbedtls_rsa_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/sha1_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/sha1_test.c b/crypto/mbedtls/test/src/testcases/sha1_test.c new file mode 100644 index 0000000..33427a7 --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/sha1_test.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 "mbedtls_test.h" + +TEST_CASE(sha1_test) +{ + int rc; + + rc = mbedtls_sha1_self_test(0); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/sha256_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/sha256_test.c b/crypto/mbedtls/test/src/testcases/sha256_test.c new file mode 100644 index 0000000..8fd4860 --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/sha256_test.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 "mbedtls_test.h" + +TEST_CASE(sha256_test) +{ + int rc; + + rc = mbedtls_sha256_self_test(0); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/sha512_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/sha512_test.c b/crypto/mbedtls/test/src/testcases/sha512_test.c new file mode 100644 index 0000000..6575d60 --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/sha512_test.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 "mbedtls_test.h" + +TEST_CASE(sha512_test) +{ + int rc; + + rc = mbedtls_sha512_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/x509_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/x509_test.c b/crypto/mbedtls/test/src/testcases/x509_test.c new file mode 100644 index 0000000..53ac342 --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/x509_test.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 "mbedtls_test.h" + +TEST_CASE(x509_test) +{ + int rc; + + rc = mbedtls_x509_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/xtea_test.c ---------------------------------------------------------------------- diff --git a/crypto/mbedtls/test/src/testcases/xtea_test.c b/crypto/mbedtls/test/src/testcases/xtea_test.c new file mode 100644 index 0000000..72296b5 --- /dev/null +++ b/crypto/mbedtls/test/src/testcases/xtea_test.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 "mbedtls_test.h" + +TEST_CASE(xtea_test) +{ + int rc; + + rc = mbedtls_xtea_self_test(1); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/base64/test/src/encoding_test.c ---------------------------------------------------------------------- diff --git a/encoding/base64/test/src/encoding_test.c b/encoding/base64/test/src/encoding_test.c index b21fee8..c3656b0 100644 --- a/encoding/base64/test/src/encoding_test.c +++ b/encoding/base64/test/src/encoding_test.c @@ -16,13 +16,14 @@ * specific language governing permissions and limitations * under the License. */ - #include <assert.h> #include <stddef.h> #include "syscfg/syscfg.h" #include "testutil/testutil.h" #include "encoding_test_priv.h" +TEST_CASE_DECL(hex2str) +TEST_CASE_DECL(str2hex) int hex_fmt_test_all(void) @@ -31,12 +32,18 @@ hex_fmt_test_all(void) return tu_case_failed; } +TEST_SUITE(hex_fmt_test_suite) +{ + hex2str(); + str2hex(); +} + #if MYNEWT_VAL(SELFTEST) int main(int argc, char **argv) { - tu_config.tc_print_results = 1; + ts_config.ts_print_results = 1; tu_init(); hex_fmt_test_all(); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/base64/test/src/encoding_test_priv.h ---------------------------------------------------------------------- diff --git a/encoding/base64/test/src/encoding_test_priv.h b/encoding/base64/test/src/encoding_test_priv.h index 424bb28..8bab6fe 100644 --- a/encoding/base64/test/src/encoding_test_priv.h +++ b/encoding/base64/test/src/encoding_test_priv.h @@ -16,10 +16,15 @@ * specific language governing permissions and limitations * under the License. */ - #ifndef __ENCODING_TEST_PRIV_ #define __ENCODING_TEST_PRIV_ +#include <assert.h> +#include <stddef.h> +#include "syscfg/syscfg.h" +#include "base64/hex.h" +#include "testutil/testutil.h" + #ifdef __cplusplus extern "C" { #endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/base64/test/src/hex_test.c ---------------------------------------------------------------------- diff --git a/encoding/base64/test/src/hex_test.c b/encoding/base64/test/src/hex_test.c deleted file mode 100644 index 471a14e..0000000 --- a/encoding/base64/test/src/hex_test.c +++ /dev/null @@ -1,125 +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 "testutil/testutil.h" -#include "base64/hex.h" - -TEST_CASE(hex2str) -{ - int i; - char *ret; - char cmp_data[8]; - - struct { - char *in; - int inlen; - char *out; - int outlen; - } test_data[] = { - [0] = { - .in = "\x01", - .inlen = 1, - .out = "01", - .outlen = 2, - }, - [1] = { - .in = "\xaf\xf2", - .inlen = 2, - .out = "aff2", - .outlen = 4, - } - }; - - for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++) { - ret = hex_format(test_data[i].in, test_data[i].inlen, - cmp_data, sizeof(cmp_data)); - TEST_ASSERT(ret == cmp_data); - TEST_ASSERT(strlen(cmp_data) == test_data[i].outlen); - TEST_ASSERT(!strcmp(test_data[i].out, cmp_data)); - } - - /* - * Test not enough space. Must have space for '\0' at the end. - */ - ret = hex_format("\x01\x02", 2, cmp_data, 1); - TEST_ASSERT(ret == NULL); - - ret = hex_format("\x01\x02", 2, cmp_data, 2); - TEST_ASSERT(ret == NULL); -} - -TEST_CASE(str2hex) -{ - int i; - char cmp_data[8]; - int rc; - - struct { - char *in; - int inlen; - char *out; - int outlen; - } test_data[] = { - [0] = { - .in = "01", - .inlen = 2, - .out = "\x01", - .outlen = 1, - }, - [1] = { - .in = "AfF2", - .inlen = 4, - .out = "\xaf\xf2", - .outlen = 2, - } - }; - - for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++) { - rc = hex_parse(test_data[i].in, test_data[i].inlen, - cmp_data, sizeof(cmp_data)); - TEST_ASSERT(rc == test_data[i].outlen); - TEST_ASSERT(!memcmp(test_data[i].out, cmp_data, rc)); - } - - /* - * Test invalid input - */ - rc = hex_parse("HJ", 2, cmp_data, sizeof(cmp_data)); - TEST_ASSERT(rc < 0); - - rc = hex_parse("a", 1, cmp_data, sizeof(cmp_data)); - TEST_ASSERT(rc < 0); - - rc = hex_parse("0102", 4, cmp_data, 1); - TEST_ASSERT(rc < 0); - - /* - * This should be valid. - */ - rc = hex_parse("0102", 4, cmp_data, 2); - TEST_ASSERT(rc == 2); -} - -TEST_SUITE(hex_fmt_test_suite) -{ - hex2str(); - str2hex(); -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/base64/test/src/testcases/hex2str.c ---------------------------------------------------------------------- diff --git a/encoding/base64/test/src/testcases/hex2str.c b/encoding/base64/test/src/testcases/hex2str.c new file mode 100644 index 0000000..7d79c4f --- /dev/null +++ b/encoding/base64/test/src/testcases/hex2str.c @@ -0,0 +1,64 @@ +/** + * 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 <string.h> +#include "encoding_test_priv.h" + +TEST_CASE(hex2str) +{ + int i; + char *ret; + char cmp_data[8]; + + struct { + char *in; + int inlen; + char *out; + int outlen; + } test_data[] = { + [0] = { + .in = "\x01", + .inlen = 1, + .out = "01", + .outlen = 2, + }, + [1] = { + .in = "\xaf\xf2", + .inlen = 2, + .out = "aff2", + .outlen = 4, + } + }; + + for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++) { + ret = hex_format(test_data[i].in, test_data[i].inlen, + cmp_data, sizeof(cmp_data)); + TEST_ASSERT(ret == cmp_data); + TEST_ASSERT(strlen(cmp_data) == test_data[i].outlen); + TEST_ASSERT(!strcmp(test_data[i].out, cmp_data)); + } + + /* + * Test not enough space. Must have space for '\0' at the end. + */ + ret = hex_format("\x01\x02", 2, cmp_data, 1); + TEST_ASSERT(ret == NULL); + + ret = hex_format("\x01\x02", 2, cmp_data, 2); + TEST_ASSERT(ret == NULL); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/base64/test/src/testcases/str2hex.c ---------------------------------------------------------------------- diff --git a/encoding/base64/test/src/testcases/str2hex.c b/encoding/base64/test/src/testcases/str2hex.c new file mode 100644 index 0000000..83a6b0d --- /dev/null +++ b/encoding/base64/test/src/testcases/str2hex.c @@ -0,0 +1,72 @@ +/** + * 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 <string.h> +#include "encoding_test_priv.h" + +TEST_CASE(str2hex) +{ + int i; + char cmp_data[8]; + int rc; + + struct { + char *in; + int inlen; + char *out; + int outlen; + } test_data[] = { + [0] = { + .in = "01", + .inlen = 2, + .out = "\x01", + .outlen = 1, + }, + [1] = { + .in = "AfF2", + .inlen = 4, + .out = "\xaf\xf2", + .outlen = 2, + } + }; + + for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++) { + rc = hex_parse(test_data[i].in, test_data[i].inlen, + cmp_data, sizeof(cmp_data)); + TEST_ASSERT(rc == test_data[i].outlen); + TEST_ASSERT(!memcmp(test_data[i].out, cmp_data, rc)); + } + + /* + * Test invalid input + */ + rc = hex_parse("HJ", 2, cmp_data, sizeof(cmp_data)); + TEST_ASSERT(rc < 0); + + rc = hex_parse("a", 1, cmp_data, sizeof(cmp_data)); + TEST_ASSERT(rc < 0); + + rc = hex_parse("0102", 4, cmp_data, 1); + TEST_ASSERT(rc < 0); + + /* + * This should be valid. + */ + rc = hex_parse("0102", 4, cmp_data, 2); + TEST_ASSERT(rc == 2); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/json/test/src/test_json.c ---------------------------------------------------------------------- diff --git a/encoding/json/test/src/test_json.c b/encoding/json/test/src/test_json.c index dab3f06..ca64f9e 100644 --- a/encoding/json/test/src/test_json.c +++ b/encoding/json/test/src/test_json.c @@ -21,6 +21,8 @@ #include "testutil/testutil.h" #include "test_json.h" +TEST_CASE_DECL(test_json_simple_encode); +TEST_CASE_DECL(test_json_simple_decode); TEST_SUITE(test_json_suite) { test_json_simple_encode(); @@ -28,16 +30,14 @@ TEST_SUITE(test_json_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(); test_json_suite(); return tu_any_failed; } - #endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/json/test/src/test_json.h ---------------------------------------------------------------------- diff --git a/encoding/json/test/src/test_json.h b/encoding/json/test/src/test_json.h index b7b9742..0cfa159 100644 --- a/encoding/json/test/src/test_json.h +++ b/encoding/json/test/src/test_json.h @@ -16,16 +16,42 @@ * specific language governing permissions and limitations * under the License. */ - #ifndef TEST_JSON_H #define TEST_JSON_H +#include <assert.h> +#include <string.h> +#include "testutil/testutil.h" +#include "test_json.h" +#include "json/json.h" + #ifdef __cplusplus extern "C" { #endif -TEST_CASE_DECL(test_json_simple_encode); -TEST_CASE_DECL(test_json_simple_decode); +char *output; +char *output1; +char *outputboolspace; +char *outputboolempty; + +char bigbuf[512]; +int buf_index; + +/* a test structure to hold the json flat buffer and pass bytes + * to the decoder */ +struct test_jbuf { + /* json_buffer must be first element in the structure */ + struct json_buffer json_buf; + char * start_buf; + char * end_buf; + int current_position; +}; + +char test_jbuf_read_next(struct json_buffer *jb); +char test_jbuf_read_prev(struct json_buffer *jb); +int test_jbuf_readn(struct json_buffer *jb, char *buf, int size); +int test_write(void *buf, char* data, int len); +void test_buf_init(struct test_jbuf *ptjb, char *string); #ifdef __cplusplus } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/json/test/src/test_json_simple.c ---------------------------------------------------------------------- diff --git a/encoding/json/test/src/test_json_simple.c b/encoding/json/test/src/test_json_simple.c deleted file mode 100644 index 0f9e10e..0000000 --- a/encoding/json/test/src/test_json_simple.c +++ /dev/null @@ -1,360 +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 <assert.h> -#include <string.h> -#include "testutil/testutil.h" -#include "test_json.h" -#include "json/json.h" - -static char *output = "{\"KeyBool\": true,\"KeyInt\": -1234,\"KeyUint\": 1353214,\"KeyString\": \"foobar\",\"KeyStringN\": \"foobarlong\",\"KeyIntArr\": [153,2532,-322]}"; - -static char *output1 ="{\"KeyBoolArr\": [true, false], \"KeyUintArr\": [0, 65535, 4294967295, 8589934590, 3451257]}"; -static char *outputboolspace = "{\"KeyBoolArr\": [ true , false,true ]}"; -static char *outputboolempty = "{\"KeyBoolArr\": , \"KeyBoolArr\": [ ]}"; - -static char bigbuf[512]; -static int buf_index; - -static int test_write(void *buf, char* data, int len) { - int i; - for(i = 0; i < len; i++) { - bigbuf[buf_index++] = data[i]; - } - return len; -} - -TEST_CASE(test_json_simple_encode){ - struct json_encoder encoder; - struct json_value value; - int rc; - - /* reset the state of the internal test */ - buf_index = 0; - memset(&encoder, 0, sizeof(encoder)); - - encoder.je_write = test_write; - encoder.je_arg= NULL; - - rc = json_encode_object_start(&encoder); - TEST_ASSERT(rc == 0); - - JSON_VALUE_BOOL(&value, 1); - rc = json_encode_object_entry(&encoder, "KeyBool", &value); - TEST_ASSERT(rc == 0); - - JSON_VALUE_INT(&value, -1234); - rc = json_encode_object_entry(&encoder, "KeyInt", &value); - TEST_ASSERT(rc == 0); - - JSON_VALUE_UINT(&value, 1353214); - rc = json_encode_object_entry(&encoder, "KeyUint", &value); - TEST_ASSERT(rc == 0); - - JSON_VALUE_STRING(&value, "foobar"); - rc = json_encode_object_entry(&encoder, "KeyString", &value); - TEST_ASSERT(rc == 0); - - /* we'll decode later differently */ - JSON_VALUE_STRINGN(&value, "foobarlongstring", 10); - rc = json_encode_object_entry(&encoder, "KeyStringN", &value); - TEST_ASSERT(rc == 0); - - rc = json_encode_array_name(&encoder, "KeyIntArr"); - TEST_ASSERT(rc == 0); - - rc = json_encode_array_start(&encoder); - TEST_ASSERT(rc == 0); - - JSON_VALUE_INT(&value, 153); - rc = json_encode_array_value(&encoder, &value); - TEST_ASSERT(rc == 0); - - JSON_VALUE_INT(&value, 2532); - rc = json_encode_array_value(&encoder, &value); - TEST_ASSERT(rc == 0); - - JSON_VALUE_INT(&value, -322); - rc = json_encode_array_value(&encoder, &value); - TEST_ASSERT(rc == 0); - - rc = json_encode_array_finish(&encoder); - TEST_ASSERT(rc == 0); - - rc = json_encode_object_finish(&encoder); - TEST_ASSERT(rc == 0); - - /* does it match what we expect it to */ - rc = strcmp(bigbuf, output); - TEST_ASSERT(rc == 0); -} - - -/* a test structure to hold the json flat buffer and pass bytes - * to the decoder */ -struct test_jbuf { - /* json_buffer must be first element in the structure */ - struct json_buffer json_buf; - char * start_buf; - char * end_buf; - int current_position; -}; - - -static char -test_jbuf_read_next(struct json_buffer *jb) { - char c; - struct test_jbuf *ptjb = (struct test_jbuf*) jb; - - if((ptjb->start_buf + ptjb->current_position) <= ptjb->end_buf) { - c = *(ptjb->start_buf + ptjb->current_position); - ptjb->current_position++; - return c; - } - return '\0'; -} - -/* this goes backward in the buffer one character */ -static char -test_jbuf_read_prev(struct json_buffer *jb) { - char c; - struct test_jbuf *ptjb = (struct test_jbuf*) jb; - if(ptjb->current_position) { - ptjb->current_position--; - c = *(ptjb->start_buf + ptjb->current_position); - return c; - } - - /* can't rewind */ - return '\0'; - -} - -static int -test_jbuf_readn(struct json_buffer *jb, char *buf, int size) { - struct test_jbuf *ptjb = (struct test_jbuf*) jb; - - int remlen; - - remlen = ptjb->end_buf - (ptjb->start_buf + ptjb->current_position); - if (size > remlen) { - size = remlen; - } - - memcpy(buf, ptjb->start_buf + ptjb->current_position, size); - ptjb->current_position += size; - return size; -} - -static void -test_buf_init(struct test_jbuf *ptjb, char *string) { - /* initialize the decode */ - ptjb->json_buf.jb_read_next = test_jbuf_read_next; - ptjb->json_buf.jb_read_prev = test_jbuf_read_prev; - ptjb->json_buf.jb_readn = test_jbuf_readn; - ptjb->start_buf = string; - ptjb->end_buf = string + strlen(string); - /* end buf points to the NULL */ - ptjb->current_position = 0; -} - -/* now test the decode on a string */ -TEST_CASE(test_json_simple_decode){ - struct test_jbuf tjb; - struct test_jbuf tjb1; - struct test_jbuf tjbboolspacearr; - struct test_jbuf tjbboolemptyarr; - long long unsigned int uint_val; - long long int int_val; - bool bool_val; - char string1[16]; - char string2[16]; - long long int intarr[8]; - int rc; - int rc1; - int rcbsa; - int array_count; - int array_countemp; - bool boolarr[2]; - unsigned long long uintarr[5]; - int array_count1; - int array_count1u; - bool boolspacearr[3]; - bool boolemptyarr[2]; - - struct json_attr_t test_attr[7] = { - [0] = { - .attribute = "KeyBool", - .type = t_boolean, - .addr.boolean = &bool_val, - .nodefault = true - }, - [1] = { - .attribute = "KeyInt", - .type = t_integer, - .addr.integer = &int_val, - .nodefault = true - }, - [2] = { - .attribute = "KeyUint", - .type = t_uinteger, - .addr.uinteger = &uint_val, - .nodefault = true - }, - [3] = { - .attribute = "KeyString", - .type = t_string, - .addr.string = string1, - .nodefault = true, - .len = sizeof(string1) - }, - [4] = { - .attribute = "KeyStringN", - .type = t_string, - .addr.string = string2, - .nodefault = true, - .len = sizeof(string2) - }, - [5] = { - .attribute = "KeyIntArr", - .type = t_array, - .addr.array = { - .element_type = t_integer, - .arr.integers.store = intarr, - .maxlen = sizeof intarr / sizeof intarr[0], - .count = &array_count, - }, - .nodefault = true, - .len = sizeof(intarr) - }, - [6] = { - .attribute = NULL - } - }; - - test_buf_init(&tjb, output); - - rc = json_read_object(&tjb.json_buf, test_attr); - TEST_ASSERT(rc==0); - TEST_ASSERT(bool_val == 1); - TEST_ASSERT(int_val == -1234); - TEST_ASSERT(uint_val == 1353214); - - rc = memcmp(string1, "foobar", strlen("foobar")); - TEST_ASSERT(rc==0); - - rc = memcmp(string2, "foobarlongstring", 10); - TEST_ASSERT(rc==0); - - TEST_ASSERT(array_count == 3); - TEST_ASSERT(intarr[0] == 153); - TEST_ASSERT(intarr[1] == 2532); - TEST_ASSERT(intarr[2] == -322); - - /*testing for the boolean*/ - struct json_attr_t test_attr1[2] = { - [0] = { - .attribute = "KeyBoolArr", - .type = t_array, - .addr.array = { - .element_type = t_boolean, - .arr.booleans.store = boolarr, - .maxlen = sizeof boolarr / sizeof boolarr[0], - .count =&array_count1, - }, - .nodefault = true, - .len = sizeof( boolarr), - }, - - [1] = { - .attribute = "KeyUintArr", - .type = t_array, - .addr.array = { - .element_type = t_uinteger, - .arr.uintegers.store = uintarr, - .maxlen = sizeof uintarr / sizeof uintarr[0], - .count =&array_count1u, - }, - .nodefault = true, - .len = sizeof( uintarr), - } - }; - - test_buf_init(&tjb1, output1); - - rc1 = json_read_object(&tjb1.json_buf, test_attr1); - TEST_ASSERT(rc1==0); - - TEST_ASSERT(boolarr[0] == true); - TEST_ASSERT(boolarr[1] == false); - - TEST_ASSERT(uintarr[0] == 0); - TEST_ASSERT(uintarr[1] == 65535); - TEST_ASSERT(uintarr[2] == 4294967295ULL); - TEST_ASSERT(uintarr[3] == 8589934590ULL); - TEST_ASSERT(uintarr[4] == 3451257ULL); - - /*testing arrays with empty spaces within the elements*/ - struct json_attr_t test_boolspacearr[2] = { - [0] = { - .attribute = "KeyBoolArr", - .type = t_array, - .addr.array = { - .element_type = t_boolean, - .arr.booleans.store = boolspacearr, - .maxlen = sizeof boolspacearr / sizeof boolspacearr[0], - .count =&array_count1, - }, - .nodefault = true, - .len = sizeof( boolspacearr), - } - - }; - - test_buf_init(&tjbboolspacearr, outputboolspace); - - rcbsa = json_read_object(&tjbboolspacearr.json_buf, test_boolspacearr); - TEST_ASSERT(rcbsa == 0); - - TEST_ASSERT(boolspacearr[0] == true); - TEST_ASSERT(boolspacearr[1] == false); - TEST_ASSERT(boolspacearr[2] == true); - - /*testing array with empty value*/ - struct json_attr_t test_boolemptyarr[2] = { - [0] = { - .attribute = "KeyBoolArr", - .type = t_array, - .addr.array = { - .element_type = t_boolean, - .arr.booleans.store = boolemptyarr, - .maxlen = sizeof boolemptyarr / sizeof boolemptyarr[0], - .count =&array_countemp, - }, - .nodefault = true, - .len = sizeof( boolemptyarr), - } - }; - - test_buf_init(&tjbboolemptyarr, outputboolempty); - - rcbsa = json_read_object(&tjbboolemptyarr.json_buf, test_boolemptyarr); - TEST_ASSERT(rcbsa == 6); - -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/json/test/src/test_json_utils.c ---------------------------------------------------------------------- diff --git a/encoding/json/test/src/test_json_utils.c b/encoding/json/test/src/test_json_utils.c new file mode 100644 index 0000000..95d1111 --- /dev/null +++ b/encoding/json/test/src/test_json_utils.c @@ -0,0 +1,98 @@ +/** + * 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 <assert.h> +#include <string.h> +#include "testutil/testutil.h" +#include "test_json.h" +#include "json/json.h" + +char *output = "{\"KeyBool\": true,\"KeyInt\": -1234,\"KeyUint\": 1353214,\"KeyString\": \"foobar\",\"KeyStringN\": \"foobarlong\",\"KeyIntArr\": [153,2532,-322]}"; + +char *output1 ="{\"KeyBoolArr\": [true, false], \"KeyUintArr\": [0, 65535, 4294967295, 8589934590, 3451257]}"; +char *outputboolspace = "{\"KeyBoolArr\": [ true , false,true ]}"; +char *outputboolempty = "{\"KeyBoolArr\": , \"KeyBoolArr\": [ ]}"; + +char bigbuf[512]; +int buf_index; + +int +test_write(void *buf, char* data, int len) { + int i; + for(i = 0; i < len; i++) { + bigbuf[buf_index++] = data[i]; + } + return len; +} + +char +test_jbuf_read_next(struct json_buffer *jb) { + char c; + struct test_jbuf *ptjb = (struct test_jbuf*) jb; + + if((ptjb->start_buf + ptjb->current_position) <= ptjb->end_buf) { + c = *(ptjb->start_buf + ptjb->current_position); + ptjb->current_position++; + return c; + } + return '\0'; +} + +/* this goes backward in the buffer one character */ +char +test_jbuf_read_prev(struct json_buffer *jb) { + char c; + struct test_jbuf *ptjb = (struct test_jbuf*) jb; + if(ptjb->current_position) { + ptjb->current_position--; + c = *(ptjb->start_buf + ptjb->current_position); + return c; + } + + /* can't rewind */ + return '\0'; + +} + +int +test_jbuf_readn(struct json_buffer *jb, char *buf, int size) { + struct test_jbuf *ptjb = (struct test_jbuf*) jb; + + int remlen; + + remlen = ptjb->end_buf - (ptjb->start_buf + ptjb->current_position); + if (size > remlen) { + size = remlen; + } + + memcpy(buf, ptjb->start_buf + ptjb->current_position, size); + ptjb->current_position += size; + return size; +} + +void +test_buf_init(struct test_jbuf *ptjb, char *string) { + /* initialize the decode */ + ptjb->json_buf.jb_read_next = test_jbuf_read_next; + ptjb->json_buf.jb_read_prev = test_jbuf_read_prev; + ptjb->json_buf.jb_readn = test_jbuf_readn; + ptjb->start_buf = string; + ptjb->end_buf = string + strlen(string); + /* end buf points to the NULL */ + ptjb->current_position = 0; +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/json/test/src/testcases/json_simple_decode.c ---------------------------------------------------------------------- diff --git a/encoding/json/test/src/testcases/json_simple_decode.c b/encoding/json/test/src/testcases/json_simple_decode.c new file mode 100644 index 0000000..31766db --- /dev/null +++ b/encoding/json/test/src/testcases/json_simple_decode.c @@ -0,0 +1,205 @@ +/** + * 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 "test_json.h" + +/* now test the decode on a string */ +TEST_CASE(test_json_simple_decode) +{ + struct test_jbuf tjb; + struct test_jbuf tjb1; + struct test_jbuf tjbboolspacearr; + struct test_jbuf tjbboolemptyarr; + long long unsigned int uint_val; + long long int int_val; + bool bool_val; + char string1[16]; + char string2[16]; + long long int intarr[8]; + int rc; + int rc1; + int rcbsa; + int array_count; + int array_countemp; + bool boolarr[2]; + unsigned long long uintarr[5]; + int array_count1; + int array_count1u; + bool boolspacearr[3]; + bool boolemptyarr[2]; + + struct json_attr_t test_attr[7] = { + [0] = { + .attribute = "KeyBool", + .type = t_boolean, + .addr.boolean = &bool_val, + .nodefault = true + }, + [1] = { + .attribute = "KeyInt", + .type = t_integer, + .addr.integer = &int_val, + .nodefault = true + }, + [2] = { + .attribute = "KeyUint", + .type = t_uinteger, + .addr.uinteger = &uint_val, + .nodefault = true + }, + [3] = { + .attribute = "KeyString", + .type = t_string, + .addr.string = string1, + .nodefault = true, + .len = sizeof(string1) + }, + [4] = { + .attribute = "KeyStringN", + .type = t_string, + .addr.string = string2, + .nodefault = true, + .len = sizeof(string2) + }, + [5] = { + .attribute = "KeyIntArr", + .type = t_array, + .addr.array = { + .element_type = t_integer, + .arr.integers.store = intarr, + .maxlen = sizeof intarr / sizeof intarr[0], + .count = &array_count, + }, + .nodefault = true, + .len = sizeof(intarr) + }, + [6] = { + .attribute = NULL + } + }; + + test_buf_init(&tjb, output); + + rc = json_read_object(&tjb.json_buf, test_attr); + TEST_ASSERT(rc==0); + TEST_ASSERT(bool_val == 1); + TEST_ASSERT(int_val == -1234); + TEST_ASSERT(uint_val == 1353214); + + rc = memcmp(string1, "foobar", strlen("foobar")); + TEST_ASSERT(rc==0); + + rc = memcmp(string2, "foobarlongstring", 10); + TEST_ASSERT(rc==0); + + TEST_ASSERT(array_count == 3); + TEST_ASSERT(intarr[0] == 153); + TEST_ASSERT(intarr[1] == 2532); + TEST_ASSERT(intarr[2] == -322); + + /*testing for the boolean*/ + struct json_attr_t test_attr1[2] = { + [0] = { + .attribute = "KeyBoolArr", + .type = t_array, + .addr.array = { + .element_type = t_boolean, + .arr.booleans.store = boolarr, + .maxlen = sizeof boolarr / sizeof boolarr[0], + .count =&array_count1, + }, + .nodefault = true, + .len = sizeof( boolarr), + }, + + [1] = { + .attribute = "KeyUintArr", + .type = t_array, + .addr.array = { + .element_type = t_uinteger, + .arr.uintegers.store = uintarr, + .maxlen = sizeof uintarr / sizeof uintarr[0], + .count =&array_count1u, + }, + .nodefault = true, + .len = sizeof( uintarr), + } + }; + + test_buf_init(&tjb1, output1); + + rc1 = json_read_object(&tjb1.json_buf, test_attr1); + TEST_ASSERT(rc1==0); + + TEST_ASSERT(boolarr[0] == true); + TEST_ASSERT(boolarr[1] == false); + + TEST_ASSERT(uintarr[0] == 0); + TEST_ASSERT(uintarr[1] == 65535); + TEST_ASSERT(uintarr[2] == 4294967295ULL); + TEST_ASSERT(uintarr[3] == 8589934590ULL); + TEST_ASSERT(uintarr[4] == 3451257ULL); + + /*testing arrays with empty spaces within the elements*/ + struct json_attr_t test_boolspacearr[2] = { + [0] = { + .attribute = "KeyBoolArr", + .type = t_array, + .addr.array = { + .element_type = t_boolean, + .arr.booleans.store = boolspacearr, + .maxlen = sizeof boolspacearr / sizeof boolspacearr[0], + .count =&array_count1, + }, + .nodefault = true, + .len = sizeof( boolspacearr), + } + + }; + + test_buf_init(&tjbboolspacearr, outputboolspace); + + rcbsa = json_read_object(&tjbboolspacearr.json_buf, test_boolspacearr); + TEST_ASSERT(rcbsa == 0); + + TEST_ASSERT(boolspacearr[0] == true); + TEST_ASSERT(boolspacearr[1] == false); + TEST_ASSERT(boolspacearr[2] == true); + + /*testing array with empty value*/ + struct json_attr_t test_boolemptyarr[2] = { + [0] = { + .attribute = "KeyBoolArr", + .type = t_array, + .addr.array = { + .element_type = t_boolean, + .arr.booleans.store = boolemptyarr, + .maxlen = sizeof boolemptyarr / sizeof boolemptyarr[0], + .count =&array_countemp, + }, + .nodefault = true, + .len = sizeof( boolemptyarr), + } + }; + + test_buf_init(&tjbboolemptyarr, outputboolempty); + + rcbsa = json_read_object(&tjbboolemptyarr.json_buf, test_boolemptyarr); + TEST_ASSERT(rcbsa == 6); + +}