Skip to content

Commit 8ea62b2

Browse files
committed
test:add mutex socket syscall directory
some test cases have been added that cover the functionality of fs, mutex, pthread, socket, and syscall Signed-off-by: tengshuangshuang <tengshuangshuang@xiaomi.com>
1 parent 9c5568c commit 8ea62b2

File tree

158 files changed

+14123
-1698
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+14123
-1698
lines changed

testing/testsuites/kernel/fs/cases/fs_append_test.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
/****************************************************************************
22
* apps/testing/testsuites/kernel/fs/cases/fs_append_test.c
3-
* Copyright (C) 2020 Xiaomi Corporation
43
*
5-
* Licensed under the Apache License, Version 2.0 (the "License");
6-
* you may not use this file except in compliance with the License.
7-
* You may obtain a copy of the License at
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership.
7+
*The ASF licenses this file to you under the Apache License, Version 2.0
8+
*(the "License"); you may not use this file except in compliance with
9+
*the License. You may obtain a copy of the License at
810
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
11+
* http://www.apache.org/licenses/LICENSE-2.0
1012
*
1113
* Unless required by applicable law or agreed to in writing, software
1214
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
16-
*/
15+
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16+
*implied. See the License for the specific language governing
17+
*permissions and limitations under the License.
18+
*
19+
****************************************************************************/
1720

1821
/****************************************************************************
1922
* Included Files
2023
****************************************************************************/
21-
2224
#include <nuttx/config.h>
2325
#include <sys/types.h>
2426
#include <sys/stat.h>
@@ -38,20 +40,20 @@
3840

3941
#define TESTFILENAME "stream01Testfile"
4042

41-
/****************************************************************************
42-
* Public Functions
43-
****************************************************************************/
44-
4543
/****************************************************************************
4644
* Name: stream
4745
* Example description:
48-
* 1. open a file with "a+".
49-
* 2. Write some strings to the file.
50-
* 3. Check if the file pointer is offset.
46+
* 1. open a file with "a+".
47+
* 2. Write some strings to the file.
48+
* 3. Check if the file pointer is offset.
5149
* Test item: fopen() fseek() ftell()
5250
* Expect results: TEST PASSED
5351
****************************************************************************/
5452

