mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-02-06 00:45:22 +08:00
[add] posix testcase frame. (#6127)
This commit is contained in:
@@ -11,6 +11,7 @@ source "$RTT_DIR/examples/utest/testcases/utest/Kconfig"
|
||||
source "$RTT_DIR/examples/utest/testcases/kernel/Kconfig"
|
||||
source "$RTT_DIR/examples/utest/testcases/cpp11/Kconfig"
|
||||
source "$RTT_DIR/examples/utest/testcases/drivers/serial_v2/Kconfig"
|
||||
source "$RTT_DIR/examples/utest/testcases/posix/Kconfig"
|
||||
|
||||
endif
|
||||
|
||||
|
||||
37
examples/utest/testcases/posix/Kconfig
Normal file
37
examples/utest/testcases/posix/Kconfig
Normal file
@@ -0,0 +1,37 @@
|
||||
menu "RTT Posix Testcase"
|
||||
|
||||
config RTT_POSIX_TESTCASE
|
||||
select RT_USING_UTEST
|
||||
bool "RTT Posix Testcase"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/aio_h/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/arpa/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/ctype_h/Kconfig" # reserve
|
||||
source "$RTT_DIR/examples/utest/testcases/posix/dirent_h/Kconfig"
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/errno_h/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/fcntl_h/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/fenv_h/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/inttypes_h/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/libgen_h/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/locale_h/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/mqueue_h/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/net/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/netdb_h/Kconfig" # reserve
|
||||
source "$RTT_DIR/examples/utest/testcases/posix/pthread_h/Kconfig"
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/sched_h/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/semaphore_h/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/setjmp_h/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/signal_h/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/stdarg_h/Kconfig" # reserve
|
||||
source "$RTT_DIR/examples/utest/testcases/posix/stdio_h/Kconfig"
|
||||
source "$RTT_DIR/examples/utest/testcases/posix/stdlib_h/Kconfig"
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/string_h/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/stropts_h/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/sys/Kconfig" # reserve
|
||||
# source "$RTT_DIR/examples/utest/testcases/posix/time_h/Kconfig" # reserve
|
||||
source "$RTT_DIR/examples/utest/testcases/posix/unistd_h/Kconfig"
|
||||
endif
|
||||
|
||||
endmenu
|
||||
14
examples/utest/testcases/posix/SConscript
Normal file
14
examples/utest/testcases/posix/SConscript
Normal file
@@ -0,0 +1,14 @@
|
||||
import os
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(d, 'SConscript'))
|
||||
|
||||
Return('objs')
|
||||
39
examples/utest/testcases/posix/aio_h/Kconfig
Normal file
39
examples/utest/testcases/posix/aio_h/Kconfig
Normal file
@@ -0,0 +1,39 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_AIO_H
|
||||
bool "<aio.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_AIO_H
|
||||
|
||||
config AIO_H_AIO_CANCEL
|
||||
bool "<aio.h -> aio_cancel>"
|
||||
default n
|
||||
|
||||
config AIO_H_AIO_ERROR
|
||||
bool "<aio.h -> aio_error>"
|
||||
default n
|
||||
|
||||
config AIO_H_AIO_FSYNC
|
||||
bool "<aio.h -> aio_fsync>"
|
||||
default n
|
||||
|
||||
config AIO_H_AIO_READ
|
||||
bool "<aio.h -> aio_read>"
|
||||
default n
|
||||
|
||||
config AIO_H_AIO_RETURN
|
||||
bool "<aio.h -> aio_return>"
|
||||
default n
|
||||
|
||||
config AIO_H_AIO_SUSPEND
|
||||
bool "<aio.h -> aio_suspend>"
|
||||
default n
|
||||
|
||||
config AIO_H_AIO_WRITE
|
||||
bool "<aio.h -> aio_write>"
|
||||
default n
|
||||
|
||||
config AIO_H_AIO_LISTIO
|
||||
bool "<aio.h -> lio_listio>"
|
||||
default n
|
||||
|
||||
endif
|
||||
1
examples/utest/testcases/posix/arpa/Kconfig
Normal file
1
examples/utest/testcases/posix/arpa/Kconfig
Normal file
@@ -0,0 +1 @@
|
||||
source "$RTT_DIR/examples/utest/testcases/posix/arpa/inet_h/Kconfig"
|
||||
11
examples/utest/testcases/posix/arpa/inet_h/Kconfig
Normal file
11
examples/utest/testcases/posix/arpa/inet_h/Kconfig
Normal file
@@ -0,0 +1,11 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_ARPA_INET_H
|
||||
bool "<arpa/inet.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_ARPA_INET_H
|
||||
|
||||
config ARPA_INET_H_INTERFACE
|
||||
bool "<arpa/inet.h> -> htonl, htons, ntohl, ntohs, inet_addr, inet_ntoa, inet_ntop, inet_pton"
|
||||
default n
|
||||
|
||||
endif
|
||||
9
examples/utest/testcases/posix/ctype_h/Kconfig
Normal file
9
examples/utest/testcases/posix/ctype_h/Kconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_CTYPE_H
|
||||
bool "<ctype.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_CTYPE_H
|
||||
|
||||
# functions, TODO
|
||||
|
||||
endif
|
||||
16
examples/utest/testcases/posix/ctype_h/SConscript
Normal file
16
examples/utest/testcases/posix/ctype_h/SConscript
Normal file
@@ -0,0 +1,16 @@
|
||||
import rtconfig
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
# get current directory
|
||||
cwd = GetCurrentDir()
|
||||
path = [cwd]
|
||||
src = []
|
||||
|
||||
if GetDepend('RTT_POSIX_TESTCASE_CTYPE_H'):
|
||||
src += Glob('./definitions/*.c')
|
||||
|
||||
group = DefineGroup('rtt_posix_testcase', src, depend = ['RTT_POSIX_TESTCASE_CTYPE_H'], CPPPATH = path)
|
||||
|
||||
|
||||
Return('group')
|
||||
31
examples/utest/testcases/posix/ctype_h/definitions/ctype_h.c
Normal file
31
examples/utest/testcases/posix/ctype_h/definitions/ctype_h.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2004, Bull SA. All rights reserved.
|
||||
* Created by: Laurent.Vivier@bull.net
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
*/
|
||||
|
||||
/* <ctype.h> */
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
static char xx;
|
||||
|
||||
static int test_defined()
|
||||
{
|
||||
isalnum(xx);
|
||||
isalpha(xx);
|
||||
isblank(xx);
|
||||
iscntrl(xx);
|
||||
isdigit(xx);
|
||||
isgraph(xx);
|
||||
islower(xx);
|
||||
isprint(xx);
|
||||
ispunct(xx);
|
||||
isspace(xx);
|
||||
isupper(xx);
|
||||
isxdigit(xx);
|
||||
tolower(xx);
|
||||
toupper(xx);
|
||||
}
|
||||
11
examples/utest/testcases/posix/dirent_h/Kconfig
Normal file
11
examples/utest/testcases/posix/dirent_h/Kconfig
Normal file
@@ -0,0 +1,11 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_DIRENT_H
|
||||
bool "<dirent.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_DIRENT_H
|
||||
|
||||
config DIRENT_H_OPENDIR_READDIR_CLOSEDIR
|
||||
bool "<dirent.h> -> opendir, readdir, closedir"
|
||||
default n
|
||||
|
||||
endif
|
||||
19
examples/utest/testcases/posix/dirent_h/SConscript
Normal file
19
examples/utest/testcases/posix/dirent_h/SConscript
Normal file
@@ -0,0 +1,19 @@
|
||||
import rtconfig
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
# get current directory
|
||||
cwd = GetCurrentDir()
|
||||
path = [cwd]
|
||||
src = []
|
||||
|
||||
if GetDepend('RTT_POSIX_TESTCASE_DIRENT_H'):
|
||||
src += Glob('./definitions/*.c')
|
||||
|
||||
if GetDepend('DIRENT_H_OPENDIR_READDIR_CLOSEDIR'):
|
||||
src += Glob('./functions/open_read_close_dir_tc.c')
|
||||
|
||||
|
||||
group = DefineGroup('rtt_posix_testcase', src, depend = ['RTT_POSIX_TESTCASE_DIRENT_H'], CPPPATH = path)
|
||||
|
||||
Return('group')
|
||||
@@ -0,0 +1,41 @@
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define DIRFD_TEST_NAME "/"
|
||||
|
||||
/* API for: opendir readdir closedir */
|
||||
static int dir_test_entry(void)
|
||||
{
|
||||
DIR *dirp;
|
||||
struct dirent *d;
|
||||
|
||||
dirp = opendir(DIRFD_TEST_NAME);
|
||||
if (dirp == RT_NULL)
|
||||
{
|
||||
printf("open directory error!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
while ((d = readdir(dirp)) != RT_NULL)
|
||||
{
|
||||
printf("found %s\n", d->d_name);
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_dir(void)
|
||||
{
|
||||
uassert_int_equal(dir_test_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_dir);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.dirent_h.open_read_close_dir_tc.c", RT_NULL, RT_NULL, 10);
|
||||
|
||||
3
examples/utest/testcases/posix/errno_h/Kconfig
Normal file
3
examples/utest/testcases/posix/errno_h/Kconfig
Normal file
@@ -0,0 +1,3 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_ERRNO_H
|
||||
bool "<errno.h>"
|
||||
default n
|
||||
15
examples/utest/testcases/posix/errno_h/SConscript
Normal file
15
examples/utest/testcases/posix/errno_h/SConscript
Normal file
@@ -0,0 +1,15 @@
|
||||
import rtconfig
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
# get current directory
|
||||
cwd = GetCurrentDir()
|
||||
path = [cwd]
|
||||
src = []
|
||||
|
||||
if GetDepend('RTT_POSIX_TESTCASE_ERRNO_H'):
|
||||
src += Glob('./definitions/*.c')
|
||||
|
||||
group = DefineGroup('rtt_posix_testcase', src, depend = ['RTT_POSIX_TESTCASE_ERRNO_H'], CPPPATH = path)
|
||||
|
||||
Return('group')
|
||||
104
examples/utest/testcases/posix/errno_h/definitions/errno_h.c
Normal file
104
examples/utest/testcases/posix/errno_h/definitions/errno_h.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* This test tests if error.h is exist and useble
|
||||
*author:ysun@lnxw.com
|
||||
*/
|
||||
|
||||
#include <sys/errno.h>
|
||||
|
||||
static int errno_test;
|
||||
|
||||
__attribute__((unused)) static int dummy1 = E2BIG;
|
||||
__attribute__((unused)) static int dummy2 = EACCES;
|
||||
__attribute__((unused)) static int dummy3 = EADDRINUSE;
|
||||
__attribute__((unused)) static int dummy4 = EADDRNOTAVAIL;
|
||||
__attribute__((unused)) static int dummy5 = EAFNOSUPPORT;
|
||||
__attribute__((unused)) static int dummy6 = EAGAIN;
|
||||
__attribute__((unused)) static int dummy7 = EALREADY;
|
||||
__attribute__((unused)) static int dummy8 = EBADF;
|
||||
#ifdef EBADMSG
|
||||
__attribute__((unused)) static int dummy9 = EBADMSG;
|
||||
#endif
|
||||
__attribute__((unused)) static int dummy10 = EBUSY;
|
||||
__attribute__((unused)) static int dummy11 = ECANCELED;
|
||||
__attribute__((unused)) static int dummy12 = ECHILD;
|
||||
__attribute__((unused)) static int dummy13 = ECONNABORTED;
|
||||
__attribute__((unused)) static int dummy14 = ECONNREFUSED;
|
||||
__attribute__((unused)) static int dummy15 = ECONNRESET;
|
||||
__attribute__((unused)) static int dummy16 = EDEADLK;
|
||||
__attribute__((unused)) static int dummy17 = EDESTADDRREQ;
|
||||
__attribute__((unused)) static int dummy18 = EDOM;
|
||||
__attribute__((unused)) static int dummy19 = EDQUOT;
|
||||
__attribute__((unused)) static int dummy20 = EEXIST;
|
||||
__attribute__((unused)) static int dummy21 = EFAULT;
|
||||
__attribute__((unused)) static int dummy22 = EFBIG;
|
||||
__attribute__((unused)) static int dummy23 = EHOSTUNREACH;
|
||||
__attribute__((unused)) static int dummy24 = EIDRM;
|
||||
__attribute__((unused)) static int dummy25 = EILSEQ;
|
||||
__attribute__((unused)) static int dummy26 = EINPROGRESS;
|
||||
__attribute__((unused)) static int dummy27 = EINTR;
|
||||
__attribute__((unused)) static int dummy28 = EINVAL;
|
||||
__attribute__((unused)) static int dummy29 = EIO;
|
||||
__attribute__((unused)) static int dummy30 = EISCONN;
|
||||
__attribute__((unused)) static int dummy31 = EISDIR;
|
||||
__attribute__((unused)) static int dummy32 = ELOOP;
|
||||
__attribute__((unused)) static int dummy33 = EMFILE;
|
||||
__attribute__((unused)) static int dummy34 = EMLINK;
|
||||
__attribute__((unused)) static int dummy35 = EMSGSIZE;
|
||||
__attribute__((unused)) static int dummy36 = EMULTIHOP;
|
||||
__attribute__((unused)) static int dummy37 = ENAMETOOLONG;
|
||||
__attribute__((unused)) static int dummy38 = ENETDOWN;
|
||||
__attribute__((unused)) static int dummy39 = ENETRESET;
|
||||
__attribute__((unused)) static int dummy40 = ENETUNREACH;
|
||||
__attribute__((unused)) static int dummy41 = ENFILE;
|
||||
__attribute__((unused)) static int dummy42 = ENOBUFS;
|
||||
#ifdef ENODATA
|
||||
__attribute__((unused)) static int dummy43 = ENODATA;
|
||||
#endif
|
||||
__attribute__((unused)) static int dummy44 = ENODEV;
|
||||
__attribute__((unused)) static int dummy45 = ENOENT;
|
||||
__attribute__((unused)) static int dummy46 = ENOEXEC;
|
||||
__attribute__((unused)) static int dummy47 = ENOLCK;
|
||||
__attribute__((unused)) static int dummy48 = ENOLINK;
|
||||
__attribute__((unused)) static int dummy49 = ENOMEM;
|
||||
__attribute__((unused)) static int dummy50 = ENOMSG;
|
||||
__attribute__((unused)) static int dummy51 = ENOPROTOOPT;
|
||||
__attribute__((unused)) static int dummy52 = ENOSPC;
|
||||
#ifdef ENOSR
|
||||
__attribute__((unused)) static int dummy53 = ENOSR;
|
||||
#endif
|
||||
#ifdef ENOSTR
|
||||
__attribute__((unused)) static int dummy54 = ENOSTR;
|
||||
#endif
|
||||
__attribute__((unused)) static int dummy55 = ENOSYS;
|
||||
__attribute__((unused)) static int dummy56 = ENOTCONN;
|
||||
__attribute__((unused)) static int dummy57 = ENOTDIR;
|
||||
__attribute__((unused)) static int dummy58 = ENOTEMPTY;
|
||||
__attribute__((unused)) static int dummy59 = ENOTSOCK;
|
||||
__attribute__((unused)) static int dummy60 = ENOTSUP;
|
||||
__attribute__((unused)) static int dummy61 = ENOTTY;
|
||||
__attribute__((unused)) static int dummy62 = ENXIO;
|
||||
__attribute__((unused)) static int dummy63 = EOPNOTSUPP;
|
||||
__attribute__((unused)) static int dummy64 = EOVERFLOW;
|
||||
__attribute__((unused)) static int dummy65 = EPERM;
|
||||
__attribute__((unused)) static int dummy66 = EPIPE;
|
||||
__attribute__((unused)) static int dummy67 = EPROTO;
|
||||
__attribute__((unused)) static int dummy68 = EPROTONOSUPPORT;
|
||||
__attribute__((unused)) static int dummy69 = EPROTOTYPE;
|
||||
__attribute__((unused)) static int dummy70 = ERANGE;
|
||||
__attribute__((unused)) static int dummy71 = EROFS;
|
||||
__attribute__((unused)) static int dummy72 = ESPIPE;
|
||||
__attribute__((unused)) static int dummy73 = ESRCH;
|
||||
__attribute__((unused)) static int dummy74 = ESTALE;
|
||||
#ifdef ETIME
|
||||
__attribute__((unused)) static int dummy75 = ETIME;
|
||||
#endif
|
||||
__attribute__((unused)) static int dummy76 = ETIMEDOUT;
|
||||
__attribute__((unused)) static int dummy77 = ETXTBSY;
|
||||
__attribute__((unused)) static int dummy78 = EWOULDBLOCK;
|
||||
__attribute__((unused)) static int dummy79 = EXDEV;
|
||||
|
||||
__attribute__((unused))static int dummyfcn(void)
|
||||
{
|
||||
errno_test = errno;
|
||||
return 0;
|
||||
}
|
||||
9
examples/utest/testcases/posix/fcntl_h/Kconfig
Normal file
9
examples/utest/testcases/posix/fcntl_h/Kconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_FCNTL_H
|
||||
bool "<fcntl.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_FCNTL_H
|
||||
|
||||
# function, TODO
|
||||
|
||||
endif
|
||||
9
examples/utest/testcases/posix/fenv_h/Kconfig
Normal file
9
examples/utest/testcases/posix/fenv_h/Kconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_FENV_H
|
||||
bool "<fenv.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_FENV_H
|
||||
|
||||
# function, TODO
|
||||
|
||||
endif
|
||||
9
examples/utest/testcases/posix/inttypes_h/Kconfig
Normal file
9
examples/utest/testcases/posix/inttypes_h/Kconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_INTTYPES_H
|
||||
bool "<inttypes.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_INTTYPES_H
|
||||
|
||||
# function, TODO
|
||||
|
||||
endif
|
||||
15
examples/utest/testcases/posix/libgen_h/Kconfig
Normal file
15
examples/utest/testcases/posix/libgen_h/Kconfig
Normal file
@@ -0,0 +1,15 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_LIBGEN_H
|
||||
bool "<libgen.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_LIBGEN_H
|
||||
|
||||
config LIBGEN_H_BASENAME
|
||||
bool "<libgen.h> -> basename"
|
||||
default n
|
||||
|
||||
config LIBGEN_H_DIRNAME
|
||||
bool "<libgen.h> -> dirname"
|
||||
default n
|
||||
|
||||
endif
|
||||
15
examples/utest/testcases/posix/locale_h/Kconfig
Normal file
15
examples/utest/testcases/posix/locale_h/Kconfig
Normal file
@@ -0,0 +1,15 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_LOCALE_H
|
||||
bool "<locale.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_LOCALE_H
|
||||
|
||||
config LOCALE_H_SETLOCALE
|
||||
bool "<locale.h -> setlocale>"
|
||||
default n
|
||||
|
||||
config LIBGEN_H_LOCALECONV
|
||||
bool "<locale.h -> localconv>"
|
||||
default n
|
||||
|
||||
endif
|
||||
9
examples/utest/testcases/posix/mqueue_h/Kconfig
Normal file
9
examples/utest/testcases/posix/mqueue_h/Kconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_MQUEUE_H
|
||||
bool "<mqueue.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_MQUEUE_H
|
||||
|
||||
# functions, TODO
|
||||
|
||||
endif
|
||||
1
examples/utest/testcases/posix/net/Kconfig
Normal file
1
examples/utest/testcases/posix/net/Kconfig
Normal file
@@ -0,0 +1 @@
|
||||
source "$RTT_DIR/examples/utest/testcases/posix/net/if_h/Kconfig"
|
||||
11
examples/utest/testcases/posix/net/if_h/Kconfig
Normal file
11
examples/utest/testcases/posix/net/if_h/Kconfig
Normal file
@@ -0,0 +1,11 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_NET_IF_H
|
||||
bool "<net/if.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_NET_IF_H
|
||||
|
||||
config NET_IF_H_NAMEINDEX
|
||||
bool "<net/if.h> -> if_freenameindex, if_indextoname, if_nameindex, if_nametoindex"
|
||||
default n
|
||||
|
||||
endif
|
||||
11
examples/utest/testcases/posix/netdb_h/Kconfig
Normal file
11
examples/utest/testcases/posix/netdb_h/Kconfig
Normal file
@@ -0,0 +1,11 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_NETDB_H
|
||||
bool "<netdb.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_NETDB_H
|
||||
|
||||
config NETDB_H_ADDRINFO
|
||||
bool "<netdb.h> -> getaddrinfo, gai_strerror, getnameinfo, freeaddrinfo"
|
||||
default n
|
||||
|
||||
endif
|
||||
43
examples/utest/testcases/posix/pthread_h/Kconfig
Normal file
43
examples/utest/testcases/posix/pthread_h/Kconfig
Normal file
@@ -0,0 +1,43 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_PTHREAD_H
|
||||
bool "<pthread.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_PTHREAD_H
|
||||
|
||||
config PTHREAD_H_PTHREAD_CREATE
|
||||
bool "<pthread.h> -> pthread_create"
|
||||
default n
|
||||
|
||||
config PTHREAD_H_PTHREAD_JOIN
|
||||
bool "<pthread.h> -> pthread_join"
|
||||
default n
|
||||
|
||||
config PTHREAD_H_PTHREAD_EXIT
|
||||
bool "<pthread.h> -> pthread_exit"
|
||||
default n
|
||||
|
||||
config PTHREAD_H_PTHREAD_COND_INIT
|
||||
bool "<pthread.h> -> pthread_cond_init"
|
||||
default n
|
||||
|
||||
config PTHREAD_H_PTHREAD_COND_DESTROY
|
||||
bool "<pthread.h> -> pthread_cond_destroy"
|
||||
default n
|
||||
|
||||
config PTHREAD_H_PTHREAD_COND_BROADCAST
|
||||
bool "<pthread.h> -> pthread_cond_broadcast"
|
||||
default n
|
||||
|
||||
config PTHREAD_H_PTHREAD_COND_SIGNAL
|
||||
bool "<pthread.h> -> pthread_cond_signal"
|
||||
default n
|
||||
|
||||
config PTHREAD_H_PTHREAD_COND_TIMEWAIT
|
||||
bool "<pthread.h> -> pthread_cond_timedwait"
|
||||
default n
|
||||
|
||||
config PTHREAD_H_PTHREAD_DETACH
|
||||
bool "<pthread.h> -> pthread_detach"
|
||||
default n
|
||||
|
||||
endif
|
||||
47
examples/utest/testcases/posix/pthread_h/SConscript
Normal file
47
examples/utest/testcases/posix/pthread_h/SConscript
Normal file
@@ -0,0 +1,47 @@
|
||||
import rtconfig
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
# get current directory
|
||||
cwd = GetCurrentDir()
|
||||
path = [cwd + '/functions']
|
||||
src = []
|
||||
|
||||
src += Glob('./definitions/testfrmw/*.c')
|
||||
path += [cwd + '/functions/testfrmw']
|
||||
|
||||
if GetDepend('RTT_POSIX_TESTCASE_PTHREAD_H'):
|
||||
src += Glob('./definitions/*.c')
|
||||
|
||||
if GetDepend(['PTHREAD_H_PTHREAD_CREATE']):
|
||||
src += Glob('./functions/pthread_create/pthread_create_1-2_tc.c')
|
||||
|
||||
if GetDepend(['PTHREAD_H_PTHREAD_JOIN']):
|
||||
src += Glob('./functions/pthread_join/pthread_join_1-1_tc.c')
|
||||
|
||||
if GetDepend(['PTHREAD_H_PTHREAD_EXIT']):
|
||||
src += Glob('./functions/pthread_exit/pthread_exit_1-1_tc.c')
|
||||
|
||||
if GetDepend(['PTHREAD_H_PTHREAD_COND_INIT']):
|
||||
src += Glob('./functions/pthread_cond_init/pthread_cond_init_1-1_tc.c')
|
||||
|
||||
if GetDepend(['PTHREAD_H_PTHREAD_COND_DESTROY']):
|
||||
src += Glob('./functions/pthread_cond_destroy/pthread_cond_destroy_1-1_tc.c')
|
||||
|
||||
if GetDepend(['PTHREAD_H_PTHREAD_COND_BROADCAST']):
|
||||
src += Glob('./functions/pthread_cond_broadcast/pthread_cond_broadcast_1-1_tc.c')
|
||||
src += Glob('./functions/pthread_cond_broadcast/pthread_cond_broadcast_2-1_tc.c')
|
||||
|
||||
if GetDepend(['PTHREAD_H_PTHREAD_COND_SIGNAL']):
|
||||
src += Glob('./functions/pthread_cond_signal/pthread_cond_signal_2-2_tc.c')
|
||||
|
||||
if GetDepend(['PTHREAD_H_PTHREAD_COND_TIMEWAIT']):
|
||||
src += Glob('./functions/pthread_cond_timedwait/pthread_cond_timedwait_1-1_tc.c')
|
||||
src += Glob('./functions/pthread_cond_timedwait/pthread_cond_timedwait_2-1_tc.c')
|
||||
|
||||
if GetDepend(['PTHREAD_H_PTHREAD_DETACH']):
|
||||
src += Glob('./functions/pthread_detach/pthread_detach_4-1_tc.c')
|
||||
|
||||
group = DefineGroup('rtt_posix_testcase', src, depend = ['RTT_POSIX_TESTCASE_PTHREAD_H'], CPPPATH = path)
|
||||
|
||||
Return('group')
|
||||
159
examples/utest/testcases/posix/pthread_h/definitions/pthread_h.c
Normal file
159
examples/utest/testcases/posix/pthread_h/definitions/pthread_h.c
Normal file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Test this function is defined:
|
||||
|
||||
int pthread_mutexattr_destroy(pthread_mutexattr_t *);
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
int (*test_pthread_atfork)(void (*prepare)(void), void (*parent)(void), void (*child)(void));
|
||||
int (*test_pthread_attr_destroy)(pthread_attr_t *__attr);
|
||||
int (*test_pthread_attr_getdetachstate)(const pthread_attr_t *__attr, int *__detachstate);
|
||||
int (*test_pthread_attr_getguardsize)(const pthread_attr_t *__attr, size_t *__guardsize);
|
||||
int (*test_pthread_attr_getinheritsched)(const pthread_attr_t *__attr, int *__inheritsched);
|
||||
int (*test_pthread_attr_getschedparam)(const pthread_attr_t *__attr, struct sched_param *__param);
|
||||
int (*test_pthread_attr_getschedpolicy)(const pthread_attr_t *__attr, int *__policy);
|
||||
int (*test_pthread_attr_getscope)(const pthread_attr_t *__attr, int *__contentionscope);
|
||||
int (*test_pthread_attr_getstack)(const pthread_attr_t *attr, void **__stackaddr, size_t *__stacksize);
|
||||
int (*test_pthread_attr_getstackaddr)(const pthread_attr_t *__attr, void **__stackaddr);
|
||||
int (*test_pthread_attr_getstacksize)(const pthread_attr_t *__attr, size_t *__stacksize);
|
||||
int (*test_pthread_attr_init)(pthread_attr_t *__attr);
|
||||
int (*test_pthread_attr_setdetachstate)(pthread_attr_t *__attr, int __detachstate);
|
||||
int (*test_pthread_attr_setguardsize)(pthread_attr_t *__attr, size_t __guardsize);
|
||||
int (*test_pthread_attr_setinheritsched)(pthread_attr_t *__attr, int __inheritsched);
|
||||
int (*test_pthread_attr_setschedparam)(pthread_attr_t *__attr, const struct sched_param *__param);
|
||||
int (*test_pthread_attr_setschedpolicy)(pthread_attr_t *__attr, int __policy);
|
||||
int (*test_pthread_attr_setscope)(pthread_attr_t *__attr, int __contentionscope);
|
||||
int (*test_pthread_attr_setstack)(pthread_attr_t *attr, void *__stackaddr, size_t __stacksize);
|
||||
int (*test_pthread_attr_setstackaddr)(pthread_attr_t *__attr, void *__stackaddr);
|
||||
int (*test_pthread_attr_setstacksize)(pthread_attr_t *__attr, size_t __stacksize);
|
||||
int (*test_pthread_cancel)(pthread_t __pthread);
|
||||
void (*test_pthread_cleanup_pop)(int execute);
|
||||
void (*test_pthread_cleanup_push)(void (*routine)(void*), void *arg);
|
||||
int (*test_pthread_cond_broadcast)(pthread_cond_t *__cond);
|
||||
int (*test_pthread_cond_destroy)(pthread_cond_t *__mutex);
|
||||
int (*test_pthread_cond_init)(pthread_cond_t *__cond, const pthread_condattr_t *__attr);
|
||||
int (*test_pthread_cond_signal)(pthread_cond_t *__cond);
|
||||
int (*test_pthread_cond_timedwait)(pthread_cond_t *__cond, pthread_mutex_t *__mutex, const struct timespec *__abstime);
|
||||
int (*test_pthread_cond_wait)(pthread_cond_t *__cond, pthread_mutex_t *__mutex);
|
||||
int (*test_pthread_condattr_destroy)(pthread_condattr_t *__attr);
|
||||
int (*test_pthread_condattr_getclock)(const pthread_condattr_t *__restrict __attr, clockid_t *__restrict __clock_id);
|
||||
int (*test_pthread_condattr_init)(pthread_condattr_t *__attr);
|
||||
int (*test_pthread_condattr_setclock)(pthread_condattr_t *__attr, clockid_t __clock_id);
|
||||
int (*test_pthread_create)(pthread_t *__pthread, const pthread_attr_t *__attr, void *(*__start_routine)(void *), void *__arg);
|
||||
int (*test_pthread_detach)(pthread_t __pthread);
|
||||
int (*test_pthread_equal)(pthread_t __t1, pthread_t __t2);
|
||||
void (*test_pthread_exit)(void *__value_ptr);
|
||||
int (*test_pthread_getcpuclockid)(pthread_t thread, clockid_t *clock_id);
|
||||
int (*test_pthread_getconcurrency)(void);
|
||||
int (*test_pthread_getschedparam)(pthread_t __pthread, int *__policy, struct sched_param *__param);
|
||||
void * (*test_pthread_getspecific)(pthread_key_t __key);
|
||||
int (*test_pthread_join)(pthread_t __pthread, void **__value_ptr);
|
||||
int (*test_pthread_key_create)(pthread_key_t *__key, void (*__destructor)(void *));
|
||||
int (*test_pthread_key_delete)(pthread_key_t __key);
|
||||
int (*test_pthread_mutex_destroy)(pthread_mutex_t *__mutex);
|
||||
int (*test_pthread_mutex_getprioceiling)(const pthread_mutex_t *__restrict __mutex, int *__prioceiling);
|
||||
int (*test_pthread_mutex_init)(pthread_mutex_t *__mutex, const pthread_mutexattr_t *__attr);
|
||||
int (*test_pthread_mutex_lock)(pthread_mutex_t *__mutex);
|
||||
int (*test_pthread_mutex_setprioceiling)(pthread_mutex_t *__mutex, int __prioceiling, int *__old_ceiling);
|
||||
int (*test_pthread_mutex_trylock)(pthread_mutex_t *__mutex);
|
||||
int (*test_pthread_mutex_unlock)(pthread_mutex_t *__mutex);
|
||||
int (*test_pthread_mutexattr_destroy)(pthread_mutexattr_t *__attr);
|
||||
int (*test_pthread_mutexattr_getprioceiling)(const pthread_mutexattr_t *__attr, int *__prioceiling);
|
||||
int (*test_pthread_mutexattr_getprotocol)(const pthread_mutexattr_t *__attr, int *__protocol);
|
||||
int (*test_pthread_mutexattr_gettype)(const pthread_mutexattr_t *__attr, int *__kind);
|
||||
int (*test_pthread_mutexattr_init)(pthread_mutexattr_t *__attr);
|
||||
int (*test_pthread_mutexattr_setprioceiling)(const pthread_mutexattr_t *__attr, int __prioceiling);
|
||||
int (*test_pthread_mutexattr_setprotocol)(const pthread_mutexattr_t *__attr, int __protocol);
|
||||
int (*test_pthread_mutexattr_settype)(pthread_mutexattr_t *__attr, int __kind);
|
||||
int (*test_pthread_once)(pthread_once_t *__once_control, void (*__init_routine)(void));
|
||||
pthread_t (*test_pthread_self)(void);
|
||||
int (*test_pthread_setcancelstate)(int __state, int *__oldstate);
|
||||
int (*test_pthread_setcanceltype)(int __type, int *__oldtype);
|
||||
int (*test_pthread_setconcurrency)(int new_level);
|
||||
int (*test_pthread_setschedparam)(pthread_t __pthread, int __policy, const struct sched_param *__param);
|
||||
int (*test_pthread_setschedprio)(pthread_t thread, int prio);
|
||||
int (*test_pthread_setspecific)(pthread_key_t __key, const void *__value);
|
||||
void (*test_pthread_testcancel)(void);
|
||||
|
||||
|
||||
__attribute__((unused)) static void dummy_func()
|
||||
{
|
||||
test_pthread_atfork = pthread_atfork;
|
||||
test_pthread_attr_destroy = pthread_attr_destroy;
|
||||
test_pthread_attr_getdetachstate = pthread_attr_getdetachstate;
|
||||
test_pthread_attr_getguardsize = pthread_attr_getguardsize;
|
||||
test_pthread_attr_getinheritsched = pthread_attr_getinheritsched;
|
||||
test_pthread_attr_getschedparam = pthread_attr_getschedparam;
|
||||
test_pthread_attr_getschedpolicy = pthread_attr_getschedpolicy;
|
||||
test_pthread_attr_getscope = pthread_attr_getscope;
|
||||
test_pthread_attr_getstack = pthread_attr_getstack;
|
||||
test_pthread_attr_getstackaddr = pthread_attr_getstackaddr;
|
||||
test_pthread_attr_getstacksize = pthread_attr_getstacksize;
|
||||
test_pthread_attr_init = pthread_attr_init;
|
||||
test_pthread_attr_setdetachstate = pthread_attr_setdetachstate;
|
||||
test_pthread_attr_setguardsize = pthread_attr_setguardsize;
|
||||
test_pthread_attr_setinheritsched = pthread_attr_setinheritsched;
|
||||
test_pthread_attr_setschedparam = pthread_attr_setschedparam;
|
||||
test_pthread_attr_setschedpolicy = pthread_attr_setschedpolicy;
|
||||
test_pthread_attr_setscope = pthread_attr_setscope;
|
||||
test_pthread_attr_setstack = pthread_attr_setstack;
|
||||
test_pthread_attr_setstackaddr = pthread_attr_setstackaddr;
|
||||
test_pthread_attr_setstacksize = pthread_attr_setstacksize;
|
||||
test_pthread_cancel = pthread_cancel;
|
||||
test_pthread_cleanup_pop = pthread_cleanup_pop;
|
||||
test_pthread_cleanup_push = pthread_cleanup_push;
|
||||
test_pthread_cond_broadcast = pthread_cond_broadcast;
|
||||
test_pthread_cond_destroy = pthread_cond_destroy;
|
||||
test_pthread_cond_init = pthread_cond_init;
|
||||
test_pthread_cond_signal = pthread_cond_signal;
|
||||
test_pthread_cond_timedwait = pthread_cond_timedwait;
|
||||
test_pthread_cond_wait = pthread_cond_wait;
|
||||
test_pthread_condattr_destroy = pthread_condattr_destroy;
|
||||
test_pthread_condattr_getclock = pthread_condattr_getclock;
|
||||
test_pthread_condattr_init = pthread_condattr_init;
|
||||
test_pthread_condattr_setclock = pthread_condattr_setclock;
|
||||
test_pthread_create = pthread_create;
|
||||
test_pthread_detach = pthread_detach;
|
||||
test_pthread_equal = pthread_equal;
|
||||
test_pthread_exit = pthread_exit;
|
||||
test_pthread_getcpuclockid = pthread_getcpuclockid;
|
||||
test_pthread_getconcurrency = pthread_getconcurrency;
|
||||
test_pthread_getschedparam = pthread_getschedparam;
|
||||
test_pthread_getspecific = pthread_getspecific;
|
||||
test_pthread_join = pthread_join;
|
||||
test_pthread_key_create = pthread_key_create;
|
||||
test_pthread_key_delete = pthread_key_delete;
|
||||
test_pthread_mutex_destroy = pthread_mutex_destroy;
|
||||
test_pthread_mutex_getprioceiling = pthread_mutex_getprioceiling;
|
||||
test_pthread_mutex_init = pthread_mutex_init;
|
||||
test_pthread_mutex_lock = pthread_mutex_lock;
|
||||
test_pthread_mutex_setprioceiling = pthread_mutex_setprioceiling;
|
||||
test_pthread_mutex_trylock = pthread_mutex_trylock;
|
||||
test_pthread_mutex_unlock = pthread_mutex_unlock;
|
||||
test_pthread_mutexattr_destroy = pthread_mutexattr_destroy;
|
||||
test_pthread_mutexattr_getprioceiling = pthread_mutexattr_getprioceiling;
|
||||
test_pthread_mutexattr_getprotocol = pthread_mutexattr_getprotocol;
|
||||
test_pthread_mutexattr_gettype = pthread_mutexattr_gettype;
|
||||
test_pthread_mutexattr_init = pthread_mutexattr_init;
|
||||
test_pthread_mutexattr_setprioceiling = pthread_mutexattr_setprioceiling;
|
||||
test_pthread_mutexattr_setprotocol = pthread_mutexattr_setprotocol;
|
||||
test_pthread_mutexattr_settype = pthread_mutexattr_settype;
|
||||
test_pthread_once = pthread_once;
|
||||
test_pthread_self = pthread_self;
|
||||
test_pthread_setcancelstate = pthread_setcancelstate;
|
||||
test_pthread_setcanceltype = pthread_setcanceltype;
|
||||
test_pthread_setconcurrency = pthread_setconcurrency;
|
||||
test_pthread_setschedparam = pthread_setschedparam;
|
||||
test_pthread_setschedprio = pthread_setschedprio;
|
||||
test_pthread_setspecific = pthread_setspecific;
|
||||
test_pthread_testcancel = pthread_testcancel;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
*/
|
||||
|
||||
/*
|
||||
* return codes
|
||||
*/
|
||||
|
||||
#define PTS_PASS 0
|
||||
#define PTS_FAIL 1
|
||||
#define PTS_UNRESOLVED 2
|
||||
#define PTS_UNSUPPORTED 4
|
||||
#define PTS_UNTESTED 5
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
#endif
|
||||
|
||||
#define PTS_ATTRIBUTE_NORETURN __attribute__((noreturn))
|
||||
#define PTS_ATTRIBUTE_UNUSED __attribute__((unused))
|
||||
#define PTS_ATTRIBUTE_UNUSED_RESULT __attribute__((warn_unused_result))
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_cond_broadcast()
|
||||
* When each thread unblocked as a result of pthread_cond_signal()
|
||||
* returns from its call to pthread_cond_wait(), the thread shall
|
||||
* own the mutex with which it called pthread_cond_wait().
|
||||
*/
|
||||
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define THREAD_NUM 3
|
||||
|
||||
static struct testdata {
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
} td;
|
||||
|
||||
static int start_num;
|
||||
static int waken_num;
|
||||
|
||||
static void *thr_func(void *arg PTS_ATTRIBUTE_UNUSED)
|
||||
{
|
||||
int rc;
|
||||
pthread_t self = pthread_self();
|
||||
|
||||
if (pthread_mutex_lock(&td.mutex) != 0) {
|
||||
fprintf(stderr, "[Thread 0x%p] failed to acquire the mutex\n",
|
||||
(void *)self);
|
||||
exit(PTS_UNRESOLVED);
|
||||
}
|
||||
fprintf(stderr, "[Thread 0x%p] started and locked the mutex\n",
|
||||
(void *)self);
|
||||
start_num++;
|
||||
|
||||
fprintf(stderr, "[Thread 0x%p] is waiting for the cond\n",
|
||||
(void *)self);
|
||||
rc = pthread_cond_wait(&td.cond, &td.mutex);
|
||||
if (rc != 0) {
|
||||
fprintf(stderr, "pthread_cond_wait return %d\n", rc);
|
||||
exit(PTS_UNRESOLVED);
|
||||
}
|
||||
|
||||
if (pthread_mutex_trylock(&td.mutex) == 0) {
|
||||
fprintf(stderr, "[Thread 0x%p] should not be able to lock the "
|
||||
"mutex again\n", (void *)self);
|
||||
printf("Test FAILED\n");
|
||||
exit(PTS_FAIL);
|
||||
}
|
||||
fprintf(stderr, "[Thread 0x%p] was wakened and acquired the "
|
||||
"mutex again\n", (void *)self);
|
||||
waken_num++;
|
||||
|
||||
if (pthread_mutex_unlock(&td.mutex) != 0) {
|
||||
fprintf(stderr, "[Thread 0x%p] failed to release the "
|
||||
"mutex\n", (void *)self);
|
||||
printf("Test FAILED\n");
|
||||
exit(PTS_FAIL);
|
||||
}
|
||||
fprintf(stderr, "[Thread 0x%p] released the mutex\n", (void *)self);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int posix_testcase(void)
|
||||
{
|
||||
struct timespec completion_wait_ts = {0, 100000};
|
||||
int i, rc;
|
||||
pthread_t thread[THREAD_NUM];
|
||||
|
||||
if (pthread_mutex_init(&td.mutex, NULL) != 0) {
|
||||
fprintf(stderr, "Fail to initialize mutex\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
if (pthread_cond_init(&td.cond, NULL) != 0) {
|
||||
fprintf(stderr, "Fail to initialize cond\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
for (i = 0; i < THREAD_NUM; i++) {
|
||||
if (pthread_create(&thread[i], NULL, thr_func, NULL) != 0) {
|
||||
fprintf(stderr, "Fail to create thread[%d]\n", i);
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
}
|
||||
while (start_num < THREAD_NUM)
|
||||
nanosleep(&completion_wait_ts, NULL);
|
||||
|
||||
/* Acquire the mutex to make sure that all waiters are currently
|
||||
blocked on pthread_cond_wait */
|
||||
if (pthread_mutex_lock(&td.mutex) != 0) {
|
||||
fprintf(stderr, "Main: Fail to acquire mutex\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
if (pthread_mutex_unlock(&td.mutex) != 0) {
|
||||
fprintf(stderr, "Main: Fail to release mutex\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* broadcast the condition to wake up all waiters */
|
||||
fprintf(stderr, "[Main thread] broadcast the condition\n");
|
||||
rc = pthread_cond_broadcast(&td.cond);
|
||||
if (rc != 0) {
|
||||
fprintf(stderr, "[Main thread] failed to broadcast the "
|
||||
"condition\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
sleep(1);
|
||||
if (waken_num < THREAD_NUM) {
|
||||
fprintf(stderr, "[Main thread] Not all waiters were wakened\n");
|
||||
for (i = 0; i < THREAD_NUM; i++)
|
||||
pthread_cancel(thread[i]);
|
||||
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
fprintf(stderr, "[Main thread] all waiters were wakened\n");
|
||||
|
||||
/* join all secondary threads */
|
||||
for (i = 0; i < THREAD_NUM; i++) {
|
||||
if (pthread_join(thread[i], NULL) != 0) {
|
||||
fprintf(stderr, "Fail to join thread[%d]\n", i);
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
}
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
#include <rtt_utest_internal.h>
|
||||
UTEST_TC_EXPORT(testcase, "posix.pthread_cond_broadcast.2-1.c", RT_NULL, RT_NULL, 10);
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_cond_destroy()
|
||||
* shall destroy the condition variable referenced by 'cond';
|
||||
* the condition variable object in effect becomes uninitialized.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
static pthread_cond_t cond1, cond2;
|
||||
static pthread_cond_t cond3 = PTHREAD_COND_INITIALIZER;
|
||||
|
||||
static int posix_testcase(void)
|
||||
{
|
||||
pthread_condattr_t condattr;
|
||||
int rc;
|
||||
|
||||
/* Initialize a condition variable attribute object */
|
||||
if ((rc = pthread_condattr_init(&condattr)) != 0) {
|
||||
fprintf(stderr, "Error at pthread_condattr_init(), rc=%d\n",
|
||||
rc);
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
printf("Line-%04d\n", __LINE__);
|
||||
|
||||
/* Initialize cond1 with the default condition variable attribute */
|
||||
if ((rc = pthread_cond_init(&cond1, &condattr)) != 0) {
|
||||
fprintf(stderr, "Fail to initialize cond1, rc=%d\n", rc);
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
printf("Line-%04d\n", __LINE__);
|
||||
/* Initialize cond2 with NULL attributes */
|
||||
if ((rc = pthread_cond_init(&cond2, NULL)) != 0) {
|
||||
fprintf(stderr, "Fail to initialize cond2, rc=%d\n", rc);
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
printf("Line-%04d\n", __LINE__);
|
||||
/* Destroy the condition variable attribute object */
|
||||
if ((rc = pthread_condattr_destroy(&condattr)) != 0) {
|
||||
fprintf(stderr, "Error at pthread_condattr_destroy(), rc=%d\n",
|
||||
rc);
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
printf("Line-%04d\n", __LINE__);
|
||||
/* Destroy cond1 */
|
||||
if ((rc = pthread_cond_destroy(&cond1)) != 0) {
|
||||
fprintf(stderr, "Fail to destroy cond1, rc=%d\n", rc);
|
||||
printf("Test FAILED\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("Line-%04d\n", __LINE__);
|
||||
/* Destroy cond2 */
|
||||
if ((rc = pthread_cond_destroy(&cond2)) != 0) {
|
||||
fprintf(stderr, "Fail to destroy cond2, rc=%d\n", rc);
|
||||
printf("Test FAILED\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("Line-%04d", __LINE__);
|
||||
/* Destroy cond3 */
|
||||
if ((rc = pthread_cond_destroy(&cond3)) != 0) {
|
||||
fprintf(stderr, "Fail to destroy cond3, rc=%d\n", rc);
|
||||
printf("Test FAILED\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("Line-%04d", __LINE__);
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
#include <rtt_utest_internal.h>
|
||||
UTEST_TC_EXPORT(testcase, "posix.pthread_cond_destroy.1-1.c", RT_NULL, RT_NULL, 10);
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_cond_init()
|
||||
* shall initialize the condition variable referenced by cond with attributes
|
||||
* referenced by attr. If attr is NULL, the default condition variable
|
||||
* attributes shall be used; the effect is the same as passing the address
|
||||
* of a default condition variable attributes object.
|
||||
|
||||
* NOTE: There is no direct way to judge if two condition variables are equal,
|
||||
* so this test does not cover the statement in the last sentence.
|
||||
*
|
||||
*
|
||||
* Modified - LK coding style 30/05/2011
|
||||
* Peter W. Morreale <pmorreale AT novell DOT com>
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define ERR_MSG(f, rc) printf("Failed: func: %s rc: %s (%u)\n", \
|
||||
f, strerror(rc), rc);
|
||||
|
||||
static int posix_testcase(void)
|
||||
{
|
||||
pthread_condattr_t condattr;
|
||||
pthread_cond_t cond1;
|
||||
pthread_cond_t cond2;
|
||||
int rc;
|
||||
char *f;
|
||||
int status = PTS_UNRESOLVED;
|
||||
|
||||
f = "pthread_condattr_init()";
|
||||
rc = pthread_condattr_init(&condattr);
|
||||
if (rc)
|
||||
goto done;
|
||||
|
||||
status = PTS_FAIL;
|
||||
f = "pthread_cond_init() - condattr";
|
||||
rc = pthread_cond_init(&cond1, &condattr);
|
||||
if (rc)
|
||||
goto done;
|
||||
|
||||
f = "pthread_cond_init() - NULL";
|
||||
rc = pthread_cond_init(&cond2, NULL);
|
||||
if (rc)
|
||||
goto done;
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
|
||||
done:
|
||||
ERR_MSG(f, rc);
|
||||
return status;
|
||||
|
||||
}
|
||||
#include <rtt_utest_internal.h>
|
||||
UTEST_TC_EXPORT(testcase, "posix.pthread_cond_init.1-1.c", RT_NULL, RT_NULL, 10);
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_cond_timedwait()
|
||||
* shall be equivalent to pthread_cond_wait(), except that an error is returned
|
||||
* if the absolute time specified by abstime passes before the condition cond is
|
||||
* signaled or broadcasted, or if the absolute time specified by abstime has
|
||||
* already been passed at the time of the call.
|
||||
*
|
||||
* Case 2-1
|
||||
* Upon successful return, the mutex shall have been locked and shall
|
||||
* be owned by the calling thread.
|
||||
*/
|
||||
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define INTERVAL 1
|
||||
#define TIMEOUT 5
|
||||
|
||||
static struct testdata {
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
} td;
|
||||
|
||||
static int t1_start = 0;
|
||||
static int signaled = 0;
|
||||
|
||||
static void *t1_func(void *arg)
|
||||
{
|
||||
int rc;
|
||||
struct timespec timeout;
|
||||
struct timeval curtime;
|
||||
|
||||
(void) arg;
|
||||
|
||||
if (pthread_mutex_lock(&td.mutex) != 0) {
|
||||
fprintf(stderr, "Thread1 failed to acquire the mutex\n");
|
||||
exit(PTS_UNRESOLVED);
|
||||
}
|
||||
fprintf(stderr, "Thread1 started\n");
|
||||
t1_start = 1; /* let main thread continue */
|
||||
|
||||
if (gettimeofday(&curtime, NULL) != 0) {
|
||||
fprintf(stderr, "Fail to get current time\n");
|
||||
exit(PTS_UNRESOLVED);
|
||||
}
|
||||
timeout.tv_sec = curtime.tv_sec + TIMEOUT;
|
||||
timeout.tv_nsec = curtime.tv_usec * 1000;
|
||||
|
||||
fprintf(stderr, "Thread1 is waiting for the cond\n");
|
||||
rc = pthread_cond_timedwait(&td.cond, &td.mutex, &timeout);
|
||||
if (rc != 0) {
|
||||
if (rc == ETIMEDOUT) {
|
||||
fprintf(stderr,
|
||||
"Thread1 stops waiting when time is out\n");
|
||||
exit(PTS_UNRESOLVED);
|
||||
} else {
|
||||
fprintf(stderr, "pthread_cond_timedwait return %d\n",
|
||||
rc);
|
||||
exit(PTS_UNRESOLVED);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "Thread1 wakened\n");
|
||||
if (signaled == 0) {
|
||||
fprintf(stderr, "Thread1 did not block on the cond at all\n");
|
||||
exit(PTS_UNRESOLVED);
|
||||
}
|
||||
|
||||
if (pthread_mutex_trylock(&td.mutex) == 0) {
|
||||
fprintf(stderr,
|
||||
"Thread1 should not be able to lock the mutex again\n");
|
||||
printf("Test FAILED\n");
|
||||
exit(PTS_FAIL);
|
||||
}
|
||||
fprintf(stderr, "Thread1 failed to trylock the mutex (as expected)\n");
|
||||
|
||||
if (pthread_mutex_unlock(&td.mutex) != 0) {
|
||||
fprintf(stderr, "Thread1 failed to release the mutex\n");
|
||||
printf("Test FAILED\n");
|
||||
exit(PTS_FAIL);
|
||||
}
|
||||
fprintf(stderr, "Thread1 released the mutex\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int posix_testcase(void)
|
||||
{
|
||||
pthread_t thread1;
|
||||
struct timespec thread_start_ts = {0, 100000};
|
||||
|
||||
if (pthread_mutex_init(&td.mutex, NULL) != 0) {
|
||||
fprintf(stderr, "Fail to initialize mutex\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
if (pthread_cond_init(&td.cond, NULL) != 0) {
|
||||
fprintf(stderr, "Fail to initialize cond\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (pthread_create(&thread1, NULL, t1_func, NULL) != 0) {
|
||||
fprintf(stderr, "Fail to create thread 1\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
while (!t1_start) /* wait for thread1 started */
|
||||
nanosleep(&thread_start_ts, NULL);
|
||||
|
||||
/* acquire the mutex released by pthread_cond_wait() within thread 1 */
|
||||
if (pthread_mutex_lock(&td.mutex) != 0) {
|
||||
fprintf(stderr, "Main failed to acquire mutex\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
if (pthread_mutex_unlock(&td.mutex) != 0) {
|
||||
fprintf(stderr, "Main failed to release mutex\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
sleep(INTERVAL);
|
||||
|
||||
fprintf(stderr, "Time to wake up thread1 by signaling a condition\n");
|
||||
signaled = 1;
|
||||
if (pthread_cond_signal(&td.cond) != 0) {
|
||||
fprintf(stderr, "Main failed to signal the condition\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
pthread_join(thread1, NULL);
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
#include <rtt_utest_internal.h>
|
||||
UTEST_TC_EXPORT(testcase, "posix.pthread_cond_timedwait.2-1.c", RT_NULL, RT_NULL, 10);
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_create() creates a new thread with attributes specified
|
||||
* by 'attr', within a process.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a thread using pthread_create()
|
||||
* 2. Cancel that thread with pthread_cancel()
|
||||
* 3. If that thread doesn't exist, then it pthread_cancel() will return
|
||||
* an error code. This would mean that pthread_create() did not create
|
||||
* a thread successfully.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
static void *a_thread_func()
|
||||
{
|
||||
sleep(10);
|
||||
|
||||
/* Shouldn't reach here. If we do, then the pthread_cancel()
|
||||
* function did not succeed. */
|
||||
fprintf(stderr, "Could not send cancel request correctly\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int posix_testcase(void)
|
||||
{
|
||||
pthread_t new_th;
|
||||
int ret;
|
||||
|
||||
ret = pthread_create(&new_th, NULL, a_thread_func, NULL);
|
||||
if (ret) {
|
||||
fprintf(stderr, "pthread_create(): %s\n", strerror(ret));
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Try to cancel the newly created thread. If an error is returned,
|
||||
* then the thread wasn't created successfully. */
|
||||
ret = pthread_cancel(new_th);
|
||||
if (ret) {
|
||||
printf("Test FAILED: A new thread wasn't created: %s\n",
|
||||
strerror(ret));
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
#include <rtt_utest_internal.h>
|
||||
UTEST_TC_EXPORT(testcase, "posix.pthread_create.1-2.c", RT_NULL, RT_NULL, 10);
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_detach()
|
||||
*
|
||||
* shall detach a thread. It shall indicate to the implementation that storage
|
||||
* for 'thread' can be reclaimed when that thread terminates.
|
||||
*
|
||||
* STEPS:
|
||||
* 1. Create a joinable thread
|
||||
* 2. Detach that thread with pthread_detach()
|
||||
* 3. Try and join the thread to main() using pthread_join()
|
||||
* 4. An error should return from the pthread_join() function saying that the
|
||||
* thread is detched. The test passes.
|
||||
* 5. Else, if pthread_join is successful, the test fails.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
static void *a_thread_func()
|
||||
{
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
|
||||
/* If the thread wasn't canceled in 10 seconds, time out */
|
||||
sleep(10);
|
||||
|
||||
perror("Thread couldn't be canceled (at cleanup time), timing out\n");
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int posix_testcase(void)
|
||||
{
|
||||
pthread_attr_t new_attr;
|
||||
pthread_t new_th;
|
||||
int ret;
|
||||
|
||||
/* Initialize attribute */
|
||||
if (pthread_attr_init(&new_attr) != 0) {
|
||||
perror("Cannot initialize attribute object\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Set the attribute object to be joinable */
|
||||
if (pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_JOINABLE) !=
|
||||
0) {
|
||||
perror("Error in pthread_attr_setdetachstate()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Create the thread */
|
||||
if (pthread_create(&new_th, &new_attr, a_thread_func, NULL) != 0) {
|
||||
perror("Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Detach the thread. */
|
||||
if (pthread_detach(new_th) != 0) {
|
||||
printf("Error detaching thread\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
/* Now try and join it. This should fail. */
|
||||
ret = pthread_join(new_th, NULL);
|
||||
|
||||
/* Cleanup: Cancel the thread */
|
||||
pthread_cancel(new_th);
|
||||
|
||||
if (ret == 0) {
|
||||
printf("Test FAILED\n");
|
||||
return PTS_FAIL;
|
||||
} else if (ret == EINVAL) {
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
} else {
|
||||
perror("Error in pthread_join\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
}
|
||||
#include <rtt_utest_internal.h>
|
||||
UTEST_TC_EXPORT(testcase, "posix.pthread_detach.1-1.c", RT_NULL, RT_NULL, 10);
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_detach()
|
||||
*
|
||||
* If 'thread' has not terminated, pthread_detach() shall not cause it to
|
||||
* terminate. The effect of multiple pthread_detach() calls on the same
|
||||
*
|
||||
* STEPS:
|
||||
* 1.Create a joinable thread
|
||||
* 2.Detach that thread
|
||||
* 3.Verify that the thread did not terminate because of this
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
static void *a_thread_func()
|
||||
{
|
||||
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
|
||||
/* If the thread wasn't canceled in 10 seconds, time out */
|
||||
sleep(10);
|
||||
|
||||
perror("Thread couldn't be canceled (at cleanup time), timing out\n");
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int posix_testcase(void)
|
||||
{
|
||||
pthread_attr_t new_attr;
|
||||
pthread_t new_th;
|
||||
int ret;
|
||||
|
||||
/* Initialize attribute */
|
||||
if (pthread_attr_init(&new_attr) != 0) {
|
||||
perror("Cannot initialize attribute object\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Set the attribute object to be joinable */
|
||||
if (pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_JOINABLE) !=
|
||||
0) {
|
||||
perror("Error in pthread_attr_setdetachstate()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Create the thread */
|
||||
if (pthread_create(&new_th, &new_attr, a_thread_func, NULL) != 0) {
|
||||
perror("Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Detach the thread. */
|
||||
if (pthread_detach(new_th) != 0) {
|
||||
printf("Error detaching thread\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
/* Verify that it hasn't terminated the thread */
|
||||
ret = pthread_cancel(new_th);
|
||||
|
||||
if (ret != 0) {
|
||||
if (ret == ESRCH) {
|
||||
printf("Test FAILED\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
perror("Error canceling thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
#include <rtt_utest_internal.h>
|
||||
UTEST_TC_EXPORT(testcase, "posix.pthread_detach.2-1.c", RT_NULL, RT_NULL, 10);
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_detach()
|
||||
*
|
||||
* Upon failure, it shall return an error number:
|
||||
* -[EINVAL] The implemenation has detected that the value specified by
|
||||
* 'thread' does not refer to a joinable thread.
|
||||
* -[ESRCH] No thread could be found corresponding to that thread
|
||||
|
||||
* It shall not return an error code of [EINTR]
|
||||
*
|
||||
* STEPS:
|
||||
* 1.Create a detached state thread
|
||||
* 2.Detach that thread
|
||||
* 3.Check the return value and make sure it is EINVAL
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
/* Thread function */
|
||||
static void *a_thread_func()
|
||||
{
|
||||
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
|
||||
/* If the thread wasn't canceled in 10 seconds, time out */
|
||||
sleep(10);
|
||||
|
||||
perror("Thread couldn't be canceled (at cleanup time), timing out\n");
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int posix_testcase(void)
|
||||
{
|
||||
pthread_attr_t new_attr;
|
||||
pthread_t new_th;
|
||||
int ret;
|
||||
|
||||
/* Initialize attribute */
|
||||
if (pthread_attr_init(&new_attr) != 0) {
|
||||
perror("Cannot initialize attribute object\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Set the attribute object to be detached */
|
||||
if (pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_DETACHED) !=
|
||||
0) {
|
||||
perror("Error in pthread_attr_setdetachstate()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Create the thread */
|
||||
if (pthread_create(&new_th, &new_attr, a_thread_func, NULL) != 0) {
|
||||
perror("Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Detach the thread. */
|
||||
ret = pthread_detach(new_th);
|
||||
|
||||
/* Cleanup and cancel the thread */
|
||||
pthread_cancel(new_th);
|
||||
|
||||
/* Check return value of pthread_detach() */
|
||||
if (ret != EINVAL) {
|
||||
if (ret == ESRCH) {
|
||||
perror("Error detaching thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
printf("Test FAILED: Incorrect return code\n");
|
||||
return PTS_FAIL;
|
||||
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
#include <rtt_utest_internal.h>
|
||||
UTEST_TC_EXPORT(testcase, "posix.pthread_detach.4-1.c", RT_NULL, RT_NULL, 10);
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_exit()
|
||||
*
|
||||
* terminates the calling thread and makes the value 'value_ptr' available
|
||||
* to any successful join with the terminating thread.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a new thread. Have it return a return code on pthread_exit();
|
||||
* 2. Call pthread_join() in main(), and pass to it 'value_ptr'.
|
||||
* 3. Check to see of the value_ptr and the value returned by pthread_exit() are the same;
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define RETURN_CODE 100 /* Set a random return code number. This shall be the return code of the
|
||||
thread when using pthread_exit(). */
|
||||
|
||||
#define INTHREAD 0 /* Control going to or is already for Thread */
|
||||
#define INMAIN 1 /* Control going to or is already for Main */
|
||||
|
||||
static int sem; /* Manual semaphore used to indicate when the thread has been created. */
|
||||
|
||||
/* Thread's function. */
|
||||
static void *a_thread_func()
|
||||
{
|
||||
sem = INMAIN;
|
||||
pthread_exit((void *)RETURN_CODE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int posix_testcase(void)
|
||||
{
|
||||
pthread_t new_th;
|
||||
int *value_ptr;
|
||||
|
||||
/* Initializing variables. */
|
||||
value_ptr = 0;
|
||||
sem = INTHREAD;
|
||||
|
||||
/* Create a new thread. */
|
||||
if (pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) {
|
||||
perror("Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Make sure the thread was created before we join it. */
|
||||
while (sem == INTHREAD)
|
||||
sleep(1);
|
||||
|
||||
/* Wait for thread to return */
|
||||
if (pthread_join(new_th, (void *)&value_ptr) != 0) {
|
||||
perror("Error in pthread_join()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Check to make sure that 'value_ptr' that was passed to pthread_join() and the
|
||||
* pthread_exit() return code that was used in the thread function are the same. */
|
||||
if ((long)value_ptr != RETURN_CODE) {
|
||||
printf
|
||||
("Test FAILED: pthread_exit() could not pass the return value of the thread in 'value_ptr' to pthread_join().\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
#include <rtt_utest_internal.h>
|
||||
UTEST_TC_EXPORT(testcase, "posix.pthread_exit.1-1.c", RT_NULL, RT_NULL, 10);
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
*
|
||||
* Test that pthread_join()
|
||||
*
|
||||
* shall suspend the execution of the calling thread until the target
|
||||
* 'thread' terminates, unless 'thread' has already terminated.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a new thread. Have it sleep for 3 seconds.
|
||||
* 2. The main() thread should wait for the new thread to finish
|
||||
* execution before exiting out.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
static int end_exec;
|
||||
|
||||
static void *a_thread_func()
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("Wait for 3 seconds for thread to finish execution:\n");
|
||||
for (i = 1; i < 4; i++) {
|
||||
printf("Waited (%d) second\n", i);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
/* Indicate that the thread has ended execution. */
|
||||
end_exec = 1;
|
||||
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int posix_testcase(void)
|
||||
{
|
||||
pthread_t new_th;
|
||||
|
||||
/* Initialize flag */
|
||||
end_exec = 0;
|
||||
|
||||
/* Create a new thread. */
|
||||
if (pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) {
|
||||
perror("Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Wait for thread to return */
|
||||
if (pthread_join(new_th, NULL) != 0) {
|
||||
perror("Error in pthread_join()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (end_exec == 0) {
|
||||
printf("Test FAILED: When using pthread_join(), "
|
||||
"main() did not wait for thread to finish "
|
||||
"execution before continuing.\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
#include <rtt_utest_internal.h>
|
||||
UTEST_TC_EXPORT(testcase, "posix.pthread_join.1-1.c", RT_NULL, RT_NULL, 10);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <utest.h>
|
||||
#include <pthread.h>
|
||||
static void posix_unit_test(void)
|
||||
{
|
||||
pthread_t new_th; /* Create a new thread. */
|
||||
int err_val;
|
||||
|
||||
if (pthread_create(&new_th, NULL, (void *(*)(void *))posix_testcase, NULL) != 0) {
|
||||
perror("Error creating thread\n");
|
||||
}
|
||||
|
||||
/* Wait for thread to return */
|
||||
if (pthread_join(new_th, (void*)&err_val) != 0) {
|
||||
perror("Error in pthread_join()\n");
|
||||
}
|
||||
|
||||
rt_thread_mdelay(1000);
|
||||
|
||||
uassert_true(err_val == 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(posix_unit_test);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2004, Bull S.A.. All rights reserved.
|
||||
* Created by: Sebastien Decugis
|
||||
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it would be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
|
||||
* This file is a wrapper to use the tests from the NPTL Test & Trace Project
|
||||
* with either the Linux Test Project or the Open POSIX Test Suite.
|
||||
|
||||
* The following function are defined:
|
||||
* void output_init()
|
||||
* void output_fini()
|
||||
* void output(char * string, ...)
|
||||
*
|
||||
* The are used to output informative text (as a printf).
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/* We use a mutex to avoid conflicts in traces */
|
||||
static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static void output_init(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static void output(char *string, ...)
|
||||
{
|
||||
va_list ap;
|
||||
struct tm *now;
|
||||
time_t nw;
|
||||
int oldstate;
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
|
||||
pthread_mutex_lock(&m_trace);
|
||||
nw = time(NULL);
|
||||
now = localtime(&nw);
|
||||
if (now == NULL)
|
||||
printf("[??:??:??]\n");
|
||||
else
|
||||
printf("[%2.2d:%2.2d:%2.2d]\n",
|
||||
now->tm_hour, now->tm_min, now->tm_sec);
|
||||
va_start(ap, string);
|
||||
vprintf(string, ap);
|
||||
va_end(ap);
|
||||
pthread_mutex_unlock(&m_trace);
|
||||
pthread_setcancelstate(oldstate, NULL);
|
||||
}
|
||||
|
||||
static void output_fini(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2004, Bull S.A.. All rights reserved.
|
||||
* Created by: Sebastien Decugis
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it would be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* This file is a wrapper to use the tests from the NPTL Test & Trace Project
|
||||
* with either the Linux Test Project or the Open POSIX Test Suite.
|
||||
*
|
||||
* The following macros are defined here:
|
||||
* UNRESOLVED(ret, descr);
|
||||
* where descr is a description of the error and ret is
|
||||
* an int (error code for example)
|
||||
* FAILED(descr);
|
||||
* where descr is a short text saying why the test has failed.
|
||||
* PASSED();
|
||||
* No parameter.
|
||||
*
|
||||
* Both three macros shall terminate the calling process.
|
||||
* The testcase shall not terminate without calling one of those macros.
|
||||
*/
|
||||
|
||||
#include "posixtest.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
#define UNRESOLVED(x, s) \
|
||||
{ \
|
||||
output("Test %s unresolved: got %i (%s) on line %i (%s)\n", \
|
||||
__FILE__, x, strerror(x), __LINE__, s); \
|
||||
output_fini(); \
|
||||
exit(PTS_UNRESOLVED); \
|
||||
}
|
||||
|
||||
#define FAILED(s) \
|
||||
{ \
|
||||
output("Test %s FAILED: %s\n", __FILE__, s); \
|
||||
output_fini(); \
|
||||
exit(PTS_FAIL); \
|
||||
}
|
||||
|
||||
#define PASSED \
|
||||
{ \
|
||||
output_fini(); \
|
||||
exit(PTS_PASS); \
|
||||
}
|
||||
|
||||
#define UNTESTED(s) \
|
||||
{ \
|
||||
output("File %s cannot test: %s\n", __FILE__, s); \
|
||||
output_fini(); \
|
||||
exit(PTS_UNTESTED); \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define UNRESOLVED(x, s) \
|
||||
{ \
|
||||
output("Test unresolved: got %i (%s) on line %i (%s)\n", \
|
||||
x, strerror(x), __LINE__, s); \
|
||||
output_fini(); \
|
||||
exit(PTS_UNRESOLVED); \
|
||||
}
|
||||
|
||||
#define FAILED(s) \
|
||||
{ \
|
||||
output("Test FAILED: %s\n", s); \
|
||||
output_fini(); \
|
||||
exit(PTS_FAIL); \
|
||||
}
|
||||
|
||||
#define PASSED \
|
||||
{ \
|
||||
output_fini(); \
|
||||
exit(PTS_PASS); \
|
||||
}
|
||||
|
||||
#define UNTESTED(s) \
|
||||
{ \
|
||||
output("Unable to test: %s\n", s); \
|
||||
output_fini(); \
|
||||
exit(PTS_UNTESTED); \
|
||||
}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
9
examples/utest/testcases/posix/sched_h/Kconfig
Normal file
9
examples/utest/testcases/posix/sched_h/Kconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_SCHED_H
|
||||
bool "<sched.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_SCHED_H
|
||||
|
||||
# functions, TODO
|
||||
|
||||
endif
|
||||
9
examples/utest/testcases/posix/semaphore_h/Kconfig
Normal file
9
examples/utest/testcases/posix/semaphore_h/Kconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_SEMAPHORE_H
|
||||
bool "<semaphore.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_SEMAPHORE_H
|
||||
|
||||
# functions, TODO
|
||||
|
||||
endif
|
||||
9
examples/utest/testcases/posix/setjmp_h/Kconfig
Normal file
9
examples/utest/testcases/posix/setjmp_h/Kconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_SETJMP_H
|
||||
bool "<setjmp.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_SETJMP_H
|
||||
|
||||
# functions, TODO
|
||||
|
||||
endif
|
||||
23
examples/utest/testcases/posix/signal_h/Kconfig
Normal file
23
examples/utest/testcases/posix/signal_h/Kconfig
Normal file
@@ -0,0 +1,23 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_SIGNAL_H
|
||||
bool "<signal.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_SIGNAL_H
|
||||
|
||||
config SIGNAL_H_SIGACTION
|
||||
bool "<signal.h> -> sigaction"
|
||||
default n
|
||||
|
||||
config SIGNAL_H_SIGPROCMASK
|
||||
bool "<signal.h> -> sigprocmask"
|
||||
default n
|
||||
|
||||
config SIGNAL_H_RAISE
|
||||
bool "<signal.h> -> raise"
|
||||
default n
|
||||
|
||||
config SIGNAL_H_SIGNAL
|
||||
bool "<signal.h> -> signal"
|
||||
default n
|
||||
|
||||
endif
|
||||
9
examples/utest/testcases/posix/stdarg_h/Kconfig
Normal file
9
examples/utest/testcases/posix/stdarg_h/Kconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_STDARG_H
|
||||
bool "<stdarg.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_STDARG_H
|
||||
|
||||
# functions, TODO
|
||||
|
||||
endif
|
||||
149
examples/utest/testcases/posix/stdio_h/Kconfig
Normal file
149
examples/utest/testcases/posix/stdio_h/Kconfig
Normal file
@@ -0,0 +1,149 @@
|
||||
menuconfig RTT_POSIX_TESTCASE_STDIO_H
|
||||
bool "<stdio.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_STDIO_H
|
||||
|
||||
config STDIO_H_CLEARERR
|
||||
bool "<stdio.h> -> clearerr"
|
||||
default n
|
||||
|
||||
config STDIO_H_FCLOSE
|
||||
bool "<stdio.h> -> fclose"
|
||||
default n
|
||||
|
||||
config STDIO_H_FDOPEN
|
||||
bool "<stdio.h> -> fdopen"
|
||||
default n
|
||||
|
||||
config STDIO_H_FEOF
|
||||
bool "<stdio.h> -> feof"
|
||||
default n
|
||||
|
||||
config STDIO_H_FERROR
|
||||
bool "<stdio.h> -> ferror"
|
||||
default n
|
||||
|
||||
config STDIO_H_FFLUSH
|
||||
bool "<stdio.h> -> fflush"
|
||||
default n
|
||||
|
||||
config STDIO_H_FGETC
|
||||
bool "<stdio.h> -> fgetc"
|
||||
default n
|
||||
|
||||
config STDIO_H_FGETS
|
||||
bool "<stdio.h> -> fgets"
|
||||
default n
|
||||
|
||||
config STDIO_H_FILENO
|
||||
bool "<stdio.h> -> fileno"
|
||||
default n
|
||||
|
||||
config STDIO_H_FOPEN
|
||||
bool "<stdio.h> -> fopen"
|
||||
default n
|
||||
|
||||
config STDIO_H_FPRINTF
|
||||
bool "<stdio.h> -> fprintf"
|
||||
default n
|
||||
|
||||
config STDIO_H_FPUTC
|
||||
bool "<stdio.h> -> fputc"
|
||||
default n
|
||||
|
||||
config STDIO_H_FPUTS
|
||||
bool "<stdio.h> -> fputs"
|
||||
default n
|
||||
|
||||
config STDIO_H_FREAD
|
||||
bool "<stdio.h> -> fread"
|
||||
default n
|
||||
|
||||
config STDIO_H_FSCANF
|
||||
bool "<stdio.h> -> fscanf"
|
||||
default n
|
||||
|
||||
config STDIO_H_FSEEK
|
||||
bool "<stdio.h> -> fseek"
|
||||
default n
|
||||
|
||||
config STDIO_H_FTELL
|
||||
bool "<stdio.h> -> ftell"
|
||||
default n
|
||||
|
||||
config STDIO_H_FWRITE
|
||||
bool "<stdio.h> -> fwrite"
|
||||
default n
|
||||
|
||||
|
||||
|
||||
config STDIO_H_PERROR
|
||||
bool "<stdio.h> -> perror"
|
||||
default n
|
||||
|
||||
config STDIO_H_PRINTF
|
||||
bool "<stdio.h> -> printf"
|
||||
default n
|
||||
|
||||
config STDIO_H_PUTC
|
||||
bool "<stdio.h> -> putc"
|
||||
default n
|
||||
|
||||
config STDIO_H_PUTCHAR
|
||||
bool "<stdio.h> -> putchar"
|
||||
default n
|
||||
|
||||
config STDIO_H_PUTS
|
||||
bool "<stdio.h> -> puts"
|
||||
default n
|
||||
|
||||
config STDIO_H_REMOVE
|
||||
bool "<stdio.h> -> remove"
|
||||
default n
|
||||
|
||||
config STDIO_H_RENAME
|
||||
bool "<stdio.h> -> rename"
|
||||
default n
|
||||
|
||||
config STDIO_H_REWIND
|
||||
bool "<stdio.h> -> rewind"
|
||||
default n
|
||||
|
||||
config STDIO_H_SETBUF
|
||||
bool "<stdio.h> -> setbuf"
|
||||
default n
|
||||
|
||||
config STDIO_H_SETVBUF
|
||||
bool "<stdio.h> -> setvbuf"
|
||||
default n
|
||||
|
||||
config STDIO_H_SNPRINTF
|
||||
bool "<stdio.h> -> snprintf"
|
||||
default n
|
||||
|
||||
config STDIO_H_SPRINTF
|
||||
bool "<stdio.h> -> sprintf"
|
||||
default n
|
||||
|
||||
config STDIO_H_SSCANF
|
||||
bool "<stdio.h> -> sscanf"
|
||||
default n
|
||||
|
||||
config STDIO_H_VFPRINTF
|
||||
bool "<stdio.h> -> vfprintf"
|
||||
default n
|
||||
|
||||
config STDIO_H_VPRINTF
|
||||
bool "<stdio.h> -> vprintf"
|
||||
default n
|
||||
|
||||
config STDIO_H_VSNPRINTF
|
||||
bool "<stdio.h> -> vsnprintf"
|
||||
default n
|
||||
|
||||
config STDIO_H_VSPRINTF
|
||||
bool "<stdio.h> -> vsprintf"
|
||||
default n
|
||||
|
||||
endif
|
||||
116
examples/utest/testcases/posix/stdio_h/SConscript
Normal file
116
examples/utest/testcases/posix/stdio_h/SConscript
Normal file
@@ -0,0 +1,116 @@
|
||||
import rtconfig
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
# get current directory
|
||||
cwd = GetCurrentDir()
|
||||
path = [cwd]
|
||||
src = []
|
||||
|
||||
if GetDepend('RTT_POSIX_TESTCASE_STDIO_H'):
|
||||
src += Glob('./definitions/*.c')
|
||||
|
||||
|
||||
if GetDepend('STDIO_H_CLEARERR'):
|
||||
src += Glob('./functions/clearerr.c')
|
||||
|
||||
if GetDepend('STDIO_H_FCLOSE'):
|
||||
src += Glob('./functions/fclose.c')
|
||||
|
||||
if GetDepend('STDIO_H_FDOPEN'):
|
||||
src += Glob('./functions/fdopen_tc.c')
|
||||
|
||||
if GetDepend('STDIO_H_FEOF'):
|
||||
src += Glob('./functions/feof.c')
|
||||
|
||||
if GetDepend('STDIO_H_FERROR'):
|
||||
src += Glob('./functions/ferror.c')
|
||||
|
||||
if GetDepend('STDIO_H_FFLUSH'):
|
||||
src += Glob('./functions/fflush.c')
|
||||
|
||||
if GetDepend('STDIO_H_FGETC'):
|
||||
src += Glob('./functions/fgetc.c')
|
||||
|
||||
if GetDepend('STDIO_H_FGETS'):
|
||||
src += Glob('./functions/fgets.c')
|
||||
|
||||
if GetDepend('STDIO_H_FILENO'):
|
||||
src += Glob('./functions/fileno.c')
|
||||
|
||||
if GetDepend('STDIO_H_FOPEN'):
|
||||
src += Glob('./functions/fopen.c')
|
||||
|
||||
if GetDepend('STDIO_H_FPRINTF'):
|
||||
src += Glob('./functions/fprintf.c')
|
||||
|
||||
if GetDepend('STDIO_H_FPUTC'):
|
||||
src += Glob('./functions/fputc.c')
|
||||
|
||||
if GetDepend('STDIO_H_FPUTS'):
|
||||
src += Glob('./functions/fputs.c')
|
||||
|
||||
if GetDepend('STDIO_H_FREAD'):
|
||||
src += Glob('./functions/fread.c')
|
||||
|
||||
if GetDepend('STDIO_H_FSCANF'):
|
||||
src += Glob('./functions/fscanf.c')
|
||||
|
||||
if GetDepend('STDIO_H_FSEEK'):
|
||||
src += Glob('./functions/fseek.c')
|
||||
|
||||
if GetDepend('STDIO_H_FTELL'):
|
||||
src += Glob('./functions/ftell.c')
|
||||
|
||||
if GetDepend('STDIO_H_FWRITE'):
|
||||
src += Glob('./functions/fwrite.c')
|
||||
|
||||
|
||||
if GetDepend('STDIO_H_PERROR'):
|
||||
src += Glob('./functions/perror.c')
|
||||
|
||||
if GetDepend('STDIO_H_PRINTF'):
|
||||
src += Glob('./functions/printf.c')
|
||||
|
||||
if GetDepend('STDIO_H_PUTC'):
|
||||
src += Glob('./functions/puts.c')
|
||||
|
||||
if GetDepend('STDIO_H_REMOVE'):
|
||||
src += Glob('./functions/remove.c')
|
||||
|
||||
if GetDepend('STDIO_H_RENAME'):
|
||||
src += Glob('./functions/rename.c')
|
||||
|
||||
if GetDepend('STDIO_H_REWIND'):
|
||||
src += Glob('./functions/rewind.c')
|
||||
|
||||
if GetDepend('STDIO_H_SETBUF'):
|
||||
src += Glob('./functions/setbuf.c')
|
||||
|
||||
if GetDepend('STDIO_H_SETVBUF'):
|
||||
src += Glob('./functions/setvbuf.c')
|
||||
|
||||
if GetDepend('STDIO_H_SNPRINTF'):
|
||||
src += Glob('./functions/snprintf.c')
|
||||
|
||||
if GetDepend('STDIO_H_SPRINTF'):
|
||||
src += Glob('./functions/sprintf.c')
|
||||
|
||||
if GetDepend('STDIO_H_SSCANF'):
|
||||
src += Glob('./functions/sscanf.c')
|
||||
|
||||
if GetDepend('STDIO_H_VFPRINTF'):
|
||||
src += Glob('./functions/vfprintf.c')
|
||||
|
||||
if GetDepend('STDIO_H_VPRINTF'):
|
||||
src += Glob('./functions/vprintf.c')
|
||||
|
||||
if GetDepend('STDIO_H_VSNPRINTF'):
|
||||
src += Glob('./functions/vsnprintf.c')
|
||||
|
||||
if GetDepend('STDIO_H_VSPRINTF'):
|
||||
src += Glob('./functions/vsprintf.c')
|
||||
|
||||
group = DefineGroup('rtt_posix_testcase', src, depend = ['RTT_POSIX_TESTCASE_STDIO_H'], CPPPATH = path)
|
||||
|
||||
Return('group')
|
||||
123
examples/utest/testcases/posix/stdio_h/definitions/stdio_h.c
Normal file
123
examples/utest/testcases/posix/stdio_h/definitions/stdio_h.c
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2004, Bull SA. All rights reserved.
|
||||
* Created by: Laurent.Vivier@bull.net
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
*/
|
||||
|
||||
/* test if stdio.h exists and can be included */
|
||||
|
||||
// #define _POSIX_C_SOURCE 2
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
void (*test_clearerr)(FILE *);
|
||||
int (*test_fclose)(FILE *);
|
||||
FILE * (*test_fdopen)(int, const char *);
|
||||
int (*test_feof)(FILE *);
|
||||
int (*test_ferror)(FILE *);
|
||||
int (*test_fflush)(FILE *);
|
||||
int (*test_fgetc)(FILE *);
|
||||
char * (*test_fgets)(char *__restrict, int, FILE *__restrict);
|
||||
int (*test_fileno)(FILE *);
|
||||
void (*test_flockfile)(FILE *);
|
||||
FILE * (*test_fopen)(const char *__restrict _name, const char *__restrict _type);
|
||||
int (*test_fprintf)(FILE *__restrict, const char *__restrict, ...);
|
||||
int (*test_fputc)(int, FILE *);
|
||||
int (*test_fputs)(const char *__restrict, FILE *__restrict);
|
||||
size_t (*test_fread)(void *__restrict, size_t _size, size_t _n, FILE *__restrict);
|
||||
FILE * (*test_freopen)(const char *__restrict, const char *__restrict, FILE *__restrict);
|
||||
int (*test_fscanf)(FILE *__restrict, const char *__restrict, ...);
|
||||
int (*test_ftrylockfile)(FILE *);
|
||||
void (*test_funlockfile)(FILE *);
|
||||
size_t (*test_fwrite)(const void *__restrict , size_t _size, size_t _n, FILE *);
|
||||
int (*test_getc)(FILE *);
|
||||
int (*test_getc_unlocked)(FILE *);
|
||||
int (*test_getchar)(void);
|
||||
int (*test_getchar_unlocked)(void);
|
||||
char * (*test_gets)(char *);
|
||||
void (*test_perror)(const char *);
|
||||
int (*test_printf)(const char *__restrict, ...);
|
||||
int (*test_putc)(int, FILE *);
|
||||
int (*test_putc_unlocked)(int, FILE *);
|
||||
int (*test_putchar)(int);
|
||||
int (*test_putchar_unlocked)(int);
|
||||
int (*test_puts)(const char *);
|
||||
int (*test_scanf)(const char *__restrict, ...);
|
||||
void (*test_setbuf)(FILE *__restrict, char *__restrict);
|
||||
int (*test_setvbuf)(FILE *__restrict, char *__restrict, int, size_t);
|
||||
int (*test_snprintf)(char *__restrict, size_t, const char *__restrict, ...);
|
||||
int (*test_sprintf)(char *__restrict, const char *__restrict, ...);
|
||||
int (*test_sscanf)(const char *__restrict, const char *__restrict, ...);
|
||||
int (*test_ungetc)(int, FILE *);
|
||||
|
||||
FILE *test_stderr;
|
||||
FILE *test_stdin;
|
||||
FILE *test_stdout;
|
||||
|
||||
int (*test_vfprintf)(FILE *restrict, const char *restrict, va_list);
|
||||
int (*test_vfscanf)(FILE *restrict, const char *restrict, va_list);
|
||||
int (*test_vprintf)(const char *restrict, va_list);
|
||||
int (*test_vscanf)(const char *restrict, va_list);
|
||||
int (*test_vsnprintf)(char *restrict, size_t, const char *restrict, va_list);
|
||||
int (*test_vsprintf)(char *restrict, const char *restrict, va_list);
|
||||
int (*test_vsscanf)(const char *restrict, const char *restrict, va_list);
|
||||
|
||||
__attribute__((unused)) static int test_defined()
|
||||
{
|
||||
test_clearerr = clearerr;
|
||||
test_fclose = fclose;
|
||||
// test_fdopen = fdopen;
|
||||
test_feof = feof;
|
||||
test_ferror = ferror;
|
||||
test_fflush = fflush;
|
||||
test_fgetc = fgetc;
|
||||
test_fgets = fgets;
|
||||
// test_fileno = fileno;
|
||||
// test_flockfile = flockfile;
|
||||
test_fopen = fopen;
|
||||
test_fprintf = fprintf;
|
||||
test_fputc = fputc;
|
||||
test_fputs = fputs;
|
||||
test_fread = fread;
|
||||
test_freopen = freopen;
|
||||
test_fscanf = fscanf;
|
||||
// test_ftrylockfile = ftrylockfile;
|
||||
// test_funlockfile = funlockfile;
|
||||
test_fwrite = fwrite;
|
||||
test_getc = getc;
|
||||
// test_getc_unlocked = getc_unlocked;
|
||||
test_getchar = getchar;
|
||||
test_gets = gets;
|
||||
test_perror = perror;
|
||||
test_printf = printf;
|
||||
test_putc = putc;
|
||||
// test_putc_unlocked = putc_unlocked;
|
||||
test_putchar = putchar;
|
||||
// test_putchar_unlocked = putchar_unlocked;
|
||||
test_puts = puts;
|
||||
test_scanf = scanf;
|
||||
test_setbuf = setbuf;
|
||||
test_setvbuf = setvbuf;
|
||||
test_snprintf = snprintf;
|
||||
test_sprintf = sprintf;
|
||||
test_sscanf = sscanf;
|
||||
test_ungetc = ungetc;
|
||||
|
||||
test_stderr = stderr;
|
||||
test_stdin = stdin;
|
||||
test_stdout = stdout;
|
||||
|
||||
test_vfprintf = vfprintf;
|
||||
test_vfscanf = vfscanf;
|
||||
test_vprintf = vprintf;
|
||||
test_vscanf = vscanf;
|
||||
test_vsnprintf = vsnprintf;
|
||||
test_vsprintf = vsprintf;
|
||||
test_vsscanf = vsscanf;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user