Skip to content

test:add mutex socket syscall directory #2891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions testing/testsuites/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,19 @@ config CM_PTHREAD_TEST
default n
depends on TESTS_TESTSUITES

config CM_SOCKET_TEST
bool "enbale socket test"
default n
depends on TESTS_TESTSUITES

config CM_SYSCALL_TEST
bool "enbale syscall test"
default n
depends on TESTS_TESTSUITES

config CM_MUTEX_TEST
bool "enbale mutex test"
default n
depends on TESTS_TESTSUITES

endif # TESTS_TESTSUITES
24 changes: 24 additions & 0 deletions testing/testsuites/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,28 @@ PROGNAME += cmocka_pthread_test
MAINSRC += $(CURDIR)/kernel/pthread/cmocka_pthread_test.c
endif

ifneq ($(CONFIG_CM_MUTEX_TEST),)
CFLAGS += -I$(CURDIR)/kernel/mutex/include
CSRCS += $(wildcard kernel/mutex/cases/*.c)
CSRCS += $(wildcard kernel/mutex/common/*.c)
PROGNAME += cmocka_mutex_test
MAINSRC += $(CURDIR)/kernel/mutex/cmocka_mutex_test.c
endif

ifneq ($(CONFIG_CM_SOCKET_TEST),)
CFLAGS += -I$(CURDIR)/kernel/socket/include
CSRCS += $(wildcard kernel/socket/cases/*.c)
PROGNAME += cmocka_socket_test
MAINSRC += $(CURDIR)/kernel/socket/cmocka_socket_test.c
endif

ifneq ($(CONFIG_CM_SYSCALL_TEST),)
CFLAGS += -I$(CURDIR)/kernel/syscall/include
CFLAGS += -I$(APPDIR)/nshlib
CSRCS += $(wildcard kernel/syscall/cases/*.c)
CSRCS += $(wildcard kernel/syscall/common/*.c)
PROGNAME += cmocka_syscall_test
MAINSRC += $(CURDIR)/kernel/syscall/cmocka_syscall_test.c
endif

include $(APPDIR)/Application.mk
40 changes: 21 additions & 19 deletions testing/testsuites/kernel/fs/cases/fs_append_test.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
/****************************************************************************
* apps/testing/testsuites/kernel/fs/cases/fs_append_test.c
* Copyright (C) 2020 Xiaomi Corporation
*
* Licensed 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
* 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
* 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.
*/
*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.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand All @@ -38,20 +40,20 @@

#define TESTFILENAME "stream01Testfile"

/****************************************************************************
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: stream
* Example description:
* 1. open a file with "a+".
* 2. Write some strings to the file.
* 3. Check if the file pointer is offset.
* 1. open a file with "a+".
* 2. Write some strings to the file.
* 3. Check if the file pointer is offset.
* Test item: fopen() fseek() ftell()
* Expect results: TEST PASSED
****************************************************************************/

/****************************************************************************
* Public Functions
****************************************************************************/

void test_nuttx_fs_append01(FAR void **state)
{
FILE *fd;
Expand All @@ -61,8 +63,8 @@ void test_nuttx_fs_append01(FAR void **state)
fd = fopen(TESTFILENAME, "a+");
if (fd == NULL)
{
syslog(LOG_ERR, "Unable to open file %s, errno %d\n",
TESTFILENAME, errno);
syslog(LOG_ERR, "Unable to open file %s, errno %d\n", TESTFILENAME,
errno);
assert_true(1 == 0);
}

Expand Down
29 changes: 16 additions & 13 deletions testing/testsuites/kernel/fs/cases/fs_creat_test.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
/****************************************************************************
* apps/testing/testsuites/kernel/fs/cases/fs_creat_test.c
* Copyright (C) 2020 Xiaomi Corporation
*
* Licensed 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
* 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
* 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.
*/
*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.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -53,9 +55,10 @@ void test_nuttx_fs_creat01(FAR void **state)
{
int fd;
int ret;
char buf[20] = {
0
};
char buf[20] =
{
0
};

struct fs_testsuites_state_s *test_state;

Expand Down
29 changes: 16 additions & 13 deletions testing/testsuites/kernel/fs/cases/fs_dup2_test.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
/****************************************************************************
* apps/testing/testsuites/kernel/fs/cases/fs_dup2_test.c
* Copyright (C) 2020 Xiaomi Corporation
*
* Licensed 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
* 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
* 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.
*/
*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.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -50,9 +52,10 @@

void test_nuttx_fs_dup201(FAR void **state)
{
char buf[16] = {
0
};
char buf[16] =
{
0
};

off_t currpos;
struct fs_testsuites_state_s *test_state;
Expand Down
40 changes: 21 additions & 19 deletions testing/testsuites/kernel/fs/cases/fs_dup_test.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
/****************************************************************************
* apps/testing/testsuites/kernel/fs/cases/fs_dup_test.c
* Copyright (C) 2020 Xiaomi Corporation
*
* Licensed 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
* 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
* 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.
*/
*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.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -53,9 +55,9 @@ void test_nuttx_fs_dup01(FAR void **state)
int fd;
int newfd;
int rval;
char buf_fd[5] = "hello";
char buf_new_fd[8] = "littleFS";
char read_buf[20] = "";
char buffd[5] = "hello";
char bufnewfd[8] = "littleFS";
char readbuf[20] = "";
struct fs_testsuites_state_s *test_state;

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

/* do write */

assert_int_in_range(write(fd, buf_fd, sizeof(buf_fd)), 1, sizeof(buf_fd));
assert_int_in_range(write(fd, buffd, sizeof(buffd)), 1, sizeof(buffd));

/* refresh to storage */

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

/* write newfd after dup */

rval = write(newfd, buf_new_fd, sizeof(buf_new_fd));
assert_int_in_range(rval, 1, sizeof(buf_new_fd));
rval = write(newfd, bufnewfd, sizeof(bufnewfd));
assert_int_in_range(rval, 1, sizeof(bufnewfd));

/* refresh to storage */

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

/* do double check */

rval = read(newfd, read_buf, 20);
rval = read(newfd, readbuf, 20);
assert_int_in_range(rval, 1, 20);

/* check read_buf */
/* check readbuf */

assert_int_equal(strncmp(read_buf, "hellolittleFS", 13), 0);
assert_int_equal(strncmp(readbuf, "hellolittleFS", 13), 0);
}
38 changes: 21 additions & 17 deletions testing/testsuites/kernel/fs/cases/fs_eventfd_test.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
/****************************************************************************
* apps/testing/testsuites/kernel/fs/cases/fs_eventfd_test.c
* Copyright (C) 2020 Xiaomi Corporation
*
* Licensed 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
* 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
* 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.
*/
*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.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -39,15 +41,17 @@
****************************************************************************/

/****************************************************************************
* Name: thread_func
* Name: threadfunc
****************************************************************************/

__attribute__((unused)) static void *thread_func(void *args)
__attribute__((unused)) static void *threadfunc(void *args)
{
eventfd_t eventfd01_buffer;
int fd = *(int *)args;

for (int i = 1; i < 6; i++)
{
read(*(int *)args, &eventfd01_buffer, sizeof(eventfd_t));
read(fd, &eventfd01_buffer, sizeof(eventfd_t));
sleep(1);
}

Expand Down Expand Up @@ -75,13 +79,13 @@ void test_nuttx_fs_eventfd(FAR void **state)
eventfd01_efd = eventfd(0, 0);
assert_int_not_equal(eventfd01_efd, -1);
test_state->fd1 = eventfd01_efd;
assert_true(pthread_create(&eventfd01_tid, NULL,
thread_func, &eventfd01_efd) >= 0);
assert_true(pthread_create(&eventfd01_tid, NULL, threadfunc,
&eventfd01_efd) >= 0);

for (int i = 1; i < 5; i++)
{
eventfd01_ret = write(eventfd01_efd, &eventfd01_buf,
sizeof(eventfd_t));
eventfd01_ret =
write(eventfd01_efd, &eventfd01_buf, sizeof(eventfd_t));
assert_int_equal(eventfd01_ret, sizeof(eventfd_t));
eventfd01_buf++;
sleep(1);
Expand Down
Loading
Loading