53+
/****************************************************************************
54+
* Public Functions
55+
****************************************************************************/
56+
5557
void test_nuttx_fs_append01(FAR void **state)
5658
{
5759
FILE *fd;
@@ -61,8 +63,8 @@ void test_nuttx_fs_append01(FAR void **state)
6163
fd = fopen(TESTFILENAME, "a+");
6264
if (fd == NULL)
6365
{
64-
syslog(LOG_ERR, "Unable to open file %s, errno %d\n",
65-
TESTFILENAME, errno);
66+
syslog(LOG_ERR, "Unable to open file %s, errno %d\n", TESTFILENAME,
67+
errno);
6668
assert_true(1 == 0);
6769
}
6870

testing/testsuites/kernel/fs/cases/fs_creat_test.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
/****************************************************************************
22
* apps/testing/testsuites/kernel/fs/cases/fs_creat_test.c
3-
* Copyright (C) 2020 Xiaomi Corporation
43
*
5-
* Licensed under the Apache License, Version 2.0 (the "License");
6-
* you may not use this file except in compliance with the License.
7-
* You may obtain a copy of the License at
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership.
7+
*The ASF licenses this file to you under the Apache License, Version 2.0
8+
*(the "License"); you may not use this file except in compliance with
9+
*the License. You may obtain a copy of the License at
810
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
11+
* http://www.apache.org/licenses/LICENSE-2.0
1012
*
1113
* Unless required by applicable law or agreed to in writing, software
1214
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
16-
*/
15+
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16+
*implied. See the License for the specific language governing
17+
*permissions and limitations under the License.
18+
*
19+
****************************************************************************/
1720

1821
/****************************************************************************
1922
* Included Files
2023
****************************************************************************/
21-
2224
#include <nuttx/config.h>
2325
#include <sys/types.h>
2426
#include <sys/stat.h>
@@ -53,9 +55,10 @@ void test_nuttx_fs_creat01(FAR void **state)
5355
{
5456
int fd;
5557
int ret;
56-
char buf[20] = {
57-
0
58-
};
58+
char buf[20] =
59+
{
60+
0
61+
};
5962

6063
struct fs_testsuites_state_s *test_state;
6164

testing/testsuites/kernel/fs/cases/fs_dup2_test.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
/****************************************************************************
22
* apps/testing/testsuites/kernel/fs/cases/fs_dup2_test.c
3-
* Copyright (C) 2020 Xiaomi Corporation
43
*
5-
* Licensed under the Apache License, Version 2.0 (the "License");
6-
* you may not use this file except in compliance with the License.
7-
* You may obtain a copy of the License at
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership.
7+
*The ASF licenses this file to you under the Apache License, Version 2.0
8+
*(the "License"); you may not use this file except in compliance with
9+
*the License. You may obtain a copy of the License at
810
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
11+
* http://www.apache.org/licenses/LICENSE-2.0
1012
*
1113
* Unless required by applicable law or agreed to in writing, software
1214
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
16-
*/
15+
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16+
*implied. See the License for the specific language governing
17+
*permissions and limitations under the License.
18+
*
19+
****************************************************************************/
1720

1821
/****************************************************************************
1922
* Included Files
2023
****************************************************************************/
21-
2224
#include <nuttx/config.h>
2325
#include <stdio.h>
2426
#include <stdlib.h>
@@ -50,9 +52,10 @@
5052

5153
void test_nuttx_fs_dup201(FAR void **state)
5254
{
53-
char buf[16] = {
54-
0
55-
};
55+
char buf[16] =
56+
{
57+
0
58+
};
5659

5760
off_t currpos;
5861
struct fs_testsuites_state_s *test_state;

testing/testsuites/kernel/fs/cases/fs_dup_test.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
/****************************************************************************
22
* apps/testing/testsuites/kernel/fs/cases/fs_dup_test.c
3-
* Copyright (C) 2020 Xiaomi Corporation
43
*
5-
* Licensed under the Apache License, Version 2.0 (the "License");
6-
* you may not use this file except in compliance with the License.
7-
* You may obtain a copy of the License at
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership.
7+
*The ASF licenses this file to you under the Apache License, Version 2.0
8+
*(the "License"); you may not use this file except in compliance with
9+
*the License. You may obtain a copy of the License at
810
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
11+
* http://www.apache.org/licenses/LICENSE-2.0
1012
*
1113
* Unless required by applicable law or agreed to in writing, software
1214
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
16-
*/
15+
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16+
*implied. See the License for the specific language governing
17+
*permissions and limitations under the License.
18+
*
19+
****************************************************************************/
1720

1821
/****************************************************************************
1922
* Included Files
2023
****************************************************************************/
21-
2224
#include <nuttx/config.h>
2325
#include <stdio.h>
2426
#include <stdlib.h>
@@ -53,9 +55,9 @@ void test_nuttx_fs_dup01(FAR void **state)
5355
int fd;
5456
int newfd;
5557
int rval;
56-
char buf_fd[5] = "hello";
57-
char buf_new_fd[8] = "littleFS";
58-
char read_buf[20] = "";
58+
char buffd[5] = "hello";
59+
char bufnewfd[8] = "littleFS";
60+
char readbuf[20] = "";
5961
struct fs_testsuites_state_s *test_state;
6062

6163
test_state = (struct fs_testsuites_state_s *)*state;
@@ -68,7 +70,7 @@ void test_nuttx_fs_dup01(FAR void **state)
6870

6971
/* do write */
7072

71-
assert_int_in_range(write(fd, buf_fd, sizeof(buf_fd)), 1, sizeof(buf_fd));
73+
assert_int_in_range(write(fd, buffd, sizeof(buffd)), 1, sizeof(buffd));
7274

7375
/* refresh to storage */
7476

@@ -88,8 +90,8 @@ void test_nuttx_fs_dup01(FAR void **state)
8890

8991
/* write newfd after dup */
9092

91-
rval = write(newfd, buf_new_fd, sizeof(buf_new_fd));
92-
assert_int_in_range(rval, 1, sizeof(buf_new_fd));
93+
rval = write(newfd, bufnewfd, sizeof(bufnewfd));
94+
assert_int_in_range(rval, 1, sizeof(bufnewfd));
9395

9496
/* refresh to storage */
9597

@@ -102,10 +104,10 @@ void test_nuttx_fs_dup01(FAR void **state)
102104

103105
/* do double check */
104106

105-
rval = read(newfd, read_buf, 20);
107+
rval = read(newfd, readbuf, 20);
106108
assert_int_in_range(rval, 1, 20);
107109

108-
/* check read_buf */
110+
/* check readbuf */
109111

110-
assert_int_equal(strncmp(read_buf, "hellolittleFS", 13), 0);
112+
assert_int_equal(strncmp(readbuf, "hellolittleFS", 13), 0);
111113
}

testing/testsuites/kernel/fs/cases/fs_eventfd_test.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
/****************************************************************************
22
* apps/testing/testsuites/kernel/fs/cases/fs_eventfd_test.c
3-
* Copyright (C) 2020 Xiaomi Corporation
43
*
5-
* Licensed under the Apache License, Version 2.0 (the "License");
6-
* you may not use this file except in compliance with the License.
7-
* You may obtain a copy of the License at
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership.
7+
*The ASF licenses this file to you under the Apache License, Version 2.0
8+
*(the "License"); you may not use this file except in compliance with
9+
*the License. You may obtain a copy of the License at
810
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
11+
* http://www.apache.org/licenses/LICENSE-2.0
1012
*
1113
* Unless required by applicable law or agreed to in writing, software
1214
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
16-
*/
15+
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16+
*implied. See the License for the specific language governing
17+
*permissions and limitations under the License.
18+
*
19+
****************************************************************************/
1720

1821
/****************************************************************************
1922
* Included Files
2023
****************************************************************************/
21-
2224
#include <nuttx/config.h>
2325
#include <stdio.h>
2426
#include <stdlib.h>
@@ -39,15 +41,17 @@
3941
****************************************************************************/
4042

4143
/****************************************************************************
42-
* Name: thread_func
44+
* Name: threadfunc
4345
****************************************************************************/
4446

45-
__attribute__((unused)) static void *thread_func(void *args)
47+
__attribute__((unused)) static void *threadfunc(void *args)
4648
{
4749
eventfd_t eventfd01_buffer;
50+
int fd = *(int *)args;
51+
4852
for (int i = 1; i < 6; i++)
4953
{
50-
read(*(int *)args, &eventfd01_buffer, sizeof(eventfd_t));
54+
read(fd, &eventfd01_buffer, sizeof(eventfd_t));
5155
sleep(1);
5256
}
5357

@@ -75,13 +79,13 @@ void test_nuttx_fs_eventfd(FAR void **state)
7579
eventfd01_efd = eventfd(0, 0);
7680
assert_int_not_equal(eventfd01_efd, -1);
7781
test_state->fd1 = eventfd01_efd;
78-
assert_true(pthread_create(&eventfd01_tid, NULL,
79-
thread_func, &eventfd01_efd) >= 0);
82+
assert_true(pthread_create(&eventfd01_tid, NULL, threadfunc,
83+
&eventfd01_efd) >= 0);
8084

8185
for (int i = 1; i < 5; i++)
8286
{
83-
eventfd01_ret = write(eventfd01_efd, &eventfd01_buf,
84-
sizeof(eventfd_t));
87+
eventfd01_ret =
88+
write(eventfd01_efd, &eventfd01_buf, sizeof(eventfd_t));
8589
assert_int_equal(eventfd01_ret, sizeof(eventfd_t));
8690
eventfd01_buf++;
8791
sleep(1);

0 commit comments

Comments
 (0)