http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/overwrite_three_test.c ---------------------------------------------------------------------- diff --git a/fs/nffs/test/src/testcases/overwrite_three_test.c b/fs/nffs/test/src/testcases/overwrite_three_test.c new file mode 100644 index 0000000..37ba872 --- /dev/null +++ b/fs/nffs/test/src/testcases/overwrite_three_test.c @@ -0,0 +1,167 @@ +/** + * 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 "nffs_test_utils.h" + +TEST_CASE(nffs_test_overwrite_three) +{ + struct nffs_test_block_desc *blocks = (struct nffs_test_block_desc[]) { { + .data = "abcdefgh", + .data_len = 8, + }, { + .data = "ijklmnop", + .data_len = 8, + }, { + .data = "qrstuvwx", + .data_len = 8, + } }; + + struct fs_file *file; + int rc; + + + /*** Setup. */ + rc = nffs_format(nffs_current_area_descs); + TEST_ASSERT(rc == 0); + + /*** Overwrite three blocks (middle). */ + nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3); + rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 24); + TEST_ASSERT(fs_getpos(file) == 0); + + rc = fs_seek(file, 6); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 24); + TEST_ASSERT(fs_getpos(file) == 6); + + rc = fs_write(file, "1234567890!@", 12); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 24); + TEST_ASSERT(fs_getpos(file) == 18); + + rc = fs_close(file); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_contents( "/myfile.txt", + "abcdef1234567890!@stuvwx", 24); + nffs_test_util_assert_block_count("/myfile.txt", 3); + + /*** Overwrite three blocks (start). */ + nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3); + rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 24); + TEST_ASSERT(fs_getpos(file) == 0); + + rc = fs_write(file, "1234567890!@#$%^&*()", 20); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 24); + TEST_ASSERT(fs_getpos(file) == 20); + + rc = fs_close(file); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_contents( "/myfile.txt", + "1234567890!@#$%^&*()uvwx", 24); + nffs_test_util_assert_block_count("/myfile.txt", 3); + + /*** Overwrite three blocks (end). */ + nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3); + rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 24); + TEST_ASSERT(fs_getpos(file) == 0); + + rc = fs_seek(file, 6); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 24); + TEST_ASSERT(fs_getpos(file) == 6); + + rc = fs_write(file, "1234567890!@#$%^&*", 18); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 24); + TEST_ASSERT(fs_getpos(file) == 24); + + rc = fs_close(file); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_contents( "/myfile.txt", + "abcdef1234567890!@#$%^&*", 24); + nffs_test_util_assert_block_count("/myfile.txt", 3); + + /*** Overwrite three blocks middle, extend. */ + nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3); + rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 24); + TEST_ASSERT(fs_getpos(file) == 0); + + rc = fs_seek(file, 6); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 24); + TEST_ASSERT(fs_getpos(file) == 6); + + rc = fs_write(file, "1234567890!@#$%^&*()", 20); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 26); + TEST_ASSERT(fs_getpos(file) == 26); + + rc = fs_close(file); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_contents( "/myfile.txt", + "abcdef1234567890!@#$%^&*()", 26); + nffs_test_util_assert_block_count("/myfile.txt", 3); + + /*** Overwrite three blocks start, extend. */ + nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3); + rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 24); + TEST_ASSERT(fs_getpos(file) == 0); + + rc = fs_write(file, "1234567890!@#$%^&*()abcdefghij", 30); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 30); + TEST_ASSERT(fs_getpos(file) == 30); + + rc = fs_close(file); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_contents( "/myfile.txt", + "1234567890!@#$%^&*()abcdefghij", 30); + nffs_test_util_assert_block_count("/myfile.txt", 3); + + struct nffs_test_file_desc *expected_system = + (struct nffs_test_file_desc[]) { { + .filename = "", + .is_dir = 1, + .children = (struct nffs_test_file_desc[]) { { + .filename = "myfile.txt", + .contents = "1234567890!@#$%^&*()abcdefghij", + .contents_len = 30, + }, { + .filename = NULL, + } }, + } }; + + nffs_test_assert_system(expected_system, nffs_current_area_descs); +}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/overwrite_two_test.c ---------------------------------------------------------------------- diff --git a/fs/nffs/test/src/testcases/overwrite_two_test.c b/fs/nffs/test/src/testcases/overwrite_two_test.c new file mode 100644 index 0000000..8082367 --- /dev/null +++ b/fs/nffs/test/src/testcases/overwrite_two_test.c @@ -0,0 +1,159 @@ +/** + * 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 "nffs_test_utils.h" + +TEST_CASE(nffs_test_overwrite_two) +{ + struct nffs_test_block_desc *blocks = (struct nffs_test_block_desc[]) { { + .data = "abcdefgh", + .data_len = 8, + }, { + .data = "ijklmnop", + .data_len = 8, + } }; + + struct fs_file *file; + int rc; + + + /*** Setup. */ + rc = nffs_format(nffs_current_area_descs); + TEST_ASSERT(rc == 0); + + /*** Overwrite two blocks (middle). */ + nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2); + rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 16); + TEST_ASSERT(fs_getpos(file) == 0); + + rc = fs_seek(file, 7); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 16); + TEST_ASSERT(fs_getpos(file) == 7); + + rc = fs_write(file, "123", 3); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 16); + TEST_ASSERT(fs_getpos(file) == 10); + + rc = fs_close(file); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_contents( "/myfile.txt", "abcdefg123klmnop", 16); + nffs_test_util_assert_block_count("/myfile.txt", 2); + + /*** Overwrite two blocks (start). */ + nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2); + rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 16); + TEST_ASSERT(fs_getpos(file) == 0); + + rc = fs_write(file, "ABCDEFGHIJ", 10); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 16); + TEST_ASSERT(fs_getpos(file) == 10); + + rc = fs_close(file); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_contents( "/myfile.txt", "ABCDEFGHIJklmnop", 16); + nffs_test_util_assert_block_count("/myfile.txt", 2); + + /*** Overwrite two blocks (end). */ + nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2); + rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 16); + TEST_ASSERT(fs_getpos(file) == 0); + + rc = fs_seek(file, 6); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 16); + TEST_ASSERT(fs_getpos(file) == 6); + + rc = fs_write(file, "1234567890", 10); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 16); + TEST_ASSERT(fs_getpos(file) == 16); + + rc = fs_close(file); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_contents( "/myfile.txt", "abcdef1234567890", 16); + nffs_test_util_assert_block_count("/myfile.txt", 2); + + /*** Overwrite two blocks middle, extend. */ + nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2); + rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 16); + TEST_ASSERT(fs_getpos(file) == 0); + + rc = fs_seek(file, 6); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 16); + TEST_ASSERT(fs_getpos(file) == 6); + + rc = fs_write(file, "1234567890!@#$", 14); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 20); + TEST_ASSERT(fs_getpos(file) == 20); + + rc = fs_close(file); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_contents( "/myfile.txt", "abcdef1234567890!@#$", 20); + nffs_test_util_assert_block_count("/myfile.txt", 2); + + /*** Overwrite two blocks start, extend. */ + nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2); + rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 16); + TEST_ASSERT(fs_getpos(file) == 0); + + rc = fs_write(file, "1234567890!@#$%^&*()", 20); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 20); + TEST_ASSERT(fs_getpos(file) == 20); + + rc = fs_close(file); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_contents( "/myfile.txt", "1234567890!@#$%^&*()", 20); + nffs_test_util_assert_block_count("/myfile.txt", 2); + + struct nffs_test_file_desc *expected_system = + (struct nffs_test_file_desc[]) { { + .filename = "", + .is_dir = 1, + .children = (struct nffs_test_file_desc[]) { { + .filename = "myfile.txt", + .contents = "1234567890!@#$%^&*()", + .contents_len = 20, + }, { + .filename = NULL, + } }, + } }; + + nffs_test_assert_system(expected_system, nffs_current_area_descs); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/read_test.c ---------------------------------------------------------------------- diff --git a/fs/nffs/test/src/testcases/read_test.c b/fs/nffs/test/src/testcases/read_test.c new file mode 100644 index 0000000..a21e16f --- /dev/null +++ b/fs/nffs/test/src/testcases/read_test.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 "nffs_test_utils.h" + +TEST_CASE(nffs_test_read) +{ + struct fs_file *file; + uint8_t buf[16]; + uint32_t bytes_read; + int rc; + + rc = nffs_format(nffs_current_area_descs); + TEST_ASSERT(rc == 0); + + nffs_test_util_create_file("/myfile.txt", "1234567890", 10); + + rc = fs_open("/myfile.txt", FS_ACCESS_READ, &file); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 10); + TEST_ASSERT(fs_getpos(file) == 0); + + rc = fs_read(file, 4, buf, &bytes_read); + TEST_ASSERT(rc == 0); + TEST_ASSERT(bytes_read == 4); + TEST_ASSERT(memcmp(buf, "1234", 4) == 0); + TEST_ASSERT(fs_getpos(file) == 4); + + rc = fs_read(file, sizeof buf - 4, buf + 4, &bytes_read); + TEST_ASSERT(rc == 0); + TEST_ASSERT(bytes_read == 6); + TEST_ASSERT(memcmp(buf, "1234567890", 10) == 0); + TEST_ASSERT(fs_getpos(file) == 10); + + rc = fs_close(file); + TEST_ASSERT(rc == 0); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/readdir_test.c ---------------------------------------------------------------------- diff --git a/fs/nffs/test/src/testcases/readdir_test.c b/fs/nffs/test/src/testcases/readdir_test.c new file mode 100644 index 0000000..aa52035 --- /dev/null +++ b/fs/nffs/test/src/testcases/readdir_test.c @@ -0,0 +1,124 @@ +/** + * 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 "nffs_test_utils.h" + +TEST_CASE(nffs_test_readdir) +{ + struct fs_dirent *dirent; + struct fs_dir *dir; + int rc; + + /*** Setup. */ + rc = nffs_format(nffs_current_area_descs); + TEST_ASSERT_FATAL(rc == 0); + + rc = fs_mkdir("/mydir"); + TEST_ASSERT_FATAL(rc == 0); + + nffs_test_util_create_file("/mydir/b", "bbbb", 4); + nffs_test_util_create_file("/mydir/a", "aaaa", 4); + rc = fs_mkdir("/mydir/c"); + TEST_ASSERT_FATAL(rc == 0); + + /* Nonexistent directory. */ + rc = fs_opendir("/asdf", &dir); + TEST_ASSERT(rc == FS_ENOENT); + + /* Fail to opendir a file. */ + rc = fs_opendir("/mydir/a", &dir); + TEST_ASSERT(rc == FS_EINVAL); + + /* Real directory (with trailing slash). */ + rc = fs_opendir("/mydir/", &dir); + TEST_ASSERT_FATAL(rc == 0); + + rc = fs_readdir(dir, &dirent); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_ent_name(dirent, "a"); + TEST_ASSERT(fs_dirent_is_dir(dirent) == 0); + + rc = fs_readdir(dir, &dirent); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_ent_name(dirent, "b"); + TEST_ASSERT(fs_dirent_is_dir(dirent) == 0); + + rc = fs_readdir(dir, &dirent); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_ent_name(dirent, "c"); + TEST_ASSERT(fs_dirent_is_dir(dirent) == 1); + + rc = fs_readdir(dir, &dirent); + TEST_ASSERT(rc == FS_ENOENT); + + rc = fs_closedir(dir); + TEST_ASSERT(rc == 0); + + /* Root directory. */ + rc = fs_opendir("/", &dir); + TEST_ASSERT(rc == 0); + rc = fs_readdir(dir, &dirent); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_ent_name(dirent, "lost+found"); + TEST_ASSERT(fs_dirent_is_dir(dirent) == 1); + + rc = fs_readdir(dir, &dirent); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_ent_name(dirent, "mydir"); + TEST_ASSERT(fs_dirent_is_dir(dirent) == 1); + + rc = fs_closedir(dir); + TEST_ASSERT(rc == 0); + + /* Delete entries while iterating. */ + rc = fs_opendir("/mydir", &dir); + TEST_ASSERT_FATAL(rc == 0); + + rc = fs_readdir(dir, &dirent); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_ent_name(dirent, "a"); + TEST_ASSERT(fs_dirent_is_dir(dirent) == 0); + + rc = fs_unlink("/mydir/b"); + TEST_ASSERT(rc == 0); + + rc = fs_readdir(dir, &dirent); + TEST_ASSERT(rc == 0); + + rc = fs_unlink("/mydir/c"); + TEST_ASSERT(rc == 0); + + rc = fs_unlink("/mydir"); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_ent_name(dirent, "c"); + TEST_ASSERT(fs_dirent_is_dir(dirent) == 1); + + rc = fs_readdir(dir, &dirent); + TEST_ASSERT(rc == FS_ENOENT); + + rc = fs_closedir(dir); + TEST_ASSERT(rc == 0); + + /* Ensure directory is gone. */ + rc = fs_opendir("/mydir", &dir); + TEST_ASSERT(rc == FS_ENOENT); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/rename_test.c ---------------------------------------------------------------------- diff --git a/fs/nffs/test/src/testcases/rename_test.c b/fs/nffs/test/src/testcases/rename_test.c new file mode 100644 index 0000000..e35456d --- /dev/null +++ b/fs/nffs/test/src/testcases/rename_test.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 "nffs_test_utils.h" + +TEST_CASE(nffs_test_rename) +{ + struct fs_file *file; + const char contents[] = "contents"; + int rc; + + + rc = nffs_format(nffs_current_area_descs); + TEST_ASSERT(rc == 0); + + rc = fs_rename("/nonexistent.txt", "/newname.txt"); + TEST_ASSERT(rc == FS_ENOENT); + + /*** Rename file. */ + nffs_test_util_create_file("/myfile.txt", contents, sizeof contents); + + rc = fs_rename("/myfile.txt", "badname"); + TEST_ASSERT(rc == FS_EINVAL); + + rc = fs_rename("/myfile.txt", "/myfile2.txt"); + TEST_ASSERT(rc == 0); + + rc = fs_open("/myfile.txt", FS_ACCESS_READ, &file); + TEST_ASSERT(rc == FS_ENOENT); + + nffs_test_util_assert_contents("/myfile2.txt", contents, sizeof contents); + + rc = fs_mkdir("/mydir"); + TEST_ASSERT(rc == 0); + + rc = fs_mkdir("/mydir/leafdir"); + TEST_ASSERT(rc == 0); + + rc = fs_rename("/myfile2.txt", "/mydir/myfile2.txt"); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_contents("/mydir/myfile2.txt", contents, + sizeof contents); + + /*** Rename directory. */ + rc = fs_rename("/mydir", "badname"); + TEST_ASSERT(rc == FS_EINVAL); + + /* Don't allow a directory to be moved into a descendent directory. */ + rc = fs_rename("/mydir", "/mydir/leafdir/a"); + TEST_ASSERT(rc == FS_EINVAL); + + rc = fs_rename("/mydir", "/mydir2"); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_contents("/mydir2/myfile2.txt", contents, + sizeof contents); + + struct nffs_test_file_desc *expected_system = + (struct nffs_test_file_desc[]) { { + .filename = "", + .is_dir = 1, + .children = (struct nffs_test_file_desc[]) { { + .filename = "mydir2", + .is_dir = 1, + .children = (struct nffs_test_file_desc[]) { { + .filename = "leafdir", + .is_dir = 1, + }, { + .filename = "myfile2.txt", + .contents = "contents", + .contents_len = 9, + }, { + .filename = NULL, + } }, + }, { + .filename = NULL, + } }, + } }; + + nffs_test_assert_system(expected_system, nffs_current_area_descs); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/split_file_test.c ---------------------------------------------------------------------- diff --git a/fs/nffs/test/src/testcases/split_file_test.c b/fs/nffs/test/src/testcases/split_file_test.c new file mode 100644 index 0000000..a152bdc --- /dev/null +++ b/fs/nffs/test/src/testcases/split_file_test.c @@ -0,0 +1,65 @@ +/** + * 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 "nffs_test_utils.h" + +TEST_CASE(nffs_test_split_file) +{ + static char data[24 * 1024]; + int rc; + int i; + + /*** Setup. */ + static const struct nffs_area_desc area_descs_two[] = { + { 0x00000000, 16 * 1024 }, + { 0x00004000, 16 * 1024 }, + { 0x00008000, 16 * 1024 }, + { 0, 0 }, + }; + + rc = nffs_format(area_descs_two); + TEST_ASSERT(rc == 0); + + for (i = 0; i < sizeof data; i++) { + data[i] = i; + } + + for (i = 0; i < 256; i++) { + nffs_test_util_create_file("/myfile.txt", data, sizeof data); + rc = fs_unlink("/myfile.txt"); + TEST_ASSERT(rc == 0); + } + + nffs_test_util_create_file("/myfile.txt", data, sizeof data); + + struct nffs_test_file_desc *expected_system = + (struct nffs_test_file_desc[]) { { + .filename = "", + .is_dir = 1, + .children = (struct nffs_test_file_desc[]) { { + .filename = "myfile.txt", + .contents = data, + .contents_len = sizeof data, + }, { + .filename = NULL, + } }, + } }; + + nffs_test_assert_system(expected_system, area_descs_two); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/truncate_test.c ---------------------------------------------------------------------- diff --git a/fs/nffs/test/src/testcases/truncate_test.c b/fs/nffs/test/src/testcases/truncate_test.c new file mode 100644 index 0000000..cf78540 --- /dev/null +++ b/fs/nffs/test/src/testcases/truncate_test.c @@ -0,0 +1,73 @@ +/** + * 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 "nffs_test_utils.h" + +TEST_CASE(nffs_test_truncate) +{ + struct fs_file *file; + int rc; + + + rc = nffs_format(nffs_current_area_descs); + TEST_ASSERT(rc == 0); + + rc = fs_open("/myfile.txt", FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE, &file); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 0); + TEST_ASSERT(fs_getpos(file) == 0); + + rc = fs_write(file, "abcdefgh", 8); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 8); + TEST_ASSERT(fs_getpos(file) == 8); + rc = fs_close(file); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_contents("/myfile.txt", "abcdefgh", 8); + + rc = fs_open("/myfile.txt", FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE, &file); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 0); + TEST_ASSERT(fs_getpos(file) == 0); + + rc = fs_write(file, "1234", 4); + TEST_ASSERT(rc == 0); + nffs_test_util_assert_file_len(file, 4); + TEST_ASSERT(fs_getpos(file) == 4); + rc = fs_close(file); + TEST_ASSERT(rc == 0); + + nffs_test_util_assert_contents("/myfile.txt", "1234", 4); + + struct nffs_test_file_desc *expected_system = + (struct nffs_test_file_desc[]) { { + .filename = "", + .is_dir = 1, + .children = (struct nffs_test_file_desc[]) { { + .filename = "myfile.txt", + .contents = "1234", + .contents_len = 4, + }, { + .filename = NULL, + } }, + } }; + + nffs_test_assert_system(expected_system, nffs_current_area_descs); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/unlink_test.c ---------------------------------------------------------------------- diff --git a/fs/nffs/test/src/testcases/unlink_test.c b/fs/nffs/test/src/testcases/unlink_test.c new file mode 100644 index 0000000..e28d19c --- /dev/null +++ b/fs/nffs/test/src/testcases/unlink_test.c @@ -0,0 +1,121 @@ +/** + * 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 "nffs_test_utils.h" + +TEST_CASE(nffs_test_unlink) +{ + struct fs_file *file0; + struct fs_file *file2; + uint8_t buf[64]; + struct nffs_file *nfs_file; + uint32_t bytes_read; + struct fs_file *file1; + int initial_num_blocks; + int initial_num_inodes; + int rc; + + rc = nffs_format(nffs_current_area_descs); + TEST_ASSERT_FATAL(rc == 0); + + initial_num_blocks = nffs_block_entry_pool.mp_num_free; + initial_num_inodes = nffs_inode_entry_pool.mp_num_free; + + nffs_test_util_create_file("/file0.txt", "0", 1); + + rc = fs_open("/file0.txt", FS_ACCESS_READ | FS_ACCESS_WRITE, &file0); + TEST_ASSERT(rc == 0); + nfs_file = (struct nffs_file *)file0; + TEST_ASSERT(nfs_file->nf_inode_entry->nie_refcnt == 2); + + rc = fs_unlink("/file0.txt"); + TEST_ASSERT(rc == 0); + TEST_ASSERT(nfs_file->nf_inode_entry->nie_refcnt == 1); + + rc = fs_open("/file0.txt", FS_ACCESS_READ, &file2); + TEST_ASSERT(rc == FS_ENOENT); + + rc = fs_write(file0, "00", 2); + TEST_ASSERT(rc == 0); + + rc = fs_seek(file0, 0); + TEST_ASSERT(rc == 0); + + rc = fs_read(file0, sizeof buf, buf, &bytes_read); + TEST_ASSERT(rc == 0); + TEST_ASSERT(bytes_read == 2); + TEST_ASSERT(memcmp(buf, "00", 2) == 0); + + rc = fs_close(file0); + TEST_ASSERT(rc == 0); + + + rc = fs_open("/file0.txt", FS_ACCESS_READ, &file0); + TEST_ASSERT(rc == FS_ENOENT); + + /* Ensure the file was fully removed from RAM. */ + TEST_ASSERT(nffs_inode_entry_pool.mp_num_free == initial_num_inodes); + TEST_ASSERT(nffs_block_entry_pool.mp_num_free == initial_num_blocks); + + /*** Nested unlink. */ + rc = fs_mkdir("/mydir"); + TEST_ASSERT(rc == 0); + nffs_test_util_create_file("/mydir/file1.txt", "1", 2); + + rc = fs_open("/mydir/file1.txt", FS_ACCESS_READ | FS_ACCESS_WRITE, &file1); + TEST_ASSERT(rc == 0); + nfs_file = (struct nffs_file *)file1; + TEST_ASSERT(nfs_file->nf_inode_entry->nie_refcnt == 2); + + rc = fs_unlink("/mydir"); + TEST_ASSERT(rc == 0); + TEST_ASSERT(nfs_file->nf_inode_entry->nie_refcnt == 1); + + rc = fs_open("/mydir/file1.txt", FS_ACCESS_READ, &file2); + TEST_ASSERT(rc == FS_ENOENT); + + rc = fs_write(file1, "11", 2); + TEST_ASSERT(rc == 0); + + rc = fs_seek(file1, 0); + TEST_ASSERT(rc == 0); + + rc = fs_read(file1, sizeof buf, buf, &bytes_read); + TEST_ASSERT(rc == 0); + TEST_ASSERT(bytes_read == 2); + TEST_ASSERT(memcmp(buf, "11", 2) == 0); + + rc = fs_close(file1); + TEST_ASSERT(rc == 0); + + rc = fs_open("/mydir/file1.txt", FS_ACCESS_READ, &file1); + TEST_ASSERT(rc == FS_ENOENT); + + struct nffs_test_file_desc *expected_system = + (struct nffs_test_file_desc[]) { { + .filename = "", + .is_dir = 1, + } }; + + nffs_test_assert_system(expected_system, nffs_current_area_descs); + + /* Ensure the files and directories were fully removed from RAM. */ + TEST_ASSERT(nffs_inode_entry_pool.mp_num_free == initial_num_inodes); + TEST_ASSERT(nffs_block_entry_pool.mp_num_free == initial_num_blocks); +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/wear_level_test.c ---------------------------------------------------------------------- diff --git a/fs/nffs/test/src/testcases/wear_level_test.c b/fs/nffs/test/src/testcases/wear_level_test.c new file mode 100644 index 0000000..2afcc7b --- /dev/null +++ b/fs/nffs/test/src/testcases/wear_level_test.c @@ -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. + */ + +#include "nffs_test_utils.h" + +TEST_CASE(nffs_test_wear_level) +{ + int rc; + int i; + int j; + + static const struct nffs_area_desc area_descs_uniform[] = { + { 0x00000000, 2 * 1024 }, + { 0x00020000, 2 * 1024 }, + { 0x00040000, 2 * 1024 }, + { 0x00060000, 2 * 1024 }, + { 0x00080000, 2 * 1024 }, + { 0, 0 }, + }; + + /*** Setup. */ + rc = nffs_format(area_descs_uniform); + TEST_ASSERT(rc == 0); + + /* Ensure areas rotate properly. */ + for (i = 0; i < 255; i++) { + for (j = 0; j < nffs_num_areas; j++) { + nffs_test_assert_area_seqs(i, nffs_num_areas - j, i + 1, j); + nffs_gc(NULL); + } + } + + /* Ensure proper rollover of sequence numbers. */ + for (j = 0; j < nffs_num_areas; j++) { + nffs_test_assert_area_seqs(255, nffs_num_areas - j, 0, j); + nffs_gc(NULL); + } + for (j = 0; j < nffs_num_areas; j++) { + nffs_test_assert_area_seqs(0, nffs_num_areas - j, 1, j); + nffs_gc(NULL); + } +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/hw/bsp/native/syscfg.yml ---------------------------------------------------------------------- diff --git a/hw/bsp/native/syscfg.yml b/hw/bsp/native/syscfg.yml index d648bb0..fb238e0 100644 --- a/hw/bsp/native/syscfg.yml +++ b/hw/bsp/native/syscfg.yml @@ -1,2 +1,3 @@ syscfg.vals: NFFS_FLASH_AREA: FLASH_AREA_NFFS + CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/arch/cortex_m4/os_test_arch_arm.c ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/arch/cortex_m4/os_test_arch_arm.c b/kernel/os/test/src/arch/cortex_m4/os_test_arch_arm.c deleted file mode 100644 index 35134f7..0000000 --- a/kernel/os/test/src/arch/cortex_m4/os_test_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 "testutil/testutil.h" -#include "os_test_priv.h" - -void -os_test_restart(void) -{ - tu_restart(); -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/arch/sim/os_test_arch_sim.c ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/arch/sim/os_test_arch_sim.c b/kernel/os/test/src/arch/sim/os_test_arch_sim.c deleted file mode 100644 index 3b6cfbf..0000000 --- a/kernel/os/test/src/arch/sim/os_test_arch_sim.c +++ /dev/null @@ -1,52 +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 <setjmp.h> -#include <signal.h> -#include <string.h> -#include <sys/time.h> -#include "testutil/testutil.h" -#include "os/os.h" -#include "os_test_priv.h" - -void -os_test_restart(void) -{ - struct sigaction sa; - struct itimerval it; - int rc; - - g_os_started = 0; - - memset(&sa, 0, sizeof sa); - sa.sa_handler = SIG_IGN; - - sigaction(SIGALRM, &sa, NULL); - sigaction(SIGVTALRM, &sa, NULL); - - memset(&it, 0, sizeof(it)); - rc = setitimer(ITIMER_VIRTUAL, &it, NULL); - if (rc != 0) { - perror("Cannot set itimer"); - abort(); - } - - tu_restart(); -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/callout_test.c ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/callout_test.c b/kernel/os/test/src/callout_test.c index 8353217..72e44a5 100644 --- a/kernel/os/test/src/callout_test.c +++ b/kernel/os/test/src/callout_test.c @@ -16,19 +16,15 @@ * specific language governing permissions and limitations * under the License. */ - #include "sysinit/sysinit.h" #include "testutil/testutil.h" #include "os/os.h" #include "os_test_priv.h" /* Task 1 for sending */ -#define CALLOUT_STACK_SIZE (5120) -#define SEND_CALLOUT_TASK_PRIO (1) struct os_task callout_task_struct_send; os_stack_t callout_task_stack_send[CALLOUT_STACK_SIZE]; -#define RECEIVE_CALLOUT_TASK_PRIO (2) struct os_task callout_task_struct_receive; os_stack_t callout_task_stack_receive[CALLOUT_STACK_SIZE]; @@ -40,16 +36,13 @@ struct os_eventq callout_evq; struct os_event callout_ev; /* The callout_stop task */ -#define SEND_STOP_CALLOUT_TASK_PRIO (3) struct os_task callout_task_struct_stop_send; os_stack_t callout_task_stack_stop_send[CALLOUT_STACK_SIZE]; -#define RECEIVE_STOP_CALLOUT_TASK_PRIO (4) struct os_task callout_task_struct_stop_receive; os_stack_t callout_task_stack_stop_receive[CALLOUT_STACK_SIZE]; /* Delearing variables for callout_stop_func */ -#define MULTI_SIZE (2) struct os_callout_func callout_func_stop_test[MULTI_SIZE]; /* The event to be sent*/ @@ -57,12 +50,10 @@ struct os_eventq callout_stop_evq[MULTI_SIZE]; struct os_event callout_stop_ev; /* Declearing varables for callout_speak */ -#define SPEAK_CALLOUT_TASK_PRIO (5) struct os_task callout_task_struct_speak; os_stack_t callout_task_stack_speak[CALLOUT_STACK_SIZE]; /* Declearing varaibles for listen */ -#define LISTEN_CALLOUT_TASK_PRIO (6) struct os_task callout_task_struct_listen; os_stack_t callout_task_stack_listen[CALLOUT_STACK_SIZE]; @@ -72,6 +63,7 @@ struct os_callout_func callout_func_speak; int p; int q; int t; + /* This is the function for callout_init*/ void my_callout_func(void *arg) @@ -235,90 +227,9 @@ callout_task_stop_listen( void *arg ) } -/* Test case to test the basics of the callout */ -TEST_CASE(callout_test) -{ - - /* Initializing the OS */ - sysinit(); - - /* Initialize the sending task */ - os_task_init(&callout_task_struct_send, "callout_task_send", - callout_task_send, NULL, SEND_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER, - callout_task_stack_send, CALLOUT_STACK_SIZE); - - /* Initialize the receive task */ - os_task_init(&callout_task_struct_receive, "callout_task_receive", - callout_task_receive, NULL, RECEIVE_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER, - callout_task_stack_receive, CALLOUT_STACK_SIZE); - - os_eventq_init(&callout_evq); - - /* Initialize the callout function */ - os_callout_func_init(&callout_func_test, &callout_evq, - my_callout_func, NULL); - - /* Does not return until OS_restart is called */ - os_start(); -} - -/* Test case of the callout_task_stop */ -TEST_CASE(callout_test_stop) -{ - int k; - /* Initializing the OS */ - sysinit(); - - /* Initialize the sending task */ - os_task_init(&callout_task_struct_stop_send, "callout_task_stop_send", - callout_task_stop_send, NULL, SEND_STOP_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER, - callout_task_stack_stop_send, CALLOUT_STACK_SIZE); - - /* Initialize the receiving task */ - os_task_init(&callout_task_struct_stop_receive, "callout_task_stop_receive", - callout_task_stop_receive, NULL, RECEIVE_STOP_CALLOUT_TASK_PRIO, - OS_WAIT_FOREVER, callout_task_stack_stop_receive, CALLOUT_STACK_SIZE); - - for(k = 0; k< MULTI_SIZE; k++){ - os_eventq_init(&callout_stop_evq[k]); - } - - /* Initialize the callout function */ - for(k = 0; k<MULTI_SIZE; k++){ - os_callout_func_init(&callout_func_stop_test[k], &callout_stop_evq[k], - my_callout_stop_func, NULL); - } - - /* Does not return until OS_restart is called */ - os_start(); - -} - -/* Test case to test case for speak and listen */ -TEST_CASE(callout_test_speak) -{ - /* Initializing the OS */ - sysinit(); - - /* Initialize the sending task */ - os_task_init(&callout_task_struct_speak, "callout_task_speak", - callout_task_stop_speak, NULL, SPEAK_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER, - callout_task_stack_speak, CALLOUT_STACK_SIZE); - - /* Initialize the receive task */ - os_task_init(&callout_task_struct_listen, "callout_task_listen", - callout_task_stop_listen, NULL, LISTEN_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER, - callout_task_stack_listen, CALLOUT_STACK_SIZE); - - os_eventq_init(&callout_evq); - - /* Initialize the callout function */ - os_callout_func_init(&callout_func_speak, &callout_evq, - my_callout_speak_func, NULL); - /* Does not return until OS_restart is called */ - os_start(); - -} +TEST_CASE_DECL(callout_test_speak) +TEST_CASE_DECL(callout_test_stop) +TEST_CASE_DECL(callout_test) TEST_SUITE(os_callout_test_suite) { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/callout_test.h ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/callout_test.h b/kernel/os/test/src/callout_test.h new file mode 100644 index 0000000..3e0d94d --- /dev/null +++ b/kernel/os/test/src/callout_test.h @@ -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. + */ +#ifndef _CALLOUT_TEST_H +#define _CALLOUT_TEST_H + +#include "sysinit/sysinit.h" +#include "testutil/testutil.h" +#include "os/os.h" +#include "os_test_priv.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Task 1 for sending */ +#define CALLOUT_STACK_SIZE (5120) +#define SEND_CALLOUT_TASK_PRIO (1) +extern struct os_task callout_task_struct_send; +extern os_stack_t callout_task_stack_send[CALLOUT_STACK_SIZE]; + +#define RECEIVE_CALLOUT_TASK_PRIO (2) +extern struct os_task callout_task_struct_receive; +extern os_stack_t callout_task_stack_receive[CALLOUT_STACK_SIZE]; + +/* Delearing variables for callout_func */ +extern struct os_callout_func callout_func_test; + +/* The event to be sent*/ +extern struct os_eventq callout_evq; +extern struct os_event callout_ev; + +/* The callout_stop task */ +#define SEND_STOP_CALLOUT_TASK_PRIO (3) +extern struct os_task callout_task_struct_stop_send; +extern os_stack_t callout_task_stack_stop_send[CALLOUT_STACK_SIZE]; + +#define RECEIVE_STOP_CALLOUT_TASK_PRIO (4) +extern struct os_task callout_task_struct_stop_receive; +extern os_stack_t callout_task_stack_stop_receive[CALLOUT_STACK_SIZE]; + +/* Delearing variables for callout_stop_func */ +#define MULTI_SIZE (2) +extern struct os_callout_func callout_func_stop_test[MULTI_SIZE]; + +/* The event to be sent*/ +extern struct os_eventq callout_stop_evq[MULTI_SIZE]; +extern struct os_event callout_stop_ev; + +/* Declearing varables for callout_speak */ +#define SPEAK_CALLOUT_TASK_PRIO (5) +extern struct os_task callout_task_struct_speak; +extern os_stack_t callout_task_stack_speak[CALLOUT_STACK_SIZE]; + +/* Declearing varaibles for listen */ +#define LISTEN_CALLOUT_TASK_PRIO (6) +extern struct os_task callout_task_struct_listen; +extern os_stack_t callout_task_stack_listen[CALLOUT_STACK_SIZE]; + +extern struct os_callout_func callout_func_speak; + +/* Global variables to be used by the callout functions */ +extern int p; +extern int q; +extern int t; + +void my_callout_func(void *arg); +void my_callout_stop_func(void *arg); +void my_callout_speak_func(void *arg); +void callout_task_send(void *arg); +void callout_task_receive(void *arg); +void callout_task_stop_send(void *arg); +void callout_task_stop_receive(void *arg); +void callout_task_stop_speak(void *arg); +void callout_task_stop_listen(void *arg); + +#ifdef __cplusplus +} +#endif + +#endif /* _CALLOUT_TEST_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/eventq_test.c ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/eventq_test.c b/kernel/os/test/src/eventq_test.c index a891f0c..77c24a6 100644 --- a/kernel/os/test/src/eventq_test.c +++ b/kernel/os/test/src/eventq_test.c @@ -82,6 +82,12 @@ os_stack_t eventq_task_stack_poll_single_s[POLL_STACK_SIZE]; struct os_task eventq_task_poll_single_r; os_stack_t eventq_task_stack_poll_single_r[POLL_STACK_SIZE]; +TEST_CASE_DECL(event_test_sr) +TEST_CASE_DECL(event_test_poll_sr) +TEST_CASE_DECL(event_test_poll_timeout_sr) +TEST_CASE_DECL(event_test_poll_single_sr) +TEST_CASE_DECL(event_test_poll_0timo) + /* This is the task function to send data */ void eventq_task_send(void *arg) @@ -261,152 +267,6 @@ eventq_task_poll_single_receive(void *arg) os_test_restart(); } -TEST_CASE(event_test_sr) -{ - int i; - - /* Initializing the OS */ - sysinit(); - /* Initialize the task */ - os_task_init(&eventq_task_s, "eventq_task_s", eventq_task_send, NULL, - SEND_TASK_PRIO, OS_WAIT_FOREVER, eventq_task_stack_s, MY_STACK_SIZE); - - /* Receive events and check whether the eevnts are correctly received */ - os_task_init(&eventq_task_r, "eventq_task_r", eventq_task_receive, NULL, - RECEIVE_TASK_PRIO, OS_WAIT_FOREVER, eventq_task_stack_r, - MY_STACK_SIZE); - - os_eventq_init(&my_eventq); - - for (i = 0; i < SIZE_MULTI_EVENT; i++){ - os_eventq_init(&multi_eventq[i]); - } - - /* Does not return until OS_restart is called */ - os_start(); - -} - -/* To test for the basic function of os_eventq_poll() */ -TEST_CASE(event_test_poll_sr) -{ - int i; - - /* Initializing the OS */ - sysinit(); - /* Initialize the task */ - os_task_init(&eventq_task_poll_s, "eventq_task_poll_s", eventq_task_poll_send, - NULL, SEND_TASK_POLL_PRIO, OS_WAIT_FOREVER, eventq_task_stack_poll_s, - POLL_STACK_SIZE); - - /* Receive events and check whether the eevnts are correctly received */ - os_task_init(&eventq_task_poll_r, "eventq_task_r", eventq_task_poll_receive, - NULL, RECEIVE_TASK_POLL_PRIO, OS_WAIT_FOREVER, eventq_task_stack_poll_r, - POLL_STACK_SIZE); - - /* Initializing the eventqs. */ - for (i = 0; i < SIZE_MULTI_EVENT; i++){ - os_eventq_init(&multi_eventq[i]); - } - - /* Does not return until OS_restart is called */ - os_start(); - -} - -/* Test case for poll timeout */ -TEST_CASE(event_test_poll_timeout_sr) -{ - int i; - - /* Initializing the OS */ - sysinit(); - /* Initialize the task */ - os_task_init(&eventq_task_poll_timeout_s, "eventq_task_poll_timeout_s", - eventq_task_poll_timeout_send, NULL, SEND_TASK_POLL_TIMEOUT_PRIO, - OS_WAIT_FOREVER, eventq_task_stack_poll_timeout_s, POLL_STACK_SIZE); - - /* Receive events and check whether the eevnts are correctly received */ - os_task_init(&eventq_task_poll_timeout_r, "eventq_task_timeout_r", - eventq_task_poll_timeout_receive, NULL, RECEIVE_TASK_POLL_TIMEOUT_PRIO, - OS_WAIT_FOREVER, eventq_task_stack_poll_timeout_r, POLL_STACK_SIZE); - - /* Initializing the eventqs. */ - for (i = 0; i < SIZE_MULTI_EVENT; i++){ - os_eventq_init(&multi_eventq[i]); - - m_event[i].ev_type = i + 10; - m_event[i].ev_arg = NULL; - } - - /* Does not return until OS_restart is called */ - os_start(); - -} - -/* The case for poll single */ -/* Test case for poll timeout */ -TEST_CASE(event_test_poll_single_sr) -{ - int i; - - /* Initializing the OS */ - sysinit(); - /* Initialize the task */ - os_task_init(&eventq_task_poll_single_s, "eventq_task_poll_single_s", - eventq_task_poll_single_send, NULL, SEND_TASK_POLL_SINGLE_PRIO, - OS_WAIT_FOREVER, eventq_task_stack_poll_single_s, POLL_STACK_SIZE); - - /* Receive events and check whether the eevnts are correctly received */ - os_task_init(&eventq_task_poll_single_r, "eventq_task_single_r", - eventq_task_poll_single_receive, NULL, RECEIVE_TASK_POLL_SINGLE_PRIO, - OS_WAIT_FOREVER, eventq_task_stack_poll_single_r, POLL_STACK_SIZE); - - for (i = 0; i < SIZE_MULTI_EVENT; i++){ - os_eventq_init(&multi_eventq[i]); - - m_event[i].ev_type = 10 * i; - m_event[i].ev_arg = NULL; - } - - /* Does not return until OS_restart is called */ - os_start(); - -} - -/** - * Tests eventq_poll() with a timeout of 0. This should not involve the - * scheduler at all, so it should work without starting the OS. - */ -TEST_CASE(event_test_poll_0timo) -{ - struct os_eventq *eventqs[SIZE_MULTI_EVENT]; - struct os_event *evp; - struct os_event ev; - int i; - - for (i = 0; i < SIZE_MULTI_EVENT; i++){ - os_eventq_init(&multi_eventq[i]); - eventqs[i] = &multi_eventq[i]; - } - - evp = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 0); - TEST_ASSERT(evp == NULL); - - /* Ensure no eventq thinks a task is waiting on it. */ - for (i = 0; i < SIZE_MULTI_EVENT; i++) { - TEST_ASSERT(eventqs[i]->evq_task == NULL); - } - - /* Put an event on one of the queues. */ - memset(&ev, 0, sizeof ev); - ev.ev_type = 1; - os_eventq_put(eventqs[3], &ev); - - evp = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 0); - TEST_ASSERT(evp == &ev); -} - TEST_SUITE(os_eventq_test_suite) { event_test_sr(); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/eventq_test.h ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/eventq_test.h b/kernel/os/test/src/eventq_test.h new file mode 100644 index 0000000..a061b86 --- /dev/null +++ b/kernel/os/test/src/eventq_test.h @@ -0,0 +1,104 @@ +/** + * 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 _EVENTQ_TEST_H +#define _EVENTQ_TEST_H + +#include <string.h> +#include "sysinit/sysinit.h" +#include "testutil/testutil.h" +#include "os/os.h" +#include "os_test_priv.h" +#include "os/os_eventq.h" + +#ifdef __cplusplus +#extern "C" { +#endif + +#define MY_STACK_SIZE (5120) +#define POLL_STACK_SIZE (4096) +/* Task 1 sending task */ +/* Define task stack and task object */ +#define SEND_TASK_PRIO (1) +extern struct os_task eventq_task_s; +extern os_stack_t eventq_task_stack_s[MY_STACK_SIZE]; + +/* Task 2 receiving task */ +#define RECEIVE_TASK_PRIO (2) +extern struct os_task eventq_task_r; +extern os_stack_t eventq_task_stack_r[MY_STACK_SIZE]; + +extern struct os_eventq my_eventq; + +#define SIZE_MULTI_EVENT (4) +extern struct os_eventq multi_eventq[SIZE_MULTI_EVENT]; + +/* This is to set the events we will use below */ +extern struct os_event g_event; +extern struct os_event m_event[SIZE_MULTI_EVENT]; + +/* Setting the event to send and receive multiple data */ +extern uint8_t my_event_type; + +/* Setting up data for the poll */ +/* Define the task stack for the eventq_task_poll_send */ +#define SEND_TASK_POLL_PRIO (3) +extern struct os_task eventq_task_poll_s; +extern os_stack_t eventq_task_stack_poll_s[POLL_STACK_SIZE]; + +/* Define the task stack for the eventq_task_poll_receive */ +#define RECEIVE_TASK_POLL_PRIO (4) +extern struct os_task eventq_task_poll_r; +extern os_stack_t eventq_task_stack_poll_r[POLL_STACK_SIZE ]; + +/* Setting the data for the poll timeout */ +/* Define the task stack for the eventq_task_poll_timeout_send */ +#define SEND_TASK_POLL_TIMEOUT_PRIO (5) +extern struct os_task eventq_task_poll_timeout_s; +extern os_stack_t eventq_task_stack_poll_timeout_s[POLL_STACK_SIZE]; + +/* Define the task stack for the eventq_task_poll_receive */ +#define RECEIVE_TASK_POLL_TIMEOUT_PRIO (6) +extern struct os_task eventq_task_poll_timeout_r; +extern os_stack_t eventq_task_stack_poll_timeout_r[POLL_STACK_SIZE]; + +/* Setting the data for the poll single */ +/* Define the task stack for the eventq_task_poll_single_send */ +#define SEND_TASK_POLL_SINGLE_PRIO (7) +extern struct os_task eventq_task_poll_single_s; +extern os_stack_t eventq_task_stack_poll_single_s[POLL_STACK_SIZE]; + +/* Define the task stack for the eventq_task_poll_single_receive */ +#define RECEIVE_TASK_POLL_SINGLE_PRIO (8) +struct os_task eventq_task_poll_single_r; +os_stack_t eventq_task_stack_poll_single_r[POLL_STACK_SIZE]; + +void eventq_task_send(void *arg); +void eventq_task_receive(void *arg); +void eventq_task_poll_send(void *arg); +void eventq_task_poll_receive(void *arg); +void eventq_task_poll_timeout_send(void *arg); +void eventq_task_poll_timeout_receive(void *arg); +void eventq_task_poll_single_send(void *arg); +void eventq_task_poll_single_receive(void *arg); + +#ifdef __cplusplus +} +#endif + +#endif /* _EVENTQ_TEST_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/mbuf_test.c ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/mbuf_test.c b/kernel/os/test/src/mbuf_test.c index dd4121d..73b6660 100644 --- a/kernel/os/test/src/mbuf_test.c +++ b/kernel/os/test/src/mbuf_test.c @@ -32,14 +32,14 @@ #define MBUF_TEST_DATA_LEN (1024) -static os_membuf_t os_mbuf_membuf[OS_MEMPOOL_SIZE(MBUF_TEST_POOL_BUF_SIZE, +os_membuf_t os_mbuf_membuf[OS_MEMPOOL_SIZE(MBUF_TEST_POOL_BUF_SIZE, MBUF_TEST_POOL_BUF_COUNT)]; -static struct os_mbuf_pool os_mbuf_pool; -static struct os_mempool os_mbuf_mempool; -static uint8_t os_mbuf_test_data[MBUF_TEST_DATA_LEN]; +struct os_mbuf_pool os_mbuf_pool; +struct os_mempool os_mbuf_mempool; +uint8_t os_mbuf_test_data[MBUF_TEST_DATA_LEN]; -static void +void os_mbuf_test_setup(void) { int rc; @@ -58,7 +58,7 @@ os_mbuf_test_setup(void) } } -static void +void os_mbuf_test_misc_assert_sane(struct os_mbuf *om, void *data, int buflen, int pktlen, int pkthdr_len) { @@ -95,318 +95,13 @@ os_mbuf_test_misc_assert_sane(struct os_mbuf *om, void *data, TEST_ASSERT(totlen == pktlen); } - -TEST_CASE(os_mbuf_test_alloc) -{ - struct os_mbuf *m; - int rc; - - os_mbuf_test_setup(); - - m = os_mbuf_get(&os_mbuf_pool, 0); - TEST_ASSERT_FATAL(m != NULL, "Error allocating mbuf"); - - rc = os_mbuf_free(m); - TEST_ASSERT_FATAL(rc == 0, "Error free'ing mbuf %d", rc); -} - -TEST_CASE(os_mbuf_test_get_pkthdr) -{ - struct os_mbuf *m; - - os_mbuf_test_setup(); - -#if (MBUF_TEST_POOL_BUF_SIZE <= 256) - m = os_mbuf_get_pkthdr(&os_mbuf_pool, MBUF_TEST_POOL_BUF_SIZE - 1); - TEST_ASSERT_FATAL(m == NULL, "Error: should not have returned mbuf"); -#endif - - m = os_mbuf_get(&os_mbuf_pool, MBUF_TEST_POOL_BUF_SIZE); - TEST_ASSERT_FATAL(m == NULL, "Error: should not have returned mbuf"); -} - - -TEST_CASE(os_mbuf_test_dup) -{ - struct os_mbuf *om; - struct os_mbuf *om2; - struct os_mbuf *dup; - int rc; - - os_mbuf_test_setup(); - - /* Test first allocating and duplicating a single mbuf */ - om = os_mbuf_get(&os_mbuf_pool, 0); - TEST_ASSERT_FATAL(om != NULL, "Error allocating mbuf"); - - rc = os_mbuf_append(om, os_mbuf_test_data, 200); - TEST_ASSERT_FATAL(rc == 0); - os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 200, 200, 0); - - dup = os_mbuf_dup(om); - TEST_ASSERT_FATAL(dup != NULL, "NULL mbuf returned from dup"); - TEST_ASSERT_FATAL(dup != om, "duplicate matches original."); - os_mbuf_test_misc_assert_sane(dup, os_mbuf_test_data, 200, 200, 0); - - rc = os_mbuf_free(om); - TEST_ASSERT_FATAL(rc == 0, "Error free'ing mbuf om %d", rc); - - rc = os_mbuf_free(dup); - TEST_ASSERT_FATAL(rc == 0, "Error free'ing mbuf dup %d", rc); - - om = os_mbuf_get(&os_mbuf_pool, 0); - TEST_ASSERT_FATAL(om != NULL, "Error allocating mbuf"); - rc = os_mbuf_append(om, os_mbuf_test_data, 200); - TEST_ASSERT_FATAL(rc == 0); - os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 200, 200, 0); - - om2 = os_mbuf_get(&os_mbuf_pool, 0); - TEST_ASSERT_FATAL(om2 != NULL, "Error allocating mbuf"); - rc = os_mbuf_append(om2, os_mbuf_test_data + 200, 200); - TEST_ASSERT_FATAL(rc == 0); - os_mbuf_test_misc_assert_sane(om2, os_mbuf_test_data + 200, 200, 200, 0); - - os_mbuf_concat(om, om2); - os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 200, 400, 0); - - dup = os_mbuf_dup(om); - TEST_ASSERT_FATAL(dup != NULL, "NULL mbuf returned from dup"); - TEST_ASSERT_FATAL(dup != om, "Duplicate matches original"); - TEST_ASSERT_FATAL(SLIST_NEXT(dup, om_next) != NULL, - "NULL chained element, duplicate should match original"); - - os_mbuf_test_misc_assert_sane(dup, os_mbuf_test_data, 200, 400, 0); - - rc = os_mbuf_free_chain(om); - TEST_ASSERT_FATAL(rc == 0, "Cannot free mbuf chain %d", rc); - - rc = os_mbuf_free_chain(dup); - TEST_ASSERT_FATAL(rc == 0, "Cannot free mbuf chain %d", rc); -} - -TEST_CASE(os_mbuf_test_append) -{ - struct os_mbuf *om; - int rc; - uint8_t databuf[] = {0xa, 0xb, 0xc, 0xd}; - uint8_t cmpbuf[] = {0xff, 0xff, 0xff, 0xff}; - - os_mbuf_test_setup(); - - om = os_mbuf_get(&os_mbuf_pool, 0); - TEST_ASSERT_FATAL(om != NULL, "Error allocating mbuf"); - os_mbuf_test_misc_assert_sane(om, NULL, 0, 0, 0); - - rc = os_mbuf_append(om, databuf, sizeof(databuf)); - TEST_ASSERT_FATAL(rc == 0, "Cannot add %d bytes to mbuf", - sizeof(databuf)); - os_mbuf_test_misc_assert_sane(om, databuf, sizeof databuf, sizeof databuf, - 0); - - memcpy(cmpbuf, OS_MBUF_DATA(om, uint8_t *), om->om_len); - TEST_ASSERT_FATAL(memcmp(cmpbuf, databuf, sizeof(databuf)) == 0, - "Databuf doesn't match cmpbuf"); -} - -TEST_CASE(os_mbuf_test_extend) -{ - struct os_mbuf *om; - void *v; - - os_mbuf_test_setup(); - - /*** Series of successful extensions. */ - om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10); - TEST_ASSERT_FATAL(om != NULL); - - TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 222); - TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL); - os_mbuf_test_misc_assert_sane(om, NULL, 0, 0, 18); - - v = os_mbuf_extend(om, 20); - TEST_ASSERT(v != NULL); - TEST_ASSERT(v == om->om_data); - TEST_ASSERT(om->om_len == 20); - - TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 202); - TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL); - os_mbuf_test_misc_assert_sane(om, NULL, 20, 20, 18); - - v = os_mbuf_extend(om, 100); - TEST_ASSERT(v != NULL); - TEST_ASSERT(v == om->om_data + 20); - TEST_ASSERT(om->om_len == 120); - - TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 102); - TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL); - os_mbuf_test_misc_assert_sane(om, NULL, 120, 120, 18); - - v = os_mbuf_extend(om, 101); - TEST_ASSERT(v != NULL); - TEST_ASSERT(v == om->om_data + 120); - TEST_ASSERT(om->om_len == 221); - - TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 1); - TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL); - os_mbuf_test_misc_assert_sane(om, NULL, 221, 221, 18); - - v = os_mbuf_extend(om, 1); - TEST_ASSERT(v != NULL); - TEST_ASSERT(v == om->om_data + 221); - TEST_ASSERT(om->om_len == 222); - - TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 0); - TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL); - os_mbuf_test_misc_assert_sane(om, NULL, 222, 222, 18); - - /* Overflow into next buffer. */ - v = os_mbuf_extend(om, 1); - TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 0); - TEST_ASSERT(SLIST_NEXT(om, om_next) != NULL); - - TEST_ASSERT(v == SLIST_NEXT(om, om_next)->om_data); - TEST_ASSERT(om->om_len == 222); - TEST_ASSERT(SLIST_NEXT(om, om_next)->om_len == 1); - os_mbuf_test_misc_assert_sane(om, NULL, 222, 223, 18); - - /*** Attempt to extend by an amount larger than max buf size fails. */ - v = os_mbuf_extend(om, 257); - TEST_ASSERT(v == NULL); - TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 0); - TEST_ASSERT(SLIST_NEXT(om, om_next) != NULL); - - TEST_ASSERT(om->om_len == 222); - TEST_ASSERT(SLIST_NEXT(om, om_next)->om_len == 1); - os_mbuf_test_misc_assert_sane(om, NULL, 222, 223, 18); -} - -TEST_CASE(os_mbuf_test_pullup) -{ - struct os_mbuf *om; - struct os_mbuf *om2; - int rc; - - os_mbuf_test_setup(); - - /*** Free when too much os_mbuf_test_data is requested. */ - om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10); - TEST_ASSERT_FATAL(om != NULL); - - om = os_mbuf_pullup(om, 1); - TEST_ASSERT(om == NULL); - - /*** No effect when all os_mbuf_test_data is already at the start. */ - om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10); - TEST_ASSERT_FATAL(om != NULL); - - rc = os_mbuf_append(om, os_mbuf_test_data, 1); - TEST_ASSERT_FATAL(rc == 0); - os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 1, 1, 18); - - om = os_mbuf_pullup(om, 1); - os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 1, 1, 18); - - /*** Spread os_mbuf_test_data across four mbufs. */ - om2 = os_mbuf_get(&os_mbuf_pool, 10); - TEST_ASSERT_FATAL(om2 != NULL); - rc = os_mbuf_append(om2, os_mbuf_test_data + 1, 1); - TEST_ASSERT_FATAL(rc == 0); - os_mbuf_concat(om, om2); - - om2 = os_mbuf_get(&os_mbuf_pool, 10); - TEST_ASSERT_FATAL(om2 != NULL); - rc = os_mbuf_append(om2, os_mbuf_test_data + 2, 1); - TEST_ASSERT_FATAL(rc == 0); - os_mbuf_concat(om, om2); - - om2 = os_mbuf_get(&os_mbuf_pool, 10); - TEST_ASSERT_FATAL(om2 != NULL); - rc = os_mbuf_append(om2, os_mbuf_test_data + 3, 1); - TEST_ASSERT_FATAL(rc == 0); - os_mbuf_concat(om, om2); - - TEST_ASSERT_FATAL(OS_MBUF_PKTLEN(om) == 4); - - om = os_mbuf_pullup(om, 4); - os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 4, 4, 18); - - os_mbuf_free_chain(om); - - /*** Require an allocation. */ - om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10); - TEST_ASSERT_FATAL(om != NULL); - - om->om_data += 100; - rc = os_mbuf_append(om, os_mbuf_test_data, 100); - TEST_ASSERT_FATAL(rc == 0); - - om2 = os_mbuf_get(&os_mbuf_pool, 10); - TEST_ASSERT_FATAL(om2 != NULL); - rc = os_mbuf_append(om2, os_mbuf_test_data + 100, 100); - TEST_ASSERT_FATAL(rc == 0); - os_mbuf_concat(om, om2); - - om = os_mbuf_pullup(om, 200); - os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 200, 200, 18); - - /*** Partial pullup. */ - om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10); - TEST_ASSERT_FATAL(om != NULL); - - om->om_data += 100; - rc = os_mbuf_append(om, os_mbuf_test_data, 100); - TEST_ASSERT_FATAL(rc == 0); - - om2 = os_mbuf_get(&os_mbuf_pool, 10); - TEST_ASSERT_FATAL(om2 != NULL); - rc = os_mbuf_append(om2, os_mbuf_test_data + 100, 100); - TEST_ASSERT_FATAL(rc == 0); - os_mbuf_concat(om, om2); - - om = os_mbuf_pullup(om, 150); - os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 150, 200, 18); -} - -TEST_CASE(os_mbuf_test_adj) -{ - struct os_mbuf *om; - int rc; - - os_mbuf_test_setup(); - - om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10); - TEST_ASSERT_FATAL(om != NULL); - - rc = os_mbuf_append(om, os_mbuf_test_data, sizeof os_mbuf_test_data); - TEST_ASSERT_FATAL(rc == 0); - - os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 222, - sizeof os_mbuf_test_data, 18); - - /* Remove from the front. */ - os_mbuf_adj(om, 10); - os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 10, 212, - sizeof os_mbuf_test_data - 10, 18); - - /* Remove from the back. */ - os_mbuf_adj(om, -10); - os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 10, 212, - sizeof os_mbuf_test_data - 20, 18); - - /* Remove entire first buffer. */ - os_mbuf_adj(om, 212); - os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 222, 0, - sizeof os_mbuf_test_data - 232, 18); - - /* Remove next buffer. */ - os_mbuf_adj(om, 256); - os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 478, 0, - sizeof os_mbuf_test_data - 488, 18); - - /* Remove more data than is present. */ - os_mbuf_adj(om, 1000); - os_mbuf_test_misc_assert_sane(om, NULL, 0, 0, 18); -} +TEST_CASE_DECL(os_mbuf_test_alloc) +TEST_CASE_DECL(os_mbuf_test_dup) +TEST_CASE_DECL(os_mbuf_test_append) +TEST_CASE_DECL(os_mbuf_test_pullup) +TEST_CASE_DECL(os_mbuf_test_extend) +TEST_CASE_DECL(os_mbuf_test_adj) +TEST_CASE_DECL(os_mbuf_test_get_pkthdr) TEST_SUITE(os_mbuf_test_suite) { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/mbuf_test.h ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/mbuf_test.h b/kernel/os/test/src/mbuf_test.h new file mode 100644 index 0000000..7585263 --- /dev/null +++ b/kernel/os/test/src/mbuf_test.h @@ -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. + */ +#ifndef _MBUF_TEST_H +#define _MBUF_TEST_H + +#include "testutil/testutil.h" +#include "os/os.h" +#include "os_test_priv.h" + +#include <string.h> + +#ifdef __cplusplus +#extern "C" { +#endif + +/* + * NOTE: currently, the buffer size cannot be changed as some tests are + * hard-coded for this size. + */ +#define MBUF_TEST_POOL_BUF_SIZE (256) +#define MBUF_TEST_POOL_BUF_COUNT (10) + +#define MBUF_TEST_DATA_LEN (1024) + +extern os_membuf_t os_mbuf_membuf[OS_MEMPOOL_SIZE(MBUF_TEST_POOL_BUF_SIZE, + MBUF_TEST_POOL_BUF_COUNT)]; + +extern struct os_mbuf_pool os_mbuf_pool; +extern struct os_mempool os_mbuf_mempool; +extern uint8_t os_mbuf_test_data[MBUF_TEST_DATA_LEN]; + +void os_mbuf_test_setup(void); +void os_mbuf_test_misc_assert_sane(struct os_mbuf *om, void *data, int buflen, + int pktlen, int pkthdr_len); + +#ifdef __cplusplus +} +#endif + +#endif /* _MBUF_TEST_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/mempool_test.c ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/mempool_test.c b/kernel/os/test/src/mempool_test.c index cd17c90..15a48bc 100644 --- a/kernel/os/test/src/mempool_test.c +++ b/kernel/os/test/src/mempool_test.c @@ -46,7 +46,7 @@ void *block_array[MEMPOOL_TEST_MAX_BLOCKS]; int verbose = 0; -static int +int mempool_test_get_pool_size(int num_blocks, int block_size) { int mem_pool_size; @@ -60,7 +60,7 @@ mempool_test_get_pool_size(int num_blocks, int block_size) return mem_pool_size; } -static void +void mempool_test(int num_blocks, int block_size) { int cnt; @@ -209,17 +209,7 @@ mempool_test(int num_blocks, int block_size) TEST_ASSERT(rc == OS_INVALID_PARM, "No error freeing bad block address"); } -/** - * os mempool test - * - * Main test loop for memory pool testing. - * - * @return int - */ -TEST_CASE(os_mempool_test_case) -{ - mempool_test(NUM_MEM_BLOCKS, MEM_BLOCK_SIZE); -} +TEST_CASE_DECL(os_mempool_test_case) TEST_SUITE(os_mempool_test_suite) { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/mempool_test.h ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/mempool_test.h b/kernel/os/test/src/mempool_test.h new file mode 100644 index 0000000..78258ca --- /dev/null +++ b/kernel/os/test/src/mempool_test.h @@ -0,0 +1,60 @@ +/** + * 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 _MEMPOOL_TEST_H +#define _MEMPOOL_TEST_H + +#include <stdio.h> +#include <string.h> +#include "testutil/testutil.h" +#include "os/os.h" +#include "os_test_priv.h" + +#ifdef __cplusplus +#extern "C" { +#endif + +/* Create a memory pool for testing */ +#define NUM_MEM_BLOCKS (10) +#define MEM_BLOCK_SIZE (80) + +/* Limit max blocks for testing */ +#define MEMPOOL_TEST_MAX_BLOCKS (128) + +extern int alignment; + +/* Test memory pool structure */ +extern struct os_mempool g_TstMempool; + +/* Test memory pool buffer */ +extern os_membuf_t TstMembuf[OS_MEMPOOL_SIZE(NUM_MEM_BLOCKS, MEM_BLOCK_SIZE)]; + +/* Array of block pointers. */ +extern void *block_array[MEMPOOL_TEST_MAX_BLOCKS]; + +extern int verbose; + +int mempool_test_get_pool_size(int num_blocks, int block_size); + +void mempool_test(int num_blocks, int block_size); + +#ifdef __cplusplus +} +#endif + +#endif /* _MEMPOOL_TEST_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/mutex_test.c ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/mutex_test.c b/kernel/os/test/src/mutex_test.c index fbcfe17..54a1f2d 100644 --- a/kernel/os/test/src/mutex_test.c +++ b/kernel/os/test/src/mutex_test.c @@ -56,7 +56,7 @@ volatile int g_task17_val; struct os_mutex g_mutex1; struct os_mutex g_mutex2; -static volatile int g_mutex_test; +volatile int g_mutex_test; /** * mutex test basic @@ -65,7 +65,7 @@ static volatile int g_mutex_test; * * @return int */ -static void +void mutex_test_basic_handler(void *arg) { struct os_mutex *mu; @@ -137,7 +137,7 @@ mutex_test_basic_handler(void *arg) os_test_restart(); } -static void +void mutex_test1_task14_handler(void *arg) { os_error_t err; @@ -162,7 +162,7 @@ mutex_test1_task14_handler(void *arg) os_test_restart(); } -static void +void mutex_test2_task14_handler(void *arg) { os_error_t err; @@ -198,7 +198,7 @@ mutex_test2_task14_handler(void *arg) os_test_restart(); } -static void +void task15_handler(void *arg) { os_error_t err; @@ -241,7 +241,7 @@ task15_handler(void *arg) } } -static void +void task16_handler(void *arg) { os_error_t err; @@ -297,7 +297,7 @@ task16_handler(void *arg) } } -static void +void task17_handler(void *arg) { os_error_t err; @@ -329,74 +329,9 @@ task17_handler(void *arg) } } -TEST_CASE(os_mutex_test_basic) -{ - sysinit(); - - os_mutex_init(&g_mutex1); - - os_task_init(&task14, "task14", mutex_test_basic_handler, NULL, - TASK14_PRIO, OS_WAIT_FOREVER, stack14, - OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)); - - os_start(); -} - -TEST_CASE(os_mutex_test_case_1) -{ - int rc; - - sysinit(); - - g_mutex_test = 1; - g_task14_val = 0; - g_task15_val = 0; - g_task16_val = 0; - - rc = os_mutex_init(&g_mutex1); - TEST_ASSERT(rc == 0); - rc = os_mutex_init(&g_mutex2); - TEST_ASSERT(rc == 0); - - os_task_init(&task14, "task14", mutex_test1_task14_handler, NULL, - TASK14_PRIO, OS_WAIT_FOREVER, stack14, - OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)); - - os_task_init(&task15, "task15", task15_handler, NULL, TASK15_PRIO, - OS_WAIT_FOREVER, stack15, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)); - - os_task_init(&task16, "task16", task16_handler, NULL, TASK16_PRIO, - OS_WAIT_FOREVER, stack16, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)); - - os_start(); -} - -TEST_CASE(os_mutex_test_case_2) -{ - sysinit(); - - g_mutex_test = 2; - g_task14_val = 0; - g_task15_val = 0; - g_task16_val = 0; - os_mutex_init(&g_mutex1); - os_mutex_init(&g_mutex2); - - os_task_init(&task14, "task14", mutex_test2_task14_handler, NULL, - TASK14_PRIO, OS_WAIT_FOREVER, stack14, - OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)); - - os_task_init(&task15, "task15", task15_handler, NULL, TASK15_PRIO, - OS_WAIT_FOREVER, stack15, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)); - - os_task_init(&task16, "task16", task16_handler, NULL, TASK16_PRIO, - OS_WAIT_FOREVER, stack16, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)); - - os_task_init(&task17, "task17", task17_handler, NULL, TASK17_PRIO, - OS_WAIT_FOREVER, stack17, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)); - - os_start(); -} +TEST_CASE_DECL(os_mutex_test_basic) +TEST_CASE_DECL(os_mutex_test_case_1) +TEST_CASE_DECL(os_mutex_test_case_2) TEST_SUITE(os_mutex_test_suite) { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/mutex_test.h ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/mutex_test.h b/kernel/os/test/src/mutex_test.h new file mode 100644 index 0000000..221d0ad --- /dev/null +++ b/kernel/os/test/src/mutex_test.h @@ -0,0 +1,78 @@ +/** + * 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 _MUTEX_TEST_H +#define _MUTEX_TEST_H + +#include <stdio.h> +#include <string.h> +#include <assert.h> +#include <sys/time.h> +#include "sysinit/sysinit.h" +#include "testutil/testutil.h" +#include "os/os.h" +#include "os/os_test.h" +#include "os_test_priv.h" + +#ifdef __cplusplus +#extern "C" { +#endif + +#ifdef ARCH_sim +#define MUTEX_TEST_STACK_SIZE 1024 +#else +#define MUTEX_TEST_STACK_SIZE 256 +#endif + +extern struct os_task task14; +extern os_stack_t stack14[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)]; + +extern struct os_task task15; +extern os_stack_t stack15[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)]; + +extern struct os_task task16; +extern os_stack_t stack16[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)]; + +extern struct os_task task17; +extern os_stack_t stack17[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)]; + +#define TASK14_PRIO (4) +#define TASK15_PRIO (5) +#define TASK16_PRIO (6) +#define TASK17_PRIO (7) + +extern volatile int g_task14_val; +extern volatile int g_task15_val; +extern volatile int g_task16_val; +extern volatile int g_task17_val; +extern struct os_mutex g_mutex1; +extern struct os_mutex g_mutex2; +extern volatile int g_mutex_test; + +void mutex_test_basic_handler(void *arg); +void mutex_test1_task14_handler(void *arg); +void mutex_test2_task14_handler(void *arg); +void task15_handler(void *arg); +void task16_handler(void *arg); +void task17_handler(void *arg); + +#ifdef __cplusplus +} +#endif + +#endif /* _MUTEX_TEST_H */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/os_test.c ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/os_test.c b/kernel/os/test/src/os_test.c index e9d041b..71188d2 100644 --- a/kernel/os/test/src/os_test.c +++ b/kernel/os/test/src/os_test.c @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - #include <assert.h> #include <stddef.h> #include "syscfg/syscfg.h" @@ -24,6 +23,38 @@ #include "os/os_test.h" #include "os_test_priv.h" +#include <stdio.h> +#include <setjmp.h> +#include <signal.h> +#include <string.h> +#include <sys/time.h> +#include "os/os.h" + +void +os_test_restart(void) +{ + struct sigaction sa; + struct itimerval it; + int rc; + + g_os_started = 0; + + memset(&sa, 0, sizeof sa); + sa.sa_handler = SIG_IGN; + + sigaction(SIGALRM, &sa, NULL); + sigaction(SIGVTALRM, &sa, NULL); + + memset(&it, 0, sizeof(it)); + rc = setitimer(ITIMER_VIRTUAL, &it, NULL); + if (rc != 0) { + perror("Cannot set itimer"); + abort(); + } + + tu_restart(); +} + int os_test_all(void) { @@ -42,7 +73,7 @@ os_test_all(void) int main(int argc, char **argv) { - tu_config.tc_print_results = 1; + ts_config.ts_print_results = 1; tu_init(); os_test_all(); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/os_test_priv.h ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/os_test_priv.h b/kernel/os/test/src/os_test_priv.h index 945efc0..eaa33d1 100644 --- a/kernel/os/test/src/os_test_priv.h +++ b/kernel/os/test/src/os_test_priv.h @@ -20,6 +20,19 @@ #ifndef H_OS_TEST_PRIV_ #define H_OS_TEST_PRIV_ +#include "sysinit/sysinit.h" +#include "testutil/testutil.h" +#include "os/os.h" +#include "os_test_priv.h" + +#include "callout_test.h" + +#include "eventq_test.h" +#include "mbuf_test.h" +#include "mempool_test.h" +#include "mutex_test.h" +#include "sem_test.h" + #ifdef __cplusplus extern "C" { #endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/sem_test.c ---------------------------------------------------------------------- diff --git a/kernel/os/test/src/sem_test.c b/kernel/os/test/src/sem_test.c index 9fe7824..1319bc7 100644 --- a/kernel/os/test/src/sem_test.c +++ b/kernel/os/test/src/sem_test.c @@ -58,6 +58,8 @@ struct os_sem g_sem1; * */ +char sem_test_buf[128]; + /** * sem test disp sem * @@ -65,18 +67,25 @@ struct os_sem g_sem1; * * @param sem */ -static const char * +const char * sem_test_sem_to_s(const struct os_sem *sem) { - static char buf[128]; +#if 0 + char buf[128]; snprintf(buf, sizeof buf, "\tSemaphore: tokens=%u head=%p", sem->sem_tokens, SLIST_FIRST(&sem->sem_head)); return buf; +#else + snprintf(sem_test_buf, sizeof sem_test_buf, "\tSemaphore: tokens=%u head=%p", + sem->sem_tokens, SLIST_FIRST(&sem->sem_head)); + + return sem_test_buf; +#endif } -static void +void sem_test_sleep_task_handler(void *arg) { struct os_task *t; @@ -88,7 +97,7 @@ sem_test_sleep_task_handler(void *arg) os_test_restart(); } -static void +void sem_test_pend_release_loop(int delay, int timeout, int itvl) { os_error_t err; @@ -113,7 +122,7 @@ sem_test_pend_release_loop(int delay, int timeout, int itvl) * * @return int */ -static void +void sem_test_basic_handler(void *arg) { struct os_task *t; @@ -178,7 +187,7 @@ sem_test_basic_handler(void *arg) os_test_restart(); } -static void +void sem_test_1_task1_handler(void *arg) { os_error_t err; @@ -207,188 +216,77 @@ sem_test_1_task1_handler(void *arg) os_test_restart(); } -TEST_CASE(os_sem_test_basic) -{ - os_error_t err; - - sysinit(); - - err = os_sem_init(&g_sem1, 1); - TEST_ASSERT(err == OS_OK); - - os_task_init(&task1, "task1", sem_test_basic_handler, NULL, TASK1_PRIO, - OS_WAIT_FOREVER, stack1, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_start(); -} - -static void +void sem_test_1_task2_handler(void *arg) { sem_test_pend_release_loop(0, OS_TICKS_PER_SEC / 10, OS_TICKS_PER_SEC / 10); } -static void +void sem_test_1_task3_handler(void *arg) { sem_test_pend_release_loop(0, OS_TIMEOUT_NEVER, OS_TICKS_PER_SEC * 2); } -TEST_CASE(os_sem_test_case_1) -{ - os_error_t err; - - sysinit(); - - err = os_sem_init(&g_sem1, 1); - TEST_ASSERT(err == OS_OK); - - os_task_init(&task1, "task1", sem_test_1_task1_handler, NULL, - TASK1_PRIO, OS_WAIT_FOREVER, stack1, - OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_task_init(&task2, "task2", sem_test_1_task2_handler, NULL, - TASK2_PRIO, OS_WAIT_FOREVER, stack2, - OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_task_init(&task3, "task3", sem_test_1_task3_handler, NULL, TASK3_PRIO, - OS_WAIT_FOREVER, stack3, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_start(); -} - -static void +void sem_test_2_task2_handler(void *arg) { sem_test_pend_release_loop(0, 2000, 2000); } -static void +void sem_test_2_task3_handler(void *arg) { sem_test_pend_release_loop(0, OS_TIMEOUT_NEVER, 2000); } -static void +void sem_test_2_task4_handler(void *arg) { sem_test_pend_release_loop(0, 2000, 2000); } -TEST_CASE(os_sem_test_case_2) -{ - os_error_t err; - - sysinit(); - - err = os_sem_init(&g_sem1, 1); - TEST_ASSERT(err == OS_OK); - - os_task_init(&task1, "task1", sem_test_sleep_task_handler, NULL, - TASK1_PRIO, OS_WAIT_FOREVER, stack1, - OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_task_init(&task2, "task2", sem_test_2_task2_handler, NULL, - TASK2_PRIO, OS_WAIT_FOREVER, stack2, - OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_task_init(&task3, "task3", sem_test_2_task3_handler, NULL, TASK3_PRIO, - OS_WAIT_FOREVER, stack3, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_task_init(&task4, "task4", sem_test_2_task4_handler, NULL, TASK4_PRIO, - OS_WAIT_FOREVER, stack4, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_start(); -} - -static void +void sem_test_3_task2_handler(void *arg) { sem_test_pend_release_loop(100, 2000, 2000); } -static void +void sem_test_3_task3_handler(void *arg) { sem_test_pend_release_loop(150, 2000, 2000); } -static void +void sem_test_3_task4_handler(void *arg) { sem_test_pend_release_loop(0, 2000, 2000); } -TEST_CASE(os_sem_test_case_3) -{ - os_error_t err; - - sysinit(); - - err = os_sem_init(&g_sem1, 1); - TEST_ASSERT(err == OS_OK); - - os_task_init(&task1, "task1", sem_test_sleep_task_handler, NULL, - TASK1_PRIO, OS_WAIT_FOREVER, stack1, - OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_task_init(&task2, "task2", sem_test_3_task2_handler, NULL, - TASK2_PRIO, OS_WAIT_FOREVER, stack2, - OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_task_init(&task3, "task3", sem_test_3_task3_handler, NULL, TASK3_PRIO, - OS_WAIT_FOREVER, stack3, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_task_init(&task4, "task4", sem_test_3_task4_handler, NULL, TASK4_PRIO, - OS_WAIT_FOREVER, stack4, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_start(); -} - -static void +void sem_test_4_task2_handler(void *arg) { sem_test_pend_release_loop(60, 2000, 2000); } -static void +void sem_test_4_task3_handler(void *arg) { sem_test_pend_release_loop(60, 2000, 2000); } -static void +void sem_test_4_task4_handler(void *arg) { sem_test_pend_release_loop(0, 2000, 2000); } - -TEST_CASE(os_sem_test_case_4) -{ - os_error_t err; - - sysinit(); - - err = os_sem_init(&g_sem1, 1); - TEST_ASSERT(err == OS_OK); - - os_task_init(&task1, "task1", sem_test_sleep_task_handler, NULL, - TASK1_PRIO, OS_WAIT_FOREVER, stack1, - OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_task_init(&task2, "task2", sem_test_4_task2_handler, NULL, - TASK2_PRIO, OS_WAIT_FOREVER, stack2, - OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_task_init(&task3, "task3", sem_test_4_task3_handler, NULL, TASK3_PRIO, - OS_WAIT_FOREVER, stack3, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_task_init(&task4, "task4", sem_test_4_task4_handler, NULL, TASK4_PRIO, - OS_WAIT_FOREVER, stack4, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)); - - os_start(); -} +TEST_CASE_DECL(os_sem_test_basic) +TEST_CASE_DECL(os_sem_test_case_1) +TEST_CASE_DECL(os_sem_test_case_2) +TEST_CASE_DECL(os_sem_test_case_3) +TEST_CASE_DECL(os_sem_test_case_4) TEST_SUITE(os_sem_test_suite) {