From b7127c23695100e390e597d6dd97a216e568e552 Mon Sep 17 00:00:00 2001 From: ganlan Date: Wed, 7 Sep 2022 02:52:24 +0800 Subject: [PATCH] add libctest cases Signed-off-by: ganlan --- .../src/functionalext/common/functionalext.h | 42 +- .../src/functionalext/supplement/BUILD.gn | 24 + .../functionalext/supplement/conf/BUILD.gn | 29 + .../functionalext/supplement/conf/fpathconf.c | 95 ++++ .../supplement/conf/get_avphys_page.c | 53 ++ .../supplement/conf/get_nprocs.c | 53 ++ .../supplement/conf/get_nprocs_conf.c | 53 ++ .../supplement/conf/get_phys_pages.c | 53 ++ .../functionalext/supplement/conf/pathconf.c | 70 +++ .../functionalext/supplement/conf/sysconf.c | 50 ++ ...test_src_functionalext_supplement_conf.gni | 22 + .../functionalext/supplement/ctype/BUILD.gn | 29 + .../supplement/ctype/__ctype_get_mb_cur_max.c | 77 +++ .../functionalext/supplement/ctype/isalnum.c | 81 +++ .../supplement/ctype/isalnum_l.c | 89 +++ .../functionalext/supplement/ctype/isalpha.c | 95 ++++ .../supplement/ctype/isalpha_l.c | 85 +++ .../functionalext/supplement/ctype/isascii.c | 44 ++ .../functionalext/supplement/ctype/isblank.c | 152 ++++++ .../supplement/ctype/isblank_l.c | 172 ++++++ .../functionalext/supplement/ctype/iscntrl.c | 92 ++++ .../supplement/ctype/iscntrl_l.c | 103 ++++ .../functionalext/supplement/ctype/isdigit.c | 87 +++ .../functionalext/supplement/ctype/isgraph.c | 54 ++ .../supplement/ctype/isgraph_l.c | 88 +++ .../functionalext/supplement/ctype/islower.c | 123 +++++ .../functionalext/supplement/ctype/isprint.c | 92 ++++ .../supplement/ctype/isprint_l.c | 103 ++++ .../functionalext/supplement/ctype/ispunct.c | 98 ++++ .../supplement/ctype/ispunct_l.c | 102 ++++ .../functionalext/supplement/ctype/isspace.c | 143 +++++ .../supplement/ctype/isspace_l.c | 150 +++++ .../functionalext/supplement/ctype/isupper.c | 123 +++++ .../functionalext/supplement/ctype/iswalhpa.c | 117 ++++ .../functionalext/supplement/ctype/iswalnum.c | 57 ++ .../functionalext/supplement/ctype/iswalpha.c | 56 ++ .../functionalext/supplement/ctype/iswblank.c | 89 +++ .../functionalext/supplement/ctype/iswcntrl.c | 96 ++++ .../functionalext/supplement/ctype/iswctype.c | 97 ++++ .../functionalext/supplement/ctype/iswdigit.c | 89 +++ .../functionalext/supplement/ctype/iswlower.c | 104 ++++ .../functionalext/supplement/ctype/iswprint.c | 89 +++ .../functionalext/supplement/ctype/iswpunct.c | 89 +++ .../functionalext/supplement/ctype/iswspace.c | 89 +++ .../functionalext/supplement/ctype/iswupper.c | 104 ++++ .../supplement/ctype/iswxdigit.c | 104 ++++ .../functionalext/supplement/ctype/isxdigit.c | 139 +++++ ...est_src_functionalext_supplement_ctype.gni | 60 ++ .../functionalext/supplement/ctype/toascii.c | 67 +++ .../functionalext/supplement/ctype/tolower.c | 83 +++ .../functionalext/supplement/ctype/toupper.c | 83 +++ .../supplement/ctype/towctrans.c | 78 +++ .../functionalext/supplement/ctype/towlower.c | 55 ++ .../functionalext/supplement/ctype/wcswidth.c | 70 +++ .../functionalext/supplement/ctype/wctrans.c | 65 +++ .../supplement/ctype/wctrans_l.c | 65 +++ .../functionalext/supplement/ctype/wctype.c | 265 +++++++++ .../functionalext/supplement/ctype/wcwidth.c | 239 ++++++++ .../functionalext/supplement/dirent/BUILD.gn | 29 + .../supplement/dirent/alphasort.c | 53 ++ .../supplement/dirent/closedir.c | 56 ++ .../functionalext/supplement/dirent/dirfd.c | 62 +++ .../supplement/dirent/fdopendir.c | 94 ++++ .../functionalext/supplement/dirent/opendir.c | 85 +++ .../functionalext/supplement/dirent/readdir.c | 55 ++ .../supplement/dirent/readdir_r.c | 72 +++ .../supplement/dirent/rewinddir.c | 88 +++ .../functionalext/supplement/dirent/scandir.c | 116 ++++ .../functionalext/supplement/dirent/seekdir.c | 140 +++++ .../functionalext/supplement/dirent/telldir.c | 74 +++ ...st_src_functionalext_supplement_dirent.gni | 26 + .../src/functionalext/supplement/env/BUILD.gn | 29 + .../src/functionalext/supplement/env/putenv.c | 75 +++ .../test_src_functionalext_supplement_env.gni | 14 + .../functionalext/supplement/errno/BUILD.gn | 29 + .../supplement/errno/__errno_location.c | 67 +++ .../functionalext/supplement/errno/strerror.c | 47 ++ ...est_src_functionalext_supplement_errno.gni | 17 + .../functionalext/supplement/exit/BUILD.gn | 29 + .../supplement/exit/__aeabi_atexit.c | 53 ++ .../supplement/exit/a_cxa_atexit.c | 72 +++ .../supplement/exit/a_cxa_finalize.c | 47 ++ .../supplement/exit/at_quick_exit.c | 62 +++ .../functionalext/supplement/exit/atexit.c | 37 ++ .../supplement/exit/quick_exit.c | 53 ++ ...test_src_functionalext_supplement_exit.gni | 21 + .../functionalext/supplement/fcntl/BUILD.gn | 29 + .../functionalext/supplement/fcntl/creat.c | 76 +++ .../src/functionalext/supplement/fcntl/open.c | 221 ++++++++ .../functionalext/supplement/fcntl/openat.c | 60 ++ .../supplement/fcntl/posix_fadvise.c | 150 +++++ .../supplement/fcntl/posix_fallocate.c | 119 ++++ ...est_src_functionalext_supplement_fcntl.gni | 20 + .../functionalext/supplement/fenv/BUILD.gn | 29 + .../supplement/fenv/__flt_rounds.c | 39 ++ .../supplement/fenv/feholdexcept.c | 36 ++ .../supplement/fenv/feupdateenv.c | 36 ++ ...test_src_functionalext_supplement_fenv.gni | 18 + .../src/functionalext/supplement/ipc/BUILD.gn | 29 + .../src/functionalext/supplement/ipc/ftok.c | 48 ++ .../functionalext/supplement/ipc/semtimedop.c | 111 ++++ .../test_src_functionalext_supplement_ipc.gni | 17 + .../functionalext/supplement/ldso/BUILD.gn | 29 + .../supplement/ldso/a_gnu_Unwind_Find_exidx.c | 42 ++ .../supplement/ldso/dl_iterate_phdr.c | 52 ++ .../functionalext/supplement/ldso/dladdr.c | 72 +++ ...test_src_functionalext_supplement_ldso.gni | 23 + .../functionalext/supplement/legacy/BUILD.gn | 29 + .../functionalext/supplement/legacy/daemon.c | 101 ++++ .../src/functionalext/supplement/legacy/ftw.c | 45 ++ .../functionalext/supplement/legacy/futimes.c | 80 +++ .../supplement/legacy/getdtablesize.c | 36 ++ .../supplement/legacy/getloadavg.c | 43 ++ .../supplement/legacy/getpagesize.c | 46 ++ .../functionalext/supplement/legacy/lutimes.c | 71 +++ ...st_src_functionalext_supplement_legacy.gni | 26 + .../functionalext/supplement/legacy/verr.c | 39 ++ .../functionalext/supplement/legacy/verrx.c | 39 ++ .../functionalext/supplement/legacy/vwarn.c | 39 ++ .../functionalext/supplement/legacy/vwarnx.c | 39 ++ .../functionalext/supplement/linux/BUILD.gn | 29 + .../functionalext/supplement/linux/adjtimex.c | 61 +++ .../src/functionalext/supplement/linux/brk.c | 47 ++ .../functionalext/supplement/linux/capget.c | 83 +++ .../functionalext/supplement/linux/capset.c | 85 +++ .../functionalext/supplement/linux/chroot.c | 75 +++ .../supplement/linux/clock_adjtime.c | 107 ++++ .../functionalext/supplement/linux/clone.c | 50 ++ .../supplement/linux/copy_file_range.c | 152 ++++++ .../functionalext/supplement/linux/eventfd.c | 58 ++ .../supplement/linux/eventfd_read.c | 71 +++ .../supplement/linux/eventfd_write.c | 71 +++ .../supplement/linux/fallocate.c | 102 ++++ .../supplement/linux/fgetxattr.c | 49 ++ .../supplement/linux/flistxattr.c | 61 +++ .../functionalext/supplement/linux/flock.c | 179 ++++++ .../supplement/linux/fremovexattr.c | 47 ++ .../supplement/linux/fsetxattr.c | 46 ++ .../functionalext/supplement/linux/getdents.c | 85 +++ .../supplement/linux/getrandom.c | 39 ++ .../functionalext/supplement/linux/getxattr.c | 73 +++ .../functionalext/supplement/linux/inotify.c | 173 ++++++ .../supplement/linux/inotify_init1.c | 82 +++ .../functionalext/supplement/linux/klogctl.c | 49 ++ .../supplement/linux/lgetxattr.c | 78 +++ .../supplement/linux/listxattr.c | 83 +++ .../supplement/linux/llistxattr.c | 84 +++ .../supplement/linux/lremovexattr.c | 80 +++ .../supplement/linux/lsetxattr.c | 73 +++ .../supplement/linux/membarrier.c | 69 +++ .../supplement/linux/memfd_create.c | 59 ++ .../functionalext/supplement/linux/mlock2.c | 70 +++ .../functionalext/supplement/linux/mount.c | 41 ++ .../supplement/linux/name_to_handle_at.c | 56 ++ .../supplement/linux/open_by_handle_at.c | 63 +++ .../supplement/linux/personality.c | 34 ++ .../functionalext/supplement/linux/ppoll.c | 87 +++ .../functionalext/supplement/linux/prctl.c | 50 ++ .../functionalext/supplement/linux/prlimit.c | 64 +++ .../supplement/linux/process_vm.c | 157 ++++++ .../functionalext/supplement/linux/ptrace.c | 40 ++ .../functionalext/supplement/linux/quotactl.c | 39 ++ .../supplement/linux/readahead.c | 38 ++ .../supplement/linux/remap_file_pages.c | 62 +++ .../supplement/linux/removexattr.c | 113 ++++ .../src/functionalext/supplement/linux/sbrk.c | 61 +++ .../functionalext/supplement/linux/sendfile.c | 101 ++++ .../functionalext/supplement/linux/setfsgid.c | 65 +++ .../functionalext/supplement/linux/setfsuid.c | 65 +++ .../supplement/linux/setgroups.c | 78 +++ .../functionalext/supplement/linux/setns.c | 72 +++ .../supplement/linux/settimeofday.c | 75 +++ .../functionalext/supplement/linux/setxattr.c | 97 ++++ .../functionalext/supplement/linux/signalfd.c | 92 ++++ .../functionalext/supplement/linux/splice.c | 144 +++++ .../functionalext/supplement/linux/swapoff.c | 52 ++ .../functionalext/supplement/linux/swapon.c | 47 ++ .../supplement/linux/sync_file_range.c | 128 +++++ .../functionalext/supplement/linux/syncfs.c | 71 +++ .../functionalext/supplement/linux/sysinfo.c | 88 +++ .../src/functionalext/supplement/linux/tee.c | 105 ++++ ...est_src_functionalext_supplement_linux.gni | 82 +++ .../supplement/linux/timerfd_create.c | 74 +++ .../supplement/linux/timerfd_gettime.c | 84 +++ .../supplement/linux/timerfd_settime.c | 87 +++ .../functionalext/supplement/linux/utimes.c | 92 ++++ .../functionalext/supplement/linux/vmsplice.c | 61 +++ .../functionalext/supplement/linux/wait3.c | 87 +++ .../functionalext/supplement/linux/wait4.c | 87 +++ .../functionalext/supplement/locale/BUILD.gn | 30 + .../supplement/locale/duplocale.c | 80 +++ .../supplement/locale/langinfo.c | 138 +++++ .../supplement/locale/localeconv.c | 65 +++ .../supplement/locale/newlocale.c | 101 ++++ .../supplement/locale/setlocale.c | 182 ++++++ .../functionalext/supplement/locale/strxfrm.c | 168 ++++++ ...st_src_functionalext_supplement_locale.gni | 24 + .../supplement/locale/uselocale.c | 73 +++ .../functionalext/supplement/locale/wcscoll.c | 39 ++ .../functionalext/supplement/locale/wcsxfrm.c | 60 ++ .../functionalext/supplement/malloc/BUILD.gn | 30 + .../supplement/malloc/aligned_alloc.c | 44 ++ .../supplement/malloc/malloc_usable_size.c | 59 ++ .../supplement/malloc/memalign.c | 137 +++++ .../supplement/malloc/posix_memalign.c | 63 +++ .../functionalext/supplement/malloc/realloc.c | 104 ++++ ...st_src_functionalext_supplement_malloc.gni | 20 + .../functionalext/supplement/manual/BUILD.gn | 24 + .../supplement/manual/env/BUILD.gn | 29 + .../supplement/manual/env/a_stack_chk_fail.c | 63 +++ ...rc_functionalext_supplement_manual_env.gni | 14 + .../supplement/manual/network/BUILD.gn | 29 + .../supplement/manual/network/gethostbyaddr.c | 63 +++ .../manual/network/gethostbyaddr_r.c | 58 ++ .../manual/network/gethostbyname2.c | 108 ++++ .../manual/network/gethostbyname2_r.c | 93 ++++ .../manual/network/gethostbyname_r.c | 83 +++ .../supplement/manual/network/getnameinfo.c | 179 ++++++ .../supplement/manual/network/getnetbyaddr.c | 127 +++++ .../supplement/manual/network/getnetbyname.c | 72 +++ .../manual/network/res_querydomain.c | 109 ++++ .../supplement/manual/network/res_send.c | 47 ++ ...unctionalext_supplement_manual_network.gni | 26 + .../supplement/manual/termios/BUILD.gn | 29 + .../supplement/manual/termios/tcgetattr.c | 59 ++ .../supplement/manual/termios/tcgetsid.c | 65 +++ .../supplement/manual/termios/tcsendbreak.c | 56 ++ .../supplement/manual/termios/tcsetattr.c | 71 +++ ...unctionalext_supplement_manual_termios.gni | 19 + ...st_src_functionalext_supplement_maunal.gni | 20 + .../supplement/manual/thread/BUILD.gn | 29 + .../supplement/manual/thread/cnd_broadcast.c | 62 +++ ...functionalext_supplement_manual_thread.gni | 14 + .../supplement/manual/unistd/BUILD.gn | 29 + .../supplement/manual/unistd/isatty.c | 68 +++ .../supplement/manual/unistd/tcgetpgrp.c | 82 +++ .../supplement/manual/unistd/tcsetpgrp.c | 82 +++ ...functionalext_supplement_manual_unistd.gni | 19 + .../supplement/manual/unistd/ttyname.c | 58 ++ .../functionalext/supplement/math/BUILD.gn | 29 + .../supplement/math/__fpclassifyf.c | 81 +++ .../supplement/math/__fpclassifyl.c | 81 +++ .../functionalext/supplement/math/__signbit.c | 73 +++ .../supplement/math/__signbitf.c | 69 +++ .../supplement/math/__signbitl.c | 70 +++ .../functionalext/supplement/math/finite.c | 106 ++++ .../functionalext/supplement/math/finitef.c | 101 ++++ .../src/functionalext/supplement/math/nan.c | 36 ++ .../src/functionalext/supplement/math/nanf.c | 36 ++ .../src/functionalext/supplement/math/nanl.c | 38 ++ .../src/functionalext/supplement/math/rint.c | 93 ++++ .../supplement/math/significand.c | 65 +++ .../supplement/math/significandf.c | 65 +++ ...test_src_functionalext_supplement_math.gni | 28 + .../functionalext/supplement/mbrlen/BUILD.gn | 29 + .../functionalext/supplement/mbrlen/mbrlen.c | 64 +++ ...st_src_functionalext_supplement_mbrlen.gni | 14 + .../functionalext/supplement/misc/BUILD.gn | 29 + .../functionalext/supplement/misc/endmntent.c | 44 ++ .../src/functionalext/supplement/misc/ffs.c | 89 +++ .../src/functionalext/supplement/misc/ffsl.c | 66 +++ .../src/functionalext/supplement/misc/ffsll.c | 69 +++ .../functionalext/supplement/misc/forkpty.c | 77 +++ .../functionalext/supplement/misc/getauxval.c | 63 +++ .../supplement/misc/getdomainname.c | 72 +++ .../supplement/misc/getentropy.c | 54 ++ .../functionalext/supplement/misc/getmntent.c | 83 +++ .../supplement/misc/getmntent_r.c | 122 +++++ .../functionalext/supplement/misc/getopt.c | 162 ++++++ .../supplement/misc/getopt_long.c | 62 +++ .../supplement/misc/getopt_long_only.c | 62 +++ .../supplement/misc/getpriority.c | 114 ++++ .../functionalext/supplement/misc/getresgid.c | 42 ++ .../functionalext/supplement/misc/getresuid.c | 71 +++ .../functionalext/supplement/misc/getrlimit.c | 59 ++ .../functionalext/supplement/misc/getrusage.c | 92 ++++ .../functionalext/supplement/misc/getsubopt.c | 57 ++ .../functionalext/supplement/misc/hasmntopt.c | 57 ++ .../supplement/misc/initgroups.c | 48 ++ .../src/functionalext/supplement/misc/ioctl.c | 134 +++++ .../functionalext/supplement/misc/issetugid.c | 37 ++ .../src/functionalext/supplement/misc/lockf.c | 120 ++++ .../functionalext/supplement/misc/login_tty.c | 37 ++ .../src/functionalext/supplement/misc/nftw.c | 100 ++++ .../functionalext/supplement/misc/openpty.c | 62 +++ .../functionalext/supplement/misc/ptsname.c | 64 +++ .../src/functionalext/supplement/misc/pty.c | 139 +++++ .../functionalext/supplement/misc/realpath.c | 53 ++ .../supplement/misc/setlogmask.c | 58 ++ .../supplement/misc/setpriority.c | 37 ++ .../functionalext/supplement/misc/syscall.c | 54 ++ .../functionalext/supplement/misc/syslog.c | 55 ++ ...test_src_functionalext_supplement_misc.gni | 52 ++ .../src/functionalext/supplement/misc/uname.c | 92 ++++ .../functionalext/supplement/misc/unlockpt.c | 54 ++ .../functionalext/supplement/misc/vsyslog.c | 63 +++ .../functionalext/supplement/mman/BUILD.gn | 29 + .../functionalext/supplement/mman/madvise.c | 95 ++++ .../functionalext/supplement/mman/mincore.c | 90 +++ .../src/functionalext/supplement/mman/mlock.c | 48 ++ .../functionalext/supplement/mman/mlockall.c | 90 +++ .../src/functionalext/supplement/mman/mmap.c | 503 +++++++++++++++++ .../functionalext/supplement/mman/mprotect.c | 110 ++++ .../functionalext/supplement/mman/mremap.c | 94 ++++ .../src/functionalext/supplement/mman/msync.c | 59 ++ .../functionalext/supplement/mman/munlock.c | 49 ++ .../supplement/mman/munlockall.c | 70 +++ .../functionalext/supplement/mman/munmap.c | 59 ++ .../supplement/mman/posix_madvise.c | 107 ++++ ...test_src_functionalext_supplement_mman.gni | 27 + .../supplement/multibyte/BUILD.gn | 29 + .../supplement/multibyte/c16rtomb.c | 173 ++++++ .../supplement/multibyte/c32rtomb.c | 49 ++ .../supplement/multibyte/mblen.c | 57 ++ .../supplement/multibyte/mbrtoc16.c | 99 ++++ .../supplement/multibyte/mbrtoc32.c | 100 ++++ .../supplement/multibyte/mbsinit.c | 68 +++ .../supplement/multibyte/mbsnrtowcs.c | 65 +++ .../supplement/multibyte/mbstowcs.c | 69 +++ .../supplement/multibyte/mbtowc.c | 69 +++ ...src_functionalext_supplement_multibyte.gni | 30 + .../supplement/multibyte/wcrtomb.c | 92 ++++ .../supplement/multibyte/wcsnrtombs.c | 102 ++++ .../supplement/multibyte/wcsrtombs.c | 57 ++ .../supplement/multibyte/wcstombs.c | 77 +++ .../supplement/multibyte/wctob.c | 72 +++ .../supplement/multibyte/wctomb.c | 84 +++ .../functionalext/supplement/network/BUILD.gn | 29 + .../supplement/network/__h_errno_location.c | 37 ++ .../supplement/network/accept4.c | 392 +++++++++++++ .../supplement/network/dn_comp.c | 124 +++++ .../supplement/network/dn_skipname.c | 75 +++ .../supplement/network/freeifaddrs.c | 44 ++ .../supplement/network/gai_strerror.c | 179 ++++++ .../supplement/network/getaddrinfo.c | 361 ++++++++++++ .../supplement/network/gethostent.c | 40 ++ .../supplement/network/getifaddrs.c | 39 ++ .../supplement/network/getnetent.c | 38 ++ .../supplement/network/getpeername.c | 131 +++++ .../supplement/network/getservbyname.c | 53 ++ .../supplement/network/getservbyport.c | 51 ++ .../supplement/network/getsockopt.c | 406 ++++++++++++++ .../supplement/network/hstrerror.c | 45 ++ .../functionalext/supplement/network/htonl.c | 35 ++ .../functionalext/supplement/network/htons.c | 36 ++ .../supplement/network/if_indextoname.c | 43 ++ .../supplement/network/if_nameindex.c | 35 ++ .../supplement/network/if_nametoindex.c | 47 ++ .../supplement/network/inet_addr.c | 80 +++ .../supplement/network/inet_aton.c | 123 +++++ .../supplement/network/inet_lnaof.c | 38 ++ .../supplement/network/inet_makeaddr.c | 39 ++ .../supplement/network/inet_netof.c | 38 ++ .../supplement/network/inet_network.c | 36 ++ .../supplement/network/inet_ntoa.c | 68 +++ .../supplement/network/inet_ntop.c | 138 +++++ .../functionalext/supplement/network/listen.c | 37 ++ .../supplement/network/ns_parse.c | 350 ++++++++++++ .../functionalext/supplement/network/proto.c | 168 ++++++ .../functionalext/supplement/network/recv.c | 152 ++++++ .../supplement/network/recvmmsg.c | 133 +++++ .../supplement/network/recvmsg.c | 175 ++++++ .../supplement/network/res_mkquery.c | 74 +++ .../supplement/network/res_query.c | 88 +++ .../functionalext/supplement/network/send.c | 200 +++++++ .../supplement/network/sendmmsg.c | 77 +++ .../supplement/network/sendmsg.c | 60 ++ .../supplement/network/setprotoent.c | 55 ++ .../supplement/network/shutdown.c | 50 ++ .../supplement/network/socketpair.c | 84 +++ ...t_src_functionalext_supplement_network.gni | 57 ++ .../functionalext/supplement/passwd/BUILD.gn | 29 + .../supplement/passwd/getgrent.c | 48 ++ .../supplement/passwd/getgrgid.c | 80 +++ .../supplement/passwd/getgrgid_r.c | 91 +++ .../supplement/passwd/getgrnam.c | 83 +++ .../supplement/passwd/getgrnam_r.c | 90 +++ .../supplement/passwd/getgrouplist.c | 74 +++ .../functionalext/supplement/passwd/getpw_r.c | 59 ++ .../supplement/passwd/getpwent.c | 93 ++++ .../supplement/passwd/setgrent.c | 60 ++ .../supplement/passwd/setpwent.c | 60 ++ ...st_src_functionalext_supplement_passwd.gni | 25 + .../functionalext/supplement/prng/BUILD.gn | 29 + .../functionalext/supplement/prng/drand48.c | 35 ++ .../functionalext/supplement/prng/erand48.c | 36 ++ .../functionalext/supplement/prng/lcong48.c | 40 ++ .../functionalext/supplement/prng/lrand48.c | 45 ++ .../functionalext/supplement/prng/mrand48.c | 67 +++ .../src/functionalext/supplement/prng/rand.c | 42 ++ .../functionalext/supplement/prng/rand_r.c | 77 +++ .../functionalext/supplement/prng/seed48.c | 69 +++ .../src/functionalext/supplement/prng/srand.c | 67 +++ .../functionalext/supplement/prng/srand48.c | 58 ++ ...test_src_functionalext_supplement_prng.gni | 25 + .../functionalext/supplement/process/BUILD.gn | 29 + .../functionalext/supplement/process/execl.c | 56 ++ .../functionalext/supplement/process/execlp.c | 74 +++ .../functionalext/supplement/process/execv.c | 77 +++ .../functionalext/supplement/process/execve.c | 75 +++ .../functionalext/supplement/process/execvp.c | 99 ++++ .../supplement/process/execvpe.c | 125 +++++ .../supplement/process/fexecve.c | 58 ++ .../supplement/process/fexecverely.c | 25 + .../functionalext/supplement/process/fork.c | 64 +++ .../supplement/process/posix_spawn.c | 131 +++++ .../posix_spawn_file_actions_addopen.c | 106 ++++ .../process/posix_spawnattr_getflags.c | 44 ++ .../process/posix_spawnattr_getpgroup.c | 45 ++ .../process/posix_spawnattr_getsigdefault.c | 56 ++ .../process/posix_spawnattr_getsigmask.c | 56 ++ .../process/posix_spawnattr_setflags.c | 76 +++ .../process/posix_spawnattr_setpgroup.c | 42 ++ .../process/posix_spawnattr_setsigdefault.c | 49 ++ .../process/posix_spawnattr_setsigmask.c | 49 ++ .../supplement/process/posix_spawnp.c | 131 +++++ .../functionalext/supplement/process/system.c | 58 ++ ...t_src_functionalext_supplement_process.gni | 39 ++ .../functionalext/supplement/process/vfork.c | 55 ++ .../functionalext/supplement/process/wait.c | 81 +++ .../functionalext/supplement/process/waitid.c | 54 ++ .../supplement/process/waitpid.c | 82 +++ .../functionalext/supplement/regex/BUILD.gn | 29 + .../src/functionalext/supplement/regex/glob.c | 51 ++ ...est_src_functionalext_supplement_regex.gni | 14 + .../functionalext/supplement/sched/BUILD.gn | 29 + .../supplement/sched/__sched_cpucount.c | 110 ++++ .../supplement/sched/sched_getaffinity.c | 54 ++ .../supplement/sched/sched_getcpu.c | 42 ++ .../supplement/sched/sched_rr_get_interval.c | 68 +++ .../supplement/sched/sched_setaffinity.c | 84 +++ .../supplement/sched/sched_yield.c | 34 ++ ...est_src_functionalext_supplement_sched.gni | 21 + .../functionalext/supplement/search/BUILD.gn | 29 + .../supplement/search/hcreate_r.c | 50 ++ .../supplement/search/hdestroy.c | 38 ++ .../supplement/search/hsearch_r.c | 66 +++ .../functionalext/supplement/search/lfind.c | 65 +++ .../supplement/search/tdestroy.c | 88 +++ ...st_src_functionalext_supplement_search.gni | 20 + .../functionalext/supplement/select/BUILD.gn | 29 + .../functionalext/supplement/select/poll.c | 167 ++++++ .../functionalext/supplement/select/pselect.c | 116 ++++ .../functionalext/supplement/select/select.c | 97 ++++ ...st_src_functionalext_supplement_select.gni | 18 + .../functionalext/supplement/setjmp/BUILD.gn | 29 + .../supplement/setjmp/_longjmp.c | 53 ++ .../functionalext/supplement/setjmp/_setjmp.c | 54 ++ ...st_src_functionalext_supplement_setjmp.gni | 17 + .../functionalext/supplement/signal/BUILD.gn | 29 + .../supplement/signal/getitimer.c | 87 +++ .../functionalext/supplement/signal/kill.c | 82 +++ .../functionalext/supplement/signal/killpg.c | 87 +++ .../supplement/signal/libc_current_sigrtmax.c | 21 + .../supplement/signal/libc_current_sigrtmin.c | 21 + .../supplement/signal/psiginfo.c | 74 +++ .../functionalext/supplement/signal/psignal.c | 65 +++ .../supplement/signal/setitimer.c | 81 +++ .../supplement/signal/sigaction.c | 53 ++ .../functionalext/supplement/signal/sighold.c | 100 ++++ .../supplement/signal/sigignore.c | 112 ++++ .../functionalext/supplement/signal/signal.c | 41 ++ .../supplement/signal/sigpause.c | 88 +++ .../supplement/signal/sigpending.c | 40 ++ .../supplement/signal/sigqueue.c | 107 ++++ .../supplement/signal/sigrelse.c | 133 +++++ .../functionalext/supplement/signal/sigset.c | 236 ++++++++ .../supplement/signal/sigsuspend.c | 98 ++++ .../functionalext/supplement/signal/sigwait.c | 66 +++ .../supplement/signal/sigwaitinfo.c | 72 +++ ...st_src_functionalext_supplement_signal.gni | 35 ++ .../functionalext/supplement/stat/BUILD.gn | 29 + .../src/functionalext/supplement/stat/chmod.c | 103 ++++ .../functionalext/supplement/stat/fchmod.c | 89 +++ .../functionalext/supplement/stat/fchmodat.c | 90 +++ .../functionalext/supplement/stat/fstatat.c | 107 ++++ .../functionalext/supplement/stat/fstatfs.c | 78 +++ .../functionalext/supplement/stat/fstatvfs.c | 66 +++ .../functionalext/supplement/stat/futimesat.c | 97 ++++ .../src/functionalext/supplement/stat/lstat.c | 102 ++++ .../src/functionalext/supplement/stat/mkdir.c | 72 +++ .../functionalext/supplement/stat/mkdirat.c | 57 ++ .../functionalext/supplement/stat/mkfifo.c | 55 ++ .../functionalext/supplement/stat/mkfifoat.c | 76 +++ .../src/functionalext/supplement/stat/mknod.c | 37 ++ .../functionalext/supplement/stat/mknodat.c | 64 +++ .../src/functionalext/supplement/stat/stat.c | 64 +++ .../functionalext/supplement/stat/statfs.c | 56 ++ .../functionalext/supplement/stat/statvfs.c | 54 ++ ...test_src_functionalext_supplement_stat.gni | 34 ++ .../src/functionalext/supplement/stat/umask.c | 59 ++ .../functionalext/supplement/stat/utimensat.c | 80 +++ .../functionalext/supplement/stdio/BUILD.gn | 29 + .../supplement/stdio/__fbufsize.c | 69 +++ .../functionalext/supplement/stdio/__flbf.c | 88 +++ .../supplement/stdio/__fpending.c | 81 +++ .../functionalext/supplement/stdio/__fpurge.c | 44 ++ .../supplement/stdio/__freadable.c | 56 ++ .../supplement/stdio/__freading.c | 84 +++ .../supplement/stdio/__fseterr.c | 53 ++ .../supplement/stdio/__fsetlocking.c | 43 ++ .../supplement/stdio/__fwritable.c | 61 +++ .../supplement/stdio/__fwriting.c | 83 +++ .../supplement/stdio/_flushlbf.c | 53 ++ .../functionalext/supplement/stdio/asprintf.c | 187 +++++++ .../functionalext/supplement/stdio/clearerr.c | 38 ++ .../functionalext/supplement/stdio/dprintf.c | 99 ++++ .../functionalext/supplement/stdio/fflush.c | 103 ++++ .../functionalext/supplement/stdio/fgetln.c | 74 +++ .../functionalext/supplement/stdio/fgetpos.c | 92 ++++ .../functionalext/supplement/stdio/fgets.c | 187 +++++++ .../functionalext/supplement/stdio/fgetws.c | 81 +++ .../supplement/stdio/flockfile.c | 60 ++ .../functionalext/supplement/stdio/fopen.c | 329 +++++++++++ .../functionalext/supplement/stdio/fprintf.c | 89 +++ .../functionalext/supplement/stdio/fputc.c | 58 ++ .../functionalext/supplement/stdio/fputs.c | 85 +++ .../functionalext/supplement/stdio/fputwc.c | 96 ++++ .../functionalext/supplement/stdio/fputws.c | 72 +++ .../functionalext/supplement/stdio/fread.c | 120 ++++ .../functionalext/supplement/stdio/freopen.c | 58 ++ .../functionalext/supplement/stdio/fseeko.c | 159 ++++++ .../functionalext/supplement/stdio/fsetpos.c | 133 +++++ .../functionalext/supplement/stdio/ftell.c | 102 ++++ .../supplement/stdio/ftrylockfile.c | 50 ++ .../supplement/stdio/funlockfile.c | 75 +++ .../functionalext/supplement/stdio/fwide.c | 85 +++ .../functionalext/supplement/stdio/fwprintf.c | 98 ++++ .../functionalext/supplement/stdio/fwrite.c | 90 +++ .../src/functionalext/supplement/stdio/getc.c | 54 ++ .../supplement/stdio/getc_unlocked.c | 68 +++ .../functionalext/supplement/stdio/getchar.c | 53 ++ .../supplement/stdio/getchar_unlocked.c | 59 ++ .../functionalext/supplement/stdio/getdelim.c | 67 +++ .../functionalext/supplement/stdio/getline.c | 89 +++ .../functionalext/supplement/stdio/getwc.c | 45 ++ .../supplement/stdio/open_wmemstream.c | 49 ++ .../functionalext/supplement/stdio/printf.c | 198 +++++++ .../src/functionalext/supplement/stdio/putc.c | 76 +++ .../supplement/stdio/putc_unlocked.c | 44 ++ .../functionalext/supplement/stdio/putchar.c | 38 ++ .../supplement/stdio/putchar_unlocked.c | 44 ++ .../src/functionalext/supplement/stdio/puts.c | 35 ++ .../src/functionalext/supplement/stdio/putw.c | 72 +++ .../functionalext/supplement/stdio/putwc.c | 74 +++ .../functionalext/supplement/stdio/putwchar.c | 43 ++ .../functionalext/supplement/stdio/remove.c | 53 ++ .../functionalext/supplement/stdio/rename.c | 84 +++ .../functionalext/supplement/stdio/rewind.c | 60 ++ .../functionalext/supplement/stdio/setbuf.c | 78 +++ .../supplement/stdio/setbuffer.c | 80 +++ .../supplement/stdio/setlinebuf.c | 75 +++ .../functionalext/supplement/stdio/setvbuf.c | 72 +++ .../functionalext/supplement/stdio/sprintf.c | 71 +++ .../functionalext/supplement/stdio/swscanf.c | 92 ++++ .../functionalext/supplement/stdio/tempnam.c | 115 ++++ ...est_src_functionalext_supplement_stdio.gni | 97 ++++ .../functionalext/supplement/stdio/tmpfile.c | 39 ++ .../functionalext/supplement/stdio/tmpnam.c | 58 ++ .../functionalext/supplement/stdio/ungetwc.c | 80 +++ .../supplement/stdio/vasprintf.c | 90 +++ .../functionalext/supplement/stdio/vdprintf.c | 80 +++ .../functionalext/supplement/stdio/vfprintf.c | 109 ++++ .../functionalext/supplement/stdio/vfscanf.c | 143 +++++ .../supplement/stdio/vfwprintf.c | 77 +++ .../functionalext/supplement/stdio/vfwscanf.c | 90 +++ .../functionalext/supplement/stdio/vprintf.c | 68 +++ .../supplement/stdio/vsnprintf.c | 79 +++ .../functionalext/supplement/stdio/vsprintf.c | 90 +++ .../functionalext/supplement/stdio/vsscanf.c | 100 ++++ .../supplement/stdio/vswprintf.c | 93 ++++ .../functionalext/supplement/stdio/vswscanf.c | 81 +++ .../functionalext/supplement/stdio/vwprintf.c | 52 ++ .../functionalext/supplement/stdio/wcstoll.c | 147 +++++ .../functionalext/supplement/stdio/wcstoull.c | 153 ++++++ .../functionalext/supplement/stdio/wprintf.c | 66 +++ .../functionalext/supplement/stdlib/BUILD.gn | 29 + .../src/functionalext/supplement/stdlib/abs.c | 58 ++ .../functionalext/supplement/stdlib/atof.c | 52 ++ .../functionalext/supplement/stdlib/atoi.c | 223 ++++++++ .../functionalext/supplement/stdlib/atoll.c | 200 +++++++ .../functionalext/supplement/stdlib/bseach.c | 66 +++ .../functionalext/supplement/stdlib/imaxabs.c | 49 ++ .../functionalext/supplement/stdlib/imaxdiv.c | 82 +++ .../functionalext/supplement/stdlib/labs.c | 37 ++ .../functionalext/supplement/stdlib/ldiv.c | 55 ++ .../functionalext/supplement/stdlib/llabs.c | 37 ++ .../functionalext/supplement/stdlib/lldiv.c | 54 ++ .../supplement/stdlib/strtoimax.c | 63 +++ .../supplement/stdlib/strtoumax.c | 82 +++ ...st_src_functionalext_supplement_stdlib.gni | 33 ++ .../functionalext/supplement/stdlib/wcstod.c | 148 +++++ .../functionalext/supplement/stdlib/wcstof.c | 148 +++++ .../supplement/stdlib/wcstoimax.c | 66 +++ .../functionalext/supplement/stdlib/wcstold.c | 134 +++++ .../supplement/stdlib/wcstoumax.c | 66 +++ .../functionalext/supplement/string/BUILD.gn | 29 + .../functionalext/supplement/string/bzero.c | 54 ++ .../functionalext/supplement/string/index.c | 71 +++ .../functionalext/supplement/string/memccpy.c | 85 +++ .../functionalext/supplement/string/memchr.c | 96 ++++ .../functionalext/supplement/string/memmem.c | 66 +++ .../functionalext/supplement/string/memmove.c | 110 ++++ .../functionalext/supplement/string/mempcpy.c | 82 +++ .../functionalext/supplement/string/memrchr.c | 60 ++ .../functionalext/supplement/string/stpcpy.c | 121 ++++ .../functionalext/supplement/string/stpncpy.c | 122 +++++ .../supplement/string/strcasecmp.c | 71 +++ .../supplement/string/strcasestr.c | 83 +++ .../functionalext/supplement/string/strcat.c | 39 ++ .../supplement/string/strchrnul.c | 85 +++ .../functionalext/supplement/string/strcoll.c | 71 +++ .../functionalext/supplement/string/strdup.c | 36 ++ .../supplement/string/strerror_r.c | 65 +++ .../functionalext/supplement/string/strlen.c | 67 +++ .../supplement/string/strncasecmp.c | 85 +++ .../functionalext/supplement/string/strndup.c | 68 +++ .../functionalext/supplement/string/strnlen.c | 55 ++ .../functionalext/supplement/string/strrchr.c | 74 +++ .../functionalext/supplement/string/strsep.c | 86 +++ .../supplement/string/strsignal.c | 52 ++ .../supplement/string/strtok_r.c | 62 +++ .../functionalext/supplement/string/swab.c | 55 ++ ...st_src_functionalext_supplement_string.gni | 66 +++ .../functionalext/supplement/string/wcpcpy.c | 43 ++ .../functionalext/supplement/string/wcpncpy.c | 84 +++ .../supplement/string/wcscasecmp.c | 98 ++++ .../supplement/string/wcscasecmp_l.c | 105 ++++ .../functionalext/supplement/string/wcscat.c | 63 +++ .../functionalext/supplement/string/wcschr.c | 72 +++ .../functionalext/supplement/string/wcscmp.c | 109 ++++ .../functionalext/supplement/string/wcscpy.c | 78 +++ .../functionalext/supplement/string/wcscspn.c | 69 +++ .../functionalext/supplement/string/wcsdup.c | 61 +++ .../functionalext/supplement/string/wcslen.c | 39 ++ .../supplement/string/wcsncasecmp.c | 108 ++++ .../supplement/string/wcsncasecmp_l.c | 108 ++++ .../functionalext/supplement/string/wcsncat.c | 80 +++ .../functionalext/supplement/string/wcsncmp.c | 80 +++ .../functionalext/supplement/string/wcsncpy.c | 112 ++++ .../functionalext/supplement/string/wcsnlen.c | 88 +++ .../functionalext/supplement/string/wcspbrk.c | 85 +++ .../functionalext/supplement/string/wcsrchr.c | 70 +++ .../functionalext/supplement/string/wcsspn.c | 68 +++ .../functionalext/supplement/string/wcstok.c | 73 +++ .../functionalext/supplement/string/wcswcs.c | 97 ++++ .../functionalext/supplement/string/wmemchr.c | 75 +++ .../functionalext/supplement/string/wmemcmp.c | 89 +++ .../functionalext/supplement/string/wmemcpy.c | 75 +++ .../supplement/string/wmemmove.c | 79 +++ .../functionalext/supplement/string/wmemset.c | 84 +++ .../functionalext/supplement/temp/BUILD.gn | 29 + .../functionalext/supplement/temp/mkdtemp.c | 64 +++ .../functionalext/supplement/temp/mkostemp.c | 167 ++++++ .../functionalext/supplement/temp/mkostemps.c | 94 ++++ .../functionalext/supplement/temp/mkstemp.c | 69 +++ .../functionalext/supplement/temp/mkstemps.c | 91 +++ .../functionalext/supplement/temp/mktemp.c | 70 +++ ...test_src_functionalext_supplement_temp.gni | 21 + .../functionalext/supplement/termios/BUILD.gn | 29 + .../supplement/termios/cfgetispeed.c | 42 ++ .../supplement/termios/cfgetospeed.c | 40 ++ .../supplement/termios/cfmakeraw.c | 47 ++ .../supplement/termios/cfsetispeed.c | 62 +++ .../supplement/termios/cfsetospeed.c | 61 +++ .../supplement/termios/tcdrain.c | 97 ++++ .../functionalext/supplement/termios/tcflow.c | 98 ++++ ...t_src_functionalext_supplement_termios.gni | 22 + .../test_src_functionalext_supplement.gni | 55 ++ .../functionalext/supplement/thread/BUILD.gn | 190 +++++++ .../supplement/thread/call_once.c | 63 +++ .../supplement/thread/cnd_init.c | 38 ++ .../supplement/thread/cnd_signal.c | 61 +++ .../supplement/thread/cnd_timedwait.c | 86 +++ .../supplement/thread/cnd_wait.c | 59 ++ .../supplement/thread/mtx_init.c | 78 +++ .../supplement/thread/mtx_lock.c | 208 +++++++ .../supplement/thread/mtx_timedlock.c | 87 +++ .../supplement/thread/mtx_trylock.c | 100 ++++ .../supplement/thread/mtx_unlock.c | 61 +++ .../supplement/thread/pthread_atfork.c | 146 +++++ .../supplement/thread/pthread_attr_destroy.c | 47 ++ .../supplement/thread/pthread_attr_get.c | 418 ++++++++++++++ .../supplement/thread/pthread_attr_getstack.c | 66 +++ .../supplement/thread/pthread_attr_init.c | 72 +++ .../thread/pthread_attr_setdetachstate.c | 59 ++ .../thread/pthread_attr_setguardsize.c | 57 ++ .../thread/pthread_attr_setinheritsched.c | 71 +++ .../thread/pthread_attr_setschedparam.c | 46 ++ .../thread/pthread_attr_setschedpolicy.c | 43 ++ .../supplement/thread/pthread_attr_setscope.c | 67 +++ .../supplement/thread/pthread_attr_setstack.c | 96 ++++ .../thread/pthread_attr_setstacksize.c | 56 ++ .../thread/pthread_barrier_destroy.c | 44 ++ .../supplement/thread/pthread_barrier_init.c | 62 +++ .../supplement/thread/pthread_barrier_wait.c | 94 ++++ .../thread/pthread_barrierattr_init.c | 42 ++ .../thread/pthread_barrierattr_setpshared.c | 72 +++ .../thread/pthread_cond_broadcast.c | 46 ++ .../supplement/thread/pthread_cond_destroy.c | 45 ++ .../supplement/thread/pthread_cond_init.c | 62 +++ .../supplement/thread/pthread_cond_signal.c | 47 ++ .../thread/pthread_cond_timedwait.c | 70 +++ .../supplement/thread/pthread_cond_wait.c | 60 ++ .../thread/pthread_condattr_destroy.c | 38 ++ .../supplement/thread/pthread_condattr_init.c | 38 ++ .../thread/pthread_condattr_setclock.c | 59 ++ .../thread/pthread_condattr_setpshared.c | 57 ++ .../supplement/thread/pthread_create.c | 134 +++++ .../supplement/thread/pthread_detach.c | 50 ++ .../supplement/thread/pthread_equal.c | 103 ++++ .../supplement/thread/pthread_exit.c | 45 ++ .../supplement/thread/pthread_getattr_np.c | 51 ++ .../supplement/thread/pthread_getcpuclockid.c | 59 ++ .../supplement/thread/pthread_getschedparam.c | 47 ++ .../supplement/thread/pthread_getspecific.c | 51 ++ .../supplement/thread/pthread_join.c | 53 ++ .../supplement/thread/pthread_key_create.c | 82 +++ .../supplement/thread/pthread_key_delete.c | 39 ++ .../supplement/thread/pthread_mutex_destroy.c | 39 ++ .../supplement/thread/pthread_mutex_init.c | 64 +++ .../supplement/thread/pthread_mutex_lock.c | 130 +++++ .../thread/pthread_mutex_timedlock.c | 95 ++++ .../supplement/thread/pthread_mutex_trylock.c | 54 ++ .../supplement/thread/pthread_mutex_unlock.c | 81 +++ .../thread/pthread_mutexattr_destroy.c | 38 ++ .../thread/pthread_mutexattr_setprotocol.c | 63 +++ .../thread/pthread_mutexattr_setpshared.c | 54 ++ .../thread/pthread_mutexattr_settype.c | 54 ++ .../supplement/thread/pthread_once.c | 61 +++ .../thread/pthread_rwlock_destroy.c | 38 ++ .../supplement/thread/pthread_rwlock_rdlock.c | 98 ++++ .../thread/pthread_rwlock_timedrdlock.c | 98 ++++ .../thread/pthread_rwlock_timedwrlock.c | 98 ++++ .../thread/pthread_rwlock_tryrdlock.c | 70 +++ .../thread/pthread_rwlock_trywrlock.c | 70 +++ .../thread/pthread_rwlockattr_destroy.c | 38 ++ .../thread/pthread_rwlockattr_init.c | 36 ++ .../thread/pthread_rwlockattr_setpshared.c | 52 ++ .../supplement/thread/pthread_self.c | 46 ++ .../supplement/thread/pthread_setschedparam.c | 49 ++ .../supplement/thread/pthread_setschedprio.c | 99 ++++ .../supplement/thread/pthread_setspecific.c | 78 +++ .../supplement/thread/pthread_sigmask.c | 105 ++++ .../supplement/thread/pthread_spin_lock.c | 92 ++++ .../supplement/thread/pthread_spin_trylock.c | 102 ++++ .../supplement/thread/pthread_spin_unlock.c | 65 +++ ...st_src_functionalext_supplement_thread.gni | 81 +++ .../supplement/thread/thrd_create.c | 114 ++++ .../supplement/thread/thrd_current.c | 131 +++++ .../supplement/thread/thrd_detach.c | 103 ++++ .../supplement/thread/thrd_equal.c | 131 +++++ .../supplement/thread/thrd_join.c | 117 ++++ .../supplement/thread/thrd_sleep.c | 98 ++++ .../supplement/thread/thrd_yield.c | 79 +++ .../functionalext/supplement/thread/tss_set.c | 81 +++ .../functionalext/supplement/time/BUILD.gn | 29 + .../src/functionalext/supplement/time/clock.c | 36 ++ .../supplement/time/clock_getcpuclockid.c | 70 +++ .../supplement/time/clock_getres.c | 91 +++ .../supplement/time/clock_nanosleep.c | 123 +++++ .../supplement/time/clock_settime.c | 49 ++ .../functionalext/supplement/time/difftime.c | 500 +++++++++++++++++ .../supplement/time/gettimeofday.c | 62 +++ .../functionalext/supplement/time/gmtime.c | 516 ++++++++++++++++++ .../functionalext/supplement/time/gmtime_r.c | 516 ++++++++++++++++++ .../functionalext/supplement/time/mktime.c | 503 +++++++++++++++++ .../functionalext/supplement/time/nanosleep.c | 53 ++ ...test_src_functionalext_supplement_time.gni | 37 ++ .../src/functionalext/supplement/time/time.c | 81 +++ .../supplement/time/timer_create.c | 98 ++++ .../supplement/time/timer_delete.c | 78 +++ .../supplement/time/timer_getoverrun.c | 97 ++++ .../supplement/time/timer_gettime.c | 104 ++++ .../supplement/time/timer_settime.c | 98 ++++ .../src/functionalext/supplement/time/times.c | 72 +++ .../supplement/time/timespec_get.c | 58 ++ .../src/functionalext/supplement/time/utime.c | 92 ++++ .../functionalext/supplement/time/wcsftime.c | 44 ++ .../supplement/time/wcsftime_l.c | 82 +++ .../functionalext/supplement/unistd/BUILD.gn | 29 + .../functionalext/supplement/unistd/access.c | 184 +++++++ .../functionalext/supplement/unistd/acct.c | 71 +++ .../functionalext/supplement/unistd/alarm.c | 57 ++ .../functionalext/supplement/unistd/chdir.c | 42 ++ .../functionalext/supplement/unistd/chown.c | 119 ++++ .../functionalext/supplement/unistd/ctermid.c | 64 +++ .../functionalext/supplement/unistd/dup3.c | 70 +++ .../functionalext/supplement/unistd/exit.c | 89 +++ .../supplement/unistd/exittest01.c | 43 ++ .../supplement/unistd/exittest02.c | 44 ++ .../supplement/unistd/faccessat.c | 237 ++++++++ .../functionalext/supplement/unistd/fchown.c | 124 +++++ .../supplement/unistd/fchownat.c | 71 +++ .../supplement/unistd/fdatasync.c | 89 +++ .../functionalext/supplement/unistd/fsync.c | 84 +++ .../supplement/unistd/ftruncate.c | 136 +++++ .../functionalext/supplement/unistd/getcwd.c | 80 +++ .../functionalext/supplement/unistd/getegid.c | 49 ++ .../functionalext/supplement/unistd/geteuid.c | 49 ++ .../functionalext/supplement/unistd/getgid.c | 51 ++ .../supplement/unistd/getgroups.c | 68 +++ .../supplement/unistd/gethostname.c | 38 ++ .../supplement/unistd/getlogin.c | 48 ++ .../supplement/unistd/getlogin_r.c | 61 +++ .../functionalext/supplement/unistd/getpgid.c | 41 ++ .../functionalext/supplement/unistd/getpgrp.c | 43 ++ .../functionalext/supplement/unistd/getpid.c | 74 +++ .../functionalext/supplement/unistd/getppid.c | 44 ++ .../functionalext/supplement/unistd/getsid.c | 35 ++ .../supplement/unistd/getsockopt.c | 431 +++++++++++++++ .../functionalext/supplement/unistd/getuid.c | 45 ++ .../functionalext/supplement/unistd/lchown.c | 37 ++ .../functionalext/supplement/unistd/link.c | 79 +++ .../functionalext/supplement/unistd/linkat.c | 95 ++++ .../functionalext/supplement/unistd/lseek.c | 178 ++++++ .../functionalext/supplement/unistd/nice.c | 54 ++ .../functionalext/supplement/unistd/pause.c | 55 ++ .../functionalext/supplement/unistd/pipe2.c | 72 +++ .../functionalext/supplement/unistd/pread.c | 100 ++++ .../functionalext/supplement/unistd/preadv.c | 92 ++++ .../functionalext/supplement/unistd/pwrite.c | 89 +++ .../functionalext/supplement/unistd/pwritev.c | 109 ++++ .../functionalext/supplement/unistd/read.c | 47 ++ .../supplement/unistd/readlink.c | 110 ++++ .../supplement/unistd/readlinkat.c | 158 ++++++ .../functionalext/supplement/unistd/readv.c | 89 +++ .../supplement/unistd/renameat.c | 74 +++ .../functionalext/supplement/unistd/rmdir.c | 72 +++ .../supplement/unistd/setdomainname.c | 122 +++++ .../functionalext/supplement/unistd/setegid.c | 73 +++ .../functionalext/supplement/unistd/seteuid.c | 38 ++ .../functionalext/supplement/unistd/setgid.c | 41 ++ .../supplement/unistd/sethostname.c | 122 +++++ .../functionalext/supplement/unistd/setpgid.c | 42 ++ .../functionalext/supplement/unistd/setpgrp.c | 37 ++ .../supplement/unistd/setregid.c | 81 +++ .../supplement/unistd/setresgid.c | 107 ++++ .../supplement/unistd/setresuid.c | 38 ++ .../supplement/unistd/setreuid.c | 81 +++ .../functionalext/supplement/unistd/setsid.c | 59 ++ .../functionalext/supplement/unistd/setuid.c | 41 ++ .../functionalext/supplement/unistd/sleep.c | 46 ++ .../functionalext/supplement/unistd/symlink.c | 67 +++ .../supplement/unistd/symlinkat.c | 115 ++++ ...st_src_functionalext_supplement_unistd.gni | 85 +++ .../supplement/unistd/truncate.c | 141 +++++ .../supplement/unistd/ttyname_r.c | 63 +++ .../functionalext/supplement/unistd/unlink.c | 61 +++ .../supplement/unistd/unlinkat.c | 64 +++ .../functionalext/supplement/unistd/usleep.c | 46 ++ .../functionalext/supplement/unistd/write.c | 152 ++++++ .../functionalext/supplement/unistd/writev.c | 86 +++ .../functionalext/supplement/wctype/BUILD.gn | 29 + .../supplement/wctype/iswalnum_l.c | 92 ++++ .../supplement/wctype/iswctype_l.c | 247 +++++++++ .../supplement/wctype/iswgraph.c | 88 +++ .../supplement/wctype/iswgraph_l.c | 92 ++++ ...st_src_functionalext_supplement_wctype.gni | 19 + .../functionalext/test_src_functionalext.gni | 1 + libc-test/test_template.gni | 6 + scripts/runtest.sh | 64 ++- scripts/runtest_Windows.bat | 29 +- 863 files changed, 67311 insertions(+), 22 deletions(-) create mode 100644 libc-test/src/functionalext/supplement/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/conf/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/conf/fpathconf.c create mode 100644 libc-test/src/functionalext/supplement/conf/get_avphys_page.c create mode 100644 libc-test/src/functionalext/supplement/conf/get_nprocs.c create mode 100644 libc-test/src/functionalext/supplement/conf/get_nprocs_conf.c create mode 100644 libc-test/src/functionalext/supplement/conf/get_phys_pages.c create mode 100755 libc-test/src/functionalext/supplement/conf/pathconf.c create mode 100644 libc-test/src/functionalext/supplement/conf/sysconf.c create mode 100644 libc-test/src/functionalext/supplement/conf/test_src_functionalext_supplement_conf.gni create mode 100644 libc-test/src/functionalext/supplement/ctype/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/ctype/__ctype_get_mb_cur_max.c create mode 100644 libc-test/src/functionalext/supplement/ctype/isalnum.c create mode 100644 libc-test/src/functionalext/supplement/ctype/isalnum_l.c create mode 100644 libc-test/src/functionalext/supplement/ctype/isalpha.c create mode 100644 libc-test/src/functionalext/supplement/ctype/isalpha_l.c create mode 100755 libc-test/src/functionalext/supplement/ctype/isascii.c create mode 100644 libc-test/src/functionalext/supplement/ctype/isblank.c create mode 100644 libc-test/src/functionalext/supplement/ctype/isblank_l.c create mode 100644 libc-test/src/functionalext/supplement/ctype/iscntrl.c create mode 100644 libc-test/src/functionalext/supplement/ctype/iscntrl_l.c create mode 100755 libc-test/src/functionalext/supplement/ctype/isdigit.c create mode 100755 libc-test/src/functionalext/supplement/ctype/isgraph.c create mode 100644 libc-test/src/functionalext/supplement/ctype/isgraph_l.c create mode 100644 libc-test/src/functionalext/supplement/ctype/islower.c create mode 100644 libc-test/src/functionalext/supplement/ctype/isprint.c create mode 100644 libc-test/src/functionalext/supplement/ctype/isprint_l.c create mode 100644 libc-test/src/functionalext/supplement/ctype/ispunct.c create mode 100644 libc-test/src/functionalext/supplement/ctype/ispunct_l.c create mode 100644 libc-test/src/functionalext/supplement/ctype/isspace.c create mode 100644 libc-test/src/functionalext/supplement/ctype/isspace_l.c create mode 100644 libc-test/src/functionalext/supplement/ctype/isupper.c create mode 100644 libc-test/src/functionalext/supplement/ctype/iswalhpa.c create mode 100755 libc-test/src/functionalext/supplement/ctype/iswalnum.c create mode 100755 libc-test/src/functionalext/supplement/ctype/iswalpha.c create mode 100755 libc-test/src/functionalext/supplement/ctype/iswblank.c create mode 100644 libc-test/src/functionalext/supplement/ctype/iswcntrl.c create mode 100644 libc-test/src/functionalext/supplement/ctype/iswctype.c create mode 100644 libc-test/src/functionalext/supplement/ctype/iswdigit.c create mode 100644 libc-test/src/functionalext/supplement/ctype/iswlower.c create mode 100644 libc-test/src/functionalext/supplement/ctype/iswprint.c create mode 100644 libc-test/src/functionalext/supplement/ctype/iswpunct.c create mode 100644 libc-test/src/functionalext/supplement/ctype/iswspace.c create mode 100644 libc-test/src/functionalext/supplement/ctype/iswupper.c create mode 100644 libc-test/src/functionalext/supplement/ctype/iswxdigit.c create mode 100644 libc-test/src/functionalext/supplement/ctype/isxdigit.c create mode 100644 libc-test/src/functionalext/supplement/ctype/test_src_functionalext_supplement_ctype.gni create mode 100644 libc-test/src/functionalext/supplement/ctype/toascii.c create mode 100644 libc-test/src/functionalext/supplement/ctype/tolower.c create mode 100644 libc-test/src/functionalext/supplement/ctype/toupper.c create mode 100644 libc-test/src/functionalext/supplement/ctype/towctrans.c create mode 100644 libc-test/src/functionalext/supplement/ctype/towlower.c create mode 100644 libc-test/src/functionalext/supplement/ctype/wcswidth.c create mode 100644 libc-test/src/functionalext/supplement/ctype/wctrans.c create mode 100644 libc-test/src/functionalext/supplement/ctype/wctrans_l.c create mode 100644 libc-test/src/functionalext/supplement/ctype/wctype.c create mode 100644 libc-test/src/functionalext/supplement/ctype/wcwidth.c create mode 100644 libc-test/src/functionalext/supplement/dirent/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/dirent/alphasort.c create mode 100644 libc-test/src/functionalext/supplement/dirent/closedir.c create mode 100644 libc-test/src/functionalext/supplement/dirent/dirfd.c create mode 100644 libc-test/src/functionalext/supplement/dirent/fdopendir.c create mode 100755 libc-test/src/functionalext/supplement/dirent/opendir.c create mode 100644 libc-test/src/functionalext/supplement/dirent/readdir.c create mode 100644 libc-test/src/functionalext/supplement/dirent/readdir_r.c create mode 100644 libc-test/src/functionalext/supplement/dirent/rewinddir.c create mode 100644 libc-test/src/functionalext/supplement/dirent/scandir.c create mode 100644 libc-test/src/functionalext/supplement/dirent/seekdir.c create mode 100644 libc-test/src/functionalext/supplement/dirent/telldir.c create mode 100644 libc-test/src/functionalext/supplement/dirent/test_src_functionalext_supplement_dirent.gni create mode 100644 libc-test/src/functionalext/supplement/env/BUILD.gn create mode 100755 libc-test/src/functionalext/supplement/env/putenv.c create mode 100644 libc-test/src/functionalext/supplement/env/test_src_functionalext_supplement_env.gni create mode 100644 libc-test/src/functionalext/supplement/errno/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/errno/__errno_location.c create mode 100644 libc-test/src/functionalext/supplement/errno/strerror.c create mode 100644 libc-test/src/functionalext/supplement/errno/test_src_functionalext_supplement_errno.gni create mode 100644 libc-test/src/functionalext/supplement/exit/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/exit/__aeabi_atexit.c create mode 100644 libc-test/src/functionalext/supplement/exit/a_cxa_atexit.c create mode 100644 libc-test/src/functionalext/supplement/exit/a_cxa_finalize.c create mode 100644 libc-test/src/functionalext/supplement/exit/at_quick_exit.c create mode 100644 libc-test/src/functionalext/supplement/exit/atexit.c create mode 100755 libc-test/src/functionalext/supplement/exit/quick_exit.c create mode 100644 libc-test/src/functionalext/supplement/exit/test_src_functionalext_supplement_exit.gni create mode 100644 libc-test/src/functionalext/supplement/fcntl/BUILD.gn create mode 100755 libc-test/src/functionalext/supplement/fcntl/creat.c create mode 100755 libc-test/src/functionalext/supplement/fcntl/open.c create mode 100755 libc-test/src/functionalext/supplement/fcntl/openat.c create mode 100644 libc-test/src/functionalext/supplement/fcntl/posix_fadvise.c create mode 100644 libc-test/src/functionalext/supplement/fcntl/posix_fallocate.c create mode 100644 libc-test/src/functionalext/supplement/fcntl/test_src_functionalext_supplement_fcntl.gni create mode 100644 libc-test/src/functionalext/supplement/fenv/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/fenv/__flt_rounds.c create mode 100644 libc-test/src/functionalext/supplement/fenv/feholdexcept.c create mode 100644 libc-test/src/functionalext/supplement/fenv/feupdateenv.c create mode 100644 libc-test/src/functionalext/supplement/fenv/test_src_functionalext_supplement_fenv.gni create mode 100644 libc-test/src/functionalext/supplement/ipc/BUILD.gn create mode 100755 libc-test/src/functionalext/supplement/ipc/ftok.c create mode 100644 libc-test/src/functionalext/supplement/ipc/semtimedop.c create mode 100644 libc-test/src/functionalext/supplement/ipc/test_src_functionalext_supplement_ipc.gni create mode 100644 libc-test/src/functionalext/supplement/ldso/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/ldso/a_gnu_Unwind_Find_exidx.c create mode 100644 libc-test/src/functionalext/supplement/ldso/dl_iterate_phdr.c create mode 100644 libc-test/src/functionalext/supplement/ldso/dladdr.c create mode 100644 libc-test/src/functionalext/supplement/ldso/test_src_functionalext_supplement_ldso.gni create mode 100644 libc-test/src/functionalext/supplement/legacy/BUILD.gn create mode 100755 libc-test/src/functionalext/supplement/legacy/daemon.c create mode 100644 libc-test/src/functionalext/supplement/legacy/ftw.c create mode 100644 libc-test/src/functionalext/supplement/legacy/futimes.c create mode 100644 libc-test/src/functionalext/supplement/legacy/getdtablesize.c create mode 100644 libc-test/src/functionalext/supplement/legacy/getloadavg.c create mode 100644 libc-test/src/functionalext/supplement/legacy/getpagesize.c create mode 100644 libc-test/src/functionalext/supplement/legacy/lutimes.c create mode 100644 libc-test/src/functionalext/supplement/legacy/test_src_functionalext_supplement_legacy.gni create mode 100644 libc-test/src/functionalext/supplement/legacy/verr.c create mode 100644 libc-test/src/functionalext/supplement/legacy/verrx.c create mode 100644 libc-test/src/functionalext/supplement/legacy/vwarn.c create mode 100644 libc-test/src/functionalext/supplement/legacy/vwarnx.c create mode 100644 libc-test/src/functionalext/supplement/linux/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/linux/adjtimex.c create mode 100755 libc-test/src/functionalext/supplement/linux/brk.c create mode 100755 libc-test/src/functionalext/supplement/linux/capget.c create mode 100755 libc-test/src/functionalext/supplement/linux/capset.c create mode 100644 libc-test/src/functionalext/supplement/linux/chroot.c create mode 100755 libc-test/src/functionalext/supplement/linux/clock_adjtime.c create mode 100644 libc-test/src/functionalext/supplement/linux/clone.c create mode 100644 libc-test/src/functionalext/supplement/linux/copy_file_range.c create mode 100755 libc-test/src/functionalext/supplement/linux/eventfd.c create mode 100755 libc-test/src/functionalext/supplement/linux/eventfd_read.c create mode 100755 libc-test/src/functionalext/supplement/linux/eventfd_write.c create mode 100755 libc-test/src/functionalext/supplement/linux/fallocate.c create mode 100644 libc-test/src/functionalext/supplement/linux/fgetxattr.c create mode 100755 libc-test/src/functionalext/supplement/linux/flistxattr.c create mode 100644 libc-test/src/functionalext/supplement/linux/flock.c create mode 100755 libc-test/src/functionalext/supplement/linux/fremovexattr.c create mode 100755 libc-test/src/functionalext/supplement/linux/fsetxattr.c create mode 100644 libc-test/src/functionalext/supplement/linux/getdents.c create mode 100644 libc-test/src/functionalext/supplement/linux/getrandom.c create mode 100644 libc-test/src/functionalext/supplement/linux/getxattr.c create mode 100755 libc-test/src/functionalext/supplement/linux/inotify.c create mode 100644 libc-test/src/functionalext/supplement/linux/inotify_init1.c create mode 100644 libc-test/src/functionalext/supplement/linux/klogctl.c create mode 100644 libc-test/src/functionalext/supplement/linux/lgetxattr.c create mode 100644 libc-test/src/functionalext/supplement/linux/listxattr.c create mode 100644 libc-test/src/functionalext/supplement/linux/llistxattr.c create mode 100644 libc-test/src/functionalext/supplement/linux/lremovexattr.c create mode 100644 libc-test/src/functionalext/supplement/linux/lsetxattr.c create mode 100755 libc-test/src/functionalext/supplement/linux/membarrier.c create mode 100644 libc-test/src/functionalext/supplement/linux/memfd_create.c create mode 100755 libc-test/src/functionalext/supplement/linux/mlock2.c create mode 100644 libc-test/src/functionalext/supplement/linux/mount.c create mode 100755 libc-test/src/functionalext/supplement/linux/name_to_handle_at.c create mode 100755 libc-test/src/functionalext/supplement/linux/open_by_handle_at.c create mode 100644 libc-test/src/functionalext/supplement/linux/personality.c create mode 100755 libc-test/src/functionalext/supplement/linux/ppoll.c create mode 100755 libc-test/src/functionalext/supplement/linux/prctl.c create mode 100755 libc-test/src/functionalext/supplement/linux/prlimit.c create mode 100644 libc-test/src/functionalext/supplement/linux/process_vm.c create mode 100644 libc-test/src/functionalext/supplement/linux/ptrace.c create mode 100755 libc-test/src/functionalext/supplement/linux/quotactl.c create mode 100644 libc-test/src/functionalext/supplement/linux/readahead.c create mode 100755 libc-test/src/functionalext/supplement/linux/remap_file_pages.c create mode 100644 libc-test/src/functionalext/supplement/linux/removexattr.c create mode 100644 libc-test/src/functionalext/supplement/linux/sbrk.c create mode 100644 libc-test/src/functionalext/supplement/linux/sendfile.c create mode 100644 libc-test/src/functionalext/supplement/linux/setfsgid.c create mode 100644 libc-test/src/functionalext/supplement/linux/setfsuid.c create mode 100644 libc-test/src/functionalext/supplement/linux/setgroups.c create mode 100644 libc-test/src/functionalext/supplement/linux/setns.c create mode 100644 libc-test/src/functionalext/supplement/linux/settimeofday.c create mode 100644 libc-test/src/functionalext/supplement/linux/setxattr.c create mode 100644 libc-test/src/functionalext/supplement/linux/signalfd.c create mode 100644 libc-test/src/functionalext/supplement/linux/splice.c create mode 100644 libc-test/src/functionalext/supplement/linux/swapoff.c create mode 100644 libc-test/src/functionalext/supplement/linux/swapon.c create mode 100644 libc-test/src/functionalext/supplement/linux/sync_file_range.c create mode 100644 libc-test/src/functionalext/supplement/linux/syncfs.c create mode 100644 libc-test/src/functionalext/supplement/linux/sysinfo.c create mode 100644 libc-test/src/functionalext/supplement/linux/tee.c create mode 100644 libc-test/src/functionalext/supplement/linux/test_src_functionalext_supplement_linux.gni create mode 100644 libc-test/src/functionalext/supplement/linux/timerfd_create.c create mode 100644 libc-test/src/functionalext/supplement/linux/timerfd_gettime.c create mode 100644 libc-test/src/functionalext/supplement/linux/timerfd_settime.c create mode 100644 libc-test/src/functionalext/supplement/linux/utimes.c create mode 100644 libc-test/src/functionalext/supplement/linux/vmsplice.c create mode 100644 libc-test/src/functionalext/supplement/linux/wait3.c create mode 100644 libc-test/src/functionalext/supplement/linux/wait4.c create mode 100644 libc-test/src/functionalext/supplement/locale/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/locale/duplocale.c create mode 100644 libc-test/src/functionalext/supplement/locale/langinfo.c create mode 100644 libc-test/src/functionalext/supplement/locale/localeconv.c create mode 100644 libc-test/src/functionalext/supplement/locale/newlocale.c create mode 100644 libc-test/src/functionalext/supplement/locale/setlocale.c create mode 100644 libc-test/src/functionalext/supplement/locale/strxfrm.c create mode 100644 libc-test/src/functionalext/supplement/locale/test_src_functionalext_supplement_locale.gni create mode 100644 libc-test/src/functionalext/supplement/locale/uselocale.c create mode 100644 libc-test/src/functionalext/supplement/locale/wcscoll.c create mode 100644 libc-test/src/functionalext/supplement/locale/wcsxfrm.c create mode 100644 libc-test/src/functionalext/supplement/malloc/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/malloc/aligned_alloc.c create mode 100755 libc-test/src/functionalext/supplement/malloc/malloc_usable_size.c create mode 100644 libc-test/src/functionalext/supplement/malloc/memalign.c create mode 100644 libc-test/src/functionalext/supplement/malloc/posix_memalign.c create mode 100644 libc-test/src/functionalext/supplement/malloc/realloc.c create mode 100644 libc-test/src/functionalext/supplement/malloc/test_src_functionalext_supplement_malloc.gni create mode 100644 libc-test/src/functionalext/supplement/manual/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/manual/env/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/manual/env/a_stack_chk_fail.c create mode 100644 libc-test/src/functionalext/supplement/manual/env/test_src_functionalext_supplement_manual_env.gni create mode 100644 libc-test/src/functionalext/supplement/manual/network/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/manual/network/gethostbyaddr.c create mode 100644 libc-test/src/functionalext/supplement/manual/network/gethostbyaddr_r.c create mode 100644 libc-test/src/functionalext/supplement/manual/network/gethostbyname2.c create mode 100644 libc-test/src/functionalext/supplement/manual/network/gethostbyname2_r.c create mode 100644 libc-test/src/functionalext/supplement/manual/network/gethostbyname_r.c create mode 100644 libc-test/src/functionalext/supplement/manual/network/getnameinfo.c create mode 100755 libc-test/src/functionalext/supplement/manual/network/getnetbyaddr.c create mode 100644 libc-test/src/functionalext/supplement/manual/network/getnetbyname.c create mode 100755 libc-test/src/functionalext/supplement/manual/network/res_querydomain.c create mode 100755 libc-test/src/functionalext/supplement/manual/network/res_send.c create mode 100644 libc-test/src/functionalext/supplement/manual/network/test_src_functionalext_supplement_manual_network.gni create mode 100644 libc-test/src/functionalext/supplement/manual/termios/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/manual/termios/tcgetattr.c create mode 100644 libc-test/src/functionalext/supplement/manual/termios/tcgetsid.c create mode 100644 libc-test/src/functionalext/supplement/manual/termios/tcsendbreak.c create mode 100644 libc-test/src/functionalext/supplement/manual/termios/tcsetattr.c create mode 100644 libc-test/src/functionalext/supplement/manual/termios/test_src_functionalext_supplement_manual_termios.gni create mode 100644 libc-test/src/functionalext/supplement/manual/test_src_functionalext_supplement_maunal.gni create mode 100644 libc-test/src/functionalext/supplement/manual/thread/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/manual/thread/cnd_broadcast.c create mode 100644 libc-test/src/functionalext/supplement/manual/thread/test_src_functionalext_supplement_manual_thread.gni create mode 100644 libc-test/src/functionalext/supplement/manual/unistd/BUILD.gn create mode 100755 libc-test/src/functionalext/supplement/manual/unistd/isatty.c create mode 100644 libc-test/src/functionalext/supplement/manual/unistd/tcgetpgrp.c create mode 100644 libc-test/src/functionalext/supplement/manual/unistd/tcsetpgrp.c create mode 100644 libc-test/src/functionalext/supplement/manual/unistd/test_src_functionalext_supplement_manual_unistd.gni create mode 100644 libc-test/src/functionalext/supplement/manual/unistd/ttyname.c create mode 100644 libc-test/src/functionalext/supplement/math/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/math/__fpclassifyf.c create mode 100644 libc-test/src/functionalext/supplement/math/__fpclassifyl.c create mode 100644 libc-test/src/functionalext/supplement/math/__signbit.c create mode 100644 libc-test/src/functionalext/supplement/math/__signbitf.c create mode 100644 libc-test/src/functionalext/supplement/math/__signbitl.c create mode 100644 libc-test/src/functionalext/supplement/math/finite.c create mode 100644 libc-test/src/functionalext/supplement/math/finitef.c create mode 100755 libc-test/src/functionalext/supplement/math/nan.c create mode 100755 libc-test/src/functionalext/supplement/math/nanf.c create mode 100644 libc-test/src/functionalext/supplement/math/nanl.c create mode 100644 libc-test/src/functionalext/supplement/math/rint.c create mode 100644 libc-test/src/functionalext/supplement/math/significand.c create mode 100644 libc-test/src/functionalext/supplement/math/significandf.c create mode 100644 libc-test/src/functionalext/supplement/math/test_src_functionalext_supplement_math.gni create mode 100644 libc-test/src/functionalext/supplement/mbrlen/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/mbrlen/mbrlen.c create mode 100644 libc-test/src/functionalext/supplement/mbrlen/test_src_functionalext_supplement_mbrlen.gni create mode 100644 libc-test/src/functionalext/supplement/misc/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/misc/endmntent.c create mode 100644 libc-test/src/functionalext/supplement/misc/ffs.c create mode 100644 libc-test/src/functionalext/supplement/misc/ffsl.c create mode 100644 libc-test/src/functionalext/supplement/misc/ffsll.c create mode 100644 libc-test/src/functionalext/supplement/misc/forkpty.c create mode 100755 libc-test/src/functionalext/supplement/misc/getauxval.c create mode 100644 libc-test/src/functionalext/supplement/misc/getdomainname.c create mode 100644 libc-test/src/functionalext/supplement/misc/getentropy.c create mode 100644 libc-test/src/functionalext/supplement/misc/getmntent.c create mode 100644 libc-test/src/functionalext/supplement/misc/getmntent_r.c create mode 100644 libc-test/src/functionalext/supplement/misc/getopt.c create mode 100644 libc-test/src/functionalext/supplement/misc/getopt_long.c create mode 100644 libc-test/src/functionalext/supplement/misc/getopt_long_only.c create mode 100755 libc-test/src/functionalext/supplement/misc/getpriority.c create mode 100644 libc-test/src/functionalext/supplement/misc/getresgid.c create mode 100644 libc-test/src/functionalext/supplement/misc/getresuid.c create mode 100644 libc-test/src/functionalext/supplement/misc/getrlimit.c create mode 100644 libc-test/src/functionalext/supplement/misc/getrusage.c create mode 100644 libc-test/src/functionalext/supplement/misc/getsubopt.c create mode 100644 libc-test/src/functionalext/supplement/misc/hasmntopt.c create mode 100644 libc-test/src/functionalext/supplement/misc/initgroups.c create mode 100644 libc-test/src/functionalext/supplement/misc/ioctl.c create mode 100644 libc-test/src/functionalext/supplement/misc/issetugid.c create mode 100644 libc-test/src/functionalext/supplement/misc/lockf.c create mode 100644 libc-test/src/functionalext/supplement/misc/login_tty.c create mode 100644 libc-test/src/functionalext/supplement/misc/nftw.c create mode 100755 libc-test/src/functionalext/supplement/misc/openpty.c create mode 100755 libc-test/src/functionalext/supplement/misc/ptsname.c create mode 100644 libc-test/src/functionalext/supplement/misc/pty.c create mode 100644 libc-test/src/functionalext/supplement/misc/realpath.c create mode 100644 libc-test/src/functionalext/supplement/misc/setlogmask.c create mode 100644 libc-test/src/functionalext/supplement/misc/setpriority.c create mode 100644 libc-test/src/functionalext/supplement/misc/syscall.c create mode 100644 libc-test/src/functionalext/supplement/misc/syslog.c create mode 100644 libc-test/src/functionalext/supplement/misc/test_src_functionalext_supplement_misc.gni create mode 100644 libc-test/src/functionalext/supplement/misc/uname.c create mode 100644 libc-test/src/functionalext/supplement/misc/unlockpt.c create mode 100644 libc-test/src/functionalext/supplement/misc/vsyslog.c create mode 100755 libc-test/src/functionalext/supplement/mman/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/mman/madvise.c create mode 100755 libc-test/src/functionalext/supplement/mman/mincore.c create mode 100644 libc-test/src/functionalext/supplement/mman/mlock.c create mode 100644 libc-test/src/functionalext/supplement/mman/mlockall.c create mode 100644 libc-test/src/functionalext/supplement/mman/mmap.c create mode 100644 libc-test/src/functionalext/supplement/mman/mprotect.c create mode 100644 libc-test/src/functionalext/supplement/mman/mremap.c create mode 100644 libc-test/src/functionalext/supplement/mman/msync.c create mode 100755 libc-test/src/functionalext/supplement/mman/munlock.c create mode 100644 libc-test/src/functionalext/supplement/mman/munlockall.c create mode 100755 libc-test/src/functionalext/supplement/mman/munmap.c create mode 100755 libc-test/src/functionalext/supplement/mman/posix_madvise.c create mode 100644 libc-test/src/functionalext/supplement/mman/test_src_functionalext_supplement_mman.gni create mode 100644 libc-test/src/functionalext/supplement/multibyte/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/multibyte/c16rtomb.c create mode 100644 libc-test/src/functionalext/supplement/multibyte/c32rtomb.c create mode 100644 libc-test/src/functionalext/supplement/multibyte/mblen.c create mode 100755 libc-test/src/functionalext/supplement/multibyte/mbrtoc16.c create mode 100755 libc-test/src/functionalext/supplement/multibyte/mbrtoc32.c create mode 100644 libc-test/src/functionalext/supplement/multibyte/mbsinit.c create mode 100644 libc-test/src/functionalext/supplement/multibyte/mbsnrtowcs.c create mode 100755 libc-test/src/functionalext/supplement/multibyte/mbstowcs.c create mode 100644 libc-test/src/functionalext/supplement/multibyte/mbtowc.c create mode 100644 libc-test/src/functionalext/supplement/multibyte/test_src_functionalext_supplement_multibyte.gni create mode 100644 libc-test/src/functionalext/supplement/multibyte/wcrtomb.c create mode 100644 libc-test/src/functionalext/supplement/multibyte/wcsnrtombs.c create mode 100644 libc-test/src/functionalext/supplement/multibyte/wcsrtombs.c create mode 100644 libc-test/src/functionalext/supplement/multibyte/wcstombs.c create mode 100644 libc-test/src/functionalext/supplement/multibyte/wctob.c create mode 100644 libc-test/src/functionalext/supplement/multibyte/wctomb.c create mode 100644 libc-test/src/functionalext/supplement/network/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/network/__h_errno_location.c create mode 100644 libc-test/src/functionalext/supplement/network/accept4.c create mode 100755 libc-test/src/functionalext/supplement/network/dn_comp.c create mode 100755 libc-test/src/functionalext/supplement/network/dn_skipname.c create mode 100644 libc-test/src/functionalext/supplement/network/freeifaddrs.c create mode 100755 libc-test/src/functionalext/supplement/network/gai_strerror.c create mode 100644 libc-test/src/functionalext/supplement/network/getaddrinfo.c create mode 100644 libc-test/src/functionalext/supplement/network/gethostent.c create mode 100644 libc-test/src/functionalext/supplement/network/getifaddrs.c create mode 100644 libc-test/src/functionalext/supplement/network/getnetent.c create mode 100755 libc-test/src/functionalext/supplement/network/getpeername.c create mode 100755 libc-test/src/functionalext/supplement/network/getservbyname.c create mode 100755 libc-test/src/functionalext/supplement/network/getservbyport.c create mode 100644 libc-test/src/functionalext/supplement/network/getsockopt.c create mode 100755 libc-test/src/functionalext/supplement/network/hstrerror.c create mode 100644 libc-test/src/functionalext/supplement/network/htonl.c create mode 100644 libc-test/src/functionalext/supplement/network/htons.c create mode 100644 libc-test/src/functionalext/supplement/network/if_indextoname.c create mode 100644 libc-test/src/functionalext/supplement/network/if_nameindex.c create mode 100644 libc-test/src/functionalext/supplement/network/if_nametoindex.c create mode 100755 libc-test/src/functionalext/supplement/network/inet_addr.c create mode 100755 libc-test/src/functionalext/supplement/network/inet_aton.c create mode 100644 libc-test/src/functionalext/supplement/network/inet_lnaof.c create mode 100644 libc-test/src/functionalext/supplement/network/inet_makeaddr.c create mode 100644 libc-test/src/functionalext/supplement/network/inet_netof.c create mode 100644 libc-test/src/functionalext/supplement/network/inet_network.c create mode 100755 libc-test/src/functionalext/supplement/network/inet_ntoa.c create mode 100755 libc-test/src/functionalext/supplement/network/inet_ntop.c create mode 100644 libc-test/src/functionalext/supplement/network/listen.c create mode 100755 libc-test/src/functionalext/supplement/network/ns_parse.c create mode 100755 libc-test/src/functionalext/supplement/network/proto.c create mode 100755 libc-test/src/functionalext/supplement/network/recv.c create mode 100644 libc-test/src/functionalext/supplement/network/recvmmsg.c create mode 100644 libc-test/src/functionalext/supplement/network/recvmsg.c create mode 100644 libc-test/src/functionalext/supplement/network/res_mkquery.c create mode 100644 libc-test/src/functionalext/supplement/network/res_query.c create mode 100755 libc-test/src/functionalext/supplement/network/send.c create mode 100644 libc-test/src/functionalext/supplement/network/sendmmsg.c create mode 100644 libc-test/src/functionalext/supplement/network/sendmsg.c create mode 100644 libc-test/src/functionalext/supplement/network/setprotoent.c create mode 100644 libc-test/src/functionalext/supplement/network/shutdown.c create mode 100644 libc-test/src/functionalext/supplement/network/socketpair.c create mode 100644 libc-test/src/functionalext/supplement/network/test_src_functionalext_supplement_network.gni create mode 100644 libc-test/src/functionalext/supplement/passwd/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/passwd/getgrent.c create mode 100644 libc-test/src/functionalext/supplement/passwd/getgrgid.c create mode 100644 libc-test/src/functionalext/supplement/passwd/getgrgid_r.c create mode 100644 libc-test/src/functionalext/supplement/passwd/getgrnam.c create mode 100644 libc-test/src/functionalext/supplement/passwd/getgrnam_r.c create mode 100755 libc-test/src/functionalext/supplement/passwd/getgrouplist.c create mode 100755 libc-test/src/functionalext/supplement/passwd/getpw_r.c create mode 100644 libc-test/src/functionalext/supplement/passwd/getpwent.c create mode 100644 libc-test/src/functionalext/supplement/passwd/setgrent.c create mode 100644 libc-test/src/functionalext/supplement/passwd/setpwent.c create mode 100644 libc-test/src/functionalext/supplement/passwd/test_src_functionalext_supplement_passwd.gni create mode 100644 libc-test/src/functionalext/supplement/prng/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/prng/drand48.c create mode 100644 libc-test/src/functionalext/supplement/prng/erand48.c create mode 100644 libc-test/src/functionalext/supplement/prng/lcong48.c create mode 100644 libc-test/src/functionalext/supplement/prng/lrand48.c create mode 100644 libc-test/src/functionalext/supplement/prng/mrand48.c create mode 100644 libc-test/src/functionalext/supplement/prng/rand.c create mode 100644 libc-test/src/functionalext/supplement/prng/rand_r.c create mode 100644 libc-test/src/functionalext/supplement/prng/seed48.c create mode 100644 libc-test/src/functionalext/supplement/prng/srand.c create mode 100644 libc-test/src/functionalext/supplement/prng/srand48.c create mode 100644 libc-test/src/functionalext/supplement/prng/test_src_functionalext_supplement_prng.gni create mode 100644 libc-test/src/functionalext/supplement/process/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/process/execl.c create mode 100644 libc-test/src/functionalext/supplement/process/execlp.c create mode 100644 libc-test/src/functionalext/supplement/process/execv.c create mode 100644 libc-test/src/functionalext/supplement/process/execve.c create mode 100644 libc-test/src/functionalext/supplement/process/execvp.c create mode 100644 libc-test/src/functionalext/supplement/process/execvpe.c create mode 100644 libc-test/src/functionalext/supplement/process/fexecve.c create mode 100644 libc-test/src/functionalext/supplement/process/fexecverely.c create mode 100644 libc-test/src/functionalext/supplement/process/fork.c create mode 100755 libc-test/src/functionalext/supplement/process/posix_spawn.c create mode 100755 libc-test/src/functionalext/supplement/process/posix_spawn_file_actions_addopen.c create mode 100755 libc-test/src/functionalext/supplement/process/posix_spawnattr_getflags.c create mode 100755 libc-test/src/functionalext/supplement/process/posix_spawnattr_getpgroup.c create mode 100755 libc-test/src/functionalext/supplement/process/posix_spawnattr_getsigdefault.c create mode 100755 libc-test/src/functionalext/supplement/process/posix_spawnattr_getsigmask.c create mode 100755 libc-test/src/functionalext/supplement/process/posix_spawnattr_setflags.c create mode 100755 libc-test/src/functionalext/supplement/process/posix_spawnattr_setpgroup.c create mode 100755 libc-test/src/functionalext/supplement/process/posix_spawnattr_setsigdefault.c create mode 100755 libc-test/src/functionalext/supplement/process/posix_spawnattr_setsigmask.c create mode 100755 libc-test/src/functionalext/supplement/process/posix_spawnp.c create mode 100644 libc-test/src/functionalext/supplement/process/system.c create mode 100644 libc-test/src/functionalext/supplement/process/test_src_functionalext_supplement_process.gni create mode 100644 libc-test/src/functionalext/supplement/process/vfork.c create mode 100644 libc-test/src/functionalext/supplement/process/wait.c create mode 100644 libc-test/src/functionalext/supplement/process/waitid.c create mode 100644 libc-test/src/functionalext/supplement/process/waitpid.c create mode 100644 libc-test/src/functionalext/supplement/regex/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/regex/glob.c create mode 100644 libc-test/src/functionalext/supplement/regex/test_src_functionalext_supplement_regex.gni create mode 100755 libc-test/src/functionalext/supplement/sched/BUILD.gn create mode 100755 libc-test/src/functionalext/supplement/sched/__sched_cpucount.c create mode 100644 libc-test/src/functionalext/supplement/sched/sched_getaffinity.c create mode 100644 libc-test/src/functionalext/supplement/sched/sched_getcpu.c create mode 100644 libc-test/src/functionalext/supplement/sched/sched_rr_get_interval.c create mode 100644 libc-test/src/functionalext/supplement/sched/sched_setaffinity.c create mode 100644 libc-test/src/functionalext/supplement/sched/sched_yield.c create mode 100644 libc-test/src/functionalext/supplement/sched/test_src_functionalext_supplement_sched.gni create mode 100644 libc-test/src/functionalext/supplement/search/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/search/hcreate_r.c create mode 100644 libc-test/src/functionalext/supplement/search/hdestroy.c create mode 100644 libc-test/src/functionalext/supplement/search/hsearch_r.c create mode 100644 libc-test/src/functionalext/supplement/search/lfind.c create mode 100644 libc-test/src/functionalext/supplement/search/tdestroy.c create mode 100644 libc-test/src/functionalext/supplement/search/test_src_functionalext_supplement_search.gni create mode 100755 libc-test/src/functionalext/supplement/select/BUILD.gn create mode 100755 libc-test/src/functionalext/supplement/select/poll.c create mode 100755 libc-test/src/functionalext/supplement/select/pselect.c create mode 100755 libc-test/src/functionalext/supplement/select/select.c create mode 100644 libc-test/src/functionalext/supplement/select/test_src_functionalext_supplement_select.gni create mode 100644 libc-test/src/functionalext/supplement/setjmp/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/setjmp/_longjmp.c create mode 100644 libc-test/src/functionalext/supplement/setjmp/_setjmp.c create mode 100644 libc-test/src/functionalext/supplement/setjmp/test_src_functionalext_supplement_setjmp.gni create mode 100644 libc-test/src/functionalext/supplement/signal/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/signal/getitimer.c create mode 100644 libc-test/src/functionalext/supplement/signal/kill.c create mode 100644 libc-test/src/functionalext/supplement/signal/killpg.c create mode 100755 libc-test/src/functionalext/supplement/signal/libc_current_sigrtmax.c create mode 100755 libc-test/src/functionalext/supplement/signal/libc_current_sigrtmin.c create mode 100755 libc-test/src/functionalext/supplement/signal/psiginfo.c create mode 100755 libc-test/src/functionalext/supplement/signal/psignal.c create mode 100644 libc-test/src/functionalext/supplement/signal/setitimer.c create mode 100644 libc-test/src/functionalext/supplement/signal/sigaction.c create mode 100644 libc-test/src/functionalext/supplement/signal/sighold.c create mode 100644 libc-test/src/functionalext/supplement/signal/sigignore.c create mode 100644 libc-test/src/functionalext/supplement/signal/signal.c create mode 100644 libc-test/src/functionalext/supplement/signal/sigpause.c create mode 100644 libc-test/src/functionalext/supplement/signal/sigpending.c create mode 100644 libc-test/src/functionalext/supplement/signal/sigqueue.c create mode 100644 libc-test/src/functionalext/supplement/signal/sigrelse.c create mode 100644 libc-test/src/functionalext/supplement/signal/sigset.c create mode 100644 libc-test/src/functionalext/supplement/signal/sigsuspend.c create mode 100644 libc-test/src/functionalext/supplement/signal/sigwait.c create mode 100644 libc-test/src/functionalext/supplement/signal/sigwaitinfo.c create mode 100644 libc-test/src/functionalext/supplement/signal/test_src_functionalext_supplement_signal.gni create mode 100644 libc-test/src/functionalext/supplement/stat/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/stat/chmod.c create mode 100755 libc-test/src/functionalext/supplement/stat/fchmod.c create mode 100755 libc-test/src/functionalext/supplement/stat/fchmodat.c create mode 100644 libc-test/src/functionalext/supplement/stat/fstatat.c create mode 100755 libc-test/src/functionalext/supplement/stat/fstatfs.c create mode 100755 libc-test/src/functionalext/supplement/stat/fstatvfs.c create mode 100755 libc-test/src/functionalext/supplement/stat/futimesat.c create mode 100755 libc-test/src/functionalext/supplement/stat/lstat.c create mode 100644 libc-test/src/functionalext/supplement/stat/mkdir.c create mode 100755 libc-test/src/functionalext/supplement/stat/mkdirat.c create mode 100644 libc-test/src/functionalext/supplement/stat/mkfifo.c create mode 100644 libc-test/src/functionalext/supplement/stat/mkfifoat.c create mode 100755 libc-test/src/functionalext/supplement/stat/mknod.c create mode 100644 libc-test/src/functionalext/supplement/stat/mknodat.c create mode 100644 libc-test/src/functionalext/supplement/stat/stat.c create mode 100644 libc-test/src/functionalext/supplement/stat/statfs.c create mode 100644 libc-test/src/functionalext/supplement/stat/statvfs.c create mode 100644 libc-test/src/functionalext/supplement/stat/test_src_functionalext_supplement_stat.gni create mode 100644 libc-test/src/functionalext/supplement/stat/umask.c create mode 100644 libc-test/src/functionalext/supplement/stat/utimensat.c create mode 100644 libc-test/src/functionalext/supplement/stdio/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/stdio/__fbufsize.c create mode 100644 libc-test/src/functionalext/supplement/stdio/__flbf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/__fpending.c create mode 100644 libc-test/src/functionalext/supplement/stdio/__fpurge.c create mode 100644 libc-test/src/functionalext/supplement/stdio/__freadable.c create mode 100644 libc-test/src/functionalext/supplement/stdio/__freading.c create mode 100644 libc-test/src/functionalext/supplement/stdio/__fseterr.c create mode 100644 libc-test/src/functionalext/supplement/stdio/__fsetlocking.c create mode 100644 libc-test/src/functionalext/supplement/stdio/__fwritable.c create mode 100644 libc-test/src/functionalext/supplement/stdio/__fwriting.c create mode 100644 libc-test/src/functionalext/supplement/stdio/_flushlbf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/asprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/clearerr.c create mode 100644 libc-test/src/functionalext/supplement/stdio/dprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fflush.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fgetln.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fgetpos.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fgets.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fgetws.c create mode 100644 libc-test/src/functionalext/supplement/stdio/flockfile.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fopen.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fputc.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fputs.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fputwc.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fputws.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fread.c create mode 100644 libc-test/src/functionalext/supplement/stdio/freopen.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fseeko.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fsetpos.c create mode 100644 libc-test/src/functionalext/supplement/stdio/ftell.c create mode 100644 libc-test/src/functionalext/supplement/stdio/ftrylockfile.c create mode 100644 libc-test/src/functionalext/supplement/stdio/funlockfile.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fwide.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fwprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/fwrite.c create mode 100644 libc-test/src/functionalext/supplement/stdio/getc.c create mode 100644 libc-test/src/functionalext/supplement/stdio/getc_unlocked.c create mode 100644 libc-test/src/functionalext/supplement/stdio/getchar.c create mode 100644 libc-test/src/functionalext/supplement/stdio/getchar_unlocked.c create mode 100644 libc-test/src/functionalext/supplement/stdio/getdelim.c create mode 100644 libc-test/src/functionalext/supplement/stdio/getline.c create mode 100644 libc-test/src/functionalext/supplement/stdio/getwc.c create mode 100755 libc-test/src/functionalext/supplement/stdio/open_wmemstream.c create mode 100644 libc-test/src/functionalext/supplement/stdio/printf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/putc.c create mode 100755 libc-test/src/functionalext/supplement/stdio/putc_unlocked.c create mode 100644 libc-test/src/functionalext/supplement/stdio/putchar.c create mode 100755 libc-test/src/functionalext/supplement/stdio/putchar_unlocked.c create mode 100644 libc-test/src/functionalext/supplement/stdio/puts.c create mode 100644 libc-test/src/functionalext/supplement/stdio/putw.c create mode 100644 libc-test/src/functionalext/supplement/stdio/putwc.c create mode 100755 libc-test/src/functionalext/supplement/stdio/putwchar.c create mode 100644 libc-test/src/functionalext/supplement/stdio/remove.c create mode 100644 libc-test/src/functionalext/supplement/stdio/rename.c create mode 100644 libc-test/src/functionalext/supplement/stdio/rewind.c create mode 100644 libc-test/src/functionalext/supplement/stdio/setbuf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/setbuffer.c create mode 100644 libc-test/src/functionalext/supplement/stdio/setlinebuf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/setvbuf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/sprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/swscanf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/tempnam.c create mode 100644 libc-test/src/functionalext/supplement/stdio/test_src_functionalext_supplement_stdio.gni create mode 100644 libc-test/src/functionalext/supplement/stdio/tmpfile.c create mode 100644 libc-test/src/functionalext/supplement/stdio/tmpnam.c create mode 100644 libc-test/src/functionalext/supplement/stdio/ungetwc.c create mode 100644 libc-test/src/functionalext/supplement/stdio/vasprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/vdprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/vfprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/vfscanf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/vfwprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/vfwscanf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/vprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/vsnprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/vsprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/vsscanf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/vswprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/vswscanf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/vwprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdio/wcstoll.c create mode 100644 libc-test/src/functionalext/supplement/stdio/wcstoull.c create mode 100644 libc-test/src/functionalext/supplement/stdio/wprintf.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/stdlib/abs.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/atof.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/atoi.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/atoll.c create mode 100755 libc-test/src/functionalext/supplement/stdlib/bseach.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/imaxabs.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/imaxdiv.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/labs.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/ldiv.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/llabs.c create mode 100755 libc-test/src/functionalext/supplement/stdlib/lldiv.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/strtoimax.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/strtoumax.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/test_src_functionalext_supplement_stdlib.gni create mode 100644 libc-test/src/functionalext/supplement/stdlib/wcstod.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/wcstof.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/wcstoimax.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/wcstold.c create mode 100644 libc-test/src/functionalext/supplement/stdlib/wcstoumax.c create mode 100644 libc-test/src/functionalext/supplement/string/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/string/bzero.c create mode 100644 libc-test/src/functionalext/supplement/string/index.c create mode 100644 libc-test/src/functionalext/supplement/string/memccpy.c create mode 100644 libc-test/src/functionalext/supplement/string/memchr.c create mode 100644 libc-test/src/functionalext/supplement/string/memmem.c create mode 100644 libc-test/src/functionalext/supplement/string/memmove.c create mode 100644 libc-test/src/functionalext/supplement/string/mempcpy.c create mode 100755 libc-test/src/functionalext/supplement/string/memrchr.c create mode 100644 libc-test/src/functionalext/supplement/string/stpcpy.c create mode 100644 libc-test/src/functionalext/supplement/string/stpncpy.c create mode 100644 libc-test/src/functionalext/supplement/string/strcasecmp.c create mode 100644 libc-test/src/functionalext/supplement/string/strcasestr.c create mode 100644 libc-test/src/functionalext/supplement/string/strcat.c create mode 100644 libc-test/src/functionalext/supplement/string/strchrnul.c create mode 100644 libc-test/src/functionalext/supplement/string/strcoll.c create mode 100644 libc-test/src/functionalext/supplement/string/strdup.c create mode 100644 libc-test/src/functionalext/supplement/string/strerror_r.c create mode 100644 libc-test/src/functionalext/supplement/string/strlen.c create mode 100644 libc-test/src/functionalext/supplement/string/strncasecmp.c create mode 100644 libc-test/src/functionalext/supplement/string/strndup.c create mode 100644 libc-test/src/functionalext/supplement/string/strnlen.c create mode 100644 libc-test/src/functionalext/supplement/string/strrchr.c create mode 100644 libc-test/src/functionalext/supplement/string/strsep.c create mode 100644 libc-test/src/functionalext/supplement/string/strsignal.c create mode 100644 libc-test/src/functionalext/supplement/string/strtok_r.c create mode 100644 libc-test/src/functionalext/supplement/string/swab.c create mode 100644 libc-test/src/functionalext/supplement/string/test_src_functionalext_supplement_string.gni create mode 100644 libc-test/src/functionalext/supplement/string/wcpcpy.c create mode 100644 libc-test/src/functionalext/supplement/string/wcpncpy.c create mode 100644 libc-test/src/functionalext/supplement/string/wcscasecmp.c create mode 100644 libc-test/src/functionalext/supplement/string/wcscasecmp_l.c create mode 100644 libc-test/src/functionalext/supplement/string/wcscat.c create mode 100644 libc-test/src/functionalext/supplement/string/wcschr.c create mode 100644 libc-test/src/functionalext/supplement/string/wcscmp.c create mode 100644 libc-test/src/functionalext/supplement/string/wcscpy.c create mode 100644 libc-test/src/functionalext/supplement/string/wcscspn.c create mode 100644 libc-test/src/functionalext/supplement/string/wcsdup.c create mode 100644 libc-test/src/functionalext/supplement/string/wcslen.c create mode 100644 libc-test/src/functionalext/supplement/string/wcsncasecmp.c create mode 100644 libc-test/src/functionalext/supplement/string/wcsncasecmp_l.c create mode 100644 libc-test/src/functionalext/supplement/string/wcsncat.c create mode 100644 libc-test/src/functionalext/supplement/string/wcsncmp.c create mode 100644 libc-test/src/functionalext/supplement/string/wcsncpy.c create mode 100644 libc-test/src/functionalext/supplement/string/wcsnlen.c create mode 100644 libc-test/src/functionalext/supplement/string/wcspbrk.c create mode 100644 libc-test/src/functionalext/supplement/string/wcsrchr.c create mode 100644 libc-test/src/functionalext/supplement/string/wcsspn.c create mode 100644 libc-test/src/functionalext/supplement/string/wcstok.c create mode 100644 libc-test/src/functionalext/supplement/string/wcswcs.c create mode 100644 libc-test/src/functionalext/supplement/string/wmemchr.c create mode 100644 libc-test/src/functionalext/supplement/string/wmemcmp.c create mode 100644 libc-test/src/functionalext/supplement/string/wmemcpy.c create mode 100644 libc-test/src/functionalext/supplement/string/wmemmove.c create mode 100644 libc-test/src/functionalext/supplement/string/wmemset.c create mode 100644 libc-test/src/functionalext/supplement/temp/BUILD.gn create mode 100755 libc-test/src/functionalext/supplement/temp/mkdtemp.c create mode 100644 libc-test/src/functionalext/supplement/temp/mkostemp.c create mode 100644 libc-test/src/functionalext/supplement/temp/mkostemps.c create mode 100644 libc-test/src/functionalext/supplement/temp/mkstemp.c create mode 100644 libc-test/src/functionalext/supplement/temp/mkstemps.c create mode 100755 libc-test/src/functionalext/supplement/temp/mktemp.c create mode 100644 libc-test/src/functionalext/supplement/temp/test_src_functionalext_supplement_temp.gni create mode 100644 libc-test/src/functionalext/supplement/termios/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/termios/cfgetispeed.c create mode 100644 libc-test/src/functionalext/supplement/termios/cfgetospeed.c create mode 100644 libc-test/src/functionalext/supplement/termios/cfmakeraw.c create mode 100644 libc-test/src/functionalext/supplement/termios/cfsetispeed.c create mode 100755 libc-test/src/functionalext/supplement/termios/cfsetospeed.c create mode 100644 libc-test/src/functionalext/supplement/termios/tcdrain.c create mode 100644 libc-test/src/functionalext/supplement/termios/tcflow.c create mode 100644 libc-test/src/functionalext/supplement/termios/test_src_functionalext_supplement_termios.gni create mode 100644 libc-test/src/functionalext/supplement/test_src_functionalext_supplement.gni create mode 100644 libc-test/src/functionalext/supplement/thread/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/thread/call_once.c create mode 100644 libc-test/src/functionalext/supplement/thread/cnd_init.c create mode 100644 libc-test/src/functionalext/supplement/thread/cnd_signal.c create mode 100644 libc-test/src/functionalext/supplement/thread/cnd_timedwait.c create mode 100644 libc-test/src/functionalext/supplement/thread/cnd_wait.c create mode 100644 libc-test/src/functionalext/supplement/thread/mtx_init.c create mode 100644 libc-test/src/functionalext/supplement/thread/mtx_lock.c create mode 100755 libc-test/src/functionalext/supplement/thread/mtx_timedlock.c create mode 100644 libc-test/src/functionalext/supplement/thread/mtx_trylock.c create mode 100644 libc-test/src/functionalext/supplement/thread/mtx_unlock.c create mode 100755 libc-test/src/functionalext/supplement/thread/pthread_atfork.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_attr_destroy.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_attr_get.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_attr_getstack.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_attr_init.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_attr_setdetachstate.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_attr_setguardsize.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_attr_setinheritsched.c create mode 100755 libc-test/src/functionalext/supplement/thread/pthread_attr_setschedparam.c create mode 100755 libc-test/src/functionalext/supplement/thread/pthread_attr_setschedpolicy.c create mode 100755 libc-test/src/functionalext/supplement/thread/pthread_attr_setscope.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_attr_setstack.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_attr_setstacksize.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_barrier_destroy.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_barrier_init.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_barrier_wait.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_barrierattr_init.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_barrierattr_setpshared.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_cond_broadcast.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_cond_destroy.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_cond_init.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_cond_signal.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_cond_timedwait.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_cond_wait.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_condattr_destroy.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_condattr_init.c create mode 100755 libc-test/src/functionalext/supplement/thread/pthread_condattr_setclock.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_condattr_setpshared.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_create.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_detach.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_equal.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_exit.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_getattr_np.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_getcpuclockid.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_getschedparam.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_getspecific.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_join.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_key_create.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_key_delete.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_mutex_destroy.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_mutex_init.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_mutex_lock.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_mutex_timedlock.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_mutex_trylock.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_mutex_unlock.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_mutexattr_destroy.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_mutexattr_setprotocol.c create mode 100755 libc-test/src/functionalext/supplement/thread/pthread_mutexattr_setpshared.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_mutexattr_settype.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_once.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_rwlock_destroy.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_rwlock_rdlock.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_rwlock_timedrdlock.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_rwlock_timedwrlock.c create mode 100755 libc-test/src/functionalext/supplement/thread/pthread_rwlock_tryrdlock.c create mode 100755 libc-test/src/functionalext/supplement/thread/pthread_rwlock_trywrlock.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_rwlockattr_destroy.c create mode 100755 libc-test/src/functionalext/supplement/thread/pthread_rwlockattr_init.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_rwlockattr_setpshared.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_self.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_setschedparam.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_setschedprio.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_setspecific.c create mode 100644 libc-test/src/functionalext/supplement/thread/pthread_sigmask.c create mode 100755 libc-test/src/functionalext/supplement/thread/pthread_spin_lock.c create mode 100755 libc-test/src/functionalext/supplement/thread/pthread_spin_trylock.c create mode 100755 libc-test/src/functionalext/supplement/thread/pthread_spin_unlock.c create mode 100644 libc-test/src/functionalext/supplement/thread/test_src_functionalext_supplement_thread.gni create mode 100644 libc-test/src/functionalext/supplement/thread/thrd_create.c create mode 100644 libc-test/src/functionalext/supplement/thread/thrd_current.c create mode 100644 libc-test/src/functionalext/supplement/thread/thrd_detach.c create mode 100644 libc-test/src/functionalext/supplement/thread/thrd_equal.c create mode 100644 libc-test/src/functionalext/supplement/thread/thrd_join.c create mode 100644 libc-test/src/functionalext/supplement/thread/thrd_sleep.c create mode 100644 libc-test/src/functionalext/supplement/thread/thrd_yield.c create mode 100644 libc-test/src/functionalext/supplement/thread/tss_set.c create mode 100644 libc-test/src/functionalext/supplement/time/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/time/clock.c create mode 100644 libc-test/src/functionalext/supplement/time/clock_getcpuclockid.c create mode 100644 libc-test/src/functionalext/supplement/time/clock_getres.c create mode 100644 libc-test/src/functionalext/supplement/time/clock_nanosleep.c create mode 100644 libc-test/src/functionalext/supplement/time/clock_settime.c create mode 100644 libc-test/src/functionalext/supplement/time/difftime.c create mode 100644 libc-test/src/functionalext/supplement/time/gettimeofday.c create mode 100644 libc-test/src/functionalext/supplement/time/gmtime.c create mode 100644 libc-test/src/functionalext/supplement/time/gmtime_r.c create mode 100644 libc-test/src/functionalext/supplement/time/mktime.c create mode 100755 libc-test/src/functionalext/supplement/time/nanosleep.c create mode 100644 libc-test/src/functionalext/supplement/time/test_src_functionalext_supplement_time.gni create mode 100644 libc-test/src/functionalext/supplement/time/time.c create mode 100644 libc-test/src/functionalext/supplement/time/timer_create.c create mode 100644 libc-test/src/functionalext/supplement/time/timer_delete.c create mode 100644 libc-test/src/functionalext/supplement/time/timer_getoverrun.c create mode 100644 libc-test/src/functionalext/supplement/time/timer_gettime.c create mode 100644 libc-test/src/functionalext/supplement/time/timer_settime.c create mode 100644 libc-test/src/functionalext/supplement/time/times.c create mode 100644 libc-test/src/functionalext/supplement/time/timespec_get.c create mode 100644 libc-test/src/functionalext/supplement/time/utime.c create mode 100644 libc-test/src/functionalext/supplement/time/wcsftime.c create mode 100644 libc-test/src/functionalext/supplement/time/wcsftime_l.c create mode 100644 libc-test/src/functionalext/supplement/unistd/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/unistd/access.c create mode 100644 libc-test/src/functionalext/supplement/unistd/acct.c create mode 100755 libc-test/src/functionalext/supplement/unistd/alarm.c create mode 100755 libc-test/src/functionalext/supplement/unistd/chdir.c create mode 100644 libc-test/src/functionalext/supplement/unistd/chown.c create mode 100755 libc-test/src/functionalext/supplement/unistd/ctermid.c create mode 100644 libc-test/src/functionalext/supplement/unistd/dup3.c create mode 100755 libc-test/src/functionalext/supplement/unistd/exit.c create mode 100755 libc-test/src/functionalext/supplement/unistd/exittest01.c create mode 100755 libc-test/src/functionalext/supplement/unistd/exittest02.c create mode 100644 libc-test/src/functionalext/supplement/unistd/faccessat.c create mode 100644 libc-test/src/functionalext/supplement/unistd/fchown.c create mode 100644 libc-test/src/functionalext/supplement/unistd/fchownat.c create mode 100755 libc-test/src/functionalext/supplement/unistd/fdatasync.c create mode 100644 libc-test/src/functionalext/supplement/unistd/fsync.c create mode 100644 libc-test/src/functionalext/supplement/unistd/ftruncate.c create mode 100755 libc-test/src/functionalext/supplement/unistd/getcwd.c create mode 100755 libc-test/src/functionalext/supplement/unistd/getegid.c create mode 100755 libc-test/src/functionalext/supplement/unistd/geteuid.c create mode 100755 libc-test/src/functionalext/supplement/unistd/getgid.c create mode 100755 libc-test/src/functionalext/supplement/unistd/getgroups.c create mode 100644 libc-test/src/functionalext/supplement/unistd/gethostname.c create mode 100644 libc-test/src/functionalext/supplement/unistd/getlogin.c create mode 100644 libc-test/src/functionalext/supplement/unistd/getlogin_r.c create mode 100644 libc-test/src/functionalext/supplement/unistd/getpgid.c create mode 100755 libc-test/src/functionalext/supplement/unistd/getpgrp.c create mode 100755 libc-test/src/functionalext/supplement/unistd/getpid.c create mode 100755 libc-test/src/functionalext/supplement/unistd/getppid.c create mode 100644 libc-test/src/functionalext/supplement/unistd/getsid.c create mode 100755 libc-test/src/functionalext/supplement/unistd/getsockopt.c create mode 100644 libc-test/src/functionalext/supplement/unistd/getuid.c create mode 100755 libc-test/src/functionalext/supplement/unistd/lchown.c create mode 100644 libc-test/src/functionalext/supplement/unistd/link.c create mode 100644 libc-test/src/functionalext/supplement/unistd/linkat.c create mode 100644 libc-test/src/functionalext/supplement/unistd/lseek.c create mode 100644 libc-test/src/functionalext/supplement/unistd/nice.c create mode 100755 libc-test/src/functionalext/supplement/unistd/pause.c create mode 100755 libc-test/src/functionalext/supplement/unistd/pipe2.c create mode 100644 libc-test/src/functionalext/supplement/unistd/pread.c create mode 100755 libc-test/src/functionalext/supplement/unistd/preadv.c create mode 100755 libc-test/src/functionalext/supplement/unistd/pwrite.c create mode 100755 libc-test/src/functionalext/supplement/unistd/pwritev.c create mode 100644 libc-test/src/functionalext/supplement/unistd/read.c create mode 100644 libc-test/src/functionalext/supplement/unistd/readlink.c create mode 100644 libc-test/src/functionalext/supplement/unistd/readlinkat.c create mode 100644 libc-test/src/functionalext/supplement/unistd/readv.c create mode 100644 libc-test/src/functionalext/supplement/unistd/renameat.c create mode 100644 libc-test/src/functionalext/supplement/unistd/rmdir.c create mode 100644 libc-test/src/functionalext/supplement/unistd/setdomainname.c create mode 100644 libc-test/src/functionalext/supplement/unistd/setegid.c create mode 100644 libc-test/src/functionalext/supplement/unistd/seteuid.c create mode 100644 libc-test/src/functionalext/supplement/unistd/setgid.c create mode 100644 libc-test/src/functionalext/supplement/unistd/sethostname.c create mode 100644 libc-test/src/functionalext/supplement/unistd/setpgid.c create mode 100644 libc-test/src/functionalext/supplement/unistd/setpgrp.c create mode 100644 libc-test/src/functionalext/supplement/unistd/setregid.c create mode 100644 libc-test/src/functionalext/supplement/unistd/setresgid.c create mode 100644 libc-test/src/functionalext/supplement/unistd/setresuid.c create mode 100644 libc-test/src/functionalext/supplement/unistd/setreuid.c create mode 100644 libc-test/src/functionalext/supplement/unistd/setsid.c create mode 100644 libc-test/src/functionalext/supplement/unistd/setuid.c create mode 100644 libc-test/src/functionalext/supplement/unistd/sleep.c create mode 100644 libc-test/src/functionalext/supplement/unistd/symlink.c create mode 100644 libc-test/src/functionalext/supplement/unistd/symlinkat.c create mode 100644 libc-test/src/functionalext/supplement/unistd/test_src_functionalext_supplement_unistd.gni create mode 100644 libc-test/src/functionalext/supplement/unistd/truncate.c create mode 100644 libc-test/src/functionalext/supplement/unistd/ttyname_r.c create mode 100644 libc-test/src/functionalext/supplement/unistd/unlink.c create mode 100644 libc-test/src/functionalext/supplement/unistd/unlinkat.c create mode 100644 libc-test/src/functionalext/supplement/unistd/usleep.c create mode 100644 libc-test/src/functionalext/supplement/unistd/write.c create mode 100644 libc-test/src/functionalext/supplement/unistd/writev.c create mode 100644 libc-test/src/functionalext/supplement/wctype/BUILD.gn create mode 100644 libc-test/src/functionalext/supplement/wctype/iswalnum_l.c create mode 100644 libc-test/src/functionalext/supplement/wctype/iswctype_l.c create mode 100644 libc-test/src/functionalext/supplement/wctype/iswgraph.c create mode 100644 libc-test/src/functionalext/supplement/wctype/iswgraph_l.c create mode 100644 libc-test/src/functionalext/supplement/wctype/test_src_functionalext_supplement_wctype.gni diff --git a/libc-test/src/functionalext/common/functionalext.h b/libc-test/src/functionalext/common/functionalext.h index 5cde5b73..1fc98cdf 100644 --- a/libc-test/src/functionalext/common/functionalext.h +++ b/libc-test/src/functionalext/common/functionalext.h @@ -27,6 +27,7 @@ #define EPS (0.00001) #define CMPFLAG 0 #define ERREXPECT (-1) +#define ONREXPECT 1 #define EXPECT_TRUE(fun, c) do { \ if (!(c)) \ @@ -43,6 +44,16 @@ t_error("[%s] failed %d != %d \n", fun, a, b); \ } while (0) +#define EXPECT_LT(fun, a, b) do { \ + if ((a) >= (b)) \ + t_error("[%s] failed (errno: %s) %d >= %d \n", #fun, strerror(errno), a, b); \ +} while(0) + +#define EXPECT_MT(fun, a, b) do { \ + if ((a) <= (b)) \ + t_error("[%s] failed (errno: %s) %d >= %d \n", #fun, strerror(errno), a, b); \ +} while(0) + #define EXPECT_NE(fun, a, b) do { \ if ((int)(a) == (int)(b)) \ t_error("[%s] failed %d == %d \n", fun, (a), (b)); \ @@ -54,9 +65,14 @@ t_error("[%s] failed %s != %s \n", fun, (a), (b)); \ } while (0) -#define EXPECT_STRNE(fun, a, b) do { \ - if (strcmp((a), (b)) == 0) \ - t_error("[%s] failed %s == %s \n", fun, (a), (b)); \ +#define EXPECT_STRLT(fun, a, b) do { \ + if ((a) >= (b)) \ + t_error("[%s] failed (errno: %s) %d >= %d \n", #fun, strerror(errno), a, b); \ +} while(0) + +#define EXPECT_STRMT(fun, a, b) do { \ + if ((a) <= (b)) \ + t_error("[%s] failed (errno: %s) %d >= %d \n", #fun, strerror(errno), a, b); \ } while(0) /* floating point comparison */ @@ -77,5 +93,25 @@ } \ } while (0) +#define EXPECT_STRNE(fun, a, b) do { \ + if (strcmp((a), (b)) == 0) \ + t_error("[%s] failed %s == %s \n", fun, (a), (b)); \ +} while(0) + +#define EXPECT_LONGEQ(fun, a, b) do { \ + if ((long)(a) != (long)(b)) \ + t_error("[%s] failed %ld != %ld \n", fun, a, b); \ +} while(0) + +#define EXPECT_LONGLONGEQ(fun, a, b) do { \ + if ((long)(a) != (long)(b)) \ + t_error("[%s] failed %lld != %lld \n", fun, a, b); \ +} while(0) + +#define EXPECT_GT(fun, a, b) do { \ + if ((a) <= (b)) { \ + t_error("[%s] failed %d > %d \n", fun, a, b); \ + } \ +} while(0) #endif \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/BUILD.gn b/libc-test/src/functionalext/supplement/BUILD.gn new file mode 100644 index 00000000..1dbbf88f --- /dev/null +++ b/libc-test/src/functionalext/supplement/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../test_template.gni") +import("test_src_functionalext_supplement.gni") + +group("functionalext_supplement_test") { + testonly = true + deps = [] + + foreach(s, functionalext_supplement_list) { + deps += [ "${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/conf/BUILD.gn b/libc-test/src/functionalext/supplement/conf/BUILD.gn new file mode 100644 index 00000000..97daa138 --- /dev/null +++ b/libc-test/src/functionalext/supplement/conf/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_conf.gni") + +foreach(s, functionalext_supplement_conf_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/conf" + } +} + +group("functionalext_supplement_conf_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_conf_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/conf/fpathconf.c b/libc-test/src/functionalext/supplement/conf/fpathconf.c new file mode 100644 index 00000000..4074fdcb --- /dev/null +++ b/libc-test/src/functionalext/supplement/conf/fpathconf.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : fpathconf_0100 + * @tc.desc : Verify that you can query values related to file system limits and options + * (each parameter is valid, the name parameter is _PC_LINK_MAX,) + * @tc.level : Level 0 + */ +void fpathconf_0100(void) +{ + long result; + result = fpathconf(0, _PC_LINK_MAX); + EXPECT_EQ("fpathconf_0100", result, _POSIX_LINK_MAX); +} + +/** + * @tc.name : fpathconf_0200 + * @tc.desc : Verify that you can query values related to file system limits and options + * (each parameter is valid, the name parameter is _PC_SOCK_MAXBUF,) + * @tc.level : Level 0 + */ +void fpathconf_0200(void) +{ + long result; + result = fpathconf(0, _PC_SOCK_MAXBUF); + EXPECT_EQ("fpathconf_0200", result, -1); +} + +/** + * @tc.name : fpathconf_0300 + * @tc.desc : Verify that you can query values related to file system limits and options + * (each parameter is valid, the name parameter is _PC_FILESIZEBITS,) + * @tc.level : Level 0 + */ +void fpathconf_0300(void) +{ + long result; + result = fpathconf(0, _PC_FILESIZEBITS); + EXPECT_EQ("fpathconf_0300", result, FILESIZEBITS); +} + +/** + * @tc.name : fpathconf_0400 + * @tc.desc : Verify that you can query values related to file system limits and options + * (each parameter is valid, the name parameter is _PC_2_SYMLINKS,) + * @tc.level : Level 0 + */ +void fpathconf_0400(void) +{ + long result; + result = fpathconf(0, _PC_2_SYMLINKS); + EXPECT_EQ("fpathconf_0400", result, 1); +} + +/** + * @tc.name : fpathconf_0500 + * @tc.desc : Verify that you can query values related to file system limits and options + * (each parameter is valid, the name parameter is 1000,) + * @tc.level : Level 2 + */ +void fpathconf_0500(void) +{ + long result; + result = fpathconf(0, 1000); + EXPECT_EQ("fpathconf_0500", result, -1); +} + +int main() +{ + fpathconf_0100(); + fpathconf_0200(); + fpathconf_0300(); + fpathconf_0400(); + fpathconf_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/conf/get_avphys_page.c b/libc-test/src/functionalext/supplement/conf/get_avphys_page.c new file mode 100644 index 00000000..411ab473 --- /dev/null +++ b/libc-test/src/functionalext/supplement/conf/get_avphys_page.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : get_nprocs_0100 + * @tc.desc : Verify the total number of pages available for acquisition + * @tc.level : Level 0 + */ +void get_nprocs_0100(void) +{ + int result; + result = get_avphys_pages(); + bool flag = false; + if (result > 0) { + flag = true; + } + EXPECT_TRUE("fpathconf_0100", true); +} + +TEST_FUN G_Fun_Array[] = { + get_nprocs_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/conf/get_nprocs.c b/libc-test/src/functionalext/supplement/conf/get_nprocs.c new file mode 100644 index 00000000..6419ced4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/conf/get_nprocs.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : get_nprocs_0100 + * @tc.desc : Verify the number of CPUs being used + * @tc.level : Level 0 + */ +void get_nprocs_0100(void) +{ + int result; + result = get_nprocs(); + bool flag = false; + if (result > 0) { + flag = true; + } + EXPECT_TRUE("fpathconf_0100", true); +} + +TEST_FUN G_Fun_Array[] = { + get_nprocs_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/conf/get_nprocs_conf.c b/libc-test/src/functionalext/supplement/conf/get_nprocs_conf.c new file mode 100644 index 00000000..8054849f --- /dev/null +++ b/libc-test/src/functionalext/supplement/conf/get_nprocs_conf.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : fpathconf_0100 + * @tc.desc : Verify the number of CPUs obtained + * @tc.level : Level 0 + */ +void get_nprocs_0100(void) +{ + int result; + result = get_nprocs_conf(); + bool flag = false; + if (result > 0) { + flag = true; + } + EXPECT_TRUE("fpathconf_0100", true); +} + +TEST_FUN G_Fun_Array[] = { + get_nprocs_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/conf/get_phys_pages.c b/libc-test/src/functionalext/supplement/conf/get_phys_pages.c new file mode 100644 index 00000000..41c096b6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/conf/get_phys_pages.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : get_nprocs_0100 + * @tc.desc : Verify the total number of pages fetched in memory + * @tc.level : Level 0 + */ +void get_nprocs_0100(void) +{ + int result; + result = get_phys_pages(); + bool flag = false; + if (result > 0) { + flag = true; + } + EXPECT_TRUE("fpathconf_0100", true); +} + +TEST_FUN G_Fun_Array[] = { + get_nprocs_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/conf/pathconf.c b/libc-test/src/functionalext/supplement/conf/pathconf.c new file mode 100755 index 00000000..f34b89e2 --- /dev/null +++ b/libc-test/src/functionalext/supplement/conf/pathconf.c @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define TEST_LIMIT_ERROR 1000 +#define TEST_LIMIT_SIZE 3 +struct limit_data { + int name; + long limit; +}; + +/** + * @tc.name : pathconf_0100 + * @tc.desc : Get file-related configuration values + * @tc.level : Level 0 + */ +void pathconf_0100(void) +{ + struct limit_data data[TEST_LIMIT_SIZE] = { + {.name = _PC_PATH_MAX, .limit = PATH_MAX}, + {.name = _PC_PIPE_BUF, .limit = PIPE_BUF}, + {.name = _PC_NAME_MAX, .limit = NAME_MAX}, + }; + + int i; + long ret; + for (i = 0; i < TEST_LIMIT_SIZE; i++) { + ret = pathconf(".", data[i].name); + EXPECT_EQ("pathconf_0100", ret, data[i].limit); + } +} + +/** + * @tc.name : pathconf_0200 + * @tc.desc : Provide exception parameters to get configuration values related to files + * @tc.level : Level 2 + */ +void pathconf_0200(void) +{ + long ret = pathconf(".", TEST_LIMIT_ERROR); + EXPECT_EQ("pathconf_0200", ret, ERREXPECT); + + ret = pathconf(NULL, PATH_MAX); + EXPECT_EQ("pathconf_0200", ret, ERREXPECT); + + ret = pathconf("not_exist", PATH_MAX); + EXPECT_EQ("pathconf_0200", ret, ERREXPECT); +} + +int main(void) +{ + pathconf_0100(); + pathconf_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/conf/sysconf.c b/libc-test/src/functionalext/supplement/conf/sysconf.c new file mode 100644 index 00000000..7f24f873 --- /dev/null +++ b/libc-test/src/functionalext/supplement/conf/sysconf.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : sysconf_0100 + * @tc.desc : The maximum number of processes running concurrently by the test user + * @tc.level : Level 0 + */ +void sysconf_0100(void) +{ + long result = sysconf(_SC_CHILD_MAX); + if (result == 0) { + t_error("%s sysconf want get result is not zero", __func__); + } +} + +/** + * @tc.name : sysconf_0200 + * @tc.desc : Get the maximum number of open files for a process + * @tc.level : Level 0 + */ +void sysconf_0200(void) +{ + long result = sysconf(_SC_OPEN_MAX); + if (result == 0) { + t_error("%s sysconf want get result is not zero", __func__); + } +} +int main(int argc, char *argv[]) +{ + sysconf_0100(); + sysconf_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/conf/test_src_functionalext_supplement_conf.gni b/libc-test/src/functionalext/supplement/conf/test_src_functionalext_supplement_conf.gni new file mode 100644 index 00000000..074569d0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/conf/test_src_functionalext_supplement_conf.gni @@ -0,0 +1,22 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_conf_test = [ + "sysconf", + "fpathconf", + "get_avphys_page", + "get_nprocs", + "get_nprocs_conf", + "get_phys_pages", + "pathconf", +] diff --git a/libc-test/src/functionalext/supplement/ctype/BUILD.gn b/libc-test/src/functionalext/supplement/ctype/BUILD.gn new file mode 100644 index 00000000..bd7c9485 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_ctype.gni") + +foreach(s, functionalext_supplement_ctype_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/ctype" + } +} + +group("functionalext_supplement_ctype_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_ctype_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/ctype/__ctype_get_mb_cur_max.c b/libc-test/src/functionalext/supplement/ctype/__ctype_get_mb_cur_max.c new file mode 100644 index 00000000..a0e1ccea --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/__ctype_get_mb_cur_max.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const ssize_t COUNT_ONE = 1; +const ssize_t COUNT_FOUR = 4; + +/** + * @tc.name : __ctype_get_mb_cur_max_0100 + * @tc.desc : Gets the maximum length of a multi-byte character (Western Language - Latin 1) + * @tc.level : Level 0 + */ +void __ctype_get_mb_cur_max_0100() +{ + setlocale(LC_ALL, ".1252"); + ssize_t result; + result = __ctype_get_mb_cur_max(); + EXPECT_TRUE("__ctype_get_mb_cur_max_0100", result > 0); +} + +/** + * @tc.name : __ctype_get_mb_cur_max_0200 + * @tc.desc : Gets the maximum length of a multi-byte character (UTF8) + * @tc.level : Level 0 + */ +void __ctype_get_mb_cur_max_0200() +{ + setlocale(LC_CTYPE, "zh_CN.utf8"); + ssize_t result; + result = __ctype_get_mb_cur_max(); + EXPECT_EQ("__ctype_get_mb_cur_max_0200", result, COUNT_FOUR); +} + +/** + * @tc.name : __ctype_get_mb_cur_max_0300 + * @tc.desc : Gets the maximum length of a multi-byte character (Chinese GBK) + * @tc.level : Level 0 + */ +void __ctype_get_mb_cur_max_0300() +{ + setlocale(LC_ALL, ".936"); + ssize_t result; + result = __ctype_get_mb_cur_max(); + EXPECT_EQ("__ctype_get_mb_cur_max_0300", result, COUNT_FOUR); +} + +TEST_FUN G_Fun_Array[] = { + __ctype_get_mb_cur_max_0100, + __ctype_get_mb_cur_max_0200, + __ctype_get_mb_cur_max_0300, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isalnum.c b/libc-test/src/functionalext/supplement/ctype/isalnum.c new file mode 100644 index 00000000..dc754656 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isalnum.c @@ -0,0 +1,81 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int COUNT = 62; +const int EOK = 0; + +/** + * @tc.name : isalnum_0100 + * @tc.desc : The parameter c is an English letter, and it is judged that the input character is a letter. + * @tc.level : Level 0 + */ +void isalnum_0100(void) +{ + int ret = isalnum('a'); + EXPECT_NE("isalnum_0100", ret, EOK); +} + +/** + * @tc.name : isalnum_0200 + * @tc.desc : The parameter c is an English number, and it is judged that the input character is a number. + * @tc.level : Level 0 + */ +void isalnum_0200(void) +{ + int ret = isalnum('1'); + EXPECT_NE("isalnum_0200", ret, EOK); +} + +/** + * @tc.name : isalnum_0300 + * @tc.desc : The parameter c is an special character, + * and it is judged that the input character is not a letter or a number. + * @tc.level : Level 2 + */ +void isalnum_0300(void) +{ + int ret = isalnum('*'); + EXPECT_EQ("isalnum_0300", ret, EOK); +} + +/** + * @tc.name : isalnum_0400 + * @tc.desc : Determine the number of letters and numbers in the ascii code table. + * @tc.level : Level 1 + */ +void isalnum_0400(void) +{ + int total = 0; + for (int i = 0; i < 128; i++) { + int ret = isalnum((char)i); + if (ret) { + total++; + } + } + EXPECT_EQ("isalnum_0400", total, COUNT); +} + +int main(void) +{ + isalnum_0100(); + isalnum_0200(); + isalnum_0300(); + isalnum_0400(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isalnum_l.c b/libc-test/src/functionalext/supplement/ctype/isalnum_l.c new file mode 100644 index 00000000..ed89a96d --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isalnum_l.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int COUNT = 62; +const int SIZE = 128; + +/** + * @tc.name : isalnum_l_0100 + * @tc.desc : Verify isalnum_l process success. The parameter c is an English letter, + * and it is judged that the input character is a letter + * @tc.level : Level 0 + */ +void isalnum_l_0100(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isalnum_l('a', m_locale); + EXPECT_NE("isalnum_l_0100", ret, 0); +} + +/** + * @tc.name : isalnum_l_0200 + * @tc.desc : Verify isalnum_l process success. The parameter c is an English number, + * and it is judged that the input character is a number + * @tc.level : Level 0 + */ +void isalnum_l_0200(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isalnum_l('1', m_locale); + EXPECT_NE("isalnum_l_0200", ret, 0); +} + +/** + * @tc.name : isalnum_l_0300 + * @tc.desc : Verify isalnum_l process success. The parameter c is an special character, + * and it is judged that the input character is not a letter or a number + * @tc.level : Level 2 + */ +void isalnum_l_0300(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isalnum_l('*', m_locale); + EXPECT_EQ("isalnum_l_0300", ret, 0); +} + +/** + * @tc.name : isalnum_l_0400 + * @tc.desc : Verify isalnum_l process success. Determine the number of letters and numbers + * in the ascii code table + * @tc.level : Level 1 + */ +void isalnum_l_0400(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int total = 0; + for (int i = 0; i < SIZE; i++) { + int ret = isalnum_l((char)i, m_locale); + if (ret) { + total++; + } + } + EXPECT_EQ("isalnum_l_0400", total, COUNT); +} + +int main(void) +{ + isalnum_l_0100(); + isalnum_l_0200(); + isalnum_l_0300(); + isalnum_l_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isalpha.c b/libc-test/src/functionalext/supplement/ctype/isalpha.c new file mode 100644 index 00000000..b01ef8a5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isalpha.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; + +/** + * @tc.name : isalpha_0100 + * @tc.desc : Verify that the entered character is a letter (parameter is 'a') + * @tc.level : Level 0 + */ +void isalpha_0100(void) +{ + int ret = isalpha('a'); + EXPECT_NE("isalpha_0100", ret, COUNT_ZERO); +} + +/** + * @tc.name : isalpha_0200 + * @tc.desc : Verify that the entered character is not a letter (parameter is 'A') + * @tc.level : Level 2 + */ +void isalpha_0200(void) +{ + int ret = isalpha('A'); + EXPECT_NE("isalpha_0200", ret, COUNT_ZERO); +} + +/** + * @tc.name : isalpha_0300 + * @tc.desc : Verify that the entered character is not a letter (parameter is '1') + * @tc.level : Level 2 + */ +void isalpha_0300(void) +{ + int ret = isspace('1'); + EXPECT_EQ("isalpha_0300", ret, COUNT_ZERO); +} + +/** + * @tc.name : isalpha_0400 + * @tc.desc : Verify that the entered character is not a letter (parameter is '【') + * @tc.level : Level 2 + */ +void isalpha_0400(void) +{ + int ret = isspace('['); + EXPECT_EQ("isalpha_0400", ret, COUNT_ZERO); +} + +/** + * @tc.name : isalpha_0500 + * @tc.desc : Verify the number of letters in the ascii code table + * @tc.level : Level 1 + */ +void isalpha_0500(void) +{ + int total = 0; + for (int i = 0; i < 128; i++) + { + int ret = isalpha((char)i); + if (ret) + { + total++; + } + } + EXPECT_EQ("isalpha_0500", total, 52); +} + +int main(void) +{ + isalpha_0100(); + isalpha_0200(); + isalpha_0300(); + isalpha_0400(); + isalpha_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isalpha_l.c b/libc-test/src/functionalext/supplement/ctype/isalpha_l.c new file mode 100644 index 00000000..76094c60 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isalpha_l.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int COUNT = 52; +const int SIZE = 128; + +/* + * @tc.name : isalpha_l_0100 + * @tc.desc : Verify isalpha_l process success. When that the entered character is a letter (parameter is 'a'). + * @tc.level : Level 0 + */ +void isalpha_l_0100(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isalpha_l('a', m_locale); + EXPECT_NE("isalpha_l_0100", ret, 0); +} + +/* + * @tc.name : isalpha_l_0200 + * @tc.desc : Verify isalpha_l process success. When the entered character is not a letter (parameter is '1'). + * @tc.level : Level 2 + */ +void isalpha_l_0200(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isalpha_l('1', m_locale); + EXPECT_EQ("isalpha_l_0200", ret, 0); +} + +/* + * @tc.name : isalpha_l_0300 + * @tc.desc : Verify isalpha_l process success. When the entered character is not a letter (parameter is '【'). + * @tc.level : Level 2 + */ +void isalpha_l_0300(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isalpha_l('[', m_locale); + EXPECT_EQ("isalpha_l_0300", ret, 0); +} + +/* + * @tc.name : isalpha_l_0400 + * @tc.desc : Verify isalpha_l process success. Verify the number of letters in the ascii code table. + * @tc.level : Level 1 + */ +void isalpha_l_0400(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int total = 0; + for (int i = 0; i < SIZE; i++) { + int ret = isalpha_l((char)i, m_locale); + if (ret) { + total++; + } + } + EXPECT_EQ("isalpha_l_0400", total, COUNT); +} + +int main(void) +{ + isalpha_l_0100(); + isalpha_l_0200(); + isalpha_l_0300(); + isalpha_l_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isascii.c b/libc-test/src/functionalext/supplement/ctype/isascii.c new file mode 100755 index 00000000..d918ac00 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isascii.c @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_DATA_COUNT 5 + +/** + * @tc.name : isascii_0100 + * @tc.desc : Test if character is ascii + * @tc.level : Level 0 + */ +void isascii_0100(void) +{ + const unsigned char ascii[TEST_DATA_COUNT] = {0x10, 0x20, 0x74, 0x34, 0x7f}; + const unsigned char not_ascii[TEST_DATA_COUNT] = {0x80, 0xef, 0xab, 0x91, 0xfe}; + int i; + for (i = 0; i < TEST_DATA_COUNT; i++) { + EXPECT_EQ("isascii_0100", isascii(ascii[i]), ONREXPECT); + } + + for (i = 0; i < TEST_DATA_COUNT; i++) { + EXPECT_EQ("isascii_0100", isascii(not_ascii[i]), CMPFLAG); + } +} + +int main(void) +{ + isascii_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isblank.c b/libc-test/src/functionalext/supplement/ctype/isblank.c new file mode 100644 index 00000000..11015ba4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isblank.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int RET = 0; +const int COUNT = 2; + +/** + * @tc.name : isblank_0100 + * @tc.desc : The parameter c is a space (' '), and the input character is judged to be a space. + * @tc.level : Level 0 + */ +void isblank_0100(void) +{ + int ret = isblank(' '); + EXPECT_NE("isblank_0100", ret, RET); +} + +/** + * @tc.name : isblank_0200 + * @tc.desc : The parameter c is a carriage return ('\t'), and the input character is judged to be a space. + * @tc.level : Level 0 + */ +void isblank_0200(void) +{ + int ret = isblank('\t'); + EXPECT_NE("isblank_0200", ret, RET); +} + +/** + * @tc.name : isblank_0300 + * @tc.desc : The parameter c is carriage return ('\r'), which determines that the input character is not a space. + * @tc.level : Level 2 + */ +void isblank_0300(void) +{ + int ret = isblank('\r'); + EXPECT_EQ("isblank_0300", ret, RET); +} + +/** + * @tc.name : isblank_0400 + * @tc.desc : The parameter c is a newline ('\n'), judging that the input character is not a space. + * @tc.level : Level 2 + */ +void isblank_0400(void) +{ + int ret = isblank('\n'); + EXPECT_EQ("isblank_0400", ret, RET); +} + +/** + * @tc.name : isblank_0500 + * @tc.desc : The parameter c is the vertical positioning character ('\v'), + * which judges that the input character is not a space. + * @tc.level : Level 2 + */ +void isblank_0500(void) +{ + int ret = isblank('\v'); + EXPECT_EQ("isblank_0500", ret, RET); +} + +/** + * @tc.name : isblank_0600 + * @tc.desc : The parameter c is page turning ('\f'), which determines that the input character is not a space. + * @tc.level : Level 2 + */ +void isblank_0600(void) +{ + int ret = isblank('\f'); + EXPECT_EQ("isblank_0600", ret, RET); +} + +/** + * @tc.name : isblank_0700 + * @tc.desc : The parameter c is an English letter, and it is judged that the input character is not a space. + * @tc.level : Level 2 + */ +void isblank_0700(void) +{ + int ret = isblank('a'); + EXPECT_EQ("isblank_0700", ret, RET); +} + +/** + * @tc.name : isblank_0800 + * @tc.desc : The parameter c is alphanumeric, and it is judged that the input character is not a space. + * @tc.level : Level 2 + */ +void isblank_0800(void) +{ + int ret = isblank('6'); + EXPECT_EQ("isblank_0800", ret, RET); +} + +/** + * @tc.name : isblank_0900 + * @tc.desc : The parameter c is a special character, and it is judged that the input character is not a space. + * @tc.level : Level 2 + */ +void isblank_0900(void) +{ + int ret = isblank('#'); + EXPECT_EQ("isblank_0900", ret, RET); +} + +/** + * @tc.name : isblank_1000 + * @tc.desc : Determine the number of space characters in the ascii code table. + * @tc.level : Level 1 + */ +void isblank_1000(void) +{ + int total = 0; + for (int i = 0; i < 128; i++) { + int ret = isblank((char)i); + if (ret) { + total++; + } + } + EXPECT_EQ("isblank_1000", total, COUNT); +} + +int main(void) +{ + isblank_0100(); + isblank_0200(); + isblank_0300(); + isblank_0400(); + isblank_0500(); + isblank_0600(); + isblank_0700(); + isblank_0800(); + isblank_0900(); + isblank_1000(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isblank_l.c b/libc-test/src/functionalext/supplement/ctype/isblank_l.c new file mode 100644 index 00000000..98fbaa6b --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isblank_l.c @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int COUNT = 2; +const int SIZE = 128; + +/** + * @tc.name : isblank_l_0100 + * @tc.desc : Verify isblank_l process success. When the parameter c is a space (' '), + * and the input character is judged to be a space. + * @tc.level : Level 0 + */ +void isblank_l_0100(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isblank_l(' ', m_locale); + EXPECT_NE("isblank_0100", ret, 0); +} + +/** + * @tc.name : isblank_l_0200 + * @tc.desc : Verify isblank_l process success. When the parameter c is a carriage return ('\t'), + * and the input character is judged to be a space. + * @tc.level : Level0 + */ +void isblank_l_0200(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isblank_l('\t', m_locale); + EXPECT_NE("isblank_0200", ret, 0); +} + +/** + * @tc.name : isblank_l_0300 + * @tc.desc : Verify isblank_l process success. When the parameter c is carriage return ('\r'), + * which determines that the input character is not a space. + * @tc.level : Level2 + */ +void isblank_l_0300(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isblank_l('\r', m_locale); + EXPECT_EQ("isblank_0300", ret, 0); +} + +/** + * @tc.name : isblank_l_0400 + * @tc.desc : Verify isblank_l process success. When the parameter c is a newline ('\n'), + * judging that the input character is not a space. + * @tc.level : Level2 + */ +void isblank_l_0400(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isblank_l('\n', m_locale); + EXPECT_EQ("isblank_l_0400", ret, 0); +} + +/** + * @tc.name : isblank_l_0500 + * @tc.desc : Verify isblank_l process success. When the parameter c is the vertical positioning character ('\v'), + * which judges that the input character is not a space. + * @tc.level : Level 2 + */ +void isblank_l_0500(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isblank_l('\v', m_locale); + EXPECT_EQ("isblank_l_0500", ret, 0); +} + +/** + * @tc.name : isblank_0600 + * @tc.desc : Verify isblank_l process success. When the parameter c is page turning ('\f'), + * which determines that the input character is not a space. + * @tc.level : Level2 + */ +void isblank_l_0600(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isblank_l('\f', m_locale); + EXPECT_EQ("isblank_l_0600", ret, 0); +} + +/** + * @tc.name : isblank_l_0700 + * @tc.desc : Verify isblank_l process success. When the parameter c is an English letter, + * and it is judged that the input character is not a space. + * @tc.level : Level2 + */ +void isblank_l_0700(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isblank_l('a', m_locale); + EXPECT_EQ("isblank_l_0700", ret, 0); +} + +/** + * @tc.name : isblank_l_0800 + * @tc.desc : Verify isblank_l process success. When the parameter c is alphanumeric, + * and it is judged that the input character is not a space. + * @tc.level : Level2 + */ +void isblank_l_0800(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isblank_l('1', m_locale); + EXPECT_EQ("isblank_0800", ret, 0); +} + +/** + * @tc.name : isblank_l_0900 + * @tc.desc : Verify isblank_l process success. When the parameter c is a special character, + * and it is judged that the input character is not a space. + * @tc.level : Level2 + */ +void isblank_l_0900(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isblank_l('#', m_locale); + EXPECT_EQ("isblank_l_0900", ret, 0); +} + +/** + * @tc.name : isblank_l_1000 + * @tc.desc : Verify isblank_l process success. Determine the number of space characters in the ascii code table. + * @tc.level : Level1 + */ +void isblank_l_1000(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int total = 0; + for (int i = 0; i < SIZE; i++) { + int ret = isblank_l((char)i, m_locale); + if (ret) { + total++; + } + } + EXPECT_EQ("isblank_l_1000", total, COUNT); +} + +int main(void) +{ + isblank_l_0100(); + isblank_l_0200(); + isblank_l_0300(); + isblank_l_0400(); + isblank_l_0500(); + isblank_l_0600(); + isblank_l_0700(); + isblank_l_0800(); + isblank_l_0900(); + isblank_l_1000(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iscntrl.c b/libc-test/src/functionalext/supplement/ctype/iscntrl.c new file mode 100644 index 00000000..1bddcf81 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iscntrl.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int RET = 0; +const int COUNT = 33; + +/** + * @tc.name : iscntrl_0100 + * @tc.desc : If the parameter c is 0, it is judged that the input character is a control character. + * @tc.level : Level 0 + */ +void iscntrl_0100(void) +{ + int ret = iscntrl(0); + EXPECT_NE("iscntrl_0100", ret, RET); +} + +/** + * @tc.name : iscntrl_0200 + * @tc.desc : The parameter c is 31, and the input character is judged to be a control character. + * @tc.level : Level 0 + */ +void iscntrl_0200(void) +{ + int ret = iscntrl(31); + EXPECT_NE("iscntrl_0200", ret, RET); +} + +/** + * @tc.name : iscntrl_0300 + * @tc.desc : The parameter c is 127, and the input character is judged to be a control character. + * @tc.level : Level 2 + */ +void iscntrl_0300(void) +{ + int ret = iscntrl(127); + EXPECT_NE("iscntrl_0300", ret, RET); +} + +/** + * @tc.name : iscntrl_0400 + * @tc.desc : The parameter c is a special character, and it is judged that the input + * character is not a control character. + * @tc.level : Level 2 + */ +void iscntrl_0400(void) +{ + int ret = iscntrl('['); + EXPECT_EQ("iscntrl_0400", ret, RET); +} + +/** + * @tc.name : iscntrl_0500 + * @tc.desc : Determine the number of control characters in the ascii code table. + * @tc.level : Level 1 + */ +void iscntrl_0500(void) +{ + int total = 0; + for (int i = 0; i < 128; i++) { + int ret = iscntrl((char)i); + if (ret) { + total++; + } + } + EXPECT_EQ("iscntrl_0500", total, COUNT); +} + +int main(void) +{ + iscntrl_0100(); + iscntrl_0200(); + iscntrl_0300(); + iscntrl_0400(); + iscntrl_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iscntrl_l.c b/libc-test/src/functionalext/supplement/ctype/iscntrl_l.c new file mode 100644 index 00000000..6c466f3f --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iscntrl_l.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "functionalext.h" + +const int COUNT = 33; +const int SIZE = 128; + +/** + * @tc.name : iscntrl_l_0100 + * @tc.desc : Verify iscntrl_l process success. When the parameter c is 0, + * it is judged that the input character is a control character. + * @tc.level : Level 0 + */ +void iscntrl_l_0100(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iscntrl_l(0, m_locale); + EXPECT_NE("iscntrl_l_0100", ret, 0); +} + +/** + * @tc.name : iscntrl_l_0200 + * @tc.desc : Verify iscntrl_l process success. When the parameter c is 31, and the input character + * is judged to be a control character. + * @tc.level : Level 0 + */ +void iscntrl_l_0200(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iscntrl_l(31, m_locale); + EXPECT_NE("iscntrl_l_0200", ret, 0); +} + +/** + * @tc.name : iscntrl_l_0300 + * @tc.desc : Verify iscntrl_l process success. When the parameter c is 127, and the input character + * is judged to be acontrol character. + * @tc.level : Level 2 + */ +void iscntrl_l_0300(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iscntrl_l(127, m_locale); + EXPECT_NE("iscntrl_l_0300", ret, 0); +} + +/** + * @tc.name : iscntrl_l_0400 + * @tc.desc : Verify iscntrl_l process success. When the parameter c is a special character, and it is judged that + * the input character is not a control character. + * @tc.level : Level 2 + */ +void iscntrl_l_0400(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iscntrl_l('[', m_locale); + EXPECT_EQ("iscntrl_l_0400", ret, 0); +} + +/** + * @tc.name : iscntrl_l_0500 + * @tc.desc : Verify iscntrl_l process success. Determine the number of control characters in ascii code table. + * @tc.level : Level 1 + */ +void iscntrl_l_0500(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int total = 0; + for (int i = 0; i < SIZE; i++) { + int ret = iscntrl_l((char)i, m_locale); + if (ret) { + total++; + } + } + EXPECT_EQ("iscntrl_l_0500", total, COUNT); +} + +int main(void) +{ + iscntrl_l_0100(); + iscntrl_l_0200(); + iscntrl_l_0300(); + iscntrl_l_0400(); + iscntrl_l_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isdigit.c b/libc-test/src/functionalext/supplement/ctype/isdigit.c new file mode 100755 index 00000000..191bd3a4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isdigit.c @@ -0,0 +1,87 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : isdigit_l_0100 + * @tc.desc : Whether the characters in a string is numeric characters + * @tc.level : Level 0 + */ +void isdigit_l_0100(void) +{ + const char *str = "0123456789"; + const char *p = str; + while (*p++ && *p != '\0') { + int ret = isdigit_l(*p, NULL); + EXPECT_EQ("isdigit_l_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : isdigit_l_0200 + * @tc.desc : Whether a character in a string is a non-numeric character + * @tc.level : Level 2 + */ +void isdigit_l_0200(void) +{ + const char *str = "!@hHiIjJZz"; + const char *p = str; + while (*p++ && *p != '\0') { + int ret = isdigit_l(*p, NULL); + EXPECT_EQ("isdigit_l_0200", ret, CMPFLAG); + } +} + +/** + * @tc.name : isdigit_0100 + * @tc.desc : Whether the characters in a string is numeric characters + * @tc.level : Level 0 + */ +void isdigit_0100(void) +{ + const char *str = "0123456789"; + const char *p = str; + while (*p++ && *p != '\0') { + int ret = isdigit(*p); + EXPECT_EQ("isdigit_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : isdigit_0200 + * @tc.desc : Whether a character in a string is a non-numeric character + * @tc.level : Level 2 + */ +void isdigit_0200(void) +{ + const char *str = "!@hHiIjJZz"; + const char *p = str; + while (*p++ && *p != '\0') { + int ret = isdigit(*p); + EXPECT_EQ("isdigit_0200", ret, CMPFLAG); + } +} + +int main(void) +{ + isdigit_l_0100(); + isdigit_l_0200(); + + isdigit_0100(); + isdigit_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isgraph.c b/libc-test/src/functionalext/supplement/ctype/isgraph.c new file mode 100755 index 00000000..108f7b80 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isgraph.c @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : isgraph_0100 + * @tc.desc : Whether the characters in a string are printable characters + * @tc.level : Level 0 + */ +void isgraph_0100(void) +{ + const char *str = "1qw@#"; + const char *p = str; + while (*p++ && *p != '\0') { + int ret = isgraph(*p); + EXPECT_EQ("isgraph_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : isgraph_0200 + * @tc.desc : Whether the characters in a string are none-printable characters + * @tc.level : Level 2 + */ +void isgraph_0200(void) +{ + const char *str = " "; + const char *p = str; + while (*p++ && *p != '\0') { + int ret = isgraph(*p); + EXPECT_EQ("isgraph_0200", ret, CMPFLAG); + } +} + +int main(void) +{ + isgraph_0100(); + isgraph_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isgraph_l.c b/libc-test/src/functionalext/supplement/ctype/isgraph_l.c new file mode 100644 index 00000000..6088f9f8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isgraph_l.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int COUNT = 94; +const int SIZE = 128; + +/* + * @tc.name : isgraph_l_0100 + * @tc.desc : Verify isgraph_l process success. When that the entered character is a letter (parameter is 'a' + * has a graphical representation). + * @tc.level : Level 0 + */ +void isgraph_l_0100(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isgraph_l('a', m_locale); + EXPECT_NE("isgraph_l_0100", ret, 0); +} + +/* + * @tc.name : isgraph_l_0200 + * @tc.desc : Verify isgraph_l process success. When that the entered character is not a letter (parameter is '!' + * has a graphical representation). + * @tc.level : Level 0 + */ +void isgraph_l_0200(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isgraph_l('!', m_locale); + EXPECT_NE("isgraph_l_0200", ret, 0); +} + +/* + * @tc.name : isgraph_l_0300 + * @tc.desc : Verify isgraph_l process success. When that the entered character is not has a graphical representation. + * @tc.level : Level 2 + */ +void isgraph_l_0300(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isgraph_l(' ', m_locale); + EXPECT_EQ("isgraph_l_0300", ret, 0); +} + +/** + * @tc.name : isgraph_l_0400 + * @tc.desc : Verify isgraph_l process success. Determine the number of control characters in the ascii code table. + * @tc.level : Level 1 + */ +void isgraph_l_0400(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int total = 0; + for (int i = 0; i < SIZE; i++) { + int ret = isgraph_l((char)i, m_locale); + if (ret) { + total++; + } + } + EXPECT_EQ("isgraph_l_0400", total, COUNT); +} + +int main(void) +{ + isgraph_l_0100(); + isgraph_l_0200(); + isgraph_l_0300(); + isgraph_l_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/islower.c b/libc-test/src/functionalext/supplement/ctype/islower.c new file mode 100644 index 00000000..3d56d137 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/islower.c @@ -0,0 +1,123 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int COUNT = 26; +const int EOK = 0; + +/** + * @tc.name : islower_0100 + * @tc.desc : The parameter c is a lowercase letter,which determines the case of the input character. + * @tc.level : Level 0 + */ +void islower_0100(void) +{ + int ret = islower('a'); + EXPECT_NE("islower_0100", ret, EOK); +} + +/** + * @tc.name : islower_0200 + * @tc.desc : The parameter c is a uppercase letter,which determines the case of the input character. + * @tc.level : Level 2 + */ +void islower_0200(void) +{ + int ret = islower('A'); + EXPECT_EQ("islower_0200", ret, EOK); +} + +/** + * @tc.name : islower_0300 + * @tc.desc : The parameter c is a number,which determines the case of the input character. + * @tc.level : Level 2 + */ +void islower_0300(void) +{ + int ret = islower('1'); + EXPECT_EQ("islower_0300", ret, EOK); +} + +/** + * @tc.name : islower_0400 + * @tc.desc : The parameter c is a special character,which determines the case of the input character. + * @tc.level : Level 2 + */ +void islower_0400(void) +{ + int ret = islower('['); + EXPECT_EQ("islower_0400", ret, EOK); +} + +/** + * @tc.name : islower_0500 + * @tc.desc : Determine the number of lowercase letters in the ascii code table. + * @tc.level : Level 1 + */ +void islower_0500(void) +{ + int total = 0; + for (int i = 0; i < 128; i++) { + int ret = islower((char)i); + if (ret) { + total++; + } + } + EXPECT_EQ("islower_0500", total, COUNT); +} + +/** + * @tc.name : islower_l_0100 + * @tc.desc : Whether the characters in a string is lower characters + * @tc.level : Level 0 + */ +void islower_l_0100(void) +{ + const char *str = "abcdegfhijklmnopqrstuvwxyz"; + const char *p = str; + while (*p++ && *p != '\0') { + int ret = islower_l(*p, NULL); + EXPECT_EQ("islower_l_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : islower_l_0200 + * @tc.desc : Whether a character in a string is a non-lower character + * @tc.level : Level 2 + */ +void islower_l_0200(void) +{ + const char *str = "23!@ABCHIJZ"; + const char *p = str; + while (*p++ && *p != '\0') { + int ret = islower_l(*p, NULL); + EXPECT_EQ("islower_l_0200", ret, CMPFLAG); + } +} + +int main(void) +{ + islower_0100(); + islower_0200(); + islower_0300(); + islower_0400(); + islower_0500(); + islower_l_0100(); + islower_l_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isprint.c b/libc-test/src/functionalext/supplement/ctype/isprint.c new file mode 100644 index 00000000..84a68cb9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isprint.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int RET = 0; +const int COUNT = 95; + +/** + * @tc.name : isprint_0100 + * @tc.desc : The parameter c is 32, and the input character is judged to be a printable character. + * @tc.level : Level 0 + */ +void isprint_0100(void) +{ + int ret = isprint(32); + EXPECT_NE("isprint_0100", ret, RET); +} + +/** + * @tc.name : isprint_0200 + * @tc.desc : The parameter c is 63, and the input character is judged to be a printable character. + * @tc.level : Level 0 + */ +void isprint_0200(void) +{ + int ret = isprint(63); + EXPECT_NE("isprint_0200", ret, RET); +} + +/** + * @tc.name : isprint_0300 + * @tc.desc : The parameter c is 126, and the input character is judged to be a printable character. + * @tc.level : Level 2 + */ +void isprint_0300(void) +{ + int ret = isprint(126); + EXPECT_NE("isprint_0300", ret, RET); +} + +/** + * @tc.name : isprint_0400 + * @tc.desc : The parameter c is the control character 20, which judges that the input character + * is not a printable character. + * @tc.level : Level 2 + */ +void isprint_0400(void) +{ + int ret = isprint(20); + EXPECT_EQ("isprint_0400", ret, RET); +} + +/** + * @tc.name : isprint_0500 + * @tc.desc : Determine the number of printable characters in the ascii code table. + * @tc.level : Level 1 + */ +void isprint_0500(void) +{ + int total = 0; + for (int i = 0; i < 128; i++) { + int ret = isprint((char)i); + if (ret) { + total++; + } + } + EXPECT_EQ("isprint_0500", total, COUNT); +} + +int main(void) +{ + isprint_0100(); + isprint_0200(); + isprint_0300(); + isprint_0400(); + isprint_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isprint_l.c b/libc-test/src/functionalext/supplement/ctype/isprint_l.c new file mode 100644 index 00000000..b326f7a6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isprint_l.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int COUNT = 95; +const int SIZE = 128; + +/** + * @tc.name : isprint_l_0100 + * @tc.desc : Verify isprint_l process success. When the parameter c is 32, and the input character is judged + * to be a printable character. + * @tc.level : Level 0 + */ +void isprint_l_0100(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isprint_l(32, m_locale); + EXPECT_NE("isprint_l_0100", ret, 0); +} + +/** + * @tc.name : isprint_l_0200 + * @tc.desc : Verify isprint_l process success. Whent the parameter c is 63, and the input character is judged + * to be a printable character. + * @tc.level : Level 0 + */ +void isprint_l_0200(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isprint_l(63, m_locale); + EXPECT_NE("isprint_l_0200", ret, 0); +} + +/** + * @tc.name : isprint_l_0300 + * @tc.desc : Verify isprint_l process success. Whent the parameter c is 126, and the input character is judged + * to be a printable character. + * @tc.level : Level 2 + */ +void isprint_l_0300(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isprint_l(126, m_locale); + EXPECT_NE("isprint_l_0300", ret, 0); +} + +/** + * @tc.name : isprint_l_0400 + * @tc.desc : Verify isprint_l process success. Whent the parameter c is the control character 20, which judges + * that the input character is not a printable character. + * @tc.level : Level 2 + */ +void isprint_l_0400(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isprint_l(20, m_locale); + EXPECT_EQ("isprint_l_0400", ret, 0); +} + +/** + * @tc.name : isprint_l_0500 + * @tc.desc : Verify isprint_l process success. Determine the number of printable characters in the ascii code + * table. + * @tc.level : Level 1 + */ +void isprint_l_0500(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int total = 0; + for (int i = 0; i < SIZE; i++) { + int ret = isprint_l((char)i, m_locale); + if (ret) { + total++; + } + } + EXPECT_EQ("isprint_l_0500", total, COUNT); +} + +int main(void) +{ + isprint_l_0100(); + isprint_l_0200(); + isprint_l_0300(); + isprint_l_0400(); + isprint_l_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/ispunct.c b/libc-test/src/functionalext/supplement/ctype/ispunct.c new file mode 100644 index 00000000..4e499d23 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/ispunct.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : ispunct_0100 + * @tc.desc : Determine whether the input character is a punctuation mark or a special symbol. + * @tc.level : Level 0 + */ +void ispunct_0100(void) +{ + int var1 = 44; + int ret = ispunct(var1); + EXPECT_NE("ispunct_0100", ret, 0); +} + +/** + * @tc.name : ispunct_0200 + * @tc.desc : Determine whether the input character is a punctuation mark or a special symbol. + * @tc.level : Level 0 + */ +void ispunct_0200(void) +{ + int var1 = 64; + int ret = ispunct(var1); + EXPECT_NE("ispunct_0200", ret, 0); +} + +/** + * @tc.name : ispunct_0300 + * @tc.desc : Determine whether the input character is a punctuation mark or a special symbol. + * @tc.level : Level 0 + */ +void ispunct_0300(void) +{ + int var1 = 94; + int ret = ispunct(var1); + EXPECT_NE("ispunct_0300", ret, 0); +} + +/** + * @tc.name : ispunct_0400 + * @tc.desc : Determine if the input character is not a punctuation mark or a special symbol. + * @tc.level : Level 2 + */ +void ispunct_0400(void) +{ + int var1 = 65; + int ret = ispunct(var1); + EXPECT_EQ("ispunct_0400", ret, 0); +} + +/** + * @tc.name : ispunct_0500 + * @tc.desc : Determine the number of punctuation marks or special symbols in the ascii code table. + * @tc.level : Level 1 + */ +void ispunct_0500(void) +{ + int cout = 0; + for (int i = 0; i < 128; i++) { + if (ispunct(i)) { + cout++; + } + } + EXPECT_EQ("ispunct_0500", cout, 32); +} + +int main(void) +{ + ispunct_0100(); + ispunct_0200(); + ispunct_0300(); + ispunct_0400(); + ispunct_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/ispunct_l.c b/libc-test/src/functionalext/supplement/ctype/ispunct_l.c new file mode 100644 index 00000000..ea26e25d --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/ispunct_l.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int SIZE = 128; +const int RESULT_SIZE = 32; + +/* + * @tc.name : ispunct_l_0100 + * @tc.desc : Verify ispunct_l process success. When the input character is a punctuation mark or a special symbol. + * @tc.level : Level 0 + */ +void ispunct_l_0100(void) +{ + int var1 = 44; + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = ispunct_l(var1, m_locale); + EXPECT_NE("ispunct_l_0100", ret, 0); +} + +/* + * @tc.name : ispunct_l_0200 + * @tc.desc : Verify ispunct_l process success. When the input character is a punctuation mark or a special symbol. + * @tc.level : Level 0 + */ +void ispunct_l_0200(void) +{ + int var1 = 64; + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = ispunct_l(var1, m_locale); + EXPECT_NE("ispunct_l_0200", ret, 0); +} + +/* + * @tc.name : ispunct_l_0300 + * @tc.desc : Verify ispunct_l process success. When the input character is a punctuation mark or a special symbol. + * @tc.level : Level 0 + */ +void ispunct_l_0300(void) +{ + int var1 = 94; + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = ispunct_l(var1, m_locale); + EXPECT_NE("ispunct_l_0300", ret, 0); +} + +/* + * @tc.name : ispunct_l_0400 + * @tc.desc : Verify ispunct_l process success. When input character is not a punctuation mark or a special symbol. + * @tc.level : Level 2 + */ +void ispunct_l_0400(void) +{ + int var1 = 65; + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = ispunct_l(var1, m_locale); + EXPECT_EQ("ispunct_l_0400", ret, 0); +} + +/* + * @tc.name : ispunct_l_0500 + * @tc.desc : Verify ispunct_l process success. When the number of punctuation marks or special symbols + * in the ascii code table. + * @tc.level : Level 1 + */ +void ispunct_l_0500(void) +{ + int cout = 0; + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + for (int i = 0; i < SIZE; i++) { + if (ispunct_l(i, m_locale)) { + cout++; + } + } + EXPECT_EQ("ispunct_l_0500", cout, RESULT_SIZE); +} + +int main(void) +{ + ispunct_l_0100(); + ispunct_l_0200(); + ispunct_l_0300(); + ispunct_l_0400(); + ispunct_l_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isspace.c b/libc-test/src/functionalext/supplement/ctype/isspace.c new file mode 100644 index 00000000..4e6e3ff4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isspace.c @@ -0,0 +1,143 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUJNT_ZERO = 0; +const int32_t COUJNT_SIX = 6; + +/* + * @tc.name : isspace_0100 + * @tc.desc : Verify that the input character is a space (the parameter is a space) + * @tc.level : Level 0 + */ +void isspace_0100(void) +{ + int ret = isspace(' '); + EXPECT_NE("isspace_0100", ret, COUJNT_ZERO); +} + +/* + * @tc.name : isspace_0200 + * @tc.desc : Verify that the input character is a space (parameter is \r) + * @tc.level : Level 1 + */ +void isspace_0200(void) +{ + int ret = isspace('\r'); + EXPECT_NE("isspace_0200", ret, COUJNT_ZERO); +} + +/* + * @tc.name : isspace_0300 + * @tc.desc : Verify that the input character is a space (parameter is \n) + * @tc.level : Level 1 + */ +void isspace_0300(void) +{ + int ret = isspace('\n'); + EXPECT_NE("isspace_0300", ret, COUJNT_ZERO); +} + +/* + * @tc.name : isspace_0400 + * @tc.desc : EVerify that the input character is a space (parameter is \v) + * @tc.level : Level 1 + */ +void isspace_0400(void) +{ + int ret = isspace('\v'); + EXPECT_NE("isspace_0400", ret, COUJNT_ZERO); +} + +/* + * @tc.name : isspace_0500 + * @tc.desc : Verify that the input character is a space (parameter is \f) + * @tc.level : Level 1 + */ +void isspace_0500(void) +{ + int ret = isspace('\f'); + EXPECT_NE("isspace_0500", ret, COUJNT_ZERO); +} + +/* + * @tc.name : isspace_0600 + * @tc.desc : Verify that the input character is not a space (parameter is 'a') + * @tc.level : Level 2 + */ +void isspace_0600(void) +{ + int ret = isspace('a'); + EXPECT_EQ("isspace_0600", ret, COUJNT_ZERO); +} + +/* + * @tc.name : isspace_0700 + * @tc.desc : Verify that the input character is not a space (parameter is '6') + * @tc.level : Level 2 + */ +void isspace_0700(void) +{ + int ret = isspace('6'); + EXPECT_EQ("isspace_0700", ret, COUJNT_ZERO); +} + +/* + * @tc.name : isspace_0800 + * @tc.desc : Verify that the input character is not a space (parameter is '#') + * @tc.level : Level 2 + */ +void isspace_0800(void) +{ + int ret = isspace('#'); + EXPECT_EQ("isspace_0800", ret, COUJNT_ZERO); +} + +/* + * @tc.name : isspace_0900 + * @tc.desc : Verify the number of characters in the ascii code table + * @tc.level : Level 1 + */ +void isspace_0900(void) +{ + int total = 0; + for (int i = 0; i < 128; i++) { + int ret = isspace((char)i); + if (ret) { + total++; + } + } + EXPECT_EQ("isspace_0900", total, COUJNT_SIX); +} + +int main(void) +{ + isspace_0100(); + isspace_0200(); + isspace_0300(); + isspace_0400(); + isspace_0500(); + isspace_0600(); + isspace_0700(); + isspace_0800(); + isspace_0900(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isspace_l.c b/libc-test/src/functionalext/supplement/ctype/isspace_l.c new file mode 100644 index 00000000..7d23e464 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isspace_l.c @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int SIZE = 128; +const int RETSIZE = 6; + +/* + * @tc.name : isspace_l_0100 + * @tc.desc : Verify isprint_l process success. When the input character is a space (the parameter is a space) + * @tc.level : Level 0 + */ +void isspace_l_0100(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isspace_l(' ', m_locale); + EXPECT_NE("isspace_l_0100", ret, 0); +} + +/* + * @tc.name : isspace_l_0200 + * @tc.desc : Verify isprint_l process success. When the input character is a space (parameter is \r) + * @tc.level : Level 1 + */ +void isspace_l_0200(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isspace_l('\r', m_locale); + EXPECT_NE("isspace_l_0200", ret, 0); +} + +/* + * @tc.name : isspace_l_0300 + * @tc.desc : Verify isprint_l process success. When the input character is a space (parameter is \n) + * @tc.level : Level 1 + */ +void isspace_l_0300(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isspace_l('\n', m_locale); + EXPECT_NE("isspace_l_0300", ret, 0); +} + +/* + * @tc.name : isspace_l_0400 + * @tc.desc : Verify isprint_l process success. When the input character is a space (parameter is \v) + * @tc.level : Level 1 + */ +void isspace_l_0400(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isspace_l('\v', m_locale); + EXPECT_NE("isspace_l_0400", ret, 0); +} + +/* + * @tc.name : isspace_l_0500 + * @tc.desc : Verify isprint_l process success. When the input character is a space (parameter is \f) + * @tc.level : Level 1 + */ +void isspace_l_0500(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isspace_l('\f', m_locale); + EXPECT_NE("isspace_l_0500", ret, 0); +} + +/* + * @tc.name : isspace_l_0600 + * @tc.desc : Verify isprint_l process success. When the input character is not a space (parameter is 'a') + * @tc.level : Level 2 + */ +void isspace_l_0600(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isspace_l('a', m_locale); + EXPECT_EQ("isspace_l_0600", ret, 0); +} + +/* + * @tc.name : isspace_l_0700 + * @tc.desc : Verify isprint_l process success. When the input character is not a space (parameter is '6') + * @tc.level : Level 2 + */ +void isspace_l_0700(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isspace_l('6', m_locale); + EXPECT_EQ("isspace_l_0700", ret, 0); +} + +/* + * @tc.name : isspace_l_0800 + * @tc.desc : Verify isprint_l process success. When the input character is not a space (parameter is '#') + * @tc.level : Level 2 + */ +void isspace_l_0800(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = isspace_l('#', m_locale); + EXPECT_EQ("isspace_l_0800", ret, 0); +} + +/* + * @tc.name : isspace_l_0900 + * @tc.desc : Verify isprint_l process success. Verify the number of characters in the ascii code table. + * @tc.level : Level 1 + */ +void isspace_l_0900() +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int total = 0; + for (int i = 0; i < SIZE; i++) { + int ret = isspace_l((char)i, m_locale); + if (ret) { + total++; + } + } + EXPECT_EQ("isspace_l_0900", total, RETSIZE); +} + +int main(void) +{ + isspace_l_0100(); + isspace_l_0200(); + isspace_l_0300(); + isspace_l_0400(); + isspace_l_0500(); + isspace_l_0600(); + isspace_l_0700(); + isspace_l_0800(); + isspace_l_0900(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isupper.c b/libc-test/src/functionalext/supplement/ctype/isupper.c new file mode 100644 index 00000000..a5ad232f --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isupper.c @@ -0,0 +1,123 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int COUNT = 26; +const int EOK = 0; + +/** + * @tc.name : isupper_0100 + * @tc.desc : The parameter c is a uppercase letter,which determines the case of the input character. + * @tc.level : Level 0 + */ +void isupper_0100(void) +{ + int ret = isupper('A'); + EXPECT_NE("isupper_0100", ret, EOK); +} + +/** + * @tc.name : isupper_0200 + * @tc.desc : The parameter c is a lowercase letter,which determines the case of the input character. + * @tc.level : Level 2 + */ +void isupper_0200(void) +{ + int ret = isupper('a'); + EXPECT_EQ("isupper_0200", ret, EOK); +} + +/** + * @tc.name : isupper_0300 + * @tc.desc : The parameter c is a number,which determines the case of the input character. + * @tc.level : Level 2 + */ +void isupper_0300(void) +{ + int ret = isupper('1'); + EXPECT_EQ("isupper_0300", ret, EOK); +} + +/** + * @tc.name : isupper_0400 + * @tc.desc : The parameter c is a special character,which determines the case of the input character. + * @tc.level : Level 2 + */ +void isupper_0400(void) +{ + int ret = isupper('['); + EXPECT_EQ("isupper_0400", ret, EOK); +} + +/** + * @tc.name : isupper_0500 + * @tc.desc : Determine the number of uppercase letters in the ascii code table. + * @tc.level : Level 1 + */ +void isupper_0500(void) +{ + int total = 0; + for (int i = 0; i < 128; i++) { + int ret = isupper((char)i); + if (ret) { + total++; + } + } + EXPECT_EQ("isupper_0500", total, COUNT); +} + +/** + * @tc.name : isupper_l_0100 + * @tc.desc : Whether the characters in a string is upper characters + * @tc.level : Level 0 + */ +void isupper_l_0100(void) +{ + const char *str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + const char *p = str; + while (*p++ && *p != '\0') { + int ret = isupper_l(*p, NULL); + EXPECT_EQ("isupper_l_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : isupper_l_0200 + * @tc.desc : Whether a character in a string is a non-upper character + * @tc.level : Level 2 + */ +void isupper_l_0200(void) +{ + const char *str = "23!@abcdefg"; + const char *p = str; + while (*p++ && *p != '\0') { + int ret = isupper_l(*p, NULL); + EXPECT_EQ("isupper_l_0200", ret, CMPFLAG); + } +} + +int main(void) +{ + isupper_0100(); + isupper_0200(); + isupper_0300(); + isupper_0400(); + isupper_0500(); + isupper_l_0100(); + isupper_l_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iswalhpa.c b/libc-test/src/functionalext/supplement/ctype/iswalhpa.c new file mode 100644 index 00000000..6e90de62 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iswalhpa.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : iswalhpa_0100 + * @tc.desc : Determine if the input wide character is a letter. + * @tc.level : Level 0 + */ +void iswalhpa_0100() +{ + setlocale(LC_CTYPE, "UTF-8"); + wchar_t str[] = L"a"; + int ret; + int i = 0; + while (str[i]) { + ret = iswalpha(str[i]); + if (!ret) { + wprintf(L"'%lc' is not\n", str[i]); + } + i++; + } + EXPECT_NE("iswalhpa_0100", ret, 0); +} + +/** + * @tc.name : iswalhpa_0200 + * @tc.desc : Determine if the input wide character is a letter. + * @tc.level : Level 0 + */ +void iswalhpa_0200() +{ + setlocale(LC_CTYPE, "UTF-8"); + wchar_t str[] = L"A"; + int ret; + int i = 0; + while (str[i]) { + ret = iswalpha(str[i]); + if (!ret) { + wprintf(L"'%lc' is not\n", str[i]); + } + i++; + } + EXPECT_NE("iswalhpa_0200", ret, 0); +} + +/** + * @tc.name : iswalhpa_0300 + * @tc.desc : Determine if the input wide character is not a letter. + * @tc.level : Level 2 + */ +void iswalhpa_0300() +{ + setlocale(LC_CTYPE, "UTF-8"); + wchar_t str[] = L"1"; + int ret; + int i = 0; + while (str[i]) { + ret = iswalpha(str[i]); + if (ret) { + wprintf(L"'%lc' is alphabetic\n", str[i]); + } + i++; + } + EXPECT_EQ("iswalhpa_0300", ret, 0); +} + +/** + * @tc.name : iswalhpa_0400 + * @tc.desc : Determine if the input wide character is not a letter. + * @tc.level : Level 2 + */ +void iswalhpa_0400() +{ + setlocale(LC_CTYPE, "UTF-8"); + wchar_t str[] = L"【"; + int ret; + int i = 0; + while (str[i]) { + ret = iswalpha(str[i]); + if (ret) { + wprintf(L"'%lc' is alphabetic\n", str[i]); + } + i++; + } + EXPECT_EQ("iswalhpa_0400", ret, 0); +} + +int main() +{ + iswalhpa_0100(); + iswalhpa_0200(); + iswalhpa_0300(); + iswalhpa_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iswalnum.c b/libc-test/src/functionalext/supplement/ctype/iswalnum.c new file mode 100755 index 00000000..dd48e1ce --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iswalnum.c @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : iswalnum_0100 + * @tc.desc : Tests whether the characters in the given string are numbers or letters + * @tc.level : Level 0 + */ +void iswalnum_0100(void) +{ + const wchar_t *str = L"aAÇçΔδ2"; + int ret = 0; + while (*str) { + ret = iswalnum(*str); + EXPECT_EQ("iswalnum_0100", ret, ONREXPECT); + str++; + } +} + +/** + * @tc.name : iswalnum_0200 + * @tc.desc : Tests that the characters in the given string are not numbers or letters + * @tc.level : Level 2 + */ +void iswalnum_0200(void) +{ + const wchar_t *str = L"@#$*&!"; + int ret = 0; + while (*str) { + ret = iswalnum(*str); + EXPECT_EQ("iswalnum_0200", ret, CMPFLAG); + str++; + } +} + +int main(void) +{ + iswalnum_0100(); + iswalnum_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iswalpha.c b/libc-test/src/functionalext/supplement/ctype/iswalpha.c new file mode 100755 index 00000000..9e35146f --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iswalpha.c @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : iswalpha_l_0100 + * @tc.desc : Whether the characters in a wide string are letters + * @tc.level : Level 0 + */ +void iswalpha_l_0100(void) +{ + const wchar_t *str = L"aBcrWER"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswalpha_l(*p, NULL); + EXPECT_EQ("iswalpha_l_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : iswalpha_l_0200 + * @tc.desc : Whether a character in a wide string is not a letter + * @tc.level : Level 2 + */ +void iswalpha_l_0200(void) +{ + const wchar_t *str = L"2!~*"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswalpha_l(*p, NULL); + EXPECT_EQ("iswalpha_l_0200", ret, CMPFLAG); + } +} + +int main(void) +{ + iswalpha_l_0100(); + iswalpha_l_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iswblank.c b/libc-test/src/functionalext/supplement/ctype/iswblank.c new file mode 100755 index 00000000..063e0bb9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iswblank.c @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : iswblank_l_0100 + * @tc.desc : Whether a character in a wide string is a blank character + * @tc.level : Level 0 + */ +void iswblank_l_0100(void) +{ + const wchar_t *str = L" \t"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswblank_l(*p, NULL); + EXPECT_EQ("iswblank_l_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : iswblank_l_0200 + * @tc.desc : Whether the characters in a wide string is blank characters + * @tc.level : Level 2 + */ +void iswblank_l_0200(void) +{ + const wchar_t *str = L"2!~*3Ad"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswblank_l(*p, NULL); + EXPECT_EQ("iswblank_l_0200", ret, CMPFLAG); + } +} + +/** + * @tc.name : iswblank_0100 + * @tc.desc : Whether a character in a wide string is a blank character + * @tc.level : Level 0 + */ +void iswblank_0100(void) +{ + const wchar_t *str = L" \t"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswblank(*p); + EXPECT_EQ("iswblank_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : iswblank_0200 + * @tc.desc : Whether the characters in a wide string is blank characters + * @tc.level : Level 2 + */ +void iswblank_0200(void) +{ + const wchar_t *str = L"2!~*3Ad"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswblank(*p); + EXPECT_EQ("iswblank_0200", ret, CMPFLAG); + } +} + +int main(void) +{ + iswblank_l_0100(); + iswblank_l_0200(); + + iswblank_0100(); + iswblank_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iswcntrl.c b/libc-test/src/functionalext/supplement/ctype/iswcntrl.c new file mode 100644 index 00000000..942e3b74 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iswcntrl.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" +#include "test.h" + +void iswcntrl_test(wchar_t ch, int want, char *func_name) +{ + int result = iswcntrl(ch); + if (result != want) { + t_error("%s iswcntrl get result is %d are not %d\n", func_name, result, want); + } +} + +/** + * @tc.name : iswcntrl_l_0100 + * @tc.desc : Whether a character in a wide string is a control character + * @tc.level : Level 0 + */ +void iswcntrl_l_0100(void) +{ + const wchar_t *str = L"\b"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswcntrl_l(*p, NULL); + EXPECT_EQ("iswcntrl_l_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : iswcntrl_l_0200 + * @tc.desc : Whether a character in a wide string is a non-control character + * @tc.level : Level 2 + */ +void iswcntrl_l_0200(void) +{ + const wchar_t *str = L"2!~*3Ad"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswcntrl_l(*p, NULL); + EXPECT_EQ("iswcntrl_l_0200", ret, CMPFLAG); + } +} + +int main(int argc, char *argv[]) +{ + char *ret = setlocale(LC_ALL, "en_US.utf8"); + if (!ret) { + printf("\n"); + } + /** + * @tc.name : iswcntrl_0100 + * @tc.desc : Test if a wide character is a control character + * @tc.level : Level 0 + */ + iswcntrl_test(L'\n', 1, "iswcntrl_0100"); + /** + * @tc.name : iswcntrl_0200 + * @tc.desc : Test whether the wide character is a control character, the incoming character is A + * @tc.level : Level 1 + */ + iswcntrl_test(L'A', 0, "iswcntrl_0200"); + /** + * @tc.name : iswcntrl_0300 + * @tc.desc : Test whether the wide character is a control character, the incoming character is \u2028 + * @tc.level : Level 1 + */ + iswcntrl_test(L'\u2028', 1, "iswcntrl_0300"); + /** + * @tc.name : iswcntrl_0400 + * @tc.desc : Test whether the wide character is a control character, the incoming character is \ufff9 + * @tc.level : Level 1 + */ + iswcntrl_test(L'\ufff9', 1, "iswcntrl_0400"); + + iswcntrl_l_0100(); + iswcntrl_l_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iswctype.c b/libc-test/src/functionalext/supplement/ctype/iswctype.c new file mode 100644 index 00000000..ea356fb8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iswctype.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +void iswctype_test(wchar_t ch, wctype_t wt, char *func_name, int want) +{ + int result = iswctype(ch, wt); + if (result != want) { + t_error("%s iswctype get result is %d are not want %d", func_name, result, want); + } +} + +int main(int argc, char *argv[]) +{ + wctype_t wt = wctype("alnum"); + /** + * @tc.name : iswctype_0100 + * @tc.desc : Use the iswctype function to determine whether the incoming wide character matches the incoming + * type + * @tc.level : Level 0 + */ + iswctype_test(L'1', wt, "iswctype_0100", 1); + wt = wctype("alpha"); + /** + * @tc.name : iswdigit_0200 + * @tc.desc : Determine letter type wide characters + * @tc.level : Level 1 + */ + iswctype_test(L'a', wt, "iswctype_0200", 1); + wt = wctype("blank"); + /** + * @tc.name : iswctype_0300 + * @tc.desc : Determine whitespace type wide character + * @tc.level : Level 1 + */ + iswctype_test(L' ', wt, "iswctype_0300", 1); + wt = wctype("cntrl"); + /** + * @tc.name : iswctype_0400 + * @tc.desc : Determine the control type wide character + * @tc.level : Level 1 + */ + iswctype_test(L'\n', wt, "iswctype_0400", 1); + wt = wctype("digit"); + /** + * @tc.name : iswctype_0500 + * @tc.desc : Determine decimal type wide characters + * @tc.level : Level 1 + */ + iswctype_test(L'9', wt, "iswctype_0500", 1); + wt = wctype("lower"); + /** + * @tc.name : iswctype_0600 + * @tc.desc : Determining lowercase type wide characters + * @tc.level : Level 1 + */ + iswctype_test(L'a', wt, "iswctype_0600", 1); + wt = wctype("print"); + /** + * @tc.name : iswctype_0700 + * @tc.desc : Determine the printable type wide character + * @tc.level : Level 1 + */ + iswctype_test(L'u', wt, "iswctype_0700", 1); + wt = wctype("punct"); + /** + * @tc.name : iswctype_0800 + * @tc.desc : Determine the punctuation type wide character + * @tc.level : Level 1 + */ + iswctype_test(L',', wt, "iswctype_0800", 1); + wt = wctype("upper"); + /** + * @tc.name : iswctype_0900 + * @tc.desc : Determine uppercase type wide characters + * @tc.level : Level 1 + */ + iswctype_test(L'G', wt, "iswctype_0900", 1); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iswdigit.c b/libc-test/src/functionalext/supplement/ctype/iswdigit.c new file mode 100644 index 00000000..e8f83904 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iswdigit.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "functionalext.h" +#include "test.h" + +/** + * @tc.name : iswdigit_0100 + * @tc.desc : Use the iswdigit function to determine whether the incoming wide character is a decimal number + * @tc.level : Level 0 + */ +void iswdigit_0100(void) +{ + wchar_t ch = L'9'; + int result = iswdigit(ch); + if (result == 0) { + t_error("%s iswdigit get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswdigit_0200 + * @tc.desc : Test iswdigit when a non-decimal digit is passed in + * @tc.level : Level 1 + */ +void iswdigit_0200(void) +{ + wchar_t ch = L'A'; + int result = iswdigit(ch); + if (result != 0) { + t_error("%s iswdigit get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswdigit_l_0100 + * @tc.desc : Whether a character in a wide string is a number character + * @tc.level : Level 0 + */ +void iswdigit_l_0100(void) +{ + const wchar_t *str = L"1234567890"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswdigit_l(*p, NULL); + EXPECT_EQ("iswdigit_l_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : iswdigit_l_0200 + * @tc.desc : Whether a character in a wide string is a non-number character + * @tc.level : Level 2 + */ +void iswdigit_l_0200(void) +{ + const wchar_t *str = L"ewqWRE!~*Ad"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswdigit_l(*p, NULL); + EXPECT_EQ("iswdigit_l_0200", ret, CMPFLAG); + } +} + +int main(int argc, char *argv[]) +{ + iswdigit_0100(); + iswdigit_0200(); + iswdigit_l_0100(); + iswdigit_l_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iswlower.c b/libc-test/src/functionalext/supplement/ctype/iswlower.c new file mode 100644 index 00000000..ecab3a6a --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iswlower.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "functionalext.h" +#include "test.h" + +/** + * @tc.name : iswlower_0100 + * @tc.desc : Use the iswlower method to determine whether the incoming wide character is a lowercase letter + * @tc.level : Level 0 + */ +void iswlower_0100(void) +{ + wchar_t ch = L'a'; + int result = iswlower(ch); + if (result == 0) { + t_error("%s iswlower get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswlower_0200 + * @tc.desc : Test the return value of iswlower when uppercase letters are passed in + * @tc.level : Level 1 + */ +void iswlower_0200(void) +{ + wchar_t ch = L'A'; + int result = iswlower(ch); + if (result != 0) { + t_error("%s iswlower get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswlower_0300 + * @tc.desc : Test the return value of iswlower when passing in a number + * @tc.level : Level 1 + */ +void iswlower_0300(void) +{ + wchar_t ch = L'1'; + int result = iswlower(ch); + if (result != 0) { + t_error("%s iswlower get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswlower_l_0100 + * @tc.desc : Whether the characters in a wide string is lower character + * @tc.level : Level 0 + */ +void iswlower_l_0100(void) +{ + const wchar_t *str = L"abcdefghijklmnopqrstuvwxyz"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswlower_l(*p, NULL); + EXPECT_EQ("iswlower_l_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : iswlower_l_0200 + * @tc.desc : Whether the characters in a wide string are non-lower character + * @tc.level : Level 2 + */ +void iswlower_l_0200(void) +{ + const wchar_t *str = L"12ABC!@#"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswlower_l(*p, NULL); + EXPECT_EQ("iswlower_l_0200", ret, CMPFLAG); + } +} + +int main(int argc, char *argv[]) +{ + iswlower_0100(); + iswlower_0200(); + iswlower_0300(); + iswlower_l_0100(); + iswlower_l_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iswprint.c b/libc-test/src/functionalext/supplement/ctype/iswprint.c new file mode 100644 index 00000000..8c62f255 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iswprint.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "functionalext.h" +#include "test.h" + +/** + * @tc.name : iswprint_0100 + * @tc.desc : Determine whether the incoming wide character can be printed by the iswprint method + * @tc.level : Level 1 + */ +void iswprint_0100(void) +{ + wchar_t ch = L'9'; + int result = iswprint(ch); + if (result == 0) { + t_error("%s iswprint get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswprint_0200 + * @tc.desc : Test the iswprint method by passing in a non-printable wide character + * @tc.level : Level 1 + */ +void iswprint_0200(void) +{ + wchar_t ch = L'\n'; + int result = iswprint(ch); + if (result != 0) { + t_error("%s iswprint get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswprint_l_0100 + * @tc.desc : Whether the characters in a wide string are printable characters + * @tc.level : Level 0 + */ +void iswprint_l_0100(void) +{ + const wchar_t *str = L"1Aa®Â Æ"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswprint_l(*p, NULL); + EXPECT_EQ("iswprint_l_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : iswprint_l_0200 + * @tc.desc : Whether the characters in a wide string are non-printable characters + * @tc.level : Level 2 + */ +void iswprint_l_0200(void) +{ + const wchar_t *str = L"\a\b"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswprint_l(*p, NULL); + EXPECT_EQ("iswprint_l_0200", ret, CMPFLAG); + } +} + +int main(int argc, char *argv[]) +{ + iswprint_0100(); + iswprint_0200(); + iswprint_l_0100(); + iswprint_l_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iswpunct.c b/libc-test/src/functionalext/supplement/ctype/iswpunct.c new file mode 100644 index 00000000..c26d4bd9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iswpunct.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "functionalext.h" +#include "test.h" + +/** + * @tc.name : iswpunct_0100 + * @tc.desc : Use the iswpunct method to determine whether the incoming wide character is a punctuation mark + * @tc.level : Level 0 + */ +void iswpunct_0100(void) +{ + wchar_t ch = L','; + int result = iswpunct(ch); + if (result == 0) { + t_error("%s iswpunct get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswpunct_0200 + * @tc.desc : Test iswpunct method for wide characters passed in non-punctuation marks + * @tc.level : Level 1 + */ +void iswpunct_0200(void) +{ + wchar_t ch = L'A'; + int result = iswpunct(ch); + if (result != 0) { + t_error("%s iswpunct get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswpunct_l_0100 + * @tc.desc : Whether the characters in a wide string are punctuation marks + * @tc.level : Level 0 + */ +void iswpunct_l_0100(void) +{ + const wchar_t *str = L"!!,。??"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswpunct_l(*p, NULL); + EXPECT_EQ("iswpunct_l_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : iswpunct_l_0200 + * @tc.desc : Whether the characters in a wide string are non-punctuation marks + * @tc.level : Level 2 + */ +void iswpunct_l_0200(void) +{ + const wchar_t *str = L"1AaÂÆ"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswpunct_l(*p, NULL); + EXPECT_EQ("iswpunct_l_0200", ret, CMPFLAG); + } +} + +int main(int argc, char *argv[]) +{ + iswpunct_0100(); + iswpunct_0200(); + iswpunct_l_0100(); + iswpunct_l_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iswspace.c b/libc-test/src/functionalext/supplement/ctype/iswspace.c new file mode 100644 index 00000000..fe47c0e6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iswspace.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "functionalext.h" +#include "test.h" + +/** + * @tc.name : iswspace_0100 + * @tc.desc : Use the iswspace method to determine whether the incoming wide character is a blank symbol + * @tc.level : Level 0 + */ +void iswspace_0100(void) +{ + wchar_t ch = L' '; + int result = iswspace(ch); + if (result == 0) { + t_error("%s iswspace get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswspace_0200 + * @tc.desc : Test iswpunct method for wide characters passing in non-whitespace characters + * @tc.level : Level 1 + */ +void iswspace_0200(void) +{ + wchar_t ch = L'A'; + int result = iswspace(ch); + if (result != 0) { + t_error("%s iswspace get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswspace_l_0100 + * @tc.desc : Whether the characters in a wide string is whitespace character + * @tc.level : Level 0 + */ +void iswspace_l_0100(void) +{ + const wchar_t *str = L" \t\n\r"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswspace_l(*p, NULL); + EXPECT_EQ("iswspace_l_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : iswspace_l_0200 + * @tc.desc : Whether the characters in a wide string are non-whitespace character + * @tc.level : Level 2 + */ +void iswspace_l_0200(void) +{ + const wchar_t *str = L"1AaÂÆ"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswspace_l(*p, NULL); + EXPECT_EQ("iswspace_l_0200", ret, CMPFLAG); + } +} + +int main(int argc, char *argv[]) +{ + iswspace_0100(); + iswspace_0200(); + iswspace_l_0100(); + iswspace_l_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iswupper.c b/libc-test/src/functionalext/supplement/ctype/iswupper.c new file mode 100644 index 00000000..3eedae25 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iswupper.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "functionalext.h" +#include "test.h" + +/** + * @tc.name : iswupper_0100 + * @tc.desc : Determine whether the incoming wide character is an uppercase letter by the iswupper method + * @tc.level : Level 0 + */ +void iswupper_0100(void) +{ + wchar_t ch = L'A'; + int result = iswupper(ch); + if (result == 0) { + t_error("%s iswupper get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswupper_0200 + * @tc.desc : Test the return value of iswupper when lowercase letters are passed in + * @tc.level : Level 1 + */ +void iswupper_0200(void) +{ + wchar_t ch = L'a'; + int result = iswupper(ch); + if (result != 0) { + t_error("%s iswupper get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswupper_0300 + * @tc.desc : Test iswupper return value when passing in a number + * @tc.level : Level 1 + */ +void iswupper_0300(void) +{ + wchar_t ch = L'1'; + int result = iswupper(ch); + if (result != 0) { + t_error("%s iswupper get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswupper_l_0100 + * @tc.desc : Whether the characters in a wide string is upper character + * @tc.level : Level 0 + */ +void iswupper_l_0100(void) +{ + const wchar_t *str = L"ABCDEFG"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswupper_l(*p, NULL); + EXPECT_EQ("iswupper_l_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : iswupper_l_0200 + * @tc.desc : Whether the characters in a wide string are non-upper character + * @tc.level : Level 2 + */ +void iswupper_l_0200(void) +{ + const wchar_t *str = L"abcefg1"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswupper_l(*p, NULL); + EXPECT_EQ("iswupper_l_0200", ret, CMPFLAG); + } +} + +int main(int argc, char *argv[]) +{ + iswupper_0100(); + iswupper_0200(); + iswupper_0300(); + iswupper_l_0100(); + iswupper_l_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/iswxdigit.c b/libc-test/src/functionalext/supplement/ctype/iswxdigit.c new file mode 100644 index 00000000..6f235766 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/iswxdigit.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "functionalext.h" +#include "test.h" + +/** + * @tc.name : iswxdigit_0100 + * @tc.desc : Use the iswxdigit method to determine whether the incoming wide character is a hexadecimal number + * @tc.level : Level 0 + */ +void iswxdigit_0100(void) +{ + wchar_t ch = L'A'; + int result = iswxdigit(ch); + if (result == 0) { + t_error("%s iswxdigit get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswxdigit_0200 + * @tc.desc : Incoming digit test iswxdigit return value + * @tc.level : Level 1 + */ +void iswxdigit_0200(void) +{ + wchar_t ch = L'1'; + int result = iswxdigit(ch); + if (result == 0) { + t_error("%s iswxdigit get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswxdigit_0300 + * @tc.desc : Pass in letters over F to test iswxdigit return value + * @tc.level : Level 1 + */ +void iswxdigit_0300(void) +{ + wchar_t ch = L'G'; + int result = iswxdigit(ch); + if (result != 0) { + t_error("%s iswxdigit get result is %d error", __func__, result); + } +} + +/** + * @tc.name : iswxdigit_l_0100 + * @tc.desc : Whether the characters in a wide string is hexadecimal digit character + * @tc.level : Level 0 + */ +void iswxdigit_l_0100(void) +{ + const wchar_t *str = L"0123456789AaBbCcDdEeFf"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswxdigit_l(*p, NULL); + EXPECT_EQ("iswxdigit_l_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : iswxdigit_l_0200 + * @tc.desc : Whether the characters in a wide string is non-hexadecimal digit character + * @tc.level : Level 2 + */ +void iswxdigit_l_0200(void) +{ + const wchar_t *str = L"!@hHiIjJZz"; + const wchar_t *p = str; + while (*p++ && *p != '\0') { + int ret = iswxdigit_l(*p, NULL); + EXPECT_EQ("iswxdigit_l_0200", ret, CMPFLAG); + } +} + +int main(int argc, char *argv[]) +{ + iswxdigit_0100(); + iswxdigit_0200(); + iswxdigit_0300(); + iswxdigit_l_0100(); + iswxdigit_l_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isxdigit.c b/libc-test/src/functionalext/supplement/ctype/isxdigit.c new file mode 100644 index 00000000..85bf5067 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/isxdigit.c @@ -0,0 +1,139 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int COUNT = 22; +const int EOK = 0; + +/** + * @tc.name : isxdigit_0100 + * @tc.desc : The parameter c is alphanumeric, and the input character is judged to be a hexadecimal number. + * @tc.level : Level 0 + */ +void isxdigit_0100(void) +{ + int ret = isxdigit('0'); + EXPECT_NE("isxdigit_0100", ret, EOK); +} + +/** + * @tc.name : isxdigit_0200 + * @tc.desc : The parameter c is a valid English letter(uppercase), + * and the input character is judged to be a hexadecimal number. + * @tc.level : Level 0 + */ +void isxdigit_0200(void) +{ + int ret = isxdigit('F'); + EXPECT_NE("isxdigit_0200", ret, EOK); +} + +/** + * @tc.name : isxdigit_0300 + * @tc.desc : The parameter c is a valid English letter(lowercase), + * and the input character is judged to be a hexadecimal number. + * @tc.level : Level 0 + */ +void isxdigit_0300(void) +{ + int ret = isxdigit('a'); + EXPECT_NE("isxdigit_0300", ret, EOK); +} + +/** + * @tc.name : isxdigit_0400 + * @tc.desc : The parameter c is a invalid English letter(uppercase), + * and the input character is not a hexadecimal number. + * @tc.level : Level 2 + */ +void isxdigit_0400(void) +{ + int ret = isxdigit('G'); + EXPECT_EQ("isxdigit_0400", ret, EOK); +} + +/** + * @tc.name : isxdigit_0500 + * @tc.desc : The parameter c is a special letter(%), + * and the input character is not a hexadecimal number. + * @tc.level : Level 2 + */ +void isxdigit_0500(void) +{ + int ret = isxdigit('%'); + EXPECT_EQ("isxdigit_0500", ret, EOK); +} + +/** + * @tc.name : isxdigit_0600 + * @tc.desc : Determine the number of hexadecimal letters in the ascii code table. + * @tc.level : Level 2 + */ +void isxdigit_0600(void) +{ + int total = 0; + for (int i = 0; i < 128; i++) { + int ret = isxdigit((char)i); + if (ret) { + total++; + } + } + EXPECT_EQ("isxdigit_0600", total, COUNT); +} + +/** + * @tc.name : isxdigit_l_0100 + * @tc.desc : Whether the characters in a string is hexadecimal digit character + * @tc.level : Level 0 + */ +void isxdigit_l_0100(void) +{ + const char *str = "0123456789AaBbCcDdEeFf"; + const char *p = str; + while (*p++ && *p != '\0') { + int ret = isxdigit_l(*p, NULL); + EXPECT_EQ("isxdigit_l_0100", ret, ONREXPECT); + } +} + +/** + * @tc.name : isxdigit_l_0200 + * @tc.desc : Whether the characters in a string is non-hexadecimal digit character + * @tc.level : Level 2 + */ +void isxdigit_l_0200(void) +{ + const char *str = "!@hHiIjJZz"; + const char *p = str; + while (*p++ && *p != '\0') { + int ret = isxdigit_l(*p, NULL); + EXPECT_EQ("isxdigit_l_0200", ret, CMPFLAG); + } +} + +int main(void) +{ + isxdigit_0100(); + isxdigit_0200(); + isxdigit_0300(); + isxdigit_0400(); + isxdigit_0500(); + isxdigit_0600(); + isxdigit_l_0100(); + isxdigit_l_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/test_src_functionalext_supplement_ctype.gni b/libc-test/src/functionalext/supplement/ctype/test_src_functionalext_supplement_ctype.gni new file mode 100644 index 00000000..b5294eaa --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/test_src_functionalext_supplement_ctype.gni @@ -0,0 +1,60 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_ctype_test = [ + "isalnum_l", + "isalpha_l", + "isblank_l", + "iscntrl_l", + "isgraph_l", + "isprint_l", + "ispunct_l", + "isspace_l", + "wcwidth", + "tolower", + "toupper", + "iswcntrl", + "iswctype", + "iswdigit", + "iswlower", + "wcswidth", + "iswprint", + "toascii", + "towlower", + "iswpunct", + "iswspace", + "iswupper", + "iswxdigit", + "wctrans", + "towctrans", + "wctrans_l", + "wctype", + "isspace", + "__ctype_get_mb_cur_max", + "isalpha", + "ispunct", + "iswalhpa", + "isalnum", + "isblank", + "iscntrl", + "islower", + "isprint", + "isupper", + "isxdigit", + "isascii", + "isdigit", + "isgraph", + "iswalnum", + "iswalpha", + "iswblank", +] diff --git a/libc-test/src/functionalext/supplement/ctype/toascii.c b/libc-test/src/functionalext/supplement/ctype/toascii.c new file mode 100644 index 00000000..75ad434f --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/toascii.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "test.h" + +/** + * @tc.name : toascii_0100 + * @tc.desc : Convert a character to ASCII + * @tc.level : Level 0 + */ +void toascii_0100(void) +{ + int c1 = 'a' + 128; + char c2 = toascii(c1); + if (c2 != 'a') { + t_error("%s toascii failed. c2 id %c", __func__, c2); + } +} + +/** + * @tc.name : toascii_0200 + * @tc.desc : Convert a character to ASCII special symbol + * @tc.level : Level 1 + */ +void toascii_0200(void) +{ + int c1 = 33; + char c2 = toascii(c1); + if (c2 != '!') { + t_error("%s toascii failed. c2 id %c", __func__, c2); + } +} + +/** + * @tc.name : toascii_0300 + * @tc.desc : Convert a character to an ASCII number + * @tc.level : Level 1 + */ +void toascii_0300(void) +{ + int c1 = 48; + char c2 = toascii(c1); + if (c2 != '0') { + t_error("%s toascii failed. c2 id %c", __func__, c2); + } +} + +int main(int argc, char *argv[]) +{ + toascii_0100(); + toascii_0200(); + toascii_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/tolower.c b/libc-test/src/functionalext/supplement/ctype/tolower.c new file mode 100644 index 00000000..ee77d943 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/tolower.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : tolower_0100 + * @tc.desc : Convert uppercase to lowercase by tolower + * @tc.level : Level 0 + */ +void tolower_0100(void) +{ + char ch = 'A'; + char result = tolower(ch); + if (result != 'a') { + t_error("%s tolower get result is %c but want get value a ", __func__, result); + } +} + +/** + * @tc.name : tolower_0200 + * @tc.desc : Test the result obtained by passing a number to tolower + * @tc.level : Level 1 + */ +void tolower_0200(void) +{ + char ch = 2; + char result = tolower(ch); + if (result != ch) { + t_error("%s tolower get result is %c but want get value %c ", __func__, result, ch); + } +} + +/** + * @tc.name : tolower_0300 + * @tc.desc : Test the result of passing lowercase letters to tolower + * @tc.level : Level 1 + */ +void tolower_0300(void) +{ + char ch = 'a'; + char result = tolower(ch); + if (result != ch) { + t_error("%s tolower get result is %c but want get value %c ", __func__, result, ch); + } +} + +/** + * @tc.name : tolower_0400 + * @tc.desc : Test the result of passing special characters into tolower + * @tc.level : Level 2 + */ +void tolower_0400(void) +{ + char ch = '$'; + char result = tolower(ch); + if (result != ch) { + t_error("%s tolower get result is %c but want get value %c ", __func__, result, ch); + } +} + +int main(int argc, char *argv[]) +{ + tolower_0100(); + tolower_0200(); + tolower_0300(); + tolower_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/toupper.c b/libc-test/src/functionalext/supplement/ctype/toupper.c new file mode 100644 index 00000000..55608807 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/toupper.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : toupper_0100 + * @tc.desc : Convert lowercase to uppercase via toupper + * @tc.level : Level 0 + */ +void toupper_0100(void) +{ + char ch = 'a'; + char result = toupper(ch); + if (result != 'A') { + t_error("%s toupper get result is %c but want get value A ", __func__, result); + } +} + +/** + * @tc.name : toupper_0200 + * @tc.desc : Test the result of passing numbers into toupper + * @tc.level : Level 1 + */ +void toupper_0200(void) +{ + char ch = 2; + char result = toupper(ch); + if (result != ch) { + t_error("%s toupper get result is %c but want get value %c ", __func__, result, ch); + } +} + +/** + * @tc.name : toupper_0300 + * @tc.desc : Test the result of passing capital letters into toupper + * @tc.level : Level 1 + */ +void toupper_0300(void) +{ + char ch = 'A'; + char result = toupper(ch); + if (result != ch) { + t_error("%s toupper get result is %c but want get value %c ", __func__, result, ch); + } +} + +/** + * @tc.name : toupper_0400 + * @tc.desc : Test the result of passing special characters into toupper + * @tc.level : Level 2 + */ +void toupper_0400(void) +{ + char ch = '$'; + char result = toupper(ch); + if (result != ch) { + t_error("%s toupper get result is %c but want get value %c ", __func__, result, ch); + } +} + +int main(int argc, char *argv[]) +{ + toupper_0100(); + toupper_0200(); + toupper_0300(); + toupper_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/towctrans.c b/libc-test/src/functionalext/supplement/ctype/towctrans.c new file mode 100644 index 00000000..b3ba38e8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/towctrans.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : towctrans_0100 + * @tc.desc : Convert character of current type to lowercases + * @tc.level : Level 0 + */ +void towctrans_0100(void) +{ + wchar_t str[] = L"ABCD"; + wctrans_t trans = wctrans("tolower"); + for (int i = 0; i < wcslen(str); i++) { + str[i] = towctrans(str[i], trans); + } + if (wcscmp(str, L"abcd")) { + t_error("%s towctrans lower failed", __func__); + } +} + +/** + * @tc.name : towctrans_0200 + * @tc.desc : Convert character of current type to uppercase + * @tc.level : Level 1 + */ +void towctrans_0200(void) +{ + wchar_t str[] = L"abcd"; + wctrans_t trans = wctrans("toupper"); + for (int i = 0; i < wcslen(str); i++) { + str[i] = towctrans(str[i], trans); + } + if (wcscmp(str, L"ABCD")) { + t_error("%s towctrans upper failed", __func__); + } +} + +/** + * @tc.name : towctrans_0300 + * @tc.desc : Convert character of current type to uppercase + * @tc.level : Level 1 + */ +void towctrans_0300(void) +{ + wchar_t str[] = L"Abcd"; + for (int i = 0; i < wcslen(str); i++) { + str[i] = towctrans(str[i], 0); + } + if (wcscmp(str, L"Abcd")) { + t_error("%s towctrans failed", __func__); + } +} + +int main(int argc, char *argv[]) +{ + towctrans_0100(); + towctrans_0200(); + towctrans_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/towlower.c b/libc-test/src/functionalext/supplement/ctype/towlower.c new file mode 100644 index 00000000..56bee221 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/towlower.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : towlower_0100 + * @tc.desc : Convert wide characters to lowercase via towlower + * @tc.level : Level 0 + */ +void towlower_0100(void) +{ + wint_t wt = L'\u0190'; + wint_t result = towlower(wt); + unsigned int want = 603; + if (result != want) { + t_error("%s towlower get result is %d are not 603\n", __func__, result); + } +} + +/** + * @tc.name : towlower_0200 + * @tc.desc : Test that the incoming character exceeds the function limit + * @tc.level : Level 1 + */ +void towlower_0200(void) +{ + wint_t wt = 0x20000; + wint_t result = towlower(wt); + if (result != wt) { + t_error("%s towlower get result is %d are not 0x20000\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + towlower_0100(); + towlower_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/wcswidth.c b/libc-test/src/functionalext/supplement/ctype/wcswidth.c new file mode 100644 index 00000000..edce5969 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/wcswidth.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +const int WIDTH = 2; +const int ERR_RESULT = -1; + +/** + * @tc.name : wcswidth_0100 + * @tc.desc : Test wcswidth to get the number of wide string columns + * @tc.level : Level 0 + */ +void wcswidth_0100(void) +{ + int result = wcswidth(L"abc", WIDTH); + if (result != WIDTH) { + t_error("%s wcswidth get result is %s are not want 2\n", __func__, result); + } +} + +/** + * @tc.name : wcswidth_0200 + * @tc.desc : wcswidth result when wide string contains non-printing characters + * @tc.level : Level 1 + */ +void wcswidth_0200(void) +{ + int result = wcswidth(L"ab\t", WIDTH); + if (result != WIDTH) { + t_error("%s wcswidth get result is %s are not want 2\n", __func__, result); + } +} + +/** + * @tc.name : wcswidth_0300 + * @tc.desc : The result of wcswidth when nonprinting characters are included in the selection + * @tc.level : Level 2 + */ +void wcswidth_0300(void) +{ + int result = wcswidth(L"a\tb", WIDTH); + if (result != ERR_RESULT) { + t_error("%s wcswidth get result is %s are not want -1\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + wcswidth_0100(); + wcswidth_0200(); + wcswidth_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/wctrans.c b/libc-test/src/functionalext/supplement/ctype/wctrans.c new file mode 100644 index 00000000..d8fc3e1a --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/wctrans.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wctrans_0100 + * @tc.desc : Test that wctrans returns a character conversion of a scalar type + * @tc.level : Level 0 + */ +void wctrans_0100(void) +{ + if (!wctrans("tolower")) { + t_error("%s wctrans error get result is NULL\n", __func__); + } +} + +/** + * @tc.name : wctrans_0200 + * @tc.desc : Test result of wctrans when incoming uppercase conversion + * @tc.level : Level 1 + */ +void wctrans_0200(void) +{ + if (!wctrans("toupper")) { + t_error("%s wctrans error get result is NULL\n", __func__); + } +} + +/** + * @tc.name : wctrans_0300 + * @tc.desc : Test the result of wctrans when passing in an exception parameter + * @tc.level : Level 2 + */ +void wctrans_0300(void) +{ + if (wctrans("monkeys")) { + t_error("%s wctrans error get result is not NULL\n", __func__); + } +} + +int main(int argc, char *argv[]) +{ + wctrans_0100(); + wctrans_0200(); + wctrans_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/wctrans_l.c b/libc-test/src/functionalext/supplement/ctype/wctrans_l.c new file mode 100644 index 00000000..8d546be6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/wctrans_l.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wctrans_l_0100 + * @tc.desc : Test that wctrans_l returns a character conversion of a scalar type + * @tc.level : Level 0 + */ +void wctrans_l_0100(void) +{ + if (!wctrans_l("tolower", NULL)) { + t_error("%s wctrans_l error get result is NULL\n", __func__); + } +} + +/** + * @tc.name : wctrans_l_0200 + * @tc.desc : Test result of wctrans_l when incoming uppercase conversion + * @tc.level : Level 1 + */ +void wctrans_l_0200(void) +{ + if (!wctrans_l("toupper", NULL)) { + t_error("%s wctrans_l error get result is NULL\n", __func__); + } +} + +/** + * @tc.name : wctrans_l_0300 + * @tc.desc : Test the result of wctrans_l when passing in an exception parameter + * @tc.level : Level 2 + */ +void wctrans_l_0300(void) +{ + if (wctrans_l("monkeys", NULL)) { + t_error("%s wctrans_l error get result is not NULL\n", __func__); + } +} + +int main(int argc, char *argv[]) +{ + wctrans_l_0100(); + wctrans_l_0200(); + wctrans_l_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/wctype.c b/libc-test/src/functionalext/supplement/ctype/wctype.c new file mode 100644 index 00000000..19f2b8d7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/wctype.c @@ -0,0 +1,265 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wctype_0100 + * @tc.desc : Test the return value when wctype input parameters are alnum and error strings + * @tc.level : Level 0 + */ +void wctype_0100(void) +{ + wctype_t expect0 = wctype("alnum"); + wctype_t target = 1; + if (expect0 != target) { + t_error("%s expect type is not alnum", __func__); + } + + wctype_t expect1 = wctype("alnumm"); + if (expect1 == target) { + t_error("%s error input type is alnum", __func__); + } +} + +/** + * @tc.name : wctype_0200 + * @tc.desc : Test the return value when wctype input parameters are alpha and error strings + * @tc.level : Level 0 + */ +void wctype_0200(void) +{ + wctype_t expect0 = wctype("alpha"); + wctype_t target = 2; + if (expect0 != target) { + t_error("%s expect type is not alpha", __func__); + } + + wctype_t expect1 = wctype("alphaa"); + if (expect1 == target) { + t_error("%s error input type is alpha", __func__); + } +} + +/** + * @tc.name : wctype_0300 + * @tc.desc : Test the return value when wctype input parameters are blank and error strings + * @tc.level : Level 0 + */ +void wctype_0300(void) +{ + wctype_t expect0 = wctype("blank"); + wctype_t target = 3; + if (expect0 != target) { + t_error("%s expect type is not blank", __func__); + } + + wctype_t expect1 = wctype("blankk"); + if (expect1 == target) { + t_error("%s error input type is blank", __func__); + } +} + +/** + * @tc.name : wctype_0400 + * @tc.desc : Test the return value when wctype input parameters are cntrl and error strings + * @tc.level : Level 0 + */ +void wctype_0400(void) +{ + wctype_t expect0 = wctype("cntrl"); + wctype_t target = 4; + if (expect0 != target) { + t_error("%s expect type is not cntrl", __func__); + } + + wctype_t expect1 = wctype("cntrll"); + if (expect1 == target) { + t_error("%s error input type is cntrl", __func__); + } +} + +/** + * @tc.name : wctype_0500 + * @tc.desc : Test the return value when wctype input parameters are digit and error strings + * @tc.level : Level 0 + */ +void wctype_0500(void) +{ + wctype_t expect0 = wctype("digit"); + wctype_t target = 5; + if (expect0 != target) { + t_error("%s expect type is not digit", __func__); + } + + wctype_t expect1 = wctype("digitt"); + if (expect1 == target) { + t_error("%s error input type is digit", __func__); + } +} + +/** + * @tc.name : wctype_0600 + * @tc.desc : Test the return value when wctype input parameters are graph and error strings + * @tc.level : Level 0 + */ +void wctype_0600(void) +{ + wctype_t expect0 = wctype("graph"); + wctype_t target = 6; + if (expect0 != target) { + t_error("%s expect type is not graph", __func__); + } + + wctype_t expect1 = wctype("graphh"); + if (expect1 == target) { + t_error("%s error input type is graph", __func__); + } +} + +/** + * @tc.name : wctype_0700 + * @tc.desc : Test the return value when wctype input parameters are lower and error strings + * @tc.level : Level 0 + */ +void wctype_0700(void) +{ + wctype_t expect0 = wctype("lower"); + wctype_t target = 7; + if (expect0 != target) { + t_error("%s expect type is not lower", __func__); + } + + wctype_t expect1 = wctype("lowerr"); + if (expect1 == target) { + t_error("%s error input type is lower", __func__); + } +} + +/** + * @tc.name : wctype_0800 + * @tc.desc : Test the return value when wctype input parameters are print and error strings + * @tc.level : Level 0 + */ +void wctype_0800(void) +{ + wctype_t expect0 = wctype("print"); + wctype_t target = 8; + if (expect0 != target) { + t_error("%s expect type is not print", __func__); + } + + wctype_t expect1 = wctype("printt"); + if (expect1 == target) { + t_error("%s error input type is print", __func__); + } +} + +/** + * @tc.name : wctype_0900 + * @tc.desc : Test the return value when wctype input parameters are punct and error strings + * @tc.level : Level 0 + */ +void wctype_0900(void) +{ + wctype_t expect0 = wctype("punct"); + wctype_t target = 9; + if (expect0 != target) { + t_error("%s expect type is not punct", __func__); + } + + wctype_t expect1 = wctype("punctt"); + if (expect1 == target) { + t_error("%s error input type is punct", __func__); + } +} + +/** + * @tc.name : wctype_1000 + * @tc.desc : Test the return value when wctype input parameters are space and error strings + * @tc.level : Level 0 + */ +void wctype_1000(void) +{ + wctype_t expect0 = wctype("space"); + wctype_t target = 10; + if (expect0 != target) { + t_error("%s expect type is not space", __func__); + } + + wctype_t expect1 = wctype("spacee"); + if (expect1 == target) { + t_error("%s error input type is space", __func__); + } +} + +/** + * @tc.name : wctype_1100 + * @tc.desc : Test the return value when wctype input parameters are upper and error strings + * @tc.level : Level 0 + */ +void wctype_1100(void) +{ + wctype_t expect0 = wctype("upper"); + wctype_t target = 11; + if (expect0 != target) { + t_error("%s expect type is not upper", __func__); + } + + wctype_t expect1 = wctype("upperr"); + if (expect1 == target) { + t_error("%s error input type is upper", __func__); + } +} + +/** + * @tc.name : wctype_1200 + * @tc.desc : Test the return value when wctype input parameters are xdigit and error strings + * @tc.level : Level 0 + */ +void wctype_1200(void) +{ + wctype_t expect0 = wctype("xdigit"); + wctype_t target = 12; + if (expect0 != target) { + t_error("%s expect type is not xdigit", __func__); + } + + wctype_t expect1 = wctype("xdigitt"); + if (expect1 == target) { + t_error("%s error input type is xdigit", __func__); + } +} + +int main(int argc, char *argv[]) +{ + wctype_0100(); + wctype_0200(); + wctype_0300(); + wctype_0400(); + wctype_0500(); + wctype_0600(); + wctype_0700(); + wctype_0800(); + wctype_0900(); + wctype_1000(); + wctype_1100(); + wctype_1200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/wcwidth.c b/libc-test/src/functionalext/supplement/ctype/wcwidth.c new file mode 100644 index 00000000..7de79bb6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ctype/wcwidth.c @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +const int INPUT_VALUE[12] = { + 0x0300, 0x20dd, 0x00ad, 0x200b, 0x4e00, 0x9fff, 0x3400, 0x4dbf, 0x20000, 0x2a6df, 0xac00, 0xd7a3}; +const int RESULT_VALUE = 2; + +/** + * @tc.name : wcwidth_0100 + * @tc.desc : Test that the wcwidth method returns the desired number of columns + * @tc.level : Level 0 + */ +void wcwidth_0100(void) +{ + int result = wcwidth(0); + if (result != 0) { + t_error("%s wcwidth get result is %d are not want 0\n", __func__, result); + } +} + +/** + * @tc.name : wcwidth_0200 + * @tc.desc : Combining grave + * @tc.level : Level 1 + */ +void wcwidth_0200(void) +{ + int result = wcwidth(INPUT_VALUE[0]); + if (result != 0) { + t_error("%s wcwidth get result is %d are not want 0\n", __func__, result); + } +} + +/** + * @tc.name : wcwidth_0300 + * @tc.desc : Combining enclosing circle + * @tc.level : Level 1 + */ +void wcwidth_0300(void) +{ + int result = wcwidth(INPUT_VALUE[1]); + if (result != 0) { + t_error("%s wcwidth get result is %d are not want 0\n", __func__, result); + } +} + +/** + * @tc.name : wcwidth_0400 + * @tc.desc : Soft hyphen (SHY) + * @tc.level : Level 1 + */ +void wcwidth_0400(void) +{ + int result = wcwidth(INPUT_VALUE[2]); + if (result != 1) { + t_error("%s wcwidth get result is %d are not want 1\n", __func__, result); + } +} + +/** + * @tc.name : wcwidth_0500 + * @tc.desc : Zero width space + * @tc.level : Level 1 + */ +void wcwidth_0500(void) +{ + int result = wcwidth(INPUT_VALUE[3]); + if (result != 0) { + t_error("%s wcwidth get result is %d are not want 0\n", __func__, result); + } +} + +/** + * @tc.name : wcwidth_0600 + * @tc.desc : Start of CJK unified block + * @tc.level : Level 1 + */ +void wcwidth_0600(void) +{ + int result = wcwidth(INPUT_VALUE[4]); + if (result != RESULT_VALUE) { + t_error("%s wcwidth get result is %d are not want 2\n", __func__, result); + } +} + +/** + * @tc.name : wcwidth_0700 + * @tc.desc : End of CJK unified block + * @tc.level : Level 1 + */ +void wcwidth_0700(void) +{ + int result = wcwidth(INPUT_VALUE[5]); + if (result != RESULT_VALUE) { + t_error("%s wcwidth get result is %d are not want 2\n", __func__, result); + } +} + +/** + * @tc.name : wcwidth_0800 + * @tc.desc : Start of CJK extension A block. + * @tc.level : Level 1 + */ +void wcwidth_0800(void) +{ + int result = wcwidth(INPUT_VALUE[6]); + if (result != RESULT_VALUE) { + t_error("%s wcwidth get result is %d are not want 2\n", __func__, result); + } +} + +/** + * @tc.name : wcwidth_0900 + * @tc.desc : End of CJK extension A block. + * @tc.level : Level 1 + */ +void wcwidth_0900(void) +{ + int result = wcwidth(INPUT_VALUE[7]); + if (result != RESULT_VALUE) { + t_error("%s wcwidth get result is %d are not want 2\n", __func__, result); + } +} + +/** + * @tc.name : wcwidth_1000 + * @tc.desc : Start of CJK extension B block. + * @tc.level : Level 1 + */ +void wcwidth_1000(void) +{ + int result = wcwidth(INPUT_VALUE[8]); + if (result != RESULT_VALUE) { + t_error("%s wcwidth get result is %d are not want 2\n", __func__, result); + } +} + +/** + * @tc.name : wcwidth_1100 + * @tc.desc : End of CJK extension B block. + * @tc.level : Level 1 + */ +void wcwidth_1100(void) +{ + int result = wcwidth(INPUT_VALUE[9]); + if (result != RESULT_VALUE) { + t_error("%s wcwidth get result is %d are not want 2\n", __func__, result); + } +} + +/** + * @tc.name : wcwidth_1200 + * @tc.desc : Start of block + * @tc.level : Level 1 + */ +void wcwidth_1200(void) +{ + int result = wcwidth(INPUT_VALUE[10]); + if (result != RESULT_VALUE) { + t_error("%s wcwidth get result is %d are not want 2\n", __func__, result); + } +} + +/** + * @tc.name : wcwidth_1300 + * @tc.desc : End of defined code points in Unicode 7 + * @tc.level : Level 1 + */ +void wcwidth_1300(void) +{ + int result = wcwidth(INPUT_VALUE[11]); + if (result != RESULT_VALUE) { + t_error("%s wcwidth get result is %d are not want 2\n", __func__, result); + } +} + +/** + * @tc.name : wcwidth_1400 + * @tc.desc : Korean "crying" emoticon. + * @tc.level : Level 1 + */ +void wcwidth_1400(void) +{ + int result = wcwidth(L'ㅜ'); + if (result != RESULT_VALUE) { + t_error("%s wcwidth get result is %d are not want 2\n", __func__, result); + } +} + +/** + * @tc.name : wcwidth_1500 + * @tc.desc : Korean "laughing" emoticon.. + * @tc.level : Level 1 + */ +void wcwidth_1500(void) +{ + int result = wcwidth(L'ㅋ'); + if (result != RESULT_VALUE) { + t_error("%s wcwidth get result is %d are not want 2\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + wcwidth_0100(); + wcwidth_0200(); + wcwidth_0300(); + wcwidth_0400(); + wcwidth_0500(); + wcwidth_0600(); + wcwidth_0700(); + wcwidth_0800(); + wcwidth_0900(); + wcwidth_1000(); + wcwidth_1100(); + wcwidth_1200(); + wcwidth_1300(); + wcwidth_1400(); + wcwidth_1500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/dirent/BUILD.gn b/libc-test/src/functionalext/supplement/dirent/BUILD.gn new file mode 100644 index 00000000..55fffeec --- /dev/null +++ b/libc-test/src/functionalext/supplement/dirent/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_dirent.gni") + +foreach(s, functionalext_supplement_dirent_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/dirent" + } +} + +group("functionalext_supplement_dirent_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_dirent_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/dirent/alphasort.c b/libc-test/src/functionalext/supplement/dirent/alphasort.c new file mode 100644 index 00000000..71be0c4c --- /dev/null +++ b/libc-test/src/functionalext/supplement/dirent/alphasort.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include "functionalext.h" + +#define MAXPATH 1000 + +/** + * @tc.name : alphasort_0100 + * @tc.desc : Verify that the directory structure can be sorted alphabetically + * @tc.level : Level 0 + */ +void alphasort_0100(void) +{ + struct dirent **namelist; + int n, total; + total = scandir("/", &namelist, 0, alphasort); + EXPECT_TRUE("alphasort_0100", total > 0); +} + +/** + * @tc.name : alphasort_0200 + * @tc.desc : Verify that the directory structure cannot be sorted alphabetically + * @tc.level : Level 2 + */ +void alphasort_0200(void) +{ + struct dirent **namelist; + int n, total; + total = scandir(NULL, &namelist, 0, alphasort); + EXPECT_TRUE("alphasort_0100", total < 0); +} + +int main() +{ + alphasort_0100(); + alphasort_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/dirent/closedir.c b/libc-test/src/functionalext/supplement/dirent/closedir.c new file mode 100644 index 00000000..1e1c6ab0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/dirent/closedir.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define MAXPATH 1000 + +/** + * @tc.name : closedir_0100 + * @tc.desc : The parameter is valid and can close the specified directory. + * @tc.level : Level 0 + */ +void closedir_0100(void) +{ + char path[MAXPATH]; + DIR *dir_ptr; + char *data = NULL; + data = getcwd(path, MAXPATH); + dir_ptr = opendir(path); + int ret = -1; + ret = closedir(dir_ptr); + EXPECT_EQ("closedir_0100", ret, 0); +} + +/** + * @tc.name : closedir_0200 + * @tc.desc : The dir parameter is invalid, the specified directory cannot be closed. + * @tc.level : Level 2 + */ +void closedir_0200(void) +{ + DIR *dir = (DIR *)"/notexist"; + int ret = 0; + ret = closedir(dir); + EXPECT_EQ("closedir_0200", ret, -1); +} + +int main() +{ + closedir_0100(); + closedir_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/dirent/dirfd.c b/libc-test/src/functionalext/supplement/dirent/dirfd.c new file mode 100644 index 00000000..5930446f --- /dev/null +++ b/libc-test/src/functionalext/supplement/dirent/dirfd.c @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" +#include "functionalext.h" + +struct __dirstream { + long long tell; + int fd; + int buf_pos; + int buf_end; + volatile int lock[1]; + char buf[2048]; +}; +#define MAXPATH 1000 +const int COUNT_NEGATIVE = -1; + +/* + * @tc.name : dirfd_0100 + * @tc.desc : Verify that the file descriptor for the directory file referred to by parameter d is available + * (parameter valid) + * @tc.level : Level 0 + */ +void dirfd_0100(void) +{ + bool flag = true; + char path[MAXPATH]; + DIR *dir_ptr; + getcwd(path, MAXPATH); + dir_ptr = opendir(path); + int result = 0; + result = dirfd(dir_ptr); + if (result > 0) { + flag = true; + } + EXPECT_TRUE("dirfd_0100", flag); + closedir(dir_ptr); +} + +int main() +{ + dirfd_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/dirent/fdopendir.c b/libc-test/src/functionalext/supplement/dirent/fdopendir.c new file mode 100644 index 00000000..8833a13b --- /dev/null +++ b/libc-test/src/functionalext/supplement/dirent/fdopendir.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : fdopendir_0100 + * @tc.desc : Each parameter is valid, and the directory information can be obtained. + * @tc.level : Level 0 + */ +void fdopendir_0100(void) +{ + bool flag = false; + DIR *dir = NULL; + int fd = open("/data/data", O_RDONLY); + if (fd < 0) { + t_error("%s open failed, fd = %d\n", __func__, fd); + } + dir = fdopendir(fd); + if (dir == 0) { + t_error("%s fdopendir failed\n", __func__); + } else { + flag = true; + } + EXPECT_TRUE("fdopendir_0100", flag); +} + +/** + * @tc.name : fdopendir_0200 + * @tc.desc : The fd parameter is invalid (0), the directory information of the file cannot be obtained. + * @tc.level : Level 2 + */ +void fdopendir_0200(void) +{ + DIR *dir = fdopendir(0); + EXPECT_EQ("fdopendir_0200", dir, NULL); +} + +/** + * @tc.name : fdopendir_0300 + * @tc.desc : The fd parameter is invalid (a non-existing directory), and the directory information. + * of the file cannot be obtained. + * @tc.level : Level 2 + */ +void fdopendir_0300(void) +{ + DIR *dir = NULL; + int fd = open("/data/data/test.txt", O_RDONLY); + dir = fdopendir(fd); + EXPECT_EQ("fdopendir_0300", dir, NULL); +} + +/** + * @tc.name : fdopendir_0400 + * @tc.desc : Each parameter is valid, and the directory information of the file can be obtained. + * @tc.level : Level 2 + */ +void fdopendir_0400(void) +{ + DIR *dir = NULL; + int fd = open("/data/data/test.txt", O_RDONLY); + dir = fdopendir(fd); + EXPECT_EQ("fdopendir_0400", dir, NULL); + system("rm -rf /data/data/test.txt"); +} + +int main() +{ + fdopendir_0100(); + fdopendir_0200(); + fdopendir_0300(); + fdopendir_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/dirent/opendir.c b/libc-test/src/functionalext/supplement/dirent/opendir.c new file mode 100755 index 00000000..b051a96a --- /dev/null +++ b/libc-test/src/functionalext/supplement/dirent/opendir.c @@ -0,0 +1,85 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +#define MAXPATH 1000 + +/* + * @tc.name : opendir_0100 + * @tc.desc : Verify that the parameters are valid to open the specified directory + * @tc.level : Level 0 + */ +void opendir_0100(void) +{ + bool flag = false; + char path[MAXPATH]; + DIR *dir_ptr; + char *data = NULL; + data = getcwd(path, MAXPATH); + dir_ptr = opendir(path); + if (dir_ptr != 0) { + flag = true; + } + EXPECT_TRUE("opendir_0100", flag); +} + +/* + * @tc.name : opendir_0200 + * @tc.desc : The verification parameter is invalid, the specified directory cannot be opened + * (name does not exist) + * @tc.level : Level 2 + */ +void opendir_0200(void) +{ + DIR *dir_ptr; + dir_ptr = opendir("/dev/key"); + EXPECT_EQ("opendir_0200", dir_ptr, 0); +} + +/* + * @tc.name : opendir_0300 + * @tc.desc : The validation parameter is invalid and the specified directory cannot be opened (name is NULL) + * @tc.level : Level 2 + */ +void opendir_0300(void) +{ + DIR *dir_ptr; + char *path = NULL; + path = getcwd(NULL, 0); + dir_ptr = opendir(NULL); + EXPECT_EQ("opendir_0300", dir_ptr, 0); +} + +TEST_FUN G_Fun_Array[] = { + opendir_0100, + opendir_0200, + opendir_0300, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/dirent/readdir.c b/libc-test/src/functionalext/supplement/dirent/readdir.c new file mode 100644 index 00000000..405add3b --- /dev/null +++ b/libc-test/src/functionalext/supplement/dirent/readdir.c @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : readdir_0100 + * @tc.desc : The parameter is valid and can return the next directory entry + * point of the parameter dir directory stream. + * @tc.level : Level 0 + */ +void readdir_0100(void) +{ + DIR *dir; + struct dirent *ret; + dir = opendir("/etc"); + ret = readdir(dir); + EXPECT_TRUE("readdir_0100", ret != NULL); + closedir(dir); +} + +/** + * @tc.name : readdir_0200 + * @tc.desc : The parameter is invalid, cannot return the next directory entry + * point of the parameter dir directory stream. + * @tc.level : Level 2 + */ +void readdir_0200(void) +{ + DIR *dir = (DIR *)""; + struct dirent *ret; + ret = readdir(dir); + EXPECT_TRUE("readdir_0200", NULL == ret); +} + +int main() +{ + readdir_0100(); + readdir_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/dirent/readdir_r.c b/libc-test/src/functionalext/supplement/dirent/readdir_r.c new file mode 100644 index 00000000..a5dd5eaf --- /dev/null +++ b/libc-test/src/functionalext/supplement/dirent/readdir_r.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +const char *name = "/data/tests/libc-test/src"; + +void handler(int sig) +{ + exit(t_status); +} + +/** + * @tc.name : readdir_r_0100 + * @tc.desc : read a directory + * @tc.level : Level 0 + */ +void readdir_r_0100(void) +{ + DIR *dir = opendir(name); + if (dir == NULL) { + t_error("%s failed: opendir. name = %s\n", __func__, name); + return; + } + + struct dirent buf; + struct dirent *res; + int result = readdir_r(dir, &buf, &res); + if (result != 0) { + t_error("%s failed: readdir_r. result = %s\n", __func__, result); + return; + } +} + +/** + * @tc.name : readdir_r_0200 + * @tc.desc : read a directory with a NULL dir + * @tc.level : Level 2 + */ +void readdir_r_0200(void) +{ + signal(SIGSEGV, handler); + + DIR *dir = NULL; + struct dirent buf; + struct dirent *res; + readdir_r(dir, &buf, &res); +} + +int main(int argc, char *argv[]) +{ + readdir_r_0100(); + readdir_r_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/dirent/rewinddir.c b/libc-test/src/functionalext/supplement/dirent/rewinddir.c new file mode 100644 index 00000000..99ea4abf --- /dev/null +++ b/libc-test/src/functionalext/supplement/dirent/rewinddir.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "test.h" + +const char *name = "/data/tests/libc-test/src"; + +void handler(int sig) +{ + exit(t_status); +} + +/** + * @tc.name : rewinddir_0100 + * @tc.desc : reset directory stream + * @tc.level : Level 0 + */ +void rewinddir_0100(void) +{ + DIR *dir = opendir(name); + if (dir == NULL) { + t_error("%s failed: opendir. name = %s\n", __func__, name); + return; + } + + struct dirent *result = readdir(dir); + if (result == NULL) { + t_error("%s failed: readdir\n", __func__); + return; + } + + char *d_name = result->d_name; + + while ((result = readdir(dir)) != NULL) { + } + + rewinddir(dir); + result = readdir(dir); + if (result == NULL) { + t_error("%s failed: readdir\n", __func__); + return; + } + + if (strcmp(d_name, result->d_name)) { + t_error("%s failed: strcmp. d_name = %s, result->d_name = %s\n", __func__, d_name, result->d_name); + return; + } + + closedir(dir); +} + +/** + * @tc.name : rewinddir_0200 + * @tc.desc : reset directory stream with a NULL dir + * @tc.level : Level 2 + */ +void rewinddir_0200(void) +{ + signal(SIGSEGV, handler); + + DIR *dir = NULL; + rewinddir(dir); +} + +int main(int argc, char *argv[]) +{ + rewinddir_0100(); + rewinddir_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/dirent/scandir.c b/libc-test/src/functionalext/supplement/dirent/scandir.c new file mode 100644 index 00000000..ed3ca573 --- /dev/null +++ b/libc-test/src/functionalext/supplement/dirent/scandir.c @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +const char *name = "/data/tests/libc-test/src"; + +int filter(const struct dirent *entry) +{ + return !0; +} + +/** + * @tc.name : scandir_0100 + * @tc.desc : scan a directory for matching entries with alphasort + * @tc.level : Level 0 + */ +void scandir_0100(void) +{ + struct dirent **namelist; + int n = scandir(name, &namelist, NULL, alphasort); + if (n < 0) { + t_error("%s failed: scandir. n = %d\n", __func__, n); + return; + } + + while (n--) { + free(namelist[n]); + } + free(namelist); +} + +/** + * @tc.name : scandir_0200 + * @tc.desc : scan a directory for matching entries with versionsort + * @tc.level : Level 1 + */ +void scandir_0200(void) +{ + struct dirent **namelist; + int n = scandir(name, &namelist, NULL, versionsort); + if (n < 0) { + t_error("%s failed: scandir. n = %d\n", __func__, n); + return; + } + + while (n--) { + free(namelist[n]); + } + free(namelist); +} + +/** + * @tc.name : scandir_0300 + * @tc.desc : scan a directory for matching entries with filter + * @tc.level : Level 1 + */ +void scandir_0300(void) +{ + struct dirent **namelist; + int n = scandir(name, &namelist, filter, versionsort); + if (n < 0) { + t_error("%s failed: scandir. n = %d\n", __func__, n); + return; + } + + while (n--) { + free(namelist[n]); + } + free(namelist); +} + +/** + * @tc.name : scandir_0400 + * @tc.desc : scan a directory for matching entries with a NULL dir + * @tc.level : Level 2 + */ +void scandir_0400(void) +{ + struct dirent **namelist; + int n = scandir(NULL, &namelist, NULL, alphasort); + if (n >= 0) { + t_error("%s failed: scandir. n = %d\n", __func__, n); + + while (n--) { + free(namelist[n]); + } + free(namelist); + return; + } +} + +int main(int argc, char *argv[]) +{ + scandir_0100(); + scandir_0200(); + scandir_0300(); + scandir_0400(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/dirent/seekdir.c b/libc-test/src/functionalext/supplement/dirent/seekdir.c new file mode 100644 index 00000000..51a90483 --- /dev/null +++ b/libc-test/src/functionalext/supplement/dirent/seekdir.c @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include "test.h" + +const char *path = "/data"; + +void handler(int sig) +{ + exit(t_status); +} + +/** + * @tc.name : seekdir_0100 + * @tc.desc : set the position of the next readdir() call in the directory stream + * @tc.level : Level 0 + */ +void seekdir_0100(void) +{ + DIR *dir = opendir(path); + if (dir == NULL) { + t_error("%s failed: opendir. path = %s\n", __func__, path); + } + + int counter = 0; + struct dirent *result; + long offset = 0; + while ((result = readdir(dir)) != NULL) { + counter++; + + if (counter > 1) { + offset = telldir(dir); + break; + } + } + + result = readdir(dir); + if (result == NULL) { + t_error("%s failed: readdir\n", __func__); + } + + char d_name[BUFSIZ] = {0}; + strcpy(d_name, result->d_name); + + errno = 0; + seekdir(dir, offset); + if (errno != 0) { + t_error("%s failed: seekdir. errno = %d\n", __func__, errno); + } + + result = readdir(dir); + if (result == NULL) { + t_error("%s failed: readdir\n", __func__); + } + + if (strcmp(result->d_name, d_name)) { + t_error("%s failed: strcmp. result->d_name = %s, d_name = %s\n", __func__, result->d_name, d_name); + } + + closedir(dir); +} + +/** + * @tc.name : seekdir_0200 + * @tc.desc : set the position of the next readdir() call in the directory stream to zero + * @tc.level : Level 1 + */ +void seekdir_0200(void) +{ + DIR *dir = opendir(path); + if (dir == NULL) { + t_error("%s failed: opendir. path = %s\n", __func__, path); + } + + struct dirent *result = readdir(dir); + if (result == NULL) { + t_error("%s failed: readdir\n", __func__); + } + + char d_name[BUFSIZ] = {0}; + strcpy(d_name, result->d_name); + + errno = 0; + seekdir(dir, 0); + if (errno != 0) { + t_error("%s failed: seekdir. errno = %d\n", __func__, errno); + } + + result = readdir(dir); + if (result == NULL) { + t_error("%s failed: readdir\n", __func__); + } + + if (strcmp(result->d_name, d_name)) { + t_error("%s failed: strcmp. result->d_name = %s, d_name = %s\n", __func__, result->d_name, d_name); + } + + closedir(dir); +} + +/** + * @tc.name : seekdir_0300 + * @tc.desc : set the position of the next readdir() call in the directory stream with NULL + * @tc.level : Level 2 + */ +void seekdir_0300(void) +{ + signal(SIGSEGV, handler); + + DIR *dir = NULL; + seekdir(dir, -1); +} + +int main(int argc, char *argv[]) +{ + seekdir_0100(); + seekdir_0200(); + seekdir_0300(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/dirent/telldir.c b/libc-test/src/functionalext/supplement/dirent/telldir.c new file mode 100644 index 00000000..93e1f784 --- /dev/null +++ b/libc-test/src/functionalext/supplement/dirent/telldir.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +const char *path = "/data"; + +void handler(int sig) +{ + exit(t_status); +} + +/** + * @tc.name : telldir_0100 + * @tc.desc : Get the current read position of the parameter dir directory stream + * @tc.level : Level 0 + */ +void telldir_0100(void) +{ + DIR *dir; + struct dirent *ptr; + int counter = 0; + dir = opendir(path); + long offset1 = telldir(dir); + long offset2 = 0; + while ((ptr = readdir(dir)) != NULL) { + counter++; + + if (counter > 1) { + offset2 = telldir(dir); + break; + } + } + if (offset1 == offset2) { + t_error("%s offset2 invalid", __func__); + } + closedir(dir); +} + +/** + * @tc.name : telldir_0200 + * @tc.desc : Catch exception when parameter dir is NULL + * @tc.level : Level 2 + */ +void telldir_0200(void) +{ + signal(SIGSEGV, handler); + + DIR *dir = NULL; + telldir(dir); +} + +int main(int argc, char *argv[]) +{ + telldir_0100(); + telldir_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/dirent/test_src_functionalext_supplement_dirent.gni b/libc-test/src/functionalext/supplement/dirent/test_src_functionalext_supplement_dirent.gni new file mode 100644 index 00000000..e0cbd222 --- /dev/null +++ b/libc-test/src/functionalext/supplement/dirent/test_src_functionalext_supplement_dirent.gni @@ -0,0 +1,26 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_dirent_test = [ + "dirfd", + "fdopendir", + "opendir", + "readdir_r", + "readdir", + "rewinddir", + "scandir", + "seekdir", + "closedir", + "telldir", + "alphasort", +] diff --git a/libc-test/src/functionalext/supplement/env/BUILD.gn b/libc-test/src/functionalext/supplement/env/BUILD.gn new file mode 100644 index 00000000..eea79ebb --- /dev/null +++ b/libc-test/src/functionalext/supplement/env/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_env.gni") + +foreach(s, functionalext_supplement_env_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/env" + } +} + +group("functionalext_supplement_env_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_env_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/env/putenv.c b/libc-test/src/functionalext/supplement/env/putenv.c new file mode 100755 index 00000000..99192bf2 --- /dev/null +++ b/libc-test/src/functionalext/supplement/env/putenv.c @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : putenv_0100 + * @tc.desc : Add or change the environment variable test + * @tc.level : Level 0 + */ +void putenv_0100(void) +{ + int ret = unsetenv("test"); + EXPECT_EQ("putenv_0100", ret, CMPFLAG); + + ret = putenv("test=putenv_0100"); + EXPECT_EQ("putenv_0100", ret, CMPFLAG); + char *test = getenv("test"); + if (test) { + EXPECT_STREQ("putenv_0100", test, "putenv_0100"); + } else { + EXPECT_PTRNE("putenv_0100", test, NULL); + } + + ret = putenv("test=putenv_new"); + EXPECT_EQ("putenv_0100", ret, CMPFLAG); + test = getenv("test"); + EXPECT_PTRNE("putenv_0100", test, NULL); + if (test) { + EXPECT_STREQ("putenv_0100", test, "putenv_new"); + } + unsetenv("test"); +} + +/** + * @tc.name : putenv_0200 + * @tc.desc : Provide exception parameters, add or modify the environment variable test + * @tc.level : Level 2 + */ +void putenv_0200(void) +{ + int ret = unsetenv("test"); + EXPECT_EQ("putenv_0200", ret, CMPFLAG); + + ret = putenv("test"); + EXPECT_EQ("putenv_0200", ret, CMPFLAG); + char *test = getenv("test"); + if (!test) { + EXPECT_PTREQ("putenv_0200", test, NULL); + } + + ret = putenv(""); + EXPECT_EQ("putenv_0200", ret, ERREXPECT); + unsetenv("test"); +} + +int main(void) +{ + putenv_0100(); + putenv_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/env/test_src_functionalext_supplement_env.gni b/libc-test/src/functionalext/supplement/env/test_src_functionalext_supplement_env.gni new file mode 100644 index 00000000..46a81726 --- /dev/null +++ b/libc-test/src/functionalext/supplement/env/test_src_functionalext_supplement_env.gni @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_env_test = [ "putenv" ] diff --git a/libc-test/src/functionalext/supplement/errno/BUILD.gn b/libc-test/src/functionalext/supplement/errno/BUILD.gn new file mode 100644 index 00000000..15eac5ac --- /dev/null +++ b/libc-test/src/functionalext/supplement/errno/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_errno.gni") + +foreach(s, functionalext_supplement_errno_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/errno" + } +} + +group("functionalext_supplement_errno_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_errno_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/errno/__errno_location.c b/libc-test/src/functionalext/supplement/errno/__errno_location.c new file mode 100644 index 00000000..5a08a958 --- /dev/null +++ b/libc-test/src/functionalext/supplement/errno/__errno_location.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : __errno_location_0100 + * @tc.desc : Test the __errno_location method to get the errno address + * @tc.level : Level 0 + */ +void __errno_location_0100(void) +{ + int result = *__errno_location(); + if (result != 0) { + t_error("%s __errno_location get errno code is %d are not want 0\n", __func__, result); + } +} + +/** + * @tc.name : __errno_location_0200 + * @tc.desc : The result returned by __errno_location when the value of errno has just been changed + * @tc.level : Level 1 + */ +void __errno_location_0200(void) +{ + errno = 10; + int result = *__errno_location(); + if (result != errno) { + t_error("%s __errno_location get errno code is %d are not want %d\n", __func__, result, errno); + } + errno = 0; +} + +/** + * @tc.name : __errno_location_0300 + * @tc.desc : Test the address returned by __errno_location and compare it with the errno address + * @tc.level : Level 1 + */ +void __errno_location_0300(void) +{ + int *result = __errno_location(); + if (result != &errno) { + t_error("%s __errno_location get ptr is %p are not want %p\n", __func__, result, &errno); + } +} + +int main(int argc, char *argv[]) +{ + __errno_location_0100(); + __errno_location_0200(); + __errno_location_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/errno/strerror.c b/libc-test/src/functionalext/supplement/errno/strerror.c new file mode 100644 index 00000000..01abf306 --- /dev/null +++ b/libc-test/src/functionalext/supplement/errno/strerror.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : strerror_0100 + * @tc.desc : Verify strerror process success when param is EILSEQ + * @tc.level : Level 0 + */ +void strerror_0100(void) +{ + char *ret = strerror(EILSEQ); + EXPECT_STREQ("strerror_0100", ret, "Illegal byte sequence"); +} + +/** + * @tc.name : strerror_0200 + * @tc.desc : Verify strerror process success when param is 0 + * @tc.level : Level 0 + */ +void strerror_0200(void) +{ + char *ret = strerror(0); + EXPECT_STREQ("strerror_0200", ret, "No error information"); +} + +int main(void) +{ + strerror_0100(); + strerror_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/errno/test_src_functionalext_supplement_errno.gni b/libc-test/src/functionalext/supplement/errno/test_src_functionalext_supplement_errno.gni new file mode 100644 index 00000000..8a873ae7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/errno/test_src_functionalext_supplement_errno.gni @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_errno_test = [ + "__errno_location", + "strerror", +] diff --git a/libc-test/src/functionalext/supplement/exit/BUILD.gn b/libc-test/src/functionalext/supplement/exit/BUILD.gn new file mode 100644 index 00000000..45c1704f --- /dev/null +++ b/libc-test/src/functionalext/supplement/exit/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_exit.gni") + +foreach(s, functionalext_supplement_exit_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/exit" + } +} + +group("functionalext_supplement_exit_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_exit_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/exit/__aeabi_atexit.c b/libc-test/src/functionalext/supplement/exit/__aeabi_atexit.c new file mode 100644 index 00000000..8962ecd5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/exit/__aeabi_atexit.c @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +int __cxa_atexit(void (*func)(void *), void *arg, void *dso); +int __aeabi_atexit(void *obj, void (*func)(void *), void *d) +{ + return __cxa_atexit(func, obj, d); +} +const int32_t COUNT_ZERO = 0; + +/* + * @tc.name : aeabi_atexit_0100 + * @tc.desc : Verify that __aeabi_atexit is called correctly (all arguments are valid) + * @tc.level : Level 0 + */ +void aeabi_atexit_0100() +{ + int result; + result = __aeabi_atexit(NULL, NULL, NULL); + EXPECT_EQ("aeabi_atexit_0100", result, COUNT_ZERO); +} + +TEST_FUN G_Fun_Array[] = { + aeabi_atexit_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/exit/a_cxa_atexit.c b/libc-test/src/functionalext/supplement/exit/a_cxa_atexit.c new file mode 100644 index 00000000..b0f7d30d --- /dev/null +++ b/libc-test/src/functionalext/supplement/exit/a_cxa_atexit.c @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +extern int __cxa_atexit(void (*func)(void *), void *arg, void *dso); +const int32_t INVALID_LEN = -1; +const int32_t INIT_LEN = 0; +const int32_t INCREASE_LEN = 1; +const int32_t COUNT = 32; +const int32_t SLOT_LEN = 10; +void exitFunc(void *arg){}; + +/** + * @tc.name: cxa_atexit_0100 + * @tc.desc: Verify cxa_atexit process success when second and third args is null. + * @tc.level: level 1. + */ +void cxa_atexit_0100(void) +{ + int32_t ret = __cxa_atexit(exitFunc, NULL, NULL); + EXPECT_EQ("cxa_atexit_0100", ret, INIT_LEN); +} + +/** + * @tc.name: cxa_atexit_0200 + * @tc.desc: Verify cxa atexit process success when third args is null and slot less than COUNT. + * @tc.level: level 0. + */ +void cxa_atexit_0200(void) +{ + int32_t slot = SLOT_LEN; + int32_t var = INIT_LEN; + int32_t ret = __cxa_atexit(exitFunc, &var, NULL); + EXPECT_LT("cxa_atexit_0200", slot + INCREASE_LEN, COUNT); + EXPECT_EQ("cxa_atexit_0200", ret, 0); +} + +/** + * @tc.name: cxa_atexit_0300 + * @tc.desc: Verify cxa atexit process success when third args is null and slot equal COUNT. + * @tc.level: level 1. + */ +void cxa_atexit_0300(void) +{ + int32_t slot = COUNT; + int32_t var = 0; + int32_t ret = __cxa_atexit(exitFunc, &var, NULL); + EXPECT_EQ("cxa_atexit_0300", slot, COUNT); + EXPECT_EQ("cxa_atexit_0300", ret, 0); +} + +int main(int argc, char *argv[]) +{ + cxa_atexit_0100(); + cxa_atexit_0200(); + cxa_atexit_0300(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/exit/a_cxa_finalize.c b/libc-test/src/functionalext/supplement/exit/a_cxa_finalize.c new file mode 100644 index 00000000..30b6aaa5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/exit/a_cxa_finalize.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +extern void __cxa_finalize(void *dso); + +const int32_t INIT_LEN = 0; +const int32_t INCREASE_LEN = 1; +int32_t flag = 0; + +void FinalizeFunc() +{ + flag++; +} + +/** + * @tc.name: cxa_finalize_0100 + * @tc.desc: Verify cxa finalize process success. + * @tc.level: level 0. + */ +void cxa_finalize_0100(void) +{ + int ret = atexit(FinalizeFunc); + EXPECT_EQ("cxa_finalize_0100", ret, 0); + __cxa_finalize(NULL); + EXPECT_EQ("cxa_finalize_0100", flag, INCREASE_LEN); +} + +int main(void) +{ + cxa_finalize_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/exit/at_quick_exit.c b/libc-test/src/functionalext/supplement/exit/at_quick_exit.c new file mode 100644 index 00000000..5cced14e --- /dev/null +++ b/libc-test/src/functionalext/supplement/exit/at_quick_exit.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; +void f1() +{} +void f2() +{} + +/** + * @tc.name : at_quick_exit_0100 + * @tc.desc : Verify that the function pointed to can be registered + * (the number of registrations is less than 32). + * @tc.level : Level 0 + */ +void at_quick_exit_0100(void) +{ + int result = at_quick_exit(f1); + quick_exit(0); + EXPECT_EQ("at_quick_exit_0100", result, SUCCESS); +} + +/** + * @tc.name : at_quick_exit_0200 + * @tc.desc : Verify that the pointed function cannot be registered + * (the number of registrations is greater than 32). + * @tc.level : Level 2 + */ +void at_quick_exit_0200(void) +{ + int result; + for (int i = 0; i < 32; i++) { + at_quick_exit(f2); + } + result = at_quick_exit(f2); + quick_exit(0); + EXPECT_EQ("at_quick_exit_0200", result, FAILED); +} + +int main(int argc, char *argv[]) +{ + at_quick_exit_0100(); + at_quick_exit_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/exit/atexit.c b/libc-test/src/functionalext/supplement/exit/atexit.c new file mode 100644 index 00000000..e9961c30 --- /dev/null +++ b/libc-test/src/functionalext/supplement/exit/atexit.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +void atexit_0100(void) +{ + printf("%s this is end msg\n", __func__); +} + +/** + * @tc.name : atexit_0100 + * @tc.desc : Execute function when testing atexit method registration and exit + * @tc.level : Level 0 + */ +int main(int argc, char *argv[]) +{ + int result = atexit(atexit_0100); + if (result != 0) { + t_error("atexit_0100 error get result is not 0\n"); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/exit/quick_exit.c b/libc-test/src/functionalext/supplement/exit/quick_exit.c new file mode 100755 index 00000000..2ec85e5f --- /dev/null +++ b/libc-test/src/functionalext/supplement/exit/quick_exit.c @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "functionalext.h" + +/** + * @tc.name : quick_exit_0100 + * @tc.desc : The main thread creates a child thread, the child thread calls quick exit to exit, + * and the child thread exit status is received in the child thread + * @tc.level : Level 0 + */ +void quick_exit_0100(void) +{ + int status; + pid_t pid = fork(); + if (pid == 0) { + sleep(1); + quick_exit(EXIT_SUCCESS); + } else if (pid > 0) { + wait(&status); + if (WIFEXITED(status)) { + EXPECT_EQ("quick_exit_0100", EXIT_SUCCESS, WEXITSTATUS(status)); + } + } else { + t_error("Fork wrong\n"); + exit(EXIT_FAILURE); + } +} + +int main(void) +{ + quick_exit_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/exit/test_src_functionalext_supplement_exit.gni b/libc-test/src/functionalext/supplement/exit/test_src_functionalext_supplement_exit.gni new file mode 100644 index 00000000..9c13aca4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/exit/test_src_functionalext_supplement_exit.gni @@ -0,0 +1,21 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_exit_test = [ + "a_cxa_atexit", + "a_cxa_finalize", + "at_quick_exit", + "atexit", + "__aeabi_atexit", + "quick_exit", +] diff --git a/libc-test/src/functionalext/supplement/fcntl/BUILD.gn b/libc-test/src/functionalext/supplement/fcntl/BUILD.gn new file mode 100644 index 00000000..4c4b2018 --- /dev/null +++ b/libc-test/src/functionalext/supplement/fcntl/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_fcntl.gni") + +foreach(s, functionalext_supplement_fcntl_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/fcntl" + } +} + +group("functionalext_supplement_fcntl_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_fcntl_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/fcntl/creat.c b/libc-test/src/functionalext/supplement/fcntl/creat.c new file mode 100755 index 00000000..059d2394 --- /dev/null +++ b/libc-test/src/functionalext/supplement/fcntl/creat.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : creat_0100 + * @tc.desc : Each parameter is valid and a new file can be created. + * @tc.level : Level 0 + */ +void creat_0100(void) +{ + int fd = -1; + const char *ptr = "creattest.txt"; + fd = creat(ptr, O_RDWR | O_CREAT); + EXPECT_NE("creat_0100", fd, -1); + close(fd); + remove(ptr); + ptr = NULL; +} + +/** + * @tc.name : creat_0200 + * @tc.desc : The filename parameter is invalid, a new file cannot be created. + * @tc.level : Level 2 + */ +void creat_0200(void) +{ + int fd = 0; + const char *ptr = ""; + fd = open(ptr, O_RDONLY); + EXPECT_EQ("creat_0200", fd, -1); + close(fd); + remove(ptr); + ptr = NULL; +} + +/** + * @tc.name : creat_0300 + * @tc.desc : The mode parameter is invalid and a new file cannot be created. + * @tc.level : Level 0 + */ +void creat_0300(void) +{ + int fd = 0; + const char *ptr = "creattest.txt"; + fd = open(ptr, O_WRONLY); + EXPECT_EQ("creat_0300", fd, -1); + close(fd); + remove(ptr); + ptr = NULL; +} + +int main() +{ + creat_0100(); + creat_0200(); + creat_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/fcntl/open.c b/libc-test/src/functionalext/supplement/fcntl/open.c new file mode 100755 index 00000000..17420d1f --- /dev/null +++ b/libc-test/src/functionalext/supplement/fcntl/open.c @@ -0,0 +1,221 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/* + * @tc.name : open_0100 + * @tc.desc : Verify file open mode is O_RDONLY + * @tc.level : Level 0 + */ +void open_0100(void) +{ + int fd, size; + char s[] = "test"; + char buffer[80] = {0}; + fd = open("/data/test.txt", O_RDONLY + O_CREAT); + if (fd == -1) { + fputs("open r is failed\n", stdout); + } + int len = write(fd, s, sizeof(s)); + size = read(fd, buffer, sizeof(buffer)); + EXPECT_EQ("open_0100", fd, 4); + EXPECT_EQ("open_0100", len, -1); + EXPECT_STREQ("open_0100", buffer, ""); + close(fd); + remove("/data/test.txt"); +} + +/* + * @tc.name : open_0200 + * @tc.desc : Verify file open mode is O_RDONLY (file does not exist) + * @tc.level : Level 2 + */ +void open_0200(void) +{ + int fd; + fd = open("/data/test.txt", O_RDONLY); + EXPECT_EQ("open_0200", fd, -1); + close(fd); +} + +/* + * @tc.name : open_0300 + * @tc.desc : VVerify file open mode is O_WRONLY + * @tc.level : Level 0 + */ +void open_0300(void) +{ + int fd, size; + char s[] = "test"; + char buffer[80] = {0}; + fd = open("/data/test.txt", O_WRONLY + O_CREAT); + if (fd == -1) { + fputs("open r is failed\n", stdout); + } + size = read(fd, buffer, sizeof(buffer)); + EXPECT_EQ("open_0300", fd, 4); + EXPECT_STREQ("open_0300", buffer, ""); + int len = write(fd, s, sizeof(s)); + EXPECT_EQ("open_0300", len, 5); + close(fd); + remove("/data/test.txt"); +} + +/* + * @tc.name : open_0400 + * @tc.desc : VVerify file open mode is O_WRONLY(file does not exist) + * @tc.level : Level 2 + */ +void open_0400(void) +{ + int fd; + fd = open("/data/test.txt", O_WRONLY); + EXPECT_EQ("open_0400", fd, -1); + close(fd); +} + +/* + * @tc.name : open_0500 + * @tc.desc : VVerify file open mode is O_RDWR | O_APPEND + * @tc.level : Level 0 + */ +void open_0500(void) +{ + int fd, size; + char s[] = "test"; + char buffer[80] = {0}; + fd = open("/data/test.txt", O_RDWR | O_APPEND + O_CREAT); + if (fd == -1) { + fputs("open r is failed\n", stdout); + } + size = read(fd, buffer, sizeof(buffer)); + EXPECT_EQ("open_0500", fd, 4); + EXPECT_STREQ("open_0500", buffer, ""); + int len = write(fd, s, sizeof(s)); + EXPECT_EQ("open_0500", len, 5); + close(fd); + remove("/data/test.txt"); +} + +/* + * @tc.name : open_0600 + * @tc.desc : VVerify file open mode is O_RDWR | O_APPEND(file does not exist) + * @tc.level : Level 1 + */ +void open_0600(void) +{ + int fd, size; + char s[] = "test"; + char buffer[80] = {0}; + fd = open("/data/test.txt", O_RDWR | O_APPEND); + size = read(fd, buffer, sizeof(buffer)); + EXPECT_EQ("open_0600", fd, -1); + EXPECT_STREQ("open_0600", buffer, ""); + int len = write(fd, s, sizeof(s)); + EXPECT_EQ("open_0600", len, -1); + close(fd); + remove("/data/test.txt"); +} + +/* + * @tc.name : open_0700 + * @tc.desc : VVerify file open mode is O_RDWR | O_APPEND(file pathname is invalid) + * @tc.level : Level 2 + */ +void open_0700(void) +{ + int fd; + fd = open("/data/test.txt", O_RDWR | O_APPEND); + EXPECT_EQ("open_0700", fd, -1); + close(fd); +} + +/* + * @tc.name : open_0800 + * @tc.desc : VVerify file open mode is O_RDWR | O_CREAT + * @tc.level : Level 0 + */ +void open_0800(void) +{ + int fd, size; + char s[] = "test"; + char buffer[80] = {0}; + fd = open("/data/test.txt", O_RDWR | O_CREAT); + if (fd == -1) { + fputs("open r is failed\n", stdout); + } + size = read(fd, buffer, sizeof(buffer)); + EXPECT_EQ("open_0800", fd, 4); + EXPECT_STREQ("open_0800", buffer, ""); + int len = write(fd, s, sizeof(s)); + EXPECT_EQ("open_0800", len, 5); + close(fd); + remove("/data/test.txt"); +} + +/* + * @tc.name : open_0900 + * @tc.desc : VVerify file open mode is O_RDWR | O_CLOEXEC + * @tc.level : Level 0 + */ +void open_0900(void) +{ + int fd, size; + char s[] = "test"; + char buffer[80] = {0}; + fd = open("/data/test.txt", O_RDWR | O_CLOEXEC + O_CREAT); + if (fd == -1) { + fputs("open r is failed\n", stdout); + } + size = read(fd, buffer, sizeof(buffer)); + EXPECT_EQ("open_1000", fd, 4); + EXPECT_STREQ("open_1000", buffer, ""); + int len = write(fd, s, sizeof(s)); + EXPECT_EQ("open_1000", len, 5); + close(fd); + remove("/data/test.txt"); +} + +TEST_FUN G_Fun_Array[] = { + open_0100, + open_0200, + open_0300, + open_0400, + open_0500, + open_0600, + open_0700, + open_0800, + open_0900, + +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/fcntl/openat.c b/libc-test/src/functionalext/supplement/fcntl/openat.c new file mode 100755 index 00000000..4c63908b --- /dev/null +++ b/libc-test/src/functionalext/supplement/fcntl/openat.c @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define TEST_MODE 0666 +/** + * @tc.name : openat_0100 + * @tc.desc : Open /dev/null + * @tc.level : Level 0 + */ +void openat_0100(void) +{ + int ret = openat(0, "/dev/null", O_CREAT); + EXPECT_NE("openat_0100", ret, ERREXPECT); + + ret = openat(0, "/dev/null", O_TMPFILE); + EXPECT_EQ("openat_0100", ret, ERREXPECT); + + ret = openat(0, "/dev/null", O_RDONLY, TEST_MODE); + EXPECT_NE("openat_0100", ret, ERREXPECT); +} + +/** + * @tc.name : openat_0200 + * @tc.desc : Open file openat_test does not exist + * @tc.level : Level 2 + */ +void openat_0200(void) +{ + int ret = openat(0, "openat_test", O_CREAT); + EXPECT_EQ("openat_0200", ret, ERREXPECT); + + ret = openat(0, "openat_test", O_TMPFILE); + EXPECT_EQ("openat_0200", ret, ERREXPECT); + + ret = openat(0, "openat_test", O_RDONLY, TEST_MODE); + EXPECT_EQ("openat_0200", ret, ERREXPECT); +} + +int main(void) +{ + openat_0100(); + openat_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/fcntl/posix_fadvise.c b/libc-test/src/functionalext/supplement/fcntl/posix_fadvise.c new file mode 100644 index 00000000..f8ce6e16 --- /dev/null +++ b/libc-test/src/functionalext/supplement/fcntl/posix_fadvise.c @@ -0,0 +1,150 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_LEN 10 +#define TEST_FLAG_SIZE 6 +/** + * @tc.name : posix_fadvise_0100 + * @tc.desc : Correct parameters, set file preload size + * @tc.level : Level 0 + */ +void posix_fadvise_0100(void) +{ + FILE *fp = tmpfile(); + if (!fp) { + EXPECT_PTRNE("posix_fadvise_0100", fp, NULL); + return; + } + + int fd = fileno(fp); + EXPECT_TRUE("posix_fadvise_0100", fd != -1); + if (fd == -1) { + fclose(fp); + return; + } + + int flags[TEST_FLAG_SIZE] = {POSIX_FADV_NORMAL, + POSIX_FADV_SEQUENTIAL, + POSIX_FADV_RANDOM, + POSIX_FADV_NOREUSE, + POSIX_FADV_WILLNEED, + POSIX_FADV_DONTNEED}; + int i; + for (i = 0; i < TEST_FLAG_SIZE; i++) { + int ret = posix_fadvise(fd, 0, TEST_LEN, flags[i]); + EXPECT_EQ("posix_fadvise_0100", ret, 0); + } + int rev = fclose(fp); + EXPECT_EQ("posix_fadvise_0100", rev, 0); +} + +/** + * @tc.name : posix_fadvise_0200 + * @tc.desc : Set file preload size to -1 + * @tc.level : Level 2 + */ +void posix_fadvise_0200(void) +{ + FILE *fp = tmpfile(); + if (!fp) { + EXPECT_PTRNE("posix_fadvise_0200", fp, NULL); + return; + } + + int fd = fileno(fp); + EXPECT_TRUE("posix_fadvise_0200", fd != -1); + if (fd == -1) { + fclose(fp); + return; + } + int ret = posix_fadvise(fd, 0, -1, POSIX_FADV_NORMAL); + EXPECT_EQ("posix_fadvise_0200", ret, EINVAL); + ret = fclose(fp); + EXPECT_EQ("posix_fadvise_0200", ret, 0); +} + +/** + * @tc.name : posix_fadvise_0300 + * @tc.desc : Set file preload offset to -1 + * @tc.level : Level 0 + */ +void posix_fadvise_0300(void) +{ + FILE *fp = tmpfile(); + if (!fp) { + EXPECT_PTRNE("posix_fadvise_0300", fp, NULL); + return; + } + + int fd = fileno(fp); + EXPECT_TRUE("posix_fadvise_0300", fd != -1); + if (fd == -1) { + fclose(fp); + return; + } + int ret = posix_fadvise(fd, -1, TEST_LEN, POSIX_FADV_NORMAL); + EXPECT_EQ("posix_fadvise_0300", ret, 0); + ret = fclose(fp); + EXPECT_EQ("posix_fadvise_0300", ret, 0); +} + +/** + * @tc.name : posix_fadvise_0400 + * @tc.desc : set wrong file descriptor + * @tc.level : Level 2 + */ +void posix_fadvise_0400(void) +{ + int ret = posix_fadvise(-1, 0, TEST_LEN, POSIX_FADV_NORMAL); + EXPECT_EQ("posix_fadvise_0400", ret, EBADF); +} + +/** + * @tc.name : posix_fadvise_0500 + * @tc.desc : set wrong flag + * @tc.level : Level 2 + */ +void posix_fadvise_0500(void) +{ + FILE *fp = tmpfile(); + if (!fp) { + EXPECT_PTRNE("posix_fadvise_0500", fp, NULL); + return; + } + + int fd = fileno(fp); + EXPECT_TRUE("posix_fadvise_0500", fd != -1); + if (fd == -1) { + fclose(fp); + return; + } + int ret = posix_fadvise(fd, 0, TEST_LEN, -1); + EXPECT_EQ("posix_fadvise_0500", ret, EINVAL); + ret = fclose(fp); + EXPECT_EQ("posix_fadvise_0500", ret, 0); +} + +int main(void) +{ + posix_fadvise_0100(); + posix_fadvise_0200(); + posix_fadvise_0300(); + posix_fadvise_0400(); + posix_fadvise_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/fcntl/posix_fallocate.c b/libc-test/src/functionalext/supplement/fcntl/posix_fallocate.c new file mode 100644 index 00000000..0959c8bc --- /dev/null +++ b/libc-test/src/functionalext/supplement/fcntl/posix_fallocate.c @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define TEST_LEN 10 + +/** + * @tc.name : posix_fallocate_0100 + * @tc.desc : Allocate a specified amount of storage space for a file + * @tc.level : Level 0 + */ +void posix_fallocate_0100(void) +{ + struct stat sb; + FILE *fp = tmpfile(); + if (!fp) { + EXPECT_PTRNE("posix_fallocate_0100", fp, NULL); + return; + } + + int fd = fileno(fp); + EXPECT_TRUE("posix_fallocate_0100", fd != -1); + if (fd == -1) { + fclose(fp); + return; + } + int ret = posix_fallocate(fd, 0, TEST_LEN); + EXPECT_EQ("posix_fallocate_0100", ret, 0); + ret = fstat(fd, &sb); + EXPECT_EQ("posix_fallocate_0100", ret, 0); + EXPECT_EQ("posix_fallocate_0100", sb.st_size, TEST_LEN); + ret = fclose(fp); + EXPECT_EQ("posix_fallocate_0100", ret, 0); +} + +/** + * @tc.name : posix_fallocate_0200 + * @tc.desc : Allocate -1 byte of storage for the file + * @tc.level : Level 2 + */ +void posix_fallocate_0200(void) +{ + FILE *fp = tmpfile(); + if (!fp) { + EXPECT_PTRNE("posix_fallocate_0200", fp, NULL); + return; + } + + int fd = fileno(fp); + EXPECT_TRUE("posix_fallocate_0200", fd != -1); + if (fd == -1) { + fclose(fp); + return; + } + int ret = posix_fallocate(fd, 0, -1); + EXPECT_EQ("posix_fallocate_0200", ret, EINVAL); + ret = fclose(fp); + EXPECT_EQ("posix_fallocate_0200", ret, 0); +} + +/** + * @tc.name : posix_fallocate_0300 + * @tc.desc : At file offset -1 byte, allocate 10 bytes of storage for the file + * @tc.level : Level 2 + */ +void posix_fallocate_0300(void) +{ + FILE *fp = tmpfile(); + if (!fp) { + EXPECT_PTRNE("posix_fallocate_0300", fp, NULL); + return; + } + + int fd = fileno(fp); + EXPECT_TRUE("posix_fallocate_0300", fd != -1); + if (fd == -1) { + fclose(fp); + return; + } + int ret = posix_fallocate(fd, -1, TEST_LEN); + EXPECT_EQ("posix_fallocate_0300", ret, EINVAL); + ret = fclose(fp); + EXPECT_EQ("posix_fallocate_0300", ret, 0); +} + +/** + * @tc.name : posix_fallocate_0400 + * @tc.desc : Bad file handle provided, allocating 10 bytes of storage for file + * @tc.level : Level 2 + */ +void posix_fallocate_0400(void) +{ + int ret = posix_fallocate(-1, 0, TEST_LEN); + EXPECT_EQ("posix_fallocate_0400", ret, EBADF); +} + +int main(void) +{ + posix_fallocate_0100(); + posix_fallocate_0200(); + posix_fallocate_0300(); + posix_fallocate_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/fcntl/test_src_functionalext_supplement_fcntl.gni b/libc-test/src/functionalext/supplement/fcntl/test_src_functionalext_supplement_fcntl.gni new file mode 100644 index 00000000..b8646e13 --- /dev/null +++ b/libc-test/src/functionalext/supplement/fcntl/test_src_functionalext_supplement_fcntl.gni @@ -0,0 +1,20 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_fcntl_test = [ + "posix_fallocate", + "posix_fadvise", + "open", + "creat", + "openat", +] diff --git a/libc-test/src/functionalext/supplement/fenv/BUILD.gn b/libc-test/src/functionalext/supplement/fenv/BUILD.gn new file mode 100644 index 00000000..e90c3556 --- /dev/null +++ b/libc-test/src/functionalext/supplement/fenv/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_fenv.gni") + +foreach(s, functionalext_supplement_fenv_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/fenv" + } +} + +group("functionalext_supplement_fenv_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_fenv_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/fenv/__flt_rounds.c b/libc-test/src/functionalext/supplement/fenv/__flt_rounds.c new file mode 100644 index 00000000..3239978a --- /dev/null +++ b/libc-test/src/functionalext/supplement/fenv/__flt_rounds.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : sendmmsg_0100 + * @tc.desc : Test __flt_rounds to get the floating point value mode + * @tc.level : Level 0 + */ +void __flt_rounds_0100(void) +{ + int result = __flt_rounds(); + if (result != 1) { + t_error("%s __flt_rounds error get result is %d are not want 1\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + __flt_rounds_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/fenv/feholdexcept.c b/libc-test/src/functionalext/supplement/fenv/feholdexcept.c new file mode 100644 index 00000000..b99af061 --- /dev/null +++ b/libc-test/src/functionalext/supplement/fenv/feholdexcept.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : feholdexcept_0100 + * @tc.desc : The parameter is valid and can save the current floating point environment. + * @tc.level : Level 0 + */ +void feholdexcept_0100(void) +{ + int ret = -1; + fenv_t envp; + ret = feholdexcept(&envp); + EXPECT_EQ("feholdexcept_0100", ret, 0); +} + +int main(int argc, char *argv[]) +{ + feholdexcept_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/fenv/feupdateenv.c b/libc-test/src/functionalext/supplement/fenv/feupdateenv.c new file mode 100644 index 00000000..17b5a643 --- /dev/null +++ b/libc-test/src/functionalext/supplement/fenv/feupdateenv.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : feupdateenv_0100 + * @tc.desc : The parameter is valid and can save the currently raised floating-point exception. + * @tc.level : Level 0 + */ +void feupdateenv_0100(void) +{ + int ret = -1; + fenv_t envp; + ret = feupdateenv(&envp); + EXPECT_EQ("feupdateenv_0100", ret, 0); +} + +int main(int argc, char *argv[]) +{ + feupdateenv_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/fenv/test_src_functionalext_supplement_fenv.gni b/libc-test/src/functionalext/supplement/fenv/test_src_functionalext_supplement_fenv.gni new file mode 100644 index 00000000..4d8f18a4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/fenv/test_src_functionalext_supplement_fenv.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_fenv_test = [ + "__flt_rounds", + "feholdexcept", + "feupdateenv", +] diff --git a/libc-test/src/functionalext/supplement/ipc/BUILD.gn b/libc-test/src/functionalext/supplement/ipc/BUILD.gn new file mode 100644 index 00000000..ed416f3d --- /dev/null +++ b/libc-test/src/functionalext/supplement/ipc/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_ipc.gni") + +foreach(s, functionalext_supplement_ipc_list) { + test_unittest(s) { + target_dir = "functionalext/supplement/ipc" + } +} + +group("functionalext_supplement_ipc_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_ipc_list) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/ipc/ftok.c b/libc-test/src/functionalext/supplement/ipc/ftok.c new file mode 100755 index 00000000..efc0af0e --- /dev/null +++ b/libc-test/src/functionalext/supplement/ipc/ftok.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" +int failed = -1; + +/* + * @tc.name : ftok_0100 + * @tc.desc : Verify that the ket_t value can be obtained (the parameter is valid) + * @tc.level : Level 0 + */ +void ftok_0100(void) +{ + key_t result = ftok("/data/tests/libc-test/src/functionalext/supplement/ipc/ftok", 1); + EXPECT_NE("ftok_0100", result, failed); +} + +/* + * @tc.name : ftok_0200 + * @tc.desc : Validation cannot get ket_t value (parameter invalid) + * @tc.level : Level 2 + */ +void ftok_0200(void) +{ + key_t result = ftok("./test", 1); + EXPECT_EQ("ftok_0200", result, failed); +} +int main(int argc, char *argv[]) +{ + ftok_0100(); + ftok_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ipc/semtimedop.c b/libc-test/src/functionalext/supplement/ipc/semtimedop.c new file mode 100644 index 00000000..e6677e67 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ipc/semtimedop.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "test.h" + +const char *path = "/data/tests/libc-test/src/file.txt"; + +/** + * @tc.name : semtimedop_0100 + * @tc.desc : System V semaphore operations + * @tc.level : Level 0 + */ +void semtimedop_0100(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + if (fd < 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + } + + char str[] = "hello"; + write(fd, str, sizeof(str)); + close(fd); + + // create a semaphore + key_t key = ftok(path, 1); + int id = semget(key, 1, IPC_CREAT | 0666); + + // check semaphore info + struct semid_ds ds; + memset(&ds, 0, sizeof(ds)); + + semctl(id, 0, IPC_STAT, &ds); + semctl(id, 0, GETVAL); + + // increment + struct sembuf ops[] = {{.sem_num = 0, .sem_op = 1, .sem_flg = 0}}; + semop(id, ops, 1); + semctl(id, 0, GETVAL); + + // test timeouts + struct timespec ts = {.tv_sec = 0, .tv_nsec = 100}; + ops[0].sem_num = 0; + ops[0].sem_op = 0; + ops[0].sem_flg = 0; + + errno = 0; + int result = semtimedop(id, ops, sizeof(ops) / sizeof(struct sembuf), &ts); + if (result != -1) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno != EAGAIN) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + semctl(id, 0, GETVAL); + + // decrement. + ops[0].sem_num = 0; + ops[0].sem_op = -1; + ops[0].sem_flg = 0; + + semop(id, ops, 1); + semctl(id, 0, GETVAL); + + // destroy the semaphore + semctl(id, 0, IPC_RMID); +} + +/** + * @tc.name : semtimedop_0200 + * @tc.desc : System V semaphore operations with invalid parameters + * @tc.level : Level 2 + */ +void semtimedop_0200(void) +{ + errno = 0; + int result = semtimedop(-1, NULL, -1, NULL); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno == 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + // semtimedop_0100(); + // semtimedop_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/ipc/test_src_functionalext_supplement_ipc.gni b/libc-test/src/functionalext/supplement/ipc/test_src_functionalext_supplement_ipc.gni new file mode 100644 index 00000000..2b732133 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ipc/test_src_functionalext_supplement_ipc.gni @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_ipc_list = [ + "semtimedop", + "ftok", +] diff --git a/libc-test/src/functionalext/supplement/ldso/BUILD.gn b/libc-test/src/functionalext/supplement/ldso/BUILD.gn new file mode 100644 index 00000000..7e612929 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ldso/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_ldso.gni") + +foreach(s, functionalext_supplement_ldso_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/ldso" + } +} + +group("functionalext_supplement_ldso_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_ldso_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/ldso/a_gnu_Unwind_Find_exidx.c b/libc-test/src/functionalext/supplement/ldso/a_gnu_Unwind_Find_exidx.c new file mode 100644 index 00000000..9dfa008c --- /dev/null +++ b/libc-test/src/functionalext/supplement/ldso/a_gnu_Unwind_Find_exidx.c @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "functionalext.h" + +uintptr_t __gnu_Unwind_Find_exidx(uintptr_t pc, int *pcount); + +const int32_t INIT_LEN = 0; +const int32_t COUNT = 32; + +/** + * @tc.name: a_gnu_Unwind_Find_exidx_0100 + * @tc.desc: Verify gnu Unwind Find exidx process success. + * @tc.level: level 2. + */ +void a_gnu_Unwind_Find_exidx_0100(void) +{ + uintptr_t pc = INIT_LEN; + int32_t pcount = COUNT; + int32_t ret = __gnu_Unwind_Find_exidx(pc, &pcount); + EXPECT_EQ("a_gnu_Unwind_Find_exidx_0100", ret, INIT_LEN); +} + +int main(void) +{ + a_gnu_Unwind_Find_exidx_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/ldso/dl_iterate_phdr.c b/libc-test/src/functionalext/supplement/ldso/dl_iterate_phdr.c new file mode 100644 index 00000000..2cda1eb1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ldso/dl_iterate_phdr.c @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "functionalext.h" + +static int header_handler(struct dl_phdr_info *info, size_t size, void *data) +{ + void *addrhead = (void *)(info->dlpi_addr + info->dlpi_phdr[0].p_vaddr); + if ((strcmp(info->dlpi_name, "/data/libtest.so") == 0) && (addrhead != NULL)) { + return 1; + } + return 0; +} + +/** + * @tc.name : dl_iterate_phdr_0100 + * @tc.desc : The parameter is valid, get the starting address of the dynamic library loaded in the memory. + * @tc.level : Level 0 + */ +void dl_iterate_phdr_0100(void) +{ + system("cp /system/lib/libutils.z.so /data/libtest.so"); + void *handle = dlopen("/data/libtest.so", RTLD_NOW); + int ret = 0; + ret = dl_iterate_phdr(header_handler, NULL); + EXPECT_EQ("dl_iterate_phdr_0100", (int)ret, 1); + system("rm -rf /data/libtest.so"); + exit(EXIT_SUCCESS); +} + +int main() +{ + dl_iterate_phdr_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ldso/dladdr.c b/libc-test/src/functionalext/supplement/ldso/dladdr.c new file mode 100644 index 00000000..b3b6cbef --- /dev/null +++ b/libc-test/src/functionalext/supplement/ldso/dladdr.c @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "functionalext.h" + +void test1() +{} + +/** + * @tc.name : dladdr_0100 + * @tc.desc : Each parameter is valid, you can get the module, name and address where a function is located. + * @tc.level : Level 0 + */ +void dladdr_0100(void) +{ + Dl_info info; + info.dli_fname = 0; + int num = 0; + int ret = dladdr((void *)test1, &info); + EXPECT_EQ("dladdr_0100", ret, 1); + char *name = "dladdr"; + if (strstr(info.dli_fname, name)) { + num = 1; + } else { + num = 2; + } + EXPECT_EQ("dladdr_0100", num, 1); +} + +/** + * @tc.name : dladdr_0200 + * @tc.desc : Each parameter is invalid, you can get the module, name and address where a function is located. + * @tc.level : Level 2 + */ +void dladdr_0200(void) +{ + Dl_info info; + info.dli_fname = 0; + int num = 0; + int ret = dladdr(NULL, &info); + EXPECT_EQ("dladdr_0100", ret, 0); + if (info.dli_fname == NULL) { + num = 1; + } else { + num = 2; + } + EXPECT_EQ("dladdr_0200", num, 1); +} + +int main() +{ + dladdr_0100(); + dladdr_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/ldso/test_src_functionalext_supplement_ldso.gni b/libc-test/src/functionalext/supplement/ldso/test_src_functionalext_supplement_ldso.gni new file mode 100644 index 00000000..46e1b683 --- /dev/null +++ b/libc-test/src/functionalext/supplement/ldso/test_src_functionalext_supplement_ldso.gni @@ -0,0 +1,23 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") + +functionalext_supplement_ldso_test = [ + "dl_iterate_phdr", + "dladdr", +] + +if (musl_arch == "arm") { + functionalext_supplement_ldso_test += [ "a_gnu_Unwind_Find_exidx" ] +} diff --git a/libc-test/src/functionalext/supplement/legacy/BUILD.gn b/libc-test/src/functionalext/supplement/legacy/BUILD.gn new file mode 100644 index 00000000..5f83ead6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/legacy/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_legacy.gni") + +foreach(s, functionalext_supplement_legacy_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/legacy" + } +} + +group("functionalext_supplement_legacy_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_legacy_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/legacy/daemon.c b/libc-test/src/functionalext/supplement/legacy/daemon.c new file mode 100755 index 00000000..ec15a334 --- /dev/null +++ b/libc-test/src/functionalext/supplement/legacy/daemon.c @@ -0,0 +1,101 @@ +#include +#include +#include "functionalext.h" + +int successfully = 0; +int failed = -1; +typedef void (*TEST_FUN)(); + +/* + * @tc.name : daemon_0100 + * @tc.desc : Verify that the working directory of the daemon can be changed (parameters is 0) + * @tc.level : Level 0 + */ +void daemon_0100(void) +{ + pid_t pid; + int result = daemon(0, 0); + EXPECT_EQ("daemon_0100", result, successfully); +} + +/* + * @tc.name : daemon_0200 + * @tc.desc : Verify that the working directory of the daemon can be changed (parameters is 7) + * @tc.level : Level 0 + */ +void daemon_0200(void) +{ + pid_t pid; + int result = daemon(7, 0); + EXPECT_EQ("daemon_0200", result, successfully); + int fd = open("/dev/null", O_RDWR); + EXPECT_EQ("daemon_0200", fd, successfully); +} + +/* + * @tc.name : daemon_0300 + * @tc.desc : Verify that the working directory of the daemon cannot be changed + * (the nochdir parameter has no effect) + * @tc.level : Level 2 + */ +void daemon_0300(void) +{ + pid_t pid; + int result = daemon(0, -1); + EXPECT_EQ("daemon_0300", result, failed); +} + +/* + * @tc.name : daemon_0400 + * @tc.desc : Verify that the working directory of the daemon cannot be changed + * (the noclose parameter has no effect) + * @tc.level : Level 2 + */ +void daemon_0400(void) +{ + pid_t pid; + int result = daemon(-1, -1); + EXPECT_EQ("daemon_0400", result, failed); + int fd = open("/dev/null", O_RDWR); + EXPECT_EQ("daemon_0400", fd, failed); +} + +/* + * @tc.name : daemon_0500 + * @tc.desc : Verify that the working directory of the daemon cannot be changed (parameter invalid) + * @tc.level : Level 2 + */ +void daemon_0500(void) +{ + pid_t pid; + int result = daemon(0, 0); + EXPECT_EQ("daemon_0500", result, successfully); + pid = fork(); + EXPECT_EQ("daemon_0500", pid, failed); +} + +/* + * @tc.name : daemon_0600 + * @tc.desc : Verify that the working directory of the daemon cannot be changed (parameter invalid) + * @tc.level : Level 2 + */ +void daemon_0600(void) +{ + pid_t pid; + int result = daemon(0, 0); + EXPECT_EQ("daemon_0600", result, successfully); + int mode = setsid(); + EXPECT_EQ("daemon_0600", mode, failed); +} + +int main() +{ + daemon_0100(); + daemon_0200(); + daemon_0300(); + daemon_0400(); + daemon_0500(); + daemon_0600(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/legacy/ftw.c b/libc-test/src/functionalext/supplement/legacy/ftw.c new file mode 100644 index 00000000..9f963f23 --- /dev/null +++ b/libc-test/src/functionalext/supplement/legacy/ftw.c @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int FAIL = -1; +int fn(const char *file, const struct stat *sb, int flag) +{ + return 0; +} + +/** + * @tc.name : ftw_0100 + * @tc.desc : Each parameter is valid and can traverse the directory tree. + * @tc.level : Level 0 + */ +void ftw_0100() +{ + int ret = -1; + ret = ftw("/data", fn, 500); + EXPECT_NE("ftw_0100", ret, FAIL); +} + +int main() +{ + ftw_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/legacy/futimes.c b/libc-test/src/functionalext/supplement/legacy/futimes.c new file mode 100644 index 00000000..df66205a --- /dev/null +++ b/libc-test/src/functionalext/supplement/legacy/futimes.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int FAIL = -1; +const int SUCCESS = 0; + +/** + * @tc.name : futimes_0100 + * @tc.desc : All parameters are valid, TV is not 0, and futimes can modify the timestamp of the file. + * @tc.level : Level 0 + */ +void futimes_0100(void) +{ + int ret = -1; + struct stat s; + static struct timeval tv[2] = {{0L, 0L}, {0L, 0L}}; + tv[0].tv_sec = s.st_atime; + tv[0].tv_usec = 0; + tv[1].tv_sec = s.st_mtime; + tv[1].tv_usec = 0; + int fd = open("futimes.txt", O_RDWR | O_CREAT, 777); + ret = futimes(fd, tv); + EXPECT_EQ("futimes_0100", ret, SUCCESS); + remove("futimes.txt"); +} + +/** + * @tc.name : futimes_0200 + * @tc.desc : All parameters are valid, TV is 0, and futimes can modify the timestamp of the file. + * @tc.level : Level 1 + */ +void futimes_0200(void) +{ + int ret = -1; + int fd = open("futimes.txt", O_RDWR | O_CREAT, 777); + ret = futimes(fd, 0); + EXPECT_EQ("futimes_0200", ret, SUCCESS); + remove("futimes.txt"); +} + +/** + * @tc.name : futimes_0300 + * @tc.desc : The fd argument is invalid and the futimes function cannot modify the timestamp of the file. + * @tc.level : Level 2 + */ +void futimes_0300(void) +{ + int ret = -1; + static struct timeval tv[2] = {{0L, 0L}, {0L, 0L}}; + int fd = open("futimes.txt", O_RDWR); + ret = futimes(fd, tv); + EXPECT_EQ("futimes_0300", ret, FAIL); +} + +int main() +{ + futimes_0100(); + futimes_0200(); + futimes_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/legacy/getdtablesize.c b/libc-test/src/functionalext/supplement/legacy/getdtablesize.c new file mode 100644 index 00000000..a0b4e6c9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/legacy/getdtablesize.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : getdtablesize_0100 + * @tc.desc : Test getdtablesize to get the maximum number of files that can be opened by a process + * @tc.level : Level 0 + */ +void getdtablesize_0100(void) +{ + int result = getdtablesize(); + if (result == 0) { + t_error("%s getdtablesize error get result is 0\n", __func__); + } +} +int main(int argc, char *argv[]) +{ + getdtablesize_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/legacy/getloadavg.c b/libc-test/src/functionalext/supplement/legacy/getloadavg.c new file mode 100644 index 00000000..a0dda92c --- /dev/null +++ b/libc-test/src/functionalext/supplement/legacy/getloadavg.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getloadavg_0100 + * @tc.desc : Verify the average number of processes in the system running queue in different time periods + * @tc.level : Level 0 + */ +void getloadavg_0100(void) +{ + bool flag = false; + double buf[1024]; + int result = -10; + result = getloadavg(buf, 1024); + if (result > 0) + { + flag = true; + } + EXPECT_TRUE("getloadavg_0100", flag); +} + +int main() +{ + getloadavg_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/legacy/getpagesize.c b/libc-test/src/functionalext/supplement/legacy/getpagesize.c new file mode 100644 index 00000000..3413a894 --- /dev/null +++ b/libc-test/src/functionalext/supplement/legacy/getpagesize.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int EOK = 0; +const int SUCCESS = 0; +const int FAILED = -1; + +/** + * @tc.name : getpagesize_0100 + * @tc.desc : The call is successful and the size of the page can be obtained + * @tc.level : Level 0 + */ +void getpagesize_0100() +{ + char list[100]; + int page = getpagesize(); + system("getconf PAGE_SIZE > /data/1.txt"); + FILE *fd; + fd = fopen("/data/1.txt", "r"); + fread(list, sizeof(list), 10, fd); + EXPECT_EQ("getpagesize_0100", page, atoi(list)); + remove("/data/1.txt"); +} + +int main() +{ + getpagesize_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/legacy/lutimes.c b/libc-test/src/functionalext/supplement/legacy/lutimes.c new file mode 100644 index 00000000..3aaa0dca --- /dev/null +++ b/libc-test/src/functionalext/supplement/legacy/lutimes.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define TEST_FIFO_MODE 777 +#define TEST_SIZE 2 + +/** + * @tc.name : lutimes_0100 + * @tc.desc : Verify inet_lnaofof process success. Lfutimes can modify the timestamp of the file. + * @tc.level : Level 0 + */ +void lutimes_0100(void) +{ + int ret; + struct stat s; + static struct timeval tv[TEST_SIZE] = {{0L, 0L}, {0L, 0L}}; + tv[0].tv_sec = s.st_atime; + tv[0].tv_usec = 0; + tv[1].tv_sec = s.st_mtime; + tv[1].tv_usec = 0; + int fd = -1; + fd = creat("./lutimes_0100.txt", TEST_FIFO_MODE); + if (fd < 0) { + EXPECT_MT("lutimes_0100", fd, 0); + return; + } else { + close(fd); + } + ret = lutimes("./lutimes_0100.txt", tv); + EXPECT_EQ("lutimes_0100", ret, 0); + ret = remove("lutimes_0100.txt"); + EXPECT_EQ("lutimes_0100", ret, 0); +} + +/** + * @tc.name : lutimes_0200 + * @tc.desc : Verify inet_lnaofof process fail. Because the fd argument is invalid + * and the lutimes function cannot modify the timestamp of the file. + * @tc.level : Level 2 + */ +void lutimes_0200(void) +{ + int ret = -1; + static struct timeval tv[TEST_SIZE] = {{0L, 0L}, {0L, 0L}}; + ret = lutimes("./lutimes_0200.txt", tv); + EXPECT_EQ("lutimes_0200", ret, -1); +} + +int main(void) +{ + lutimes_0100(); + lutimes_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/legacy/test_src_functionalext_supplement_legacy.gni b/libc-test/src/functionalext/supplement/legacy/test_src_functionalext_supplement_legacy.gni new file mode 100644 index 00000000..54d7ddbb --- /dev/null +++ b/libc-test/src/functionalext/supplement/legacy/test_src_functionalext_supplement_legacy.gni @@ -0,0 +1,26 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_legacy_test = [ + "getdtablesize", + "getpagesize", + "ftw", + "futimes", + "lutimes", + "daemon", + "verr", + "verrx", + "vwarn", + "vwarnx", + "getloadavg", +] diff --git a/libc-test/src/functionalext/supplement/legacy/verr.c b/libc-test/src/functionalext/supplement/legacy/verr.c new file mode 100644 index 00000000..f657885c --- /dev/null +++ b/libc-test/src/functionalext/supplement/legacy/verr.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/* + * @tc.name : veer_0100 + * @tc.desc : The test verr method prints the error message + * @tc.level : Level 0 + */ +void veer_0100(int status, char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + verr(status, fmt, ap); + va_end(ap); +} + +int main(int argc, char *argv[]) +{ + veer_0100(t_status, "veer_0100 printf info: %s", "this is msg"); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/legacy/verrx.c b/libc-test/src/functionalext/supplement/legacy/verrx.c new file mode 100644 index 00000000..3f3cfe91 --- /dev/null +++ b/libc-test/src/functionalext/supplement/legacy/verrx.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/* + * @tc.name : veerx_0100 + * @tc.desc : The test verrx method prints the error message + * @tc.level : Level 0 + */ +void veerx_0100(int status, char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + verrx(status, fmt, ap); + va_end(ap); +} + +int main(int argc, char *argv[]) +{ + veerx_0100(t_status, "veerx_0100 printf info: %s", "this is msg"); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/legacy/vwarn.c b/libc-test/src/functionalext/supplement/legacy/vwarn.c new file mode 100644 index 00000000..b7ca69c8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/legacy/vwarn.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/* + * @tc.name : vwarn_0100 + * @tc.desc : The test vwarn method prints the error message + * @tc.level : Level 0 + */ +void vwarn_0100(char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vwarn(fmt, ap); + va_end(ap); +} + +int main(int argc, char *argv[]) +{ + vwarn_0100("vwarn_0100 printf info: %s", "this is msg"); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/legacy/vwarnx.c b/libc-test/src/functionalext/supplement/legacy/vwarnx.c new file mode 100644 index 00000000..8bcfeaab --- /dev/null +++ b/libc-test/src/functionalext/supplement/legacy/vwarnx.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/* + * @tc.name : vwarnx_0100 + * @tc.desc : The test vwarnx method prints the error message + * @tc.level : Level 0 + */ +void vwarnx_0100(char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vwarnx(fmt, ap); + va_end(ap); +} + +int main(int argc, char *argv[]) +{ + vwarnx_0100("vwarnx_0100 printf info: %s", "this is msg"); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/BUILD.gn b/libc-test/src/functionalext/supplement/linux/BUILD.gn new file mode 100644 index 00000000..4c6f7c3b --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_linux.gni") + +foreach(s, functionalext_supplement_linux_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/linux" + } +} + +group("functionalext_supplement_linux_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_linux_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/linux/adjtimex.c b/libc-test/src/functionalext/supplement/linux/adjtimex.c new file mode 100644 index 00000000..af3e2e36 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/adjtimex.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t NUM_NEG = -1; + +/** + * @tc.name : adjtimex_0100 + * @tc.desc : Verify the time to tune the kernel. + * @tc.level : Level 0 + */ +void adjtimex_0100(void) +{ + struct timex tx; + tx.offset = ADJ_OFFSET; + tx.tick = ADJ_TICK; + tx.maxerror = ADJ_MAXERROR; + tx.esterror = ADJ_ESTERROR; + tx.constant = ADJ_TIMECONST; + tx.freq = ADJ_FREQUENCY; + tx.status = ADJ_STATUS; + tx.precision = 1; + tx.tolerance = 1; + tx.ppsfreq = 1; + tx.jitter = 1; + tx.stabil = 1; + tx.jitcnt = 1; + tx.calcnt = 1; + tx.errcnt = 1; + tx.stbcnt = 1; + int result = -1; + result = adjtimex(&tx); + EXPECT_NE("adjtimex_0100", result, NUM_NEG); +} + +int main(int argc, char *argv[]) +{ + adjtimex_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/brk.c b/libc-test/src/functionalext/supplement/linux/brk.c new file mode 100755 index 00000000..ebd6a25e --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/brk.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +#define MAX 10 + +/** + * @tc.name : brk_0100 + * @tc.desc : Verify Change the location of program breakpoints + * @tc.level : Level 0 + */ +void brk_0100(void) +{ + int *p, n = 0, max = MAX; + FILE *fp; + int result; + p = (int *)malloc(MAX * sizeof(int)); + max++; + result = brk(p); +#ifdef __BSD_SOURCE + EXPECT_EQ("brk_0100", result, 0); +#endif +} + +int main() +{ + brk_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/capget.c b/libc-test/src/functionalext/supplement/linux/capget.c new file mode 100755 index 00000000..ab8cae82 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/capget.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +#undef _POSIX_SOURCE +const int32_t COUNT_ZERO = 0; +const int32_t COUNT_NEGATIVE = -1; + +/** + * @tc.name : capget_0100 + * @tc.desc : Verify that you can obtain process permissions (parameter valid) + * @tc.level : Level 0 + */ +void capget_0100(void) +{ + struct __user_cap_header_struct cap_header_data; + cap_user_header_t cap_header = &cap_header_data; + struct __user_cap_data_struct cap_data_data; + cap_user_data_t cap_data = &cap_data_data; + int result; + cap_header->pid = getpid(); + cap_header->version = _LINUX_CAPABILITY_VERSION_1; + result = capget(cap_header, cap_data); + EXPECT_EQ("capget_0100", result, COUNT_ZERO); +} + +/** + * @tc.name : capget_0200 + * @tc.desc : Validation could not obtain process permissions (parameter a is invalid) + * @tc.level : Level 2 + */ +void capget_0200(void) +{ + struct __user_cap_data_struct cap_data_data; + cap_user_data_t cap_data = &cap_data_data; + int result; + result = capget(NULL, cap_data); + EXPECT_EQ("capget_0200", result, COUNT_NEGATIVE); +} + +/** + * @tc.name : capget_0300 + * @tc.desc : Verify that the process permission can be obtained + * @tc.level : Level 1 + */ +void capget_0300(void) +{ + struct __user_cap_header_struct cap_header_data; + cap_user_header_t cap_header = &cap_header_data; + cap_header->pid = getpid(); + cap_header->version = _LINUX_CAPABILITY_VERSION_1; + struct __user_cap_data_struct cap_data_data; + cap_user_data_t cap_data = NULL; + int result; + result = capget(cap_header, NULL); + EXPECT_EQ("capget_0300", result, COUNT_ZERO); +} + +int main() +{ + capget_0100(); + capget_0200(); + capget_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/capset.c b/libc-test/src/functionalext/supplement/linux/capset.c new file mode 100755 index 00000000..3679c598 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/capset.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +#undef _POSIX_SOURCE +const int32_t COUNT_ZERO = 0; +const int32_t COUNT_NEGATIVE = -1; + +/** + * @tc.name : capset_0100 + * @tc.desc : Verify that process permissions can be set (parameter valid) + * @tc.level : Level 0 + */ +void capset_0100(void) +{ + struct __user_cap_header_struct cap_header_data; + cap_user_header_t cap_header = &cap_header_data; + struct __user_cap_data_struct cap_data_data; + cap_user_data_t cap_data = &cap_data_data; + int result; + cap_header->pid = getpid(); + cap_header->version = _LINUX_CAPABILITY_VERSION_1; + result = capset(cap_header, cap_data); +#ifdef __POSIX_SOURCE + EXPECT_EQ("capset_0100", result, COUNT_ZERO); +#endif +} + +/** + * @tc.name : capset_0200 + * @tc.desc : Validation cannot set process permissions (a parameter is invalid) + * @tc.level : Level 2 + */ +void capset_0200(void) +{ + struct __user_cap_data_struct cap_data_data; + cap_user_data_t cap_data = &cap_data_data; + int result; + result = capset(NULL, cap_data); + EXPECT_EQ("capset_0200", result, COUNT_NEGATIVE); +} + +/** + * @tc.name : capset_0300 + * @tc.desc : Validation cannot set process permissions (b parameter invalid) + * @tc.level : Level 2 + */ +void capset_0300(void) +{ + struct __user_cap_header_struct cap_header_data; + cap_user_header_t cap_header = &cap_header_data; + cap_header->pid = getpid(); + cap_header->version = _LINUX_CAPABILITY_VERSION_1; + struct __user_cap_data_struct cap_data_data; + cap_user_data_t cap_data = NULL; + int result; + result = capset(cap_header, NULL); + EXPECT_EQ("capset_0300", result, COUNT_NEGATIVE); +} + +int main() +{ + capset_0100(); + capset_0200(); + capset_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/chroot.c b/libc-test/src/functionalext/supplement/linux/chroot.c new file mode 100644 index 00000000..009a352c --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/chroot.c @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/* + * @tc.name : chroot_0100 + * @tc.desc : Verify that the file root directory can be changed (parameters are valid) + * @tc.level : Level 0 + */ +void chroot_0100(void) +{ + char *ftpr = "/"; + int result = chroot(ftpr); + EXPECT_EQ("chroot_0100", result, 0); +} + +/* + * @tc.name : chroot_0200 + * @tc.desc : Verify that the file root directory cannot be changed (parameter is NULL) + * @tc.level : Level 2 + */ +void chroot_0200(void) +{ + char *ftpr = "data/app"; + int result = chroot(NULL); + EXPECT_EQ("chroot_0100", result, -1); +} + +/* + * @tc.name : chroot_0300 + * @tc.desc : Verify that the file root directory cannot be changed (parameter exceeds maximum length) + * @tc.level : Level 2 + */ +void chroot_0300(void) +{ + char *ftpr = "data/app/el1/bundle/public/com.example.disributedcalc/com.example.disributedcalc/assets/js"; + int result = chroot(ftpr); + EXPECT_EQ("chroot_0100", result, -1); +} + +/* + * @tc.name : chroot_0400 + * @tc.desc : Verify that the file root directory cannot be changed (parameter invalid) + * @tc.level : Level 2 + */ +void chroot_0400(void) +{ + char *ftpr = "system/app"; + int result = chroot(ftpr); + EXPECT_EQ("chroot_0100", result, -1); +} + +int main() +{ + chroot_0100(); + chroot_0200(); + chroot_0300(); + chroot_0400(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/clock_adjtime.c b/libc-test/src/functionalext/supplement/linux/clock_adjtime.c new file mode 100755 index 00000000..2ec71c0c --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/clock_adjtime.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_NEGATIVE = -1; + +/** + * @tc.name : clock_adjtime_0100 + * @tc.desc : Verify that the kernel time can be adjusted (all parameters are valid, clock_id is CLOCK_REALTIME) + * @tc.level : Level 0 + */ +void clock_adjtime_0100(void) +{ + bool flag = false; + struct timex tx = {0}; + int result = -1; + result = clock_adjtime(CLOCK_REALTIME, &tx); + if (result != -1) + { + flag = true; + } + EXPECT_TRUE("clock_adjtime_0100", flag); +} + +/** + * @tc.name : clock_adjtime_0200 + * @tc.desc : Verify that the kernel time can not be adjusted (each parameter is valid, clock_id is + * CLOCK_MONOTONIC) + * @tc.level : Level 2 + */ +void clock_adjtime_0200(void) +{ + struct timex tx = {ADJ_OFFSET_SS_READ}; + int result = -1; + result = clock_adjtime(CLOCK_MONOTONIC, &tx); + EXPECT_EQ("clock_adjtime_0200", result, COUNT_NEGATIVE); +} + +/** + * @tc.name : clock_adjtime_0300 + * @tc.desc : Verify that the kernel time can not be adjusted (all parameters are valid, clock_id is + * CLOCK_PROCESS_CPUTIME_ID) + * @tc.level : Level 2 + */ +void clock_adjtime_0300(void) +{ + struct timex tx = {0}; + int result = -1; + result = clock_adjtime(CLOCK_PROCESS_CPUTIME_ID, &tx); + EXPECT_EQ("clock_adjtime_0300", result, COUNT_NEGATIVE); +} + +/** + * @tc.name : clock_adjtime_0400 + * @tc.desc : Verify that the kernel time can not be adjusted (all parameters are valid, clock_id is + * CLOCK_THREAD_CPUTIME_ID) + * @tc.level : Level 2 + */ +void clock_adjtime_0400(void) +{ + struct timex tx = {0}; + int result = -1; + result = clock_adjtime(CLOCK_THREAD_CPUTIME_ID, &tx); + EXPECT_EQ("clock_adjtime_0400", result, COUNT_NEGATIVE); +} + +/** + * @tc.name : clock_adjtime_0500 + * @tc.desc : Verify that kernel time cannot be adjusted (tx parameter invalid) + * @tc.level : Level 2 + */ +void clock_adjtime_0500(void) +{ + struct timex tx = {100000}; + int result = 0; + result = clock_adjtime(CLOCK_REALTIME, &tx); + EXPECT_EQ("clock_adjtime_0500", result, COUNT_NEGATIVE); +} + +int main() +{ + clock_adjtime_0100(); + clock_adjtime_0200(); + clock_adjtime_0300(); + clock_adjtime_0400(); + clock_adjtime_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/clone.c b/libc-test/src/functionalext/supplement/linux/clone.c new file mode 100644 index 00000000..8478df56 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/clone.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int STACK_SIZE = 1024 * 8192; +const int SUCCESS = 0; +void *test(void *p) +{ + return NULL; +} + +/** + * @tc.name : clone_0100 + * @tc.desc : Each parameter is valid, and a new thread can be created through the clone function. + * @tc.level : Level 0 + */ +void clone_0100(void) +{ + void *stack = malloc(STACK_SIZE); + int cpid = -1; + cpid = clone((int (*)(void *))test, (char *)stack + STACK_SIZE, + CLONE_VM | CLONE_FS | CLONE_FILES | SIGCHLD, NULL); + sleep(1); + EXPECT_NE("clone_0100", cpid, -1); +} + +int main() +{ + clone_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/copy_file_range.c b/libc-test/src/functionalext/supplement/linux/copy_file_range.c new file mode 100644 index 00000000..06afe1f6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/copy_file_range.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +const char *path_in = "/data/tests/libc-test/src/file_in.txt"; +const char *path_out = "/data/tests/libc-test/src/file_out.txt"; +const char *str = "Hello"; + +/** + * @tc.name : copy_file_range_0100 + * @tc.desc : Copy a range of data from one file to another + * @tc.level : Level 0 + */ +void copy_file_range_0100(void) +{ + int fd_in, fd_out, wlen, result; + char buffer[BUFSIZ]; + + fd_in = open(path_in, O_RDWR | O_CREAT); + if (fd_in == -1) { + t_error("%s open path_in failed\n", __func__); + return; + } + + wlen = write(fd_in, str, strlen(str)); + if (wlen != strlen(str)) { + t_error("%s write failed\n", __func__); + return; + } + + close(fd_in); + fd_in = open(path_in, O_RDONLY); + + fd_out = open(path_out, O_RDWR | O_CREAT); + if (fd_out == -1) { + t_error("%s open path_out failed\n", __func__); + return; + } + + do { + result = copy_file_range(fd_in, NULL, fd_out, NULL, wlen, 0); + if (result == -1) { + t_error("%s copy_file_range failed\n", __func__); + return; + } + wlen -= result; + } while (wlen > 0 && result > 0); + + close(fd_out); + fd_out = open(path_out, O_RDONLY); + memset(buffer, 0, sizeof(buffer)); + result = read(fd_out, buffer, sizeof(buffer)); + if (result == -1) { + t_error("%s read failed\n", __func__); + } + if (strcmp(str, buffer)) { + t_error("%s buffer is %s, not %s", __func__, buffer, str); + } + + close(fd_in); + close(fd_out); + remove(path_in); + remove(path_out); +} + +/** + * @tc.name : copy_file_range_0200 + * @tc.desc : One or more file descriptors are not valid + * @tc.level : Level 2 + */ +void copy_file_range_0200(void) +{ + errno = 0; + int result = copy_file_range(-1, NULL, -1, NULL, 0, 0); + if (result != -1) { + t_error("%s copy_file_range should failed, result is %d\n", __func__, result); + } + if (errno != EBADF) { + t_error("%s errno is %d, not EBADF", __func__, errno); + } +} + +/** + * @tc.name : copy_file_range_0300 + * @tc.desc : File permissions are restricted + * @tc.level : Level 2 + */ +void copy_file_range_0300(void) +{ + int fd_in, fd_out, wlen, result; + char buffer[BUFSIZ]; + + fd_in = open(path_in, O_WRONLY | O_CREAT); + if (fd_in == -1) { + t_error("%s open path_in failed\n", __func__); + return; + } + + wlen = write(fd_in, str, strlen(str)); + if (wlen != strlen(str)) { + t_error("%s write failed\n", __func__); + return; + } + + close(fd_in); + fd_in = open(path_in, O_WRONLY); + + fd_out = open(path_out, O_RDONLY | O_CREAT); + if (fd_out == -1) { + t_error("%s open path_out failed\n", __func__); + return; + } + + errno = 0; + result = copy_file_range(fd_in, NULL, fd_out, NULL, wlen, 0); + if (result != -1) { + t_error("%s copy_file_range should failded\n", __func__); + } + if (errno != EBADF) { + t_error("%s errno is %d, not EBADF\n", __func__, errno); + } + + close(fd_in); + close(fd_out); + remove(path_in); + remove(path_out); +} + +int main(int argc, char *argv[]) +{ + copy_file_range_0100(); + copy_file_range_0200(); + copy_file_range_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/eventfd.c b/libc-test/src/functionalext/supplement/linux/eventfd.c new file mode 100755 index 00000000..aed6f63e --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/eventfd.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : eventfd_0100 + * @tc.desc : The flags parameter is equal to EFD_SEMAPHORE, which creates an eventfd object. + * @tc.level : Level 0 + */ +void eventfd_0100() +{ + int ret = eventfd(0, EFD_SEMAPHORE); + EXPECT_TRUE("eventfd_0100", ret > 0); +} + +/** + * @tc.name : eventfd_0200 + * @tc.desc : The flags parameter is equal to EFD_CLOEXEC, which creates an eventfd object. + * @tc.level : Level 1 + */ +void eventfd_0200() +{ + int ret = eventfd(0, EFD_CLOEXEC); + EXPECT_TRUE("eventfd_0200", ret > 0); +} + +/** + * @tc.name : eventfd_0300 + * @tc.desc : The flags parameter is equal to EFD_NONBLOCK, which creates an eventfd object. + * @tc.level : Level 1 + */ +void eventfd_0300() +{ + int ret = eventfd(0, EFD_NONBLOCK); + EXPECT_TRUE("eventfd_0300", ret > 0); +} + +int main() +{ + eventfd_0100(); + eventfd_0200(); + eventfd_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/eventfd_read.c b/libc-test/src/functionalext/supplement/linux/eventfd_read.c new file mode 100755 index 00000000..30d88397 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/eventfd_read.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : eventfd_read_0100 + * @tc.desc : The flags parameter is equal to EFD_SEMAPHORE, which creates an eventfd object. + * @tc.level : Level 0 + */ +void eventfd_read_0100(void) +{ + int fd, write_ret, read_ret; + uint64_t value; + fd = eventfd(1, EFD_NONBLOCK); + write_ret = eventfd_write(fd, 20); + read_ret = eventfd_read(fd, &value); + EXPECT_EQ("eventfd_read_0100", read_ret, 0); +} + +/** + * @tc.name : eventfd_read_0200 + * @tc.desc : The flags parameter is equal to EFD_CLOEXEC, which creates an eventfd object. + * @tc.level : Level 2 + */ +void eventfd_read_0200(void) +{ + int fd, write_ret, read_ret; + fd = eventfd(1, EFD_NONBLOCK); + write_ret = eventfd_write(fd, 20); + read_ret = eventfd_read(fd, NULL); + EXPECT_EQ("eventfd_read_0200", read_ret, -1); +} + +/** + * @tc.name : eventfd_read_0300 + * @tc.desc : The flags parameter is equal to EFD_NONBLOCK, which creates an eventfd object. + * @tc.level : Level 2 + */ +void eventfd_read_0300(void) +{ + int fd, write_ret, read_ret; + uint64_t value; + read_ret = eventfd_read(-1, &value); + EXPECT_EQ("eventfd_read_0300", read_ret, -1); +} + +int main() +{ + eventfd_read_0100(); + eventfd_read_0200(); + eventfd_read_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/eventfd_write.c b/libc-test/src/functionalext/supplement/linux/eventfd_write.c new file mode 100755 index 00000000..5c849224 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/eventfd_write.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : eventfd_write_0100 + * @tc.desc : The flags parameter is equal to EFD_SEMAPHORE, which creates an eventfd object. + * @tc.level : Level 0 + */ +void eventfd_write_0100(void) +{ + int fd, write_ret; + uint64_t value; + fd = eventfd(1, EFD_NONBLOCK); + write_ret = eventfd_write(fd, 20); + EXPECT_EQ("eventfd_write_0100", write_ret, 0); +} + +/** + * @tc.name : eventfd_write_0200 + * @tc.desc : The flags parameter is equal to EFD_CLOEXEC, which creates an eventfd object. + * @tc.level : Level 2 + */ +void eventfd_write_0200(void) +{ + int fd, write_ret; + uint64_t value; + fd = eventfd(1, EFD_NONBLOCK); + write_ret = eventfd_write(-1, 20); + EXPECT_EQ("eventfd_write_0200", write_ret, -1); +} + +/** + * @tc.name : eventfd_write_0300 + * @tc.desc : The flags parameter is equal to EFD_NONBLOCK, which creates an eventfd object. + * @tc.level : Level 2 + */ +void eventfd_write_0300(void) +{ + int fd, write_ret; + uint64_t value; + fd = eventfd(1, EFD_NONBLOCK); + write_ret = eventfd_write(fd, -1); + EXPECT_EQ("eventfd_write_0300", write_ret, -1); +} + +int main() +{ + eventfd_write_0100(); + eventfd_write_0200(); + eventfd_write_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/fallocate.c b/libc-test/src/functionalext/supplement/linux/fallocate.c new file mode 100755 index 00000000..25c84d42 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/fallocate.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int SIZE = 18; +const int SUCCESS = 0; +const int FAILED = -1; + +/** + * @tc.name : fallocate_0100 + * @tc.desc : The parameter mode is 0, which can expand the file space. + * @tc.level : Level 0 + */ +void fallocate_0100() +{ + char str[] = "this is a fatest\n"; + char buffer[1024] = {0}; + int fd = open("fatest.txt", O_RDWR | O_CREAT); + EXPECT_TRUE("fallocate_0100", fd >= 0); + int retwrite = write(fd, str, sizeof(str)); + EXPECT_EQ("fallocate_0100", retwrite, SIZE); + int ret = fallocate(fd, 0, 4096, 4096 * 3); + EXPECT_EQ("fallocate_0100", ret, SUCCESS); + close(fd); + remove("fatest.txt"); +} + +/** + * @tc.name : fallocate_0200 + * @tc.desc : The parameter mode is FALLOC_FL_KEEP_SIZE, which can expand the file space. + * @tc.level : Level 1 + */ +void fallocate_0200(void) +{ + char str[] = "this is a fatest\n"; + char buffer[1024] = {0}; + int fd = open("fatest.txt", O_RDWR | O_CREAT); + EXPECT_TRUE("fallocate_0200", fd >= 0); + int retwrite = write(fd, str, sizeof(str)); + EXPECT_EQ("fallocate_0200", retwrite, SIZE); + int ret = fallocate(fd, FALLOC_FL_KEEP_SIZE, 4096, 4096 * 3); + EXPECT_EQ("fallocate_0200", ret, SUCCESS); + close(fd); + remove("fatest.txt"); +} + +/** + * @tc.name : fallocate_0300 + * @tc.desc : The parameter mode is FALLOC_FL_KEEP_SIZE|FALLOC_FL_PUNCH_HOLE, which can release file space. + * @tc.level : Level 1 + */ +void fallocate_0300(void) +{ + char str[] = "this is a fatest\n"; + char buffer[1024] = {0}; + int fd = open("fatest.txt", O_RDWR | O_CREAT); + EXPECT_TRUE("fallocate_0300", fd >= 0); + int retwrite = write(fd, str, sizeof(str)); + EXPECT_EQ("fallocate_0300", retwrite, SIZE); + lseek(fd, 0, SEEK_SET); + int ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, 4096, 4096 * 3); + EXPECT_EQ("fallocate_0300", ret, SUCCESS); + close(fd); + remove("fatest.txt"); +} + +/** + * @tc.name : fallocate_0400 + * @tc.desc : The parameter fd is invalid, the mode is FALLOC_FL_KEEP_SIZE, and the file space cannot be expanded + * @tc.level : Level 1 + */ +void fallocate_0400(void) +{ + int fd = -1; + int ret = fallocate(fd, FALLOC_FL_KEEP_SIZE, 4096, 4096 * 3); + EXPECT_EQ("fallocate_0400", ret, FAILED); + close(fd); + remove("fatest.txt"); +} + +int main() +{ + fallocate_0100(); + fallocate_0200(); + fallocate_0300(); + fallocate_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/fgetxattr.c b/libc-test/src/functionalext/supplement/linux/fgetxattr.c new file mode 100644 index 00000000..9e97177a --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/fgetxattr.c @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" +#include "sys/xattr.h" + +/** + * @tc.name : fgetxattr_0100 + * @tc.desc : Verify that the extended attribute value can be obtained. + * @tc.level : Level 0 + */ +void fgetxattr_0100(void) +{ + int fd = open("fgetxattr.txt", O_RDWR | O_CREAT); + char name[] = "user.x"; + char value[] = "the past is not dead."; + ssize_t size; + fsetxattr(fd, name, value, strlen(value), 0); + size = fgetxattr(fd, name, value, 1024); + bool flag = false; + if (size >= 0) + { + flag = true; + } + EXPECT_TRUE("fgetxattr_0100", flag); + close(fd); + remove("fgetxattr.txt"); +} + +int main(int argc, char *argv[]) +{ + fgetxattr_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/flistxattr.c b/libc-test/src/functionalext/supplement/linux/flistxattr.c new file mode 100755 index 00000000..bdde7afb --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/flistxattr.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : flistxattr_0100 + * @tc.desc : Verify that extended attribute names can be listed (each parameter is valid) + * @tc.level : Level 0 + */ +void flistxattr_0100(void) +{ + bool flag = false; + int fd = open("/data/test.txt", O_CREAT | O_WRONLY, 0667); + char name[] = "user.x"; + char value[] = "the past is not dead."; + ssize_t result; + fsetxattr(fd, name, value, strlen(value), 0); + result = flistxattr(fd, name, 0); + if (result >= 0) + { + flag = true; + } + EXPECT_TRUE("flistxattr_0100", flag); + close(fd); + remove("/data/test.txt"); +} + +TEST_FUN G_Fun_Array[] = { + flistxattr_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) + { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/flock.c b/libc-test/src/functionalext/supplement/linux/flock.c new file mode 100644 index 00000000..fa487425 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/flock.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; + +/** + * @tc.name : flock_0100 + * @tc.desc : Each parameter is valid, the op parameter is LOCK_SH, which can lock the file + * @tc.level : Level 0 + */ +void flock_0100() +{ + int fd = -1; + int result = -1; + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666); + lseek(fd, 2, SEEK_SET); + if (fd < 0) { + printf("open failed!\n"); + return; + } + result = flock(fd, LOCK_SH); + EXPECT_EQ("flock_0100", result, SUCCESS); + close(fd); + system("rm -rf /data/test.txt"); +} + +/** + * @tc.name : flock_0200 + * @tc.desc : Each parameter is valid, the op parameter is LOCK_SH|LOCK_NB, which can lock the file + * @tc.level : Level 1 + */ +void flock_0200() +{ + int fd = -1; + int result = -1; + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666); + lseek(fd, 2, SEEK_SET); + if (fd < 0) { + printf("open failed!\n"); + return; + } + result = flock(fd, LOCK_SH | LOCK_NB); + EXPECT_EQ("flock_0200", result, SUCCESS); + close(fd); + system("rm -rf /data/test.txt"); +} + +/** + * @tc.name : flock_0300 + * @tc.desc : Each parameter is valid, the op parameter is LOCK_EX, which can lock the file + * @tc.level : Level 0 + */ +void flock_0300() +{ + int fd = -1; + int result = -1; + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666); + lseek(fd, 2, SEEK_SET); + if (fd < 0) { + printf("open failed!\n"); + return; + } + result = flock(fd, LOCK_EX); + EXPECT_EQ("flock_0300", result, SUCCESS); + close(fd); + system("rm -rf /data/test.txt"); +} + +/** + * @tc.name : flock_0400 + * @tc.desc : Each parameter is valid, the op parameter is LOCK_EX|LOCK_NB, which can lock the file + * @tc.level : Level 1 + */ +void flock_0400() +{ + int fd = -1; + int result = -1; + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666); + lseek(fd, 2, SEEK_SET); + if (fd < 0) { + printf("open failed!\n"); + return; + } + result = flock(fd, LOCK_EX | LOCK_NB); + EXPECT_EQ("flock_0400", result, SUCCESS); + close(fd); + system("rm -rf /data/test.txt"); +} + +/** + * @tc.name : flock_0500 + * @tc.desc : Each parameter is valid, the op parameter is LOCK_UN, which can release the file lock state + * @tc.level : Level 0 + */ +void flock_0500() +{ + int fd = -1; + int result = -1; + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666); + lseek(fd, 2, SEEK_SET); + if (fd < 0) { + printf("open failed!\n"); + return; + } + result = flock(fd, LOCK_UN); + EXPECT_EQ("flock_0500", result, SUCCESS); + close(fd); + system("rm -rf /data/test.txt"); +} + +/** + * @tc.name : flock_0600 + * @tc.desc : The fd parameter is invalid, the file cannot be locked + * @tc.level : Level 2 + */ +void flock_0600() +{ + int fd = -1; + int result = 0; + result = flock(fd, LOCK_EX); + EXPECT_EQ("flock_0600", result, FAILED); + close(fd); +} + +/** + * @tc.name : flock_0700 + * @tc.desc : The op parameter is invalid, the file cannot be locked + * @tc.level : Level 2 + */ +void flock_0700() +{ + int fd = -1; + int result = 0; + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666); + lseek(fd, 2, SEEK_SET); + if (fd < 0) { + printf("open failed!\n"); + return; + } + result = flock(fd, 0); + EXPECT_EQ("flock_0700", result, FAILED); + close(fd); + system("rm -rf /data/test.txt"); +} + +int main() +{ + flock_0100(); + flock_0200(); + flock_0300(); + flock_0400(); + flock_0500(); + flock_0600(); + flock_0700(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/fremovexattr.c b/libc-test/src/functionalext/supplement/linux/fremovexattr.c new file mode 100755 index 00000000..6414d6fe --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/fremovexattr.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; + +/** + * @tc.name : fremovexattr_0100 + * @tc.desc : Verify that the extended properties of the specified file can be deleted. + * @tc.level : Level 0 + */ +void fremovexattr_0100(void) +{ + int fd = open("/data/test.txt", O_CREAT | O_WRONLY, 0667); + char name[] = "user.x"; + char value[] = "the past is not dead."; + int result; + fsetxattr(fd, name, value, strlen(value), 0); + result = fremovexattr(fd, name); + EXPECT_EQ("fremovexattr_0100", result, COUNT_ZERO); + close(fd); + remove("/data/test.txt"); +} + +int main() +{ + fremovexattr_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/fsetxattr.c b/libc-test/src/functionalext/supplement/linux/fsetxattr.c new file mode 100755 index 00000000..a51fd0d1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/fsetxattr.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; + +/** + * @tc.name : fsetxattr_0100 + * @tc.desc : Verify that you can set the extended properties of the specified file (all parameters are valid) + * @tc.level : Level 0 + */ +void fsetxattr_0100(void) +{ + int fd = open("/data/test.txt", O_CREAT | O_WRONLY, 0667); + char name[] = "user.x"; + char value[] = "the past is not dead."; + int result; + result = fsetxattr(fd, name, value, strlen(value), 0); + EXPECT_EQ("fsetxattr_0100", result, COUNT_ZERO); + close(fd); + remove("/data/test.txt"); +} + +int main() +{ + fsetxattr_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/getdents.c b/libc-test/src/functionalext/supplement/linux/getdents.c new file mode 100644 index 00000000..7cd23df2 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/getdents.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int FAILED = -1; + +/** + * @tc.name : getdents_0100 + * @tc.desc : Each parameter is valid, the len parameter is less than or equal to INT_MAX, and the directory + * information can be read into the specified buffer. + * @tc.level : Level 0 + */ +void getdents_0100(void) +{ + int fd = -1; + int result = -1; + struct dirent buf; + fd = open("/data/data", O_RDONLY); + if (fd < 0) { + printf("open failed!\n"); + } + result = getdents(fd, &buf, INT_MAX); + EXPECT_TRUE("getdents_0100", result > 0); +} + +/** + * @tc.name : getdents_0200 + * @tc.desc : The fd parameter is invalid, the directory information cannot be read into the specified buffer. + * @tc.level : Level 2 + */ +void getdents_0200(void) +{ + int fd = 0; + int result = 0; + struct dirent buf; + fd = open("/getdents", O_RDONLY); + result = getdents(fd, &buf, INT_MAX); + EXPECT_EQ("getdents_0200", result, FAILED); +} + +/** + * @tc.name : getdents_0300 + * @tc.desc : The buf parameter is invalid, the directory information cannot be read into the specified buffer. + * @tc.level : Level 2 + */ +void getdents_0300(void) +{ + int fd = 0; + int result = 0; + struct dirent buf; + fd = open("/data/data", O_RDONLY); + if (fd < 0) { + printf("open failed!\n"); + } + result = getdents(fd, NULL, INT_MAX); + EXPECT_EQ("getdents_0300", result, FAILED); +} + +int main() +{ + getdents_0100(); + getdents_0200(); + getdents_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/getrandom.c b/libc-test/src/functionalext/supplement/linux/getrandom.c new file mode 100644 index 00000000..426783ed --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/getrandom.c @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" +#include "sys/random.h" + +#define GRND_NONBLOCK 0x0001 + +/** + * @tc.name : getrandom_0100 + * @tc.desc : Verify getrandom process success + * @tc.level : Level 0 + */ +void getrandom_0100(void) +{ + unsigned int tmp; + + int32_t ret = getrandom(&tmp, sizeof(unsigned int), GRND_NONBLOCK); + EXPECT_NE("getrandom_0100", ret, -1); +} + +int main(void) +{ + getrandom_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/getxattr.c b/libc-test/src/functionalext/supplement/linux/getxattr.c new file mode 100644 index 00000000..82600f0d --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/getxattr.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const char *path = "file.txt"; +const char *name = "user.txt"; +const char *value = "dat"; +const int size = 3; + +/** + * @tc.name : getxattr_0100 + * @tc.desc : Verify getxattr process success + * @tc.level : Level 0 + */ +void getxattr_0100(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + if (fd < 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + return; + } + + char str[] = "dat"; + write(fd, str, sizeof(str)); + close(fd); + + int ret = setxattr(path, name, value, strlen(value), XATTR_CREATE); + if (ret != 0) { + t_error("%s failed: ret = %d\n", __func__, ret); + return; + } + + char buf[BUFSIZ] = {0}; + + ret = getxattr(path, name, buf, sizeof(buf)); + EXPECT_EQ("getxattr_0100", ret, size); + EXPECT_STREQ("getxattr_0100", buf, str); + ret = remove(path); + EXPECT_EQ("getxattr_0100", ret, 0); +} + +/** + * @tc.name : getxattr_0200 + * @tc.desc : Verify getxattr process fail bacause param is null + * @tc.level : Level 0 + */ +void getxattr_0200(void) +{ + int ret = getxattr(NULL, NULL, NULL, -1); + EXPECT_EQ("getxattr_0200", ret, -1); +} + +int main(void) +{ + getxattr_0100(); + getxattr_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/inotify.c b/libc-test/src/functionalext/supplement/linux/inotify.c new file mode 100755 index 00000000..24d9d67d --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/inotify.c @@ -0,0 +1,173 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define TEST_BUFFER_SIZE 128 +#define TEST_DATA_COUNT 10 + +struct inotify_test { + int fd; + int wd; + uint32_t mask; +}; + +static int inotify_init_test(void) +{ + errno = 0; + return inotify_init(); +} + +static int inotify_add_watch_test(int fd, uint32_t mask) +{ + errno = 0; + return inotify_add_watch(fd, "/data", mask); +} + +static int inotify_rm_watch_test(int fd, int wd) +{ + errno = 0; + return inotify_rm_watch(fd, wd); +} + +static void inotify_test(const char *msg) +{ + int fd = inotify_init_test(); + EXPECT_NE(msg, fd, ERREXPECT); + if (fd == -1) { + return; + } + + int i, j; + struct inotify_test data[TEST_DATA_COUNT] = {{.fd = fd, .wd = -1, .mask = IN_ACCESS}, + {.fd = fd, .wd = -1, .mask = IN_MODIFY}, + {.fd = fd, .wd = -1, .mask = IN_ATTRIB}, + {.fd = fd, .wd = -1, .mask = IN_CLOSE_WRITE}, + {.fd = fd, .wd = -1, .mask = IN_CLOSE_NOWRITE}, + {.fd = fd, .wd = -1, .mask = IN_OPEN}, + {.fd = fd, .wd = -1, .mask = IN_MOVED_FROM}, + {.fd = fd, .wd = -1, .mask = IN_MOVED_TO}, + {.fd = fd, .wd = -1, .mask = IN_CREATE}, + {.fd = fd, .wd = -1, .mask = IN_DELETE}}; + + for (i = 0; i < TEST_DATA_COUNT; i++) { + data[i].wd = inotify_add_watch_test(fd, data[i].mask); + EXPECT_NE(msg, data[i].wd, ERREXPECT); + } + + for (i = 0; i < TEST_DATA_COUNT; i++) { + for (j = i; j >= 0; j--) { + if (data[j].wd != data[i].wd) { + int ret = inotify_rm_watch_test(fd, data[i].wd); + EXPECT_EQ(msg, ret, CMPFLAG); + break; + } + } + } + close(fd); +} + +/** + * @tc.name : inotify_init_0100 + * @tc.desc : initialize an inotify instance + * @tc.level : Level 0 + */ +void inotify_init_0100(void) +{ + int fd = inotify_init_test(); + EXPECT_NE("inotify_init_0100", fd, ERREXPECT); + EXPECT_EQ("inotify_init_0100", errno, CMPFLAG); + close(fd); +} + +/** + * @tc.name : inotify_add_watch_0100 + * @tc.desc : add some watches to an initialized inotify instance + * @tc.level : Level 0 + */ +void inotify_add_watch_0100(void) +{ + inotify_test("inotify_add_watch_0100"); +} + +/** + * @tc.name : inotify_add_watch_0200 + * @tc.desc : Using the wrong fd, add some monitoring events to the inotify instance + * @tc.level : Level 2 + */ +void inotify_add_watch_0200(void) +{ + int i; + struct inotify_test data[TEST_DATA_COUNT] = {{.fd = -1, .wd = -1, .mask = IN_ACCESS}, + {.fd = -1, .wd = -1, .mask = IN_MODIFY}, + {.fd = -1, .wd = -1, .mask = IN_ATTRIB}, + {.fd = -1, .wd = -1, .mask = IN_CLOSE_WRITE}, + {.fd = -1, .wd = -1, .mask = IN_CLOSE_NOWRITE}, + {.fd = -1, .wd = -1, .mask = IN_OPEN}, + {.fd = -1, .wd = -1, .mask = IN_MOVED_FROM}, + {.fd = -1, .wd = -1, .mask = IN_MOVED_TO}, + {.fd = -1, .wd = -1, .mask = IN_CREATE}, + {.fd = -1, .wd = -1, .mask = IN_DELETE}}; + + for (i = 0; i < TEST_DATA_COUNT; i++) { + data[i].wd = inotify_add_watch_test(data[i].fd, data[i].mask); + EXPECT_EQ("inotify_add_watch_0100", data[i].wd, ERREXPECT); + } +} + +/** + * @tc.name : inotify_rm_watch_0100 + * @tc.desc : Remove some monitoring events from the inotify instance + * @tc.level : Level 0 + */ +void inotify_rm_watch_0100(void) +{ + inotify_test("inotify_rm_watch_0100"); +} + +/** + * @tc.name : inotify_rm_watch_0200 + * @tc.desc : Provide exception parameter to remove monitoring event from inotify instance + * @tc.level : Level 2 + */ +void inotify_rm_watch_0200(void) +{ + int fd = inotify_init_test(); + if (fd == -1) { + return; + } + + int ret = inotify_rm_watch(fd, -1); + EXPECT_EQ("inotify_rm_watch_0200", ret, ERREXPECT); + close(fd); + + ret = inotify_rm_watch(-1, -1); + EXPECT_EQ("inotify_rm_watch_0200", ret, ERREXPECT); +} + +int main(void) +{ + inotify_init_0100(); + + inotify_add_watch_0100(); + inotify_add_watch_0200(); + + inotify_rm_watch_0100(); + inotify_rm_watch_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/inotify_init1.c b/libc-test/src/functionalext/supplement/linux/inotify_init1.c new file mode 100644 index 00000000..c36cc34c --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/inotify_init1.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : inotify_init1_0100 + * @tc.desc : Verify inotify_init1 process success. when param flag is 0 + * @tc.level : Level 0 + */ +void inotify_init1_0100(void) +{ + errno = 0; + int fd = inotify_init1(0); + EXPECT_NE("inotify_init1_0100", fd, -1); + EXPECT_EQ("inotify_init1_0100", errno, 0); + close(fd); +} + +/** + * @tc.name : inotify_init1_0200 + * @tc.desc : Verify inotify_init1 process success. when param flag is IN_NONBLOCK + * @tc.level : Level 0 + */ +void inotify_init1_0200(void) +{ + errno = 0; + int fd = inotify_init1(IN_NONBLOCK); + EXPECT_NE("inotify_init1_0200", fd, -1); + EXPECT_EQ("inotify_init1_0200", errno, 0); + close(fd); +} + +/** + * @tc.name : inotify_init1_0300 + * @tc.desc : Verify inotify_init1 process success. when param flag is IN_CLOEXEC + * @tc.level : Level 0 + */ +void inotify_init1_0300(void) +{ + errno = 0; + int fd = inotify_init1(IN_CLOEXEC); + EXPECT_NE("inotify_init1_0300", fd, -1); + EXPECT_EQ("inotify_init1_0300", errno, 0); + close(fd); +} + +/** + * @tc.name : inotify_init1_0400 + * @tc.desc : Verify inotify_init1 process success. when param flag is invalid + * @tc.level : Level 2 + */ +void inotify_init1_0400(void) +{ + errno = 0; + int fd = inotify_init1(-1); + EXPECT_EQ("inotify_init1_0400", fd, -1); + EXPECT_EQ("inotify_init1_0400", errno, EINVAL); + close(fd); +} + +int main(void) +{ + inotify_init1_0100(); + inotify_init1_0200(); + inotify_init1_0300(); + inotify_init1_0400(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/klogctl.c b/libc-test/src/functionalext/supplement/linux/klogctl.c new file mode 100644 index 00000000..5db97e73 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/klogctl.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define SYSLOG_ACTION_SIZE_BUFFER (10) + +/** + * @tc.name : klogctl_0100 + * @tc.desc : Verify klogctl process success. + * @tc.level : Level 0 + */ +void klogctl_0100(void) +{ + int ret = klogctl(SYSLOG_ACTION_SIZE_BUFFER, 0, 0); + EXPECT_MT("klogctl_0200", ret, 0); +} + +/** + * @tc.name : klogctl_0200 + * @tc.desc : Verify klogctl process fail bacause param type is invalid. + * @tc.level : Level 0 + */ +void klogctl_0200(void) +{ + int ret = klogctl(-1, 0, 0); + EXPECT_EQ("klogctl_0200", ret, -1); +} + +int main(void) +{ + klogctl_0100(); + klogctl_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/lgetxattr.c b/libc-test/src/functionalext/supplement/linux/lgetxattr.c new file mode 100644 index 00000000..ebe55176 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/lgetxattr.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const char *path = "file.txt"; +const char *name = "user.txt"; +const char *value = "dat"; +const int size = 3; + +/** + * @tc.name : lgetxattr_0100 + * @tc.desc : Verify lgetxattr process success. + * @tc.level : Level 0 + */ +void lgetxattr_0100(void) +{ + if (access(path, F_OK) == 0) { + remove(path); + } + mode_t perms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + int fd = open(path, O_RDWR | O_CREAT, perms); + if (fd == -1) { + t_error("%s failed: fd = %d\n", __func__, fd); + return; + } + + char str[] = "dat"; + write(fd, str, sizeof(str)); + close(fd); + system("chmod 777 file.txt"); + + int ret = lsetxattr(path, name, value, strlen(value), XATTR_CREATE); + if (ret != 0) { + remove(path); + t_error("%s failed: ret = %d\n", __func__, ret); + return; + } + + char buf[BUFSIZ] = {0}; + ret = lgetxattr(path, name, buf, sizeof(buf)); + EXPECT_EQ("lgetxattr_0100", ret, size); + EXPECT_STREQ("lgetxattr_0100", buf, str); + remove(path); +} + +/** + * @tc.name : lgetxattr_0200 + * @tc.desc : Verify lgetxattr process fail bacause param is null. + * @tc.level : Level 2 + */ +void lgetxattr_0200(void) +{ + int ret = lgetxattr(NULL, NULL, NULL, -1); + EXPECT_EQ("lgetxattr_0200", ret, -1); +} + +int main(void) +{ + lgetxattr_0100(); + lgetxattr_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/listxattr.c b/libc-test/src/functionalext/supplement/linux/listxattr.c new file mode 100644 index 00000000..f0b9883e --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/listxattr.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const char *path = "file.txt"; +const char *name = "user.txt"; +const char *value = "dat"; + +/** + * @tc.name : listxattr_0100 + * @tc.desc : Verify listxattr process success. + * @tc.level : Level 0 + */ +void listxattr_0100(void) +{ + if (access(path, F_OK) == 0) { + remove(path); + } + mode_t perms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + int fd = open(path, O_RDWR | O_CREAT, perms); + if (fd == -1) { + t_error("%s failed: fd = %d\n", __func__, fd); + return; + } + + char str[] = "dat"; + write(fd, str, sizeof(str)); + close(fd); + + system("chmod 777 file.txt"); + int ret = setxattr(path, name, value, strlen(value), XATTR_CREATE); + if (ret != 0) { + t_error("%s failed: ret = %d\n", __func__, ret); + remove(path); + return; + } + + char list[BUFSIZ] = {0}; + ret = listxattr(path, list, sizeof(list)); + EXPECT_TRUE("listxattr_0100", ret > 0); + if (strcasecmp(list, name)) { + if (strcasecmp(list, "security.selinux")) { + t_error("%s failed: list error\n", __func__); + } + } + ret = remove(path); + EXPECT_EQ("listxattr_0100", ret, 0); +} + +/** + * @tc.name : listxattr_0200 + * @tc.desc : Verify listxattr process fail bacause param is null. + * @tc.level : Level 2 + */ +void listxattr_0200(void) +{ + int ret = listxattr(NULL, NULL, -1); + EXPECT_EQ("listxattr_0200", ret, -1); +} + +int main(void) +{ + listxattr_0100(); + listxattr_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/llistxattr.c b/libc-test/src/functionalext/supplement/linux/llistxattr.c new file mode 100644 index 00000000..5cb261ec --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/llistxattr.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const char *path = "file.txt"; +const char *name = "user.txt"; +const char *value = "dat"; + +/** + * @tc.name : llistxattr_0100 + * @tc.desc : Verify llistxattr process success. + * @tc.level : Level 0 + */ +void llistxattr_0100(void) +{ + if (access(path, F_OK) == 0) { + remove(path); + } + mode_t perms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + int fd = open(path, O_RDWR | O_CREAT, perms); + if (fd == -1) { + t_error("%s failed: fd = %d\n", __func__, fd); + return; + } + + char str[] = "dat"; + write(fd, str, sizeof(str)); + close(fd); + + system("chmod 777 file.txt"); + int ret = lsetxattr(path, name, value, strlen(value), XATTR_CREATE); + if (ret != 0) { + t_error("%s failed: ret = %d\n", __func__, ret); + remove(path); + return; + } + + char list[BUFSIZ] = {0}; + ret = llistxattr(path, list, sizeof(list)); + EXPECT_TRUE("llistxattr_0100", ret > 0); + if (strcasecmp(list, name)) { + if (strcasecmp(list, "security.selinux")) { + t_error("%s failed: list error\n", __func__); + } + } + ret = remove(path); + EXPECT_EQ("listxattr_0100", ret, 0); +} + +/** + * @tc.name : llistxattr_0200 + * @tc.desc : Verify llistxattr process fail bacause param is null. + * @tc.level : Level 2 + */ +void llistxattr_0200(void) +{ + int ret = llistxattr(NULL, NULL, -1); + EXPECT_EQ("llistxattr_0200", ret, -1); +} + +int main(void) +{ + llistxattr_0100(); + llistxattr_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/lremovexattr.c b/libc-test/src/functionalext/supplement/linux/lremovexattr.c new file mode 100644 index 00000000..3db2f66b --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/lremovexattr.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const char *path = "file.txt"; +const char *name = "user.txt"; +const char *value = "dat"; +const int size = 3; + +/** + * @tc.name : lremovexattr_0100 + * @tc.desc : Verify lremovexattr process success. + * @tc.level : Level 0 + */ +void lremovexattr_0100(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + if (fd < 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + return; + } + + char str[] = "dat"; + write(fd, str, sizeof(str)); + close(fd); + + int ret = lsetxattr(path, name, value, strlen(value), XATTR_CREATE); + if (ret != 0) { + t_error("%s failed: ret = %d\n", __func__, ret); + return; + } + + char buf[BUFSIZ] = {0}; + + ret = lgetxattr(path, name, buf, sizeof(buf)); + EXPECT_EQ("lgetxattr_0100", ret, size); + EXPECT_STREQ("lgetxattr_0100", buf, str); + + ret = lremovexattr(path, name); + EXPECT_EQ("lremovexattr_0100", ret, 0); + + ret = lgetxattr(path, name, buf, sizeof(buf)); + EXPECT_EQ("lgetxattr_0100", ret, -1); + + ret = remove(path); + EXPECT_EQ("lgetxattr_0100", ret, 0); +} + +/** + * @tc.name : lremovexattr_0200 + * @tc.desc : Verify lremovexattr process fail bacause param is null. + * @tc.level : Level 0 + */ +void lremovexattr_0200(void) +{ + int ret = lremovexattr(NULL, NULL); + EXPECT_EQ("lremovexattr_0200", ret, -1); +} + +int main(void) +{ + lremovexattr_0100(); + lremovexattr_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/lsetxattr.c b/libc-test/src/functionalext/supplement/linux/lsetxattr.c new file mode 100644 index 00000000..0626cd00 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/lsetxattr.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const char *path = "file.txt"; +const char *name = "user.txt"; +const char *value = "dat"; +const int size = 3; + +/** + * @tc.name : lsetxattr_0100 + * @tc.desc : Verify lsetxattr process success. + * @tc.level : Level 0 + */ +void lsetxattr_0100(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + if (fd < 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + return; + } + + char str[] = "dat"; + write(fd, str, sizeof(str)); + close(fd); + + int ret = lsetxattr(path, name, value, strlen(value), XATTR_CREATE); + if (ret != 0) { + t_error("%s failed: ret = %d\n", __func__, ret); + return; + } + + char buf[BUFSIZ] = {0}; + + ret = lgetxattr(path, name, buf, sizeof(buf)); + EXPECT_EQ("lgetxattr_0100", ret, size); + EXPECT_STREQ("lgetxattr_0100", buf, str); + ret = remove(path); + EXPECT_EQ("lgetxattr_0100", ret, 0); +} + +/** + * @tc.name : lsetxattr_0200 + * @tc.desc : Verify lsetxattr process fail bacause param is null. + * @tc.level : Level 0 + */ +void lsetxattr_0200(void) +{ + int ret = lsetxattr(NULL, NULL, NULL, -1, -1); + EXPECT_EQ("lgetxattr_0200", ret, -1); +} + +int main(void) +{ + lsetxattr_0100(); + lsetxattr_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/membarrier.c b/libc-test/src/functionalext/supplement/linux/membarrier.c new file mode 100755 index 00000000..a56a7688 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/membarrier.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; +const int32_t COUNT_NEGATIVE = -1; +int membarrier(int, int); + +/** + * @tc.name : membarrier_0100 + * @tc.desc : Verify memory masking + * (all parameters are valid, CMD is not equal to MEMBARRIER_CMD_PRIVATE_EXPEDITED) + * @tc.level : Level 0 + */ +void membarrier_0100(void) +{ + int result; + result = membarrier(MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED, 0); + EXPECT_EQ("membarrier_0100", result, COUNT_ZERO); +} + +/** + * @tc.name : membarrier_0200 + * @tc.desc : Verify memory masking (valid with CMD equal to MEMBARRIER_CMD_PRIVATE_EXPEDITED) + * @tc.level : Level 1 + */ +void membarrier_0200(void) +{ + int result; + result = membarrier(MEMBARRIER_CMD_PRIVATE_EXPEDITED, 0); + EXPECT_EQ("membarrier_0200", result, COUNT_ZERO); +} + +/** + * @tc.name : membarrier_0300 + * @tc.desc : Verify that memory masking is not possible (CMD argument is invalid) + * @tc.level : Level 2 + */ +void membarrier_0300(void) +{ + int result; + result = membarrier(-1, 0); + EXPECT_EQ("membarrier_0300", result, COUNT_NEGATIVE); +} + +int main() +{ + membarrier_0100(); + membarrier_0200(); + membarrier_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/memfd_create.c b/libc-test/src/functionalext/supplement/linux/memfd_create.c new file mode 100644 index 00000000..2e43dde6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/memfd_create.c @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : memfd_create_0100 + * @tc.desc : Process memfd_create success. + * @tc.level : Level 0 + */ +void memfd_create_0100(void) +{ + char tmpfile[] = "/data/memfd_create_0100.txt"; + int fd = memfd_create(tmpfile, 0); + EXPECT_TRUE("memfd_create_0100", fd != -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("memfd_create_0100", cnt == strlen(tmpfile)); + close(fd); + } +} + +/** + * @tc.name: memfd_create_0200 + * @tc.desc: Process memfd_create fail. because param is error. + * @tc.level: Level 2 + */ +void memfd_create_0200(void) +{ + char tmpfile[] = "/data/memfd_create_0200.txt"; + int fd = memfd_create(tmpfile, -1); + EXPECT_TRUE("memfd_create_0200", fd == -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("memfd_create_0200", cnt == strlen(tmpfile)); + close(fd); + } +} + +int main(void) +{ + memfd_create_0100(); + memfd_create_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/mlock2.c b/libc-test/src/functionalext/supplement/linux/mlock2.c new file mode 100755 index 00000000..c8add87f --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/mlock2.c @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : mlock2_0100 + * @tc.desc : Lock 4k memory, release memory after unlocking + * @tc.level : Level 0 + */ +void mlock2_0100(void) +{ + size_t memsize = 4096; + char *memory = (char *)malloc(memsize); + if (memory == NULL) { + EXPECT_PTRNE("mlock2_0100", memory, NULL); + return; + } + memset(memory, '\0', memsize); + int ret = mlock2(memory, memsize, CMPFLAG); + EXPECT_EQ("mlock2_0100", ret, CMPFLAG); + + munlock(memory, memsize); + free(memory); + memory = NULL; +} + +/** + * @tc.name : mlock2_0200 + * @tc.desc : Lock 1k memory and mark all 4k memory size, release memory after unlocking + * @tc.level : Level 0 + */ +void mlock2_0200(void) +{ + size_t memsize = 4096; + size_t memchip = 1024; + char *memory = (char *)malloc(memsize); + if (memory == NULL) { + EXPECT_PTRNE("mlock2_0200", memory, NULL); + return; + } + memset(memory, '\0', memsize); + int ret = mlock2(memory, memchip, MLOCK_ONFAULT); + EXPECT_EQ("mlock2_0200", ret, CMPFLAG); + + munlock(memory, memsize); + free(memory); + memory = NULL; +} + +int main(void) +{ + mlock2_0100(); + mlock2_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/mount.c b/libc-test/src/functionalext/supplement/linux/mount.c new file mode 100644 index 00000000..245a0fa5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/mount.c @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : mount_0100 + * @tc.desc : Mount the directory /mymount to the /tmp directory + * @tc.level : Level 2 + */ +void mount_0100(void) +{ + const char special[] = "/mymount"; + const char target[] = "/tmp"; + int rev = mount(special, target, "", 0, ""); + EXPECT_EQ("mount_0100", rev, -1); + if (rev == 0) { + rev = umount(special); + EXPECT_EQ("mount_0100", rev, 0); + } +} + +int main(void) +{ + mount_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/name_to_handle_at.c b/libc-test/src/functionalext/supplement/linux/name_to_handle_at.c new file mode 100755 index 00000000..850237b3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/name_to_handle_at.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; + +/** + * @tc.name : name_to_handle_at_0100 + * @tc.desc : Verify that the name_TO_HANDLE_AT function was successfully called (all parameters are valid) + * @tc.level : Level 0 + */ +void name_to_handle_at_0100(void) +{ + int result; + struct file_handle *fhp; + int mount_id, fhsize, flags, dirfd; + char *pathname; + pathname = "/data"; + fhsize = sizeof(*fhp); + fhp = malloc(fhsize); + dirfd = AT_FDCWD; + flags = 0; + fhp->handle_bytes = 0; + name_to_handle_at(dirfd, pathname, fhp, &mount_id, flags); + fhsize = sizeof(struct file_handle) + fhp->handle_bytes; + fhp = realloc(fhp, fhsize); + result = name_to_handle_at(dirfd, pathname, fhp, &mount_id, flags); + EXPECT_EQ("name_to_handle_at_0100", result, COUNT_ZERO); +} + +int main() +{ + // name_to_handle_at_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/open_by_handle_at.c b/libc-test/src/functionalext/supplement/linux/open_by_handle_at.c new file mode 100755 index 00000000..857d818e --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/open_by_handle_at.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +#define LINE_SIZE 100 + +/** + * @tc.name : open_by_handle_at_0100 + * @tc.desc : Verify that the open_by_handle_at function was successfully called (all parameters are valid) + * @tc.level : Level 0 + */ +void open_by_handle_at_0100(void) +{ + int result; + struct file_handle *fhp; + int mount_id, fhsize, flags, dirfd; + char *pathname; + pathname = "/data"; + fhsize = sizeof(*fhp); + fhp = malloc(fhsize); + dirfd = AT_FDCWD; + flags = 0; + fhp->handle_bytes = 0; + name_to_handle_at(dirfd, pathname, fhp, &mount_id, flags); + fhsize = sizeof(struct file_handle) + fhp->handle_bytes; + fhp = realloc(fhp, fhsize); + name_to_handle_at(dirfd, pathname, fhp, &mount_id, flags); + result = open_by_handle_at(AT_FDCWD, fhp, O_NOFOLLOW); + bool flag = false; + if (result > 0) { + flag = true; + } + EXPECT_TRUE("open_by_handle_at_0100", flag); +} + +int main() +{ + // open_by_handle_at_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/personality.c b/libc-test/src/functionalext/supplement/linux/personality.c new file mode 100644 index 00000000..d00ec6b5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/personality.c @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : personality_0100 + * @tc.desc : Get System personality + * @tc.level : Level 0 + */ +void personality_0100(void) +{ + int ret = personality(-1); + EXPECT_EQ("personality_0100", ret & PER_MASK, PER_LINUX); +} + +int main(void) +{ + personality_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/ppoll.c b/libc-test/src/functionalext/supplement/linux/ppoll.c new file mode 100755 index 00000000..b5915066 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/ppoll.c @@ -0,0 +1,87 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : ppoll_0100 + * @tc.desc : Monitor the readable attribute time of the specified file + * @tc.level : Level 0 + */ +void ppoll_0100(void) +{ + int fd = open("ppoll_function_file", O_RDWR | O_CREAT, S_IRWXU); + if (fd == -1) { + t_error("create file failed\n"); + return; + } + struct pollfd pollfds[] = {{.fd = fd, .events = POLLIN, .revents = 0}}; + struct timespec timeout; + timeout.tv_sec = 5; + timeout.tv_nsec = 0; + + int ret = ppoll(pollfds, 1, &timeout, NULL); + EXPECT_GT("ppoll_0100", ret, CMPFLAG); + EXPECT_EQ("ppoll_0100", pollfds[0].revents, POLLIN); + close(fd); + ret = access("ppoll_function_file", F_OK); + if (ret != -1) { + ret = remove("ppoll_function_file"); + EXPECT_EQ("ppoll_0100", ret, CMPFLAG); + } +} + +/** + * @tc.name : ppoll_0200 + * @tc.desc : Listen to non-specified file time (timeout returns) + * @tc.level : Level 2 + */ +void ppoll_0200(void) +{ + struct pollfd pollfds[] = {{.fd = -1, .events = POLLIN, .revents = 0}}; + struct timespec timeout; + timeout.tv_sec = 3; + timeout.tv_nsec = 0; + + int ret = ppoll(pollfds, 1, &timeout, NULL); + EXPECT_EQ("ppoll_0200", ret, CMPFLAG); +} + +/** + * @tc.name : ppoll_0300 + * @tc.desc : Listen for readable file event (illegal parameter) + * @tc.level : Level 2 + */ +void ppoll_0300(void) +{ + struct timespec timeout; + timeout.tv_sec = 1; + timeout.tv_nsec = 0; + + int ret = ppoll(NULL, 1, &timeout, NULL); + EXPECT_EQ("ppoll_0300", ret, ERREXPECT); +} + +int main(void) +{ + ppoll_0100(); + ppoll_0200(); + ppoll_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/prctl.c b/libc-test/src/functionalext/supplement/linux/prctl.c new file mode 100755 index 00000000..bd324a6f --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/prctl.c @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/* + * @tc.name : prctl_0100 + * @tc.desc : Verify that the thread can be given a name and get the name + * @tc.level : Level 0 + */ +void prctl_0100(void) +{ + char buff[100] = {0}; + int prc = prctl(PR_SET_NAME, (unsigned long)"TestThread"); + int data = prctl(PR_GET_NAME, (unsigned long)buff); + EXPECT_EQ("prctl_0100", prc, 0); + EXPECT_EQ("prctl_0100", data, 0); + EXPECT_STREQ("prctl_0100", buff, "TestThread"); +} + +TEST_FUN G_Fun_Array[] = { + prctl_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/prlimit.c b/libc-test/src/functionalext/supplement/linux/prlimit.c new file mode 100755 index 00000000..83eec7ca --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/prlimit.c @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : prlimit_0100 + * @tc.desc : Set the heap size of the process, and re-get the heap size value of the process + * @tc.level : Level 0 + */ +void prlimit_0100(void) +{ + static const unsigned long long lim = 4; + struct rlimit new_limit = {.rlim_cur = lim, .rlim_max = lim}; + + struct rlimit old_limit = {.rlim_cur = 0, .rlim_max = 0}; + + int ret = prlimit(getpid(), RLIMIT_STACK, &new_limit, NULL); + EXPECT_EQ("prlimit_0100", ret, CMPFLAG); + ret = prlimit(getpid(), RLIMIT_STACK, NULL, &old_limit); + EXPECT_EQ("prlimit_0100", ret, CMPFLAG); + EXPECT_LONGLONGEQ("prlimit_0100", old_limit.rlim_cur, lim); + EXPECT_LONGLONGEQ("prlimit_0100", old_limit.rlim_max, lim); +} + +/** + * @tc.name : prlimit_0200 + * @tc.desc : An illegal parameter was passed in, setting the process limit parameter failed + * @tc.level : Level 2 + */ +void prlimit_0200(void) +{ + static const unsigned long long lim = 4; + struct rlimit new_limit = {.rlim_cur = lim, .rlim_max = lim}; + + int ret = prlimit(getpid(), -1, &new_limit, NULL); + EXPECT_EQ("prlimit_0200", ret, ERREXPECT); + + new_limit.rlim_cur = lim + 1; + ret = prlimit(getpid(), RLIMIT_STACK, &new_limit, NULL); + EXPECT_EQ("prlimit_0200", ret, ERREXPECT); +} + +int main(void) +{ + prlimit_0100(); + prlimit_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/process_vm.c b/libc-test/src/functionalext/supplement/linux/process_vm.c new file mode 100644 index 00000000..154fdc8b --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/process_vm.c @@ -0,0 +1,157 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define __VALUE_BUFFER_SIZE__ 256 +#define __VALUE_DATA_SIZE__ 2 + +/** + * @tc.name : process_vm_writev_0100 + * @tc.desc : Single data inter-process data transfer + * @tc.level : Level 0 + */ +void process_vm_writev_0100(void) +{ + char src[__VALUE_BUFFER_SIZE__] = "This is process_vm_writev_0100."; + char dst[__VALUE_BUFFER_SIZE__] = ""; + struct iovec local = {.iov_base = dst, .iov_len = sizeof(dst)}; + struct iovec remote = {.iov_base = src, .iov_len = sizeof(src)}; + + ssize_t rev = process_vm_readv(getpid(), &local, 1, &remote, 1, 0); + EXPECT_EQ("process_vm_writev_0100", rev, sizeof(dst)); + EXPECT_STREQ("process_vm_writev_0100", dst, src); +} + +/** + * @tc.name : process_vm_writev_0200 + * @tc.desc : Data transfer between multiple data processes + * @tc.level : Level 0 + */ +void process_vm_writev_0200(void) +{ + char src1[__VALUE_BUFFER_SIZE__] = "This is process_vm_writev_0200_1."; + char src2[__VALUE_BUFFER_SIZE__] = "This is process_vm_writev_0200_2."; + char dst1[__VALUE_BUFFER_SIZE__] = ""; + char dst2[__VALUE_BUFFER_SIZE__] = ""; + struct iovec local[__VALUE_DATA_SIZE__] = { + {.iov_base = dst1, .iov_len = sizeof(dst1)}, + {.iov_base = dst2, .iov_len = sizeof(dst2)}, + }; + struct iovec remote[__VALUE_DATA_SIZE__] = { + {.iov_base = src1, .iov_len = sizeof(src1)}, + {.iov_base = src2, .iov_len = sizeof(src2)}, + }; + + ssize_t rev = process_vm_readv(getpid(), local, 2, remote, 2, 0); + EXPECT_EQ("process_vm_writev_0200", rev, sizeof(dst1) + sizeof(dst2)); + int i; + for (i = 0; i < __VALUE_DATA_SIZE__; i++) { + EXPECT_STREQ("process_vm_writev_0200", local[i].iov_base, remote[i].iov_base); + } +} + +/** + * @tc.name : process_vm_writev_0300 + * @tc.desc : Provide the correct template, create a temporary file + * @tc.level : Level 2 + */ +void process_vm_writev_0300(void) +{ + char src[__VALUE_BUFFER_SIZE__] = "This is process_vm_writev_0300."; + struct iovec local = { + .iov_base = NULL, + .iov_len = 0, + }; + struct iovec remote = {.iov_base = src, .iov_len = sizeof(src)}; + + ssize_t rev = process_vm_readv(getpid(), &local, 1, &remote, 1, 0); + EXPECT_EQ("process_vm_writev_0300", rev, 0); +} + +/** + * @tc.name : process_vm_readv_0100 + * @tc.desc : Transfers data from the remote process to the local process + * @tc.level : Level 0 + */ +void process_vm_readv_0100(void) +{ + char src[__VALUE_BUFFER_SIZE__] = "This is process_vm_readv_0100."; + char dst[__VALUE_BUFFER_SIZE__] = ""; + struct iovec remote, local; + remote.iov_base = src; + remote.iov_len = __VALUE_BUFFER_SIZE__; + + local.iov_base = dst; + local.iov_len = __VALUE_BUFFER_SIZE__; + + int ret = process_vm_readv(getpid(), &local, 1, &remote, 1, 0); + EXPECT_EQ("process_vm_readv_0100", ret, sizeof(src)); + EXPECT_STREQ("process_vm_readv_0100", dst, src); +} + +/** + * @tc.name : process_vm_readv_0200 + * @tc.desc : No remote instance data specified, transfer data from remote process to local process + * @tc.level : Level 2 + */ +void process_vm_readv_0200(void) +{ + char dst[__VALUE_BUFFER_SIZE__] = ""; + struct iovec remote, local; + remote.iov_base = NULL; + remote.iov_len = __VALUE_BUFFER_SIZE__; + + local.iov_base = dst; + local.iov_len = __VALUE_BUFFER_SIZE__; + + int ret = process_vm_readv(getpid(), &local, 1, &remote, 1, 0); + EXPECT_EQ("process_vm_readv_0200", ret, ERREXPECT); + EXPECT_EQ("process_vm_readv_0200", errno, EFAULT); +} + +/** + * @tc.name : process_vm_readv_0300 + * @tc.desc : No local instance data specified, transfer data from remote process to local process + * @tc.level : Level 2 + */ +void process_vm_readv_0300(void) +{ + char src[__VALUE_BUFFER_SIZE__] = "This is process_vm_readv_0300."; + struct iovec remote, local; + remote.iov_base = src; + remote.iov_len = __VALUE_BUFFER_SIZE__; + + local.iov_base = NULL; + local.iov_len = __VALUE_BUFFER_SIZE__; + + int ret = process_vm_readv(getpid(), &local, 1, &remote, 1, 0); + EXPECT_EQ("process_vm_readv_0300", ret, ERREXPECT); + EXPECT_EQ("process_vm_readv_0300", errno, EFAULT); +} + +int main(void) +{ + process_vm_writev_0100(); + process_vm_writev_0200(); + process_vm_writev_0300(); + process_vm_readv_0100(); + process_vm_readv_0200(); + process_vm_readv_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/ptrace.c b/libc-test/src/functionalext/supplement/linux/ptrace.c new file mode 100644 index 00000000..c6864f2c --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/ptrace.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" +#include "sys/ptrace.h" + +#define PTRACE_TRACEME 0 + +/** + * @tc.name : ptrace_0100 + * @tc.desc : Verify ptrace process success + * @tc.level : Level 1 + */ +void ptrace_0100(void) +{ + int32_t ret; + pid_t child_pid = fork(); + ret = ptrace(PTRACE_TRACEME); + EXPECT_EQ("realpath_0100", ret, 0); +} + +int main(void) +{ + ptrace_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/quotactl.c b/libc-test/src/functionalext/supplement/linux/quotactl.c new file mode 100755 index 00000000..a7980bbf --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/quotactl.c @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : quotactl_0100 + * @tc.desc : Since there is no kernel with CONFIG_QUOTA enabled, the abnormal + * return value of the judgment function + * @tc.level : Level 2 + */ +void quotactl_0100(void) +{ + int cmd = QCMD(Q_GETQUOTA, USRQUOTA); + struct dqblk strinfo; + int ret = quotactl(cmd, "/dev", getuid(), (char *)(&strinfo)); + + EXPECT_EQ("quotactl_0100", ret, ERREXPECT); +} + +int main(void) +{ + quotactl_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/readahead.c b/libc-test/src/functionalext/supplement/linux/readahead.c new file mode 100644 index 00000000..762eb51c --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/readahead.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : readahead_0100 + * @tc.desc : Test file readahead for readahead method + * @tc.level : Level 2 + */ +void readahead_0100(void) +{ + int result = readahead(-1, 0, 123); + int errcode = -1; + if (result != errcode) { + t_error("%s readahead error get result is %d are not want -1\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + readahead_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/remap_file_pages.c b/libc-test/src/functionalext/supplement/linux/remap_file_pages.c new file mode 100755 index 00000000..ff407881 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/remap_file_pages.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +#define LEN 8192 +typedef void (*TEST_FUN)(); +const int32_t COUNT_ZERO = 0; + +/** + * @tc.name : remap_file_pages_0100 + * @tc.desc : Verify that a nonlinear mapping file can be created (parameters are valid) + * @tc.level : Level 0 + */ +void remap_file_pages_0100(void) +{ + int i, fd, ret; + char str[LEN] = {0}; + char *start = NULL; + fd = open("text", O_RDWR | O_CREAT); + start = mmap(NULL, LEN, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + ret = remap_file_pages(start, LEN >> 1, 0, 1, MAP_SHARED); + if (ret < 0) { + perror("remap file pages failed1"); + } + EXPECT_EQ("remap_file_pages_0100", ret, 0); + close(fd); + remove("text"); +} + +TEST_FUN G_Fun_Array[] = { + // remap_file_pages_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/removexattr.c b/libc-test/src/functionalext/supplement/linux/removexattr.c new file mode 100644 index 00000000..4f0fdc5a --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/removexattr.c @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "test.h" + +const char *path = "/data/tests/libc-test/src/file.txt"; +const char *name = "user.foo"; +const char *value = "bar"; + +/** + * @tc.name : removexattr_0100 + * @tc.desc : remove an extended attribute + * @tc.level : Level 0 + */ +void removexattr_0100(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + if (fd < 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + } + + char str[] = "bar"; + write(fd, str, sizeof(str)); + close(fd); + + errno = 0; + int result = setxattr(path, name, value, strlen(value), XATTR_CREATE); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + char buf[BUFSIZ] = {0}; + + errno = 0; + result = getxattr(path, name, buf, sizeof(buf)); + if (result < 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + if (strcmp(buf, str)) { + t_error("%s failed: buf = %s\n", __func__, buf); + } + + errno = 0; + result = removexattr(path, name); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + errno = 0; + result = getxattr(path, name, buf, sizeof(buf)); + if (result != -1) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno != ENODATA) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + remove(path); +} + +/** + * @tc.name : removexattr_0200 + * @tc.desc : remove an extended attribute with invalid parameters + * @tc.level : Level 2 + */ +void removexattr_0200(void) +{ + errno = 0; + int result = removexattr(NULL, NULL); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno != EFAULT) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + removexattr_0100(); + removexattr_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/sbrk.c b/libc-test/src/functionalext/supplement/linux/sbrk.c new file mode 100644 index 00000000..0a27f557 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/sbrk.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : sbrk_0100 + * @tc.desc : Find the current location of the program break + * @tc.level : Level 0 + */ +void sbrk_0100(void) +{ + errno = 0; + int *p = sbrk(0); + if (p == (void *)(-1)) { + t_error("%s sbrk failed\n", __func__); + } + if (errno == ENOMEM) { + t_error("%s errno is %d\n", __func__, errno); + } +} + +/** + * @tc.name : sbrk_0100 + * @tc.desc : Exception return value test when parameter is 1 + * @tc.level : Level 2 + */ +void sbrk_0200(void) +{ + errno = 0; + int *p = sbrk(1); + if (p != (void *)(-1)) { + t_error("%s sbrk failed\n", __func__); + } + if (errno != ENOMEM) { + t_error("%s errno is %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + sbrk_0100(); + sbrk_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/sendfile.c b/libc-test/src/functionalext/supplement/linux/sendfile.c new file mode 100644 index 00000000..6d916218 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/sendfile.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "test.h" + +const char *fromfile = "/data/tests/libc-test/src/fromfile.txt"; +const char *tofile = "/data/tests/libc-test/src/tofile.txt"; + +/** + * @tc.name : sendfile_0100 + * @tc.desc : transfer data between file descriptors + * @tc.level : Level 0 + */ +void sendfile_0100(void) +{ + FILE *f = fopen(fromfile, "w+"); + const char src[] = "A"; + fwrite(src, strlen(src), 1, f); + fclose(f); + + f = fopen(tofile, "w+"); + fclose(f); + + int fromfd = open(fromfile, O_RDONLY); + if (fromfd < 0) { + t_error("%s failed: open. fromfd = %d\n", __func__, fromfd); + } + + int tofd = open(tofile, O_WRONLY | O_CREAT); + if (tofd < 0) { + t_error("%s failed: open. tofd = %d\n", __func__, tofd); + } + + off_t off = 0; + int result = sendfile(tofd, fromfd, &off, 1); + if (result < 0) { + t_error("%s failed: sendfile. result = %d\n", __func__, result); + } + + close(fromfd); + close(tofd); + + f = fopen(tofile, "r"); + char buf[sizeof(src) + 1] = {0}; + fread(buf, 1, strlen(src), f); + fclose(f); + + if (strcmp(src, buf)) { + t_error("%s failed: sendfile. buf = %s\n", __func__, buf); + } + + remove(fromfile); + remove(tofile); +} + +/** + * @tc.name : sendfile_0200 + * @tc.desc : transfer data between invalid file descriptors + * @tc.level : Level 2 + */ +void sendfile_0200(void) +{ + int fromfd = -1; + int tofd = -1; + off_t off = 0; + + int result = sendfile(tofd, fromfd, &off, 1); + if (result >= 0) { + t_error("%s failed: sendfile. result = %d\n", __func__, result); + } + + if (errno != EBADF) { + t_error("%s failed: sendfile. errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + sendfile_0100(); + sendfile_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/setfsgid.c b/libc-test/src/functionalext/supplement/linux/setfsgid.c new file mode 100644 index 00000000..bd4639d6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/setfsgid.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "test.h" + +const gid_t fsgid = 1; +const gid_t invalid_fsgid = -1; + +/** + * @tc.name : setfsgid_0100 + * @tc.desc : set group identity used for filesystem checks + * @tc.level : Level 0 + */ +void setfsgid_0100(void) +{ + int result = setfsgid(fsgid); + if (result < 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = setfsgid(result); + if (result != fsgid) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : setfsgid_0200 + * @tc.desc : set an invalid group identity used for filesystem checks + * @tc.level : Level 2 + */ +void setfsgid_0200(void) +{ + int result = setfsgid(invalid_fsgid); + if (result < 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = setfsgid(result); + if (result == fsgid) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + // setfsgid_0100(); + // setfsgid_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/setfsuid.c b/libc-test/src/functionalext/supplement/linux/setfsuid.c new file mode 100644 index 00000000..255bcaf3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/setfsuid.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "test.h" + +const gid_t fsuid = 1; +const gid_t invalid_fsuid = -1; + +/** + * @tc.name : setfsuid_0100 + * @tc.desc : set user identity used for filesystem checks + * @tc.level : Level 0 + */ +void setfsuid_0100(void) +{ + int result = setfsuid(fsuid); + if (result < 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = setfsuid(result); + if (result != fsuid) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : setfsuid_0200 + * @tc.desc : set aninvalid user identity used for filesystem checks + * @tc.level : Level 2 + */ +void setfsuid_0200(void) +{ + int result = setfsuid(invalid_fsuid); + if (result < 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = setfsuid(result); + if (result == fsuid) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + // setfsuid_0100(); + // setfsuid_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/setgroups.c b/libc-test/src/functionalext/supplement/linux/setgroups.c new file mode 100644 index 00000000..53d3c803 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/setgroups.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +#define GROUPS_MAX 2 + +/** + * @tc.name : setgroups_0100 + * @tc.desc : Sets the supplementary group IDs for the calling process. + * @tc.level : Level 0 + */ +void setgroups_0100(void) +{ + gid_t groups[GROUPS_MAX]; + int count = GROUPS_MAX; + gid_t groupslist[GROUPS_MAX]; + int size = GROUPS_MAX; + groups[0] = 0; + groups[1] = 1; + int result = setgroups(count, groups); + if (result == -1) { + t_error("%s setgroups failed", __func__); + } + int num = getgroups(size, groupslist); + if (groupslist[0] != groups[0] && groupslist[1] != groups[1]) { + t_error("%s setgroups invalid", __func__); + } +} + +/** + * @tc.name : setgroups_0200 + * @tc.desc : Drop all of its supplementary groups. + * @tc.level : Level 0 + */ +void setgroups_0200(void) +{ + gid_t groups[GROUPS_MAX]; + int count = GROUPS_MAX; + gid_t groupslist[GROUPS_MAX]; + int size = GROUPS_MAX; + groups[0] = 0; + groups[1] = 1; + int result = setgroups(count, groups); + if (result == -1) { + t_error("%s setgroups failed", __func__); + } + if (setgroups(0, NULL) == -1) { + t_error("%s drop all of its supplementary groups failed", __func__); + return; + } + int num = getgroups(size, groupslist); + if (num != 0) { + t_error("%s drop failed", __func__); + } +} + +int main(int argc, char *argv[]) +{ + setgroups_0100(); + setgroups_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/setns.c b/libc-test/src/functionalext/supplement/linux/setns.c new file mode 100644 index 00000000..c9c7d8ee --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/setns.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "test.h" + +/** + * @tc.name : setns_0100 + * @tc.desc : reassociate thread with a namespace + * @tc.level : Level 0 + */ +void setns_0100(void) +{ + pid_t pid = getpid(); + if (pid < 0) { + t_error("%s failed: pid = %d\n", __func__, pid); + } + + int fd = syscall(SYS_pidfd_open, pid, 0); + if (fd < 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + } + + errno = 0; + int result = setns(fd, 0); + if (result != -1 || errno != EINVAL) { + t_error("%s failed: result = %d\n", __func__, result); + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +/** + * @tc.name : setns_0200 + * @tc.desc : reassociate an invliad fd with a namespace + * @tc.level : Level 2 + */ +void setns_0200(void) +{ + int fd = -1; + int nstype = 0; + + errno = 0; + int result = setns(fd, nstype); + if (result == 0 || errno == 0) { + t_error("%s failed: result = %d\n", __func__, result); + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + setns_0100(); + setns_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/settimeofday.c b/libc-test/src/functionalext/supplement/linux/settimeofday.c new file mode 100644 index 00000000..5535c726 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/settimeofday.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : settimeofday_0100 + * @tc.desc : Test that the function returns a value when tv points to a null pointer + * @tc.level : Level 0 + */ +void settimeofday_0100(void) +{ + int result = settimeofday(NULL, NULL); + if (result != 0) { + t_error("%s settimeofday failed", __func__); + } +} + +/** + * @tc.name : settimeofday_0200 + * @tc.desc : Test the return value of the function when usec in the parameter tv is 1000000ULL + * @tc.level : Level 1 + */ +void settimeofday_0200(void) +{ + struct timeval tv; + tv.tv_sec = 0; + tv.tv_usec = 1000000ULL; + + int result = settimeofday(&tv, NULL); + if (result != -1) { + t_error("%s settimeofday failed", __func__); + } +} + +/** + * @tc.name : settimeofday_0300 + * @tc.desc : Set the time to 10:1 on January 11, 1970 + * @tc.level : Level 1 + */ +void settimeofday_0300(void) +{ + struct timeval tv; + tv.tv_sec = 864000 + 36000 + 60; + tv.tv_usec = 0; + + int result = settimeofday(&tv, NULL); + if (result == -1) { + t_error("%s settimeofday failed", __func__); + } +} + +int main(int argc, char *argv[]) +{ + settimeofday_0100(); + settimeofday_0200(); + settimeofday_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/setxattr.c b/libc-test/src/functionalext/supplement/linux/setxattr.c new file mode 100644 index 00000000..fb71224b --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/setxattr.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "test.h" + +const char *path = "/data/tests/libc-test/src/file.txt"; +const char *name = "user.foo"; +const char *value = "bar"; + +/** + * @tc.name : setxattr_0100 + * @tc.desc : set an extended attribute value + * @tc.level : Level 0 + */ +void setxattr_0100(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + if (fd < 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + } + + char str[] = "bar"; + write(fd, str, sizeof(str)); + close(fd); + + errno = 0; + int result = setxattr(path, name, value, strlen(value), XATTR_CREATE); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + char buf[BUFSIZ] = {0}; + + errno = 0; + result = getxattr(path, name, buf, sizeof(buf)); + if (result < 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + if (strcmp(buf, str)) { + t_error("%s failed: buf = %s\n", __func__, buf); + } + + remove(path); +} + +/** + * @tc.name : setxattr_0200 + * @tc.desc : set an extended attribute value with invalid parameters + * @tc.level : Level 2 + */ +void setxattr_0200(void) +{ + errno = 0; + int result = setxattr(NULL, NULL, NULL, -1, -1); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno != EFAULT) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + setxattr_0100(); + setxattr_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/signalfd.c b/libc-test/src/functionalext/supplement/linux/signalfd.c new file mode 100644 index 00000000..01e2eb8d --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/signalfd.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +const int sig = SIGALRM; + +/** + * @tc.name : signalfd_0100 + * @tc.desc : create a file descriptor for accepting signals + * @tc.level : Level 0 + */ +void signalfd_0100(void) +{ + sigset_t mask = {}; + + int result = sigaddset(&mask, sig); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = sigprocmask(SIG_SETMASK, &mask, NULL); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + errno = 0; + int fd = signalfd(-1, &mask, SFD_CLOEXEC); + if (fd <= 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + } + + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + raise(sig); + + struct signalfd_siginfo sfd_si = {0}; + ssize_t size = read(fd, &sfd_si, sizeof(sfd_si)); + if (size <= 0) { + t_error("%s failed: size = %ld\n", __func__, size); + } + + if (sfd_si.ssi_signo != sig) { + t_error("%s failed: sfd_si.ssi_signo = %d\n", __func__, sfd_si.ssi_signo); + } + + close(fd); +} + +/** + * @tc.name : signalfd_0200 + * @tc.desc : create a file descriptor for accepting signals with invalid parameters + * @tc.level : Level 2 + */ +void signalfd_0200(void) +{ + errno = 0; + int fd = signalfd(-1, NULL, -1); + if (fd > 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + } + + if (errno == 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + signalfd_0100(); + signalfd_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/splice.c b/libc-test/src/functionalext/supplement/linux/splice.c new file mode 100644 index 00000000..725e4d60 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/splice.c @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "test.h" + +const char *fromfile = "/data/tests/libc-test/src/fromfile.txt"; +const char *tofile = "/data/tests/libc-test/src/tofile.txt"; +const char *path = "/proc/version"; + +/** + * @tc.name : splice_0100 + * @tc.desc : splice 0 data to/from a pipe + * @tc.level : Level 0 + */ +void splice_0100(void) +{ + int fromfd = open(fromfile, O_RDWR | O_CREAT); + if (fromfd < 0) { + t_error("%s failed: fromfd = %d\n", __func__, fromfd); + } + + int tofd = open(tofile, O_RDWR | O_CREAT); + if (tofd < 0) { + t_error("%s failed: tofd = %d\n", __func__, tofd); + } + + off_t off = 0; + size_t len = 0; + int flags = 0; + + errno = 0; + ssize_t result = splice(fromfd, &off, tofd, &off, len, flags); + if (result != 0) { + t_error("%s failed: result = %ld\n", __func__, result); + } + + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + remove(fromfile); + remove(tofile); +} + +/** + * @tc.name : splice_0200 + * @tc.desc : splice data to/from a pipe + * @tc.level : Level 1 + */ +void splice_0200(void) +{ + char buf[BUFSIZ] = {0}; + FILE *f = fopen(path, "r"); + if (f == NULL) { + t_error("%s failed: fopen\n", __func__); + return; + } + + fgets(buf, sizeof(buf), f); + fclose(f); + + int fromfd = open(path, O_RDONLY); + if (fromfd < 0) { + t_error("%s failed: fromfd = %d\n", __func__, fromfd); + } + + int pipe1[1 + 1]; + int result = pipe(pipe1); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + size_t len = BUFSIZ; + int flags = SPLICE_F_MORE | SPLICE_F_MOVE; + + ssize_t bytes = splice(fromfd, NULL, pipe1[1], NULL, len, flags); + if (bytes <= 0) { + t_error("%s failed: bytes = %ld\n", __func__, bytes); + return; + } + + close(pipe1[1]); + + char buf2[BUFSIZ] = {0}; + f = fdopen(pipe1[0], "r"); + if (f == NULL) { + t_error("%s failed: fdopen\n", __func__); + return; + } + + fgets(buf2, sizeof(buf2), f); + fclose(f); + + if (strcmp(buf2, buf)) { + t_error("%s failed: buf2 = %s\n", __func__, buf2); + return; + } +} + +/** + * @tc.name : splice_0300 + * @tc.desc : splice data to/from a pipe with invalid parameters + * @tc.level : Level 2 + */ +void splice_0300(void) +{ + errno = 0; + ssize_t bytes = splice(-1, NULL, -1, NULL, -1, -1); + if (bytes >= 0) { + t_error("%s failed: bytes = %ld\n", __func__, bytes); + } + + if (errno == 0) { + t_error("%s failed: errno = %ld\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + splice_0100(); + splice_0200(); + splice_0300(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/swapoff.c b/libc-test/src/functionalext/supplement/linux/swapoff.c new file mode 100644 index 00000000..4a9fd576 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/swapoff.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : swapoff_0100 + * @tc.desc : Stop swapping to file/device + * @tc.level : Level 0 + */ +void swapoff_0100(void) +{ + errno = 0; + system("cd /data/tests/libc-test/src; dd if=/dev/zero of=swapfile count=1 bs=1k; mkswap swapfile"); + int result = swapon("/data/tests/libc-test/src/swapfile", SWAP_FLAG_PREFER); + if (result == -1) { + t_error("%s swapon failed\n", __func__); + remove("/data/tests/libc-test/src/swapfile"); + return; + } + if (errno == ENOSYS) { + t_error("%s errno is %d\n", __func__, errno); + return; + } + + result = swapoff("/data/tests/libc-test/src/swapfile"); + if (result == -1) { + t_error("%s swapoff failed", __func__); + } +} + +int main(int argc, char *argv[]) +{ + // swapoff_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/swapon.c b/libc-test/src/functionalext/supplement/linux/swapon.c new file mode 100644 index 00000000..31bb7de9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/swapon.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : swapon_0100 + * @tc.desc : Start swapping to file/device + * @tc.level : Level 0 + */ +void swapon_0100(void) +{ + errno = 0; + system("cd /data/tests/libc-test/src; dd if=/dev/zero of=swapfile count=1 bs=1k; mkswap swapfile"); + int result = swapon("/data/tests/libc-test/src/swapfile", SWAP_FLAG_PREFER); + if (result == -1) { + t_error("%s swapon failed\n", __func__); + remove("/data/tests/libc-test/src/swapfile"); + } + + if (errno == ENOSYS) { + t_error("%s errno is %d\n", __func__, errno); + return; + } +} + +int main(int argc, char *argv[]) +{ + // swapon_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/sync_file_range.c b/libc-test/src/functionalext/supplement/linux/sync_file_range.c new file mode 100644 index 00000000..32f24c04 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/sync_file_range.c @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +const char *path = "/data/tests/libc-test/src/sync_file_range.txt"; + +/** + * @tc.name : sync_file_range_0100 + * @tc.desc : Check simple successful case + * @tc.level : Level 0 + */ +void sync_file_range_0100(void) +{ + errno = 0; + int result, fd; + + fd = open(path, O_RDWR | O_CREAT); + if (fd == -1) { + t_error("%s open failed\n", __func__); + return; + } + + result = sync_file_range(fd, 0, 1024, 0); + if (result == -1) { + t_error("%s sync_file_range failed, result is %d\n", __func__, result); + } + close(fd); + remove(path); +} + +/** + * @tc.name : sync_file_range_0200 + * @tc.desc : Check for invalid file descriptor + * @tc.level : Level 2 + */ +void sync_file_range_0200(void) +{ + errno = 0; + int result; + + result = sync_file_range(-1, 0, 0, 0); + if (result != -1) { + t_error("%s sync_file_range should failed, result is %d\n", __func__, result); + } + if (errno != EBADF) { + t_error("%s sync_file_range did not set errno to EBADF\n", __func__); + } +} + +/** + * @tc.name : sync_file_range_0300 + * @tc.desc : Check for invalid flags + * @tc.level : Level 2 + */ +void sync_file_range_0300(void) +{ + errno = 0; + int result, fd; + + fd = open(path, O_RDWR | O_CREAT); + if (fd == -1) { + t_error("%s open failed\n", __func__); + return; + } + + result = sync_file_range(fd, 0, 0, -1); + if (result != -1) { + t_error("%s sync_file_range did not failed with invalid flags, result is %d\n", __func__, result); + } + if (errno != EINVAL) { + t_error("%s sync_file_range did not set errno to EINVAL\n", __func__); + } + close(fd); + remove(path); +} + +/** + * @tc.name : sync_file_range_0400 + * @tc.desc : Check for negative offset + * @tc.level : Level 2 + */ +void sync_file_range_0400(void) +{ + errno = 0; + int result, fd; + + fd = open(path, O_RDWR | O_CREAT); + if (fd == -1) { + t_error("%s open failed\n", __func__); + return; + } + + result = sync_file_range(fd, -1, -1, 0); + if (result != -1) { + t_error("%s sync_file_range did not failed with invalid offset, result is %d\n", __func__, result); + } + if (errno != EINVAL) { + t_error("%s sync_file_range did not set errno to EINVAL\n", __func__); + } + close(fd); + remove(path); +} + +int main(int argc, char *argv[]) +{ + sync_file_range_0100(); + sync_file_range_0200(); + sync_file_range_0300(); + sync_file_range_0400(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/syncfs.c b/libc-test/src/functionalext/supplement/linux/syncfs.c new file mode 100644 index 00000000..cb731f9b --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/syncfs.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +const char *path = "/data/tests/libc-test/src/syncfs.txt"; + +/** + * @tc.name : syncfs_0100 + * @tc.desc : Commit filesystem caches to disk + * @tc.level : Level 0 + */ +void syncfs_0100(void) +{ + errno = 0; + int fd = open(path, O_RDWR | O_CREAT); + if (fd == -1) { + t_error("%s open failed\n", __func__); + return; + } + + int result = syncfs(fd); + if (result == -1) { + t_error("%s syncfs failed, result is %d\n", __func__, result); + } + if (errno == EBADF) { + t_error("%s errno is %d\n", __func__, errno); + } + close(fd); + remove(path); +} + +/** + * @tc.name : syncfs_0200 + * @tc.desc : Can't sync an invalid fd + * @tc.level : Level 2 + */ +void syncfs_0200(void) +{ + errno = 0; + int result = syncfs(-1); + if (result != -1) { + t_error("%s syncfs should failed, resuly is %d\n", __func__, result); + } + if (errno != EBADF) { + t_error("%s errno is %d\n", errno); + } +} + +int main(int argc, char *argv[]) +{ + syncfs_0100(); + syncfs_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/sysinfo.c b/libc-test/src/functionalext/supplement/linux/sysinfo.c new file mode 100644 index 00000000..1a7d00ba --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/sysinfo.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +/** + * @tc.name : sysinfo_0100 + * @tc.desc : return system information + * @tc.level : Level 0 + */ +void sysinfo_0100(void) +{ + struct sysinfo info; + memset(&info, 0, sizeof(info)); + + int result = sysinfo(&info); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + if (info.uptime <= 0) { + t_error("%s failed: info.uptime = %ld\n", __func__, info.uptime); + return; + } + + if (info.totalram < 0) { + t_error("%s failed: info.totalram = %ld\n", __func__, info.totalram); + return; + } + + if (info.totalram < info.freeram) { + t_error("%s failed: info.totalram = %ld, info.freeram = %ld\n", __func__, info.totalram, info.freeram); + return; + } + + if (info.totalswap < 0) { + t_error("%s failed: info.totalswap = %ld\n", __func__, info.totalswap); + return; + } + + if (info.totalswap < info.freeswap) { + t_error("%s failed: info.totalswap = %ld, info.freeswap = %ld\n", __func__, info.totalswap, info.freeswap); + return; + } +} + +/** + * @tc.name : sysinfo_0200 + * @tc.desc : return system information with NULL + * @tc.level : Level 2 + */ +void sysinfo_0200(void) +{ + int result = sysinfo(NULL); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + if (errno != EFAULT) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + sysinfo_0100(); + sysinfo_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/linux/tee.c b/libc-test/src/functionalext/supplement/linux/tee.c new file mode 100644 index 00000000..b62561f5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/tee.c @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +#define BUFF_SIZE (20) + +/** + * @tc.name : tee_0100 + * @tc.desc : Copy data between two pipe file descriptors + * @tc.level : Level 0 + */ +void tee_0100(void) +{ + char buf[BUFF_SIZE]; + char *text = "Hello"; + int result; + memset(buf, 0, sizeof(buf)); + + int pipefd1[2]; + result = pipe(pipefd1); + if (result == -1) { + t_error("%s pipe stdout failed\n", __func__); + } + if (write(pipefd1[1], text, strlen(text)) == -1) { + t_error("%s write failed\n", __func__); + } + + int pipefd2[2]; + result = pipe(pipefd2); + if (result == -1) { + t_error("%s pipe file failed\n", __func__); + } + + result = tee(pipefd1[0], pipefd2[1], 32768, SPLICE_F_NONBLOCK); + if (result == -1) { + t_error("%s tee failed\n", __func__); + } + if (read(pipefd2[0], buf, sizeof(buf)) == -1) { + t_error("%s read failed\n", __func__); + } + + if (strcmp(buf, text)) { + t_error("%s tee failed, buf = %s\n", __func__, buf); + } + close(pipefd1[0]); + close(pipefd1[1]); + close(pipefd2[0]); + close(pipefd2[1]); +} + +/** + * @tc.name : tee_0200 + * @tc.desc : Input argument is not a pipe descriptor + * @tc.level : Level 2 + */ +void tee_0200(void) +{ + char buf[BUFF_SIZE]; + char *text = "Hello"; + char *path = "/data/tests/libc-test/src/file.txt"; + int result; + + int fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0666); + if (fd < 0) { + t_error("%s open failed\n", __func__); + } + + int pipefd2[2]; + result = pipe(pipefd2); + if (result == -1) { + t_error("%s pipe file failed\n", __func__); + } + + result = tee(fd, pipefd2[1], 32768, SPLICE_F_NONBLOCK); + if (result != -1) { + t_error("%s test failed\n", __func__); + } + close(fd); + close(pipefd2[0]); + close(pipefd2[1]); +} + +int main(int argc, char *argv[]) +{ + tee_0100(); + tee_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/test_src_functionalext_supplement_linux.gni b/libc-test/src/functionalext/supplement/linux/test_src_functionalext_supplement_linux.gni new file mode 100644 index 00000000..34cbe049 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/test_src_functionalext_supplement_linux.gni @@ -0,0 +1,82 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_linux_test = [ + "getrandom", + "getxattr", + "inotify_init1", + "klogctl", + "lgetxattr", + "listxattr", + "llistxattr", + "lremovexattr", + "lsetxattr", + "memfd_create", + "personality", + "process_vm", + "ptrace", + "readahead", + "removexattr", + "sbrk", + "sendfile", + "setfsgid", + "setfsuid", + "setxattr", + "signalfd", + "splice", + "setgroups", + "setns", + "settimeofday", + "sysinfo", + "utimes", + "vmsplice", + "wait3", + "wait4", + "mount", + "prctl", + "capget", + "capset", + "eventfd_read", + "eventfd_write", + "flock", + "eventfd", + "fallocate", + "brk", + "clock_adjtime", + "fremovexattr", + "fsetxattr", + "flistxattr", + "adjtimex", + "fgetxattr", + "getdents", + "clone", + "tee", + "timerfd_create", + "timerfd_gettime", + "timerfd_settime", + "membarrier", + "swapon", + "swapoff", + "sync_file_range", + "syncfs", + "copy_file_range", + "name_to_handle_at", + "open_by_handle_at", + "remap_file_pages", + "inotify", + "mlock2", + "ppoll", + "prlimit", + "quotactl", + "chroot", +] diff --git a/libc-test/src/functionalext/supplement/linux/timerfd_create.c b/libc-test/src/functionalext/supplement/linux/timerfd_create.c new file mode 100644 index 00000000..6f69be9d --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/timerfd_create.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : timerfd_create_0100 + * @tc.desc : Create timer descriptor + * @tc.level : Level 0 + */ +void timerfd_create_0100(void) +{ + errno = 0; + int timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC); + if (timerfd == -1 || errno != 0) { + t_error("%s timerfd create failed", __func__); + return; + } + close(timerfd); +} + +/** + * @tc.name : timerfd_create_0200 + * @tc.desc : Create timer descriptor with different parameters + * @tc.level : Level 1 + */ +void timerfd_create_0200(void) +{ + errno = 0; + int timerfd = timerfd_create(CLOCK_REALTIME, 0); + if (timerfd == -1 || errno != 0) { + t_error("%s timerfd create failed", __func__); + return; + } + close(timerfd); +} + +/** + * @tc.name : timerfd_create_0300 + * @tc.desc : Exception parameter + * @tc.level : Level 2 + */ +void timerfd_create_0300(void) +{ + int timerfd = timerfd_create(-1, -1); + if (timerfd != -1) { + t_error("%s failed, timerfd is %d", __func__, timerfd); + return; + } + close(timerfd); +} + +int main(int argc, char *argv[]) +{ + timerfd_create_0100(); + timerfd_create_0200(); + timerfd_create_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/timerfd_gettime.c b/libc-test/src/functionalext/supplement/linux/timerfd_gettime.c new file mode 100644 index 00000000..9238e1ef --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/timerfd_gettime.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" + +#define NANOSECOND (1000000000) +#define MICROSECONDS (1000000) + +/** + * @tc.name : timerfd_gettime_0100 + * @tc.desc : Get the time left by the timer until the next supermarket + * @tc.level : Level 0 + */ +void timerfd_gettime_0100(void) +{ + struct itimerspec its = {{0, 0}, {2, 0}}; + struct itimerspec val; + int fd, result; + + fd = timerfd_create(CLOCK_REALTIME, 0); + if (fd < 0) { + t_error("%s timerfd_create failed", __func__); + return; + } + + result = timerfd_settime(fd, 0, &its, NULL); + if (result != 0) { + t_error("%s timerfd_settime failed", __func__); + return; + } + + result = usleep(MICROSECONDS); + if (result != 0) { + t_error("%s usleep failed", __func__); + return; + } + + result = timerfd_gettime(fd, &val); + if (result != 0) { + t_error("%s timerfd_gettime failed", __func__); + return; + } + if (val.it_value.tv_nsec > NANOSECOND) { + t_error("%s timerfd error"); + } +} + +/** + * @tc.name : timerfd_gettime_0200 + * @tc.desc : arms the timerfd with invalid parameters + * @tc.level : Level 2 + */ +void timerfd_gettime_0200(void) +{ + int result = timerfd_gettime(-1, NULL); + if (result != -1) { + t_error("%s failed, result is %d", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + timerfd_gettime_0100(); + timerfd_gettime_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/timerfd_settime.c b/libc-test/src/functionalext/supplement/linux/timerfd_settime.c new file mode 100644 index 00000000..34a51fc9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/timerfd_settime.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +#define NANOSECOND (1000000000) +#define MICROSECONDS (1000000) +#define DATA_TWO (2) + +void exception_handler(int sig) +{ + exit(t_status); +} + +/** + * @tc.name : timerfd_settime_0100 + * @tc.desc : Start the timer specified by fd + * @tc.level : Level 0 + */ +void timerfd_settime_0100(void) +{ + struct itimerspec its = {{0, 0}, {DATA_TWO, 0}}; + struct itimerspec val; + int fd, result; + + fd = timerfd_create(CLOCK_REALTIME, 0); + if (fd < 0) { + t_error("%s timerfd_create failed\n", __func__); + return; + } + + result = timerfd_settime(fd, 0, &its, NULL); + if (result != 0) { + t_error("%s timerfd_settime failed\n", __func__); + return; + } + + result = usleep(MICROSECONDS); + if (result != 0) { + t_error("%s usleep failed\n", __func__); + return; + } + + result = timerfd_gettime(fd, &val); + if (result != 0) { + t_error("%s timerfd_gettime failed\n", __func__); + return; + } + if (val.it_value.tv_nsec > NANOSECOND) { + t_error("%s timerfd error\n"); + } +} + +/** + * @tc.name : timerfd_settime_0200 + * @tc.desc : arms the timer with invalid parameters + * @tc.level : Level 2 + */ +void timerfd_settime_0200(void) +{ + signal(SIGSEGV, exception_handler); + + timerfd_settime(-1, 0, NULL, NULL); +} + +int main(int argc, char *argv[]) +{ + timerfd_settime_0100(); + timerfd_settime_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/utimes.c b/libc-test/src/functionalext/supplement/linux/utimes.c new file mode 100644 index 00000000..3e1be9a8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/utimes.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : utimes_0100 + * @tc.desc : Change file last access and modification times + * @tc.level : Level 0 + */ +void utimes_0100(void) +{ + const char *path = "/data/utimes.txt"; + int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); + if (fd == -1) { + t_error("%s write create file error", __func__); + return; + } + close(fd); + struct stat buf1; + struct stat buf2; + time_t t_mold, t_aold, t_now, t_new; + stat(path, &buf1); + + t_mold = buf1.st_mtime; + t_aold = buf1.st_atime; + t_now = time(NULL); + if (utimes(path, NULL) != 0) { + t_error("%s utimes failed", __func__); + } else { + stat(path, &buf2); + t_new = buf2.st_mtime; + if (t_new != t_now) { + t_error("%s utimes failed", __func__); + } + } + remove(path); +} + +/** + * @tc.name : utimes_0100 + * @tc.desc : Specify time to change file last access and modification time + * @tc.level : Level 1 + */ +void utimes_0200(void) +{ + const char *path = "/data/utimes.txt"; + int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); + if (fd == -1) { + t_error("%s write create file error", __func__); + return; + } + close(fd); + struct stat st; + struct timeval tv[2] = {{1, 0}, {1, 0}}; + + int result = utimes(path, tv); + if (result != 0) { + t_error("%s utimes failed", __func__); + } else { + stat(path, &st); + if (st.st_atime != tv[0].tv_sec && st.st_mtime != tv[1].tv_sec) { + t_error("%s utimes failed", __func__); + } + } + remove(path); +} + +int main(int argc, char *argv[]) +{ + utimes_0100(); + utimes_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/vmsplice.c b/libc-test/src/functionalext/supplement/linux/vmsplice.c new file mode 100644 index 00000000..321cb1dd --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/vmsplice.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +void vmsplice_0100(void) +{ + int pipe_size = 2; + int iov_length = 6; + int pipe_fds[pipe_size]; + if (pipe(pipe_fds) != 0) { + t_error("%s create pipe error\n", __func__); + } + struct iovec v[pipe_size]; + char *str_hello = "hello "; + char *str_world = "world\n"; + v[0].iov_base = str_hello; + v[0].iov_len = iov_length; + v[1].iov_base = str_world; + v[1].iov_len = iov_length; + size_t result = vmsplice(pipe_fds[1], v, sizeof(v) / sizeof(struct iovec), 0); + if (result != v[0].iov_len + v[1].iov_len) { + t_error("%s vmsplice error get result is %d are not want %d\n", __func__, result, v[0].iov_len + v[1].iov_len); + } + close(pipe_fds[1]); + char buf[BUFSIZ]; + FILE *fp = fdopen(pipe_fds[0], "r"); + if (!fp) { + t_error("%s fdopen get ptr is NULL\n", __func__); + } + if (!fgets(buf, sizeof(buf), fp)) { + t_error("%s fgets get ptr is NULL\n", __func__); + } + fclose(fp); + if (strcmp(buf, "hello world\n") != 0) { + t_error("%s fgets get str is '%s' are not want 'hello world'\n", __func__, buf); + } +} + +int main(int argc, char *argv[]) +{ + vmsplice_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/wait3.c b/libc-test/src/functionalext/supplement/linux/wait3.c new file mode 100644 index 00000000..a9c95f5b --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/wait3.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" + +const int EXIT_CODE = 66; +const int SLEEP_TIME = 2; + +/** + * @tc.name : wait3_0100 + * @tc.desc : Test the wait3 function to wait3 for the child process + * @tc.level : Level 0 + */ +void wait3_0100(void) +{ + pid_t pid = fork(); + if (pid > 0) { + int status = 0; + int options = 0; + struct rusage ru; + pid_t wait3_for_pind = wait3(&status, options, &ru); + if (wait3_for_pind != pid) { + t_error("%s wait3 get pid is %d are not want %d\n", __func__, wait3_for_pind, pid); + } + if (status != 0) { + t_error("%s wait3 get status is %d are not 0\n", __func__, status); + } + } else if (pid == 0) { + sleep(1); + exit(0); + } else { + t_error("%s wait3 fork error\n"); + } +} + +/** + * @tc.name : wait3_0200 + * @tc.desc : Test the result of the wait3 function when the exit code of the child process is not 0 + * @tc.level : Level 1 + */ +void wait3_0200(void) +{ + pid_t pid = fork(); + if (pid > 0) { + int status = 0; + int options = 0; + struct rusage ru; + pid_t wait3_for_pind = wait3(&status, options, &ru); + if (wait3_for_pind != pid) { + t_error("%s wait3 get pid is %d are not want %d\n", __func__, wait3_for_pind, pid); + } + if (status == 0) { + t_error("%s wait3 get status is 0\n", __func__); + } + } else if (pid == 0) { + sleep(1); + exit(EXIT_CODE); + } else { + t_error("%s wait3 fork error\n"); + } +} + +int main(int argc, char *argv[]) +{ + wait3_0100(); + sleep(SLEEP_TIME); + wait3_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/linux/wait4.c b/libc-test/src/functionalext/supplement/linux/wait4.c new file mode 100644 index 00000000..368f8bb7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/linux/wait4.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" + +const int EXIT_CODE = 66; +const int SLEEP_TIME = 2; + +/** + * @tc.name : wait4_0100 + * @tc.desc : Test the wait4 function to wait4 for the child process + * @tc.level : Level 0 + */ +void wait4_0100(void) +{ + pid_t pid = fork(); + if (pid > 0) { + int status = 0; + int options = 0; + struct rusage ru; + pid_t wait4_for_pind = wait4(pid, &status, options, &ru); + if (wait4_for_pind != pid) { + t_error("%s wait4 get pid is %d are not want %d\n", __func__, wait4_for_pind, pid); + } + if (status != 0) { + t_error("%s wait4 get status is %d are not 0\n", __func__, status); + } + } else if (pid == 0) { + sleep(1); + exit(0); + } else { + t_error("%s wait4 fork error\n"); + } +} + +/** + * @tc.name : wait4_0200 + * @tc.desc : Test the result of the wait4 function when the exit code of the child process is not 0 + * @tc.level : Level 1 + */ +void wait4_0200(void) +{ + pid_t pid = fork(); + if (pid > 0) { + int status = 0; + int options = 0; + struct rusage ru; + pid_t wait4_for_pind = wait4(pid, &status, options, &ru); + if (wait4_for_pind != pid) { + t_error("%s wait4 get pid is %d are not want %d\n", __func__, wait4_for_pind, pid); + } + if (status == 0) { + t_error("%s wait4 get status is 0\n", __func__); + } + } else if (pid == 0) { + sleep(1); + exit(EXIT_CODE); + } else { + t_error("%s wait4 fork error\n"); + } +} + +int main(int argc, char *argv[]) +{ + wait4_0100(); + sleep(SLEEP_TIME); + wait4_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/locale/BUILD.gn b/libc-test/src/functionalext/supplement/locale/BUILD.gn new file mode 100644 index 00000000..64301377 --- /dev/null +++ b/libc-test/src/functionalext/supplement/locale/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("//build/test.gni") +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_locale.gni") + +foreach(s, functionalext_supplement_locale_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/locale" + } +} + +group("functionalext_supplement_locale_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_locale_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/locale/duplocale.c b/libc-test/src/functionalext/supplement/locale/duplocale.c new file mode 100644 index 00000000..c6475784 --- /dev/null +++ b/libc-test/src/functionalext/supplement/locale/duplocale.c @@ -0,0 +1,80 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : duplocale_0100 + * @tc.desc : Asserts whether duplocale returns a null value for the global locale + * @tc.level : Level 0 + */ +void duplocale_0100(void) +{ + char *lo = setlocale(LC_ALL, "C"); + if (!lo) { + EXPECT_PTRNE("duplocale_0100", lo, NULL); + return; + } + + locale_t newlocale_ = duplocale(LC_GLOBAL_LOCALE); + EXPECT_TRUE("duplocale_0100", newlocale_); + if (newlocale_) { + freelocale(newlocale_); + newlocale_ = NULL; + } +} + +/** + * @tc.name : duplocale_0200 + * @tc.desc : Asserts that duplocale jumps first to the global locale and then to the custom locale, + * expecting that the results of the two calls are not equal + * @tc.level : Level 0 + */ +void duplocale_0200(void) +{ + char *lo = setlocale(LC_ALL, "C"); + if (!lo) { + EXPECT_PTRNE("duplocale_0200", lo, NULL); + return; + } + + locale_t global = duplocale(LC_GLOBAL_LOCALE); + EXPECT_PTRNE("duplocale_0200", global, NULL); + + locale_t newlocale_ = newlocale(LC_ALL_MASK, "en-US", NULL); + EXPECT_PTRNE("duplocale_0200", newlocale_, NULL); + + locale_t clonelocale = duplocale(newlocale_); + EXPECT_PTRNE("duplocale_0200", clonelocale, NULL); + EXPECT_PTRNE("duplocale_0200", clonelocale, global); + + if (clonelocale) { + freelocale(clonelocale); + clonelocale = NULL; + } + if (newlocale_) { + freelocale(newlocale_); + newlocale_ = NULL; + } +} + +int main(void) +{ + duplocale_0100(); + duplocale_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/locale/langinfo.c b/libc-test/src/functionalext/supplement/locale/langinfo.c new file mode 100644 index 00000000..cf2d3f18 --- /dev/null +++ b/libc-test/src/functionalext/supplement/locale/langinfo.c @@ -0,0 +1,138 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define TIME_ERROR_INFO 0x20034 +#define MESSAGES_ERROR_INFO 0x50004 + +/** + * @tc.name : langinfo_0100 + * @tc.desc : Asserts whether the nl_langinfo function succeeds in reading data + * from the MUSL_LOCPATH environment variable set to zh_CN. Utf-8 + * @tc.level : Level 0 + */ +void langinfo_0100(void) +{ + setenv("MUSL_LOCPATH", "/etc/locale", 1); + char *lo = setlocale(LC_TIME, ""); + if (!lo) { + EXPECT_PTRNE("nl_langinfo_0100", lo, NULL); + return; + } + lo = setlocale(LC_TIME, "zh_CN.UTF-8"); + if (!lo) { + EXPECT_PTRNE("nl_langinfo_0100", lo, NULL); + return; + } + char *ptr = nl_langinfo(DAY_2); + EXPECT_STREQ("nl_langinfo_0100", ptr, "Monday"); +} + +/** + * @tc.name : nl_langinfo_0200 + * @tc.desc : Assert that the nl_langinfo function does not read data from the default zh_CN.UTF-8 file + * when the locale is reset to the default environment + * @tc.level : Level 0 + */ +void nl_langinfo_0200() +{ + char *lo = setlocale(LC_TIME, ""); + if (!lo) { + EXPECT_PTRNE("nl_langinfo_0200", lo, NULL); + return; + } + char *ptr = nl_langinfo(DAY_2); + if (ptr) { + EXPECT_STRNE("nl_langinfo_0200", ptr, "lm星期一"); + } +} + +/** + * @tc.name : nl_langinfo_0300 + * @tc.desc : Assert whether the LC_TIME data type is set to zh_CN.UTF-8 through setlocale, and whether the + * return value is empty when the abnormal time data is passed to the nl_langinfo function + * @tc.level : Level 2 + */ +void nl_langinfo_0300() +{ + char *lo = setlocale(LC_TIME, ""); + if (!lo) { + EXPECT_PTRNE("nl_langinfo_0300", lo, NULL); + return; + } + lo = setlocale(LC_TIME, "zh_CN.UTF-8"); + if (!lo) { + EXPECT_PTRNE("nl_langinfo_0300", lo, NULL); + return; + } + char *ptr = nl_langinfo(TIME_ERROR_INFO); + EXPECT_STREQ("nl_langinfo_0300", ptr, ""); +} + +/** + * @tc.name : nl_langinfo_0400 + * @tc.desc : Assert whether the data type of LC_MESSAGES is set to zh_CN.UTF-8 through setlocale, and whether + * the return value is empty when the abnormal time data is passed to the nl_langinfo function + * @tc.level : Level 2 + */ +void nl_langinfo_0400() +{ + char *lo = setlocale(LC_MESSAGES, "zh_CN.UTF-8"); + if (!lo) { + EXPECT_PTRNE("nl_langinfo_0400", lo, NULL); + return; + } + char *ptr = nl_langinfo(MESSAGES_ERROR_INFO); + EXPECT_STREQ("nl_langinfo_0400", ptr, ""); +} + +/** + * @tc.name : nl_langinfo_0500 + * @tc.desc : Assert whether the return value result is UTF-8 or ASCII + * when the function nl_langinfo passes in the CODESET parameter + * @tc.level : Level 2 + */ +void nl_langinfo_0500() +{ + char *lo = setlocale(LC_CTYPE, ""); + if (!lo) { + EXPECT_PTRNE("nl_langinfo_0500", lo, NULL); + return; + } + char *ptr = nl_langinfo(CODESET); + EXPECT_STREQ("nl_langinfo_0500", ptr, "UTF-8"); + + lo = setlocale(LC_TIME, ""); + if (!lo) { + EXPECT_PTRNE("nl_langinfo_0500", lo, NULL); + return; + } + ptr = nl_langinfo(CODESET); + EXPECT_STREQ("nl_langinfo_0500", ptr, "UTF-8"); +} + +int main(void) +{ + langinfo_0100(); + nl_langinfo_0200(); + nl_langinfo_0300(); + nl_langinfo_0400(); + nl_langinfo_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/locale/localeconv.c b/libc-test/src/functionalext/supplement/locale/localeconv.c new file mode 100644 index 00000000..f214ffd9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/locale/localeconv.c @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : localeconv_0100 + * @tc.desc : Asserts whether the localeconv function returns a value that is expected by default + * @tc.level : Level 0 + */ +void localeconv_0100(void) +{ + struct lconv *pconv = localeconv(); + if (pconv == NULL) { + EXPECT_PTRNE("localeconv_0100", pconv, NULL); + return; + } + EXPECT_STREQ("localeconv_0100", ".", pconv->decimal_point); + EXPECT_STREQ("localeconv_0100", "", pconv->thousands_sep); + EXPECT_STREQ("localeconv_0100", "", pconv->grouping); + EXPECT_STREQ("localeconv_0100", "", pconv->int_curr_symbol); + EXPECT_STREQ("localeconv_0100", "", pconv->currency_symbol); + EXPECT_STREQ("localeconv_0100", "", pconv->mon_decimal_point); + EXPECT_STREQ("localeconv_0100", "", pconv->mon_thousands_sep); + EXPECT_STREQ("localeconv_0100", "", pconv->mon_grouping); + EXPECT_STREQ("localeconv_0100", "", pconv->positive_sign); + EXPECT_STREQ("localeconv_0100", "", pconv->negative_sign); + EXPECT_EQ("localeconv_0100", CHAR_MAX, pconv->int_frac_digits); + EXPECT_EQ("localeconv_0100", CHAR_MAX, pconv->frac_digits); + EXPECT_EQ("localeconv_0100", CHAR_MAX, pconv->p_cs_precedes); + EXPECT_EQ("localeconv_0100", CHAR_MAX, pconv->p_sep_by_space); + EXPECT_EQ("localeconv_0100", CHAR_MAX, pconv->n_cs_precedes); + EXPECT_EQ("localeconv_0100", CHAR_MAX, pconv->n_sep_by_space); + EXPECT_EQ("localeconv_0100", CHAR_MAX, pconv->p_sign_posn); + EXPECT_EQ("localeconv_0100", CHAR_MAX, pconv->n_sign_posn); +#ifdef __USE_ISOC99 + EXPECT_EQ("localeconv_0100", CHAR_MAX, pconv->int_p_cs_precedes); + EXPECT_EQ("localeconv_0100", CHAR_MAX, pconv->int_p_sep_by_space); + EXPECT_EQ("localeconv_0100", CHAR_MAX, pconv->int_n_cs_precedes); + EXPECT_EQ("localeconv_0100", CHAR_MAX, pconv->int_n_sep_by_space); + EXPECT_EQ("localeconv_0100", CHAR_MAX, pconv->int_p_sign_posn); + EXPECT_EQ("localeconv_0100", CHAR_MAX, pconv->int_n_sign_posn); +#endif +} + +int main(void) +{ + localeconv_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/locale/newlocale.c b/libc-test/src/functionalext/supplement/locale/newlocale.c new file mode 100644 index 00000000..d296a62f --- /dev/null +++ b/libc-test/src/functionalext/supplement/locale/newlocale.c @@ -0,0 +1,101 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +static const int lcMarkArry[] = {LC_PAPER_MASK, + LC_NAME_MASK, + LC_ADDRESS_MASK, + LC_TELEPHONE_MASK, + LC_MEASUREMENT_MASK, + LC_IDENTIFICATION_MASK, + LC_ALL_MASK}; + +/** + * @tc.name : newlocale_0100 + * @tc.desc : Check whether the LC_ALL type is passed to newlocale to create a custom locale environment + * @tc.level : Level 0 + */ +void newlocale_0100(void) +{ + char *lo = setlocale(LC_ALL, "C"); + if (!lo) { + EXPECT_PTRNE("newlocale_0100", lo, NULL); + return; + } + locale_t newlocale_ = newlocale(LC_ALL_MASK, "en-US", NULL); + EXPECT_PTRNE("newlocale_0100", newlocale_, NULL); + + if (newlocale_) { + freelocale(newlocale_); + newlocale_ = NULL; + } +} + +/** + * @tc.name : newlocale_0200 + * @tc.desc : Check whether the LC_ALL type is passed to newlocale to create a custom locale environment + * @tc.level : Level 0 + */ +void newlocale_0200(void) +{ + char *lo = setlocale(LC_ALL, "C"); + if (!lo) { + EXPECT_PTRNE("newlocale_0200", lo, NULL); + return; + } + locale_t newlocale_ = newlocale(LC_ALL_MASK, "C", NULL); + EXPECT_PTRNE("newlocale_0200", newlocale_, NULL); + + if (newlocale_) { + freelocale(newlocale_); + newlocale_ = NULL; + } +} + +/** + * @tc.name : newlocale_0300 + * @tc.desc : Determines whether the custom locale environment is created successfully + * by passing different LC data types to newlocale + * @tc.level : Level 0 + */ +void newlocale_0300(void) +{ + char *lo = setlocale(LC_ALL, "C"); + if (!lo) { + EXPECT_PTRNE("newlocale_0300", lo, NULL); + return; + } + for (int i = 0; i < sizeof(lcMarkArry) / sizeof(lcMarkArry[0]); i++) { + locale_t newlocale_ = newlocale(lcMarkArry[i], "en-US", NULL); + EXPECT_PTRNE("newlocale_0300", newlocale_, NULL); + + if (newlocale_) { + freelocale(newlocale_); + newlocale_ = NULL; + } + } +} + +int main(void) +{ + newlocale_0100(); + newlocale_0200(); + newlocale_0300(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/locale/setlocale.c b/libc-test/src/functionalext/supplement/locale/setlocale.c new file mode 100644 index 00000000..27e4b3fb --- /dev/null +++ b/libc-test/src/functionalext/supplement/locale/setlocale.c @@ -0,0 +1,182 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define TEST_LC_COUNT 7 +#define TEST_LC_LENGTH 18 +#define TEST_LC_OFFSET 6 +#define PARAM_ERROR_VALUE_1 13 +#define PARAM_ERROR_VALUE_2 (-1) + +static const int LcArry[TEST_LC_COUNT] = { + LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEASUREMENT, LC_IDENTIFICATION, LC_ALL}; + +static const char envforlocale[][TEST_LC_LENGTH] = { + "LC_PAPER", + "LC_NAME", + "LC_ADDRESS", + "LC_TELEPHONE", + "LC_MEASUREMENT", + "LC_IDENTIFICATION", +}; + +/** + * @tc.name : setlocaletest_0100 + * @tc.desc : Determines whether setlocale returns the default value C + * when the character set passed in for different data types is NULL + * @tc.level : Level 0 + */ +void setlocale_0100(void) +{ + const int num = sizeof(LcArry) / sizeof(LcArry[0]); + for (int i = 0; i < num; i++) { + const char *locale = setlocale(LcArry[i], NULL); + if (!locale) { + t_error("[%s] failed\n", "setlocale_0100"); + return; + } + EXPECT_EQ("SetlocaleTest_0100", strcmp(locale, "C"), 0); + } +} + +/** + * @tc.name : setlocaletest_0200 + * @tc.desc : Determines whether setlocale returns the default value "C" + * when the default value "C" is passed in for different LC data types + * @tc.level : Level 0 + */ +void setlocale_0200(void) +{ + const int num = sizeof(LcArry) / sizeof(LcArry[0]); + for (int i = 0; i < num; i++) { + setenv(envforlocale[i], "en-US", 1); + const char *locale = setlocale(LcArry[i], "C"); + if (!locale) { + t_error("[%s] failed\n", "setlocale_0200"); + return; + } + EXPECT_STREQ("SetlocaleTest_0200", locale, "C"); + } +} + +/** + * @tc.name : setlocaletest_0300 + * @tc.desc : Asserts whether the result returned is null when an exception LC data type is passed in + * @tc.level : Level 2 + */ +void setlocale_0300(void) +{ + const char *locale1 = setlocale(PARAM_ERROR_VALUE_1, NULL); + if (locale1) { + t_error("[%s] failed\n", "SetlocaleTest_0300"); + } + + const char *locale2 = setlocale(PARAM_ERROR_VALUE_2, NULL); + if (locale2) { + t_error("[%s] failed\n", "SetlocaleTest_0300"); + } +} + +/** + * @tc.name : setlocaletest_0400 + * @tc.desc : Determines whether setlocale returns da_DK + * when the environment variable is set to da_DK for different LC data types + * @tc.level : Level 0 + */ +void setlocale_0400(void) +{ + for (unsigned int i = 0; i < sizeof(envforlocale) / sizeof(envforlocale[0]); i++) { + setenv(envforlocale[i], "da_DK", 1); + const char *locale = setlocale(LcArry[i], ""); + if (!locale) { + t_error("[%s] failed\n", "setlocale_0400"); + return; + } + EXPECT_STREQ("SetlocaleTest_0400", locale, "da_DK"); + } +} + +/** + * @tc.name : setlocaletest_0500 + * @tc.desc : Determines whether setlocale returns en_ZA + * when the character set passed in for different LC data types is set to en_ZA + * @tc.level : Level 0 + */ +void setlocale_0500(void) +{ + char *rev = setlocale(LC_ALL, "C"); + if (!rev) { + t_error("[%s] failed\n", "setlocale_0500"); + return; + } + for (unsigned int i = 0; i < sizeof(LcArry) / sizeof(LcArry[0]); i++) { + const char *locale = setlocale(LcArry[i], "en_ZA"); + if (locale == NULL) { + t_error("[%s] failed\n", "setlocale_0500"); + return; + } + EXPECT_STREQ("SetlocaleTest_0600", locale, "en_ZA"); + } +} + +/** + * @tc.name : setlocaletest_0600 + * @tc.desc : Verify that the environment variable of different LC data types is set to ar_QA. When the setlocale + * function is used to pass LC_ALL, the corresponding field returned by the function is ar_QA + * @tc.level : Level 0 + */ +void setlocale_0600(void) +{ + for (unsigned int i = 0; i < sizeof(envforlocale) / sizeof(envforlocale[0]); i++) { + int count = 0; + char *vec[LC_ALL]; + const char *flag = ";"; + + setenv(envforlocale[i], "ar_QA", 1); + char *locale = setlocale(LC_ALL, ""); + if (locale == NULL) { + t_error("[%s] failed\n", "setlocale_0600"); + return; + } + + char *token = strtok(locale, flag); + while (token != NULL && count < LC_ALL) { + vec[count] = token; + token = strtok(NULL, flag); + count++; + } + + EXPECT_NE("setlocale_0600", count, 0); + + int expectPos = i + TEST_LC_OFFSET; + EXPECT_STREQ("setlocale_0600", "ar_QA", vec[expectPos]); + } +} + +int main(void) +{ + setlocale_0100(); + setlocale_0200(); + setlocale_0300(); + setlocale_0400(); + setlocale_0500(); + setlocale_0600(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/locale/strxfrm.c b/libc-test/src/functionalext/supplement/locale/strxfrm.c new file mode 100644 index 00000000..537d964d --- /dev/null +++ b/libc-test/src/functionalext/supplement/locale/strxfrm.c @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : strxfrm_0100 + * @tc.desc : Put all characters in src into dest + * @tc.level : Level 0 + */ +void strxfrm_0100(void) +{ + char desp[20] = {}; + char *str = "abcdef"; + int want = 6; + size_t result = strxfrm(desp, str, want + 1); + if (result != want) { + t_error("%s strxfrm get size is %d is not want %d\n", __func__, result, want); + } + if (strcmp(desp, str) != 0) { + t_error("%s strxfrm get desp is %s is not want %s\n", __func__, desp, str); + } +} + +/** + * @tc.name : strxfrm_0200 + * @tc.desc : Put all characters in src into dest, and set n to be the same as the length of src + * @tc.level : Level 1 + */ +void strxfrm_0200(void) +{ + char desp[20] = {}; + char *str = "abcdef"; + int want = 6; + size_t result = strxfrm(desp, str, want); + if (result != want) { + t_error("%s strxfrm get size is %d is not want %d\n", __func__, result, want); + } + if (strcmp(desp, str) == 0) { + t_error("%s strxfrm get desp is %s is not want %s\n", __func__, desp, str); + } +} + +/** + * @tc.name : strxfrm_0300 + * @tc.desc : Put all characters in src into dest, set n less than the length of src + * @tc.level : Level 1 + */ +void strxfrm_0300(void) +{ + char desp[20] = {}; + char *str = "abcdef"; + int want = 3; + size_t result = strxfrm(desp, str, want); + if (result != strlen(str)) { + t_error("%s strxfrm get size is %d is not want %d\n", __func__, result, strlen(str)); + } + if (strcmp(desp, str) == 0) { + t_error("%s strxfrm get desp is %s is not want %s\n", __func__, desp, str); + } +} + +/** + * @tc.name : strxfrm_0400 + * @tc.desc : Test empty string dest array size is less than src + * @tc.level : Level 1 + */ +void strxfrm_0400(void) +{ + char desp[5]; + char *str = "abcdef"; + int want = 6; + size_t result = strxfrm(desp, str, want + 1); + if (result != want) { + t_error("%s strxfrm get size is %d is not want %d\n", __func__, result, want); + } + if (strcmp(desp, str) != 0) { + t_error("%s strxfrm get desp is %s is not want %s\n", __func__, desp, str); + } +} + +/** + * @tc.name : strxfrm_0500 + * @tc.desc : Test to copy the content of src to the string dest of the existing content + * @tc.level : Level 1 + */ +void strxfrm_0500(void) +{ + char desp[10]; + strcpy(desp, "123"); + char *str = "abcdef"; + int want = 6; + size_t result = strxfrm(desp, str, want + 1); + if (result != want) { + t_error("%s strxfrm get size is %d is not want %d\n", __func__, result, want); + } + if (strcmp(desp, str) != 0) { + t_error("%s strxfrm get desp is %s is not want %s\n", __func__, desp, str); + } +} + +/** + * @tc.name : strxfrm_0600 + * @tc.desc : The test copies the content of src to dest whose length is greater than src through strxfrm + * @tc.level : Level 1 + */ +void strxfrm_0600(void) +{ + char desp[10]; + strcpy(desp, "1234567"); + char *str = "abcdef"; + int want = 6; + size_t result = strxfrm(desp, str, want + 1); + if (result != want) { + t_error("%s strxfrm get size is %d is not want %d\n", __func__, result, want); + } + if (strcmp(desp, str) != 0) { + t_error("%s strxfrm get desp is %s is not want %s\n", __func__, desp, str); + } +} + +/** + * @tc.name : strxfrm_0700 + * @tc.desc : Test move over src + * @tc.level : Level 1 + */ +void strxfrm_0700(void) +{ + char desp[10]; + strcpy(desp, "1234567"); + char *str = "abcdef"; + int move = 10; + size_t result = strxfrm(desp, str, move); + int want = 6; + if (result != want) { + t_error("%s strxfrm get size is %d is not want %d\n", __func__, result, want); + } + if (strcmp(desp, str) != 0) { + t_error("%s strxfrm get desp is %s is not want %s\n", __func__, desp, str); + } +} + +int main(int argc, char *argv[]) +{ + strxfrm_0100(); + strxfrm_0200(); + strxfrm_0300(); + strxfrm_0400(); + strxfrm_0500(); + strxfrm_0600(); + strxfrm_0700(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/locale/test_src_functionalext_supplement_locale.gni b/libc-test/src/functionalext/supplement/locale/test_src_functionalext_supplement_locale.gni new file mode 100644 index 00000000..741fbdc2 --- /dev/null +++ b/libc-test/src/functionalext/supplement/locale/test_src_functionalext_supplement_locale.gni @@ -0,0 +1,24 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_locale_test = [ + "duplocale", + "langinfo", + "localeconv", + "newlocale", + "setlocale", + "uselocale", + "strxfrm", + "wcscoll", + "wcsxfrm", +] diff --git a/libc-test/src/functionalext/supplement/locale/uselocale.c b/libc-test/src/functionalext/supplement/locale/uselocale.c new file mode 100644 index 00000000..3fb84351 --- /dev/null +++ b/libc-test/src/functionalext/supplement/locale/uselocale.c @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : uselocale_0100 + * @tc.desc : Asserts whether the result returned when uselocale passes a null pointer is the global locale + * @tc.level : Level 0 + */ +void uselocale_0100(void) +{ + char *rev = setlocale(LC_ALL, "C"); + if (!rev) { + EXPECT_PTRNE("uselocale_0100", rev, NULL); + return; + } + locale_t usenow = uselocale(NULL); + EXPECT_PTRNE("uselocale_0100", usenow, NULL); + EXPECT_PTREQ("uselocale_0100", usenow, LC_GLOBAL_LOCALE); +} + +/** + * @tc.name : uselocale_0200 + * @tc.desc : Asserts whether a custom locale is successfully created using newLOCALE and + * used using the custom locale using the uselocale function + * @tc.level : Level 0 + */ +void uselocale_0200(void) +{ + char *rev = setlocale(LC_ALL, "C"); + if (!rev) { + EXPECT_PTRNE("uselocale_0200", rev, NULL); + return; + } + uselocale(NULL); + locale_t newLocale = newlocale(LC_PAPER_MASK, "en_ZA", NULL); + if (newLocale == NULL) { + EXPECT_PTRNE("uselocale_0200", newLocale, NULL); + return; + } + + locale_t usenow = uselocale(newLocale); + EXPECT_PTREQ("uselocale_0200", usenow, LC_GLOBAL_LOCALE); + locale_t it = uselocale(NULL); + EXPECT_PTREQ("uselocale_0200", it, newLocale); + + if (newLocale) { + freelocale(newLocale); + newLocale = NULL; + } +} + +int main(void) +{ + uselocale_0100(); + uselocale_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/locale/wcscoll.c b/libc-test/src/functionalext/supplement/locale/wcscoll.c new file mode 100644 index 00000000..4ff7d9bd --- /dev/null +++ b/libc-test/src/functionalext/supplement/locale/wcscoll.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +void wcscoll_test(wchar_t *l, wchar_t *r, char *func_name, int want_result) +{ + int result = wcscoll(l, r); + if (result != want_result) { + t_error("%s wcscoll error get result is %d not want result %d\n", func_name, result, want_result); + } +} + +int main(int argc, char *argv[]) +{ + setlocale(LC_COLLATE, "en_US.utf8"); + /** + * @tc.name : wcscoll_0100 + * @tc.desc : Call wcscoll to compare the precedence of wide characters in the current locale + * @tc.level : Level 0 + */ + wcscoll_test(L"år", L"ängel", "wcscoll_0100", 1); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/locale/wcsxfrm.c b/libc-test/src/functionalext/supplement/locale/wcsxfrm.c new file mode 100644 index 00000000..04332eb7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/locale/wcsxfrm.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +void wcsxfrm_0100(void) +{ + wchar_t *wc = L"ABCD"; + wchar_t src[20]; + size_t result = wcsxfrm(src, wc, 5); + if (result != wcslen(wc)) { + t_error("%s wcsxfrm get result is %d are not %d\n", __func__, result, wcslen(wc)); + } + if (wcscmp(src, wc) != 0) { + t_error("%s wcsxfrm get is %ls are not %ls\n", __func__, src, wc); + } +} + +void wcsxfrm_0200(void) +{ + wchar_t *wc = L"\u00e5\ue011"; + wchar_t src[20]; + size_t result = wcsxfrm(src, wc, 1); + if (result != wcslen(wc)) { + t_error("%s wcsxfrm get result is %d are not %d\n", __func__, result, wcslen(wc)); + } +} + +int main(int argc, char *argv[]) +{ + setlocale(LC_COLLATE, "en_US.utf8"); + /** + * @tc.name : wcsxfrm_0100 + * @tc.desc : Call wcsxfrm to copy wide strings + * @tc.level : Level 0 + */ + wcsxfrm_0100(); + /** + * @tc.name : wcsxfrm_0200 + * @tc.desc : The incoming length is less than the wide string length + * @tc.level : Level 0 + */ + wcsxfrm_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/malloc/BUILD.gn b/libc-test/src/functionalext/supplement/malloc/BUILD.gn new file mode 100644 index 00000000..1b56f1e1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/malloc/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("//build/test.gni") +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_malloc.gni") + +foreach(s, functionalext_supplement_malloc_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/malloc" + } +} + +group("functionalext_supplement_malloc_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_malloc_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/malloc/aligned_alloc.c b/libc-test/src/functionalext/supplement/malloc/aligned_alloc.c new file mode 100644 index 00000000..107c7dee --- /dev/null +++ b/libc-test/src/functionalext/supplement/malloc/aligned_alloc.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : aligned_alloc_0100 + * @tc.desc : Verify that memory allocation is successful (parameters are valid) + * @tc.level : Level 0 + */ +void aligned_alloc_0100(void) +{ + bool flag = false; + int pagesize = getpagesize(); + int *p1 = (int *)aligned_alloc(pagesize, 1024 * sizeof(int)); + if (p1 != 0) { + flag = true; + } + EXPECT_TRUE("aligned_alloc_0100", flag); +} + +int main(void) +{ + aligned_alloc_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/malloc/malloc_usable_size.c b/libc-test/src/functionalext/supplement/malloc/malloc_usable_size.c new file mode 100755 index 00000000..4e0c66f6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/malloc/malloc_usable_size.c @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_MALLOC_SIZE 256 +#define TEST_MALLOC_PLACEHOLDER_SIZE 8 +#define TEST_MALLOC_PLACEHOLDER64_SIZE 16 +/** + * @tc.name : malloc_usable_size_0100 + * @tc.desc : Obtain size of block of memory allocated from heap + * @tc.level : Level 0 + */ +void malloc_usable_size_0100(void) +{ + void *p = malloc(TEST_MALLOC_SIZE); + EXPECT_PTRNE("malloc_usable_size_0100", p, NULL); + if (!p) { + return; + } + size_t ret = malloc_usable_size(p); +#ifdef _ARM64_ + EXPECT_EQ("malloc_usable_size_0100", ret, TEST_MALLOC_SIZE + TEST_MALLOC_PLACEHOLDER64_SIZE); +#else + EXPECT_EQ("malloc_usable_size_0100", ret, TEST_MALLOC_SIZE + TEST_MALLOC_PLACEHOLDER_SIZE); +#endif + free(p); +} + +/** + * @tc.name : malloc_usable_size_0200 + * @tc.desc : The parameter is NULL, get the memory size + * @tc.level : Level 2 + */ +void malloc_usable_size_0200(void) +{ + size_t ret = malloc_usable_size(NULL); + EXPECT_EQ("malloc_usable_size_0200", ret, CMPFLAG); +} + +int main(void) +{ + malloc_usable_size_0100(); + malloc_usable_size_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/malloc/memalign.c b/libc-test/src/functionalext/supplement/malloc/memalign.c new file mode 100644 index 00000000..6f795bdc --- /dev/null +++ b/libc-test/src/functionalext/supplement/malloc/memalign.c @@ -0,0 +1,137 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : memalign_0100 + * @tc.desc : Each parameter is valid, and align is obtained by getpagesize(), + * which can allocate a memory block whose size is specified + * by len and whose address is a multiple of align. + * @tc.level : Level 0 + */ +void memalign_0100(void) +{ + int align = getpagesize(); + void *buff = NULL; + if (align == -1) { + printf("getpagesize error!\n"); + } + buff = (void *)memalign(align, 8 * align); + bool flag = false; + if (buff != NULL) { + flag = true; + } + EXPECT_TRUE("memalign_0100", flag); + free(buff); + buff = NULL; +} + +/** + * @tc.name : memalign_0200 + * @tc.desc : Each parameter is valid, and it can allocate a memory block + * with the size specified by len and the address is a multiple of align + * @tc.level : Level 1 + */ +void memalign_0200(void) +{ + int align = 16; + void *buff = NULL; + if (align == -1) { + printf("getpagesize error!\n"); + } + buff = (void *)memalign(align, 8 * align); + bool flag = false; + if (buff != NULL) { + flag = true; + } + EXPECT_TRUE("memalign_0200", flag); + free(buff); + buff = NULL; +} + +/** + * @tc.name : memalign_0300 + * @tc.desc : The align parameter is invalid, and a memory block whose size is specified + * by len and whose address is a multiple of align cannot be allocated + * @tc.level : Level 2 + */ +void memalign_0300(void) +{ + int align = getpagesize() - 1; + void *buff = NULL; + if (align == -1) { + printf("getpagesize error!\n"); + } + buff = (void *)memalign(align, 128); + EXPECT_EQ("memalign_0300", buff, NULL); + free(buff); + buff = NULL; +} + +/** + * @tc.name : memalign_0400 + * @tc.desc : The len parameter is invalid, and a memory block whose size is specified by + * len and whose address is a multiple of align cannot be allocated + * @tc.level : Level 2 + */ +void memalign_0400(void) +{ + int align = getpagesize(); + void *buff = NULL; + if (align == -1) { + printf("getpagesize error!\n"); + } + buff = (void *)memalign(align, SIZE_MAX - align + 1); + EXPECT_EQ("memalign_0400", buff, NULL); + free(buff); + buff = NULL; +} + +/** + * @tc.name : memalign_0500 + * @tc.desc : Insufficient memory space to allocate a memory block + * with a size specified by len and an address that is a multiple of align + * @tc.level : Level 2 + */ +void memalign_0500(void) +{ + int align = (4 * sizeof(size_t)) + 1; + void *buff = NULL; + if (align == -1) { + printf("getpagesize error!\n"); + } + buff = (void *)memalign(align, align * 1024); + EXPECT_EQ("memalign_0500", buff, NULL); + free(buff); + buff = NULL; +} + +int main() +{ + memalign_0100(); + memalign_0200(); + memalign_0300(); + memalign_0400(); + memalign_0500(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/malloc/posix_memalign.c b/libc-test/src/functionalext/supplement/malloc/posix_memalign.c new file mode 100644 index 00000000..ae2bbd95 --- /dev/null +++ b/libc-test/src/functionalext/supplement/malloc/posix_memalign.c @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define TEST_MEMALIGN_ALIGN 16 + +/** + * @tc.name : posix_memalign_0100 + * @tc.desc : Allocate memory blocks with 16-byte alignment + * @tc.level : Level 0 + */ +void posix_memalign_0100(void) +{ + size_t block[] = {1, 4, 8, 256, 1024, 65000, 128000, 256000, 1000000}; + int count = sizeof(block) / sizeof(size_t); + int i = 0; + for (i = 0; i < count; i++) { + void *memory = NULL; + int rev = posix_memalign(&memory, TEST_MEMALIGN_ALIGN, block[i]); + EXPECT_EQ("posix_memalign_0100", rev, 0); + EXPECT_TRUE("posix_memalign_0100", memory != NULL); + if (memory) { + free(memory); + } + } +} + +/** + * @tc.name : posix_memalign_0200 + * @tc.desc : Synchronize a file with a memory map + * @tc.level : Level 2 + */ +void posix_memalign_0200(void) +{ + void *memory = NULL; + int rev = posix_memalign(&memory, 1, 1); + EXPECT_EQ("posix_memalign_0200", rev, EINVAL); + if (memory) { + free(memory); + } +} + +int main(void) +{ + posix_memalign_0100(); + posix_memalign_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/malloc/realloc.c b/libc-test/src/functionalext/supplement/malloc/realloc.c new file mode 100644 index 00000000..cf3494ea --- /dev/null +++ b/libc-test/src/functionalext/supplement/malloc/realloc.c @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define SIZE_ALIGN (4 * sizeof(size_t)) + +const int32_t RELLOCTLEN = 100; +const int32_t INVALIDLEN = -100; + +/** + * @tc.name: realloc_0100 + * @tc.desc: Verify realloc process success when first args is null second args is 50. + * @tc.level: level 0. + */ +void realloc_0100(void) +{ + void *ret = realloc(NULL, RELLOCTLEN); + EXPECT_PTRNE("realloc_0100", ret, NULL); +} + +/** + * @tc.name: realloc_0200 + * @tc.desc: Verify realloc process success when first args is null second args is 0. + * @tc.level: level 2 + */ +void realloc_0200(void) +{ + void *ret = realloc(NULL, 0); + EXPECT_PTRNE("realloc_0200", ret, NULL); +} + +/** + * @tc.name: realloc_0300 + * @tc.desc: Verify realloc process fail when first args is null second args is -100. + * @tc.level: level 2. + */ +void realloc_0300(void) +{ + void *ret = realloc(NULL, INVALIDLEN); + EXPECT_PTREQ("realloc_0300", ret, NULL); +} + +/** + * @tc.name: realloc_0400 + * @tc.desc: Verify realloc process success when first args is not null second args is 200 + * @tc.level: level 0. + */ +void realloc_0400(void) +{ + char *cptr = (char *)malloc(RELLOCTLEN); + void *ret = realloc(cptr, RELLOCTLEN + RELLOCTLEN); + EXPECT_PTRNE("realloc_0400", ret, NULL); +} + +/** + * @tc.name: realloc_0500 + * @tc.desc: Verify realloc process success when first args is not null second args is 100 + * @tc.level: level 1. + */ +void realloc_0500(void) +{ + char *cptr = (char *)malloc(RELLOCTLEN); + void *ret = realloc(cptr, RELLOCTLEN); + EXPECT_PTRNE("realloc_0500", ret, NULL); +} + +/** + * @tc.name: realloc_0600 + * @tc.desc: Verify realloc process success when first args is not null second args is 50 + * @tc.level: level 1. + */ +void realloc_0600(void) +{ + char *cptr = (char *)malloc(RELLOCTLEN); + void *ret = realloc(cptr, RELLOCTLEN / 2); + EXPECT_PTRNE("realloc_0600", ret, NULL); +} + +int main(void) +{ + realloc_0100(); + realloc_0200(); + realloc_0300(); + realloc_0400(); + realloc_0500(); + realloc_0600(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/malloc/test_src_functionalext_supplement_malloc.gni b/libc-test/src/functionalext/supplement/malloc/test_src_functionalext_supplement_malloc.gni new file mode 100644 index 00000000..f4f6a0a0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/malloc/test_src_functionalext_supplement_malloc.gni @@ -0,0 +1,20 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_malloc_test = [ + "realloc", + "posix_memalign", + "memalign", + "aligned_alloc", + "malloc_usable_size", +] diff --git a/libc-test/src/functionalext/supplement/manual/BUILD.gn b/libc-test/src/functionalext/supplement/manual/BUILD.gn new file mode 100644 index 00000000..dcc83265 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_maunal.gni") + +group("functionalext_supplement_manual_test") { + testonly = true + deps = [] + + foreach(s, functionalext_supplement_manual_test) { + deps += [ "${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/manual/env/BUILD.gn b/libc-test/src/functionalext/supplement/manual/env/BUILD.gn new file mode 100644 index 00000000..92ba7a0e --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/env/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../../test_template.gni") +import("test_src_functionalext_supplement_manual_env.gni") + +foreach(s, functionalext_supplement_manual_env_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/manual/env" + } +} + +group("functionalext_supplement_manual_env_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_manual_env_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/manual/env/a_stack_chk_fail.c b/libc-test/src/functionalext/supplement/manual/env/a_stack_chk_fail.c new file mode 100644 index 00000000..af7ad98d --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/env/a_stack_chk_fail.c @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +extern void __stack_chk_fail(void); + +const int32_t INIT_LEN = 0; +const int32_t INCREASE_LEN = 1; +int32_t flag = 0; + +void Killfunc(int signu) +{ + switch (signu) { + case SIGILL: + flag++; + EXPECT_EQ("a_stack_chk_fail_0100 exception", flag, INCREASE_LEN); + exit(-1); + case SIGSEGV: + flag++; + EXPECT_EQ("a_stack_chk_fail_0100 exception", flag, INCREASE_LEN); + exit(-1); + default: + break; + } + return; +} + +/** + * @tc.name : a_stack_chk_fail_0100 + * @tc.desc : Verify stack check fail process success + * @tc.level : Level 0 + */ +void a_stack_chk_fail_0100(void) +{ + struct sigaction act, oldact; + act.sa_handler = Killfunc; + act.sa_flags = 0; + sigaction(SIGILL, &act, &oldact); + sigaction(SIGSEGV, &act, &oldact); + __stack_chk_fail(); + EXPECT_EQ("a_stack_chk_fail_0100", flag, INIT_LEN); +} + +int main(void) +{ + a_stack_chk_fail_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/manual/env/test_src_functionalext_supplement_manual_env.gni b/libc-test/src/functionalext/supplement/manual/env/test_src_functionalext_supplement_manual_env.gni new file mode 100644 index 00000000..abafb510 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/env/test_src_functionalext_supplement_manual_env.gni @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_manual_env_test = [ "a_stack_chk_fail" ] diff --git a/libc-test/src/functionalext/supplement/manual/network/BUILD.gn b/libc-test/src/functionalext/supplement/manual/network/BUILD.gn new file mode 100644 index 00000000..8bb0ec81 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/network/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../../test_template.gni") +import("test_src_functionalext_supplement_manual_network.gni") + +foreach(s, functionalext_supplement_manual_network_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/manual/network" + } +} + +group("functionalext_supplement_manual_network_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_manual_network_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/manual/network/gethostbyaddr.c b/libc-test/src/functionalext/supplement/manual/network/gethostbyaddr.c new file mode 100644 index 00000000..16127e29 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/network/gethostbyaddr.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : gethostbyaddre_0100 + * @tc.desc : Can get host information through an IPv4 address. + * @tc.level : Level 0 + */ +void gethostbyaddre_0100(void) +{ + char *ptr = "127.0.0.1"; + struct hostent *hptr = NULL; + struct in_addr addr; + if (inet_pton(AF_INET, ptr, &addr) <= 0) { + printf("inet_pton error:%s\n", strerror(errno)); + } + hptr = gethostbyaddr((const char *)&addr, sizeof(addr), AF_INET); + if (hptr == NULL) { + printf("gethostbyaddr error:%s\n", strerror(h_errno)); + } + EXPECT_TRUE("gethostbyaddre_0100", hptr != NULL); + EXPECT_EQ("gethostbyaddre_0100", strcmp(hptr->h_name, ptr), 0); +} + +/** + * @tc.name : gethostbyaddre_0200 + * @tc.desc : Can obtain host information through an IPv6 address. + * @tc.level : Level 0 + */ +void gethostbyaddre_0200(void) +{ + char *ptr = "fe80::bed5:4695:6cac:bef8"; + struct hostent *hptr = NULL; + struct in_addr addr; + addr.s_addr = inet_addr(ptr); + hptr = gethostbyaddr((void *)&addr.s_addr, 16, AF_INET6); + EXPECT_TRUE("gethostbyaddre_0200", hptr != NULL); +} + +int main() +{ + gethostbyaddre_0100(); + gethostbyaddre_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/manual/network/gethostbyaddr_r.c b/libc-test/src/functionalext/supplement/manual/network/gethostbyaddr_r.c new file mode 100644 index 00000000..769e1646 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/network/gethostbyaddr_r.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : gethostbyaddr_r_0100 + * @tc.desc : Each parameter is valid, and multiple threads simultaneously obtain host information. + * @tc.level : Level 0 + */ +void gethostbyaddr_r_0100(void) +{ + struct hostent h, *res = NULL; + char buf[8192] = {0}; + int err = 0; + in_addr_t a = inet_addr("127.0.0.1"); + int ret = gethostbyaddr_r((void *)&a, 4, AF_INET, &h, buf, sizeof(buf), &res, &err); + EXPECT_EQ("gethostbyaddr_r_0100", ret, 0); + EXPECT_TRUE("gethostbyaddr_r_0100", strcmp(h.h_name, "127.0.0.1") == 0); +} + +/** + * @tc.name : gethostbyaddr_r_0200 + * @tc.desc : Invalid parameter, failed to get host information. + * @tc.level : Level 2 + */ +void gethostbyaddr_r_0200(void) +{ + struct hostent h, *res = NULL; + char buf[8192] = {0}; + int err = 0; + in_addr_t a = inet_addr("127.0.0.1"); + int ret = gethostbyaddr_r((void *)&a, 0, AF_INET, &h, buf, sizeof(buf), &res, &err); + EXPECT_NE("gethostbyaddr_r_0200", ret, 0); +} + +int main() +{ + gethostbyaddr_r_0100(); + gethostbyaddr_r_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/manual/network/gethostbyname2.c b/libc-test/src/functionalext/supplement/manual/network/gethostbyname2.c new file mode 100644 index 00000000..e8ff8d74 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/network/gethostbyname2.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : gethostbyname2_0100 + * @tc.desc : Verify that host information can be obtained (all parameters are valid, fd is AF_INET) + * @tc.level : Level 0 + */ +void gethostbyname2_0100(void) +{ + bool flag = false; + struct hostent *hptr; + hptr = gethostbyname2("127.0.0.1", AF_INET); + if (hptr != NULL) { + flag = true; + } + EXPECT_TRUE("gethostbyname2_0100", flag); + EXPECT_STREQ("gethostbyname2_0100", hptr->h_name, "127.0.0.1"); +} + +/** + * @tc.name : gethostbyname2_0200 + * @tc.desc : Verify that the host information can be obtained (all parameters are valid, fd is AF_INET6) + * @tc.level : Level 0 + */ +void gethostbyname2_0200(void) +{ + bool flag = false; + struct hostent *hptr; + hptr = gethostbyname2("::1", AF_INET6); + if (hptr != NULL) { + flag = true; + } + EXPECT_TRUE("gethostbyname2_0200", flag); + EXPECT_STREQ("gethostbyname2_0200", hptr->h_name, "::1"); +} + +/** + * @tc.name : gethostbyname2_0300 + * @tc.desc : Verify cannot get host information (name parameter invalid) + * @tc.level : Level 2 + */ +void gethostbyname2_0300(void) +{ + bool flag = false; + struct hostent *hptr; + hptr = gethostbyname2("127.0.w.1", AF_INET6); + if (hptr == NULL) { + flag = true; + } + EXPECT_TRUE("gethostbyname2_0300", flag); +} + +/** + * @tc.name : gethostbyname2_0400 + * @tc.desc : Verify that host information cannot be obtained (fd parameter invalid) + * @tc.level : Level 2 + */ +void gethostbyname2_0400(void) +{ + bool flag = false; + struct hostent *hptr; + hptr = gethostbyname2("::1", AF_INET); + if (hptr == NULL) { + flag = true; + } + EXPECT_TRUE("gethostbyname2_0400", flag); +} + +TEST_FUN G_Fun_Array[] = { + gethostbyname2_0100, + gethostbyname2_0200, + gethostbyname2_0300, + gethostbyname2_0400, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/manual/network/gethostbyname2_r.c b/libc-test/src/functionalext/supplement/manual/network/gethostbyname2_r.c new file mode 100644 index 00000000..db3f226a --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/network/gethostbyname2_r.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : gethostbyname2_r_0100 + * @tc.desc : The parameter fd is AF_INET, and multiple threads simultaneously obtain host information. + * @tc.level : Level 0 + */ +void gethostbyname2_r_0100(void) +{ + struct hostent h, *res = NULL; + char buf[8192] = {0}; + int err = 0; + + char *name = "127.0.0.1"; + int ret = gethostbyname2_r(name, AF_INET, &h, buf, sizeof(buf), &res, &err); + EXPECT_EQ("gethostbyname2_r_0100", ret, 0); + EXPECT_TRUE("gethostbyname2_r_0100", strcmp(h.h_name, "127.0.0.1") == 0); +} + +/** + * @tc.name : gethostbyname2_r_0200 + * @tc.desc : The parameter fd is AF_INET6, and multiple threads simultaneously obtain host information. + * @tc.level : Level 0 + */ +void gethostbyname2_r_0200(void) +{ + struct hostent h, *res = NULL; + char buf[8192] = {0}; + int err = 0; + + char *name = "::1"; + int ret = gethostbyname2_r(name, AF_INET6, &h, buf, sizeof(buf), &res, &err); + EXPECT_EQ("gethostbyname2_r_0200", ret, 0); + EXPECT_TRUE("gethostbyname2_r_0200", strcmp(h.h_name, "::1") == 0); +} + +/** + * @tc.name : gethostbyname2_r_0300 + * @tc.desc : The parameter name is invalid, the host information cannot be obtained. + * @tc.level : Level 2 + */ +void gethostbyname2_r_0300(void) +{ + struct hostent h, *res = NULL; + char buf[8192] = {0}; + int err = 0; + char *name = "aaaa"; + int ret = gethostbyname2_r(name, AF_INET, &h, buf, sizeof(buf), &res, &err); + EXPECT_NE("gethostbyname2_r_0300", ret, 0); +} + +/** + * @tc.name : gethostbyname2_r_0400 + * @tc.desc : The parameter fd is invalid, the host information cannot be obtained. + * @tc.level : Level 2 + */ +void gethostbyname2_r_0400(void) +{ + struct hostent h, *res = NULL; + char buf[8192] = {0}; + int err = 0; + char *name = "localhost"; + int ret = gethostbyname2_r(name, 0, &h, buf, sizeof(buf), &res, &err); + EXPECT_NE("gethostbyname2_r_0400", ret, 0); +} + +int main() +{ + gethostbyname2_r_0100(); + gethostbyname2_r_0200(); + gethostbyname2_r_0300(); + gethostbyname2_r_0400(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/manual/network/gethostbyname_r.c b/libc-test/src/functionalext/supplement/manual/network/gethostbyname_r.c new file mode 100644 index 00000000..e831c65d --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/network/gethostbyname_r.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int32_t COUNT_ZERO = 0; + +/** + * @tc.name : gethostbyname_r_0100 + * @tc.desc : Verify that the host information can be obtained + * @tc.level : Level 0 + */ +void gethostbyname_r_0100(void) +{ + bool flag = false; + int result = 10; + struct hostent h; + char buf[1024] = "\0"; + size_t buflen; + struct hostent *res = NULL; + int err; + result = gethostbyname_r("127.0.0.1", &h, buf, 1024, &res, &err); + if (result == 0) { + flag = true; + } + EXPECT_TRUE("gethostbyname_r_0100", flag); + EXPECT_STREQ("gethostbyname_r_0100", h.h_name, "127.0.0.1"); +} + +/** + * @tc.name : gethostbyname_r_0200 + * @tc.desc : The host information cannot be obtained + * @tc.level : Level 2 + */ +void gethostbyname_r_0200(void) +{ + bool flag = false; + int result = 10; + struct hostent h; + char buf[1024] = "\0"; + size_t buflen; + struct hostent *res = NULL; + int err; + result = gethostbyname_r("127.0.w.1", &h, buf, 1024, &res, &err); + if (result != 0) { + flag = true; + } + EXPECT_TRUE("gethostbyname_r_0200", flag); +} + +TEST_FUN G_Fun_Array[] = { + gethostbyname_r_0100, + gethostbyname_r_0200, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/manual/network/getnameinfo.c b/libc-test/src/functionalext/supplement/manual/network/getnameinfo.c new file mode 100644 index 00000000..a3d3a186 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/network/getnameinfo.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int INFO_RESULT = 0; +const int FAMILY_NOTSUPPORTED = -6; + +/** + * @tc.name : getnameinfo_0100 + * @tc.desc : Each parameter is valid and can resolve the IP address of the host name(hint.ai_flags =AI_ALL). + * @tc.level : Level 0 + */ +void getnameinfo_0100() +{ + int ret; + char host[NI_MAXHOST]; + char server[NI_MAXSERV]; + struct sockaddr_in sa; + memset(&sa, 0, sizeof(sa)); + sa.sin_family = AF_INET; + inet_pton(AF_INET, "127.0.0.1", &sa.sin_addr.s_addr); + ret = getnameinfo((const struct sockaddr *)(&sa), sizeof(sa), host, sizeof(host), server, sizeof(server), 0); + EXPECT_EQ("getnameinfo_0100", ret, INFO_RESULT); + EXPECT_NE("getnameinfo_0100", strlen(host), 0); + EXPECT_NE("getnameinfo_0100", strlen(server), 0); +} + +/** + * @tc.name : getnameinfo_0200 + * @tc.desc : Each parameter is valid and can resolve the IP address of the host name(hint.ai_flags =AI_ALL). + * @tc.level : Level 0 + */ +void getnameinfo_0200() +{ + int ret = -1; + int num = -1; + int res = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_NUMERICHOST; + hint.ai_family = AF_INET6; + char buf[] = "fe80::bed5:4695:6cac:bef8"; + ret = getaddrinfo(buf, NULL, &hint, &result); + char host[NI_MAXHOST]; + char server[NI_MAXSERV]; + if (ret == 0) { + res = getnameinfo(result->ai_addr, result->ai_addrlen, host, sizeof(host), server, sizeof(server), 0); + } + EXPECT_EQ("getnameinfo_0200", res, INFO_RESULT); + EXPECT_NE("getnameinfo_0200", strlen(host), 0); + EXPECT_NE("getnameinfo_0200", strlen(server), 0); + freeaddrinfo(result); + result = NULL; +} + +/** + * @tc.name : getnameinfo_0300 + * @tc.desc : Each parameter is valid and can resolve the IP address of the host name(hint.ai_flags =AI_ALL). + * @tc.level : Level 1 + */ +void getnameinfo_0300() +{ + int ret; + char host[NI_MAXHOST]; + char server[NI_MAXSERV]; + struct sockaddr_in sa; + memset(&sa, 0, sizeof(sa)); + sa.sin_family = AF_INET; + inet_pton(AF_INET, "127.0.0.1", &sa.sin_addr.s_addr); + ret = getnameinfo((const struct sockaddr *)(&sa), sizeof(sa), 0, 0, server, sizeof(server), 0); + EXPECT_EQ("getnameinfo_0300", ret, INFO_RESULT); + EXPECT_NE("getnameinfo_0300", strlen(server), 0); +} + +/** + * @tc.name : getnameinfo_0400 + * @tc.desc : Each parameter is valid and can resolve the IP address of the host name(hint.ai_flags =AI_ALL). + * @tc.level : Level 1 + */ +void getnameinfo_0400() +{ + int ret; + char host[NI_MAXHOST]; + char server[NI_MAXSERV]; + struct sockaddr_in sa; + memset(&sa, 0, sizeof(sa)); + sa.sin_family = AF_INET; + inet_pton(AF_INET, "127.0.0.1", &sa.sin_addr.s_addr); + ret = getnameinfo((const struct sockaddr *)(&sa), sizeof(sa), host, sizeof(host), 0, 0, 0); + EXPECT_EQ("getnameinfo_0400", ret, INFO_RESULT); + EXPECT_NE("getnameinfo_0400", strlen(host), 0); +} +/** + * @tc.name : getnameinfo_0500 + * @tc.desc : Each parameter is valid and can resolve the IP address of the host name(hint.ai_flags =AI_ALL). + * @tc.level : Level 2 + */ +void getnameinfo_0500() +{ + int ret; + char host[NI_MAXHOST]; + char server[NI_MAXSERV]; + struct sockaddr_in sa; + memset(&sa, 0, sizeof(sa)); + sa.sin_family = AF_INET; + inet_pton(AF_INET, "127.0.0.1", &sa.sin_addr.s_addr); + ret = getnameinfo((const struct sockaddr *)(&sa), 4, host, sizeof(host), server, sizeof(server), 0); + EXPECT_EQ("getnameinfo_0500", ret, FAMILY_NOTSUPPORTED); +} + +/** + * @tc.name : getnameinfo_0600 + * @tc.desc : Each parameter is valid and can resolve the IP address of the host name(hint.ai_flags =AI_ALL). + * @tc.level : Level 2 + */ +void getnameinfo_0600() +{ + int ret = -1; + int num = -1; + int res = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_NUMERICHOST; + hint.ai_family = AF_INET6; + char buf[] = "fe80::bed5:4695:6cac:bef8"; + ret = getaddrinfo(buf, NULL, &hint, &result); + char host[NI_MAXHOST]; + char server[NI_MAXSERV]; + if (ret == 0) { + res = getnameinfo(result->ai_addr, 4, host, sizeof(host), server, sizeof(server), 0); + } + EXPECT_EQ("getnameinfo_0600", res, FAMILY_NOTSUPPORTED); + freeaddrinfo(result); + result = NULL; +} + +/** + * @tc.name : getnameinfo_0700 + * @tc.desc : Each parameter is valid, sa->sa_family is AF_LOCAL, the information of the host cannot be obtained. + * @tc.level : Level 2 + */ +void getnameinfo_0700() +{ + int ret; + char host[NI_MAXHOST]; + char server[NI_MAXSERV]; + struct sockaddr_in sa; + memset(&sa, 0, sizeof(sa)); + sa.sin_family = AF_LOCAL; + ret = getnameinfo((const struct sockaddr *)(&sa), sizeof(sa), host, sizeof(host), server, sizeof(server), 0); + EXPECT_EQ("getnameinfo_0700", ret, FAMILY_NOTSUPPORTED); +} + +int main() +{ + getnameinfo_0100(); + getnameinfo_0200(); + getnameinfo_0300(); + getnameinfo_0400(); + getnameinfo_0500(); + getnameinfo_0600(); + getnameinfo_0700(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/manual/network/getnetbyaddr.c b/libc-test/src/functionalext/supplement/manual/network/getnetbyaddr.c new file mode 100755 index 00000000..61d020a0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/network/getnetbyaddr.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : getnetbyaddr_0100 + * @tc.desc : Verify that the network information is successfully obtained through a valid IPv4 address + * @tc.level : Level 0 + */ +void getnetbyaddr_0100(void) +{ + bool flag = false; + char *ptr, **pptr; + char str[INET_ADDRSTRLEN]; + struct hostent *hptr; + struct in_addr *addr; + struct sockaddr_in saddr; + inet_aton("127.0.0.1", &saddr.sin_addr); + hptr = gethostbyaddr((void *)&saddr.sin_addr, 4, AF_INET); + if (hptr != NULL) { + flag = true; + } + EXPECT_STREQ("getnetbyaddr_0100", hptr->h_name, "127.0.0.1"); + EXPECT_TRUE("getnetbyaddr_0100", flag); +} + +/** + * @tc.name : getnetbyaddr_0200 + * @tc.desc : Authentication failed to obtain network information through invalid IPv4 address + * @tc.level : Level 2 + */ +void getnetbyaddr_0200(void) +{ + bool flag = false; + char *ptr, **pptr; + char str[INET_ADDRSTRLEN]; + struct hostent *hptr; + struct in_addr *addr; + struct sockaddr_in saddr; + inet_aton("-128.256.w.1", &saddr.sin_addr); + hptr = gethostbyaddr((void *)&saddr.sin_addr, 0, AF_INET); + if (hptr == NULL) { + flag = true; + } + EXPECT_TRUE("getnetbyaddr_0200", flag); +} + +/** + * @tc.name : getnetbyaddr_0300 + * @tc.desc : Verify that the network information is successfully obtained through a valid IPv6 address + * @tc.level : Level 0 + */ +void getnetbyaddr_0300(void) +{ + bool flag = false; + char *ptr, **pptr; + char str[INET_ADDRSTRLEN]; + struct hostent *hptr; + struct in_addr *addr; + struct sockaddr_in saddr; + inet_aton("::1", &saddr.sin_addr); + hptr = gethostbyaddr((void *)&saddr.sin_addr, 16, AF_INET6); + if (hptr != NULL) { + flag = true; + } + EXPECT_TRUE("getnetbyaddr_0300", flag); +} + +/** + * @tc.name : getnetbyaddr_0400 + * @tc.desc : Authentication failed to obtain network information through invalid IPv6 address + * @tc.level : Level 2 + */ +void getnetbyaddr_0400(void) +{ + bool flag = false; + char *ptr, **pptr; + char str[INET_ADDRSTRLEN]; + struct hostent *hptr; + struct in_addr *addr; + struct sockaddr_in saddr; + inet_aton("0:-127.w.-256.1", &saddr.sin_addr); + hptr = gethostbyaddr((void *)&saddr.sin_addr, 4, AF_INET6); + if (hptr == NULL) { + flag = true; + } + EXPECT_TRUE("getnetbyaddr_0400", flag); +} + +TEST_FUN G_Fun_Array[] = { + getnetbyaddr_0100, + getnetbyaddr_0200, + getnetbyaddr_0300, + getnetbyaddr_0400, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/manual/network/getnetbyname.c b/libc-test/src/functionalext/supplement/manual/network/getnetbyname.c new file mode 100644 index 00000000..a54e566a --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/network/getnetbyname.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : getnetbyname_0100 + * @tc.desc : Verify the valid domain name to obtain network information successfully + * @tc.level : Level 0 + */ +void getnetbyname_0100(void) +{ + struct netent *Socket = NULL; + Socket = getnetbyname("127.0.0.1"); + if (Socket != NULL) { + printf(" name is %s\n", Socket->n_name); + } else { + printf("getnetbyname_0100 is failed\n"); + } +} + +/** + * @tc.name : getnetbyname_0200 + * @tc.desc : Failed to verify invalid domain name to obtain network information. + * @tc.level : Level 2 + */ +void getnetbyname_0200(void) +{ + struct netent *Socket = NULL; + Socket = getnetbyname("1ww.baidu.com"); + bool flag = false; + if (Socket == NULL) { + flag = true; + } + EXPECT_TRUE("getnetbyname_0200", flag); +} + +TEST_FUN G_Fun_Array[] = { + getnetbyname_0100, + getnetbyname_0200, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/manual/network/res_querydomain.c b/libc-test/src/functionalext/supplement/manual/network/res_querydomain.c new file mode 100755 index 00000000..fc4c7371 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/network/res_querydomain.c @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : res_querydomain_0100 + * @tc.desc : Verify that the domain name can be queried (parameters are valid) + * @tc.level : Level 0 + */ +void res_querydomain_0100(void) +{ + int aslen = 1024; + unsigned char aswr[1024]; + char name[] = "test"; + char domain[] = "hello"; + int result = res_querydomain(name, domain, 1, 1, aswr, aslen); + EXPECT_EQ("res_querydomain_0100", result, 0); +} + +/** + * @tc.name : res_querydomain_0200 + * @tc.desc : Verify that the domain name cannot be queried (the name parameter is invalid) + * @tc.level : Level 2 + */ +void res_querydomain_0200(void) +{ + int aslen = 1024; + unsigned char aswr[1024]; + char name[254]; + for (int i = 0; i < 254; i++) { + name[i] = 'a'; + } + char domain[] = "hello"; + int result = res_querydomain(name, domain, 1, 1, aswr, aslen); + EXPECT_EQ("res_querydomain_0200", result, -1); +} + +/** + * @tc.name : res_querydomain_0300 + * @tc.desc : Verify that the domain name cannot be queried (the domain parameter is invalid) + * @tc.level : Level 2 + */ +void res_querydomain_0300(void) +{ + int aslen = 1024; + unsigned char aswr[1024]; + char domain[254]; + for (int i = 0; i < 254; i++) { + domain[i] = 'a'; + } + char name[] = "test"; + int result = res_querydomain(name, domain, 1, 1, aswr, aslen); + EXPECT_EQ("res_querydomain_0300", result, -1); +} + +/** + * @tc.name : res_querydomain_0400 + * @tc.desc : Verify that the domain name cannot be queried (the name parameter and domain parameter are invalid) + * @tc.level : Level 2 + */ +void res_querydomain_0400(void) +{ + int aslen = 1024; + unsigned char aswr[1024]; + char name[254]; + char domain[254]; + for (int i = 0; i < 127; i++) { + name[i] = 'a'; + } + for (int j = 0; j < 127; j++) { + domain[j] = 'b'; + } + int result = res_querydomain(name, domain, 1, 1, aswr, aslen); + EXPECT_EQ("res_querydomain_0400", result, -1); +} + +TEST_FUN G_Fun_Array[] = { + res_querydomain_0100, + res_querydomain_0200, + res_querydomain_0300, + res_querydomain_0400, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/manual/network/res_send.c b/libc-test/src/functionalext/supplement/manual/network/res_send.c new file mode 100755 index 00000000..2a768999 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/network/res_send.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : res_send_0100 + * @tc.desc : Verify that the response can be sent (all parameters are valid) + * @tc.level : Level 0 + */ +void res_send_0100(void) +{ + bool flag = false; + int result; + unsigned char buf1[1024] = "127.0.0.1"; + unsigned char buf2[1024] = "\0"; + result = res_send(buf1, 0, buf2, 10); + if (result >= 0) { + flag = true; + } + EXPECT_TRUE("res_send_0100", flag); +} + +int main() +{ + res_send_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/manual/network/test_src_functionalext_supplement_manual_network.gni b/libc-test/src/functionalext/supplement/manual/network/test_src_functionalext_supplement_manual_network.gni new file mode 100644 index 00000000..e6e636f6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/network/test_src_functionalext_supplement_manual_network.gni @@ -0,0 +1,26 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_manual_network_test = [ + "getnameinfo", + "getnetbyaddr", + "res_send", + "res_querydomain", + "gethostbyname2", + "gethostbyname_r", + "gethostbyaddr_r", + "gethostbyname2_r", + "gethostbyaddr", + + #"getnetbyname", +] diff --git a/libc-test/src/functionalext/supplement/manual/termios/BUILD.gn b/libc-test/src/functionalext/supplement/manual/termios/BUILD.gn new file mode 100644 index 00000000..d8fcca44 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/termios/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../../test_template.gni") +import("test_src_functionalext_supplement_manual_termios.gni") + +foreach(s, functionalext_supplement_manual_termios_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/manual/termios" + } +} + +group("functionalext_supplement_manual_termios_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_manual_termios_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/manual/termios/tcgetattr.c b/libc-test/src/functionalext/supplement/manual/termios/tcgetattr.c new file mode 100644 index 00000000..2840c8ab --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/termios/tcgetattr.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +/** + * @tc.name : tcgetattr_0100 + * @tc.desc : get terminal attributes + * @tc.level : Level 0 + */ +void tcgetattr_0100(void) +{ + struct termios tio = {}; + int result = tcgetattr(STDIN_FILENO, &tio); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : tcgetattr_0200 + * @tc.desc : get terminal attributes with invalid parameters + * @tc.level : Level 2 + */ +void tcgetattr_0200(void) +{ + errno = 0; + int result = tcgetattr(-1, NULL); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno == 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + tcgetattr_0100(); + tcgetattr_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/manual/termios/tcgetsid.c b/libc-test/src/functionalext/supplement/manual/termios/tcgetsid.c new file mode 100644 index 00000000..8209f908 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/termios/tcgetsid.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : tcgetsid_0100 + * @tc.desc : Get session ID + * @tc.level : Level 0 + */ +void tcgetsid_0100(void) +{ + errno = 0; + pid_t sid; + + sid = tcgetsid(STDIN_FILENO); + if (sid == -1) { + t_error("%s tcgetsid failed\n", __func__); + } + if (errno != 0) { + t_error("%s errno is %d\n", __func__, errno); + } +} + +/** + * @tc.name : tcgetsid_0200 + * @tc.desc : Fd is not a valid file descriptor + * @tc.level : Level 2 + */ +void tcgetsid_0200(void) +{ + errno = 0; + pid_t sid; + sid = tcgetsid(-1); + if (sid != -1) { + t_error("%s tcgetsid should failed, sid is %d", __func__, sid); + } + if (errno != EBADF) { + t_error("%s errno is %d", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + tcgetsid_0100(); + tcgetsid_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/manual/termios/tcsendbreak.c b/libc-test/src/functionalext/supplement/manual/termios/tcsendbreak.c new file mode 100644 index 00000000..430ef7f8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/termios/tcsendbreak.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : tcsendbreak_0100 + * @tc.desc : Send a break condition to a terminal + * @tc.level : Level 0 + */ +void tcsendbreak_0100(void) +{ + int result = tcsendbreak(STDIN_FILENO, 0); + if (result != 0) { + t_error("%s tcsendbreak failed\n", __func__); + } +} + +/** + * @tc.name : tcsendbreak_0200 + * @tc.desc : Fd is not a valid file descriptor + * @tc.level : Level 0 + */ +void tcsendbreak_0200(void) +{ + errno = 0; + int result = tcsendbreak(-1, 0); + if (result == 0) { + t_error("%s tcsendbreak should failed\n", __func__); + } + if (errno != EBADF) { + t_error("%s errno is %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + tcsendbreak_0100(); + tcsendbreak_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/manual/termios/tcsetattr.c b/libc-test/src/functionalext/supplement/manual/termios/tcsetattr.c new file mode 100644 index 00000000..2fdf2559 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/termios/tcsetattr.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +const cc_t veof = (cc_t)0x07; + +/** + * @tc.name : tcsetattr_0100 + * @tc.desc : set terminal attributes + * @tc.level : Level 0 + */ +void tcsetattr_0100(void) +{ + struct termios tio = {}; + tio.c_cc[VEOF] = veof; + int result = tcsetattr(STDIN_FILENO, TCSAFLUSH, &tio); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = tcgetattr(STDIN_FILENO, &tio); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (tio.c_cc[VEOF] != veof) { + t_error("%s failed: tio.c_cc[%d] = %#x\n", __func__, VEOF, tio.c_cc[VEOF]); + } +} + +/** + * @tc.name : tcsetattr_0200 + * @tc.desc : set terminal attributes with invalid parameters + * @tc.level : Level 2 + */ +void tcsetattr_0200(void) +{ + errno = 0; + int result = tcsetattr(-1, -1, NULL); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno == 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + tcsetattr_0100(); + tcsetattr_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/manual/termios/test_src_functionalext_supplement_manual_termios.gni b/libc-test/src/functionalext/supplement/manual/termios/test_src_functionalext_supplement_manual_termios.gni new file mode 100644 index 00000000..8aed730b --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/termios/test_src_functionalext_supplement_manual_termios.gni @@ -0,0 +1,19 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_manual_termios_test = [ + "tcgetsid", + "tcsendbreak", + "tcgetattr", + "tcsetattr", +] diff --git a/libc-test/src/functionalext/supplement/manual/test_src_functionalext_supplement_maunal.gni b/libc-test/src/functionalext/supplement/manual/test_src_functionalext_supplement_maunal.gni new file mode 100644 index 00000000..fbf99b58 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/test_src_functionalext_supplement_maunal.gni @@ -0,0 +1,20 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_manual_test = [ + "env:functionalext_supplement_manual_env_test", + "termios:functionalext_supplement_manual_termios_test", + "unistd:functionalext_supplement_manual_unistd_test", + "network:functionalext_supplement_manual_network_test", + "thread:functionalext_supplement_manual_thread_test", +] diff --git a/libc-test/src/functionalext/supplement/manual/thread/BUILD.gn b/libc-test/src/functionalext/supplement/manual/thread/BUILD.gn new file mode 100644 index 00000000..fbe21310 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/thread/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../../test_template.gni") +import("test_src_functionalext_supplement_manual_thread.gni") + +foreach(s, functionalext_supplement_manual_thread_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/manual/thread" + } +} + +group("functionalext_supplement_manual_thread_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_manual_thread_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/manual/thread/cnd_broadcast.c b/libc-test/src/functionalext/supplement/manual/thread/cnd_broadcast.c new file mode 100644 index 00000000..0f6652a7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/thread/cnd_broadcast.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +mtx_t mtx; +cnd_t cndPut; +void cnd_timedwaitfirst(void *arg) +{ + int res = -1; + struct timespec ts; + mtx_lock(&mtx); + res = cnd_timedwait(&cndPut, &mtx, &ts); + mtx_unlock(&mtx); +} + +/** + * @tc.name : cnd_broadcast_0100 + * @tc.desc : Validation wakes up all threads waiting for the specified condition variable + * @tc.level : Level 0 + */ +void cnd_broadcast_0100(void) +{ + thrd_t id1; + int ret; + int result = -1; + cnd_init(&cndPut); + mtx_init(&mtx, 0); + ret = thrd_create(&id1, (thrd_start_t)cnd_timedwaitfirst, (void *)1); + if (0 != ret) { + printf("thread 1 create failed!\n"); + } + sleep(1); + mtx_lock(&mtx); + result = cnd_broadcast(&cndPut); + EXPECT_EQ("cnd_broadcast_0100", result, thrd_success); + mtx_unlock(&mtx); + thrd_join(id1, NULL); + cnd_destroy(&cndPut); + mtx_destroy(&mtx); +} + +int main() +{ + cnd_broadcast_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/manual/thread/test_src_functionalext_supplement_manual_thread.gni b/libc-test/src/functionalext/supplement/manual/thread/test_src_functionalext_supplement_manual_thread.gni new file mode 100644 index 00000000..293b7e4e --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/thread/test_src_functionalext_supplement_manual_thread.gni @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_manual_thread_test = [ "cnd_broadcast" ] diff --git a/libc-test/src/functionalext/supplement/manual/unistd/BUILD.gn b/libc-test/src/functionalext/supplement/manual/unistd/BUILD.gn new file mode 100644 index 00000000..20250da0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/unistd/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../../test_template.gni") +import("test_src_functionalext_supplement_manual_unistd.gni") + +foreach(s, functionalext_supplement_manual_unistd_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/manual/unistd" + } +} + +group("functionalext_supplement_manual_unistd_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_manual_unistd_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/manual/unistd/isatty.c b/libc-test/src/functionalext/supplement/manual/unistd/isatty.c new file mode 100755 index 00000000..1a7ee710 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/unistd/isatty.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int32_t COUNT_ZERO = 0; +const int32_t COUNT_ONE = 1; + +/** + * @tc.name : isatty_0100 + * @tc.desc : Verify that the file is a terminal (parameters are valid) + * @tc.level : Level 0 + */ +void isatty_0100() +{ + int result = isatty(fileno(stdout)); + EXPECT_EQ("isatty_0100", result, COUNT_ONE); +} + +/** + * @tc.name : isatty_0200 + * @tc.desc : Verify that the file is not a terminal (parameter invalid) + * @tc.level : Level 2 + */ +void isatty_0200() +{ + int fd = open("readtest.txt", O_RDWR | O_CREAT); + int result = isatty(fd); + EXPECT_EQ("isatty_0200", result, COUNT_ZERO); + close(fd); + remove("readtest.txt"); +} + +TEST_FUN G_Fun_Array[] = { + isatty_0100, + isatty_0200, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/manual/unistd/tcgetpgrp.c b/libc-test/src/functionalext/supplement/manual/unistd/tcgetpgrp.c new file mode 100644 index 00000000..eb0e30cf --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/unistd/tcgetpgrp.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +#define BACKGROUND (0) +#define FOREGROUND (1) +#define TCGETPGRPERROR (-1) + +int tcgetpgrp_handler(void) +{ + pid_t pid; + errno = 0; + pid = tcgetpgrp(STDIN_FILENO); + if (pid == -1) { + return TCGETPGRPERROR; + } else if (pid == getpgrp()) { + return FOREGROUND; + } else { + return BACKGROUND; + } +} + +/** + * @tc.name : tcgetpgrp_0100 + * @tc.desc : Get terminal foreground process + * @tc.level : Level 0 + */ +void tcgetpgrp_0100(void) +{ + int result, ret; + pid_t spid; + spid = tcgetsid(STDIN_FILENO); + ret = tcgetpgrp_handler(); + if (ret != 1) { + t_error("%s tcgetpgrp is not foreground\n", __func__); + } + result = tcsetpgrp(STDIN_FILENO, getpgrp()); + if (result == -1) { + t_error("%s tcsetpgrp failed", __func__); + } + + ret = tcgetpgrp_handler(); + result = tcsetpgrp(STDIN_FILENO, spid); +} + +/** + * @tc.name : tcgetpgrp_0200 + * @tc.desc : Invalid parameter input + * @tc.level : Level 2 + */ +void tcgetpgrp_0200(void) +{ + int result; + result = tcgetpgrp(-1); + if (result != -1) { + t_error("%s tcgetpgrp should failed, result is %d\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + tcgetpgrp_0100(); + tcgetpgrp_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/manual/unistd/tcsetpgrp.c b/libc-test/src/functionalext/supplement/manual/unistd/tcsetpgrp.c new file mode 100644 index 00000000..a0681dd4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/unistd/tcsetpgrp.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +#define BACKGROUND (0) +#define FOREGROUND (1) +#define TCGETPGRPERROR (-1) + +int tcgetpgrp_handler(void) +{ + pid_t pid; + errno = 0; + pid = tcgetpgrp(STDIN_FILENO); + if (pid == -1) { + return TCGETPGRPERROR; + } else if (pid == getpgrp()) { + return FOREGROUND; + } else { + return BACKGROUND; + } +} + +/** + * @tc.name : tcsetpgrp_0100 + * @tc.desc : Set terminal foreground process + * @tc.level : Level 0 + */ +void tcsetpgrp_0100(void) +{ + int result, ret; + pid_t spid; + spid = tcgetsid(STDIN_FILENO); + ret = tcgetpgrp_handler(); + if (ret != 1) { + t_error("%s tcgetpgrp is not foreground\n", __func__); + } + result = tcsetpgrp(STDIN_FILENO, getpgrp()); + if (result == -1) { + t_error("%s tcsetpgrp failed", __func__); + } + + ret = tcgetpgrp_handler(); + result = tcsetpgrp(STDIN_FILENO, spid); +} + +/** + * @tc.name : tcsetpgrp_0200 + * @tc.desc : Invalid parameter input + * @tc.level : Level 2 + */ +void tcsetpgrp_0200(void) +{ + int result; + result = tcsetpgrp(-1, -1); + if (result != -1) { + t_error("%s tcsetpgrp failed, result is %d\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + tcsetpgrp_0100(); + tcsetpgrp_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/manual/unistd/test_src_functionalext_supplement_manual_unistd.gni b/libc-test/src/functionalext/supplement/manual/unistd/test_src_functionalext_supplement_manual_unistd.gni new file mode 100644 index 00000000..57759a60 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/unistd/test_src_functionalext_supplement_manual_unistd.gni @@ -0,0 +1,19 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_manual_unistd_test = [ + "tcgetpgrp", + "tcsetpgrp", + "isatty", + "ttyname", +] diff --git a/libc-test/src/functionalext/supplement/manual/unistd/ttyname.c b/libc-test/src/functionalext/supplement/manual/unistd/ttyname.c new file mode 100644 index 00000000..0c6993d3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/manual/unistd/ttyname.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : ttyname_0100 + * @tc.desc : Test the ttyname method to get the terminal name through the file handle + * @tc.level : Level 0 + */ +void ttyname_0100(void) +{ + char *file = "/dev/tty"; + int fd = open(file, O_RDONLY); + char *result = ttyname(fd); + if (strcmp(result, file) != 0) { + t_error("%s ttyname get result is %s are not want %s\n", __func__, result, file); + } +} + +/** + * @tc.name : ttyname_0200 + * @tc.desc : Test the return value of ttyname when a non-existing terminal file handle is passed in + * @tc.level : Level 1 + */ +void ttyname_0200(void) +{ + char *file = "/unexit"; + int fd = open(file, O_RDONLY); + char *result = ttyname(fd); + if (result) { + t_error("%s ttyname get result is %s are not null\n", __func__, result); + } +} + +int main(void) +{ + ttyname_0100(); + ttyname_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/math/BUILD.gn b/libc-test/src/functionalext/supplement/math/BUILD.gn new file mode 100644 index 00000000..87e1038b --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_math.gni") + +foreach(s, functionalext_supplement_math_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/math" + } +} + +group("functionalext_supplement_math_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_math_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/math/__fpclassifyf.c b/libc-test/src/functionalext/supplement/math/__fpclassifyf.c new file mode 100644 index 00000000..2f579f4d --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/__fpclassifyf.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : __fpclassifyf_0100 + * @tc.desc : The parameter is valid, x is 1.0, can get the integer value matching the + * classification macro constant. + * @tc.level : Level 0 + */ +void __fpclassifyf_0100(void) +{ + float x = 1.0; + int ret = __fpclassifyf(x); + EXPECT_EQ("__fpclassifyf_0100", ret, FP_NORMAL); +} + +/** + * @tc.name : __fpclassifyf_0200 + * @tc.desc : The parameter is valid, x is NAN, can get the integer value matching the + * classification macro constant. + * @tc.level : Level 1 + */ +void __fpclassifyf_0200(void) +{ + float x = NAN; + int ret = __fpclassifyf(x); + EXPECT_EQ("__fpclassifyf_0200", ret, FP_NAN); +} + +/** + * @tc.name : __fpclassifyf_0300 + * @tc.desc : The parameter is valid, x is INFINITY, can get the integer value matching the + * classification macro constant. + * @tc.level : Level 1 + */ +void __fpclassifyf_0300(void) +{ + float x = INFINITY; + int ret = __fpclassifyf(x); + EXPECT_EQ("__fpclassifyf_0300", ret, FP_INFINITE); +} + +/** + * @tc.name : __fpclassifyf_0400 + * @tc.desc : The parameter is valid, x is -0.0, can get the integer value matching the + * classification macro constant. + * @tc.level : Level 1 + */ +void __fpclassifyf_0400(void) +{ + float x = -0.0; + int ret = __fpclassifyf(x); + EXPECT_EQ("__fpclassifyf_0400", ret, FP_ZERO); +} + + +int main() +{ + __fpclassifyf_0100(); + __fpclassifyf_0200(); + __fpclassifyf_0300(); + __fpclassifyf_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/math/__fpclassifyl.c b/libc-test/src/functionalext/supplement/math/__fpclassifyl.c new file mode 100644 index 00000000..03300fe4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/__fpclassifyl.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : __fpclassifyl_0100 + * @tc.desc : The parameter is valid, x is 1.0, can get the integer value matching the + * classification macro constant. + * @tc.level : Level 0 + */ +void __fpclassifyl_0100(void) +{ + long double x = 1.0; + int ret = __fpclassifyl(x); + EXPECT_EQ("__fpclassifyl_0100", ret, FP_NORMAL); +} + +/** + * @tc.name : __fpclassifyl_0200 + * @tc.desc : The parameter is valid, x is NAN, can get the integer value matching the + * classification macro constant. + * @tc.level : Level 1 + */ +void __fpclassifyl_0200(void) +{ + long double x = NAN; + int ret = __fpclassifyl(x); + EXPECT_EQ("__fpclassifyl_0200", ret, FP_NAN); +} + +/** + * @tc.name : __fpclassifyl_0300 + * @tc.desc : The parameter is valid, x is INFINITY, can get the integer value matching the + * classification macro constant. + * @tc.level : Level 1 + */ +void __fpclassifyl_0300(void) +{ + long double x = INFINITY; + int ret = __fpclassifyl(x); + EXPECT_EQ("__fpclassifyl_0300", ret, FP_INFINITE); +} + +/** + * @tc.name : __fpclassifyl_0400 + * @tc.desc : The parameter is valid, x is -0.0, can get the integer value matching the + * classification macro constant. + * @tc.level : Level 1 + */ +void __fpclassifyl_0400(void) +{ + long double x = -0.0; + int ret = __fpclassifyl(x); + EXPECT_EQ("__fpclassifyl_0400", ret, FP_ZERO); +} + + +int main() +{ + __fpclassifyl_0100(); + __fpclassifyl_0200(); + __fpclassifyl_0300(); + __fpclassifyl_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/math/__signbit.c b/libc-test/src/functionalext/supplement/math/__signbit.c new file mode 100644 index 00000000..2df14ac6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/__signbit.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int32_t COUNT_ZERO = 0; +const int32_t COUNT_ONE = 1; + +/** + * @tc.name : __signbit_0100 + * @tc.desc : When the float value is 0, test the return value of the function + * @tc.level : Level 0 + */ +void __signbit_0100() +{ + double x = 0; + int result = __signbit(x); + EXPECT_EQ("_signbit_0100", result, COUNT_ZERO); +} + +/** + * @tc.name : __signbit_0200 + * @tc.desc : When the float value is 3.14, test the return value of the function + * @tc.level : Level 0 + */ +void __signbit_0200() +{ + double x = 3.14; + int result = __signbit(x); + EXPECT_EQ("_signbit_0200", result, COUNT_ZERO); +} + +/** + * @tc.name : __signbit_0300 + * @tc.desc : When the float value is -3.14, test the return value of the function + * @tc.level : Level 0 + */ +void __signbit_0300() +{ + double x = -3.14; + int result = __signbit(x); + EXPECT_EQ("_signbit_0300", result, COUNT_ONE); +} + +TEST_FUN G_Fun_Array[] = { + __signbit_0100, + __signbit_0200, + __signbit_0300, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/math/__signbitf.c b/libc-test/src/functionalext/supplement/math/__signbitf.c new file mode 100644 index 00000000..37163ae0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/__signbitf.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; +const int32_t COUNT_ONE = 1; + +/* + * @tc.name : __signbitf_0100 + * @tc.desc : The parameter value of float type is 0, and the sign bit of the return parameter is 0. + * @tc.level : Level 0 + */ +void __signbitf_0100(void) +{ + float x = 0; + int result; + result = __signbitf(x); + EXPECT_EQ(" __signbitf_0100", result, COUNT_ZERO); +} + +/* + * @tc.name : __signbitf_0200 + * @tc.desc : The parameter value of type float is a positive number, + * and the sign bit of the returned parameter is 0. + * @tc.level : Level 0 + */ +void __signbitf_0200(void) +{ + float x = 10; + int result; + result = __signbitf(x); + EXPECT_EQ(" __signbitf_0200", result, COUNT_ZERO); +} + +/* + * @tc.name : __signbitf_0300 + * @tc.desc : The parameter value of type float is negative, + * and the sign bit of the return parameter is 1. + * @tc.level : Level 0 + */ +void __signbitf_0300(void) +{ + float x = -10; + int result; + result = __signbitf(x); + EXPECT_EQ(" __signbitf_0300", result, COUNT_ONE); +} + +int main() +{ + __signbitf_0100(); + __signbitf_0200(); + __signbitf_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/math/__signbitl.c b/libc-test/src/functionalext/supplement/math/__signbitl.c new file mode 100644 index 00000000..a454d49e --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/__signbitl.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; +const int32_t COUNT_ONE = 1; + +/** + * @tc.name : signbitl_0100 + * @tc.desc : the sign bit of the returned argument is 0 (The value of the argument of type long is 0) + * @tc.level : Level 0 + */ +void signbitl_0100(void) +{ + long double x = 0; + int result; + result = __signbitl(x); + EXPECT_EQ("signbitl_0100", result, COUNT_ZERO); +} + +/** + * @tc.name : signbitl_0200 + * @tc.desc : the sign bit of the returned argument is 0 (The value of the argument of type long is positive) + * @tc.level : Level 0 + */ +void signbitl_0200(void) +{ + long double x = 10; + int result; + result = __signbitl(x); + EXPECT_EQ("signbitl_0200", result, COUNT_ZERO); +} + +/** + * @tc.name : signbitl_0300 + * @tc.desc : the sign bit of the returned parameter is 1 + * (The parameter value of type long is negative) + * @tc.level : Level 0 + */ +void signbitl_0300(void) +{ + long double x = -10; + int result; + result = __signbitl(x); + EXPECT_EQ("signbitl_0300", result, COUNT_ONE); +} + +int main() +{ + signbitl_0100(); + signbitl_0200(); + signbitl_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/math/finite.c b/libc-test/src/functionalext/supplement/math/finite.c new file mode 100644 index 00000000..76a68b70 --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/finite.c @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int SUCCESS = 1; +const int FAILED = 0; + +/** + * @tc.name : finite_0100 + * @tc.desc : The parameter is 0.0, it is judged that the parameter is a finite value. + * @tc.level : Level 0 + */ +void finite_0100(void) +{ + int ret = finite(0.0); + EXPECT_EQ("finite_0100", ret, SUCCESS); +} + +/** + * @tc.name : finite_0200 + * @tc.desc : The parameter is DBL_MIN/2.0, and it is judged that the parameter is a finite value + * @tc.level : Level 0 + */ +void finite_0200(void) +{ + int ret = finite(__DBL_MIN__ / 2); + EXPECT_EQ("finite_0100", ret, SUCCESS); +} + +/** + * @tc.name : finite_0300 + * @tc.desc : If the parameter is NAN, it is judged that the parameter is not a finite value. + * @tc.level : Level 2 + */ +void finite_0300(void) +{ + int ret = finite(NAN); + EXPECT_EQ("finite_0100", ret, FAILED); +} + +/** + * @tc.name : finite_0400 + * @tc.desc : If the parameter is INFINITY, it is judged that the parameter is not a finite value. + * @tc.level : Level 2 + */ +void finite_0400(void) +{ + int ret = finite(INFINITY); + EXPECT_EQ("finite_0400", ret, FAILED); +} + +/** + * @tc.name : finite_0500 + * @tc.desc : If the parameter is sqrt(-1.0), it is judged that the parameter is not a finite value. + * @tc.level : Level 2 + */ +void finite_0500(void) +{ + int ret = finite(sqrt(-1.0)); + EXPECT_EQ("finite_0500", ret, FAILED); +} + +/** + * @tc.name : finite_0600 + * @tc.desc : If the parameter is exp(800), it is judged that the parameter is not a finite value. + * @tc.level : Level 2 + */ +void finite_0600(void) +{ + int ret = finite(exp(800)); + EXPECT_EQ("finite_0600", ret, FAILED); +} + +TEST_FUN G_Fun_Array[] = { + finite_0100, + finite_0200, + finite_0300, + finite_0400, + finite_0500, + finite_0600, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/math/finitef.c b/libc-test/src/functionalext/supplement/math/finitef.c new file mode 100644 index 00000000..d3e484de --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/finitef.c @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" +#include "math.h" + +const int32_t NUM_ZERO = 0; +const int32_t NUM_ONE = 1; + +/** + * @tc.name : finitef_0100 + * @tc.desc : Validate that the input parameter is a finite value (parameter is 0.0). + * @tc.level : Level 0 + */ +void finitef_0100(void) +{ + float ret = finitef(0.0); + EXPECT_EQ("finitef_0100", ret, NUM_ONE); +} + +/** + * @tc.name : finitef_0200 + * @tc.desc : Validate that the input parameter is a finite value (parameter is DBL_MIN/2). + * @tc.level : Level 0 + */ +void finitef_0200(void) +{ + float ret = finitef(DBL_MIN / 2); + EXPECT_EQ("finitef_0100", ret, NUM_ONE); +} + +/** + * @tc.name : finitef_0300 + * @tc.desc : Verify that the input parameter is not a finite value (parameter is NAN). + * @tc.level : Level 2 + */ +void finitef_0300(void) +{ + float ret = finitef(NAN); + EXPECT_EQ("finitef_0100", ret, NUM_ZERO); +} + +/** + * @tc.name : finitef_0400 + * @tc.desc : Verify that the input parameter is not a finite value (parameter is INFINITY). + * @tc.level : Level 2 + */ +void finitef_0400(void) +{ + float ret = finitef(INFINITY); + EXPECT_EQ("finitef_0100", ret, NUM_ZERO); +} + +/** + * @tc.name : finitef_0500 + * @tc.desc : Verify that the input parameter is not a finite value (parameter is sqrt(-1.0)). + * @tc.level : Level 2 + */ +void finitef_0500(void) +{ + float ret = finitef(sqrt(-1.0)); + EXPECT_EQ("finitef_0100", ret, NUM_ZERO); +} + +/** + * @tc.name : finitef_0600 + * @tc.desc : Verify that the input parameter is not a finite value (exp(800)). + * @tc.level : Level 2 + */ +void finitef_0600(void) +{ + float ret = finitef(exp(800)); + EXPECT_EQ("finitef_0100", ret, NUM_ZERO); +} + +int main(int argc, char *argv[]) +{ + finitef_0100(); + finitef_0200(); + finitef_0300(); + finitef_0400(); + finitef_0500(); + finitef_0600(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/math/nan.c b/libc-test/src/functionalext/supplement/math/nan.c new file mode 100755 index 00000000..c0036766 --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/nan.c @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : nan_0100 + * @tc.desc : Returns a floating point representation of NaN + * @tc.level : Level 0 + */ +void nan_0100(void) +{ + double ret = nan(NULL); + if (fabs(ret - NAN) > EPS) { + t_error("nan_0100 failed \n"); + } +} + +int main(void) +{ + nan_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/math/nanf.c b/libc-test/src/functionalext/supplement/math/nanf.c new file mode 100755 index 00000000..3dc37c1d --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/nanf.c @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : nanf_0100 + * @tc.desc : Returns a floating point representation of NaN + * @tc.level : Level 0 + */ +void nanf_0100(void) +{ + float ret = nanf(NULL); + if (fabs(ret - NAN) > EPS) { + t_error("nanf_0100 failed \n"); + } +} + +int main(void) +{ + nanf_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/math/nanl.c b/libc-test/src/functionalext/supplement/math/nanl.c new file mode 100644 index 00000000..675ec141 --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/nanl.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : nanl. + * @tc.desc : Verify nanl process success and return 0. + * @tc.level : level 0 + */ +void nanl_0100(void) +{ + long double ret = nanl(""); + if (fabsl(ret - NAN) > LDBL_EPSILON) { + t_error("nanl_0100 failed"); + } +} + +int main(void) +{ + nanl_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/math/rint.c b/libc-test/src/functionalext/supplement/math/rint.c new file mode 100644 index 00000000..8ceb8c0b --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/rint.c @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const float argNum1 = 2.4; +const float argNum2 = 3.9; +const float argNum3 = -2.4; +const float argNum4 = -3.9; + +const int32_t retNum1 = 2; +const int32_t retNum2 = 4; +const int32_t retNum3 = -2; +const int32_t retNum4 = -4; + +/** + * @tc.name : rint_0100 + * @tc.desc : Verify rint process success and return 0 when param is 2.4 + * @tc.level : Level 0 + */ +void rint_0100(void) +{ + int32_t ret = rint(argNum1); + EXPECT_EQ("rint_0100", ret, retNum1); +} + +/** + * @tc.name : rint_0200 + * @tc.desc : Verify rint process success and return 0 when param is 3.9 + * @tc.level : Level 0 + */ +void rint_0200(void) +{ + int32_t ret = rint(argNum2); + EXPECT_EQ("rint_0200", ret, retNum2); +} + +/** + * @tc.name : rint_0300 + * @tc.desc : Verify rint process success and return 0 when param is -2.4 + * @tc.level : Level 0 + */ +void rint_0300(void) +{ + int32_t ret = rint(argNum3); + EXPECT_EQ("rint_0300", ret, retNum3); +} + +/** + * @tc.name : rint_0400 + * @tc.desc : Verify rint process success and return 0 when param is -3.9 + * @tc.level : Level 0 + */ +void rint_0400(void) +{ + int32_t ret = rint(argNum4); + EXPECT_EQ("rint_0300", ret, retNum4); +} + +/** + * @tc.name : rint_0500 + * @tc.desc : Verify rint process success and return 0 when param is 0 + * @tc.level : Level 0 + */ +void rint_0500(void) +{ + int32_t ret = rint(0); + EXPECT_EQ("rint_0400", ret, 0); +} + +int main(void) +{ + rint_0100(); + rint_0200(); + rint_0300(); + rint_0400(); + rint_0500(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/math/significand.c b/libc-test/src/functionalext/supplement/math/significand.c new file mode 100644 index 00000000..8d408d24 --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/significand.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +#define EXPECT_DOUBLE_EQ(a, b) \ + do { \ + if (!(fabs(a - b) < DBL_EPSILON)) \ + t_error("%s failed: %f is not equal to %f\n", __func__, a, b); \ + } while (0) + +/* + * @tc.name : significand_0100 + * @tc.desc : Get mantissa of floating-point number 0.0 + * @tc.level : Level 0 + */ +void significand_0100(void) +{ + double d = significand(0.0); + EXPECT_DOUBLE_EQ(0.0, d); +} + +/* + * @tc.name : significand_0200 + * @tc.desc : Get mantissa of floating-point number 1.2 + * @tc.level : Level 1 + */ +void significand_0200(void) +{ + double d = significand(1.2); + EXPECT_DOUBLE_EQ(1.2, d); +} + +/* + * @tc.name : significand_0300 + * @tc.desc : Get mantissa of floating-point number 12.25 + * @tc.level : Level 1 + */ +void significand_0300(void) +{ + double d = significand(12.25); + EXPECT_DOUBLE_EQ(1.53125, d); +} + +int main(int argc, char *argv[]) +{ + significand_0100(); + significand_0200(); + significand_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/math/significandf.c b/libc-test/src/functionalext/supplement/math/significandf.c new file mode 100644 index 00000000..ad960d3e --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/significandf.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +#define EXPECT_FLOAT_EQ(a, b) \ + do { \ + if (!(fabsf(a - b) < FLT_EPSILON)) \ + t_error("%s failed: %f is not equal to %f\n", __func__, a, b); \ + } while (0) + +/* + * @tc.name : significandf_0100 + * @tc.desc : Get mantissa of floating-point number 0.0f + * @tc.level : Level 0 + */ +void significandf_0100(void) +{ + float f = significandf(0.0f); + EXPECT_FLOAT_EQ(0.0f, f); +} + +/* + * @tc.name : significandf_0200 + * @tc.desc : Get mantissa of floating-point number 1.2f + * @tc.level : Level 1 + */ +void significandf_0200(void) +{ + float f = significandf(1.2f); + EXPECT_FLOAT_EQ(1.2f, f); +} + +/* + * @tc.name : significandf_0300 + * @tc.desc : Get mantissa of floating-point number 12.25f + * @tc.level : Level 1 + */ +void significandf_0300(void) +{ + float f = significandf(12.25f); + EXPECT_FLOAT_EQ(1.53125f, f); +} + +int main(int argc, char *argv[]) +{ + significandf_0100(); + significandf_0200(); + significandf_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/math/test_src_functionalext_supplement_math.gni b/libc-test/src/functionalext/supplement/math/test_src_functionalext_supplement_math.gni new file mode 100644 index 00000000..05758d8f --- /dev/null +++ b/libc-test/src/functionalext/supplement/math/test_src_functionalext_supplement_math.gni @@ -0,0 +1,28 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_math_test = [ + "__signbit", + "__signbitl", + "__signbitf", + "finite", + "nanl", + "rint", + "__fpclassifyl", + "finitef", + "significand", + "significandf", + "nan", + "nanf", + "__fpclassifyf", +] diff --git a/libc-test/src/functionalext/supplement/mbrlen/BUILD.gn b/libc-test/src/functionalext/supplement/mbrlen/BUILD.gn new file mode 100644 index 00000000..b68dbf3d --- /dev/null +++ b/libc-test/src/functionalext/supplement/mbrlen/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_mbrlen.gni") + +foreach(s, functionalext_supplement_mbrlen_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/mbrlen" + } +} + +group("functionalext_supplement_mbrlen_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_mbrlen_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/mbrlen/mbrlen.c b/libc-test/src/functionalext/supplement/mbrlen/mbrlen.c new file mode 100644 index 00000000..5b26fe7a --- /dev/null +++ b/libc-test/src/functionalext/supplement/mbrlen/mbrlen.c @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "functionalext.h" + +/** + * @tc.name : mbrlen_0100 + * @tc.desc : Verify that the obtained character length is 1 byte + * @tc.level : Level 0 + */ +void mbrlen_0100(void) +{ + char test[] = {'m', 'u', 's', 'l'}; + const int num = sizeof(test) / sizeof(test[0]); + size_t limitsize = sizeof(test[0]); + for (unsigned int i = 0; i < num; i++) { + EXPECT_EQ("mbrlen_0100", mbrlen(test + i, limitsize, NULL), 1); + } +} + +/** + * @tc.name : mbrlen_0200 + * @tc.desc : Verify that the length return value of the incoming exception is not an illegal value + * @tc.level : Level 2 + */ +void mbrlen_0200(void) +{ + char test[] = {'m', 'u', 's', 'l', '\0'}; + size_t index = 1; + size_t ret = 0; + const int num = sizeof(test) / sizeof(test[0]) - 1; + for (unsigned int i = 0; i < num; i++) { + ret = mbrlen(&test[i], 0, NULL); + EXPECT_NE("mbrlen_0200", ret, index); + } + if (test[num] == '\0') { + ret = mbrlen(&test[num], 1, NULL); + EXPECT_EQ("mbrlen_0200", ret, CMPFLAG); + } +} + +int main(void) +{ + mbrlen_0100(); + mbrlen_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/mbrlen/test_src_functionalext_supplement_mbrlen.gni b/libc-test/src/functionalext/supplement/mbrlen/test_src_functionalext_supplement_mbrlen.gni new file mode 100644 index 00000000..da44e816 --- /dev/null +++ b/libc-test/src/functionalext/supplement/mbrlen/test_src_functionalext_supplement_mbrlen.gni @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_mbrlen_test = [ "mbrlen" ] diff --git a/libc-test/src/functionalext/supplement/misc/BUILD.gn b/libc-test/src/functionalext/supplement/misc/BUILD.gn new file mode 100644 index 00000000..97a89aa9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_misc.gni") + +foreach(s, functionalext_supplement_misc_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/misc" + } +} + +group("functionalext_supplement_misc_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_misc_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/misc/endmntent.c b/libc-test/src/functionalext/supplement/misc/endmntent.c new file mode 100644 index 00000000..55ff21a2 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/endmntent.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ONE = 1; + +/** + * @tc.name : endmntent_0100 + * @tc.desc : Verify that the stream and its associated file system description file can be closed + * (parameter valid) + * @tc.level : Level 0 + */ +void endmntent_0100(void) +{ + struct mntent *m; + int result = 0; + FILE *fptr = fopen("/data/test.txt", "w+"); + result = endmntent(fptr); + EXPECT_EQ("endmntent_0100", result, COUNT_ONE); + remove("/data/test.txt"); +} + +int main() +{ + endmntent_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/ffs.c b/libc-test/src/functionalext/supplement/misc/ffs.c new file mode 100644 index 00000000..2b459b5a --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/ffs.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : ffs_0100 + * @tc.desc : Validation looks for first set value in integer (parameter is 0). + * @tc.level : Level 0 + */ +void ffs_0100(void) +{ + int result; + result = ffs(0); + EXPECT_EQ("ffs_0100", result, 0); +} + +/** + * @tc.name : ffs_0200 + * @tc.desc : Validation looks for first set value in integer (parameter is 1). + * @tc.level : Level 0 + */ +void ffs_0200(void) +{ + int result; + result = ffs(1); + EXPECT_EQ("ffs_0200", result, 1); +} + +/** + * @tc.name : ffs_0300 + * @tc.desc : Validation looks for first set value in integer (parameter is 2). + * @tc.level : Level 0 + */ +void ffs_0300(void) +{ + int result; + result = ffs(2); + EXPECT_EQ("ffs_0300", result, 2); +} + +/** + * @tc.name : ffs_0400 + * @tc.desc : Validation looks for first set value in integer (parameter is 3). + * @tc.level : Level 0 + */ +void ffs_0400(void) +{ + int result; + result = ffs(3); + EXPECT_EQ("ffs_0400", result, 1); +} + +/** + * @tc.name : ffs_0500 + * @tc.desc : Validation looks for first set value in integer (parameter is 255). + * @tc.level : Level 0 + */ +void ffs_0500(void) +{ + int result; + result = ffs(128); + EXPECT_EQ("ffs_0500", result, 8); +} + +int main() +{ + ffs_0100(); + ffs_0200(); + ffs_0300(); + ffs_0400(); + ffs_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/ffsl.c b/libc-test/src/functionalext/supplement/misc/ffsl.c new file mode 100644 index 00000000..ca40021c --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/ffsl.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : ffsl_0100 + * @tc.desc : Validates the ability to find the first set value of a value of type long. + * @tc.level : Level 0 + */ +void ffsl_0100(void) +{ + int result; + result = ffsl(0); + EXPECT_EQ("ffsl_0100", result, 0); +} + +/** + * @tc.name : ffsl_0200 + * @tc.desc : Verify to find the first set value of a value of type long (0x8, bit 1) + * @tc.level : Level 0 + */ +void ffsl_0200(void) +{ + int result; + result = ffsl(0x8); + EXPECT_EQ("ffsl_0200", result, 4); +} + +/** + * @tc.name : ffsl_0300 + * @tc.desc : Validates the ability to find the first set value of a value of type long (0x8000, bit 1) + * @tc.level : Level 0 + */ +void ffsl_0300(void) +{ + int result; + result = ffsl(0x8000); + EXPECT_EQ("ffsl_0300", result, 16); +} + +int main() +{ + ffsl_0100(); + ffsl_0200(); + ffsl_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/ffsll.c b/libc-test/src/functionalext/supplement/misc/ffsll.c new file mode 100644 index 00000000..63426c04 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/ffsll.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : ffsll_0100 + * @tc.desc : Verify to find the first set value of a value of type long long + * (valid for each argument, 0, bit 1) + * @tc.level : Level 0 + */ +void ffsll_0100(void) +{ + int result; + result = ffsll(0); + EXPECT_EQ("ffsll_0100", result, 0); +} + +/** + * @tc.name : ffsll_0200 + * @tc.desc : Verify to find the first set value of a value of type long long + * (valid for each argument, 0x8000000,bit 1) + * @tc.level : Level 0 + */ +void ffsll_0200(void) +{ + int result; + result = ffsll(0x8000000); + EXPECT_EQ("ffsll_0200", result, 28); +} + +/** + * @tc.name : ffsll_0300 + * @tc.desc : Verify to find the first set value of a value of type long long + * (valid for each argument, 0x800000000,bit 1) + * @tc.level : Level 0 + */ +void ffsll_0300(void) +{ + int result; + result = ffsll(0x800000000); + EXPECT_EQ("ffsll_0300", result, 36); +} + +int main() +{ + ffsll_0100(); + ffsll_0200(); + ffsll_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/forkpty.c b/libc-test/src/functionalext/supplement/misc/forkpty.c new file mode 100644 index 00000000..466c56f4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/forkpty.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : forkpty_0100 + * @tc.desc : Each parameter is valid and can open a pair of pseudo-terminals for a new + * session and create a processing process. + * @tc.level : Level 0 + */ +void forkpty_0100(void) +{ + int master; + pid_t pid = forkpty(&master, NULL, NULL, NULL); + char *sign_r = "1"; + char *sign_f = "0"; + char list1[2]; + char list2[2]; + FILE *fp; + if (pid < 0) { + printf("error in fork!"); + } else if (pid == 0) { + fp = fopen("test1.txt", "w+"); + fwrite(sign_r, sizeof(char), strlen(sign_r), fp); + fclose(fp); + } else { + fp = fopen("test2.txt", "w+"); + fwrite(sign_r, sizeof(char), strlen(sign_r), fp); + fclose(fp); + } + sleep(1); + FILE *fp1 = fopen("test1.txt", "r"); + FILE *fp2 = fopen("test2.txt", "r"); + fread(list1, sizeof(list1), 1, fp1); + fread(list2, sizeof(list2), 1, fp2); + EXPECT_EQ("forkpty_0100", list1[0], '1'); + EXPECT_EQ("forkpty_0100", list2[0], '1'); + fclose(fp1); + fclose(fp2); + remove("test1.txt"); + remove("test2.txt"); +} + +TEST_FUN G_Fun_Array[] = { + forkpty_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/getauxval.c b/libc-test/src/functionalext/supplement/misc/getauxval.c new file mode 100755 index 00000000..35f43cd3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/getauxval.c @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" +int successsfly = 0; + +/* + * @tc.name : getauxval_0100 + * @tc.desc : Verify that the value can be retrieved from the auxiliary vector (parameter is AT_SECURE) + * @tc.level : Level 0 + */ +void getauxval_0100(void) +{ + long int result; + result = getauxval(AT_SECURE); + EXPECT_EQ("getauxval_0100", result, 0); +} + +/* + * @tc.name : getauxval_0200 + * @tc.desc : Verify that the value can be retrieved from the auxiliary vector (parameter is AT_SYSINFO) + * @tc.level : Level 0 + */ +void getauxval_0200(void) +{ + long int result; + result = getauxval(AT_SYSINFO); + EXPECT_EQ("getauxval_0200", result, 0); +} + +/* + * @tc.name : getauxval_0300 + * @tc.desc : Verify that the value can be retrieved from the auxiliary vector (parameter is AT_SYSINFO_EHDR) + * @tc.level : Level 0 + */ +void getauxval_0300(void) +{ + long int result; + result = getauxval(AT_SYSINFO_EHDR); + EXPECT_TRUE("getauxval_0300", result != 0); +} + +int main() +{ + getauxval_0100(); + getauxval_0200(); + getauxval_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/getdomainname.c b/libc-test/src/functionalext/supplement/misc/getdomainname.c new file mode 100644 index 00000000..dbdec693 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/getdomainname.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t SUCCESS = 0; +const int32_t FAILED = -1; + +/** + * @tc.name : getdomainname_0100 + * @tc.desc : Verify domain name (valid) + * @tc.level : Level 0 + */ +void getdomainname_0100(void) +{ + int result; + char name[1024] = "\0"; + result = getdomainname(name, 1024); + EXPECT_EQ("getdomainname_0100", result, SUCCESS); + EXPECT_TRUE("getdomainname_0100", strcmp(name, "\0") != 0); +} + +/** + * @tc.name : getdomainname_0200 + * @tc.desc : Verify domain name cannot be obtained (len parameter invalid, 0) + * @tc.level : Level 2 + */ +void getdomainname_0200(void) +{ + int result; + char name[1024] = "\0"; + result = getdomainname(name, 0); + EXPECT_EQ("getdomainname_0200", result, FAILED); +} + +/** + * @tc.name : getdomainname_0300 + * @tc.desc : Failed to obtain domain name (len parameter invalid, less than domain name length) + * @tc.level : Level 2 + */ +void getdomainname_0300(void) +{ + int result; + char name[1024] = "\0"; + result = getdomainname(name, 1); + EXPECT_EQ("getdomainname_0300", result, FAILED); +} + +int main() +{ + getdomainname_0100(); + getdomainname_0200(); + getdomainname_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/getentropy.c b/libc-test/src/functionalext/supplement/misc/getentropy.c new file mode 100644 index 00000000..a55c63ee --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/getentropy.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; + +/* + * @tc.name : getentropy_0100 + * @tc.desc : Verify that secure random numbers can be generated + * @tc.level : Level 0 + */ +void getentropy_0100(void) +{ + void *buffer[256]; + int result = getentropy(buffer, 256); + EXPECT_EQ("getentrcopy_0100", result, SUCCESS); +} + +/* + * @tc.name : getentropy_0200 + * @tc.desc : Validation cannot generate secure random numbers + * @tc.level : Level 2 + */ +void getentropy_0200(void) +{ + void *buffer[256]; + int result = getentropy(buffer, 257); + EXPECT_EQ("getentrcopy_0200", result, FAILED); +} + +int main() +{ + getentropy_0100(); + getentropy_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/getmntent.c b/libc-test/src/functionalext/supplement/misc/getmntent.c new file mode 100644 index 00000000..b51ade95 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/getmntent.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getmntent_0100 + * @tc.desc : The parameters are valid and the file information can be read. + * @tc.level : Level 0 + */ +void getmntent_0100(void) +{ + char c[1000]; + char str[100]; + FILE *fptr = NULL; + if ((fptr = fopen("/proc/mounts", "r")) == NULL) { + printf("Error! opening file"); + } + fscanf(fptr, "%[^\n]", c); + fclose(fptr); + sscanf(c, "%[^ ]", str); + struct mntent *m = NULL; + FILE *ffp = setmntent("/proc/mounts", "r"); + if (!ffp) { + printf("error:%s\n", strerror(errno)); + } + m = getmntent(ffp); + bool flag = false; + if (m != NULL) { + flag = true; + } + EXPECT_TRUE("getmntent_0100", flag); + if (m != NULL) { + EXPECT_EQ("getmntent_0100", strcmp(m->mnt_fsname, str), 0); + } else { + printf("error\n"); + } + endmntent(ffp); +} + +/** + * @tc.name : getmntent_0200 + * @tc.desc : Invalid parameter, failed to read file information. + * @tc.level : Level 2 + */ +void getmntent_0200(void) +{ + char c[1000]; + char *str = "This is a test"; + FILE *fp = fopen("/data/getmntent.txt", "w"); + fputs(str, fp); + fclose(fp); + struct mntent *m = NULL; + FILE *ffp = setmntent("/data/getmntent.txt", "r"); + if (!ffp) { + printf("error:%s\n", strerror(errno)); + } + m = getmntent(ffp); + EXPECT_EQ("getmntent_0200", m, NULL); + endmntent(ffp); + remove("/data/getmntent.txt"); +} + +int main(void) +{ + getmntent_0100(); + getmntent_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/getmntent_r.c b/libc-test/src/functionalext/supplement/misc/getmntent_r.c new file mode 100644 index 00000000..a819c99c --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/getmntent_r.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int32_t SUCCESS = 0; +static pthread_barrier_t g_barrier; +#define WAIT() pthread_barrier_wait(&g_barrier) +void *getmntent_rOne() +{ + char c[1000]; + char str[100]; + FILE *fptr = NULL; + char strings[1024]; + if ((fptr = fopen("/proc/mounts", "r")) == NULL) { + printf("Error! opening file"); + } + fscanf(fptr, "%[^\n]", c); + fclose(fptr); + sscanf(c, "%[^ ]", str); + struct mntent *m = NULL; + struct mntent mntbuf; + memset(&m, 0x00, sizeof(m)); + memset(&strings[0], 0x00, sizeof(strings)); + FILE *ffp = setmntent("/proc/mounts", "r"); + if (!ffp) { + printf("error:%s\n", strerror(errno)); + } + WAIT(); + m = getmntent_r(ffp, &mntbuf, strings, sizeof(strings)); + if (m != NULL) { + EXPECT_EQ("getmntent_r_0100", strcmp(m->mnt_fsname, str), 0); + EXPECT_EQ("getmntent_r_0100", strcmp(mntbuf.mnt_fsname, str), 0); + } else { + printf("error\n"); + } + endmntent(ffp); + return m; +} + +/** + * @tc.name : getmntent_r_0100 + * @tc.desc : Multiple threads simultaneously read file information. + * @tc.level : Level 0 + */ +void getmntent_r_0100(void) +{ + pthread_t srv; + pthread_t cli; + int ret = pthread_barrier_init(&g_barrier, 0, 2); + EXPECT_EQ("getmntent_r_0100", SUCCESS, ret); + ret = pthread_create(&srv, NULL, getmntent_rOne, NULL); + EXPECT_EQ("getmntent_r_0100", SUCCESS, ret); + ret = pthread_create(&cli, NULL, getmntent_rOne, NULL); + EXPECT_EQ("getmntent_r_0100", SUCCESS, ret); + ret = pthread_join(cli, NULL); + EXPECT_EQ("getmntent_r_0100", SUCCESS, ret); + ret = pthread_join(srv, NULL); + EXPECT_EQ("getmntent_r_0100", SUCCESS, ret); + ret = pthread_barrier_destroy(&g_barrier); + EXPECT_EQ("getmntent_r_0100", SUCCESS, ret); +} + +/** + * @tc.name : getmntent_r_0200 + * @tc.desc : The f parameter is invalid, reading the file information failed. + * @tc.level : Level 2 + */ +void getmntent_r_0200(void) +{ + char c[1000]; + char str[100]; + FILE *fptr = NULL; + char strings[1024]; + if ((fptr = fopen("/data/getmntent.txt", "w")) == NULL) { + printf("Error! opening file"); + } + fclose(fptr); + struct mntent *m = NULL; + struct mntent mntbuf; + memset(&m, 0x00, sizeof(m)); + memset(&strings[0], 0x00, sizeof(strings)); + FILE *ffp = setmntent("/data/getmntent.txt", "r"); + if (!ffp) { + printf("error:%s\n", strerror(errno)); + } + m = getmntent_r(ffp, &mntbuf, strings, sizeof(strings)); + EXPECT_EQ("getmntent_r_0200", m, NULL); + endmntent(ffp); + remove("/data/getmntent.txt"); +} + +TEST_FUN G_Fun_Array[] = { + getmntent_r_0100, + getmntent_r_0200, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/getopt.c b/libc-test/src/functionalext/supplement/misc/getopt.c new file mode 100644 index 00000000..ddfc419f --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/getopt.c @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : getopt_0100 + * @tc.desc : Each parameter is valid, argv is an existing command line parameter, and the analysis of the + * command line parameter is successful + * @tc.level : Level 0 + */ +void getopt_0100(void) +{ + int argc = 2; + char *argv[] = {"./getopt", "-b"}; + char *optstring = "a:bcde"; + int result = getopt(argc, argv, optstring); + if (result != 'b') { + t_error("%s getopt get result is '%c' are not want 'b'\n", __func__, result); + } +} + +/** + * @tc.name : getopt_0200 + * @tc.desc : Each parameter is valid, argv is an existing command line parameter with a colon, and the analysis + * of the command line parameter is failed + * @tc.level : Level 0 + */ +void getopt_0200(void) +{ + int argc = 2; + char *argv[] = {"./getopt", "-a12345"}; + char *optstring = "a:bcde"; + int result = getopt(argc, argv, optstring); + if (result != -1) { + t_error("%s getopt get result is %d are not want -1\n", __func__, result); + } +} + +/** + * @tc.name : getopt_0300 + * @tc.desc : The argv parameter is invalid without a colon, and the parsing of the command line parameters failed + * @tc.level : Level 2 + */ +void getopt_0300(void) +{ + int argc = 2; + char *argv[] = {"./getopt", "-a"}; + char *optstring = "a:bcde"; + int result = getopt(argc, argv, optstring); + if (result != -1) { + t_error("%s getopt get result is %d are not want -1\n", __func__, result); + } +} + +/** + * @tc.name : getopt_0400 + * @tc.desc : The argv parameter is invalid, the command line parameter does not exist, and the parsing of the + * command line parameter failed + * @tc.level : Level 2 + */ +void getopt_0400(void) +{ + int argc = 2; + char *argv[] = {"./getopt", "-f"}; + char *optstring = "a:bcde"; + int result = getopt(argc, argv, optstring); + if (result != -1) { + t_error("%s getopt get result is %d are not want -1\n", __func__, result); + } +} + +/** + * @tc.name : getopt_0500 + * @tc.desc : The argv argument is invalid, argv is NULL, and parsing command line arguments failed + * @tc.level : Level 2 + */ +void getopt_0500(void) +{ + int argc = 2; + char *argv[] = {"./getopt", NULL}; + char *optstring = "a:bcde"; + int result = getopt(argc, argv, optstring); + if (result != -1) { + t_error("%s getopt get result is %d are not want -1\n", __func__, result); + } +} + +/** + * @tc.name : getopt_0600 + * @tc.desc : Invalid argv argument, argv is -, failed to parse command line arguments + * @tc.level : Level 2 + */ +void getopt_0600(void) +{ + int argc = 2; + char *argv[] = {"./getopt", "-"}; + char *optstring = "a:bcde"; + int result = getopt(argc, argv, optstring); + if (result != -1) { + t_error("%s getopt get result is %d are not want -1\n", __func__, result); + } +} + +/** + * @tc.name : getopt_0700 + * @tc.desc : argv argument is valid, optstring starts with -, parsing command line arguments fails + * @tc.level : Level 2 + */ +void getopt_0700(void) +{ + int argc = 2; + char *argv[] = {"./getopt", "b"}; + char *optstring = "-a:bcde"; + int result = getopt(argc, argv, optstring); + if (result != -1) { + t_error("%s getopt get result is %d are not want -1\n", __func__, result); + } +} + +/** + * @tc.name : getopt_0800 + * @tc.desc : Invalid argc argument, failed to parse command line arguments + * @tc.level : Level 2 + */ +void getopt_0800(void) +{ + int argc = 0; + char *argv[] = {"./getopt", "-b"}; + char *optstring = "a:bcde"; + int result = getopt(argc, argv, optstring); + if (result != -1) { + t_error("%s getopt get result is %d are not want -1\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + getopt_0100(); + getopt_0200(); + getopt_0300(); + getopt_0400(); + getopt_0500(); + getopt_0600(); + getopt_0700(); + getopt_0800(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/getopt_long.c b/libc-test/src/functionalext/supplement/misc/getopt_long.c new file mode 100644 index 00000000..ff5dd51d --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/getopt_long.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int32_t FAILED = -1; + +/** + * @tc.name : getopt_long_0100 + * @tc.desc : Each parameter is valid, and the command line parsing of the long option is successful. + * @tc.level : Level 0 + */ +void getopt_long_0100(int a) +{ + int c = a; + EXPECT_NE("getopt_long_0100", c, FAILED); +} + +/** + * @tc.name : getopt_long_0200 + * @tc.desc : Invalid argument, command line parsing of long options failed. + * @tc.level : Level 2 + */ +void getopt_long_0200(int b) +{ + int c = b; + EXPECT_EQ("getopt_long_0200", c, FAILED); +} + +int main(int argc, char *argv[]) +{ + argc = 2; + argv[1] = "-n"; + char *l_opt_arg; + char *const short_options = "nbl:"; + struct option long_options[] = { + {"name", 0, NULL, 'n'}, + {"bf_name", 0, NULL, 'b'}, + {"love", 1, NULL, 'l'}, + {0, 0, 0, 0}, + }; + int c; + c = getopt_long(argc, argv, short_options, long_options, NULL); + getopt_long_0100(c); + c = getopt_long(0, 0, 0, 0, NULL); + getopt_long_0200(c); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/getopt_long_only.c b/libc-test/src/functionalext/supplement/misc/getopt_long_only.c new file mode 100644 index 00000000..87176fea --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/getopt_long_only.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int32_t FAILED = -1; + +/** + * @tc.name : getopt_long_only_0100 + * @tc.desc : Each parameter is valid, and the short option command is first parsed with the long parameter. + * @tc.level : Level 0 + */ +void getopt_long_only_0100(int a) +{ + int c = a; + EXPECT_NE("getopt_long_only_0100", c, FAILED); +} + +/** + * @tc.name : getopt_long_only_0200 + * @tc.desc : Invalid argument, command line parsing failed. + * @tc.level : Level 2 + */ +void getopt_long_only_0200(int b) +{ + int c = b; + EXPECT_EQ("getopt_long_only_0200", c, FAILED); +} + +int main(int argc, char *argv[]) +{ + argc = 2; + argv[1] = "-n"; + char *l_opt_arg; + char *const short_options = "nbl:"; + struct option long_options[] = { + {"name", 0, NULL, 'n'}, + {"bf_name", 0, NULL, 'b'}, + {"love", 1, NULL, 'l'}, + {0, 0, 0, 0}, + }; + int c; + c = getopt_long_only(argc, argv, short_options, long_options, NULL); + getopt_long_only_0100(c); + c = getopt_long_only(0, 0, 0, 0, NULL); + getopt_long_only_0200(c); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/getpriority.c b/libc-test/src/functionalext/supplement/misc/getpriority.c new file mode 100755 index 00000000..e7754234 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/getpriority.c @@ -0,0 +1,114 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define TEST_PRIORITY_MAX 20 +#define TEST_PRIORITY_MIN (-20) +#define TEST_WHO_ERROR 1000 + +/** + * @tc.name : getpriority_0100 + * @tc.desc : Get the default program scheduling priority + * @tc.level : Level 0 + */ +void getpriority_0100(void) +{ + errno = 0; + int ret = getpriority(PRIO_PROCESS, getpid()); + EXPECT_EQ("getpriority_0100", errno, CMPFLAG); + EXPECT_TRUE("getpriority_0100", ret >= TEST_PRIORITY_MIN && ret <= TEST_PRIORITY_MAX); + + errno = 0; + ret = getpriority(PRIO_PGRP, getpgid(getpid())); + EXPECT_EQ("getpriority_0100", errno, CMPFLAG); + EXPECT_TRUE("getpriority_0100", ret >= TEST_PRIORITY_MIN && ret <= TEST_PRIORITY_MAX); + + errno = 0; + ret = getpriority(PRIO_USER, getuid()); + EXPECT_EQ("getpriority_0100", errno, CMPFLAG); + EXPECT_TRUE("getpriority_0100", ret >= TEST_PRIORITY_MIN && ret <= TEST_PRIORITY_MAX); +} + +/** + * @tc.name : getpriority_0200 + * @tc.desc : Set and get program scheduling priority + * @tc.level : Level 0 + */ +void getpriority_0200(void) +{ + int i, ret; + for (i = TEST_PRIORITY_MIN; i < TEST_PRIORITY_MAX; i++) { + errno = 0; + ret = setpriority(PRIO_PROCESS, getpid(), i); + EXPECT_EQ("getpriority_0200", ret, CMPFLAG); + + errno = 0; + ret = getpriority(PRIO_PROCESS, getpid()); + EXPECT_EQ("getpriority_0200", ret, i); + EXPECT_EQ("getpriority_0200", errno, CMPFLAG); + } + + for (i = TEST_PRIORITY_MIN; i < TEST_PRIORITY_MAX; i++) { + errno = 0; + ret = setpriority(PRIO_PGRP, getpgid(getpid()), i); + EXPECT_EQ("getpriority_0200", ret, CMPFLAG); + + errno = 0; + ret = getpriority(PRIO_PGRP, getpgid(getpid())); + EXPECT_EQ("getpriority_0200", ret, i); + EXPECT_EQ("getpriority_0200", errno, CMPFLAG); + } + + for (i = TEST_PRIORITY_MIN; i < TEST_PRIORITY_MAX; i++) { + errno = 0; + ret = setpriority(PRIO_USER, getuid(), i); + EXPECT_EQ("getpriority_0200", ret, CMPFLAG); + + errno = 0; + ret = getpriority(PRIO_USER, getuid()); + EXPECT_EQ("getpriority_0200", ret, i); + EXPECT_EQ("getpriority_0200", errno, CMPFLAG); + } +} + +/** + * @tc.name : getpriority_0300 + * @tc.desc : Provide exception parameters, get program scheduling priority + * @tc.level : Level 2 + */ +void getpriority_0300(void) +{ + errno = 0; + int ret = getpriority(-1, -1); + EXPECT_EQ("getpriority_0300", ret, ERREXPECT); + EXPECT_EQ("getpriority_0300", errno, EINVAL); + + errno = 0; + ret = getpriority(TEST_WHO_ERROR, getpid()); + EXPECT_EQ("getpriority_0300", ret, ERREXPECT); + EXPECT_EQ("getpriority_0300", errno, EINVAL); +} + +int main(void) +{ + getpriority_0100(); + getpriority_0200(); + getpriority_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/getresgid.c b/libc-test/src/functionalext/supplement/misc/getresgid.c new file mode 100644 index 00000000..be7a9418 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/getresgid.c @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int32_t GID1000 = 1000; + +/** + * @tc.name : getresgid_0100 + * @tc.desc : Verify getresgid process success + * @tc.level : Level 0 + */ +void getresgid_0100(void) +{ + setgid(GID1000); + gid_t gid_R, gid_E, gid_S; + int ret = getresgid(&gid_R, &gid_E, &gid_S); + EXPECT_EQ("getresgid_0100", ret, 0); + EXPECT_EQ("getresgid_0100", gid_R, GID1000); + EXPECT_EQ("getresgid_0100", gid_E, GID1000); + EXPECT_EQ("getresgid_0100", gid_S, GID1000); +} + +int main(void) +{ + getresgid_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/misc/getresuid.c b/libc-test/src/functionalext/supplement/misc/getresuid.c new file mode 100644 index 00000000..cfa29fd3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/getresuid.c @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getresuid_0100 + * @tc.desc : Get the real UID, the effective UID, and the saved set-user-ID of the calling process + * @tc.level : Level 0 + */ +void getresuid_0100(void) +{ + uid_t ruid = -1; + uid_t euid = -1; + uid_t suid = -1; + int rev = getresuid(&ruid, &euid, &suid); + EXPECT_EQ("getresuid_0100", rev, 0); +} + +/** + * @tc.name : getresuid_0200 + * @tc.desc : Get the real UID, the effective UID, and the saved set-user-ID of the child process + * @tc.level : Level 0 + */ +void getresuid_0200(void) +{ + pid_t pid = fork(); + if (pid == 0) { + uid_t ruid = -1; + uid_t euid = -1; + uid_t suid = -1; + int rev = getresuid(&ruid, &euid, &suid); + EXPECT_EQ("getresuid_0200", rev, 0); + } else if (pid > 0) { + wait(NULL); + } +} + +/** + * @tc.name : getresuid_0300 + * @tc.desc : Provide wrong arguments, call getresuid + * @tc.level : Level 2 + */ +void getresuid_0300(void) +{ + int rev = getresuid(NULL, NULL, NULL); + EXPECT_EQ("getresuid_0300", rev, -1); +} + +int main(void) +{ + getresuid_0100(); + getresuid_0200(); + getresuid_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/getrlimit.c b/libc-test/src/functionalext/supplement/misc/getrlimit.c new file mode 100644 index 00000000..0d64fbc6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/getrlimit.c @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getrlimit_0100 + * @tc.desc : Verify getrlimit process success + * @tc.level : Level 0 + */ +void getrlimit_0100(void) +{ + static const long lim = 42; + static const int r = RLIMIT_NOFILE; + struct rlimit rl; + + rl.rlim_max = lim; + rl.rlim_cur = lim; + int ret = setrlimit(r, &rl); + EXPECT_EQ("getrlimit_0100", ret, 0); + struct rlimit retrl; + ret = getrlimit(r, &retrl); + EXPECT_EQ("getrlimit_0100", ret, 0); + EXPECT_LONGLONGEQ("getrlimit_0100", retrl.rlim_max, lim); + EXPECT_LONGLONGEQ("getrlimit_0100", retrl.rlim_cur, lim); +} + +/** + * @tc.name : getrlimit_0200 + * @tc.desc : Verify getrlimit process success fail bacaus param is error + * @tc.level : Level 2 + */ +void getrlimit_0200(void) +{ + struct rlimit limit; + int ret = getrlimit(-1, &limit); + EXPECT_EQ("getrlimit_0200", ret, -1); +} + +int main(void) +{ + getrlimit_0100(); + getrlimit_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/misc/getrusage.c b/libc-test/src/functionalext/supplement/misc/getrusage.c new file mode 100644 index 00000000..c456517e --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/getrusage.c @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +int success = 0; +int fail = -1; + +/** + * @tc.name : getrusage_0100 + * @tc.desc : Verify the program running time (parameter is RUSAGE_SELF) + * @tc.level : Level 0 + */ +void getrusage_0100(void) +{ + struct rusage usage; + int result = getrusage(RUSAGE_SELF, &usage); + EXPECT_EQ("getrusage_0100", result, success); +} + +/** + * @tc.name : getrusage_0200 + * @tc.desc : Verify the program running time (parameter is RUSAGE_CHILDREN) + * @tc.level : Level 1 + */ +void getrusage_0200(void) +{ + struct rusage usage; + int result = getrusage(RUSAGE_CHILDREN, &usage); + EXPECT_EQ("getrusage_0200", result, success); +} + +/** + * @tc.name : getrusage_0300 + * @tc.desc : Verify the program running time (parameter is RUSAGE_THREAD) + * @tc.level : Level 1 + */ +void getrusage_0300(void) +{ + struct rusage usage; + int result = getrusage(RUSAGE_THREAD, &usage); + EXPECT_EQ("getrusage_0300", result, success); +} + +/** + * @tc.name : getrusage_0400 + * @tc.desc : Verify that the program running time cannot be obtained (parameter is 100) + * @tc.level : Level 2 + */ +void getrusage_0400(void) +{ + struct rusage usage; + int result = getrusage(100, &usage); + EXPECT_EQ("getrusage_0400", result, fail); +} + +/** + * @tc.name : getrusage_0500 + * @tc.desc : Verify that the program running time cannot be obtained (parameter is RUSAGE_SELF) + * @tc.level : Level 2 + */ +void getrusage_0500(void) +{ + struct rusage usage; + int result = getrusage(RUSAGE_SELF, NULL); + EXPECT_EQ("getrusage_0500", result, fail); +} + +int main(void) +{ + getrusage_0100(); + getrusage_0200(); + getrusage_0300(); + getrusage_0400(); + getrusage_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/getsubopt.c b/libc-test/src/functionalext/supplement/misc/getsubopt.c new file mode 100644 index 00000000..22048dfa --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/getsubopt.c @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int32_t BUF_SIZE = 1024; + +/** + * @tc.name : getsubopt_0100 + * @tc.desc : Verify getsubopt process success find subparam + * @tc.level : Level 0 + */ +void getsubopt_0100(void) +{ + char *tokens[] = {"getsubopt", "test", NULL}; + char buf[BUF_SIZE]; + strcpy(buf, "getsubopt=0100,unknown"); + char *subopts = buf; + char *value = NULL; + EXPECT_EQ("getsubopt_0100", 0, getsubopt(&subopts, tokens, &value)); + EXPECT_STREQ("getsubopt_0100", "0100", value); +} + +/** + * @tc.name : getsubopt_0200 + * @tc.desc : Verify getsubopt process fail not find subparam + * @tc.level : Level 2 + */ +void getsubopt_0200(void) +{ + char *tokens[] = {"getsubopt", "test", NULL}; + char buf[BUF_SIZE]; + strcpy(buf, "0200=unknown, test"); + char *subopts = buf; + char *value = NULL; + EXPECT_EQ("getsubopt_0100", -1, getsubopt(&subopts, tokens, &value)); +} + +int main(void) +{ + getsubopt_0100(); + getsubopt_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/misc/hasmntopt.c b/libc-test/src/functionalext/supplement/misc/hasmntopt.c new file mode 100644 index 00000000..94cf3c19 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/hasmntopt.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int SIZE = 10; + +/** + * @tc.name : hasmntopt_0100 + * @tc.desc : Verify hasmntopt process success + * @tc.level : Level 0 + */ +void hasmntopt_0100(void) +{ + char *mnt_opts = "test_hasmntopt"; + struct mntent ent; + memset(&ent, 0, sizeof(ent)); + ent.mnt_opts = mnt_opts; + char *ret = hasmntopt(&ent, "hasmntopt"); + EXPECT_STREQ("hasmntopt_0100", ret, "hasmntopt"); +} + +/** + * @tc.name : hasmntopt_0200 + * @tc.desc : Verify hasmntopt process fail. Because opt not in mnt_opts + * @tc.level : Level 2 + */ +void hasmntopt_0200(void) +{ + char *mnt_opts = "test_hasmntopt"; + struct mntent ent; + memset(&ent, 0, sizeof(ent)); + ent.mnt_opts = mnt_opts; + char *ret = hasmntopt(&ent, "0200"); + EXPECT_PTREQ("hasmntopt_0100", ret, NULL); +} + +int main(void) +{ + hasmntopt_0100(); + hasmntopt_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/misc/initgroups.c b/libc-test/src/functionalext/supplement/misc/initgroups.c new file mode 100644 index 00000000..cdecc643 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/initgroups.c @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_GROUP_ID 1089 + +/** + * @tc.name : initgroups_0100 + * @tc.desc : The group_id of the initialization group usr_test is 1089 + * @tc.level : Level 0 + */ +void initgroups_0100(void) +{ + int rev = initgroups("usr_test", TEST_GROUP_ID); + EXPECT_EQ("initgroups_0100", rev, 0); +} + +/** + * @tc.name : initgroups_0200 + * @tc.desc : The group_id of the initialization group usr_test is -1 + * @tc.level : Level 2 + */ +void initgroups_0200(void) +{ + int rev = initgroups("usr_test", -1); + EXPECT_EQ("initgroups_0200", rev, -1); +} + +int main(void) +{ + initgroups_0100(); + initgroups_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/ioctl.c b/libc-test/src/functionalext/supplement/misc/ioctl.c new file mode 100644 index 00000000..87e69ae5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/ioctl.c @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +unsigned char TEST_IOCTL_ACCESS_TOKEN_ID = 'A'; +unsigned int GET_TOKEN_ID = 1; +unsigned int SET_TOKEN_ID = 2; +const char device_tokenid[] = "/dev/access_token_id"; +#define TEST_TOKENID_GET_TOKENID _IOR(TEST_IOCTL_ACCESS_TOKEN_ID, GET_TOKEN_ID, unsigned long long) +#define TEST_TOKENID_SET_TOKENID _IOW(TEST_IOCTL_ACCESS_TOKEN_ID, SET_TOKEN_ID, unsigned long long) +static unsigned long long GetRand64(void) +{ + unsigned long long randValue = 0; + int randFd = open("/dev/random", O_RDONLY); + if (randFd > 0) { + read(randFd, &randValue, sizeof(unsigned long long)); + } + close(randFd); + return randValue; +} + +/** + * @tc.name : ioctl_0100 + * @tc.desc : Verify ioctl management of character device. + * @tc.level : Level 0 + */ +void ioctl_0100(void) +{ + unsigned long long tokenGet; + unsigned long long token = GetRand64(); + int fd = open(device_tokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\n", device_tokenid); + EXPECT_TRUE(ioctl_0100, false); + return; + } + int ret = ioctl(fd, TEST_TOKENID_GET_TOKENID, &token); + EXPECT_EQ("ioctl_0100", 0, ret); + ret = ioctl(fd, TEST_TOKENID_GET_TOKENID, &tokenGet); + EXPECT_EQ("ioctl_0100", 0, ret); + EXPECT_EQ("ioctl_0100", 0, ret); +} + +/** + * @tc.name : ioctl_0200 + * @tc.desc : Verify ioctl management of network device. + * @tc.level : Level 0 + */ +void ioctl_0200(void) +{ + int sockFd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockFd < 0) { + printf("socket failed\n"); + EXPECT_TRUE(ioctl_0200, false); + close(sockFd); + return; + } + EXPECT_NE("ioctl_0200", -1, sockFd); + struct ifreq ifr[3]; + struct ifconf ifc = {0}; + ifc.ifc_len = 3 * sizeof(struct ifreq); + ifc.ifc_buf = (char *)ifr; + int ret = ioctl(sockFd, SIOCGIFCONF, &ifc); + EXPECT_EQ("ioctl_0200", 0, ret); + int ifrCount = ifc.ifc_len / sizeof(struct ifreq); + for (int i = 0; i < ifrCount; i++) { + printf("interface name: %s\n", ifr[i].ifr_name); + printf("address: %s\n", inet_ntoa(((struct sockaddr_in *)&(ifr[i].ifr_addr))->sin_addr)); + } + if (ifrCount == 0) { + close(sockFd); + return; + } + char interName[128]; + strcpy(interName, ifr[0].ifr_name); + char interAddr[128]; + strcpy(interAddr, inet_ntoa(((struct sockaddr_in *)&(ifr[0].ifr_addr))->sin_addr)); + struct ifreq ifrAddr = {0}; + strcpy(ifrAddr.ifr_name, interName); + ret = ioctl(sockFd, SIOCGIFADDR, &ifrAddr); + EXPECT_EQ("ioctl_0200", 0, ret); + struct sockaddr_in *srvAddr = (struct sockaddr_in *)&ifrAddr.ifr_addr; + EXPECT_STREQ("ioctl_0200", interAddr, inet_ntoa(srvAddr->sin_addr)); + close(sockFd); +} + +TEST_FUN G_Fun_Array[] = { + ioctl_0100, + ioctl_0200, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/misc/issetugid.c b/libc-test/src/functionalext/supplement/misc/issetugid.c new file mode 100644 index 00000000..3a0ba4fe --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/issetugid.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : issetugid_0100 + * @tc.desc : Test whether the issetugid function get program has set gid uid + * @tc.level : Level 0 + */ +void issetugid_0100(void) +{ + int result = issetugid(); + if (result != 0) { + t_error("%s issetugid error get result is %d are not 0", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + issetugid_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/lockf.c b/libc-test/src/functionalext/supplement/misc/lockf.c new file mode 100644 index 00000000..c88c1b87 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/lockf.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const char *path = "lockf.txt"; +const int SIZE = 3; + +/** + * @tc.name : lockf_0100 + * @tc.desc : Verify lockf process success. When cmd is F_LOCK. + * @tc.level : Level 0 + */ +void lockf_0100(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + if (fd < 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + return; + } + + int ret = lockf(fd, F_LOCK, 0); + EXPECT_EQ("lockf_0100", ret, 0); + + ret = lockf(fd, F_ULOCK, 0); + EXPECT_EQ("lockf_0100", ret, 0); + + ret = remove(path); + EXPECT_EQ("lockf_0100", ret, 0); +} + +/** + * @tc.name : lockf_0200 + * @tc.desc : Verify lockf process success. When cmd is F_TLOCK. + * @tc.level : Level 0 + */ +void lockf_0200(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + if (fd < 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + return; + } + + int ret = lockf(fd, F_TLOCK, 0); + EXPECT_EQ("lockf_0200", ret, 0); + + ret = lockf(fd, F_ULOCK, 0); + EXPECT_EQ("lockf_0200", ret, 0); + + ret = remove(path); + EXPECT_EQ("lockf_0200", ret, 0); +} + +/** + * @tc.name : lockf_0300 + * @tc.desc : Verify lockf process success. When cmd is F_TEST. + * @tc.level : Level 0 + */ +void lockf_0300(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + if (fd < 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + } + + int ret = lockf(fd, F_LOCK, 0); + EXPECT_EQ("lockf_0300", ret, 0); + + ret = lockf(fd, F_TEST, 0); + EXPECT_EQ("lockf_0300", ret, 0); + + ret = lockf(fd, F_ULOCK, 0); + EXPECT_EQ("lockf_0300", ret, 0); + + ret = remove(path); + EXPECT_EQ("lockf_0300", ret, 0); +} + +/** + * @tc.name : lockf_0400 + * @tc.desc : Verify lockf process fail bacause lock mode is error. + * @tc.level : Level 0 + */ +void lockf_0400(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + if (fd < 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + } + + int ret = lockf(fd, -1, 0); + EXPECT_EQ("lockf_0400", ret, -1); + + ret = remove(path); + EXPECT_EQ("lockf_0400", ret, 0); +} + +int main(void) +{ + lockf_0100(); + lockf_0200(); + lockf_0300(); + lockf_0400(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/misc/login_tty.c b/libc-test/src/functionalext/supplement/misc/login_tty.c new file mode 100644 index 00000000..04d7c12f --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/login_tty.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int32_t fd = 3; + +/** + * @tc.name : login_tty_0100. + * @tc.desc : Verify login_tty process success when param is -1 return -1. + * @tc.level : level 0 + */ +void login_tty_0100(void) +{ + int ret = login_tty(-1); + EXPECT_EQ("login_tty_0100", ret, -1); +} + +int main(void) +{ + login_tty_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/misc/nftw.c b/libc-test/src/functionalext/supplement/misc/nftw.c new file mode 100644 index 00000000..d8881e59 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/nftw.c @@ -0,0 +1,100 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +#define TEST_FD_LIMIT 128 +#define TEST_FLAG_SIZE 4 +#define TEST_DIGIT_TWO 2 + +static int nftw_callback(const char *pathname, const struct stat *sb, int flag, struct FTW *ftw) +{ + EXPECT_TRUE("nftw_callback", pathname != NULL); + EXPECT_TRUE("nftw_callback", sb != NULL); + if (flag == FTW_NS) { + struct stat st; + EXPECT_EQ("nftw_callback", stat(pathname, &st), -1); + return 0; + } + + if (S_ISDIR(sb->st_mode)) { + if (access(pathname, R_OK) == 0) { + EXPECT_TRUE("nftw_callback", flag == FTW_D || flag == FTW_DP); + } else { + EXPECT_EQ("nftw_callback", flag, FTW_DNR); + } + } else if (S_ISLNK(sb->st_mode)) { + EXPECT_EQ("nftw_callback", flag, FTW_SL); + } else { + EXPECT_EQ("nftw_callback", flag, FTW_F); + } + return 0; +} + +/** + * @tc.name : nftw_0100 + * @tc.desc : Traverse directory /data + * @tc.level : Level 0 + */ +void nftw_0100(void) +{ + int flag[TEST_FLAG_SIZE] = {FTW_PHYS, FTW_MOUNT, FTW_CHDIR, FTW_DEPTH}; + const char *path = "/data"; + int i; + for (i = 0; i < TEST_FLAG_SIZE; i++) { + int ret = nftw(path, nftw_callback, TEST_FD_LIMIT, flag[i]); + EXPECT_EQ("nftw_0100", ret, 0); + } +} + +/** + * @tc.name : nftw_0200 + * @tc.desc : Traverse directory /data, but the maximum number of file descriptors is 0 + * @tc.level : Level 0 + */ +void nftw_0200(void) +{ + const char *path = "/data"; + int ret = nftw(path, nftw_callback, 0, FTW_PHYS); + EXPECT_EQ("nftw_0200", ret, 0); +} + +/** + * @tc.name : nftw_0300 + * @tc.desc : The file path length exceeds PATH_MAX, traverse the directory + * @tc.level : Level 2 + */ +void nftw_0300(void) +{ + char path[PATH_MAX * TEST_DIGIT_TWO]; + memset(path, 'a', sizeof(path)); + path[PATH_MAX * TEST_DIGIT_TWO - 1] = 0; + int ret = nftw(path, nftw_callback, TEST_FD_LIMIT, FTW_PHYS); + EXPECT_EQ("nftw_0300", ret, -1); + EXPECT_EQ("nftw_0300", errno, ENAMETOOLONG); +} + +int main(void) +{ + nftw_0100(); + nftw_0200(); + nftw_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/openpty.c b/libc-test/src/functionalext/supplement/misc/openpty.c new file mode 100755 index 00000000..eaf89d7c --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/openpty.c @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : openpty_0100 + * @tc.desc : Open the ptm file to establish a pseudo terminal, and determine + * whether the terminal descriptor is successfully obtained + * @tc.level : Level 0 + */ +void openpty_0100(void) +{ + int amaster, aslave; + int ret = openpty(&amaster, &aslave, NULL, NULL, NULL); + + EXPECT_EQ("openpty_0100", ret, CMPFLAG); + EXPECT_NE("openpty_0100", amaster, ERREXPECT); + EXPECT_NE("openpty_0100", aslave, ERREXPECT); +} + +/** + * @tc.name : openpty_0200 + * @tc.desc : Open the ptm file to establish a pseudo terminal, and judge + * whether the function successfully obtains the terminal name + * @tc.level : Level 0 + */ +void openpty_0200(void) +{ + int amaster, aslave; + char name[32] = {0}; + struct termios tio; + struct winsize size; + int ret = openpty(&amaster, &aslave, name, &tio, &size); + EXPECT_EQ("openpty_0200", ret, CMPFLAG); + EXPECT_NE("openpty_0200", amaster, ERREXPECT); + EXPECT_NE("openpty_0200", aslave, ERREXPECT); +} + +int main(void) +{ + openpty_0100(); + openpty_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/ptsname.c b/libc-test/src/functionalext/supplement/misc/ptsname.c new file mode 100755 index 00000000..eb15f268 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/ptsname.c @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +#define PTMPATH "/dev/ptmx" + +/** + * @tc.name : ptsname_0100 + * @tc.desc : Open the ptm file to establish a pseudo terminal, and judge + * whether the function successfully obtains the terminal name + * @tc.level : Level 0 + */ +void ptsname_0100(void) +{ + char *mastername = NULL; + + int masterfd = open(PTMPATH, O_RDONLY); + if (masterfd == -1) { + perror("open failed"); + exit(EXIT_FAILURE); + } + mastername = ptsname(masterfd); + EXPECT_PTRNE("ptsname_0100", mastername, NULL); + + close(masterfd); +} + +/** + * @tc.name : ptsname_0200 + * @tc.desc : Pass in a non-existing terminal descriptor to determine whether the function returns NULL + * @tc.level : Level 2 + */ +void ptsname_0200(void) +{ + int aslave = -1; + char *aslavename = NULL; + + aslavename = ptsname(aslave); + EXPECT_PTREQ("ptsname_0200", aslavename, NULL); +} + +int main(void) +{ + ptsname_0100(); + ptsname_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/pty.c b/libc-test/src/functionalext/supplement/misc/pty.c new file mode 100644 index 00000000..83ccf203 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/pty.c @@ -0,0 +1,139 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "functionalext.h" + +#define TEST_BUFFER_SIZE 128 + +/** + * @tc.name : grantpt_0100 + * @tc.desc : Grant access to the slave pseudoterminal + * @tc.level : Level 0 + */ +void grantpt_0100(void) +{ + int rev = grantpt(0); + EXPECT_EQ("grantpt_0100", rev, 0); +} + +/** + * @tc.name : ptsname_r_0100 + * @tc.desc : Provide the correct parameters to get the terminal device name + * @tc.level : Level 0 + */ +void ptsname_r_0100(void) +{ + char buf[TEST_BUFFER_SIZE]; + int fd = open("/dev/pts/ptmx", O_RDWR | O_NOCTTY); + EXPECT_NE("ptsname_r_0100", fd, -1); + int ret = grantpt(fd); + EXPECT_EQ("ptsname_r_0100", ret, 0); + + ret = ptsname_r(fd, buf, sizeof(buf)); + EXPECT_EQ("ptsname_r_0100", ret, 0); + close(fd); +} + +/** + * @tc.name : ptsname_r_0200 + * @tc.desc : Provide illegal buffer parameter, get terminal device name + * @tc.level : Level 2 + */ +void ptsname_r_0200(void) +{ + char *buf = NULL; + int fd = open("/dev/pts/ptmx", O_RDWR | O_NOCTTY); + EXPECT_NE("ptsname_r_0200", fd, -1); + int ret = grantpt(fd); + EXPECT_EQ("ptsname_r_0200", ret, 0); + + ret = ptsname_r(fd, buf, TEST_BUFFER_SIZE); + EXPECT_EQ("ptsname_r_0200", ret, ERANGE); + close(fd); +} + +/** + * @tc.name : ptsname_r_0300 + * @tc.desc : Provide wrong device ID number, get terminal device name + * @tc.level : Level 2 + */ +void ptsname_r_0300(void) +{ + char buf[TEST_BUFFER_SIZE]; + int ret = ptsname_r(STDOUT_FILENO, buf, sizeof(buf)); + EXPECT_EQ("ptsname_r_0300", ret, ENOTTY); +} + +/** + * @tc.name : ptsname_r_0400 + * @tc.desc : Provide a small buffer to get the terminal device name + * @tc.level : Level 2 + */ +void ptsname_r_0400(void) +{ + char buf[1]; + int fd = open("/dev/pts/ptmx", O_RDWR | O_NOCTTY); + EXPECT_NE("ptsname_r_0400", fd, -1); + int ret = grantpt(fd); + EXPECT_EQ("ptsname_r_0400", ret, 0); + + ret = ptsname_r(fd, buf, sizeof(buf)); + EXPECT_EQ("ptsname_r_0400", ret, ERANGE); + close(fd); +} + +/** + * @tc.name : posix_openpt_0100 + * @tc.desc : Open the ptmx file in the dev directory (success) + * @tc.level : Level 0 + */ +void posix_openpt_0100(void) +{ + int amaster, aslave; + int ret = posix_openpt(O_RDWR | O_CREAT); + EXPECT_NE("posix_openpt_0100", ret, ERREXPECT); + ret = close(ret); +} + +/** + * @tc.name : posix_openpt_0200 + * @tc.desc : Open the ptmx file in the dev directory (failed) + * @tc.level : Level 2 + */ +void posix_openpt_0200(void) +{ + errno = ENOSPC; + int ret = posix_openpt(O_EXCL | O_CREAT); + EXPECT_EQ("posix_openpt_0200", ret, ERREXPECT); +} + +int main(void) +{ + grantpt_0100(); + ptsname_r_0100(); + ptsname_r_0200(); + ptsname_r_0300(); + ptsname_r_0400(); + posix_openpt_0100(); + posix_openpt_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/realpath.c b/libc-test/src/functionalext/supplement/misc/realpath.c new file mode 100644 index 00000000..4bda90a9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/realpath.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : realpath_0100 + * @tc.desc : Verify realpath process success + * @tc.level : Level 0 + */ +void realpath_0100(void) +{ + char actualPath[4096]; + char *ret = realpath("/system/bin/../etc", actualPath); + EXPECT_STREQ("realpath_0100", ret, "/system/etc"); + EXPECT_STREQ("realpath_0100", actualPath, "/system/etc"); +} + +/** + * @tc.name : realpath_0200 + * @tc.desc : Verify realpath process success fail bacaus path is error + * @tc.level : Level 2 + */ +void realpath_0200(void) +{ + char actualPath[4096] = {0}; + char *ret = realpath(NULL, actualPath); + EXPECT_PTREQ("realpath_0200", ret, NULL); + ret = realpath("/system/bin/../mypth", actualPath); + EXPECT_PTREQ("realpath_0200", ret, NULL); + ret = realpath("/system/bin/../etc", NULL); + EXPECT_STREQ("realpath_0200", ret, "/system/etc"); +} + +int main(int argc, char *argv[]) +{ + realpath_0100(); + realpath_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/misc/setlogmask.c b/libc-test/src/functionalext/supplement/misc/setlogmask.c new file mode 100644 index 00000000..81041a33 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/setlogmask.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "test.h" + +const int maskpri = LOG_UPTO(LOG_WARNING); + +/** + * @tc.name : setlogmask_0100 + * @tc.desc : set log priority mask + * @tc.level : Level 0 + */ +void setlogmask_0100(void) +{ + int result = setlogmask(maskpri); + + result = setlogmask(result); + + if (result != maskpri) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : setlogmask_0200 + * @tc.desc : set log an invalid priority mask + * @tc.level : Level 2 + */ +void setlogmask_0200(void) +{ + int result = setlogmask(0); + + if (result != setlogmask(result)) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + setlogmask_0100(); + setlogmask_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/misc/setpriority.c b/libc-test/src/functionalext/supplement/misc/setpriority.c new file mode 100644 index 00000000..db0d4bb5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/setpriority.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : setpriority_0100 + * @tc.desc : Set process priority + * @tc.level : Level 0 + */ +void setpriority_0100(void) +{ + int result = setpriority(PRIO_PROCESS, gettid(), 1); + if (result != 0) { + t_error("%s setpriority get result is %d not zero", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + setpriority_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/syscall.c b/libc-test/src/functionalext/supplement/misc/syscall.c new file mode 100644 index 00000000..355b4ee2 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/syscall.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : syscall_0100 + * @tc.desc : Test used syscall to get thread kernel id + * @tc.level : Level 0 + */ +void syscall_0100(void) +{ + pid_t tid; + tid = syscall(SYS_gettid); + if (tid == 0) { + t_error("%s syscall SYS_gettid is 0\n", __func__); + } +} + +/** + * @tc.name : syscall_0200 + * @tc.desc : Test used syscall to get gid + * @tc.level : Level 0 + */ +void syscall_0200(void) +{ + gid_t gid; + gid = syscall(SYS_getgid); + if (gid != 0) { + t_error("%s syscall SYS_getgid is not 0\n", __func__); + } +} + +int main(int argc, char *argv[]) +{ + syscall_0100(); + syscall_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/syslog.c b/libc-test/src/functionalext/supplement/misc/syslog.c new file mode 100644 index 00000000..d63dced1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/syslog.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +#define INVALID_LEVEL (-1) + +/** + * @tc.name : syslog_0100 + * @tc.desc : generates a log message + * @tc.level : Level 0 + */ +void syslog_0100(void) +{ + syslog(LOG_INFO, "syslog"); + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +/** + * @tc.name : syslog_0200 + * @tc.desc : generates a log message with an invalid level + * @tc.level : Level 2 + */ +void syslog_0200(void) +{ + syslog(INVALID_LEVEL, "syslog"); + if (errno == 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + syslog_0100(); + syslog_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/misc/test_src_functionalext_supplement_misc.gni b/libc-test/src/functionalext/supplement/misc/test_src_functionalext_supplement_misc.gni new file mode 100644 index 00000000..cbe0c43e --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/test_src_functionalext_supplement_misc.gni @@ -0,0 +1,52 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_misc_test = [ + "getrlimit", + "getresgid", + "getsubopt", + "hasmntopt", + "realpath", + "setlogmask", + "setpriority", + "syscall", + "syslog", + "issetugid", + "lockf", + "login_tty", + "uname", + "getresuid", + "initgroups", + "nftw", + "pty", + "ffs", + "getopt", + "getopt_long", + "endmntent", + "getopt_long_only", + "getmntent", + "getmntent_r", + "ffsl", + "ffsll", + "forkpty", + "getdomainname", + "getpriority", + "openpty", + "ptsname", + "unlockpt", + "vsyslog", + "getauxval", + "getentropy", + "getrusage", + "ioctl", +] diff --git a/libc-test/src/functionalext/supplement/misc/uname.c b/libc-test/src/functionalext/supplement/misc/uname.c new file mode 100644 index 00000000..b0eee9a6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/uname.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +/** + * @tc.name : uname_0100 + * @tc.desc : get system infomation + * @tc.level : Level 0 + */ +void uname_0100(void) +{ + struct utsname buf; + int result = uname(&buf); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + if (strlen(buf.sysname) == 0) { + t_error("%s failed: sysname\n", __func__, result); + } + + if (strlen(buf.nodename) == 0) { + t_error("%s failed: nodename\n", __func__); + } + + if (strlen(buf.release) == 0) { + t_error("%s failed: release\n", __func__); + } + + if (strlen(buf.version) == 0) { + t_error("%s failed: version\n", __func__); + } + + if (strlen(buf.machine) == 0) { + t_error("%s failed: machine\n", __func__); + } + +#ifdef _GNU_SOURCE + if (strlen(buf.domainname) == 0) { + t_error("%s failed: domainname\n", __func__); + } +#else + if (strlen(buf.__domainname) == 0) { + t_error("%s failed: __domainname\n", __func__); + } +#endif +} + +/** + * @tc.name : uname_0200 + * @tc.desc : get system infomation with NULL + * @tc.level : Level 2 + */ +void uname_0200(void) +{ + int result = uname(NULL); + if (result == 0) { + t_error("%s failed\n", __func__); + return; + } + + if (errno != EFAULT) { + t_error("%s failed: errno = %d\n", __func__, errno); + return; + } +} + +int main(int argc, char *argv[]) +{ + uname_0100(); + uname_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/misc/unlockpt.c b/libc-test/src/functionalext/supplement/misc/unlockpt.c new file mode 100644 index 00000000..aafe5655 --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/unlockpt.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : unlockpt_0100 + * @tc.desc : Test the unlockpt method to gain access to the pseudo-terminal + * @tc.level : Level 0 + */ +void unlockpt_0100(void) +{ + int result; + + int fdm = open("/dev/pts/ptmx", O_RDWR | O_NOCTTY); + if (fdm < 0) { + t_error("%s open master failed", __func__); + return; + } + result = grantpt(fdm); + if (result < 0) { + t_error("%s grantpt failed", __func__); + return; + } + + result = unlockpt(fdm); + if (result < 0) { + t_error("%s unlockpt failed", __func__); + return; + } +} + +int main(int argc, char *argv[]) +{ + unlockpt_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/misc/vsyslog.c b/libc-test/src/functionalext/supplement/misc/vsyslog.c new file mode 100644 index 00000000..56e5787d --- /dev/null +++ b/libc-test/src/functionalext/supplement/misc/vsyslog.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +#define INVALID_LEVEL (-1) + +/** + * @tc.name : vsyslog_0100 + * @tc.desc : generates a log message + * @tc.level : Level 0 + */ +void vsyslog_0100(char *s, ...) +{ + errno = 0; + va_list ap; + va_start(ap, s); + vsyslog(LOG_INFO, s, ap); + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + va_end(ap); +} + +/** + * @tc.name : vsyslog_0200 + * @tc.desc : generates a log message with an invalid level + * @tc.level : Level 2 + */ +void vsyslog_0200(char *s, ...) +{ + errno = 0; + va_list ap; + va_start(ap, s); + vsyslog(INVALID_LEVEL, s, ap); + if (errno == 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + va_end(ap); +} + +int main(int argc, char *argv[]) +{ + vsyslog_0100("vsyslog: %d", 1); + vsyslog_0200("vsyslog: %d", 1); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/mman/BUILD.gn b/libc-test/src/functionalext/supplement/mman/BUILD.gn new file mode 100755 index 00000000..c1e65566 --- /dev/null +++ b/libc-test/src/functionalext/supplement/mman/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_mman.gni") + +foreach(s, functionalext_supplement_mman_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/mman" + } +} + +group("functionalext_supplement_mman_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_mman_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/mman/madvise.c b/libc-test/src/functionalext/supplement/mman/madvise.c new file mode 100644 index 00000000..4887e1e1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/mman/madvise.c @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "functionalext.h" + +const char *path = "madvise_function_test.c"; + +static int openfile(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + if (fd < 0) { + t_error("open file failed\n"); + return -1; + } + return fd; +} + +static void clearfile(void) +{ + if (access(path, F_OK) == 0) { + remove(path); + } +} + +/** + * @tc.name : madvise_0100 + * @tc.desc : Verify that the return value result of creating a reasonable data page is as expected + * @tc.level : Level 1 + */ +void madvise_0100(void) +{ + size_t length = 4096; + int fd = openfile(); + EXPECT_NE("madvise_0100", fd, ERREXPECT); + void *ptr = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + EXPECT_PTRNE("madvise_0100", ptr, MAP_FAILED); + if (ptr == MAP_FAILED || ptr == NULL) { + return; + } + int ret = madvise(ptr, length, MADV_NORMAL); + EXPECT_EQ("madvise_0100", ret, CMPFLAG); + munmap(ptr, length); + close(fd); + clearfile(); +} + +/** + * @tc.name : madvise_0200 + * @tc.desc : Verify that the return value result of creating a super long data page is as expected + * @tc.level : Level 2 + */ +void madvise_0200(void) +{ + size_t length = 4096; + int fd = openfile(); + + EXPECT_NE("madvise_0200", fd, ERREXPECT); + void *ptr = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + EXPECT_PTRNE("madvise_0200", ptr, MAP_FAILED); + if (ptr == MAP_FAILED || ptr == NULL) { + return; + } + + size_t errorlen = -1; + int ret = madvise(ptr, errorlen, MADV_NORMAL); + EXPECT_EQ("madvise_0200", ret, ERREXPECT); + + munmap(ptr, length); + close(fd); + clearfile(); +} + +int main(void) +{ + madvise_0100(); + madvise_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/mman/mincore.c b/libc-test/src/functionalext/supplement/mman/mincore.c new file mode 100755 index 00000000..6f4c1b3a --- /dev/null +++ b/libc-test/src/functionalext/supplement/mman/mincore.c @@ -0,0 +1,90 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +#define TEST_SIZE 4096 + +/** + * @tc.name : mincore_0100 + * @tc.desc : Determine whether pages are resident in memory + * @tc.level : Level 0 + */ +void mincore_0100(void) +{ + struct stat st; + const char *pathname = "/data/tests/libc-test/src/functionalext/supplement/mman/mincore"; + int ret = stat(pathname, &st); + EXPECT_EQ("mincore_0100", ret, CMPFLAG); + if (ret != 0) { + return; + } + + int fd = open(pathname, O_RDONLY); + EXPECT_NE("mincore_0100", fd, ERREXPECT); + if (fd == -1) { + return; + } + + void *start = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + close(fd); + EXPECT_PTRNE("mincore_0100", start, NULL); + if (!start) { + return; + } + + unsigned char vec[TEST_SIZE]; + memset(vec, 0x0, sizeof(vec)); + ret = mincore(start, TEST_SIZE, vec); + EXPECT_EQ("mincore_0100", ret, CMPFLAG); + + munmap(start, st.st_size); +} + +/** + * @tc.name : mincore_0200 + * @tc.desc : Determine whether pages are resident in memory + * @tc.level : Level 2 + */ +void mincore_0200(void) +{ + char *memory = (char *)malloc(TEST_SIZE); + if (memory == NULL) { + EXPECT_PTRNE("mincore_0200", memory, NULL); + return; + } + + unsigned char vec[TEST_SIZE]; + memset(vec, 0x0, sizeof(vec)); + int ret = mincore(memory, TEST_SIZE, vec); + EXPECT_EQ("mincore_0200", ret, ERREXPECT); + + ret = mincore(memory, TEST_SIZE, NULL); + EXPECT_EQ("mincore_0200", ret, ERREXPECT); + free(memory); + memory = NULL; +} + +int main(void) +{ + mincore_0100(); + mincore_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/mman/mlock.c b/libc-test/src/functionalext/supplement/mman/mlock.c new file mode 100644 index 00000000..6db64b2a --- /dev/null +++ b/libc-test/src/functionalext/supplement/mman/mlock.c @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "functionalext.h" + +/** + * @tc.name : mlock_0100 + * @tc.desc : Assert whether locking 4k memory is successful, release resources after use + * @tc.level : Level 0 + */ +void mlock_0100(void) +{ + size_t memsize = 4096; + char *memory = (char *)malloc(memsize); + if (memory == NULL) { + EXPECT_PTRNE("mlock_0100", memory, NULL); + return; + } + memset(memory, '\0', memsize); + int result = mlock(memory, memsize); + EXPECT_NE("mlock_0100", result, ERREXPECT); + + munlock(memory, memsize); + free(memory); + memory = NULL; +} + +int main(void) +{ + mlock_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/mman/mlockall.c b/libc-test/src/functionalext/supplement/mman/mlockall.c new file mode 100644 index 00000000..66169949 --- /dev/null +++ b/libc-test/src/functionalext/supplement/mman/mlockall.c @@ -0,0 +1,90 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : mlockall_0100 + * @tc.desc : Verify mlockall success. When flag is MCL_CURRENT. + * @tc.level : Level 0 + */ +void mlockall_0100(void) +{ + size_t memsize = 4096; + char *memory = (char *)malloc(memsize); + if (memory == NULL) { + EXPECT_PTRNE("mlockall_0100", memory, NULL); + return; + } + memset(memory, '\0', memsize); + int result = mlockall(MCL_CURRENT); + EXPECT_EQ("mlockall_0100", result, 0); + + munlockall(); + free(memory); + memory = NULL; +} + +/** + * @tc.name : mlockall_0200 + * @tc.desc : Verify mlockall success. When flag is MCL_FUTURE. + * @tc.level : Level 0 + */ +void mlockall_0200(void) +{ + int result = mlockall(MCL_FUTURE); + EXPECT_EQ("mlockall_0200", result, 0); + size_t memsize = 4096; + char *memory = (char *)malloc(memsize); + if (memory == NULL) { + EXPECT_PTRNE("mlockall_0200", memory, NULL); + return; + } + memset(memory, '\0', memsize); + munlockall(); + free(memory); + memory = NULL; +} + +/** + * @tc.name : mlockall_0300 + * @tc.desc : Verify mlockall success. When flag is error. + * @tc.level : Level 0 + */ +void mlockall_0300(void) +{ + size_t memsize = 4096; + char *memory = (char *)malloc(memsize); + if (memory == NULL) { + EXPECT_PTRNE("mlockall_0300", memory, NULL); + return; + } + memset(memory, '\0', memsize); + int result = mlockall(-1); + EXPECT_EQ("mlockall_0300", result, ERREXPECT); + + free(memory); + memory = NULL; +} + +int main(void) +{ + mlockall_0100(); + mlockall_0200(); + mlockall_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/mman/mmap.c b/libc-test/src/functionalext/supplement/mman/mmap.c new file mode 100644 index 00000000..86d8d38b --- /dev/null +++ b/libc-test/src/functionalext/supplement/mman/mmap.c @@ -0,0 +1,503 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int EOK = 0; +const int SUCCESS = 0; +const int FAILED = -1; +#define OFF_MASK ((-0x2000ULL << (8 * sizeof(long) - 1)) | (4096ULL - 1)) + +/** + * @tc.name : mmap_0100 + * @tc.desc : The parameters are valid, prot is PROT_READ, + * and flags is MAP_PRIVATE, which can map the file content into memory + * @tc.level : Level 0 + */ +void mmap_0100(void) +{ + int fd; + int mm; + void *start; + const char *ptr = "/data/test.txt"; + static char str[] = "this is a sample!"; + int number = 0; + FILE *fptr = fopen(ptr, "w+"); + struct stat statbuff; + fwrite(str, sizeof(char), strlen(str), fptr); + fseek(fptr, 0L, SEEK_SET); + if (fgetc(fptr) == EOF) { + number = 1; + } else { + number = 2; + } + int back = stat(ptr, &statbuff); + fclose(fptr); + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777); + if (fd < 0) { + printf("Error!1"); + exit(1); + } + start = mmap(NULL, statbuff.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + EXPECT_EQ("mmap_0100", number, 2); + EXPECT_EQ("mmap_0100", back, SUCCESS); + bool flag = false; + if (start != MAP_FAILED) { + flag = true; + } + EXPECT_TRUE("mmap_0100", flag); + mm = munmap(start, statbuff.st_size); + EXPECT_EQ("mmap_0100", mm, SUCCESS); + remove(ptr); + remove("/data/test.txt"); + fptr = NULL; + ptr = NULL; + close(fd); +} + +/** + * @tc.name : mmap_0200 + * @tc.desc : The parameters are valid, prot is PROT_READ|PROT_WRITE, + * and flags is MAP_SHARED, which can map the file content into memory + * @tc.level : Level 0 + */ +void mmap_0200(void) +{ + int fd; + int mm; + void *start; + const char *ptr = "/data/test.txt"; + static char str[] = "this is a sample!"; + int number = 0; + FILE *fptr = fopen(ptr, "w+"); + struct stat statbuff; + struct stat sb; + fwrite(str, sizeof(char), strlen(str), fptr); + fseek(fptr, 0L, SEEK_SET); + if (fgetc(fptr) == EOF) { + number = 1; + } else { + number = 2; + } + int back = stat(ptr, &statbuff); + fclose(fptr); + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777); + if (fd < 0) { + printf("Error!2"); + exit(1); + } + start = mmap(NULL, statbuff.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + EXPECT_EQ("mmap_0200", number, 2); + EXPECT_EQ("mmap_0200", back, SUCCESS); + bool flag = false; + if (start != MAP_FAILED) { + flag = true; + } + EXPECT_TRUE("mmap_0200", flag); + mm = munmap(start, statbuff.st_size); + EXPECT_EQ("mmap_0200", mm, SUCCESS); + remove(ptr); + remove("/data/test.txt"); + fptr = NULL; + ptr = NULL; + close(fd); +} + +/** + * @tc.name : mmap_0300 + * @tc.desc : The parameters are valid, prot is PROT_READ|PROT_WRITE, and flags is MAP_SHARED|MAP_ANON, + * which can map the file content into memory + * @tc.level : Level 1 + */ +void mmap_0300(void) +{ + void *start; + int mm; + start = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + bool flag = false; + if (start != MAP_FAILED) { + flag = true; + } + EXPECT_TRUE("mmap_0300", flag); + mm = munmap(start, getpagesize()); + EXPECT_EQ("mmap_0300", mm, SUCCESS); +} + +/** + * @tc.name : mmap_0400 + * @tc.desc : The parameters are valid, prot is PROT_EXEC, and flags is MAP_LOCKED, + * which can map the file content into memory + * @tc.level : Level 1 + */ +void mmap_0400(void) +{ + int fd; + int mm; + void *start; + const char *ptr = "/data/test.txt"; + static char str[] = "this is a sample!"; + int number = 0; + FILE *fptr = fopen(ptr, "w+"); + struct stat statbuff; + struct stat sb; + fwrite(str, sizeof(char), strlen(str), fptr); + fseek(fptr, 0L, SEEK_SET); + if (fgetc(fptr) == EOF) { + number = 1; + } else { + number = 2; + } + int back = stat(ptr, &statbuff); + fclose(fptr); + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777); + if (fd < 0) { + printf("Error!4"); + exit(1); + } + start = mmap(NULL, statbuff.st_size, PROT_EXEC, MAP_PRIVATE | MAP_LOCKED, fd, 0); + EXPECT_EQ("mmap_0400", number, 2); + EXPECT_EQ("mmap_0400", back, SUCCESS); + bool flag = false; + if (start != MAP_FAILED) { + flag = true; + } + EXPECT_TRUE("mmap_0400", flag); + mm = munmap(start, statbuff.st_size); + EXPECT_EQ("mmap_0400", mm, SUCCESS); + remove(ptr); + remove("/data/test.txt"); + fptr = NULL; + ptr = NULL; + close(fd); +} + +/** + * @tc.name : mmap_0500 + * @tc.desc : The parameters are valid, prot is PROT_READ|PROT_WRITE, and flags is MAP_PRIVATE|MAP_DENYWRITE, + * which can map the file content into memory + * @tc.level : Level 1 + */ +void mmap_0500(void) +{ + int fd; + int mm; + void *start; + const char *ptr = "/data/test.txt"; + static char str[] = "this is a sample!"; + int number = 0; + FILE *fptr = fopen(ptr, "w+"); + struct stat statbuff; + struct stat sb; + fwrite(str, sizeof(char), strlen(str), fptr); + fseek(fptr, 0L, SEEK_SET); + if (fgetc(fptr) == EOF) { + number = 1; + } else { + number = 2; + } + int back = stat(ptr, &statbuff); + fclose(fptr); + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777); + if (fd < 0) { + printf("Error!5"); + exit(1); + } + start = mmap(NULL, statbuff.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_DENYWRITE, fd, 0); + EXPECT_EQ("mmap_0500", number, 2); + EXPECT_EQ("mmap_0500", back, SUCCESS); + bool flag = false; + if (start != MAP_FAILED) { + flag = true; + } + EXPECT_TRUE("mmap_0500", flag); + mm = munmap(start, statbuff.st_size); + EXPECT_EQ("mmap_0500", mm, SUCCESS); + remove(ptr); + remove("/data/test.txt"); + fptr = NULL; + ptr = NULL; + close(fd); +} + +/** + * @tc.name : mmap_0600 + * @tc.desc : The parameters are valid, prot is PROT_NONE, and flags is MAP_PRIVATE|MAP_FIXED, + * which can map the file content into memory + * @tc.level : Level 2 + */ +void mmap_0600(void) +{ + int fd; + int mm; + void *start; + const char *ptr = "/data/test.txt"; + static char str[] = "this is a sample!"; + int number = 0; + FILE *fptr = fopen(ptr, "w+"); + struct stat statbuff; + struct stat sb; + fwrite(str, sizeof(char), strlen(str), fptr); + fseek(fptr, 0L, SEEK_SET); + if (fgetc(fptr) == EOF) { + number = 1; + } else { + number = 2; + } + int back = stat(ptr, &statbuff); + fclose(fptr); + fd = open("/data/test.txt", O_RDONLY); + if (fd < 0) { + printf("Error!6"); + exit(1); + } + start = mmap(NULL, statbuff.st_size, PROT_NONE, MAP_PRIVATE | MAP_FIXED, -1, 0); + EXPECT_EQ("mmap_0600", number, 2); + EXPECT_EQ("mmap_0600", back, SUCCESS); + EXPECT_EQ("mmap_0600", start, MAP_FAILED); + remove(ptr); + remove("/data/test.txt"); + fptr = NULL; + ptr = NULL; + close(fd); +} + +/** + * @tc.name : mmap_0700 + * @tc.desc : The parameter is invalid, the off parameter is OFF_MASK, + * the file content cannot be mapped into memory + * @tc.level : Level 2 + */ +void mmap_0700(void) +{ + int fd; + void *start; + const char *ptr = "/data/test.txt"; + static char str[] = "this is a sample!"; + int number = 0; + FILE *fptr = fopen(ptr, "w+"); + struct stat statbuff; + struct stat sb; + fwrite(str, sizeof(char), strlen(str), fptr); + fseek(fptr, 0L, SEEK_SET); + if (fgetc(fptr) == EOF) { + number = 1; + } else { + number = 2; + } + int back = stat(ptr, &statbuff); + fclose(fptr); + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777); + if (fd < 0) { + printf("Error!7"); + exit(1); + } + start = mmap(NULL, statbuff.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, OFF_MASK); + EXPECT_EQ("mmap_0700", number, 2); + EXPECT_EQ("mmap_0700", back, SUCCESS); + EXPECT_EQ("mmap_0700", start, MAP_FAILED); + remove(ptr); + remove("/data/test.txt"); + fptr = NULL; + ptr = NULL; + close(fd); +} + +/** + * @tc.name : mmap_0800 + * @tc.desc : The parameter is invalid, the len parameter exceeds the maximum value, + * and the file content cannot be mapped into memory + * @tc.level : Level 2 + */ +void mmap_0800(void) +{ + int fd; + void *start; + const char *ptr = "/data/test.txt"; + static char str[] = "this is a sample!"; + int number = 0; + FILE *fptr = fopen(ptr, "w+"); + fwrite(str, sizeof(char), strlen(str), fptr); + fseek(fptr, 0L, SEEK_SET); + if (fgetc(fptr) == EOF) { + number = 1; + } else { + number = 2; + } + fclose(fptr); + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777); + if (fd < 0) { + printf("Error!8"); + exit(1); + } + start = mmap(NULL, PTRDIFF_MAX + 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + EXPECT_EQ("mmap_0800", number, 2); + EXPECT_EQ("mmap_0800", start, MAP_FAILED); + remove(ptr); + remove("/data/test.txt"); + fptr = NULL; + ptr = NULL; + close(fd); +} + +/** + * @tc.name : mmap_0900 + * @tc.desc : The parameter is invalid, the len parameter is 0, the file content cannot be mapped into memory + * @tc.level : Level 2 + */ +void mmap_0900(void) +{ + int fd; + void *start; + const char *ptr = "/data/test.txt"; + static char str[] = "this is a sample!"; + int number = 0; + FILE *fptr = fopen(ptr, "w+"); + fwrite(str, sizeof(char), strlen(str), fptr); + fseek(fptr, 0L, SEEK_SET); + if (fgetc(fptr) == EOF) { + number = 1; + } else { + number = 2; + } + fclose(fptr); + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777); + if (fd < 0) { + printf("Error!9"); + exit(1); + } + start = mmap(NULL, 0, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + EXPECT_EQ("mmap_0900", number, 2); + EXPECT_EQ("mmap_0900", start, MAP_FAILED); + remove(ptr); + remove("/data/test.txt"); + fptr = NULL; + ptr = NULL; + close(fd); +} + +/** + * @tc.name : mmap_1000 + * @tc.desc : The parameter is invalid, the flags parameter is MAP_SHARED|MAP_ANON, and the off parameter is + * not an integer multiple of the page, the file content cannot be mapped into the memory + * @tc.level : Level 2 + */ +void mmap_1000(void) +{ + int fd; + void *start; + const char *ptr = "/data/test.txt"; + static char str[] = "this is a sample!"; + int number = 0; + FILE *fptr = fopen(ptr, "w+"); + struct stat statbuff; + struct stat sb; + fwrite(str, sizeof(char), strlen(str), fptr); + fseek(fptr, 0L, SEEK_SET); + if (fgetc(fptr) == EOF) { + number = 1; + } else { + number = 2; + } + int back = stat(ptr, &statbuff); + fclose(fptr); + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777); + if (fd < 0) { + printf("Error!10"); + exit(1); + } + start = mmap(NULL, statbuff.st_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, fd, getpagesize() - 1); + EXPECT_EQ("mmap_1000", number, 2); + EXPECT_EQ("mmap_1000", back, SUCCESS); + EXPECT_EQ("mmap_1000", start, MAP_FAILED); + remove(ptr); + remove("/data/test.txt"); + fptr = NULL; + ptr = NULL; + close(fd); +} + +/** + * @tc.name : mmap_1100 + * @tc.desc : The parameter is invalid, start is not an integer multiple of the page, + * and the file content cannot be mapped into memory + * @tc.level : Level 1 + */ +void mmap_1100(void) +{ + int fd; + int mm; + void *start; + const char *ptr = "/data/test.txt"; + static char str[] = "this is a sample!"; + int number = 0; + FILE *fptr = fopen(ptr, "w+"); + struct stat statbuff; + struct stat sb; + fwrite(str, sizeof(char), strlen(str), fptr); + fseek(fptr, 0L, SEEK_SET); + if (fgetc(fptr) == EOF) { + number = 1; + } else { + number = 2; + } + int back = stat(ptr, &statbuff); + fclose(fptr); + fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777); + if (fd < 0) { + printf("Error!11"); + exit(1); + } + int get = getpagesize() - 1; + start = mmap((void *)(&get), statbuff.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_DENYWRITE, fd, 0); + EXPECT_EQ("mmap_1100", number, 2); + EXPECT_EQ("mmap_1100", back, SUCCESS); + bool flag = false; + if (start != MAP_FAILED) { + flag = true; + } + EXPECT_TRUE("mmap_1100", flag); + mm = munmap(start, statbuff.st_size); + EXPECT_EQ("mmap_1100", mm, SUCCESS); + remove(ptr); + remove("/data/test.txt"); + fptr = NULL; + ptr = NULL; + close(fd); +} + +int main() +{ + mmap_0100(); + mmap_0200(); + mmap_0300(); + mmap_0400(); + mmap_0500(); + mmap_0600(); + mmap_0700(); + mmap_0800(); + mmap_0900(); + mmap_1000(); + mmap_1100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/mman/mprotect.c b/libc-test/src/functionalext/supplement/mman/mprotect.c new file mode 100644 index 00000000..2c6ec77a --- /dev/null +++ b/libc-test/src/functionalext/supplement/mman/mprotect.c @@ -0,0 +1,110 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; + +/** + * @tc.name : mprotect_0100 + * @tc.desc : The port parameter is PROT_READ,which can set the protection attribute of memory area. + * @tc.level : Level 0 + */ +void mprotect_0100(void) +{ + size_t align = getpagesize(); + void *buffer = memalign(align, 8 * align); + int ret = mprotect(buffer, getpagesize(), PROT_READ); + EXPECT_EQ("mprotect_0100", ret, SUCCESS); +} + +/** + * @tc.name : mprotect_0200 + * @tc.desc : The port parameter is PROT_WRITE,which can set the protection attribute of memory area. + * @tc.level : Level 0 + */ +void mprotect_0200(void) +{ + size_t align = getpagesize(); + void *buffer = memalign(align, 8 * align); + int ret = mprotect(buffer, getpagesize(), PROT_WRITE); + EXPECT_EQ("mprotect_0200", ret, SUCCESS); +} + +/** + * @tc.name : mprotect_0300 + * @tc.desc : The port parameter is PROT_EXEC,which can set the protection attribute of memory area. + * @tc.level : Level 0 + */ +void mprotect_0300(void) +{ + size_t align = getpagesize(); + void *buffer = memalign(align, 8 * align); + int ret = mprotect(buffer, getpagesize(), PROT_EXEC); + EXPECT_EQ("mprotect_0300", ret, SUCCESS); +} + +/** + * @tc.name : mprotect_0400 + * @tc.desc : The port parameter is PROT_NONE,which can set the protection attribute of memory area. + * @tc.level : Level 0 + */ +void mprotect_0400(void) +{ + size_t align = getpagesize(); + void *buffer = memalign(align, 8 * align); + int ret = mprotect(buffer, getpagesize(), PROT_NONE); + EXPECT_EQ("mprotect_0400", ret, SUCCESS); +} + +/** + * @tc.name : mprotect_0500 + * @tc.desc : The port parameter is PROT_READ|PROT_WRITE,which can set the protection attribute of memory area. + * @tc.level : Level 1 + */ +void mprotect_0500(void) +{ + size_t align = getpagesize(); + void *buffer = memalign(align, 8 * align); + int ret = mprotect(buffer, getpagesize(), PROT_READ | PROT_WRITE); + EXPECT_EQ("mprotect_0500", ret, SUCCESS); +} + +/** + * @tc.name : mprotect_0600 + * @tc.desc : The start parameter is not an integer multiple of the page, + * and the protection attribute of the memory area cannot be set. + * @tc.level : Level 2 + */ +void mprotect_0600(void) +{ + int ret = mprotect((void *)0x0001, getpagesize(), PROT_READ); + EXPECT_EQ("mprotect_0600", ret, FAILED); +} + +int main() +{ + mprotect_0100(); + mprotect_0200(); + mprotect_0300(); + mprotect_0400(); + mprotect_0500(); + mprotect_0600(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/mman/mremap.c b/libc-test/src/functionalext/supplement/mman/mremap.c new file mode 100644 index 00000000..efda0aa6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/mman/mremap.c @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define TEST_M_SIZE 1024 +#define TEST_M_NEW_SIZE 2048 + +/** + * @tc.name : mremap_0100 + * @tc.desc : Modify the size of the memory map + * @tc.level : Level 0 + */ +void mremap_0100(void) +{ + FILE *fp = tmpfile(); + if (!fp) { + EXPECT_PTRNE("mremap_0100", fp, NULL); + return; + } + + int fd = fileno(fp); + if (fd == -1) { + fclose(fp); + EXPECT_TRUE("mremap_0100", fd != -1); + return; + } + void *map = mmap(NULL, TEST_M_SIZE, PROT_READ, MAP_SHARED, fd, 0); + if (!map) { + EXPECT_PTRNE("mremap_0100", map, NULL); + return; + } + void *map_new = mremap(map, TEST_M_SIZE, TEST_M_NEW_SIZE, MREMAP_MAYMOVE); + EXPECT_PTREQ("mremap_0100", map_new, map); + int rev = munmap(map_new, TEST_M_NEW_SIZE); + EXPECT_EQ("mremap_0100", rev, 0); + rev = fclose(fp); + EXPECT_EQ("mremap_0100", rev, 0); +} + +/** + * @tc.name : mremap_0200 + * @tc.desc : Modify the size of the memory map with the maximum value, failed + * @tc.level : Level 2 + */ +void mremap_0200(void) +{ + FILE *fp = tmpfile(); + if (!fp) { + EXPECT_PTRNE("mremap_0200", fp, NULL); + return; + } + + int fd = fileno(fp); + if (fd == -1) { + fclose(fp); + EXPECT_TRUE("mremap_0200", fd != -1); + return; + } + + void *map = mmap(NULL, TEST_M_SIZE, PROT_READ, MAP_SHARED, fd, 0); + if (!map) { + EXPECT_PTRNE("mremap_0200", map, NULL); + return; + } + void *map_new = mremap(map, TEST_M_SIZE, PTRDIFF_MAX, MREMAP_MAYMOVE); + EXPECT_PTRNE("mremap_0200", map_new, map); + int rev = munmap(map, TEST_M_SIZE); + EXPECT_EQ("mremap_0200", rev, 0); + rev = fclose(fp); + EXPECT_EQ("mremap_0200", rev, 0); +} + +int main(void) +{ + mremap_0100(); + mremap_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/mman/msync.c b/libc-test/src/functionalext/supplement/mman/msync.c new file mode 100644 index 00000000..a8ec708d --- /dev/null +++ b/libc-test/src/functionalext/supplement/mman/msync.c @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define TEST_MS_SIZE 1024 + +/** + * @tc.name : msync_0100 + * @tc.desc : Synchronize a file with a memory map + * @tc.level : Level 0 + */ +void msync_0100(void) +{ + FILE *fp = tmpfile(); + if (!fp) { + EXPECT_PTRNE("msync_0100", fp, NULL); + return; + } + + int fd = fileno(fp); + if (fd == -1) { + fclose(fp); + EXPECT_TRUE("msync_0100", fd != -1); + return; + } + void *map = mmap(NULL, TEST_MS_SIZE, PROT_READ, MAP_SHARED, fd, 0); + if (!map) { + EXPECT_PTRNE("msync_0100", map, NULL); + return; + } + int rev = msync(map, TEST_MS_SIZE, MS_ASYNC); + EXPECT_EQ("msync_0100", rev, 0); + rev = munmap(map, TEST_MS_SIZE); + EXPECT_EQ("msync_0100", rev, 0); + rev = fclose(fp); + EXPECT_EQ("msync_0100", rev, 0); +} + +int main(void) +{ + msync_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/mman/munlock.c b/libc-test/src/functionalext/supplement/mman/munlock.c new file mode 100755 index 00000000..d59e5229 --- /dev/null +++ b/libc-test/src/functionalext/supplement/mman/munlock.c @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define TEST_SIZE 4096 + +/** + * @tc.name : munlock_0100 + * @tc.desc : Unlock locked memory block + * @tc.level : Level 0 + */ +void munlock_0100(void) +{ + char *memory = (char *)malloc(TEST_SIZE); + if (memory == NULL) { + EXPECT_PTRNE("munlock_0100", memory, NULL); + return; + } + + memset(memory, 0x0, TEST_SIZE); + int ret = mlock(memory, TEST_SIZE); + EXPECT_NE("munlock_0100", ret, ERREXPECT); + + ret = munlock(memory, TEST_SIZE); + EXPECT_EQ("munlock_0100", ret, CMPFLAG); + free(memory); + memory = NULL; +} + +int main(void) +{ + munlock_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/mman/munlockall.c b/libc-test/src/functionalext/supplement/mman/munlockall.c new file mode 100644 index 00000000..6bc1f6f6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/mman/munlockall.c @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : munlockall_0100 + * @tc.desc : Verify munlockall success. When lock all flag is MCL_CURRENT. + * @tc.level : Level 0 + */ +void munlockall_0100(void) +{ + size_t memsize = 4096; + char *memory = (char *)malloc(memsize); + if (memory == NULL) { + EXPECT_PTRNE("munlockall_0100", memory, NULL); + return; + } + memset(memory, '\0', memsize); + int result = mlockall(MCL_CURRENT); + EXPECT_EQ("munlockall_0100", result, 0); + + result = munlockall(); + EXPECT_EQ("munlockall_0100", result, 0); + free(memory); + memory = NULL; +} + +/** + * @tc.name : munlockall_0200 + * @tc.desc : Verify munlockall success. When lock all flag is MCL_CURRENT. + * @tc.level : Level 0 + */ +void munlockall_0200(void) +{ + int result = mlockall(MCL_FUTURE); + EXPECT_EQ("munlockall_0200", result, 0); + size_t memsize = 4096; + char *memory = (char *)malloc(memsize); + if (memory == NULL) { + EXPECT_PTRNE("munlockall_0200", memory, NULL); + return; + } + memset(memory, '\0', memsize); + result = munlockall(); + EXPECT_EQ("munlockall_0200", result, 0); + free(memory); + memory = NULL; +} + +int main(void) +{ + munlockall_0100(); + munlockall_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/mman/munmap.c b/libc-test/src/functionalext/supplement/mman/munmap.c new file mode 100755 index 00000000..796f6d55 --- /dev/null +++ b/libc-test/src/functionalext/supplement/mman/munmap.c @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int32_t COUNT_ZERO = 0; + +/* + * @tc.name : munmap_0100 + * @tc.desc : Verify that the parameters are valid to unmap the memory + * @tc.level : Level 0 + */ +void munmap_0100(void) +{ + const char *ptr = "/data/test.txt"; + const char str[] = "this is a sample!"; + FILE *fptr = fopen(ptr, "w+"); + char *p_map; + struct stat statbuff; + fwrite(str, sizeof(char), strlen(str), fptr); + fseek(fptr, 0L, SEEK_SET); + p_map = mmap(NULL, sizeof(char) * 10, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(fptr), 0); + fclose(fptr); + int data = munmap(p_map, sizeof(char) * 10); + EXPECT_EQ("munmap_0100", data, COUNT_ZERO); + remove(ptr); +} + +TEST_FUN G_Fun_Array[] = { + munmap_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/mman/posix_madvise.c b/libc-test/src/functionalext/supplement/mman/posix_madvise.c new file mode 100755 index 00000000..0c1a1fc5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/mman/posix_madvise.c @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const char *path = "posix_madvise_function_test.c"; + +static int openfile(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + if (fd < 0) { + t_error("open file failed\n"); + return -1; + } + return fd; +} + +static void clearfile(void) +{ + if (access(path, F_OK) == 0) { + remove(path); + } +} + +/** + * @tc.name : posix_madvise_0100 + * @tc.desc : Verify that the return value result of creating a reasonable data page is as expected + * @tc.level : Level 1 + */ +void posix_madvise_0100(void) +{ + size_t length = 4096; + + int fd = openfile(); + EXPECT_NE("posix_madvise_0100", fd, ERREXPECT); + + void *ptr = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + EXPECT_PTRNE("posix_madvise_0100", ptr, MAP_FAILED); + if (ptr != MAP_FAILED) { + EXPECT_EQ("posix_madvise_0100", posix_madvise(ptr, length, MADV_NORMAL), CMPFLAG); + } + munmap(ptr, length); + close(fd); + clearfile(); +} + +/** + * @tc.name : posix_madvise_0200 + * @tc.desc : Verify that the return value result of creating a super long data page is as expected + * @tc.level : Level 2 + */ +void posix_madvise_0200(void) +{ + size_t length = 4096; + int fd = openfile(); + + EXPECT_NE("posix_madvise_0200", fd, ERREXPECT); + void *ptr = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + EXPECT_PTRNE("posix_madvise_0200", ptr, MAP_FAILED); + if (ptr != MAP_FAILED) { + size_t errorlen = -1; + int ret = posix_madvise(ptr, errorlen, MADV_NORMAL); + EXPECT_GT("posix_madvise_0200", ret, CMPFLAG); + } + munmap(ptr, length); + close(fd); + clearfile(); +} + +/** + * @tc.name : posix_madvise_0300 + * @tc.desc : When the advice parameter is passed to MADV_DONTNEED + * the function exits directly and returns 0 + * @tc.level : Level 2 + */ +void posix_madvise_0300(void) +{ + void *ptr = NULL; + size_t len = 1024; + int ret = posix_madvise(ptr, len, MADV_DONTNEED); + EXPECT_EQ("posix_madvise_0300", ret, CMPFLAG); +} + +int main(void) +{ + posix_madvise_0100(); + posix_madvise_0200(); + posix_madvise_0300(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/mman/test_src_functionalext_supplement_mman.gni b/libc-test/src/functionalext/supplement/mman/test_src_functionalext_supplement_mman.gni new file mode 100644 index 00000000..f0d0efb0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/mman/test_src_functionalext_supplement_mman.gni @@ -0,0 +1,27 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_mman_test = [ + "madvise", + "mlock", + "mlockall", + "mremap", + "msync", + "munlockall", + "munmap", + "mprotect", + "mmap", + "mincore", + "munlock", + "posix_madvise", +] diff --git a/libc-test/src/functionalext/supplement/multibyte/BUILD.gn b/libc-test/src/functionalext/supplement/multibyte/BUILD.gn new file mode 100644 index 00000000..5cc6c84e --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_multibyte.gni") + +foreach(s, functionalext_supplement_multibyte_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/multibyte" + } +} + +group("functionalext_supplement_multibyte_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_multibyte_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/multibyte/c16rtomb.c b/libc-test/src/functionalext/supplement/multibyte/c16rtomb.c new file mode 100644 index 00000000..04b8beaa --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/c16rtomb.c @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +mbstate_t state; + +/** + * @tc.name : c16rtomb_0100 + * @tc.desc : Verify that the 16-bit wide character representation is converted to a narrow multibyte character + * representation. + * @tc.level : Level 0 + */ +void c16rtomb_0100(void) +{ + wchar_t str[] = L"test"; + size_t in_sz = sizeof str / sizeof *str; + int rc = 0; + char out[MB_CUR_MAX * in_sz]; + char *p = out; + for (size_t n = 0; n < in_sz; ++n) { + rc = c16rtomb(p, str[n], &state); + p += rc; + } + EXPECT_EQ("c16rtomb_0100", rc, 1); +} + +/** + * @tc.name : c16rtomb_0200 + * @tc.desc : Verify that the 16-bit wide character representation is converted to a narrow multibyte character + * representation(s parameter NULL). representation. + * @tc.level : Level 1 + */ +void c16rtomb_0200(void) +{ + wchar_t str[] = L""; + size_t in_sz = sizeof str / sizeof *str; + int rc = 0; + char out[MB_CUR_MAX * in_sz]; + char *p = out; + for (size_t n = 0; n < in_sz; ++n) { + rc = c16rtomb(p, str[n], &state); + p += rc; + } + EXPECT_EQ("c16rtomb_0200", rc, 1); +} + +/** + * @tc.name : c16rtomb_0300 + * @tc.desc : Verify that the 16-bit wide character representation cannot be converted to a narrow multibyte + * character representation (s parameter NULL). + * @tc.level : Level 2 + */ +void c16rtomb_0300(void) +{ + wchar_t str[] = L""; + size_t in_sz = sizeof str / sizeof *str; + int rc = 0; + char out[MB_CUR_MAX * in_sz]; + char *p = out; + size_t n = 0; + rc = c16rtomb(p, 0xE000u, NULL); + EXPECT_EQ("c16rtomb_0300", rc, -1); +} + +/** + * @tc.name : c16rtomb_0400 + * @tc.desc : Verify that the 16-bit wide character representation is converted to a narrow multibyte character + * representation(c16 is 0xD800u,ps parameter NULL). + * @tc.leve : Level 1 + */ +void c16rtomb_0400(void) +{ + wchar_t str[] = L"test"; + size_t in_sz = sizeof str / sizeof *str; + int rc = 0; + char out[MB_CUR_MAX * in_sz]; + char *p = out; + for (size_t n = 0; n < in_sz; ++n) { + rc = c16rtomb(p, 0xD800u, NULL); + p += rc; + } + EXPECT_EQ("c16rtomb_0400", rc, 0); +} + +/** + * @tc.name : c16rtomb_0500 + * @tc.desc : Verify that the 16-bit wide character representation is converted to a narrow multibyte character + * representation (c16 is 0xDC00u,s parameter NULL). + * @tc.leve : Level 1 + */ +void c16rtomb_0500(void) +{ + wchar_t str[] = L"test"; + size_t in_sz = sizeof str / sizeof *str; + int rc = 0; + char out[MB_CUR_MAX * in_sz]; + char *p = out; + for (size_t n = 0; n < in_sz; n++) { + rc = c16rtomb(p, 0xdc00u, NULL); + p += rc; + } + EXPECT_EQ("c16rtomb_0500", rc, -1); +} + +/** + * @tc.name : c16rtomb_0600 + * @tc.desc : Verify that the 16-bit wide character representation cannot be converted to a narrow multibyte + * character representation (c16 is 0xE000u). + * @tc.leve : Level 2 + */ +void c16rtomb_0600(void) +{ + wchar_t str[] = L"test"; + size_t in_sz = sizeof str / sizeof *str; + int rc = 0; + char out[MB_CUR_MAX * in_sz]; + char *p = out; + for (size_t n = 0; n < in_sz; ++n) { + rc = c16rtomb(p, 0xE000u, &state); + p += rc; + } + EXPECT_EQ("c16rtomb_0600", rc, -1); +} + +/** + * @tc.name : c16rtomb_0700 + * @tc.desc : Verify that the 16-bit wide character representation is converted to a narrow multibyte character + * representation (c16 is 0xDFFFu). + * @tc.leve : Level 1 + */ +void c16rtomb_0700(void) +{ + wchar_t str[] = L"test"; + size_t in_sz = sizeof str / sizeof *str; + int rc = 0; + char out[MB_CUR_MAX * in_sz]; + char *p = out; + for (size_t n = 0; n < in_sz; ++n) { + rc = c16rtomb(p, 0xDFFFu, &state); + p += rc; + } + EXPECT_EQ("c16rtomb_0700", rc, 1); +} + +int main() +{ + c16rtomb_0100(); + c16rtomb_0200(); + c16rtomb_0300(); + c16rtomb_0400(); + c16rtomb_0500(); + c16rtomb_0600(); + c16rtomb_0700(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/multibyte/c32rtomb.c b/libc-test/src/functionalext/supplement/multibyte/c32rtomb.c new file mode 100644 index 00000000..b4eebdd1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/c32rtomb.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +mbstate_t state; + +/** + * @tc.name : c32rtomb_0100 + * @tc.desc : Verify that the 32-bit wide character representation is converted to a narrow multibyte character + * representation. + * @tc.leve : Level 0 + */ +void c32rtomb_0100(void) +{ + wchar_t str[] = L"test"; + size_t in_sz = sizeof str / sizeof *str; + int rc = 0; + char out[MB_CUR_MAX * in_sz]; + char *p = out; + for (size_t n = 0; n < in_sz; ++n) { + rc = c32rtomb(p, str[n], &state); + p += rc; + } + EXPECT_EQ("c32rtomb_0100", rc, 1); +} + +int main() +{ + c32rtomb_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/multibyte/mblen.c b/libc-test/src/functionalext/supplement/multibyte/mblen.c new file mode 100644 index 00000000..e709bcd0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/mblen.c @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define ARRY_MAX 128 + +/** + * @tc.name : mblen_0100 + * @tc.desc : Verify mblen process success when wide string is not null. + * @tc.level : Level 0 + */ +void mblen_0100(void) +{ + char *src = (char *)malloc(ARRY_MAX); + if (!src) { + return; + } + wchar_t *pwc = L"mblen_0100"; + wchar_t *pwcs = (wchar_t *)malloc(sizeof(wchar_t)); + EXPECT_PTRNE("mblen_0100", pwcs, NULL); + int result = wcstombs(src, pwc, ARRY_MAX); + EXPECT_NE("mblen_0100", result, -1); + size_t ret = mblen(src, ARRY_MAX); + EXPECT_EQ("mblen_0100", ret, 1); +} + +/** + * @tc.name : mblen_0200 + * @tc.desc : Verify mblen process success when wide string is null. + * @tc.leve : Level 0 + */ +void mblen_0200(void) +{ + size_t ret = mblen(NULL, ARRY_MAX); + EXPECT_EQ("mblen_0100", ret, 0); +} + +int main(void) +{ + mblen_0100(); + mblen_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/multibyte/mbrtoc16.c b/libc-test/src/functionalext/supplement/multibyte/mbrtoc16.c new file mode 100755 index 00000000..63d190e6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/mbrtoc16.c @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define TWO_BYTE_TEST_VALUE 0x00a3 +#define THREE_BYTE_TEST_VALUE 0x08a3 +#define TWO 2 +#define THREE 3 + +/** + * @tc.name : mbrtoc16_0100 + * @tc.desc : Convert a single-byte string to a wide string + * @tc.level : Level 0 + */ +void mbrtoc16_0100(void) +{ + char16_t pc = 0; + int ret = -1; + char *str = setlocale(LC_CTYPE, "C.UTF-8"); + if (str == NULL) { + t_error("setlocale failed\n"); + return; + } + uselocale(LC_GLOBAL_LOCALE); + + ret = mbrtoc16(&pc, "abcdef", 1, NULL); + EXPECT_EQ("mbrtoc16_0100", ret, 1); + EXPECT_EQ("mbrtoc16_0100", pc, 'a'); +} + +/** + * @tc.name : mbrtoc16_0200 + * @tc.desc : Convert a multibyte string to a wide-character string + * @tc.level : Level 0 + */ +void mbrtoc16_0200(void) +{ + char16_t out; + int ret = 0; + char str[] = "\u00a3"; + char str1[] = "\u08a3"; + mbstate_t ps; + memset(&ps, 0x0, sizeof(ps)); + + ret = mbrtoc16(&out, str, strlen(str), NULL); + EXPECT_EQ("mbrtoc16_0200", ret, TWO); + EXPECT_EQ("mbrtoc16_0200", out, TWO_BYTE_TEST_VALUE); + + ret = mbrtoc16(&out, str1, strlen(str1), &ps); + EXPECT_EQ("mbrtoc16_0200", ret, THREE); + EXPECT_EQ("mbrtoc16_0200", out, THREE_BYTE_TEST_VALUE); +} + +/** + * @tc.name : mbrtoc16_0300 + * @tc.desc : Provide exception parameter data, convert the string to a wide string + * @tc.level : Level 2 + */ +void mbrtoc16_0300(void) +{ + char16_t out; + char str[] = "\xc2"; + char strx[] = "\xc2\xa3"; + int errorresult = -2; + mbstate_t ps; + memset(&ps, 0x0, sizeof(ps)); + + int ret = (int)(mbrtoc16(&out, str, sizeof(str), NULL)); + EXPECT_EQ("mbrtoc16_0300", ret, ERREXPECT); + EXPECT_EQ("mbrtoc16_0300", errno, EILSEQ); + ret = (int)(mbrtoc16(&out, strx, 1, NULL)); + EXPECT_EQ("mbrtoc16_0300", ret, errorresult); + ret = (int)(mbrtoc16(NULL, NULL, 0, &ps)); + EXPECT_EQ("mbrtoc16_0300", ret, CMPFLAG); +} + +int main(void) +{ + mbrtoc16_0100(); + mbrtoc16_0200(); + mbrtoc16_0300(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/multibyte/mbrtoc32.c b/libc-test/src/functionalext/supplement/multibyte/mbrtoc32.c new file mode 100755 index 00000000..03b7775f --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/mbrtoc32.c @@ -0,0 +1,100 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define TWO_BYTE_TEST_VALUE 0x00a3 +#define THREE_BYTE_TEST_VALUE 0x08a3 +#define TWO 2 +#define THREE 3 + +/** + * @tc.name : mbrtoc32_0100 + * @tc.desc : Convert a single-byte string to a wide string + * @tc.level : Level 0 + */ +void mbrtoc32_0100(void) +{ + char32_t pc = 0; + int ret = 0; + char *str = setlocale(LC_CTYPE, "C.UTF-8"); + if (str == NULL) { + t_error("setlocale failed\n"); + return; + } + uselocale(LC_GLOBAL_LOCALE); + + ret = mbrtoc32(&pc, "abcdef", 1, NULL); + EXPECT_EQ("mbrtoc32_0100", ret, 1); + EXPECT_EQ("mbrtoc32_0100", pc, 'a'); +} + +/** + * @tc.name : mbrtoc32_0200 + * @tc.desc : Convert a multibyte string to a wide-character string + * @tc.level : Level 0 + */ +void mbrtoc32_0200(void) +{ + char32_t out; + char str[] = "\u00a3"; + char str1[] = "\u08a3"; + mbstate_t ps; + int ret = 0; + memset(&ps, 0x0, sizeof(ps)); + + ret = mbrtoc32(&out, str, strlen(str), NULL); + EXPECT_EQ("mbrtoc32_0200", ret, TWO); + EXPECT_EQ("mbrtoc32_0200", out, TWO_BYTE_TEST_VALUE); + + ret = mbrtoc32(&out, str1, strlen(str1), &ps); + EXPECT_EQ("mbrtoc32_0200", ret, THREE); + EXPECT_EQ("mbrtoc32_0200", out, THREE_BYTE_TEST_VALUE); +} + +/** + * @tc.name : mbrtoc32_0300 + * @tc.desc : Provide exception parameter data, convert the string to a wide string + * @tc.level : Level 2 + */ +void mbrtoc32_0300(void) +{ + char32_t out; + char str[] = "\xc2"; + char strx[] = "\xc2\xa3"; + int errorresult = -2; + mbstate_t ps; + int ret = 0; + memset(&ps, 0x0, sizeof(ps)); + + ret = (int)(mbrtoc32(&out, str, sizeof(str), NULL)); + EXPECT_EQ("mbrtoc32_0300", ret, ERREXPECT); + EXPECT_EQ("mbrtoc32_0300", errno, EILSEQ); + ret = (int)(mbrtoc32(&out, strx, 1, NULL)); + EXPECT_EQ("mbrtoc32_0300", ret, errorresult); + ret = (int)(mbrtoc32(NULL, NULL, 0, &ps)); + EXPECT_EQ("mbrtoc32_0300", ret, CMPFLAG); +} + +int main(void) +{ + mbrtoc32_0100(); + mbrtoc32_0200(); + mbrtoc32_0300(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/multibyte/mbsinit.c b/libc-test/src/functionalext/supplement/multibyte/mbsinit.c new file mode 100644 index 00000000..fdfcea4c --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/mbsinit.c @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define SIZE 128 +#define INIT_ERROR_VALUE 0x01 + +/** + * @tc.name : mbsinit_0100 + * @tc.desc : Verify mbsinit process success and return nonzero value when st points to an mbstate_t object + * that describes the initial transition state. + * @tc.leve : Level 0 + */ +void mbsinit_0100(void) +{ + mbstate_t mbst; + memset(&mbst, 0, sizeof(mbst)); + int ret = mbsinit(&mbst); + EXPECT_NE("mbsinit_0100", ret, 0); +} + +/** + * @tc.name : mbsinit_0200 + * @tc.desc : Verify mbsinit process success and return nonzero value when st is null. + * @tc.leve : Level 0 + */ +void mbsinit_0200(void) +{ + int ret = mbsinit(NULL); + EXPECT_NE("mbsinit_0200", ret, 0); +} + +/** + * @tc.name : mbsinit_0300 + * @tc.desc : Verify mbsinit process success and return zero value when when st points to an mbstate_t object + * that not describes the initial transition state. + * @tc.leve : Level 1 + */ +void mbsinit_0300(void) +{ + mbstate_t mbst; + memset(&mbst, INIT_ERROR_VALUE, sizeof(mbst)); + int ret = mbsinit(&mbst); + EXPECT_EQ("mbsinit_0300", ret, 0); +} + +int main(void) +{ + mbsinit_0100(); + mbsinit_0200(); + mbsinit_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/multibyte/mbsnrtowcs.c b/libc-test/src/functionalext/supplement/multibyte/mbsnrtowcs.c new file mode 100644 index 00000000..e6a877ef --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/mbsnrtowcs.c @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "functionalext.h" + +#define ARRY_MAX 128 + +/** + * @tc.name : mbsnrtowcs_0100 + * @tc.desc : whether the function successfully converted the character + * @tc.level : Level 0 + */ +void mbsnrtowcs_0100(void) +{ + const char *test = "musl test"; + + wchar_t wc[ARRY_MAX]; + memset(wc, 0, sizeof(wc)); + + size_t result = mbsnrtowcs(wc, &test, 2, ARRY_MAX, NULL); + if (result != -1) { + EXPECT_EQ("mbsnrtowcs_0100", result, 2); + EXPECT_EQ("mbsnrtowcs_0100", wc[0], L'm'); + EXPECT_EQ("mbsnrtowcs_0100", wc[1], L'u'); + } +} + +/** + * @tc.name : mbsnrtowcs_0200 + * @tc.desc : Pass in the return value of the abnormal length judgment function + * @tc.level : Level 2 + */ +void mbsnrtowcs_0200(void) +{ + const char *test = "musl test"; + wchar_t wc[ARRY_MAX]; + memset(wc, 0, sizeof(wc)); + size_t result = mbsnrtowcs(wc, &test, 11, ARRY_MAX, NULL); + + EXPECT_EQ("mbsnrtowcs_0200", result, 9); +} + +int main(void) +{ + mbsnrtowcs_0100(); + mbsnrtowcs_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/multibyte/mbstowcs.c b/libc-test/src/functionalext/supplement/multibyte/mbstowcs.c new file mode 100755 index 00000000..c3baa76e --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/mbstowcs.c @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define TEST_BUFFER_SIZE 128 + +/** + * @tc.name : mbstowcs_0100 + * @tc.desc : Convert a multibyte string to a wide-character string + * @tc.level : Level 0 + */ +void mbstowcs_0100(void) +{ + const char *src = "mbstowcs_0100"; + wchar_t dst[TEST_BUFFER_SIZE]; + const wchar_t *wsrc = L"mbstowcs_0100"; + + memset(dst, 0x0, sizeof(wchar_t) * TEST_BUFFER_SIZE); + size_t ret = mbstowcs(dst, src, strlen(src)); + EXPECT_EQ("mbstowcs_0100", ret, strlen(src)); + + if (ret > 0) { + int r = wmemcmp(dst, wsrc, ret); + EXPECT_EQ("mbstowcs_0100", r, CMPFLAG); + } +} + +/** + * @tc.name : mbstowcs_0200 + * @tc.desc : Provide exception parameter data, convert the string to a wide string + * @tc.level : Level 2 + */ +void mbstowcs_0200(void) +{ + const char *src = "mbstowcs_0200"; + wchar_t dst[TEST_BUFFER_SIZE]; + memset(dst, 0x0, sizeof(wchar_t) * TEST_BUFFER_SIZE); + + size_t ret = mbstowcs(dst, src, 0); + if (ret != CMPFLAG) { + EXPECT_EQ("mbstowcs_0200", ret, CMPFLAG); + } + + ret = mbstowcs(NULL, src, strlen(src)); + EXPECT_EQ("mbstowcs_0200", ret, strlen(src)); +} + +int main(void) +{ + mbstowcs_0100(); + mbstowcs_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/multibyte/mbtowc.c b/libc-test/src/functionalext/supplement/multibyte/mbtowc.c new file mode 100644 index 00000000..b65460c6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/mbtowc.c @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "functionalext.h" + +#define ARRY_MAX 128 + +/** + * @tc.name : mblen_0100 + * @tc.desc : whether the function successfully converted the character + * @tc.level : Level 0 + */ +void mbtowc_0100(void) +{ + const char *test = "musl"; + wchar_t wc[ARRY_MAX]; + size_t result = 0; + result = mbtowc(wc, test, 1); + + EXPECT_EQ("mbtowc_0100", result, 1); + EXPECT_EQ("mbtowc_0100", wc[0], L'm'); +} + +/** + * @tc.name : mbtowc_0200 + * @tc.desc : Pass in the return value of the abnormal length judgment function + * @tc.level : Level 2 + */ +void mbtowc_0200(void) +{ + const char *test = "musl"; + wchar_t wc[ARRY_MAX]; + size_t result = 0; + result = mbtowc(wc, test, 0); + EXPECT_EQ("mbtowc_0200", result, -1); + EXPECT_EQ("mbtowc_0200", errno, EILSEQ); + + result = mbtowc(wc, NULL, 0); + EXPECT_EQ("mbtowc_0200", result, 0); + EXPECT_EQ("mbtowc_0200", errno, EILSEQ); + + result = mbtowc(NULL, test, 1); + EXPECT_EQ("mbtowc_0200", result, 1); + EXPECT_EQ("mbtowc_0200", errno, EILSEQ); +} + +int main(void) +{ + mbtowc_0100(); + mbtowc_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/multibyte/test_src_functionalext_supplement_multibyte.gni b/libc-test/src/functionalext/supplement/multibyte/test_src_functionalext_supplement_multibyte.gni new file mode 100644 index 00000000..af9df967 --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/test_src_functionalext_supplement_multibyte.gni @@ -0,0 +1,30 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_multibyte_test = [ + "mblen", + "mbsinit", + "wcrtomb", + "wcsnrtombs", + "wcsrtombs", + "wcstombs", + "wctob", + "mbsnrtowcs", + "wctomb", + "mbtowc", + "c16rtomb", + "c32rtomb", + "mbrtoc16", + "mbrtoc32", + "mbstowcs", +] diff --git a/libc-test/src/functionalext/supplement/multibyte/wcrtomb.c b/libc-test/src/functionalext/supplement/multibyte/wcrtomb.c new file mode 100644 index 00000000..864736c4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/wcrtomb.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcrtomb_0100 + * @tc.desc : call wcrtomb to convert wide characters to narrow characters + * @tc.level : Level 0 + */ +void wcrtomb_0100(void) +{ + wchar_t wcs = L'A'; + char s[20]; + mbstate_t pr; + memset(&pr, 0, sizeof pr); + int result = wcrtomb(s, wcs, &pr); + if (result != 1) { + t_error("%s wcrtomb get result is %d are not 1\n", __func__, result); + } + if (strcmp(s, "A") != 0) { + t_error("%s wcrtomb error get s is '%s' are not 'A'\n", __func__, s); + } +} + +/** + * @tc.name : wcrtomb_0200 + * @tc.desc : Wide character length exceeds 0x80 + * @tc.level : Level 1 + */ +void wcrtomb_0200(void) +{ + wchar_t wcs = L'\u00df'; + int want = 2; + char s[20]; + mbstate_t pr; + memset(&pr, 0, sizeof pr); + int result = wcrtomb(s, wcs, &pr); + if (result != want) { + t_error("%s wcrtomb get result is %d are not 2\n", __func__, result); + } + if (strcmp(s, "ß") != 0) { + t_error("%s wcrtomb error get s is '%s' are not 'ß'\n", __func__, s); + } +} + +/** + * @tc.name : wcrtomb_0300 + * @tc.desc : Wide character length exceeds 0x800 + * @tc.level : Level 1 + */ +void wcrtomb_0300(void) +{ + wchar_t wcs = L'\ud10f'; + int want = 3; + char s[20]; + mbstate_t pr; + memset(&pr, 0, sizeof pr); + int result = wcrtomb(s, wcs, &pr); + if (result != want) { + t_error("%s wcrtomb get result is %d are not 3\n", __func__, result); + } + if (strcmp(s, "턏") != 0) { + t_error("%s wcrtomb error get s is '%s' are not '턏'\n", __func__, s); + } +} + +int main(int argc, char *argv[]) +{ + setlocale(LC_ALL, "en_US.utf8"); + + wcrtomb_0100(); + wcrtomb_0200(); + wcrtomb_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/multibyte/wcsnrtombs.c b/libc-test/src/functionalext/supplement/multibyte/wcsnrtombs.c new file mode 100644 index 00000000..85fca601 --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/wcsnrtombs.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcsnrtombs_0100 + * @tc.desc : Convert wn wide characters in a wide string to a multibyte string + * @tc.level : Level 0 + */ +void wcsnrtombs_0100(void) +{ + const wchar_t src[] = L"test wcsnrtombs"; + const wchar_t *p; + mbstate_t mbs; + char buffer[32]; + int wn = 4; + int n = 4; + mbrlen(NULL, 0, &mbs); + memset(buffer, 0, sizeof(buffer)); + p = src; + int result = wcsnrtombs(buffer, &p, wn, n, &mbs); + if (result < 0) { + t_error("%s, get result failed", __func__); + } + if (strcmp(buffer, "test")) { + t_error("%s string in buffer is not right", __func__); + } +} + +/** + * @tc.name : wcsnrtombs_0200 + * @tc.desc : Conversion of wide characters to multibyte characters when wn < n + * @tc.level : Level 1 + */ +void wcsnrtombs_0200(void) +{ + const wchar_t src[] = L"test wcsnrtombs"; + const wchar_t *p; + mbstate_t mbs; + char buffer[32]; + int wn = 4; + int n = 5; + mbrlen(NULL, 0, &mbs); + memset(buffer, 0, sizeof(buffer)); + p = src; + int result = wcsnrtombs(buffer, &p, wn, n, &mbs); + if (result < 0) { + t_error("%s get result failed", __func__); + } + if (strcmp(buffer, "test")) { + t_error("%s string in buffer is not right", __func__); + } +} + +/** + * @tc.name : wcsnrtombs_0300 + * @tc.desc : Conversion of wide characters to multibyte characters when dst=NULL + * @tc.level : Level 2 + */ +void wcsnrtombs_0300(void) +{ + const wchar_t src[] = L"test wcsnrtombs"; + const wchar_t *p; + mbstate_t mbs; + char *buffer = NULL; + int wn = 4; + int n = 4; + mbrlen(NULL, 0, &mbs); + p = src; + int result = wcsnrtombs(buffer, &p, wn, n, &mbs); + if (result < 0) { + t_error("%s get result failed", __func__); + } + if (result != wn) { + t_error("%s get result is not equal to %d", __func__, wn); + } +} + +int main(int argc, char *argv[]) +{ + wcsnrtombs_0100(); + wcsnrtombs_0200(); + wcsnrtombs_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/multibyte/wcsrtombs.c b/libc-test/src/functionalext/supplement/multibyte/wcsrtombs.c new file mode 100644 index 00000000..ad6e80ae --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/wcsrtombs.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcsrtombs_0100 + * @tc.desc : Test the result of wcspbrk when the target character is punctuation + * @tc.level : Level 0 + */ +void wcsrtombs_0100(void) +{ + char str[256] = {0}; + int want = 6; + const wchar_t *src = L"ABCDEF"; + size_t result = wcsrtombs(str, &src, 10, NULL); + if (result != want) { + t_error("%s wcsrtombs error get result is %d are not 6", __func__, result); + } +} + +/** + * @tc.name : wcsrtombs_0200 + * @tc.desc : Test the result of wcsrtombs when the incoming number is less than the length of the wide string + * @tc.level : Level 1 + */ +void wcsrtombs_0200(void) +{ + char str[256] = {0}; + const wchar_t *src = L"ABCDEF"; + size_t result = wcsrtombs(str, &src, 0, NULL); + if (result != 0) { + t_error("%s wcsrtombs error get result is %d are not 0", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + wcsrtombs_0100(); + wcsrtombs_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/multibyte/wcstombs.c b/libc-test/src/functionalext/supplement/multibyte/wcstombs.c new file mode 100644 index 00000000..11758f1d --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/wcstombs.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +#define BUF_SIZE (40) + +/** + * @tc.name : wcstombs_0100 + * @tc.desc : convert a wide-character string to a multibyte string + * @tc.level : Level 0 + */ +void wcstombs_0100(void) +{ + char buf[BUF_SIZE] = {0}; + wchar_t src[] = L"Hello"; + + size_t result = wcstombs(buf, src, BUF_SIZE); + if (result < 0) { + t_error("%s failed: wcstombs. result = %zu\n", __func__, result); + } +} + +/** + * @tc.name : wcstombs_0200 + * @tc.desc : convert a wide-character string to a multibyte string with zero size + * @tc.level : Level 1 + */ +void wcstombs_0200(void) +{ + char buf[BUF_SIZE] = {0}; + wchar_t src[] = L"Hello"; + + size_t result = wcstombs(buf, src, 0); + if (result != 0) { + t_error("%s failed: wcstombs. result = %zu\n", __func__, result); + } +} + +/** + * @tc.name : wcstombs_0300 + * @tc.desc : convert a wide-character string to NULL + * @tc.level : Level 2 + */ +void wcstombs_0300(void) +{ + wchar_t src[] = L"Hello"; + + size_t result = wcstombs(NULL, src, 0); + if (result != wcslen(src)) { + t_error("%s failed: wcstombs. result = %zu\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + wcstombs_0100(); + wcstombs_0200(); + wcstombs_0300(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/multibyte/wctob.c b/libc-test/src/functionalext/supplement/multibyte/wctob.c new file mode 100644 index 00000000..0fd19262 --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/wctob.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wctob_0100 + * @tc.desc : Call the wctob function to convert wide characters to single bytes + * @tc.level : Level 0 + */ +void wctob_0100(void) +{ + wchar_t c = L'A'; + int result = wctob(c); + if (result != 'A') { + t_error("%s wctob get result is %c are not 'A'", __func__, result); + } +} + +/** + * @tc.name : wctob_0200 + * @tc.desc : characters over 0x80 + * @tc.level : Level 1 + */ +void wctob_0200(void) +{ + wchar_t c = L'\u00df'; + int result = wctob(c); + if (result != EOF) { + t_error("%s wctob get result is %d are not -1", __func__, result); + } +} + +/** + * @tc.name : wctob_0300 + * @tc.desc : Wide characters exceed 0xff00 + * @tc.level : Level 1 + */ +void wctob_0300(void) +{ + wchar_t c = L'\uff02'; + int result = wctob(c); + if (result != EOF) { + t_error("%s wctob get result is %c are not EOF", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + setlocale(LC_ALL, "en_US.utf8"); + + wctob_0100(); + wctob_0200(); + wctob_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/multibyte/wctomb.c b/libc-test/src/functionalext/supplement/multibyte/wctomb.c new file mode 100644 index 00000000..68904b99 --- /dev/null +++ b/libc-test/src/functionalext/supplement/multibyte/wctomb.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wctomb_0100 + * @tc.desc : Test the wctomb method to copy wide characters into a string + * @tc.level : Level 0 + */ +void wctomb_0100(void) +{ + char byte[256] = {0}; + int result = wctomb(byte, L'h'); + if (result != 1) { + t_error("%s wctomb get result is %d are not want 1\n", __func__, result); + } +} + +/** + * @tc.name : wctomb_0200 + * @tc.desc : Test the result of wctomb when the incoming wide character is the terminator + * @tc.level : Level 1 + */ +void wctomb_0200(void) +{ + char byte[256] = {0}; + int result = wctomb(byte, L'\0'); + if (result != 1) { + t_error("%s wctomb get result is %d are not want 1\n", __func__, result); + } +} + +/** + * @tc.name : wctomb_0300 + * @tc.desc : wctomb result when test string is NULL + * @tc.level : Level 2 + */ +void wctomb_0300(void) +{ + int result = wctomb(NULL, L'h'); + if (result != 0) { + t_error("%s wctomb get result is %d are not want 0\n", __func__, result); + } +} + +/** + * @tc.name : wctomb_0400 + * @tc.desc : wctomb result when test string is NULL and wide character is terminator + * @tc.level : Level 2 + */ +void wctomb_0400(void) +{ + int result = wctomb(NULL, L'\0'); + if (result != 0) { + t_error("%s wctomb get result is %d are not want 0\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + wctomb_0100(); + wctomb_0200(); + wctomb_0300(); + wctomb_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/BUILD.gn b/libc-test/src/functionalext/supplement/network/BUILD.gn new file mode 100644 index 00000000..2a3dbc0f --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_network.gni") + +foreach(s, functionalext_supplement_network_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/network" + } +} + +group("functionalext_supplement_network_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_network_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/network/__h_errno_location.c b/libc-test/src/functionalext/supplement/network/__h_errno_location.c new file mode 100644 index 00000000..857b4ed9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/__h_errno_location.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : __h_errno_location_0100 + * @tc.desc : Test the __h_errno_location function + * @tc.level : Level 0 + */ +void __h_errno_location_0100(void) +{ + int *result = __h_errno_location(); + if (*result != 0) { + t_error("%s __h_errno_location get result is %d are not want 0\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + __h_errno_location_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/accept4.c b/libc-test/src/functionalext/supplement/network/accept4.c new file mode 100644 index 00000000..25238c25 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/accept4.c @@ -0,0 +1,392 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int SUCCESS = 0; +#define BUF_SIZE (100) +#define PORT 2288 +#define WAIT() pthread_barrier_wait(&g_barrier) +static const char *g_localHost = "127.0.0.1"; +static pthread_barrier_t g_barrier; + +void *ServerTaskOne() +{ + int *ret = (int *)malloc(sizeof(int)); + int rets = -1; + int sListen = socket(AF_INET, SOCK_STREAM, 0); + if (sListen == -1) { + *ret = -1; + return ret; + } + int flag = 1; + rets = setsockopt(sListen, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int)); + if (rets != 0) { + printf("[server] setsockopt fail, rets: %d!\n", rets); + } + struct sockaddr_in srvAddr = {0}; + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PORT); + rets = bind(sListen, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + if (rets != 0) { + close(sListen); + *ret = -1; + return ret; + } + rets = listen(sListen, 2); + if (rets != 0) { + close(sListen); + *ret = -1; + return ret; + } + WAIT(); + struct sockaddr_in clnAddr = {0}; + socklen_t clnAddrLen = sizeof(clnAddr); + int sClient = -1; + sClient = accept4(sListen, (struct sockaddr *)&clnAddr, &clnAddrLen, 0); + EXPECT_NE("accept4_0100", sClient, -1); + close(sClient); + close(sListen); + return ret; +} + +void *ServerTaskTwo() +{ + int *ret = (int *)malloc(sizeof(int)); + int rets = -1; + int sListen = socket(AF_INET, SOCK_STREAM, 0); + if (sListen == -1) { + *ret = -1; + return ret; + } + int flag = 1; + rets = setsockopt(sListen, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int)); + if (rets != 0) { + printf("[server] setsockopt fail, rets: %d!\n", rets); + } + struct sockaddr_in srvAddr = {0}; + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PORT); + rets = bind(sListen, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + if (rets != 0) { + close(sListen); + *ret = -1; + return ret; + } + rets = listen(sListen, 2); + if (rets != 0) { + close(sListen); + *ret = -1; + return ret; + } + WAIT(); + struct sockaddr_in clnAddr = {0}; + socklen_t clnAddrLen = sizeof(clnAddr); + int sClient = -1; + sClient = accept4(sListen, (struct sockaddr *)&clnAddr, &clnAddrLen, SOCK_NONBLOCK); + EXPECT_NE("accept4_0200", sClient, -1); + close(sClient); + close(sListen); + return ret; +} + +void *ServerTaskThree() +{ + int *ret = (int *)malloc(sizeof(int)); + int rets = -1; + int sListen = socket(AF_INET, SOCK_STREAM, 0); + if (sListen == -1) { + *ret = -1; + return ret; + } + int flag = 1; + rets = setsockopt(sListen, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int)); + if (rets != 0) { + printf("[server] setsockopt fail, rets: %d!\n", rets); + } + struct sockaddr_in srvAddr = {0}; + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PORT); + rets = bind(sListen, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + if (rets != 0) { + close(sListen); + *ret = -1; + return ret; + } + rets = listen(sListen, 2); + if (rets != 0) { + close(sListen); + *ret = -1; + return ret; + } + WAIT(); + struct sockaddr_in clnAddr = {0}; + socklen_t clnAddrLen = sizeof(clnAddr); + int sClient = -1; + sClient = accept4(sListen, (struct sockaddr *)&clnAddr, &clnAddrLen, SOCK_CLOEXEC); + EXPECT_NE("accept4_0300", sClient, -1); + close(sClient); + close(sListen); + return ret; +} + +void *ServerTaskFive() +{ + int *ret = (int *)malloc(sizeof(int)); + int rets = -1; + int sListen = socket(AF_INET, SOCK_STREAM, 0); + if (sListen == -1) { + *ret = -1; + return ret; + } + int flag = 1; + rets = setsockopt(sListen, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int)); + if (rets != 0) { + printf("[server] setsockopt fail, rets: %d!\n", rets); + } + struct sockaddr_in srvAddr = {0}; + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PORT); + rets = bind(sListen, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + if (rets != 0) { + close(sListen); + *ret = -1; + return ret; + } + rets = listen(sListen, 2); + if (rets != 0) { + close(sListen); + *ret = -1; + return ret; + } + WAIT(); + struct sockaddr_in clnAddr = {0}; + socklen_t clnAddrLen = sizeof(clnAddr); + int sClient = -1; + sClient = accept4(sListen, 0, &clnAddrLen, SOCK_CLOEXEC); + EXPECT_NE("accept4_0500", sClient, -1); + close(sClient); + close(sListen); + return ret; +} + +void *ServerTaskSix() +{ + int *ret = (int *)malloc(sizeof(int)); + int rets = -1; + int sListen = socket(AF_INET, SOCK_STREAM, 0); + if (sListen == -1) { + *ret = -1; + } + int flag = 1; + rets = setsockopt(sListen, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int)); + if (rets != 0) { + printf("[server] setsockopt fail, rets: %d!\n", rets); + } + struct sockaddr_in srvAddr = {0}; + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PORT); + rets = bind(sListen, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + if (rets != 0) { + close(sListen); + *ret = -1; + } + rets = listen(sListen, 2); + if (rets != 0) { + close(sListen); + *ret = -1; + } + WAIT(); + struct sockaddr_in clnAddr = {0}; + socklen_t clnAddrLen = sizeof(clnAddr); + int sClient = 0; + sClient = accept4(sListen, (struct sockaddr *)&clnAddr, 0, 0); + EXPECT_EQ("accept4_0600", sClient, -1); + close(sClient); + close(sListen); + return ret; +} + +void *ClientTask() +{ + int clnFd = socket(AF_INET, SOCK_STREAM, 0); + WAIT(); + struct sockaddr_in srvAddr = {0}; + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PORT); + int ret = connect(clnFd, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + if (ret != 0) { + printf("connect failed\n"); + } + close(clnFd); + return NULL; +} + +/** + * @tc.name : accept4_0100 + * @tc.desc : Each parameter is valid, the flag parameter is 0, and the socket connection can be accepted. + * @tc.level : Level 0 + */ +void accept4_0100(void) +{ + pthread_t srv; + pthread_t cli; + int ret = pthread_barrier_init(&g_barrier, 0, 2); + EXPECT_EQ("accept4_0100", SUCCESS, ret); + ret = pthread_create(&srv, NULL, ServerTaskOne, NULL); + EXPECT_EQ("accept4_0100", SUCCESS, ret); + ret = pthread_create(&cli, NULL, ClientTask, NULL); + EXPECT_EQ("accept4_0100", SUCCESS, ret); + ret = pthread_join(cli, NULL); + EXPECT_EQ("accept4_0100", SUCCESS, ret); + ret = pthread_join(srv, NULL); + EXPECT_EQ("accept4_0100", SUCCESS, ret); + ret = pthread_barrier_destroy(&g_barrier); + EXPECT_EQ("accept4_0100", SUCCESS, ret); +} + +/** + * @tc.name : accept4_0200 + * @tc.desc : Each parameter is valid, the flag parameter is SOCK_NONBLOCK, which can accept socket connection. + * @tc.level : Level 1 + */ +void accept4_0200(void) +{ + pthread_t srv; + pthread_t cli; + int ret = pthread_barrier_init(&g_barrier, 0, 2); + EXPECT_EQ("accept4_0200", SUCCESS, ret); + ret = pthread_create(&srv, NULL, ServerTaskTwo, NULL); + EXPECT_EQ("accept4_0200", SUCCESS, ret); + ret = pthread_create(&cli, NULL, ClientTask, NULL); + EXPECT_EQ("accept4_0200", SUCCESS, ret); + ret = pthread_join(cli, NULL); + EXPECT_EQ("accept4_0200", SUCCESS, ret); + ret = pthread_join(srv, NULL); + EXPECT_EQ("accept4_0200", SUCCESS, ret); + ret = pthread_barrier_destroy(&g_barrier); + EXPECT_EQ("accept4_0200", SUCCESS, ret); +} + +/** + * @tc.name : accept4_0300 + * @tc.desc : Each parameter is valid, the flag parameter is SOCK_CLOEXEC, which can accept socket connection. + * @tc.level : Level 1 + */ +void accept4_0300(void) +{ + pthread_t srv; + pthread_t cli; + int ret = pthread_barrier_init(&g_barrier, 0, 2); + EXPECT_EQ("accept4_0300", SUCCESS, ret); + ret = pthread_create(&srv, NULL, ServerTaskThree, NULL); + EXPECT_EQ("accept4_0300", SUCCESS, ret); + ret = pthread_create(&cli, NULL, ClientTask, NULL); + EXPECT_EQ("accept4_0300", SUCCESS, ret); + ret = pthread_join(cli, NULL); + EXPECT_EQ("accept4_0300", SUCCESS, ret); + ret = pthread_join(srv, NULL); + EXPECT_EQ("accept4_0300", SUCCESS, ret); + ret = pthread_barrier_destroy(&g_barrier); + EXPECT_EQ("accept4_0300", SUCCESS, ret); +} + +/** + * @tc.name : accept4_0400 + * @tc.desc : The fd parameter is invalid, socket connection cannot be accepted. + * @tc.level : Level 2 + */ +void accept4_0400(void) +{ + struct sockaddr_in clnAddr = {0}; + socklen_t clnAddrLen = sizeof(clnAddr); + int sClient = 0; + sClient = accept4(0, (struct sockaddr *)&clnAddr, &clnAddrLen, 0); + EXPECT_EQ("accept4_0400", sClient, -1); +} + +/** + * @tc.name : accept4_0500 + * @tc.desc : The addr parameter is invalid, socket connection can be accepted. + * @tc.level : Level 1 + */ +void accept4_0500(void) +{ + pthread_t srv; + pthread_t cli; + int ret = pthread_barrier_init(&g_barrier, 0, 2); + EXPECT_EQ("accept4_0500", SUCCESS, ret); + ret = pthread_create(&srv, NULL, ServerTaskFive, NULL); + EXPECT_EQ("accept4_0500", SUCCESS, ret); + ret = pthread_create(&cli, NULL, ClientTask, NULL); + EXPECT_EQ("accept4_0500", SUCCESS, ret); + ret = pthread_join(cli, NULL); + EXPECT_EQ("accept4_0500", SUCCESS, ret); + ret = pthread_join(srv, NULL); + EXPECT_EQ("accept4_0500", SUCCESS, ret); + ret = pthread_barrier_destroy(&g_barrier); + EXPECT_EQ("accept4_0500", SUCCESS, ret); +} + +/** + * @tc.name : accept4_0600 + * @tc.desc : The len parameter is invalid, socket connection cannot be accepted. + * @tc.level : Level 2 + */ +void accept4_0600(void) +{ + pthread_t srv; + pthread_t cli; + int ret = pthread_barrier_init(&g_barrier, 0, 2); + EXPECT_EQ("accept4_0600", SUCCESS, ret); + ret = pthread_create(&srv, NULL, ServerTaskSix, NULL); + EXPECT_EQ("accept4_0600", SUCCESS, ret); + ret = pthread_create(&cli, NULL, ClientTask, NULL); + EXPECT_EQ("accept4_0600", SUCCESS, ret); + ret = pthread_join(cli, NULL); + EXPECT_EQ("accept4_0600", SUCCESS, ret); + ret = pthread_join(srv, NULL); + EXPECT_EQ("accept4_0600", SUCCESS, ret); + ret = pthread_barrier_destroy(&g_barrier); + EXPECT_EQ("accept4_0600", SUCCESS, ret); +} +int main() +{ + accept4_0100(); + accept4_0200(); + accept4_0300(); + accept4_0400(); + accept4_0500(); + accept4_0600(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/dn_comp.c b/libc-test/src/functionalext/supplement/network/dn_comp.c new file mode 100755 index 00000000..d6631db4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/dn_comp.c @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_SUCCESS = 1; +const int32_t COUNT_FAILED = -1; + +/** + * @tc.name : dn_comp_0100 + * @tc.desc : Verify domain name compression (all parameters are valid) + * @tc.level : Level 0 + */ +void dn_comp_0100(void) +{ + int result; + char name[1024] = "www.baidu.com"; + unsigned char buf[1024] = "\0"; + result = dn_comp(name, buf, 1024, NULL, NULL); + EXPECT_EQ("dn_comp_0100", result, 15); +} + +/** + * @tc.name : dn_comp_0200 + * @tc.desc : Verify that the domain name cannot be compressed (SRC parameter invalid, length 1) + * @tc.level : Level 1 + */ +void dn_comp_0200(void) +{ + int result; + char name[1024] = "."; + unsigned char buf[1024] = "\0"; + result = dn_comp(name, buf, 1024, NULL, NULL); + EXPECT_EQ("dn_comp_0200", result, COUNT_SUCCESS); +} + +/** + * @tc.name : dn_comp_0300 + * @tc.desc : Verify that the domain name cannot be compressed (SRC parameter invalid, length greater than 253) + * @tc.level : Level 2 + */ +void dn_comp_0300(void) +{ + int result; + char name[1024]; + for (int i = 0; i < 260; i++) + { + name[i] = 'w'; + } + unsigned char buf[1024] = "\0"; + result = dn_comp(name, buf, 1024, NULL, NULL); + EXPECT_EQ("dn_comp_0300", result, COUNT_FAILED); +} + +/** + * @tc.name : dn_comp_0400 + * @tc.desc : Verify that the domain name cannot be compressed (the space parameter is invalid, equal to 0) + * @tc.level : Level 2 + */ +void dn_comp_0400(void) +{ + int result; + char name[1024] = "www.baidu.com"; + unsigned char buf[1024] = "\0"; + result = dn_comp(name, buf, 0, NULL, NULL); + EXPECT_EQ("dn_comp_0400", result, COUNT_FAILED); +} + +/** + * @tc.name : dn_comp_0500 + * @tc.desc : Verify that the domain name cannot be compressed (space argument is invalid, less than 0) + * @tc.level : Level 2 + */ +void dn_comp_0500(void) +{ + int result; + char name[1024] = "www.baidu.com"; + unsigned char buf[1024] = "\0"; + result = dn_comp(name, buf, -1, NULL, NULL); + EXPECT_EQ("dn_comp_0500", result, COUNT_FAILED); +} + +/** + * @tc.name : dn_comp_0600 + * @tc.desc : Verify that the domain name cannot be compressed (space argument is invalid, equal to 1) + * @tc.level : Level 2 + */ +void dn_comp_0600(void) +{ + int result; + char name[1024] = "www.baidu.com"; + unsigned char buf[1024] = "\0"; + result = dn_comp(name, buf, 1, NULL, NULL); + EXPECT_EQ("dn_comp_0600", result, COUNT_FAILED); +} + +int main() +{ + dn_comp_0100(); + dn_comp_0200(); + dn_comp_0300(); + dn_comp_0400(); + dn_comp_0500(); + dn_comp_0600(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/dn_skipname.c b/libc-test/src/functionalext/supplement/network/dn_skipname.c new file mode 100755 index 00000000..b0a659e0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/dn_skipname.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : dn_skipname_0100 + * @tc.desc : Verify that the domain name can be compressed (parameters are valid) + * @tc.level : Level 0 + */ +void dn_skipname_0100(void) +{ + unsigned char s[10] = {0, 2, 34, 45, 75, 23, 12, 192, 87, 254}; + int result = dn_skipname(&s[0], &s[1]); + EXPECT_EQ("dn_skipname_0100", result, 1); +} + +/** + * @tc.name : dn_skipname_0200 + * @tc.desc : Verify that the domain name can be compressed (parameters are valid) + * @tc.level : Level 1 + */ +void dn_skipname_0200(void) +{ + unsigned char s[10] = {0, 2, 34, 45, 75, 23, 12, 192, 87, 254}; + int result = dn_skipname(&s[7], &s[9]); + EXPECT_EQ("dn_skipname_0200", result, 2); +} + +/** + * @tc.name : dn_skipname_0300 + * @tc.desc : Verify that the domain name cannot be compressed (s and end are equal) + * @tc.level : Level 2 + */ +void dn_skipname_0300(void) +{ + unsigned char s[10] = {0, 2, 2, 45, 75, 23, 12, 192, 87, 254}; + int result = dn_skipname(&s[1], &s[2]); + EXPECT_EQ("dn_skipname_0300", result, -1); +} + +TEST_FUN G_Fun_Array[] = { + dn_skipname_0100, + dn_skipname_0200, + dn_skipname_0300, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/freeifaddrs.c b/libc-test/src/functionalext/supplement/network/freeifaddrs.c new file mode 100644 index 00000000..de96c761 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/freeifaddrs.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : freeifaddrs_0100 + * @tc.desc : Verifies that the specified memory can be freed (parameter valid) + * @tc.level : Level 0 + */ +void freeifaddrs_0100(void) +{ + struct ifaddrs *ifaddr; + int ret = getifaddrs(&ifaddr); + ifaddr->ifa_next = NULL; + freeifaddrs(ifaddr); + ifaddr = NULL; + bool flag = false; + if (ifaddr == NULL) + { + flag = true; + } + EXPECT_TRUE("freeifaddrs_0100", flag); +} + +int main() +{ + freeifaddrs_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/gai_strerror.c b/libc-test/src/functionalext/supplement/network/gai_strerror.c new file mode 100755 index 00000000..fedc24f7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/gai_strerror.c @@ -0,0 +1,179 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/* + * @tc.name : gai_strerror_0100 + * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_BADFLAGS) + * @tc.level : Level 0 + */ +void gai_strerror_0100() +{ + const char *result = gai_strerror(EAI_BADFLAGS); + EXPECT_TRUE(gai_strerror_0100, strcmp(result, "Invalid flags\0") == 0); +} + +/* + * @tc.name : gai_strerror_0200 + * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_NONAME) + * @tc.level : Level 0 + */ +void gai_strerror_0200() +{ + const char *result = gai_strerror(EAI_NONAME); + EXPECT_TRUE(gai_strerror_0200, strcmp(result, "Name does not resolve\0") == 0); +} + +/* + * @tc.name : gai_strerror_0300 + * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_AGAIN) + * @tc.level : Level 0 + */ +void gai_strerror_0300() +{ + const char *result = gai_strerror(EAI_AGAIN); + EXPECT_TRUE(gai_strerror_0300, strcmp(result, "Try again\0") == 0); +} + +/* + * @tc.name : gai_strerror_0400 + * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_FAIL) + * @tc.level : Level 0 + */ +void gai_strerror_0400() +{ + const char *result = gai_strerror(EAI_FAIL); + EXPECT_TRUE(gai_strerror_0400, strcmp(result, "Non-recoverable error\0") == 0); +} + +/* + * @tc.name : gai_strerror_0500 + * @tc.desc : Verify that the corresponding error message can be returned (parameter is -5) + * @tc.level : Level 1 + */ +void gai_strerror_0500() +{ + const char *result = gai_strerror(-5); + EXPECT_TRUE(gai_strerror_0500, strcmp(result, "Unknown error\0") == 0); +} + +/* + * @tc.name : gai_strerror_0600 + * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_FAMILY) + * @tc.level : Level 0 + */ +void gai_strerror_0600() +{ + const char *result = gai_strerror(EAI_FAMILY); + EXPECT_TRUE(gai_strerror_0600, strcmp(result, "Unrecognized address family or invalid length\0") == 0); +} + +/* + * @tc.name : gai_strerror_0700 + * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_SOCKTYPE) + * @tc.level : Level 0 + */ +void gai_strerror_0700() +{ + const char *result = gai_strerror(EAI_SOCKTYPE); + EXPECT_TRUE(gai_strerror_0700, strcmp(result, "Unrecognized socket type\0") == 0); +} + +/* + * @tc.name : gai_strerror_0800 + * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_SERVICE) + * @tc.level : Level 0 + */ +void gai_strerror_0800() +{ + const char *result = gai_strerror(EAI_SERVICE); + EXPECT_TRUE(gai_strerror_0800, strcmp(result, "Unrecognized service\0") == 0); +} + +/* + * @tc.name : gai_strerror_0900 + * @tc.desc : Verify that the corresponding error message can be returned (parameter is -9) + * @tc.level : Level 1 + */ +void gai_strerror_0900() +{ + const char *result = gai_strerror(-9); + EXPECT_TRUE(gai_strerror_0900, strcmp(result, "Unknown error\0") == 0); +} + +/* + * @tc.name : gai_strerror_1000 + * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_MEMORY) + * @tc.level : Level 0 + */ +void gai_strerror_1000() +{ + const char *result = gai_strerror(EAI_MEMORY); + EXPECT_TRUE(gai_strerror_1000, strcmp(result, "Out of memory\0") == 0); +} + +/* + * @tc.name : gai_strerror_1100 + * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_SYSTEM) + * @tc.level : Level 0 + */ +void gai_strerror_1100() +{ + const char *result = gai_strerror(EAI_SYSTEM); + EXPECT_TRUE(gai_strerror_1100, strcmp(result, "System error\0") == 0); +} + +/* + * @tc.name : gai_strerror_1200 + * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_OVERFLOW) + * @tc.level : Level 0 + */ +void gai_strerror_1200() +{ + const char *result = gai_strerror(EAI_OVERFLOW); + EXPECT_TRUE(gai_strerror_1200, strcmp(result, "Overflow\0") == 0); +} + +/* + * @tc.name : gai_strerror_1300 + * @tc.desc : Verify that the corresponding error message can be returned (parameter is -13) + * @tc.level : Level 1 + */ +void gai_strerror_1300() +{ + const char *result = gai_strerror(-13); + EXPECT_TRUE(gai_strerror_1300, strcmp(result, "Unknown error\0") == 0); +} + +int main() +{ + gai_strerror_0100(); + gai_strerror_0200(); + gai_strerror_0300(); + gai_strerror_0400(); + gai_strerror_0500(); + gai_strerror_0600(); + gai_strerror_0700(); + gai_strerror_0800(); + gai_strerror_0900(); + gai_strerror_1000(); + gai_strerror_1100(); + gai_strerror_1200(); + gai_strerror_1300(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/getaddrinfo.c b/libc-test/src/functionalext/supplement/network/getaddrinfo.c new file mode 100644 index 00000000..3ef39c9b --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/getaddrinfo.c @@ -0,0 +1,361 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "functionalext.h" + +const int GETADDRINFO_RESULT = 0; +const int FLAGS_FIELD = -1; +const int SERVICE_UNKNOEN = -2; +const int FAMILY_NOTSUPPORTED = -6; +const int SOCKTYPE_NOTSUPPORTED = -8; + +/** + * @tc.name : getaddrinfo_0100 + * @tc.desc : Each parameter is valid, the ai_flags of hint is AI_PASSIVE, which can resolve the IP + * address of the host name. + * @tc.level : Level 0 + */ +void getaddrinfo_0100(void) +{ + int ret = -1; + int num = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_ALL; + hint.ai_family = AF_UNSPEC; + ret = getaddrinfo("127.0.0.1", NULL, &hint, &result); + EXPECT_EQ("getaddrinfo_0100", ret, GETADDRINFO_RESULT); + if (result->ai_addr != NULL) { + num = 1; + } else { + num = 2; + } + EXPECT_EQ("getaddrinfo_0100", num, 1); + freeaddrinfo(result); + result = NULL; +} + +/** + * @tc.name : getaddrinfo_0200 + * @tc.desc : Each parameter is valid and can resolve the IP address of the host name. + * @tc.level : Level 0 + */ +void getaddrinfo_0200(void) +{ + int ret = -1; + int num = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_ALL; + hint.ai_family = AF_UNSPEC; + ret = getaddrinfo("127.0.0.1", NULL, &hint, &result); + EXPECT_EQ("getaddrinfo_0200", ret, GETADDRINFO_RESULT); + if (result->ai_addr != NULL) { + num = 1; + } else { + num = 2; + } + EXPECT_EQ("getaddrinfo_0200", num, 1); + freeaddrinfo(result); + result = NULL; +} + +/** + * @tc.name : getaddrinfo_0300 + * @tc.desc : Each parameter is valid and can resolve the IP address of the host name + * (hint.ai_flags =AI_NUMERICHOST). + * @tc.level : Level 0 + */ +void getaddrinfo_0300(void) +{ + int ret = -1; + int num = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_NUMERICHOST; + hint.ai_family = AF_INET6; + char buf[] = "fe80::bed5:4695:6cac:bef8"; + ret = getaddrinfo(buf, NULL, &hint, &result); + EXPECT_EQ("getaddrinfo_0300", ret, GETADDRINFO_RESULT); + if (result->ai_addr != NULL) { + num = 1; + } else { + num = 2; + } + EXPECT_EQ("getaddrinfo_0300", num, 1); + freeaddrinfo(result); + result = NULL; +} + +/** + * @tc.name : getaddrinfo_0400 + * @tc.desc : Each parameter is valid and can resolve the IP address of the host name(hint =AI_V4MAPPED). + * @tc.level : Level 0 + */ +void getaddrinfo_0400(void) +{ + int ret = -1; + int num = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_V4MAPPED; + hint.ai_family = AF_INET6; + ret = getaddrinfo("127.0.0.1", NULL, &hint, &result); + EXPECT_EQ("getaddrinfo_0400", ret, GETADDRINFO_RESULT); + if (result->ai_addr != NULL) { + num = 1; + } else { + num = 2; + } + EXPECT_EQ("getaddrinfo_0400", num, 1); + freeaddrinfo(result); + result = NULL; +} + +/** + * @tc.name : getaddrinfo_0500 + * @tc.desc : Each parameter is valid and can resolve the IP address of the host name(hint =AI_V4MAPPED). + * @tc.level : Level 0 + */ +void getaddrinfo_0500(void) +{ + int ret = -1; + int num = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_ALL; + hint.ai_family = AF_UNSPEC; + ret = getaddrinfo("127.0.0.1", NULL, &hint, &result); + EXPECT_EQ("getaddrinfo_0500", ret, GETADDRINFO_RESULT); + if (result->ai_addr != NULL) { + num = 1; + } else { + num = 2; + } + EXPECT_EQ("getaddrinfo_0500", num, 1); + freeaddrinfo(result); + result = NULL; +} + +/** + * @tc.name : getaddrinfo_0600 + * @tc.desc : Each parameter is valid and can resolve the IP address of + * the host name(hint.ai_flags =AI_ADDRCONFIG). + * @tc.level : Level 0 + */ +void getaddrinfo_0600(void) +{ + int ret = -1; + int num = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_ADDRCONFIG; + hint.ai_family = AF_UNSPEC; + ret = getaddrinfo("127.0.0.1", NULL, &hint, &result); + EXPECT_EQ("getaddrinfo_0600", ret, GETADDRINFO_RESULT); + if (result->ai_addr != NULL) { + num = 1; + } else { + num = 2; + } + EXPECT_EQ("getaddrinfo_0600", num, 1); + freeaddrinfo(result); + result = NULL; +} + +/** + * @tc.name : getaddrinfo_0700 + * @tc.desc : Each parameter is valid and can resolve the IP address + * of the host name(hint.ai_flags =AI_NUMERICSERV). + * @tc.level : Level 1 + */ +void getaddrinfo_0700(void) +{ + int ret = -1; + int num = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_NUMERICSERV; + hint.ai_family = AF_UNSPEC; + ret = getaddrinfo("127.0.0.1", NULL, &hint, &result); + EXPECT_EQ("getaddrinfo_0700", ret, GETADDRINFO_RESULT); + if (result->ai_addr != NULL) { + num = 1; + } else { + num = 2; + } + EXPECT_EQ("getaddrinfo_0700", num, 1); + freeaddrinfo(result); + result = NULL; +} + +/** + * @tc.name : getaddrinfo_0800 + * @tc.desc : Each parameter is valid and can resolve the IP address of the host name(hint =NULL). + * @tc.level : Level 1 + */ +void getaddrinfo_0800(void) +{ + int ret = -1; + int num = -1; + struct addrinfo *result; + ret = getaddrinfo("127.0.0.1", NULL, NULL, &result); + EXPECT_EQ("getaddrinfo_0800", ret, GETADDRINFO_RESULT); + if (result->ai_addr != NULL) { + num = 1; + } else { + num = 2; + } + EXPECT_EQ("getaddrinfo_0800", num, 1); + freeaddrinfo(result); + result = NULL; +} + +/** + * @tc.name : getaddrinfo_0900 + * @tc.desc : Invalid parameter, Hint’s ai_flags is invalid, can not resolve the IP address of the host name. + * @tc.level : Level 2 + */ +void getaddrinfo_0900(void) +{ + int ret = -1; + struct addrinfo *result, hint; + hint.ai_flags = 0x4000; + hint.ai_family = AF_UNSPEC; + ret = getaddrinfo("127.0.0.1", NULL, &hint, &result); + EXPECT_EQ("getaddrinfo_0900", ret, FLAGS_FIELD); +} + +/** + * @tc.name : getaddrinfo_1000 + * @tc.desc : Invalid parameter, Hint’s ai_family is invalid, can not resolve the IP address of the host name. + * @tc.level : Level 2 + */ +void getaddrinfo_1000(void) +{ + int ret = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_ALL; + hint.ai_family = PF_AX25; + ret = getaddrinfo("127.0.0.1", NULL, &hint, &result); + EXPECT_EQ("getaddrinfo_1000", ret, FAMILY_NOTSUPPORTED); +} + +/** + * @tc.name : getaddrinfo_1100 + * @tc.desc : The parameters are invalid,hint ai_flags is AI_NUMERICHOST, + * host format is incorrect, can not resolve the host name Ip address. + * @tc.level : Level 2 + */ +void getaddrinfo_1100(void) +{ + int ret = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_NUMERICHOST; + hint.ai_family = AF_INET6; + char one[300] = "fe80::bed5:4695:6cac:bef8:4695:6cac:bef8:4695:bef8:4695:6cac:bef8:4695"; + char two[] = ":fe80::bed5:4695:6cac:bef8:4695:6cac:bef8:4695:bef8:4695:6cac:bef8:4695"; + char three[] = ":fe80::bed5:4695:6cac:bef8:4695:6cac:bef8:4695:bef8:4695:6cac:bef8:4695"; + char four[] = ":fe80::bed5:4695:6cac:bef8:4695:6cac:bef8:4695:bef8:4695:6cac:bef8:4695"; + strcat(one, two); + strcat(one, three); + strcat(one, four); + ret = getaddrinfo(one, NULL, &hint, &result); + EXPECT_EQ("getaddrinfo_1100", ret, SERVICE_UNKNOEN); +} + +/** + * @tc.name : getaddrinfo_1200 + * @tc.desc : The parameter is invalid, host is NULL, SERV is NULL, and the IP address of the + * host name can not be resolved. + * @tc.level : Level 2 + */ +void getaddrinfo_1200(void) +{ + int ret = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_NUMERICHOST; + hint.ai_family = AF_INET6; + ret = getaddrinfo(NULL, NULL, &hint, &result); + EXPECT_EQ("getaddrinfo_1200", ret, SERVICE_UNKNOEN); +} + +/** + * @tc.name : getaddrinfo_1300 + * @tc.desc : The parameter is invalid and the IP address of the host name can not be resolved. + * @tc.level : Level 2 + */ +void getaddrinfo_1300(void) +{ + int ret = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_CANONNAME; + hint.ai_family = AF_INET; + hint.ai_protocol = IPPROTO_UDP; + hint.ai_socktype = SOCK_STREAM; + ret = getaddrinfo("127.0.0.1", NULL, &hint, &result); + EXPECT_EQ("getaddrinfo_1300", ret, SOCKTYPE_NOTSUPPORTED); +} + +/** + * @tc.name : getaddrinfo_1400 + * @tc.desc : The parameter is invalid and the IP address of the host name can not be resolved. + * @tc.level : Level 2 + */ +void getaddrinfo_1400(void) +{ + int ret = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_CANONNAME; + hint.ai_family = AF_INET; + hint.ai_protocol = IPPROTO_TCP; + hint.ai_socktype = SOCK_DGRAM; + ret = getaddrinfo("127.0.0.1", NULL, &hint, &result); + EXPECT_EQ("getaddrinfo_1400", ret, SOCKTYPE_NOTSUPPORTED); +} + +/** + * @tc.name : getaddrinfo_1500 + * @tc.desc : The parameter is invalid and the IP address of the host name can not be resolved. + * @tc.level : Level 2 + */ +void getaddrinfo_1500(void) +{ + int ret = -1; + struct addrinfo *result, hint; + hint.ai_flags = AI_CANONNAME; + hint.ai_family = AF_INET; + hint.ai_socktype = SOCK_RAW; + ret = getaddrinfo("127.0.0.1", "2000", &hint, &result); + EXPECT_EQ("getaddrinfo_1500", ret, SOCKTYPE_NOTSUPPORTED); +} + +int main() +{ + getaddrinfo_0100(); + getaddrinfo_0200(); + getaddrinfo_0300(); + getaddrinfo_0400(); + getaddrinfo_0500(); + getaddrinfo_0600(); + getaddrinfo_0700(); + getaddrinfo_0800(); + getaddrinfo_0900(); + getaddrinfo_1000(); + getaddrinfo_1100(); + getaddrinfo_1200(); + getaddrinfo_1300(); + getaddrinfo_1400(); + getaddrinfo_1500(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/network/gethostent.c b/libc-test/src/functionalext/supplement/network/gethostent.c new file mode 100644 index 00000000..3fbf6c68 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/gethostent.c @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : gethostent_0100 + * @tc.desc : Able to get host information. + * @tc.level : Level 0 + */ +void gethostent_0100(void) +{ + struct hostent *host = NULL; + sethostent(1); + host = gethostent(); + EXPECT_EQ("gethostent_0100", host, 0); + endhostent(); +} + +int main() +{ + gethostent_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/getifaddrs.c b/libc-test/src/functionalext/supplement/network/getifaddrs.c new file mode 100644 index 00000000..b1677e1e --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/getifaddrs.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int SUCCESS = 0; + +/** + * @tc.name : getifaddrs_0100 + * @tc.desc : The parameter is valid, and the information of the local network interface can be obtained. + * @tc.level : Level 0 + */ +void getifaddrs_0100(void) +{ + struct ifaddrs *ifaddr; + int ret = getifaddrs(&ifaddr); + EXPECT_EQ("getifaddrs_0100", ret, SUCCESS); + freeifaddrs(ifaddr); + ifaddr = NULL; +} + +int main() +{ + getifaddrs_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/getnetent.c b/libc-test/src/functionalext/supplement/network/getnetent.c new file mode 100644 index 00000000..53747b3d --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/getnetent.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int SUCCESS = 0; + +/** + * @tc.name : getnetent_0100 + * @tc.desc : Successfully obtained network information. + * @tc.level : Level 0 + */ +void getnetent_0100(void) +{ + struct netent *ret; + ret = getnetent(); + EXPECT_EQ("getnetent_0100", ret, 0); + ret = NULL; +} + +int main() +{ + getnetent_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/getpeername.c b/libc-test/src/functionalext/supplement/network/getpeername.c new file mode 100755 index 00000000..48cca081 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/getpeername.c @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +#define PORT 2288 +static const char *g_localHost = "127.0.0.1"; +#define BUF_SIZE (100) +static pthread_barrier_t g_barrier; +#define WAIT() pthread_barrier_wait(&g_barrier) +typedef void (*TEST_FUN)(); +void *SampleServerTask() +{ + int *ret = (int *)malloc(sizeof(int)); + int rets = -1; + int sListen = socket(AF_INET, SOCK_STREAM, 0); + if (sListen == -1) { + *ret = -1; + return ret; + } + int flag = 1; + rets = setsockopt(sListen, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int)); + struct sockaddr_in srvAddr = {0}; + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PORT); + rets = bind(sListen, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + if (rets != 0) { + close(sListen); + *ret = -1; + return ret; + } + rets = listen(sListen, 2); + if (rets != 0) { + close(sListen); + *ret = -1; + return ret; + } + WAIT(); + struct sockaddr_in clnAddr = {0}; + socklen_t clnAddrLen = sizeof(clnAddr); + int sClient = accept(sListen, (struct sockaddr *)&clnAddr, &clnAddrLen); + struct sockaddr addr = {0}; + socklen_t addrLen = sizeof(addr); + rets = getpeername(sClient, &addr, &addrLen); + static char recordAddr[BUF_SIZE + 1] = {0}; + memset(recordAddr, '\0', BUF_SIZE); + strcpy(recordAddr, inet_ntoa(((struct sockaddr_in *)&addr)->sin_addr)); + EXPECT_STREQ("getpeername_0100", g_localHost, recordAddr); + EXPECT_EQ("getpeername_0100", 0, rets); + close(sClient); + close(sListen); + return ret; +} + +void *SampleClientTask() +{ + int clnFd = socket(AF_INET, SOCK_STREAM, 0); + WAIT(); + struct sockaddr_in srvAddr = {0}; + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PORT); + int ret = connect(clnFd, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + EXPECT_EQ("getpeername_0100", 0, ret); + close(clnFd); + return NULL; +} + +/* + * @tc.name : getpeername_0100 + * @tc.desc : Get the address associated with the socket + * @tc.level : Level 0 + */ +void getpeername_0100() +{ + pthread_t srv; + pthread_t cli; + int ret = pthread_barrier_init(&g_barrier, 0, 2); + EXPECT_EQ("getpeername_0100", 0, ret); + ret = pthread_create(&srv, NULL, SampleServerTask, NULL); + EXPECT_EQ("getpeername_0100", 0, ret); + ret = pthread_create(&cli, NULL, SampleClientTask, NULL); + EXPECT_EQ("getpeername_0100", 0, ret); + ret = pthread_join(cli, NULL); + EXPECT_EQ("getpeername_0100", 0, ret); + ret = pthread_join(srv, NULL); + EXPECT_EQ("getpeername_0100", 0, ret); + ret = pthread_barrier_destroy(&g_barrier); + EXPECT_EQ("getpeername_0100", 0, ret); +} + +TEST_FUN G_Fun_Array[] = {getpeername_0100}; +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/getservbyname.c b/libc-test/src/functionalext/supplement/network/getservbyname.c new file mode 100755 index 00000000..b07188b7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/getservbyname.c @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : getservbyname_0100 + * @tc.desc : Get service entry + * @tc.level : Level 0 + */ +void getservbyname_0100(void) +{ + struct servent *se = getservbyname("smtp", "tcp"); + if (se) { + EXPECT_STREQ("getservbyname_0100", se->s_proto, "tcp"); + } + + se = getservbyname("echo", "udp"); + if (se) { + EXPECT_STREQ("getservbyname_0100", se->s_proto, "udp"); + } +} + +/** + * @tc.name : getservbyname_0200 + * @tc.desc : Get the service information of the specified port + * @tc.level : Level 0 + */ +void getservbyname_0200(void) +{ + struct servent *se = getservbyname("name", "proto"); + EXPECT_PTREQ("getservbyname_0200", se, NULL); +} + +int main(void) +{ + getservbyname_0100(); + getservbyname_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/getservbyport.c b/libc-test/src/functionalext/supplement/network/getservbyport.c new file mode 100755 index 00000000..a87b5050 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/getservbyport.c @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_GET_SEVERBY_TCP_PORT 25 +#define TEST_GET_SEVERBY_UDP_PORT 7 +/** + * @tc.name : getservbyport_0100 + * @tc.desc : Get the service information of the specified port + * @tc.level : Level 0 + */ +void getservbyport_0100(void) +{ + struct servent *se = getservbyport(htons(TEST_GET_SEVERBY_TCP_PORT), NULL); + if (se) { + EXPECT_EQ("getservbyport_0100", ntohs(se->s_port), TEST_GET_SEVERBY_TCP_PORT); + EXPECT_STREQ("getservbyport_0100", se->s_proto, "tcp"); + } + + se = getservbyport(htons(TEST_GET_SEVERBY_TCP_PORT), "tcp"); + if (se) { + EXPECT_EQ("getservbyport_0100", ntohs(se->s_port), TEST_GET_SEVERBY_TCP_PORT); + EXPECT_STREQ("getservbyport_0100", se->s_proto, "tcp"); + } + + se = getservbyport(htons(TEST_GET_SEVERBY_UDP_PORT), "udp"); + if (se) { + EXPECT_EQ("getservbyport_0100", ntohs(se->s_port), TEST_GET_SEVERBY_UDP_PORT); + EXPECT_STREQ("getservbyport_0100", se->s_proto, "udp"); + } +} + +int main(void) +{ + getservbyport_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/getsockopt.c b/libc-test/src/functionalext/supplement/network/getsockopt.c new file mode 100644 index 00000000..073f95f0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/getsockopt.c @@ -0,0 +1,406 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" +#define IPPROTO_IP 0 +#define IP_HDRINCL 3 +#define IP_TTL 2 +#define TCP_MAXSEG 2 +#define TCP_NODELAY 1 +#define IP_TOS 1 +#define IP_OPTIONS 4 + +/** + * @tc.name : getsockopt_0100 + * @tc.desc : SOL_SOCKET,SO_DEBUG + * @tc.level : Level 0 + */ +void getsockopt_0100(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_DEBUG, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0100", content, 0); +} + +/** + * @tc.name : getsockopt_0200 + * @tc.desc : SOL_SOCKET,SO_REUSEADDR + * @tc.level : Level 0 + */ +void getsockopt_0200(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0200", content, 0); +} + +/** + * @tc.name : getsockopt_0300 + * @tc.desc : SOL_SOCKET,SO_TYPE + * @tc.level : Level 0 + */ +void getsockopt_0300(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_TYPE, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0300", content, 0); +} + +/** + * @tc.name : getsockopt_0400 + * @tc.desc : SOL_SOCKET,SO_ERROR + * @tc.level : Level 0 + */ +void getsockopt_0400(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0400", content, 0); +} + +/** + * @tc.name : getsockopt_0500 + * @tc.desc : SOL_SOCKET,SO_DONTROUTE + * @tc.level : Level 0 + */ +void getsockopt_0500(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_DONTROUTE, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0500", content, 0); +} + +/** + * @tc.name : getsockopt_0600 + * @tc.desc : SOL_SOCKET,SO_BROADCAST + * @tc.level : Level 0 + */ +void getsockopt_0600(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0600", content, 0); +} + +/** + * @tc.name : getsockopt_0700 + * @tc.desc : SOL_SOCKET,SO_SNDBUF + * @tc.level : Level 0 + */ +void getsockopt_0700(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0700", content, 0); +} + +/** + * @tc.name : getsockopt_0800 + * @tc.desc : SOL_SOCKET,SO_RCVBUF + * @tc.level : Level 0 + */ +void getsockopt_0800(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0800", content, 0); +} + +/** + * @tc.name : getsockopt_0900 + * @tc.desc : SOL_SOCKET,SO_KEEPALIVE + * @tc.level : Level 0 + */ +void getsockopt_0900(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0900", content, 0); +} + +/** + * @tc.name : getsockopt_1000 + * @tc.desc : SOL_SOCKET,SO_OOBINLINE + * @tc.level : Level 0 + */ +void getsockopt_1000(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_OOBINLINE, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1000", content, 0); +} + +/** + * @tc.name : getsockopt_1100 + * @tc.desc : SOL_SOCKET,SO_LINGER + * @tc.level : Level 0 + */ +void getsockopt_1100(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_LINGER, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1100", content, 0); +} + +/** + * @tc.name : getsockopt_1200 + * @tc.desc : SOL_SOCKET,SO_RCVLOWAT + * @tc.level : Level 0 + */ +void getsockopt_1200(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_RCVLOWAT, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1200", content, 0); +} + +/** + * @tc.name : getsockopt_1300 + * @tc.desc : SOL_SOCKET,SO_SNDLOWAT + * @tc.level : Level 0 + */ +void getsockopt_1300(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_SNDLOWAT, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1300", content, 0); +} + +/** + * @tc.name : getsockopt_1400 + * @tc.desc : SOL_SOCKET,O_RCVTIMEO + * @tc.level : Level 1 + */ +void getsockopt_1400(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1400", content, 0); +} + +/** + * @tc.name : getsockopt_1500 + * @tc.desc : SOL_SOCKET,SO_SNDTIMEO + * @tc.level : Level 1 + */ +void getsockopt_1500(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1500", content, 0); +} + +/** + * @tc.name : getsockopt_1600 + * @tc.desc : SOL_SOCKET,SO_TIMESTAMP + * @tc.level : Level 1 + */ +void getsockopt_1600(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_TIMESTAMP, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1600", content, 0); +} + +/** + * @tc.name : getsockopt_1700 + * @tc.desc : SOL_SOCKET,SO_TIMESTAMPNS + * @tc.level : Level 1 + */ +void getsockopt_1700(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_TIMESTAMPNS, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1700", content, 0); +} + +/** + * @tc.name : getsockopt_1800 + * @tc.desc : IPPROTO_IP,IP_HDRINCL + * @tc.level : Level 1 + */ +void getsockopt_1800(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1800", content, 0); +} + +/** + * @tc.name : getsockopt_1900 + * @tc.desc : IPPROTO_IP,IP_OPTIONS + * @tc.level : Level 1 + */ +void getsockopt_1900(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, IPPROTO_IP, IP_OPTIONS, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1900", content, 0); +} + +/** + * @tc.name : getsockopt_2000 + * @tc.desc : IPPROTO_IP,IP_TOS + * @tc.level : Level 1 + */ +void getsockopt_2000(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, IPPROTO_IP, IP_TOS, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_2000", content, 0); +} + +/** + * @tc.name : getsockopt_2100 + * @tc.desc : IPPROTO_IP,IP_TTL + * @tc.level : Level 1 + */ +void getsockopt_2100(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, IPPROTO_IP, IP_TTL, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_2100", content, 0); +} + +/** + * @tc.name : getsockopt_2200 + * @tc.desc : IPPROTO_IP,TCP_MAXSEGs + * @tc.level : Level 1 + */ +void getsockopt_2200(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, IPPROTO_IP, TCP_MAXSEG, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_2200", content, 0); +} + +/** + * @tc.name : getsockopt_2300 + * @tc.desc : IPPROTO_IP,TCP_NODELAY + * @tc.level : Level 1 + */ +void getsockopt_2300(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, IPPROTO_IP, TCP_NODELAY, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_2200", content, 0); +} + +/** + * @tc.name : getsockopt_2400 + * @tc.desc : SOL_SOCKET,SO_RCVBUF + * @tc.level : Level 2 + */ +void getsockopt_2400(void) +{ + int optval; + int optlen = 0; + int content = getsockopt(0, SOL_SOCKET, SO_RCVBUF, &optval, (socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_2400", content, -1); +} + +/** + * @tc.name : getsockopt_2500 + * @tc.desc : SOL_SOCKET,SO_DEBUG NULL + * @tc.level : Level 2 + */ +void getsockopt_2500(void) +{ + int optval; + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + int content = getsockopt(sockfd, SOL_SOCKET, SO_DEBUG, &optval, NULL); + EXPECT_EQ("getsockopt_2500", content, -1); +} + +int main(void) +{ + getsockopt_0100(); + getsockopt_0200(); + getsockopt_0300(); + getsockopt_0400(); + getsockopt_0500(); + getsockopt_0600(); + getsockopt_0700(); + getsockopt_0800(); + getsockopt_0900(); + getsockopt_1000(); + getsockopt_1100(); + getsockopt_1200(); + getsockopt_1300(); + getsockopt_1400(); + getsockopt_1500(); + getsockopt_1600(); + getsockopt_1700(); + getsockopt_1800(); + getsockopt_1900(); + getsockopt_2000(); + getsockopt_2100(); + getsockopt_2200(); + getsockopt_2300(); + getsockopt_2400(); + getsockopt_2500(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/network/hstrerror.c b/libc-test/src/functionalext/supplement/network/hstrerror.c new file mode 100755 index 00000000..e1d0ca63 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/hstrerror.c @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_MSG_COUNT 5 + +/** + * @tc.name : hstrerror_0100 + * @tc.desc : Get error information from error code + * @tc.level : Level 0 + */ +void hstrerror_0100(void) +{ + const char *msg[TEST_MSG_COUNT] = { + "Unknown error", "Host not found", "Try again", "Non-recoverable error", "Address not available"}; + + int i; + for (i = 0; i < TEST_MSG_COUNT; i++) { + const char *ret = hstrerror(i); + EXPECT_PTRNE("hstrerror_0100", ret, NULL); + if (ret) { + EXPECT_STREQ("hstrerror_0100", ret, msg[i]); + } + } +} + +int main(void) +{ + hstrerror_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/htonl.c b/libc-test/src/functionalext/supplement/network/htonl.c new file mode 100644 index 00000000..fb5af03a --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/htonl.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const uint32_t IP = 0x7f000001; + +/** + * @tc.name : htonl_0100 + * @tc.desc : Verify htonl process success + * @tc.level : Level 0 + */ +void htonl_0100(void) +{ + EXPECT_EQ("htonl_0100", htonl(IP), inet_addr("127.0.0.1")); +} + +int main(void) +{ + htonl_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/network/htons.c b/libc-test/src/functionalext/supplement/network/htons.c new file mode 100644 index 00000000..d34b6388 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/htons.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +static const uint16_t LE = 0x1234; +static const uint16_t BE = 0x3412; + +/** + * @tc.name : htons_0100 + * @tc.desc : Verify htons process success. + * @tc.level : Level 0 + */ +void htons_0100(void) +{ + EXPECT_EQ("htonls_0100", BE, htons(LE)); +} + +int main(void) +{ + htons_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/network/if_indextoname.c b/libc-test/src/functionalext/supplement/network/if_indextoname.c new file mode 100644 index 00000000..481e8693 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/if_indextoname.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : if_indextoname_0100 + * @tc.desc : Get network interface by index + * @tc.level : Level 0 + */ +void if_indextoname_0100(void) +{ + int saved_errno = errno; + char if_name[IFNAMSIZ] = {'\0'}; + unsigned int if_index = (unsigned int)atoi("1"); + + char *name = if_indextoname(if_index, if_name); + if (name == NULL && errno == ENXIO) { + t_error("%s if_indextoname get name is NULL", __func__); + } +} + +int main(int argc, char *argv[]) +{ + if_indextoname_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/if_nameindex.c b/libc-test/src/functionalext/supplement/network/if_nameindex.c new file mode 100644 index 00000000..5800b736 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/if_nameindex.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : if_nameindex_0100 + * @tc.desc : Verify if_nameindex process success + * @tc.level : Level 0 + */ +void if_nameindex_0100(void) +{ + struct if_nameindex *ifni = if_nameindex(); + EXPECT_PTRNE("if_nameindex_0100", ifni, NULL); + if_freenameindex(ifni); +} + +int main(void) +{ + if_nameindex_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/network/if_nametoindex.c b/libc-test/src/functionalext/supplement/network/if_nametoindex.c new file mode 100644 index 00000000..fa4764f7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/if_nametoindex.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : if_nametoindex_0100 + * @tc.desc : Get index by network interface name + * @tc.level : Level 0 + */ +void if_nametoindex_0100(void) +{ + int saved_errno = errno; + char if_name[IFNAMSIZ] = {'\0'}; + unsigned int if_index = (unsigned int)atoi("1"); + + char *name = if_indextoname(if_index, if_name); + if (name == NULL && errno == ENXIO) { + t_error("%s if_indextoname get name is NULL", __func__); + } + unsigned int result = if_nametoindex(name); + if (result != 1) { + t_error("%s if_nametoindex by name :'%s' get result is %d are not want 1\n", __func__, name, result); + } +} + +int main(int argc, char *argv[]) +{ + if_nametoindex_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/inet_addr.c b/libc-test/src/functionalext/supplement/network/inet_addr.c new file mode 100755 index 00000000..9ad5bb6a --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/inet_addr.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : inet_addr_0100 + * @tc.desc : The parameter is valid and converts an IP address string into a network binary number + * @tc.level : Level 0 + */ +void inet_addr_0100() +{ + char buff[] = "127.0.0.1"; + int result; + result = inet_addr(buff); + EXPECT_NE("inet_addr_0100", result, INADDR_NONE); +} + +/** + * @tc.name : inet_addr_0200 + * @tc.desc : The p argument is invalid and has a negative number. + * An IP address string cannot be converted to a network binary number + * @tc.level : Level 2 + */ +void inet_addr_0200() +{ + char buff[] = "-127.0.0.1"; + int result; + result = inet_addr(buff); + EXPECT_EQ("inet_addr_0200", result, INADDR_NONE); +} + +/** + * @tc.name : inet_addr_0300 + * @tc.desc : The p argument is invalid. A number greater than 255 exists. + * An IP address string cannot be converted to a network binary number + * @tc.level : Level 2 + */ +void inet_addr_0300() +{ + char buff[] = "127.0.256.1"; + int result; + result = inet_addr(buff); + EXPECT_EQ("inet_addr_0300", result, INADDR_NONE); +} + +TEST_FUN G_Fun_Array[] = { + inet_addr_0100, + inet_addr_0200, + inet_addr_0300, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/inet_aton.c b/libc-test/src/functionalext/supplement/network/inet_aton.c new file mode 100755 index 00000000..5be54fa1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/inet_aton.c @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int COUNT_ZERO = 0; +const int COUNT_ONE = 1; + +/** + * @tc.name : inet_aton_0100 + * @tc.desc : Verify converting an IP address string to a network binary number (parameter valid) + * @tc.level : Level 0 + */ +void inet_aton_0100() +{ + bool flag = false; + char ip4test[] = "127.0.0.1"; + struct in_addr sin_addr; + int result; + result = inet_aton(ip4test, &sin_addr); + if (sin_addr.s_addr == 16777343) { + flag = true; + } + EXPECT_TRUE("inet_aton_0100", flag); + EXPECT_EQ("inet_aton_0100", result, COUNT_ONE); +} + +/** + * @tc.name : inet_aton_0200 + * @tc.desc : Validation cannot convert an IP address string to a network binary number + * (the s0 argument is invalid and has a negative number) + * @tc.level : Level 2 + */ +void inet_aton_0200() +{ + char ip4test[] = "-127.0.0.1"; + struct in_addr sin_addr; + int result; + result = inet_aton(ip4test, &sin_addr); + EXPECT_EQ("inet_aton_0200", result, COUNT_ZERO); +} + +/** + * @tc.name : inet_aton_0300 + * @tc.desc : Validation cannot convert an IP address string to a network binary number + * (s0 argument invalid, number greater than 255 exists) + * @tc.level : Level 2 + */ +void inet_aton_0300() +{ + char ip4test[] = "127.0.256.1"; + struct in_addr sin_addr; + int result; + result = inet_aton(ip4test, &sin_addr); + EXPECT_EQ("inet_aton_0300", result, COUNT_ZERO); +} + +/** + * @tc.name : inet_aton_0400 + * @tc.desc : Validation cannot convert an IP address string to a network binary number + * (the s0 argument is invalid, the format is not correct) + * @tc.level : Level 2 + */ +void inet_aton_0400() +{ + char ip4test[] = "127.1.2.3.4"; + struct in_addr sin_addr; + int result; + result = inet_aton(ip4test, &sin_addr); + EXPECT_EQ("inet_aton_0400", result, COUNT_ZERO); +} + +/** + * @tc.name : inet_aton_0500 + * @tc.desc : Validation cannot convert an IP address string to a network binary number + * (the s0 argument is invalid and contains characters) + * @tc.level : Level 2 + */ +void inet_aton_0500() +{ + char ip4test[] = "127.0.w.1"; + struct in_addr sin_addr; + int result; + result = inet_aton(ip4test, &sin_addr); + EXPECT_EQ("inet_aton_0500", result, COUNT_ZERO); +} + +TEST_FUN G_Fun_Array[] = { + inet_aton_0100, + inet_aton_0200, + inet_aton_0300, + inet_aton_0400, + inet_aton_0500, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/inet_lnaof.c b/libc-test/src/functionalext/supplement/network/inet_lnaof.c new file mode 100644 index 00000000..193b4383 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/inet_lnaof.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const uint32_t HOST = 0x00000001; +const uint32_t IP = 0x7f000001; + +/** + * @tc.name : inet_lnaof_0100 + * @tc.desc : Verify inet_lnaofof process success + * @tc.level : Level 0 + */ +void inet_lnaof_0100(void) +{ + struct in_addr a = {htonl(IP)}; + EXPECT_EQ("inet_netof_0100", inet_lnaof(a), HOST); +} + +int main(void) +{ + inet_lnaof_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/network/inet_makeaddr.c b/libc-test/src/functionalext/supplement/network/inet_makeaddr.c new file mode 100644 index 00000000..754bb4b7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/inet_makeaddr.c @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const uint32_t NET = 0x0000007f; +const uint32_t HOST = 0x00000001; +const uint32_t IP = 0x7f000001; + +/** + * @tc.name : inet_makeaddr_0100 + * @tc.desc : Verify inet_makeaddr process success + * @tc.level : Level 0 + */ +void inet_makeaddr_0100(void) +{ + struct in_addr a = inet_makeaddr(NET, HOST); + EXPECT_EQ("inet_makeaddr_0100", htonl(IP), a.s_addr); +} + +int main(void) +{ + inet_makeaddr_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/network/inet_netof.c b/libc-test/src/functionalext/supplement/network/inet_netof.c new file mode 100644 index 00000000..78039d88 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/inet_netof.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const uint32_t NET = 0x0000007f; +const uint32_t IP = 0x7f000001; + +/** + * @tc.name : inet_netof_0100 + * @tc.desc : Verify inet_netof process success + * @tc.level : Level 0 + */ +void inet_netof_0100(void) +{ + struct in_addr a = {htonl(IP)}; + EXPECT_EQ("inet_netof_0100", inet_netof(a), NET); +} + +int main(void) +{ + inet_netof_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/network/inet_network.c b/libc-test/src/functionalext/supplement/network/inet_network.c new file mode 100644 index 00000000..9ce382c4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/inet_network.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const uint32_t IP = 0x7f000001; + +/** + * @tc.name : inet_network_0100 + * @tc.desc : Verify inet_network process success + * @tc.level : Level 0 + */ +void inet_network_0100(void) +{ + const char *addr = "127.0.0.1"; + EXPECT_EQ("inet_network", inet_network(addr), IP); +} + +int main(void) +{ + inet_network_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/network/inet_ntoa.c b/libc-test/src/functionalext/supplement/network/inet_ntoa.c new file mode 100755 index 00000000..8399f4d5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/inet_ntoa.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : inet_ntoa_0100 + * @tc.desc : Validation converts a network binary number to an IP address string + * @tc.level : Level 0 + */ +void inet_ntoa_0100() +{ + char buff[] = "127.0.0.1"; + struct in_addr in; + char *result; + inet_aton(buff, &in); + result = inet_ntoa(in); + EXPECT_STREQ("inet_ntoa_0100", result, buff); +} + +/** + * @tc.name : inet_ntoa_0200 + * @tc.desc : Validation cannot convert a network binary number to an IP address string + * (the in argument is invalid) + * @tc.level : Level 2 + */ +void inet_ntoa_0200() +{ + struct in_addr in; + in.s_addr = 0; + char *result; + result = inet_ntoa(in); + EXPECT_STREQ("inet_ntoa_0200", result, "0.0.0.0"); +} + +TEST_FUN G_Fun_Array[] = { + inet_ntoa_0100, + inet_ntoa_0200, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/inet_ntop.c b/libc-test/src/functionalext/supplement/network/inet_ntop.c new file mode 100755 index 00000000..3af4e20b --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/inet_ntop.c @@ -0,0 +1,138 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/* + * @tc.name : inet_ntop_0100 + * @tc.desc : Verify that the data format is converted to IP address format (the address cluster is AF_INET). + * @tc.level : Level 0 + */ +void inet_ntop_0100(void) +{ + char ip4test[] = "10.10.0.1"; + struct in_addr sin_addr; + inet_pton(AF_INET, ip4test, &sin_addr); + const char *ptr = inet_ntop(AF_INET, &sin_addr, ip4test, sizeof(ip4test)); + EXPECT_EQ("inet_ntop_0100", ptr, ip4test); +} + +/* + * @tc.name : inet_ntop_0200 + * @tc.desc : Verify that the data format is converted to the IP address format + * (the address cluster is AF_INET6, and the metadata is colon and hexadecimal notation) + * @tc.level : Level 0 + */ +void inet_ntop_0200(void) +{ + char ip6test[] = "A157:CD01:3579:1526:DBAC:EF21:4356:7879"; + struct in_addr sin_addr; + inet_pton(AF_INET6, ip6test, &sin_addr); + const char *ptr = inet_ntop(AF_INET6, &sin_addr, ip6test, sizeof(ip6test)); + EXPECT_EQ("inet_ntop_0200", ptr, ip6test); +} + +/* + * @tc.name : inet_ntop_0300 + * @tc.desc : Verify data format is converted to IP address format + * (address cluster is AF_INET6, metadata is 0-bit compressed notation) + * @tc.level : Level 0 + */ +void inet_ntop_0300(void) +{ + char ip6test[] = "fe80::bed5:4695:6cac:bef8"; + struct in_addr sin_addr; + inet_pton(AF_INET6, ip6test, &sin_addr); + const char *ptr = inet_ntop(AF_INET6, &sin_addr, ip6test, sizeof(ip6test)); + EXPECT_EQ("inet_ntop_0300", ptr, ip6test); +} + +/* + * @tc.name : inet_ntop_0400 + * @tc.desc : Verify that the data format is converted to IP address format + * (the address cluster is AF_INET6, and the metadata is the embedded Ipv address notation) + * @tc.level : Level 0 + */ +void inet_ntop_0400(void) +{ + char ip6test[] = "::10.10.0.1"; + struct in_addr sin_addr; + inet_pton(AF_INET6, ip6test, &sin_addr); + const char *ptr = inet_ntop(AF_INET6, &sin_addr, ip6test, sizeof(ip6test)); + EXPECT_EQ("inet_ntop_0400", ptr, ip6test); +} + +/* + * @tc.name : inet_ntop_0500 + * @tc.desc : Verify that the data format is converted to IP address format (the address cluster is AF_UNIX) + * @tc.level : Level 2 + */ +void inet_ntop_0500(void) +{ + bool flag = false; + char ip4test[] = "10.10.0.1"; + struct in_addr sin_addr; + inet_pton(AF_UNIX, ip4test, &sin_addr); + const char *ptr = inet_ntop(AF_UNIX, &sin_addr, ip4test, sizeof(ip4test)); + if (ptr == NULL) { + flag = true; + } + EXPECT_TRUE("inet_ntop_0500", flag); +} + +/* + * @tc.name : inet_ntop_0600 + * @tc.desc : Verify that the data format is converted to IP address format (the address cluster is AF_INET6) + * @tc.level : Level 2 + */ +void inet_ntop_0600(void) +{ + bool flag = false; + char ip6test[] = "10.10.0.1"; + struct in_addr sin_addr; + inet_pton(AF_INET6, ip6test, &sin_addr); + const char *ptr = inet_ntop(AF_INET6, &sin_addr, ip6test, sizeof(ip6test)); + if (ptr == NULL) { + flag = true; + } + EXPECT_TRUE("inet_ntop_0500", flag); +} + +TEST_FUN G_Fun_Array[] = { + inet_ntop_0100, + inet_ntop_0200, + inet_ntop_0300, + inet_ntop_0400, + inet_ntop_0500, + inet_ntop_0600, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/listen.c b/libc-test/src/functionalext/supplement/network/listen.c new file mode 100644 index 00000000..2d7b63ab --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/listen.c @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : listen_0100 + * @tc.desc : The parameters are valid and can listen for client connections. + * @tc.level : Level 0 + */ +void listen_0100(void) +{ + int fd = -1; + fd = socket(AF_INET, SOCK_STREAM, 0); + int ret = listen(fd, 3); + EXPECT_EQ("listen_0100", ret, 0); +} + +int main() +{ + listen_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/ns_parse.c b/libc-test/src/functionalext/supplement/network/ns_parse.c new file mode 100755 index 00000000..9082ed8b --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/ns_parse.c @@ -0,0 +1,350 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +#define TEST_MSG_SIZE 8 +#define TEST_DNS_HEAD 12 +#define TEST_SHIFT 8 +#define TEST_INDEX_2 2 +#define TEST_INDEX_3 3 +#define TEST_INDEX_5 5 +#define TEST_SKIP_SIZE 4 +#define TEST_DATA_LEN 10 + +struct test_skiprr_data { + int sect; + int result; +}; + +static unsigned char msg[] = "\x71\x79\x81\x80\x00\x01" + "\x00\x02\x00\x04\x00\x04\x03\x77\x77\x77\x03\x61\x62\x63\x03\x63" + "\x6f\x6d\x00\x00\x01\x00\x01\xc0\x0c\x00\x05\x00\x01\x00\x00\x02" + "\xe8\x00\x02\xc0\x10\xc0\x10\x00\x01\x00\x01\x00\x00\x02\xe9\x00" + "\x04\x0a\xb5\x84\xfa\xc0\x10\x00\x02\x00\x01\x00\x00\xda\xeb\x00" + "\x0d\x06\x73\x65\x6e\x73\x30\x31\x03\x64\x69\x67\xc0\x14\xc0\x10" + "\x00\x02\x00\x01\x00\x00\xda\xeb\x00\x09\x06\x73\x65\x6e\x73\x30" + "\x32\xc0\x4e\xc0\x10\x00\x02\x00\x01\x00\x00\xda\xeb\x00\x09\x06" + "\x6f\x72\x6e\x73\x30\x31\xc0\x4e\xc0\x10\x00\x02\x00\x01\x00\x00" + "\xda\xeb\x00\x09\x06\x6f\x72\x6e\x73\x30\x32\xc0\x4e\xc0\x75\x00" + "\x01\x00\x01\x00\x00\x7a\x36\x00\x04\x0a\xbb\xbd\x2c\xc0\x8a\x00" + "\x01\x00\x01\x00\x00\x1b\x96\x00\x04\x0a\xbb\xbe\x2c\xc0\x47\x00" + "\x01\x00\x01\x00\x00\x92\xb1\x00\x04\x0a\xb5\x86\x10\xc0\x60\x00" + "\x01\x00\x01\x00\x00\x92\xb1\x00\x04\x0a\xb5\x87\xc7"; + +static struct test_skiprr_data test_data[TEST_SKIP_SIZE] = {{1, 17}, {2, 30}, {4, 88}, {4, 64}}; + +/** + * @tc.name : ns_get16_0100 + * @tc.desc : Parse data from array and return + * @tc.level : Level 0 + */ +void ns_get16_0100(void) +{ + const unsigned char cp[] = "11"; + unsigned int ret = ns_get16(cp); + unsigned int getresult = 12593; + EXPECT_EQ("ns_get16_0100", ret, getresult); +} + +/** + * @tc.name : ns_get32_0100 + * @tc.desc : Parse data from array and return + * @tc.level : Level 0 + */ +void ns_get32_0100(void) +{ + const unsigned char cp[] = "11"; + unsigned long ret = ns_get32(cp); + unsigned long getresult = 825294897; + EXPECT_LONGEQ("ns_get32_0100", ret, getresult); +} + +/** + * @tc.name : ns_put16_0100 + * @tc.desc : Get actual data value from data of ns_get16 + * @tc.level : Level 0 + */ +void ns_put16_0100(void) +{ + const unsigned char from[] = "11"; + unsigned char to[TEST_MSG_SIZE]; + memset(to, 0x0, TEST_MSG_SIZE); + unsigned int ret = ns_get16(from); + ns_put16(ret, to); + for (int i = 0; i < sizeof(from) / sizeof(unsigned char); i++) { + EXPECT_EQ("ns_put16_0100", from[i], to[i]); + } +} + +/** + * @tc.name : ns_put32_0100 + * @tc.desc : Get actual data value from data of ns_get32 + * @tc.level : Level 0 + */ +void ns_put32_0100(void) +{ + const unsigned char from[] = "1234"; + unsigned char to[TEST_MSG_SIZE]; + memset(to, 0x0, TEST_MSG_SIZE); + unsigned long ret = ns_get32(from); + ns_put32(ret, to); + for (int i = 0; i < sizeof(from) / sizeof(unsigned char); i++) { + EXPECT_LONGEQ("ns_put32_0100", from[i], to[i]); + } +} + +/** + * @tc.name : ns_name_uncompress_0100 + * @tc.desc : Get the domain name from the array and store the data in the array (success) + * @tc.level : Level 0 + */ +void ns_name_uncompress_0100(void) +{ + unsigned char domain[] = {2, 'p', 'q', 0xc0, 5, 0}; + char name[] = "XXXX"; + + int ret = ns_name_uncompress(domain, domain + 6, domain, name, TEST_MSG_SIZE); + EXPECT_EQ("ns_name_uncompress_0100", ret, 5); + EXPECT_STREQ("ns_name_uncompress_0100", name, "pq"); + + memcpy(domain, "\xc0\x02", 3); + memcpy(name, "XXXX", 5); + size_t limitsize = 1; + ret = ns_name_uncompress(domain, domain + 3, domain, name, limitsize); + + EXPECT_EQ("ns_name_uncompress_0100", ret, 2); + EXPECT_STREQ("ns_name_uncompress_0100", name, ""); +} + +/** + * @tc.name : ns_name_uncompress_0200 + * @tc.desc : Get the domain name from the array and store the data in the array (failed) + * @tc.level : Level 2 + */ +void ns_name_uncompress_0200(void) +{ + unsigned char domain[] = {2, 'p', 'q', 0xc0, 5, 0}; + char name[] = "XXXX"; + + int ret = ns_name_uncompress(domain, domain + 6, domain, name, ERREXPECT); + EXPECT_EQ("ns_name_uncompress_0200", ret, ERREXPECT); + EXPECT_EQ("ns_name_uncompress_0200", errno, EMSGSIZE); +} + +/** + * @tc.name : ns_name_uncompress_0300 + * @tc.desc : Get the domain name from the array and store the data in the array (failed) + * @tc.level : Level 2 + */ +void ns_name_uncompress_0300(void) +{ + unsigned char domain[] = "error value"; + char name[] = "XXXX"; + + int ret = ns_name_uncompress(domain, domain + 6, domain, name, ERREXPECT); + EXPECT_EQ("ns_name_uncompress_0200", ret, ERREXPECT); + EXPECT_EQ("ns_name_uncompress_0200", errno, EMSGSIZE); +} + +/** + * @tc.name : ns_initparse_0100 + * @tc.desc : Parse DNS protocol reply packets into ns_msg structure + * @tc.level : Level 0 + */ +void ns_initparse_0100(void) +{ + ns_msg handle; + errno = 0; + int ret = ns_initparse(msg, sizeof(msg) - 1, &handle); + EXPECT_EQ("ns_initparse_0100", ret, CMPFLAG); + EXPECT_EQ("ns_initparse_0100", errno, CMPFLAG); + + uint16_t id = (msg[0] << TEST_SHIFT) | msg[1]; + uint16_t flags = (msg[TEST_INDEX_2] << TEST_SHIFT) | msg[TEST_INDEX_3]; + EXPECT_EQ("ns_initparse_0100", handle._id, id); + EXPECT_EQ("ns_initparse_0100", handle._flags, flags); +} + +/** + * @tc.name : ns_initparse_0200 + * @tc.desc : Provide error parameter data, parse DNS protocol response packet into ns_msg structure + * @tc.level : Level 2 + */ +void ns_initparse_0200(void) +{ + ns_msg handle; + errno = 0; + int ret = ns_initparse(msg, TEST_DATA_LEN, &handle); + EXPECT_EQ("ns_initparse_0200", ret, ERREXPECT); + EXPECT_EQ("ns_initparse_0200", errno, EMSGSIZE); + + errno = 0; + ret = ns_initparse(msg, sizeof(msg), &handle); + EXPECT_EQ("ns_initparse_0200", ret, ERREXPECT); + EXPECT_EQ("ns_initparse_0200", errno, EMSGSIZE); +} + +/** + * @tc.name : ns_skiprr_0100 + * @tc.desc : Find the record location from a given DNS packet + * @tc.level : Level 0 + */ +void ns_skiprr_0100(void) +{ + unsigned char *ptr = msg + TEST_DNS_HEAD; + unsigned char *eom = msg + sizeof(msg) - 1; + int i, ret; + for (i = 0; i < TEST_SKIP_SIZE; i++) { + errno = 0; + ret = ns_skiprr(ptr, eom, i, test_data[i].sect); + if (ret == -1) { + break; + } + ptr += ret; + EXPECT_EQ("ns_skiprr_0100", ret, test_data[i].result); + EXPECT_EQ("ns_skiprr_0100", errno, CMPFLAG); + } + EXPECT_PTREQ("ns_skiprr_0100", ptr, eom); +} + +/** + * @tc.name : ns_skiprr_0200 + * @tc.desc : Provide error message, find record location + * @tc.level : Level 2 + */ +void ns_skiprr_0200(void) +{ + unsigned char *ptr = msg; + unsigned char *eom = msg + sizeof(msg); + int i, ret; + for (i = 0; i < TEST_SKIP_SIZE; i++) { + errno = 0; + ret = ns_skiprr(ptr, eom, i, test_data[i].sect); + if (ret == -1) { + break; + } + ptr += ret; + } + EXPECT_PTRNE("ns_skiprr_0200", ptr, eom); +} + +/** + * @tc.name : ns_parserr_0100 + * @tc.desc : Extract data from a given DNS packet + * @tc.level : Level 0 + */ +void ns_parserr_0100(void) +{ + ns_msg handle; + errno = 0; + int ret = ns_initparse(msg, sizeof(msg) - 1, &handle); + EXPECT_EQ("ns_parserr_0100", ret, 0); + if (ret != 0) { + return; + } + + ns_rr rr; + memset(&rr, 0x0, sizeof(ns_rr)); + ret = ns_parserr(&handle, ns_s_qd, 0, &rr); + EXPECT_EQ("ns_parserr_0100", ret, 0); + EXPECT_STREQ("ns_parserr_0100", rr.name, "www.abc.com"); + EXPECT_EQ("ns_parserr_0100", rr.rr_class, 1); + EXPECT_EQ("ns_parserr_0100", rr.type, 1); + EXPECT_EQ("ns_parserr_0100", rr.ttl, 0); + EXPECT_EQ("ns_parserr_0100", rr.rdlength, 0); + EXPECT_PTREQ("ns_parserr_0100", rr.rdata, NULL); + + memset(&rr, 0x0, sizeof(ns_rr)); + ret = ns_parserr(&handle, ns_s_an, 0, &rr); + EXPECT_EQ("ns_parserr_0100", ret, 0); + EXPECT_STREQ("ns_parserr_0100", rr.name, "www.abc.com"); + EXPECT_EQ("ns_parserr_0100", rr.rr_class, 1); + EXPECT_EQ("ns_parserr_0100", rr.type, TEST_INDEX_5); + EXPECT_TRUE("ns_parserr_0100", rr.ttl > 0); + EXPECT_TRUE("ns_parserr_0100", rr.rdlength > 0); + EXPECT_PTRNE("ns_parserr_0100", rr.rdata, NULL); +} + +/** + * @tc.name : ns_parserr_0200 + * @tc.desc : Extracting data from given DNS message by providing wrong message length + * @tc.level : Level 2 + */ +void ns_parserr_0200(void) +{ + ns_msg handle; + errno = 0; + int ret = ns_initparse(msg, sizeof(msg) - 1, &handle); + EXPECT_EQ("ns_parserr_0200", ret, 0); + if (ret != 0) { + return; + } + + ns_rr rr; + errno = 0; + memset(&rr, 0x0, sizeof(ns_rr)); + ret = ns_parserr(&handle, -1, 0, &rr); + EXPECT_EQ("ns_parserr_0200", ret, -1); + EXPECT_EQ("ns_parserr_0200", errno, ENODEV); + + errno = 0; + memset(&rr, 0x0, sizeof(ns_rr)); + ret = ns_parserr(&handle, ns_s_max + 1, 0, &rr); + EXPECT_EQ("ns_parserr_0200", ret, -1); + EXPECT_EQ("ns_parserr_0200", errno, ENODEV); +} + +/** + * @tc.name : ns_parserr_0300 + * @tc.desc : Provides an uninitialized ns_msg to extract data from the given DNS message + * @tc.level : Level 2 + */ +void ns_parserr_0300(void) +{ + ns_msg handle; + errno = 0; + ns_rr rr; + memset(&handle, 0x0, sizeof(ns_msg)); + memset(&rr, 0x0, sizeof(ns_rr)); + + int ret = ns_parserr(&handle, ns_s_qd, 0, &rr); + EXPECT_EQ("ns_parserr_0300", ret, -1); + EXPECT_EQ("ns_parserr_0300", errno, ENODEV); +} + +int main(void) +{ + ns_get16_0100(); + ns_get32_0100(); + ns_put16_0100(); + ns_put32_0100(); + ns_name_uncompress_0100(); + ns_name_uncompress_0200(); + ns_name_uncompress_0300(); + ns_initparse_0100(); + ns_initparse_0200(); + ns_skiprr_0100(); + ns_skiprr_0200(); + ns_parserr_0100(); + ns_parserr_0200(); + ns_parserr_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/proto.c b/libc-test/src/functionalext/supplement/network/proto.c new file mode 100755 index 00000000..86de5e28 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/proto.c @@ -0,0 +1,168 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_PROTO_NUM 6 +#define TEST_INVALID_NUMBER 10240 +#define TEST_TERMINATE_SIZE 2 + +static int test_index = 0; +static const unsigned char test_protos[] = {"\000ip\0" + "\001icmp\0" + "\002igmp\0" + "\003ggp\0" + "\004ipencap\0" + "\005st\0" + "\006tcp\0" + "\010egp\0" + "\014pup\0" + "\021udp\0" + "\024hmp\0" + "\026xns-idp\0" + "\033rdp\0" + "\035iso-tp4\0" + "\044xtp\0" + "\045ddp\0" + "\046idpr-cmtp\0" + "\051ipv6\0" + "\053ipv6-route\0" + "\054ipv6-frag\0" + "\055idrp\0" + "\056rsvp\0" + "\057gre\0" + "\062esp\0" + "\063ah\0" + "\071skip\0" + "\072ipv6-icmp\0" + "\073ipv6-nonxt\0" + "\074ipv6-opts\0" + "\111rspf\0" + "\121vmtp\0" + "\131ospf\0" + "\136ipip\0" + "\142encap\0" + "\147pim\0" + "\377raw"}; + +struct protoent *test_getprotoent(void) +{ + static struct protoent p; + if (test_index >= sizeof(test_protos)) { + return NULL; + } + p.p_proto = test_protos[test_index]; + p.p_name = (char *)&test_protos[test_index + 1]; + test_index += strlen(p.p_name) + TEST_TERMINATE_SIZE; + return &p; +} + +void test_resetprotoent(void) +{ + test_index = 0; + setprotoent(0); + endprotoent(); +} + +/** + * @tc.name : getprotobyname_0100 + * @tc.desc : Get the specified protocol name by name + * @tc.level : Level 0 + */ +void getprotobyname_0100(void) +{ + struct protoent *ret = getprotobyname("tcp"); + EXPECT_PTRNE("getprotobyname_0100", ret, NULL); + if (ret) { + EXPECT_STREQ("getprotobyname_0100", ret->p_name, "tcp"); + EXPECT_EQ("getprotobyname_0100", ret->p_proto, TEST_PROTO_NUM); + } +} + +/** + * @tc.name : getprotobyname_0200 + * @tc.desc : Get the specified protocol name by name + * @tc.level : Level 2 + */ +void getprotobyname_0200(void) +{ + struct protoent *ret = getprotobyname("abcd"); + EXPECT_PTREQ("getprotobyname_0200", ret, NULL); +} + +/** + * @tc.name : getprotobynumber_0100 + * @tc.desc : Get the specified protocol name by number + * @tc.level : Level 0 + */ +void getprotobynumber_0100(void) +{ + struct protoent *ret = getprotobynumber(TEST_PROTO_NUM); + EXPECT_PTRNE("getprotobynumber_0100", ret, NULL); + if (ret) { + EXPECT_STREQ("getprotobynumber_0100", ret->p_name, "tcp"); + EXPECT_EQ("getprotobynumber_0100", ret->p_proto, TEST_PROTO_NUM); + } +} + +/** + * @tc.name : getprotobynumber_0200 + * @tc.desc : Get the specified protocol name by number + * @tc.level : Level 2 + */ +void getprotobynumber_0200(void) +{ + struct protoent *ret = getprotobynumber(TEST_INVALID_NUMBER); + EXPECT_PTREQ("getprotobynumber_0200", ret, NULL); +} + +/** + * @tc.name : getprotoent_0100 + * @tc.desc : Get the protocol information scheduled by the system + * @tc.level : Level 0 + */ +void getprotoent_0100(void) +{ + test_resetprotoent(); + struct protoent *dst = NULL; + struct protoent *src = NULL; + int count = 0; + while (1) { + dst = getprotoent(); + src = test_getprotoent(); + if (dst && src) { + count++; + EXPECT_EQ("getprotoent_0100", dst->p_proto, src->p_proto); + EXPECT_STREQ("getprotoent_0100", dst->p_name, src->p_name); + } else { + break; + } + } + EXPECT_TRUE("getprotoent_0100", count > 0); + test_resetprotoent(); +} + +int main(void) +{ + getprotobyname_0100(); + getprotobyname_0200(); + + getprotobynumber_0100(); + getprotobynumber_0200(); + + getprotoent_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/recv.c b/libc-test/src/functionalext/supplement/network/recv.c new file mode 100755 index 00000000..f4ec5550 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/recv.c @@ -0,0 +1,152 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +#define BUF_SIZE (100) +#define PORT 2288 +#define WAIT() pthread_barrier_wait(&g_barrier) +static const char *g_cliMsg = "Hello, this is client"; +static const char *g_localHost = "127.0.0.1"; +static pthread_barrier_t g_barrier; +int bufSize = 0; + +void *SampleServerTask() +{ + int *sign = (int *)malloc(sizeof(int)); + int rets = -1; + int sListen = socket(AF_INET, SOCK_STREAM, 0); + if (sListen == -1) + { + printf("[Server] socket fail!\n"); + *sign = -1; + return sign; + } + int flag = 1; + rets = setsockopt(sListen, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int)); + if (rets != 0) + { + printf("[server] setsockopt fail, rets: %d!\n", rets); + } + struct sockaddr_in srvAddr = {0}; + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PORT); + rets = bind(sListen, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + if (rets != 0) + { + printf("[Server] bind fail!\n"); + close(sListen); + *sign = -1; + return sign; + } + rets = listen(sListen, 2); + if (rets != 0) + { + printf("[Server] listen fail!\n"); + close(sListen); + *sign = -1; + return sign; + } + WAIT(); + struct sockaddr_in clnAddr = {0}; + socklen_t clnAddrLen = sizeof(clnAddr); + int sClient = accept(sListen, (struct sockaddr *)&clnAddr, &clnAddrLen); + printf("[server] accept <%s:%d>\n", inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port)); + static char buf[BUF_SIZE + 1] = {0}; + memset(buf, '\0', BUF_SIZE); + rets = recv(sClient, buf, sizeof(buf), 0); + EXPECT_EQ("recv_0100", rets, bufSize); + close(sClient); + close(sListen); + return sign; +} + +void *SampleClientTask() +{ + int clnFd = socket(AF_INET, SOCK_STREAM, 0); + WAIT(); + struct sockaddr_in srvAddr = {0}; + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PORT); + int sign = connect(clnFd, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + EXPECT_EQ("recv_0100", 0, sign); + if (sign == 0) + { + printf("[client] connect success\n"); + } + static char buf[BUF_SIZE + 1] = {0}; + memset(buf, '\0', BUF_SIZE); + strcpy(buf, g_cliMsg); + bufSize = sizeof(buf); + int sendRet = send(clnFd, buf, sizeof(buf), 0); + EXPECT_EQ("recv_0100", sendRet, sizeof(buf)); + close(clnFd); + return NULL; +} + +/* + * @tc.name : recv_0100 + * @tc.desc : Verify that the server recv successfully + * @tc.level : Level 0 + */ +void recv_0100() +{ + pthread_t srv; + pthread_t cli; + + int sign = pthread_barrier_init(&g_barrier, 0, 2); + EXPECT_EQ("recv_0100", 0, sign); + + sign = pthread_create(&srv, NULL, SampleServerTask, NULL); + EXPECT_EQ("recv_0100", 0, sign); + sign = pthread_create(&cli, NULL, SampleClientTask, NULL); + EXPECT_EQ("recv_0100", 0, sign); + + sign = pthread_join(cli, NULL); + EXPECT_EQ("recv_0100", 0, sign); + sign = pthread_join(srv, NULL); + EXPECT_EQ("recv_0100", 0, sign); + + sign = pthread_barrier_destroy(&g_barrier); + EXPECT_EQ("recv_0100", 0, sign); +} + +int main() +{ + recv_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/recvmmsg.c b/libc-test/src/functionalext/supplement/network/recvmmsg.c new file mode 100644 index 00000000..8f2b35bf --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/recvmmsg.c @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "test.h" + +const int SLEEP_TIME = 2; + +void sendsss(void) +{ + int sockfd; + struct sockaddr_in addr; + struct mmsghdr msg[2]; + struct iovec msg1[2], msg2; + int retval; + + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd == -1) { + t_error("recvmmsg_0100 socket error"); + exit(EXIT_FAILURE); + } + + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + addr.sin_port = htons(1234); + if (connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { + t_error("recvmmsg_0100 connect error"); + exit(EXIT_FAILURE); + } + + memset(msg1, 0, sizeof(msg1)); + msg1[0].iov_base = "one"; + msg1[0].iov_len = 3; + msg1[1].iov_base = "two"; + msg1[1].iov_len = 3; + + memset(&msg2, 0, sizeof(msg2)); + msg2.iov_base = "three"; + msg2.iov_len = 5; + + memset(msg, 0, sizeof(msg)); + msg[0].msg_hdr.msg_iov = msg1; + msg[0].msg_hdr.msg_iovlen = 2; + + msg[1].msg_hdr.msg_iov = &msg2; + msg[1].msg_hdr.msg_iovlen = 1; + + retval = sendmmsg(sockfd, msg, 2, 0); + if (retval == -1) + t_error("recvmmsg_0100 sendmmsg error"); +} + +void recvsss(void) +{ +#define VLEN 10 +#define BUFSIZE 200 +#define TIMEOUT 1 + int sockfd, retval; + struct sockaddr_in addr; + struct mmsghdr msgs[VLEN]; + struct iovec iovecs[VLEN]; + char bufs[VLEN][BUFSIZE + 1]; + struct timespec timeout; + + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd == -1) { + t_error("recvmmsg_0100 recv socket error"); + exit(EXIT_FAILURE); + } + + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + addr.sin_port = htons(1234); + if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { + t_error("recvmmsg_0100 recv bind error"); + exit(EXIT_FAILURE); + } + + memset(msgs, 0, sizeof(msgs)); + for (int i = 0; i < VLEN; i++) { + iovecs[i].iov_base = bufs[i]; + iovecs[i].iov_len = BUFSIZE; + msgs[i].msg_hdr.msg_iov = &iovecs[i]; + msgs[i].msg_hdr.msg_iovlen = 1; + } + + timeout.tv_sec = TIMEOUT; + timeout.tv_nsec = 0; + + retval = recvmmsg(sockfd, msgs, VLEN, 0, &timeout); + if (retval == -1) { + t_error("recvmmsg_0100 recv recvmmsg error"); + exit(EXIT_FAILURE); + } +} + +/** + * @tc.name : recvmmsg_0100 + * @tc.desc : Test recvmmsg to recv messages through socket + * @tc.level : Level 0 + */ +int main(int argc, char *argv[]) +{ + pid_t pid = fork(); + if (pid > 0) { + recvsss(); + } else if (pid == 0) { + sleep(SLEEP_TIME); + sendsss(); + } else { + t_error("recvmmsg_0100 fork error"); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/recvmsg.c b/libc-test/src/functionalext/supplement/network/recvmsg.c new file mode 100644 index 00000000..9305cbcc --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/recvmsg.c @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +#define TEST_MSG_PORT 7788 +#define TEST_BUF_SIZE 256 +#define TEST_TIMEOUT 5 + +const char *text = "This is a simple test case."; + +void fill_socket_addr(struct sockaddr_in *addr) +{ + if (addr) { + bzero(addr, sizeof(struct sockaddr_in)); + addr->sin_family = AF_INET; + inet_pton(AF_INET, "127.0.0.1", &addr->sin_addr); + addr->sin_port = htons(TEST_MSG_PORT); + } +} + +int check_recv_message(int sockfd) +{ + struct timeval t; + fd_set rset; + + int timeout = TEST_TIMEOUT; + int ret; + while (timeout > 0) { + FD_ZERO(&rset); + FD_SET(sockfd, &rset); + t.tv_sec = 1; + t.tv_usec = 0; + + ret = select(sockfd + 1, &rset, NULL, NULL, &t); + if (ret == 0) { + timeout--; + } else if (ret < 0) { + return ret; + } else { + if (FD_ISSET(sockfd, &rset)) { + return ret; + } + } + } + return -1; +} + +void send_message(int flag, const char *msg) +{ + int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); + if (sockfd == -1) { + t_error("[%s] failed\n", msg); + return; + } + + struct sockaddr_in addr; + struct msghdr msg_send; + struct iovec iov_send; + char buf[TEST_BUF_SIZE]; + + fill_socket_addr(&addr); + memset(&msg_send, 0x0, sizeof(struct msghdr)); + memset(&iov_send, 0x0, sizeof(struct iovec)); + + iov_send.iov_base = buf; + iov_send.iov_len = TEST_BUF_SIZE; + + msg_send.msg_iovlen = 1; + msg_send.msg_iov = &iov_send; + msg_send.msg_control = 0; + msg_send.msg_controllen = 0; + + if (connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { + close(sockfd); + t_error("[%s] failed\n", msg); + return; + } + + int ret = sendmsg(sockfd, &msg_send, flag); + close(sockfd); + EXPECT_TRUE(msg, ret > 0); +} + +int recv_message(int flag, const char *msg) +{ + int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); + if (sockfd == -1) { + t_error("[%s] failed\n", msg); + exit(1); + } + + struct sockaddr_in addr; + struct msghdr msg_recv; + struct iovec iov_recv; + char buf[TEST_BUF_SIZE]; + char control[TEST_BUF_SIZE]; + + fill_socket_addr(&addr); + memset(&msg_recv, 0x0, sizeof(struct msghdr)); + memset(&iov_recv, 0x0, sizeof(struct iovec)); + memset(buf, 0x0, sizeof(buf)); + + iov_recv.iov_base = (void *)buf; + iov_recv.iov_len = TEST_BUF_SIZE; + + msg_recv.msg_name = &addr; + msg_recv.msg_iovlen = 1; + msg_recv.msg_iov = &iov_recv; + msg_recv.msg_control = control; + msg_recv.msg_controllen = TEST_BUF_SIZE; + msg_recv.msg_flags = 0; + + if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { + close(sockfd); + t_error("[%s] failed\n", msg); + exit(1); + } + + int ret = check_recv_message(sockfd); + EXPECT_TRUE(msg, ret > 0); + if (ret > 0) { + ret = recvmsg(sockfd, &msg_recv, flag); + EXPECT_TRUE(msg, ret > 0); + EXPECT_STREQ(msg, iov_recv.iov_base, text); + } + close(sockfd); + exit(0); +} + +/** + * @tc.name : recvmsg_0100 + * @tc.desc : Test recvmsg to recv messages through socket + * @tc.level : Level 0 + */ +void recvmsg_0100(void) +{ + pid_t pid = fork(); + if (pid == 0) { + recv_message(0, "recvmsg_0100"); + } else if (pid > 0) { + sleep(1); + send_message(0, "recvmsg_0100"); + wait(NULL); + } else { + t_error("recvmsg_0100 fork error"); + } +} + +int main(void) +{ + recvmsg_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/res_mkquery.c b/libc-test/src/functionalext/supplement/network/res_mkquery.c new file mode 100644 index 00000000..56005e6a --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/res_mkquery.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +const int op = QUERY; +const int class = C_IN; +const int type = T_TXT; +const char dname[] = "www.example.com"; +const unsigned char *data = (const unsigned char *)""; +const char qbuf[] = "\0\1\0\0\0\0\0\0"; +const char qname[] = "\3www\7example\3com"; + +/** + * @tc.name : res_mkquery_0100 + * @tc.desc : construct a query message + * @tc.level : Level 0 + */ +void res_mkquery_0100(void) +{ + unsigned char buf[BUFSIZ] = {0}; + + int result = res_mkquery(op, dname, class, type, data, 0, NULL, buf, sizeof(buf)); + if (result < 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = memcmp(buf + 12, qname, sizeof(qname) - 1); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = memcmp(buf + 4, qbuf, sizeof(qbuf) - 1); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : res_mkquery_0200 + * @tc.desc : construct a query message with an invalid type + * @tc.level : Level 2 + */ +void res_mkquery_0200(void) +{ + int result = res_mkquery(op, dname, class, T_ANY + 1, data, 0, NULL, NULL, 0); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + res_mkquery_0100(); + res_mkquery_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/network/res_query.c b/libc-test/src/functionalext/supplement/network/res_query.c new file mode 100644 index 00000000..45d49e1f --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/res_query.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +const char dname[] = "www.example.com"; +const int class = C_IN; +const int type = T_TXT; +const char options[] = "options timeout:0"; + +void set_timeout(void) +{ + system("cp /etc/resolv.conf /etc/resolv.conf.bak"); + + FILE *f = fopen(_PATH_RESCONF, "a+"); + if (f == NULL) { + t_error("%s failed: fopen\n", __func__); + return; + } + + fwrite(options, sizeof(options), 1, f); + fclose(f); +} + +void restore_conf(void) +{ + remove(_PATH_RESCONF); + rename("/etc/resolv.conf.bak", _PATH_RESCONF); +} + +/** + * @tc.name : res_query_0100 + * @tc.desc : query the name server + * @tc.level : Level 0 + */ +void res_query_0100(void) +{ + set_timeout(); + + unsigned char buf[BUFSIZ] = {0}; + int result = res_query(dname, class, type, buf, sizeof(buf)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + restore_conf(); +} + +/** + * @tc.name : res_query_0200 + * @tc.desc : query the name server with an invalid type + * @tc.level : Level 2 + */ +void res_query_0200(void) +{ + set_timeout(); + + int result = res_query(dname, class, T_ANY + 1, NULL, 0); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + restore_conf(); +} + +int main(int argc, char *argv[]) +{ + res_query_0100(); + res_query_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/network/send.c b/libc-test/src/functionalext/supplement/network/send.c new file mode 100755 index 00000000..cba486fc --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/send.c @@ -0,0 +1,200 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +#define BUF_SIZE (100) +#define PORT 2288 +#define WAIT() pthread_barrier_wait(&g_barrier) +static const char *g_cliMsg = "Hello, this is client"; +static const char *g_localHost = "127.0.0.1"; +static pthread_barrier_t g_barrier; + +void *SampleServerTask() +{ + int *ret = (int *)malloc(sizeof(int)); + int rets = -1; + int sListen = socket(AF_INET, SOCK_STREAM, 0); + if (sListen == -1) { + *ret = -1; + return ret; + } + int flag = 1; + rets = setsockopt(sListen, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int)); + struct sockaddr_in srvAddr = {0}; + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PORT); + rets = bind(sListen, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + if (rets != 0) { + close(sListen); + *ret = -1; + return ret; + } + rets = listen(sListen, 2); + if (rets != 0) { + close(sListen); + *ret = -1; + return ret; + } + WAIT(); + struct sockaddr_in clnAddr = {0}; + socklen_t clnAddrLen = sizeof(clnAddr); + int sClient = accept(sListen, (struct sockaddr *)&clnAddr, &clnAddrLen); + static char buf[BUF_SIZE + 1] = {0}; + memset(buf, '\0', BUF_SIZE); + rets = recv(sClient, buf, sizeof(buf), 0); + close(sClient); + close(sListen); + return ret; +} + +void *SampleClientTask() +{ + int clnFd = socket(AF_INET, SOCK_STREAM, 0); + WAIT(); + struct sockaddr_in srvAddr = {0}; + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PORT); + int ret = connect(clnFd, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + EXPECT_EQ("send_0100", 0, ret); + static char buf[BUF_SIZE + 1] = {0}; + memset(buf, '\0', BUF_SIZE); + strcpy(buf, g_cliMsg); + int sendRet = send(clnFd, buf, sizeof(buf), 0); + EXPECT_EQ("send_0100", sendRet, sizeof(buf)); + close(clnFd); + return NULL; +} + +void *SampleServerNullTask() +{ + int *ret = (int *)malloc(sizeof(int)); + int rets = 0; + int sListen = socket(AF_INET, SOCK_STREAM, 0); + if (sListen == -1) { + *ret = -1; + return ret; + } + int flag = 1; + rets = setsockopt(sListen, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int)); + struct sockaddr_in srvAddr = {0}; + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PORT); + rets = bind(sListen, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + if (rets != 0) { + close(sListen); + *ret = -1; + return ret; + } + rets = listen(sListen, 2); + if (rets != 0) { + close(sListen); + *ret = -1; + return ret; + } + WAIT(); + struct sockaddr_in clnAddr = {0}; + socklen_t clnAddrLen = sizeof(clnAddr); + accept(sListen, (struct sockaddr *)&clnAddr, &clnAddrLen); + close(sListen); + return ret; +} + +void *SampleClientNullTask() +{ + int clnFd = socket(AF_INET, SOCK_STREAM, 0); + WAIT(); + struct sockaddr_in srvAddr = {0}; + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PORT); + int ret = connect(clnFd, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + EXPECT_EQ("send_0200", 0, ret); + static char buf[BUF_SIZE + 1] = {0}; + memset(buf, '\0', BUF_SIZE); + strcpy(buf, g_cliMsg); + int result = send(clnFd, NULL, sizeof(buf), 0); + EXPECT_EQ("send_0200", result, -1); + return NULL; +} + +/* + * @tc.name : send_0100 + * @tc.desc : Verify that the client sent successfully + * @tc.level : Level 0 + */ +void send_0100(void) +{ + pthread_t srv; + pthread_t cli; + int ret = pthread_barrier_init(&g_barrier, 0, 2); + EXPECT_EQ("send_0100", 0, ret); + ret = pthread_create(&srv, NULL, SampleServerTask, NULL); + EXPECT_EQ("send_0100", 0, ret); + ret = pthread_create(&cli, NULL, SampleClientTask, NULL); + EXPECT_EQ("send_0100", 0, ret); + ret = pthread_join(cli, NULL); + EXPECT_EQ("send_0100", 0, ret); + ret = pthread_join(srv, NULL); + EXPECT_EQ("send_0100", 0, ret); + ret = pthread_barrier_destroy(&g_barrier); + EXPECT_EQ("send_0100", 0, ret); +} + +/* + * @tc.name : send_0200 + * @tc.desc : Verify that client send failed when parameter is invalid + * @tc.level : Level 2 + */ +void send_0200(void) +{ + pthread_t srv; + pthread_t cli; + int ret = pthread_barrier_init(&g_barrier, 0, 2); + EXPECT_EQ("send_0200", 0, ret); + ret = pthread_create(&srv, NULL, SampleServerNullTask, NULL); + EXPECT_EQ("send_0200", 0, ret); + ret = pthread_create(&cli, NULL, SampleClientNullTask, NULL); + EXPECT_EQ("send_0200", 0, ret); + ret = pthread_join(cli, NULL); + EXPECT_EQ("send_0200", 0, ret); + ret = pthread_join(srv, NULL); + EXPECT_EQ("send_0200", 0, ret); + ret = pthread_barrier_destroy(&g_barrier); + EXPECT_EQ("send_0200", 0, ret); +} + +TEST_FUN G_Fun_Array[] = {send_0100, send_0200}; +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/sendmmsg.c b/libc-test/src/functionalext/supplement/network/sendmmsg.c new file mode 100644 index 00000000..1080bb14 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/sendmmsg.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : sendmmsg_0100 + * @tc.desc : Test sendmmsg to send messages through socket + * @tc.level : Level 0 + */ +void sendmmsg_0100(void) +{ + int sockfd; + struct sockaddr_in addr; + struct mmsghdr msg[2]; + struct iovec msg1[2], msg2; + int retval; + + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd == -1) { + t_error("sendmmsg_0100 socket error"); + exit(EXIT_FAILURE); + } + + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + addr.sin_port = htons(1234); + if (connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { + t_error("sendmmsg_0100 connect error"); + exit(EXIT_FAILURE); + } + + memset(msg1, 0, sizeof(msg1)); + msg1[0].iov_base = "one"; + msg1[0].iov_len = 3; + msg1[1].iov_base = "two"; + msg1[1].iov_len = 3; + + memset(&msg2, 0, sizeof(msg2)); + msg2.iov_base = "three"; + msg2.iov_len = 5; + + memset(msg, 0, sizeof(msg)); + msg[0].msg_hdr.msg_iov = msg1; + msg[0].msg_hdr.msg_iovlen = 2; + + msg[1].msg_hdr.msg_iov = &msg2; + msg[1].msg_hdr.msg_iovlen = 1; + + retval = sendmmsg(sockfd, msg, 2, 0); + if (retval == -1) + t_error("sendmmsg_0100 sendmmsg error"); +} + +int main(int argc, char *argv[]) +{ + sendmmsg_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/sendmsg.c b/libc-test/src/functionalext/supplement/network/sendmsg.c new file mode 100644 index 00000000..170b6a4e --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/sendmsg.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : sendmsg_0100 + * @tc.desc : Test sendmsg to send messages through socket + * @tc.level : Level 0 + */ +void sendmsg_0100(void) +{ + int sockfd; + struct sockaddr_in addr; + int retval; + + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd == -1) { + t_error("sendmsg_0100 socket error"); + exit(EXIT_FAILURE); + } + + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + addr.sin_port = htons(1234); + if (connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { + t_error("sendmsg_0100 connect error"); + exit(EXIT_FAILURE); + } + struct msghdr msg; + bzero(&msg, sizeof(struct msghdr)); + + retval = sendmsg(sockfd, &msg, 2); + if (retval == -1) + t_error("sendmsg_0100 sendmsg error"); +} + +int main(int argc, char *argv[]) +{ + sendmsg_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/setprotoent.c b/libc-test/src/functionalext/supplement/network/setprotoent.c new file mode 100644 index 00000000..ee829fff --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/setprotoent.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +/** + * @tc.name : setprotoent_0100 + * @tc.desc : set protocol entry + * @tc.level : Level 0 + */ +void setprotoent_0100(void) +{ + endprotoent(); + + struct protoent *result = getprotoent(); + if (result == NULL) { + t_error("%s failed: result = %p\n", __func__, result); + } + + char buf[BUFSIZ] = {0}; + strcpy(buf, result->p_name); + + setprotoent(0); + result = getprotoent(); + if (result == NULL) { + t_error("%s failed: result = %p\n", __func__, result); + } + + if (strcmp(result->p_name, buf)) { + t_error("%s failed: result->p_name = %s\n", __func__, result->p_name); + } +} + +int main(int argc, char *argv[]) +{ + setprotoent_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/network/shutdown.c b/libc-test/src/functionalext/supplement/network/shutdown.c new file mode 100644 index 00000000..5b79cc3a --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/shutdown.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : shutdown_0100 + * @tc.desc : The test stops the socket transmission through the shutdown function + * @tc.level : Level 0 + */ +void shutdown_0100(void) +{ + int sd = socket(AF_INET, SOCK_STREAM, 0); + struct sockaddr_in server_addr; + bzero(&server_addr, sizeof(server_addr)); + server_addr.sin_addr.s_addr = INADDR_ANY; + server_addr.sin_addr.s_addr = INADDR_ANY; + server_addr.sin_port = htons(9898); + server_addr.sin_family = AF_INET; + bind(sd, (struct sockaddr *)(&server_addr), sizeof(server_addr)); + listen(sd, 5); + int result = shutdown(sd, 0); + if (result != 0) { + t_error("%s shutdown get result is %d are not 0", result); + } + close(sd); +} + +int main(int argc, char *argv[]) +{ + shutdown_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/socketpair.c b/libc-test/src/functionalext/supplement/network/socketpair.c new file mode 100644 index 00000000..d0db569c --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/socketpair.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : socketpair_0100 + * @tc.desc : Use the socketpair function to create a pair of unnamed, interconnected sockets. + * @tc.level : Level 0 + */ +void socketpair_0100(void) +{ + int fb[2]; + char buf[128] = {0}; + char *str = "mgn info is hello world"; + int result = socketpair(AF_UNIX, SOCK_STREAM, 0, fb); + if (result == -1) { + t_error("%s socketpair get result error is -1\n", __func__); + } + int size = write(fb[0], str, strlen(str)); + read(fb[1], buf, size); + if (strcmp(buf, str) != 0) { + t_error("%s socketpair get buf is %s are not %s\n", __func__, buf, str); + } +} + +/** + * @tc.name : socketpair_0200 + * @tc.desc : Pass in AF_INET when testing the socketpair function call + * @tc.level : Level 2 + */ +void socketpair_0200(void) +{ + int fb[2]; + int result = socketpair(AF_INET, SOCK_STREAM, 0, fb); + if (result != -1) { + t_error("%s socketpair get result error is %d not -1\n", __func__, result); + } +} + +/** + * @tc.name : socketpair_0300 + * @tc.desc : Test that the length of the array passed two + * @tc.level : Level 1 + */ +void socketpair_0300(void) +{ + int fb[3]; + char buf[128] = {0}; + char *str = "mgn info is hello world"; + int result = socketpair(AF_UNIX, SOCK_STREAM, 0, fb); + if (result == -1) { + t_error("%s socketpair get result error is %d not -1\n", __func__, result); + } + int size = write(fb[0], str, strlen(str)); + read(fb[1], buf, size); + if (strcmp(buf, str) != 0) { + t_error("%s socketpair get buf is %s are not %s\n", __func__, buf, str); + } +} + +int main(int argc, char *argv[]) +{ + socketpair_0100(); + socketpair_0200(); + socketpair_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/network/test_src_functionalext_supplement_network.gni b/libc-test/src/functionalext/supplement/network/test_src_functionalext_supplement_network.gni new file mode 100644 index 00000000..35908350 --- /dev/null +++ b/libc-test/src/functionalext/supplement/network/test_src_functionalext_supplement_network.gni @@ -0,0 +1,57 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_network_test = [ + "__h_errno_location", + "res_mkquery", + "res_query", + "sendmmsg", + "recvmmsg", + "sendmsg", + "setprotoent", + "shutdown", + "socketpair", + "if_indextoname", + "if_nametoindex", + "inet_ntop", + "inet_addr", + "inet_aton", + "inet_lnaof", + "inet_makeaddr", + "inet_netof", + "inet_network", + "inet_ntoa", + "send", + "accept4", + "getaddrinfo", + "listen", + "getifaddrs", + "gethostent", + "getnetent", + "htonl", + "htons", + "if_nameindex", + "dn_skipname", + "dn_comp", + "getservbyname", + "getservbyport", + "hstrerror", + "ns_parse", + "proto", + "recvmsg", + "getpeername", + "freeifaddrs", + "getsockopt", + "gai_strerror", + "recv", +] diff --git a/libc-test/src/functionalext/supplement/passwd/BUILD.gn b/libc-test/src/functionalext/supplement/passwd/BUILD.gn new file mode 100644 index 00000000..eaf0c203 --- /dev/null +++ b/libc-test/src/functionalext/supplement/passwd/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_passwd.gni") + +foreach(s, functionalext_supplement_passwd_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/passwd" + } +} + +group("functionalext_supplement_passwd_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_passwd_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/passwd/getgrent.c b/libc-test/src/functionalext/supplement/passwd/getgrent.c new file mode 100644 index 00000000..d2c88057 --- /dev/null +++ b/libc-test/src/functionalext/supplement/passwd/getgrent.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getgrent_0100 + * @tc.desc : Verify that account data can be retrieved from the group file + * @tc.level : Level 0 + */ +void getgrent_0100(void) +{ + struct group *data; + bool flag = false; + data = getgrent(); + if (data != NULL) { + flag = true; + } + EXPECT_TRUE("getgrent_0100", flag); + endgrent(); +} + +int main() +{ + getgrent_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/passwd/getgrgid.c b/libc-test/src/functionalext/supplement/passwd/getgrgid.c new file mode 100644 index 00000000..ccb87ab9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/passwd/getgrgid.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : mprotect_0100 + * @tc.desc : Verify that the specified GID can be retrieved from the group file (parameter valid) + * @tc.level : Level 0 + */ +void getgrgid_0100(void) +{ + system("ps -eo command,gid | grep -E \"GID|getgrgid\" > ps.txt"); + char abc[256] = {0}; + bool successflag = false; + FILE *fptr = fopen("ps.txt", "r"); + if (fptr) { + while (!feof(fptr)) { + fread(abc, sizeof(abc), 1, fptr); + char num[8] = {0}; + int index = 0; + for (int i = 0; i < (int)strlen(abc); i++) { + if (abc[i] >= '0' && abc[i] <= '9') { + num[index++] += abc[i]; + } + } + num[index] = '\0'; + gid_t intgid = atoi(num); + struct group *gid; + gid = getgrgid(intgid); + if (gid->gr_gid == intgid) { + successflag = true; + } + } + } + EXPECT_TRUE("getgrgid_0100", successflag); + fclose(fptr); + remove("ps.txt"); +} + +/** + * @tc.name : getgrgid_0200 + * @tc.desc : Verify that data with the specified GID cannot be retrieved from the group file + * (gid argument is invalid) + * @tc.level : Level 2 + */ +void getgrgid_0200(void) +{ + struct group *data; + data = getgrgid(-1); + EXPECT_EQ("getgrgid_0200", data, 0); +} + +int main() +{ + getgrgid_0100(); + getgrgid_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/passwd/getgrgid_r.c b/libc-test/src/functionalext/supplement/passwd/getgrgid_r.c new file mode 100644 index 00000000..9caaea41 --- /dev/null +++ b/libc-test/src/functionalext/supplement/passwd/getgrgid_r.c @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getgrgid_r_0100 + * @tc.desc : Verify that the specified gid data can be obtained from the group file (parameters are valid) + * @tc.level : Level 0 + */ +void getgrgid_r_0100(void) +{ + system("ps -eo command,gid | grep -E \"GID|/data/tests/libc-test/src/functionalext/supplement/passwd/" + "getgrgid_r\" > ps.txt"); + char abc[256] = {0}; + bool successflag = false; + FILE *fptr = fopen("ps.txt", "r"); + if (fptr) { + while (!feof(fptr)) { + fread(abc, sizeof(abc), 1, fptr); + char num[8] = {0}; + int index = 0; + for (int i = 0; i < (int)strlen(abc); i++) { + if (abc[i] >= '0' && abc[i] <= '9') { + num[index++] += abc[i]; + } + } + num[index] = '\0'; + gid_t intgid = atoi(num); + int data; + short int lp; + struct group grp; + struct group *grpptr = &grp; + struct group *tempGrpPtr; + char grpbuffer[200]; + int grplinelen = sizeof(grpbuffer); + data = getgrgid_r(91, grpptr, grpbuffer, grplinelen, &tempGrpPtr); + if (data == intgid) { + successflag = true; + } + } + } + EXPECT_TRUE("getgrgid_r_0100", successflag); + fclose(fptr); + remove("ps.txt"); +} + +/** + * @tc.name : getgrgid_r_0200 + * @tc.desc : Verify that the specified gid data can be obtained from the group file (the parameter is invalid) + * @tc.level : Level 2 + */ +void getgrgid_r_0200(void) +{ + int data; + struct group grp; + struct group *grpptr = &grp; + struct group *tempGrpPtr; + char grpbuffer[200]; + int grplinelen = sizeof(grpbuffer); + data = getgrgid_r(0, grpptr, grpbuffer, -1, &tempGrpPtr); + EXPECT_EQ("getgrgid_r_0200", data, 0); +} + +int main() +{ + getgrgid_r_0100(); + getgrgid_r_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/passwd/getgrnam.c b/libc-test/src/functionalext/supplement/passwd/getgrnam.c new file mode 100644 index 00000000..ff7272ee --- /dev/null +++ b/libc-test/src/functionalext/supplement/passwd/getgrnam.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getgrnam_0100 + * @tc.desc : Verify that the specified group can be retrieved from the group file (parameter valid) + * @tc.level : Level 0 + */ +void getgrnam_0100(void) +{ + system("ps -eo command,gid | grep -E \"GID|getgrnam\" > ps.txt"); + char abc[256] = {0}; + bool successflag = false; + FILE *fptr = fopen("ps.txt", "r"); + if (fptr) { + while (!feof(fptr)) { + fread(abc, sizeof(abc), 1, fptr); + char num[8] = {0}; + int index = 0; + for (int i = 0; i < (int)strlen(abc); i++) { + if (abc[i] >= '0' && abc[i] <= '9') { + num[index++] += abc[i]; + } + } + num[index] = '\0'; + gid_t intgid = atoi(num); + struct group *data; + data = getgrnam("root"); + if (data->gr_gid == intgid) { + successflag = true; + } + } + } + EXPECT_TRUE("getgrnam_0100", successflag); + fclose(fptr); + remove("ps.txt"); +} + +/** + * @tc.name : getgrnam_0200 + * @tc.desc : Verify that the specified group cannot be retrieved from the group file + * (the name parameter is invalid) + * @tc.level : Level 2 + */ +void getgrnam_0200(void) +{ + int flag = false; + struct group *result; + result = getgrnam(0); + if (result != 0) { + flag = true; + } + EXPECT_TRUE("getgrnam_0200", flag); +} + +int main() +{ + getgrnam_0100(); + getgrnam_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/passwd/getgrnam_r.c b/libc-test/src/functionalext/supplement/passwd/getgrnam_r.c new file mode 100644 index 00000000..4b6a9692 --- /dev/null +++ b/libc-test/src/functionalext/supplement/passwd/getgrnam_r.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getgrnam_r_0100 + * @tc.desc : Verify that the specified group data can be obtained from the group file (parameters are valid) + * @tc.level : Level 0 + */ +void getgrnam_r_0100(void) +{ + system("ps -eo command,gid | grep -E \"GID|getgrnam_r\" > " + "/data/tests/libc-test/src/functionalext/supplement/passwd/pss.txt"); + char abc[256] = {0}; + bool successflag = false; + FILE *fptr = fopen("/data/tests/libc-test/src/functionalext/supplement/passwd/pss.txt", "r"); + if (fptr) { + while (!feof(fptr)) { + fread(abc, sizeof(abc), 1, fptr); + char num[8] = {0}; + int index = 0; + for (int i = 0; i < (int)strlen(abc); i++) { + if (abc[i] >= '0' && abc[i] <= '9') { + num[index++] += abc[i]; + } + } + num[index] = '\0'; + gid_t intgid = atoi(num); + int data; + short int lp; + struct group grp; + struct group *grpptr = &grp; + struct group *tempGrpPtr; + char grpbuffer[200]; + int grplinelen = sizeof(grpbuffer); + data = getgrnam_r("root", grpptr, grpbuffer, grplinelen, &tempGrpPtr); + if (data == intgid) { + successflag = true; + } + } + } + EXPECT_TRUE("getgrgid_r_0100", successflag); + fclose(fptr); + remove("/data/tests/libc-test/src/functionalext/supplement/passwd/pss.txt"); +} + +/** + * @tc.name : getgrnam_r_0200 + * @tc.desc : Verify that the specified group data can be obtained from the group file (parameter invalid) + * @tc.level : Level 2 + */ +void getgrnam_r_0200(void) +{ + int data; + struct group grp; + struct group *grpptr = &grp; + struct group *tempGrpPtr; + char grpbuffer[200]; + int grplinelen = sizeof(grpbuffer); + data = getgrnam_r("root", grpptr, grpbuffer, -1, &tempGrpPtr); + EXPECT_EQ("getgrnam_r_0200", data, 0); +} + +int main() +{ + getgrnam_r_0100(); + getgrnam_r_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/passwd/getgrouplist.c b/libc-test/src/functionalext/supplement/passwd/getgrouplist.c new file mode 100755 index 00000000..62b594ec --- /dev/null +++ b/libc-test/src/functionalext/supplement/passwd/getgrouplist.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" +#include + +/* + * @tc.name : getgrouplist_0100 + * @tc.desc : Verify that the list of group IDs can be obtained (parameters are valid) + * @tc.level : Level 0 + */ +void getgrouplist_0100() +{ + int ngroups; + char who[1024] = {0}; + system("whoami > /data/user.txt"); + FILE *fptr = fopen("/data/user.txt", "r"); + fread(who, sizeof(who), 1, fptr); + + char buffer[1024] = {0}; + system("id -g > /data/id.txt"); + FILE *ptr = fopen("/data/id.txt", "r"); + fread(buffer, sizeof(buffer), 1, ptr); + gid_t id = atoi(buffer); + gid_t gid = getgid(); + int result = getgrouplist(who, gid, &id, &ngroups); + + EXPECT_TRUE("getgrouplist_0100", (result, -1) != 0); +} + +/* + * @tc.name : getgrouplist_0200 + * @tc.desc : Validation cannot get group ID list (parameter invalid) + * @tc.level : Level 2 + */ +void getgrouplist_0200() +{ + int ngroups; + char who[1024] = {0}; + char user[1024] = {0}; + system("whoami > /data/user.txt"); + FILE *fptr = fopen("/data/user.txt", "r"); + fread(who, sizeof(who), 1, fptr); + + char buffer[1204] = {0}; + system("id -g > /data/id.txt"); + FILE *ptr = fopen("/data/id.txt", "r"); + fread(buffer, sizeof(buffer), 1, ptr); + gid_t id = atoi(buffer); + gid_t gid = getgid(); + + int result = getgrouplist(user, gid, &id, &ngroups); + + EXPECT_EQ("getgrouplist_0200", result, -1); + remove("/data/id.txt"); + remove("/data/user.txt"); +} + +int main() +{ + getgrouplist_0100(); + getgrouplist_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/passwd/getpw_r.c b/libc-test/src/functionalext/supplement/passwd/getpw_r.c new file mode 100755 index 00000000..af9d1be5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/passwd/getpw_r.c @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_BUFFER_SIZE 128 + +/** + * @tc.name : getpwuid_r_0100 + * @tc.desc : Get account information based on the current uid + * @tc.level : Level 0 + */ +void getpwuid_r_0100(void) +{ + struct passwd pw; + struct passwd *res = NULL; + char buf[TEST_BUFFER_SIZE]; + + int ret = getpwuid_r(getuid(), &pw, buf, sizeof(buf), &res); + EXPECT_EQ("getpwuid_r_0100", ret, CMPFLAG); + if (!ret) { + EXPECT_EQ("getpwuid_r_0100", pw.pw_uid, getuid()); + } +} + +/** + * @tc.name : getpwuid_r_0200 + * @tc.desc : Incorrect cache size, get account information based on current uid + * @tc.level : Level 2 + */ +void getpwuid_r_0200(void) +{ + struct passwd pw; + struct passwd *res = NULL; + char buf[TEST_BUFFER_SIZE]; + + int ret = getpwuid_r(getuid(), &pw, buf, 1, &res); + EXPECT_EQ("getpwuid_r_0200", ret, ERANGE); +} + +int main(void) +{ + getpwuid_r_0100(); + getpwuid_r_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/passwd/getpwent.c b/libc-test/src/functionalext/supplement/passwd/getpwent.c new file mode 100644 index 00000000..1ac6c79d --- /dev/null +++ b/libc-test/src/functionalext/supplement/passwd/getpwent.c @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" +#define TEST_ERROR_UID 99999999 + +/** + * @tc.name : getpwent_0100 + * @tc.desc : Verify getpwent process success + * @tc.level : Level 0 + */ +void getpwent_0100(void) +{ + struct passwd *user = getpwent(); + EXPECT_PTRNE("getpwent_0100", user, NULL); +} + +/** + * @tc.name : getpwnam_0100 + * @tc.desc : Get account data from password file + * @tc.level : Level 0 + */ +void getpwnam_0100(void) +{ + struct passwd *ret = getpwnam("root"); + EXPECT_PTRNE("getpwnam_0100", ret, NULL); + if (ret) { + EXPECT_STREQ("getpwnam_0100", ret->pw_name, "root"); + EXPECT_EQ("getpwnam_0100", ret->pw_uid, CMPFLAG); + EXPECT_EQ("getpwnam_0100", ret->pw_gid, CMPFLAG); + } +} + +/** + * @tc.name : getpwnam_0200 + * @tc.desc : Retrieve data from password file for non-existing accounts + * @tc.level : Level 2 + */ +void getpwnam_0200(void) +{ + struct passwd *ret = getpwnam("abcdefg"); + EXPECT_PTREQ("getpwnam_0200", ret, NULL); +} + +/** + * @tc.name : getpwuid_0100 + * @tc.desc : Get password file entry by uid + * @tc.level : Level 0 + */ +void getpwuid_0100(void) +{ + struct passwd *ret = getpwuid(getuid()); + EXPECT_PTRNE("getpwuid_0100", ret, NULL); + if (ret) { + EXPECT_EQ("getpwuid_0100", ret->pw_uid, getuid()); + } +} + +/** + * @tc.name : getpwuid_0200 + * @tc.desc : Provide illegal uid to get password file entry + * @tc.level : Level 2 + */ +void getpwuid_0200(void) +{ + struct passwd *ret = getpwuid(TEST_ERROR_UID); + EXPECT_PTREQ("getpwuid_0200", ret, NULL); +} + +int main(void) +{ + getpwent_0100(); + getpwnam_0100(); + getpwnam_0200(); + getpwuid_0100(); + getpwuid_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/passwd/setgrent.c b/libc-test/src/functionalext/supplement/passwd/setgrent.c new file mode 100644 index 00000000..74f671b4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/passwd/setgrent.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "test.h" + +/** + * @tc.name : setgrent_0100 + * @tc.desc : rewinds to the beginning of the group database + * @tc.level : Level 0 + */ +void setgrent_0100(void) +{ + errno = 0; + struct group *result = getgrent(); + if (result == NULL) { + t_error("%s failed: getgrent\n", __func__); + } + + if (errno != 0) { + t_error("%s failed: errno = %ld\n", __func__, errno); + } + + char buf[BUFSIZ] = {0}; + strcpy(buf, result->gr_name); + + setgrent(); + + result = getgrent(); + if (result == NULL) { + t_error("%s failed: getgrent\n", __func__); + } + + if (strcmp(result->gr_name, buf)) { + t_error("%s failed: result->gr_name = %s\n", __func__, result->gr_name); + } +} + +int main(int argc, char *argv[]) +{ + setgrent_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/passwd/setpwent.c b/libc-test/src/functionalext/supplement/passwd/setpwent.c new file mode 100644 index 00000000..ca80fc56 --- /dev/null +++ b/libc-test/src/functionalext/supplement/passwd/setpwent.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "test.h" + +/** + * @tc.name : setpwent_0100 + * @tc.desc : rewinds to the beginning of the password database + * @tc.level : Level 0 + */ +void setpwent_0100(void) +{ + errno = 0; + struct passwd *result = getpwent(); + if (result == NULL) { + t_error("%s failed: getpwent\n", __func__); + } + + if (errno != 0) { + t_error("%s failed: getpwent. errno = %ld\n", __func__, errno); + } + + char buf[BUFSIZ] = {0}; + strcpy(buf, result->pw_name); + + setpwent(); + + result = getpwent(); + if (result == NULL) { + t_error("%s failed: getpwent\n", __func__); + } + + if (strcmp(result->pw_name, buf)) { + t_error("%s failed: result->pw_name = %s\n", __func__, result->pw_name); + } +} + +int main(int argc, char *argv[]) +{ + setpwent_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/passwd/test_src_functionalext_supplement_passwd.gni b/libc-test/src/functionalext/supplement/passwd/test_src_functionalext_supplement_passwd.gni new file mode 100644 index 00000000..44acbab9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/passwd/test_src_functionalext_supplement_passwd.gni @@ -0,0 +1,25 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_passwd_test = [ + "getgrnam", + "getgrgid", + "getpwent", + "setgrent", + "setpwent", + "getpw_r", + "getgrent", + "getgrouplist", + "getgrgid_r", + "getgrnam_r", +] diff --git a/libc-test/src/functionalext/supplement/prng/BUILD.gn b/libc-test/src/functionalext/supplement/prng/BUILD.gn new file mode 100644 index 00000000..33e1d360 --- /dev/null +++ b/libc-test/src/functionalext/supplement/prng/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_prng.gni") + +foreach(s, functionalext_supplement_prng_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/prng" + } +} + +group("functionalext_supplement_prng_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_prng_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/prng/drand48.c b/libc-test/src/functionalext/supplement/prng/drand48.c new file mode 100644 index 00000000..74ef93a5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/prng/drand48.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : drand48_0100 + * @tc.desc : The function call is successful and returns a double random number between [0.0, 1.0). + * @tc.level : Level 0 + */ +void drand48_0100(void) +{ + srand48(1); + double ret = drand48(); + EXPECT_TRUE("drand48_0100", ret >= 0.0 && ret < 1.0); +} + +int main() +{ + drand48_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/prng/erand48.c b/libc-test/src/functionalext/supplement/prng/erand48.c new file mode 100644 index 00000000..86897aa9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/prng/erand48.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : erand48_0100 + * @tc.desc : Verify that a positive random floating-point number is generated (valid argument) + * @tc.level : Level 0 + */ +void erand48_0100(void) +{ + double result = 0; + unsigned short xseed[3] = {1, 2, 3}; + result = erand48(xseed); + EXPECT_TRUE("erand48_0100", result >= 0.0 && result < 1.0); +} + +int main() +{ + erand48_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/prng/lcong48.c b/libc-test/src/functionalext/supplement/prng/lcong48.c new file mode 100644 index 00000000..08b3d8c4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/prng/lcong48.c @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int TWO = 2; +const int THRITYONE = 31; + +/** + * @tc.name : lcong48_0100 + * @tc.desc : Verify lcong48 process success. Set random number seed for 48 bit operation. + * @tc.level : Level 0 + */ +void lcong48_0100(void) +{ + unsigned short p[7] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090a, 0x0b0c, 0x0d0e}; + lcong48(p); + long ret = mrand48(); + EXPECT_TRUE("lcong48_0100", ret < pow(TWO, THRITYONE) && ret > -pow(TWO, THRITYONE)); +} + +int main(void) +{ + lcong48_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/prng/lrand48.c b/libc-test/src/functionalext/supplement/prng/lrand48.c new file mode 100644 index 00000000..4edb88a8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/prng/lrand48.c @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define TEST_NRAND_SIZE 3 +#define TEST_TIMES 10 + +/** + * @tc.name : nrand48_0100 + * @tc.desc : Generate a random number of 10 long integers + * @tc.level : Level 0 + */ +void nrand48_0100(void) +{ + unsigned short s[TEST_NRAND_SIZE] = {1, 2, 3}; + int i, j; + for (i = 0; i < TEST_TIMES; i++) { + for (j = 0; j < TEST_NRAND_SIZE; j++) { + s[j] += i * TEST_TIMES; + } + long rev = nrand48(s); + EXPECT_TRUE("nrand48_0100", rev < pow(2, 31) && rev >= 0); + } +} + +int main(void) +{ + nrand48_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/prng/mrand48.c b/libc-test/src/functionalext/supplement/prng/mrand48.c new file mode 100644 index 00000000..06acaf58 --- /dev/null +++ b/libc-test/src/functionalext/supplement/prng/mrand48.c @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define TEST_JRAND_SIZE 3 +#define TWO 2 +#define THIRTYONE 31 + +/** + * @tc.name : jrand48_0100 + * @tc.desc : Use [1, 2, 3] as parameters to generate a long integer random number + * @tc.level : Level 0 + */ +void jrand48_0100(void) +{ + unsigned short s[TEST_JRAND_SIZE] = {1, 2, 3}; + long rev = jrand48(s); + EXPECT_TRUE("jrand48_0100", rev < pow(TWO, THIRTYONE) && rev > -pow(TWO, THIRTYONE)); +} + +/** + * @tc.name : jrand48_0200 + * @tc.desc : Use [0, 0, 0] as parameters to generate a long integer random number + * @tc.level : Level 0 + */ +void jrand48_0200(void) +{ + unsigned short s[TEST_JRAND_SIZE] = {0, 0, 0}; + long rev = jrand48(s); + EXPECT_EQ("jrand48_0200", rev, 0); +} + +/** + * @tc.name : mrand48_0100 + * @tc.desc : Verify mrand48 process success. Generate a long integer random number + * @tc.level : Level 0 + */ +void mrand48_0100(void) +{ + unsigned short p[7] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090a, 0x0b0c, 0x0d0e}; + lcong48(p); + long ret = mrand48(); + EXPECT_TRUE("mrand48_0100", ret < pow(TWO, THIRTYONE) && ret > -pow(TWO, THIRTYONE)); +} + +int main(void) +{ + mrand48_0100(); + jrand48_0100(); + jrand48_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/prng/rand.c b/libc-test/src/functionalext/supplement/prng/rand.c new file mode 100644 index 00000000..48ee44fb --- /dev/null +++ b/libc-test/src/functionalext/supplement/prng/rand.c @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int32_t SIZE = 5; +const int32_t RANGE = 10; + +/** + * @tc.name : rand_0100 + * @tc.desc : Verify rand process success + * @tc.level : Level 0 + */ +void rand_0100(void) +{ + srand((unsigned int)time(0)); + int i = 0; + for (; i < SIZE; ++i) { + int num = rand() % RANGE; + EXPECT_LT("rand_0100", num, RANGE); + } +} + +int main(void) +{ + rand_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/prng/rand_r.c b/libc-test/src/functionalext/supplement/prng/rand_r.c new file mode 100644 index 00000000..e14fed7e --- /dev/null +++ b/libc-test/src/functionalext/supplement/prng/rand_r.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +unsigned int seed_ = 123; + +/** + * @tc.name : rand_r_0100 + * @tc.desc : The return value obtained by calling rand_d is different when testing different random number seeds + * @tc.level : Level 0 + */ +void rand_r_0100(void) +{ + unsigned int seed = 10; + int a_result = rand_r(&seed); + seed = 200; + int b_result = rand_r(&seed); + if (a_result == b_result) { + t_error("%s rand_r error change seed get result is all %d\n", __func__, a_result); + } +} + +/** + * @tc.name : rand_r_0200 + * @tc.desc : When the test changes the same random number seed, the return value obtained by calling rand_d is + * the same + * @tc.level : Level 1 + */ +void rand_r_0200(void) +{ + unsigned int seed = seed_; + int a_result = rand_r(&seed); + seed = seed_; + int b_result = rand_r(&seed); + if (a_result != b_result) { + t_error("%s rand_r error get result is %d and %d \n", __func__, a_result, b_result); + } +} + +/** + * @tc.name : rand_r_0300 + * @tc.desc : Test that the function return value obtained by calling the rand_d function twice in a row is + * different + * @tc.level : Level 1 + */ +void rand_r_0300(void) +{ + unsigned int seed = 10; + int a_result = rand_r(&seed); + int b_result = rand_r(&seed); + if (a_result == b_result) { + t_error("%s rand_r error change seed get result is all %d\n", __func__, a_result); + } +} + +int main(int argc, char *argv[]) +{ + rand_r_0100(); + rand_r_0200(); + rand_r_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/prng/seed48.c b/libc-test/src/functionalext/supplement/prng/seed48.c new file mode 100644 index 00000000..ece7f341 --- /dev/null +++ b/libc-test/src/functionalext/supplement/prng/seed48.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +unsigned short xsp0 = 0x330e; +unsigned short xsp1 = 0x5432; +unsigned short xsp2 = 0x9876; + +void handler(int sig) +{ + exit(t_status); +} + +/** + * @tc.name : seed48_0100 + * @tc.desc : generate uniformly distributed pseudo-random numbers + * @tc.level : Level 0 + */ +void seed48_0100(void) +{ + long seed = 0x98765432; + srand48(seed); + + unsigned short xs[] = {0x0001, 0x0012, 0x0123}; + unsigned short *xsp = seed48(xs); + if (xsp[0] != xsp0 || xsp[1] != xsp1 || xsp[2] != xsp2) { + t_error("%s failed: xsp[0] = %x, xsp[1] = %x, xsp[2] = %x\n", __func__, xsp[0], xsp[1], xsp[2]); + } + + memcpy(xs, xsp, sizeof(xs)); + seed48(xs); +} + +/** + * @tc.name : seed48_0200 + * @tc.desc : generate uniformly distributed pseudo-random numbers with NULL + * @tc.level : Level 2 + */ +void seed48_0200(void) +{ + signal(SIGSEGV, handler); + + seed48(NULL); +} + +int main(int argc, char *argv[]) +{ + seed48_0100(); + seed48_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/prng/srand.c b/libc-test/src/functionalext/supplement/prng/srand.c new file mode 100644 index 00000000..dc366fd0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/prng/srand.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : srand_0100 + * @tc.desc : Test the srand function to set the random number seed + * @tc.level : Level 0 + */ +void srand_0100(void) +{ + int a[10] = {0}; + int b[10] = {0}; + srand(10); + for (int i = 0; i < 10; i++) { + a[i] = rand(); + } + srand(10); + for (int i = 0; i < 10; i++) { + b[i] = rand(); + } + for (int i = 0; i < 10; i++) { + if (a[i] != b[i]) { + t_error("%s srand rand in %d is %d , %d \n", __func__, i, a[i], b[i]); + } + } +} + +/** + * @tc.name : srand_0200 + * @tc.desc : Change the random number seed + * @tc.level : Level 1 + */ +void srand_0200(void) +{ + int a = 0; + int b = 0; + srand(10); + a = rand(); + srand(500); + b = rand(); + if (a == b) { + t_error("%s srand get rand is %d , %d \n", __func__, a, b); + } +} + +int main(int argc, char *argv[]) +{ + srand_0100(); + srand_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/prng/srand48.c b/libc-test/src/functionalext/supplement/prng/srand48.c new file mode 100644 index 00000000..fa8af8b0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/prng/srand48.c @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : srand48_0100 + * @tc.desc : Verify that the random number can be obtained by calling the srand48 function. + * @tc.level : Level 0 + */ +void srand48_0100(void) +{ + struct srand48_data { + long seed; + double value[5]; + }; + struct srand48_data test_data[2] = { + {1, + {0.0416303447718782138, + 0.454492444728629152, + 0.834817218166914898, + 0.335986030145200232, + 0.565489403566136417}}, + {2, + {0.912432653437466712, + 0.15908290897229449, + 0.573262780710262376, + 0.801506833263324836, + 0.553675300337165055}}, + }; + int i, j; + for (i = 0; i < 2; i++) { + srand48(test_data[i].seed); + for (j = 0; j < 5; j++) { + EXPECT_TRUE("srand48_0100", fabs(drand48() - test_data[i].value[j]) < 0.00000000001); + } + } +} + +int main() +{ + srand48_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/prng/test_src_functionalext_supplement_prng.gni b/libc-test/src/functionalext/supplement/prng/test_src_functionalext_supplement_prng.gni new file mode 100644 index 00000000..564a069e --- /dev/null +++ b/libc-test/src/functionalext/supplement/prng/test_src_functionalext_supplement_prng.gni @@ -0,0 +1,25 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_prng_test = [ + "lcong48", + "rand", + "seed48", + "srand", + "rand_r", + "lrand48", + "mrand48", + "srand48", + "drand48", + "erand48", +] diff --git a/libc-test/src/functionalext/supplement/process/BUILD.gn b/libc-test/src/functionalext/supplement/process/BUILD.gn new file mode 100644 index 00000000..e04e2db3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_process.gni") + +foreach(s, functionalext_supplement_process_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/process" + } +} + +group("functionalext_supplement_process_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_process_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/process/execl.c b/libc-test/src/functionalext/supplement/process/execl.c new file mode 100644 index 00000000..b94016d8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/execl.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int32_t COUNT_NEFATIVE = -1; +int result; + +/** + * @tc.name : execl_0100 + * @tc.desc : The file in the specified directory can be executed + * @tc.level : Level 0 + */ +void execl_0100() +{ + mkdir("/data/tests/libc-test/src/functionalext/supplement/process/test", 0777); + pid_t fpid; + fpid = fork(); + if (fpid == 0) { + result = execl("/bin/ls", "ls", "/data/tests/libc-test/src/functionalext/supplement/process/test/", (char *)0); + } + sleep(1); + EXPECT_NE("execl_0100", result, COUNT_NEFATIVE); +} + +TEST_FUN G_Fun_Array[] = { + execl_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/process/execlp.c b/libc-test/src/functionalext/supplement/process/execlp.c new file mode 100644 index 00000000..c77d4d00 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/execlp.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "functionalext.h" + +/** + * @tc.name : execlp_0100 + * @tc.desc : Each parameter is valid, and the specified file can be executed. + * @tc.level : Level 0 + */ +void execlp_0100(void) +{ + pid_t fpid; + fpid = fork(); + if (fpid == 0) + { + int ret = execlp("touch", "touch", "execlptest.txt", NULL); + } + sleep(1); + + int isExist = access("execlptest.txt", F_OK); + EXPECT_EQ("execlp_0100", isExist, 0); + if (isExist == 0) + { + remove("execlptest.txt"); + } +} + +/** + * @tc.name : execlp_0200 + * @tc.desc : The content pointed to by the file parameter is empty, and the specified file cannot be executed. + * @tc.level : Level 2 + */ +void execlp_0200(void) +{ + int ret = execlp(" ", "touch", "execlptest.txt", NULL); + EXPECT_EQ("execlp_0200", ret, -1); +} + +/** + * @tc.name : execlp_0300 + * @tc.desc : The length of file exceeds NAME_MAX, and the specified file cannot be executed. + * @tc.level : Level 2 + */ +void execlp_0300(void) +{ + char buff[300]; + for (int i = 0; i < 300; i++) + { + buff[i] = 'a'; + } + int ret = execlp(buff, "touch", "execlptest.txt", NULL); + EXPECT_EQ("execlp_0300", ret, -1); +} + +int main() +{ + execlp_0100(); + execlp_0200(); + execlp_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/process/execv.c b/libc-test/src/functionalext/supplement/process/execv.c new file mode 100644 index 00000000..dec6ac1b --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/execv.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "functionalext.h" + +/** + * @tc.name : execv_0100 + * @tc.desc : Each parameter is valid, and the specified file can be executed. + * @tc.level : Level 0 + */ +void execv_0100(void) +{ + pid_t fpid; + fpid = fork(); + FILE *fp; + if (fpid == 0) + { + char *argv[] = {"touch", "touch", "execvtest.txt", NULL}; + int ret = execv("/bin/touch", argv); + } + sleep(1); + int isExist = access("execvtest.txt", F_OK); + EXPECT_EQ("execv_0100", isExist, 0); + if (isExist == 0) + { + remove("execvtest.txt"); + } +} + +/** + * @tc.name : execv_0200 + * @tc.desc : The content pointed to by the path parameter is empty, and the specified file cannot be executed. + * @tc.level : Level 2 + */ +void execv_0200(void) +{ + char *argv[] = {"touch", "touch", "execvtest.txt", NULL}; + int ret = execv(" ", argv); + EXPECT_TRUE("execv_0200", ret == -1); +} + +/** + * @tc.name : execv_0300 + * @tc.desc : The length of path exceeds NAME_MAX, and the specified file cannot be executed. + * @tc.level : Level 2 + */ +void execv_0300(void) +{ + char buff[300]; + for (int i = 0; i < 300; i++) + { + buff[i] = 'a'; + } + char *argv[] = {"touch", "touch", "execvtest.txt", NULL}; + int ret = execv(buff, argv); + EXPECT_TRUE("execv_0300", ret == -1); +} + +int main() +{ + execv_0100(); + execv_0200(); + execv_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/process/execve.c b/libc-test/src/functionalext/supplement/process/execve.c new file mode 100644 index 00000000..ff494fde --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/execve.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "functionalext.h" + +char *my_env[] = {0, NULL}; + +/** + * @tc.name : execve_0100 + * @tc.desc : Each parameter is valid, and the specified file can be executed. + * @tc.level : Level 0 + */ +void execve_0100(void) +{ + pid_t fpid; + fpid = fork(); + if (fpid == 0) { + char *argv[] = {"touch", "execvetest.txt", NULL}; + execve("/bin/touch", argv, my_env); + } + sleep(1); + int isExist = access("execvetest.txt", F_OK); + EXPECT_EQ("execve_0100", isExist, 0); + if (isExist == 0) { + remove("execvetest.txt"); + } +} + +/** + * @tc.name : execve_0200 + * @tc.desc : The content pointed to by the path parameter is empty, and the specified file cannot be executed. + * @tc.level : Level 2 + */ +void execve_0200(void) +{ + char *argv[] = {"touch", "execvetest.txt", NULL}; + int ret = execve(" ", argv, my_env); + EXPECT_EQ("execve_0200", ret, -1); +} + +/** + * @tc.name : execve_0300 + * @tc.desc : The length of path exceeds NAME_MAX, and the specified file cannot be executed. + * @tc.level : Level 2 + */ +void execve_0300(void) +{ + char buff[300]; + for (int i = 0; i < 300; i++) { + buff[i] = 'a'; + } + char *argv[] = {"touch", "execvetest.txt", NULL}; + int ret = execve(buff, argv, my_env); + EXPECT_EQ("execve_0300", ret, -1); +} + +int main() +{ + execve_0100(); + execve_0200(); + execve_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/process/execvp.c b/libc-test/src/functionalext/supplement/process/execvp.c new file mode 100644 index 00000000..ffd5c766 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/execvp.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : execvp_0100 + * @tc.desc : Each parameter is valid, and the specified file can be executed. + * @tc.level : Level 0 + */ +void execvp_0100(void) +{ + pid_t fpid; + fpid = fork(); + if (fpid == 0) { + char *argv[] = {"touch", "execvptest.txt", NULL}; + execvp("touch", argv); + } + sleep(1); + int isExist = access("execvptest.txt", F_OK); + EXPECT_EQ("execvp_0100", isExist, 0); + if (isExist == 0) { + remove("execvptest.txt"); + } +} + +/** + * @tc.name : execvp_0200 + * @tc.desc : Each parameter is valid, the PATH is empty, and the specified file can be executed. + * @tc.level : Level 0 + */ +void execvp_0200(void) +{ + pid_t fpid; + fpid = fork(); + if (fpid == 0) { + char *argv[] = {"touch", "execvptest.txt", NULL}; + char *buff = getenv("ls"); + setenv("ls", " ", 1); + execvp("touch", argv); + setenv("ls", buff, 1); + } + sleep(1); + int isExist = access("execvptest.txt", F_OK); + EXPECT_EQ("execvp_0200", isExist, 0); + if (isExist == 0) { + remove("execvptest.txt"); + } +} + +/** + * @tc.name : execvp_0300 + * @tc.desc : The content pointed to by the path parameter is empty, and the specified file cannot be executed. + * @tc.level : Level 2 + */ +void execvp_0300(void) +{ + char *argv[] = {"touch", "execvptest.txt", NULL}; + int ret = execvp(" ", argv); + EXPECT_EQ("execvp_0300", ret, -1); +} + +/** + * @tc.name : execvp_0400 + * @tc.desc : The length of path exceeds NAME_MAX, and the specified file cannot be executed. + * @tc.level : Level 2 + */ +void execvp_0400(void) +{ + char buff[300]; + for (int i = 0; i < 300; i++) { + buff[i] = 'a'; + } + char *argv[] = {"touch", "execvptest.txt", NULL}; + int ret = execvp(buff, argv); + EXPECT_EQ("execvp_0400", ret, -1); +} + +int main() +{ + execvp_0100(); + execvp_0200(); + execvp_0300(); + execvp_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/process/execvpe.c b/libc-test/src/functionalext/supplement/process/execvpe.c new file mode 100644 index 00000000..76b9376a --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/execvpe.c @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_NEGATIVE = -1; +char *my_env[] = {"THIS=environment will be", "PASSED=to new process by", "the EXEC=functions", NULL}; +int result_1; +int result_2; + +/** + * @tc.name : execvpe_0100 + * @tc.desc : Verify that the specified file can be executed + * (all parameters are valid, PATH is not empty by default) + * @tc.level : Level 0 + */ +void execvpe_0100(void) +{ + bool flag = false; + char *path; + path = getenv("touch"); + pid_t fpid; + fpid = fork(); + if (fpid == 0) { + char *argv[] = {"touch", "touch", "/data/test.txt", 0}; + result_1 = execvpe("touch", argv, &path); + } + sleep(1); + FILE *fptr = fopen("/data/test.txt", "r"); + if (fptr != NULL) { + flag = true; + } + EXPECT_NE("execvpe_0100", result_1, COUNT_NEGATIVE); + EXPECT_TRUE("execvpe_0100", flag); + fclose(fptr); + remove("/data/test.txt"); +} + +/** + * @tc.name : execvpe_0200 + * @tc.desc : Verify that the specified file can be executed (all parameters are valid, PATH is null) + * @tc.level : Level 0 + */ +void execvpe_0200(void) +{ + bool flag = false; + char *path = getenv("touch"); + setenv("touch", "\0", 1); + pid_t fpid; + fpid = fork(); + if (fpid == 0) { + char *argv[] = {"touch", "touch", "/data/test.txt", 0}; + result_2 = execvpe("touch", argv, &path); + } + sleep(1); + FILE *fptr = fopen("/data/test.txt", "r"); + if (fptr != NULL) { + flag = true; + } + fclose(fptr); + remove("/data/test.txt"); + EXPECT_NE("execvpe_0200", result_2, COUNT_NEGATIVE); + EXPECT_TRUE("execvpe_0200", flag); + unsetenv("touch"); +} + +/** + * @tc.name : execvpe_0300 + * @tc.desc : Verify that the specified file cannot be executed (file argument is invalid, file + * argument points to NULL) + * @tc.level : Level 2 + */ +void execvpe_0300(void) +{ + int result; + char buff[] = "\0"; + char *argv[] = {"ls", "-al", "/etc/passwd", 0}; + result = execvpe(buff, argv, my_env); + EXPECT_EQ("execvpe_0300", result, COUNT_NEGATIVE); +} + +/** + * @tc.name : execvpe_0400 + * @tc.desc : Verify that the specified file cannot be executed (file argument is invalid, file + * length exceeds NAME_MAX) + * @tc.level : Level 2 + */ +void execvpe_0400(void) +{ + int result; + char *argv[] = {"ls", "-al", "/etc/passwd", 0}; + char buff[300]; + for (int i = 0; i < 300; i++) { + buff[i] = 'a'; + } + result = execvpe(buff, argv, my_env); + EXPECT_EQ("execvpe_0400", result, COUNT_NEGATIVE); +} + +int main() +{ + execvpe_0100(); + execvpe_0200(); + execvpe_0300(); + execvpe_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/process/fexecve.c b/libc-test/src/functionalext/supplement/process/fexecve.c new file mode 100644 index 00000000..1c261c0f --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/fexecve.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : fexecve_0100 + * @tc.desc : Each parameter is valid, the fexecve function can execute the specified file. + * @tc.level : Level 0 + */ +void fexecve_0100(void) +{ + pid_t fpid; + fpid = fork(); + if (fpid == 0) { + char *argv[] = {"./fexecverely", NULL}; + char *environ[] = {0, NULL}; + int fd = open("fexecverely", O_RDONLY, 0777); + int ret = fexecve(fd, argv, environ); + EXPECT_NE("fexecve_0100", ret, -1); + } + sleep(1); +} + +/** + * @tc.name : fexecve_0200 + * @tc.desc : The fd parameter is invalid (NULL), the fexecve function cannot execute the specified file. + * @tc.level : Level 2 + */ +void fexecve_0200(void) +{ + char *my_env[] = {NULL}; + char *argv[] = {"touch", "fexecvetest.txt", NULL}; + int ret = fexecve(-1, argv, my_env); + EXPECT_EQ("fexecve_0200", ret, -1); +} + +int main() +{ + fexecve_0100(); + fexecve_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/process/fexecverely.c b/libc-test/src/functionalext/supplement/process/fexecverely.c new file mode 100644 index 00000000..78add69c --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/fexecverely.c @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +int main() +{ + uid_t uid = getuid(); + EXPECT_EQ("fexecverely", uid, getuid()); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/process/fork.c b/libc-test/src/functionalext/supplement/process/fork.c new file mode 100644 index 00000000..717b1fe0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/fork.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : fork_0100 + * @tc.desc : The function call is successful and the process can be created + * @tc.level : Level 0 + */ +void fork_0100() +{ + pid_t fpid; + int count = 0; + fpid = fork(); + char *sign_r = "1"; + char *sign_f = "0"; + char list1[2]; + char list2[2]; + FILE *fp; + if (fpid < 0) { + printf("error in fork!"); + } else if (fpid == 0) { + fp = fopen("test1.txt", "w+"); + fwrite(sign_r, sizeof(char), strlen(sign_r), fp); + fclose(fp); + } else { + fp = fopen("test2.txt", "w+"); + fwrite(sign_r, sizeof(char), strlen(sign_r), fp); + fclose(fp); + } + sleep(1); + FILE *fp1 = fopen("test1.txt", "r"); + FILE *fp2 = fopen("test2.txt", "r"); + fread(list1, sizeof(list1), 1, fp1); + fread(list2, sizeof(list2), 1, fp2); + EXPECT_EQ("fork_0100", list1[0], '1'); + EXPECT_EQ("fork_0100", list2[0], '1'); + fclose(fp1); + fclose(fp2); + remove("test1.txt"); + remove("test2.txt"); +} + +int main() +{ + fork_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/process/posix_spawn.c b/libc-test/src/functionalext/supplement/process/posix_spawn.c new file mode 100755 index 00000000..484ab8ea --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/posix_spawn.c @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : posix_spawn_0100 + * @tc.desc : Use the default process attributes, create a subprocess and + * execute shell commands, which are input from outside + * @tc.level : Level 0 + */ +void posix_spawn_0100(char *cmd) +{ + pid_t pid; + char *argv[] = {"sh", "-c", cmd, NULL}; + int ret = posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, NULL); + EXPECT_EQ("posix_spawn_0100", ret, CMPFLAG); + if (ret != 0) { + t_error("posix_spawn create failed\n"); + return; + } + wait(NULL); +} + +/** + * @tc.name : posix_spawn_0200 + * @tc.desc : Add SIGCHLD to the signal set, create a subprocess and + * execute shell commands, which are input from outside + * @tc.level : Level 0 + */ +void posix_spawn_0200(char *cmd) +{ + pid_t pid; + sigset_t def; + posix_spawnattr_t attr; + char *argv[] = {"sh", "-c", cmd, NULL}; + int ret = posix_spawnattr_init(&attr); + + ret = sigemptyset(&def); + ret = sigaddset(&def, SIGCHLD); + if (ret == ERREXPECT) { + EXPECT_NE("posix_spawn_0200", ret, ERREXPECT); + return; + } + + ret = posix_spawnattr_setsigdefault(&attr, &def); + posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK); + + ret = posix_spawn(&pid, "/bin/sh", NULL, &attr, argv, NULL); + EXPECT_EQ("posix_spawn_0200", ret, CMPFLAG); + if (ret != 0) { + t_error("posix_spawn create failed\n"); + return; + } + + wait(NULL); + posix_spawnattr_destroy(&attr); +} + +/** + * @tc.name : posix_spawn_0300 + * @tc.desc : Set process attributes, create subprocesses and execute shell + * commands, which are input externally + * @tc.level : Level 0 + */ +void posix_spawn_0300(char *cmd) +{ + pid_t pid; + sigset_t def; + posix_spawnattr_t attr; + char *argv[] = {"sh", "-c", cmd, NULL}; + int ret = posix_spawnattr_init(&attr); + + posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF); + + ret = posix_spawn(&pid, "/bin/sh", NULL, &attr, argv, NULL); + EXPECT_EQ("posix_spawn_0300", ret, CMPFLAG); + if (ret != 0) { + t_error("posix_spawn create failed\n"); + return; + } + + wait(NULL); + posix_spawnattr_destroy(&attr); +} + +/** + * @tc.name : posix_spawn_0400 + * @tc.desc : Create a child process and execute a non-existing file in the current + * directory, the process creation fails + * @tc.level : Level 2 + */ +void posix_spawn_0400(void) +{ + pid_t pid; + + int ret = posix_spawn(&pid, "unexitfile", NULL, NULL, NULL, NULL); + EXPECT_NE("posix_spawn_0400", ret, CMPFLAG); + if (ret != 0) { + return; + } + waitpid(pid, NULL, WNOHANG); +} + +int main(int argc, char *argv[]) +{ + if (argc > 1) { + posix_spawn_0100(argv[1]); + posix_spawn_0200(argv[1]); + posix_spawn_0300(argv[1]); + posix_spawn_0400(); + } + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/process/posix_spawn_file_actions_addopen.c b/libc-test/src/functionalext/supplement/process/posix_spawn_file_actions_addopen.c new file mode 100755 index 00000000..596c3810 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/posix_spawn_file_actions_addopen.c @@ -0,0 +1,106 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : posix_spawn_file_actions_addopen_0100 + * @tc.desc : Set the behavior property of the open file to the spawn file actions object + * @tc.level : Level 0 + */ +void posix_spawn_file_actions_addopen_0100(void) +{ + posix_spawn_file_actions_t fa; + struct fdop *ptr = NULL; + + posix_spawn_file_actions_init(&fa); + + int fd = 10; + int ret = posix_spawn_file_actions_addopen(&fa, fd, "/data", O_RDWR | O_CREAT, S_IXGRP); + EXPECT_EQ("posix_spawn_file_actions_addopen_0100", ret, CMPFLAG); + if (ret == 0) { + ptr = (struct fdop *)fa.__actions; + EXPECT_EQ("posix_spawn_file_actions_addopen_0100", ptr->cmd, FDOP_OPEN); + EXPECT_EQ("posix_spawn_file_actions_addopen_0100", ptr->fd, fd); + EXPECT_EQ("posix_spawn_file_actions_addopen_0100", ptr->oflag, O_RDWR | O_CREAT); + EXPECT_EQ("posix_spawn_file_actions_addopen_0100", ptr->mode, S_IXGRP); + EXPECT_STREQ("posix_spawn_file_actions_addopen_0100", ptr->path, "/data"); + } + + posix_spawn_file_actions_destroy(&fa); +} + +/** + * @tc.name : posix_spawn_file_actions_addopen_0200 + * @tc.desc : Set the behavior property of the open file to the spawn file actions object + * @tc.level : Level 0 + */ +void posix_spawn_file_actions_addopen_0200(void) +{ + posix_spawn_file_actions_t fa; + struct fdop *ptr = NULL; + int fd = 10; + posix_spawn_file_actions_init(&fa); + int ret = posix_spawn_file_actions_addopen(&fa, fd, "/data", O_RDONLY | O_CREAT, S_IXGRP | S_IROTH | S_IWOTH); + EXPECT_EQ("posix_spawn_file_actions_addopen_0200", ret, CMPFLAG); + if (ret == 0) { + ptr = (struct fdop *)fa.__actions; + EXPECT_EQ("posix_spawn_file_actions_addopen_0200", ptr->cmd, FDOP_OPEN); + EXPECT_EQ("posix_spawn_file_actions_addopen_0200", ptr->fd, fd); + EXPECT_EQ("posix_spawn_file_actions_addopen_0200", ptr->oflag, O_RDONLY | O_CREAT); + EXPECT_EQ("posix_spawn_file_actions_addopen_0200", ptr->mode, S_IXGRP | S_IROTH | S_IWOTH); + EXPECT_STREQ("posix_spawn_file_actions_addopen_0200", ptr->path, "/data"); + } + + ret = posix_spawn_file_actions_destroy(&fa); +} + +/** + * @tc.name : posix_spawn_file_actions_addopen_0300 + * @tc.desc : Set the behavior property of the open file to the spawn file actions object + * @tc.level : Level 0 + */ +void posix_spawn_file_actions_addopen_0300(void) +{ + posix_spawn_file_actions_t fa; + struct fdop *ptr = NULL; + int fd = 10; + posix_spawn_file_actions_init(&fa); + int ret = posix_spawn_file_actions_addopen(&fa, fd, "/data", O_WRONLY | O_CREAT, S_IXGRP | S_IROTH | S_IWOTH); + EXPECT_EQ("posix_spawn_file_actions_addopen_0300", ret, CMPFLAG); + if (ret == 0) { + ptr = (struct fdop *)fa.__actions; + EXPECT_EQ("posix_spawn_file_actions_addopen_0300", ptr->cmd, FDOP_OPEN); + EXPECT_EQ("posix_spawn_file_actions_addopen_0300", ptr->fd, fd); + EXPECT_EQ("posix_spawn_file_actions_addopen_0300", ptr->oflag, O_WRONLY | O_CREAT); + EXPECT_EQ("posix_spawn_file_actions_addopen_0300", ptr->mode, S_IXGRP | S_IROTH | S_IWOTH); + EXPECT_STREQ("posix_spawn_file_actions_addopen_0300", ptr->path, "/data"); + } + + ret = posix_spawn_file_actions_destroy(&fa); +} + +int main(void) +{ + posix_spawn_file_actions_addopen_0100(); + posix_spawn_file_actions_addopen_0200(); + posix_spawn_file_actions_addopen_0300(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/process/posix_spawnattr_getflags.c b/libc-test/src/functionalext/supplement/process/posix_spawnattr_getflags.c new file mode 100755 index 00000000..66a8d3ac --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/posix_spawnattr_getflags.c @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : posix_spawnattr_getflags_0100 + * @tc.desc : Get the flags of spawn attr + * @tc.level : Level 0 + */ +void posix_spawnattr_getflags_0100(void) +{ + posix_spawnattr_t spawnattr; + short flags = POSIX_SPAWN_RESETIDS; + short getvalue = 0; + int ret = posix_spawnattr_init(&spawnattr); + ret = posix_spawnattr_setflags(&spawnattr, flags); + ret = posix_spawnattr_getflags(&spawnattr, &getvalue); + EXPECT_EQ("posix_spawnattr_getflags_0100", ret, CMPFLAG); + EXPECT_EQ("posix_spawnattr_getflags_0100", getvalue, POSIX_SPAWN_RESETIDS); + posix_spawnattr_destroy(&spawnattr); +} + +int main(void) +{ + posix_spawnattr_getflags_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/process/posix_spawnattr_getpgroup.c b/libc-test/src/functionalext/supplement/process/posix_spawnattr_getpgroup.c new file mode 100755 index 00000000..c4ffd9ab --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/posix_spawnattr_getpgroup.c @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : posix_spawnattr_getflags_0100 + * @tc.desc : Get the process group of spawn attr + * @tc.level : Level 0 + */ +void posix_spawnattr_getpgroup_0100(void) +{ + posix_spawnattr_t spawnattr; + pid_t group = 1312; + pid_t getvalue = -1; + int ret = posix_spawnattr_init(&spawnattr); + ret = posix_spawnattr_setpgroup(&spawnattr, group); + ret = posix_spawnattr_getpgroup(&spawnattr, &getvalue); + EXPECT_EQ("posix_spawnattr_getpgroup_0100", ret, CMPFLAG); + EXPECT_EQ("posix_spawnattr_getpgroup_0100", getvalue, group); + posix_spawnattr_destroy(&spawnattr); +} + +int main(void) +{ + posix_spawnattr_getpgroup_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/process/posix_spawnattr_getsigdefault.c b/libc-test/src/functionalext/supplement/process/posix_spawnattr_getsigdefault.c new file mode 100755 index 00000000..4e475e61 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/posix_spawnattr_getsigdefault.c @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : posix_spawnattr_getsigdefault_0100 + * @tc.desc : get the sigal number of spawn attr(success) + * @tc.level : Level 0 + */ +void posix_spawnattr_getsigdefault_0100(void) +{ + posix_spawnattr_t spawnattr; + sigset_t def; + sigset_t getdef; + + int ret = sigemptyset(&def); + ret = sigemptyset(&getdef); + ret = sigaddset(&def, SIGCHLD); + if (ret == ERREXPECT) { + EXPECT_NE("posix_spawnattr_getsigdefault_0100", ret, ERREXPECT); + return; + } + + posix_spawnattr_init(&spawnattr); + ret = posix_spawnattr_setsigdefault(&spawnattr, &def); + + ret = posix_spawnattr_getsigdefault(&spawnattr, &getdef); + EXPECT_EQ("posix_spawnattr_getsigdefault_0100", ret, CMPFLAG); + EXPECT_NE("posix_spawnattr_getsigdefault_0100", sigismember(&getdef, SIGCHLD), CMPFLAG); + posix_spawnattr_destroy(&spawnattr); +} + +int main(void) +{ + posix_spawnattr_getsigdefault_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/process/posix_spawnattr_getsigmask.c b/libc-test/src/functionalext/supplement/process/posix_spawnattr_getsigmask.c new file mode 100755 index 00000000..6c74b5f1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/posix_spawnattr_getsigmask.c @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : posix_spawnattr_getsigmask_0100 + * @tc.desc : get the sigal number of spawn attr(success) + * @tc.level : Level 0 + */ +void posix_spawnattr_getsigmask_0100(void) +{ + posix_spawnattr_t spawnattr; + sigset_t def; + sigset_t getdef; + + int ret = sigemptyset(&def); + ret = sigemptyset(&getdef); + ret = sigaddset(&def, SIGCHLD); + if (ret == ERREXPECT) { + EXPECT_NE("posix_spawnattr_getsigmask_0100", ret, ERREXPECT); + return; + } + + posix_spawnattr_init(&spawnattr); + ret = posix_spawnattr_setsigmask(&spawnattr, &def); + + ret = posix_spawnattr_getsigmask(&spawnattr, &getdef); + EXPECT_EQ("posix_spawnattr_getsigmask_0100", ret, CMPFLAG); + EXPECT_NE("posix_spawnattr_getsigmask_0100", sigismember(&getdef, SIGCHLD), CMPFLAG); + posix_spawnattr_destroy(&spawnattr); +} + +int main(void) +{ + posix_spawnattr_getsigmask_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/process/posix_spawnattr_setflags.c b/libc-test/src/functionalext/supplement/process/posix_spawnattr_setflags.c new file mode 100755 index 00000000..34d6fa7e --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/posix_spawnattr_setflags.c @@ -0,0 +1,76 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : posix_spawnattr_setflags_0100 + * @tc.desc : set the flags of spawn attr(success) + * @tc.level : Level 0 + */ +void posix_spawnattr_setflags_0100(void) +{ + posix_spawnattr_t spawnattr; + + int ret = posix_spawnattr_init(&spawnattr); + ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_RESETIDS); + EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG); + ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_SETPGROUP); + EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG); + ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_SETSIGDEF); + EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG); + ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_SETSIGMASK); + EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG); + ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_SETSCHEDPARAM); + EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG); + ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_SETSCHEDULER); + EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG); + ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_USEVFORK); + EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG); + ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_SETSID); + EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG); + + ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_SETSID | POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP); + EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG); + + posix_spawnattr_destroy(&spawnattr); +} + +/** + * @tc.name : posix_spawnattr_setflags_0200 + * @tc.desc : set the flags of spawn attr(failed) + * @tc.level : Level 2 + */ +void posix_spawnattr_setflags_0200(void) +{ + posix_spawnattr_t spawnattr; + short overflow = 256; + int ret = posix_spawnattr_init(&spawnattr); + ret = posix_spawnattr_setflags(&spawnattr, overflow); + EXPECT_EQ("posix_spawnattr_setflags_0200", ret, EINVAL); + + posix_spawnattr_destroy(&spawnattr); +} + +int main(void) +{ + posix_spawnattr_setflags_0100(); + posix_spawnattr_setflags_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/process/posix_spawnattr_setpgroup.c b/libc-test/src/functionalext/supplement/process/posix_spawnattr_setpgroup.c new file mode 100755 index 00000000..bdf8514a --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/posix_spawnattr_setpgroup.c @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : posix_spawnattr_setpgroup_0100 + * @tc.desc : set the process group of spawn attr(success) + * @tc.level : Level 0 + */ +void posix_spawnattr_setpgroup_0100(void) +{ + posix_spawnattr_t spawnattr; + pid_t group = 1153; + int ret = posix_spawnattr_init(&spawnattr); + ret = posix_spawnattr_setpgroup(&spawnattr, group); + EXPECT_EQ("posix_spawnattr_setpgroup_0100", ret, CMPFLAG); + posix_spawnattr_destroy(&spawnattr); +} + +int main(void) +{ + posix_spawnattr_setpgroup_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/process/posix_spawnattr_setsigdefault.c b/libc-test/src/functionalext/supplement/process/posix_spawnattr_setsigdefault.c new file mode 100755 index 00000000..413f8edc --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/posix_spawnattr_setsigdefault.c @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : posix_spawnattr_setsigdefault_0100 + * @tc.desc : set the sigal number of spawn attr(success) + * @tc.level : Level 0 + */ +void posix_spawnattr_setsigdefault_0100(void) +{ + posix_spawnattr_t spawnattr; + sigset_t def; + + int ret = sigemptyset(&def); + ret = sigaddset(&def, SIGCHLD); + if (ret == ERREXPECT) { + EXPECT_NE("posix_spawnattr_setsigdefault_0100", ret, ERREXPECT); + return; + } + posix_spawnattr_init(&spawnattr); + ret = posix_spawnattr_setsigdefault(&spawnattr, &def); + EXPECT_EQ("posix_spawnattr_setsigdefault_0100", ret, CMPFLAG); + posix_spawnattr_destroy(&spawnattr); +} + +int main(void) +{ + posix_spawnattr_setsigdefault_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/process/posix_spawnattr_setsigmask.c b/libc-test/src/functionalext/supplement/process/posix_spawnattr_setsigmask.c new file mode 100755 index 00000000..9c16a713 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/posix_spawnattr_setsigmask.c @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : posix_spawnattr_setsigmask_0100 + * @tc.desc : get the sigal number of spawn attr(success) + * @tc.level : Level 0 + */ +void posix_spawnattr_setsigmask_0100(void) +{ + posix_spawnattr_t spawnattr; + sigset_t def; + + int ret = sigemptyset(&def); + ret = sigaddset(&def, SIGCHLD); + if (ret == ERREXPECT) { + EXPECT_NE("posix_spawnattr_setsigmask_0100", ret, ERREXPECT); + return; + } + posix_spawnattr_init(&spawnattr); + ret = posix_spawnattr_setsigmask(&spawnattr, &def); + EXPECT_EQ("posix_spawnattr_setsigmask_0100", ret, CMPFLAG); + posix_spawnattr_destroy(&spawnattr); +} + +int main(void) +{ + posix_spawnattr_setsigmask_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/process/posix_spawnp.c b/libc-test/src/functionalext/supplement/process/posix_spawnp.c new file mode 100755 index 00000000..01d2d4fd --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/posix_spawnp.c @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : posix_spawnp_0100 + * @tc.desc : Use the default process attributes, create a subprocess and + * execute shell commands, which are input from outside + * @tc.level : Level 0 + */ +void posix_spawnp_0100(char *cmd) +{ + pid_t pid; + char *argv[] = {"sh", "-c", cmd, NULL}; + int ret = posix_spawnp(&pid, "/bin/sh", NULL, NULL, argv, NULL); + EXPECT_EQ("posix_spawnp_0100", ret, CMPFLAG); + if (ret != 0) { + t_error("posix_spawnp create child process failed\n"); + return; + } + wait(NULL); +} + +/** + * @tc.name : posix_spawnp_0200 + * @tc.desc : Add SIGCHLD to the signal set, create a subprocess and + * execute shell commands, which are input from outside + * @tc.level : Level 0 + */ +void posix_spawnp_0200(char *cmd) +{ + pid_t pid; + sigset_t def; + posix_spawnattr_t attr; + char *argv[] = {"sh", "-c", cmd, NULL}; + int ret = posix_spawnattr_init(&attr); + + ret = sigemptyset(&def); + ret = sigaddset(&def, SIGCHLD); + if (ret == ERREXPECT) { + EXPECT_NE("posix_spawnp_0200", ret, ERREXPECT); + return; + } + + ret = posix_spawnattr_setsigdefault(&attr, &def); + posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK); + + ret = posix_spawnp(&pid, "/bin/sh", NULL, &attr, argv, NULL); + EXPECT_EQ("posix_spawnp_0200", ret, CMPFLAG); + if (ret != 0) { + t_error("posix_spawnp create child process failed\n"); + return; + } + + wait(NULL); + posix_spawnattr_destroy(&attr); +} + +/** + * @tc.name : posix_spawnp_0300 + * @tc.desc : Set process attributes, create subprocesses and execute shell + * commands, which are input externally + * @tc.level : Level 0 + */ +void posix_spawnp_0300(char *cmd) +{ + pid_t pid; + sigset_t def; + posix_spawnattr_t attr; + char *argv[] = {"sh", "-c", cmd, NULL}; + int ret = posix_spawnattr_init(&attr); + + posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF); + + ret = posix_spawnp(&pid, "/bin/sh", NULL, &attr, argv, NULL); + EXPECT_EQ("posix_spawnp_0300", ret, CMPFLAG); + if (ret != 0) { + t_error("posix_spawnp create child process failed\n"); + return; + } + + wait(NULL); + posix_spawnattr_destroy(&attr); +} + +/** + * @tc.name : posix_spawnp_0400 + * @tc.desc : Create a child process and execute a non-existing file in the current + * directory, the process creation fails + * @tc.level : Level 2 + */ +void posix_spawnp_0400(void) +{ + pid_t pid; + + int ret = posix_spawnp(&pid, "unexitfile", NULL, NULL, NULL, NULL); + EXPECT_NE("posix_spawnp_0400", ret, CMPFLAG); + if (ret != 0) { + return; + } + waitpid(pid, NULL, WNOHANG); +} + +int main(int argc, char *argv[]) +{ + if (argc > 1) { + posix_spawnp_0100(argv[1]); + posix_spawnp_0200(argv[1]); + posix_spawnp_0300(argv[1]); + posix_spawnp_0400(); + } + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/process/system.c b/libc-test/src/functionalext/supplement/process/system.c new file mode 100644 index 00000000..0c220f55 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/system.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +/** + * @tc.name : system_0100 + * @tc.desc : execute a shell command + * @tc.level : Level 0 + */ +void system_0100(void) +{ + sighandler_t handler = signal(SIGCHLD, SIG_DFL); + + int result = system("cd /"); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + signal(SIGCHLD, handler); +} + +/** + * @tc.name : system_0200 + * @tc.desc : execute a shell command with NULL + * @tc.level : Level 2 + */ +void system_0200(void) +{ + int result = system(NULL); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + system_0100(); + system_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/process/test_src_functionalext_supplement_process.gni b/libc-test/src/functionalext/supplement/process/test_src_functionalext_supplement_process.gni new file mode 100644 index 00000000..9367de09 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/test_src_functionalext_supplement_process.gni @@ -0,0 +1,39 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_process_test = [ + "system", + "waitpid", + "wait", + "waitid", + "execl", + "execvpe", + "fork", + "execlp", + "execv", + "execve", + "execvp", + "fexecve", + "fexecverely", + "posix_spawn", + "posix_spawn_file_actions_addopen", + "posix_spawnattr_getflags", + "posix_spawnattr_getpgroup", + "posix_spawnattr_getsigdefault", + "posix_spawnattr_getsigmask", + "posix_spawnattr_setflags", + "posix_spawnattr_setpgroup", + "posix_spawnattr_setsigdefault", + "posix_spawnattr_setsigmask", + "posix_spawnp", +] diff --git a/libc-test/src/functionalext/supplement/process/vfork.c b/libc-test/src/functionalext/supplement/process/vfork.c new file mode 100644 index 00000000..ccfc5983 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/vfork.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : vfork_0100 + * @tc.desc : The parent process will execute after the child process exits, and the two share memory space + * @tc.level : Level 0 + */ +void vfork_0100() +{ + int a = 1; + int b = 2; + + pid_t pid; + pid = vfork(); + + if (pid < 0) { + t_error("%s vfork failed\n", __func__); + } else if (pid == 0) { + sleep(1); + printf("child\n"); + a = 10; + b = 20; + _exit(0); + } else if (pid > 0) { + if (a == 1 || b == 2) { + t_error("%s failed, a is %d, b is %d\n", __func__, a, b); + } + } +} + +int main() +{ + vfork_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/process/wait.c b/libc-test/src/functionalext/supplement/process/wait.c new file mode 100644 index 00000000..bf766c26 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/wait.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +const int WAIT_TIME = 2; + +/** + * @tc.name : wait_0100 + * @tc.desc : Test the wait function to wait for the child process + * @tc.level : Level 0 + */ +void wait_0100(void) +{ + pid_t pid = fork(); + if (pid > 0) { + int flag = 0; + pid_t wait_for_pind = wait(&flag); + if (wait_for_pind != pid) { + t_error("%s wait get pid is %d are not want %d\n", __func__, wait_for_pind, pid); + } + if (flag != 0) { + t_error("%s wait get status is not 0\n", __func__); + } + } else if (pid == 0) { + sleep(1); + exit(0); + } else { + t_error("%s wait fork error\n"); + } +} + +/** + * @tc.name : wait_0200 + * @tc.desc : Test the result of the wait function when the exit code of the child process is not 0 + * @tc.level : Level 1 + */ +void wait_0200(void) +{ + pid_t pid = fork(); + if (pid > 0) { + int flag = 0; + pid_t wait_for_pind = wait(&flag); + if (wait_for_pind != pid) { + t_error("%s wait get pid is %d are not want %d\n", __func__, wait_for_pind, pid); + } + if (flag == 0) { + t_error("%s wait get status is not 0\n", __func__); + } + } else if (pid == 0) { + sleep(1); + exit(66); + } else { + t_error("%s wait fork error\n"); + } +} + +int main(int argc, char *argv[]) +{ + wait_0100(); + sleep(WAIT_TIME); + wait_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/process/waitid.c b/libc-test/src/functionalext/supplement/process/waitid.c new file mode 100644 index 00000000..f188f534 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/waitid.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : waitid_0100 + * @tc.desc : Test waitid function for process control + * @tc.level : Level 0 + */ +void waitid_0100(void) +{ + pid_t pid = fork(); + if (pid == -1) { + t_error("%s waitid fork error\n", __func__); + } + if (pid == 0) + _exit(66); + siginfo_t si = {}; + int result = waitid(P_PID, pid, &si, WEXITED); + if (result != 0) { + t_error("%s waitid error get result is %d are not want 0\n", __func__, result); + } + if (pid != si.si_pid) { + t_error("%s waitid error pid not = si.si_pid\n", __func__); + } + if (si.si_status != 66) { + t_error("%s waitid error si.si_status not = 66\n", __func__); + } + if (si.si_code != CLD_EXITED) { + t_error("%s waitid error si.si_code not = CLD_EXITED\n", __func__); + } +} + +int main(int argc, char *argv[]) +{ + waitid_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/process/waitpid.c b/libc-test/src/functionalext/supplement/process/waitpid.c new file mode 100644 index 00000000..df8b31a4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/process/waitpid.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : waitpid_0100 + * @tc.desc : Test the waitpid function to waitpid for the child process + * @tc.level : Level 0 + */ +void waitpid_0100(void) +{ + pid_t pid = fork(); + if (pid > 0) { + int status = 0; + int options = 0; + pid_t waitpid_for_pind = waitpid(pid, &status, options); + if (waitpid_for_pind != pid) { + t_error("%s waitpid get pid is %d are not want %d\n", __func__, waitpid_for_pind, pid); + } + if (status != 0) { + t_error("%s waitpid get status is %d are not 0\n", __func__, status); + } + } else if (pid == 0) { + sleep(1); + exit(0); + } else { + t_error("%s waitpid fork error\n"); + } +} + +/** + * @tc.name : waitpid_0200 + * @tc.desc : Test the result of the waitpid function when the exit code of the child process is not 0 + * @tc.level : Level 1 + */ +void waitpid_0200(void) +{ + pid_t pid = fork(); + if (pid > 0) { + int status = 0; + int options = 0; + pid_t waitpid_for_pind = waitpid(pid, &status, options); + if (waitpid_for_pind != pid) { + t_error("%s waitpid get pid is %d are not want %d\n", __func__, waitpid_for_pind, pid); + } + if (status == 0) { + t_error("%s waitpid get status is 0\n", __func__); + } + } else if (pid == 0) { + sleep(1); + exit(66); + } else { + t_error("%s waitpid fork error\n"); + } +} + +int main(int argc, char *argv[]) +{ + waitpid_0100(); + sleep(2); + waitpid_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/regex/BUILD.gn b/libc-test/src/functionalext/supplement/regex/BUILD.gn new file mode 100644 index 00000000..1641bfe5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/regex/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_regex.gni") + +foreach(s, functionalext_supplement_regex_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/regex" + } +} + +group("functionalext_supplement_regex_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_regex_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/regex/glob.c b/libc-test/src/functionalext/supplement/regex/glob.c new file mode 100644 index 00000000..ac1dbbe8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/regex/glob.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : glob_0100 + * @tc.desc : Verify glob process success + * @tc.level : Level 0 + */ +void glob_0100(void) +{ + glob_t buf; + int ret = glob("./*", GLOB_NOSORT, NULL, &buf); + EXPECT_EQ("glob_0100", ret, 0); + globfree(&buf); +} + +/** + * @tc.name : glob_0200 + * @tc.desc : Verify glob process fail. when no found matches + * @tc.level : Level 2 + */ +void glob_0200(void) +{ + glob_t buf; + int ret = glob("./does-not-match", GLOB_NOSORT, NULL, &buf); + EXPECT_EQ("glob_0100", ret, GLOB_NOMATCH); + globfree(&buf); +} + +int main(void) +{ + glob_0100(); + glob_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/regex/test_src_functionalext_supplement_regex.gni b/libc-test/src/functionalext/supplement/regex/test_src_functionalext_supplement_regex.gni new file mode 100644 index 00000000..56ddc4f7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/regex/test_src_functionalext_supplement_regex.gni @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_regex_test = [ "glob" ] diff --git a/libc-test/src/functionalext/supplement/sched/BUILD.gn b/libc-test/src/functionalext/supplement/sched/BUILD.gn new file mode 100755 index 00000000..0a03e975 --- /dev/null +++ b/libc-test/src/functionalext/supplement/sched/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_sched.gni") + +foreach(s, functionalext_supplement_sched_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/sched" + } +} + +group("functionalext_supplement_sched_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_sched_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/sched/__sched_cpucount.c b/libc-test/src/functionalext/supplement/sched/__sched_cpucount.c new file mode 100755 index 00000000..81e26f26 --- /dev/null +++ b/libc-test/src/functionalext/supplement/sched/__sched_cpucount.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/* + * @tc.name : __sched_cpucount_0100 + * @tc.desc : Each parameter value is valid, and the number of CPUs included in the collection can be obtained. + * @tc.level : Level 0 + */ +void __sched_cpucount_0100(void) +{ + int ret = 0; + cpu_set_t *cpusetp; + size_t size; + int num_cpus; + num_cpus = sysconf(_SC_NPROCESSORS_CONF); + cpusetp = CPU_ALLOC(num_cpus); + if (cpusetp == NULL) { + perror("CPU_ALLOC"); + exit(EXIT_FAILURE); + } + size = CPU_ALLOC_SIZE(num_cpus); + CPU_ZERO_S(size, cpusetp); + for (int cpu = 0; cpu < num_cpus; cpu++) { + CPU_SET_S(cpu, size, cpusetp); + } + ret = __sched_cpucount(size, cpusetp); + EXPECT_EQ("__sched_cpucount_0100", ret, num_cpus); + CPU_FREE(cpusetp); +} + +/* + * @tc.name : __sched_cpucount_0200 + * @tc.desc : The size parameter is invalid (0), the set parameter is valid, and the number of CPUs + * contained in the set cannot be obtained. + * @tc.level : Level 2 + */ +void __sched_cpucount_0200(void) +{ + int ret = 0; + cpu_set_t *cpusetp; + size_t size; + int num_cpus; + num_cpus = sysconf(_SC_NPROCESSORS_CONF); + cpusetp = CPU_ALLOC(num_cpus); + if (cpusetp == NULL) { + perror("CPU_ALLOC"); + exit(EXIT_FAILURE); + } + size = CPU_ALLOC_SIZE(num_cpus); + CPU_ZERO_S(size, cpusetp); + for (int cpu = 0; cpu < num_cpus; cpu++) { + CPU_SET_S(cpu, size, cpusetp); + } + ret = __sched_cpucount(0, cpusetp); + EXPECT_EQ("__sched_cpucount_0200", ret, 0); + CPU_FREE(cpusetp); +} + +/* + * @tc.name : __sched_cpucount_0300 + * @tc.desc : The size parameter is valid, the set parameter is invalid (null), and the number of CPUs + * contained in the set cannot be obtained. + * @tc.level : Level 2 + */ +void __sched_cpucount_0300(void) +{ + int ret = 0; + cpu_set_t *cpusetp; + size_t size; + int num_cpus; + num_cpus = sysconf(_SC_NPROCESSORS_CONF); + cpusetp = CPU_ALLOC(num_cpus); + if (cpusetp == NULL) { + perror("CPU_ALLOC"); + exit(EXIT_FAILURE); + } + size = CPU_ALLOC_SIZE(num_cpus); + CPU_ZERO_S(size, cpusetp); + ret = __sched_cpucount(size, cpusetp); + EXPECT_EQ("__sched_cpucount_0300", ret, 0); + CPU_FREE(cpusetp); +} + +int main() +{ + __sched_cpucount_0100(); + __sched_cpucount_0200(); + __sched_cpucount_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/sched/sched_getaffinity.c b/libc-test/src/functionalext/supplement/sched/sched_getaffinity.c new file mode 100644 index 00000000..7041f724 --- /dev/null +++ b/libc-test/src/functionalext/supplement/sched/sched_getaffinity.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/* + * @tc.name : sched_getaffinity_0100 + * @tc.desc : Get cpu affinity + * @tc.level : Level 1 + */ +void sched_getaffinity_0100(void) +{ + cpu_set_t mask; + cpu_set_t get; + + CPU_ZERO(&mask); + CPU_SET(0, &mask); + + int result = sched_setaffinity(0, sizeof(mask), &mask); + if (result == -1) { + t_error("%s failed to set cpu affinity\n", __func__); + } + + CPU_ZERO(&get); + result = sched_getaffinity(0, sizeof(get), &get); + if (result == -1) { + t_error("%s sched_getaffinity failed\n", __func__); + } + + if (!CPU_ISSET(0, &get)) { + t_error("%s getaffinity is not 0\n", __func__); + } +} + +int main(int argc, char *argv[]) +{ + sched_getaffinity_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/sched/sched_getcpu.c b/libc-test/src/functionalext/supplement/sched/sched_getcpu.c new file mode 100644 index 00000000..d6302c3f --- /dev/null +++ b/libc-test/src/functionalext/supplement/sched/sched_getcpu.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/* + * @tc.name : sched_getcpu_0100 + * @tc.desc : Determine CPU on which the calling thread is running + * @tc.level : Level 0 + */ +void sched_getcpu_0100(void) +{ + errno = 0; + int result = sched_getcpu(); + if (result == -1) { + t_error("%s sched_getcpu failed\n", __func__); + } + if (errno != 0) { + t_error("%s errno is %d\n", errno); + } +} + +int main(int argc, char *argv[]) +{ + sched_getcpu_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/sched/sched_rr_get_interval.c b/libc-test/src/functionalext/supplement/sched/sched_rr_get_interval.c new file mode 100644 index 00000000..585bd4ce --- /dev/null +++ b/libc-test/src/functionalext/supplement/sched/sched_rr_get_interval.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +/** + * @tc.name : sched_rr_get_interval_0100 + * @tc.desc : get the SCHED_RR interval for the named process + * @tc.level : Level 0 + */ +void sched_rr_get_interval_0100(void) +{ + pid_t pid = getpid(); + struct timespec ts = {0}; + + errno = 0; + int result = sched_rr_get_interval(pid, &ts); + if (result != 0 || errno != 0) { + t_error("%s failed: result = %d\n", __func__, result); + t_error("%s failed: errno = %d\n", __func__, errno); + } + + if (ts.tv_sec < 0 || ts.tv_nsec < 0) { + t_error("%s failed: ts.tv_sec = %ld\n", __func__, ts.tv_sec); + t_error("%s failed: ts.tv_nsec = %ld\n", __func__, ts.tv_nsec); + } +} + +/** + * @tc.name : sched_rr_get_interval_0200 + * @tc.desc : get the SCHED_RR interval for an invalid process + * @tc.level : Level 2 + */ +void sched_rr_get_interval_0200(void) +{ + pid_t pid = -1; + struct timespec ts = {0}; + + errno = 0; + int result = sched_rr_get_interval(pid, &ts); + if (result == 0 || errno == 0) { + t_error("%s failed: result = %d\n", __func__, result); + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + sched_rr_get_interval_0100(); + sched_rr_get_interval_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/sched/sched_setaffinity.c b/libc-test/src/functionalext/supplement/sched/sched_setaffinity.c new file mode 100644 index 00000000..c9d7b323 --- /dev/null +++ b/libc-test/src/functionalext/supplement/sched/sched_setaffinity.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/* + * @tc.name : sched_setaffinity_0100 + * @tc.desc : Invalid cpu set size + * @tc.level : Level 0 + */ +void sched_setaffinity_0100(void) +{ + errno = 0; + int max = sysconf(_SC_NPROCESSORS_CONF) + 1; + cpu_set_t *set = CPU_ALLOC(max); + if (set == NULL) { + t_error("%s failed, set is NULL", __func__); + } + + size_t set_size = CPU_ALLOC_SIZE(max); + CPU_ZERO_S(set_size, set); + CPU_SET_S(max, set_size, set); + + int result = sched_setaffinity(0, set_size, set); + if (result != -1) { + t_error("%s affinity mask does not trigger an error", __func__); + } + + if (errno != EINVAL) { + t_error("%s errno is %d", __func__, errno); + } +} + +/* + * @tc.name : sched_setaffinity_0100 + * @tc.desc : Set cpu affinity + * @tc.level : Level 1 + */ +void sched_setaffinity_0200(void) +{ + cpu_set_t mask; + cpu_set_t get; + + CPU_ZERO(&mask); + CPU_SET(0, &mask); + + int result = sched_setaffinity(0, sizeof(mask), &mask); + if (result == -1) { + t_error("%s failed to set cpu affinity\n", __func__); + } + + CPU_ZERO(&get); + result = sched_getaffinity(0, sizeof(get), &get); + if (result == -1) { + t_error("%s sched_getaffinity failed\n", __func__); + } + + if (!CPU_ISSET(0, &get)) { + t_error("%s getaffinity is not 0\n", __func__); + } +} + +int main(int argc, char *argv[]) +{ + sched_setaffinity_0100(); + sched_setaffinity_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/sched/sched_yield.c b/libc-test/src/functionalext/supplement/sched/sched_yield.c new file mode 100644 index 00000000..cd837a06 --- /dev/null +++ b/libc-test/src/functionalext/supplement/sched/sched_yield.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/* + * @tc.name : sched_yield_0100 + * @tc.desc : Verify sched_yield process success + * @tc.level : Level 0 + */ +void sched_yield_0100(void) +{ + int ret = sched_yield(); + EXPECT_EQ("sched_yield_0100", ret, 0); +} + +int main(int argc, char *argv[]) +{ + sched_yield_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/sched/test_src_functionalext_supplement_sched.gni b/libc-test/src/functionalext/supplement/sched/test_src_functionalext_supplement_sched.gni new file mode 100644 index 00000000..66a5e2f1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/sched/test_src_functionalext_supplement_sched.gni @@ -0,0 +1,21 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_sched_test = [ + "__sched_cpucount", + "sched_rr_get_interval", + "sched_getaffinity", + "sched_getcpu", + "sched_setaffinity", + "sched_yield", +] diff --git a/libc-test/src/functionalext/supplement/search/BUILD.gn b/libc-test/src/functionalext/supplement/search/BUILD.gn new file mode 100644 index 00000000..87a9f044 --- /dev/null +++ b/libc-test/src/functionalext/supplement/search/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_search.gni") + +foreach(s, functionalext_supplement_search_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/search" + } +} + +group("functionalext_supplement_search_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_search_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/search/hcreate_r.c b/libc-test/src/functionalext/supplement/search/hcreate_r.c new file mode 100644 index 00000000..7d839308 --- /dev/null +++ b/libc-test/src/functionalext/supplement/search/hcreate_r.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const size_t SIZE = 2; + +/** + * @tc.name : hcreate_r_0100 + * @tc.desc : Verify hcreate_r process success + * @tc.level : Level 0 + */ +void hcreate_r_0100(void) +{ + struct hsearch_data h_data = {}; + int ret; + EXPECT_NE("hcreate_r_0100", hcreate_r(SIZE, &h_data), 0); + hdestroy_r(&h_data); +} + +/** + * @tc.name : hcreate_r_0200 + * @tc.desc : Verify hcreate_r process fail + * @tc.level : Level 2 + */ +void hcreate_r_0200(void) +{ + struct hsearch_data h_data = {}; + EXPECT_EQ("hcreate_r_0200", hcreate_r(-1, &h_data), 0); +} + +int main(void) +{ + hcreate_r_0100(); + hcreate_r_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/search/hdestroy.c b/libc-test/src/functionalext/supplement/search/hdestroy.c new file mode 100644 index 00000000..cbea92d7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/search/hdestroy.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const size_t SIZE = 2; + +/** + * @tc.name : hdestroy_0100 + * @tc.desc : Verify hdestroy process success + * @tc.level : Level 0 + */ +void hdestroy_0100(void) +{ + struct hsearch_data h_data = {}; + int ret; + EXPECT_NE("hdestroy_0100", hcreate(SIZE), 0); + hdestroy(); +} + +int main(void) +{ + hdestroy_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/search/hsearch_r.c b/libc-test/src/functionalext/supplement/search/hsearch_r.c new file mode 100644 index 00000000..cc3d70e9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/search/hsearch_r.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const size_t SIZE = 2; +static char *data[] = {"hsearch_r_0100", "hsearch_r_0200"}; + +/** + * @tc.name : hsearch_r_0100 + * @tc.desc : Verify hsearch_r process success + * @tc.level : Level 0 + */ +void hsearch_r_0100(void) +{ + struct hsearch_data h_data = {}; + int ret; + EXPECT_NE("hsearch_r_0100", hcreate_r(SIZE, &h_data), 0); + ENTRY e, *ep; + for (int i = 0; i < SIZE; i++) { + e.key = data[i]; + e.data = (void *)&i; + ret = hsearch_r(e, ENTER, &ep, &h_data); + EXPECT_NE("hsearch_r_0100", ret, 0); + } + hdestroy_r(&h_data); +} + +/** + * @tc.name : hsearch_r_0200 + * @tc.desc : Verify hsearch_r process success + * @tc.level : Level 2 + */ +void hsearch_r_0200(void) +{ + struct hsearch_data h_data = {}; + int ret; + EXPECT_NE("hsearch_r_0100", hcreate_r(SIZE, &h_data), 0); + ENTRY e, *ep; + for (int i = 0; i < SIZE; i++) { + e.key = data[i]; + ret = hsearch_r(e, FIND, &ep, &h_data); + EXPECT_EQ("hsearch_r_0100", ret, 0); + } + hdestroy_r(&h_data); +} + +int main(void) +{ + hsearch_r_0100(); + hsearch_r_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/search/lfind.c b/libc-test/src/functionalext/supplement/search/lfind.c new file mode 100644 index 00000000..a9b03b64 --- /dev/null +++ b/libc-test/src/functionalext/supplement/search/lfind.c @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int KEY = 10; +const int LENGTH1 = 10; +const int LENGTH2 = 5; + +int compare(int *x, int *y) +{ + return (*x - *y); +} + +/** + * @tc.name : lfind_0100 + * @tc.desc : Verify lfind process success. + * @tc.level : level 0. + */ +void lfind_0100(void) +{ + int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + size_t nlength = LENGTH1; + int key; + int *ret; + key = KEY; + ret = lfind(&key, array, &nlength, sizeof(int), (int (*)(const void *, const void *))compare); + EXPECT_NE("lfind_0100", *ret, 0); +} + +/** + * @tc.name : lfind. + * @tc.desc : Verify lfind process fail because key not is array. + * @tc.level : level 2. + */ +void lfind_0200(void) +{ + int array[5] = {1, 2, 3, 4, 5}; + size_t nlength = LENGTH2; + int key; + int *ret; + key = 0; + ret = lfind(&key, array, &nlength, sizeof(int), (int (*)(const void *, const void *))compare); + EXPECT_PTREQ("lfind_0200", ret, NULL); +} + +int main(void) +{ + lfind_0100(); + lfind_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/search/tdestroy.c b/libc-test/src/functionalext/supplement/search/tdestroy.c new file mode 100644 index 00000000..57423b8f --- /dev/null +++ b/libc-test/src/functionalext/supplement/search/tdestroy.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +#define ARRAY_SIZE (10) +static void *root = NULL; +static int g_free_calls = 0; + +void *malloc_node(unsigned n) +{ + void *p; + p = malloc(n); + if (p) { + return p; + } + fprintf(stderr, "insufficient memory\n"); + exit(EXIT_FAILURE); +} + +int cmp_node(const void *pa, const void *pb) +{ + if (*(int *)pa < *(int *)pb) { + return -1; + } + if (*(int *)pa > *(int *)pb) { + return 1; + } + return 0; +} + +void node_free(void *p) +{ + free(p); + g_free_calls++; +} + +/** + * @tc.name : tdestroy_0100 + * @tc.desc : Removes the whole tree pointed to by root + * @tc.level : Level 0 + */ +void tdestroy_0100(void) +{ + int i, *ptr, *target; + void *val, *result; + int array[ARRAY_SIZE] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + + for (i = 0; i < ARRAY_SIZE; i++) { + ptr = malloc_node(sizeof(int)); + *ptr = array[i]; + val = tsearch((void *)ptr, &root, cmp_node); + if (val == NULL) { + exit(EXIT_FAILURE); + + } else if ((*(int **)val) != ptr) { + free(ptr); + } + } + + tdestroy(root, node_free); + if (g_free_calls != ARRAY_SIZE) { + t_error("%s tdestroy failed, g_free_calls is %d\n", __func__, g_free_calls); + } +} + +int main(int argc, char *argv[]) +{ + tdestroy_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/search/test_src_functionalext_supplement_search.gni b/libc-test/src/functionalext/supplement/search/test_src_functionalext_supplement_search.gni new file mode 100644 index 00000000..b2ff79cd --- /dev/null +++ b/libc-test/src/functionalext/supplement/search/test_src_functionalext_supplement_search.gni @@ -0,0 +1,20 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_search_test = [ + "hcreate_r", + "hdestroy", + "hsearch_r", + "lfind", + "tdestroy", +] diff --git a/libc-test/src/functionalext/supplement/select/BUILD.gn b/libc-test/src/functionalext/supplement/select/BUILD.gn new file mode 100755 index 00000000..85005590 --- /dev/null +++ b/libc-test/src/functionalext/supplement/select/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_select.gni") + +foreach(s, functionalext_supplement_select_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/select" + } +} + +group("functionalext_supplement_select_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_select_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/select/poll.c b/libc-test/src/functionalext/supplement/select/poll.c new file mode 100755 index 00000000..14c86656 --- /dev/null +++ b/libc-test/src/functionalext/supplement/select/poll.c @@ -0,0 +1,167 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int32_t COUNT_FAILED = -1; + +/* + * @tc.name : poll_0100 + * @tc.desc : Verify the attribute changes of the monitored file descriptor (timeout parameter is greater than 0) + * @tc.level : Level 0 + */ +void poll_0100(void) +{ + int fd, ret; + unsigned char key_val; + struct pollfd fds[1]; + fd = open("/data/test.txt", O_RDWR | O_CREAT); + if (fd < 0) { + fputs("open r is failed\n", stdout); + } + fds[0].fd = fd; + fds[0].events = POLLIN; + ret = poll(fds, 1, 2000); + bool flag = false; + if (ret >= 0) { + flag = true; + } + EXPECT_TRUE("poll_0100", flag); + close(fd); + remove("/data/test.txt"); +} + +/* + * @tc.name : poll_0200 + * @tc.desc : Verify the attribute changes of the monitored file descriptor (timeout parameter is equal to 0) + * @tc.level : Level 1 + */ +void poll_0200(void) +{ + int fd, ret; + unsigned char key_val; + struct pollfd fds[1]; + fd = open("/data/test.txt", O_RDWR | O_CREAT); + if (fd < 0) { + fputs("open r is failed\n", stdout); + } + fds[0].fd = fd; + fds[0].events = POLLIN; + ret = poll(fds, 1, 0); + bool flag = false; + if (ret >= 0) { + flag = true; + } + EXPECT_TRUE("poll_0200", flag); + close(fd); + remove("/data/test.txt"); +} + +/* + * @tc.name : poll_0300 + * @tc.desc : Verify the attribute changes of the monitored file descriptor (timeout parameter is less than 0) + * @tc.level : Level 1 + */ +void poll_0300(void) +{ + int fd, ret; + unsigned char key_val; + struct pollfd fds[1]; + fd = open("/data/test.txt", O_RDWR | O_CREAT); + if (fd < 0) { + fputs("open r is failed\n", stdout); + } + fds[0].fd = fd; + fds[0].events = POLLIN; + ret = poll(fds, 1, -1); + bool flag = false; + if (ret > 0) { + flag = true; + } + EXPECT_TRUE("poll_0300", flag); + close(fd); + remove("/data/test.txt"); +} + +/* + * @tc.name : poll_0400 + * @tc.desc : Verify that the attribute changes of the monitored file descriptor (fds parameter NULL) + * @tc.level : Level 2 + */ +void poll_0400(void) +{ + int fd, ret; + unsigned char key_val; + struct pollfd fds[1]; + fd = open("/data/test.txt", O_RDWR | O_CREAT); + if (fd < 0) { + fputs("open r is failed\n", stdout); + } + fds[0].fd = fd; + fds[0].events = POLLIN; + ret = poll(NULL, 1, 0); + EXPECT_EQ("poll_0400", ret, COUNT_FAILED); + close(fd); + remove("/data/test.txt"); +} + +/* + * @tc.name : poll_0500 + * @tc.desc : Validate the attribute changes of the monitored file descriptor (n parameter -1) + * @tc.level : Level 2 + */ +void poll_0500(void) +{ + int fd, ret; + unsigned char key_val; + struct pollfd fds[1]; + fd = open("/data/test.txt", O_RDWR | O_CREAT); + if (fd < 0) { + fputs("open r is failed\n", stdout); + } + fds[0].fd = fd; + fds[0].events = POLLIN; + ret = poll(fds, -1, 2000); + EXPECT_EQ("poll_0500", ret, COUNT_FAILED); + close(fd); + remove("/data/test.txt"); +} + +TEST_FUN G_Fun_Array[] = { + poll_0100, + poll_0200, + poll_0300, + poll_0400, + poll_0500, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/select/pselect.c b/libc-test/src/functionalext/supplement/select/pselect.c new file mode 100755 index 00000000..34e03a57 --- /dev/null +++ b/libc-test/src/functionalext/supplement/select/pselect.c @@ -0,0 +1,116 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : pselect_fdset_0100 + * @tc.desc : Determine whether the fdset macro is normal + * @tc.level : Level 0 + */ +void pselect_fdset_0100(void) +{ + fd_set set; + FD_ZERO(&set); + for (size_t i = 0; i < 1024; ++i) { + EXPECT_FALSE("pselect_fdset_0100", FD_ISSET(i, &set)); + } + FD_SET(STDIN_FILENO, &set); + EXPECT_TRUE("pselect_fdset_0100", FD_ISSET(STDIN_FILENO, &set)); + EXPECT_FALSE("pselect_fdset_0100", FD_ISSET(STDOUT_FILENO, &set)); + FD_SET(STDOUT_FILENO, &set); + EXPECT_TRUE("pselect_fdset_0100", FD_ISSET(STDIN_FILENO, &set)); + EXPECT_TRUE("pselect_fdset_0100", FD_ISSET(STDOUT_FILENO, &set)); + FD_CLR(STDIN_FILENO, &set); + EXPECT_FALSE("pselect_fdset_0100", FD_ISSET(STDIN_FILENO, &set)); + EXPECT_TRUE("pselect_fdset_0100", FD_ISSET(STDOUT_FILENO, &set)); + FD_CLR(STDOUT_FILENO, &set); + EXPECT_FALSE("pselect_fdset_0100", FD_ISSET(STDIN_FILENO, &set)); + EXPECT_FALSE("pselect_fdset_0100", FD_ISSET(STDOUT_FILENO, &set)); +} + +/** + * @tc.name : pselect_normal_0100 + * @tc.desc : Monitor stdout file for writability (normal) + * @tc.level : Level 0 + */ +void pselect_normal_0100(void) +{ + fd_set set; + struct timespec timeout; + timeout.tv_sec = 5; + timeout.tv_nsec = 0; + FD_ZERO(&set); + FD_SET(STDOUT_FILENO, &set); + + int ret = pselect(STDOUT_FILENO + 1, NULL, &set, NULL, &timeout, NULL); + EXPECT_EQ("pselect_normal_0100", ret, 1); + EXPECT_TRUE("pselect_normal_0100", FD_ISSET(STDOUT_FILENO, &set)); +} + +/** + * @tc.name : pselect_error_0100 + * @tc.desc : Incoming illegal file descriptor size to monitor stdout file writability + * @tc.level : Level 2 + */ +void pselect_error_0100(void) +{ + fd_set set; + struct timespec timeout; + timeout.tv_sec = 5; + timeout.tv_nsec = 0; + FD_ZERO(&set); + FD_SET(STDOUT_FILENO, &set); + + int ret = pselect(-1, NULL, &set, NULL, &timeout, NULL); + EXPECT_EQ("pselect_error_0100", ret, ERREXPECT); +} + +/** + * @tc.name : pselect_timeout_0100 + * @tc.desc : Monitor stdout file for readability (timeout) + * @tc.level : Level 2 + */ +void pselect_timeout_0100(void) +{ + fd_set set; + sigset_t sigmask; + struct timespec timeout; + timeout.tv_sec = 2; + timeout.tv_nsec = 0; + FD_ZERO(&set); + FD_SET(STDOUT_FILENO, &set); + sigemptyset(&sigmask); + sigaddset(&sigmask, SIGINT); + int ret = pselect(STDOUT_FILENO + 1, &set, NULL, NULL, &timeout, &sigmask); + if (ret == 0) { + EXPECT_FALSE("pselect_timeout_0100", FD_ISSET(STDOUT_FILENO, &set)); + } +} + +int main(void) +{ + pselect_fdset_0100(); + pselect_normal_0100(); + pselect_error_0100(); + pselect_timeout_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/select/select.c b/libc-test/src/functionalext/supplement/select/select.c new file mode 100755 index 00000000..94bbf5ce --- /dev/null +++ b/libc-test/src/functionalext/supplement/select/select.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; +const int32_t COUNT_FAILED = -1; + +/** + * @tc.name : select_0100 + * @tc.desc : Verify that the monitoring descriptor is successful (valid parameters) + * @tc.level : Level 0 + */ +void select_0100(void) +{ + struct timeval timeout; + timeout.tv_sec = 5; + timeout.tv_usec = 0; + fd_set readfds, writefds; + FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_SET(0, &readfds); + FD_SET(1, &writefds); + int result; + result = select(2, &readfds, &writefds, 0, &timeout); + EXPECT_TRUE("select_0100", result > 0); +} + +/** + * @tc.name : select_0200 + * @tc.desc : Failed to validate monitoring descriptor + * (invalid parameter, microsecond invalid value in timeout structure) + * @tc.level : Level 2 + */ +void select_0200(void) +{ + struct timeval timeout; + timeout.tv_sec = -50; + fd_set readfds, writefds; + FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_SET(0, &readfds); + FD_SET(1, &writefds); + int result; + result = select(2, &readfds, &writefds, 0, &timeout); + EXPECT_EQ("select_0200", result, COUNT_FAILED); +} + +/** + * @tc.name : select_0300 + * @tc.desc : Validation monitoring descriptor failed + * (invalid parameter, invalid parameter added to descriptor set) + * @tc.level : Level 1 + */ +void select_0300(void) +{ + struct timeval timeout; + timeout.tv_sec = 0; + fd_set readfds, writefds; + int fd1, fd2; + FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_SET(2, &readfds); + FD_SET(2, &writefds); + int result; + result = select(2, &readfds, &writefds, 0, &timeout); + EXPECT_EQ("select_0300", result, COUNT_ZERO); +} + +int main(void) +{ + select_0100(); + select_0200(); + select_0300(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/select/test_src_functionalext_supplement_select.gni b/libc-test/src/functionalext/supplement/select/test_src_functionalext_supplement_select.gni new file mode 100644 index 00000000..98deaee7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/select/test_src_functionalext_supplement_select.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_select_test = [ + "poll", + "pselect", + "select", +] diff --git a/libc-test/src/functionalext/supplement/setjmp/BUILD.gn b/libc-test/src/functionalext/supplement/setjmp/BUILD.gn new file mode 100644 index 00000000..530d0f06 --- /dev/null +++ b/libc-test/src/functionalext/supplement/setjmp/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_setjmp.gni") + +foreach(s, functionalext_supplement_setjmp_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/setjmp" + } +} + +group("functionalext_supplement_setjmp_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_setjmp_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/setjmp/_longjmp.c b/libc-test/src/functionalext/supplement/setjmp/_longjmp.c new file mode 100644 index 00000000..ff28bbfc --- /dev/null +++ b/libc-test/src/functionalext/supplement/setjmp/_longjmp.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +static jmp_buf buf; +bool FLAG = false; +void second() +{ + longjmp(buf, 1); +} +void first() +{ + FLAG = true; + second(); + FLAG = false; +} + +/** + * @tc.name : _longjmp_0100 + * @tc.desc : Verify that jumps between functions can be achieved + * @tc.level : Level 0 + */ +void _longjmp_0100(void) +{ + if (!setjmp(buf)) { + first(); + } else { + EXPECT_TRUE("_longjmp_0100", FLAG); + } +} + +int main() +{ + _longjmp_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/setjmp/_setjmp.c b/libc-test/src/functionalext/supplement/setjmp/_setjmp.c new file mode 100644 index 00000000..e42dc6aa --- /dev/null +++ b/libc-test/src/functionalext/supplement/setjmp/_setjmp.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +bool FLAG = false; +static jmp_buf envbuf; +void second() +{ + FLAG = true; + longjmp(envbuf, 5); +} +void first() +{ + FLAG = false; + second(); + FLAG = false; +} + +/** + * @tc.name : _setjmp_0100 + * @tc.desc : Verify that jumps between functions can be achieved + * @tc.level : Level 0 + */ +void _setjmp_0100(void) +{ + if (setjmp(envbuf) == 0) { + first(); + } else { + EXPECT_TRUE("_setjmp_0100", FLAG); + } +} + +int main() +{ + _setjmp_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/setjmp/test_src_functionalext_supplement_setjmp.gni b/libc-test/src/functionalext/supplement/setjmp/test_src_functionalext_supplement_setjmp.gni new file mode 100644 index 00000000..a7fd7c31 --- /dev/null +++ b/libc-test/src/functionalext/supplement/setjmp/test_src_functionalext_supplement_setjmp.gni @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_setjmp_test = [ + "_setjmp", + "_longjmp", +] diff --git a/libc-test/src/functionalext/supplement/signal/BUILD.gn b/libc-test/src/functionalext/supplement/signal/BUILD.gn new file mode 100644 index 00000000..751f7ea9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_signal.gni") + +foreach(s, functionalext_supplement_signal_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/signal" + } +} + +group("functionalext_supplement_signal_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_signal_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/signal/getitimer.c b/libc-test/src/functionalext/supplement/signal/getitimer.c new file mode 100644 index 00000000..0a995eb1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/getitimer.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include +#include "functionalext.h" + +static int count = 0; +void expireTimer(int signo) +{ + struct itimerval val; + count++; + if (count > 1) { + getitimer(signo, &val); + val.it_value.tv_sec = 0; + val.it_value.tv_usec = 0; + setitimer(signo, &val, NULL); + count = 0; + } +} + +void signalHandler(int signo) +{ + switch (signo) { + case SIGALRM: + printf("catch a SIGALRM signal\n"); + expireTimer(signo); + break; + case SIGVTALRM: + printf("catch a SIGVTALRM signal\n"); + break; + case SIGPROF: + printf("catch a SIGPROF signal\n"); + break; + default: + printf("no signal\n"); + break; + } +} + +/** + * @tc.name : getitimer_0100 + * @tc.desc : Verify the value of the interval timer (parameter is ITIMER_REAL) + * @tc.level : Level 0 + */ +void getitimer_0100(void) +{ + signal(SIGALRM, signalHandler); + struct itimerval old; + int result = getitimer(ITIMER_REAL, &old); + EXPECT_EQ("getitimer_0100", result, 0); +} + +/** + * @tc.name : getitimer_0200 + * @tc.desc : Verify the value of the interval timer (parameter is ITIMER_VIRTUAL) + * @tc.level : Level 0 + */ +void getitimer_0200(void) +{ + signal(SIGALRM, signalHandler); + struct itimerval old; + int result = getitimer(ITIMER_VIRTUAL, &old); + EXPECT_EQ("getitimer_0200", result, 0); +} + +/** + * @tc.name : getitimer_0300 + * @tc.desc : Verify the value of the interval timer (parameter is ITIMER_PROF) + * @tc.level : Level 0 + */ +void getitimer_0300(void) +{ + signal(SIGALRM, signalHandler); + struct itimerval old; + int result = getitimer(ITIMER_PROF, &old); + EXPECT_EQ("getitimer_0300", result, 0); +} + +int main(void) +{ + getitimer_0100(); + getitimer_0200(); + getitimer_0300(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/signal/kill.c b/libc-test/src/functionalext/supplement/signal/kill.c new file mode 100644 index 00000000..677f1f59 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/kill.c @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +static int exit_flag = 0; + +void Killfunc(int signal) +{ + switch (signal) { + case SIGUSR1: + exit_flag = 1; + break; + default: + break; + } + return; +} + +/** + * @tc.name : kill_0100 + * @tc.desc : Determine whether the child process successfully receives the signal to + * the main process and respond accordingly + * @tc.level : Level 1 + */ +void kill_0100(void) +{ + int status; + pid_t pid = fork(); + if (pid == 0) { + sleep(1); + kill(getppid(), SIGUSR1); + exit(EXIT_SUCCESS); + } else if (pid > 0) { + signal(SIGUSR1, Killfunc); + + while (!exit_flag) { + sleep(1); + } + wait(NULL); + EXPECT_EQ("kill_0100", exit_flag, 1); + } else { + printf("Fork wrong\n"); + exit(EXIT_FAILURE); + } +} + +/** + * @tc.name : kill_0200 + * @tc.desc : Outlier judgment + * @tc.level : Level 2 + */ +void kill_0200(void) +{ + int rev = kill(0, 1000); + EXPECT_EQ("kill_0200", rev, ERREXPECT); +} + +int main(void) +{ + kill_0100(); + kill_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/signal/killpg.c b/libc-test/src/functionalext/supplement/signal/killpg.c new file mode 100644 index 00000000..7fde7f80 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/killpg.c @@ -0,0 +1,87 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +static int exit_flag = 0; + +void ChildFunc(int signal) +{ + switch (signal) { + case SIGCHLD: + exit_flag = 1; + break; + default: + break; + } + return; +} + +/** + * @tc.name : killpg_0100 + * @tc.desc : Determine whether the child process successfully receives the signal to + * the main process and respond accordingly + * @tc.level : Level 1 + */ +void killpg_0100(void) +{ + pid_t pid; + int status; + sigset_t sigset; + sigemptyset(&sigset); + sigaddset(&sigset, SIGCHLD); + sigprocmask(SIG_BLOCK, &sigset, NULL); + pid = fork(); + if (pid == 0) { + sleep(1); + int ret = killpg(getpgrp(), SIGCHLD); + EXPECT_EQ("killpg_0100", ret, 0); + exit(EXIT_SUCCESS); + } else if (pid > 0) { + signal(SIGCHLD, ChildFunc); + sigprocmask(SIG_UNBLOCK, &sigset, NULL); + while (!exit_flag) { + sleep(1); + } + wait(NULL); + EXPECT_EQ("killpg_0100", exit_flag, 1); + } else { + printf("Fork wrong\n"); + exit(EXIT_FAILURE); + } +} + +/** + * @tc.name : killpg_0200 + * @tc.desc : Outlier judgment + * @tc.level : Level 2 + */ +void killpg_0200(void) +{ + int ret = killpg(-1, -1); + EXPECT_EQ("killpg_0200", ret, -1); +} + +int main(void) +{ + killpg_0100(); + killpg_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/signal/libc_current_sigrtmax.c b/libc-test/src/functionalext/supplement/signal/libc_current_sigrtmax.c new file mode 100755 index 00000000..7ea3b8a0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/libc_current_sigrtmax.c @@ -0,0 +1,21 @@ +#include +#include "functionalext.h" +#define MAXPATH 1000 + +/* + * @tc.name : libc_current_sigrtmax_0100 + * @tc.desc : Verify that the number of available signals can be obtained + * @tc.level : Level 0 + */ +void libc_current_sigrtmax_0100(void) +{ + int result = __libc_current_sigrtmax(); + EXPECT_EQ("libc_current_sigrtmax_0100", result, 64); +} + +int main() +{ + libc_current_sigrtmax_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/signal/libc_current_sigrtmin.c b/libc-test/src/functionalext/supplement/signal/libc_current_sigrtmin.c new file mode 100755 index 00000000..284b02f2 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/libc_current_sigrtmin.c @@ -0,0 +1,21 @@ +#include +#include "functionalext.h" +#define MAXPATH 1000 + +/* + * @tc.name : libc_current_sigrtmin_0100 + * @tc.desc : Verify that the number of real-time signals can be obtained + * @tc.level : Level 0 + */ +void libc_current_sigrtmin_0100(void) +{ + int result = __libc_current_sigrtmin(); + EXPECT_EQ("libc_current_sigrtmin_0100", result, 35); +} + +int main() +{ + libc_current_sigrtmin_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/signal/psiginfo.c b/libc-test/src/functionalext/supplement/signal/psiginfo.c new file mode 100755 index 00000000..3eb3ea88 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/psiginfo.c @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : psiginfo_0100 + * @tc.desc : Pass the normal parameters, the function call is successful, + * and the message is output in the console + * @tc.level : Level 0 + */ +void psiginfo_0100(void) +{ + errno = 0; + siginfo_t info; + memset(&info, 0x0, sizeof(siginfo_t)); + info.si_signo = SIGUSR1; + psiginfo(&info, "SIGUSR1"); + EXPECT_EQ("psiginfo_0100", errno, CMPFLAG); +} + +/** + * @tc.name : psiginfo_0200 + * @tc.desc : Invalid parameters are passed in, the function call succeeds, + * and a message is output to the console + * @tc.level : Level 0 + */ +void psiginfo_0200(void) +{ + errno = 0; + siginfo_t info; + memset(&info, 0x0, sizeof(siginfo_t)); + info.si_signo = SIGUSR1; + psiginfo(&info, NULL); + EXPECT_EQ("psiginfo_0200", errno, CMPFLAG); +} + +/** + * @tc.name : psiginfo_0300 + * @tc.desc : Invalid parameters are passed in, the function call succeeds, + * and a message is output to the console + * @tc.level : Level 2 + */ +void psiginfo_0300(void) +{ + errno = 0; + siginfo_t info; + memset(&info, 0x0, sizeof(siginfo_t)); + info.si_signo = -1; + psiginfo(&info, NULL); + EXPECT_EQ("psiginfo_0300", errno, CMPFLAG); +} + +int main(void) +{ + psiginfo_0100(); + psiginfo_0200(); + psiginfo_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/signal/psignal.c b/libc-test/src/functionalext/supplement/signal/psignal.c new file mode 100755 index 00000000..c2898e1f --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/psignal.c @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : psignal_0100 + * @tc.desc : Pass the normal parameters, the function call is successful, + * and the message is output in the console + * @tc.level : Level 0 + */ +void psignal_0100(void) +{ + errno = 0; + psignal(SIGUSR1, "SIGUSR1"); + EXPECT_EQ("psignal_0100", errno, CMPFLAG); +} + +/** + * @tc.name : psignal_0200 + * @tc.desc : Invalid parameters are passed in, the function call succeeds, + * and a message is output to the console + * @tc.level : Level 0 + */ +void psignal_0200(void) +{ + errno = 0; + psignal(SIGUSR1, NULL); + EXPECT_EQ("psignal_0200", errno, CMPFLAG); +} + +/** + * @tc.name : psignal_0300 + * @tc.desc : Invalid parameters are passed in, the function call succeeds, + * and a message is output to the console + * @tc.level : Level 2 + */ +void psignal_0300(void) +{ + errno = 0; + psignal(-1, NULL); + EXPECT_EQ("psignal_0300", errno, CMPFLAG); +} + +int main(void) +{ + psignal_0100(); + psignal_0200(); + psignal_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/signal/setitimer.c b/libc-test/src/functionalext/supplement/signal/setitimer.c new file mode 100644 index 00000000..5877f99b --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/setitimer.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +static int count = 0; + +void expireTimer(int signo) +{ + struct itimerval val; + count++; + if (count > 1) { + getitimer(signo, &val); + val.it_value.tv_sec = 0; + val.it_value.tv_usec = 0; + setitimer(signo, &val, NULL); + count = 0; + } +} + +void signalHandler(int signo) +{ + switch (signo) { + case SIGALRM: + printf("catch a SIGALRM signal\n"); + expireTimer(signo); + break; + case SIGVTALRM: + printf("catch a SIGVTALRM signal\n"); + break; + case SIGPROF: + printf("catch a SIGPROF signal\n"); + break; + default: + printf("no signal\n"); + break; + } +} + +/** + * @tc.name : setitimer_0100 + * @tc.desc : Set value of an interval timer + * @tc.level : Level 0 + */ +void setitimer_0100(void) +{ + signal(SIGALRM, signalHandler); + struct itimerval it; + memset(&it, 0, sizeof(it)); + + it.it_value.tv_sec = 0; + it.it_value.tv_usec = 100000; + it.it_interval.tv_sec = 0; + it.it_interval.tv_usec = 100000; + + if (setitimer(ITIMER_REAL, &it, NULL)) { + t_error("%s set timer failed", __func__); + } +} + +int main(int argc, char *argv[]) +{ + setitimer_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/signal/sigaction.c b/libc-test/src/functionalext/supplement/signal/sigaction.c new file mode 100644 index 00000000..de881d9c --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/sigaction.c @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; + +/** + * @tc.name : signal_0100 + * @tc.desc : The parameters are normal Verify that the capture signal is successful. + * @tc.level : Level 0 + */ +void signal_0100(void) +{ + struct sigaction act, oldact; + int ret = sigaction(SIGILL, &act, &oldact); + EXPECT_EQ("signal_0100", ret, SUCCESS); +} + +/** + * @tc.name : signal_0200 + * @tc.desc : Parameter exception Failed to validate capture signal. + * @tc.level : Level 2 + */ +void signal_0200(void) +{ + int flag = 0; + struct sigaction act, oldact; + int ret = sigaction(-1, &act, &oldact); + EXPECT_EQ("signal_0200", ret, FAILED); +} + +int main() +{ + signal_0100(); + signal_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/signal/sighold.c b/libc-test/src/functionalext/supplement/signal/sighold.c new file mode 100644 index 00000000..d3528a26 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/sighold.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +static int handler_count = 0; + +void handler(int sig) +{ + handler_count++; +} + +/** + * @tc.name : sighold_0100 + * @tc.desc : add sig to the signal mask of the calling process + * @tc.level : Level 0 + */ +void sighold_0100(void) +{ + handler_count = 0; + + int sig = SIGALRM; + struct sigaction act = {.sa_flags = 0, .sa_handler = handler}; + struct sigaction old_act = {0}; + int result = sigaction(sig, &act, &old_act); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + result = sighold(sig); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + sigset_t set = {0}; + result = sigprocmask(SIG_SETMASK, NULL, &set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + result = sigismember(&set, sig); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + result = raise(sig); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (handler_count != 0) { + t_error("%s failed: handler_count = %d\n", __func__, handler_count); + } +} + +/** + * @tc.name : sighold_0200 + * @tc.desc : add an invalid sig to the signal mask of the calling process + * @tc.level : Level 2 + */ +void sighold_0200(void) +{ + errno = 0; + int sig = 99999; + int result = sighold(sig); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno == 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + sighold_0100(); + sighold_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/signal/sigignore.c b/libc-test/src/functionalext/supplement/signal/sigignore.c new file mode 100644 index 00000000..d040bf83 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/sigignore.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +/** + * @tc.name : sigignore_0100 + * @tc.desc : sets the disposition of sig to SIG_IGN + * @tc.level : Level 0 + */ +void sigignore_0100(void) +{ + int sig = SIGALRM; + struct sigaction old_act = {0}; + errno = 0; + int result = sigaction(sig, NULL, &old_act); + if (result != 0 || errno != 0) { + t_error("%s failed: result = %d\n", __func__, result); + t_error("%s failed: errno = %d\n", __func__, errno); + } + + errno = 0; + result = sigignore(sig); + if (result != 0 || errno != 0) { + t_error("%s failed: result = %d\n", __func__, result); + t_error("%s failed: errno = %d\n", __func__, errno); + } + + struct sigaction sa; + errno = 0; + result = sigaction(SIGALRM, NULL, &sa); + if (result != 0 || errno != 0) { + t_error("%s failed: result = %d\n", __func__, result); + t_error("%s failed: errno = %d\n", __func__, errno); + } + + if (SIG_IGN != sa.sa_handler) { + t_error("%s failed: sa.sa_handler\n", __func__); + } +} + +/** + * @tc.name : sigignore_0200 + * @tc.desc : sets the disposition of the SIGKILL sig to SIG_IGN + * @tc.level : Level 1 + */ +void sigignore_0200(void) +{ + errno = 0; + int result = sigignore(SIGKILL); + if (result != -1 || errno != EINVAL) { + t_error("%s failed: result = %d\n", __func__, result); + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +/** + * @tc.name : sigignore_0300 + * @tc.desc : sets the disposition of the SIGSTOP sig to SIG_IGN + * @tc.level : Level 1 + */ +void sigignore_0300(void) +{ + errno = 0; + int result = sigignore(SIGSTOP); + if (result != -1 || errno != EINVAL) { + t_error("%s failed: result = %d\n", __func__, result); + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +/** + * @tc.name : sigignore_0400 + * @tc.desc : sets the disposition of an invalid sig to SIG_IGN + * @tc.level : Level 2 + */ +void sigignore_0400(void) +{ + int sig = 99999; + + errno = 0; + int result = sigignore(sig); + if (result == 0 || errno != EINVAL) { + t_error("%s failed: result = %d\n", __func__, result); + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + sigignore_0100(); + sigignore_0200(); + sigignore_0300(); + sigignore_0400(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/signal/signal.c b/libc-test/src/functionalext/supplement/signal/signal.c new file mode 100644 index 00000000..924f034f --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/signal.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : signal_0100 + * @tc.desc : The test catches the exception through the signal function + * @tc.level : Level 0 + */ +void signal_0100(int code) +{ + if (code != SIGILL & code != SIGTRAP) { + t_error("%s signal get error code is %d are not SIGILL or SIGTRAP\n", __func__, code); + } + exit(t_status); +} + +int main(int argc, char *argv[]) +{ + int *p = NULL; + signal(SIGILL, signal_0100); + signal(SIGTRAP, signal_0100); + *p = 0; + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/signal/sigpause.c b/libc-test/src/functionalext/supplement/signal/sigpause.c new file mode 100644 index 00000000..57c2ac99 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/sigpause.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +static int handler_count = 0; + +void handler(int sig) +{ + handler_count++; +} + +/** + * @tc.name : sigpause_0100 + * @tc.desc : atomically release blocked signals + * @tc.level : Level 0 + */ +void sigpause_0100(void) +{ + handler_count = 0; + + int sig = SIGALRM; + struct sigaction act = {.sa_flags = 0, .sa_handler = handler}; + struct sigaction old_act = {0}; + int result = sigaction(sig, &act, &old_act); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + result = sighold(sig); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + sigset_t set = {0}; + result = sigprocmask(SIG_SETMASK, NULL, &set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + result = sigismember(&set, sig); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + result = raise(sig); + if (result != 0 || handler_count != 0) { + t_error("%s failed: result = %d\n", __func__, result); + t_error("%s failed: handler_count = %d\n", __func__, handler_count); + } + + errno = 0; + result = sigpause(sig); + if (result != -1 || errno != EINTR) { + t_error("%s failed: result = %d\n", __func__, result); + t_error("%s failed: errno = %d\n", __func__, errno); + } + + if (handler_count != 1) { + t_error("%s failed: handler_count = %d\n", __func__, handler_count); + } +} + +int main(int argc, char *argv[]) +{ + sigpause_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/signal/sigpending.c b/libc-test/src/functionalext/supplement/signal/sigpending.c new file mode 100644 index 00000000..dfc2e6e0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/sigpending.c @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +/** + * @tc.name : sigpending_0100 + * @tc.desc : Test the sigpending function to get the signal set set to SIG_BLOCK + * @tc.level : Level 0 + */ +void sigpending_0100(void) +{ + sigset_t pending; + sigemptyset(&pending); + int result = sigpending(&pending); + if (result != 0) { + t_error("%s sigpending error get result is %d are not want 0\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + sigpending_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/signal/sigqueue.c b/libc-test/src/functionalext/supplement/signal/sigqueue.c new file mode 100644 index 00000000..03c1c1b1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/sigqueue.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +static int action_count = 0; + +void action(int sig, siginfo_t *info, void *ctx) +{ + if (sig != SIGALRM) { + t_error("%s failed: sig = %d\n", __func__, sig); + } + + if (info->si_signo != SIGALRM) { + t_error("%s failed: info->si_signo = %d\n", __func__, info->si_signo); + } + + if (info->si_code != SI_QUEUE) { + t_error("%s failed: info->si_code = %d\n", __func__, info->si_code); + } + + if (info->si_value.sival_int != 1) { + t_error("%s failed: info->si_value.sival_int = %d\n", __func__, info->si_value.sival_int); + } + + action_count++; +} + +/** + * @tc.name : sigqueue_0100 + * @tc.desc : queue a signal + * @tc.level : Level 0 + */ +void sigqueue_0100(void) +{ + action_count = 0; + + int sig = SIGALRM; + int flags = SA_SIGINFO; + struct sigaction act = {.sa_flags = flags, .sa_sigaction = action}; + struct sigaction old_act = {0}; + int result = sigaction(sig, &act, &old_act); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + union sigval sigval = {.sival_int = 1}; + + errno = 0; + result = sigqueue(getpid(), sig, sigval); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + if (action_count != 1) { + t_error("%s failed: action_count = %d\n", __func__, action_count); + } +} + +/** + * @tc.name : sigqueue_0200 + * @tc.desc : queue a signal with an invalid sig + * @tc.level : Level 2 + */ +void sigqueue_0200(void) +{ + int sig = 99999; + union sigval sigval = {.sival_int = 1}; + + errno = 0; + int result = sigqueue(getpid(), sig, sigval); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno == 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + sigqueue_0100(); + sigqueue_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/signal/sigrelse.c b/libc-test/src/functionalext/supplement/signal/sigrelse.c new file mode 100644 index 00000000..a7ce467d --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/sigrelse.c @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +static int handler_count = 0; + +void handler(int sig) +{ + handler_count++; +} + +/** + * @tc.name : sigrelse_0100 + * @tc.desc : removes sig from the calling process's signal mask + * @tc.level : Level 0 + */ +void sigrelse_0100(void) +{ + handler_count = 0; + + int sig = SIGALRM; + struct sigaction act = {.sa_flags = 0, .sa_handler = handler}; + struct sigaction old_act = {0}; + int result = sigaction(sig, &act, &old_act); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + result = sighold(sig); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + sigset_t set = {0}; + result = sigprocmask(SIG_SETMASK, NULL, &set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + result = sigismember(&set, sig); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + result = raise(sig); + if (result != 0 || handler_count != 0) { + t_error("%s failed: result = %d\n", __func__, result); + t_error("%s failed: handler_count = %d\n", __func__, handler_count); + } + + errno = 0; + result = sigpause(sig); + if (result != -1 || errno != EINTR) { + t_error("%s failed: result = %d\n", __func__, result); + t_error("%s failed: errno = %d\n", __func__, errno); + } + + if (handler_count != 1) { + t_error("%s failed: handler_count = %d\n", __func__, handler_count); + } + + result = sigprocmask(SIG_SETMASK, NULL, &set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = sigismember(&set, sig); + if (result != 1) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = sigrelse(sig); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = sigprocmask(SIG_SETMASK, NULL, &set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = sigismember(&set, sig); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : sigrelse_0200 + * @tc.desc : removes an invalid sig from the calling process's signal mask + * @tc.level : Level 2 + */ +void sigrelse_0200(void) +{ + errno = 0; + int sig = 99999; + int result = sigrelse(sig); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno == 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + sigrelse_0100(); + sigrelse_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/signal/sigset.c b/libc-test/src/functionalext/supplement/signal/sigset.c new file mode 100644 index 00000000..5abf8ce3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/sigset.c @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +static int handler_count = 0; +const int sig = SIGALRM; + +void handler(int sig) +{ + handler_count++; +} + +int prepare(sigset_t *set) +{ + handler_count = 0; + + struct sigaction act = {.sa_flags = 0, .sa_handler = handler}; + struct sigaction old_act = {0}; + int result = sigaction(sig, &act, &old_act); + if (result != 0) { + return result; + } + + if (handler_count != 0) { + return -1; + } + + result = raise(sig); + if (result != 0) { + return result; + } + + if (handler_count != 1) { + return -1; + } + + result = sigemptyset(set); + if (result != 0) { + return result; + } + + result = sigaddset(set, sig); + if (result != 0) { + return result; + } + + result = sigprocmask(SIG_BLOCK, NULL, set); + if (result != 0) { + return result; + } + + return 0; +} + +/** + * @tc.name : sigset_0100 + * @tc.desc : modifies the disposition of the signal sig with a handler + * @tc.level : Level 0 + */ +void sigset_0100(void) +{ + sigset_t set; + int result = prepare(&set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = sigemptyset(&set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + errno = 0; + sigset(sig, handler); + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + result = sigprocmask(SIG_BLOCK, NULL, &set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = sigismember(&set, sig); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : sigset_0200 + * @tc.desc : modifies the disposition of the signal sig with SIG_IGN + * @tc.level : Level 1 + */ +void sigset_0200(void) +{ + sigset_t set; + int result = prepare(&set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = sigemptyset(&set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + errno = 0; + sigset(sig, SIG_IGN); + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + result = sigprocmask(SIG_BLOCK, NULL, &set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = sigismember(&set, sig); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : sigset_0300 + * @tc.desc : modifies the disposition of the signal sig with SIG_DFL + * @tc.level : Level 1 + */ +void sigset_0300(void) +{ + sigset_t set; + int result = prepare(&set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = sigemptyset(&set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + errno = 0; + sigset(sig, SIG_DFL); + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + result = sigprocmask(SIG_BLOCK, NULL, &set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = sigismember(&set, sig); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : sigset_0400 + * @tc.desc : modifies the disposition of the signal sig with SIG_HOLD + * @tc.level : Level 1 + */ +void sigset_0400(void) +{ + sigset_t set; + int result = prepare(&set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = sigemptyset(&set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + errno = 0; + sigset(sig, SIG_HOLD); + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + result = sigprocmask(SIG_BLOCK, NULL, &set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = sigismember(&set, sig); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : sigset_0500 + * @tc.desc : modifies the disposition of the invalid signal sig + * @tc.level : Level 2 + */ +void sigset_0500(void) +{ + errno = 0; + int sig = 99999; + + sigset(sig, SIG_DFL); + if (errno == 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + sigset_0100(); + sigset_0200(); + sigset_0300(); + sigset_0400(); + sigset_0500(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/signal/sigsuspend.c b/libc-test/src/functionalext/supplement/signal/sigsuspend.c new file mode 100644 index 00000000..67a7731c --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/sigsuspend.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +static int handler_count = 0; + +void handler(int sig) +{ + handler_count++; +} + +/** + * @tc.name : sigsuspend_0100 + * @tc.desc : wait for a signal + * @tc.level : Level 0 + */ +void sigsuspend_0100(void) +{ + sigset_t set; + sigemptyset(&set); + + int sig = SIGALRM; + sigaddset(&set, sig); + sigprocmask(SIG_BLOCK, &set, NULL); + + int flags = 0; + struct sigaction act = {.sa_flags = flags, .sa_handler = handler}; + struct sigaction old_act = {0}; + int result = sigaction(sig, &act, &old_act); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + sigset_t pending_set; + sigemptyset(&pending_set); + sigpending(&pending_set); + + for (int i = SIGHUP; i <= SIGSTKSZ; ++i) { + result = sigismember(&pending_set, i); + if (result != 0) { + t_error("%s failed: result = %d, i = %d\n", __func__, result, i); + } + } + + raise(sig); + if (handler_count != 0) { + t_error("%s failed: handler_count = %d\n", __func__, handler_count); + } + + sigemptyset(&pending_set); + sigpending(&pending_set); + + for (int i = SIGHUP; i <= SIGSTKSZ; ++i) { + if ((i == sig) != (sigismember(&pending_set, i))) { + t_error("%s failed: i = %d, sig = %d\n", __func__, i, sig); + } + } + + sigset_t set_without_sig; + sigfillset(&set_without_sig); + sigdelset(&set_without_sig, sig); + + result = sigsuspend(&set_without_sig); + if (result != -1) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno != EINTR) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + if (handler_count != 1) { + t_error("%s failed: handler_count = %d\n", __func__, handler_count); + } +} + +int main(int argc, char *argv[]) +{ + sigsuspend_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/signal/sigwait.c b/libc-test/src/functionalext/supplement/signal/sigwait.c new file mode 100644 index 00000000..05512a5e --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/sigwait.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "test.h" + +/** + * @tc.name : sigwait_0100 + * @tc.desc : wait for a signal + * @tc.level : Level 0 + */ +void sigwait_0100(void) +{ + sigset_t set = {0}; + int result = sigemptyset(&set); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + int sig = SIGALRM; + result = sigaddset(&set, sig); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + result = sigprocmask(SIG_BLOCK, &set, NULL); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + union sigval sigval = {.sival_int = 1}; + result = sigqueue(getpid(), sig, sigval); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + sig = 0; + result = sigwait(&set, &sig); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (sig != SIGALRM) { + t_error("%s failed: sig = %d\n", __func__, sig); + } +} + +int main(int argc, char *argv[]) +{ + sigwait_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/signal/sigwaitinfo.c b/libc-test/src/functionalext/supplement/signal/sigwaitinfo.c new file mode 100644 index 00000000..eb9a17d8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/sigwaitinfo.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +/** + * @tc.name : sigwaitinfo_0100 + * @tc.desc : wait for queued signals + * @tc.level : Level 0 + */ +void sigwaitinfo_0100(void) +{ + // block a signal + sigset_t set; + sigemptyset(&set); + + int sig = SIGALRM; + sigaddset(&set, sig); + int result = sigprocmask(SIG_BLOCK, &set, NULL); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + // raise a signal + union sigval sigval = {.sival_int = 1}; + result = sigqueue(getpid(), sig, sigval); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + // get the pending signal. + siginfo_t info; + errno = 0; + result = sigwaitinfo(&set, &info); + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + if (result != sig) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (info.si_signo != sig) { + t_error("%s failed: info.si_signo = %d\n", __func__, info.si_signo); + } + + if (info.si_value.sival_int != sigval.sival_int) { + t_error("%s failed: info.si_value.sival_int = %d\n", __func__, info.si_value.sival_int); + } +} + +int main(int argc, char *argv[]) +{ + sigwaitinfo_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/signal/test_src_functionalext_supplement_signal.gni b/libc-test/src/functionalext/supplement/signal/test_src_functionalext_supplement_signal.gni new file mode 100644 index 00000000..f2fe4ce5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/signal/test_src_functionalext_supplement_signal.gni @@ -0,0 +1,35 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_signal_test = [ + "kill", + "killpg", + "setitimer", + "sigaction", + "sighold", + "sigignore", + "signal", + "sigpause", + "sigpending", + "sigqueue", + "sigrelse", + "sigset", + "sigsuspend", + "sigwait", + "sigwaitinfo", + "psiginfo", + "psignal", + "libc_current_sigrtmax", + "libc_current_sigrtmin", + "getitimer", +] diff --git a/libc-test/src/functionalext/supplement/stat/BUILD.gn b/libc-test/src/functionalext/supplement/stat/BUILD.gn new file mode 100644 index 00000000..15548dbe --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_stat.gni") + +foreach(s, functionalext_supplement_stat_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/stat" + } +} + +group("functionalext_supplement_stat_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_stat_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/stat/chmod.c b/libc-test/src/functionalext/supplement/stat/chmod.c new file mode 100644 index 00000000..e02e0508 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/chmod.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : chmod_0100 + * @tc.desc : Verify the permission to modify the file (the mode parameter is set separately) + * @tc.level : Level 0 + */ +void chmod_0100() +{ + + struct stat buf; + open("test.txt", O_RDWR | O_CREAT); + int result = chmod("test.txt", + S_IRUSR | S_ISGID | S_ISVTX | S_IWUSR | S_IROTH | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | + S_IWOTH | S_IXOTH); + stat("test.txt", &buf); + EXPECT_EQ("chmod_0100", result, 0); + EXPECT_EQ("chmod_0100", buf.st_mode, 34815); + remove("test.txt"); +} + +/* + * @tc.name : chmod_0200 + * @tc.desc : Verify the permission to modify the file (the overall setting of the mode parameter) + * @tc.level : Level 2 + */ +void chmod_0200() +{ + + struct stat buf; + open("test.txt", O_RDWR | O_CREAT); + int result = chmod("test.txt", S_IRWXU | S_IRWXG | S_IRWXO); + stat("test.txt", &buf); + EXPECT_EQ("chmod_0200", result, 0); + EXPECT_EQ("chmod_0200", buf.st_mode, 33279); + remove("test.txt"); +} + +/* + * @tc.name : chmod_0300 + * @tc.desc : Verify that file permissions cannot be modified (parameter invalid) + * @tc.level : Level 2 + */ +void chmod_0300() +{ + char filename[80]; + char buf[100] = ""; + int file; + gets(filename); + file = creat(filename, 0); + int num = chmod("data/AAA.txt", + S_ISUID | S_ISGID | S_ISVTX | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | + S_IXOTH); + EXPECT_EQ("chmod_0300", num, -1); + struct stat res; + stat("/data/AAA.txt", &res); +} + +/* + * @tc.name : chmod_0400 + * @tc.desc : Verify that file permissions cannot be modified (parameter invalid) + * @tc.level : Level 2 + */ +void chmod_0400() +{ + char filename[80]; + char buf[100] = ""; + int file; + gets(filename); + file = creat(filename, 0); + int num = chmod("data/test.txt", -0000); + EXPECT_EQ("chmod_0400", num, -1); + struct stat res; + stat("/data/AAA.txt", &res); + remove("data/test.txt"); +} + +int main() +{ + chmod_0100(); + chmod_0200(); + chmod_0300(); + chmod_0400(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/fchmod.c b/libc-test/src/functionalext/supplement/stat/fchmod.c new file mode 100755 index 00000000..c7fce233 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/fchmod.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : fchmod_0100 + * @tc.desc : Verify the permission to modify the file (parameters are set separately) + * @tc.level : Level 0 + */ +void fchmod_0100() +{ + int fd; + struct stat buf; + fd = open("test.txt", O_RDWR | O_CREAT); + int result = fchmod(fd, + S_IRUSR | S_ISGID | S_ISVTX | S_IWUSR | S_IROTH | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | + S_IWOTH | S_IXOTH); + stat("test.txt", &buf); + EXPECT_EQ("fchmod_0100", result, 0); + EXPECT_EQ("fchmod_0100", buf.st_mode, 34815); + close(fd); + remove("test.txt"); +} + +/** + * @tc.name : fchmod_0200 + * @tc.desc : Verify permission to modify files (overall parameter settings) + * @tc.level : Level 0 + */ +void fchmod_0200() +{ + int fd; + struct stat buf; + fd = open("test.txt", O_RDWR | O_CREAT); + int result = fchmod(fd, S_IRWXU | S_IRWXG | S_IRWXO); + stat("test.txt", &buf); + EXPECT_EQ("fchmod_0200", result, 0); + EXPECT_EQ("fchmod_0200", buf.st_mode, 33279); + close(fd); + remove("test.txt"); +} + +/** + * @tc.name : fchmod_0300 + * @tc.desc : Failed to verify permission to modify file (fd parameter is invalid) + * @tc.level : Level 2 + */ +void fchmod_0300() +{ + int result = fchmod(-1, S_IRWXU | S_IRWXG | S_IRWXO); + EXPECT_EQ("fchmod_0300", result, -1); +} + +TEST_FUN G_Fun_Array[] = { + fchmod_0100, + fchmod_0200, + fchmod_0300, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/fchmodat.c b/libc-test/src/functionalext/supplement/stat/fchmodat.c new file mode 100755 index 00000000..32fd7c17 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/fchmodat.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +int success = 36863; +int SUCCESS = 33279; +int failed = -1; + +/** + * @tc.name : fchmodat_0100 + * @tc.desc : Verify the permission to modify the file (parameters are set separately) + * @tc.level : Level 0 + */ +void fchmodat_0100(void) +{ + int fd; + struct stat buf; + fd = open("/data/tests/libc-test/src/functionalext/supplement/stat/test.txt", O_RDWR | O_CREAT); + int result = fchmodat(fd, + "/data/tests/libc-test/src/functionalext/supplement/stat/test.txt", + S_ISUID | S_ISGID | S_ISVTX | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | + S_IXOTH, + AT_SYMLINK_NOFOLLOW); + stat("/data/tests/libc-test/src/functionalext/supplement/stat/test.txt", &buf); + EXPECT_EQ("fchmodat_0100", result, 0); + EXPECT_EQ("fchmodat_0100", buf.st_mode, success); + close(fd); + remove("/data/tests/libc-test/src/functionalext/supplement/stat/test.txt"); +} + +/** + * @tc.name : fchmod_0200 + * @tc.desc : Verify permission to modify files (overall parameter settings) + * @tc.level : Level 0 + */ +void fchmodat_0200(void) +{ + int fd; + struct stat buf; + fd = open("/data/tests/libc-test/src/functionalext/supplement/stat/test.txt", O_RDWR | O_CREAT); + int result = fchmodat(fd, + "/data/tests/libc-test/src/functionalext/supplement/stat/test.txt", + S_IRWXU | S_IRWXG | S_IRWXO, + AT_SYMLINK_NOFOLLOW); + stat("/data/tests/libc-test/src/functionalext/supplement/stat/test.txt", &buf); + EXPECT_EQ("fchmodat_0200", result, 0); + EXPECT_EQ("fchmodat_0200", buf.st_mode, SUCCESS); + close(fd); + remove("/data/tests/libc-test/src/functionalext/supplement/stat/test.txt"); +} + +/** + * @tc.name : fchmod_0300 + * @tc.desc : Failed to verify permission to modify file (fd parameter is invalid) + * @tc.level : Level 2 + */ +void fchmodat_0300(void) +{ + int result = fchmodat(-1, "test.txt", S_IRWXU | S_IRWXG | S_IRWXO, AT_SYMLINK_NOFOLLOW); + EXPECT_EQ("fchmodat_0300", result, failed); +} + +int main() +{ + fchmodat_0100(); + fchmodat_0200(); + fchmodat_0300(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/fstatat.c b/libc-test/src/functionalext/supplement/stat/fstatat.c new file mode 100644 index 00000000..16ff5a1a --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/fstatat.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int SUCCESS = 0; + +/** + * @tc.name : fstatat_0100 + * @tc.desc : The parameter fd is equal to AT_FDCWD, the flag is 0, + * and the information of the file can be obtained. + * @tc.level : Level 0 + */ +void fstatat_0100(void) +{ + const char *ptr = "fstatattest.txt"; + struct stat st; + int fd = open(ptr, O_RDWR | O_CREAT); + EXPECT_TRUE("fstatat_0100", fd >= 0); + lseek(fd, 0, SEEK_SET); + int ret = fstatat(AT_FDCWD, ptr, &st, 0); + EXPECT_EQ("fstatat_0100", ret, SUCCESS); + uid_t uid = getuid(); + EXPECT_EQ("fstatat_0100", st.st_uid, uid); + gid_t gid = getgid(); + EXPECT_EQ("fstatat_0100", st.st_gid, gid); + close(fd); + remove(ptr); + ptr = NULL; +} + +/** + * @tc.name : fstatat_0200 + * @tc.desc : The parameter fd is equal to AT_FDCWD, the flag is AT_SYMLINK_NOFOLLOW, + * and the information of the file can be obtained. + * @tc.level : Level 0 + */ +void fstatat_0200(void) +{ + const char *ptr = "fstatattest.txt"; + struct stat st; + int fd = open(ptr, O_RDWR | O_CREAT); + EXPECT_TRUE("fstatat_0200", fd >= 0); + lseek(fd, 0, SEEK_SET); + const char *softptr = "./fstatattest.txt.soft"; + int link = symlink(ptr, softptr); + EXPECT_EQ("fstatat_0200", link, 0); + int ret = fstatat(AT_FDCWD, softptr, &st, AT_SYMLINK_NOFOLLOW); + EXPECT_EQ("fstatat_0200", ret, SUCCESS); + uid_t uid = getuid(); + EXPECT_EQ("fstatat_0200", st.st_uid, uid); + gid_t gid = getgid(); + EXPECT_EQ("fstatat_0200", st.st_gid, gid); + EXPECT_TRUE("fstatat_0200", st.st_mode); + close(fd); + remove(softptr); + remove(ptr); + softptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : fstatat_0300 + * @tc.desc : The parameter fd is equal to the return value of opening the test file, the flag is 0, + * and the information of the file can be obtained. + * @tc.level : Level 0 + */ +void fstatat_0300(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stat/fstatattest.txt"; + struct stat st; + int fd = open(ptr, O_RDWR | O_CREAT); + EXPECT_TRUE("fstatat_0300", fd >= 0); + lseek(fd, 0, SEEK_SET); + int ret = fstatat(0, ptr, &st, 0); + EXPECT_EQ("fstatat_0300", ret, SUCCESS); + uid_t uid = getuid(); + EXPECT_EQ("fstatat_0300", st.st_uid, uid); + gid_t gid = getgid(); + EXPECT_EQ("fstatat_0300", st.st_gid, gid); + close(fd); + remove(ptr); + ptr = NULL; +} + +int main() +{ + fstatat_0100(); + fstatat_0200(); + fstatat_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/fstatfs.c b/libc-test/src/functionalext/supplement/stat/fstatfs.c new file mode 100755 index 00000000..5d59d4e7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/fstatfs.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : fstatfs_0100 + * @tc.desc : Validation failed to get file status (parameter invalid file does not exist) + * @tc.level : Level 0 + */ +void fstatfs_0100(void) +{ + struct statfs buff; + int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); + int result = fstatfs(fd, &buff); + EXPECT_EQ("fstatfs_0100", result, 0); + close(fd); + remove("/data/readtest.txt"); +} + +/** + * @tc.name : fstatfs_0200 + * @tc.desc : Validation failed to get file status (parameter invalid file does not exist) + * @tc.level : Level 2 + */ +void fstatfs_0200(void) +{ + struct statfs buff; + int fd = open("/data/readtest.txt", O_RDWR); + int result = fstatfs(fd, &buff); + EXPECT_EQ("fstatfs_0200", result, -1); +} + +/** + * @tc.name : fstatfs_0300 + * @tc.desc : Validation failed to get file status (parameter invalid file does not exist) + * @tc.level : Level 2 + */ +void fstatfs_0300(void) +{ + struct statfs buff; + buff.f_type = -666666; + buff.f_bsize = -1111111; + int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); + int result = fstatfs(fd, &buff); + EXPECT_EQ("fstatfs_0300", result, 0); + close(fd); + remove("/data/readtest.txt"); +} + +int main() +{ + fstatfs_0100(); + fstatfs_0200(); + fstatfs_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/fstatvfs.c b/libc-test/src/functionalext/supplement/stat/fstatvfs.c new file mode 100755 index 00000000..7c2b26c3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/fstatvfs.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; +const int32_t COUNT_NEGATIVE = -1; + +/** + * @tc.name : fstatvfs_0100 + * @tc.desc : Verify that file system statistics can be obtained (all parameters are valid) + * @tc.level : Level 0 + */ +void fstatvfs_0100(void) +{ + struct statvfs buff; + int result; + int fd = open("test.txt", O_RDWR | O_CREAT); + result = fstatvfs(fd, &buff); + EXPECT_EQ("fstatvfs_0100", result, COUNT_ZERO); + close(fd); + remove("test.txt"); +} + +/** + * @tc.name : fstatvfs_0200 + * @tc.desc : Verify that file system statistics cannot be obtained (fd argument is invalid) + * @tc.level : Level 2 + */ +void fstatvfs_0200(void) +{ + struct statvfs buff; + int result; + int fd = open("test.txt", O_RDWR | O_CREAT); + result = fstatvfs(-1, &buff); + EXPECT_EQ("fstatvfs_0200", result, COUNT_NEGATIVE); + close(fd); + remove("test.txt"); +} + +int main() +{ + fstatvfs_0100(); + fstatvfs_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/futimesat.c b/libc-test/src/functionalext/supplement/stat/futimesat.c new file mode 100755 index 00000000..a4ae483f --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/futimesat.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; +const int32_t COUNT_NEGATIVE = -1; +const char *path = "/data/file.txt"; + +/** + * @tc.name : futimesat_0100 + * @tc.desc : Verify that you can set the file access time and modify time (valid parameters, times is not 0) + * @tc.level : Level 0 + */ +void futimesat_0100(void) +{ + int result = 10; + int fd = open(path, O_RDWR | O_CREAT); + result = futimesat(fd, path, NULL); + EXPECT_EQ("futimesat_0100", result, COUNT_ZERO); + close(fd); + remove(path); +} + +/** + * @tc.name : futimesat_0200 + * @tc.desc : Verify that you can set the file access time and modify time (valid parameters, times is 0) + * @tc.level : Level 1 + */ +void futimesat_0200(void) +{ + int result = 10; + int fd = open(path, O_RDWR | O_CREAT); + result = futimesat(fd, path, 0); + EXPECT_EQ("futimesat_0200", result, COUNT_ZERO); + close(fd); + remove(path); +} + +/** + * @tc.name : futimesat_0300 + * @tc.desc : Verify that file access time and modification time cannot be set (the dirfd parameter is invalid) + * @tc.level : Level 2 + */ +void futimesat_0300(void) +{ + int result = 10; + int fd = open(path, O_RDWR | O_CREAT); + close(fd); + remove(path); + result = futimesat(fd, path, NULL); + EXPECT_EQ("futimesat_0300", result, COUNT_NEGATIVE); +} + +/** + * @tc.name : futimesat_0400 + * @tc.desc : Validation cannot set file access time and modify time (pathname parameter invalid) + * @tc.level : Level 2 + */ +void futimesat_0400(void) +{ + int result = 10; + int fd = open(path, O_RDWR | O_CREAT); + result = futimesat(fd, "", NULL); + EXPECT_EQ("futimesat_0400", result, COUNT_NEGATIVE); + close(fd); + remove(path); +} + +int main() +{ + futimesat_0100(); + futimesat_0200(); + futimesat_0300(); + futimesat_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/lstat.c b/libc-test/src/functionalext/supplement/stat/lstat.c new file mode 100755 index 00000000..01a761e7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/lstat.c @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/* + * @tc.name : lstat_0100 + * @tc.desc : Verify that the parameters are valid, get the file status successfully + * @tc.level : Level 0 + */ +void lstat_0100(void) +{ + const char *ptr = "test.txt"; + const char str[] = "this is a sample!"; + FILE *fptr = fopen(ptr, "w+"); + struct stat statbuff; + fwrite(str, sizeof(char), strlen(str), fptr); + fseek(fptr, 0L, SEEK_SET); + int32_t back = lstat(ptr, &statbuff); + EXPECT_EQ("lstat_0100", back, 0); + EXPECT_EQ("lstat_0100", statbuff.st_size, 17); + fclose(fptr); + remove(ptr); +} + +/* + * @tc.name : lstat_0200 + * @tc.desc : Validation failed to get file status (parameter invalid file does not exist) + * @tc.level : Level 2 + */ +void lstat_0200(void) +{ + fopen("/data/NULL.txt", "w+"); + struct stat statbuff; + int32_t back = lstat("test.txt", &statbuff); + EXPECT_EQ("lstat_0200", back, -1); + remove("/data/NULL.txt"); +} + +/* + * @tc.name : lstat_0300 + * @tc.desc : Verify that the file pathname is valid and the file is a linked file + * @tc.level : Level 1 + */ +void lstat_0300(void) +{ + struct stat buf[3]; + const char *ptr = "tests.txt"; + FILE *fptr = fopen(ptr, "w+"); + system("ln -s tests.txt tests.txt.soft"); + struct stat statbuff; + int32_t back = lstat("tests.txt.soft", &statbuff); + EXPECT_EQ("lstat_0300", back, 0); + bool successflag = false; + if (S_ISLNK(statbuff.st_mode)) { + successflag = true; + } else { + successflag = false; + } + EXPECT_TRUE("lstat_0300", successflag); + fclose(fptr); + remove(ptr); + remove("tests.txt.soft"); +} + +TEST_FUN G_Fun_Array[] = { + lstat_0100, + lstat_0200, + lstat_0300, + +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/mkdir.c b/libc-test/src/functionalext/supplement/stat/mkdir.c new file mode 100644 index 00000000..2b95bcc1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/mkdir.c @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; + +/** + * @tc.name : mkdir_0100 + * @tc.desc : The parameters are valid and the directoty can be created. + * @tc.level : Level 0 + */ +void mkdir_0100(void) +{ + char *path = "mkdirtest"; + if (access(path, F_OK) != 0) { + int ret = mkdir(path, 0777); + EXPECT_EQ("mkdir_0100", ret, SUCCESS); + remove(path); + } else { + remove(path); + int ret = mkdir(path, 0777); + EXPECT_EQ("mkdir_0100", ret, SUCCESS); + remove(path); + } + path = NULL; +} + +/** + * @tc.name : mkdir_0200 + * @tc.desc : The path parameters is invalid,the directoty cannot be created. + * @tc.level : Level 2 + */ +void mkdir_0200(void) +{ + char *path = "mkdirtest"; + if (access(path, F_OK) == 0) { + int ret = mkdir(path, 0777); + EXPECT_EQ("mkdir_0200", ret, FAILED); + remove(path); + } else { + int retcreate = mkdir(path, 0777); + EXPECT_EQ("mkdir_0200", retcreate, SUCCESS); + int ret = mkdir(path, 0777); + EXPECT_EQ("mkdir_0200", ret, FAILED); + remove(path); + } + path = NULL; +} + +int main() +{ + mkdir_0100(); + mkdir_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/mkdirat.c b/libc-test/src/functionalext/supplement/stat/mkdirat.c new file mode 100755 index 00000000..b968dd86 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/mkdirat.c @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_AT_FDCWD (-100) +#define TEST_ERROR_AT_FDCWD 100 + +/** + * @tc.name : mkdirat_0100 + * @tc.desc : Create a subdirectory aa in the current directory + * @tc.level : Level 0 + */ +void mkdirat_0100(void) +{ + int ret = mkdirat(TEST_AT_FDCWD, "aa", S_IRWXU | S_IRWXG | S_IXOTH | S_IROTH); + EXPECT_EQ("mkdirat_0100", ret, CMPFLAG); + + if (access("aa", F_OK) == 0) { + rmdir("aa"); + } +} + +/** + * @tc.name : mkdirat_0200 + * @tc.desc : Using the wrong fd, create a subdirectory bb in the current directory + * @tc.level : Level 2 + */ +void mkdirat_0200(void) +{ + int ret = mkdirat(TEST_ERROR_AT_FDCWD, "bb", S_IRWXU | S_IRWXG | S_IXOTH | S_IROTH); + EXPECT_EQ("mkdirat_0200", ret, ERREXPECT); + + if (access("bb", F_OK) == 0) { + rmdir("bb"); + } +} + +int main(void) +{ + mkdirat_0100(); + mkdirat_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/mkfifo.c b/libc-test/src/functionalext/supplement/stat/mkfifo.c new file mode 100644 index 00000000..7b8d48f6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/mkfifo.c @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define TEST_FIFO_MODE 0666 +/** + * @tc.name : mkfifo_0100 + * @tc.desc : Create named pipe with correct parameters + * @tc.level : Level 0 + */ +void mkfifo_0100(void) +{ + struct stat sb; + const char *path = "/data/test_fifo"; + int ret = mkfifo(path, S_IFIFO | TEST_FIFO_MODE); + EXPECT_EQ("mkfifo_0100", ret, 0); + ret = stat(path, &sb); + EXPECT_EQ("mkfifo_0100", ret, 0); + EXPECT_TRUE("mkfifo_0100", S_ISFIFO(sb.st_mode)); + unlink(path); +} + +/** + * @tc.name : mkfifo_0200 + * @tc.desc : Create named pipe with exception argument + * @tc.level : Level 0 + */ +void mkfifo_0200(void) +{ + int ret = mkfifo("/", TEST_FIFO_MODE); + EXPECT_EQ("mkfifo_0200", ret, -1); + EXPECT_EQ("mkfifo_0200", errno, EEXIST); +} + +int main(void) +{ + mkfifo_0100(); + mkfifo_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/mkfifoat.c b/libc-test/src/functionalext/supplement/stat/mkfifoat.c new file mode 100644 index 00000000..05949e03 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/mkfifoat.c @@ -0,0 +1,76 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define TEST_FIFO_MODE 0666 +#define TEST_AT_FDCWD -100 + +/** + * @tc.name : mkfifoat_0100 + * @tc.desc : Verify mkfifoat process success. Create named pipe with correct parameters. + * The pathname given in pathname is absolute. + * @tc.level : Level 0 + */ +void mkfifoat_0100(void) +{ + struct stat sb; + const char *path = "/data/mkfifoat_0100"; + int ret = mkfifoat(-1, path, S_IFIFO | TEST_FIFO_MODE); + EXPECT_EQ("mkfifoat_0100", ret, 0); + ret = stat(path, &sb); + EXPECT_EQ("mkfifoat_0100", ret, 0); + EXPECT_TRUE("mkfifoat_0100", S_ISFIFO(sb.st_mode)); + unlink(path); +} + +/** + * @tc.name : mkfifoat_0200 + * @tc.desc : Verify mkfifoat process success. Create named pipe with correct parameters. + * The pathname given in pathname is relative. + * @tc.level : Level 0 + */ +void mkfifoat_0200(void) +{ + struct stat sb; + const char *path = "mkfifoat_0200"; + int ret = mkfifoat(TEST_AT_FDCWD, path, S_IFIFO | TEST_FIFO_MODE); + EXPECT_EQ("mkfifoat_0200", ret, 0); + ret = stat(path, &sb); + EXPECT_EQ("mkfifoat_0200", ret, 0); + EXPECT_TRUE("mkfifoat_0200", S_ISFIFO(sb.st_mode)); + unlink(path); +} + +/** + * @tc.name : mkfifoat_0300 + * @tc.desc : Verify mkfifoat process fail. Create named pipe with exception argument. + * @tc.level : Level 2 + */ +void mkfifoat_0300(void) +{ + int ret = mkfifoat(-1, "mkfifoat_0300", S_IFIFO | TEST_FIFO_MODE); + EXPECT_EQ("mkfifoat_0300", ret, -1); +} + +int main(void) +{ + mkfifoat_0100(); + mkfifoat_0200(); + mkfifoat_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/mknod.c b/libc-test/src/functionalext/supplement/stat/mknod.c new file mode 100755 index 00000000..beceed40 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/mknod.c @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_MODE 0666 + +/** + * @tc.name : mknod_0100 + * @tc.desc : Create file node + * @tc.level : Level 2 + */ +void mknod_0100(void) +{ + const char *pathname = "/data/tests/libc-test/src/functionalext/supplement/stat/mknod"; + int ret = mknod(pathname, TEST_MODE, 0); + EXPECT_EQ("mknod_0100", ret, ERREXPECT); +} + +int main(void) +{ + mknod_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/mknodat.c b/libc-test/src/functionalext/supplement/stat/mknodat.c new file mode 100644 index 00000000..233e6b8b --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/mknodat.c @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define TEST_FIFO_MODE 0666 + +/** + * @tc.name : mknodat_0100 + * @tc.desc : Verify mknodat process success. Create named pipe with correct parameters. + * The pathname given in pathname is absolute. + * @tc.level : Level 0 + */ +void mknodat_0100(void) +{ + struct stat sb; + const char *path = "/data/mknodat_0100"; + int ret = mknodat(-1, path, S_IFIFO | TEST_FIFO_MODE, 0); + EXPECT_EQ("mknodat_0100", ret, 0); + ret = stat(path, &sb); + EXPECT_EQ("mknodat_0100", ret, 0); + EXPECT_TRUE("mknodat_0100", S_ISFIFO(sb.st_mode)); + unlink(path); +} + +/** + * @tc.name : mknodat_0200 + * @tc.desc : Verify mknodat process fail. Because pathname already exists. + * @tc.level : Level 0 + */ +void mknodat_0200(void) +{ + struct stat sb; + const char *path = "/data/mknodat_0200"; + int ret = mknodat(-1, path, S_IFIFO | TEST_FIFO_MODE, 0); + EXPECT_EQ("mknodat_0200", ret, 0); + ret = stat(path, &sb); + EXPECT_EQ("mknodat_0200", ret, 0); + EXPECT_TRUE("mknodat_0200", S_ISFIFO(sb.st_mode)); + ret = mknodat(-1, path, S_IFIFO | TEST_FIFO_MODE, 0); + EXPECT_EQ("mknodat_0200", ret, -1); + unlink(path); +} + +int main(void) +{ + mknodat_0100(); + mknodat_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/stat.c b/libc-test/src/functionalext/supplement/stat/stat.c new file mode 100644 index 00000000..7c57ebe6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/stat.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t CREAT_MODE = 666; + +/** + * @tc.name : stat_0100 + * @tc.desc : Verify stat process success with two params + * @tc.level : Level 0 + */ +void stat_0100(void) +{ + struct stat buf; + int fd = -1; + fd = creat("test1.txt", CREAT_MODE); + if (fd < 0) { + EXPECT_MT("stat_0100", fd, 0); + return; + } else { + close(fd); + } + int32_t ret = stat("test1.txt", &buf); + EXPECT_EQ("stat_0100", ret, 0); + EXPECT_EQ("stat_0100", buf.st_size, 0); + ret = remove("test1.txt"); + EXPECT_EQ("stat_0100", ret, 0); +} + +/** + * @tc.name : stat_0200 + * @tc.desc : Verify stat process fail because file is not exit + * @tc.level : Level 2 + */ +void stat_0200(void) +{ + struct stat buf; + int32_t ret = stat("test2.txt", &buf); + EXPECT_EQ("stat_0200", ret, -1); +} + +int main(void) +{ + stat_0100(); + stat_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stat/statfs.c b/libc-test/src/functionalext/supplement/stat/statfs.c new file mode 100644 index 00000000..de1932f3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/statfs.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/* + * @tc.name : statfs_0100 + * @tc.desc : Test statfs to read information such as the size of the directory + * @tc.level : Level 0 + */ +void statfs_0100(void) +{ + struct statfs sb; + int result = statfs("/proc", &sb); + if (result != 0) { + t_error("%s statfs error get result is %d are not want 0\n", __func__, result); + } +} + +/* + * @tc.name : statfs_0200 + * @tc.desc : Test the return value of the statfs function when a non-existing directory is passed in + * @tc.level : Level 1 + */ +void statfs_0200(void) +{ + struct statfs sb; + int want = -1; + int result = statfs("/does-not-exist", &sb); + if (result != want) { + t_error("%s statfs error get result is %d are not want -1\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + statfs_0100(); + statfs_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/statvfs.c b/libc-test/src/functionalext/supplement/stat/statvfs.c new file mode 100644 index 00000000..1d4d8f83 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/statvfs.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : statvfs_0100 + * @tc.desc : Test statvfs to get filesystem statistics in a given path + * @tc.level : Level 0 + */ +void statvfs_0100(void) +{ + struct statvfs sb; + int result = statvfs("/proc", &sb); + if (result != 0) { + t_error("%s statvfs error get result is %d are not want 0\n", __func__, result); + } +} + +/** + * @tc.name : statvfs_0200 + * @tc.desc : Test statvfs results when incoming paths, etc. are empty + * @tc.level : Level 2 + */ +void statvfs_0200(void) +{ + int want = -1; + int result = statvfs(NULL, NULL); + if (result != want) { + t_error("%s statvfs error get result is %d are not want -1\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + statvfs_0100(); + statvfs_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/test_src_functionalext_supplement_stat.gni b/libc-test/src/functionalext/supplement/stat/test_src_functionalext_supplement_stat.gni new file mode 100644 index 00000000..1c593aaf --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/test_src_functionalext_supplement_stat.gni @@ -0,0 +1,34 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_stat_test = [ + "statvfs", + "stat", + "statfs", + "mkfifo", + "mkfifoat", + "mknodat", + "lstat", + "fchmod", + "fstatfs", + "mkdir", + "umask", + "utimensat", + "fstatvfs", + "futimesat", + "fstatat", + "mkdirat", + "mknod", + "chmod", + "fchmodat", +] diff --git a/libc-test/src/functionalext/supplement/stat/umask.c b/libc-test/src/functionalext/supplement/stat/umask.c new file mode 100644 index 00000000..62fe5f4d --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/umask.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +/** + * @tc.name : umask_0100 + * @tc.desc : set file mode creation mask + * @tc.level : Level 0 + */ +void umask_0100(void) +{ + mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; + mode_t result = umask(mode); + + result = umask(result); + if (result != mode) { + t_error("%s failed: result = %o\n", __func__, result); + } +} + +/** + * @tc.name : umask_0200 + * @tc.desc : set an invalid file mode creation mask + * @tc.level : Level 2 + */ +void umask_0200(void) +{ + mode_t mode = -1; + mode_t result = umask(mode); + + result = umask(result); + if (result == mode) { + t_error("%s failed: result = %o\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + umask_0100(); + umask_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stat/utimensat.c b/libc-test/src/functionalext/supplement/stat/utimensat.c new file mode 100644 index 00000000..5124e2a6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stat/utimensat.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "test.h" + +const char *path = "/data/tests/libc-test/src/file.txt"; +const long sec = 123840; + +/** + * @tc.name : utimensat_0100 + * @tc.desc : change file timestamps with nanosecond precision + * @tc.level : Level 0 + */ +void utimensat_0100(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + struct timespec times[] = {{.tv_sec = 0}, {.tv_sec = sec}}; + + int result = utimensat(fd, path, times, 0); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + close(fd); + + struct stat statbuf; + result = stat(path, &statbuf); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (statbuf.st_mtim.tv_sec != sec) { + t_error("%s failed: statbuf.st_mtim.tv_sec = %ld\n", __func__, statbuf.st_mtim.tv_sec); + } + + remove(path); +} + +/** + * @tc.name : utimensat_0200 + * @tc.desc : change file timestamps with invalid parameters + * @tc.level : Level 2 + */ +void utimensat_0200(void) +{ + errno = 0; + int result = utimensat(-1, NULL, NULL, 0); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno != EBADF) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + utimensat_0100(); + utimensat_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/BUILD.gn b/libc-test/src/functionalext/supplement/stdio/BUILD.gn new file mode 100644 index 00000000..0a1c5ba6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_stdio.gni") + +foreach(s, functionalext_supplement_stdio_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/stdio" + } +} + +group("functionalext_supplement_stdio_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_stdio_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/stdio/__fbufsize.c b/libc-test/src/functionalext/supplement/stdio/__fbufsize.c new file mode 100644 index 00000000..0350adcc --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/__fbufsize.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +const size_t COUNT_ZERO = 0; + +/** + * @tc.name : __fbufsize_0100 + * @tc.desc : Verify that you can get the size of the buffer used by the file + (In bytes. Valid, file size greater than 0) + * @tc.level : Level 0 + */ +void __fbufsize_0100(void) +{ + bool flag = false; + FILE *fptr = fopen("test.txt", "w+"); + fwrite("1", 1, 1, fptr); + size_t result = 0; + result = __fbufsize(fptr); + if (result > 0) + { + flag = true; + } + EXPECT_TRUE("__fbufsize_0200", flag); + fclose(fptr); + remove("test.txt"); +} + +/** + * @tc.name : __fbufsize_0200 + * @tc.desc : Verify that you can get the size of the buffer used by the file + (In bytes. File size = 0) + * @tc.level : Level 0 + */ +void __fbufsize_0200(void) +{ + FILE *fptr = fopen("test.txt", "w+"); + setbuf(fptr, NULL); + size_t result = 0; + result = __fbufsize(fptr); + EXPECT_EQ("__fbufsize_0200", result, COUNT_ZERO); + fclose(fptr); + remove("test.txt"); +} + +int main() +{ + __fbufsize_0100(); + __fbufsize_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/__flbf.c b/libc-test/src/functionalext/supplement/stdio/__flbf.c new file mode 100644 index 00000000..fb49ed12 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/__flbf.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; + +/** + * @tc.name : __flbf_0100 + * @tc.desc : Verify file stream is row buffered (valid argument, is row buffered) + * @tc.level : Level 0 + */ +void __flbf_0100(void) +{ + char buf[1024]; + int result = 0; + bool flag = false; + FILE *fptr = fopen("test.txt", "w"); + setvbuf(fptr, buf, _IOLBF, 1024); + result = __flbf(fptr); + if (result > 0) + { + flag = true; + } + EXPECT_TRUE("__flbf_0100", flag); + fclose(fptr); + remove("test.txt"); +} + +/** + * @tc.name : __flbf_0200 + * @tc.desc : Verify file stream is not row buffered (valid argument, is full buffered) + * @tc.level : Level 1 + */ +void __flbf_0200(void) +{ + char buf[1024]; + int result = 0; + FILE *fptr = fopen("test.txt", "w"); + setvbuf(fptr, buf, _IOFBF, 1024); + result = __flbf(fptr); + EXPECT_EQ("__flbf_0200", result, COUNT_ZERO); + fclose(fptr); + remove("test.txt"); +} + +/** + * @tc.name : __flbf_0300 + * @tc.desc :Verify file stream is not row buffered (parameter valid, is not buffered) + * @tc.level : Level 1 + */ +void __flbf_0300(void) +{ + char buf[1024]; + int result = 0; + FILE *fptr = fopen("test.txt", "w"); + setvbuf(fptr, buf, _IONBF, 1024); + result = __flbf(fptr); + EXPECT_EQ("__flbf_0300", result, COUNT_ZERO); + fclose(fptr); + remove("test.txt"); +} + +int main() +{ + __flbf_0100(); + __flbf_0200(); + __flbf_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/__fpending.c b/libc-test/src/functionalext/supplement/stdio/__fpending.c new file mode 100644 index 00000000..c77b60a1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/__fpending.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : __fpending_0100 + * @tc.desc : The parameter is valid, f is the file opened in w mode, there is data in the buffer, + * get the number of bytes in the current buffer. + * @tc.level : Level 0 + */ +void __fpending_0100(void) +{ + char *str = "This is a test"; + FILE *fp = fopen("fpending.txt", "w"); + fputs(str, fp); + size_t ret = __fpending(fp); + EXPECT_TRUE("__fpending_0100", ret > 0); + EXPECT_EQ("__fpending_0100", ret, strlen(str)); + fclose(fp); + remove("fpending.txt"); +} + +/** + * @tc.name : __fpending_0200 + * @tc.desc : The parameter is valid, f is the file opened in w mode, there is no data in the buffer, + * et the number of bytes in the current buffer. + * @tc.level : Level 1 + */ +void __fpending_0200(void) +{ + char *str = "This is a test"; + FILE *fp = fopen("fpending.txt", "w"); + fputs(str, fp); + fflush(fp); + size_t ret = __fpending(fp); + EXPECT_EQ("__fpending_0200", ret, 0); + fclose(fp); + remove("fpending.txt"); +} + +/** + * @tc.name : __fpending_0300 + * @tc.desc : The parameter is valid, f is the file opened in r mode, and the number of bytes in + * the current buffer cannot be obtained. + * @tc.level : Level 2 + */ +void __fpending_0300(void) +{ + char *str = "This is a test"; + FILE *fp = fopen("fpending.txt", "w"); + fputs(str, fp); + fclose(fp); + FILE *ffp = fopen("fpending.txt", "r"); + size_t ret = __fpending(ffp); + EXPECT_EQ("__fpending_0300", ret, 0); + fclose(ffp); + remove("fpending.txt"); +} + +int main() +{ + __fpending_0100(); + __fpending_0200(); + __fpending_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/__fpurge.c b/libc-test/src/functionalext/supplement/stdio/__fpurge.c new file mode 100644 index 00000000..2831d663 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/__fpurge.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : __fpurge_0100 + * @tc.desc : Each parameter value is valid and can be used to completely clear the data in the buffer. + * @tc.level : Level 0 + */ +void __fpurge_0100() +{ + char buf[100]; + char *str = "This is a test"; + FILE *fp = fopen("fpurge.txt", "w"); + fputs(str, fp); + size_t ret = __fpurge(fp); + fgets(buf, 100, fp); + EXPECT_EQ("__fpurge_0100", strstr(buf, str), 0); + EXPECT_EQ("__fpurge_0100", ret, 0); + fclose(fp); + remove("fpurge.txt"); +} + +int main() +{ + __fpurge_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/__freadable.c b/libc-test/src/functionalext/supplement/stdio/__freadable.c new file mode 100644 index 00000000..4ba54309 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/__freadable.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : __freadable_0100 + * @tc.desc : The parameters are valid, and the file can be judged to be readable. + * @tc.level : Level 0 + */ +void __freadable_0100(void) +{ + char buf[100]; + FILE *fp = fopen("freadable.txt", "w"); + fclose(fp); + FILE *ffp = fopen("freadable.txt", "r"); + size_t ret = __freadable(ffp); + EXPECT_NE("__freadable_0100", ret, 0); + fclose(ffp); + remove("freadable.txt"); +} + +/** + * @tc.name : __freadable_0200 + * @tc.desc : The parameters are valid, and the file can be judged to be unreadable. + * @tc.level : Level 1 + */ +void __freadable_0200(void) +{ + FILE *fp = fopen("freadable.txt", "wb"); + size_t ret = __freadable(fp); + EXPECT_EQ("__freadable_0200", ret, 0); + fclose(fp); + remove("freadable.txt"); +} + +int main() +{ + __freadable_0100(); + __freadable_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/__freading.c b/libc-test/src/functionalext/supplement/stdio/__freading.c new file mode 100644 index 00000000..360dfd11 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/__freading.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : __freading_0100 + * @tc.desc : The parameter is valid, the file is opened in read-only mode, and the file stream can + * be judged to be read-only. + * @tc.level : Level 0 + */ +void __freading_0100(void) +{ + char *str = "This is a test"; + FILE *fp = fopen("freading.txt", "w"); + fputs(str, fp); + fclose(fp); + FILE *ffp = fopen("freading.txt", "r"); + size_t ret = __freading(ffp); + EXPECT_NE("__freading_0100", ret, 0); + fclose(ffp); + remove("freading.txt"); +} + +/** + * @tc.name : __freading_0200 + * @tc.desc : The parameter is valid, the file has just been read, and it is judged that the file + * stream has been read. + * @tc.level : Level 0 + */ +void __freading_0200(void) +{ + char *str = "This is a test"; + FILE *fp = fopen("freading.txt", "w"); + fputs(str, fp); + fclose(fp); + FILE *ffp = fopen("freading.txt", "r"); + char buf[100]; + fgets(buf, 100, ffp); + size_t ret = __freading(ffp); + EXPECT_NE("__freading_0200", ret, 0); + fclose(ffp); + remove("freading.txt"); +} + +/** + * @tc.name : __freading_0300 + * @tc.desc : The parameter is valid, the file has just been written, and it is judged that the file stream + * has not been read. + * @tc.level : Level 2 + */ +void __freading_0300(void) +{ + char *str = "This is a test"; + FILE *fp = fopen("freading.txt", "w"); + fputs(str, fp); + size_t ret = __freading(fp); + EXPECT_EQ("__freading_0300", ret, 0); + fclose(fp); + remove("freading.txt"); +} + +int main() +{ + __freading_0100(); + __freading_0200(); + __freading_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/__fseterr.c b/libc-test/src/functionalext/supplement/stdio/__fseterr.c new file mode 100644 index 00000000..5dcfd785 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/__fseterr.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; + +/** + * @tc.name : __fseterr_0100 + * @tc.desc : Validate errors that can specify streams (parameter valid) + * @tc.level : Level 0 + */ +void __fseterr_0100(void) +{ + bool flag = false; + int result1, result2; + FILE *fptr = fopen("test.txt", "w+"); + result1 = ferror(fptr); + __fseterr(fptr); + result2 = ferror(fptr); + EXPECT_EQ("__fseterr_0100", result1, COUNT_ZERO); + if (result2 != 0) + { + flag = true; + } + EXPECT_TRUE("__fseterr_0100", flag); + fclose(fptr); + remove("test.txt"); +} + +int main() +{ + __fseterr_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/__fsetlocking.c b/libc-test/src/functionalext/supplement/stdio/__fsetlocking.c new file mode 100644 index 00000000..5c95782c --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/__fsetlocking.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; + +/** + * @tc.name : __fsetlocking_0100 + * @tc.desc : Function is not implemented, always return 0 + * @tc.level : Level 0 + */ +void __fsetlocking_0100(void) +{ + FILE *fptr = fopen("test.txt", "w+"); + int result; + result = __fsetlocking(fptr, FSETLOCKING_INTERNAL); + EXPECT_EQ("__fsetlocking_0100", result, COUNT_ZERO); + fclose(fptr); + remove("test.txt"); +} + +int main() +{ + __fsetlocking_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/__fwritable.c b/libc-test/src/functionalext/supplement/stdio/__fwritable.c new file mode 100644 index 00000000..9cf9b537 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/__fwritable.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int32_t NUM_ZERO = 0; + +/** + * @tc.name : __fwritable_0100 + * @tc.desc : Verify that the file is writable (parameters are valid) + * @tc.level : Level 0 + */ +void __fwritable_0100(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt"; + FILE *fptr = fopen(ptr, "w+"); + if (!fptr) { + t_error("%s fopen failed\n", __func__); + } + int result = __fwritable(fptr); + EXPECT_NE("__fwritable_0100", result, NUM_ZERO); + fclose(fptr); +} + +/** + * @tc.name : __fwritable_0200 + * @tc.desc : Verify file is not writable (parameter invalid) + * @tc.level : Level 1 + */ +void __fwritable_0200(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt"; + FILE *fptr = fopen(ptr, "r"); + if (!fptr) { + t_error("%s fopen failed\n", __func__); + } + int result = __fwritable(fptr); + EXPECT_EQ("__fwritable_0200", result, NUM_ZERO); + fclose(fptr); + remove(ptr); +} + +int main() +{ + __fwritable_0100(); + __fwritable_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/__fwriting.c b/libc-test/src/functionalext/supplement/stdio/__fwriting.c new file mode 100644 index 00000000..48f5c767 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/__fwriting.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t NUM_ZERO = 0; + +/** + * @tc.name : __fwriting_0100 + * @tc.desc : Verify that the file stream is write-only + * @tc.level : Level 0 + */ +void __fwriting_0100(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt"; + FILE *fptr = fopen(ptr, "w"); + int result = __fwriting(fptr); + EXPECT_NE("__fwriting_0100", result, NUM_ZERO); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : __fwriting_0200 + * @tc.desc : The last operation on the stream was a write operation + * @tc.level : Level 0 + */ +void __fwriting_0200(void) +{ + const char *wrstring = "helloworld"; + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt"; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + int result = __fwriting(fptr); + EXPECT_NE("__fwriting_0200", result, NUM_ZERO); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : __fwriting_0300 + * @tc.desc : The last operation on the stream was not a write operation + * @tc.level : Level 2 + */ +void __fwriting_0300(void) +{ + char abc[100] = {0}; + const char *wrstring = "helloworld"; + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt"; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fseek(fptr, 0, SEEK_SET); + int32_t rsize = fread(abc, 1, 10, fptr); + int result = __fwriting(fptr); + EXPECT_EQ("__fwriting_0300", result, NUM_ZERO); + fclose(fptr); + remove(ptr); +} + +int main() +{ + __fwriting_0100(); + __fwriting_0200(); + __fwriting_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/_flushlbf.c b/libc-test/src/functionalext/supplement/stdio/_flushlbf.c new file mode 100644 index 00000000..c3e61d54 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/_flushlbf.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t INIT_LEN = 0; + +/** + * @tc.name : flushlbf_0100 + * @tc.desc : Verify that flushing the line buffer was successful. + * @tc.level : Level 0 + */ +void flushlbf_0100(void) +{ + char buffer[1024] = {0}; + char array[] = "this is a test!"; + FILE *fd = fopen("/data/test.txt", "w+"); + fprintf(fd, "%s", array); + FILE *fp = freopen("/data/test.txt", "r", stdin); + fseek(fp, 0, SEEK_SET); + int32_t rsize = fread(buffer, 1, 10, fd); + EXPECT_EQ("flushlbf_0100", rsize, INIT_LEN); + _flushlbf(); + fseek(fp, 0, SEEK_SET); + fread(buffer, 1, 20, fp); + EXPECT_STREQ("flushlbf_0100", buffer, "this is a test!"); + fclose(stdin); + fclose(fp); + remove("/data/test.txt"); +} + +int main(int argc, char *argv[]) +{ + flushlbf_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/asprintf.c b/libc-test/src/functionalext/supplement/stdio/asprintf.c new file mode 100644 index 00000000..25399a14 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/asprintf.c @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : asprintf_0100 + * @tc.desc : The parameters are valid and the data can be output according to the format + * @tc.level : Level 0 + */ +void asprintf_0100(void) +{ + char *buf = "d"; + char *testStr = NULL; + int n; + n = asprintf(&testStr, "%s", buf); + free(testStr); + testStr = NULL; + EXPECT_TRUE("asprintf_0100", n > 0); +} + +/** + * @tc.name : asprintf_0200 + * @tc.desc : The parameters are valid and the data can be output according to the format + * @tc.level : Level 0 + */ +void asprintf_0200(void) +{ + char *buf = "o"; + char *testStr = NULL; + int n; + n = asprintf(&testStr, "%s", buf); + free(testStr); + testStr = NULL; + EXPECT_TRUE("asprintf_0200", n > 0); +} + +/** + * @tc.name : asprintf_0300 + * @tc.desc : The parameters are valid and the data can be output according to the format + * @tc.level : Level 0 + */ +void asprintf_0300(void) +{ + char *buf = "x,X"; + char *testStr = NULL; + int n; + n = asprintf(&testStr, "%s", buf); + free(testStr); + testStr = NULL; + EXPECT_TRUE("asprintf_0300", n > 0); +} + +/** + * @tc.name : asprintf_0400 + * @tc.desc : The parameters are valid and the data can be output according to the format + * @tc.level : Level 0 + */ +void asprintf_0400(void) +{ + char *buf = "u"; + char *testStr = NULL; + int n; + n = asprintf(&testStr, "%s", buf); + free(testStr); + testStr = NULL; + EXPECT_TRUE("asprintf_0400", n > 0); +} + +/** + * @tc.name : asprintf_0500 + * @tc.desc : The parameters are valid and the data can be output according to the format + * @tc.level : Level 0 + */ +void asprintf_0500(void) +{ + char *buf = "f"; + char *testStr = NULL; + int n; + n = asprintf(&testStr, "%s", buf); + free(testStr); + testStr = NULL; + EXPECT_TRUE("asprintf_0500", n > 0); +} + +/** + * @tc.name : asprintf_0600 + * @tc.desc : The parameters are valid and the data can be output according to the format + * @tc.level : Level 0 + */ +void asprintf_0600(void) +{ + char *buf = "e,E"; + char *testStr = NULL; + int n; + n = asprintf(&testStr, "%s", buf); + free(testStr); + testStr = NULL; + EXPECT_TRUE("asprintf_0600", n > 0); +} + +/** + * @tc.name : asprintf_0700 + * @tc.desc : The parameters are valid and the data can be output according to the format + * @tc.level : Level 0 + */ +void asprintf_0700(void) +{ + char *buf = "g,G"; + char *testStr = NULL; + int n; + n = asprintf(&testStr, "%s", buf); + free(testStr); + testStr = NULL; + EXPECT_TRUE("asprintf_0700", n > 0); +} + +/** + * @tc.name : asprintf_0800 + * @tc.desc : The parameters are valid and the data can be output according to the format + * @tc.level : Level 0 + */ +void asprintf_0800(void) +{ + char *buf = "c"; + char *testStr = NULL; + int n; + n = asprintf(&testStr, "%s", buf); + free(testStr); + testStr = NULL; + EXPECT_TRUE("asprintf_0800", n > 0); +} + +/** + * @tc.name : asprintf_0900 + * @tc.desc : The parameters are valid and the data can be output according to the format + * @tc.level : Level 0 + */ +void asprintf_0900(void) +{ + char *buf = "s"; + char *testStr = NULL; + int n; + n = asprintf(&testStr, "%s", buf); + free(testStr); + testStr = NULL; + EXPECT_TRUE("asprintf_0900", n > 0); +} + +TEST_FUN G_Fun_Array[] = { + asprintf_0100, + asprintf_0200, + asprintf_0300, + asprintf_0400, + asprintf_0500, + asprintf_0600, + asprintf_0700, + asprintf_0800, + asprintf_0900, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/clearerr.c b/libc-test/src/functionalext/supplement/stdio/clearerr.c new file mode 100644 index 00000000..dd8d7ff0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/clearerr.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : clearerr_0100 + * @tc.desc : The parameter is valid and can clear (reset) the error flag of the file stream. + * @tc.level : Level 0 + */ +void clearerr_0100(void) +{ + int c; + putc('c', stdin); + if (ferror(stdin)) { + clearerr(stdin); + } + EXPECT_EQ("clearerr_0100", ferror(stdin), 0); +} + +int main() +{ + clearerr_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/dprintf.c b/libc-test/src/functionalext/supplement/stdio/dprintf.c new file mode 100644 index 00000000..8c69d273 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/dprintf.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_NEGATIVE = -1; + +/** + * @tc.name : dprintf_0100 + * @tc.desc : Verify the number of characters returned by the function (if the file parameter is stdout) + * @tc.level : Level 0 + */ +void dprintf_0100(void) +{ + int result; + result = dprintf(1, "This is a test!!QAZ@WSX12"); + printf("\n"); + int ret; + ret = strlen("This is a test!!QAZ@WSX12"); + EXPECT_EQ("dprintf_0100", result, ret); +} + +/** + * @tc.name : dprintf_0200 + * @tc.desc : Verify the number of characters returned by the function (if the file argument is stderr) + * @tc.level : Level 0 + */ +void dprintf_0200(void) +{ + int result; + result = dprintf(2, "This is a test!"); + printf("\n"); + int ret; + ret = strlen("This is a test!"); + EXPECT_EQ("dprintf_0200", result, ret); +} + +/** + * @tc.name : dprintf_0300 + * @tc.desc : Verify the number of characters returned by the function + (if the file is successfully opened in W mode and its return value is used as a file parameter) + * @tc.level : Level 0 + */ +void dprintf_0300(void) +{ + int result; + int fd = open("test.txt", O_CREAT | O_WRONLY); + result = dprintf(fd, "This is a test!"); + int ret; + ret = strlen("This is a test!"); + close(fd); + remove("test.txt"); + EXPECT_EQ("dprintf_0300", result, ret); +} + +/** + * @tc.name : dprintf_0400 + * @tc.desc : Verify the number of characters returned by the function + (if the file is successfully opened in R mode and its return value is used as a file parameter) + * @tc.level : Level 2 + */ +void dprintf_0400(void) +{ + int result; + int fd = open("test.txt", O_CREAT | O_RDONLY); + result = dprintf(fd, "This is a test!"); + close(fd); + remove("test.txt"); + EXPECT_EQ("dprintf_0400", result, COUNT_NEGATIVE); +} + +int main() +{ + dprintf_0100(); + dprintf_0200(); + dprintf_0300(); + dprintf_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/fflush.c b/libc-test/src/functionalext/supplement/stdio/fflush.c new file mode 100644 index 00000000..83f816b1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fflush.c @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int32_t INIT_LEN = 0; + +/** + * @tc.name : fflush_0100 + * @tc.desc : Verify fflush process success and return 0. + * @tc.level : level 0 + */ +void fflush_0100(void) +{ + int32_t ret = fflush(NULL); + EXPECT_EQ("fflush_0100", ret, INIT_LEN); +} + +/** + * @tc.name : fflush_0200 + * @tc.desc : Verify fflush and stdout process success and return 0. + * @tc.level : level 0 + */ +void fflush_0200(void) +{ + char array[] = "this is fflush test!"; + int32_t ret = fprintf(stdout, "%s", array); + EXPECT_MT("fflush_0200", ret, 0); + ret = fflush(NULL); + EXPECT_EQ("fflush_0200", ret, INIT_LEN); +} + +/** + * @tc.name : fflush_0300 + * @tc.desc : Verify fflush and stderr process success and return 0. + * @tc.level : level 0 + */ +void fflush_0300(void) +{ + char array[] = "this is fflush error!"; + int32_t ret = fprintf(stderr, "%s", array); + EXPECT_MT("fflush_0300", ret, 0); + ret = fflush(NULL); + EXPECT_EQ("fflush_0300", ret, INIT_LEN); +} + +/** + * @tc.name : fflush_0400 + * @tc.desc : Verify fflush and fopen("w") and fclose process success and return 0. + * @tc.level : level 0 + */ +void fflush_0400(void) +{ + FILE *fptr = fopen("/data/tempory_testff.txt", "w"); + int32_t ret = 0; + if (fptr != NULL) { + fputs("fopen is success", fptr); + ret = fflush(fptr); + fclose(fptr); + } + EXPECT_EQ("fflush_0400", ret, INIT_LEN); +} + +/** + * @tc.name : fflush_0500 + * @tc.desc : Verify fflush and fopen("r") and fclose process success and return 0. + * @tc.level : level 0 + */ +void fflush_0500(void) +{ + FILE *fptr = fopen("/data/tempory_testff.txt", "r"); + int32_t ret = 0; + if (fptr != NULL) { + ret = fflush(fptr); + fclose(fptr); + } + EXPECT_EQ("fflush_0500", ret, INIT_LEN); + remove("/data/tempory_testff.txt"); +} + +int main(void) +{ + fflush_0100(); + fflush_0200(); + fflush_0300(); + fflush_0400(); + fflush_0500(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/fgetln.c b/libc-test/src/functionalext/supplement/stdio/fgetln.c new file mode 100644 index 00000000..9c16d367 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fgetln.c @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" +#include +#include +#include +#include +#include + +/** + * @tc.name : fgetln_0100 + * @tc.desc : Verify that a pointer to the next row can be obtained. + * @tc.level : level 0 + */ +void fgetln_0100(void) +{ + + char *p = NULL; + size_t len; + FILE *fptr = fopen("test.txt", "w+"); + fputs("this is test", fptr); + fprintf(fptr, "\n"); + fputs("that is test.txt", fptr); + fseek(fptr, 0, SEEK_SET); + bool flag = false; + p = fgetln(fptr, &len); + if (p != NULL) { + flag = true; + } + EXPECT_TRUE("fgetln_0100", flag); + fclose(fptr); + remove("test.txt"); +} + +/** + * @tc.name : fgetln_0200 + * @tc.desc : Validation cannot get pointer to next row (f argument invalid) + * @tc.level : level 2 + */ +void fgetln_0200() +{ + char *p = NULL; + size_t len; + FILE *fptr = fopen("test.txt", "w"); + fseek(fptr, 0, SEEK_SET); + bool flag = false; + p = fgetln(fptr, &len); + if (p == NULL) { + flag = true; + } + EXPECT_TRUE("fgetln_0200", flag); + fclose(fptr); +} + +int main() +{ + fgetln_0100(); + fgetln_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/fgetpos.c b/libc-test/src/functionalext/supplement/stdio/fgetpos.c new file mode 100644 index 00000000..0b6cafd2 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fgetpos.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int32_t NUM_ZERO = 0; +const int32_t NUN_ELEVEN = 11; + +/** + * @tc.name : fgetpos_0100 + * @tc.desc : File pointer at the end of a file, the position to which the current file pointer points + * @tc.level : Level 0 + */ +void fgetpos_0100() +{ + fpos_t pos; + int result; + char buff[] = "hello world"; + FILE *fptr = fopen("test.txt", "w+"); + fputs(buff, fptr); + fseek(fptr, 0, SEEK_END); + result = fgetpos(fptr, &pos); + EXPECT_EQ("fgetpos_0100", result, NUM_ZERO); + fclose(fptr); + remove("test.txt"); +} + +/** + * @tc.name : fgetpos_0200 + * @tc.desc : File pointer at the beginning of a file, the location to which the current file pointer points + * @tc.level : Level 0 + */ +void fgetpos_0200() +{ + fpos_t pos; + int result; + char buff[] = "hello world"; + FILE *fptr = fopen("test.txt", "w+"); + fputs(buff, fptr); + fseek(fptr, 0, SEEK_SET); + result = fgetpos(fptr, &pos); + EXPECT_EQ("fgetpos_0200", result, NUM_ZERO); + fclose(fptr); + remove("test.txt"); +} + +/** + * @tc.name : fgetpos_0300 + * @tc.desc : Invalid argument. Cannot get the location of the current file pointer + * @tc.level : Level 2 + */ +void fgetpos_0300() +{ + FILE *fptr = fopen("test.txt", "w+"); + remove("test.txt"); + fpos_t pos; + int result; + result = fgetpos(fptr, &pos); + EXPECT_EQ("fgetpos_0300", result, NUM_ZERO); +} + +TEST_FUN G_Fun_Array[] = { + fgetpos_0100, + fgetpos_0200, + fgetpos_0300, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/fgets.c b/libc-test/src/functionalext/supplement/stdio/fgets.c new file mode 100644 index 00000000..4f09c422 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fgets.c @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : fgets_0100 + * @tc.desc : The parameter n is greater than the number of characters,and all content can be read. + * @tc.level : Level 0 + */ +void fgets_0100(void) +{ + bool successflag = false; + char str[100]; + const char *ptr = "fgetstest.txt"; + char *wrstring = "this is a test\n"; + FILE *fptr = fopen(ptr, "wr+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fflush(fptr); + fseek(fptr, 0L, SEEK_SET); + char *content = fgets(str, 100, fptr); + if (strcmp(content, "this is a test\n") == 0) { + successflag = true; + } + EXPECT_TRUE("fgets_0100", successflag); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; + wrstring = NULL; +} + +/** + * @tc.name : fgets_0200 + * @tc.desc : The parameter n is greater than 2,and part of the content can be read. + * @tc.level : Level 0 + */ +void fgets_0200(void) +{ + char str[5]; + bool successflag = false; + const char *ptr = "fgetstest.txt"; + char *wrstring = "this is a test\n"; + FILE *fptr = fopen(ptr, "wr+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fflush(fptr); + fseek(fptr, 0L, SEEK_SET); + char *content = fgets(str, 5, fptr); + if (strcmp(content, "this") == 0) { + successflag = true; + } + EXPECT_TRUE("fgets_0200", successflag); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : fgets_0300 + * @tc.desc : The parameter n is equal to 2,and part of the content can be read. + * @tc.level : Level 1 + */ +void fgets_0300(void) +{ + char str[2]; + bool successflag = false; + const char *ptr = "fgetstest.txt"; + char *wrstring = "this is a test\n"; + FILE *fptr = fopen(ptr, "wr+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fflush(fptr); + fseek(fptr, 0L, SEEK_SET); + char *content = fgets(str, 2, fptr); + if (strcmp(content, "t") == 0) { + successflag = true; + } + EXPECT_TRUE("fgets_0300", successflag); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : fgets_0400 + * @tc.desc : The parameter n is equal to 1,and the content cannot be read. + * @tc.level : Level 2 + */ +void fgets_0400(void) +{ + char str[2]; + bool successflag = false; + const char *ptr = "fgetstest.txt"; + char *wrstring = "this is a test\n"; + FILE *fptr = fopen(ptr, "wr+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fflush(fptr); + fseek(fptr, 0L, SEEK_SET); + char *content = fgets(str, 1, fptr); + if (*content == 0) { + successflag = true; + } + EXPECT_TRUE("fgets_0400", successflag); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : fgets_0500 + * @tc.desc : The parameter n is equal to 0,and the content cannot be read. + * @tc.level : Level 2 + */ +void fgets_0500(void) +{ + char str[2]; + bool successflag = false; + const char *ptr = "fgetstest.txt"; + char *wrstring = "this is a test\n"; + FILE *fptr = fopen(ptr, "wr+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fflush(fptr); + fseek(fptr, 0L, SEEK_SET); + char *content = fgets(str, 0, fptr); + if (content == NULL) { + successflag = true; + } + EXPECT_TRUE("fgets_0500", successflag); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : fgets_0600 + * @tc.desc : Points to the end of the file,and the content cannot be read. + * @tc.level : Level 2 + */ +void fgets_0600(void) +{ + char str[100]; + bool successflag = false; + const char *ptr = "fgetstest.txt"; + char *wrstring = "this is a test\n"; + FILE *fptr = fopen(ptr, "wr+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fflush(fptr); + fseek(fptr, 0L, SEEK_END); + char *content = fgets(str, 100, fptr); + if (content == NULL) { + successflag = true; + } + EXPECT_TRUE("fgets_0600", successflag); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +int main() +{ + fgets_0100(); + fgets_0200(); + fgets_0300(); + fgets_0400(); + fgets_0500(); + fgets_0600(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/fgetws.c b/libc-test/src/functionalext/supplement/stdio/fgetws.c new file mode 100644 index 00000000..38918cf7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fgetws.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : fgetws_0100 + * @tc.desc : Verify that a string of wide characters can be read from the specified file + * @tc.level : Level 0 + */ +void fgetws_0100() +{ + bool flag = false; + wchar_t wrstring[100]; + wchar_t line[] = L"hello\n"; + const char *ptr = "test.txt"; + wchar_t *ch; + FILE *fptr = fopen(ptr, "w+"); + fwrite(line, sizeof(char), 100, fptr); + fseek(fptr, 0, SEEK_SET); + rewind(fptr); + ch = fgetws(wrstring, 100, fptr); + if (ch > 0) + { + flag = true; + } + EXPECT_TRUE("fgetws_0100", flag); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : fgetws_0200 + * @tc.desc : Verify that a string of wide characters cannot be read from the specified file + * @tc.level : Level 2 + */ +void fgetws_0200() +{ + bool flag = false; + wchar_t wrstring[100]; + wchar_t line[] = L"hello\n"; + const char *ptr = "test.txt"; + wchar_t *ch = NULL; + FILE *fptr = fopen(ptr, "w+"); + fwrite(line, sizeof(char), 100, fptr); + fflush(fptr); + ch = fgetws(wrstring, EINVAL, fptr); + EXPECT_TRUE("fgetws_0200", ch <= 0); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +int main() +{ + fgetws_0100(); + fgetws_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/flockfile.c b/libc-test/src/functionalext/supplement/stdio/flockfile.c new file mode 100644 index 00000000..8b6b0000 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/flockfile.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +void *pthreadFunc(FILE *fptr) +{ + pthread_t newthid; + newthid = pthread_self(); + char buf[] = "test1"; + fwrite(buf, 1, sizeof(buf), fptr); + fseek(fptr, 0, SEEK_END); + return NULL; +} + +/** + * @tc.name : flockfile_0100 + * @tc.desc : Verify that files can be locked + * @tc.level : Level 0 + */ +void flockfile_0100(void) +{ + FILE *fptr; + pthread_t tid; + char buf[] = "test"; + char buff[1024] = "\0"; + bzero(buff, sizeof(buf)); + fptr = fopen("test.txt", "w+"); + ftrylockfile(fptr); + fwrite(buf, 1, strlen(buf), fptr); + fseek(fptr, 0, SEEK_END); + int ret1 = pthread_create(&tid, NULL, (void *)pthreadFunc, fptr); + sleep(3); + rewind(fptr); + fgets(buff, 1024, fptr); + EXPECT_STREQ("flockfile_0100", buf, buff); + fclose(fptr); + remove("test.txt"); +} + +int main() +{ + flockfile_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/fopen.c b/libc-test/src/functionalext/supplement/stdio/fopen.c new file mode 100644 index 00000000..1d29f311 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fopen.c @@ -0,0 +1,329 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t INIT_LEN = 0; +const int32_t INCREASE_LEN = 1; +const int32_t CREAT_MODE = 666; + +/** + * @tc.name : fopen_0100 + * @tc.desc : Verify fopen("r") and fclose fread and fwrite, fopen success, fread success, fwrite failed + * @tc.level : level 0. + */ +void fopen_0100(void) +{ + char abc[100] = {0}; + const char *add = "this is tempory test!"; + const char *wrstring = "to write"; + const char *wstring = "this is tempory test!"; + int ret = creat("tempory_test.txt", CREAT_MODE); + if (ret < 0) { + EXPECT_MT("fopen_0100", ret, 0); + return; + } + FILE *fptr = fopen("tempory_test.txt", "w"); + if (fptr != NULL) { + size_t wrsize = fwrite(wstring, sizeof(char), strlen(wstring), fptr); + if (wrsize == INIT_LEN) { + EXPECT_EQ("fopen_0100", wrsize, INIT_LEN); + } + fclose(fptr); + } + fptr = fopen("tempory_test.txt", "r"); + bool writeFailedFlag = false; + bool consistentFlag = false; + if (fptr != NULL) { + while (!feof(fptr)) { + int32_t rsize = fread(abc, sizeof(abc), 1, fptr); + EXPECT_EQ("pread_0100", rsize, 0); + } + if (!strncmp(abc, add, strlen(add))) { + consistentFlag = true; + } + + size_t wrsize = fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + if (wrsize == INIT_LEN) { + writeFailedFlag = true; + } + fclose(fptr); + } + + EXPECT_TRUE("fopen_0100", writeFailedFlag); + EXPECT_TRUE("fopen_0100", consistentFlag); + remove("tempory_test.txt"); +} + +/** + * @tc.name : fopen_0200 + * @tc.desc : Verify fopen("r") and fclose and fopen failed + * @tc.level : level 2. + */ +void fopen_0200(void) +{ + FILE *fptr = fopen("tempory_test1.txt", "r"); + EXPECT_EQ("fopen_0200", fptr, NULL); +} + +/** + * @tc.name : fopen_0300 + * @tc.desc : Verify fopen("w") and fclose and fread and fwrite and fopen success, fread failed, fwrite success + * @tc.level : level 0. + */ +void fopen_0300(void) +{ + int32_t rsize = 0; + char abc[100] = {0}; + const char *wrstring = "to write"; + FILE *fptr = fopen("tempory_test3.txt", "w"); + bool writeSuccessFlag = false; + + if (fptr != NULL) { + rsize = fread(abc, sizeof(abc), 1, fptr); + size_t wrsize = fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + if (wrsize == INIT_LEN) { + EXPECT_EQ("fopen_0300", wrsize, INIT_LEN); + ; + } else if (wrsize == strlen(wrstring)) { + writeSuccessFlag = true; + } + fclose(fptr); + } + + EXPECT_EQ("fopen_0300", rsize, INIT_LEN); + EXPECT_TRUE("fopen_0300", writeSuccessFlag); + remove("tempory_test3.txt"); +} + +/** + * @tc.name : fopen_0400 + * @tc.desc : Verify fopen("w") and fclose and fread and fwrite and fopen success, fread failed, fwrite success + * @tc.level : level 1. + */ +void fopen_0400(void) +{ + int32_t rsize = 0; + char abc[100] = {0}; + const char *wrstring = "to write"; + FILE *fptr = fopen("tempory_test2.txt", "w"); + bool writeSuccessFlag = false; + + if (fptr != NULL) { + rsize = fread(abc, sizeof(abc), 1, fptr); + + size_t wrsize = fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + if (wrsize == INIT_LEN) { + EXPECT_EQ("fopen_0400", wrsize, INIT_LEN); + } else if (wrsize == strlen(wrstring)) { + writeSuccessFlag = true; + } + fclose(fptr); + } + + EXPECT_EQ("fopen_0400", rsize, INIT_LEN); + EXPECT_TRUE("fopen_0400", writeSuccessFlag); + remove("tempory_test2.txt"); +} + +/** + * @tc.name : fopen_0500 + * @tc.desc : Verify fopen("a") and fclose and fread and fwrite and fopen success, fread success, fwrite success + * @tc.level : level 0. + */ +void fopen_0500(void) +{ + char abc[100] = {0}; + const char *add = "this is tempory test!to write"; + const char *wrstring = "to write"; + const char *wstring = "this is tempory test!"; + int ret = creat("tempory_test5.txt", CREAT_MODE); + if (ret < 0) { + EXPECT_MT("fopen_0500", ret, 0); + return; + } + FILE *fptr = fopen("tempory_test5.txt", "w"); + if (fptr != NULL) { + size_t wrsize = fwrite(wstring, sizeof(char), strlen(wstring), fptr); + if (wrsize == INIT_LEN) { + EXPECT_EQ("fopen_0500", wrsize, INIT_LEN); + } + fclose(fptr); + } + + fptr = fopen("tempory_test5.txt", "a"); + bool writeSuccessFlag = false; + bool consistentFlag = false; + if (fptr != NULL) { + fseek(fptr, 0, SEEK_SET); + size_t wrsize = fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + if (wrsize == INIT_LEN) { + EXPECT_EQ("fopen_0500", wrsize, INIT_LEN); + } else if (wrsize == strlen(wrstring)) { + writeSuccessFlag = true; + } + fclose(fptr); + } + + fptr = fopen("tempory_test5.txt", "r"); + if (fptr != NULL) { + while (!feof(fptr)) { + int32_t rsize = fread(abc, sizeof(abc), 1, fptr); + EXPECT_EQ("pread_0500", rsize, 0); + } + if (!strncmp(abc, add, strlen(add))) { + consistentFlag = true; + } + fclose(fptr); + } + + EXPECT_TRUE("fopen_0500", writeSuccessFlag); + EXPECT_TRUE("fopen_0500", consistentFlag); + remove("tempory_test5.txt"); +} + +/** + * @tc.name : fopen_0600 + * @tc.desc : Verify fopen("a") and fclose and fread and fwrite and fopen success, fread success, fwrite success + * @tc.level : level 1. + */ +void fopen_0600(void) +{ + int32_t rsize = 0; + char abc[100] = {0}; + const char *wrstring = "to write"; + FILE *fptr = fopen("tempory_test6.txt", "w"); + bool writeSuccessFlag = false; + + if (fptr != NULL) { + rsize = fread(abc, sizeof(abc), 1, fptr); + + size_t wrsize = fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + if (wrsize == INIT_LEN) { + EXPECT_EQ("fopen_0600", wrsize, INIT_LEN); + ; + } else if (wrsize == strlen(wrstring)) { + writeSuccessFlag = true; + } + fclose(fptr); + } + + EXPECT_EQ("fopen_0600", rsize, INIT_LEN); + EXPECT_TRUE("fopen_0600", writeSuccessFlag); + remove("tempory_test6.txt"); +} + +/** + * @tc.name : fopen_0700 + * @tc.desc : Verify fopen("b") and fclose and fread and fwrite and fopen failed + * @tc.level : level 2. + */ +void fopen_0700(void) +{ + FILE *fptr = fopen("./tempory_test.txt", "b"); + int32_t flag = INIT_LEN; + if (fptr == NULL) { + EXPECT_EQ("fopen_0700", errno, EINVAL); + } else { + flag++; + EXPECT_EQ("fopen_0700", flag, INCREASE_LEN); + } +} + +/** + * @tc.name : fopen_0800 + * @tc.desc : Verify fopen("a") and fclose and fread and fwrite and fopen failed + * @tc.level : level 2. + */ +void fopen_0800(void) +{ + FILE *fptr = fopen("./tmp/tempory_test.txt", "a"); + EXPECT_EQ("fopen_0800", fptr, NULL); +} + +/** + * @tc.name : fopen_0900 + * @tc.desc : Verify fopen("ae") and fclose and fread and fwrite and fopen success, fread success, fwrite success + * @tc.level : level 0. + */ +void fopen_0900(void) +{ + char abc[100] = {0}; + const char *add = "this is tempory test!to write"; + const char *wrstring = "to write"; + const char *wstring = "this is tempory test!"; + int ret = creat("tempory_test9.txt", CREAT_MODE); + if (ret < 0) { + EXPECT_MT("fopen_0900", ret, 0); + return; + } + FILE *fptr = fopen("tempory_test9.txt", "w"); + if (fptr != NULL) { + size_t wrsize = fwrite(wstring, sizeof(char), strlen(wstring), fptr); + if (wrsize == INIT_LEN) { + EXPECT_EQ("fopen_0900", wrsize, INIT_LEN); + ; + } + fclose(fptr); + } + + fptr = fopen("tempory_test9.txt", "ae"); + bool writeSuccessFlag = false; + bool consistentFlag = false; + if (fptr != NULL) { + size_t wrsize = fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + if (wrsize == INIT_LEN) { + EXPECT_EQ("fopen_0900", wrsize, INIT_LEN); + ; + } else if (wrsize == strlen(wrstring)) { + writeSuccessFlag = true; + } + fclose(fptr); + } + + fptr = fopen("tempory_test9.txt", "r"); + if (fptr != NULL) { + while (!feof(fptr)) { + int32_t rsize = fread(abc, sizeof(abc), 1, fptr); + EXPECT_EQ("pread_0900", rsize, 0); + } + if (!strncmp(abc, add, strlen(add))) { + consistentFlag = true; + } + fclose(fptr); + } + remove("tempory_test9.txt"); + + EXPECT_TRUE("fopen_0900", writeSuccessFlag); + EXPECT_TRUE("fopen_0900", consistentFlag); +} + +int main(void) +{ + fopen_0100(); + fopen_0200(); + fopen_0300(); + fopen_0400(); + fopen_0500(); + fopen_0600(); + fopen_0700(); + fopen_0800(); + fopen_0900(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/fprintf.c b/libc-test/src/functionalext/supplement/stdio/fprintf.c new file mode 100644 index 00000000..d10619d7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fprintf.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int32_t ERRORLEN = -1; + +/** + * @tc.name: fprintf_0100 + * @tc.desc: Verify fprintf and stdout process success. + * @tc.level: level 0. + */ +void fprintf_0100(void) +{ + char str[] = "This is a fprintf_0100"; + int32_t len = fprintf(stdout, "%s", str); + EXPECT_EQ("fprintf_0100", len, strlen(str)); +} + +/** + * @tc.name: fprintf_0200 + * @tc.desc: Verify fprintf and stderr process success. + * @tc.level: level 0. + */ +void fprintf_0200(void) +{ + char str[] = "This is a test fprintf_0200"; + int32_t len = fprintf(stderr, "%s", str); + EXPECT_EQ("fprintf_0200", len, strlen(str)); +} + +/** + * @tc.name: fprintf_0300 + * @tc.desc: Verify fprintf and fopen("w") process success. + * @tc.level: level 0. + */ +void fprintf_0300(void) +{ + char str[] = "这是一个测试"; + int len = 0; + FILE *fptr = fopen("tempory_testfprintf.txt", "w"); + if (fptr != NULL) { + len = fprintf(fptr, "%s", str); + fclose(fptr); + } + EXPECT_EQ("fprintf_0300", len, strlen(str)); +} + +/** + * @tc.name: fprintf_0400 + * @tc.desc: Verify fflush and fopen("r") and fclose and return -1. + * @tc.level: level 2. + */ +void fprintf_0400(void) +{ + char str[] = "这是一个测试"; + int32_t len = 0; + FILE *fptr = fopen("tempory_testfprintf.txt", "r"); + if (fptr != NULL) { + len = fprintf(fptr, "%s", str); + fclose(fptr); + } + EXPECT_EQ("fprintf_0400", len, ERRORLEN); + remove("tempory_testfprintf.txt"); +} + +int main(void) +{ + fprintf_0100(); + fprintf_0200(); + fprintf_0300(); + fprintf_0400(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/fputc.c b/libc-test/src/functionalext/supplement/stdio/fputc.c new file mode 100644 index 00000000..8ce18dd4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fputc.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : fputc_0100 + * @tc.desc : Verify that a character can be written to the file + * @tc.level : level 0. + */ +void fputc_0100(void) +{ + FILE *fptr = NULL; + fptr = fopen("/data/tests/libc-test/src/functionalext/supplement/stdio/fputc.txt", "w"); + int Exit = fputc('a', fptr); + EXPECT_EQ("fputc_0100", Exit, 97); + fclose(fptr); + fptr = NULL; +} + +/** + * @tc.name : fputc_0200 + * @tc.desc : Verify that a character cannot be written to the file + * @tc.level : level 2. + */ +void fputc_0200(void) +{ + FILE *fptr = NULL; + fptr = fopen("/data/tests/libc-test/src/functionalext/supplement/stdio/fputc.txt", "r"); + int Exit = fputc('a', fptr); + EXPECT_EQ("fputc_0200", Exit, EOF); + fclose(fptr); + remove("/data/tests/libc-test/src/functionalext/supplement/stdio/fputc.txt"); + fptr = NULL; +} + +int main(void) +{ + fputc_0100(); + fputc_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/fputs.c b/libc-test/src/functionalext/supplement/stdio/fputs.c new file mode 100644 index 00000000..5c50419c --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fputs.c @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" +const int SUCCESS = 0; + +/** + * @tc.name : fputs_0100 + * @tc.desc : Verify that an empty string is written in the specified file. + * @tc.level : level 0. + */ +void fputs_0100(void) +{ + char str[80] = "string\n"; + FILE *fptr = NULL; + fptr = fopen("/data/tests/libc-test/src/functionalext/supplement/stdio/fputs.txt", "w+"); + if (fptr == NULL) { + perror("fopen"); + } + int len = fputs(str, fptr); + EXPECT_EQ("fputs_0100", len, SUCCESS); + fclose(fptr); + remove("/data/tests/libc-test/src/functionalext/supplement/stdio/fputs.txt"); + fptr = NULL; +} + +/** + * @tc.name : fputs_0200 + * @tc.desc : Verify that an empty string is written in the specified file (parameter is empty). + * @tc.level : level 0. + */ +void fputs_0200(void) +{ + FILE *fptr = NULL; + fptr = fopen("/data/tests/libc-test/src/functionalext/supplement/stdio/fputs.txt", "w+"); + if (fptr == NULL) { + perror("fopen"); + } + int len = fputs("", fptr); + EXPECT_EQ("fputs_02 00", len, SUCCESS); + fclose(fptr); + remove("/data/tests/libc-test/src/functionalext/supplement/stdio/fputs.txt"); + fptr = NULL; +} + +/** + * @tc.name : fputs_0300 + * @tc.desc : Verify that an empty string cannot be written to the specified file. + * @tc.level : level 2. + */ +void fputs_0300(void) +{ + FILE *fptr = NULL; + FILE *p = fopen("/data/tests/libc-test/src/functionalext/supplement/stdio/fputs.txt", "w"); + fclose(p); + fptr = fopen("/data/tests/libc-test/src/functionalext/supplement/stdio/fputs.txt", "r"); + int rsize = fputs("this is a test string", fptr); + EXPECT_EQ("fputs_0300", rsize, EOF); + remove("/data/tests/libc-test/src/functionalext/supplement/stdio/fputs.txt"); + fptr = NULL; +} + +int main() +{ + fputs_0100(); + fputs_0200(); + fputs_0300(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/fputwc.c b/libc-test/src/functionalext/supplement/stdio/fputwc.c new file mode 100644 index 00000000..ea18285e --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fputwc.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; +const int STRING_EQUAL = 0; + +/** + * @tc.name : fputwc_0100 + * @tc.desc : Each parameter is valid, a single call can output wide characters to the file stream + * @tc.level : Level 0 + */ +void fputwc_0100() +{ + wchar_t str[] = L"T"; + wchar_t buf[100]; + wint_t wc; + int ri = 0; + int j = 0; + FILE *fp = fopen("file.txt", "w+"); + if (fp) { + for (unsigned int i = 0; i < wcslen(str); i++) { + wc = fputwc(str[i], fp); + if (wc != str[i]) { + ri++; + } + } + } else { + perror("File opening failed"); + } + fclose(fp); + FILE *ffp = fopen("file.txt", "r"); + fgetws(buf, wcslen(str) + 1, ffp); + EXPECT_EQ("fputwc_0100", ri, 0); + EXPECT_EQ("fputwc_0100", wcscoll(buf, str), STRING_EQUAL); + fclose(ffp); + system("rm -rf file.txt"); +} + +/** + * @tc.name : fputwc_0200 + * @tc.desc : Each parameter is valid, called multiple times, and can output wide characters to the file stream + * @tc.level : Level 1 + */ +void fputwc_0200() +{ + wchar_t str[] = L"This is a test"; + wchar_t buf[100]; + wint_t wc; + int ri = 0; + int j = 0; + FILE *fp = fopen("file.txt", "w+"); + if (fp) { + for (unsigned int i = 0; i < wcslen(str); i++) { + wc = fputwc(str[i], fp); + if (wc != str[i]) { + ri++; + } + } + } else { + perror("File opening failed"); + } + fclose(fp); + FILE *ffp = fopen("file.txt", "r"); + fgetws(buf, wcslen(str) + 1, ffp); + EXPECT_EQ("fputwc_0200", ri, 0); + EXPECT_EQ("fputwc_0200", wcscoll(buf, str), STRING_EQUAL); + fclose(ffp); + system("rm -rf file.txt"); +} + +int main() +{ + fputwc_0100(); + fputwc_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/fputws.c b/libc-test/src/functionalext/supplement/stdio/fputws.c new file mode 100644 index 00000000..091a65e6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fputws.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int FAILED = -1; + +/** + * @tc.name : fputws_0100 + * @tc.desc : Each parameter is valid and can output a wide character string to a file stream. + * @tc.level : Level 0 + */ +void fputws_0100(void) +{ + char str[100] = {0}; + const char *ptr = "fputwstest.txt"; + FILE *fptr = fopen(ptr, "w+"); + EXPECT_TRUE("fputws_0100", fptr != NULL); + setlocale(LC_ALL, "en_US.utf8"); + int ret = fputws(L"this is the test", fptr); + EXPECT_TRUE("fputws_0100", ret >= 0); + fseek(fptr, 0, SEEK_SET); + int rsize = fread(str, sizeof(char), 100, fptr); + EXPECT_EQ("fputws_0100", rsize, ret); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : fputws_0200 + * @tc.desc : The f parameter is invalid, a wide string cannot be output to a file stream. + * @tc.level : Level 2 + */ +void fputws_0200(void) +{ + const char *ptr = "fputwstest.txt"; + FILE *fptr = fopen(ptr, "w+"); + EXPECT_TRUE("fputws_0200", fptr != NULL); + fclose(fptr); + fptr = fopen(ptr, "r"); + EXPECT_TRUE("fputws_0200", fptr != NULL); + int ret = fputws(L"this is the test", fptr); + EXPECT_EQ("fputws_0200", ret, FAILED); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +int main() +{ + fputws_0100(); + fputws_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/fread.c b/libc-test/src/functionalext/supplement/stdio/fread.c new file mode 100644 index 00000000..714d2c8f --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fread.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int32_t NUM_ZERO = 0; +const int32_t NUM_TEN = 10; +const int32_t NUM_TWENTY = 20; + +/** + * @tc.name : fread_0100 + * @tc.desc : Verify that the number of data read is less than the number of data in the file + * @tc.level : Level 0 + */ +void fread_0100(void) +{ + char abc[100] = {0}; + const char *wrstring = "starttowritehelloworld"; + const char *ptr = "Freadtest.txt"; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fseek(fptr, 0, SEEK_SET); + int32_t rsize = fread(abc, 1, 10, fptr); + EXPECT_EQ("fread_0100", rsize, NUM_TEN); + EXPECT_STREQ("fread_0100", abc, "starttowri"); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : fread_0200 + * @tc.desc : Verify that the number of data read is greater than the number of data in the file + * @tc.level : Level 1 + */ +void fread_0200(void) +{ + char abc[100] = {0}; + const char *wrstring = "startwritehelloworld"; + const char *ptr = "Freadtest.txt"; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fseek(fptr, 0, SEEK_SET); + int32_t rsize = fread(abc, 1, 25, fptr); + EXPECT_EQ("fread_0200", rsize, NUM_TWENTY); + EXPECT_STREQ("fread_0200", abc, wrstring); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : fread_0300 + * @tc.desc : Verify that the number of data read is greater than the number of data in the file + * (the file pointer is at the end) + * @tc.level : Level 2 + */ +void fread_0300(void) +{ + char abc[100] = {0}; + const char *wrstring = "startwritehelloworld"; + const char *ptr = "Freadtest.txt"; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fseek(fptr, 0, SEEK_END); + int32_t rsize = fread(abc, 1, 10, fptr); + EXPECT_EQ("fread_0300", rsize, NUM_ZERO); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : fread_0400 + * @tc.desc : Verify that the size parameter is invalid and cannot read the specified file content + * @tc.level : Level 2 + */ +void fread_0400(void) +{ + char abc[100] = {0}; + const char *wrstring = "startwritehelloworld"; + const char *ptr = "Freadtest.txt"; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fseek(fptr, 0, SEEK_END); + int32_t rsize = fread(abc, 0, 10, fptr); + EXPECT_EQ("fread_0400", rsize, NUM_ZERO); + fclose(fptr); + remove(ptr); +} + +TEST_FUN G_Fun_Array[] = { + fread_0100, + fread_0200, + fread_0300, + fread_0400, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/freopen.c b/libc-test/src/functionalext/supplement/stdio/freopen.c new file mode 100644 index 00000000..fbf0256f --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/freopen.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : freopen_0100 + * @tc.desc : Each parameter is valid, f is stdin, which can realize input redirection. + * @tc.level : Level 0 + */ +void freopen_0100(void) +{ + int flag = false; + FILE *fp; + FILE *fd; + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/freopen.txt"; + fd = freopen(ptr, "w+", stdin); + if (fd != 0) { + flag = true; + } + EXPECT_TRUE("freopen_0100", flag); + fclose(stdin); + fclose(fd); + remove(ptr); +} + +TEST_FUN G_Fun_Array[] = { + freopen_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/fseeko.c b/libc-test/src/functionalext/supplement/stdio/fseeko.c new file mode 100644 index 00000000..fff3467f --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fseeko.c @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : fseeko_0100 + * @tc.desc : Verify that the file pointer is moved to the beginning of the file + * @tc.level : Level 0 + */ +void fseeko_0100(void) +{ + const char *wrstring = "This is a test sample!"; + const char *ptr = "test.txt"; + char ch; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + int32_t data = fseek(fptr, 0L, SEEK_SET); + ch = fgetc(fptr); + EXPECT_EQ("fseeko_0100", data, 0); + EXPECT_EQ("fseeko_0100", ch, 'T'); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : fseeko_0200 + * @tc.desc : Verify that the file pointer is moved to any position in the file + * @tc.level : Level 0 + */ +void fseeko_0200(void) +{ + const char *wrstring = "This is a test sample!"; + const char *ptr = "test.txt"; + char ch; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + int32_t data = fseek(fptr, 8L, SEEK_SET); + ch = fgetc(fptr); + EXPECT_EQ("fseeko_0200", data, 0); + EXPECT_EQ("fseeko_0200", ch, 'a'); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : fseeko_0300 + * @tc.desc : Verify that the file pointer is moved to the current position of the file + * @tc.level : Level 0 + */ +void fseeko_0300(void) +{ + const char *wrstring = "This is a test sample!"; + const char *ptr = "test.txt"; + char ch; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + int32_t code = fseek(fptr, 10L, SEEK_SET); + int32_t data = fseek(fptr, 0L, SEEK_CUR); + ch = fgetc(fptr); + EXPECT_EQ("fseeko_0300", data, 0); + EXPECT_EQ("fseeko_0300", ch, 't'); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : fseeko_0400 + * @tc.desc : Verify that the file pointer is moved to the end of the file + * @tc.level : Level 0 + */ +void fseeko_0400(void) +{ + const char *wrstring = "This is a test sample!"; + const char *ptr = "test.txt"; + char ch; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + int32_t data = fseek(fptr, -1L, SEEK_END); + ch = fgetc(fptr); + EXPECT_EQ("fseeko_0400", data, 0); + EXPECT_EQ("fseeko_0400", ch, '!'); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : fseeko_0500 + * @tc.desc : Verify that the moved file pointer position exceeds the starting position pointer movement failed + * @tc.level : Level 2 + */ +void fseeko_0500(void) +{ + const char *wrstring = "This is a test sample!"; + const char *ptr = "test.txt"; + char ch; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + int32_t data = fseek(fptr, -10L, SEEK_SET); + ch = fgetc(fptr); + EXPECT_EQ("fseeko_0500", data, -1); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : fseeko_0600 + * @tc.desc : Verify that the moved file pointer position exceeds the end position pointer movement failed + * @tc.level : Level 1 + */ +void fseeko_0600(void) +{ + const char *wrstring = "This is a test sample!"; + const char *ptr = "test.txt"; + char ch; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + int32_t data = fseek(fptr, 10L, SEEK_END); + ch = fgetc(fptr); + EXPECT_EQ("fseeko_0600", data, 0); + fclose(fptr); + remove(ptr); +} + +TEST_FUN G_Fun_Array[] = { + fseeko_0100, + fseeko_0200, + fseeko_0300, + fseeko_0400, + fseeko_0500, + fseeko_0600, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/fsetpos.c b/libc-test/src/functionalext/supplement/stdio/fsetpos.c new file mode 100644 index 00000000..5604288d --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fsetpos.c @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int SUCCESS = 0; +const int SIZE = 20; +const int HALF_SIZE = 10; +const int END_SIZE = 0; + +/** + * @tc.name : fsetpos_0100 + * @tc.desc : Each parameter is valid, and the file pointer is set to the beginning of the file. + * @tc.level : Level 0 + */ +void fsetpos_0100() +{ + char str[100] = {0}; + const char *ptr = "test.txt"; + const char *wstring = "This is a test case!"; + long long a = 0; + fpos_t pos; + pos = (fpos_t)a; + FILE *fptr = fopen(ptr, "w+"); + EXPECT_TRUE("fsetpos_0100", fptr != NULL); + fwrite(wstring, sizeof(char), strlen(wstring), fptr); + int result = fsetpos(fptr, &pos); + EXPECT_EQ("fsetpos_0100", result, SUCCESS); + int rsize = fread(str, sizeof(char), 100, fptr); + EXPECT_EQ("fsetpos_0100", rsize, SIZE); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : fsetpos_0200 + * @tc.desc : Each parameter is valid, and the file pointer is set to the middle of the file. + * @tc.level : Level 0 + */ +void fsetpos_0200() +{ + char str[100] = {0}; + const char *ptr = "test.txt"; + const char *wstring = "This is a test case!"; + fpos_t pos; + long long a = 10; + pos = (fpos_t)a; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wstring, sizeof(char), strlen(wstring), fptr); + int data = fsetpos(fptr, &pos); + EXPECT_EQ("fsetpos_0200", data, SUCCESS); + int rsize = fread(str, 1, 100, fptr); + EXPECT_EQ("fsetpos_0200", rsize, HALF_SIZE); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; + wstring = NULL; +} + +/** + * @tc.name : fsetpos_0300 + * @tc.desc : Each parameter is valid, and the file pointer is set to the end of the file. + * @tc.level : Level 0 + */ +void fsetpos_0300() +{ + char str[100] = {0}; + const char *ptr = "test.txt"; + const char *wstring = "This is a test case!"; + fpos_t pos; + long long a = 20; + pos = (fpos_t)a; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wstring, sizeof(char), strlen(wstring), fptr); + int data = fsetpos(fptr, &pos); + EXPECT_EQ("fsetpos_0300", data, SUCCESS); + int rsize = fread(str, 1, 100, fptr); + EXPECT_EQ("fsetpos_0300", rsize, END_SIZE); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; + wstring = NULL; +} + +/** + * @tc.name : fsetpos_0400 + * @tc.desc : The pos parameter is valid, and the file pointer cannot be set. + * @tc.level : Level 2 + */ +void fsetpos_0400() +{ + char str[100] = {0}; + const char *ptr = "test.txt"; + const char *wrstring = "This is a test case!"; + fpos_t pos; + long long a = -1; + pos = (fpos_t)a; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + int data = fsetpos(fptr, &pos); + EXPECT_NE("fsetpos_0400", data, SUCCESS); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; + wrstring = NULL; +} + +int main() +{ + fsetpos_0100(); + fsetpos_0200(); + fsetpos_0300(); + fsetpos_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/ftell.c b/libc-test/src/functionalext/supplement/stdio/ftell.c new file mode 100644 index 00000000..e3025a99 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/ftell.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int COUNT_ZERO = 0; +const int COUNT_ZE = -1; +const int COUNT_EIGHT = 8; +const int COUNT_TWENTYTWO = 22; +#define ERROR_LEN 8 + +/** + * @tc.name : ftell_0100 + * @tc.desc : Verify that the file pointer is at the beginning (call the ftell function to see the return value) + * @tc.level : Level 0 + */ +void ftell_0100(void) +{ + const char *wrstring = "This is a test sample!"; + const char *ptr = "test.txt"; + unsigned long filesize = -1; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fseek(fptr, 0L, SEEK_SET); + filesize = ftell(fptr); + EXPECT_EQ("ftell_0100", filesize, COUNT_ZERO); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : ftell_0200 + * @tc.desc : Verify that the file pointer is in the middle (call the ftell function to see the return value) + * @tc.level : Level 0 + */ +void ftell_0200(void) +{ + const char *wrstring = "This is a test sample!"; + const char *ptr = "test.txt"; + unsigned long filesize = -1; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fseek(fptr, 8L, SEEK_SET); + filesize = ftell(fptr); + EXPECT_EQ("ftell_0200", filesize, COUNT_EIGHT); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : ftell_0300 + * @tc.desc : Verify that the file pointer is at the end (call the ftell function to see the return value) + * @tc.level : Level 0 + */ +void ftell_0300(void) +{ + const char *wrstring = "This is a test sample!"; + const char *ptr = "test.txt"; + unsigned long filesize = -1; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fseek(fptr, 0L, SEEK_END); + filesize = ftell(fptr); + EXPECT_EQ("ftell_0300", filesize, COUNT_TWENTYTWO); + fclose(fptr); + remove(ptr); +} + + +TEST_FUN G_Fun_Array[] = { + ftell_0100, + ftell_0200, + ftell_0300, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/ftrylockfile.c b/libc-test/src/functionalext/supplement/stdio/ftrylockfile.c new file mode 100644 index 00000000..8b31d2cd --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/ftrylockfile.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : ftrylockfile_0100 + * @tc.desc : The parameter is valid, the ftrylockfile function can lock the file. + * @tc.level : Level 0 + */ +void ftrylockfile_0100(void) +{ + int ret = -1; + FILE *fptr = fopen("ftrylockfile.txt", "w+"); + ret = ftrylockfile(fptr); + EXPECT_EQ("ftrylockfile_0100", ret, 0); + funlockfile(fptr); + fclose(fptr); + remove("ftrylockfile.txt"); +} + +TEST_FUN G_Fun_Array[] = { + ftrylockfile_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/funlockfile.c b/libc-test/src/functionalext/supplement/stdio/funlockfile.c new file mode 100644 index 00000000..afb5d891 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/funlockfile.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +void *pthreadFunc(FILE *fptr) +{ + pthread_t newthid; + newthid = pthread_self(); + char buf[] = "test1"; + fwrite(buf, 1, sizeof(buf), fptr); + fseek(fptr, 0, SEEK_END); + return NULL; +} +void *pthreadFunc1(FILE *fptr) +{ + pthread_t newthid; + newthid = pthread_self(); + char buf[] = "test2"; + fwrite(buf, 1, sizeof(buf), fptr); + fseek(fptr, 0, SEEK_END); + return NULL; +} + +/** + * @tc.name : funlockfile_0100 + * @tc.desc : Verify that files can be locked + * @tc.level : Level 0 + */ +void funlockfile_0100(void) +{ + FILE *fptr; + pthread_t tid; + pthread_t tid1; + char buf[] = "test"; + char buff[1024] = "\0"; + char bufff[] = "testtest1"; + bzero(buff, sizeof(buf)); + fptr = fopen("test.txt", "w+"); + ftrylockfile(fptr); + fwrite(buf, 1, strlen(buf), fptr); + fseek(fptr, 0, SEEK_END); + int ret1 = pthread_create(&tid, NULL, (void *)pthreadFunc, fptr); + sleep(1); + fseek(fptr, 0, SEEK_END); + funlockfile(fptr); + int ret2 = pthread_create(&tid1, NULL, (void *)pthreadFunc1, fptr); + sleep(1); + rewind(fptr); + fgets(buff, 1024, fptr); + EXPECT_STREQ("funlockfile_0100", bufff, buff); + fclose(fptr); + remove("test.txt"); +} + +int main() +{ + funlockfile_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/fwide.c b/libc-test/src/functionalext/supplement/stdio/fwide.c new file mode 100644 index 00000000..8b23f42a --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fwide.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; + +/** + * @tc.name : fwide_0100 + * @tc.desc : Verify that the set byte stream is a wide character stream (valid, mode > 0) + * @tc.level : Level 0 + */ +void fwide_0100(void) +{ + FILE *fptr = fopen("test.txt", "w+"); + int result; + bool flag = false; + result = fwide(fptr, 5); + if (result > 0) { + flag = true; + } + EXPECT_TRUE("fwide_0100", flag); + fclose(fptr); + remove("test.txt"); +} + +/** + * @tc.name : fwide_0200 + * @tc.desc : Verify that the set byte stream remains as it is (all parameters are valid, mode equals 0) + * @tc.level : Level 0 + */ +void fwide_0200(void) +{ + FILE *fptr = fopen("test.txt", "w+"); + int result; + result = fwide(fptr, 0); + EXPECT_EQ("fwide_0200", result, COUNT_ZERO); + fclose(fptr); + remove("test.txt"); +} + +/** + * @tc.name : fwide_0300 + * @tc.desc : Verify that the set byte stream is a multi-byte character stream (valid with mode less than 0) + * @tc.level : Level 0 + */ +void fwide_0300(void) +{ + FILE *fptr = fopen("test.txt", "w+"); + int result; + bool flag = false; + result = fwide(fptr, -5); + if (result < 0) { + flag = true; + } + EXPECT_TRUE("fwide_0300", flag); + fclose(fptr); + remove("test.txt"); +} + +int main() +{ + + fwide_0100(); + fwide_0200(); + fwide_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/fwprintf.c b/libc-test/src/functionalext/supplement/stdio/fwprintf.c new file mode 100644 index 00000000..a900afa3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fwprintf.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_NEGATIVE = -1; + +/** + * @tc.name : fwprintf_0100 + * @tc.desc : Verify the number of wide characters returned by the function (if the file parameter is stdout) + * @tc.level : Level 0 + */ +void fwprintf_0100(void) +{ + int result; + result = fwprintf(stdout, L"This is a test!!QAZ@WSX12"); + printf("\n"); + int ret; + ret = strlen("This is a test!!QAZ@WSX12"); + EXPECT_EQ("fwprintf_0100", result, ret); +} + +/** + * @tc.name : fwprintf_0200 + * @tc.desc : Verify the number of wide characters returned by the function (if the file parameter is stderr) + * @tc.level : Level 0 + */ +void fwprintf_0200(void) +{ + int result; + result = fwprintf(stderr, L"This is a test!"); + printf("\n"); + int ret; + ret = strlen("This is a test!"); + EXPECT_EQ("fwprintf_0200", result, ret); +} + +/** + * @tc.name : fwprintf_0300 + * @tc.desc : Verifies the number of wide characters returned by the function + (if the file is successfully opened in W mode and its return value is used as the file parameter) + * @tc.level : Level 0 + */ +void fwprintf_0300(void) +{ + int result; + FILE *fptr = fopen("test.txt", "w"); + result = fwprintf(fptr, L"This is a test!"); + int ret; + ret = strlen("This is a test!"); + fclose(fptr); + remove("test.txt"); + EXPECT_EQ("fwprintf_0300", result, ret); +} + +/** + * @tc.name : fwprintf_0400 + * @tc.desc : Verifies the number of wide characters returned by the function + (if the file is successfully opened in R mode and its return value is used as a file parameter) + * @tc.level : Level 2 + */ +void fwprintf_0400(void) +{ + int result; + FILE *fptr1 = fopen("test.txt", "w"); + fclose(fptr1); + FILE *fptr2 = fopen("test.txt", "r"); + result = fwprintf(fptr2, L"This is a test!"); + fclose(fptr2); + remove("test.txt"); + EXPECT_EQ("fwprintf_0400", result, COUNT_NEGATIVE); +} + +int main() +{ + fwprintf_0100(); + fwprintf_0200(); + fwprintf_0300(); + fwprintf_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/fwrite.c b/libc-test/src/functionalext/supplement/stdio/fwrite.c new file mode 100644 index 00000000..5997e7b3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/fwrite.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; + +/** + * @tc.name : fwrite_0100 + * @tc.desc : File pointer at the end of a file, the position to which the current file pointer points + * @tc.level : Level 0 + */ +void fwrite_0100(void) +{ + bool flag = false; + FILE *fptr = fopen("test.txt", "w+"); + int result = 0; + char buf[] = "this is test"; + result = fwrite(buf, sizeof(char), strlen(buf), fptr); + if (result > 0) { + flag = true; + } + fclose(fptr); + remove("test.txt"); + EXPECT_TRUE("fwrite_0100", flag); +} + +/** + * @tc.name : fwrite_0200 + * @tc.desc : File pointer at the beginning of a file, the location to which the current file pointer points + * @tc.level : Level 0 + */ +void fwrite_0200(void) +{ + bool flag = false; + FILE *fptr = fopen("test.txt", "w+"); + int result = 0; + char buf[] = "this is test"; + result = fwrite(buf, 0, strlen(buf), fptr); + if (result > 0) { + flag = true; + } + fclose(fptr); + remove("test.txt"); + EXPECT_EQ("fwrite_0200", result, COUNT_ZERO); +} + +/** + * @tc.name : fwrite_0300 + * @tc.desc : Invalid argument. Cannot get the location of the current file pointer + * @tc.level : Level 2 + */ +void fwrite_0300(void) +{ + bool flag = false; + FILE *fptr = fopen("test.txt", "w+"); + int result = 0; + char buf[] = "this is test"; + result = fwrite(buf, sizeof(char), 0, fptr); + if (result > 0) { + flag = true; + } + fclose(fptr); + remove("test.txt"); + EXPECT_EQ("fwrite_0300", result, COUNT_ZERO); +} + +int main() +{ + fwrite_0100(); + fwrite_0200(); + fwrite_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/getc.c b/libc-test/src/functionalext/supplement/stdio/getc.c new file mode 100644 index 00000000..625c9a93 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/getc.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : getc_0100 + * @tc.desc : Verify that the characters in the file can be get + * @tc.level : Level 0 + */ +void getc_0100(void) +{ + const char *wrstring = "This is a test sample!"; + const char *ptr = "test.txt"; + char ch; + FILE *fptr = fopen(ptr, "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); + fseek(fptr, 0, SEEK_SET); + ch = fgetc(fptr); + EXPECT_EQ("getc_0100", ch, 'T'); + fclose(fptr); + remove(ptr); +} + +TEST_FUN G_Fun_Array[] = { + getc_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/getc_unlocked.c b/libc-test/src/functionalext/supplement/stdio/getc_unlocked.c new file mode 100644 index 00000000..df9aed4f --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/getc_unlocked.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int SIZE = 97; + +/** + * @tc.name : getc_unlocked_0100 + * @tc.desc : The parameter is valid, and the specified character can be obtained. + * @tc.level : Level 0 + */ +void getc_unlocked_0100(void) +{ + const char *ptr = "getc_unlockedtest.txt"; + FILE *fptr = fopen(ptr, "wr+"); + EXPECT_TRUE("getc_unlocked_0100", fptr != NULL); + const char *wstr = "a"; + fwrite(wstr, sizeof(char), strlen(wstr), fptr); + fseek(fptr, 0, SEEK_SET); + int ret = getc_unlocked(fptr); + EXPECT_EQ("getc_unlocked_0100", ret, SIZE); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : getc_unlocked_0200 + * @tc.desc : The parameter f is invalid, and the specified character cannot be obtained. + * @tc.level : Level 2 + */ +void getc_unlocked_0200(void) +{ + const char *ptr = "getc_unlockedtest.txt"; + FILE *fptr = fopen(ptr, "wr+"); + EXPECT_TRUE("getc_unlocked_0200", fptr != NULL); + fclose(fptr); + fptr = fopen(ptr, "r"); + EXPECT_TRUE("getc_unlocked_0200", fptr != NULL); + int ret = getc_unlocked(fptr); + EXPECT_EQ("getc_unlocked_0200", ret, EOF); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +int main() +{ + getc_unlocked_0100(); + getc_unlocked_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/getchar.c b/libc-test/src/functionalext/supplement/stdio/getchar.c new file mode 100644 index 00000000..9a914ab4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/getchar.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getchar_0100 + * @tc.desc : Verify that the characters in the file can be get + * @tc.level : Level 0 + */ +void getchar_0100(void) +{ + bool flag = false; + char str[] = "r\n"; + int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); + write(fd, str, sizeof(str)); + FILE *fp = freopen("/data/readtest.txt", "r", stdin); + char reschar; + reschar = getchar(); + if (reschar == 'r') + { + flag = true; + } + EXPECT_TRUE("getchar_0100", flag); + fclose(stdin); + close(fd); + remove("/data/readtest.txt"); +} + +int main() +{ + getchar_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/getchar_unlocked.c b/libc-test/src/functionalext/supplement/stdio/getchar_unlocked.c new file mode 100644 index 00000000..b97f1dc8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/getchar_unlocked.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : getchar_unlocked_0100 + * @tc.desc : Verify that a character can be read from standard input. + * @tc.level : Level 0 + */ +void getchar_unlocked_0100(void) +{ + bool flag = false; + char str[] = "r\n"; + int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); + write(fd, str, sizeof(str)); + FILE *fp = freopen("/data/readtest.txt", "r", stdin); + char result = getchar_unlocked(); + if (result == 'r') { + flag = true; + } + EXPECT_TRUE("getchar_unlocked_0100", flag); + fclose(fp); + close(fd); + fclose(stdin); + remove("/data/readtest.txt"); +} + +TEST_FUN G_Fun_Array[] = { + getchar_unlocked_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/getdelim.c b/libc-test/src/functionalext/supplement/stdio/getdelim.c new file mode 100644 index 00000000..43d4df13 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/getdelim.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getdelim_0100 + * @tc.desc : Verify that the file content can be read with the specified delimiter (parameters are valid) + * @tc.level : Level 0 + */ +void getdelim_0100() +{ + ssize_t result; + char *wrstring = "helloworld"; + char *line = NULL; + size_t len = 0; + FILE *fp = fopen("getdelim.txt", "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fp); + fseek(fp, 0, SEEK_SET); + result = getdelim(&line, &len, 'l', fp); + EXPECT_TRUE("getdelim_0100", result > 0); + remove("getdelim.txt"); +} + +/** + * @tc.name : getdelim_0200 + * @tc.desc : Verify that the delimiter cannot be specified to read the file content (the s parameter is invalid) + * @tc.level : Level 2 + */ +void getdelim_0200() +{ + ssize_t result; + char *line = NULL; + char *wrstring = "helloworld"; + size_t a = 0; + FILE *fp = fopen("getdelim.txt", "w+"); + result = getdelim(&line, NULL, 'l', fp); + EXPECT_EQ("getdelim_0200", result, -1); + remove("getdelim.txt"); +} + +/** + * @tc.name : getdelim_0300 + * @tc.desc : Verify that the delimiter cannot be specified to read the file content (the n parameter is invalid) + * @tc.level : Level 2 + */ +void getdelim_0300() +{ + ssize_t result; + char *wrstring = "helloworld"; + size_t a = 0; + FILE *fp = fopen("getdelim.txt", "w+"); + result = getdelim(NULL, &a, 'l', fp); + EXPECT_EQ("getdelim_0300", result, -1); + remove("getdelim.txt"); +} + +int main() +{ + getdelim_0100(); + getdelim_0200(); + getdelim_0300(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/getline.c b/libc-test/src/functionalext/supplement/stdio/getline.c new file mode 100644 index 00000000..fea5e285 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/getline.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getline_0100 + * @tc.desc : Verify that a row of data can be read (parameters are valid). + * @tc.level : Level 0 + */ +void getline_0100(void) +{ + char abc[100] = {0}; + char *wrstring = "helloworld"; + FILE *fp; + char *line = NULL; + size_t len = 0; + ssize_t read; + fp = fopen("test.txt", "w+"); + fwrite(wrstring, sizeof(char), strlen(wrstring), fp); + fseek(fp, 0, SEEK_SET); + read = getline(&line, &len, fp); + EXPECT_EQ("getline_0100", read, 10); + EXPECT_STREQ("getline_0100", line, "helloworld"); + fclose(fp); + remove("test.txt"); +} + +/** + * @tc.name : getline_0200 + * @tc.desc : Validation cannot read a row of data (parameter is NULL). + * @tc.level : Level 2 + */ +void getline_0200(void) +{ + FILE *fp; + char *line = NULL; + size_t len = 0; + ssize_t read; + fp = fopen("test.txt", "w+"); + read = getline(NULL, &len, fp); + EXPECT_EQ("getline_0200", read, -1); + fclose(fp); + remove("test.txt"); +} + +/** + * @tc.name : getline_0300 + * @tc.desc : TValidation cannot read a row of data (parameter is 0). + * @tc.level : Level 2 + */ +void getline_0300(void) +{ + FILE *fp; + char *line = NULL; + size_t len = 0; + ssize_t read; + fp = fopen("test.txt", "w+"); + read = getline(&line, 0, fp); + EXPECT_EQ("getline_0300", read, -1); + fclose(fp); + remove("test.txt"); +} + +int main() +{ + getline_0100(); + getline_0200(); + getline_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/getwc.c b/libc-test/src/functionalext/supplement/stdio/getwc.c new file mode 100644 index 00000000..9e4173f7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/getwc.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getwc_0100 + * @tc.desc : Verify that wide characters can be obtained from the file (parameters are valid) + * @tc.level : Level 0 + */ +void getwc_0100(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/test.txt"; + FILE *fptr = fopen(ptr, "w+"); + EXPECT_PTRNE("putwc_0100", fptr, NULL); + wchar_t wc = L'p'; + char ret = fputwc(wc, fptr); + char result = getwc(fptr); + EXPECT_EQ("getwc_0100", result, 255); + fclose(fptr); + remove(ptr); +} + +int main(void) +{ + getwc_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/open_wmemstream.c b/libc-test/src/functionalext/supplement/stdio/open_wmemstream.c new file mode 100755 index 00000000..89777978 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/open_wmemstream.c @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : open_wmemstream_0100 + * @tc.desc : Create and open a memory stream file(success) + * @tc.level : Level 0 + */ +void open_wmemstream_0100(void) +{ + size_t len = -1; + int ret = 0; + wchar_t *ptr = NULL; + + FILE *fp = open_wmemstream(&ptr, &len); + if (fp == NULL) { + EXPECT_PTRNE("open_wmemstream_0100", fp, NULL); + return; + } + ret = fprintf(fp, "open_wmemstream success!"); + EXPECT_PTRNE("open_wmemstream_0100", ptr, NULL); + ret = fclose(fp); + free(ptr); + ptr = NULL; +} + +int main(void) +{ + open_wmemstream_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/printf.c b/libc-test/src/functionalext/supplement/stdio/printf.c new file mode 100644 index 00000000..ba550db1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/printf.c @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int32_t COUNT_ZERO = 0; + +/** + * @tc.name : printf_0100 + * @tc.desc : Verify the output data in the specified format (the format character is d) + * @tc.level : Level 0 + */ +void printf_0100(void) +{ + int num = 6; + int count; + count = printf("num:%d\n", num); + bool flag = false; + if (count > COUNT_ZERO) { + flag = true; + } + EXPECT_TRUE("printf_0100", flag); +} + +/** + * @tc.name : printf_0200 + * @tc.desc : Verify the output data in the specified format (the format character is o) + * @tc.level : Level 0 + */ +void printf_0200(void) +{ + int num = 6; + int count; + count = printf("num:%o\n", num); + bool flag = false; + if (count > COUNT_ZERO) { + flag = true; + } + EXPECT_TRUE("printf_0200", flag); +} + +/** + * @tc.name : printf_0300 + * @tc.desc : Verify the output data in the specified format (the format character is x,X) + * @tc.level : Level 0 + */ +void printf_0300(void) +{ + int num = 6; + int count; + count = printf("num:%x,X\n", num); + bool flag = false; + if (count > COUNT_ZERO) { + flag = true; + } + EXPECT_TRUE("printf_0300", flag); +} + +/** + * @tc.name : printf_0400 + * @tc.desc : Verify the output data in the specified format (the format character is u) + * @tc.level : Level 0 + */ +void printf_0400(void) +{ + int num = 6; + int count; + count = printf("num:%u\n", num); + bool flag = false; + if (count > COUNT_ZERO) { + flag = true; + } + EXPECT_TRUE("printf_0400", flag); +} + +/** + * @tc.name : printf_0500 + * @tc.desc : Verify the output data in the specified format (the format character is f) + * @tc.level : Level 0 + */ +void printf_0500(void) +{ + int num = 6; + int count; + count = printf("num:%f\n", num); + bool flag = false; + if (count > COUNT_ZERO) { + flag = true; + } + EXPECT_TRUE("printf_0500", flag); +} + +/** + * @tc.name : printf_0600 + * @tc.desc : Verify the output data in the specified format (the format character is e,E) + * @tc.level : Level 0 + */ +void printf_0600(void) +{ + int num = 6; + int count; + count = printf("num:%e,E\n", num); + bool flag = false; + if (count > COUNT_ZERO) { + flag = true; + } + EXPECT_TRUE("printf_0600", flag); +} + +/** + * @tc.name : printf_0700 + * @tc.desc : Verify the output data in the specified format (the format character is g,G) + * @tc.level : Level 0 + */ +void printf_0700(void) +{ + int num = 6; + int count; + count = printf("num:%g,G\n", num); + bool flag = false; + if (count > COUNT_ZERO) { + flag = true; + } + EXPECT_TRUE("printf_0700", flag); +} + +/** + * @tc.name : printf_0800 + * @tc.desc : Verify the output data in the specified format (the format character is c) + * @tc.level : Level 0 + */ +void printf_0800(void) +{ + int num = 6; + int count; + count = printf("num:%c\n", num); + bool flag = false; + if (count > COUNT_ZERO) { + flag = true; + } + EXPECT_TRUE("printf_0800", flag); +} + +/** + * @tc.name : printf_0900 + * @tc.desc : Verify the output data in the specified format (the format character is s) + * @tc.level : Level 0 + */ +void printf_0900(void) +{ + char num[] = "test"; + int count; + count = printf("num:%s\n", num); + bool flag = false; + if (count > COUNT_ZERO) { + flag = true; + } + EXPECT_TRUE("printf_0900", flag); +} + +TEST_FUN G_Fun_Array[] = { + printf_0100, + printf_0200, + printf_0300, + printf_0400, + printf_0500, + printf_0600, + printf_0700, + printf_0800, + printf_0900, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/putc.c b/libc-test/src/functionalext/supplement/stdio/putc.c new file mode 100644 index 00000000..bd22777f --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/putc.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int32_t PUTC_RET = 112; +const int32_t CREAT_MODE = 666; + +/** + * @tc.name : putc_0100 + * @tc.desc : Verify putc process success + * @tc.level : Level 0 + */ +void putc_0100(void) +{ + int32_t ret = creat("putc_0100.txt", CREAT_MODE); + if (ret < 0) { + EXPECT_MT("pread_0100", ret, 0); + return; + } + FILE *fptr = fopen("putc_0100.txt", "w"); + if (!fptr) { + EXPECT_PTRNE("putc_0100", fptr, NULL); + return; + } + EXPECT_PTRNE("putc_0100", fptr, NULL); + EXPECT_EQ("putc_0100", putc('p', fptr), PUTC_RET); + ret = fclose(fptr); + EXPECT_EQ("putc_0100", ret, 0); + remove("putc_0100.txt"); +} + +/** + * @tc.name : putc_0200 + * @tc.desc : Verify putc process failed + * @tc.level : Level 2 + */ +void putc_0200(void) +{ + int ret = creat("putc_0200.txt", CREAT_MODE); + if (ret < 0) { + EXPECT_MT("pread_0200", ret, 0); + return; + } + FILE *fptr = fopen("putc_0200.txt", "r"); + if (!fptr) { + EXPECT_PTRNE("putc_0200", fptr, NULL); + return; + } + EXPECT_EQ("putc_0200", putc('p', fptr), EOF); + ret = fclose(fptr); + EXPECT_EQ("putc_0100", ret, 0); + remove("putc_0200.txt"); +} + +int main(void) +{ + putc_0100(); + putc_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/putc_unlocked.c b/libc-test/src/functionalext/supplement/stdio/putc_unlocked.c new file mode 100755 index 00000000..f4b59588 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/putc_unlocked.c @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : putc_unlocked_0100 + * @tc.desc : write data the content to the stdout file (success) + * @tc.level : Level 0 + */ +void putc_unlocked_0100(void) +{ + int ret; + wchar_t ch[] = L"this is putc_unlocked_0100 test, std output success!\n"; + + int length = sizeof(ch) / sizeof(wchar_t); + for (int i = 0; i < length; i++) { + ret = putc_unlocked(ch[i], stdout); + EXPECT_EQ("putc_unlocked_0100", ret, ch[i]); + EXPECT_NE("putc_unlocked_0100", ret, EOF); + } +} + +int main(void) +{ + putc_unlocked_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/putchar.c b/libc-test/src/functionalext/supplement/stdio/putchar.c new file mode 100644 index 00000000..2f5368f9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/putchar.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "functionalext.h" +#include "stdio.h" + +const int32_t PUTC_RET = 112; + +/** + * @tc.name : putchar_0100 + * @tc.desc : Verify putchar process success + * @tc.level : Level 0 + */ +void putchar_0100(void) +{ + int32_t ret = putchar('p'); + EXPECT_EQ("putchar_0100", ret, PUTC_RET); +} + +int main(int argc, char *argv[]) +{ + putchar_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/putchar_unlocked.c b/libc-test/src/functionalext/supplement/stdio/putchar_unlocked.c new file mode 100755 index 00000000..7fc7fcae --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/putchar_unlocked.c @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : putchar_unlocked_0100 + * @tc.desc : Write a string to the stdout file, which will be output to the console (success) + * @tc.level : Level 0 + */ +void putchar_unlocked_0100(void) +{ + int ret; + wchar_t ch[] = L"this is putchar_unlocked_0100 test case, std output success!\n"; + + int length = sizeof(ch) / sizeof(wchar_t); + for (int i = 0; i < length; i++) { + ret = putchar_unlocked(ch[i]); + EXPECT_EQ("putchar_unlocked_0100", ret, ch[i]); + EXPECT_NE("putchar_unlocked_0100", ret, EOF); + } +} + +int main(void) +{ + putchar_unlocked_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/puts.c b/libc-test/src/functionalext/supplement/stdio/puts.c new file mode 100644 index 00000000..5e3e172f --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/puts.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : puts_0100 + * @tc.desc : The parameters are valid and the function returns a non-negative value. + * @tc.level : Level 0 + */ +void puts_0100(void) +{ + char str[] = "test"; + int ret = puts(str); + EXPECT_TRUE("puts_0100", ret >= 0); +} + +int main() +{ + puts_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/putw.c b/libc-test/src/functionalext/supplement/stdio/putw.c new file mode 100644 index 00000000..43651b6a --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/putw.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "test.h" + +void deal_aberrant(int code) +{ + if (code != SIGSEGV) { + t_error("putw_0200 code is %d are not SIGSEGV", __func__, code); + } + exit(t_status); +} + +/** + * @tc.name : putw_0100 + * @tc.desc : Test the putw method to write integers to the file + * @tc.level : Level 0 + */ +void putw_0100(void) +{ + FILE *fp; + char *file = "putw_test.txt"; + fp = fopen(file, "w+"); + if (fp == NULL) { + t_error("%s fopen failed\n", __func__); + return; + } + int result = putw(10, fp); + if (result != 0) { + t_error("%s putw error get result is %d are not want 0\n", __func__, result); + } + fclose(fp); + remove(file); +} + +/** + * @tc.name : putw_0200 + * @tc.desc : Test the result of putw when the incoming file pointer is empty + * @tc.level : Level 2 + */ +void putw_0200(void) +{ + FILE *fp = NULL; + signal(SIGSEGV, deal_aberrant); + int result = putw(10, fp); +} + +int main(int argc, char *argv[]) +{ + putw_0100(); + putw_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/putwc.c b/libc-test/src/functionalext/supplement/stdio/putwc.c new file mode 100644 index 00000000..f0ca6a52 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/putwc.c @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t PUTC_RET = 112; +const int32_t CREAT_MODE = 666; + +/** + * @tc.name : putwc_0100 + * @tc.desc : Verify putwc process success + * @tc.level : Level 0 + */ +void putwc_0100(void) +{ + int32_t ret = creat("putwc_0100.txt", CREAT_MODE); + if (ret < 0) { + EXPECT_MT("putwc_0100", ret, 0); + return; + } + FILE *fptr = fopen("putwc_0100.txt", "w"); + EXPECT_PTRNE("putwc_0100", fptr, NULL); + wchar_t wc = L'p'; + ret = putwc(wc, fptr); + EXPECT_EQ("putwc_0100", ret, PUTC_RET); + ret = fclose(fptr); + EXPECT_EQ("putwc_0100", ret, 0); + remove("putwc_0100.txt"); +} + +/** + * @tc.name : putwc_0200 + * @tc.desc : Verify fputc process failed. + * @tc.level : level 2. + */ +void putwc_0200(void) +{ + int32_t ret = creat("putwc_0200.txt", CREAT_MODE); + if (ret < 0) { + EXPECT_MT("putwc_0200", ret, 0); + return; + } + FILE *fptr = fopen("putwc_0200.txt", "r"); + EXPECT_PTRNE("putwc_0200", fptr, NULL); + wchar_t wc = L'p'; + ret = putwc(wc, fptr); + EXPECT_EQ("putwc_0200", ret, WEOF); + ret = fclose(fptr); + EXPECT_EQ("putwc_0200", ret, 0); + remove("putwc_0200.txt"); +} + +int main(void) +{ + putwc_0100(); + putwc_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/putwchar.c b/libc-test/src/functionalext/supplement/stdio/putwchar.c new file mode 100755 index 00000000..a332e5ea --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/putwchar.c @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : putwchar_0100 + * @tc.desc : Write a string to the stdout file, which will be output to the console (success) + * @tc.level : Level 0 + */ +void putwchar_0100(void) +{ + int ret; + wchar_t ch[] = L"this is putwchar_0100 test case, std output success!\n"; + + int length = sizeof(ch) / sizeof(wchar_t); + for (int i = 0; i < length; i++) { + ret = putwchar(ch[i]); + EXPECT_EQ("putwchar_0100", ret, ch[i]); + EXPECT_NE("putwchar_0100", ret, EOF); + } +} + +int main(void) +{ + putwchar_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/remove.c b/libc-test/src/functionalext/supplement/stdio/remove.c new file mode 100644 index 00000000..f5399aab --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/remove.c @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "functionalext.h" + +/** + * @tc.name : remove_0100 + * @tc.desc : The parameter is valid and the file can be deleted. + * @tc.level : Level 0 + */ +void remove_0100(void) +{ + const char *ptr = "test.txt"; + FILE *fptr = fopen(ptr, "w"); + EXPECT_TRUE("remove_0100", fptr != NULL); + fclose(fptr); + int ret = remove(ptr); + EXPECT_EQ("remove_0100", ret, 0); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : remove_0200 + * @tc.desc : The parameter is invalid and the file cannot be deleted. + * @tc.level : Level 2 + */ +void remove_0200(void) +{ + const char *ptr = "test.txt"; + int ret = remove(ptr); + EXPECT_EQ("remove_0200", ret, -1); + ptr = NULL; +} + +int main() +{ + remove_0100(); + remove_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/rename.c b/libc-test/src/functionalext/supplement/stdio/rename.c new file mode 100644 index 00000000..d4d2391b --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/rename.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "functionalext.h" + +/** + * @tc.name : rename_0100 + * @tc.desc : Each parameter is valid, and the file name can be changed. + * @tc.level : Level 0 + */ +void rename_0100(void) +{ + const char *ptr = "oldfile.txt"; + const char *newptr = "newfile.txt"; + FILE *fptr = fopen(ptr, "w"); + EXPECT_TRUE("rename_0100", fptr != NULL); + int ret = rename(ptr, newptr); + EXPECT_EQ("rename_0100", ret, 0); + fclose(fptr); + remove(ptr); + remove(newptr); + fptr = NULL; + ptr = NULL; + newptr = NULL; +} + +/** + * @tc.name : rename_0200 + * @tc.desc : Parameter 1 is invalid, the file name cannot be changed. + * @tc.level : Level 2 + */ +void rename_0200(void) +{ + const char *ptr = "test.txt"; + const char *newptr = "newfile.txt"; + int ret = rename(ptr, newptr); + EXPECT_EQ("rename_0200", ret, -1); + ptr = NULL; + newptr = NULL; +} + +/** + * @tc.name : rename_0300 + * @tc.desc : Parameter 2 is invalid, the file name cannot be changed. + * @tc.level : Level 2 + */ +void rename_0300(void) +{ + const char *ptr = "oldfile.txt"; + const char *newptr = "newfile.txt"; + FILE *fptr = fopen(ptr, "w"); + EXPECT_TRUE("rename_0300", fptr != NULL); + FILE *newfptr = fopen(newptr, "w"); + EXPECT_TRUE("rename_0300", fptr != NULL); + int ret = rename(ptr, newptr); + EXPECT_EQ("rename_0300", ret, 0); + fclose(fptr); + fclose(newfptr); + remove(ptr); + remove(newptr); + fptr = NULL; + ptr = NULL; + newptr = NULL; +} + +int main() +{ + rename_0100(); + rename_0200(); + rename_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/rewind.c b/libc-test/src/functionalext/supplement/stdio/rewind.c new file mode 100644 index 00000000..d7d393f7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/rewind.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int32_t CREAT_MODE = 666; + +/** + * @tc.name : rewind_0100 + * @tc.desc : Verify rewind process success + * @tc.level : Level 0 + */ +void rewind_0100(void) +{ + int32_t ret = creat("/data/rewind_0100.txt", CREAT_MODE); + if (ret < 0) { + EXPECT_MT("rewind_0100", ret, 0); + return; + } + + FILE *fptr = fopen("/data/rewind_0100.txt", "w"); + EXPECT_PTRNE("rewind_0100", fptr, NULL); + char str[] = "test"; + fwrite(str, 1, sizeof(str), fptr); + ret = fclose(fptr); + EXPECT_EQ("rewind_0100", ret, 0); + + fptr = fopen("/data/rewind_0100.txt", "r"); + EXPECT_PTRNE("rewind_0100", fptr, NULL); + int ch; + while ( (ch = fgetc(fptr)) != EOF ){ + break; + } + + rewind(fptr); + EXPECT_FALSE("rewind_0100", feof(fptr)); + fclose(fptr); + remove("/data/rewind_0100.txt"); +} + +int main(void) +{ + rewind_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/setbuf.c b/libc-test/src/functionalext/supplement/stdio/setbuf.c new file mode 100644 index 00000000..dbbd0e17 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/setbuf.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +const char *path = "/data/tests/libc-test/src/file.txt"; +const char *str = "Hello"; + +/** + * @tc.name : setbuf_0100 + * @tc.desc : stream buffering operations + * @tc.level : Level 0 + */ +void setbuf_0100(void) +{ + char buf[BUFSIZ] = {0}; + FILE *f = fopen(path, "w+"); + errno = 0; + setbuf(f, buf); + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + fputs(str, f); + fflush(f); + fclose(f); + f = fopen(path, "r"); + memset(buf, 0, sizeof(buf)); + fread(buf, sizeof(buf), 1, f); + if (strcmp(buf, str)) { + t_error("%s failed: setbuf. buf = %s\n", __func__, buf); + } + fclose(f); + remove(path); +} + +/** + * @tc.name : setbuf_0200 + * @tc.desc : stream buffering operations with NULL + * @tc.level : Level 2 + */ +void setbuf_0200(void) +{ + FILE *f = fopen(path, "w+"); + + errno = 0; + setbuf(f, NULL); + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + fclose(f); + + remove(path); +} + +int main(int argc, char *argv[]) +{ + setbuf_0100(); + setbuf_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/setbuffer.c b/libc-test/src/functionalext/supplement/stdio/setbuffer.c new file mode 100644 index 00000000..e74ffdf8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/setbuffer.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +const char *path = "/data/tests/libc-test/src/file.txt"; +const char *str = "Hello"; + +/** + * @tc.name : setbuffer_0100 + * @tc.desc : The buffer type is _IOFBF + * @tc.level : Level 0 + */ +void setbuffer_0100(void) +{ + FILE *fp = fopen(path, "w+"); + char buf[BUFSIZ] = {0}; + errno = 0; + setbuffer(fp, buf, BUFSIZ); + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + fputs(str, fp); + fflush(fp); + fclose(fp); + + fp = fopen(path, "r"); + + memset(buf, 0, sizeof(buf)); + fread(buf, sizeof(buf), 1, fp); + + if (strcmp(buf, str)) { + t_error("%s failed: setbuf. buf = %s\n", __func__, buf); + } + + fclose(fp); + remove(path); +} + +/** + * @tc.name : setbuffer_0200 + * @tc.desc : Stream buffering operations with NULL + * @tc.level : Level 1 + */ +void setbuffer_0200(void) +{ + FILE *f = fopen(path, "w+"); + + errno = 0; + setbuffer(f, NULL, BUFSIZ); + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + fclose(f); + remove(path); +} + +int main(int argc, char *argv[]) +{ + setbuffer_0100(); + setbuffer_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/setlinebuf.c b/libc-test/src/functionalext/supplement/stdio/setlinebuf.c new file mode 100644 index 00000000..25e0f1a9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/setlinebuf.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +const char *path = "/data/tests/libc-test/src/file.txt"; +const char *str = "Hello"; + +/** + * @tc.name : setlinebuf_0100 + * @tc.desc : Set file stream to linear buffer + * @tc.level : Level 0 + */ +void setlinebuf_0100(void) +{ + FILE *f = fopen(path, "w+"); + char buffer[BUFSIZ]; + errno = 0; + setlinebuf(f); + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + fputs(str, f); + fclose(f); + f = fopen(path, "r"); + + memset(buffer, 0, sizeof(buffer)); + fread(buffer, sizeof(buffer), 1, f); + + if (strcmp(buffer, str)) { + t_error("%s failed: setlinebuf. buf = %s\n", __func__, buffer); + } + fclose(f); + remove(path); +} + +/** + * @tc.name : setlinebuf_0200 + * @tc.desc : Output to console + * @tc.level : Level 2 + */ +void setlinebuf_0200(void) +{ + errno = 0; + setlinebuf(stdout); + if (errno != 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } + + printf("test"); + sleep(1); +} + +int main(int argc, char *argv[]) +{ + setlinebuf_0100(); + setlinebuf_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/setvbuf.c b/libc-test/src/functionalext/supplement/stdio/setvbuf.c new file mode 100644 index 00000000..3717b8f6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/setvbuf.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int32_t COUNT_ZERO = 0; +const int32_t COUNT_failed = -1; + +/** + * @tc.name : setvbuf_0100 + * @tc.desc : Authentication is successful (call the setvbuf function to see the return value) + * @tc.level : Level 0 + */ +void setvbuf_0100(void) +{ + char buff[1024]; + const char *ptr = "test.txt"; + int result; + FILE *fptr = fopen(ptr, "w+"); + result = setvbuf(fptr, buff, _IOFBF, 1024); + EXPECT_EQ("setvbuf_0100", result, COUNT_ZERO); + fclose(fptr); + remove("test.txt"); +} + +/** + * @tc.name : setvbuf_0200 + * @tc.desc : Authentication is fails (call the setvbuf function to see the return value) + * @tc.level : Level 2 + */ +void setvbuf_0200(void) +{ + char buff[1024]; + const char *ptr = "test.txt"; + int result; + FILE *fptr = fopen(ptr, "w+"); + result = setvbuf(fptr, buff, -1, 1024); + EXPECT_EQ("setvbuf_0200", result, COUNT_failed); + fclose(fptr); + remove("test.txt"); +} + +TEST_FUN G_Fun_Array[] = { + setvbuf_0100, + setvbuf_0200, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/sprintf.c b/libc-test/src/functionalext/supplement/stdio/sprintf.c new file mode 100644 index 00000000..a2872bc6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/sprintf.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int32_t SPRINTF_0100_RESULT = 4; +const int32_t SPRINTF_0200_RESULT = 5; +const int32_t SPRINTF_0300_RESULT = 19; +const int32_t SECOND_PARAM = 2; +const int32_t THIRD_PARAM = 12345; + +/** + * @tc.name : sprintf_0100 + * @tc.desc : Verify sprintf process success with two params + * @tc.level : Level 0 + */ +void sprintf_0100(void) +{ + char str[1024]; + int ret = sprintf(str, "test"); + EXPECT_EQ("sprintf_0100", ret, SPRINTF_0100_RESULT); + EXPECT_STREQ("sprintf_0100", str, "test"); +} + +/** + * @tc.name : sprintf_0200 + * @tc.desc : Verify sprintf process success with three params(the thrid praram type is int_32) + * @tc.level : Level 0 + */ +void sprintf_0200(void) +{ + char str[1024]; + int ret = sprintf(str, "test%d", SECOND_PARAM); + EXPECT_EQ("sprintf_0200", ret, SPRINTF_0200_RESULT); + EXPECT_STREQ("sprintf_0200", str, "test2"); +} + +/** + * @tc.name : sprintf_0300 + * @tc.desc : Verify sprintf process success with three params(the thrid praram type is string) + * @tc.level : Level 0 + */ +void sprintf_0300(void) +{ + char str[1024]; + int ret = sprintf(str, "testname:%s%d", "test3", THIRD_PARAM); + EXPECT_EQ("sprintf_0300", ret, SPRINTF_0300_RESULT); + EXPECT_STREQ("sprintf_0300", str, "testname:test312345"); +} + +int main(void) +{ + sprintf_0100(); + sprintf_0200(); + sprintf_0300(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/swscanf.c b/libc-test/src/functionalext/supplement/stdio/swscanf.c new file mode 100644 index 00000000..e6795870 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/swscanf.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +#define BUFF_SIZE (20) +#define RESULT_VAL (2) + +/** + * @tc.name : swscanf_0100 + * @tc.desc : Reads data from the wide string ws and stores them according to parameter format + * @tc.level : Level 0 + */ +void swscanf_0100(void) +{ + wchar_t wstr[] = L"swscanf 123"; + wchar_t tmp[BUFF_SIZE]; + int i; + int result = swscanf(wstr, L"%ls %d", tmp, &i); + if (result == EOF) { + t_error("%s swscanf failed\n", __func__); + return; + } + + if (i != 123) { + t_error("%s i = %d is not want 123\n", __func__, i); + } + if (wcscmp(tmp, L"swscanf")) { + t_error("%s wide string is %s not swscanf\n", __func__, tmp); + } +} + +/** + * @tc.name : swscanf_0200 + * @tc.desc : Different formatted data + * @tc.level : Level 1 + */ +void swscanf_0200(void) +{ + wchar_t wstr[] = L"swscanf 123"; + wchar_t tmp1[BUFF_SIZE]; + wchar_t tmp2[BUFF_SIZE]; + int i; + int result = swscanf(wstr, L"%ls %ls", tmp1, tmp2); + if (result == EOF) { + t_error("%s swscanf failed\n", __func__); + return; + } + if (wcscmp(tmp1, L"swscanf")) { + t_error("%s tmp1 = %s is not want swscanf\n", __func__, tmp1); + } + if (wcscmp(tmp2, L"123")) { + t_error("%s tmp2 = %s is not want 123\n", __func__, tmp2); + } +} + +/** + * @tc.name : swscanf_0300 + * @tc.desc : Formatting exception + * @tc.level : Level 2 + */ +void swscanf_0300(void) +{ + wchar_t wstr[] = L"swscanf 123"; + int i, j; + int result = swscanf(wstr, L"%d %d", &i, &j); + if (result >= RESULT_VAL) { + t_error("%s swscanf expect failed\n", __func__); + } +} + +int main(int argc, char *argv[]) +{ + swscanf_0100(); + swscanf_0200(); + swscanf_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/tempnam.c b/libc-test/src/functionalext/supplement/stdio/tempnam.c new file mode 100644 index 00000000..44d63f64 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/tempnam.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : tempnam_0100 + * @tc.desc : Call the tempnam method to generate a temporary file + * @tc.level : Level 0 + */ +void tempnam_0100(void) +{ + char *dir = "/data"; + char *pte = "temp"; + char *result = tempnam(dir, pte); + if (!result) { + t_error("%s tempnam error cannot create temp file\n", __func__); + } + if (!strstr(result, pte)) { + t_error("%s tempnam get result not contain %s\n", __func__, pte); + } +} + +/** + * @tc.name : tempnam_0200 + * @tc.desc : test tempnam is the result when pfx is empty + * @tc.level : Level 1 + */ +void tempnam_0200(void) +{ + char *dir = "/data"; + char *pte = NULL; + char *result = tempnam(dir, pte); + if (!result) { + t_error("%s tempnam error cannot create temp file\n", __func__); + } +} + +/** + * @tc.name : tempnam_0300 + * @tc.desc : Test tempnam results when the dir path does not exist + * @tc.level : Level 1 + */ +void tempnam_0300(void) +{ + char *dir = "/file"; + char *pte = "temp"; + char *result = tempnam(dir, pte); + if (!result) { + t_error("%s tempnam error cannot create temp file\n", __func__); + } + if (!strstr(result, pte)) { + t_error("%s tempnam get result not contain %s\n", __func__, pte); + } +} + +/** + * @tc.name : tempnam_0400 + * @tc.desc : Test tempnam when the dir path is a file + * @tc.level : Level 1 + */ +void tempnam_0400(void) +{ + char *dir = "/file/a.txt"; + char *pte = "temp"; + char *result = tempnam(dir, pte); + if (!result) { + t_error("%s tempnam error cannot create temp file\n", __func__); + } + if (!strstr(result, pte)) { + t_error("%s tempnam get result not contain %s\n", __func__, pte); + } +} + +/** + * @tc.name : tempnam_0500 + * @tc.desc : Test tempnam when dir path is empty string + * @tc.level : Level 1 + */ +void tempnam_0500(void) +{ + char *dir = NULL; + char *pte = "temp"; + char *result = tempnam(dir, pte); + if (!result) { + t_error("%s tempnam error cannot create temp file\n", __func__); + } + if (!strstr(result, pte)) { + t_error("%s tempnam get result not contain %s\n", __func__, pte); + } +} + +int main(int argc, char *argv[]) +{ + // tempnam_0100(); + // tempnam_0200(); + // tempnam_0300(); + // tempnam_0400(); + // tempnam_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/test_src_functionalext_supplement_stdio.gni b/libc-test/src/functionalext/supplement/stdio/test_src_functionalext_supplement_stdio.gni new file mode 100644 index 00000000..1412aac9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/test_src_functionalext_supplement_stdio.gni @@ -0,0 +1,97 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_stdio_test = [ + "fflush", + "fopen", + "fprintf", + "putc", + "putchar", + "putwc", + "rewind", + "setbuf", + "sprintf", + "setbuffer", + "putw", + "setlinebuf", + "swscanf", + "tmpfile", + "tmpnam", + "ungetwc", + "vasprintf", + "vfprintf", + "vfscanf", + "tempnam", + "vfwprintf", + "vswscanf", + "vprintf", + "vsnprintf", + "vfwscanf", + "vdprintf", + "vsscanf", + "vswprintf", + "vsprintf", + "vwprintf", + "wcstoll", + "wcstoull", + "wprintf", + "fread", + "fseeko", + "ftell", + "getc", + "printf", + "setvbuf", + "fgetpos", + "getchar", + "getline", + "flockfile", + "funlockfile", + "asprintf", + "fputwc", + "fgets", + "puts", + "remove", + "rename", + "fsetpos", + "fputws", + "getc_unlocked", + "__fbufsize", + "__flbf", + "__fsetlocking", + "__fseterr", + "dprintf", + "__fpending", + "__fpurge", + "__freadable", + "__freading", + "clearerr", + "__fwritable", + "__fwriting", + "_flushlbf", + "fgetws", + "ftrylockfile", + "fwide", + "fwprintf", + "fwrite", + "getchar_unlocked", + "open_wmemstream", + "putc_unlocked", + "putchar_unlocked", + "putwchar", + "getdelim", + "getwc", + "freopen", + "fputc", + "fputs", + "fgetln", +] diff --git a/libc-test/src/functionalext/supplement/stdio/tmpfile.c b/libc-test/src/functionalext/supplement/stdio/tmpfile.c new file mode 100644 index 00000000..a2a0558a --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/tmpfile.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "test.h" + +/** + * @tc.name : tmpfile_0100 + * @tc.desc : create a temporary file + * @tc.level : Level 0 + */ +void tmpfile_0100(void) +{ + FILE *f = tmpfile(); + if (f == NULL) { + t_error("%s failed: tmpfile\n", __func__); + return; + } +} + +int main(int argc, char *argv[]) +{ + tmpfile_0100(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/tmpnam.c b/libc-test/src/functionalext/supplement/stdio/tmpnam.c new file mode 100644 index 00000000..8e893a2d --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/tmpnam.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : tmpnam_0100 + * @tc.desc : When buffer is provided, the pointer points to the custom buffer + * @tc.level : Level 0 + */ +void tmpnam_0100(void) +{ + char buffer[L_tmpnam]; + char *p = tmpnam(buffer); + if (p == NULL) { + t_error("%s tmpnam failed", __func__); + } + if (strlen(buffer) == 0) { + t_error("%s creat temporary name failed", __func__); + } +} + +/** + * @tc.name : tmpnam_0200 + * @tc.desc : When str is a null pointer, returns a pointer to the internal buffer + * @tc.level : Level 1 + */ +void tmpnam_0200(void) +{ + char *p = tmpnam(NULL); + if (p == NULL) { + t_error("%s tmpnam failed", __func__); + } + if (strlen(p) == 0) { + t_error("%s creat temporary name failed", __func__); + } +} + +int main(int argc, char *argv[]) +{ + // tmpnam_0100(); + // tmpnam_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/ungetwc.c b/libc-test/src/functionalext/supplement/stdio/ungetwc.c new file mode 100644 index 00000000..8c09ba0a --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/ungetwc.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "test.h" + +const char *path = "/data/tests/libc-test/src/file.txt"; + +void handler(int sig) +{ + exit(t_status); +} + +/** + * @tc.name : ungetwc_0100 + * @tc.desc : push back a wide character + * @tc.level : Level 0 + */ +void ungetwc_0100(void) +{ + FILE *file = fopen(path, "a+"); + if (!file) { + t_error("%s failed: fopen\n", __func__); + return; + } + + wint_t wc = L'a'; + wint_t result = ungetwc(wc, file); + if (result != wc) { + remove(path); + + t_error("%s failed: ungetwc\n", __func__); + return; + } + + result = getwc(file); + if (result != wc) { + remove(path); + + t_error("%s failed: getwc\n", __func__); + return; + } +} + +/** + * @tc.name : ungetwc_0200 + * @tc.desc : push back a wide character with an invalid FILE stream + * @tc.level : Level 2 + */ +void ungetwc_0200(void) +{ + signal(SIGSEGV, handler); + + wint_t wc = L'a'; + ungetwc(wc, NULL); +} + +int main(int argc, char *argv[]) +{ + ungetwc_0100(); + ungetwc_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdio/vasprintf.c b/libc-test/src/functionalext/supplement/stdio/vasprintf.c new file mode 100644 index 00000000..1bccb278 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/vasprintf.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : vasprintf_0100 + * @tc.desc : Format the output string through vasprintf, the formatted part is a number + * @tc.level : Level 0 + */ +void vasprintf_0100(char *v, ...) +{ + va_list ap; + va_start(ap, v); + char ta[] = " "; + char *temp = ta; + int result = vasprintf(&temp, v, ap); + if (result == 0) { + t_error("%s vasprintf result value is 0\n", __func__); + } + if (strcmp(temp, "value is 123 and 321.") != 0) { + t_error("%s vasprintf get tmep is %s are not 'value is 123 and 321.'\n", __func__, temp); + } + va_end(ap); +} + +/** + * @tc.name : vasprintf_0200 + * @tc.desc : Format the output string through vasprintf, the formatted part is a string + * @tc.level : Level 1 + */ +void vasprintf_0200(char *v, ...) +{ + va_list ap; + va_start(ap, v); + char ta[] = " "; + char *temp = ta; + int result = vasprintf(&temp, v, ap); + if (result == 0) { + t_error("%s vasprintf result value is 0\n", __func__); + } + if (strcmp(temp, "value is qer and erq.") != 0) { + t_error("%s vasprintf get tmep is %s are not 'value is qer and erq.'\n", __func__, temp); + } + va_end(ap); +} + +/** + * @tc.name : vasprintf_0300 + * @tc.desc : The parameters passed in when calling vasprintf are inconsistent with the data type to be formatted + * @tc.level : Level 2 + */ +void vasprintf_0300(char *v, ...) +{ + va_list ap; + va_start(ap, v); + char ta[] = " "; + char *temp = ta; + int result = vasprintf(&temp, v, ap); + if (result == 0) { + t_error("%s vasprintf result value is 0\n", __func__); + } + if (strcmp(temp, "value is qer and erq.") == 0) { + t_error("%s vasprintf error get tmep is '%s'\n", __func__, temp); + } + va_end(ap); +} + +int main(int argc, char *argv[]) +{ + vasprintf_0100("value is %d and %d.", 123, 321); + vasprintf_0200("value is %s and %s.", "qer", "erq"); + vasprintf_0300("value is %s and %d.", "qer", "erq"); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/vdprintf.c b/libc-test/src/functionalext/supplement/stdio/vdprintf.c new file mode 100644 index 00000000..11f58bcd --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/vdprintf.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +int readFile(int stream, char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int result = vdprintf(stream, fmt, ap); + va_end(ap); + return result; +} + +/** + * @tc.name : vdprintf_0100 + * @tc.desc : Test the vdprintf method to write to the file + * @tc.level : Level 0 + */ +void vdprintf_0100(void) +{ + char *value = "asdf"; + char buffer[100] = {0}; + int fp = open("/data/temp_vdprintf.txt", O_RDWR | O_CREAT); + if (fp < 0) { + t_error("%s open failed", __func__); + return; + } + int result = readFile(fp, "%s", value); + if (result < 0) { + t_error("%s vdprintf get result is %d are less 0\n", __func__, result); + } + close(fp); + fp = open("/data/temp_vdprintf.txt", O_RDWR); + read(fp, buffer, strlen(value)); + if (strcmp(buffer, "asdf") != 0) { + t_error("%s vdprintf get is '%s' are not 'asdf'\n", __func__, buffer); + } + close(fp); + unlink("/data/temp_vdprintf.txt"); +} + +/** + * @tc.name : vdprintf_0200 + * @tc.desc : Test that vdprintf returns the result when the file descriptor is incorrect + * @tc.level : Level 2 + */ +void vdprintf_0200(void) +{ + char *value = "asdf"; + int want = -1; + int fp = -1; + int result = readFile(fp, "%s", value); + if (result != want) { + t_error("%s vdprintf get result is %d are want -1\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + vdprintf_0100(); + vdprintf_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/vfprintf.c b/libc-test/src/functionalext/supplement/stdio/vfprintf.c new file mode 100644 index 00000000..ccb40dbd --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/vfprintf.c @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +char *getfileall(char *fname) +{ + FILE *fp; + char *str; + char txt[1000]; + int filesize; + if ((fp = fopen(fname, "r")) == NULL) { + printf("打开文件%s错误\n", fname); + return NULL; + } + fseek(fp, 0, SEEK_END); + filesize = ftell(fp); + str = (char *)malloc(filesize); + str[0] = 0; + rewind(fp); + + while ((fgets(txt, 1000, fp)) != NULL) { + strcat(str, txt); + } + fclose(fp); + return str; +} + +void vfprintf_test(char *file_name, char *format, char *func_name, char *want_reuslt, ...) +{ + FILE *file = fopen(file_name, "w"); + va_list ap; + va_start(ap, want_reuslt); + int result = vfprintf(file, format, ap); + va_end(ap); + fclose(file); + if (result < 0) { + t_error("%s vfprintf get result is %d not less 0", func_name, result); + } + char *buffer = getfileall(file_name); + if (strcmp(buffer, want_reuslt) != 0) { + t_error("%s vfprintf get is '%s' not '%s'", func_name, buffer, want_reuslt); + } + unlink(file_name); +} + +void vfprintf_n_test(char *file_name, char *format, char *func_name, char *want_reuslt, ...) +{ + FILE *file = fopen(file_name, "w"); + va_list ap; + va_start(ap, want_reuslt); + int result = vfprintf(file, format, ap); + va_end(ap); + fclose(file); + if (result < 0) { + t_error("%s vfprintf get result is %d not less 0", func_name, result); + } + char *buffer = getfileall(file_name); + if (strcmp(buffer, want_reuslt) == 0) { + t_error("%s vfprintf get is '%s'", func_name, buffer); + } + unlink(file_name); +} + +int main() +{ + /** + * @tc.name : vfprintf_0100 + * @tc.desc : Format the output string through vfprintf, the formatted part is a number + * @tc.level : Level 0 + */ + vfprintf_test("/data/vfprintf.txt", "value is %s and %s", "vfprintf_0100", "value is qwe and 1", "qwe", "1"); + /** + * @tc.name : vfprintf_0200 + * @tc.desc : Format the output string through vfprintf, the formatted part is a string + * @tc.level : Level 1 + */ + vfprintf_test("/data/vfprintf.txt", "value is %d and %d", "vfprintf_0200", "value is 1 and 1", 1, 1); + /** + * @tc.name : vfprintf_0300 + * @tc.desc : When calling vfprintf, the parameters passed in exceeds the number of formats to be formatted + * @tc.level : Level 2 + */ + vfprintf_test("/data/vfprintf.txt", "value is %d", "vfprintf_0300", "value is 1", 1, 1); + /** + * @tc.name : vfprintf_0400 + * @tc.desc : The parameters passed in when calling vfprintf are inconsistent with the data type to be + * formatted + * @tc.level : Level 2 + */ + vfprintf_n_test("/data/vfprintf.txt", "value is %s and %d", "vfprintf_0400", "value is qer and erq", "qer", "erq"); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/vfscanf.c b/libc-test/src/functionalext/supplement/stdio/vfscanf.c new file mode 100644 index 00000000..f5a99db3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/vfscanf.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +const char *file = "/data/tests/libc-test/src/functionalext/supplement/stdio/vfscanf.txt"; + +int readFile(FILE *stream, char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int result = vfscanf(stream, fmt, ap); + va_end(ap); + return result; +} + +/** + * @tc.name : vfscanf_0100 + * @tc.desc : Reads data from the stream and stores them according to the parameter format. + * @tc.level : Level 0 + */ +void vfscanf_0100(void) +{ + FILE *fp = NULL; + int val = 0; + char buffer[BUFSIZ]; + fp = fopen(file, "w+"); + if (fp == NULL) { + t_error("%s fopen failed\n", __func__); + return; + } + if (fprintf(fp, "%s %d", "vfscanftest", 123) < 0) { + t_error("%s fprintf failed\n", __func__); + return; + } + rewind(fp); + + int result = readFile(fp, "%s %d", buffer, &val); + if (result < 0) { + t_error("%s vfscanf get result is %d are less 0\n", __func__, result); + } + if (strcmp(buffer, "vfscanftest") != 0) { + t_error("%s vfscanf get is '%s' are not 'vfscanftest'\n", __func__, buffer); + } + if (val != 123) { + t_error("%s vfscanf get is %d are not 123\n", __func__, val); + } + fclose(fp); + remove(file); +} + +/** + * @tc.name : vfscanf_0200 + * @tc.desc : Test conversion of different formats + * @tc.level : Level 1 + */ +void vfscanf_0200(void) +{ + FILE *fp = NULL; + char val[BUFSIZ]; + char buffer[BUFSIZ]; + fp = fopen(file, "w+"); + if (fp == NULL) { + t_error("%s fopen failed\n", __func__); + return; + } + if (fprintf(fp, "%s %d", "vfscanftest", 123) < 0) { + t_error("%s fprintf failed\n", __func__); + return; + } + rewind(fp); + + int result = readFile(fp, "%s %s", buffer, val); + if (result < 0) { + t_error("%s vfscanf get result is %d are less 0\n", __func__, result); + } + if (strcmp(buffer, "vfscanftest") != 0) { + t_error("%s vfscanf get is '%s' are not 'vfscanftest'\n", __func__, buffer); + } + if (strcmp(val, "123") != 0) { + t_error("%s vfscanf get is '%s' are not '123'\n", __func__, val); + } + fclose(fp); + remove(file); +} + +/** + * @tc.name : vfscanf_0300 + * @tc.desc : The test corresponding position does not match the format + * @tc.level : Level 2 + */ +void vfscanf_0300(void) +{ + FILE *fp = NULL; + int val1 = 0; + int val2 = 0; + fp = fopen(file, "w+"); + if (fp == NULL) { + t_error("%s fopen failed", __func__); + return; + } + if (fprintf(fp, "%s %d", "vfscanftest", 123) < 0) { + t_error("%s fprintf failed", __func__); + return; + } + rewind(fp); + + int result = readFile(fp, "%d %d", val1, val2); + if (result > 0) { + t_error("%s vfscanf get result is %d are more than the 0\n", __func__, result); + } + if (val1 != 0) { + t_error("%s vfscanf get is %d are not 0\n", __func__, val1); + } + if (val2 != 0) { + t_error("%s vfscanf get is %d are not 0\n", __func__, val2); + } + fclose(fp); + remove(file); +} + +int main(int argc, char *argv[]) +{ + vfscanf_0100(); + vfscanf_0200(); + vfscanf_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/vfwprintf.c b/libc-test/src/functionalext/supplement/stdio/vfwprintf.c new file mode 100644 index 00000000..cf9818d4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/vfwprintf.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "test.h" + +void deal_aberrant(int code) +{ + if (code != SIGSEGV) { + t_error("vfwprintf_0200 code is %d are not SIGSEGV", __func__, code); + } + exit(t_status); +} + +int readFile(FILE *stream, wchar_t *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int result = vfwprintf(stream, fmt, ap); + va_end(ap); + return result; +} + +/** + * @tc.name : vfwprintf_0100 + * @tc.desc : Test vfwprintf method to write wide string to file + * @tc.level : Level 0 + */ +void vfwprintf_0100(void) +{ + wchar_t *value = L"hello %ls"; + char *file_name = "/data/temp_vfwprintf.txt"; + FILE *file = fopen(file_name, "w"); + int resule = readFile(file, value, L"world"); + if (resule < 0) { + t_error("%s vfwprintf error get result is %d are not less 0\n", __func__, resule); + } + fclose(file); + unlink(file_name); +} + +/** + * @tc.name : vfwprintf_0200 + * @tc.desc : Test the result of the vfwprintf function when the incoming file is empty + * @tc.level : Level 2 + */ +void vfwprintf_0200(void) +{ + wchar_t *value = L"hello %ls"; + signal(SIGSEGV, deal_aberrant); + int resule = readFile(NULL, value, L"world"); +} + +int main(int argc, char *argv[]) +{ + vfwprintf_0100(); + vfwprintf_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/vfwscanf.c b/libc-test/src/functionalext/supplement/stdio/vfwscanf.c new file mode 100644 index 00000000..7752b287 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/vfwscanf.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "test.h" + +void deal_aberrant(int code) +{ + if (code != SIGSEGV) { + t_error("vfwscanf_0200 code is %d are not SIGSEGV", __func__, code); + } + exit(t_status); +} + +int read_from_file(FILE *fp, const wchar_t *format, ...) +{ + va_list args; + va_start(args, format); + int result = vfwscanf(fp, format, args); + va_end(args); + return result; +} + +/** + * @tc.name : vfwscanf_0100 + * @tc.desc : Test vfwscanf method to read wide string from file + * @tc.level : Level 0 + */ +void vfwscanf_0100(void) +{ + setlocale(LC_ALL, "en_US.UTF-8"); + + wchar_t symbol[] = L"\u0915\u0916\u0917\u0918\u0919"; + wchar_t names[5][5] = {L"Ka", L"Kha", L"Ga", L"Gha", L"Nga"}; + FILE *fp = fopen("example.txt", "w+"); + + for (int i = 0; i < 5; i++) + fwprintf(fp, L"%lc %ls ", symbol[i], names[i]); + rewind(fp); + + wchar_t ch, str[5]; + for (int i = 0; i < 5; i++) { + read_from_file(fp, L"%lc %ls ", &ch, str); + if (wcscmp(str, names[i]) != 0) { + t_error("%s vfwscanf in %d get result is %ls are not want %ls\n", __func__, i, str, names[i]); + } + } + + fclose(fp); + unlink("example.txt"); +} + +/** + * @tc.name : vfwscanf_0200 + * @tc.desc : Test the result of the vfwscanf function when the incoming file is empty + * @tc.level : Level 2 + */ +void vfwscanf_0200(void) +{ + wchar_t symbol[] = L"\u0915\u0916\u0917\u0918\u0919"; + wchar_t names[5][5] = {L"Ka", L"Kha", L"Ga", L"Gha", L"Nga"}; + signal(SIGSEGV, deal_aberrant); + read_from_file(NULL, symbol, names); +} + +int main(int argc, char *argv[]) +{ + vfwscanf_0100(); + vfwscanf_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/vprintf.c b/libc-test/src/functionalext/supplement/stdio/vprintf.c new file mode 100644 index 00000000..4d3eccde --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/vprintf.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : vprintf_0100 + * @tc.desc : Send formatted output to standard output with %d + * @tc.level : Level 0 + */ +void vprintf_0100(char *format, ...) +{ + va_list args; + va_start(args, format); + int result = vprintf(format, args); + va_end(args); + if (result < 0) { + t_error("%s vprintf get result is less than 0", __func__); + } + char *want = "This is the 1th test for vprintf"; + int len = strlen(want); + if (result != len) { + t_error("%s vprintf get wrong result, want %s", __func__, want); + } +} + +/** + * @tc.name : vprintf_0200 + * @tc.desc : Send formatted output to standard output whit %s + * @tc.level : Level 1 + */ +void vprintf_0200(char *format, ...) +{ + va_list args; + va_start(args, format); + int result = vprintf(format, args); + va_end(args); + if (result < 0) { + t_error("%s vprintf get result is less than 0", __func__); + } + char *want = "This is the 2th test for vprintf"; + int len = strlen(want); + if (result != len) { + t_error("%s vprintf get wrong result, want %s", __func__, want); + } +} + +int main(int argc, char *argv[]) +{ + vprintf_0100("This is the %dth test for vprintf", 1); + vprintf_0200("This is the 2th test for %s", "vprintf"); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/vsnprintf.c b/libc-test/src/functionalext/supplement/stdio/vsnprintf.c new file mode 100644 index 00000000..22eba6b5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/vsnprintf.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +void vsnprintf_test(char *str, size_t n, char *fmt, const char *func_name, ...) +{ + char s[n]; + va_list ap; + va_start(ap, func_name); + int result = vsnprintf(s, n, fmt, ap); + va_end(ap); + if (result < 0) { + t_error("%s vsnprintf get result is %d are less 0\n", func_name, result); + } + if (strcmp(s, str) != 0) { + t_error("%s vsnprintf get is '%s' are not '%s'\n", func_name, s, str); + } +} + +void vsnprintf_zeron(char *str, char *fmt, const char *func_name, ...) +{ + char s[10]; + va_list ap; + va_start(ap, func_name); + int result = vsnprintf(s, 0, fmt, ap); + va_end(ap); + if (result < 0) { + t_error("%s vsnprintf get result is %d are less 0\n", func_name, result); + } + if (strcmp(s, str) == 0) { + t_error("%s vsnprintf get is '%s' but donnot want that\n", func_name, s); + } +} + +int main(int argc, char *argv[]) +{ + /** + * @tc.name : vsnprintf_0100 + * @tc.desc : Call vsnprinf to get formatted output + * @tc.level : Level 0 + */ + vsnprintf_test("value is use", 13, "value is %s", "vsnprintf_0100", "use"); + /** + * @tc.name : vsnprintf_0200 + * @tc.desc : The number of digits to be truncated is less than the length of the format string + * @tc.level : Level 1 + */ + vsnprintf_test("value is ", 10, "value is %s", "vsnprintf_0200", "use"); + /** + * @tc.name : vsnprintf_0300 + * @tc.desc : The number of bits to be truncated is greater than the format string length + * @tc.level : Level 1 + */ + vsnprintf_test("value is use", 15, "value is %s", "vsnprintf_0300", "use"); + /** + * @tc.name : vsnprintf_0400 + * @tc.desc : Truncate bits to 0 + * @tc.level : Level 2 + */ + vsnprintf_zeron("value is use", "value is %s", "vsnprintf_0400", "use"); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/vsprintf.c b/libc-test/src/functionalext/supplement/stdio/vsprintf.c new file mode 100644 index 00000000..c83130c6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/vsprintf.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : vsprintf_0100 + * @tc.desc : Write formatted data %d to string from variable argument list + * @tc.level : Level 0 + */ +void vsprintf_0100(char *format, ...) +{ + char buffer[20]; + va_list aptr; + va_start(aptr, format); + int result = vsprintf(buffer, format, aptr); + va_end(aptr); + if (result < 0) { + t_error("%s vsprintf get result is less than 0", __func__); + } + if (strcmp(buffer, "1")) { + t_error("%s wrong string written to buf", __func__); + } +} + +/** + * @tc.name : vsprintf_0200 + * @tc.desc : Write formatted data %f to string from variable argument list + * @tc.level : Level 1 + */ +void vsprintf_0200(char *format, ...) +{ + char buffer[20]; + va_list aptr; + va_start(aptr, format); + int result = vsprintf(buffer, format, aptr); + va_end(aptr); + if (result < 0) { + t_error("%s vsprintf get result is less than 0", __func__); + } + if (strncmp(buffer, "3.0", 3)) { + t_error("%s wrong string written to buf", __func__); + } +} + +/** + * @tc.name : vsprintf_0300 + * @tc.desc : Write formatted data %s to string from variable argument list + * @tc.level : Level 1 + */ +void vsprintf_0300(char *format, ...) +{ + char buffer[20]; + va_list aptr; + va_start(aptr, format); + int result = vsprintf(buffer, format, aptr); + va_end(aptr); + if (result < 0) { + t_error("%s vsprintf get result is less than 0", __func__); + } + if (strcmp(buffer, "vsprintf test")) { + t_error("%s wrong string written to buf", __func__); + } +} + +int main(int argc, char *argv[]) +{ + int i = 1; + float f = 3.0f; + char str[] = "vsprintf test"; + vsprintf_0100("%d", i); + vsprintf_0200("%f", f); + vsprintf_0300("%s", str); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/vsscanf.c b/libc-test/src/functionalext/supplement/stdio/vsscanf.c new file mode 100644 index 00000000..c0731cb5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/vsscanf.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +int get_return_vaule(char *s, char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int result = vsscanf(s, fmt, ap); + va_end(ap); + return result; +} + +/** + * @tc.name : vsscanf_0100 + * @tc.desc : Call vsscanf to convert and format the data from the data according to format + * @tc.level : Level 0 + */ +void vsscanf_0100(void) +{ + int val = 0; + char buffer[100]; + int result = get_return_vaule("value 123 info", "%s %d", &buffer, &val); + if (result < 0) { + t_error("%s vsscanf get result is %d are less 0\n", __func__, result); + } + if (strcmp(buffer, "value") != 0) { + t_error("%s vsscanf get is '%s' are not 'value'\n", __func__, buffer); + } + if (val != 123) { + t_error("%s vsscanf get is %d are not 123\n", __func__, val); + } +} + +/** + * @tc.name : vsscanf_0200 + * @tc.desc : Test conversion of different formats + * @tc.level : Level 1 + */ +void vsscanf_0200(void) +{ + char buffer[100]; + char get_val[100]; + int result = get_return_vaule("value 123 info", "%s %s", &buffer, &get_val); + if (result < 0) { + t_error("%s vsscanf get result is %d are less 0\n", __func__, result); + } + if (strcmp(buffer, "value") != 0) { + t_error("%s vsscanf get is '%s' are not 'value'\n", __func__, buffer); + } + if (strcmp(get_val, "123") != 0) { + t_error("%s vsscanf get is %s are not 123\n", __func__, get_val); + } +} + +/** + * @tc.name : vsscanf_0300 + * @tc.desc : The test corresponding position does not match the format + * @tc.level : Level 2 + */ +void vsscanf_0300(void) +{ + int val = 0; + int val_temp = 0; + int result = get_return_vaule("value 123 info", "%d %d", &val, &val_temp); + if (result > 0) { + t_error("%s vsscanf get result is %d are more than the 0\n", __func__, result); + } + if (val != 0) { + t_error("%s vsscanf get is %d are not 0\n", __func__, val); + } + if (val_temp != 0) { + t_error("%s vsscanf get is %d are not 0\n", __func__, val_temp); + } +} + +int main(int argc, char *argv[]) +{ + vsscanf_0100(); + vsscanf_0200(); + vsscanf_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/vswprintf.c b/libc-test/src/functionalext/supplement/stdio/vswprintf.c new file mode 100644 index 00000000..7df49fb9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/vswprintf.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +#define MAX (20) + +/** + * @tc.name : vswprintf_0100 + * @tc.desc : Write formatted data %d to string from variable argument list + * @tc.level : Level 0 + */ +void vswprintf_0100(wchar_t *format, ...) +{ + wchar_t buffer[MAX]; + va_list aptr; + va_start(aptr, format); + int result = vswprintf(buffer, MAX, format, aptr); + va_end(aptr); + if (result < 0) { + t_error("%s vswprintf get result is less than 0", __func__); + } + if (wcscmp(buffer, L"1")) { + t_error("%s wrong string written to buf", __func__); + } +} + +/** + * @tc.name : vswprintf_0200 + * @tc.desc : Write formatted data %f to string from variable argument list + * @tc.level : Level 1 + */ +void vswprintf_0200(wchar_t *format, ...) +{ + wchar_t buffer[MAX]; + va_list aptr; + va_start(aptr, format); + int result = vswprintf(buffer, MAX, format, aptr); + va_end(aptr); + if (result < 0) { + t_error("%s vswprintf get result is less than 0", __func__); + } + if (wcsncmp(buffer, L"3.0", 3)) { + t_error("%s wrong string written to buf", __func__); + } +} + +/** + * @tc.name : vswprintf_0300 + * @tc.desc : Write formatted data %s to string from variable argument list + * @tc.level : Level 1 + */ +void vswprintf_0300(wchar_t *format, ...) +{ + wchar_t buffer[MAX]; + va_list aptr; + va_start(aptr, format); + int result = vswprintf(buffer, MAX, format, aptr); + va_end(aptr); + if (result < 0) { + t_error("%s vsprintf get result is less than 0", __func__); + } + if (wcscmp(buffer, L"vswprintf test")) { + t_error("%s wrong string written to buf", __func__); + } +} + +int main(int argc, char *argv[]) +{ + int i = 1; + float f = 3.0f; + wchar_t str[] = L"vswprintf test"; + vswprintf_0100(L"%d", i); + vswprintf_0200(L"%f", f); + vswprintf_0300(L"%ls", str); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/vswscanf.c b/libc-test/src/functionalext/supplement/stdio/vswscanf.c new file mode 100644 index 00000000..2621bd34 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/vswscanf.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" + +int get_str_value(const wchar_t *buffer, const wchar_t *format, ...) +{ + int result = 0; + va_list args; + va_start(args, format); + vswscanf(buffer, format, args); + va_end(args); + return result; +} + +/** + * @tc.name : vswscanf_0100 + * @tc.desc : Test the vswscanf function to read data from the wide character buffer and store it in the + * corresponding variable + * @tc.level : Level 0 + */ +void vswscanf_0100(void) +{ + wchar_t symbol[] = L"\u0fd7\u00c6\u20b9\u2127\u17d8"; + wchar_t str[20]; + int result = get_str_value(symbol, L"%ls", str); + if (result != 0) { + t_error("%s vswscanf get result is %d are not want 0\n", __func__, result); + } + if (wcscmp(symbol, str) != 0) { + t_error("%s vswscanf error %ls are not eq %ls\n", __func__, symbol, str); + } +} + +/** + * @tc.name : vswscanf_0200 + * @tc.desc : Test the result of wswscanf when fetching multiple variables from a wide character buffer + * @tc.level : Level 1 + */ +void vswscanf_0200(void) +{ + wchar_t symbol[] = L"ABC DEF"; + wchar_t str[20]; + wchar_t strs[20]; + int result = get_str_value(symbol, L"%ls %ls", str, strs); + if (result != 0) { + t_error("%s vswscanf get result is %d are not want 0\n", __func__, result); + } + if (wcscmp(str, L"ABC") != 0) { + t_error("%s vswscanf error %ls are not eq ABC\n", __func__, str); + } + if (wcscmp(strs, L"DEF") != 0) { + t_error("%s vswscanf error %ls are not eq DEF\n", __func__, strs); + } +} + +int main(int argc, char *argv[]) +{ + setlocale(LC_ALL, "en_US.UTF-8"); + vswscanf_0100(); + vswscanf_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/vwprintf.c b/libc-test/src/functionalext/supplement/stdio/vwprintf.c new file mode 100644 index 00000000..5157f74d --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/vwprintf.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "test.h" + +int readFile(wchar_t *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int result = vwprintf(fmt, ap); + va_end(ap); + return result; +} + +/** + * @tc.name : vwprintf_0100 + * @tc.desc : Test the vwprintf method to write a wide string to the console + * @tc.level : Level 0 + */ +void vwprintf_0100(void) +{ + wchar_t *value = L"hello %ls\n"; + int resule = readFile(value, L"world"); + if (resule < 0) { + t_error("%s vwprintf error get result is %d are not less 0\n", __func__, resule); + } +} + +int main(int argc, char *argv[]) +{ + vwprintf_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/wcstoll.c b/libc-test/src/functionalext/supplement/stdio/wcstoll.c new file mode 100644 index 00000000..5cfc9def --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/wcstoll.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +#define TEST(r, f, x, m) (errno = 0, msg = #f, ((r) = (f)) == (x) || (t_error("%s failed (" m ")\n", #f, r, x), 0)) + +#define TEST2(r, f, x, m) (((r) = (f)) == (x) || (t_error("%s failed (" m ")\n", msg, r, x), 0)) + +/** + * @tc.name : wcstoll_0100 + * @tc.desc : Convert wide string "2147483647" to long long type + * @tc.level : Level 0 + */ +void wcstoll_0100(void) +{ + long long ll; + char *msg = ""; + TEST(ll, wcstoll(L"2147483647", 0, 0), 2147483647LL, "expect signed %lld != %lld"); +} + +/** + * @tc.name : wcstoll_0200 + * @tc.desc : Convert wide string "10" to long long type + * @tc.level : Level 0 + */ +void wcstoll_0200(void) +{ + long long ll; + char *msg = ""; + TEST(ll, wcstoll(L"10", 0, 0), 10LL, "expect signed %lld != %lld"); +} + +/** + * @tc.name : wcstoll_0300 + * @tc.desc : Convert wide string "z" to long long type + * @tc.level : Level 1 + */ +void wcstoll_0300(void) +{ + long long ll; + char *msg = ""; + TEST(ll, wcstoll(L"z", 0, 36), 35LL, "%lld != %lld"); +} + +/** + * @tc.name : wcstoll_0400 + * @tc.desc : Convert wide string "00010010001101000101011001111000" to long long type + * @tc.level : Level 1 + */ +void wcstoll_0400(void) +{ + long long ll; + char *msg = ""; + TEST(ll, wcstoll(L"00010010001101000101011001111000", 0, 2), 0x12345678, "%lld != %lld"); +} + +/** + * @tc.name : wcstoll_0500 + * @tc.desc : Convert wide string "0xz" to long long type + * @tc.level : Level 1 + */ +void wcstoll_0500(void) +{ + int i; + long long ll; + char *msg = ""; + wchar_t *s, *c; + TEST(ll, wcstoll(s = L"0xz", &c, 16), 0, "%lld != %lld"); + TEST2(i, c - s, 1, "wrong final position %lld != %lld"); +} + +/** + * @tc.name : wcstoll_0600 + * @tc.desc : Convert wide string "0x1234" to long long type + * @tc.level : Level 1 + */ +void wcstoll_0600(void) +{ + int i; + long long ll; + char *msg = ""; + wchar_t *s, *c; + TEST(ll, wcstoll(s = L"0x1234", &c, 16), 0x1234, "%lld != %ld"); + TEST2(i, c - s, 6, "wrong final position %lld != %lld"); +} + +/** + * @tc.name : wcstoll_0700 + * @tc.desc : Convert wide string "9223372036854775808" to long long type exceeds the maximum value of the type + * @tc.level : Level 2 + */ +void wcstoll_0700(void) +{ + int i; + long long ll; + char *msg = ""; + wchar_t *s, *c; + TEST(ll, wcstoll(s = L"9223372036854775808", &c, 0), 9223372036854775807LL, "uncaught overflow %lld != %lld"); + TEST2(i, c - s, 19, "wrong final position %d != %d"); + TEST2(i, errno, ERANGE, "missing errno %d != %d"); +} + +/** + * @tc.name : wcstoll_0800 + * @tc.desc : Convert wide string "-9223372036854775809" to long long type exceeds the maximum value of the type + * @tc.level : Level 2 + */ +void wcstoll_0800(void) +{ + int i; + long long ll; + char *msg = ""; + wchar_t *s, *c; + TEST(ll, wcstoll(s = L"-9223372036854775809", &c, 0), -9223372036854775807LL - 1, "overflow %lld != %lld"); + TEST2(i, c - s, 20, "wrong final position %d != %d"); + TEST2(i, errno, ERANGE, "missing errno %d != %d"); +} + +int main(int argc, char *argv[]) +{ + wcstoll_0100(); + wcstoll_0200(); + wcstoll_0300(); + wcstoll_0400(); + wcstoll_0500(); + wcstoll_0600(); + wcstoll_0700(); + wcstoll_0800(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/wcstoull.c b/libc-test/src/functionalext/supplement/stdio/wcstoull.c new file mode 100644 index 00000000..234604f4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/wcstoull.c @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +#define TEST(r, f, x, m) (errno = 0, msg = #f, ((r) = (f)) == (x) || (t_error("%s failed (" m ")\n", #f, r, x), 0)) + +#define TEST2(r, f, x, m) (((r) = (f)) == (x) || (t_error("%s failed (" m ")\n", msg, r, x), 0)) + +/** + * @tc.name : wcstoull_0100 + * @tc.desc : Convert wide string to unsigned long long type based on decimal + * @tc.level : Level 0 + */ +void wcstoull_0100(void) +{ + unsigned long long ull; + char *msg = ""; + wchar_t *s, *c; + TEST(ull, wcstoull(s = L"250068492", &c, 10), 250068492ULL, "expect unsigned %llu != %llu"); +} + +/** + * @tc.name : wcstoull_0200 + * @tc.desc : Convert wide string to unsigned long long type based on hexadecimal + * @tc.level : Level 1 + */ +void wcstoull_0200(void) +{ + unsigned long long ull; + char *msg = ""; + wchar_t *s, *c; + TEST(ull, wcstoull(s = L"7b06af00", &c, 16), 2064035584ULL, "expect unsigned %llu != %llu"); +} + +/** + * @tc.name : wcstoull_0300 + * @tc.desc : Convert wide string to unsigned long long type based on binary + * @tc.level : Level 1 + */ +void wcstoull_0300(void) +{ + unsigned long long ull; + char *msg = ""; + wchar_t *s, *c; + TEST(ull, wcstoull(s = L"1100011011110101010001100000", &c, 2), 208622688ULL, "expect unsigned %llu != %llu"); +} + +/** + * @tc.name : wcstoull_0400 + * @tc.desc : Convert wide string to unsigned long long type based on parameter 'base' equal to 0 + * @tc.level : Level 1 + */ +void wcstoull_0400(void) +{ + unsigned long long ull; + char *msg = ""; + wchar_t *s, *c; + TEST(ull, wcstoull(s = L"0x6fffff", &c, 0), 7340031ULL, "expect unsigned %llu != %llu"); +} + +/** + * @tc.name : wcstoull_0500 + * @tc.desc : Convert wide string to unsigned long long type exceeds the maximum value of the type + * @tc.level : Level 2 + */ +void wcstoull_0500(void) +{ + int i; + unsigned long long ull; + char *msg = ""; + wchar_t *s, *c; + TEST(ull, wcstoull(s = L"18446744073709551616", &c, 0), 18446744073709551615ULL, "uncaught overflow %llu != %llu"); + TEST2(i, c - s, 20, "wrong final position %d != %d"); + TEST2(i, errno, ERANGE, "missing errno %d != %d"); +} + +/** + * @tc.name : wcstoull_0600 + * @tc.desc : The converted result value -1 is invalid + * @tc.level : Level 2 + */ +void wcstoull_0600(void) +{ + int i; + unsigned long long ull; + char *msg = ""; + wchar_t *s, *c; + TEST(ull, wcstoull(s = L"-1", &c, 0), -1ULL, "rejected negative %llu != %llu"); + TEST2(i, c - s, 2, "wrong final position %d != %d"); + TEST2(i, errno, 0, "spurious errno %d != %d"); +} + +/** + * @tc.name : wcstoull_0700 + * @tc.desc : The converted result value -2 is invalid + * @tc.level : Level 2 + */ +void wcstoull_0700(void) +{ + int i; + unsigned long long ull; + char *msg = ""; + wchar_t *s, *c; + TEST(ull, wcstoull(s = L"-2", &c, 0), -2ULL, "rejected negative %llu != %llu"); + TEST2(i, c - s, 2, "wrong final position %d != %d"); + TEST2(i, errno, 0, "spurious errno %d != %d"); +} + +/** + * @tc.name : wcstoull_0800 + * @tc.desc : The converted result value -9223372036854775808 is invalid + * @tc.level : Level 2 + */ +void wcstoull_0800(void) +{ + int i; + unsigned long long ull; + char *msg = ""; + wchar_t *s, *c; + TEST(ull, wcstoull(s = L"-9223372036854775808", &c, 0), -9223372036854775808ULL, "rejected negative %llu != %llu"); + TEST2(i, c - s, 20, "wrong final position %d != %d"); + TEST2(i, errno, 0, "spurious errno %d != %d"); +} + +int main(int argc, char *argv[]) +{ + wcstoull_0100(); + wcstoull_0200(); + wcstoull_0300(); + wcstoull_0400(); + wcstoull_0500(); + wcstoull_0600(); + wcstoull_0700(); + wcstoull_0800(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdio/wprintf.c b/libc-test/src/functionalext/supplement/stdio/wprintf.c new file mode 100644 index 00000000..7cf6ab60 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdio/wprintf.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wprintf_0100 + * @tc.desc : Print formatted characters to stdout + * @tc.level : Level 0 + */ +void wprintf_0100(void) +{ + int result = wprintf(L"%lc\n", L'a'); + if (result < 0) { + t_error("%s print formatted characters to stdout failed\n", __func__); + } +} + +/** + * @tc.name : wprintf_0200 + * @tc.desc : Print formatted decimals to stdout + * @tc.level : Level 1 + */ +void wprintf_0200(void) +{ + int result = wprintf(L"%d, %ld\n", 123, 650000L); + if (result < 0) { + t_error("%s failed to format decimals\n", __func__); + } +} + +/** + * @tc.name : wprintf_0300 + * @tc.desc : Print formatted wide string to stdout + * @tc.level : Level 1 + */ +void wprintf_0300(void) +{ + int result = wprintf(L"%ls\n", L"wprintf test"); + if (result < 0) { + t_error("%s failed to format wide string\n", __func__); + } +} + +int main(int argc, char *argv[]) +{ + wprintf_0100(); + wprintf_0200(); + wprintf_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/BUILD.gn b/libc-test/src/functionalext/supplement/stdlib/BUILD.gn new file mode 100644 index 00000000..6f12ef6e --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_stdlib.gni") + +foreach(s, functionalext_supplement_stdlib_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/stdlib" + } +} + +group("functionalext_supplement_stdlib_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_stdlib_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/stdlib/abs.c b/libc-test/src/functionalext/supplement/stdlib/abs.c new file mode 100644 index 00000000..c2b04792 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/abs.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : abs_0100 + * @tc.desc : Verify that the absolute value of the returned parameter is 0 (parameter is 0). + * @tc.level : Level 0 + */ +void abs_0100(void) +{ + int result = abs(0); + EXPECT_EQ("abs_0100", result, 0); +} + +/** + * @tc.name : abs_0200 + * @tc.desc : Verify that the absolute value of the returned parameter is a positive number (parameter is 10). + * @tc.level : Level 0 + */ +void abs_0200(void) +{ + int result = abs(10); + EXPECT_EQ("abs_0200", result, 10); +} + +/** + * @tc.name : abs_0300 + * @tc.desc : Verify that the absolute value of the returned parameter is a positive number (parameter is -10). + * @tc.level : Level 0 + */ +void abs_0300(void) +{ + int result = abs(-10); + EXPECT_EQ("abs_0300", result, 10); +} + +int main() +{ + abs_0100(); + abs_0200(); + abs_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/atof.c b/libc-test/src/functionalext/supplement/stdlib/atof.c new file mode 100644 index 00000000..1cd62d6d --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/atof.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const double COUNT_SUCCESS = 123456.00; + +/** + * @tc.name : atof_0100 + * @tc.desc : Verify that the parameter is valid convert the string to an integer + * @tc.level : Level 0 + */ +void atof_0100() +{ + bool flag = false; + const char *buff = "123456.00"; + double result = atof(buff); + if (result == COUNT_SUCCESS) { + flag = true; + } + EXPECT_TRUE("atof_0100", flag); +} + +TEST_FUN G_Fun_Array[] = { + atof_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/atoi.c b/libc-test/src/functionalext/supplement/stdlib/atoi.c new file mode 100644 index 00000000..cf75b8b8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/atoi.c @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int32_t ZERO = 0; +const int32_t NUMBER = 123456; +const int32_t NUM = 123; +const int32_t NUMB = 1234; +const int32_t NU = 12; +const int32_t BURDENNUM = -2147483648; + +/** + * @tc.name : atoi_0100 + * @tc.desc : Verify that there are and only numbers (starting with non-zero digits) + * strings are converted to integers + * @tc.level : Level 0 + */ +void atoi_0100(void) +{ + char str[] = "123456"; + int32_t fptr = atoi(str); + EXPECT_EQ("atoi_0100", fptr, NUMBER); +} + +/** + * @tc.name : atoi_0200 + * @tc.desc : Verify that there are and only numbers (starting with a 0) string is converted to an integer + * @tc.level : Level 0 + */ +void atoi_0200(void) +{ + char str[] = "000123456"; + int32_t fptr = atoi(str); + EXPECT_EQ("atoi_0200", fptr, NUMBER); +} + +/** + * @tc.name : atoi_0300 + * @tc.desc : Verify that spaces are at the beginning of the string string is converted to an integer + * @tc.level : Level 1 + */ +void atoi_0300(void) +{ + char str[] = " 123456"; + int32_t fptr = atoi(str); + EXPECT_EQ("atoi_0300", fptr, NUMBER); +} + +/** + * @tc.name : atoi_0400 + * @tc.desc : Verify that spaces are in the middle of the string and convert the string to an integer + * @tc.level : Level 1 + */ +void atoi_0400(void) +{ + char str[] = "123 456"; + int32_t fptr = atoi(str); + EXPECT_EQ("atoi_0400", fptr, NUM); +} + +/** + * @tc.name : atoi_0500 + * @tc.desc : Verify that string conversion to integer (- at the beginning of the number) + * @tc.level : Level 1 + */ +void atoi_0500(void) +{ + char str[] = "-123456"; + int32_t fptr = atoi(str); + EXPECT_EQ("atoi_0500", fptr, -NUMBER); +} + +/** + * @tc.name : atoi_0600 + * @tc.desc : Verify that string conversion to integer (- in the middle of the number) + * @tc.level : Level 1 + */ +void atoi_0600(void) +{ + char str[] = "1234-56"; + int32_t fptr = atoi(str); + EXPECT_EQ("atoi_0600", fptr, NUMB); +} + +/** + * @tc.name : atoi_0700 + * @tc.desc : Verify that string conversion to integer (+ at the beginning of the number) + * @tc.level : Level 1 + */ +void atoi_0700(void) +{ + char str[] = "+123456"; + int32_t fptr = atoi(str); + EXPECT_EQ("atoi_0700", fptr, NUMBER); +} + +/** + * @tc.name : atoi_0800 + * @tc.desc : Verify that string conversion to integer (+ in the middle of the number) + * @tc.level : Level 1 + */ +void atoi_0800(void) +{ + char str[] = "1234+56"; + int32_t fptr = atoi(str); + EXPECT_EQ("atoi_0800", fptr, NUMB); +} + +/** + * @tc.name : atoi_0900 + * @tc.desc : Verify that string conversion to integer (English characters are at the beginning) + * @tc.level : Level 2 + */ +void atoi_0900(void) +{ + char str[] = "a123456"; + int32_t fptr = atoi(str); + EXPECT_EQ("atoi_0900", fptr, ZERO); +} + +/** + * @tc.name : atoi_1000 + * @tc.desc : Verify that string conversion to integer (English characters are in the middle) + * @tc.level : Level 2 + */ +void atoi_1000(void) +{ + char str[] = "12b3456"; + int32_t fptr = atoi(str); + EXPECT_EQ("atoi_1000", fptr, NU); +} + +/** + * @tc.name : atoi_1100 + * @tc.desc : Verify that string conversion to integer (parameter invalid NULL) + * @tc.level : Level 2 + */ +void atoi_1100(void) +{ + char str[] = "NULL"; + int32_t fptr = atoi(str); + EXPECT_EQ("atoi_1100", fptr, ZERO); +} + +/** + * @tc.name : atoi_1200 + * @tc.desc : Verify that string conversion to integer (parameter invalid "") + * @tc.level : Level 2 + */ +void atoi_1200(void) +{ + char str[] = ""; + int32_t fptr = atoi(str); + EXPECT_EQ("atoi_1200", fptr, ZERO); +} + +/** + * @tc.name : atoi_1300 + * @tc.desc : Verify that string conversion to integer (parameter exceeds max value) + * @tc.level : Level 2 + */ +void atoi_1300(void) +{ + char str[] = "2147483648"; + int32_t fptr = atoi(str); + EXPECT_EQ("atoi_1300", fptr, BURDENNUM); +} + +/** + * @tc.name : atoi_1400 + * @tc.desc : erify that string conversion to integer (parameter less than minimum value) + * @tc.level : Level 2 + */ +void atoi_1400(void) +{ + char str[] = "-2147483648"; + int32_t fptr = atoi(str); + EXPECT_EQ("atoi_1400", fptr, BURDENNUM); +} + +TEST_FUN G_Fun_Array[] = { + atoi_0100, + atoi_0200, + atoi_0300, + atoi_0400, + atoi_0500, + atoi_0600, + atoi_0700, + atoi_0800, + atoi_0900, + atoi_1000, + atoi_1100, + atoi_1200, + atoi_1300, + atoi_1400, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/atoll.c b/libc-test/src/functionalext/supplement/stdlib/atoll.c new file mode 100644 index 00000000..4a7852e7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/atoll.c @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +long long int result = 123456789012345; +int resultA = 123456; +int resultC = -123456; +int resultD = 1234567890; +int resultE = 1234; +int successfully = 0; +int resultG = 12; + +/** + * @tc.name : atoll_0100 + * @tc.desc : Verify that the string can be converted to an integer (parameter is 123456789012345) + * @tc.level : Level 0 + */ +void atoll_0100(void) +{ + long long int num; + char str[] = "123456789012345"; + num = atoll(str); + EXPECT_EQ("atoll_0100", num, result); +} + +/** + * @tc.name : atoll_0200 + * @tc.desc : Verify that the string can be converted to an integer (parameter is 000123456) + * @tc.level : Level 0 + */ +void atoll_0200(void) +{ + long long int num; + char str[] = "000123456"; + num = atoll(str); + EXPECT_EQ("atoll_0200", num, resultA); +} + +/** + * @tc.name : atoll_0300 + * @tc.desc : Verify that the string can be converted to an integer (parameter is 123456) + * @tc.level : Level 1 + */ +void atoll_0300(void) +{ + long long int num; + char str[] = " 123456"; + num = atoll(str); + EXPECT_EQ("atoll_0300", num, resultA); +} + +/** + * @tc.name : atoll_0400 + * @tc.desc : Verify that the string can be converted to an integer (parameter is 123 456) + * @tc.level : Level 1 + */ +void atoll_0400(void) +{ + long long int num; + char str[] = "123 456"; + num = atoll(str); + EXPECT_EQ("atoll_0400", num, 123); +} + +/** + * @tc.name : atoll_0500 + * @tc.desc : Verify that the string can be converted to an integer (parameter is -123456) + * @tc.level : Level 1 + */ +void atoll_0500(void) +{ + long long int num; + char str[] = "-123456"; + num = atoll(str); + EXPECT_EQ("atoll_0500", num, resultC); +} + +/** + * @tc.name : atoll_0600 + * @tc.desc : Verify that the string can be converted to an integer (parameter is 1234567890-56) + * @tc.level : Level 1 + */ +void atoll_0600(void) +{ + long long int num; + char str[] = "1234567890-56"; + num = atoll(str); + EXPECT_EQ("atoll_0600", num, resultD); +} + +/** + * @tc.name : atoll_0700 + * @tc.desc : Verify that the string can be converted to an integer (parameter is +123456) + * @tc.level : Level 1 + */ +void atoll_0700(void) +{ + long long int num; + char str[] = "+123456"; + num = atoll(str); + EXPECT_EQ("atoll_0700", num, resultA); +} + +/** + * @tc.name : atoll_0800 + * @tc.desc : Verify that the string can be converted to an integer (parameter is 1234+56) + * @tc.level : Level 1 + */ +void atoll_0800(void) +{ + long long int num; + char str[] = "1234+56"; + num = atoll(str); + EXPECT_EQ("atoll_0800", num, resultE); +} + +/** + * @tc.name : atoll_0900 + * @tc.desc : Verify that cannot convert string to integer (parameter is a123456) + * @tc.level : Level 2 + */ +void atoll_0900(void) +{ + long long int num; + char str[] = "a123456"; + num = atoll(str); + EXPECT_EQ("atoll_0900", num, successfully); +} + +/** + * @tc.name : atoll_1000 + * @tc.desc : Verify that cannot convert string to integer (parameter is 12b3456789012345) + * @tc.level : Level 2 + */ +void atoll_1000(void) +{ + long long int num; + char str[] = "12b3456789012345"; + num = atoll(str); + EXPECT_EQ("atoll_1000", num, resultG); +} + +/** + * @tc.name : atoll_1100 + * @tc.desc : Verify that cannot convert string to integer (parameter is NULL) + * @tc.level : Level 2 + */ +void atoll_1100(void) +{ + long long int num; + char str[] = "NULL"; + num = atoll(str); + EXPECT_EQ("atoll_1100", num, successfully); +} + +/** + * @tc.name : atoll_1200 + * @tc.desc : Verify that cannot convert string to integer (parameter is “”) + * @tc.level : Level 2 + */ +void atoll_1200(void) +{ + long long int num; + char str[] = ""; + num = atoll(str); + EXPECT_EQ("atoll_1200", num, successfully); +} + +int main() +{ + atoll_0100(); + atoll_0200(); + atoll_0300(); + atoll_0400(); + atoll_0500(); + atoll_0600(); + atoll_0700(); + atoll_0800(); + atoll_0900(); + atoll_1000(); + atoll_1100(); + atoll_1200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/bseach.c b/libc-test/src/functionalext/supplement/stdlib/bseach.c new file mode 100755 index 00000000..2c0d9207 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/bseach.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define NUM 8 +int compare(const void *p, const void *q) +{ + return (*(int *)p - *(int *)q); +} + +/** + * @tc.name : bsearch_0100 + * @tc.desc : Verify that binary search can be achieved (each parameter is valid) + * @tc.level : Level 0 + */ +void bsearch_0100(void) +{ + int array[NUM] = {9, 2, 7, 11, 3, 87, 34, 6}; + int key = 3; + int *p; + qsort(array, NUM, sizeof(int), compare); + p = (int *)bsearch(&key, array, NUM, sizeof(int), compare); + EXPECT_EQ("bsearch_0100", (*p), key); +} + +/** + * @tc.name : bsearch_0200 + * @tc.desc : Binary lookup cannot be implemented in validation (invalid parameters) + * @tc.level : Level 2 + */ +void bsearch_0200(void) +{ + int array[NUM] = {9, 2, 7, 11, 3, 87, 34, 6}; + int key = 3; + int *p; + qsort(array, NUM, sizeof(int), compare); + p = (int *)bsearch(&key, array, 0, sizeof(int), compare); + bool flag = false; + if (p == NULL) { + flag = true; + } + EXPECT_TRUE("bsearch_0200", flag); +} + +int main() +{ + bsearch_0100(); + bsearch_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/imaxabs.c b/libc-test/src/functionalext/supplement/stdlib/imaxabs.c new file mode 100644 index 00000000..dc0cb50d --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/imaxabs.c @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : imaxabs_0100 + * @tc.desc : Verify imaxabs process success when param is positive integer + * @tc.level : Level 0 + */ +void imaxabs_0100(void) +{ + intmax_t posmax_t = 1024; + intmax_t ret = imaxabs(posmax_t); + EXPECT_EQ("imaxabs_0100", ret, posmax_t); +} + +/** + * @tc.name : imaxabs_0200 + * @tc.desc : Verify imaxabs process success when param is negative integer + * @tc.level : Level 0 + */ +void imaxabs_0200(void) +{ + intmax_t posmax_t = 1024; + intmax_t negmax_t = -1024; + intmax_t ret = imaxabs(negmax_t); + EXPECT_EQ("imaxabs_0200", ret, posmax_t); +} + +int main(void) +{ + imaxabs_0100(); + imaxabs_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdlib/imaxdiv.c b/libc-test/src/functionalext/supplement/stdlib/imaxdiv.c new file mode 100644 index 00000000..1827b1dd --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/imaxdiv.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : imaxdiv_0100 + * @tc.desc : Verify imaxdiv process success when param num is positive integer, param den is positive integer + * @tc.level : Level 0 + */ +void imaxdiv_0100(void) +{ + intmax_t num = 4; + intmax_t den = 3; + imaxdiv_t ret = imaxdiv(num, den); + EXPECT_EQ("imaxdiv_0100", ret.quot, 1); + EXPECT_EQ("imaxdiv_0100", ret.rem, 1); +} + +/** + * @tc.name : imaxdiv_0200 + * @tc.desc : Verify imaxdiv process success when param num is positive integer, param den is negative integer + * @tc.level : Level 0 + */ +void imaxdiv_0200(void) +{ + intmax_t num = 4; + intmax_t den = -3; + imaxdiv_t ret = imaxdiv(num, den); + EXPECT_EQ("imaxdiv_0200", ret.quot, -1); + EXPECT_EQ("imaxdiv_0200", ret.rem, 1); +} + +/** + * @tc.name : imaxdiv_0300 + * @tc.desc : Verify imaxdiv process success when param num is negative integer, param den is positive integer + * @tc.level : Level 0 + */ +void imaxdiv_0300(void) +{ + intmax_t num = -4; + intmax_t den = 3; + imaxdiv_t ret = imaxdiv(num, den); + EXPECT_EQ("imaxdiv_0300", ret.quot, -1); + EXPECT_EQ("imaxdiv_0300", ret.rem, -1); +} + +/** + * @tc.name : imaxdiv_0400 + * @tc.desc : Verify imaxdiv process success when param num is negative integer, param den is negative integer + * @tc.level : Level 0 + */ +void imaxdiv_0400(void) +{ + intmax_t num = -4; + intmax_t den = -3; + imaxdiv_t ret = imaxdiv(num, den); + EXPECT_EQ("imaxdiv_0400", ret.quot, 1); + EXPECT_EQ("imaxdiv_0400", ret.rem, -1); +} + +int main(int argc, char *argv[]) +{ + imaxdiv_0100(); + imaxdiv_0200(); + imaxdiv_0300(); + imaxdiv_0400(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdlib/labs.c b/libc-test/src/functionalext/supplement/stdlib/labs.c new file mode 100644 index 00000000..c4c3645b --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/labs.c @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : labs_0100 + * @tc.desc : Get the absolute value of a long + * @tc.level : Level 0 + */ +void labs_0100(void) +{ + long rev = labs(1); + EXPECT_EQ("labs_0100", rev, 1); + + rev = labs(-1); + EXPECT_EQ("labs_0100", rev, 1); +} + +int main(void) +{ + labs_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/ldiv.c b/libc-test/src/functionalext/supplement/stdlib/ldiv.c new file mode 100644 index 00000000..8bb6f278 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/ldiv.c @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_LDIV_P_SEVENT 7 +#define TEST_LDIV_P_FOUR 4 +#define TEST_LDIV_P_THREE 3 +#define TEST_LDIV_N_SEVENT (-7) +#define TEST_LDIV_N_FOUR (-4) +#define TEST_LDIV_N_THREE (-3) + +/** + * @tc.name : ldiv_0100 + * @tc.desc : Divide two long integers, return the quotient and remainder + * @tc.level : Level 0 + */ +void ldiv_0100(void) +{ + ldiv_t ret; + ret = ldiv(TEST_LDIV_P_SEVENT, TEST_LDIV_P_FOUR); + EXPECT_EQ("ldiv_0100", ret.quot, 1); + EXPECT_EQ("ldiv_0100", ret.rem, TEST_LDIV_P_THREE); + + ret = ldiv(TEST_LDIV_P_SEVENT, TEST_LDIV_N_FOUR); + EXPECT_EQ("ldiv_0100", ret.quot, -1); + EXPECT_EQ("ldiv_0100", ret.rem, TEST_LDIV_P_THREE); + + ret = ldiv(TEST_LDIV_N_SEVENT, TEST_LDIV_P_FOUR); + EXPECT_EQ("ldiv_0100", ret.quot, -1); + EXPECT_EQ("ldiv_0100", ret.rem, TEST_LDIV_N_THREE); + + ret = ldiv(TEST_LDIV_N_SEVENT, TEST_LDIV_N_FOUR); + EXPECT_EQ("ldiv_0100", ret.quot, 1); + EXPECT_EQ("ldiv_0100", ret.rem, TEST_LDIV_N_THREE); +} + +int main(void) +{ + ldiv_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/llabs.c b/libc-test/src/functionalext/supplement/stdlib/llabs.c new file mode 100644 index 00000000..f07b016b --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/llabs.c @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : llabs_0100 + * @tc.desc : Get the absolute value of a long long + * @tc.level : Level 0 + */ +void llabs_0100(void) +{ + long long rev = llabs(1); + EXPECT_EQ("llabs_0100", rev, 1); + + rev = llabs(-1); + EXPECT_EQ("llabs_0100", rev, 1); +} + +int main(void) +{ + llabs_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/lldiv.c b/libc-test/src/functionalext/supplement/stdlib/lldiv.c new file mode 100755 index 00000000..1b5538e5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/lldiv.c @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_LDIV_P_SEVENT 7 +#define TEST_LDIV_P_FOUR 4 +#define TEST_LDIV_P_THREE 3 +#define TEST_LDIV_N_SEVENT (-7) +#define TEST_LDIV_N_FOUR (-4) +#define TEST_LDIV_N_THREE (-3) + +/** + * @tc.name : lldiv_0100 + * @tc.desc : Divide two long long integers, return the quotient and remainder + * @tc.level : Level 0 + */ +void lldiv_0100(void) +{ + lldiv_t ret = lldiv(TEST_LDIV_P_SEVENT, TEST_LDIV_P_FOUR); + EXPECT_EQ("lldiv_0100", ret.quot, 1); + EXPECT_EQ("lldiv_0100", ret.rem, TEST_LDIV_P_THREE); + + ret = lldiv(TEST_LDIV_P_SEVENT, TEST_LDIV_N_FOUR); + EXPECT_EQ("lldiv_0100", ret.quot, ERREXPECT); + EXPECT_EQ("lldiv_0100", ret.rem, TEST_LDIV_P_THREE); + + ret = lldiv(TEST_LDIV_N_SEVENT, TEST_LDIV_P_FOUR); + EXPECT_EQ("lldiv_0100", ret.quot, ERREXPECT); + EXPECT_EQ("lldiv_0100", ret.rem, TEST_LDIV_N_THREE); + + ret = lldiv(TEST_LDIV_N_SEVENT, TEST_LDIV_N_FOUR); + EXPECT_EQ("lldiv_0100", ret.quot, 1); + EXPECT_EQ("lldiv_0100", ret.rem, TEST_LDIV_N_THREE); +} + +int main(void) +{ + lldiv_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/stdlib/strtoimax.c b/libc-test/src/functionalext/supplement/stdlib/strtoimax.c new file mode 100644 index 00000000..31c39ca0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/strtoimax.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : strtoimax_0100 + * @tc.desc : Test that strtoimax interprets string contents as base 10 integers + * @tc.level : Level 0 + */ +void strtoimax_0100(void) +{ + char *p = {0}; + intmax_t want = -18737357; + intmax_t result = strtoimax("-18737357foobar12", &p, 10); + if (result != want) { + t_error("%s strtoimax get result is %zu are not -18737357\n", __func__, result); + } + if (strcmp(p, "foobar12") != 0) { + t_error("%s strtoimax get is '%s' are not 'foobar12'\n", __func__, p); + } +} + +/** + * @tc.name : strtoimax_0200 + * @tc.desc : Test that strtoimax interprets string contents as base 16 integers + * @tc.level : Level 1 + */ +void strtoimax_0200(void) +{ + char *p = {0}; + intmax_t want = -0x18737357f; + intmax_t result = strtoimax("-18737357foobar12", &p, 16); + if (result != want) { + t_error("%s strtoimax get result is %zu are not -0x18737357f\n", __func__, result); + } + if (strcmp(p, "oobar12") != 0) { + t_error("%s strtoimax get is '%s' are not 'oobar12'\n", __func__, p); + } +} + +int main(int argc, char *argv[]) +{ + strtoimax_0100(); + strtoimax_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/strtoumax.c b/libc-test/src/functionalext/supplement/stdlib/strtoumax.c new file mode 100644 index 00000000..7153c7e5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/strtoumax.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : strtoumax_0100 + * @tc.desc : Test the strtoumax function to interpret the string content as a base 10 integer + * @tc.level : Level 0 + */ +void strtoumax_0100(void) +{ + char *p = {0}; + intmax_t want = 18737357U; + intmax_t result = strtoumax("18737357foobar12", &p, 10); + if (result != want) { + t_error("%s strtoumax get result is %zu are not 18737357U\n", __func__, result); + } + if (strcmp(p, "foobar12") != 0) { + t_error("%s strtoumax get is '%s' are not 'foobar12'\n", __func__, p); + } +} + +/** + * @tc.name : strtoumax_0200 + * @tc.desc : Test the strtoumax function to interpret the string content as a base 16 integer + * @tc.level : Level 1 + */ +void strtoumax_0200(void) +{ + char *p = {0}; + intmax_t want = 0x18737357fU; + intmax_t result = strtoumax("18737357foobar12", &p, 16); + if (result != want) { + t_error("%s strtoumax get result is %zu are not 0x18737357fU\n", __func__, result); + } + if (strcmp(p, "oobar12") != 0) { + t_error("%s strtoumax get is '%s' are not 'oobar12'\n", __func__, p); + } +} + +/** + * @tc.name : strtoumax_0300 + * @tc.desc : Test that strtoumax interprets negative string contents as base 10 integers + * @tc.level : Level 1 + */ +void strtoumax_0300(void) +{ + char *p = {0}; + intmax_t subnum = 18737357; + intmax_t result = strtoumax("-18737357foobar12", &p, 10); + if (result != UINTMAX_MAX - subnum + 1) { + t_error("%s strtoumax get result error is %zu\n", __func__, result); + } + if (strcmp(p, "foobar12") != 0) { + t_error("%s strtoumax get is '%s' are not 'foobar12'\n", __func__, p); + } +} + +int main(int argc, char *argv[]) +{ + strtoumax_0100(); + strtoumax_0200(); + strtoumax_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/test_src_functionalext_supplement_stdlib.gni b/libc-test/src/functionalext/supplement/stdlib/test_src_functionalext_supplement_stdlib.gni new file mode 100644 index 00000000..a8d8aba3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/test_src_functionalext_supplement_stdlib.gni @@ -0,0 +1,33 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_stdlib_test = [ + "imaxabs", + "imaxdiv", + "wcstod", + "wcstof", + "wcstold", + "wcstoimax", + "wcstoumax", + "strtoumax", + "strtoimax", + "labs", + "ldiv", + "llabs", + "atoi", + "atof", + "abs", + "lldiv", + "atoll", + "bseach", +] diff --git a/libc-test/src/functionalext/supplement/stdlib/wcstod.c b/libc-test/src/functionalext/supplement/stdlib/wcstod.c new file mode 100644 index 00000000..e11df31a --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/wcstod.c @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "math.h" +#include "test.h" + +#define EXPECT_DOUBLE_EQ(a, b) \ + do { \ + if (!(fabs(a - b) < DBL_EPSILON)) \ + t_error("%s failed: %f is not equal to %f\n", __func__, a, b); \ + } while (0) + +/** + * @tc.name : wcstod_0100 + * @tc.desc : Convert wide string to dobule type + * @tc.level : Level 0 + */ +void wcstod_0100(void) +{ + wchar_t str0[] = L"3.14wcstod"; + wchar_t *end = NULL; + const double target = 3.14; + wchar_t str1[] = L"wcstod"; + double val = wcstod(str0, &end); + EXPECT_DOUBLE_EQ(val, target); + if (wcscmp(end, str1)) { + t_error("%s the result of comparing two strings should be equal", __func__); + } +} + +/** + * @tc.name : wcstod_0200 + * @tc.desc : Convert wide string to dobule type with no end string characters + * @tc.level : Level 1 + */ +void wcstod_0200(void) +{ + wchar_t str[] = L"3.14"; + wchar_t *end = NULL; + const double target = 3.14; + double val = wcstod(str, &end); + EXPECT_DOUBLE_EQ(val, target); +} + +/** + * @tc.name : wcstod_0300 + * @tc.desc : Convert wide string to dobule type with whitespace present at the beginning + * @tc.level : Level 1 + */ +void wcstod_0300(void) +{ + wchar_t str[] = L" 3.14"; + wchar_t *end = NULL; + const double target = 3.14; + double val = wcstod(str, &end); + EXPECT_DOUBLE_EQ(val, target); +} + +/** + * @tc.name : wcstod_0400 + * @tc.desc : Convert wide string to dobule type with string characters at the beginning + * @tc.level : Level 2 + */ +void wcstod_0400(void) +{ + wchar_t str[] = L"wcstod3.14"; + wchar_t *end = NULL; + const double target = 3.14; + double val = wcstod(str, &end); + if (val != 0) { + t_error("%s invalid conversion", __func__); + } +} + +/** + * @tc.name : wcstod_0500 + * @tc.desc : Convert wide string to negative number of type double + * @tc.level : Level 1 + */ +void wcstod_0500(void) +{ + wchar_t str[] = L"-3.14"; + wchar_t *end = NULL; + const double target = -3.14; + double val = wcstod(str, &end); + EXPECT_DOUBLE_EQ(val, target); +} + +/** + * @tc.name : wcstod_0600 + * @tc.desc : Convert the hexadecimal string in the wide string to double type + * @tc.level : Level 1 + */ +void wcstod_0600(void) +{ + wchar_t str[] = L"0X1.BC70A3D70A3D7P+6"; + wchar_t *end = NULL; + double val = wcstod(str, &end); + const double target = 111.11; + EXPECT_DOUBLE_EQ(val, target); +} + +/** + * @tc.name : wcstod_0700 + * @tc.desc : The converted value is greater than double max + * @tc.level : Level 2 + */ +void wcstod_0700(void) +{ + wchar_t str[] = L"1.18973e+4932"; + wchar_t *end = NULL; + double val = wcstod(str, &end); + if (errno != ERANGE) { + t_error("%s errno is not set", __func__); + } + if (val != INFINITY) { + t_error("%s val is not equal to inf", __func__); + } +} + +int main(int argc, char *argv[]) +{ + wcstod_0100(); + wcstod_0200(); + wcstod_0300(); + wcstod_0400(); + wcstod_0500(); + wcstod_0600(); + wcstod_0700(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/wcstof.c b/libc-test/src/functionalext/supplement/stdlib/wcstof.c new file mode 100644 index 00000000..aacfa7d5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/wcstof.c @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "math.h" +#include "test.h" + +#define EXPECT_FLOAT_EQ(a, b) \ + do { \ + if (!(fabsf(a - b) < FLT_EPSILON)) \ + t_error("%s failed: %f is not equal to %f\n", __func__, a, b); \ + } while (0) + +/** + * @tc.name : wcstof_0100 + * @tc.desc : Convert wide string to float type + * @tc.level : Level 0 + */ +void wcstof_0100(void) +{ + wchar_t str0[] = L"3.14wcstof"; + wchar_t *end = NULL; + const float target = 3.14f; + wchar_t str1[] = L"wcstof"; + float val = wcstof(str0, &end); + EXPECT_FLOAT_EQ(val, target); + if (wcscmp(end, str1)) { + t_error("%s the result of comparing two strings should be equal", __func__); + } +} + +/** + * @tc.name : wcstof_0200 + * @tc.desc : Convert wide string to float type with no end string characters + * @tc.level : Level 1 + */ +void wcstof_0200(void) +{ + wchar_t str[] = L"3.14"; + wchar_t *end = NULL; + const float target = 3.14f; + float val = wcstof(str, &end); + EXPECT_FLOAT_EQ(val, target); +} + +/** + * @tc.name : wcstof_0300 + * @tc.desc : Convert wide string to float type with whitespace present at the beginning + * @tc.level : Level 1 + */ +void wcstof_0300(void) +{ + wchar_t str[] = L" 3.14"; + wchar_t *end = NULL; + const float target = 3.14f; + float val = wcstof(str, &end); + EXPECT_FLOAT_EQ(val, target); +} + +/** + * @tc.name : wcstof_0400 + * @tc.desc : Convert wide string to float type with string characters at the beginning + * @tc.level : Level 2 + */ +void wcstof_0400(void) +{ + wchar_t str[] = L"wcstof3.14"; + wchar_t *end = NULL; + const float target = 3.14f; + float val = wcstof(str, &end); + if (val != 0) { + t_error("%s invalid conversion", __func__); + } +} + +/** + * @tc.name : wcstof_0500 + * @tc.desc : Convert wide string to negative number of type float + * @tc.level : Level 1 + */ +void wcstof_0500(void) +{ + wchar_t str[] = L"-3.14"; + wchar_t *end = NULL; + const float target = -3.14f; + float val = wcstof(str, &end); + EXPECT_FLOAT_EQ(val, target); +} + +/** + * @tc.name : wcstof_0600 + * @tc.desc : Convert wide string to negative number of type float + * @tc.level : Level 1 + */ +void wcstof_0600(void) +{ + wchar_t str[] = L"0X1.BC70A3D70A3D7P+6"; + wchar_t *end = NULL; + float val = wcstof(str, &end); + const float target = 111.11f; + EXPECT_FLOAT_EQ(val, target); +} + +/** + * @tc.name : wcstof_0700 + * @tc.desc : The converted value is greater than float max + * @tc.level : Level 2 + */ +void wcstof_0700(void) +{ + wchar_t str[] = L"1.18973e+4932"; + wchar_t *end = NULL; + float val = wcstof(str, &end); + if (errno != ERANGE) { + t_error("%s errno is not set", __func__); + } + if (val != INFINITY) { + t_error("%s val is not equal to inf", __func__); + } +} + +int main(int argc, char *argv[]) +{ + wcstof_0100(); + wcstof_0200(); + wcstof_0300(); + wcstof_0400(); + wcstof_0500(); + wcstof_0600(); + wcstof_0700(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/wcstoimax.c b/libc-test/src/functionalext/supplement/stdlib/wcstoimax.c new file mode 100644 index 00000000..1beeaaa0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/wcstoimax.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" + +void deal_aberrant(int code) +{ + if (code != SIGSEGV) { + t_error("wcstoimax_0200 code is %d are not SIGSEGV", __func__, code); + } + exit(t_status); +} + +/** + * @tc.name : wcstoimax_0100 + * @tc.desc : Test wcstoimax to get numeric part in wide string + * @tc.level : Level 0 + */ +void wcstoimax_0100(void) +{ + wchar_t *end = NULL; + intmax_t want = 123; + intmax_t result = wcstoimax(L" +123x", &end, 10); + if (result != want) { + t_error("%s wcstoimax get result is %d are not want 123\n", __func__, result); + } + if (wcscmp(end, L"x") != 0) { + t_error("%s wcstoimax get end is %ls are not want x\n", __func__, end); + } +} + +/** + * @tc.name : wcstoimax_0200 + * @tc.desc : Test the result of the wcstoimax method when the incoming parameter is empty + * @tc.level : Level 2 + */ +void wcstoimax_0200(void) +{ + signal(SIGSEGV, deal_aberrant); + intmax_t result = wcstoimax(NULL, NULL, 0); +} + +int main(int argc, char *argv[]) +{ + wcstoimax_0100(); + wcstoimax_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/wcstold.c b/libc-test/src/functionalext/supplement/stdlib/wcstold.c new file mode 100644 index 00000000..3fc7cf3b --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/wcstold.c @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "math.h" +#include "test.h" + +#define EXPECT_LONG_DOUBLE_EQ(a, b) \ + do { \ + if (!(fabsl(a - b) < LDBL_EPSILON)) \ + t_error("%s failed: %f is not equal to %f\n", __func__, a, b); \ + } while (0) + +/** + * @tc.name : wcstold_0100 + * @tc.desc : Convert wide string to long double type + * @tc.level : Level 0 + */ +void wcstold_0100(void) +{ + wchar_t str0[] = L"3.14wcstold"; + wchar_t *end = NULL; + const long double target = 3.14L; + wchar_t str1[] = L"wcstold"; + long double val = wcstold(str0, &end); + EXPECT_LONG_DOUBLE_EQ(val, target); + if (wcscmp(end, str1)) { + t_error("%s the result of comparing two strings should be equal", __func__); + } +} + +/** + * @tc.name : wcstold_0200 + * @tc.desc : Convert wide string to long double type with no end string characters + * @tc.level : Level 1 + */ +void wcstold_0200(void) +{ + wchar_t str[] = L"3.14"; + wchar_t *end = NULL; + const long double target = 3.14L; + long double val = wcstold(str, &end); + EXPECT_LONG_DOUBLE_EQ(val, target); +} + +/** + * @tc.name : wcstold_0300 + * @tc.desc : Convert wide string to long double type with whitespace present at the beginning + * @tc.level : Level 1 + */ +void wcstold_0300(void) +{ + wchar_t str[] = L" 3.14"; + wchar_t *end = NULL; + const long double target = 3.14L; + long double val = wcstold(str, &end); + EXPECT_LONG_DOUBLE_EQ(val, target); +} + +/** + * @tc.name : wcstold_0400 + * @tc.desc : Convert wide string to long double type with string characters at the beginning + * @tc.level : Level 2 + */ +void wcstold_0400(void) +{ + wchar_t str[] = L"wcstold3.14"; + wchar_t *end = NULL; + const long double target = 3.14L; + long double val = wcstold(str, &end); + if (val != 0) { + t_error("%s invalid conversion", __func__); + } +} + +/** + * @tc.name : wcstold_0500 + * @tc.desc : Convert wide string to negative number of type long double + * @tc.level : Level 1 + */ +void wcstold_0500(void) +{ + wchar_t str[] = L"-3.14"; + wchar_t *end = NULL; + const long double target = -3.14L; + long double val = wcstold(str, &end); + EXPECT_LONG_DOUBLE_EQ(val, target); +} + +/** + * @tc.name : wcstold_0600 + * @tc.desc : The converted value is greater than long double max + * @tc.level : Level 2 + */ +void wcstold_0600(void) +{ + errno = 0; + wchar_t str[] = L"1.18973e+49322"; + wchar_t *end = NULL; + long double val = wcstold(str, &end); + if (errno != ERANGE) { + t_error("%s errno is not set\n", __func__); + } + if (val != HUGE_VALL) { + t_error("%s val is not equal to inf\n", __func__); + } +} + +int main(int argc, char *argv[]) +{ + wcstold_0100(); + wcstold_0200(); + wcstold_0300(); + wcstold_0400(); + wcstold_0500(); + wcstold_0600(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stdlib/wcstoumax.c b/libc-test/src/functionalext/supplement/stdlib/wcstoumax.c new file mode 100644 index 00000000..e3176daf --- /dev/null +++ b/libc-test/src/functionalext/supplement/stdlib/wcstoumax.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" + +void deal_aberrant(int code) +{ + if (code != SIGSEGV) { + t_error("wcstoumax_0200 code is %d are not SIGSEGV", __func__, code); + } + exit(t_status); +} + +/** + * @tc.name : wcstoumax_0100 + * @tc.desc : Test wcstoumax to get numeric part in wide string + * @tc.level : Level 0 + */ +void wcstoumax_0100(void) +{ + wchar_t *end = NULL; + uintmax_t want = 123U; + uintmax_t result = wcstoumax(L" +123x", &end, 10); + if (result != want) { + t_error("%s wcstoumax get result is %d are not want 123U\n", __func__, result); + } + if (wcscmp(end, L"x") != 0) { + t_error("%s wcstoumax get end is %ls are not want x\n", __func__, end); + } +} + +/** + * @tc.name : wcstoumax_0200 + * @tc.desc : Test the result of the wcstoumax method when the incoming parameter is empty + * @tc.level : Level 2 + */ +void wcstoumax_0200(void) +{ + signal(SIGSEGV, deal_aberrant); + uintmax_t result = wcstoumax(NULL, NULL, 0); +} + +int main(int argc, char *argv[]) +{ + wcstoumax_0100(); + wcstoumax_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/BUILD.gn b/libc-test/src/functionalext/supplement/string/BUILD.gn new file mode 100644 index 00000000..bb0c2fb7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_string.gni") + +foreach(s, functionalext_supplement_string_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/string" + } +} + +group("functionalext_supplement_string_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_string_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/string/bzero.c b/libc-test/src/functionalext/supplement/string/bzero.c new file mode 100644 index 00000000..9d299342 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/bzero.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : bzero_0100 + * @tc.desc : Empty the specified number of elements in the string + * @tc.level : Level 0 + */ +void bzero_0100(void) +{ + char str[20] = "bzero"; + bzero(str, 1); + if (str[0] != 0) { + t_error("%s bzero failed", __func__); + } +} + +/** + * @tc.name : bzero_0200 + * @tc.desc : set '\0' to 0 + * @tc.level : Level 1 + */ +void bzero_0200(void) +{ + char str[20] = "bzero"; + int len = strlen(str); + bzero(str, sizeof(str)); + if (str[len] != 0) { + t_error("%s bzero failed", __func__); + } +} + +int main(int argc, char *argv[]) +{ + bzero_0100(); + bzero_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/index.c b/libc-test/src/functionalext/supplement/string/index.c new file mode 100644 index 00000000..0cb47d61 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/index.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : index_0100 + * @tc.desc : Test the index method to get the position of the first occurrence of the target character + * @tc.level : Level 0 + */ +void index_0100(void) +{ + char *str = "hello world"; + char *result = index(str, 'e'); + if (strcmp(str + 1, result) != 0) { + t_error("%s index get result is %s are not want %s\n", __func__, result, str + 1); + } +} + +/** + * @tc.name : index_0200 + * @tc.desc : The result returned by the index function when the target character appears multiple times in the + * test string + * @tc.level : Level 1 + */ +void index_0200(void) +{ + int add_size = 2; + char *str = "hello world"; + char *result = index(str, 'l'); + if (strcmp(str + add_size, result) != 0) { + t_error("%s index get result is %s are not want %s\n", __func__, result, str + add_size); + } +} + +/** + * @tc.name : index_0300 + * @tc.desc : The result returned by the index function when the target character does not appear in the test + * string + * @tc.level : Level 1 + */ +void index_0300(void) +{ + char *str = "hello world"; + char *result = index(str, 'a'); + if (result) { + t_error("%s index get result is %s are not want ''\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + index_0100(); + index_0200(); + index_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/memccpy.c b/libc-test/src/functionalext/supplement/string/memccpy.c new file mode 100644 index 00000000..255e7c3f --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/memccpy.c @@ -0,0 +1,85 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_BUFFER_SIZE 128 +#define TEST_DATA_LEN 2 + +/** + * @tc.name : memccpy_0100 + * @tc.desc : Copies a string until spaces or data is greater than the specified length + * @tc.level : Level 0 + */ +void memccpy_0100(void) +{ + const char src[TEST_BUFFER_SIZE] = "musl test"; + char dest[TEST_BUFFER_SIZE] = ""; + int i; + void *rev = memccpy(dest, src, ' ', TEST_DATA_LEN); + EXPECT_PTREQ("memccpy_0100", rev, NULL); + EXPECT_EQ("memccpy_0100", strlen(dest), TEST_DATA_LEN); + for (i = 0; i < TEST_DATA_LEN; i++) { + EXPECT_EQ("memccpy_0100", dest[i], src[i]); + } + + memset(dest, 0x0, sizeof(dest)); + rev = memccpy(dest, src, ' ', sizeof(src)); + EXPECT_PTRNE("memccpy_0100", rev, NULL); + EXPECT_EQ("memccpy_0100", strlen(dest), strlen("musl ")); + for (i = 0; i < strlen("musl "); i++) { + EXPECT_EQ("memccpy_0100", dest[i], src[i]); + } +} + +/** + * @tc.name : memccpy_0200 + * @tc.desc : Use a character not contained in the original string as the end position + * for processing the copied string + * @tc.level : Level 0 + */ +void memccpy_0200(void) +{ + const char src[TEST_BUFFER_SIZE] = "musl test"; + char dest[TEST_BUFFER_SIZE] = ""; + int i; + void *rev = memccpy(dest, src, 'A', strlen(src)); + EXPECT_PTREQ("memccpy_0200", rev, NULL); + EXPECT_STREQ("memccpy_0200", dest, src); +} + +/** + * @tc.name : memccpy_0300 + * @tc.desc : The length of the copied string is 0 + * @tc.level : Level 2 + */ +void memccpy_0300(void) +{ + const char src[TEST_BUFFER_SIZE] = "musl test"; + char dest[TEST_BUFFER_SIZE] = ""; + int i; + void *rev = memccpy(dest, src, ' ', 0); + EXPECT_PTREQ("memccpy_0300", rev, NULL); + EXPECT_EQ("memccpy_0300", strlen(dest), 0); +} + +int main(void) +{ + memccpy_0100(); + memccpy_0200(); + memccpy_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/memchr.c b/libc-test/src/functionalext/supplement/string/memchr.c new file mode 100644 index 00000000..759ad9b4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/memchr.c @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int INIT_LEN = 0; + +/** + * @tc.name :memchr_0100 + * @tc.desc :Verify memchr is successed and return 0. + * @tc.level :level 0. + */ +void memchr_0100(void) +{ + const char *srcstring = "this is a unittest"; + char fitch = 'u'; + char *findch = (char *)memchr(srcstring, fitch, strlen(srcstring)); + if (findch) { + EXPECT_EQ("memchr_0100", fitch, findch[0]); + EXPECT_STREQ("memchr_0100", "unittest", findch); + } else { + EXPECT_PTRNE("memchr_0100", findch, NULL); + } +} + +/** + * @tc.name :memchr_0200 + * @tc.desc :Verify memchr is failed and return NULL. + * @tc.level :level 1. + */ +void memchr_0200(void) +{ + const char *srcstring = "this is a unittest"; + char *findch = (char *)memchr(srcstring, 'w', strlen(srcstring)); + EXPECT_PTREQ("memchr_0200", findch, NULL); +} + +/** + * @tc.name :memchr_0300 + * @tc.desc :Verify memchr is failed when first param src is invalid. + * @tc.level :level 2. + */ +void memchr_0300(void) +{ + const char *srcstring = ""; + char *findch = (char *)memchr(srcstring, 'w', strlen(srcstring)); + EXPECT_PTREQ("memchr_0300", findch, NULL); +} + +/** + * @tc.name :memchr_0400 + * @tc.desc :Verify memchr is failed when second param c is invalid. + * @tc.level :level 2. + */ +void memchr_0400(void) +{ + const char *srcstring = "this is a unittest"; + char *findch = (char *)memchr(srcstring, '\0', strlen(srcstring)); + EXPECT_PTREQ("memchr_0400", findch, NULL); +} + +/** + * @tc.name :memchr_0500 + * @tc.desc :Verify memchr is failed when third param n is invalid. + * @tc.level :level 2. + */ +void memchr_0500(void) +{ + const char *srcstring = "this is a unittest"; + char *findch = (char *)memchr(srcstring, 'u', INIT_LEN); + EXPECT_PTREQ("memchr_0500", findch, NULL); +} + +int main(void) +{ + memchr_0100(); + memchr_0200(); + memchr_0300(); + memchr_0400(); + memchr_0500(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/string/memmem.c b/libc-test/src/functionalext/supplement/string/memmem.c new file mode 100644 index 00000000..18a188dc --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/memmem.c @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : memmem_0100 + * @tc.desc : Normal value test, assert whether the address value of the return value is + * the created buffer address + * @tc.level : Level 0 + */ +void memmem_0100(void) +{ + const char buffer[] = "musl test"; + const char cmp[] = "musl"; + char *ptr = NULL; + + for (int i = 0; i < sizeof(cmp) / sizeof(cmp[0]); i++) { + ptr = memmem(buffer, sizeof(buffer), cmp, i); + if (ptr == NULL) { + EXPECT_PTRNE("memmem_0100", ptr, NULL); + return; + } + EXPECT_PTREQ("memmem_0100", ptr, buffer); + } +} + +/** + * @tc.name : memmem_0200 + * @tc.desc : Assert whether the returned value of an invalid parameter is null + * @tc.level : Level 2 + */ +void memmem_0200(void) +{ + const char buffer[] = "musl test"; + size_t buflen = sizeof(buffer) / sizeof(buffer[0]); + size_t errlen = buflen + 1; + char *ptr = NULL; + + ptr = memmem(buffer, sizeof(buffer), "musl", errlen); + EXPECT_PTREQ("memmem_0200", ptr, NULL); + + ptr = memmem(buffer, sizeof(buffer), "muls", 3); + EXPECT_PTREQ("memmem_0200", ptr, NULL); +} + +int main(void) +{ + memmem_0100(); + memmem_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/memmove.c b/libc-test/src/functionalext/supplement/string/memmove.c new file mode 100644 index 00000000..6ebe4a04 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/memmove.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : memmove_0100 + * @tc.desc : The source address and the destination address are equal, and no copying is performed. + * @tc.level : Level 1 + */ +void memmove_0100(void) +{ + char str[] = "memmove_0100"; + void *p = memmove(str, str, 5); + EXPECT_EQ("memmove_0100", p, str); + bool flag = false; + if (p != NULL) { + flag = true; + } + EXPECT_TRUE("memmove_0100", flag); +} + +/** + * @tc.name : memmove_0200 + * @tc.desc : The source address and the destination address do not overlap, copy it. + * @tc.level : Level 0 + */ +void memmove_0200(void) +{ + bool successflag = false; + char str[] = "memmove_0200"; + char *dest = str + 3, *src = str; + void *p = memmove(dest, src, 2); + if (strstr(dest, src) != NULL || strstr(src, dest) != NULL) { + successflag = true; + } + EXPECT_TRUE("memmove_0200", successflag); + bool flag = false; + if (p != NULL) { + flag = true; + } + EXPECT_TRUE("memmove_0200", flag); +} + +/** + * @tc.name : memmove_0300 + * @tc.desc : The first address of dest is less than the first address of src, and forward copy is performed. + * @tc.level : Level 1 + */ +void memmove_0300(void) +{ + bool successflag = false; + char str[] = "memmove_0300"; + char *dest = str, *src = str + 2; + void *p = memmove(dest, src, 5); + if (strstr(dest, src) != NULL || strstr(src, dest) != NULL) { + successflag = true; + } + EXPECT_TRUE("memmove_0300", successflag); + bool flag = false; + if (p != NULL) { + flag = true; + } + EXPECT_TRUE("memmove_0300", flag); +} + +/** + * @tc.name : memmove_0400 + * @tc.desc : The first address of dest is greater than the first address of src, and reverse copy is performed. + * @tc.level : Level 1 + */ +void memmove_0400(void) +{ + bool successflag = false; + char str[] = "memmove_0400"; + char *dest = str + 2, *src = str; + void *p = memmove(dest, src, 5); + if (strstr(dest, src) != NULL || strstr(src, dest) != NULL) { + successflag = true; + } + EXPECT_TRUE("memmove_0400", successflag); + bool flag = false; + if (p != NULL) { + flag = true; + } + EXPECT_TRUE("memmove_0400", flag); +} + +int main() +{ + memmove_0100(); + memmove_0200(); + memmove_0300(); + memmove_0400(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/mempcpy.c b/libc-test/src/functionalext/supplement/string/mempcpy.c new file mode 100644 index 00000000..9b377171 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/mempcpy.c @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_BUFFER_SIZE 128 +#define TEST_DATA_LEN 8 + +/** + * @tc.name : mempcpy_0100 + * @tc.desc : Verify strcasecmp process success. Copies the string into the array dest. + * @tc.level : Level 0 + */ +void mempcpy_0100(void) +{ + const char src[TEST_BUFFER_SIZE] = "mempcpy_0100"; + char dest[TEST_BUFFER_SIZE] = ""; + void *rev = mempcpy(dest, src, strlen(src)); + EXPECT_STREQ("mempcpy_0100", dest, "mempcpy_0100"); +} + +/** + * @tc.name : mempcpy_0200 + * @tc.desc : Verify strcasecmp process success. Copies the 8 consecutive characters starting with the 8th + * character in src into d. + * @tc.level : Level 0 + */ +void mempcpy_0200(void) +{ + const char src[TEST_BUFFER_SIZE] = "mempcpy_0200test"; + char dest[TEST_BUFFER_SIZE] = ""; + void *rev = mempcpy(dest, src + TEST_DATA_LEN, TEST_DATA_LEN * strlen(src)); + EXPECT_STREQ("mempcpy_0200", dest, "0200test"); +} + +/** + * @tc.name : mempcpy_0300 + * @tc.desc : Verify strcasecmp process success. Overwrite the original data. + * @tc.level : Level 0 + */ +void mempcpy_0300(void) +{ + const char src[TEST_BUFFER_SIZE] = "mempcpy_0300"; + char dest[TEST_BUFFER_SIZE] = "****"; + void *rev = mempcpy(dest, src, strlen(src)); + EXPECT_STREQ("mempcpy_0300", dest, "mempcpy_0300"); +} + +/** + * @tc.name : mempcpy_0400 + * @tc.desc : Verify strcasecmp process fail. The length of the copied string is 0. + * @tc.level : Level 2 + */ +void mempcpy_0400(void) +{ + const char src[TEST_BUFFER_SIZE] = "mempcpy_0400"; + char dest[TEST_BUFFER_SIZE] = ""; + void *rev = mempcpy(dest, src, 0); + EXPECT_STREQ("mempcpy_0200", dest, ""); +} + +int main(void) +{ + mempcpy_0100(); + mempcpy_0200(); + mempcpy_0300(); + mempcpy_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/memrchr.c b/libc-test/src/functionalext/supplement/string/memrchr.c new file mode 100755 index 00000000..5fd37028 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/memrchr.c @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_AT_FDCWD (-100) +#define TEST_ERROR_AT_FDCWD 100 + +/** + * @tc.name : memrchr_0100 + * @tc.desc : Search for a character in the specified memory block + * @tc.level : Level 0 + */ +void memrchr_0100(void) +{ + const char *src = "this is memrchr_0100 test."; + + char *ret = memrchr(src, 'r', strlen(src)); + EXPECT_PTRNE("memrchr_0100", ret, NULL); + EXPECT_STREQ("memrchr_0100", ret, "r_0100 test."); + + ret = memrchr(src, 'r', strlen("memrchr_0100 test.")); + EXPECT_PTRNE("memrchr_0100", ret, NULL); + EXPECT_STREQ("memrchr_0100", ret, "r_0100 test."); + + ret = memrchr(src, 'w', strlen(src)); + EXPECT_PTREQ("memrchr_0100", ret, NULL); +} + +/** + * @tc.name : memrchr_0200 + * @tc.desc : Provide an exception parameter to search for characters in the specified memory block + * @tc.level : Level 2 + */ +void memrchr_0200(void) +{ + const char *src = "this is memrchr_0200 test."; + char *ret = memrchr(src, 'r', 0); + EXPECT_PTREQ("memrchr_0200", ret, NULL); +} + +int main(void) +{ + memrchr_0100(); + memrchr_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/stpcpy.c b/libc-test/src/functionalext/supplement/string/stpcpy.c new file mode 100644 index 00000000..eaf03b02 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/stpcpy.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +#define BUF_SIZE (13) + +void handler(int sig) +{ + exit(t_status); +} + +/** + * @tc.name : stpcpy_0100 + * @tc.desc : copy a string returning a pointer to its end + * @tc.level : Level 0 + */ +void stpcpy_0100(void) +{ + char buf[BUF_SIZE]; + memset(buf, 'A', sizeof(buf)); + + char *src = "Hello"; + char *dest = (char *)buf; + strcpy(dest, src); + + if (strcmp(src, buf)) { + t_error("%s failed: src = %s, buf = %s\n", __func__, src, buf); + return; + } + + for (int i = strlen(src) + 1; i < BUF_SIZE; i++) { + if (buf[i] != 'A') { + t_error("%s failed: buf[%d] = %c\n", __func__, i, buf[i]); + return; + } + } +} + +/** + * @tc.name : stpcpy_0200 + * @tc.desc : copy an empty string returning a pointer to its end + * @tc.level : Level 1 + */ +void stpcpy_0200(void) +{ + char buf[1]; + + char *src = ""; + char *dest = (char *)buf; + strcpy(dest, src); + + if (strcmp(src, buf)) { + t_error("%s failed: src = %s, buf = %s\n", __func__, src, buf); + return; + } + + if (buf[0] != '\0') { + t_error("%s failed: buf[0] = %c\n", __func__, buf[0]); + return; + } +} + +/** + * @tc.name : stpcpy_0300 + * @tc.desc : copy a string with the same size + * @tc.level : Level 1 + */ +void stpcpy_0300(void) +{ + char buf[BUF_SIZE]; + memset(buf, 'A', sizeof(buf)); + + char *src = "Hello world!"; + char *dest = (char *)buf; + strcpy(dest, src); + + if (strcmp(src, buf)) { + t_error("%s failed: src = %s, buf = %s\n", __func__, src, buf); + return; + } +} + +/** + * @tc.name : stpcpy_0400 + * @tc.desc : copy a string to a NULL pointer + * @tc.level : Level 2 + */ +void stpcpy_0400(void) +{ + signal(SIGSEGV, handler); + + char *src = "Hello world!"; + strcpy(NULL, src); +} + +int main(int argc, char *argv[]) +{ + stpcpy_0100(); + stpcpy_0200(); + stpcpy_0300(); + stpcpy_0400(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/string/stpncpy.c b/libc-test/src/functionalext/supplement/string/stpncpy.c new file mode 100644 index 00000000..c40d83a6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/stpncpy.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +#define BUF_SIZE (13) + +void handler(int sig) +{ + exit(t_status); +} + +/** + * @tc.name : stpncpy_0100 + * @tc.desc : copy a string returning a pointer to its end + * @tc.level : Level 0 + */ +void stpncpy_0100(void) +{ + char buf[BUF_SIZE]; + memset(buf, 'A', sizeof(buf)); + + char *src = "Hello"; + char *dest = (char *)buf; + stpncpy(dest, src, strlen(src)); + + if (strncmp(src, buf, strlen(src))) { + t_error("%s failed: src = %s, buf = %s\n", __func__, src, buf); + return; + } + + for (int i = strlen(src) + 1; i < BUF_SIZE; i++) { + if (buf[i] != 'A') { + t_error("%s failed: buf[%d] = %c\n", __func__, i, buf[i]); + return; + } + } +} + +/** + * @tc.name : stpncpy_0200 + * @tc.desc : copy an empty string returning a pointer to its end + * @tc.level : Level 1 + */ +void stpncpy_0200(void) +{ + char buf[1]; + memset(buf, 0, sizeof(buf)); + + char *src = ""; + char *dest = (char *)buf; + stpncpy(dest, src, strlen(src)); + + if (strcmp(src, buf)) { + t_error("%s failed: src = %s, buf = %s\n", __func__, src, buf); + return; + } + + if (buf[0] != '\0') { + t_error("%s failed: buf[0] = %c\n", __func__, buf[0]); + return; + } +} + +/** + * @tc.name : stpncpy_0300 + * @tc.desc : copy a string with the same size + * @tc.level : Level 1 + */ +void stpncpy_0300(void) +{ + char buf[BUF_SIZE]; + memset(buf, 'A', sizeof(buf)); + + char *src = "Hello world!"; + char *dest = (char *)buf; + stpncpy(dest, src, strlen(src)); + + if (strncmp(src, buf, strlen(src))) { + t_error("%s failed: src = %s, buf = %s\n", __func__, src, buf); + return; + } +} + +/** + * @tc.name : stpncpy_0400 + * @tc.desc : copy a string to a NULL pointer + * @tc.level : Level 2 + */ +void stpncpy_0400(void) +{ + signal(SIGSEGV, handler); + + char *src = "Hello world!"; + stpncpy(NULL, src, strlen(src)); +} + +int main(int argc, char *argv[]) +{ + stpncpy_0100(); + stpncpy_0200(); + stpncpy_0300(); + stpncpy_0400(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/string/strcasecmp.c b/libc-test/src/functionalext/supplement/string/strcasecmp.c new file mode 100644 index 00000000..2eaa42d4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strcasecmp.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : strcasecmp_0100 + * @tc.desc : Verify strcasecmp process success when fist string equal second stirng + * @tc.level : Level 0 + */ +void strcasecmp_0100(void) +{ + int32_t ret = strcasecmp("aBcDeF", "AbCdEf"); + EXPECT_EQ("strcasecmp_0100", ret, 0); +} + +/** + * @tc.name : strcasecmp_0200 + * @tc.desc : Verify strcasecmp process success when fist string less than second stirng + * @tc.level : Level 1 + */ +void strcasecmp_0200(void) +{ + int32_t ret = strcasecmp("", "AbCdEf"); + EXPECT_LT("strcasecmp_0200", ret, 0); +} + +/** + * @tc.name : strcasecmp_0300 + * @tc.desc : Verify strcasecmp process success when fist string more than second stirng + * @tc.level : Level 1 + */ +void strcasecmp_0300(void) +{ + int32_t ret = strcasecmp("AbCdEf", ""); + EXPECT_MT("strcasecmp_0300", ret, 0); +} + +/** + * @tc.name : strcasecmp_0400 + * @tc.desc : Verify strcasecmp process success when fist string is null second stirng is null + * @tc.level : Level 1 + */ +void strcasecmp_0400(void) +{ + int32_t ret = strcasecmp("", ""); + EXPECT_EQ("strcasecmp_0400", ret, 0); +} + +int main(void) +{ + strcasecmp_0100(); + strcasecmp_0200(); + strcasecmp_0300(); + strcasecmp_0400(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/string/strcasestr.c b/libc-test/src/functionalext/supplement/string/strcasestr.c new file mode 100644 index 00000000..953ce0c0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strcasestr.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : strcasestr_0100 + * @tc.desc : Test strcasestr method to intercept string + * @tc.level : Level 0 + */ +void strcasestr_0100(void) +{ + char *haystate = "bIg dAdDy/gIaNt hAyStAcKs"; + char *result = strcasestr(haystate, ""); + if (strcmp(result, "bIg dAdDy/gIaNt hAyStAcKs") != 0) { + t_error("%s strcasestr error get result is %s\n", __func__, result); + } +} + +/** + * @tc.name : strcasestr_0200 + * @tc.desc : Test strcasestr method incoming uppercase letter interception + * @tc.level : Level 1 + */ +void strcasestr_0200(void) +{ + char *haystate = "bIg dAdDy/gIaNt hAyStAcKs"; + char *result = strcasestr(haystate, "B"); + if (strcmp(result, "bIg dAdDy/gIaNt hAyStAcKs") != 0) { + t_error("%s strcasestr error get result is %s\n", __func__, result); + } +} + +/** + * @tc.name : strcasestr_0300 + * @tc.desc : Test strcasestr method incoming lowercase letter interception + * @tc.level : Level 1 + */ +void strcasestr_0300(void) +{ + char *haystate = "bIg dAdDy/gIaNt hAyStAcKs"; + char *result = strcasestr(haystate, "i"); + if (strcmp(result, "Ig dAdDy/gIaNt hAyStAcKs") != 0) { + t_error("%s strcasestr error get result is %s\n", __func__, result); + } +} + +/** + * @tc.name : strcasestr_0400 + * @tc.desc : Test strcasestr method incoming string interception + * @tc.level : Level 1 + */ +void strcasestr_0400(void) +{ + char *haystate = "bIg dAdDy/gIaNt hAyStAcKs"; + char *result = strcasestr(haystate, "Da"); + if (strcmp(result, "dAdDy/gIaNt hAyStAcKs") != 0) { + t_error("%s strcasestr error get result is %s\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + strcasestr_0100(); + strcasestr_0200(); + strcasestr_0300(); + strcasestr_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/strcat.c b/libc-test/src/functionalext/supplement/string/strcat.c new file mode 100644 index 00000000..cecbdd1b --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strcat.c @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define LENGTH 50 + +/** + * @tc.name : strcat_0100 + * @tc.desc : Verify strcat process success + * @tc.level : Level 0 + */ +void strcat_0100(void) +{ + char src[LENGTH] = "Source"; + char *ret = strcat(src, "Destination"); + EXPECT_STREQ("strcat_0100", ret, "SourceDestination"); +} + +int main(void) +{ + strcat_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/string/strchrnul.c b/libc-test/src/functionalext/supplement/string/strchrnul.c new file mode 100644 index 00000000..74d7bc4f --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strchrnul.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "test.h" + +/** + * @tc.name : strchrnul_0100 + * @tc.desc : Find the specified character in a string + * @tc.level : Level 0 + */ +void strchrnul_0100(void) +{ + char *str = "Hello world"; + char *tmp = NULL; + + tmp = strchrnul(str, 'w'); + if (tmp == NULL) { + t_error("%s tmp is NULL", __func__); + } + + if (strcmp(tmp, "world")) { + t_error("%s tmp is %s, not world", __func__, tmp); + } +} + +/** + * @tc.name : strchrnul_0200 + * @tc.desc : Find \0 Character in String + * @tc.level : Level 1 + */ +void strchrnul_0200(void) +{ + char *str = "Hello world"; + char *tmp = NULL; + + tmp = strchrnul(str, '\0'); + if (tmp == NULL) { + t_error("%s tmp is NULL", __func__); + } + + if (strcmp(tmp, "")) { + t_error("%s tmp is %s, not 0", __func__, tmp); + } +} + +/** + * @tc.name : strchrnul_0300 + * @tc.desc : Find \0 Character in String + * @tc.level : Level 2 + */ +void strchrnul_0300(void) +{ + char *str = "Hello world"; + char *tmp = NULL; + + tmp = strchrnul(str, 'a'); + if (tmp == NULL) { + t_error("%s tmp is NULL", __func__); + } + + if (strcmp(tmp, "")) { + t_error("%s tmp is %s, not NULL", __func__, tmp); + } +} + +int main(int argc, char *argv[]) +{ + strchrnul_0100(); + strchrnul_0200(); + strchrnul_0300(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/string/strcoll.c b/libc-test/src/functionalext/supplement/string/strcoll.c new file mode 100644 index 00000000..f27417ff --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strcoll.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : strcoll_0100 + * @tc.desc : Verify strcoll process success when fist string equal second stirng + * @tc.level : Level 0 + */ +void strcoll_0100(void) +{ + int32_t ret = strcoll("aBcDeF", "aBcDeF"); + EXPECT_EQ("strcoll_0100", ret, 0); +} + +/** + * @tc.name : strcoll_0200 + * @tc.desc : Verify strcoll process success when fist string less than second stirng + * @tc.level : Level 1 + */ +void strcoll_0200(void) +{ + int32_t ret = strcoll("", "AbCdEf"); + EXPECT_LT("strcoll_0200", ret, 0); +} + +/** + * @tc.name : strcoll_0300 + * @tc.desc : Verify strcoll process success when fist string more than second stirng + * @tc.level : Level 1 + */ +void strcoll_0300(void) +{ + int32_t ret = strcoll("AbCdEf", ""); + EXPECT_MT("strcoll_0300", ret, 0); +} + +/** + * @tc.name : strcoll_0400 + * @tc.desc : Verify strcoll process success when fist string is null second stirng is null + * @tc.level : Level 1 + */ +void strcoll_0400(void) +{ + int32_t ret = strcoll("", ""); + EXPECT_EQ("strcoll_0400", ret, 0); +} + +int main(void) +{ + strcoll_0100(); + strcoll_0200(); + strcoll_0300(); + strcoll_0400(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/string/strdup.c b/libc-test/src/functionalext/supplement/string/strdup.c new file mode 100644 index 00000000..65e4bb5f --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strdup.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : strdup_0100 + * @tc.desc : Verify strdup process success + * @tc.level : Level 0 + */ +void strdup_0100(void) +{ + char *ret = strdup("strduptest"); + EXPECT_STREQ("strdup_0100", ret, "strduptest"); +} + +int main(void) +{ + strdup_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/string/strerror_r.c b/libc-test/src/functionalext/supplement/string/strerror_r.c new file mode 100644 index 00000000..872782ad --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strerror_r.c @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define BUFSIZE 1024 +const int32_t invalidParam = 1; + +/** + * @tc.name : strerror_r_0100 + * @tc.desc : Verify strerror_r process success + * @tc.level : Level 0 + */ +void strerror_r_0100(void) +{ + char src[BUFSIZE] = "strerror_r_0100"; + int32_t ret = strerror_r(EDOM, src, BUFSIZE); + EXPECT_EQ("strerror_r_0100", ret, 0); +} + +/** + * @tc.name : strerror_r_0200 + * @tc.desc : Verify strerror_r process success when thrid param is 0 + * @tc.level : Level 1 + */ +void strerror_r_0200(void) +{ + char src[BUFSIZE] = "strcasecmp_0200"; + int32_t ret = strerror_r(EDOM, src, 0); + EXPECT_EQ("strerror_r_0200", ret, ERANGE); +} + +/** + * @tc.name : strerror_r_0300 + * @tc.desc : Verify strerror_r process success when thrid param is 1 + * @tc.level : Level 1 + */ +void strerror_r_0300(void) +{ + char src[BUFSIZE] = "strerror_r_0300"; + int32_t ret = strerror_r(EDOM, src, invalidParam); + EXPECT_EQ("strerror_r_0300", ret, ERANGE); +} + +int main(void) +{ + strerror_r_0100(); + strerror_r_0200(); + strerror_r_0300(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/string/strlen.c b/libc-test/src/functionalext/supplement/string/strlen.c new file mode 100644 index 00000000..32693bec --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strlen.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int INIT_LEN = 0; + +/** + * @tc.name :strlen_0100 + * @tc.desc :Verify strlen is successed when src is "this is a test 1234~@#$%". + * @tc.desc :level 0 + */ +void strlen_0100(void) +{ + char src[] = "this is a test 1234~@#$%"; + int srcLen = sizeof(src) / sizeof(src[0]) - 1; + int ret = strlen(src); + EXPECT_EQ("strlen_0100", ret, srcLen); +} + +/** + * @tc.name :strlen_0200 + * @tc.desc :Verify strlen is successed when src is "测试1234~@#$%". + * @tc.desc :level 1 + */ +void strlen_0200(void) +{ + char src[] = "测试1234~@#$%"; + int srcLen = sizeof(src) / sizeof(src[0]) - 1; + int ret = strlen(src); + EXPECT_EQ("strlen_0200", ret, srcLen); +} + +/** + * @tc.name :strlen_0300 + * @tc.desc :Verify strlen is successed when src is "". + * @tc.desc :level 1 + */ +void strlen_0300(void) +{ + char src[] = ""; + int srcLen = INIT_LEN; + int ret = strlen(src); + EXPECT_EQ("strlen_0300", ret, srcLen); +} + +int main(void) +{ + strlen_0100(); + strlen_0200(); + strlen_0300(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/string/strncasecmp.c b/libc-test/src/functionalext/supplement/string/strncasecmp.c new file mode 100644 index 00000000..a3bb5c9f --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strncasecmp.c @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int32_t compareLength = 3; + +/** + * @tc.name : strncasecmp_0100 + * @tc.desc : Verify strncasecmp process success when fist string equal second stirng + * @tc.level : Level 0 + */ +void strncasecmp_0100(void) +{ + int32_t ret = strncasecmp("aBcDeF", "AbCdEf", compareLength); + EXPECT_EQ("strncasecmp_0100", ret, 0); +} + +/** + * @tc.name : strncasecmp_0200 + * @tc.desc : Verify strncasecmp process success when fist string equal second stirng and compare length is 0 + * @tc.level : Level 1 + */ +void strncasecmp_0200(void) +{ + int32_t ret = strncasecmp("aBcDeF", "AbCdEf", 0); + EXPECT_EQ("strncasecmp_0200", ret, 0); +} + +/** + * @tc.name : strncasecmp_0300 + * @tc.desc : Verify strcasecmp process success when fist string less than second stirng + * @tc.level : Level 1 + */ +void strncasecmp_0300(void) +{ + int32_t ret = strncasecmp("", "AbCdEf", compareLength); + EXPECT_LT("strcasecmp_0300", ret, 0); +} + +/** + * @tc.name : strncasecmp_0400 + * @tc.desc : Verify strncasecmp process success when fist string more than second stirng + * @tc.level : Level 1 + */ +void strncasecmp_0400(void) +{ + int32_t ret = strncasecmp("AbCdEf", "", compareLength); + EXPECT_MT("strncasecmp_0400", ret, 0); +} + +/** + * @tc.name : strncasecmp_0500 + * @tc.desc : Verify strncasecmp process success when fist string is null second stirng is null + * @tc.level : Level 1 + */ +void strncasecmp_0500(void) +{ + int32_t ret = strncasecmp("", "", 3); + EXPECT_EQ("strncasecmp_0500", ret, 0); +} + +int main(void) +{ + strncasecmp_0100(); + strncasecmp_0200(); + strncasecmp_0300(); + strncasecmp_0400(); + strncasecmp_0500(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/string/strndup.c b/libc-test/src/functionalext/supplement/string/strndup.c new file mode 100644 index 00000000..556318a0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strndup.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : strndup_0100 + * @tc.desc : Test the strndup function to copy the string according to the input parameter + * @tc.level : Level 0 + */ +void strndup_0100(void) +{ + char *str = "helloworld"; + char *result = strndup(str, 2); + if (strcmp(result, "he")) { + t_error("%s strndup get result is '%s' are not 'he'\n", __func__, result); + } +} + +/** + * @tc.name : strndup_0200 + * @tc.desc : Test the return value of strndup when the number of copies of the input exceeds the passed string + * @tc.level : Level 1 + */ +void strndup_0200(void) +{ + char *str = "helloworld"; + char *result = strndup(str, 12); + if (strcmp(result, "helloworld")) { + t_error("%s strndup get result is '%s' are not 'he'\n", __func__, result); + } +} + +/** + * @tc.name : strndup_0300 + * @tc.desc : The return value of strndup when the number of test copies is 0 + * @tc.level : Level 1 + */ +void strndup_0300(void) +{ + char *str = "helloworld"; + char *result = strndup(str, 0); + if (strcmp(result, "") != 0) { + t_error("%s strndup get result is '%s' are not ''\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + strndup_0100(); + strndup_0200(); + strndup_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/strnlen.c b/libc-test/src/functionalext/supplement/string/strnlen.c new file mode 100644 index 00000000..5c41ac48 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strnlen.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : strnlen_0100 + * @tc.desc : Test strnlen function to get string length + * @tc.level : Level 0 + */ +void strnlen_0100(void) +{ + size_t want = 5; + char *str = "123456"; + size_t result = strnlen(str, 5); + if (result != want) { + t_error("%s strnlen get result is %d are not 5\n", __func__, result); + } +} + +/** + * @tc.name : strnlen_0200 + * @tc.desc : The incoming length is greater than the string length + * @tc.level : Level 1 + */ +void strnlen_0200(void) +{ + size_t want = 6; + char *str = "123456"; + size_t result = strnlen(str, 9); + if (result != want) { + t_error("%s strnlen get result is %d are not 6\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + strnlen_0100(); + strnlen_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/strrchr.c b/libc-test/src/functionalext/supplement/string/strrchr.c new file mode 100644 index 00000000..e7fb5f90 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strrchr.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +#define T(no, str, c, substr) \ + { \ + char *result = strrchr(str, c); \ + if (strcmp(result, substr) != 0) \ + t_error("%s strrchr(%s,%s) returned %s, wanted %s\n", #no, #str, #c, result, substr); \ + } + +#define N(no, str, c) \ + { \ + char *result = strrchr(str, c); \ + if (result != NULL) \ + t_error("%s strrchr(%s,%s) returned %s is not NULL\n", #no, #str, #c, result); \ + } + +#define N1(no, str) \ + { \ + char *result = strrchr(str, 0); \ + if (strcmp(result, "") != 0) \ + t_error("%s strrchr(%s,NULL) returned %s is not ''\n", #no, #str, result); \ + } + +int main(int argc, char *argv[]) +{ + /** + * @tc.name : strrchr_0100 + * @tc.desc : Get the position of the last occurrence of a character in a string + * @tc.level : Level 0 + */ + T("strrchr_0100", "happy", 'a', "appy"); + /** + * @tc.name : strrchr_0200 + * @tc.desc : Get is the last occurrence of a character in a string + * @tc.level : Level 1 + */ + T("strrchr_0200", "happy", 'p', "py"); + /** + * @tc.name : strrchr_0300 + * @tc.desc : Test string does not appear parameter + * @tc.level : Level 1 + */ + N("strrchr_0300", "happy", 'd'); + /** + * @tc.name : strrchr_0400 + * @tc.desc : Test empty string as parameter + * @tc.level : Level 2 + */ + N("strrchr_0400", "", 'd'); + /** + * @tc.name : strrchr_0500 + * @tc.desc : Test null character as parameter + * @tc.level : Level 2 + */ + N1("strrchr_0500", "happy"); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/strsep.c b/libc-test/src/functionalext/supplement/string/strsep.c new file mode 100644 index 00000000..d69d20c0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strsep.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : strsep_0100 + * @tc.desc : Test calling strsep function to intercept string + * @tc.level : Level 0 + */ +void strsep_0100(void) +{ + char str[12] = {0}; + strcpy(str, "helloworld"); + char *p = (char *)str; + char *sep = "w"; + char *result = strsep(&p, sep); + if (strcmp(result, "hello") != 0) { + t_error("%s strsep get result is '%s' are not 'hello'\n", __func__, result); + } + if (strcmp(str, "hello") != 0) { + t_error("%s strsep get str is '%s' are not 'hello'\n", __func__, str); + } +} + +/** + * @tc.name : strsep_0200 + * @tc.desc : Test strsep result when marker character appears multiple times in truncated string + * @tc.level : Level 1 + */ +void strsep_0200(void) +{ + char str[12] = {0}; + strcpy(str, "helloworld"); + char *p = (char *)str; + char *sep = "l"; + char *result = strsep(&p, sep); + if (strcmp(result, "he") != 0) { + t_error("%s strsep get result is '%s' are not 'he'\n", __func__, result); + } + if (strcmp(str, "he") != 0) { + t_error("%s strsep get result is '%s' are not 'he'\n", __func__, str); + } +} + +/** + * @tc.name : strsep_0300 + * @tc.desc : test strsep result when marker character does not appear in truncated string + * @tc.level : Level 1 + */ +void strsep_0300(void) +{ + char str[12] = {0}; + strcpy(str, "helloworld"); + char *p = (char *)str; + char *sep = "a"; + char *result = strsep(&p, sep); + if (strcmp(result, "helloworld") != 0) { + t_error("%s strsep get result is '%s' are not 'helloworld'\n", __func__, result); + } + if (strcmp(str, "helloworld") != 0) { + t_error("%s strsep get result is '%s' are not 'helloworld'\n", __func__, str); + } +} + +int main(int argc, char *argv[]) +{ + strsep_0100(); + strsep_0200(); + strsep_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/strsignal.c b/libc-test/src/functionalext/supplement/string/strsignal.c new file mode 100644 index 00000000..2826285e --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strsignal.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : strsignal_0100 + * @tc.desc : Returns a string describing the signal number + * @tc.level : Level 0 + */ +void strsignal_0100(void) +{ + char *str = strsignal(SIGHUP); + if (strcmp(str, "Hangup")) { + t_error("%s failed, str is %s", __func__, str); + } +} + +/** + * @tc.name : strsignal_0200 + * @tc.desc : The parameter signum is equal to _NSIG + * @tc.level : Level 1 + */ +void strsignal_0200(void) +{ + char *str = strsignal(_NSIG); + if (strcmp(str, "Unknown signal")) { + t_error("%s failed, str is %s\n", __func__, str); + } +} + +int main(int argc, char *argv[]) +{ + strsignal_0100(); + strsignal_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/strtok_r.c b/libc-test/src/functionalext/supplement/string/strtok_r.c new file mode 100644 index 00000000..36759870 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/strtok_r.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : strtok_r_0100 + * @tc.desc : Test strtok_r function to intercept string according to input characters + * @tc.level : Level 0 + */ +void strtok_r_0100(void) +{ + char *compare[3] = {"ABC", "DEF", "GHI"}; + char buf[] = "ABC,DEF,GHI"; + char *result[3]; + char *p = buf; + char *outer_ptr = NULL; + for (int i = 0; i < 3; i++) { + result[i] = strtok_r(outer_ptr, ",", &p); + } + for (int a = 0; a < 3; a++) { + if (strcmp(result[a], compare[a]) != 0) { + t_error("%s strtok_r in %d get value is %s are not %s\n", __func__, a, result[a], compare[a]); + } + } +} + +/** + * @tc.name : strtok_r_0200 + * @tc.desc : Test the return value of the strtok_r function when the intercepted string is an empty string + * @tc.level : Level 1 + */ +void strtok_r_0200(void) +{ + char *p; + char *outer_ptr = NULL; + char *result = strtok_r(outer_ptr, ",", &p); + if (!result) { + t_error("%s strtok_r error get result is %s not null\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + strtok_r_0100(); + strtok_r_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/swab.c b/libc-test/src/functionalext/supplement/string/swab.c new file mode 100644 index 00000000..260196ad --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/swab.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : swab_0100 + * @tc.desc : Swap bytes from source and destination area + * @tc.level : Level 0 + */ +void swab_0100(void) +{ + char src[20] = "swab"; + char dest[20]; + swab(src, dest, strlen(src)); + if (strcmp(dest, "wsba")) { + t_error("%s swab failed", __func__); + } +} + +/** + * @tc.name : swab_0200 + * @tc.desc : Swap bytes from source and destination area, and dest is initialized + * @tc.level : Level 1 + */ +void swab_0200(void) +{ + char src[20] = "swab"; + char dest[20] = "swab"; + swab(src, dest, strlen(src)); + if (strcmp(dest, "wsba")) { + t_error("%s swab failed", __func__); + } +} + +int main(int argc, char *argv[]) +{ + swab_0100(); + swab_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/test_src_functionalext_supplement_string.gni b/libc-test/src/functionalext/supplement/string/test_src_functionalext_supplement_string.gni new file mode 100644 index 00000000..7c8c78c3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/test_src_functionalext_supplement_string.gni @@ -0,0 +1,66 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_string_test = [ + "bzero", + "memchr", + "strcasecmp", + "stpcpy", + "stpncpy", + "strcasestr", + "strcat", + "strcoll", + "strdup", + "wcswcs", + "strerror_r", + "wcsdup", + "strchrnul", + "strndup", + "wcpncpy", + "wcscspn", + "wcsspn", + "wcpcpy", + "strnlen", + "strrchr", + "strsep", + "strsignal", + "strtok_r", + "swab", + "index", + "wcsnlen", + "wcscasecmp_l", + "wcscasecmp", + "wcsncasecmp_l", + "wcsncasecmp", + "wcscmp", + "wcslen", + "wcsncmp", + "wcsncpy", + "wcspbrk", + "wcsrchr", + "wcsncat", + "wcstok", + "wcscat", + "wcschr", + "wcscpy", + "wmemchr", + "wmemcmp", + "wmemcpy", + "wmemmove", + "wmemset", + "memccpy", + "mempcpy", + "memmem", + "memmove", + "memrchr", +] diff --git a/libc-test/src/functionalext/supplement/string/wcpcpy.c b/libc-test/src/functionalext/supplement/string/wcpcpy.c new file mode 100644 index 00000000..a50fe0ad --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcpcpy.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcpcpy_0100 + * @tc.desc : Test the wcpcpy method to copy a wide string in bits + * @tc.level : Level 0 + */ +void wcpcpy_0100(void) +{ + wchar_t src[] = L"Source string"; + wchar_t dst[14]; + wchar_t *result = wcpcpy(dst, src); + if (wcscmp(result, dst + 13) != 0) { + t_error("%s wcpcpy get result is %ls are not want %ls\n", __func__, result, dst + 13); + } + if (wcscmp(src, dst) != 0) { + t_error("%s wcpcpy get dst is %ls are not want %ls\n", __func__, dst, src); + } +} + +int main(int argc, char *argv[]) +{ + wcpcpy_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcpncpy.c b/libc-test/src/functionalext/supplement/string/wcpncpy.c new file mode 100644 index 00000000..84f3d93f --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcpncpy.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcpncpy_0100 + * @tc.desc : Test the wcpncpy method to copy a wide string in bits + * @tc.level : Level 0 + */ +void wcpncpy_0100(void) +{ + wchar_t src[] = L"Source string"; + wchar_t dst[18]; + size_t src_len = 13; + wchar_t *result = wcpncpy(dst, src, src_len + 1); + if (wcscmp(result, dst + src_len) != 0) { + t_error("%s wcpncpy get result is %ls are not want %ls\n", __func__, result, dst + src_len); + } + if (wcscmp(src, dst) != 0) { + t_error("%s wcpncpy get dst is %ls are not want %ls\n", __func__, dst, src); + } +} + +/** + * @tc.name : wcpncpy_0200 + * @tc.desc : Test the result of the wcpncpy method when the incoming length is less than the copied wide string + * @tc.level : Level 1 + */ +void wcpncpy_0200(void) +{ + wchar_t src[] = L"Source string"; + wchar_t dst[18]; + size_t src_len = 13; + wchar_t *result = wcpncpy(dst, src, 2); + if (wcscmp(result, dst + 2) != 0) { + t_error("%s wcpncpy get result is %ls are not want %ls\n", __func__, result, dst + 2); + } + if (wcscmp(src, dst) != 0) { + t_error("%s wcpncpy get dst is %ls are not want %ls\n", __func__, dst, src); + } +} + +/** + * @tc.name : wcpncpy_0300 + * @tc.desc : Test the result of the wcpncpy method when the incoming length is greater than the copied wide string + * @tc.level : Level 1 + */ +void wcpncpy_0300(void) +{ + wchar_t src[] = L"Source string"; + wchar_t dst[18]; + size_t src_len = 13; + wchar_t *result = wcpncpy(dst, src, 17); + if (wcscmp(result, dst + src_len) != 0) { + t_error("%s wcpncpy get result is %ls are not want %ls\n", __func__, result, dst + src_len); + } + if (wcscmp(src, dst) != 0) { + t_error("%s wcpncpy get dst is %ls are not want %ls\n", __func__, dst, src); + } +} + +int main(int argc, char *argv[]) +{ + wcpncpy_0100(); + wcpncpy_0200(); + wcpncpy_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcscasecmp.c b/libc-test/src/functionalext/supplement/string/wcscasecmp.c new file mode 100644 index 00000000..67d22a0c --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcscasecmp.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcscasecmp_0100 + * @tc.desc : Test wcscasecmp compare case-ignoring wide strings + * @tc.level : Level 0 + */ +void wcscasecmp_0100(void) +{ + int result = wcscasecmp(L"hello", L"HELLO"); + if (result != 0) { + t_error("%s wcscasecmp get result is %d are not 0\n", __func__, result); + } +} + +/** + * @tc.name : wcscasecmp_0200 + * @tc.desc : Test the result of calling wcscasecmp with uppercase letters, plus numbers, and lowercase letters + * and small numbers + * @tc.level : Level 1 + */ +void wcscasecmp_0200(void) +{ + int result = wcscasecmp(L"hello1", L"HELLO2"); + if (result >= 0) { + t_error("%s wcscasecmp get result is %d are more then 0\n", __func__, result); + } +} + +/** + * @tc.name : wcscasecmp_0300 + * @tc.desc : Test the result of calling wcscasecmp with uppercase letters plus small numbers and lowercase + * letters and large numbers + * @tc.level : Level 1 + */ +void wcscasecmp_0300(void) +{ + int result = wcscasecmp(L"hello2", L"HELLO1"); + if (result <= 0) { + t_error("%s wcscasecmp get result is %d are less then 0\n", __func__, result); + } +} + +/** + * @tc.name : wcscasecmp_0400 + * @tc.desc : Test the result of calling wcscasecmp for shorter uppercase wide strings versus longer lowercase + * wide strings + * @tc.level : Level 1 + */ +void wcscasecmp_0400(void) +{ + int result = wcscasecmp(L"hello", L"HELL"); + if (result <= 0) { + t_error("%s wcscasecmp get result is %d are less then 0\n", __func__, result); + } +} + +/** + * @tc.name : wcscasecmp_0500 + * @tc.desc : Test the result of calling wcscasecmp on a shorter lowercase wide string versus a longer uppercase + * wide string + * @tc.level : Level 1 + */ +void wcscasecmp_0500(void) +{ + int result = wcscasecmp(L"hell", L"HELLO"); + if (result >= 0) { + t_error("%s wcscasecmp get result is %d are more then 0\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + wcscasecmp_0100(); + wcscasecmp_0200(); + wcscasecmp_0300(); + wcscasecmp_0400(); + wcscasecmp_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcscasecmp_l.c b/libc-test/src/functionalext/supplement/string/wcscasecmp_l.c new file mode 100644 index 00000000..150cff7c --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcscasecmp_l.c @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcscasecmp_l_0100 + * @tc.desc : Test wcscasecmp_l compare case-ignoring wide strings + * @tc.level : Level 0 + */ +void wcscasecmp_l_0100(void) +{ + locale_t local_info = NULL; + int result = wcscasecmp_l(L"hello", L"HELLO", local_info); + if (result != 0) { + t_error("%s wcscasecmp_l get result is %d are not 0\n", __func__, result); + } +} + +/** + * @tc.name : wcscasecmp_l_0200 + * @tc.desc : Test the result of calling wcscasecmp_l with uppercase letters, plus numbers, and lowercase letters + * and small numbers + * @tc.level : Level 1 + */ +void wcscasecmp_l_0200(void) +{ + locale_t local_info = NULL; + int result = wcscasecmp_l(L"hello1", L"HELLO2", local_info); + if (result >= 0) { + t_error("%s wcscasecmp_l get result is %d are more then 0\n", __func__, result); + } +} + +/** + * @tc.name : wcscasecmp_l_0300 + * @tc.desc : Test the result of calling wcscasecmp_l with uppercase letters plus small numbers and lowercase + * letters and large numbers + * @tc.level : Level 1 + */ +void wcscasecmp_l_0300(void) +{ + locale_t local_info = NULL; + int result = wcscasecmp_l(L"hello2", L"HELLO1", local_info); + if (result <= 0) { + t_error("%s wcscasecmp_l get result is %d are less then 0\n", __func__, result); + } +} + +/** + * @tc.name : wcscasecmp_l_0400 + * @tc.desc : Test the result of calling wcscasecmp_l for shorter uppercase wide strings versus longer lowercase + * wide strings + * @tc.level : Level 1 + */ +void wcscasecmp_l_0400(void) +{ + locale_t local_info = NULL; + int result = wcscasecmp_l(L"hello", L"HELL", local_info); + if (result <= 0) { + t_error("%s wcscasecmp_l get result is %d are less then 0\n", __func__, result); + } +} + +/** + * @tc.name : wcscasecmp_l_0500 + * @tc.desc : Test the result of calling wcscasecmp_l on a shorter lowercase wide string versus a longer uppercase + * wide string + * @tc.level : Level 1 + */ +void wcscasecmp_l_0500(void) +{ + locale_t local_info = NULL; + int result = wcscasecmp_l(L"hell", L"HELLO", local_info); + if (result >= 0) { + t_error("%s wcscasecmp_l get result is %d are more then 0\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + wcscasecmp_l_0100(); + wcscasecmp_l_0200(); + wcscasecmp_l_0300(); + wcscasecmp_l_0400(); + wcscasecmp_l_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcscat.c b/libc-test/src/functionalext/supplement/string/wcscat.c new file mode 100644 index 00000000..1ac56985 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcscat.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +#define MAX (20) + +void handler(int sig) +{ + exit(t_status); +} + +/** + * @tc.name : wcscat_0100 + * @tc.desc : Concatenate wide strings + * @tc.level : Level 0 + */ +void wcscat_0100(void) +{ + wchar_t dest[MAX] = L"wcscat "; + wchar_t src[MAX] = L"test"; + wcscat(dest, src); + if (wcscmp(dest, L"wcscat test")) { + t_error("%s concatenate wide strings failed\n", __func__); + } +} + +/** + * @tc.name : wcscat_0200 + * @tc.desc : destination and source overlap. + * @tc.level : Level 2 + */ +void wcscat_0200(void) +{ + signal(SIGSEGV, handler); + + wchar_t dest[MAX] = L"wcscat "; + wchar_t *src = &dest[1]; + wcscat(dest, src); +} + +int main(int argc, char *argv[]) +{ + wcscat_0100(); + wcscat_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcschr.c b/libc-test/src/functionalext/supplement/string/wcschr.c new file mode 100644 index 00000000..77e5dcb2 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcschr.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcschr_0100 + * @tc.desc : returns a pointer to the first occurrence of the wide character c + * @tc.level : Level 0 + */ +void wcschr_0100(void) +{ + wchar_t wcs[] = L"This is a c test for wcschr"; + wchar_t *p; + p = wcschr(wcs, L'c'); + if (*p != L'c') { + t_error("%s the character pointed to by the pointer is not c", __func__); + } +} + +/** + * @tc.name : wcschr_0200 + * @tc.desc : The target character is empty, returns a pointer to the end of the wide string + * @tc.level : Level 1 + */ +void wcschr_0200(void) +{ + wchar_t wcs[] = L"This is a c test for wcschr"; + wchar_t *p; + p = wcschr(wcs, L'\0'); + if ((p - wcs) != wcslen(wcs)) { + t_error("%s pointer does not point to end of wide string", __func__); + } +} + +/** + * @tc.name : wcschr_0300 + * @tc.desc : The first character of the wide string is the target character + * @tc.level : Level 1 + */ +void wcschr_0300(void) +{ + wchar_t wcs[] = L"This is a c test for wcschr"; + wchar_t *p; + p = wcschr(wcs, L'T'); + if (*p != L'T') { + t_error("%s the character pointed to by the pointer is not T", __func__); + } +} + +int main(int argc, char *argv[]) +{ + wcschr_0100(); + wcschr_0200(); + wcschr_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcscmp.c b/libc-test/src/functionalext/supplement/string/wcscmp.c new file mode 100644 index 00000000..52d9ac12 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcscmp.c @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcscmp_0100 + * @tc.desc : Compares two equal wide strings and returns a value equal to 0 + * @tc.level : Level 0 + */ +void wcscmp_0100(void) +{ + wchar_t str1[] = L"test wcscmp"; + wchar_t str2[] = L"test wcscmp"; + if (wcscmp(str1, str2)) { + t_error("%s error, the result of comparing two strings should be equal", __func__); + } +} + +/** + * @tc.name : wcscmp_0200 + * @tc.desc : Compares two equal wide strings and returns a value less than zero + * @tc.level : Level 0 + */ +void wcscmp_0200(void) +{ + wchar_t str1[] = L"ABCD"; + wchar_t str2[] = L"ABCE"; + if (wcscmp(str1, str2) >= 0) { + t_error("%s error, expected result value less than zero", __func__); + } +} + +/** + * @tc.name : wcscmp_0300 + * @tc.desc : Compares two equal wide strings and returns a value greater than zero + * @tc.level : Level 0 + */ +void wcscmp_0300(void) +{ + wchar_t str1[] = L"ABCE"; + wchar_t str2[] = L"ABCD"; + if (wcscmp(str1, str2) <= 0) { + t_error("%s error, expected result value greater than zero", __func__); + } +} + +/** + * @tc.name : wcscmp_0400 + * @tc.desc : The first characters of the compared wide strings are different + * @tc.level : Level 1 + */ +void wcscmp_0400(void) +{ + wchar_t str1[] = L"ABCD"; + wchar_t str2[] = L"BCDE"; + if (wcscmp(str1, str2) >= 0) { + t_error("%s error, expected result value less than zero", __func__); + } + if (wcscmp(str2, str1) <= 0) { + t_error("%s error, expected result value greater than zero", __func__); + } +} + +/** + * @tc.name : wcscmp_0500 + * @tc.desc : One or both of the wide strings compared are equal to NULL + * @tc.level : Level 1 + */ +void wcscmp_0500(void) +{ + wchar_t str1[] = L""; + wchar_t str2[] = L""; + wchar_t str3[] = L"A"; + if (wcscmp(str1, str3) >= 0) { + t_error("%s error, expected result value less than zero", __func__); + } + if (wcscmp(str3, str1) <= 0) { + t_error("%s error, expected result value greater than zero", __func__); + } + if (wcscmp(str1, str2)) { + t_error("%s error, the result of comparing two strings should be equal", __func__); + } +} + +int main(int argc, char *argv[]) +{ + wcscmp_0100(); + wcscmp_0200(); + wcscmp_0300(); + wcscmp_0400(); + wcscmp_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcscpy.c b/libc-test/src/functionalext/supplement/string/wcscpy.c new file mode 100644 index 00000000..c0944500 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcscpy.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +#define BUFF_SIZE (40) + +void handler(int sig) +{ + exit(t_status); +} + +/** + * @tc.name : wcscpy_0100 + * @tc.desc : Copies the C wide string pointed by wcs into the array pointed by des + * @tc.level : Level 0 + */ +void wcscpy_0100(void) +{ + wchar_t wcs[] = L"wcscpy test"; + wchar_t des[BUFF_SIZE]; + wcscpy(des, wcs); + if (wcscmp(wcs, des)) { + t_error("%s wcscpy failed", __func__); + } +} + +/** + * @tc.name : wcscpy_0200 + * @tc.desc : Copy when wcs is an empty string + * @tc.level : Level 1 + */ +void wcscpy_0200(void) +{ + wchar_t wcs[] = L""; + wchar_t des[] = L"wcscpy test"; + wcscpy(des, wcs); + if (wcscmp(wcs, des)) { + t_error("%s des is not equal to wcs", __func__); + } +} + +/** + * @tc.name : wcscpy_0300 + * @tc.desc : des is empty, the program is abnormal + * @tc.level : Level 2 + */ +void wcscpy_0300(void) +{ + signal(SIGSEGV, handler); + + wchar_t wcs[] = L"wcscpy test"; + wcscpy(NULL, wcs); +} + +int main(int argc, char *argv[]) +{ + wcscpy_0100(); + wcscpy_0200(); + wcscpy_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcscspn.c b/libc-test/src/functionalext/supplement/string/wcscspn.c new file mode 100644 index 00000000..27a9c43f --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcscspn.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcscspn_0100 + * @tc.desc : Call the wcscspn method to get the length of the maximum initial segment of the wide string points + * to dest + * @tc.level : Level 0 + */ +void wcscspn_0100(void) +{ + size_t result = wcscspn(L"hello world", L"abcdefghijklmnopqrstuvwxyz"); + if (result != 0U) { + t_error("%s wcscspn get result is %d are not want 0U\n", __func__, result); + } +} + +/** + * @tc.name : wcscspn_0200 + * @tc.desc : The return result of wcscspn when dest is a space + * @tc.level : Level 1 + */ +void wcscspn_0200(void) +{ + size_t result = wcscspn(L"hello world", L" "); + size_t want = 5U; + if (result != want) { + t_error("%s wcscspn get result is %d are not want 5U\n", __func__, result); + } +} + +/** + * @tc.name : wcscspn_0300 + * @tc.desc : wcscspn returns result when dest is punctuation + * @tc.level : Level 1 + */ +void wcscspn_0300(void) +{ + size_t result = wcscspn(L"hello world", L"!"); + size_t want = 11U; + if (result != want) { + t_error("%s wcscspn get result is %d are not want 11U\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + wcscspn_0100(); + wcscspn_0200(); + wcscspn_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcsdup.c b/libc-test/src/functionalext/supplement/string/wcsdup.c new file mode 100644 index 00000000..80b45537 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcsdup.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +void deal_aberrant(int code) +{ + if (code != SIGSEGV) { + t_error("wcsdup_0200 code is %d are not SIGSEGV", __func__, code); + } + exit(t_status); +} + +/** + * @tc.name : wcsdup_0100 + * @tc.desc : Call wcsdup to get a newly allocated wide string + * @tc.level : Level 0 + */ +void wcsdup_0100(void) +{ + wchar_t *src = L"hello"; + wchar_t *result = wcsdup(src); + if (wcscmp(src, result) != 0) { + t_error("%s wcscmp get result is %ls are not want %ls\n", __func__, result, src); + } +} + +/** + * @tc.name : wcsdup_0200 + * @tc.desc : Test the wcsdup result when the incoming null + * @tc.level : Level 2 + */ +void wcsdup_0200(void) +{ + signal(SIGSEGV, deal_aberrant); + wchar_t *result = wcsdup(NULL); +} + +int main(int argc, char *argv[]) +{ + wcsdup_0100(); + wcsdup_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcslen.c b/libc-test/src/functionalext/supplement/string/wcslen.c new file mode 100644 index 00000000..825fdd1f --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcslen.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcslen_0100 + * @tc.desc : Calculate the length of a wide character array + * @tc.level : Level 0 + */ +void wcslen_0100(void) +{ + wchar_t str[] = L"wcslen"; + int target = 6; + size_t num = wcslen(str); + if (num != target) + t_error("%s wcslen is not right", __func__); +} + +int main(int argc, char *argv[]) +{ + wcslen_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcsncasecmp.c b/libc-test/src/functionalext/supplement/string/wcsncasecmp.c new file mode 100644 index 00000000..95336791 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcsncasecmp.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcsncasecmp_0100 + * @tc.desc : Test wcsncasecmp ignore case compares the first n digits of two wide strings + * @tc.level : Level 0 + */ +void wcsncasecmp_0100(void) +{ + int result = wcsncasecmp(L"hello1", L"HELLO2", 5); + if (result != 0) { + t_error("%s wcsncasecmp get result is %d are not want 0\n", __func__, result); + } +} + +/** + * @tc.name : wcsncasecmp_0200 + * @tc.desc : Test that wcsncasecmp returns the result when ws1 is greater than ws2 in the dictionary + * @tc.level : Level 1 + */ +void wcsncasecmp_0200(void) +{ + int result = wcsncasecmp(L"hello1", L"HELLO2", 6); + if (result >= 0) { + t_error("%s wcsncasecmp get result is %d are not want less 0\n", __func__, result); + } +} + +/** + * @tc.name : wcsncasecmp_0300 + * @tc.desc : Test that wcsncasecmp returns the result when ws1 is less than ws2 in the dictionary + * @tc.level : Level 1 + */ +void wcsncasecmp_0300(void) +{ + int result = wcsncasecmp(L"hello2", L"HELLO1", 6); + if (result <= 0) { + t_error("%s wcsncasecmp get result is %d are not want gress 0\n", __func__, result); + } +} + +/** + * @tc.name : wcsncasecmp_0400 + * @tc.desc : Test that wcsncasecmp returns the result when ws1 is longer in the dictionary than ws2 + * @tc.level : Level 1 + */ +void wcsncasecmp_0400(void) +{ + int result = wcsncasecmp(L"hello", L"HELL", 5); + if (result <= 0) { + t_error("%s wcsncasecmp get result is %d are not want gress 0\n", __func__, result); + } +} + +/** + * @tc.name : wcsncasecmp_0500 + * @tc.desc : wcsncasecmp returns result when test ws1 is shorter than ws2 in dictionary + * @tc.level : Level 1 + */ +void wcsncasecmp_0500(void) +{ + int result = wcsncasecmp(L"hell", L"HELLO", 5); + if (result >= 0) { + t_error("%s wcsncasecmp get result is %d are not want less 0\n", __func__, result); + } +} + +/** + * @tc.name : wcsncasecmp_0600 + * @tc.desc : Test the result returned by wcsncasecmp when the number of comparisons is 0 + * @tc.level : Level 2 + */ +void wcsncasecmp_0600(void) +{ + int result = wcsncasecmp(L"foo", L"bar", 0); + if (result != 0) { + t_error("%s wcsncasecmp get result is %d are not want 0\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + wcsncasecmp_0100(); + wcsncasecmp_0200(); + wcsncasecmp_0300(); + wcsncasecmp_0400(); + wcsncasecmp_0500(); + wcsncasecmp_0600(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcsncasecmp_l.c b/libc-test/src/functionalext/supplement/string/wcsncasecmp_l.c new file mode 100644 index 00000000..b1f752f2 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcsncasecmp_l.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcsncasecmp_l_0100 + * @tc.desc : Test wcsncasecmp_l ignore case compares the first n digits of two wide strings + * @tc.level : Level 0 + */ +void wcsncasecmp_l_0100(void) +{ + int result = wcsncasecmp_l(L"hello1", L"HELLO2", 5, NULL); + if (result != 0) { + t_error("%s wcsncasecmp_l get result is %d are not want 0\n", __func__, result); + } +} + +/** + * @tc.name : wcsncasecmp_l_0200 + * @tc.desc : Test that wcsncasecmp_l returns the result when ws1 is greater than ws2 in the dictionary + * @tc.level : Level 1 + */ +void wcsncasecmp_l_0200(void) +{ + int result = wcsncasecmp_l(L"hello1", L"HELLO2", 6, NULL); + if (result >= 0) { + t_error("%s wcsncasecmp_l get result is %d are not want less 0\n", __func__, result); + } +} + +/** + * @tc.name : wcsncasecmp_l_0300 + * @tc.desc : Test that wcsncasecmp_l returns the result when ws1 is less than ws2 in the dictionary + * @tc.level : Level 1 + */ +void wcsncasecmp_l_0300(void) +{ + int result = wcsncasecmp_l(L"hello2", L"HELLO1", 6, NULL); + if (result <= 0) { + t_error("%s wcsncasecmp_l get result is %d are not want gress 0\n", __func__, result); + } +} + +/** + * @tc.name : wcsncasecmp_l_0400 + * @tc.desc : Test that wcsncasecmp_l returns the result when ws1 is longer in the dictionary than ws2 + * @tc.level : Level 1 + */ +void wcsncasecmp_l_0400(void) +{ + int result = wcsncasecmp_l(L"hello", L"HELL", 5, NULL); + if (result <= 0) { + t_error("%s wcsncasecmp_l get result is %d are not want gress 0\n", __func__, result); + } +} + +/** + * @tc.name : wcsncasecmp_l_0500 + * @tc.desc : wcsncasecmp_l returns result when test ws1 is shorter than ws2 in dictionary + * @tc.level : Level 1 + */ +void wcsncasecmp_l_0500(void) +{ + int result = wcsncasecmp_l(L"hell", L"HELLO", 5, NULL); + if (result >= 0) { + t_error("%s wcsncasecmp_l get result is %d are not want less 0\n", __func__, result); + } +} + +/** + * @tc.name : wcsncasecmp_l_0600 + * @tc.desc : Test the result returned by wcsncasecmp_l when the number of comparisons is 0 + * @tc.level : Level 2 + */ +void wcsncasecmp_l_0600(void) +{ + int result = wcsncasecmp_l(L"foo", L"bar", 0, NULL); + if (result != 0) { + t_error("%s wcsncasecmp_l get result is %d are not want 0\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + wcsncasecmp_l_0100(); + wcsncasecmp_l_0200(); + wcsncasecmp_l_0300(); + wcsncasecmp_l_0400(); + wcsncasecmp_l_0500(); + wcsncasecmp_l_0600(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcsncat.c b/libc-test/src/functionalext/supplement/string/wcsncat.c new file mode 100644 index 00000000..826d62ff --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcsncat.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcsncat_0100 + * @tc.desc : Test the wcsncat method to pass the source wide string into the target wide string according to the + * number passed in + * @tc.level : Level 0 + */ +void wcsncat_0100(void) +{ + wchar_t dst[32] = {0}; + wchar_t *result = wcsncat(dst, L"hello, world!", 5); + if (wcscmp(dst, result) != 0) { + t_error("%s wcsncat get result is %s are not %s\n", __func__, dst, result); + } + if (wcscmp(dst, L"hello") != 0) { + t_error("%s wcsncat get result is %s are not 'hello'\n", __func__, dst); + } +} + +/** + * @tc.name : wcsncat_0200 + * @tc.desc : Test the result of the function wcsncat when the number of incoming copies is 0 + * @tc.level : Level 1 + */ +void wcsncat_0200(void) +{ + wchar_t dst[32] = {0}; + wchar_t *result = wcsncat(dst, L"hello, world!", 0); + if (wcscmp(dst, result) != 0) { + t_error("%s wcsncat get result is %s are not %s\n", __func__, dst, result); + } + if (wcscmp(dst, L"") != 0) { + t_error("%s wcsncat get result is %s are not 'hello'\n", __func__, dst); + } +} + +/** + * @tc.name : wcsncat_0300 + * @tc.desc : Test the result of the wcsncat function when the number of incoming copies is greater than the + * source string + * @tc.level : Level 1 + */ +void wcsncat_0300(void) +{ + wchar_t dst[32] = {0}; + wchar_t *result = wcsncat(dst, L"hello, world!", 16); + if (wcscmp(dst, result) != 0) { + t_error("%s wcsncat get result is %s are not %s\n", __func__, dst, result); + } + if (wcscmp(dst, L"hello, world!") != 0) { + t_error("%s wcsncat get result is %s are not 'hello, world!'\n", __func__, dst); + } +} + +int main(int argc, char *argv[]) +{ + wcsncat_0100(); + wcsncat_0200(); + wcsncat_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcsncmp.c b/libc-test/src/functionalext/supplement/string/wcsncmp.c new file mode 100644 index 00000000..eebe765e --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcsncmp.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcsncmp_0100 + * @tc.desc : Test the wcsncmp function to compare the first n bits of two wide strings + * @tc.level : Level 0 + */ +void wcsncmp_0100(void) +{ + int result = wcsncmp(L"aaaa", L"aaab", 3); + if (result != 0) { + t_error("%s wcsncmp get result is %d are not 0", __func__, result); + } +} + +/** + * @tc.name : wcsncmp_0200 + * @tc.desc : Test the wcsncmp result when comparing the top 0 bits + * @tc.level : Level 1 + */ +void wcsncmp_0200(void) +{ + int result = wcsncmp(L"foo", L"bar", 0); + if (result != 0) { + t_error("%s wcsncmp get result is %d are not 0", __func__, result); + } +} + +/** + * @tc.name : wcsncmp_0300 + * @tc.desc : Test wcsncmp result when first wide string is lexicographically lower than second wide string + * @tc.level : Level 1 + */ +void wcsncmp_0300(void) +{ + int result = wcsncmp(L"aaaa", L"aaab", 4); + if (result >= 0) { + t_error("%s wcsncmp get result is %d are not less 0", __func__, result); + } +} + +/** + * @tc.name : wcsncmp_0400 + * @tc.desc : Test wcsncmp result when first wide string is lexicographically higher than second wide string + * @tc.level : Level 1 + */ +void wcsncmp_0400(void) +{ + int result = wcsncmp(L"aaab", L"aaaa", 4); + if (result <= 0) { + t_error("%s wcsncmp get result is %d are not more 0", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + wcsncmp_0100(); + wcsncmp_0200(); + wcsncmp_0300(); + wcsncmp_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcsncpy.c b/libc-test/src/functionalext/supplement/string/wcsncpy.c new file mode 100644 index 00000000..5c09c455 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcsncpy.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +#define SIZEOF_WCHAR(x) (sizeof(x) / sizeof(wchar_t)) + +void handler(int sig) +{ + exit(t_status); +} + +/** + * @tc.name : wcsncpy_0100 + * @tc.desc : copy a fixed-size string of wide characters + * @tc.level : Level 0 + */ +void wcsncpy_0100(void) +{ + const wchar_t src[] = L"Hello"; + wchar_t buf[SIZEOF_WCHAR(src) + 1]; + wmemset(buf, L'A', SIZEOF_WCHAR(buf)); + wchar_t *dest = (wchar_t *)buf; + + if (dest != wcsncpy(dest, src, SIZEOF_WCHAR(src))) { + t_error("%s failed: wcsncpy. src = %ls, dest = %ls\n", __func__, src, dest); + } +} + +/** + * @tc.name : wcsncpy_0200 + * @tc.desc : copy a 0-size string of wide characters + * @tc.level : Level 1 + */ +void wcsncpy_0200(void) +{ + const wchar_t src[] = L"Hello"; + wchar_t buf[SIZEOF_WCHAR(src)]; + wmemset(buf, L'A', SIZEOF_WCHAR(buf)); + wchar_t *dest = (wchar_t *)buf; + + if (dest != wcsncpy(dest, src, 0)) { + t_error("%s failed: wcsncpy. src = %ls, dest = %ls\n", __func__, src, dest); + } +} + +/** + * @tc.name : wcsncpy_0300 + * @tc.desc : copy a fixed-size string of wide characters with a larger size + * @tc.level : Level 1 + */ +void wcsncpy_0300(void) +{ + const wchar_t src[] = L"Hello"; + wchar_t buf[SIZEOF_WCHAR(src) + SIZEOF_WCHAR(src)]; + wmemset(buf, L'A', SIZEOF_WCHAR(buf)); + wchar_t *dest = (wchar_t *)buf; + + if (dest != wcsncpy(dest, src, SIZEOF_WCHAR(src) + SIZEOF_WCHAR(src) - 1)) { + t_error("%s failed: wcsncpy. src = %ls, dest = %ls\n", __func__, src, dest); + } + + int i = 0; + for (i = SIZEOF_WCHAR(src) + 1; i < SIZEOF_WCHAR(buf) - 1; i++) { + if (buf[i] != L'\0') { + t_error("%s failed: buf[%d] = %lc\n", __func__, i, buf[i]); + } + } + + if (buf[i] != L'A') { + t_error("%s failed: buf[%d] = %lc\n", __func__, i, buf[i]); + } +} + +/** + * @tc.name : wcsncpy_0400 + * @tc.desc : copy a fixed-size string of wide characters to a NULL pointer + * @tc.level : Level 2 + */ +void wcsncpy_0400(void) +{ + signal(SIGSEGV, handler); + + const wchar_t src[] = L"Hello"; + wcsncpy(NULL, src, SIZEOF_WCHAR(src)); +} + +int main(int argc, char *argv[]) +{ + wcsncpy_0100(); + wcsncpy_0200(); + wcsncpy_0300(); + wcsncpy_0400(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/string/wcsnlen.c b/libc-test/src/functionalext/supplement/string/wcsnlen.c new file mode 100644 index 00000000..8b026062 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcsnlen.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcsnlen_0100 + * @tc.desc : Test the wcsnlen method to get the number of wide strings + * @tc.level : Level 0 + */ +void wcsnlen_0100(void) +{ + wchar_t *wc = L"ABCDEF"; + size_t want = 6; + size_t result = wcsnlen(wc, 6); + if (result != want) { + t_error("%s wcsnlen error get result is %d are not want 6\n", __func__, result); + } +} + +/** + * @tc.name : wcsnlen_0200 + * @tc.desc : Test the return value of wcsnlen when the incoming length is 0 + * @tc.level : Level 1 + */ +void wcsnlen_0200(void) +{ + wchar_t *wc = L"ABCDEF"; + size_t result = wcsnlen(wc, 0); + if (result != 0) { + t_error("%s wcsnlen error get result is %d are not want 0\n", __func__, result); + } +} + +/** + * @tc.name : wcsnlen_0300 + * @tc.desc : Test the return value of wcsnlen when the incoming length is less than the incoming wide string + * @tc.level : Level 1 + */ +void wcsnlen_0300(void) +{ + wchar_t *wc = L"ABCDEF"; + size_t want = 3; + size_t result = wcsnlen(wc, 3); + if (result != want) { + t_error("%s wcsnlen error get result is %d are not want 3\n", __func__, result); + } +} + +/** + * @tc.name : wcsnlen_0400 + * @tc.desc : Test the return value of wcsnlen when the incoming length is greater than the incoming wide string + * length + * @tc.level : Level 1 + */ +void wcsnlen_0400(void) +{ + wchar_t *wc = L"ABCDEF"; + size_t want = 6; + size_t result = wcsnlen(wc, 7); + if (result != want) { + t_error("%s wcsnlen error get result is %d are not want 6\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + wcsnlen_0100(); + wcsnlen_0200(); + wcsnlen_0300(); + wcsnlen_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcspbrk.c b/libc-test/src/functionalext/supplement/string/wcspbrk.c new file mode 100644 index 00000000..62fc1b87 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcspbrk.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcspbrk_0100 + * @tc.desc : Test wcspbrk to get the first occurrence of the target character in the source string + * @tc.level : Level 0 + */ +void wcspbrk_0100(void) +{ + const wchar_t *s = L"hello, world!"; + wchar_t *result = wcspbrk(s, L"-"); + if (result) { + t_error("%s wcspbrk get are not null\n", __func__); + } +} + +/** + * @tc.name : wcspbrk_0200 + * @tc.desc : Test the result of wcspbrk when the target character appears at the first position of the source + * character + * @tc.level : Level 1 + */ +void wcspbrk_0200(void) +{ + const wchar_t *s = L"hello, world!"; + wchar_t *result = wcspbrk(s, L"abch"); + if (wcscmp(result, s) != 0) { + t_error("%s wcspbrk get result is %lc are not %lc\n", __func__, result, s); + } +} + +/** + * @tc.name : wcspbrk_0300 + * @tc.desc : Test the result of wcspbrk when the target character appears in the middle of the source character + * @tc.level : Level 1 + */ +void wcspbrk_0300(void) +{ + const wchar_t *s = L"hello, world!"; + wchar_t *result = wcspbrk(s, L"l"); + if (wcscmp(result, s + 2) != 0) { + t_error("%s wcspbrk get result is %lc are not %lc\n", __func__, result, s + 2); + } +} + +/** + * @tc.name : wcspbrk_0400 + * @tc.desc : Test the result of wcspbrk when the target character is punctuation + * @tc.level : Level 1 + */ +void wcspbrk_0400(void) +{ + const wchar_t *s = L"hello, world!"; + wchar_t *result = wcspbrk(s, L",. !"); + if (wcscmp(result, s + 5) != 0) { + t_error("%s wcspbrk get result is %lc are not %lc\n", __func__, result, s + 5); + } +} + +int main(int argc, char *argv[]) +{ + wcspbrk_0100(); + wcspbrk_0200(); + wcspbrk_0300(); + wcspbrk_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcsrchr.c b/libc-test/src/functionalext/supplement/string/wcsrchr.c new file mode 100644 index 00000000..be0f1b76 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcsrchr.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcsrchr_0100 + * @tc.desc : Test wcsrchr to get the position of the last occurrence of the target wide character in the wide + * string + * @tc.level : Level 0 + */ +void wcsrchr_0100(void) +{ + wchar_t *ch = L"hello, world"; + wchar_t *result = wcsrchr(ch, L'h'); + if (wcscmp(result, ch) != 0) { + t_error("%s wcsrchr get result is %s are not want 'hello, world'\n", __func__, result); + } +} + +/** + * @tc.name : wcsrchr_0200 + * @tc.desc : wcsrchr returns result when testing multiple occurrences of target character in wide string + * @tc.level : Level 1 + */ +void wcsrchr_0200(void) +{ + wchar_t *ch = L"hello, world"; + wchar_t *result = wcsrchr(ch, L'l'); + if (wcscmp(result, ch + 10) != 0) { + t_error("%s wcsrchr get result is %s are not want 'ld'\n", __func__, result); + } +} + +/** + * @tc.name : wcsrchr_0300 + * @tc.desc : The test wide string does not contain the target wide character is the wcsrchr result + * @tc.level : Level 1 + */ +void wcsrchr_0300(void) +{ + wchar_t *ch = L"hello, world"; + wchar_t *result = wcsrchr(ch, L'a'); + if (result) { + t_error("%s wcsrchr get result is %s are not want ''\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + wcsrchr_0100(); + wcsrchr_0200(); + wcsrchr_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcsspn.c b/libc-test/src/functionalext/supplement/string/wcsspn.c new file mode 100644 index 00000000..2cfb0db6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcsspn.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcsspn_0100 + * @tc.desc : Test the wcsspn function to get the length of the largest initial segment of the wide string pointed + * @tc.level : Level 0 + */ +void wcsspn_0100(void) +{ + size_t result = wcsspn(L"hello world", L"abcdefghijklmnopqrstuvwxyz"); + size_t want = 5U; + if (result != want) { + t_error("%s wcsspn get result is %d are not want 5U\n", __func__, result); + } +} + +/** + * @tc.name : wcsspn_0200 + * @tc.desc : Test the wcsspn result when the search string contains spaces + * @tc.level : Level 1 + */ +void wcsspn_0200(void) +{ + size_t result = wcsspn(L"hello world", L"abcdefghijklmnopqrstuvwxyz "); + size_t want = 11U; + if (result != want) { + t_error("%s wcsspn get result is %d are not want 11U\n", __func__, result); + } +} + +/** + * @tc.name : wcsspn_0300 + * @tc.desc : The result of the wcsspn function when no target exists for the retrieved string + * @tc.level : Level 1 + */ +void wcsspn_0300(void) +{ + size_t result = wcsspn(L"hello world", L"!"); + if (result != 0U) { + t_error("%s wcsspn get result is %d are not want 0U\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + wcsspn_0100(); + wcsspn_0200(); + wcsspn_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcstok.c b/libc-test/src/functionalext/supplement/string/wcstok.c new file mode 100644 index 00000000..cb75905a --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcstok.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcstok_0100 + * @tc.desc : Test wcstok to intercept the target string according to the incoming wide string + * @tc.level : Level 0 + */ +void wcstok_0100(void) +{ + wchar_t str[] = L"parrot,owl,sparrow,pigeon,crow"; + wchar_t delim[] = L","; + wchar_t *ptr; + wchar_t *compare[5] = {L"parrot", L"owl", L"sparrow", L"pigeon", L"crow"}; + wchar_t *result[5] = {0}; + wchar_t *token = wcstok(str, delim, &ptr); + int i = 0; + while (token) { + result[i] = token; + i++; + token = wcstok(NULL, delim, &ptr); + } + for (i = 0; i < 5; i++) { + if (wcscmp(result[i], compare[i]) != 0) { + t_error("%s wcstok in %d get value is %s and %s\n", __func__, i, result[i], compare[i]); + } + } +} + +/** + * @tc.name : wcstok_0200 + * @tc.desc : Test wcstok to intercept multiple targets according to incoming + * @tc.level : Level 1 + */ +void wcstok_0200(void) +{ + wchar_t str[] = L"parrot,owl.sparrow,pigeon,crow"; + wchar_t delim[] = L",."; + wchar_t *ptr; + wchar_t *result = wcstok(str, delim, &ptr); + if (wcscmp(result, L"parrot") != 0) { + t_error("%s wcstok get result is %s are not parrot\n", __func__, result); + } + if (wcscmp(ptr, L"owl.sparrow,pigeon,crow") != 0) { + t_error("%s wcstok get ptr is %s are not parrot\n", __func__, ptr); + } +} + +int main(int argc, char *argv[]) +{ + setlocale(LC_ALL, "en_US.utf8"); + wcstok_0100(); + wcstok_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wcswcs.c b/libc-test/src/functionalext/supplement/string/wcswcs.c new file mode 100644 index 00000000..80b2d76a --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wcswcs.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +#define N(s, sub) \ + { \ + wchar_t *p = s; \ + wchar_t *q = wcswcs(p, sub); \ + if (q) \ + t_error("wcswcs(%s,%s) returned str+%d, wanted 0\n", #s, #sub, q - p); \ + } + +#define T(s, sub, n) \ + { \ + wchar_t *p = s; \ + wchar_t *q = wcswcs(p, sub); \ + if (q == 0) \ + t_error("wcswcs(%s,%s) returned 0, wanted str+%d\n", #s, #sub, n); \ + else if (q - p != n) \ + t_error("wcswcs(%s,%s) returned str+%d, wanted str+%d\n", #s, #sub, q - p, n); \ + } + +/** + * @tc.name : wcswcs_0100 + * @tc.desc : Test the wcswcs method to find the first occurrence of the second wide string from the first wide + * string + * @tc.level : Level 0 + */ +void wcswcs_0100(void) +{ + T(L"", L"", 0) + T(L"abcd", L"", 0) + T(L"abcd", L"a", 0) + T(L"abcd", L"b", 1) + T(L"abcd", L"c", 2) + T(L"abcd", L"d", 3) + T(L"abcd", L"ab", 0) + T(L"abcd", L"bc", 1) + T(L"abcd", L"cd", 2) + T(L"ababa", L"baba", 1) + T(L"ababab", L"babab", 1) + T(L"abababa", L"bababa", 1) + T(L"abababab", L"bababab", 1) + T(L"ababababa", L"babababa", 1) + T(L"abbababab", L"bababa", 2) + T(L"abbababab", L"ababab", 3) + T(L"abacabcabcab", L"abcabcab", 4) + T(L"nanabanabanana", L"aba", 3) + T(L"nanabanabanana", L"ban", 4) + T(L"nanabanabanana", L"anab", 1) + T(L"nanabanabanana", L"banana", 8) + T(L"_ _\xff_ _", L"_\xff_", 2) +} + +/** + * @tc.name : wcswcs_0200 + * @tc.desc : Test the result of the wcswcs method when the second substring cannot be found from the first + * substring + * @tc.level : Level 1 + */ +void wcswcs_0200(void) +{ + N(L"", L"a") + N(L"a", L"aa") + N(L"a", L"b") + N(L"aa", L"ab") + N(L"aa", L"aaa") + N(L"abba", L"aba") + N(L"abc abc", L"abcd") + N(L"0-1-2-3-4-5-6-7-8-9", L"-3-4-56-7-8-") + N(L"0-1-2-3-4-5-6-7-8-9", L"-3-4-5+6-7-8-") + N(L"_ _ _\xff_ _ _", L"_\x7f_") + N(L"_ _ _\x7f_ _ _", L"_\xff_") +} + +int main(int argc, char *argv[]) +{ + wcswcs_0100(); + wcswcs_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wmemchr.c b/libc-test/src/functionalext/supplement/string/wmemchr.c new file mode 100644 index 00000000..7f3f7df5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wmemchr.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wmemchr_0100 + * @tc.desc : Find the first occurrence of a wide character in the target array + * @tc.level : Level 0 + */ +void wmemchr_0100(void) +{ + wchar_t str[] = L"ABCDEFG"; + wchar_t target = L'C'; + size_t sz = sizeof(str) / sizeof(*str); + wchar_t *result = wmemchr(str, target, sz); + if (!result) { + t_error("%s not found target ch\n", __func__); + } +} + +/** + * @tc.name : wmemchr_0200 + * @tc.desc : Test the return value of the function when there are no wide characters in the destination array + * @tc.level : Level 1 + */ +void wmemchr_0200(void) +{ + wchar_t str[] = L"ABCDEFG"; + wchar_t target = L'H'; + size_t sz = sizeof(str) / sizeof(*str); + wchar_t *result = wmemchr(str, target, sz); + if (result) { + t_error("%s found target ch\n", __func__); + } +} + +/** + * @tc.name : wmemchr_0300 + * @tc.desc : Test the return value of the function when n=0 + * @tc.level : Level 1 + */ +void wmemchr_0300(void) +{ + wchar_t str[] = L"ABCDEFG"; + wchar_t target = L'C'; + size_t sz = 0; + wchar_t *result = wmemchr(str, target, sz); + if (result) { + t_error("%s found target ch", __func__); + } +} + +int main(int argc, char *argv[]) +{ + wmemchr_0100(); + wmemchr_0200(); + wmemchr_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wmemcmp.c b/libc-test/src/functionalext/supplement/string/wmemcmp.c new file mode 100644 index 00000000..f1679520 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wmemcmp.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wmemcmp_0100 + * @tc.desc : Test the return value of wmemcmp when two strings are equal + * @tc.level : Level 0 + */ +void wmemcmp_0100(void) +{ + wchar_t l[] = L"ABCD"; + wchar_t r[] = L"ABCD"; + int result = wmemcmp(l, r, sizeof(l) / sizeof(*l)); + if (result != 0) { + t_error("%s two strings are not equal\n", __func__); + } +} + +/** + * @tc.name : wmemcmp_0200 + * @tc.desc : l precedes r in lexicographical order + * @tc.level : Level 1 + */ +void wmemcmp_0200(void) +{ + wchar_t l[] = L"ABCD"; + wchar_t r[] = L"ABCE"; + int result = wmemcmp(l, r, sizeof(l) / sizeof(*l)); + if (result >= 0) { + t_error("%s l is not precedes to r\n", __func__); + } +} + +/** + * @tc.name : wmemcmp_0300 + * @tc.desc : r precedes l in lexicographical order + * @tc.level : Level 1 + */ +void wmemcmp_0300(void) +{ + wchar_t l[] = L"ABCD"; + wchar_t r[] = L"ABCC"; + int result = wmemcmp(l, r, sizeof(l) / sizeof(*l)); + if (result <= 0) { + t_error("%s l is not follows to r\n", __func__); + } +} + +/** + * @tc.name : wmemcmp_0400 + * @tc.desc : Test the return value of the function when n=0 + * @tc.level : Level 1 + */ +void wmemcmp_0400(void) +{ + wchar_t l[] = L"ABCD"; + wchar_t r[] = L"ABCC"; + int n = 0; + int result = wmemcmp(l, r, n); + if (result != 0) { + t_error("%s result is not want 0\n", __func__); + } +} + +int main(int argc, char *argv[]) +{ + wmemcmp_0100(); + wmemcmp_0200(); + wmemcmp_0300(); + wmemcmp_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wmemcpy.c b/libc-test/src/functionalext/supplement/string/wmemcpy.c new file mode 100644 index 00000000..4d61a5e2 --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wmemcpy.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wmemcpy_0100 + * @tc.desc : Copies specified number of characters from one string to another + * @tc.level : Level 0 + */ +void wmemcpy_0100(void) +{ + wchar_t dest[30]; + wchar_t src[] = L"This is a c test for wmemcpy"; + int n = 13; + wmemcpy(dest, src, n); + if (wcsncmp(dest, src, n)) { + t_error("%s The string of dest is not equal to src\n", __func__); + } +} + +/** + * @tc.name : wmemcpy_0200 + * @tc.desc : Test wmemcpy when 'n' is equal to the number characters in src string + * @tc.level : Level 0 + */ +void wmemcpy_0200(void) +{ + wchar_t dest[3]; + wchar_t src[] = L"aaa"; + int n = 3; + wmemcpy(dest, src, n); + if (wcsncmp(dest, src, n)) { + t_error("%s The string of dest is not equal to src\n", __func__); + } +} + +/** + * @tc.name : wmemcpy_0300 + * @tc.desc : Test wmemcpy when 'n' is equal to 0 + * @tc.level : Level 0 + */ +void wmemcpy_0300(void) +{ + wchar_t dest[3]; + wchar_t src[] = L"aaa"; + int n = 0; + wmemcpy(dest, src, n); + if (!wcscmp(dest, src)) { + t_error("%s The string of dest is equal to src\n", __func__); + } +} + +int main(int argc, char *argv[]) +{ + wmemcpy_0100(); + wmemcpy_0200(); + wmemcpy_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wmemmove.c b/libc-test/src/functionalext/supplement/string/wmemmove.c new file mode 100644 index 00000000..cba1b4fe --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wmemmove.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wmemmove_0100 + * @tc.desc : Copies the specified number of wide characters from the source to the destination + * @tc.level : Level 0 + */ +void wmemmove_0100(void) +{ + wchar_t dest[] = L"This is a c test for wmemmove function"; + const wchar_t src[] = L"src content"; + int count = 5; + wchar_t tmp[count + 1]; + wcsncpy(tmp, src, count); + wmemmove(dest, src, count); + if (wcsncmp(dest, tmp, count)) { + t_error("The dest specified bits are not equal to the src\n", __func__); + } +} + +/** + * @tc.name : wmemmove_0200 + * @tc.desc : Dest and src overlaps + * @tc.level : Level 1 + */ +void wmemmove_0200(void) +{ + wchar_t src[] = L"This is a c test for wmemmove function"; + wchar_t *dest = &src[2]; + int count = 5; + wchar_t tmp[count + 1]; + wcsncpy(tmp, src, count); + wmemmove(dest, src, count); + if (wcsncmp(dest, tmp, count)) { + t_error("The dest specified bits are not equal to the src\n", __func__); + } +} + +/** + * @tc.name : wmemmove_0300 + * @tc.desc : The first address of dest is the same as src + * @tc.level : Level 1 + */ +void wmemmove_0300(void) +{ + wchar_t src[] = L"This is a c test for wmemmove function"; + wchar_t *dest = &src[0]; + int count = 5; + wchar_t *result = wmemmove(dest, src, count); + if (!(result == dest)) { + t_error("The first address of dest is not the same as src\n", __func__); + } +} + +int main(int argc, char *argv[]) +{ + wmemmove_0100(); + wmemmove_0200(); + wmemmove_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/string/wmemset.c b/libc-test/src/functionalext/supplement/string/wmemset.c new file mode 100644 index 00000000..ab89511b --- /dev/null +++ b/libc-test/src/functionalext/supplement/string/wmemset.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wmemset_0100 + * @tc.desc : Copies the specified number of wide characters from the source to the destination + * @tc.level : Level 0 + */ +void wmemset_0100(void) +{ + const int index = 20; + int count = 10; + wchar_t ch = L'C'; + wchar_t des[index]; + wmemset(des, ch, count); + for (int i = 0; i < count; i++) { + if (des[i] != ch) { + t_error("%s des[%d] is not C\n", __func__, i); + } + } +} + +/** + * @tc.name : wmemset_0200 + * @tc.desc : Test wmemset when count is 0 + * @tc.level : Level 1 + */ +void wmemset_0200(void) +{ + const int index = 10; + int count = 0; + wchar_t ch = L'C'; + wchar_t des[index]; + wmemset(des, ch, count); + for (int i = 0; i < index; i++) { + if (des[i] == ch) { + t_error("%s des[%d] is not want C\n", __func__, i); + } + } +} + +/** + * @tc.name : wmemset_0300 + * @tc.desc : Test wmemset when count is equal to the number characters in dest string + * @tc.level : Level 1 + */ +void wmemset_0300(void) +{ + const int index = 10; + int count = 10; + wchar_t ch = L'C'; + wchar_t des[index]; + wmemset(des, ch, count); + for (int i = 0; i < index; i++) { + if (des[i] != ch) { + t_error("%s des[%d] is not want C\n", __func__, i); + } + } +} + +int main(int argc, char *argv[]) +{ + wmemset_0100(); + wmemset_0200(); + wmemset_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/temp/BUILD.gn b/libc-test/src/functionalext/supplement/temp/BUILD.gn new file mode 100644 index 00000000..caf92134 --- /dev/null +++ b/libc-test/src/functionalext/supplement/temp/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_temp.gni") + +foreach(s, functionalext_supplement_temp_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/temp" + } +} + +group("functionalext_supplement_temp_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_temp_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/temp/mkdtemp.c b/libc-test/src/functionalext/supplement/temp/mkdtemp.c new file mode 100755 index 00000000..e8f08aad --- /dev/null +++ b/libc-test/src/functionalext/supplement/temp/mkdtemp.c @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : mkdtemp_0100 + * @tc.desc : Create a temporary directory with the correct parameters + * @tc.level : Level 0 + */ +void mkdtemp_0100(void) +{ + char temp_dir[] = "test-XXXXXX"; + char *ret = mkdtemp(temp_dir); + EXPECT_PTRNE("mkdtemp_0100", ret, NULL); + if (ret) { + EXPECT_NE("mkdtemp_0100", ret[0], CMPFLAG); + } +} + +/** + * @tc.name : mkdtemp_0200 + * @tc.desc : Create temp directory with wrong template parameter + * @tc.level : Level 2 + */ +void mkdtemp_0200(void) +{ + char temp_dir[] = "test"; + char *ret = mkdtemp(temp_dir); + EXPECT_PTREQ("mkdtemp_0200", ret, NULL); +} + +/** + * @tc.name : mkdtemp_0300 + * @tc.desc : Create temp directory with wrong template argument (wrong template length) + * @tc.level : Level 2 + */ +void mkdtemp_0300(void) +{ + char temp_dir[] = "test-XX"; + char *ret = mkdtemp(temp_dir); + EXPECT_PTREQ("mkdtemp_0300", ret, NULL); +} + +int main(void) +{ + mkdtemp_0100(); + mkdtemp_0200(); + mkdtemp_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/temp/mkostemp.c b/libc-test/src/functionalext/supplement/temp/mkostemp.c new file mode 100644 index 00000000..38d521d8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/temp/mkostemp.c @@ -0,0 +1,167 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : mkostemp_0100 + * @tc.desc : Verify mkostemp process success. Provide the correct template and no fixed suffix, + * specified in flags: O_APPEND, create a temporary file. + * @tc.level : Level 0 + */ +void mkostemp_0100(void) +{ + char tmpfile[] = "/data/mkostemp_0100_XXXXXX"; + int fd = mkostemp(tmpfile, O_APPEND); + EXPECT_TRUE("mkostemp_0100", fd != -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("mkostemp_0100", cnt == strlen(tmpfile)); + close(fd); + char rmfile[128]; + int len = sprintf(rmfile, "rm %s", tmpfile); + if (len > 0) { + system(rmfile); + } + } +} + +/** + * @tc.name : mkostemp_0200 + * @tc.desc : Verify mkostemp process success. Provide the correct template and no fixed suffix, + * specified in flags: O_CLOEXEC, create a temporary file. + * @tc.level : Level 0 + */ +void mkostemp_0200(void) +{ + char tmpfile[] = "/data/mkostemp_0200_XXXXXX"; + int fd = mkostemp(tmpfile, O_CLOEXEC); + EXPECT_TRUE("mkostemp_0200", fd != -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("mkostemp_0200", cnt == strlen(tmpfile)); + close(fd); + char rmfile[128]; + int len = sprintf(rmfile, "rm %s", tmpfile); + if (len > 0) { + system(rmfile); + } + } +} + +/** + * @tc.name : mkostemp_0300 + * @tc.desc : Verify mkostemp process success. Provide the correct template and no fixed suffix, + * specified in flags: O_CLOEXEC, create a temporary file. + * @tc.level : Level 0 + */ +void mkostemp_0300(void) +{ + char tmpfile[] = "/data/mkostemp_0300_XXXXXX"; + int fd = mkostemp(tmpfile, O_SYNC); + EXPECT_TRUE("mkostemp_0300", fd != -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("mkostemp_0300", cnt == strlen(tmpfile)); + close(fd); + char rmfile[128]; + int len = sprintf(rmfile, "rm %s", tmpfile); + if (len > 0) { + system(rmfile); + } + } +} + +/** + * @tc.name : mkostemp_0400 + * @tc.desc : Verify mkostemp process fail. Provide error template, specified in flags: O_APPEND, + * create temp file fail. + * @tc.level : Level 2 + */ +void mkostemp_0400(void) +{ + char tmpfile[] = "/tmp/mkostemp_0400.dat"; + int fd = mkostemp(tmpfile, O_APPEND); + EXPECT_TRUE("mkostemp_0400", fd == -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("mkostemp_0400", cnt == strlen(tmpfile)); + close(fd); + char rmfile[128]; + int len = sprintf(rmfile, "rm %s", tmpfile); + if (len > 0) { + system(rmfile); + } + } +} + +/** + * @tc.name : mkostemp_0500 + * @tc.desc : Verify mkostemp process fail. Provide error template, specified in flags: O_CLOEXEC, + * create temp file fail. + * @tc.level : Level 2 + */ +void mkostemp_0500(void) +{ + char tmpfile[] = "/tmp/mkostemp_0500.dat"; + int fd = mkostemp(tmpfile, O_CLOEXEC); + EXPECT_TRUE("mkostemp_0500", fd == -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("mkostemp_0500", cnt == strlen(tmpfile)); + close(fd); + char rmfile[128]; + int len = sprintf(rmfile, "rm %s", tmpfile); + if (len > 0) { + system(rmfile); + } + } +} + +/** + * @tc.name : mkostemp_0600 + * @tc.desc : Verify mkostemp process fail. Provide error template, specified in flags: O_SYNC, + * create temp file fail. + * @tc.level : Level 2 + */ +void mkostemp_0600(void) +{ + char tmpfile[] = "/tmp/mkostemp_0600.dat"; + int fd = mkostemp(tmpfile, O_SYNC); + EXPECT_TRUE("mkostemp_0600", fd == -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("mkostemp_0600", cnt == strlen(tmpfile)); + close(fd); + char rmfile[128]; + int len = sprintf(rmfile, "rm %s", tmpfile); + if (len > 0) { + system(rmfile); + } + } +} + +int main(void) +{ + mkostemp_0100(); + mkostemp_0200(); + mkostemp_0300(); + mkostemp_0400(); + mkostemp_0500(); + mkostemp_0600(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/temp/mkostemps.c b/libc-test/src/functionalext/supplement/temp/mkostemps.c new file mode 100644 index 00000000..b3d69956 --- /dev/null +++ b/libc-test/src/functionalext/supplement/temp/mkostemps.c @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : mkostemps_0100 + * @tc.desc : Verify mkostemps process success. Provide the correct template and fixed suffix, + * create a temporary file. + * @tc.level : Level 0 + */ +void mkostemps_0100(void) +{ + char tmpfile[] = "/tmp/mkostemps_0100_XXXXXX.dat"; + int fd = mkostemps(tmpfile, strlen(".dat"), O_CREAT); + EXPECT_TRUE("mkostemps_0100", fd != -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("mkostemps_0100", cnt == strlen(tmpfile)); + close(fd); + char rmfile[128]; + int len = sprintf(rmfile, "rm %s", tmpfile); + if (len > 0) { + system(rmfile); + } + } +} + +/** + * @tc.name : mkostemps_0200 + * @tc.desc : Verify mkostemps process success. Provide the correct template and no fixed suffix, + * create a temporary file. + * @tc.level : Level 0 + */ +void mkostemps_0200(void) +{ + char tmpfile[] = "/tmp/mkostemps_0200_XXXXXX"; + int fd = mkostemps(tmpfile, 0, O_CREAT); + EXPECT_TRUE("mkostemps_0200", fd != -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("mkostemps_0200", cnt == strlen(tmpfile)); + close(fd); + char rmfile[128]; + int len = sprintf(rmfile, "rm %s", tmpfile); + if (len > 0) { + system(rmfile); + } + } +} + +/** + * @tc.name : mkostemps_0300 + * @tc.desc : Verify mkstemp process fail. Because provide error template. + * @tc.level : Level 2 + */ +void mkostemps_0300(void) +{ + char tmpfile[] = "/tmp/mkostemps_0300.dat"; + int fd = mkostemps(tmpfile, strlen(".dat"), O_CREAT); + EXPECT_TRUE("mkostemps_0300", fd == -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("mkostemps_0300", cnt == strlen(tmpfile)); + close(fd); + char rmfile[128]; + int len = sprintf(rmfile, "rm %s", tmpfile); + if (len > 0) { + system(rmfile); + } + } +} + +int main(void) +{ + mkostemps_0100(); + mkostemps_0200(); + mkostemps_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/temp/mkstemp.c b/libc-test/src/functionalext/supplement/temp/mkstemp.c new file mode 100644 index 00000000..31926e01 --- /dev/null +++ b/libc-test/src/functionalext/supplement/temp/mkstemp.c @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : mkstemp_0100 + * @tc.desc : Verify mkstemp process success. Provide the correct template and no fixed suffix, create a + * temporary file + * @tc.level : Level 0 + */ +void mkstemp_0100(void) +{ + char tmpfile[] = "/data/mkstemp_0100_XXXXXX"; + int fd = mkstemp(tmpfile); + EXPECT_TRUE("mkstemp_0100", fd != -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("mkstemp_0100", cnt == strlen(tmpfile)); + close(fd); + char rmfile[128]; + int len = sprintf(rmfile, "rm %s", tmpfile); + if (len > 0) { + system(rmfile); + } + } +} + +/** + * @tc.name : mkstemp_0200 + * @tc.desc : Verify mkstemp process fail. Provide error template, create temp file fail + * @tc.level : Level 2 + */ +void mkstemp_0200(void) +{ + char tmpfile[] = "/data/mkstemp_0200.dat"; + int fd = mkstemp(tmpfile); + EXPECT_TRUE("mkstemp_0200", fd == -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("mkstemp_0200", cnt == strlen(tmpfile)); + close(fd); + char rmfile[128]; + int len = sprintf(rmfile, "rm %s", tmpfile); + if (len > 0) { + system(rmfile); + } + } +} + +int main(void) +{ + mkstemp_0100(); + mkstemp_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/temp/mkstemps.c b/libc-test/src/functionalext/supplement/temp/mkstemps.c new file mode 100644 index 00000000..2fa2ee4e --- /dev/null +++ b/libc-test/src/functionalext/supplement/temp/mkstemps.c @@ -0,0 +1,91 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : mkstemps_0100 + * @tc.desc : Provide the correct template, create a temporary file + * @tc.level : Level 0 + */ +void mkstemps_0100(void) +{ + char tmpfile[] = "/tmp/mkstemps_0100_XXXXXX.dat"; + int fd = mkstemps(tmpfile, strlen(".dat")); + EXPECT_TRUE("mkstemps_0100", fd != -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("mkstemps_0100", cnt == strlen(tmpfile)); + close(fd); + char rmfile[128]; + int len = sprintf(rmfile, "rm %s", tmpfile); + if (len > 0) { + system(rmfile); + } + } +} + +/** + * @tc.name : mkstemps_0200 + * @tc.desc : Provide the correct template and no fixed suffix, create a temporary file + * @tc.level : Level 0 + */ +void mkstemps_0200(void) +{ + char tmpfile[] = "/tmp/mkstemps_0200_XXXXXX"; + int fd = mkstemps(tmpfile, 0); + EXPECT_TRUE("mkstemps_0200", fd != -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("mkstemps_0200", cnt == strlen(tmpfile)); + close(fd); + char rmfile[128]; + int len = sprintf(rmfile, "rm %s", tmpfile); + if (len > 0) { + system(rmfile); + } + } +} + +/** + * @tc.name : mkstemps_0300 + * @tc.desc : Provide error template, create temp file + * @tc.level : Level 2 + */ +void mkstemps_0300(void) +{ + char tmpfile[] = "/tmp/mkstemps_0300.dat"; + int fd = mkstemps(tmpfile, strlen(".dat")); + EXPECT_TRUE("mkstemps_0300", fd == -1); + if (fd != -1) { + int cnt = write(fd, tmpfile, strlen(tmpfile)); + EXPECT_TRUE("mkstemps_0300", cnt == strlen(tmpfile)); + close(fd); + char rmfile[128]; + int len = sprintf(rmfile, "rm %s", tmpfile); + if (len > 0) { + system(rmfile); + } + } +} + +int main(void) +{ + mkstemps_0100(); + mkstemps_0200(); + mkstemps_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/temp/mktemp.c b/libc-test/src/functionalext/supplement/temp/mktemp.c new file mode 100755 index 00000000..e7c913ed --- /dev/null +++ b/libc-test/src/functionalext/supplement/temp/mktemp.c @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : mktemp_0100 + * @tc.desc : Create a temporary file with the correct parameters + * @tc.level : Level 0 + */ +void mktemp_0100(void) +{ + char temp_file[] = "test-XXXXXX"; + char *ret = mktemp(temp_file); + EXPECT_PTRNE("mktemp_0100", ret, NULL); + if (ret) { + EXPECT_NE("mktemp_0100", ret[0], 0); + } +} + +/** + * @tc.name : mktemp_0200 + * @tc.desc : Create temp file with wrong template parameter + * @tc.level : Level 2 + */ +void mktemp_0200(void) +{ + char temp_file[] = "test"; + char *ret = mktemp(temp_file); + EXPECT_PTRNE("mktemp_0200", ret, NULL); + if (ret) { + EXPECT_EQ("mktemp_0200", ret[0], 0); + } +} + +/** + * @tc.name : mktemp_0300 + * @tc.desc : Create temp file with wrong template argument (wrong template length) + * @tc.level : Level 2 + */ +void mktemp_0300(void) +{ + char temp_file[] = "test-XX"; + char *ret = mktemp(temp_file); + EXPECT_PTRNE("mktemp_0300", ret, NULL); + if (ret) { + EXPECT_EQ("mktemp_0300", ret[0], 0); + } +} + +int main(void) +{ + mktemp_0100(); + mktemp_0200(); + mktemp_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/temp/test_src_functionalext_supplement_temp.gni b/libc-test/src/functionalext/supplement/temp/test_src_functionalext_supplement_temp.gni new file mode 100644 index 00000000..3131040b --- /dev/null +++ b/libc-test/src/functionalext/supplement/temp/test_src_functionalext_supplement_temp.gni @@ -0,0 +1,21 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_temp_test = [ + "mkostemp", + "mkostemps", + "mkstemp", + "mkstemps", + "mkdtemp", + "mktemp", +] diff --git a/libc-test/src/functionalext/supplement/termios/BUILD.gn b/libc-test/src/functionalext/supplement/termios/BUILD.gn new file mode 100644 index 00000000..76c804bc --- /dev/null +++ b/libc-test/src/functionalext/supplement/termios/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_termios.gni") + +foreach(s, functionalext_supplement_termios_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/termios" + } +} + +group("functionalext_supplement_termios_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_termios_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/termios/cfgetispeed.c b/libc-test/src/functionalext/supplement/termios/cfgetispeed.c new file mode 100644 index 00000000..d3894d1b --- /dev/null +++ b/libc-test/src/functionalext/supplement/termios/cfgetispeed.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : cfgetispeed_0100 + * @tc.desc : Verify that information about the input baud rate is obtained. + * @tc.level : Level 0 + */ +void cfgetispeed_0100(void) +{ + struct termios termptr; + tcgetattr(STDIN_FILENO, &termptr); + speed_t result = cfgetispeed(&termptr); + EXPECT_TRUE("cfgetispeed_0100", result >= 0); +} + +int main() +{ + cfgetispeed_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/termios/cfgetospeed.c b/libc-test/src/functionalext/supplement/termios/cfgetospeed.c new file mode 100644 index 00000000..dc991569 --- /dev/null +++ b/libc-test/src/functionalext/supplement/termios/cfgetospeed.c @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : cfgetispeed_0100 + * @tc.desc : Verify that information about the output baud rate is obtained. + * @tc.level : Level 0 + */ +void cfgetispeed_0100(void) +{ + struct termios termios_p; + tcgetattr(STDIN_FILENO, &termios_p); + speed_t result = cfgetospeed(&termios_p); + EXPECT_TRUE("cfgetispeed_0100", result >= 0); +} + +int main() +{ + cfgetispeed_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/termios/cfmakeraw.c b/libc-test/src/functionalext/supplement/termios/cfmakeraw.c new file mode 100644 index 00000000..3c326645 --- /dev/null +++ b/libc-test/src/functionalext/supplement/termios/cfmakeraw.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : cfmakeraw_0100 + * @tc.desc : Verify that the terminal is set to raw mode. + * @tc.level : Level 0 + */ +void cfmakeraw_0100(void) +{ + static struct termios tin; + static struct termios tlocal; + memcpy(&tlocal, &tin, sizeof(tin)); + cfmakeraw(&tlocal); + tcsetattr(STDIN_FILENO, TCSANOW, &tlocal); + tcgetattr(STDIN_FILENO, &tin); + EXPECT_TRUE("cfmakeraw_0100", tin.c_cflag >= 0); + EXPECT_EQ("cfmakeraw_0100", tin.c_iflag, 0); + EXPECT_EQ("cfmakeraw_0100", tin.c_oflag, 0); + EXPECT_EQ("cfmakeraw_0100", tin.c_cc[VTIME], 0); + EXPECT_EQ("cfmakeraw_0100", tin.c_iflag, 0); +} + +int main() +{ + cfmakeraw_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/termios/cfsetispeed.c b/libc-test/src/functionalext/supplement/termios/cfsetispeed.c new file mode 100644 index 00000000..91b4f080 --- /dev/null +++ b/libc-test/src/functionalext/supplement/termios/cfsetispeed.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; +const int32_t COUNT_NEGATIVE = -1; + +/** + * @tc.name : cfgetispeed_0100 + * @tc.desc : Verify information that can set the input baud rate (parameter valid). + * @tc.level : Level 0 + */ +void cfgetispeed_0100(void) +{ + struct termios termios_p; + tcgetattr(STDIN_FILENO, &termios_p); + speed_t speed = B50; + int result = cfsetispeed(&termios_p, speed); + EXPECT_EQ("cfgetispeed_0100", result, COUNT_ZERO); +} + +/** + * @tc.name : cfgetispeed_0200 + * @tc.desc : Verify that the input baud rate cannot be set (the speed parameter is invalid). + * @tc.level : Level 2 + */ +void cfgetispeed_0200(void) +{ + struct termios termios_p; + tcgetattr(STDIN_FILENO, &termios_p); + speed_t speed = -2; + int result = cfsetispeed(&termios_p, speed); + EXPECT_EQ("cfgetispeed_0200", result, COUNT_NEGATIVE); +} + +int main() +{ + cfgetispeed_0100(); + cfgetispeed_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/termios/cfsetospeed.c b/libc-test/src/functionalext/supplement/termios/cfsetospeed.c new file mode 100755 index 00000000..4ba1096e --- /dev/null +++ b/libc-test/src/functionalext/supplement/termios/cfsetospeed.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int32_t COUNT_ZERO = 0; +const int32_t COUNT_NEGATIVE = -1; + +/** + * @tc.name : cfsetospeed_0100 + * @tc.desc : Verify information that can set output baud rate (parameter valid). + * @tc.level : Level 0 + */ +void cfsetospeed_0100(void) +{ + int result; + struct termios buff; + tcgetattr(STDIN_FILENO, &buff); + result = cfsetospeed(&buff, B0); + EXPECT_EQ("cfsetospeed_0100", result, COUNT_ZERO); +} + +/** + * @tc.name : cfsetospeed_0200 + * @tc.desc : Verify that the output baud rate cannot be set (the speed parameter is invalid). + * @tc.level : Level 2 + */ +void cfsetospeed_0200(void) +{ + int result; + struct termios buff; + tcgetattr(STDIN_FILENO, &buff); + result = cfsetospeed(&buff, -10); + EXPECT_EQ("cfsetospeed_0200", result, COUNT_NEGATIVE); +} + +int main() +{ + cfsetospeed_0100(); + cfsetospeed_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/termios/tcdrain.c b/libc-test/src/functionalext/supplement/termios/tcdrain.c new file mode 100644 index 00000000..edc1cba6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/termios/tcdrain.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : tcdrain_0100 + * @tc.desc : Wait until output has been transmitted + * @tc.level : Level 0 + */ +void tcdrain_0100(void) +{ + char Master[] = "/dev/pts/ptmx"; + char text[] = "text to be written to tty"; + char data[80]; + int fd_master, fd_slave, result; + time_t T; + + fd_master = open(Master, O_RDWR | O_NONBLOCK); + if (fd_master < 0) { + t_error("%s open master failed", __func__); + } + + result = grantpt(fd_master); + if (result < 0) { + t_error("%s grantpt failed", __func__); + return; + } + + result = unlockpt(fd_master); + if (result < 0) { + t_error("%s unlockpt failed", __func__); + return; + } + + char *Slave = ptsname(fd_master); + fd_slave = open(Slave, O_RDWR | O_NONBLOCK); + if (fd_slave < 0) { + t_error("%s open slave failed", __func__); + } + + if (fork() == 0) { + if (write(fd_slave, text, strlen(text) + 1) == -1) { + t_error("%s write failed", __func__); + } + time(&T); + printf("child has written to tty, tcdrain() started at %s", ctime(&T)); + + if (tcdrain(fd_slave) != 0) { + t_error("%s tcdrain failed", __func__); + } + + time(&T); + printf("tcdrain() returned at %s", ctime(&T)); + exit(0); + } + + time(&T); + printf("parent is starting nap at %s", ctime(&T)); + sleep(2); + time(&T); + printf("parent is done with nap at %s", ctime(&T)); + if (read(fd_master, data, sizeof(data)) == -1) { + t_error("%s read failed", __func__); + } else { + printf("read '%s' from the tty\n", data); + } + sleep(2); + close(fd_slave); + close(fd_master); +} + +int main(int argc, char *argv[]) +{ + tcdrain_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/termios/tcflow.c b/libc-test/src/functionalext/supplement/termios/tcflow.c new file mode 100644 index 00000000..b57038df --- /dev/null +++ b/libc-test/src/functionalext/supplement/termios/tcflow.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" + +const char *text = "Hello"; + +/** + * @tc.name : tcflow_0100 + * @tc.desc : Resume blocked terminal and read data + * @tc.level : Level 0 + */ +void tcflow_0100(void) +{ + char data[BUFSIZ]; + int result; + + int fdm = open("/dev/pts/ptmx", O_RDWR | O_NOCTTY); + if (fdm < 0) { + t_error("%s open master failed", __func__); + return; + } + result = grantpt(fdm); + if (result < 0) { + t_error("%s grantpt failed", __func__); + return; + } + + result = unlockpt(fdm); + if (result < 0) { + t_error("%s unlockpt failed", __func__); + return; + } + + char *slave = ptsname(fdm); + int fds = open(slave, O_RDWR | O_NOCTTY); + if (fds < 0) { + t_error("%s open slave failed", __func__); + return; + } + + if (write(fds, text, strlen(text) + 1) == -1) { + t_error("%s write failed", __func__); + return; + } + + if (tcflow(fds, TCOON) != 0) { + t_error("%s tcflow failed", __func__); + } + + if (read(fdm, data, sizeof(data)) == -1) { + t_error("%s read resume failed", __func__); + } + if (strcmp(data, text)) { + t_error("%s read data is %s", __func__, data); + } + + close(fdm); + close(fds); +} + +/** + * @tc.name : tcflow_0200 + * @tc.desc : Fildes is not a valid open file descriptor + * @tc.level : Level 2 + */ +void tcflow_0200(void) +{ + int result = tcflow(-1, TCOON); + if (result != -1) { + t_error("%s result is %d", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + tcflow_0100(); + tcflow_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/termios/test_src_functionalext_supplement_termios.gni b/libc-test/src/functionalext/supplement/termios/test_src_functionalext_supplement_termios.gni new file mode 100644 index 00000000..c815bafa --- /dev/null +++ b/libc-test/src/functionalext/supplement/termios/test_src_functionalext_supplement_termios.gni @@ -0,0 +1,22 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_termios_test = [ + "cfgetispeed", + "cfgetospeed", + "cfmakeraw", + "cfsetispeed", + "cfsetospeed", + "tcdrain", + "tcflow", +] diff --git a/libc-test/src/functionalext/supplement/test_src_functionalext_supplement.gni b/libc-test/src/functionalext/supplement/test_src_functionalext_supplement.gni new file mode 100644 index 00000000..8a47f6e3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/test_src_functionalext_supplement.gni @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_list = [ + "conf:functionalext_supplement_conf_test", + "ctype:functionalext_supplement_ctype_test", + "env:functionalext_supplement_env_test", + "errno:functionalext_supplement_errno_test", + "exit:functionalext_supplement_exit_test", + "dirent:functionalext_supplement_dirent_test", + "fcntl:functionalext_supplement_fcntl_test", + "ipc:functionalext_supplement_ipc_test", + "ldso:functionalext_supplement_ldso_test", + "linux:functionalext_supplement_linux_test", + "locale:functionalext_supplement_locale_test", + "malloc:functionalext_supplement_malloc_test", + "math:functionalext_supplement_math_test", + "mbrlen:functionalext_supplement_mbrlen_test", + "misc:functionalext_supplement_misc_test", + "mman:functionalext_supplement_mman_test", + "multibyte:functionalext_supplement_multibyte_test", + "network:functionalext_supplement_network_test", + "passwd:functionalext_supplement_passwd_test", + "prng:functionalext_supplement_prng_test", + "legacy:functionalext_supplement_legacy_test", + "process:functionalext_supplement_process_test", + "regex:functionalext_supplement_regex_test", + "sched:functionalext_supplement_sched_test", + "signal:functionalext_supplement_signal_test", + "stat:functionalext_supplement_stat_test", + "stdio:functionalext_supplement_stdio_test", + "stdlib:functionalext_supplement_stdlib_test", + "string:functionalext_supplement_string_test", + "temp:functionalext_supplement_temp_test", + "thread:functionalext_supplement_thread_test", + "time:functionalext_supplement_time_test", + "unistd:functionalext_supplement_unistd_test", + "wctype:functionalext_supplement_wctype_test", + "termios:functionalext_supplement_termios_test", + "setjmp:functionalext_supplement_setjmp_test", + "fenv:functionalext_supplement_fenv_test", + "select:functionalext_supplement_select_test", + "search:functionalext_supplement_search_test", + "manual:functionalext_supplement_manual_test", +] diff --git a/libc-test/src/functionalext/supplement/thread/BUILD.gn b/libc-test/src/functionalext/supplement/thread/BUILD.gn new file mode 100644 index 00000000..179c3f9b --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/BUILD.gn @@ -0,0 +1,190 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("//build/test.gni") +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_thread.gni") + +default_include_dirs = + [ "//third_party/musl/libc-test/src/functionalext/common" ] + +default_configs = [ "//third_party/musl/libc-test/src/common:config_runtest" ] + +default_module_out_path = "libc-test/src/functionalext/supplement/thread" + +ohos_unittest("pthread_attr_getstack_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_attr_getstack.c" ] +} + +ohos_unittest("pthread_attr_setdetachstate_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_attr_setdetachstate.c" ] +} + +ohos_unittest("pthread_attr_setstacksize_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_attr_setstacksize.c" ] +} + +ohos_unittest("pthread_condattr_destroy_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_condattr_destroy.c" ] +} + +ohos_unittest("pthread_condattr_init_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_condattr_init.c" ] +} + +ohos_unittest("pthread_create_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_create.c" ] +} + +ohos_unittest("pthread_exit_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_exit.c" ] +} + +ohos_unittest("pthread_getattr_np_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_getattr_np.c" ] +} + +ohos_unittest("pthread_getschedparam_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_getschedparam.c" ] +} + +ohos_unittest("pthread_getspecific_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_getspecific.c" ] +} + +ohos_unittest("pthread_key_create_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_key_create.c" ] +} + +ohos_unittest("pthread_mutex_init_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_mutex_init.c" ] +} + +ohos_unittest("pthread_mutex_lock_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_mutex_lock.c" ] +} + +ohos_unittest("pthread_mutex_unlock_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_mutex_unlock.c" ] +} + +ohos_unittest("pthread_once_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_once.c" ] +} + +ohos_unittest("pthread_rwlock_destroy_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_rwlock_destroy.c" ] +} + +ohos_unittest("pthread_setschedparam_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_setschedparam.c" ] +} + +ohos_unittest("pthread_setspecific_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_setspecific.c" ] +} + +ohos_unittest("pthread_sigmask_test") { + module_out_path = default_module_out_path + include_dirs = default_include_dirs + configs = default_configs + sources = [ "pthread_sigmask.c" ] +} + +foreach(s, functionalext_supplement_thread_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/thread" + } +} + +group("functionalext_supplement_thread_test") { + testonly = true + deps = [ + ":pthread_attr_getstack_test", + ":pthread_attr_setdetachstate_test", + ":pthread_attr_setstacksize_test", + ":pthread_condattr_destroy_test", + ":pthread_condattr_init_test", + ":pthread_create_test", + ":pthread_exit_test", + ":pthread_getattr_np_test", + ":pthread_getschedparam_test", + ":pthread_getspecific_test", + ":pthread_key_create_test", + ":pthread_mutex_init_test", + ":pthread_mutex_lock_test", + ":pthread_mutex_unlock_test", + ":pthread_once_test", + ":pthread_rwlock_destroy_test", + ":pthread_setschedparam_test", + ":pthread_setspecific_test", + ":pthread_sigmask_test", + ] + foreach(s, functionalext_supplement_thread_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/thread/call_once.c b/libc-test/src/functionalext/supplement/thread/call_once.c new file mode 100644 index 00000000..f42f3be8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/call_once.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +static char list[100]; +static char buf[12] = "called once"; +void do_once(void) +{ + FILE *fp = fopen("call_once.txt", "a+"); + fwrite(buf, sizeof(char), strlen(buf), fp); + fclose(fp); + FILE *fp2 = fopen("call_once.txt", "r"); + fread(list, sizeof(list), 1, fp2); + fclose(fp2); +} +static once_flag flag = ONCE_FLAG_INIT; +void func(void *data) +{ + call_once(&flag, do_once); +} + +/** + * @tc.name : call_once_0100 + * @tc.desc : Each parameter is valid, and the function func is called only once. + * @tc.level : Level 0 + */ +void call_once_0100(void) +{ + EXPECT_EQ("call_once_0100", strcmp(list, buf), 0); +} + +int main(void) +{ + thrd_t t1, t2, t3, t4; + thrd_create(&t1, (thrd_start_t)func, NULL); + thrd_create(&t2, (thrd_start_t)func, NULL); + thrd_create(&t3, (thrd_start_t)func, NULL); + thrd_create(&t4, (thrd_start_t)func, NULL); + thrd_join(t1, NULL); + thrd_join(t2, NULL); + thrd_join(t3, NULL); + thrd_join(t4, NULL); + call_once_0100(); + remove("call_once.txt"); + memset(list, 0x00, sizeof(list)); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/cnd_init.c b/libc-test/src/functionalext/supplement/thread/cnd_init.c new file mode 100644 index 00000000..cc2f7765 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/cnd_init.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : cnd_init_0100 + * @tc.desc : Verify that a new condition variable can be initialized + * @tc.level : Level 0 + */ +void cnd_init_0100(void) +{ + cnd_t buf; + int result = -1; + result = cnd_init(&buf); + EXPECT_EQ("cnd_init_0100", result, thrd_success); +} + +int main() +{ + cnd_init_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/cnd_signal.c b/libc-test/src/functionalext/supplement/thread/cnd_signal.c new file mode 100644 index 00000000..642cc951 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/cnd_signal.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +mtx_t mtx; +cnd_t cndPut; +void cnd_timedwaitfirst(void *arg) +{ + int res = -1; + struct timespec ts; + mtx_lock(&mtx); + res = cnd_timedwait(&cndPut, &mtx, &ts); + mtx_unlock(&mtx); +} + +/** + * @tc.name : cnd_signal_0100 + * @tc.desc : The parameter is valid, among any number of threads waiting for the specified condition + * variable, wake up one of the threads. + * @tc.level : Level 0 + */ +void cnd_signal_0100(void) +{ + thrd_t id1; + int ret; + int res = -1; + cnd_init(&cndPut); + mtx_init(&mtx, 0); + ret = thrd_create(&id1, (thrd_start_t)cnd_timedwaitfirst, (void *)1); + if (0 != ret) { + printf("thread 1 create failed!\n"); + } + sleep(2); + mtx_lock(&mtx); + res = cnd_signal(&cndPut); + EXPECT_EQ("cnd_signal_0100", res, thrd_success); + mtx_unlock(&mtx); + thrd_join(id1, NULL); + cnd_destroy(&cndPut); + mtx_destroy(&mtx); +} + +int main() +{ + cnd_signal_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/cnd_timedwait.c b/libc-test/src/functionalext/supplement/thread/cnd_timedwait.c new file mode 100644 index 00000000..62e1df26 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/cnd_timedwait.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +static cnd_t cond; +static mtx_t mutex; + +static int signal_parent(void *arg) +{ + if (mtx_lock(&mutex) != thrd_success) { + t_error("%s mtx_lock failed\n", __func__); + } + if (cnd_signal(&cond) != thrd_success) { + t_error("%s cnd_signal failed\n", __func__); + } + if (mtx_unlock(&mutex) != thrd_success) { + t_error("%s mtx_unlock failed\n", __func__); + } + + thrd_exit(thrd_success); +} + +/** + * @tc.name : cnd_timedwait_0100 + * @tc.desc : The parameter is valid and can block the calling thread and release the specified mutex. + * @tc.level : Level 0 + */ +void cnd_timedwait_0100(void) +{ + thrd_t id; + struct timespec w_time; + + if (cnd_init(&cond) != thrd_success) { + t_error("%s cnd_init failed\n", __func__); + } + if (mtx_init(&mutex, mtx_plain) != thrd_success) { + t_error("%s mtx_init failed\n", __func__); + } + if (mtx_lock(&mutex) != thrd_success) { + t_error("%s mtx_lock failed\n", __func__); + } + if (clock_gettime(CLOCK_REALTIME, &w_time) != 0) { + t_error("%s clock_gettime failed\n", __func__); + } + + w_time.tv_sec += 3600; + + if (thrd_create(&id, signal_parent, NULL) != thrd_success) { + t_error("%s thrd_create failed\n", __func__); + } + + if (cnd_timedwait(&cond, &mutex, &w_time) != thrd_success) { + t_error("%s cnd_timedwait failed\n", __func__); + } + + if (thrd_join(id, NULL) != thrd_success) { + t_error("%s thrd_join failed\n", __func__); + } + + if (mtx_unlock(&mutex) != thrd_success) { + t_error("%s mtx_unlock failed\n", __func__); + } + mtx_destroy(&mutex); + cnd_destroy(&cond); +} + +int main() +{ + cnd_timedwait_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/cnd_wait.c b/libc-test/src/functionalext/supplement/thread/cnd_wait.c new file mode 100644 index 00000000..1814975d --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/cnd_wait.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +mtx_t mtx; +cnd_t cnd; +void cnd_waitfirst(void *arg) +{ + int res = -1; + mtx_lock(&mtx); + res = cnd_wait(&cnd, &mtx); + EXPECT_EQ("cnd_wait_0100", res, thrd_success); + mtx_unlock(&mtx); +} + +/** + * @tc.name : cnd_wait_0100 + * @tc.desc : The parameter is valid and can block the calling thread and release the specified mutex + * @tc.level : Level 0 + */ +void cnd_wait_0100(void) +{ + thrd_t id1; + int ret; + cnd_init(&cnd); + mtx_init(&mtx, 0); + ret = thrd_create(&id1, (thrd_start_t)cnd_waitfirst, (void *)1); + if (0 != ret) { + printf("thread 1 create failed!\n"); + } + sleep(2); + mtx_lock(&mtx); + cnd_signal(&cnd); + mtx_unlock(&mtx); + thrd_join(id1, NULL); + cnd_destroy(&cnd); + mtx_destroy(&mtx); +} + +int main() +{ + cnd_wait_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/mtx_init.c b/libc-test/src/functionalext/supplement/thread/mtx_init.c new file mode 100644 index 00000000..9f7aeec7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/mtx_init.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +static mtx_t g_mtx; + +/** + * @tc.name : mtx_init. + * @tc.desc : Verify mtx_init process success when second args is mtx_plain. + * @tc.desc : level 0 + */ +void mtx_init_0100(void) +{ + int32_t ret = 0; + ret = mtx_init(&g_mtx, mtx_plain); + EXPECT_EQ("mtx_init_0100", ret, thrd_success); +} + +/** + * @tc.name : mtx_init. + * @tc.desc : Verify mtx_init process success when second args is mtx_timed. + * @tc.desc : level 1 + */ +void mtx_init_0200(void) +{ + int32_t ret = 0; + ret = mtx_init(&g_mtx, mtx_timed); + EXPECT_EQ("mtx_init_0200", ret, thrd_success); +} + +/** + * @tc.name : mtx_init. + * @tc.desc : Verify mtx_init process success when second args is mtx_plain | mtx_recursive. + * @tc.desc : level 0 + */ +void mtx_init_0300(void) +{ + int32_t ret = 0; + ret = mtx_init(&g_mtx, mtx_plain | mtx_recursive); + EXPECT_EQ("mtx_init_0300", ret, thrd_success); +} + +/** + * @tc.name : mtx_init. + * @tc.desc : Verify mtx_init process success when second args is mtx_timed | mtx_recursive. + * @tc.desc : level 0 + */ +void mtx_init_0400(void) +{ + int32_t ret = 0; + ret = mtx_init(&g_mtx, mtx_timed | mtx_recursive); + EXPECT_EQ("mtx_init_0400", ret, thrd_success); +} + +int main(void) +{ + mtx_init_0100(); + mtx_init_0200(); + mtx_init_0300(); + mtx_init_0400(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/mtx_lock.c b/libc-test/src/functionalext/supplement/thread/mtx_lock.c new file mode 100644 index 00000000..e23a6091 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/mtx_lock.c @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +static mtx_t g_mtex; + +int threadfuncA(void *arg) +{ + int32_t ret = 0; + ret = mtx_lock(&g_mtex); + EXPECT_EQ("mtx_lock_0100", ret, thrd_success); + ret = mtx_unlock(&g_mtex); + EXPECT_EQ("mtx_lock_0100", ret, thrd_success); + return 0; +} + +int threadfuncB(void *arg) +{ + int32_t ret = 0; + ret = mtx_lock(&g_mtex); + EXPECT_EQ("mtx_lock_0200", ret, thrd_success); + ret = mtx_unlock(&g_mtex); + EXPECT_EQ("mtx_lock_0200", ret, thrd_success); + return 0; +} + +int threadfuncC(void *arg) +{ + int32_t ret = 0; + ret = mtx_lock(&g_mtex); + EXPECT_EQ("mtx_lock_0300", ret, thrd_success); + ret = mtx_unlock(&g_mtex); + EXPECT_EQ("mtx_lock_0300", ret, thrd_success); + return 0; +} + +int threadfuncD(void *arg) +{ + int32_t ret = 0; + ret = mtx_lock(&g_mtex); + EXPECT_EQ("mtx_lock_0400", ret, thrd_success); + ret = mtx_unlock(&g_mtex); + EXPECT_EQ("mtx_lock_0400", ret, thrd_success); + return 0; +} + +int threadfuncE(void *arg) +{ + int32_t ret = 0; + ret = mtx_lock(&g_mtex); + ret = mtx_lock(&g_mtex); + EXPECT_EQ("mtx_lock_0500", ret, thrd_success); + ret = mtx_unlock(&g_mtex); + EXPECT_EQ("mtx_lock_0500", ret, thrd_success); + return 0; +} + +/** + * @tc.name : mtx_lock_0100 + * @tc.desc : Verify process mtx_lock success when mtx_init second args is mtx_plain. + * @tc.level : Level 0 + */ +void mtx_lock_0100(void) +{ + int result = mtx_init(&g_mtex, mtx_plain); + if (result != thrd_success) { + t_error("%s mtx_init failed", __func__); + return; + } + thrd_t tid1; + thrd_create(&tid1, threadfuncA, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + return; + } + thrd_join(tid1, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + return; + } +} + +/** + * @tc.name : mtx_lock_0200 + * @tc.desc : Verify process mtx_lock success when mtx_init second args is mtx_timed. + * @tc.level : Level 0 + */ +void mtx_lock_0200(void) +{ + int result = mtx_init(&g_mtex, mtx_timed); + if (result != thrd_success) { + t_error("%s mtx_init failed", __func__); + return; + } + thrd_t tid2; + thrd_create(&tid2, threadfuncB, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + return; + } + thrd_join(tid2, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + return; + } +} + +/** + * @tc.name : mtx_lock_0300 + * @tc.desc : Verify process mtx_lock success when mtx_plain second args is mtx_plain | mtx_recursive. + * @tc.level : Level 0 + */ +void mtx_lock_0300(void) +{ + int result = mtx_init(&g_mtex, mtx_plain | mtx_recursive); + if (result != thrd_success) { + t_error("%s mtx_init failed", __func__); + return; + } + thrd_t tid3; + thrd_create(&tid3, threadfuncC, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + return; + } + thrd_join(tid3, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + return; + } +} + +/** + * @tc.name : mtx_lock_0400 + * @tc.desc : Verify process mtx_lock success when mtx_plain second args is mtx_timed | mtx_recursive. + * @tc.level : Level 0 + */ +void mtx_lock_0400(void) +{ + int result= mtx_init(&g_mtex, mtx_timed | mtx_recursive); + if (result != thrd_success) { + t_error("%s mtx_init failed", __func__); + return; + } + thrd_t tid4; + thrd_create(&tid4, threadfuncD, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + return; + } + thrd_join(tid4, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + return; + } +} + + +/** + * @tc.name : mtx_lock_0500 + * @tc.desc : Verify process mtx_lock twice success when mtx_plain second args is mtx_plain | mtx_recursive. + * @tc.level : Level 1 + */ +void mtx_lock_0500(void) +{ + int result = mtx_init(&g_mtex, mtx_plain | mtx_recursive); + if (result != thrd_success) { + t_error("%s mtx_init failed", __func__); + return; + } + thrd_t tid5; + thrd_create(&tid5, threadfuncE, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + return; + } + thrd_join(tid5, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + return; + } +} + +int main(void) +{ + mtx_lock_0100(); + mtx_lock_0200(); + mtx_lock_0300(); + mtx_lock_0400(); + mtx_lock_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/mtx_timedlock.c b/libc-test/src/functionalext/supplement/thread/mtx_timedlock.c new file mode 100755 index 00000000..ce42c74a --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/mtx_timedlock.c @@ -0,0 +1,87 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int TWO = 2; + +/** + * @tc.name : mtx_timedlock_0100 + * @tc.desc : Provide correct parameters, test timeout and lock + * @tc.level : Level 0 + */ +void mtx_timedlock_0100(void) +{ + struct timespec timeout; + timeout.tv_sec = TWO; + timeout.tv_nsec = 0; + mtx_t mutex; + int ret = 0; + ret = mtx_init(&mutex, mtx_timed); + if (ret != thrd_success) { + t_error("%s mtx_init failed", __func__); + return; + } + ret = mtx_timedlock(&mutex, &timeout); + EXPECT_EQ("mtx_timedlock_0100", ret, thrd_success); + ret = mtx_unlock(&mutex); + if (ret != thrd_success) { + t_error("%s mtx_unlock failed", __func__); + return; + } + mtx_destroy(&mutex); +} + +/** + * @tc.name : mtx_timedlock_0200 + * @tc.desc : In the locked state, the test times out and locks + * @tc.level : Level 2 + */ +void mtx_timedlock_0200(void) +{ + mtx_t mutex; + struct timespec timeout; + timeout.tv_sec = TWO; + timeout.tv_nsec = 0; + int ret = 0; + ret = mtx_init(&mutex, mtx_timed); + if (ret != thrd_success) { + t_error("%s mtx_init failed", __func__); + return; + } + if (ret != thrd_success) { + t_error("%s mtx_init failed", __func__); + return; + } + ret = mtx_lock(&mutex); + ret = mtx_timedlock(&mutex, &timeout); + EXPECT_EQ("mtx_timedlock_0200", ret, thrd_timedout); + ret = mtx_unlock(&mutex); + if (ret != thrd_success) { + t_error("%s mtx_unlock failed", __func__); + return; + } + mtx_destroy(&mutex); +} + +int main(void) +{ + mtx_timedlock_0100(); + mtx_timedlock_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/mtx_trylock.c b/libc-test/src/functionalext/supplement/thread/mtx_trylock.c new file mode 100644 index 00000000..bf16d45b --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/mtx_trylock.c @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +static mtx_t g_mtex; + +int threadfuncA(void *arg) +{ + int32_t ret = 0; + ret = mtx_lock(&g_mtex); + ret = mtx_trylock(&g_mtex); + EXPECT_EQ("mtx_lock_0100", ret, thrd_success); + ret = mtx_unlock(&g_mtex); + EXPECT_EQ("mtx_lock_0100", ret, thrd_success); + return 0; +} + +int threadfuncB(void *arg) +{ + int32_t ret = 0; + ret = mtx_lock(&g_mtex); + ret = mtx_trylock(&g_mtex); + EXPECT_EQ("mtx_lock_0200", ret, thrd_busy); + ret = mtx_unlock(&g_mtex); + EXPECT_EQ("mtx_lock_0200", ret, thrd_success); + return 0; +} + +/** + * @tc.name : mtx_trylock_0100 + * @tc.desc : Verify process mtx_trylock success when mtx_init second args is mtx_plain | tx_recursive. + * @tc.level : Level 0 + */ +void mtx_trylock_0100(void) +{ + int result = mtx_init(&g_mtex, mtx_plain | mtx_recursive); + if (result != thrd_success) { + t_error("%s mtx_init failed", __func__); + return; + } + thrd_t tid1; + result = thrd_create(&tid1, threadfuncA, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + return; + } + result = thrd_join(tid1, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + return; + } +} + +/** + * @tc.name : mtx_trylock_0200 + * @tc.desc : Verify process mtx_trylock fail when mtx_init second args is mtx_plain. + * @tc.level : Level 2 + */ +void mtx_trylock_0200(void) +{ + int result = mtx_init(&g_mtex, mtx_plain); + if (result != thrd_success) { + t_error("%s mtx_init failed", __func__); + return; + } + thrd_t tid2; + result = thrd_create(&tid2, threadfuncB, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + return; + } + result = thrd_join(tid2, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + return; + } +} + +int main(int argc, char *argv[]) +{ + mtx_trylock_0100(); + mtx_trylock_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/mtx_unlock.c b/libc-test/src/functionalext/supplement/thread/mtx_unlock.c new file mode 100644 index 00000000..e27bb196 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/mtx_unlock.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +static mtx_t g_mtx; + +int threadfuncA(void *arg) +{ + int ret= mtx_lock(&g_mtx); + EXPECT_EQ("mtx_unlock_0100", ret, 0); + ret = mtx_unlock(&g_mtx); + EXPECT_EQ("mtx_unlock_0100", ret, 0); + return 0; +} + +/** + * @tc.name : mtx_unlock_0100. + * @tc.desc : Verify process mtx_unlock once success. + * @tc.level : Level 0. + */ +void mtx_unlock_0100(void) +{ + int result = mtx_init(&g_mtx, mtx_plain); + if (result != thrd_success) { + t_error("%s mtx_init failed", __func__); + return; + } + thrd_t tid1; + result = thrd_create(&tid1, threadfuncA, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + return; + } + result = thrd_join(tid1, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + return; + } +} + +int main(void) +{ + mtx_unlock_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_atfork.c b/libc-test/src/functionalext/supplement/thread/pthread_atfork.c new file mode 100755 index 00000000..0ef8932d --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_atfork.c @@ -0,0 +1,146 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +#define TEST_THREAD_SLEEP 3 + +pthread_mutex_t glock = PTHREAD_MUTEX_INITIALIZER; +static int gprepare_flag = 0; +static int gparent_flag = 0; +static int gchild_flag = 0; + +void reset_data(void) +{ + gprepare_flag = 0; + gparent_flag = 0; + gchild_flag = 0; +} + +static void prepare(void) +{ + int ret = pthread_mutex_lock(&glock); + EXPECT_EQ("pthread_atfork prepare", ret, 0); + gprepare_flag++; +} + +static void parent(void) +{ + int ret = pthread_mutex_unlock(&glock); + EXPECT_EQ("pthread_atfork prepare", ret, 0); + gparent_flag++; +} + +static void child(void) +{ + int ret = pthread_mutex_unlock(&glock); + EXPECT_EQ("pthread_atfork prepare", ret, 0); + gchild_flag++; +} + +static void *thread_fun(void *arg) +{ + while (1) { + pthread_testcancel(); + pthread_mutex_lock(&glock); + sleep(TEST_THREAD_SLEEP); + pthread_mutex_unlock(&glock); + sleep(1); + } + return NULL; +} + +/** + * @tc.name : pthread_atfork_0100 + * @tc.desc : Provide a callback to test the relationship between pthread_atfork and fork + * @tc.level : Level 1 + */ +void pthread_atfork_0100(void) +{ + reset_data(); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + + pthread_t tid; + int ret = pthread_create(&tid, NULL, thread_fun, NULL); + EXPECT_EQ("pthread_atfork_0100", ret, CMPFLAG); + if (ret != 0) { + return; + } + + ret = pthread_atfork(prepare, parent, child); + EXPECT_EQ("pthread_atfork_0100", ret, CMPFLAG); + if (ret != 0) { + return; + } + sleep(1); + + pid_t pid = fork(); + if (pid == 0) { + pthread_mutex_lock(&glock); + sleep(1); + pthread_mutex_unlock(&glock); + EXPECT_EQ("pthread_atfork_0100", gchild_flag, 1); + _exit(0); + } else if (pid > 0) { + wait(NULL); + pthread_cancel(tid); + pthread_join(tid, NULL); + + EXPECT_EQ("pthread_atfork_0100", gprepare_flag, 1); + EXPECT_EQ("pthread_atfork_0100", gparent_flag, 1); + } else { + EXPECT_FALSE("pthread_atfork_0100", 1); + } +} + +/** + * @tc.name : pthread_atfork_0200 + * @tc.desc : No callback is provided, test the relationship between pthread_atfork and fork + * @tc.level : Level 2 + */ +void pthread_atfork_0200(void) +{ + reset_data(); + int ret = pthread_atfork(NULL, NULL, NULL); + EXPECT_EQ("pthread_atfork_0200", ret, CMPFLAG); + if (ret != 0) { + return; + } + + pid_t pid = fork(); + if (pid == 0) { + EXPECT_EQ("pthread_atfork_0200", gchild_flag, 0); + _exit(0); + } else if (pid > 0) { + wait(NULL); + + EXPECT_EQ("pthread_atfork_0200", gprepare_flag, 0); + EXPECT_EQ("pthread_atfork_0200", gparent_flag, 0); + } else { + EXPECT_FALSE("pthread_atfork_0200", 1); + } +} + +int main(void) +{ + pthread_atfork_0200(); + pthread_atfork_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_attr_destroy.c b/libc-test/src/functionalext/supplement/thread/pthread_attr_destroy.c new file mode 100644 index 00000000..ee309c43 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_attr_destroy.c @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; + +/** + * @tc.name : pthread_attr_destroy_0100 + * @tc.desc : The parameters are valid and the function can return normally + * @tc.level : Level 0 + */ +void pthread_attr_destroy_0100(void) +{ + pthread_attr_t attr; + int result = pthread_attr_destroy(&attr); + EXPECT_EQ("pthread_attr_destroy_0100", result, SUCCESS); +} + +int main() +{ + pthread_attr_destroy_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_attr_get.c b/libc-test/src/functionalext/supplement/thread/pthread_attr_get.c new file mode 100644 index 00000000..c9366a27 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_attr_get.c @@ -0,0 +1,418 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define TEST_STACK_SIZE 4096 + +/** + * @tc.name : pthread_attr_getscope_0100 + * @tc.desc : Get thread scope + * @tc.level : Level 0 + */ +void pthread_attr_getscope_0100(void) +{ + int scope = 0; + pthread_attr_t attr; + pthread_attr_init(&attr); + int rev = pthread_attr_getscope(&attr, &scope); + EXPECT_EQ("pthread_attr_getscope_0100", rev, 0); + EXPECT_EQ("pthread_attr_getscope_0100", scope, PTHREAD_SCOPE_SYSTEM); + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_attr_getguardsize_0100 + * @tc.desc : Get the guard value of the thread property + * @tc.level : Level 0 + */ +void pthread_attr_getguardsize_0100(void) +{ + size_t size = 0; + pthread_attr_t attr; + pthread_attr_init(&attr); + int rev = pthread_attr_getguardsize(&attr, &size); + EXPECT_EQ("pthread_attr_getguardsize_0100", rev, 0); + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_attr_getinheritsched_0100 + * @tc.desc : Verify that the preset properties can be obtained through get inheritsched in + * a single-threaded environment + * @tc.level : Level 0 + */ +void pthread_attr_getinheritsched_0100(void) +{ + pthread_attr_t attr; + int result = -1; + + int ret = pthread_attr_init(&attr); + EXPECT_EQ("pthread_attr_getinheritsched_0100", ret, CMPFLAG); + ret = pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); + EXPECT_EQ("pthread_attr_getinheritsched_0100", ret, CMPFLAG); + + ret = pthread_attr_getinheritsched(&attr, &result); + EXPECT_EQ("pthread_attr_getinheritsched_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_attr_getinheritsched_0100", result, PTHREAD_INHERIT_SCHED); + + ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + EXPECT_EQ("pthread_attr_getinheritsched_0100", ret, CMPFLAG); + + ret = pthread_attr_getinheritsched(&attr, &result); + EXPECT_EQ("pthread_attr_getinheritsched_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_attr_getinheritsched_0100", result, PTHREAD_EXPLICIT_SCHED); + + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_attr_getinheritsched_0200 + * @tc.desc : Verify that the return value is EINVAL when setting an exception value in a single-threaded + * environment + * @tc.level : Level 0 + */ +void pthread_attr_getinheritsched_0200(void) +{ + pthread_attr_t attr; + int inheritsched = 2; + int result = -1; + + int ret = pthread_attr_init(&attr); + EXPECT_EQ("pthread_attr_getinheritsched_0200", ret, CMPFLAG); + ret = pthread_attr_setinheritsched(&attr, inheritsched); + EXPECT_EQ("pthread_attr_getinheritsched_0200", ret, EINVAL); + + ret = pthread_attr_getinheritsched(&attr, &result); + EXPECT_EQ("pthread_attr_getinheritsched_0200", ret, CMPFLAG); + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_barrierattr_getpshared_0100 + * @tc.desc : Correct parameter setting barrier variable property value + * @tc.level : Level 0 + */ +void pthread_barrierattr_getpshared_0100(void) +{ + pthread_barrierattr_t attr; + int result = -1; + int share = 0; + + int ret = pthread_barrierattr_init(&attr); + EXPECT_EQ("pthread_barrierattr_getpshared_0100", ret, CMPFLAG); + + ret = pthread_barrierattr_setpshared(&attr, share); + EXPECT_EQ("pthread_barrierattr_getpshared_0100", ret, CMPFLAG); + + ret = pthread_barrierattr_getpshared(&attr, &result); + EXPECT_EQ("pthread_barrierattr_getpshared_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_barrierattr_getpshared_0100", result, share); + + share = 1; + ret = pthread_barrierattr_setpshared(&attr, share); + + ret = pthread_barrierattr_getpshared(&attr, &result); + EXPECT_EQ("pthread_barrierattr_getpshared_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_barrierattr_getpshared_0100", result, share); + + pthread_barrierattr_destroy(&attr); +} + +/** + * @tc.name : pthread_condattr_getclock_0100 + * @tc.desc : Correct parameter setting condition variable property value + * @tc.level : Level 0 + */ +void pthread_condattr_getclock_0100(void) +{ + pthread_condattr_t attr; + clockid_t result = -1; + + int ret = pthread_condattr_init(&attr); + EXPECT_EQ("pthread_condattr_getclock_0100", ret, CMPFLAG); + + ret = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC_RAW); + EXPECT_EQ("pthread_condattr_getclock_0100", ret, CMPFLAG); + + ret = pthread_condattr_getclock(&attr, &result); + EXPECT_EQ("pthread_condattr_getclock_0200", ret, CMPFLAG); + EXPECT_EQ("pthread_condattr_getclock_0100", result, CLOCK_MONOTONIC_RAW); + + pthread_condattr_destroy(&attr); +} + +/** + * @tc.name : pthread_condattr_getpshared_0100 + * @tc.desc : Correct parameter setting condition variable property value + * @tc.level : Level 0 + */ +void pthread_condattr_getpshared_0100(void) +{ + pthread_condattr_t attr; + int result = -1; + int share = 0; + int ret = pthread_condattr_init(&attr); + + EXPECT_EQ("pthread_condattr_getpshared_0100", ret, CMPFLAG); + + ret = pthread_condattr_setpshared(&attr, share); + EXPECT_EQ("pthread_condattr_getpshared_0100", ret, CMPFLAG); + + ret = pthread_condattr_getpshared(&attr, &result); + EXPECT_EQ("pthread_condattr_getpshared_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_condattr_getpshared_0100", result, share); + + share = 1; + ret = pthread_condattr_setpshared(&attr, share); + + ret = pthread_condattr_getpshared(&attr, &result); + EXPECT_EQ("pthread_condattr_getpshared_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_condattr_getpshared_0100", result, share); + + pthread_condattr_destroy(&attr); +} + +/** + * @tc.name : pthread_mutexattr_getprotocol_0100 + * @tc.desc : Correct parameter setting condition variable property value + * @tc.level : Level 0 + */ +void pthread_mutexattr_getprotocol_0100(void) +{ + pthread_mutexattr_t attr; + int result = -1; + + int ret = pthread_mutexattr_init(&attr); + EXPECT_EQ("pthread_mutexattr_getprotocol_0100", ret, CMPFLAG); + + ret = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_NONE); + EXPECT_EQ("pthread_mutexattr_getprotocol_0100", ret, CMPFLAG); + + ret = pthread_mutexattr_getprotocol(&attr, &result); + EXPECT_EQ("pthread_mutexattr_getprotocol_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_mutexattr_getprotocol_0100", result, PTHREAD_PRIO_NONE); + + pthread_mutexattr_destroy(&attr); +} + +/** + * @tc.name : pthread_mutexattr_gettype_0100 + * @tc.desc : Correct parameter setting condition variable property value + * @tc.level : Level 0 + */ +void pthread_mutexattr_gettype_0100(void) +{ + pthread_mutexattr_t attr; + int result = -1; + + int ret = pthread_mutexattr_init(&attr); + EXPECT_EQ("pthread_mutexattr_gettype_0100", ret, CMPFLAG); + + ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); + EXPECT_EQ("pthread_mutexattr_gettype_0100", ret, CMPFLAG); + + ret = pthread_mutexattr_gettype(&attr, &result); + EXPECT_EQ("pthread_mutexattr_gettype_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_mutexattr_gettype_0100", result, PTHREAD_MUTEX_NORMAL); + + ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); + EXPECT_EQ("pthread_mutexattr_gettype_0100", ret, CMPFLAG); + + ret = pthread_mutexattr_gettype(&attr, &result); + EXPECT_EQ("pthread_mutexattr_gettype_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_mutexattr_gettype_0100", result, PTHREAD_MUTEX_ERRORCHECK); + + ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + EXPECT_EQ("pthread_mutexattr_gettype_0100", ret, CMPFLAG); + + ret = pthread_mutexattr_gettype(&attr, &result); + EXPECT_EQ("pthread_mutexattr_gettype_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_mutexattr_gettype_0100", result, PTHREAD_MUTEX_RECURSIVE); + + ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT); + EXPECT_EQ("pthread_mutexattr_gettype_0100", ret, CMPFLAG); + + ret = pthread_mutexattr_gettype(&attr, &result); + EXPECT_EQ("pthread_mutexattr_gettype_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_mutexattr_gettype_0100", result, PTHREAD_MUTEX_DEFAULT); + + pthread_mutexattr_destroy(&attr); +} + +/** + * @tc.name : pthread_mutexattr_getpshared_0100 + * @tc.desc : Correct parameter setting mutex variable property value + * @tc.level : Level 0 + */ +void pthread_mutexattr_getpshared_0100(void) +{ + pthread_mutexattr_t attr; + int result = -1; + int share = 0; + int ret = pthread_mutexattr_init(&attr); + + EXPECT_EQ("pthread_mutexattr_getpshared_0100", ret, CMPFLAG); + + ret = pthread_mutexattr_setpshared(&attr, share); + EXPECT_EQ("pthread_mutexattr_getpshared_0100", ret, CMPFLAG); + + ret = pthread_mutexattr_getpshared(&attr, &result); + EXPECT_EQ("pthread_mutexattr_getpshared_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_mutexattr_getpshared_0100", result, share); + + share = 1; + ret = pthread_mutexattr_setpshared(&attr, share); + + ret = pthread_mutexattr_getpshared(&attr, &result); + EXPECT_EQ("pthread_mutexattr_getpshared_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_mutexattr_getpshared_0100", result, share); + + pthread_mutexattr_destroy(&attr); +} + +/** + * @tc.name : pthread_rwlockattr_getpshared_0100 + * @tc.desc : Correct parameter setting rwlock variable property value + * @tc.level : Level 0 + */ +void pthread_rwlockattr_getpshared_0100(void) +{ + pthread_rwlockattr_t attr; + int result = -1; + int share = 0; + int ret = pthread_rwlockattr_init(&attr); + + EXPECT_EQ("pthread_rwlockattr_getpshared_0100", ret, CMPFLAG); + + ret = pthread_rwlockattr_setpshared(&attr, share); + EXPECT_EQ("pthread_rwlockattr_getpshared_0100", ret, CMPFLAG); + + ret = pthread_rwlockattr_getpshared(&attr, &result); + EXPECT_EQ("pthread_rwlockattr_getpshared_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_rwlockattr_getpshared_0100", result, share); + + share = 1; + ret = pthread_rwlockattr_setpshared(&attr, share); + + ret = pthread_rwlockattr_getpshared(&attr, &result); + EXPECT_EQ("pthread_rwlockattr_getpshared_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_rwlockattr_getpshared_0100", result, share); + + pthread_rwlockattr_destroy(&attr); +} + +/** + * @tc.name : pthread_attr_getdetachstate_0100 + * @tc.desc : Get detached state from thread attr + * @tc.level : Level 0 + */ +void pthread_attr_getdetachstate_0100(void) +{ + pthread_attr_t attr; + int state = 0; + pthread_attr_init(&attr); + int ret = pthread_attr_getdetachstate(&attr, &state); + EXPECT_EQ("pthread_attr_getdetachstate_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_attr_getdetachstate_0100", state, CMPFLAG); + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_attr_getschedpolicy_0100 + * @tc.desc : Get detached state from thread attr + * @tc.level : Level 0 + */ +void pthread_attr_getschedpolicy_0100(void) +{ + pthread_attr_t attr; + int setpolicy = 1; + int getpolicy = 0; + pthread_attr_init(&attr); + int ret = pthread_attr_setschedpolicy(&attr, setpolicy); + EXPECT_EQ("pthread_attr_getschedpolicy_0100", ret, CMPFLAG); + + ret = pthread_attr_getschedpolicy(&attr, &getpolicy); + EXPECT_EQ("pthread_attr_getschedpolicy_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_attr_getschedpolicy_0100", getpolicy, setpolicy); + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_attr_getschedparam_0100 + * @tc.desc : Get scheduling parameter attributes in thread attributes object + * @tc.level : Level 0 + */ +void pthread_attr_getschedparam_0100(void) +{ + pthread_attr_t attr; + struct sched_param setparam; + struct sched_param getparam; + + memset(&setparam, 0x0, sizeof(setparam)); + memset(&getparam, 0x0, sizeof(getparam)); + setparam.sched_priority = 1; + + pthread_attr_init(&attr); + int ret = pthread_attr_setschedparam(&attr, &setparam); + EXPECT_EQ("pthread_attr_getschedparam_0100", ret, CMPFLAG); + + ret = pthread_attr_getschedparam(&attr, &getparam); + EXPECT_EQ("pthread_attr_getschedparam_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_attr_getschedparam_0100", getparam.sched_priority, 1); + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_attr_getstacksize_0100 + * @tc.desc : Get stack size attribute in thread attributes object + * @tc.level : Level 0 + */ +void pthread_attr_getstacksize_0100(void) +{ + size_t size; + pthread_attr_t attr; + pthread_attr_init(&attr); + + int ret = pthread_attr_setstacksize(&attr, TEST_STACK_SIZE); + EXPECT_EQ("pthread_attr_getstacksize_0100", ret, CMPFLAG); + + ret = pthread_attr_getstacksize(&attr, &size); + EXPECT_EQ("pthread_attr_getstacksize_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_attr_getstacksize_0100", size, TEST_STACK_SIZE); + pthread_attr_destroy(&attr); +} + +int main(void) +{ + pthread_attr_getscope_0100(); + pthread_attr_getguardsize_0100(); + pthread_attr_getinheritsched_0100(); + pthread_attr_getinheritsched_0200(); + pthread_barrierattr_getpshared_0100(); + pthread_condattr_getclock_0100(); + pthread_condattr_getpshared_0100(); + pthread_mutexattr_getprotocol_0100(); + pthread_mutexattr_gettype_0100(); + pthread_mutexattr_getpshared_0100(); + pthread_rwlockattr_getpshared_0100(); + pthread_attr_getdetachstate_0100(); + pthread_attr_getschedpolicy_0100(); + pthread_attr_getschedparam_0100(); + pthread_attr_getstacksize_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_attr_getstack.c b/libc-test/src/functionalext/supplement/thread/pthread_attr_getstack.c new file mode 100644 index 00000000..021b412d --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_attr_getstack.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int32_t STACK_SIZE = 4 * 1024; + +/** + * @tc.name : pthread_attr_getstack_0100 + * @tc.desc : Verify pthread_attr_getstack process fail. By default, get the thread stack address and size fail + * @tc.level : Level 2 + */ +void pthread_attr_getstack_0100(void) +{ + pthread_attr_t attr; + pthread_attr_init(&attr); + void *stack = NULL; + size_t stacksize; + int32_t ret = pthread_attr_getstack(&attr, &stack, &stacksize); + EXPECT_EQ("pthread_attr_getstack_0100", ret, EINVAL); + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_attr_getstack_0200 + * @tc.desc : Verify pthread_asuccessttr_getstack process success.Customize the thread stack,get the thread stack + * address and size success + * @tc.level : Level 1 + */ +void pthread_attr_getstack_0200(void) +{ + pthread_attr_t attr; + pthread_attr_init(&attr); + void *stack = malloc(STACK_SIZE); + EXPECT_PTRNE("pthread_attr_getstack_0200", stack, NULL); + void *retstack = NULL; + size_t stacksize; + pthread_attr_setstack(&attr, stack, STACK_SIZE); + int32_t ret = pthread_attr_getstack(&attr, &retstack, &stacksize); + EXPECT_EQ("pthread_attr_getstack_0200", ret, 0); + EXPECT_PTREQ("pthread_attr_getstack_0200", stack, retstack); + EXPECT_EQ("pthread_attr_getstack_0200", stacksize, STACK_SIZE); + pthread_attr_destroy(&attr); +} + +int main(void) +{ + pthread_attr_getstack_0100(); + pthread_attr_getstack_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_attr_init.c b/libc-test/src/functionalext/supplement/thread/pthread_attr_init.c new file mode 100644 index 00000000..98c804bb --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_attr_init.c @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; + +void *ThreadFun(void *arg) +{ + + return NULL; +} + +/** + * @tc.name : pthread_attr_init_0100 + * @tc.desc : Initialize the thread properties, the parameters are valid, + * and the parameter assignment can be passed normally + * @tc.level : Level 0 + */ +void pthread_attr_init_0100(void) +{ + pthread_attr_t attr; + int back = pthread_attr_init(&attr); + EXPECT_EQ("pthread_attr_init_0100", back, SUCCESS); +} + +/** + * @tc.name : pthread_attr_init_0200 + * @tc.desc : Initialize the thread attributes, the parameters are valid, the parameter assignment can + * be passed normally, and the thread is created to pass the parameter pthread_attr_t + * @tc.level : Level 0 + */ +void pthread_attr_init_0200(void) +{ + pthread_attr_t attr; + pthread_t myThread1; + int back = pthread_attr_init(&attr); + int result = pthread_create(&myThread1, &attr, ThreadFun, NULL); + pthread_join(myThread1, NULL); + EXPECT_EQ("pthread_attr_init_0200", back, SUCCESS); + EXPECT_EQ("pthread_attr_init_0200", result, SUCCESS); +} + +int main() +{ + pthread_attr_init_0100(); + pthread_attr_init_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_attr_setdetachstate.c b/libc-test/src/functionalext/supplement/thread/pthread_attr_setdetachstate.c new file mode 100644 index 00000000..332b538a --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_attr_setdetachstate.c @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int32_t ERROR = 2U; + +/** + * @tc.name : pthread_attr_setdetachstate_0100 + * @tc.desc : Verify pthread_attr_setdetachstate process success + * @tc.level : Level 1 + */ +void pthread_attr_setdetachstate_0100(void) +{ + pthread_attr_t attr; + pthread_attr_init(&attr); + struct sched_param sched = {0, 1}; + int32_t ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); + EXPECT_EQ("pthread_attr_setdetachstate_0100", ret, 0); + ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + EXPECT_EQ("pthread_attr_setdetachstate_0100", ret, 0); + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_attr_setdetachstate_0200 + * @tc.desc : Verify pthread_attr_setdetachstate process fail.Because second param is error + * @tc.level : Level 1 + */ +void pthread_attr_setdetachstate_0200(void) +{ + pthread_attr_t attr; + pthread_attr_init(&attr); + int32_t ret = pthread_attr_setdetachstate(&attr, ERROR); + EXPECT_EQ("pthread_attr_setdetachstate_0200", ret, EINVAL); + pthread_attr_destroy(&attr); +} + +int main(int argc, char *argv[]) +{ + pthread_attr_setdetachstate_0100(); + pthread_attr_setdetachstate_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_attr_setguardsize.c b/libc-test/src/functionalext/supplement/thread/pthread_attr_setguardsize.c new file mode 100644 index 00000000..28c901f7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_attr_setguardsize.c @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define TEST_GUARD_SIZE 128 + +/** + * @tc.name : pthread_attr_setguardsize_0100 + * @tc.desc : Set thread property threshold value + * @tc.level : Level 0 + */ +void pthread_attr_setguardsize_0100(void) +{ + int scope = 0; + pthread_attr_t attr; + pthread_attr_init(&attr); + int rev = pthread_attr_setguardsize(&attr, TEST_GUARD_SIZE); + EXPECT_EQ("pthread_attr_setguardsize_0100", rev, 0); + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_attr_setguardsize_0200 + * @tc.desc : Use an excessively large value, set the thread property threshold value + * @tc.level : Level 2 + */ +void pthread_attr_setguardsize_0200(void) +{ + int scope = 0; + pthread_attr_t attr; + pthread_attr_init(&attr); + int rev = pthread_attr_setguardsize(&attr, SIZE_MAX); + EXPECT_EQ("pthread_attr_setguardsize_0200", rev, EINVAL); + pthread_attr_destroy(&attr); +} + +int main(void) +{ + pthread_attr_setguardsize_0100(); + pthread_attr_setguardsize_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_attr_setinheritsched.c b/libc-test/src/functionalext/supplement/thread/pthread_attr_setinheritsched.c new file mode 100644 index 00000000..3591bc53 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_attr_setinheritsched.c @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "functionalext.h" + +/** + * @tc.name : pthread_attr_setinheritsched_0100 + * @tc.desc : Verify that the preset properties can be obtained through get inheritsched in a single-threaded + * environment + * @tc.level : Level 0 + */ +void pthread_attr_setinheritsched_0100(void) +{ + pthread_attr_t attr; + + pthread_attr_init(&attr); + + pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); + int result = pthread_attr_getinheritsched(&attr, &result); + EXPECT_EQ("pthread_attr_setinheritsched_0100", result, PTHREAD_INHERIT_SCHED); + + pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + pthread_attr_getinheritsched(&attr, &result); + EXPECT_EQ("pthread_attr_setinheritsched_0100", result, PTHREAD_EXPLICIT_SCHED); + + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_attr_setinheritsched_0200 + * @tc.desc : Verify that the return value is EINVAL when setting an exception value in a single-threaded + * environment + * @tc.level : Level 2 + */ +void pthread_attr_setinheritsched_0200(void) +{ + pthread_attr_t attr; + int inheritsched = 2; + int result = -1; + + int ret = pthread_attr_init(&attr); + EXPECT_EQ("pthread_attr_setinheritsched_0200", ret, CMPFLAG); + + ret = pthread_attr_setinheritsched(&attr, inheritsched); + EXPECT_EQ("pthread_attr_setinheritsched_0200", ret, EINVAL); + + pthread_attr_destroy(&attr); +} + +int main(void) +{ + pthread_attr_setinheritsched_0100(); + pthread_attr_setinheritsched_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_attr_setschedparam.c b/libc-test/src/functionalext/supplement/thread/pthread_attr_setschedparam.c new file mode 100755 index 00000000..9858c804 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_attr_setschedparam.c @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_attr_setschedparam_0100 + * @tc.desc : Set scheduling parameter attributes in thread attributes object + * @tc.level : Level 0 + */ +void pthread_attr_setschedparam_0100(void) +{ + pthread_attr_t attr; + struct sched_param setparam; + struct sched_param getparam; + setparam.sched_priority = 1; + + pthread_attr_init(&attr); + int ret = pthread_attr_setschedparam(&attr, &setparam); + EXPECT_EQ("pthread_attr_setschedparam_0100", ret, CMPFLAG); + + getparam.sched_priority = 0; + ret = pthread_attr_getschedparam(&attr, &getparam); + EXPECT_EQ("pthread_attr_setschedparam_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_attr_setschedparam_0100", getparam.sched_priority, setparam.sched_priority); + pthread_attr_destroy(&attr); +} + +int main(void) +{ + pthread_attr_setschedparam_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_attr_setschedpolicy.c b/libc-test/src/functionalext/supplement/thread/pthread_attr_setschedpolicy.c new file mode 100755 index 00000000..7406418c --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_attr_setschedpolicy.c @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_attr_setschedpolicy_0100 + * @tc.desc : Set thread scheduling policy + * @tc.level : Level 0 + */ +void pthread_attr_setschedpolicy_0100(void) +{ + pthread_attr_t attr; + int setpolicy = 1; + int getpolicy = 0; + pthread_attr_init(&attr); + int ret = pthread_attr_setschedpolicy(&attr, setpolicy); + EXPECT_EQ("pthread_attr_setschedpolicy_0100", ret, CMPFLAG); + + ret = pthread_attr_getschedpolicy(&attr, &getpolicy); + EXPECT_EQ("pthread_attr_setschedpolicy_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_attr_setschedpolicy_0100", getpolicy, setpolicy); + pthread_attr_destroy(&attr); +} + +int main(void) +{ + pthread_attr_setschedpolicy_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_attr_setscope.c b/libc-test/src/functionalext/supplement/thread/pthread_attr_setscope.c new file mode 100755 index 00000000..f70dfa81 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_attr_setscope.c @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_attr_setscope_0100 + * @tc.desc : Set contention scope attribute in thread attributes object with PTHREAD_SCOPE_SYSTEM + * @tc.level : Level 0 + */ +void pthread_attr_setscope_0100(void) +{ + pthread_attr_t attr; + pthread_attr_init(&attr); + int ret = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); + EXPECT_EQ("pthread_attr_setscope_0100", ret, CMPFLAG); + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_attr_setscope_0200 + * @tc.desc : Set contention scope attribute in thread attributes object with PTHREAD_SCOPE_PROCESS + * @tc.level : Level 2 + */ +void pthread_attr_setscope_0200(void) +{ + pthread_attr_t attr; + pthread_attr_init(&attr); + int ret = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS); + EXPECT_EQ("pthread_attr_setscope_0200", ret, ENOTSUP); + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_attr_setscope_0300 + * @tc.desc : Set contention scope attribute in thread attributes object with -1 + * @tc.level : Level 2 + */ +void pthread_attr_setscope_0300(void) +{ + pthread_attr_t attr; + pthread_attr_init(&attr); + int ret = pthread_attr_setscope(&attr, -1); + EXPECT_EQ("pthread_attr_setscope_0300", ret, EINVAL); + pthread_attr_destroy(&attr); +} + +int main(void) +{ + pthread_attr_setscope_0100(); + pthread_attr_setscope_0200(); + pthread_attr_setscope_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_attr_setstack.c b/libc-test/src/functionalext/supplement/thread/pthread_attr_setstack.c new file mode 100644 index 00000000..0ce7ff58 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_attr_setstack.c @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +#define THREAD_STACK_LEN 0x4001 +#define BUFFEIZE 0x3000 + +/** + * @tc.name : pthread_attr_setstack_0100 + * @tc.desc : Create a stack memory size of 4k, get the size value through the + * pthread_attr_getstack function, whether the setting is successful + * @tc.level : Level 0 + */ +void pthread_attr_setstack_0100(void) +{ + pthread_t thread; + pthread_attr_t attr; + void *stackAddr = NULL; + void *getstackaddr = NULL; + + size_t getstackSize = 0; + int ret = 0; + void *p = NULL; + + int pageSize = getpagesize(); + if (pageSize == 0) { + t_error("page Size is 0\n"); + return; + } + pthread_attr_init(&attr); + ret = posix_memalign(&stackAddr, pageSize, THREAD_STACK_LEN); + if (ret != 0) { + EXPECT_EQ("pthread_attr_setstack_0100", ret, 0); + return; + } + ret = pthread_attr_setstack(&attr, stackAddr, THREAD_STACK_LEN); + if (ret != 0) { + EXPECT_EQ("pthread_attr_setstack_0100", ret, 0); + return; + } + + pthread_attr_getstack(&attr, &getstackaddr, &getstackSize); + EXPECT_EQ("pthread_attr_setstack_0100", getstackSize, THREAD_STACK_LEN); + + pthread_attr_destroy(&attr); + free(stackAddr); + stackAddr = NULL; +} + +/** + * @tc.name : pthread_attr_setstack_0200 + * @tc.desc : Determine whether the stack maximum function returns an abnormal value + * @tc.level : Level 2 + */ +void pthread_attr_setstack_0200(void) +{ + pthread_attr_t attr; + void *stackAddr = NULL; + int ret = 0; + int MINSIZE = PTHREAD_STACK_MIN - 1; + + pthread_attr_init(&attr); + + ret = pthread_attr_setstack(&attr, stackAddr, ERREXPECT); + EXPECT_EQ("pthread_attr_setstack_0200", ret, EINVAL); + + ret = pthread_attr_setstack(&attr, stackAddr, MINSIZE); + EXPECT_EQ("pthread_attr_setstack_0200", ret, EINVAL); + + pthread_attr_destroy(&attr); +} + +int main(void) +{ + pthread_attr_setstack_0100(); + pthread_attr_setstack_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_attr_setstacksize.c b/libc-test/src/functionalext/supplement/thread/pthread_attr_setstacksize.c new file mode 100644 index 00000000..46f89bad --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_attr_setstacksize.c @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int32_t STACK_SIZE = 4 * 1024; + +/** + * @tc.name : pthread_attr_setstacksize_0100 + * @tc.desc : Verify pthread_attr_setstacksize process success + * @tc.level : Level 1 + */ +void pthread_attr_setstacksize_0100(void) +{ + pthread_attr_t attr; + pthread_attr_init(&attr); + int32_t ret = pthread_attr_setstacksize(&attr, STACK_SIZE); + EXPECT_EQ("pthread_attr_setstacksize_0100", ret, 0); + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_attr_setstacksize_0200 + * @tc.desc : Verify pthread_attr_setstacksize process fail because second param is unsigned large numbers + * @tc.level : Level 2 + */ +void pthread_attr_setstacksize_0200(void) +{ + pthread_attr_t attr; + pthread_attr_init(&attr); + int32_t ret = pthread_attr_setstacksize(&attr, -1); + EXPECT_EQ("pthread_attr_setstacksize_0200", ret, EINVAL); + pthread_attr_destroy(&attr); +} + +int main(int argc, char *argv[]) +{ + pthread_attr_setstacksize_0100(); + pthread_attr_setstacksize_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_barrier_destroy.c b/libc-test/src/functionalext/supplement/thread/pthread_barrier_destroy.c new file mode 100644 index 00000000..ef8071ec --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_barrier_destroy.c @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "functionalext.h" + +/** + * @tc.name : pthread_barrier_destroy_0100 + * @tc.desc : destroy creates a successful pthread_barrier_t type object + * and determines whether the return value meets expectations + * @tc.level : Level 0 + */ +void pthread_barrier_destroy_0100(void) +{ + pthread_barrier_t mybarrier; + unsigned int threadnum = 4; + + int ret = pthread_barrier_init(&mybarrier, NULL, threadnum); + EXPECT_EQ("pthread_barrier_destroy_0100", ret, 0); + + ret = pthread_barrier_destroy(&mybarrier); + EXPECT_EQ("pthread_barrier_destroy_0100", ret, 0); +} + +int main(void) +{ + pthread_barrier_destroy_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_barrier_init.c b/libc-test/src/functionalext/supplement/thread/pthread_barrier_init.c new file mode 100644 index 00000000..7f871093 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_barrier_init.c @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "functionalext.h" + +/** + * @tc.name : pthread_barrier_init_0100 + * @tc.desc : Pass a reasonable number of threads to determine whether the return value of the function is normal + * @tc.level : Level 0 + */ +void pthread_barrier_init_0100(void) +{ + pthread_barrier_t mybarrier; + unsigned int threadnum = 4; + + int ret = pthread_barrier_init(&mybarrier, NULL, threadnum); + EXPECT_EQ("pthread_barrier_init_0100", ret, CMPFLAG); + + ret = pthread_barrier_destroy(&mybarrier); + EXPECT_EQ("pthread_barrier_init_0100", ret, CMPFLAG); +} + +/** + * @tc.name : pthread_barrier_init_0200 + * @tc.desc : Pass the abnormal minimum values to determine whether the return value of + * the function is EINVAL + * @tc.level : Level 2 + */ +void pthread_barrier_init_0200(void) +{ + pthread_barrier_t mybarrier; + int threadnum = 0; + + int ret = pthread_barrier_init(&mybarrier, NULL, threadnum); + EXPECT_EQ("pthread_barrier_init_0200", ret, EINVAL); + + ret = pthread_barrier_destroy(&mybarrier); + EXPECT_EQ("pthread_barrier_init_0200", ret, CMPFLAG); +} + +int main(void) +{ + pthread_barrier_init_0100(); + pthread_barrier_init_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_barrier_wait.c b/libc-test/src/functionalext/supplement/thread/pthread_barrier_wait.c new file mode 100644 index 00000000..01d05bab --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_barrier_wait.c @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "functionalext.h" + +#define THREADNUM 4 + +pthread_barrier_t mybarrier; + +static void threadfunc(void) +{ + sleep(1); + int ret = pthread_barrier_wait(&mybarrier); + EXPECT_NE("pthread_barrier_wait_0100", ret, ERREXPECT); + + return; +} + +/** + * @tc.name : pthread_barrier_wait_0100 + * @tc.desc : Blocking and waiting for 4 sub-threads, the return value of the calling function is successful + * @tc.level : Level 1 + */ +void pthread_barrier_wait_0100(void) +{ + int i = 0; + pthread_t ids[THREADNUM]; + + int ret = pthread_barrier_init(&mybarrier, NULL, THREADNUM + 1); + EXPECT_EQ("pthread_barrier_wait_0100", ret, CMPFLAG); + + for (i = 0; i < THREADNUM; i++) { + if (pthread_create(&ids[i], NULL, (void *)threadfunc, NULL) != 0) { + t_error("create thread failed\n"); + return; + } + } + + ret = pthread_barrier_wait(&mybarrier); + + for (i = 0; i < THREADNUM; i++) { + ret = pthread_join(ids[i], NULL); + if (ret != 0) { + t_error("thread wait failed\n"); + return; + } + } + + ret = pthread_barrier_destroy(&mybarrier); + EXPECT_EQ("pthread_barrier_wait_0100", ret, CMPFLAG); +} + +/** + * @tc.name : pthread_barrier_wait_0200 + * @tc.desc : The number of blocked threads is 1, and the calling function returns ERREXPECT + * @tc.level : Level 2 + */ +void pthread_barrier_wait_0200(void) +{ + int threadnum = 1; + + int ret = pthread_barrier_init(&mybarrier, NULL, threadnum); + EXPECT_EQ("pthread_barrier_wait_0200", ret, CMPFLAG); + + ret = pthread_barrier_wait(&mybarrier); + EXPECT_EQ("pthread_barrier_wait_0200", ret, ERREXPECT); + + ret = pthread_barrier_destroy(&mybarrier); + EXPECT_EQ("pthread_barrier_wait_0200", ret, CMPFLAG); +} + +int main(void) +{ + pthread_barrier_wait_0100(); + pthread_barrier_wait_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_barrierattr_init.c b/libc-test/src/functionalext/supplement/thread/pthread_barrierattr_init.c new file mode 100644 index 00000000..430a0b7e --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_barrierattr_init.c @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "functionalext.h" + +/** + * @tc.name : pthread_barrierattr_init_0100 + * @tc.desc : Initialize barrier pthread properties + * @tc.level : Level 0 + */ +void pthread_barrierattr_init_0100(void) +{ + pthread_barrierattr_t attr; + + int ret = pthread_barrierattr_init(&attr); + EXPECT_EQ("pthread_barrierattr_init_0100", ret, 0); + + ret = pthread_barrierattr_destroy(&attr); +} + +int main(void) +{ + pthread_barrierattr_init_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_barrierattr_setpshared.c b/libc-test/src/functionalext/supplement/thread/pthread_barrierattr_setpshared.c new file mode 100644 index 00000000..53582f9c --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_barrierattr_setpshared.c @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_COND_ATTR_VALUE_MIN (-1) +#define TEST_COND_ATTR_VALUE_MAX 2 + +/** + * @tc.name : pthread_barrierattr_setpshared_0100 + * @tc.desc : Correct parameter setting barrier variable property value + * @tc.level : Level 0 + */ +void pthread_barrierattr_setpshared_0100(void) +{ + pthread_barrierattr_t attr; + int result = -1; + int shared = 0; + + int ret = pthread_barrierattr_init(&attr); + EXPECT_EQ("pthread_barrierattr_setpshared_0100", ret, CMPFLAG); + ret = pthread_barrierattr_setpshared(&attr, shared); + EXPECT_EQ("pthread_barrierattr_setpshared_0100", ret, CMPFLAG); + + shared = 1; + ret = pthread_barrierattr_setpshared(&attr, shared); + EXPECT_EQ("pthread_barrierattr_setpshared_0100", ret, CMPFLAG); + + pthread_barrierattr_destroy(&attr); +} + +/** + * @tc.name : pthread_barrierattr_setpshared_0200 + * @tc.desc : Exception parameter sets barrier variable property value + * @tc.level : Level 2 + */ +void pthread_barrierattr_setpshared_0200(void) +{ + pthread_barrierattr_t attr; + + int ret = pthread_barrierattr_init(&attr); + EXPECT_EQ("pthread_barrierattr_setpshared_0200", ret, 0); + + ret = pthread_barrierattr_setpshared(&attr, TEST_COND_ATTR_VALUE_MIN); + EXPECT_EQ("pthread_barrierattr_setpshared_0200", ret, EINVAL); + + ret = pthread_barrierattr_setpshared(&attr, TEST_COND_ATTR_VALUE_MAX); + EXPECT_EQ("pthread_barrierattr_setpshared_0200", ret, EINVAL); + + pthread_barrierattr_destroy(&attr); +} + +int main(void) +{ + pthread_barrierattr_setpshared_0100(); + pthread_barrierattr_setpshared_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_cond_broadcast.c b/libc-test/src/functionalext/supplement/thread/pthread_cond_broadcast.c new file mode 100644 index 00000000..df3591cf --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_cond_broadcast.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; + +/** + * @tc.name : pthread_cond_broadcast_0100 + * @tc.desc : The function will unlock all threads waiting for the condition variable, + * the parameters are valid, and the function can return normally + * @tc.level : Level 0 + */ +void pthread_cond_broadcast_0100(void) +{ + static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; + int back = pthread_cond_broadcast(&cond); + EXPECT_EQ("pthread_cond_broadcast_0100", back, SUCCESS); +} + +int main() +{ + pthread_cond_broadcast_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_cond_destroy.c b/libc-test/src/functionalext/supplement/thread/pthread_cond_destroy.c new file mode 100644 index 00000000..24ec6a85 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_cond_destroy.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; + +/** + * @tc.name : pthread_cond_destroy_0100 + * @tc.desc : The parameter is valid, and the parameter assignment can be passed normally + * @tc.level : Level 0 + */ +void pthread_cond_destroy_0100() +{ + pthread_cond_t attr; + int result = pthread_cond_init(&attr, NULL); + if (result != 0) { + t_error("%s pthread_cond_init failed\n", __func__); + } + result = pthread_cond_destroy(&attr); + if (result != 0) { + t_error("%s pthread_cond_destroy failed\n", __func__); + } +} + +int main() +{ + pthread_cond_destroy_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_cond_init.c b/libc-test/src/functionalext/supplement/thread/pthread_cond_init.c new file mode 100644 index 00000000..bf6f61bd --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_cond_init.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; + +/** + * @tc.name : pthread_cond_init_0100 + * @tc.desc : The pthread_cond_init initialization parameter is valid, + * and the parameter assignment can be passed normally + * @tc.level : Level 0 + */ +void pthread_cond_init_0100() +{ + static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; + int back = pthread_cond_init(&cond, NULL); + EXPECT_EQ("pthread_cond_init_0100", back, SUCCESS); +} + +/** + * @tc.name : pthread_cond_init_0200 + * @tc.desc : The pthread_cond_init initialization parameter is valid, + * the parameter assignment can be passed normally, and the thread can be created normally + * @tc.level : Level 0 + */ +void pthread_cond_init_0200() +{ + static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; + const pthread_condattr_t a; + int back = pthread_cond_init(&cond, &a); + EXPECT_EQ("pthread_cond_init_0200", back, SUCCESS); +} + +int main() +{ + pthread_cond_init_0100(); + pthread_cond_init_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_cond_signal.c b/libc-test/src/functionalext/supplement/thread/pthread_cond_signal.c new file mode 100644 index 00000000..25be2b1e --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_cond_signal.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; + +/** + * @tc.name : pthread_cond_signal_0100 + * @tc.desc : The pthread_cond_signal parameter is valid and returns correctly. + * @tc.level : Level 0 + */ +void pthread_cond_signal_0100(void) +{ + pthread_cond_t cond = PTHREAD_COND_INITIALIZER; + int back = pthread_cond_signal(&cond); + EXPECT_EQ("pthread_cond_signal_0100", back, SUCCESS); +} + +int main() +{ + pthread_cond_signal_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_cond_timedwait.c b/libc-test/src/functionalext/supplement/thread/pthread_cond_timedwait.c new file mode 100644 index 00000000..d7e7634e --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_cond_timedwait.c @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" +int flag = 0; +static pthread_cond_t gcond; +static pthread_mutex_t gmutex; +struct timespec gtm; + +void *threadfuncA(void *arg) +{ + struct timeval now; + struct timespec outtime; + gtm.tv_nsec = 1; + pthread_mutex_lock(&gmutex); + gettimeofday(&now, NULL); + outtime.tv_sec = now.tv_sec + 5; + outtime.tv_nsec = now.tv_usec * 1000; + pthread_cond_timedwait(&gcond, &gmutex, &outtime); + flag++; + pthread_mutex_unlock(&gmutex); + return arg; +} + +void *threadfuncB(void *arg) +{ + pthread_mutex_lock(&gmutex); + pthread_cond_signal(&gcond); + pthread_mutex_unlock(&gmutex); + return arg; +} + +/** + * @tc.name: pthread_cond_timedwait_0100 + * @tc.desc: Verify pthread create process success + * @tc.level: level 0. + */ +void pthread_cond_timedwait_0100(void) +{ + pthread_t pid1, pid2; + pthread_create(&pid1, NULL, threadfuncA, NULL); + pthread_create(&pid2, NULL, threadfuncB, NULL); + pthread_join(pid1, NULL); + pthread_join(pid2, NULL); + EXPECT_EQ("pthread_cond_timedwait_0200", flag, 1); + pthread_mutex_destroy(&gmutex); + pthread_cond_destroy(&gcond); +} + +int main(void) +{ + pthread_cond_timedwait_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_cond_wait.c b/libc-test/src/functionalext/supplement/thread/pthread_cond_wait.c new file mode 100644 index 00000000..44e67d66 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_cond_wait.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +pthread_cond_t cond; +pthread_mutex_t mutex; +int flag = 0; +pthread_t pid1; +pthread_t pid2; + +void *threadfunc1(void *arg) +{ + pthread_mutex_lock(&mutex); + pthread_cond_wait(&cond, &mutex); + flag++; + return 0; +} + +void *threadfunc2(void *arg) +{ + sleep(1); + pthread_mutex_lock(&mutex); + pthread_cond_signal(&cond); + if (flag != 1) { + t_error("pthread_cond_wait_0100 pthread_cond_wait error get flag is %d are not want 1\n", flag); + } + return 0; +} + +/** + * @tc.name : pthread_cond_wait_0100 + * @tc.desc : The parameter is valid, verify that the condition variable is activated + * @tc.level : Level 0 + */ +void pthread_cond_wait_0100(void) +{ + pthread_create(&pid1, NULL, threadfunc1, NULL); + pthread_create(&pid2, NULL, threadfunc2, NULL); +} + +int main(int argc, char *argv[]) +{ + pthread_cond_wait_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_condattr_destroy.c b/libc-test/src/functionalext/supplement/thread/pthread_condattr_destroy.c new file mode 100644 index 00000000..cd03872b --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_condattr_destroy.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_condattr_destroy_0100 + * @tc.desc : Verify pthread_condattr_destroy process succes + * @tc.level : Level 1 + */ +void pthread_condattr_destroy_0100(void) +{ + pthread_condattr_t condattr; + pthread_condattr_init(&condattr); + int32_t ret = pthread_condattr_destroy(&condattr); + EXPECT_EQ("pthread_condattr_destroy_0100", ret, 0); +} + +int main(void) +{ + pthread_condattr_destroy_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_condattr_init.c b/libc-test/src/functionalext/supplement/thread/pthread_condattr_init.c new file mode 100644 index 00000000..12776051 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_condattr_init.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_condattr_init_0100 + * @tc.desc : Verify pthread_condattr_init process success + * @tc.level : Level 1 + */ +void pthread_condattr_init_0100(void) +{ + pthread_condattr_t condattr; + int32_t ret = pthread_condattr_init(&condattr); + EXPECT_EQ("pthread_condattr_init_0100", ret, 0); + pthread_condattr_destroy(&condattr); +} + +int main(void) +{ + pthread_condattr_init_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_condattr_setclock.c b/libc-test/src/functionalext/supplement/thread/pthread_condattr_setclock.c new file mode 100755 index 00000000..cf20ad8c --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_condattr_setclock.c @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_CONDATTR_VALUE 60 +#define TEST_CONDATTR_ERROR_VALUE 3 + +/** + * @tc.name : pthread_condattr_setclock_0100 + * @tc.desc : Correct parameters, set the clock property of the condition variable + * @tc.level : Level 0 + */ +void pthread_condattr_setclock_0100(void) +{ + pthread_condattr_t attr; + pthread_condattr_init(&attr); + int ret = pthread_condattr_setclock(&attr, TEST_CONDATTR_VALUE); + EXPECT_EQ("pthread_condattr_setclock_0100", ret, CMPFLAG); + pthread_condattr_destroy(&attr); +} + +/** + * @tc.name : pthread_condattr_setclock_0200 + * @tc.desc : Error parameter, set the clock property of the condition variable + * @tc.level : Level 0 + */ +void pthread_condattr_setclock_0200(void) +{ + pthread_condattr_t attr; + pthread_condattr_init(&attr); + int ret = pthread_condattr_setclock(&attr, -1); + EXPECT_EQ("pthread_condattr_setclock_0200", ret, EINVAL); + + ret = pthread_condattr_setclock(&attr, TEST_CONDATTR_ERROR_VALUE); + EXPECT_EQ("pthread_condattr_setclock_0200", ret, EINVAL); + + pthread_condattr_destroy(&attr); +} + +int main(void) +{ + pthread_condattr_setclock_0100(); + pthread_condattr_setclock_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_condattr_setpshared.c b/libc-test/src/functionalext/supplement/thread/pthread_condattr_setpshared.c new file mode 100644 index 00000000..36de11ab --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_condattr_setpshared.c @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_COND_ATTR_VALUE 2 +/** + * @tc.name : pthread_condattr_setpshared_0100 + * @tc.desc : Correct parameter setting condition variable property value + * @tc.level : Level 0 + */ +void pthread_condattr_setpshared_0100(void) +{ + pthread_condattr_t attr; + int ret = pthread_condattr_init(&attr); + EXPECT_EQ("pthread_condattr_setpshared_0100", ret, 0); + + ret = pthread_condattr_setpshared(&attr, 1); + EXPECT_EQ("pthread_condattr_setpshared_0100", ret, 0); + pthread_condattr_destroy(&attr); +} + +/** + * @tc.name : pthread_condattr_setpshared_0200 + * @tc.desc : Exception parameter sets condition variable property value + * @tc.level : Level 2 + */ +void pthread_condattr_setpshared_0200(void) +{ + pthread_condattr_t attr; + int ret = pthread_condattr_init(&attr); + EXPECT_EQ("pthread_condattr_setpshared_0200", ret, 0); + + ret = pthread_condattr_setpshared(&attr, TEST_COND_ATTR_VALUE); + EXPECT_EQ("pthread_condattr_setpshared_0200", ret, EINVAL); + pthread_condattr_destroy(&attr); +} + +int main(void) +{ + pthread_condattr_setpshared_0100(); + pthread_condattr_setpshared_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_create.c b/libc-test/src/functionalext/supplement/thread/pthread_create.c new file mode 100644 index 00000000..60abb53a --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_create.c @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +int32_t COUNT = 0; +const int32_t INIT_LEN = 0; +const int32_t INCREASE_LEN = 1; +const int32_t PTHREADSTACK = 0x4001; +const char *URL = "http://c.test.com"; + +void *threadfuncA(void *arg) +{ + COUNT++; + return arg; +} + +void *threadfunc(void *arg) +{ + return arg; +} + +/** + * @tc.name: pthread_create_0100 + * @tc.desc: Verify pthread create process sucess when attrp and arg is NULL. + * @tc.level: level 0. + */ +void pthread_create_0100(void) +{ + pthread_t ph; + int32_t ret = pthread_create(&ph, NULL, threadfuncA, NULL); + pthread_join(ph, NULL); + EXPECT_EQ("pthread_create_0100", ret, INIT_LEN); + EXPECT_EQ("pthread_create_0100", COUNT, INCREASE_LEN); +} + +/** + * @tc.name: pthread_create_0200 + * @tc.desc: Verify pthread create process sucess when attrp is NULL. + * @tc.level: level 0. + */ +void pthread_create_0200(void) +{ + pthread_t ph; + int32_t ret = pthread_create(&ph, NULL, threadfunc, (char *)(URL)); + pthread_join(ph, NULL); + EXPECT_EQ("pthread_create_0200", ret, INIT_LEN); +} + +/** + * @tc.name: pthread_create_0300 + * @tc.desc: Verify pthread create process sucess when attrp is NULL. + * @tc.level: level 1. + */ +void pthread_create_0300(void) +{ + pthread_t ph; + pthread_attr_t atrr; + + pthread_attr_init(&atrr); + int32_t ret = pthread_create(&ph, &atrr, threadfunc, (char *)(URL)); + pthread_join(ph, NULL); + EXPECT_EQ("pthread_create_0300", ret, INIT_LEN); +} + +/** + * @tc.name: pthread_create_0400 + * @tc.desc: Verify pthread create process sucess when stackAddr is null. + * @tc.level: level 1 + */ +void pthread_create_0400(void) +{ + int32_t ret; + pthread_t ph; + void *stackAddr = NULL; + pthread_attr_t attr; + int32_t pageSize = getpagesize(); + pthread_attr_init(&attr); + ret = posix_memalign(&stackAddr, pageSize, PTHREADSTACK); + if (ret) { + EXPECT_NE("pthread_create_0400", ret, 0); + return; + } + ret = pthread_attr_setstack(&attr, stackAddr, PTHREADSTACK); + if (ret) { + EXPECT_NE("pthread_create_0400", ret, 0); + return; + } + ret = pthread_create(&ph, &attr, threadfunc, (char *)(URL)); + pthread_join(ph, NULL); + pthread_attr_destroy(&attr); + EXPECT_EQ("pthread_create_0400", ret, INIT_LEN); +} + +/** + * @tc.name: pthread_create_0500 + * @tc.desc: Verify pthread_create success when pthread is detached. + * @tc.level: levlel 1 + */ +void pthread_create_0500(void) +{ + pthread_t ph; + pthread_attr_t attr; + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + int32_t ret = pthread_create(&ph, &attr, threadfunc, (char *)(URL)); + EXPECT_EQ("pthread_create_0500", ret, INIT_LEN); +} + +int main(void) +{ + pthread_create_0100(); + pthread_create_0200(); + pthread_create_0300(); + pthread_create_0400(); + pthread_create_0500(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_detach.c b/libc-test/src/functionalext/supplement/thread/pthread_detach.c new file mode 100644 index 00000000..14b4d17b --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_detach.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" +int flag = 0; +const int SLEEPTIME = 3; + +void *threadfunc(void *arg) +{ + sleep(1); + flag++; + pthread_exit(0); + return arg; +} + +/** + * @tc.name: pthread_detach_0100 + * @tc.desc: Verify pthread_detach process sucess + * @tc.level: level 0. + */ +void pthread_detach_0100(void) +{ + pthread_t pid; + flag = 0; + pthread_create(&pid, NULL, threadfunc, NULL); + pthread_detach(pid); + EXPECT_EQ("pthread_detach_0100", flag, 0); + sleep(SLEEPTIME); +} + +int main(void) +{ + pthread_detach_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_equal.c b/libc-test/src/functionalext/supplement/thread/pthread_equal.c new file mode 100644 index 00000000..cb576e3b --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_equal.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "test.h" + +static pthread_t g_pthd_1, g_pthd_2; + +void *threadfuncA(void *arg) +{ + g_pthd_1 = pthread_self(); + return arg; +} + +void *threadfuncB(void *arg) +{ + pthread_t pth = pthread_self(); + int ret = pthread_equal(g_pthd_1, pth); + if (ret != 0) { + t_error("%s two should not equal, ret is %d\n", __func__, ret); + } + return arg; +} + +void *threadfuncC(void *arg) +{ + int ret = pthread_equal(g_pthd_2, pthread_self()); + if (ret == 0) { + t_error("%s the same thread, the result should be greater than zero, ret = %d\n", __func__, ret); + } + return arg; +} + +/** + * @tc.name : pthread_equal_0100 + * @tc.desc : Compare two different threads + * @tc.level : Level 0 + */ +void pthread_equal_0100(void) +{ + pthread_t pthread1, pthread2; + int result; + + result = pthread_create(&pthread1, NULL, threadfuncA, NULL); + if (result != 0) { + t_error("%s pthread_create failed\n", __func__); + return; + } + result = pthread_create(&pthread2, NULL, threadfuncB, NULL); + if (result != 0) { + t_error("%s pthread_create failed\n", __func__); + return; + } + + result = pthread_join(pthread1, NULL); + if (result != 0) { + t_error("%s pthread_join failed, result is %d\n", __func__, result); + } + pthread_join(pthread2, NULL); + if (result != 0) { + t_error("%s pthread_join failed, result is %d\n", __func__, result); + } +} + +/** + * @tc.name : pthread_equal_0200 + * @tc.desc : Compare the same thread + * @tc.level : Level 0 + */ +void pthread_equal_0200(void) +{ + int result; + + result = pthread_create(&g_pthd_2, NULL, threadfuncC, NULL); + if (result != 0) { + t_error("%s pthread_create failed\n", __func__); + return; + } + + result = pthread_join(g_pthd_2, NULL); + if (result != 0) { + t_error("%s pthread_join failed, result is %d\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + pthread_equal_0100(); + pthread_equal_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_exit.c b/libc-test/src/functionalext/supplement/thread/pthread_exit.c new file mode 100644 index 00000000..49568e20 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_exit.c @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +void *threadfuncA(void *arg) +{ + pthread_exit("pthread_exit_0100"); + return arg; +} + +/** + * @tc.name : pthread_exit_0100 + * @tc.desc : Verify pthread_exit process success + * @tc.level : Level 1 + */ +void pthread_exit_0100(void) +{ + pthread_t ph; + int32_t ret = pthread_create(&ph, NULL, threadfuncA, NULL); + void *thread_result = NULL; + pthread_join(ph, &thread_result); + EXPECT_STREQ("pthread_exit_0100", (char *)thread_result, "pthread_exit_0100"); +} + +int main(void) +{ + pthread_exit_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_getattr_np.c b/libc-test/src/functionalext/supplement/thread/pthread_getattr_np.c new file mode 100644 index 00000000..63c77783 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_getattr_np.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +void *threadfuncA(void *arg) +{ + return arg; +} + +/** + * @tc.name : pthread_getattr_np_0100 + * @tc.desc : Verify pthread_getattr_np process success + * @tc.level : Level 0 + */ +void pthread_getattr_np_0100(void) +{ + pthread_t ph; + pthread_create(&ph, NULL, threadfuncA, NULL); + pthread_attr_t attr; + pthread_attr_init(&attr); + void *thread_result = NULL; + int32_t ret = pthread_getattr_np(ph, &attr); + pthread_attr_destroy(&attr); + pthread_join(ph, &thread_result); + void *stack = NULL; + size_t stacksize; + pthread_attr_getstack(&attr, &stack, &stacksize); + EXPECT_PTRNE("pthread_getattr_np_0100", stack, NULL); +} + +int main(void) +{ + pthread_getattr_np_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_getcpuclockid.c b/libc-test/src/functionalext/supplement/thread/pthread_getcpuclockid.c new file mode 100644 index 00000000..29a49eff --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_getcpuclockid.c @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +int gthread_exit_flag = 0; +static void *thread_func(void *arg) +{ + for (;;) { + if (gthread_exit_flag) { + break; + } else { + continue; + } + } + return (void *)0; +} + +/** + * @tc.name : pthread_getcpuclockid_0100 + * @tc.desc : Get the specified thread clock ID + * @tc.level : Level 0 + */ +void pthread_getcpuclockid_0100(void) +{ + pthread_t thread; + clockid_t cid; + int ret = pthread_create(&thread, NULL, thread_func, NULL); + EXPECT_EQ("pthread_getcpuclockid_0100", ret, 0); + ret = pthread_getcpuclockid(pthread_self(), &cid); + EXPECT_EQ("pthread_getcpuclockid_0100", ret, 0); + EXPECT_TRUE("pthread_getcpuclockid_0100", cid != 0); + + ret = pthread_getcpuclockid(thread, &cid); + EXPECT_EQ("pthread_getcpuclockid_0100", ret, 0); + EXPECT_TRUE("pthread_getcpuclockid_0100", cid != 0); + gthread_exit_flag = 1; + sleep(1); +} + +int main(void) +{ + pthread_getcpuclockid_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_getschedparam.c b/libc-test/src/functionalext/supplement/thread/pthread_getschedparam.c new file mode 100644 index 00000000..b70ef8e7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_getschedparam.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +void *threadfuncA(void *arg) +{ + return arg; +} + +/** + * @tc.name : pthread_getschedparam_0100 + * @tc.desc : Verify pthread_getschedparam process success + * @tc.level : Level 1 + */ +void pthread_getschedparam_0100(void) +{ + pthread_t ph; + pthread_create(&ph, NULL, threadfuncA, NULL); + int policy = 0; + struct sched_param sp; + int32_t ret = pthread_getschedparam(ph, &policy, &sp); + void *thread_result = NULL; + pthread_join(ph, &thread_result); + EXPECT_EQ("pthread_getschedparam_0100", ret, 0); +} + +int main(void) +{ + pthread_getschedparam_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_getspecific.c b/libc-test/src/functionalext/supplement/thread/pthread_getspecific.c new file mode 100644 index 00000000..72d1a21c --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_getspecific.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +static pthread_key_t g_key; + +void *threadfuncA(void *arg) +{ + int32_t value = 0; + int32_t ret = pthread_setspecific(g_key, &value); + EXPECT_EQ("pthread_getspecific_0100", ret, 0); + int32_t *keyRet = (int32_t *)pthread_getspecific(g_key); + EXPECT_EQ("pthread_getspecific_0100", *keyRet, 0); + return arg; +} + +/** + * @tc.name: pthread_getspecific_0100 + * @tc.desc: Verify pthread_getspecific process success. + * @tc.level: level 0 + */ +void pthread_getspecific_0100(void) +{ + pthread_key_create(&g_key, NULL); + pthread_t tid1; + pthread_create(&tid1, NULL, threadfuncA, NULL); + pthread_join(tid1, NULL); + pthread_key_delete(g_key); +} + +int main(void) +{ + pthread_getspecific_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_join.c b/libc-test/src/functionalext/supplement/thread/pthread_join.c new file mode 100644 index 00000000..a2808751 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_join.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +pthread_t pid; +int flag = 0; + +void *threadfunc(void *arg) +{ + sleep(2); + flag++; + return 0; +} + +/** + * @tc.name : pthread_join_0100 + * @tc.desc : The parameters are valid, verify that the main thread does not wait for other threads to end the + * scene + * @tc.level : Level 0 + */ +void pthread_join_0100(void) +{ + flag = 0; + pthread_create(&pid, NULL, threadfunc, NULL); + int result = pthread_join(pid, NULL); + if (result != 0) { + t_error("%s pthread_join error get result is %d are not want 0\n", __func__, result); + } + if (flag != 1) { + t_error("%s pthread_join error get flag is %d are not want 1\n", __func__, flag); + } +} + +int main(int argc, char *argv[]) +{ + pthread_join_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_key_create.c b/libc-test/src/functionalext/supplement/thread/pthread_key_create.c new file mode 100644 index 00000000..81ddfb3a --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_key_create.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +static int32_t g_sleep_time = 2; +static pthread_key_t g_key; + +void *threadfuncA(void *arg) +{ + sleep(g_sleep_time); + int32_t value = 0; + int32_t ret = pthread_setspecific(g_key, &value); + EXPECT_EQ("pthread_key_create_0100_threadfuncA", ret, 0); + int32_t *keyRet = (int32_t *)pthread_getspecific(g_key); + EXPECT_EQ("pthread_key_create_0100_threadfuncA", *keyRet, 0); + return arg; +} + +void *threadfuncB(void *arg) +{ + int32_t value = 0; + int32_t ret = pthread_setspecific(g_key, &value); + EXPECT_EQ("pthread_key_create_0200_threadfuncB", ret, 0); + int32_t *keyRet = (int32_t *)pthread_getspecific(g_key); + EXPECT_EQ("pthread_key_create_0200_threadfuncB", *keyRet, 0); + return arg; +} + +void testfunc(void *arg) +{} + +/** + * @tc.name: pthread_key_create_0100 + * @tc.desc: Verify pthread_key_create process success when second args is null. + * @tc.desc: level 0 + */ +void pthread_key_create_0100(void) +{ + pthread_t tid1; + pthread_create(&tid1, NULL, threadfuncA, NULL); + int32_t ret = pthread_key_create(&g_key, NULL); + EXPECT_EQ("pthread_key_create_0100", ret, 0); + pthread_join(tid1, NULL); + pthread_key_delete(g_key); +} + +/** + * @tc.name: pthread_key_create_0200 + * @tc.desc: Verify pthread_key_create process success when second args is not null. + * @tc.desc: level 1 + */ +void pthread_key_create_0200(void) +{ + pthread_t tid2; + int32_t ret = pthread_key_create(&g_key, testfunc); + pthread_create(&tid2, NULL, threadfuncB, NULL); + pthread_join(tid2, NULL); + EXPECT_EQ("pthread_key_create_0200", ret, 0); +} + +int main(void) +{ + pthread_key_create_0100(); + pthread_key_create_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_key_delete.c b/libc-test/src/functionalext/supplement/thread/pthread_key_delete.c new file mode 100644 index 00000000..b6c3d35e --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_key_delete.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : pthread_key_delete_0100 + * @tc.desc : The parameter is valid, verify that the specified data key of the destroy thread is successful + * @tc.level : Level 0 + */ +void pthread_key_delete_0100(void) +{ + pthread_key_t key; + pthread_key_create(&key, NULL); + int result = pthread_key_delete(key); + if (result != 0) { + t_error("%s pthread_key_delete error get result is %d are not want 0\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + pthread_key_delete_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_mutex_destroy.c b/libc-test/src/functionalext/supplement/thread/pthread_mutex_destroy.c new file mode 100644 index 00000000..4356e152 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_mutex_destroy.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : pthread_mutex_destroy_0100 + * @tc.desc : The parameters are valid, verify that the mutex is destroyed successfully + * @tc.level : Level 0 + */ +void pthread_mutex_destroy_0100(void) +{ + pthread_mutex_t mutex; + pthread_mutex_init(&mutex, NULL); + int result = pthread_mutex_destroy(&mutex); + if (result != 0) { + t_error("%s pthread_mutex_destroy error get result is %d are not want 0\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + pthread_mutex_destroy_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_mutex_init.c b/libc-test/src/functionalext/supplement/thread/pthread_mutex_init.c new file mode 100644 index 00000000..701f902a --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_mutex_init.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +static pthread_mutex_t g_mutex; + +/** + * @tc.name: pthread_mutex_init_0100 + * @tc.desc: Verify pthread_mutex_init process success when second args is null. + * @tc.desc: level 0 + */ +void pthread_mutex_init_0100(void) +{ + int32_t ret = pthread_mutex_init(&g_mutex, NULL); + EXPECT_EQ("pthread_mutex_init_0100", ret, 0); +} + +/** + * @tc.name: pthread_mutex_init_0200 + * @tc.desc: Verify pthread_mutex_init process success when second args is PTHREAD_MUTEX_RECURSIVE. + * @tc.desc: level 1 + */ +void pthread_mutex_init_0200(void) +{ + int32_t type = PTHREAD_MUTEX_RECURSIVE; + int32_t ret = pthread_mutex_init(&g_mutex, (pthread_mutexattr_t *)(&type)); + EXPECT_EQ("pthread_mutex_init_0200", ret, 0); +} + +/** + * @tc.name: pthread_mutex_init_0300 + * @tc.desc: Verify pthread_mutex_init process success when second args is PTHREAD_MUTEX_RECURSIVE. + * @tc.desc: level 1 + */ +void pthread_mutex_init_0300(void) +{ + int32_t type = PTHREAD_MUTEX_ERRORCHECK; + int32_t ret = pthread_mutex_init(&g_mutex, (pthread_mutexattr_t *)(&type)); + EXPECT_EQ("pthread_mutex_init_0300", ret, 0); +} + +int main(void) +{ + pthread_mutex_init_0100(); + pthread_mutex_init_0200(); + pthread_mutex_init_0300(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_mutex_lock.c b/libc-test/src/functionalext/supplement/thread/pthread_mutex_lock.c new file mode 100644 index 00000000..8eb95e78 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_mutex_lock.c @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +static pthread_mutex_t g_mutex; +static int32_t g_count = 0; +static int32_t g_run_max_count = 10000; + +void *threadfuncA(void *arg) +{ + int32_t ret = pthread_mutex_lock(&g_mutex); + EXPECT_EQ("pthread_mutex_lock_0100", ret, 0); + pthread_mutex_unlock(&g_mutex); + return arg; +} + +void *threadfuncB(void *arg) +{ + int32_t ret = pthread_mutex_lock(&g_mutex); + ret = pthread_mutex_lock(&g_mutex); + EXPECT_EQ("pthread_mutex_lock_0200", ret, 0); + pthread_mutex_unlock(&g_mutex); + return arg; +} + +void *threadfuncC(void *arg) +{ + g_count++; + int32_t ret = pthread_mutex_lock(&g_mutex); + if (g_count == INT_MAX) { + EXPECT_EQ("pthread_mutex_lock_0300", ret, EAGAIN); + } + pthread_mutex_unlock(&g_mutex); + return arg; +} + +void *threadfuncD(void *arg) +{ + int32_t ret = pthread_mutex_lock(&g_mutex); + ret = pthread_mutex_lock(&g_mutex); + EXPECT_EQ("pthread_mutex_lock_0400", ret, EDEADLK); + pthread_mutex_unlock(&g_mutex); + return arg; +} + +/** + * @tc.name: pthread_mutex_lock_0100 + * @tc.desc: Verify process pthread_mutex_lock once success when pthread_mutex_init second args is null. + * @tc.level: level 0 + */ +void pthread_mutex_lock_0100(void) +{ + pthread_mutex_init(&g_mutex, NULL); + pthread_t tid1; + int32_t ret = pthread_create(&tid1, NULL, threadfuncA, NULL); + pthread_join(tid1, NULL); +} + +/** + * @tc.name: pthread_mutex_lock_0200 + * @tc.desc: Verify process pthread_mutex_lock twice success when pthread_mutex_init second args is + * PTHREAD_MUTEX_NORMAL. + * @tc.level: level 1 + */ +void pthread_mutex_lock_0200(void) +{ + int32_t type = PTHREAD_MUTEX_RECURSIVE; + pthread_mutex_init(&g_mutex, (pthread_mutexattr_t *)(&type)); + pthread_t tid2; + pthread_create(&tid2, NULL, threadfuncB, NULL); + pthread_join(tid2, NULL); +} + +/** + * @tc.name: pthread_mutex_lock_0300 + * @tc.desc: Verify process pthread_mutex_lock once success when pthread_mutex_init second args is + * PTHREAD_MUTEX_RECURSIVE. + * @tc.level: level 2 + */ +void pthread_mutex_lock_0300(void) +{ + int32_t type = PTHREAD_MUTEX_RECURSIVE; + pthread_mutex_init(&g_mutex, (pthread_mutexattr_t *)(&type)); + pthread_t tid3; + for (int32_t i = 0; i <= g_run_max_count; i++) { + pthread_create(&tid3, NULL, threadfuncC, NULL); + pthread_join(tid3, NULL); + } +} + +/** + * @tc.name: pthread_mutex_lock_0400 + * @tc.desc: Verify process pthread_mutex_lock twice success when pthread_mutex_init second args is + * PTHREAD_MUTEX_RECURSIVE. + * @tc.level: level 2 + */ +void pthread_mutex_lock_0400(void) +{ + int32_t type = PTHREAD_MUTEX_ERRORCHECK; + pthread_mutex_init(&g_mutex, (pthread_mutexattr_t *)(&type)); + pthread_t tid4; + pthread_create(&tid4, NULL, threadfuncD, NULL); + pthread_join(tid4, NULL); +} + +int main(void) +{ + pthread_mutex_lock_0100(); + pthread_mutex_lock_0200(); + pthread_mutex_lock_0300(); + pthread_mutex_lock_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_mutex_timedlock.c b/libc-test/src/functionalext/supplement/thread/pthread_mutex_timedlock.c new file mode 100644 index 00000000..c3a51ce1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_mutex_timedlock.c @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define TEST_MUTEX_ATTR 15 + +/** + * @tc.name : pthread_mutex_timedlock_0100 + * @tc.desc : Provide correct parameters, test timeout and lock + * @tc.level : Level 0 + */ +void pthread_mutex_timedlock_0100(void) +{ + struct timespec ts = {.tv_nsec = 0, .tv_sec = 1}; + pthread_mutexattr_t mutex_attr; + pthread_mutex_t mutex; + pthread_mutexattr_init(&mutex_attr); + pthread_mutexattr_settype(&mutex_attr, TEST_MUTEX_ATTR); + pthread_mutex_init(&mutex, &mutex_attr); + + int rev = pthread_mutex_timedlock(&mutex, &ts); + EXPECT_EQ("pthread_mutex_timedlock_0100", rev, 0); + + pthread_mutex_unlock(&mutex); + pthread_mutex_destroy(&mutex); + pthread_mutexattr_destroy(&mutex_attr); +} + +/** + * @tc.name : pthread_mutex_timedlock_0200 + * @tc.desc : The lock attribute is PTHREAD_MUTEX_ERRORCHECK, and the test timeout is locked + * @tc.level : Level 0 + */ +void pthread_mutex_timedlock_0200(void) +{ + struct timespec ts = {.tv_nsec = 0, .tv_sec = 1}; + pthread_mutexattr_t mutex_attr; + pthread_mutex_t mutex; + + pthread_mutexattr_init(&mutex_attr); + pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK); + pthread_mutex_init(&mutex, &mutex_attr); + int rev = pthread_mutex_timedlock(&mutex, &ts); + EXPECT_EQ("pthread_mutex_timedlock_0200", rev, 0); + + pthread_mutex_unlock(&mutex); + pthread_mutex_destroy(&mutex); + pthread_mutexattr_destroy(&mutex_attr); +} + +/** + * @tc.name : pthread_mutex_timedlock_0300 + * @tc.desc : In the locked state, the test times out and locks + * @tc.level : Level 2 + */ +void pthread_mutex_timedlock_0300(void) +{ + struct timespec ts = {.tv_nsec = 0, .tv_sec = 1}; + pthread_mutexattr_t mutex_attr; + pthread_mutex_t mutex; + pthread_mutexattr_init(&mutex_attr); + pthread_mutexattr_settype(&mutex_attr, TEST_MUTEX_ATTR); + pthread_mutex_init(&mutex, &mutex_attr); + int rev = pthread_mutex_lock(&mutex); + EXPECT_EQ("pthread_mutex_timedlock_0300", rev, 0); + rev = pthread_mutex_timedlock(&mutex, &ts); + EXPECT_EQ("pthread_mutex_timedlock_0300", rev, ETIMEDOUT); + + pthread_mutex_unlock(&mutex); + pthread_mutex_destroy(&mutex); + pthread_mutexattr_destroy(&mutex_attr); +} + +int main(void) +{ + pthread_mutex_timedlock_0100(); + pthread_mutex_timedlock_0200(); + pthread_mutex_timedlock_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_mutex_trylock.c b/libc-test/src/functionalext/supplement/thread/pthread_mutex_trylock.c new file mode 100644 index 00000000..3d5efe24 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_mutex_trylock.c @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +static pthread_mutex_t g_mutex; + +/** + * @tc.name: pthread_mutex_trylock_0100 + * @tc.desc: Verify process pthread_mutex_try_lock success + * @tc.level: level 0 + */ +void pthread_mutex_trylock_0100(void) +{ + pthread_mutex_init(&g_mutex, NULL); + int ret = pthread_mutex_trylock(&g_mutex); + EXPECT_EQ("pthread_mutex_lock_0100", ret, 0); + pthread_mutex_unlock(&g_mutex); +} + +/** + * @tc.name: pthread_mutex_trylock_0200 + * @tc.desc: Verify process pthread_mutex_try_lock fail + * @tc.level: level 2 + */ +void pthread_mutex_trylock_0200(void) +{ + pthread_mutex_init(&g_mutex, NULL); + pthread_mutex_lock(&g_mutex); + int ret = pthread_mutex_trylock(&g_mutex); + EXPECT_NE("pthread_mutex_lock_0200", ret, 0); + pthread_mutex_unlock(&g_mutex); +} + +int main(void) +{ + pthread_mutex_trylock_0100(); + pthread_mutex_trylock_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_mutex_unlock.c b/libc-test/src/functionalext/supplement/thread/pthread_mutex_unlock.c new file mode 100644 index 00000000..7184b8bf --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_mutex_unlock.c @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +static pthread_mutex_t g_mutex; + +void *threadfuncA(void *arg) +{ + int32_t ret = pthread_mutex_lock(&g_mutex); + ret = pthread_mutex_unlock(&g_mutex); + EXPECT_EQ("pthread_mutex_un_lock_0100", ret, 0); + return arg; +} + +void *threadfuncB(void *arg) +{ + pthread_mutex_lock(&g_mutex); + return arg; +} + +void *threadfuncC(void *arg) +{ + int32_t ret = pthread_mutex_unlock(&g_mutex); + EXPECT_EQ("pthread_mutex_un_lock_0200", ret, EPERM); + return arg; +} + +/** + * @tc.name: pthread_mutex_un_lock_0100 + * @tc.desc: Verify process pthread_mutex_un_lock once success. + * @tc.level: level 0. + */ +void pthread_mutex_un_lock_0100(void) +{ + int32_t type = PTHREAD_MUTEX_RECURSIVE; + pthread_mutex_init(&g_mutex, (pthread_mutexattr_t *)(&type)); + pthread_t tid1; + pthread_create(&tid1, NULL, threadfuncA, NULL); + pthread_join(tid1, NULL); +} + +/** + * @tc.name: pthread_mutex_un_lock_0200 + * @tc.desc: Verify process pthread_mutex_un_lock fail. Because can not release a mutex pointed to a mutex + * that is not this thread. + * @tc.level: level 2. + */ +void pthread_mutex_un_lock_0200(void) +{ + int32_t type = PTHREAD_MUTEX_RECURSIVE; + pthread_mutex_init(&g_mutex, (pthread_mutexattr_t *)(&type)); + pthread_t tid2, tid3; + pthread_create(&tid2, NULL, threadfuncB, NULL); + pthread_join(tid2, NULL); + pthread_create(&tid3, NULL, threadfuncC, NULL); + pthread_join(tid3, NULL); + pthread_mutex_destroy(&g_mutex); +} + +int main(void) +{ + pthread_mutex_un_lock_0100(); + pthread_mutex_un_lock_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_mutexattr_destroy.c b/libc-test/src/functionalext/supplement/thread/pthread_mutexattr_destroy.c new file mode 100644 index 00000000..8b9d4420 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_mutexattr_destroy.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_mutexattr_destroy_0100 + * @tc.desc : Verify pthread_mutexattr_destroy process succes + * @tc.level : Level 1 + */ +void pthread_mutexattr_destroy_0100(void) +{ + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + int32_t ret = pthread_mutexattr_destroy(&attr); + EXPECT_EQ("pthread_condattr_destroy_0100", ret, 0); +} + +int main(void) +{ + pthread_mutexattr_destroy_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_mutexattr_setprotocol.c b/libc-test/src/functionalext/supplement/thread/pthread_mutexattr_setprotocol.c new file mode 100644 index 00000000..ee02373a --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_mutexattr_setprotocol.c @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_mutexattr_setprotocol_0100 + * @tc.desc : Correct parameter setting condition variable property value + * @tc.level : Level 0 + */ +void pthread_mutexattr_setprotocol_0100(void) +{ + pthread_mutexattr_t attr; + int ret = pthread_mutexattr_init(&attr); + EXPECT_EQ("pthread_mutexattr_setprotocol_0100", ret, CMPFLAG); + + ret = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_NONE); + EXPECT_EQ("pthread_mutexattr_setprotocol_0100", ret, CMPFLAG); + + ret = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_PROTECT); + EXPECT_EQ("pthread_mutexattr_setprotocol_0100", ret, ENOTSUP); + + pthread_mutexattr_destroy(&attr); +} + +/** + * @tc.name : pthread_mutexattr_setprotocol_0200 + * @tc.desc : Exception parameter sets mutex variable property value + * @tc.level : Level 2 + */ +void pthread_mutexattr_setprotocol_0200(void) +{ + pthread_mutexattr_t attr; + int error = PTHREAD_PRIO_PROTECT + 1; + + int ret = pthread_mutexattr_init(&attr); + EXPECT_EQ("pthread_mutexattr_setprotocol_0200", ret, CMPFLAG); + + ret = pthread_mutexattr_setprotocol(&attr, error); + EXPECT_EQ("pthread_mutexattr_setprotocol_0200", ret, EINVAL); + + pthread_mutexattr_destroy(&attr); +} + +int main(void) +{ + pthread_mutexattr_setprotocol_0100(); + pthread_mutexattr_setprotocol_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_mutexattr_setpshared.c b/libc-test/src/functionalext/supplement/thread/pthread_mutexattr_setpshared.c new file mode 100755 index 00000000..47bd189e --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_mutexattr_setpshared.c @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_MUTEXT_ATTR_VALUE 2 + +/** + * @tc.name : pthread_mutexattr_setpshared_0100 + * @tc.desc : Correct parameter setting mutex attribute value + * @tc.level : Level 0 + */ +void pthread_mutexattr_setpshared_0100(void) +{ + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + int ret = pthread_mutexattr_setpshared(&attr, 1); + EXPECT_EQ("pthread_mutexattr_setpshared_0100", ret, CMPFLAG); + pthread_mutexattr_destroy(&attr); +} + +/** + * @tc.name : pthread_mutexattr_setpshared_0200 + * @tc.desc : Invalid parameter setting mutex attribute value + * @tc.level : Level 2 + */ +void pthread_mutexattr_setpshared_0200(void) +{ + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + int ret = pthread_mutexattr_setpshared(&attr, TEST_MUTEXT_ATTR_VALUE); + EXPECT_EQ("pthread_mutexattr_setpshared_0200", ret, EINVAL); + pthread_mutexattr_destroy(&attr); +} + +int main(void) +{ + pthread_mutexattr_setpshared_0100(); + pthread_mutexattr_setpshared_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_mutexattr_settype.c b/libc-test/src/functionalext/supplement/thread/pthread_mutexattr_settype.c new file mode 100644 index 00000000..1ba5d906 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_mutexattr_settype.c @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +static pthread_mutexattr_t gmutexattr; +const int INVALIDTYPE = 4; + +/** + * @tc.name: pthread_mutexattr_settype_0100 + * @tc.desc: Verify process pthread_mutexattr_settype success + * @tc.level: level 0 + */ +void pthread_mutexattr_settype_0100(void) +{ + pthread_mutexattr_init(&gmutexattr); + int ret = pthread_mutexattr_settype(&gmutexattr, PTHREAD_MUTEX_NORMAL); + EXPECT_EQ("pthread_mutexattr_settype", ret, 0); + pthread_mutexattr_destroy(&gmutexattr); +} + +/** + * @tc.name: pthread_mutexattr_settype_0200 + * @tc.desc: Verify process pthread_mutexattr_settype fail. Because type is invalid + * @tc.level: level 2 + */ +void pthread_mutexattr_settype_0200(void) +{ + pthread_mutexattr_init(&gmutexattr); + int ret = pthread_mutexattr_settype(&gmutexattr, INVALIDTYPE); + EXPECT_EQ("pthread_mutexattr_settype", ret, EINVAL); + pthread_mutexattr_destroy(&gmutexattr); +} + +int main(void) +{ + pthread_mutexattr_settype_0100(); + pthread_mutexattr_settype_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_once.c b/libc-test/src/functionalext/supplement/thread/pthread_once.c new file mode 100644 index 00000000..ed916c93 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_once.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +static pthread_once_t g_once = PTHREAD_ONCE_INIT; +static int32_t g_count = 0; + +void OnceRun(void) +{ + g_count++; +} + +void *threadfuncA(void *arg) +{ + int32_t ret = pthread_once(&g_once, OnceRun); + EXPECT_EQ("pthread_once_0100", ret, 0); + return arg; +} + +void *threadfuncB(void *arg) +{ + int32_t ret = pthread_once(&g_once, OnceRun); + EXPECT_EQ("pthread_once_0100", ret, 0); + return arg; +} + +/** + * @tc.name: pthread_once_0100 + * @tc.desc: Verify process pthread_mutex_once success. + * @tc.level: level 0. + */ +void pthread_once_0100(void) +{ + pthread_t tid1, tid2; + pthread_create(&tid1, NULL, threadfuncA, NULL); + pthread_create(&tid2, NULL, threadfuncB, NULL); + pthread_join(tid1, NULL); + pthread_join(tid2, NULL); +} + +int main(void) +{ + pthread_once_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_rwlock_destroy.c b/libc-test/src/functionalext/supplement/thread/pthread_rwlock_destroy.c new file mode 100644 index 00000000..c8982590 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_rwlock_destroy.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_rwlock_destroy_0100 + * @tc.desc : Verify pthread_rwlock_destroy process success + * @tc.level : Level 1 + */ +void pthread_rwlock_destroy_0100(void) +{ + pthread_rwlock_t rw_lock; + pthread_rwlock_init(&rw_lock, NULL); + int32_t ret = pthread_rwlock_destroy(&rw_lock); + EXPECT_EQ("pthread_rwlock_destroy_0100", ret, 0); +} + +int main(void) +{ + pthread_rwlock_destroy_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_rwlock_rdlock.c b/libc-test/src/functionalext/supplement/thread/pthread_rwlock_rdlock.c new file mode 100644 index 00000000..4ecff5d4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_rwlock_rdlock.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +#define TEST(c, ...) ((c) || (t_error(#c " failed: " __VA_ARGS__), 0)) +#define SLEEP_20_MS (20000) + +pthread_rwlock_t g_rwlock1; +static int number = 0; + +static void *pthreadRdlockR1(void *arg) +{ + TEST(pthread_rwlock_rdlock(&g_rwlock1) == 0); + number++; + TEST(pthread_rwlock_unlock(&g_rwlock1) == 0); + return arg; +} + +static void *pthreadRdlockR2(void *arg) +{ + usleep(SLEEP_20_MS); + TEST(pthread_rwlock_rdlock(&g_rwlock1) == 0); + number--; + TEST(pthread_rwlock_unlock(&g_rwlock1) == 0); + return arg; +} + +/** + * @tc.name : pthread_rwlock_rdlock_0100 + * @tc.desc : Verify read lock read-write lock success + * @tc.level : Level 0 + */ +void pthread_rwlock_rdlock_0100(void) +{ + pthread_t thread; + TEST(pthread_rwlock_init(&g_rwlock1, NULL) == 0); + TEST(pthread_rwlock_rdlock(&g_rwlock1) == 0); + TEST(pthread_rwlock_unlock(&g_rwlock1) == 0); + TEST(pthread_rwlock_destroy(&g_rwlock1) == 0); +} + +/** + * @tc.name : pthread_rwlock_rdlock_0200 + * @tc.desc : Verify that the read lock is successful for multiple read-write locks + * @tc.level : Level 1 + */ +void pthread_rwlock_rdlock_0200(void) +{ + pthread_t thread; + TEST(pthread_rwlock_init(&g_rwlock1, NULL) == 0); + TEST(pthread_rwlock_rdlock(&g_rwlock1) == 0); + TEST(pthread_rwlock_rdlock(&g_rwlock1) == 0); + TEST(pthread_rwlock_unlock(&g_rwlock1) == 0); + TEST(pthread_rwlock_unlock(&g_rwlock1) == 0); + TEST(pthread_rwlock_destroy(&g_rwlock1) == 0); +} + +/** + * @tc.name : pthread_rwlock_rdlock_0300 + * @tc.desc : Verify that the read lock read-write lock is successfully set multiple times + * @tc.level : Level 1 + */ +void pthread_rwlock_rdlock_0300(void) +{ + pthread_t tid[2]; + TEST(pthread_rwlock_init(&g_rwlock1, NULL) == 0); + + TEST(pthread_create(&tid[0], NULL, pthreadRdlockR1, NULL) == 0); + TEST(pthread_create(&tid[1], NULL, pthreadRdlockR2, NULL) == 0); + TEST(pthread_join(tid[0], NULL) == 0); + TEST(pthread_join(tid[1], NULL) == 0); + TEST(number == 0); + TEST(pthread_rwlock_destroy(&g_rwlock1) == 0); +} + +int main(int argc, char *argv[]) +{ + pthread_rwlock_rdlock_0100(); + pthread_rwlock_rdlock_0200(); + pthread_rwlock_rdlock_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_rwlock_timedrdlock.c b/libc-test/src/functionalext/supplement/thread/pthread_rwlock_timedrdlock.c new file mode 100644 index 00000000..6dd7126a --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_rwlock_timedrdlock.c @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_rwlock_timedrdlock_0100 + * @tc.desc : Provide correct parameters, test timeout and rwlock + * @tc.level : Level 0 + */ +void pthread_rwlock_timedrdlock_0100(void) +{ + struct timespec ts = {.tv_nsec = 0, .tv_sec = 0}; + pthread_rwlock_t rwlock; + pthread_rwlock_init(&rwlock, NULL); + clock_gettime(CLOCK_REALTIME, &ts); + struct tm *tmp = localtime(&ts.tv_sec); + int rev = -1; + if (tmp) { + ts.tv_sec += 1; + rev = pthread_rwlock_timedrdlock(&rwlock, &ts); + } + EXPECT_EQ("pthread_rwlock_timedrdlock_0100", rev, 0); + if (rev == 0) { + pthread_rwlock_unlock(&rwlock); + } + pthread_rwlock_destroy(&rwlock); +} + +/** + * @tc.name : pthread_rwlock_timedrdlock_0200 + * @tc.desc : In the locked (read lock) state, the test times out and rwlock + * @tc.level : Level 0 + */ +void pthread_rwlock_timedrdlock_0200(void) +{ + struct timespec ts = {.tv_nsec = 0, .tv_sec = 0}; + pthread_rwlock_t rwlock; + pthread_rwlock_init(&rwlock, NULL); + int rev = pthread_rwlock_timedrdlock(&rwlock, NULL); + EXPECT_EQ("pthread_rwlock_timedrdlock_0200", rev, 0); + clock_gettime(CLOCK_REALTIME, &ts); + struct tm *tmp = localtime(&ts.tv_sec); + rev = -1; + if (tmp) { + ts.tv_sec += 1; + rev = pthread_rwlock_timedrdlock(&rwlock, &ts); + } + EXPECT_EQ("pthread_rwlock_timedrdlock_0200", rev, 0); + pthread_rwlock_unlock(&rwlock); + pthread_rwlock_destroy(&rwlock); +} + +/** + * @tc.name : pthread_rwlock_timedrdlock_0300 + * @tc.desc : In the locked (write lock) state, the test times out and rwlock + * @tc.level : Level 2 + */ +void pthread_rwlock_timedrdlock_0300(void) +{ + struct timespec ts = {.tv_nsec = 0, .tv_sec = 0}; + pthread_rwlock_t rwlock; + pthread_rwlock_init(&rwlock, NULL); + int rev = pthread_rwlock_timedwrlock(&rwlock, NULL); + EXPECT_EQ("pthread_rwlock_timedrdlock_0300", rev, 0); + clock_gettime(CLOCK_REALTIME, &ts); + struct tm *tmp = localtime(&ts.tv_sec); + rev = -1; + if (tmp) { + ts.tv_sec += 1; + rev = pthread_rwlock_timedrdlock(&rwlock, &ts); + } + EXPECT_EQ("pthread_rwlock_timedrdlock_0300", rev, ETIMEDOUT); + pthread_rwlock_unlock(&rwlock); + pthread_rwlock_destroy(&rwlock); +} + +int main(void) +{ + pthread_rwlock_timedrdlock_0100(); + pthread_rwlock_timedrdlock_0200(); + pthread_rwlock_timedrdlock_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_rwlock_timedwrlock.c b/libc-test/src/functionalext/supplement/thread/pthread_rwlock_timedwrlock.c new file mode 100644 index 00000000..42808845 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_rwlock_timedwrlock.c @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_rwlock_timedwrlock_0100 + * @tc.desc : Provide correct parameters, test timeout and rwlock + * @tc.level : Level 0 + */ +void pthread_rwlock_timedwrlock_0100(void) +{ + struct timespec ts = {.tv_nsec = 0, .tv_sec = 0}; + pthread_rwlock_t rwlock; + pthread_rwlock_init(&rwlock, NULL); + clock_gettime(CLOCK_REALTIME, &ts); + struct tm *tmp = localtime(&ts.tv_sec); + int rev = -1; + if (tmp) { + ts.tv_sec += 1; + rev = pthread_rwlock_timedwrlock(&rwlock, &ts); + } + EXPECT_EQ("pthread_rwlock_timedwrlock_0100", rev, 0); + if (rev == 0) { + pthread_rwlock_unlock(&rwlock); + } + pthread_rwlock_destroy(&rwlock); +} + +/** + * @tc.name : pthread_rwlock_timedwrlock_0200 + * @tc.desc : In the locked (read lock) state, the test times out and rwlock + * @tc.level : Level 2 + */ +void pthread_rwlock_timedwrlock_0200(void) +{ + struct timespec ts = {.tv_nsec = 0, .tv_sec = 0}; + pthread_rwlock_t rwlock; + pthread_rwlock_init(&rwlock, NULL); + int rev = pthread_rwlock_timedrdlock(&rwlock, NULL); + EXPECT_EQ("pthread_rwlock_timedwrlock_0200", rev, 0); + clock_gettime(CLOCK_REALTIME, &ts); + struct tm *tmp = localtime(&ts.tv_sec); + rev = -1; + if (tmp) { + ts.tv_sec += 1; + rev = pthread_rwlock_timedwrlock(&rwlock, &ts); + } + EXPECT_EQ("pthread_rwlock_timedwrlock_0200", rev, ETIMEDOUT); + pthread_rwlock_unlock(&rwlock); + pthread_rwlock_destroy(&rwlock); +} + +/** + * @tc.name : pthread_rwlock_timedwrlock_0300 + * @tc.desc : In the locked (write lock) state, the test times out and rwlock + * @tc.level : Level 2 + */ +void pthread_rwlock_timedwrlock_0300(void) +{ + struct timespec ts = {.tv_nsec = 0, .tv_sec = 0}; + pthread_rwlock_t rwlock; + pthread_rwlock_init(&rwlock, NULL); + int rev = pthread_rwlock_timedwrlock(&rwlock, NULL); + EXPECT_EQ("pthread_rwlock_timedwrlock_0300", rev, 0); + clock_gettime(CLOCK_REALTIME, &ts); + struct tm *tmp = localtime(&ts.tv_sec); + rev = -1; + if (tmp) { + ts.tv_sec += 1; + rev = pthread_rwlock_timedwrlock(&rwlock, &ts); + } + EXPECT_EQ("pthread_rwlock_timedwrlock_0300", rev, ETIMEDOUT); + pthread_rwlock_unlock(&rwlock); + pthread_rwlock_destroy(&rwlock); +} + +int main(void) +{ + pthread_rwlock_timedwrlock_0100(); + pthread_rwlock_timedwrlock_0200(); + pthread_rwlock_timedwrlock_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_rwlock_tryrdlock.c b/libc-test/src/functionalext/supplement/thread/pthread_rwlock_tryrdlock.c new file mode 100755 index 00000000..c63a7a73 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_rwlock_tryrdlock.c @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_rwlock_tryrdlock_0100 + * @tc.desc : Try adding a read lock + * @tc.level : Level 0 + */ +void pthread_rwlock_tryrdlock_0100(void) +{ + pthread_rwlock_t rwlock; + pthread_rwlockattr_t rwlockattr; + pthread_rwlockattr_init(&rwlockattr); + pthread_rwlock_init(&rwlock, &rwlockattr); + + int ret = pthread_rwlock_tryrdlock(&rwlock); + EXPECT_EQ("pthread_rwlock_tryrdlock_0100", ret, CMPFLAG); + ret = pthread_rwlock_unlock(&rwlock); + EXPECT_EQ("pthread_rwlock_tryrdlock_0100", ret, CMPFLAG); + + pthread_rwlock_destroy(&rwlock); + pthread_rwlockattr_destroy(&rwlockattr); +} + +/** + * @tc.name : pthread_rwlock_tryrdlock_0200 + * @tc.desc : If a write lock has been added, try adding a read lock again + * @tc.level : Level 2 + */ +void pthread_rwlock_tryrdlock_0200(void) +{ + pthread_rwlock_t rwlock; + pthread_rwlockattr_t rwlockattr; + pthread_rwlockattr_init(&rwlockattr); + pthread_rwlock_init(&rwlock, &rwlockattr); + + int ret = pthread_rwlock_wrlock(&rwlock); + EXPECT_EQ("pthread_rwlock_tryrdlock_0200", ret, CMPFLAG); + + ret = pthread_rwlock_tryrdlock(&rwlock); + EXPECT_EQ("pthread_rwlock_tryrdlock_0200", ret, EBUSY); + + ret = pthread_rwlock_unlock(&rwlock); + EXPECT_EQ("pthread_rwlock_tryrdlock_0200", ret, CMPFLAG); + + pthread_rwlock_destroy(&rwlock); + pthread_rwlockattr_destroy(&rwlockattr); +} + +int main(void) +{ + pthread_rwlock_tryrdlock_0100(); + pthread_rwlock_tryrdlock_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_rwlock_trywrlock.c b/libc-test/src/functionalext/supplement/thread/pthread_rwlock_trywrlock.c new file mode 100755 index 00000000..1fde87d8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_rwlock_trywrlock.c @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_rwlock_trywrlock_0100 + * @tc.desc : Try adding a write lock + * @tc.level : Level 0 + */ +void pthread_rwlock_trywrlock_0100(void) +{ + pthread_rwlock_t rwlock; + pthread_rwlockattr_t rwlockattr; + pthread_rwlockattr_init(&rwlockattr); + pthread_rwlock_init(&rwlock, &rwlockattr); + + int ret = pthread_rwlock_trywrlock(&rwlock); + EXPECT_EQ("pthread_rwlock_trywrlock_0100", ret, CMPFLAG); + ret = pthread_rwlock_unlock(&rwlock); + EXPECT_EQ("pthread_rwlock_trywrlock_0100", ret, CMPFLAG); + + pthread_rwlock_destroy(&rwlock); + pthread_rwlockattr_destroy(&rwlockattr); +} + +/** + * @tc.name : pthread_rwlock_trywrlock_0200 + * @tc.desc : If it is already locked, try adding a write lock + * @tc.level : Level 2 + */ +void pthread_rwlock_trywrlock_0200(void) +{ + pthread_rwlock_t rwlock; + pthread_rwlockattr_t rwlockattr; + pthread_rwlockattr_init(&rwlockattr); + pthread_rwlock_init(&rwlock, &rwlockattr); + + int ret = pthread_rwlock_wrlock(&rwlock); + EXPECT_EQ("pthread_rwlock_trywrlock_0100", ret, CMPFLAG); + + ret = pthread_rwlock_trywrlock(&rwlock); + EXPECT_EQ("pthread_rwlock_trywrlock_0100", ret, EBUSY); + + ret = pthread_rwlock_unlock(&rwlock); + EXPECT_EQ("pthread_rwlock_trywrlock_0100", ret, CMPFLAG); + + pthread_rwlock_destroy(&rwlock); + pthread_rwlockattr_destroy(&rwlockattr); +} + +int main(void) +{ + pthread_rwlock_trywrlock_0100(); + pthread_rwlock_trywrlock_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_rwlockattr_destroy.c b/libc-test/src/functionalext/supplement/thread/pthread_rwlockattr_destroy.c new file mode 100644 index 00000000..228165dd --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_rwlockattr_destroy.c @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_rwlockattr_destroy_0100 + * @tc.desc : Release thread read-write lock attribute + * @tc.level : Level 0 + */ +void pthread_rwlockattr_destroy_0100(void) +{ + pthread_rwlockattr_t attr; + int ret = pthread_rwlockattr_init(&attr); + EXPECT_EQ("pthread_rwlockattr_destroy_0100", ret, 0); + + ret = pthread_rwlockattr_destroy(&attr); + EXPECT_EQ("pthread_rwlockattr_destroy_0100", ret, 0); +} + +int main(void) +{ + pthread_rwlockattr_destroy_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_rwlockattr_init.c b/libc-test/src/functionalext/supplement/thread/pthread_rwlockattr_init.c new file mode 100755 index 00000000..fb228995 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_rwlockattr_init.c @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_rwlockattr_init_0100 + * @tc.desc : Initialize thread read-write lock properties + * @tc.level : Level 0 + */ +void pthread_rwlockattr_init_0100(void) +{ + pthread_rwlockattr_t rwlockattr; + int ret = pthread_rwlockattr_init(&rwlockattr); + EXPECT_EQ("pthread_rwlockattr_init_0100", ret, CMPFLAG); + pthread_rwlockattr_destroy(&rwlockattr); +} + +int main(void) +{ + pthread_rwlockattr_init_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_rwlockattr_setpshared.c b/libc-test/src/functionalext/supplement/thread/pthread_rwlockattr_setpshared.c new file mode 100644 index 00000000..2bdeedcf --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_rwlockattr_setpshared.c @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +/** + * @tc.name : pthread_rwlockattr_setpshared_0100 + * @tc.desc : Get thread scope + * @tc.level : Level 0 + */ +void pthread_rwlockattr_setpshared_0100(void) +{ + pthread_rwlockattr_t attr; + pthread_rwlockattr_init(&attr); + int rev = pthread_rwlockattr_setpshared(&attr, 1); + EXPECT_EQ("pthread_rwlockattr_setpshared_0100", rev, 0); + pthread_rwlockattr_destroy(&attr); +} + +/** + * @tc.name : pthread_rwlockattr_setpshared_0200 + * @tc.desc : Failed to get thread scope + * @tc.level : Level 2 + */ +void pthread_rwlockattr_setpshared_0200(void) +{ + pthread_rwlockattr_t attr; + pthread_rwlockattr_init(&attr); + int rev = pthread_rwlockattr_setpshared(&attr, 2); + EXPECT_EQ("pthread_rwlockattr_setpshared_0200", rev, EINVAL); + pthread_rwlockattr_destroy(&attr); +} + +int main(void) +{ + pthread_rwlockattr_setpshared_0100(); + pthread_rwlockattr_setpshared_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_self.c b/libc-test/src/functionalext/supplement/thread/pthread_self.c new file mode 100644 index 00000000..33e2c778 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_self.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +static pthread_t tid1; + +void *threadfunc(void *arg) +{ + pthread_t result = pthread_self(); + if (tid1 != result) { + t_error("pthread_self_0100 pthread_self get result is %ld are not want %ld", result, tid1); + } + return 0; +} + +/** + * @tc.name : pthread_self_0100 + * @tc.desc : Verify that the number of threads in the thread library is obtained successfully + * @tc.level : Level 0 + */ +void pthread_self_0100(void) +{ + pthread_create(&tid1, NULL, threadfunc, NULL); + pthread_join(tid1, NULL); +} + +int main(int argc, char *argv[]) +{ + pthread_self_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_setschedparam.c b/libc-test/src/functionalext/supplement/thread/pthread_setschedparam.c new file mode 100644 index 00000000..51936526 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_setschedparam.c @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +static int32_t priorityTen = 10; +static int32_t priorityHundred = 100; + +void *threadfuncA(void *arg) +{ + return arg; +} + +/** + * @tc.name : pthread_setschedparam_0100 + * @tc.desc : Verify pthread_setschedparam process success when scheduling policy is SCHED_OTHER and priority is 0 + * @tc.level : Level 1 + */ +void pthread_setschedparam_0100(void) +{ + pthread_t tid; + pthread_create(&tid, NULL, threadfuncA, NULL); + struct sched_param sched; + sched.sched_priority = 0; + int32_t ret = pthread_setschedparam(tid, SCHED_OTHER, &sched); + EXPECT_EQ("pthread_setschedparam_0100", ret, 0); + pthread_join(tid, NULL); +} + +int main(void) +{ + pthread_setschedparam_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_setschedprio.c b/libc-test/src/functionalext/supplement/thread/pthread_setschedprio.c new file mode 100644 index 00000000..167e4aac --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_setschedprio.c @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +static void Thread1(void) +{ + sleep(1); + int ret = pthread_setschedprio(pthread_self(), 10); + EXPECT_EQ("pthread_setschedprio_0100", ret, 0); +} + +static void Thread2(void) +{ + sleep(1); + + int ret = pthread_setschedprio(pthread_self(), 1000); + EXPECT_EQ("pthread_setschedprio_0100", ret, EINVAL); +} + +static void setthreadproperty(pthread_attr_t *attr, struct sched_param *param) +{ + int ret = pthread_attr_init(attr); + EXPECT_EQ("pthread_setschedprio_0100", ret, CMPFLAG); + + param->sched_priority = 51; + ret = pthread_attr_setschedpolicy(attr, SCHED_RR); + EXPECT_EQ("pthread_setschedprio_0100", ret, CMPFLAG); + ret = pthread_attr_setschedparam(attr, param); + EXPECT_EQ("pthread_setschedprio_0100", ret, CMPFLAG); + + ret = pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED); + EXPECT_EQ("pthread_setschedprio_0100", ret, CMPFLAG); +} + +/** + * @tc.name : pthread_setschedprio_0100 + * @tc.desc : Set the thread properties, and judge the normal system of the function in the child thread + * @tc.level : Level 0 + */ +void pthread_setschedprio_0100(void) +{ + pthread_t thread; + pthread_attr_t attr; + struct sched_param param; + + setthreadproperty(&attr, ¶m); + int ret = pthread_create(&thread, &attr, (void *)Thread1, NULL); + if (ret != 0) { + EXPECT_EQ("pthread_setschedprio_0100", ret, CMPFLAG); + return; + } + + pthread_join(thread, NULL); + pthread_attr_destroy(&attr); +} + +/** + * @tc.name : pthread_setschedprio_0200 + * @tc.desc : Set the thread properties, and judge abnormal system of the function in the child thread + * @tc.level : Level 2 + */ +void pthread_setschedprio_0200(void) +{ + pthread_t thread; + pthread_attr_t attr; + struct sched_param param; + + setthreadproperty(&attr, ¶m); + int ret = pthread_create(&thread, &attr, (void *)Thread2, NULL); + if (ret != 0) { + EXPECT_EQ("pthread_setschedprio_0200", ret, CMPFLAG); + return; + } + + pthread_join(thread, NULL); + pthread_attr_destroy(&attr); +} + +int main(void) +{ + pthread_setschedprio_0100(); + pthread_setschedprio_0200(); + + return 0; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_setspecific.c b/libc-test/src/functionalext/supplement/thread/pthread_setspecific.c new file mode 100644 index 00000000..720c76dc --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_setspecific.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +static pthread_key_t g_key; + +void *threadfuncA(void *arg) +{ + int32_t value = 0; + int32_t ret = pthread_setspecific(g_key, &value); + EXPECT_EQ("pthread_setspecific_0100", ret, 0); + int32_t *keyRet = (int32_t *)pthread_getspecific(g_key); + EXPECT_EQ("pthread_setspecific_0100", *keyRet, 0); + return arg; +} + +void *threadfuncB(void *arg) +{ + int32_t value = 0; + int32_t ret = pthread_setspecific(g_key, &value); + EXPECT_EQ("pthread_setspecific_0200", ret, 0); + ret = pthread_setspecific(g_key, &value); + EXPECT_EQ("pthread_setspecific_0200", ret, 0); + int32_t *keyRet = (int32_t *)pthread_getspecific(g_key); + EXPECT_EQ("pthread_setspecific_0200", *keyRet, 0); + return arg; +} + +/** + * @tc.name: pthread_setspecific_0100 + * @tc.desc: Verify call pthread_setspecific once process success. + * @tc.level: level 0. + */ +void pthread_setspecific_0100(void) +{ + pthread_key_create(&g_key, NULL); + pthread_t tid1; + pthread_create(&tid1, NULL, threadfuncA, NULL); + pthread_join(tid1, NULL); + pthread_key_delete(g_key); +} + +/** + * @tc.name: pthread_setspecific_0200 + * @tc.desc: Verify call pthread_setspecific twice process success. + * @tc.level: level 0 + */ +void pthread_setspecific_0200(void) +{ + pthread_key_create(&g_key, NULL); + pthread_t tid2; + pthread_create(&tid2, NULL, threadfuncB, NULL); + pthread_join(tid2, NULL); + pthread_key_delete(g_key); +} + +int main(void) +{ + pthread_setspecific_0100(); + pthread_setspecific_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/thread/pthread_sigmask.c b/libc-test/src/functionalext/supplement/thread/pthread_sigmask.c new file mode 100644 index 00000000..57abf4cb --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_sigmask.c @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +static int32_t errorParam = 3; + +/** + * @tc.name : pthread_sigmask_0100 + * @tc.desc : Verify pthread_sigmask process success when define shield signal is SIGUSR1 + * @tc.level : Level 1 + */ +void pthread_sigmask_0100(void) +{ + sigset_t set; + sigaddset(&set, SIGUSR1); + int32_t ret = pthread_sigmask(SIG_BLOCK, &set, NULL); + EXPECT_EQ("pthread_sigmask_0100", ret, 0); + sigset_t setOne, setEmpty; + sigaddset(&setOne, SIGUSR2); + sigemptyset(&setEmpty); + ret = pthread_sigmask(SIG_BLOCK, &setOne, &setEmpty); + EXPECT_EQ("pthread_sigmask_0100", ret, 0); + sigismember(&set, SIGUSR1); + EXPECT_EQ("pthread_sigmask_0100", sigismember(&set, SIGUSR1), 1); +} + +/** + * @tc.name : pthread_sigmask_0200 + * @tc.desc : Verify pthread_sigmask process success when undefine shield signal + * @tc.level : Level 1 + */ +void pthread_sigmask_0200(void) +{ + sigset_t set; + sigaddset(&set, SIGUSR1); + sigaddset(&set, SIGQUIT); + int32_t ret = pthread_sigmask(SIG_BLOCK, &set, NULL); + EXPECT_EQ("pthread_sigmask_0200", ret, 0); + sigset_t setEmpty; + sigemptyset(&setEmpty); + ret = pthread_sigmask(SIG_BLOCK, &setEmpty, NULL); + EXPECT_EQ("pthread_sigmask_0200", ret, 0); + ret = sigismember(&set, SIGUSR1); + EXPECT_EQ("pthread_sigmask_0200", ret, 1); + ret = sigismember(&set, SIGQUIT); + EXPECT_EQ("pthread_sigmask_0200", ret, 1); +} + +/** + * @tc.name : pthread_sigmask_0300 + * @tc.desc : Verify pthread_sigmask process fail becaus first param is error + * @tc.level : Level 2 + */ +void pthread_sigmask_0300(void) +{ + sigset_t set; + sigaddset(&set, SIGUSR1); + sigaddset(&set, SIGQUIT); + int32_t ret = pthread_sigmask(SIG_BLOCK + errorParam, &set, NULL); + EXPECT_EQ("pthread_sigmask_0300", ret, EINVAL); +} + +/** + * @tc.name : pthread_sigmask_0400 + * @tc.desc : Verify pthread_sigmask process success when second and third param is null + * @tc.level : Level 2 + */ +void pthread_sigmask_0400(void) +{ + sigset_t set, setEmpty; + sigaddset(&set, SIGUSR1); + sigemptyset(&setEmpty); + int32_t ret = pthread_sigmask(SIG_BLOCK, &set, NULL); + EXPECT_EQ("pthread_setschedparam_0400", ret, 0); + ret = pthread_sigmask(SIG_BLOCK, NULL, &setEmpty); + EXPECT_EQ("pthread_setschedparam_0400", ret, 0); + ret = sigismember(&set, SIGUSR1); + EXPECT_EQ("pthread_setschedparam_0400", ret, 1); +} + +int main(void) +{ + pthread_sigmask_0100(); + pthread_sigmask_0200(); + pthread_sigmask_0300(); + pthread_sigmask_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_spin_lock.c b/libc-test/src/functionalext/supplement/thread/pthread_spin_lock.c new file mode 100755 index 00000000..f062f221 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_spin_lock.c @@ -0,0 +1,92 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +pthread_spinlock_t lock = 0; +volatile int count = 0; + +static void thread1(void) +{ + int ret = pthread_spin_lock(&lock); + EXPECT_EQ("pthread_spin_lock_0100", ret, CMPFLAG); + ++count; + ret = pthread_spin_unlock(&lock); + pthread_exit("success"); +} + +/** + * @tc.name : pthread_spin_lock_0100 + * @tc.desc : Verify that the return value of the calling function is correct + * @tc.level : Level 0 + */ +void pthread_spin_lock_0100(void) +{ + pthread_spinlock_t spin; + + int ret = pthread_spin_init(&spin, PTHREAD_PROCESS_PRIVATE); + EXPECT_EQ("pthread_spin_lock_0100", ret, CMPFLAG); + + ret = pthread_spin_lock(&spin); + EXPECT_EQ("pthread_spin_lock_0100", ret, CMPFLAG); + + ret = pthread_spin_unlock(&spin); + EXPECT_EQ("pthread_spin_lock_0100", ret, CMPFLAG); + + pthread_spin_destroy(&spin); +} + +/** + * @tc.name : pthread_spin_lock_0200 + * @tc.desc : Verify that under multi-threading, whether the modification of the global variable data is + * as expected, and whether the spin lock is successfully locked + * @tc.level : Level 0 + */ +void pthread_spin_lock_0200(void) +{ + pthread_t thread; + void *rev; + + int ret = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE); + + EXPECT_EQ("pthread_spin_lock_0200", ret, CMPFLAG); + ret = pthread_create(&thread, NULL, (void *)thread1, NULL); + if (ret != 0) { + EXPECT_EQ("pthread_spin_lock_0200", ret, CMPFLAG); + return; + } + + ret = pthread_spin_lock(&lock); + EXPECT_EQ("pthread_spin_lock_0200", ret, CMPFLAG); + + ++count; + ret = pthread_spin_unlock(&lock); + + pthread_join(thread, &rev); + EXPECT_STREQ("pthread_spin_lock_0200", rev, "success"); + EXPECT_EQ("pthread_spin_lock_0200", count, 2); + + pthread_spin_destroy(&lock); +} + +int main(void) +{ + pthread_spin_lock_0100(); + pthread_spin_lock_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_spin_trylock.c b/libc-test/src/functionalext/supplement/thread/pthread_spin_trylock.c new file mode 100755 index 00000000..d9a1af4e --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_spin_trylock.c @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +pthread_spinlock_t lock = 0; +int count = 0; + +static void thread1(void) +{ + int ret = pthread_spin_trylock(&lock); + EXPECT_EQ("pthread_spin_trylock_0100", ret, CMPFLAG); + ++count; + ret = pthread_spin_unlock(&lock); + pthread_exit("success"); +} + +static void thread2(void) +{ + int ret = pthread_spin_lock(&lock); + EXPECT_EQ("pthread_spin_trylock_0200", ret, CMPFLAG); + + ret = pthread_spin_trylock(&lock); + EXPECT_EQ("pthread_spin_trylock_0200", ret, EBUSY); + ret = pthread_spin_unlock(&lock); + pthread_exit("success"); +} + +/** + * @tc.name : pthread_spin_trylock_0100 + * @tc.desc : Verify that the attempt to lock is successful under multi-threading(success) + * @tc.level : Level 0 + */ +void pthread_spin_trylock_0100(void) +{ + pthread_t thread; + void *rev; + + int ret = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE); + + EXPECT_EQ("pthread_spin_trylock_0100", ret, CMPFLAG); + ret = pthread_create(&thread, NULL, (void *)thread1, NULL); + if (ret != 0) { + EXPECT_EQ("pthread_spin_trylock_0100", ret, CMPFLAG); + return; + } + + ret = pthread_spin_lock(&lock); + EXPECT_EQ("pthread_spin_trylock_0100", ret, CMPFLAG); + + ++count; + ret = pthread_spin_unlock(&lock); + + pthread_join(thread, &rev); + EXPECT_STREQ("pthread_spin_trylock_0100", rev, "success"); + EXPECT_EQ("pthread_spin_trylock_0100", count, 2); +} + +/** + * @tc.name : pthread_spin_trylock_0200 + * @tc.desc : Verify that the attempt to lock is successful under multi-threading(failed) + * @tc.level : Level 2 + */ +void pthread_spin_trylock_0200(void) +{ + pthread_t thread; + void *rev; + + int ret = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE); + + EXPECT_EQ("pthread_spin_trylock_0200", ret, CMPFLAG); + ret = pthread_create(&thread, NULL, (void *)thread2, NULL); + if (ret != 0) { + EXPECT_EQ("pthread_spin_trylock_0200", ret, CMPFLAG); + return; + } + + pthread_join(thread, &rev); + pthread_spin_destroy(&lock); +} + +int main(void) +{ + pthread_spin_trylock_0100(); + pthread_spin_trylock_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/pthread_spin_unlock.c b/libc-test/src/functionalext/supplement/thread/pthread_spin_unlock.c new file mode 100755 index 00000000..e3f196b5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/pthread_spin_unlock.c @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +pthread_spinlock_t lock = 0; +int count = 0; + +static void thread1(void) +{ + int ret = pthread_spin_lock(&lock); + EXPECT_EQ("pthread_spin_unlock_0100", ret, CMPFLAG); + ++count; + ret = pthread_spin_unlock(&lock); + EXPECT_EQ("pthread_spin_unlock_0100", ret, CMPFLAG); + EXPECT_EQ("pthread_spin_unlock_0100", count, 1); + pthread_exit("success"); +} + +/** + * @tc.name : pthread_spin_unlock_0100 + * @tc.desc : Verify that the spin lock releases the lock successfully under multi-threading + * @tc.level : Level 0 + */ +void pthread_spin_unlock_0100(void) +{ + pthread_t thread; + void *rev; + + int ret = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE); + + EXPECT_EQ("pthread_spin_unlock_0100", ret, CMPFLAG); + ret = pthread_create(&thread, NULL, (void *)thread1, NULL); + if (ret != 0) { + EXPECT_EQ("pthread_spin_unlock_0100", ret, CMPFLAG); + pthread_spin_destroy(&lock); + return; + } + + pthread_join(thread, &rev); + EXPECT_STREQ("pthread_spin_unlock_0100", rev, "success"); + EXPECT_EQ("pthread_spin_unlock_0100", count, 1); + + pthread_spin_destroy(&lock); +} + +int main(void) +{ + pthread_spin_unlock_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/test_src_functionalext_supplement_thread.gni b/libc-test/src/functionalext/supplement/thread/test_src_functionalext_supplement_thread.gni new file mode 100644 index 00000000..acef9169 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/test_src_functionalext_supplement_thread.gni @@ -0,0 +1,81 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_thread_test = [ + "mtx_init", + "mtx_lock", + "mtx_trylock", + "mtx_unlock", + "pthread_attr_destroy", + "pthread_attr_get", + "pthread_attr_setguardsize", + "pthread_attr_init", + "pthread_attr_setinheritsched", + "pthread_attr_setstack", + "pthread_barrier_destroy", + "pthread_barrier_init", + "pthread_barrier_wait", + "pthread_barrierattr_init", + "pthread_barrierattr_setpshared", + "pthread_cond_broadcast", + "pthread_cond_destroy", + "pthread_cond_init", + "pthread_cond_signal", + "pthread_cond_wait", + "pthread_cond_timedwait", + "pthread_condattr_setpshared", + "pthread_mutexattr_settype", + "pthread_getcpuclockid", + "pthread_join", + "pthread_mutex_destroy", + "pthread_mutex_timedlock", + "pthread_mutex_trylock", + "pthread_mutexattr_destroy", + "pthread_mutexattr_setprotocol", + "pthread_rwlock_timedrdlock", + "pthread_rwlock_timedwrlock", + "pthread_rwlockattr_destroy", + "pthread_rwlockattr_setpshared", + "pthread_setschedprio", + "cnd_init", + "cnd_signal", + "cnd_timedwait", + "cnd_wait", + "call_once", + "thrd_create", + "thrd_current", + "thrd_detach", + "thrd_equal", + "thrd_join", + "thrd_sleep", + "thrd_yield", + "tss_set", + "mtx_timedlock", + "pthread_atfork", + "pthread_attr_setschedparam", + "pthread_attr_setschedpolicy", + "pthread_attr_setscope", + "pthread_condattr_setclock", + "pthread_mutexattr_setpshared", + "pthread_detach", + "pthread_rwlock_tryrdlock", + "pthread_rwlock_trywrlock", + "pthread_rwlockattr_init", + "pthread_self", + "pthread_spin_lock", + "pthread_spin_trylock", + "pthread_spin_unlock", + "pthread_key_delete", + "pthread_equal", + "pthread_rwlock_rdlock", +] diff --git a/libc-test/src/functionalext/supplement/thread/thrd_create.c b/libc-test/src/functionalext/supplement/thread/thrd_create.c new file mode 100644 index 00000000..71377ec8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/thrd_create.c @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +static int count = 0; +const char *src = "Hello"; + +void exception_handler(int sig) +{ + exit(t_status); +} + +int threadfunc(void *arg) +{ + signal(SIGSEGV, exception_handler); + + count++; + thrd_exit(thrd_success); +} + +/** + * @tc.name : thrd_create_0100 + * @tc.desc : Creates a new thread executing the function func + * @tc.level : Level 0 + */ +void thrd_create_0100(void) +{ + thrd_t id; + int result; + result = thrd_create(&id, threadfunc, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + } + + result = thrd_sleep(&(struct timespec){.tv_sec = 1}, NULL); + if (result != 0) { + t_error("%s thrd_sleep failed", __func__); + } + + result = thrd_join(id, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + } + + if (count != 1) { + t_error("%s failed, count is %d", __func__, count); + } + + count = 0; +} + +/** + * @tc.name : thrd_create_0200 + * @tc.desc : Creates a new thread executing the function func(arg) + * @tc.level : Level 1 + */ +void thrd_create_0200(void) +{ + thrd_t id; + int result; + result = thrd_create(&id, threadfunc, (char *)src); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + } + + result = thrd_sleep(&(struct timespec){.tv_sec = 1}, NULL); + if (result != 0) { + t_error("%s thrd_sleep failed", __func__); + } + + result = thrd_join(id, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + } + + if (count != 1) { + t_error("%s failed, count is %d", __func__, count); + } + count = 0; +} + +/** + * @tc.name : thrd_create_0300 + * @tc.desc : exception test + * @tc.level : Level 2 + */ +void thrd_create_0300(void) +{ + thrd_create(NULL, threadfunc, NULL); +} + +int main(int argc, char *argv[]) +{ + thrd_create_0100(); + thrd_create_0200(); + thrd_create_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/thrd_current.c b/libc-test/src/functionalext/supplement/thread/thrd_current.c new file mode 100644 index 00000000..2e4599c4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/thrd_current.c @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +static thrd_t thr; +static int count = 0; + +int threadfuncA(void *arg) +{ + count++; + thrd_t id = thrd_current(); + + if (!(thrd_equal(id, thr))) { + t_error("%s thrd_current failed", __func__); + } + + thrd_exit(thrd_success); +} + +int threadfuncB(void *arg) +{ + count++; + + thrd_exit(thrd_success); +} + +/** + * @tc.name : thrd_current_0100 + * @tc.desc : Returns the identifier of the calling thread + * @tc.level : Level 0 + */ +void thrd_current_0100(void) +{ + int result; + + result = thrd_create(&thr, threadfuncA, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + } + + result = thrd_sleep(&(struct timespec){.tv_sec = 1}, NULL); + if (result != 0) { + t_error("%s thrd_sleep failed", __func__); + } + + result = thrd_join(thr, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + } + + if (count != 1) { + t_error("%s failed, count is %d", __func__, count); + } + count = 0; +} + +/** + * @tc.name : thrd_current_0200 + * @tc.desc : Create two threads to execute the same func + * @tc.level : Level 1 + */ +void thrd_current_0200(void) +{ + thrd_t thr1, thr2; + int result; + + result = thrd_create(&thr1, threadfuncB, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + } + + result = thrd_create(&thr2, threadfuncB, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + } + + result = thrd_sleep(&(struct timespec){.tv_sec = 1}, NULL); + if (result != 0) { + t_error("%s thrd_sleep failed", __func__); + } + + if (thrd_equal(thr1, thr2)) { + t_error("%s equal", __func__); + } + + if (thrd_equal(thr1, thrd_current())) { + t_error("%s equal", __func__); + } + + if (thrd_equal(thr2, thrd_current())) { + t_error("%s equal", __func__); + } + + result = thrd_join(thr1, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + } + + result = thrd_join(thr2, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + } + + if (count != 2) { + t_error("%s failed, count is %d", __func__, count); + } + count = 0; +} + +int main(int argc, char *argv[]) +{ + thrd_current_0100(); + thrd_current_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/thrd_detach.c b/libc-test/src/functionalext/supplement/thread/thrd_detach.c new file mode 100644 index 00000000..3bfaabc0 --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/thrd_detach.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +static int count = 0; + +void exception_handler(int sig) +{ + exit(t_status); +} + +int threadfunc(void *arg) +{ + count++; + int ret = thrd_detach(thrd_current()); + if (ret != thrd_success) { + t_error("%s thrd_detach failed", __func__); + } + + thrd_exit(thrd_success); +} + +/** + * @tc.name : thrd_detach_0100 + * @tc.desc : Detaches the thread identified by thr from the current environment + * @tc.level : Level 0 + */ +void thrd_detach_0100(void) +{ + thrd_t id; + int result; + + result = thrd_create(&id, threadfunc, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + } + + result = thrd_sleep(&(struct timespec){.tv_sec = 1}, NULL); + if (result != 0) { + t_error("%s thrd_sleep failed", __func__); + } + + if (count != 1) { + t_error("%s failed, count is %d", __func__, count); + } + count = 0; +} + +/** + * @tc.name : thrd_detach_0200 + * @tc.desc : Use thrd_join after thrd_detach + * @tc.level : Level 2 + */ +void thrd_detach_0200(void) +{ + signal(SIGSEGV, exception_handler); + + thrd_t id; + int result; + + result = thrd_create(&id, threadfunc, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + } + + result = thrd_sleep(&(struct timespec){.tv_sec = 1}, NULL); + if (result != 0) { + t_error("%s thrd_sleep failed", __func__); + } + + result = thrd_join(id, NULL); + if (result == thrd_success) { + t_error("%s thrd_join should fail", __func__); + } + + if (count != 1) { + t_error("%s failed, count is %d", __func__, count); + } + count = 0; +} + +int main(int argc, char *argv[]) +{ + thrd_detach_0100(); + thrd_detach_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/thrd_equal.c b/libc-test/src/functionalext/supplement/thread/thrd_equal.c new file mode 100644 index 00000000..d837009b --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/thrd_equal.c @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +static thrd_t thr; +static int count = 0; + +int threadfuncA(void *arg) +{ + count++; + thrd_t id = thrd_current(); + + if (!(thrd_equal(id, thr))) { + t_error("%s thrd_current failed", __func__); + } + + thrd_exit(thrd_success); +} + +int threadfuncB(void *arg) +{ + count++; + + thrd_exit(thrd_success); +} + +/** + * @tc.name : thrd_equal_0100 + * @tc.desc : Test that two threads have the same ID + * @tc.level : Level 0 + */ +void thrd_equal_0100(void) +{ + int result; + + result = thrd_create(&thr, threadfuncA, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + } + + result = thrd_sleep(&(struct timespec){.tv_sec = 1}, NULL); + if (result != 0) { + t_error("%s thrd_sleep failed", __func__); + } + + result = thrd_join(thr, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + } + + if (count != 1) { + t_error("%s failed, count is %d", __func__, count); + } + count = 0; +} + +/** + * @tc.name : thrd_equal_0200 + * @tc.desc : Test that two threads have different ID + * @tc.level : Level 1 + */ +void thrd_equal_0200(void) +{ + thrd_t thr1, thr2; + int result; + + result = thrd_create(&thr1, threadfuncB, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + } + + result = thrd_create(&thr2, threadfuncB, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + } + + result = thrd_sleep(&(struct timespec){.tv_sec = 1}, NULL); + if (result != 0) { + t_error("%s thrd_sleep failed", __func__); + } + + if (thrd_equal(thr1, thr2)) { + t_error("%s failed, thr1 and thr2 equal", __func__); + } + + if (thrd_equal(thr1, thrd_current())) { + t_error("%s failed, thr1 and current thread equal", __func__); + } + + if (thrd_equal(thr2, thrd_current())) { + t_error("%s failed, thr2 and current thread equal", __func__); + } + + result = thrd_join(thr1, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + } + + result = thrd_join(thr2, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + } + + if (count != 2) { + t_error("%s failed, count is %d", __func__, count); + } + count = 0; +} + +int main(int argc, char *argv[]) +{ + thrd_equal_0100(); + thrd_equal_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/thrd_join.c b/libc-test/src/functionalext/supplement/thread/thrd_join.c new file mode 100644 index 00000000..e4c53f1b --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/thrd_join.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +static int count = 0; + +void exception_handler(int sig) +{ + exit(t_status); +} + +int threadfunc(void *arg) +{ + count++; + return 0; +} + +/** + * @tc.name : thrd_join_0100 + * @tc.desc : Blocks current thread until it identified by thr finishes execution with no return value + * @tc.level : Level 0 + */ +void thrd_join_0100(void) +{ + thrd_t id; + int result; + result = thrd_create(&id, threadfunc, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + } + + result = thrd_sleep(&(struct timespec){.tv_nsec = 1000000}, NULL); + if (result != 0) { + t_error("%s thrd_sleep failed", __func__); + } + + result = thrd_join(id, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + } + + if (count != 1) { + t_error("%s failed, count is %d", __func__, count); + } + count = 0; +} + +/** + * @tc.name : thrd_join_0200 + * @tc.desc : Blocks current thread until it identified by thr finishes execution with return value + * @tc.level : Level 1 + */ +void thrd_join_0200(void) +{ + thrd_t id; + int ret = 1; + int result; + result = thrd_create(&id, threadfunc, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + } + + result = thrd_sleep(&(struct timespec){.tv_nsec = 1000000}, NULL); + if (result != 0) { + t_error("%s thrd_sleep failed", __func__); + } + + result = thrd_join(id, &ret); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + } + + if (ret != 0) { + t_error("%s return value failed", __func__); + } + + if (count != 1) { + t_error("%s failed, count is %d", __func__, count); + } + count = 0; +} + +/** + * @tc.name : thrd_join_0300 + * @tc.desc : Invalid parameter test + * @tc.level : Level 2 + */ +void thrd_join_0300(void) +{ + signal(SIGSEGV, exception_handler); + + thrd_join(NULL, NULL); +} + +int main(int argc, char *argv[]) +{ + thrd_join_0100(); + thrd_join_0200(); + thrd_join_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/thrd_sleep.c b/libc-test/src/functionalext/supplement/thread/thrd_sleep.c new file mode 100644 index 00000000..04514d1b --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/thrd_sleep.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +static int count = 0; + +void exception_handler(int sig) +{ + exit(t_status); +} + +int threadfunc(void *arg) +{ + count++; + + struct timespec const *tl = (struct timespec const *)arg; + if (thrd_sleep(tl, NULL) != 0) { + t_error("%s thrd_sleep failed", __func__); + } + + thrd_exit(thrd_success); +} + +/** + * @tc.name : thrd_sleep_0100 + * @tc.desc : Thread waits for 1s + * @tc.level : Level 0 + */ +void thrd_sleep_0100(void) +{ + int result; + thrd_t id; + struct timespec ts = {.tv_sec = 1}; + + result = thrd_create(&id, threadfunc, (void *)(&ts)); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + } + + result = thrd_join(id, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + } + + if (count != 1) { + t_error("%s failed, count is %d", __func__, count); + } + count = 0; +} + +/** + * @tc.name : thrd_sleep_0200 + * @tc.desc : Negative value + * @tc.level : Level 1 + */ +void thrd_sleep_0200(void) +{ + int result = thrd_sleep(&(struct timespec){.tv_sec = -1}, NULL); + if (result != -2) { + t_error("%s negative value", __func__); + } +} + +/** + * @tc.name : thrd_sleep_0300 + * @tc.desc : Invalid parameter test + * @tc.level : Level 2 + */ +void thrd_sleep_0300(void) +{ + signal(SIGSEGV, exception_handler); + + thrd_sleep(NULL, NULL); +} + +int main(int argc, char *argv[]) +{ + thrd_sleep_0100(); + thrd_sleep_0200(); + thrd_sleep_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/thrd_yield.c b/libc-test/src/functionalext/supplement/thread/thrd_yield.c new file mode 100644 index 00000000..ff04a96a --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/thrd_yield.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +#define ms (1000.0) +#define us (1000000) +#define ns (1000000000L) + +double ustimer(struct timespec tss, struct timespec tse) +{ + double sd = difftime(tse.tv_sec, tss.tv_sec); + long nsd = tse.tv_nsec - tss.tv_nsec; + if (nsd < 0) { + return us * (sd - 1) + (ns + nsd) / ms; + } else { + return us * (sd) + nsd / ms; + } +} + +void yieldfunc(void) +{ + struct timespec tss, tse; + timespec_get(&tss, TIME_UTC); + do { + thrd_yield(); + timespec_get(&tse, TIME_UTC); + } while (ustimer(tss, tse) < 100.0); +} + +/** + * @tc.name : thrd_yield_0100 + * @tc.desc : Busy wait while yielding + * @tc.level : Level 0 + */ +void thrd_yield_0100(void) +{ + int result; + struct timespec tss, tse; + + result = timespec_get(&tss, TIME_UTC); + if (result != TIME_UTC) { + t_error("%s timespec_get start failed", __func__); + return; + } + + yieldfunc(); + + result = timespec_get(&tse, TIME_UTC); + if (result != TIME_UTC) { + t_error("%s timespec_get end failed", __func__); + return; + } + + if ((ustimer(tss, tse) - 100.0) < 0) { + t_error("%s sleep time is not 100us", __func__); + return; + } +} + +int main(int argc, char *argv[]) +{ + thrd_yield_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/thread/tss_set.c b/libc-test/src/functionalext/supplement/thread/tss_set.c new file mode 100644 index 00000000..6c09684c --- /dev/null +++ b/libc-test/src/functionalext/supplement/thread/tss_set.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "test.h" + +#define TSS_SET_VALUE (void *)0xFF +static tss_t key; + +int tssfunc(void *arg) +{ + int ret; + ret = tss_create(&key, NULL); + if (ret != thrd_success) { + t_error("%s tss_create failed", __func__); + } + ret = tss_set(key, TSS_SET_VALUE); + if (ret != thrd_success) { + t_error("%s tss_set failed", __func__); + } + void *value = tss_get(key); + if (value == 0) { + t_error("%s tss_get failed", __func__); + } + if (value != TSS_SET_VALUE) { + t_error("%s tss_get return val is %p, expect %p", __func__, value, TSS_SET_VALUE); + } + + thrd_exit(thrd_success); +} + +/** + * @tc.name : tss_set_0100 + * @tc.desc : Sets the value of the thread-specific storage identified by tss_id for the current thread to val + * @tc.level : Level 0 + */ +void tss_set_0100(void) +{ + thrd_t id; + int result; + + result = tss_create(&key, NULL); + if (result != thrd_success) { + t_error("%s tss_create failed", __func__); + } + + result = thrd_create(&id, tssfunc, NULL); + if (result != thrd_success) { + t_error("%s thrd_create failed", __func__); + } + + result = thrd_join(id, NULL); + if (result != thrd_success) { + t_error("%s thrd_join failed", __func__); + } + + void *value = tss_get(key); + if (value != 0) { + t_error("%s it should have failed", __func__); + } + + tss_delete(key); +} + +int main(int argc, char *argv[]) +{ + tss_set_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/BUILD.gn b/libc-test/src/functionalext/supplement/time/BUILD.gn new file mode 100644 index 00000000..7edf8cf8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_time.gni") + +foreach(s, functionalext_supplement_time_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/time" + } +} + +group("functionalext_supplement_time_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_time_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/time/clock.c b/libc-test/src/functionalext/supplement/time/clock.c new file mode 100644 index 00000000..f01e8600 --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/clock.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : clock_0100 + * @tc.desc : Can get the time used by the processor clock. + * @tc.level : Level 0 + */ +void clock_0100() +{ + clock_t ret; + ret = clock(); + EXPECT_TRUE("clock_0100", ret > 0); +} + +int main() +{ + clock_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/clock_getcpuclockid.c b/libc-test/src/functionalext/supplement/time/clock_getcpuclockid.c new file mode 100644 index 00000000..9a92ba00 --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/clock_getcpuclockid.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int32_t COUNT_ZERO = 0; +const int32_t COUNT_NEGATIVE = -1; + +/** + * @tc.name : clock_getcpuclockid_0100 + * @tc.desc : Verify that the clock ID can be obtained (all parameters are valid) + * @tc.level : Level 0 + */ +void clock_getcpuclockid_0100(void) +{ + bool flag = false; + clockid_t clk = 0; + int result = -1; + pid_t pid; + pid = getppid(); + result = clock_getcpuclockid(pid, &clk); + if (clk != 0) { + flag = true; + } + EXPECT_TRUE("clock_getcpuclockid_0100", flag); + EXPECT_EQ("clock_getcpuclockid_0100", result, COUNT_ZERO); +} + +/** + * @tc.name : clock_getcpuclockid_0200 + * @tc.desc : Verify could not get clock ID (pid parameter invalid) + * @tc.level : Level 2 + */ +void clock_getcpuclockid_0200(void) +{ + bool flag = false; + clockid_t clk = 0; + int result = 0; + result = clock_getcpuclockid(45000, &clk); + if (result != 0) { + flag = true; + } + EXPECT_TRUE("clock_getcpuclockid_0200", flag); +} + +int main() +{ + clock_getcpuclockid_0100(); + clock_getcpuclockid_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/clock_getres.c b/libc-test/src/functionalext/supplement/time/clock_getres.c new file mode 100644 index 00000000..c4d6fbad --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/clock_getres.c @@ -0,0 +1,91 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : clock_getres_0100 + * @tc.desc : Verify that the resolution in the specified poem can be found (the parameter is CLOCK_REALTIME) + * @tc.level : Level 0 + */ +void clock_getres_0100(void) +{ + struct timespec ts; + int result = clock_getres(CLOCK_REALTIME, &ts); + EXPECT_EQ("clock_getres_0100", result, 0); +} + +/** + * @tc.name : clock_getres_0200 + * @tc.desc : Verify that the resolution in the specified poem can be found (the parameter is CLOCK_TAI) + * @tc.level : Level 0 + */ +void clock_getres_0200(void) +{ + struct timespec ts; + int result = clock_getres(CLOCK_TAI, &ts); + EXPECT_EQ("clock_getres_0200", result, 0); +} + +/** + * @tc.name : clock_getres_0300 + * @tc.desc : Verify that the resolution in the specified poem can be found (the parameter is CLOCK_MONOTONIC) + * @tc.level : Level 0 + */ +void clock_getres_0300(void) +{ + struct timespec ts; + int result = clock_getres(CLOCK_MONOTONIC, &ts); + EXPECT_EQ("clock_getres_0300", result, 0); +} + +/** + * @tc.name : clock_getres_0400 + * @tc.desc : Verify that the resolution in the specified poem can be found (the parameter is CLOCK_BOOTTIME) + * @tc.level : Level 0 + */ +void clock_getres_0400(void) +{ + struct timespec ts; + int result = clock_getres(CLOCK_BOOTTIME, &ts); + EXPECT_EQ("clock_getres_0400", result, 0); +} + +/** + * @tc.name : clock_getres_0500 + * @tc.desc : Verify that the resolution in the specified poem cannot be found (parameter is 100) + * @tc.level : Level 2 + */ +void clock_getres_0500(void) +{ + struct timespec ts; + int result = clock_getres(100, &ts); + EXPECT_EQ("clock_getres_0500", result, -1); +} + +int main(void) +{ + clock_getres_0100(); + clock_getres_0200(); + clock_getres_0300(); + clock_getres_0400(); + clock_getres_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/clock_nanosleep.c b/libc-test/src/functionalext/supplement/time/clock_nanosleep.c new file mode 100644 index 00000000..037868fb --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/clock_nanosleep.c @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int SUCCESS = 0; + +/** + * @tc.name : clock_nanosleep_0100 + * @tc.desc : Each parameter is valid, clk is CLOCK_REALTIME, which can specify the sleep of the clock. + * @tc.level : Level 0 + */ +void clock_nanosleep_0100(void) +{ + struct timespec ts; + ts.tv_sec = ts.tv_nsec / 1000000000; + ts.tv_nsec = 200000000; + int ret = -1; + ret = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL); + EXPECT_EQ("clock_nanosleep_0100", ret, SUCCESS); +} + +/** + * @tc.name : clock_nanosleep_0200 + * @tc.desc : Each parameter is valid, clk is CLOCK_TAI, which can specify the sleep of the clock. + * @tc.level : Level 0 + */ +void clock_nanosleep_0200(void) +{ + struct timespec ts; + ts.tv_sec = ts.tv_nsec / 1000000000; + ts.tv_nsec = 200000000; + int ret = -1; + ret = clock_nanosleep(CLOCK_TAI, TIMER_ABSTIME, &ts, NULL); + EXPECT_EQ("clock_nanosleep_0200", ret, SUCCESS); +} + +/** + * @tc.name : clock_nanosleep_0300 + * @tc.desc : Each parameter is valid, clk is CLOCK_MONOTONIC, which can specify the sleep of the clock + * @tc.level : Level 0 + */ +void clock_nanosleep_0300(void) +{ + struct timespec ts; + ts.tv_sec = ts.tv_nsec / 1000000000; + ts.tv_nsec = 200000000; + int ret = -1; + ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL); + EXPECT_EQ("clock_nanosleep_0300", ret, SUCCESS); +} + +/** + * @tc.name : clock_nanosleep_0400 + * @tc.desc : Each parameter is valid, clk is CLOCK_BOOTTIME, which can specify the sleep of the clock + * @tc.level : Level 0 + */ +void clock_nanosleep_0400(void) +{ + struct timespec ts; + ts.tv_sec = ts.tv_nsec / 1000000000; + ts.tv_nsec = 200000000; + int ret = -1; + ret = clock_nanosleep(CLOCK_BOOTTIME, TIMER_ABSTIME, &ts, NULL); + EXPECT_EQ("clock_nanosleep_0400", ret, SUCCESS); +} + +/** + * @tc.name : clock_nanosleep_0500 + * @tc.desc : Each parameter is valid, clk is CLOCK_REALTIME, and flags is 0, + * which can specify the sleep of the clock + * @tc.level : Level 1 + */ +void clock_nanosleep_0500(void) +{ + struct timespec ts; + ts.tv_sec = ts.tv_nsec / 1000000000; + ts.tv_nsec = 200000000; + int ret = -1; + ret = clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL); + EXPECT_EQ("clock_nanosleep_0500", ret, SUCCESS); +} + +/** + * @tc.name : clock_nanosleep_0600 + * @tc.desc : The clk parameter is invalid, clk is CLOCK_THREAD_CPUTIME_ID, + * the sleep of the clock cannot be specified + * @tc.level : Level 2 + */ +void clock_nanosleep_0600(void) +{ + struct timespec ts; + ts.tv_sec = ts.tv_nsec / 1000000000; + ts.tv_nsec = 200000000; + int ret = -1; + ret = clock_nanosleep(CLOCK_THREAD_CPUTIME_ID, TIMER_ABSTIME, &ts, NULL); + EXPECT_EQ("clock_nanosleep_0600", ret, EINVAL); +} + +int main() +{ + clock_nanosleep_0100(); + clock_nanosleep_0200(); + clock_nanosleep_0300(); + clock_nanosleep_0400(); + clock_nanosleep_0500(); + clock_nanosleep_0600(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/clock_settime.c b/libc-test/src/functionalext/supplement/time/clock_settime.c new file mode 100644 index 00000000..3bcf3fba --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/clock_settime.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int SUCCESS = 0; + +/** + * @tc.name : clock_settime_0100 + * @tc.desc : Each parameter is valid, the clk parameter is CLOCK_REALTIME, which can set the system + * time seconds and nanoseconds. + * @tc.level : Level 0 + */ +void clock_settime_0100(void) +{ + struct timespec ts; + struct tm tim = { + .tm_year = 2022 - 1900, + .tm_min = 16, + .tm_hour = 18, + .tm_mon = 6, + .tm_mday = 6, + }; + ts.tv_sec = mktime(&tim); + ts.tv_nsec = 0; + int ret = -1; + ret = clock_settime(CLOCK_REALTIME, &ts); + EXPECT_EQ("clock_settime_0100", ret, SUCCESS); +} + +int main() +{ + clock_settime_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/difftime.c b/libc-test/src/functionalext/supplement/time/difftime.c new file mode 100644 index 00000000..0b102d52 --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/difftime.c @@ -0,0 +1,500 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +struct difftime_struct { + const char *tz; + const double result; +}; + +static const struct difftime_struct gResultData[] = { + {"Pacific/Rarotonga", 10.000000}, + {"Pacific/Wake", 10.000000}, + {"Pacific/Tarawa", 10.000000}, + {"Pacific/Fakaofo", 10.000000}, + {"Pacific/Apia", 10.000000}, + {"Pacific/Kwajalein", 10.000000}, + {"Pacific/Tahiti", 10.000000}, + {"Pacific/Easter", 10.000000}, + {"Pacific/Tongatapu", 10.000000}, + {"Pacific/Guadalcanal", 10.000000}, + {"Pacific/Chuuk", 10.000000}, + {"Pacific/Pitcairn", 10.000000}, + {"Pacific/Pohnpei", 10.000000}, + {"Pacific/Fiji", 10.000000}, + {"Pacific/Majuro", 10.000000}, + {"Pacific/Kiritimati", 10.000000}, + {"Pacific/Port_Moresby", 10.000000}, + {"Pacific/Galapagos", 10.000000}, + {"Pacific/Saipan", 10.000000}, + {"Pacific/Marquesas", 10.000000}, + {"Pacific/Wallis", 10.000000}, + {"Pacific/Palau", 10.000000}, + {"Pacific/Bougainville", 10.000000}, + {"Pacific/Honolulu", 10.000000}, + {"Pacific/Noumea", 10.000000}, + {"Pacific/Pago_Pago", 10.000000}, + {"Pacific/Guam", 10.000000}, + {"Pacific/Auckland", 10.000000}, + {"Pacific/Norfolk", 10.000000}, + {"Pacific/Kosrae", 10.000000}, + {"Pacific/Nauru", 10.000000}, + {"Pacific/Chatham", 10.000000}, + {"Pacific/Efate", 10.000000}, + {"Pacific/Midway", 10.000000}, + {"Pacific/Niue", 10.000000}, + {"Pacific/Enderbury", 10.000000}, + {"Pacific/Funafuti", 10.000000}, + {"Pacific/Gambier", 10.000000}, + {"EET", 10.000000}, + {"MST", 10.000000}, + {"Europe/Dublin", 10.000000}, + {"Europe/Minsk", 10.000000}, + {"Europe/Budapest", 10.000000}, + {"Europe/Riga", 10.000000}, + {"Europe/Jersey", 10.000000}, + {"Europe/London", 10.000000}, + {"Europe/Istanbul", 10.000000}, + {"Europe/Moscow", 10.000000}, + {"Europe/Chisinau", 10.000000}, + {"Europe/Andorra", 10.000000}, + {"Europe/Vaduz", 10.000000}, + {"Europe/Zaporozhye", 10.000000}, + {"Europe/San_Marino", 10.000000}, + {"Europe/Monaco", 10.000000}, + {"Europe/Ulyanovsk", 10.000000}, + {"Europe/Isle_of_Man", 10.000000}, + {"Europe/Tirane", 10.000000}, + {"Europe/Vatican", 10.000000}, + {"Europe/Belgrade", 10.000000}, + {"Europe/Paris", 10.000000}, + {"Europe/Nicosia", 10.000000}, + {"Europe/Athens", 10.000000}, + {"Europe/Malta", 10.000000}, + {"Europe/Astrakhan", 10.000000}, + {"Europe/Bratislava", 10.000000}, + {"Europe/Uzhgorod", 10.000000}, + {"Europe/Zurich", 10.000000}, + {"Europe/Brussels", 10.000000}, + {"Europe/Sofia", 10.000000}, + {"Europe/Kiev", 10.000000}, + {"Europe/Guernsey", 10.000000}, + {"Europe/Busingen", 10.000000}, + {"Europe/Copenhagen", 10.000000}, + {"Europe/Skopje", 10.000000}, + {"Europe/Luxembourg", 10.000000}, + {"Europe/Lisbon", 10.000000}, + {"Europe/Saratov", 10.000000}, + {"Europe/Zagreb", 10.000000}, + {"Europe/Simferopol", 10.000000}, + {"Europe/Amsterdam", 10.000000}, + {"Europe/Oslo", 10.000000}, + {"Europe/Samara", 10.000000}, + {"Europe/Warsaw", 10.000000}, + {"Europe/Prague", 10.000000}, + {"Europe/Vienna", 10.000000}, + {"Europe/Mariehamn", 10.000000}, + {"Europe/Gibraltar", 10.000000}, + {"Europe/Stockholm", 10.000000}, + {"Europe/Tallinn", 10.000000}, + {"Europe/Kaliningrad", 10.000000}, + {"Europe/Podgorica", 10.000000}, + {"Europe/Kirov", 10.000000}, + {"Europe/Helsinki", 10.000000}, + {"Europe/Sarajevo", 10.000000}, + {"Europe/Rome", 10.000000}, + {"Europe/Bucharest", 10.000000}, + {"Europe/Berlin", 10.000000}, + {"Europe/Volgograd", 10.000000}, + {"Europe/Ljubljana", 10.000000}, + {"Europe/Vilnius", 10.000000}, + {"Europe/Madrid", 10.000000}, + {"Antarctica/Casey", 10.000000}, + {"Antarctica/Macquarie", 10.000000}, + {"Antarctica/Rothera", 10.000000}, + {"Antarctica/Vostok", 10.000000}, + {"Antarctica/Davis", 10.000000}, + {"Antarctica/Troll", 10.000000}, + {"Antarctica/Mawson", 10.000000}, + {"Antarctica/McMurdo", 10.000000}, + {"Antarctica/DumontDUrville", 10.000000}, + {"Antarctica/Palmer", 10.000000}, + {"Antarctica/Syowa", 10.000000}, + {"WET", 10.000000}, + {"CST6CDT", 10.000000}, + {"MET", 10.000000}, + {"Arctic/Longyearbyen", 10.000000}, + {"Atlantic/Faroe", 10.000000}, + {"Atlantic/Madeira", 10.000000}, + {"Atlantic/Canary", 10.000000}, + {"Atlantic/Reykjavik", 10.000000}, + {"Atlantic/St_Helena", 10.000000}, + {"Atlantic/South_Georgia", 10.000000}, + {"Atlantic/Azores", 10.000000}, + {"Atlantic/Bermuda", 10.000000}, + {"Atlantic/Stanley", 10.000000}, + {"Atlantic/Cape_Verde", 10.000000}, + {"Africa/Niamey", 10.000000}, + {"Africa/Algiers", 10.000000}, + {"Africa/Maputo", 10.000000}, + {"Africa/Johannesburg", 10.000000}, + {"Africa/Addis_Ababa", 10.000000}, + {"Africa/Malabo", 10.000000}, + {"Africa/Cairo", 10.000000}, + {"Africa/Bissau", 10.000000}, + {"Africa/Ndjamena", 10.000000}, + {"Africa/Tunis", 10.000000}, + {"Africa/Harare", 10.000000}, + {"Africa/El_Aaiun", 10.000000}, + {"Africa/Kampala", 10.000000}, + {"Africa/Libreville", 10.000000}, + {"Africa/Blantyre", 10.000000}, + {"Africa/Brazzaville", 10.000000}, + {"Africa/Bangui", 10.000000}, + {"Africa/Luanda", 10.000000}, + {"Africa/Freetown", 10.000000}, + {"Africa/Casablanca", 10.000000}, + {"Africa/Conakry", 10.000000}, + {"Africa/Kinshasa", 10.000000}, + {"Africa/Dakar", 10.000000}, + {"Africa/Ouagadougou", 10.000000}, + {"Africa/Nouakchott", 10.000000}, + {"Africa/Monrovia", 10.000000}, + {"Africa/Kigali", 10.000000}, + {"Africa/Windhoek", 10.000000}, + {"Africa/Juba", 10.000000}, + {"Africa/Sao_Tome", 10.000000}, + {"Africa/Banjul", 10.000000}, + {"Africa/Mbabane", 10.000000}, + {"Africa/Asmara", 10.000000}, + {"Africa/Djibouti", 10.000000}, + {"Africa/Tripoli", 10.000000}, + {"Africa/Ceuta", 10.000000}, + {"Africa/Khartoum", 10.000000}, + {"Africa/Bamako", 10.000000}, + {"Africa/Porto-Novo", 10.000000}, + {"Africa/Mogadishu", 10.000000}, + {"Africa/Abidjan", 10.000000}, + {"Africa/Lusaka", 10.000000}, + {"Africa/Lagos", 10.000000}, + {"Africa/Lubumbashi", 10.000000}, + {"Africa/Nairobi", 10.000000}, + {"Africa/Accra", 10.000000}, + {"Africa/Maseru", 10.000000}, + {"Africa/Lome", 10.000000}, + {"Africa/Douala", 10.000000}, + {"Africa/Bujumbura", 10.000000}, + {"Africa/Dar_es_Salaam", 10.000000}, + {"Africa/Gaborone", 10.000000}, + {"Australia/Adelaide", 10.000000}, + {"Australia/Broken_Hill", 10.000000}, + {"Australia/Perth", 10.000000}, + {"Australia/Darwin", 10.000000}, + {"Australia/Lord_Howe", 10.000000}, + {"Australia/Hobart", 10.000000}, + {"Australia/Brisbane", 10.000000}, + {"Australia/Sydney", 10.000000}, + {"Australia/Lindeman", 10.000000}, + {"Australia/Melbourne", 10.000000}, + {"Australia/Eucla", 10.000000}, + {"America/Grand_Turk", 10.000000}, + {"America/St_Thomas", 10.000000}, + {"America/Havana", 10.000000}, + {"America/Thunder_Bay", 10.000000}, + {"America/Inuvik", 10.000000}, + {"America/Winnipeg", 10.000000}, + {"America/Maceio", 10.000000}, + {"America/Chihuahua", 10.000000}, + {"America/North_Dakota/Beulah", 10.000000}, + {"America/North_Dakota/Center", 10.000000}, + {"America/North_Dakota/New_Salem", 10.000000}, + {"America/Campo_Grande", 10.000000}, + {"America/Scoresbysund", 10.000000}, + {"America/Tijuana", 10.000000}, + {"America/Bahia", 10.000000}, + {"America/St_Vincent", 10.000000}, + {"America/Creston", 10.000000}, + {"America/Dawson", 10.000000}, + {"America/Tegucigalpa", 10.000000}, + {"America/Lima", 10.000000}, + {"America/Mexico_City", 10.000000}, + {"America/Dominica", 10.000000}, + {"America/Atikokan", 10.000000}, + {"America/Port-au-Prince", 10.000000}, + {"America/Yakutat", 10.000000}, + {"America/St_Kitts", 10.000000}, + {"America/Guatemala", 10.000000}, + {"America/St_Barthelemy", 10.000000}, + {"America/Vancouver", 10.000000}, + {"America/Jamaica", 10.000000}, + {"America/Whitehorse", 10.000000}, + {"America/Asuncion", 10.000000}, + {"America/Toronto", 10.000000}, + {"America/Hermosillo", 10.000000}, + {"America/Denver", 10.000000}, + {"America/Mazatlan", 10.000000}, + {"America/Iqaluit", 10.000000}, + {"America/Nuuk", 10.000000}, + {"America/Cayenne", 10.000000}, + {"America/Santarem", 10.000000}, + {"America/Noronha", 10.000000}, + {"America/Ojinaga", 10.000000}, + {"America/Fort_Nelson", 10.000000}, + {"America/Aruba", 10.000000}, + {"America/Indiana/Vevay", 10.000000}, + {"America/Indiana/Marengo", 10.000000}, + {"America/Indiana/Indianapolis", 10.000000}, + {"America/Indiana/Tell_City", 10.000000}, + {"America/Indiana/Petersburg", 10.000000}, + {"America/Indiana/Winamac", 10.000000}, + {"America/Indiana/Knox", 10.000000}, + {"America/Indiana/Vincennes", 10.000000}, + {"America/Cayman", 10.000000}, + {"America/Sao_Paulo", 10.000000}, + {"America/Curacao", 10.000000}, + {"America/Anchorage", 10.000000}, + {"America/Guyana", 10.000000}, + {"America/Rankin_Inlet", 10.000000}, + {"America/Antigua", 10.000000}, + {"America/Juneau", 10.000000}, + {"America/Merida", 10.000000}, + {"America/Punta_Arenas", 10.000000}, + {"America/Moncton", 10.000000}, + {"America/Fortaleza", 10.000000}, + {"America/Resolute", 10.000000}, + {"America/Nassau", 10.000000}, + {"America/Edmonton", 10.000000}, + {"America/Regina", 10.000000}, + {"America/Halifax", 10.000000}, + {"America/Danmarkshavn", 10.000000}, + {"America/Metlakatla", 10.000000}, + {"America/Guadeloupe", 10.000000}, + {"America/Caracas", 10.000000}, + {"America/Detroit", 10.000000}, + {"America/Matamoros", 10.000000}, + {"America/Glace_Bay", 10.000000}, + {"America/Phoenix", 10.000000}, + {"America/La_Paz", 10.000000}, + {"America/Swift_Current", 10.000000}, + {"America/Nipigon", 10.000000}, + {"America/Cancun", 10.000000}, + {"America/Port_of_Spain", 10.000000}, + {"America/Kralendijk", 10.000000}, + {"America/Grenada", 10.000000}, + {"America/Belem", 10.000000}, + {"America/Managua", 10.000000}, + {"America/Adak", 10.000000}, + {"America/St_Lucia", 10.000000}, + {"America/Rio_Branco", 10.000000}, + {"America/Santiago", 10.000000}, + {"America/Puerto_Rico", 10.000000}, + {"America/Miquelon", 10.000000}, + {"America/Cuiaba", 10.000000}, + {"America/Martinique", 10.000000}, + {"America/Argentina/Buenos_Aires", 10.000000}, + {"America/Argentina/San_Luis", 10.000000}, + {"America/Argentina/Catamarca", 10.000000}, + {"America/Argentina/Jujuy", 10.000000}, + {"America/Argentina/Salta", 10.000000}, + {"America/Argentina/Ushuaia", 10.000000}, + {"America/Argentina/Mendoza", 10.000000}, + {"America/Argentina/Rio_Gallegos", 10.000000}, + {"America/Argentina/Tucuman", 10.000000}, + {"America/Argentina/San_Juan", 10.000000}, + {"America/Argentina/Cordoba", 10.000000}, + {"America/Argentina/La_Rioja", 10.000000}, + {"America/Barbados", 10.000000}, + {"America/Monterrey", 10.000000}, + {"America/Thule", 10.000000}, + {"America/Montserrat", 10.000000}, + {"America/Guayaquil", 10.000000}, + {"America/St_Johns", 10.000000}, + {"America/Boise", 10.000000}, + {"America/Manaus", 10.000000}, + {"America/Nome", 10.000000}, + {"America/Goose_Bay", 10.000000}, + {"America/Belize", 10.000000}, + {"America/Sitka", 10.000000}, + {"America/Dawson_Creek", 10.000000}, + {"America/Recife", 10.000000}, + {"America/Kentucky/Louisville", 10.000000}, + {"America/Kentucky/Monticello", 10.000000}, + {"America/New_York", 10.000000}, + {"America/Tortola", 10.000000}, + {"America/Chicago", 10.000000}, + {"America/Pangnirtung", 10.000000}, + {"America/Boa_Vista", 10.000000}, + {"America/Bogota", 10.000000}, + {"America/Rainy_River", 10.000000}, + {"America/El_Salvador", 10.000000}, + {"America/Bahia_Banderas", 10.000000}, + {"America/Yellowknife", 10.000000}, + {"America/Montevideo", 10.000000}, + {"America/Cambridge_Bay", 10.000000}, + {"America/Panama", 10.000000}, + {"America/Santo_Domingo", 10.000000}, + {"America/Anguilla", 10.000000}, + {"America/Paramaribo", 10.000000}, + {"America/Marigot", 10.000000}, + {"America/Menominee", 10.000000}, + {"America/Blanc-Sablon", 10.000000}, + {"America/Costa_Rica", 10.000000}, + {"America/Los_Angeles", 10.000000}, + {"America/Lower_Princes", 10.000000}, + {"America/Eirunepe", 10.000000}, + {"America/Araguaina", 10.000000}, + {"America/Porto_Velho", 10.000000}, + {"EST", 10.000000}, + {"CET", 10.000000}, + {"MST7MDT", 10.000000}, + {"Indian/Chagos", 10.000000}, + {"Indian/Kerguelen", 10.000000}, + {"Indian/Reunion", 10.000000}, + {"Indian/Antananarivo", 10.000000}, + {"Indian/Cocos", 10.000000}, + {"Indian/Mauritius", 10.000000}, + {"Indian/Christmas", 10.000000}, + {"Indian/Maldives", 10.000000}, + {"Indian/Comoro", 10.000000}, + {"Indian/Mahe", 10.000000}, + {"Indian/Mayotte", 10.000000}, + {"Asia/Novokuznetsk", 10.000000}, + {"Asia/Magadan", 10.000000}, + {"Asia/Yangon", 10.000000}, + {"Asia/Samarkand", 10.000000}, + {"Asia/Tehran", 10.000000}, + {"Asia/Dili", 10.000000}, + {"Asia/Yerevan", 10.000000}, + {"Asia/Qatar", 10.000000}, + {"Asia/Chita", 10.000000}, + {"Asia/Makassar", 10.000000}, + {"Asia/Hovd", 10.000000}, + {"Asia/Istanbul", 10.000000}, + {"Asia/Irkutsk", 10.000000}, + {"Asia/Pontianak", 10.000000}, + {"Asia/Qyzylorda", 10.000000}, + {"Asia/Srednekolymsk", 10.000000}, + {"Asia/Aden", 10.000000}, + {"Asia/Kabul", 10.000000}, + {"Asia/Macau", 10.000000}, + {"Asia/Riyadh", 10.000000}, + {"Asia/Taipei", 10.000000}, + {"Asia/Manila", 10.000000}, + {"Asia/Aqtau", 10.000000}, + {"Asia/Thimphu", 10.000000}, + {"Asia/Shanghai", 10.000000}, + {"Asia/Choibalsan", 10.000000}, + {"Asia/Nicosia", 10.000000}, + {"Asia/Dubai", 10.000000}, + {"Asia/Baku", 10.000000}, + {"Asia/Kuching", 10.000000}, + {"Asia/Gaza", 10.000000}, + {"Asia/Jayapura", 10.000000}, + {"Asia/Tokyo", 10.000000}, + {"Asia/Muscat", 10.000000}, + {"Asia/Kolkata", 10.000000}, + {"Asia/Ho_Chi_Minh", 10.000000}, + {"Asia/Tashkent", 10.000000}, + {"Asia/Bangkok", 10.000000}, + {"Asia/Karachi", 10.000000}, + {"Asia/Krasnoyarsk", 10.000000}, + {"Asia/Yekaterinburg", 10.000000}, + {"Asia/Famagusta", 10.000000}, + {"Asia/Ulaanbaatar", 10.000000}, + {"Asia/Bahrain", 10.000000}, + {"Asia/Barnaul", 10.000000}, + {"Asia/Jerusalem", 10.000000}, + {"Asia/Qostanay", 10.000000}, + {"Asia/Ust-Nera", 10.000000}, + {"Asia/Tomsk", 10.000000}, + {"Asia/Kuala_Lumpur", 10.000000}, + {"Asia/Brunei", 10.000000}, + {"Asia/Aqtobe", 10.000000}, + {"Asia/Vladivostok", 10.000000}, + {"Asia/Damascus", 10.000000}, + {"Asia/Omsk", 10.000000}, + {"Asia/Almaty", 10.000000}, + {"Asia/Dhaka", 10.000000}, + {"Asia/Tbilisi", 10.000000}, + {"Asia/Baghdad", 10.000000}, + {"Asia/Phnom_Penh", 10.000000}, + {"Asia/Kamchatka", 10.000000}, + {"Asia/Ashgabat", 10.000000}, + {"Asia/Sakhalin", 10.000000}, + {"Asia/Novosibirsk", 10.000000}, + {"Asia/Kuwait", 10.000000}, + {"Asia/Hong_Kong", 10.000000}, + {"Asia/Amman", 10.000000}, + {"Asia/Beirut", 10.000000}, + {"Asia/Yakutsk", 10.000000}, + {"Asia/Colombo", 10.000000}, + {"Asia/Oral", 10.000000}, + {"Asia/Kathmandu", 10.000000}, + {"Asia/Bishkek", 10.000000}, + {"Asia/Hebron", 10.000000}, + {"Asia/Singapore", 10.000000}, + {"Asia/Atyrau", 10.000000}, + {"Asia/Khandyga", 10.000000}, + {"Asia/Vientiane", 10.000000}, + {"Asia/Jakarta", 10.000000}, + {"Asia/Dushanbe", 10.000000}, + {"Asia/Seoul", 10.000000}, + {"Asia/Pyongyang", 10.000000}, + {"Asia/Urumqi", 10.000000}, + {"Asia/Anadyr", 10.000000}, + {"PST8PDT", 10.000000}, + {"HST", 10.000000}, + {"EST5EDT", 10.000000}, +}; + +/** + * @tc.name : difftime_0100 + * @tc.desc : according to different time zones, calculate the time difference between two moments + * @tc.level : Level 0 + */ +void difftime_0100(void) +{ + time_t timeStart = 20000; + time_t timeEnd = 20010; + for (int32_t i = 0; i < (int32_t)(sizeof(gResultData) / sizeof(gResultData[0])); i++) { + const char *tz = gResultData[i].tz; + const char *handlerChar; +#ifdef TIME_ZONE_SUB_TAG + char *str = strrchr(tz, TIME_ZONE_SUB_TAG); + if (str) { + handlerChar = ++str; + } else { + handlerChar = tz; + } +#else + handlerChar = tz; +#endif + setenv("TZ", handlerChar, 1); + tzset(); + double returnVal; + returnVal = difftime(timeEnd, timeStart); + EXPECT_TRUE( + "difftime_0100", abs(gResultData[i].result - returnVal) >= 0 && abs(gResultData[i].result - returnVal) < 1); + } +} + +int main(void) +{ + difftime_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/gettimeofday.c b/libc-test/src/functionalext/supplement/time/gettimeofday.c new file mode 100644 index 00000000..3b2b352f --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/gettimeofday.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int SUCCESS = 0; + +/** + * @tc.name : gettimeofday_0100 + * @tc.desc : Each parameter is valid, and the current system time can be obtained. + * @tc.level : Level 0 + */ +void gettimeofday_0100(void) +{ + struct timeval tv; + char str[10]; + system("date +%s > ./time.txt"); + FILE *fptr = fopen("time.txt", "r"); + fflush(fptr); + fread(str, sizeof(str), 1, fptr); + int sec = atoi(str); + int returnflag = gettimeofday(&tv, NULL); + EXPECT_EQ("gettimeofday_0100", returnflag, SUCCESS); + EXPECT_EQ("gettimeofday_0100", (long)sec, (long)tv.tv_sec); + remove("time.txt"); +} + +/** + * @tc.name : gettimeofday_0200 + * @tc.desc : Each parameter is valid, and the current system time can be obtained. + * @tc.level : Level 2 + */ +void gettimeofday_0200(void) +{ + struct timeval tv; + int returnflag = gettimeofday(&tv, NULL); + EXPECT_EQ("gettimeofday_0200", returnflag, SUCCESS); +} + +int main() +{ + gettimeofday_0100(); + gettimeofday_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/gmtime.c b/libc-test/src/functionalext/supplement/time/gmtime.c new file mode 100644 index 00000000..989dfca5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/gmtime.c @@ -0,0 +1,516 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +struct gmtime_struct { + const char *tz; + const char *result; +}; + +static const struct gmtime_struct gResultData[] = { + {"Pacific/Rarotonga", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Wake", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Tarawa", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Fakaofo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Apia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Kwajalein", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Tahiti", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Easter", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Tongatapu", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Guadalcanal", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Chuuk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Pitcairn", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Pohnpei", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Fiji", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Majuro", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Kiritimati", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Port_Moresby", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Galapagos", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Saipan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Marquesas", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Wallis", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Palau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Bougainville", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Honolulu", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Noumea", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Pago_Pago", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Guam", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Auckland", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Norfolk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Kosrae", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Nauru", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Chatham", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Efate", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Midway", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Niue", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Enderbury", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Funafuti", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Gambier", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"EET", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"MST", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Dublin", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Minsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Budapest", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Riga", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Jersey", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/London", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Istanbul", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Moscow", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Chisinau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Andorra", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Vaduz", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Zaporozhye", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/San_Marino", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Monaco", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Ulyanovsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Isle_of_Man", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Tirane", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Vatican", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Belgrade", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Paris", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Nicosia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Athens", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Malta", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Astrakhan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Bratislava", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Uzhgorod", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Zurich", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Brussels", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Sofia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Kiev", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Guernsey", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Busingen", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Copenhagen", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Skopje", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Luxembourg", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Lisbon", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Saratov", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Zagreb", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Simferopol", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Amsterdam", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Oslo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Samara", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Warsaw", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Prague", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Vienna", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Mariehamn", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Gibraltar", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Stockholm", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Tallinn", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Kaliningrad", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Podgorica", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Kirov", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Helsinki", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Sarajevo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Rome", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Bucharest", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Berlin", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Volgograd", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Ljubljana", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Vilnius", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Madrid", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Casey", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Macquarie", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Rothera", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Vostok", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Davis", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Troll", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Mawson", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/McMurdo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/DumontDUrville", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Palmer", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Syowa", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"WET", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"CST6CDT", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"MET", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Arctic/Longyearbyen", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Faroe", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Madeira", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Canary", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Reykjavik", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/St_Helena", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/South_Georgia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Azores", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Bermuda", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Stanley", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Cape_Verde", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Niamey", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Algiers", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Maputo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Johannesburg", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Addis_Ababa", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Malabo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Cairo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Bissau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Ndjamena", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Tunis", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Harare", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/El_Aaiun", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Kampala", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Libreville", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Blantyre", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Brazzaville", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Bangui", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Luanda", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Freetown", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Casablanca", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Conakry", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Kinshasa", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Dakar", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Ouagadougou", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Nouakchott", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Monrovia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Kigali", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Windhoek", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Juba", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Sao_Tome", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Banjul", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Mbabane", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Asmara", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Djibouti", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Tripoli", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Ceuta", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Khartoum", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Bamako", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Porto-Novo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Mogadishu", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Abidjan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Lusaka", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Lagos", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Lubumbashi", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Nairobi", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Accra", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Maseru", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Lome", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Douala", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Bujumbura", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Dar_es_Salaam", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Gaborone", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Adelaide", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Broken_Hill", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Perth", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Darwin", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Lord_Howe", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Hobart", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Brisbane", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Sydney", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Lindeman", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Melbourne", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Eucla", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Grand_Turk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/St_Thomas", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Havana", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Thunder_Bay", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Inuvik", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Winnipeg", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Maceio", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Chihuahua", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/North_Dakota/Beulah", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/North_Dakota/Center", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/North_Dakota/New_Salem", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Campo_Grande", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Scoresbysund", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Tijuana", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Bahia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/St_Vincent", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Creston", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Dawson", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Tegucigalpa", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Lima", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Mexico_City", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Dominica", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Atikokan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Port-au-Prince", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Yakutat", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/St_Kitts", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Guatemala", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/St_Barthelemy", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Vancouver", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Jamaica", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Whitehorse", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Asuncion", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Toronto", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Hermosillo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Denver", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Mazatlan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Iqaluit", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Nuuk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Cayenne", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Santarem", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Noronha", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Ojinaga", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Fort_Nelson", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Aruba", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Vevay", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Marengo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Indianapolis", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Tell_City", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Petersburg", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Winamac", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Knox", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Vincennes", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Cayman", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Sao_Paulo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Curacao", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Anchorage", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Guyana", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Rankin_Inlet", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Antigua", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Juneau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Merida", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Punta_Arenas", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Moncton", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Fortaleza", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Resolute", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Nassau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Edmonton", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Regina", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Halifax", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Danmarkshavn", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Metlakatla", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Guadeloupe", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Caracas", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Detroit", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Matamoros", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Glace_Bay", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Phoenix", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/La_Paz", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Swift_Current", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Nipigon", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Cancun", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Port_of_Spain", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Kralendijk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Grenada", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Belem", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Managua", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Adak", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/St_Lucia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Rio_Branco", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Santiago", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Puerto_Rico", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Miquelon", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Cuiaba", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Martinique", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Buenos_Aires", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/San_Luis", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Catamarca", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Jujuy", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Salta", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Ushuaia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Mendoza", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Rio_Gallegos", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Tucuman", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/San_Juan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Cordoba", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/La_Rioja", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Barbados", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Monterrey", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Thule", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Montserrat", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Guayaquil", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/St_Johns", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Boise", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Manaus", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Nome", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Goose_Bay", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Belize", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Sitka", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Dawson_Creek", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Recife", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Kentucky/Louisville", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Kentucky/Monticello", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/New_York", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Tortola", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Chicago", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Pangnirtung", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Boa_Vista", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Bogota", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Rainy_River", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/El_Salvador", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Bahia_Banderas", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Yellowknife", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Montevideo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Cambridge_Bay", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Panama", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Santo_Domingo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Anguilla", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Paramaribo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Marigot", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Menominee", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Blanc-Sablon", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Costa_Rica", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Los_Angeles", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Lower_Princes", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Eirunepe", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Araguaina", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Porto_Velho", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"EST", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"CET", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"MST7MDT", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Chagos", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Kerguelen", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Reunion", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Antananarivo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Cocos", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Mauritius", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Christmas", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Maldives", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Comoro", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Mahe", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Mayotte", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Novokuznetsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Magadan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Yangon", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Samarkand", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Tehran", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Dili", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Yerevan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Qatar", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Chita", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Makassar", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Hovd", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Istanbul", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Irkutsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Pontianak", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Qyzylorda", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Srednekolymsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Aden", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Kabul", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Macau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Riyadh", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Taipei", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Manila", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Aqtau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Thimphu", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Shanghai", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Choibalsan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Nicosia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Dubai", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Baku", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Kuching", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Gaza", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Jayapura", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Tokyo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Muscat", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Kolkata", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Ho_Chi_Minh", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Tashkent", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Bangkok", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Karachi", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Krasnoyarsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Yekaterinburg", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Famagusta", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Ulaanbaatar", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Bahrain", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Barnaul", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Jerusalem", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Qostanay", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Ust-Nera", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Tomsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Kuala_Lumpur", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Brunei", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Aqtobe", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Vladivostok", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Damascus", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Omsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Almaty", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Dhaka", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Tbilisi", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Baghdad", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Phnom_Penh", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Kamchatka", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Ashgabat", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Sakhalin", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Novosibirsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Kuwait", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Hong_Kong", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Amman", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Beirut", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Yakutsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Colombo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Oral", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Kathmandu", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Bishkek", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Hebron", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Singapore", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Atyrau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Khandyga", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Vientiane", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Jakarta", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Dushanbe", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Seoul", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Pyongyang", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Urumqi", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Anadyr", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"PST8PDT", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"HST", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"EST5EDT", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, +}; + +static time_t gTime = 1659177614; +static int16_t gYearBase = 1900; +static int16_t gBufferSize = 500; + +/** + * @tc.name : gmtime_0100 + * @tc.desc : according to different time zones, convert date and time to GMT time + * @tc.level : Level 0 + */ +void gmtime_0100(void) +{ + for (int32_t i = 0; i < (int32_t)(sizeof(gResultData) / sizeof(gResultData[0])); i++) { + const char *tz = gResultData[i].tz; + const char *handlerChar; +#ifdef TIME_ZONE_SUB_TAG + char *str = strrchr(tz, TIME_ZONE_SUB_TAG); + if (str) { + handlerChar = ++str; + } else { + handlerChar = tz; + } +#else + handlerChar = tz; +#endif + setenv("TZ", handlerChar, 1); + tzset(); + struct tm *gmtm; + gmtm = gmtime(&gTime); + char buff[gBufferSize]; + int cnt = sprintf(buff, + "%d-%d-%d %d:%d:%d wday=%d,yday=%d,isdst=%d,gmtoff=%ld,zone=%s", + (gmtm->tm_year + gYearBase), + gmtm->tm_mon, + gmtm->tm_mday, + gmtm->tm_hour, + gmtm->tm_min, + gmtm->tm_sec, + gmtm->tm_wday, + gmtm->tm_yday, + gmtm->tm_isdst, + gmtm->tm_gmtoff, + gmtm->tm_zone); + EXPECT_TRUE("gmtime_0100", cnt > 0); + EXPECT_STREQ("gmtime_0100", gResultData[i].result, buff); + } +} + +int main(void) +{ + gmtime_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/gmtime_r.c b/libc-test/src/functionalext/supplement/time/gmtime_r.c new file mode 100644 index 00000000..4d5a219f --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/gmtime_r.c @@ -0,0 +1,516 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +struct gmtime_r_struct { + const char *tz; + const char *result; +}; + +static const struct gmtime_r_struct gResultData[] = { + {"Pacific/Rarotonga", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Wake", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Tarawa", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Fakaofo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Apia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Kwajalein", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Tahiti", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Easter", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Tongatapu", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Guadalcanal", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Chuuk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Pitcairn", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Pohnpei", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Fiji", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Majuro", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Kiritimati", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Port_Moresby", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Galapagos", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Saipan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Marquesas", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Wallis", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Palau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Bougainville", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Honolulu", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Noumea", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Pago_Pago", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Guam", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Auckland", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Norfolk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Kosrae", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Nauru", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Chatham", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Efate", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Midway", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Niue", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Enderbury", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Funafuti", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Pacific/Gambier", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"EET", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"MST", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Dublin", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Minsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Budapest", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Riga", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Jersey", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/London", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Istanbul", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Moscow", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Chisinau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Andorra", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Vaduz", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Zaporozhye", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/San_Marino", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Monaco", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Ulyanovsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Isle_of_Man", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Tirane", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Vatican", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Belgrade", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Paris", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Nicosia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Athens", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Malta", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Astrakhan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Bratislava", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Uzhgorod", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Zurich", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Brussels", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Sofia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Kiev", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Guernsey", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Busingen", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Copenhagen", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Skopje", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Luxembourg", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Lisbon", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Saratov", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Zagreb", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Simferopol", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Amsterdam", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Oslo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Samara", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Warsaw", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Prague", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Vienna", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Mariehamn", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Gibraltar", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Stockholm", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Tallinn", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Kaliningrad", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Podgorica", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Kirov", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Helsinki", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Sarajevo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Rome", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Bucharest", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Berlin", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Volgograd", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Ljubljana", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Vilnius", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Europe/Madrid", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Casey", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Macquarie", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Rothera", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Vostok", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Davis", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Troll", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Mawson", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/McMurdo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/DumontDUrville", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Palmer", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Antarctica/Syowa", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"WET", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"CST6CDT", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"MET", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Arctic/Longyearbyen", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Faroe", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Madeira", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Canary", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Reykjavik", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/St_Helena", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/South_Georgia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Azores", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Bermuda", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Stanley", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Atlantic/Cape_Verde", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Niamey", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Algiers", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Maputo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Johannesburg", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Addis_Ababa", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Malabo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Cairo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Bissau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Ndjamena", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Tunis", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Harare", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/El_Aaiun", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Kampala", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Libreville", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Blantyre", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Brazzaville", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Bangui", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Luanda", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Freetown", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Casablanca", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Conakry", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Kinshasa", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Dakar", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Ouagadougou", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Nouakchott", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Monrovia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Kigali", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Windhoek", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Juba", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Sao_Tome", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Banjul", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Mbabane", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Asmara", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Djibouti", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Tripoli", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Ceuta", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Khartoum", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Bamako", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Porto-Novo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Mogadishu", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Abidjan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Lusaka", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Lagos", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Lubumbashi", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Nairobi", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Accra", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Maseru", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Lome", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Douala", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Bujumbura", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Dar_es_Salaam", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Africa/Gaborone", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Adelaide", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Broken_Hill", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Perth", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Darwin", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Lord_Howe", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Hobart", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Brisbane", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Sydney", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Lindeman", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Melbourne", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Australia/Eucla", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Grand_Turk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/St_Thomas", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Havana", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Thunder_Bay", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Inuvik", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Winnipeg", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Maceio", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Chihuahua", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/North_Dakota/Beulah", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/North_Dakota/Center", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/North_Dakota/New_Salem", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Campo_Grande", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Scoresbysund", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Tijuana", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Bahia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/St_Vincent", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Creston", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Dawson", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Tegucigalpa", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Lima", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Mexico_City", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Dominica", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Atikokan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Port-au-Prince", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Yakutat", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/St_Kitts", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Guatemala", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/St_Barthelemy", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Vancouver", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Jamaica", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Whitehorse", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Asuncion", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Toronto", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Hermosillo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Denver", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Mazatlan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Iqaluit", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Nuuk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Cayenne", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Santarem", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Noronha", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Ojinaga", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Fort_Nelson", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Aruba", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Vevay", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Marengo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Indianapolis", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Tell_City", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Petersburg", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Winamac", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Knox", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Indiana/Vincennes", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Cayman", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Sao_Paulo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Curacao", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Anchorage", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Guyana", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Rankin_Inlet", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Antigua", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Juneau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Merida", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Punta_Arenas", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Moncton", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Fortaleza", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Resolute", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Nassau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Edmonton", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Regina", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Halifax", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Danmarkshavn", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Metlakatla", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Guadeloupe", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Caracas", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Detroit", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Matamoros", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Glace_Bay", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Phoenix", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/La_Paz", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Swift_Current", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Nipigon", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Cancun", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Port_of_Spain", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Kralendijk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Grenada", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Belem", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Managua", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Adak", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/St_Lucia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Rio_Branco", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Santiago", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Puerto_Rico", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Miquelon", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Cuiaba", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Martinique", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Buenos_Aires", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/San_Luis", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Catamarca", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Jujuy", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Salta", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Ushuaia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Mendoza", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Rio_Gallegos", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Tucuman", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/San_Juan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/Cordoba", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Argentina/La_Rioja", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Barbados", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Monterrey", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Thule", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Montserrat", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Guayaquil", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/St_Johns", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Boise", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Manaus", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Nome", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Goose_Bay", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Belize", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Sitka", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Dawson_Creek", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Recife", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Kentucky/Louisville", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Kentucky/Monticello", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/New_York", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Tortola", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Chicago", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Pangnirtung", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Boa_Vista", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Bogota", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Rainy_River", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/El_Salvador", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Bahia_Banderas", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Yellowknife", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Montevideo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Cambridge_Bay", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Panama", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Santo_Domingo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Anguilla", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Paramaribo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Marigot", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Menominee", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Blanc-Sablon", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Costa_Rica", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Los_Angeles", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Lower_Princes", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Eirunepe", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Araguaina", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"America/Porto_Velho", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"EST", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"CET", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"MST7MDT", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Chagos", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Kerguelen", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Reunion", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Antananarivo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Cocos", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Mauritius", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Christmas", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Maldives", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Comoro", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Mahe", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Indian/Mayotte", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Novokuznetsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Magadan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Yangon", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Samarkand", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Tehran", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Dili", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Yerevan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Qatar", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Chita", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Makassar", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Hovd", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Istanbul", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Irkutsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Pontianak", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Qyzylorda", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Srednekolymsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Aden", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Kabul", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Macau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Riyadh", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Taipei", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Manila", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Aqtau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Thimphu", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Shanghai", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Choibalsan", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Nicosia", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Dubai", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Baku", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Kuching", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Gaza", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Jayapura", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Tokyo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Muscat", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Kolkata", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Ho_Chi_Minh", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Tashkent", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Bangkok", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Karachi", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Krasnoyarsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Yekaterinburg", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Famagusta", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Ulaanbaatar", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Bahrain", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Barnaul", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Jerusalem", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Qostanay", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Ust-Nera", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Tomsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Kuala_Lumpur", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Brunei", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Aqtobe", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Vladivostok", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Damascus", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Omsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Almaty", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Dhaka", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Tbilisi", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Baghdad", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Phnom_Penh", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Kamchatka", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Ashgabat", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Sakhalin", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Novosibirsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Kuwait", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Hong_Kong", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Amman", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Beirut", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Yakutsk", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Colombo", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Oral", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Kathmandu", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Bishkek", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Hebron", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Singapore", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Atyrau", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Khandyga", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Vientiane", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Jakarta", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Dushanbe", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Seoul", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Pyongyang", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Urumqi", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"Asia/Anadyr", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"PST8PDT", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"HST", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, + {"EST5EDT", "2022-6-30 10:40:14 wday=6,yday=210,isdst=0,gmtoff=0,zone=GMT"}, +}; + +static time_t gTime = 1659177614; +static int16_t gYearBase = 1900; +static int16_t gBufferSize = 500; + +/** + * @tc.name : gmtime_r_0100 + * @tc.desc : according to different time zones, convert date and time to GMT time + * @tc.level : Level 0 + */ +void gmtime_r_0100(void) +{ + for (int32_t i = 0; i < (int32_t)(sizeof(gResultData) / sizeof(gResultData[0])); i++) { + const char *tz = gResultData[i].tz; + const char *handlerChar; +#ifdef TIME_ZONE_SUB_TAG + char *str = strrchr(tz, TIME_ZONE_SUB_TAG); + if (str) { + handlerChar = ++str; + } else { + handlerChar = tz; + } +#else + handlerChar = tz; +#endif + setenv("TZ", handlerChar, 1); + tzset(); + struct tm res = {0}; + struct tm *gmtm = gmtime_r(&gTime, &res); + char buff[gBufferSize]; + int cnt = sprintf(buff, + "%d-%d-%d %d:%d:%d wday=%d,yday=%d,isdst=%d,gmtoff=%ld,zone=%s", + (gmtm->tm_year + gYearBase), + gmtm->tm_mon, + gmtm->tm_mday, + gmtm->tm_hour, + gmtm->tm_min, + gmtm->tm_sec, + gmtm->tm_wday, + gmtm->tm_yday, + gmtm->tm_isdst, + gmtm->tm_gmtoff, + gmtm->tm_zone); + EXPECT_TRUE("gmtime_r_0100", cnt > 0); + EXPECT_STREQ("gmtime_r_0100", gResultData[i].result, buff); + } +} + +int main(void) +{ + gmtime_r_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/mktime.c b/libc-test/src/functionalext/supplement/time/mktime.c new file mode 100644 index 00000000..3d5e057c --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/mktime.c @@ -0,0 +1,503 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +struct mktime_struct { + const char *tz; + const time_t result; +}; + +static const struct mktime_struct gResultData[] = { + {"Pacific/Rarotonga", 1659177614}, + {"Pacific/Wake", 1659177614}, + {"Pacific/Tarawa", 1659177614}, + {"Pacific/Fakaofo", 1659177614}, + {"Pacific/Apia", 1659177614}, + {"Pacific/Kwajalein", 1659177614}, + {"Pacific/Tahiti", 1659177614}, + {"Pacific/Easter", 1659177614}, + {"Pacific/Tongatapu", 1659177614}, + {"Pacific/Guadalcanal", 1659177614}, + {"Pacific/Chuuk", 1659177614}, + {"Pacific/Pitcairn", 1659177614}, + {"Pacific/Pohnpei", 1659177614}, + {"Pacific/Fiji", 1659177614}, + {"Pacific/Majuro", 1659177614}, + {"Pacific/Kiritimati", 1659177614}, + {"Pacific/Port_Moresby", 1659177614}, + {"Pacific/Galapagos", 1659177614}, + {"Pacific/Saipan", 1659177614}, + {"Pacific/Marquesas", 1659177614}, + {"Pacific/Wallis", 1659177614}, + {"Pacific/Palau", 1659177614}, + {"Pacific/Bougainville", 1659177614}, + {"Pacific/Honolulu", 1659177614}, + {"Pacific/Noumea", 1659177614}, + {"Pacific/Pago_Pago", 1659177614}, + {"Pacific/Guam", 1659177614}, + {"Pacific/Auckland", 1659177614}, + {"Pacific/Norfolk", 1659177614}, + {"Pacific/Kosrae", 1659177614}, + {"Pacific/Nauru", 1659177614}, + {"Pacific/Chatham", 1659177614}, + {"Pacific/Efate", 1659177614}, + {"Pacific/Midway", 1659177614}, + {"Pacific/Niue", 1659177614}, + {"Pacific/Enderbury", 1659177614}, + {"Pacific/Funafuti", 1659177614}, + {"Pacific/Gambier", 1659177614}, + {"EET", 1659177614}, + {"MST", 1659177614}, + {"Europe/Dublin", 1659177614}, + {"Europe/Minsk", 1659177614}, + {"Europe/Budapest", 1659177614}, + {"Europe/Riga", 1659177614}, + {"Europe/Jersey", 1659177614}, + {"Europe/London", 1659177614}, + {"Europe/Istanbul", 1659177614}, + {"Europe/Moscow", 1659177614}, + {"Europe/Chisinau", 1659177614}, + {"Europe/Andorra", 1659177614}, + {"Europe/Vaduz", 1659177614}, + {"Europe/Zaporozhye", 1659177614}, + {"Europe/San_Marino", 1659177614}, + {"Europe/Monaco", 1659177614}, + {"Europe/Ulyanovsk", 1659177614}, + {"Europe/Isle_of_Man", 1659177614}, + {"Europe/Tirane", 1659177614}, + {"Europe/Vatican", 1659177614}, + {"Europe/Belgrade", 1659177614}, + {"Europe/Paris", 1659177614}, + {"Europe/Nicosia", 1659177614}, + {"Europe/Athens", 1659177614}, + {"Europe/Malta", 1659177614}, + {"Europe/Astrakhan", 1659177614}, + {"Europe/Bratislava", 1659177614}, + {"Europe/Uzhgorod", 1659177614}, + {"Europe/Zurich", 1659177614}, + {"Europe/Brussels", 1659177614}, + {"Europe/Sofia", 1659177614}, + {"Europe/Kiev", 1659177614}, + {"Europe/Guernsey", 1659177614}, + {"Europe/Busingen", 1659177614}, + {"Europe/Copenhagen", 1659177614}, + {"Europe/Skopje", 1659177614}, + {"Europe/Luxembourg", 1659177614}, + {"Europe/Lisbon", 1659177614}, + {"Europe/Saratov", 1659177614}, + {"Europe/Zagreb", 1659177614}, + {"Europe/Simferopol", 1659177614}, + {"Europe/Amsterdam", 1659177614}, + {"Europe/Oslo", 1659177614}, + {"Europe/Samara", 1659177614}, + {"Europe/Warsaw", 1659177614}, + {"Europe/Prague", 1659177614}, + {"Europe/Vienna", 1659177614}, + {"Europe/Mariehamn", 1659177614}, + {"Europe/Gibraltar", 1659177614}, + {"Europe/Stockholm", 1659177614}, + {"Europe/Tallinn", 1659177614}, + {"Europe/Kaliningrad", 1659177614}, + {"Europe/Podgorica", 1659177614}, + {"Europe/Kirov", 1659177614}, + {"Europe/Helsinki", 1659177614}, + {"Europe/Sarajevo", 1659177614}, + {"Europe/Rome", 1659177614}, + {"Europe/Bucharest", 1659177614}, + {"Europe/Berlin", 1659177614}, + {"Europe/Volgograd", 1659177614}, + {"Europe/Ljubljana", 1659177614}, + {"Europe/Vilnius", 1659177614}, + {"Europe/Madrid", 1659177614}, + {"Antarctica/Casey", 1659177614}, + {"Antarctica/Macquarie", 1659177614}, + {"Antarctica/Rothera", 1659177614}, + {"Antarctica/Vostok", 1659177614}, + {"Antarctica/Davis", 1659177614}, + {"Antarctica/Troll", 1659177614}, + {"Antarctica/Mawson", 1659177614}, + {"Antarctica/McMurdo", 1659177614}, + {"Antarctica/DumontDUrville", 1659177614}, + {"Antarctica/Palmer", 1659177614}, + {"Antarctica/Syowa", 1659177614}, + {"WET", 1659177614}, + {"CST6CDT", 1659177614}, + {"MET", 1659177614}, + {"Arctic/Longyearbyen", 1659177614}, + {"Atlantic/Faroe", 1659177614}, + {"Atlantic/Madeira", 1659177614}, + {"Atlantic/Canary", 1659177614}, + {"Atlantic/Reykjavik", 1659177614}, + {"Atlantic/St_Helena", 1659177614}, + {"Atlantic/South_Georgia", 1659177614}, + {"Atlantic/Azores", 1659177614}, + {"Atlantic/Bermuda", 1659177614}, + {"Atlantic/Stanley", 1659177614}, + {"Atlantic/Cape_Verde", 1659177614}, + {"Africa/Niamey", 1659177614}, + {"Africa/Algiers", 1659177614}, + {"Africa/Maputo", 1659177614}, + {"Africa/Johannesburg", 1659177614}, + {"Africa/Addis_Ababa", 1659177614}, + {"Africa/Malabo", 1659177614}, + {"Africa/Cairo", 1659177614}, + {"Africa/Bissau", 1659177614}, + {"Africa/Ndjamena", 1659177614}, + {"Africa/Tunis", 1659177614}, + {"Africa/Harare", 1659177614}, + {"Africa/El_Aaiun", 1659177614}, + {"Africa/Kampala", 1659177614}, + {"Africa/Libreville", 1659177614}, + {"Africa/Blantyre", 1659177614}, + {"Africa/Brazzaville", 1659177614}, + {"Africa/Bangui", 1659177614}, + {"Africa/Luanda", 1659177614}, + {"Africa/Freetown", 1659177614}, + {"Africa/Casablanca", 1659177614}, + {"Africa/Conakry", 1659177614}, + {"Africa/Kinshasa", 1659177614}, + {"Africa/Dakar", 1659177614}, + {"Africa/Ouagadougou", 1659177614}, + {"Africa/Nouakchott", 1659177614}, + {"Africa/Monrovia", 1659177614}, + {"Africa/Kigali", 1659177614}, + {"Africa/Windhoek", 1659177614}, + {"Africa/Juba", 1659177614}, + {"Africa/Sao_Tome", 1659177614}, + {"Africa/Banjul", 1659177614}, + {"Africa/Mbabane", 1659177614}, + {"Africa/Asmara", 1659177614}, + {"Africa/Djibouti", 1659177614}, + {"Africa/Tripoli", 1659177614}, + {"Africa/Ceuta", 1659177614}, + {"Africa/Khartoum", 1659177614}, + {"Africa/Bamako", 1659177614}, + {"Africa/Porto-Novo", 1659177614}, + {"Africa/Mogadishu", 1659177614}, + {"Africa/Abidjan", 1659177614}, + {"Africa/Lusaka", 1659177614}, + {"Africa/Lagos", 1659177614}, + {"Africa/Lubumbashi", 1659177614}, + {"Africa/Nairobi", 1659177614}, + {"Africa/Accra", 1659177614}, + {"Africa/Maseru", 1659177614}, + {"Africa/Lome", 1659177614}, + {"Africa/Douala", 1659177614}, + {"Africa/Bujumbura", 1659177614}, + {"Africa/Dar_es_Salaam", 1659177614}, + {"Africa/Gaborone", 1659177614}, + {"Australia/Adelaide", 1659177614}, + {"Australia/Broken_Hill", 1659177614}, + {"Australia/Perth", 1659177614}, + {"Australia/Darwin", 1659177614}, + {"Australia/Lord_Howe", 1659177614}, + {"Australia/Hobart", 1659177614}, + {"Australia/Brisbane", 1659177614}, + {"Australia/Sydney", 1659177614}, + {"Australia/Lindeman", 1659177614}, + {"Australia/Melbourne", 1659177614}, + {"Australia/Eucla", 1659177614}, + {"America/Grand_Turk", 1659177614}, + {"America/St_Thomas", 1659177614}, + {"America/Havana", 1659177614}, + {"America/Thunder_Bay", 1659177614}, + {"America/Inuvik", 1659177614}, + {"America/Winnipeg", 1659177614}, + {"America/Maceio", 1659177614}, + {"America/Chihuahua", 1659177614}, + {"America/North_Dakota/Beulah", 1659177614}, + {"America/North_Dakota/Center", 1659177614}, + {"America/North_Dakota/New_Salem", 1659177614}, + {"America/Campo_Grande", 1659177614}, + {"America/Scoresbysund", 1659177614}, + {"America/Tijuana", 1659177614}, + {"America/Bahia", 1659177614}, + {"America/St_Vincent", 1659177614}, + {"America/Creston", 1659177614}, + {"America/Dawson", 1659177614}, + {"America/Tegucigalpa", 1659177614}, + {"America/Lima", 1659177614}, + {"America/Mexico_City", 1659177614}, + {"America/Dominica", 1659177614}, + {"America/Atikokan", 1659177614}, + {"America/Port-au-Prince", 1659177614}, + {"America/Yakutat", 1659177614}, + {"America/St_Kitts", 1659177614}, + {"America/Guatemala", 1659177614}, + {"America/St_Barthelemy", 1659177614}, + {"America/Vancouver", 1659177614}, + {"America/Jamaica", 1659177614}, + {"America/Whitehorse", 1659177614}, + {"America/Asuncion", 1659177614}, + {"America/Toronto", 1659177614}, + {"America/Hermosillo", 1659177614}, + {"America/Denver", 1659177614}, + {"America/Mazatlan", 1659177614}, + {"America/Iqaluit", 1659177614}, + {"America/Nuuk", 1659177614}, + {"America/Cayenne", 1659177614}, + {"America/Santarem", 1659177614}, + {"America/Noronha", 1659177614}, + {"America/Ojinaga", 1659177614}, + {"America/Fort_Nelson", 1659177614}, + {"America/Aruba", 1659177614}, + {"America/Indiana/Vevay", 1659177614}, + {"America/Indiana/Marengo", 1659177614}, + {"America/Indiana/Indianapolis", 1659177614}, + {"America/Indiana/Tell_City", 1659177614}, + {"America/Indiana/Petersburg", 1659177614}, + {"America/Indiana/Winamac", 1659177614}, + {"America/Indiana/Knox", 1659177614}, + {"America/Indiana/Vincennes", 1659177614}, + {"America/Cayman", 1659177614}, + {"America/Sao_Paulo", 1659177614}, + {"America/Curacao", 1659177614}, + {"America/Anchorage", 1659177614}, + {"America/Guyana", 1659177614}, + {"America/Rankin_Inlet", 1659177614}, + {"America/Antigua", 1659177614}, + {"America/Juneau", 1659177614}, + {"America/Merida", 1659177614}, + {"America/Punta_Arenas", 1659177614}, + {"America/Moncton", 1659177614}, + {"America/Fortaleza", 1659177614}, + {"America/Resolute", 1659177614}, + {"America/Nassau", 1659177614}, + {"America/Edmonton", 1659177614}, + {"America/Regina", 1659177614}, + {"America/Halifax", 1659177614}, + {"America/Danmarkshavn", 1659177614}, + {"America/Metlakatla", 1659177614}, + {"America/Guadeloupe", 1659177614}, + {"America/Caracas", 1659177614}, + {"America/Detroit", 1659177614}, + {"America/Matamoros", 1659177614}, + {"America/Glace_Bay", 1659177614}, + {"America/Phoenix", 1659177614}, + {"America/La_Paz", 1659177614}, + {"America/Swift_Current", 1659177614}, + {"America/Nipigon", 1659177614}, + {"America/Cancun", 1659177614}, + {"America/Port_of_Spain", 1659177614}, + {"America/Kralendijk", 1659177614}, + {"America/Grenada", 1659177614}, + {"America/Belem", 1659177614}, + {"America/Managua", 1659177614}, + {"America/Adak", 1659177614}, + {"America/St_Lucia", 1659177614}, + {"America/Rio_Branco", 1659177614}, + {"America/Santiago", 1659177614}, + {"America/Puerto_Rico", 1659177614}, + {"America/Miquelon", 1659177614}, + {"America/Cuiaba", 1659177614}, + {"America/Martinique", 1659177614}, + {"America/Argentina/Buenos_Aires", 1659177614}, + {"America/Argentina/San_Luis", 1659177614}, + {"America/Argentina/Catamarca", 1659177614}, + {"America/Argentina/Jujuy", 1659177614}, + {"America/Argentina/Salta", 1659177614}, + {"America/Argentina/Ushuaia", 1659177614}, + {"America/Argentina/Mendoza", 1659177614}, + {"America/Argentina/Rio_Gallegos", 1659177614}, + {"America/Argentina/Tucuman", 1659177614}, + {"America/Argentina/San_Juan", 1659177614}, + {"America/Argentina/Cordoba", 1659177614}, + {"America/Argentina/La_Rioja", 1659177614}, + {"America/Barbados", 1659177614}, + {"America/Monterrey", 1659177614}, + {"America/Thule", 1659177614}, + {"America/Montserrat", 1659177614}, + {"America/Guayaquil", 1659177614}, + {"America/St_Johns", 1659177614}, + {"America/Boise", 1659177614}, + {"America/Manaus", 1659177614}, + {"America/Nome", 1659177614}, + {"America/Goose_Bay", 1659177614}, + {"America/Belize", 1659177614}, + {"America/Sitka", 1659177614}, + {"America/Dawson_Creek", 1659177614}, + {"America/Recife", 1659177614}, + {"America/Kentucky/Louisville", 1659177614}, + {"America/Kentucky/Monticello", 1659177614}, + {"America/New_York", 1659177614}, + {"America/Tortola", 1659177614}, + {"America/Chicago", 1659177614}, + {"America/Pangnirtung", 1659177614}, + {"America/Boa_Vista", 1659177614}, + {"America/Bogota", 1659177614}, + {"America/Rainy_River", 1659177614}, + {"America/El_Salvador", 1659177614}, + {"America/Bahia_Banderas", 1659177614}, + {"America/Yellowknife", 1659177614}, + {"America/Montevideo", 1659177614}, + {"America/Cambridge_Bay", 1659177614}, + {"America/Panama", 1659177614}, + {"America/Santo_Domingo", 1659177614}, + {"America/Anguilla", 1659177614}, + {"America/Paramaribo", 1659177614}, + {"America/Marigot", 1659177614}, + {"America/Menominee", 1659177614}, + {"America/Blanc-Sablon", 1659177614}, + {"America/Costa_Rica", 1659177614}, + {"America/Los_Angeles", 1659177614}, + {"America/Lower_Princes", 1659177614}, + {"America/Eirunepe", 1659177614}, + {"America/Araguaina", 1659177614}, + {"America/Porto_Velho", 1659177614}, + {"EST", 1659177614}, + {"CET", 1659177614}, + {"MST7MDT", 1659177614}, + {"Indian/Chagos", 1659177614}, + {"Indian/Kerguelen", 1659177614}, + {"Indian/Reunion", 1659177614}, + {"Indian/Antananarivo", 1659177614}, + {"Indian/Cocos", 1659177614}, + {"Indian/Mauritius", 1659177614}, + {"Indian/Christmas", 1659177614}, + {"Indian/Maldives", 1659177614}, + {"Indian/Comoro", 1659177614}, + {"Indian/Mahe", 1659177614}, + {"Indian/Mayotte", 1659177614}, + {"Asia/Novokuznetsk", 1659177614}, + {"Asia/Magadan", 1659177614}, + {"Asia/Yangon", 1659177614}, + {"Asia/Samarkand", 1659177614}, + {"Asia/Tehran", 1659177614}, + {"Asia/Dili", 1659177614}, + {"Asia/Yerevan", 1659177614}, + {"Asia/Qatar", 1659177614}, + {"Asia/Chita", 1659177614}, + {"Asia/Makassar", 1659177614}, + {"Asia/Hovd", 1659177614}, + {"Asia/Istanbul", 1659177614}, + {"Asia/Irkutsk", 1659177614}, + {"Asia/Pontianak", 1659177614}, + {"Asia/Qyzylorda", 1659177614}, + {"Asia/Srednekolymsk", 1659177614}, + {"Asia/Aden", 1659177614}, + {"Asia/Kabul", 1659177614}, + {"Asia/Macau", 1659177614}, + {"Asia/Riyadh", 1659177614}, + {"Asia/Taipei", 1659177614}, + {"Asia/Manila", 1659177614}, + {"Asia/Aqtau", 1659177614}, + {"Asia/Thimphu", 1659177614}, + {"Asia/Shanghai", 1659177614}, + {"Asia/Choibalsan", 1659177614}, + {"Asia/Nicosia", 1659177614}, + {"Asia/Dubai", 1659177614}, + {"Asia/Baku", 1659177614}, + {"Asia/Kuching", 1659177614}, + {"Asia/Gaza", 1659177614}, + {"Asia/Jayapura", 1659177614}, + {"Asia/Tokyo", 1659177614}, + {"Asia/Muscat", 1659177614}, + {"Asia/Kolkata", 1659177614}, + {"Asia/Ho_Chi_Minh", 1659177614}, + {"Asia/Tashkent", 1659177614}, + {"Asia/Bangkok", 1659177614}, + {"Asia/Karachi", 1659177614}, + {"Asia/Krasnoyarsk", 1659177614}, + {"Asia/Yekaterinburg", 1659177614}, + {"Asia/Famagusta", 1659177614}, + {"Asia/Ulaanbaatar", 1659177614}, + {"Asia/Bahrain", 1659177614}, + {"Asia/Barnaul", 1659177614}, + {"Asia/Jerusalem", 1659177614}, + {"Asia/Qostanay", 1659177614}, + {"Asia/Ust-Nera", 1659177614}, + {"Asia/Tomsk", 1659177614}, + {"Asia/Kuala_Lumpur", 1659177614}, + {"Asia/Brunei", 1659177614}, + {"Asia/Aqtobe", 1659177614}, + {"Asia/Vladivostok", 1659177614}, + {"Asia/Damascus", 1659177614}, + {"Asia/Omsk", 1659177614}, + {"Asia/Almaty", 1659177614}, + {"Asia/Dhaka", 1659177614}, + {"Asia/Tbilisi", 1659177614}, + {"Asia/Baghdad", 1659177614}, + {"Asia/Phnom_Penh", 1659177614}, + {"Asia/Kamchatka", 1659177614}, + {"Asia/Ashgabat", 1659177614}, + {"Asia/Sakhalin", 1659177614}, + {"Asia/Novosibirsk", 1659177614}, + {"Asia/Kuwait", 1659177614}, + {"Asia/Hong_Kong", 1659177614}, + {"Asia/Amman", 1659177614}, + {"Asia/Beirut", 1659177614}, + {"Asia/Yakutsk", 1659177614}, + {"Asia/Colombo", 1659177614}, + {"Asia/Oral", 1659177614}, + {"Asia/Kathmandu", 1659177614}, + {"Asia/Bishkek", 1659177614}, + {"Asia/Hebron", 1659177614}, + {"Asia/Singapore", 1659177614}, + {"Asia/Atyrau", 1659177614}, + {"Asia/Khandyga", 1659177614}, + {"Asia/Vientiane", 1659177614}, + {"Asia/Jakarta", 1659177614}, + {"Asia/Dushanbe", 1659177614}, + {"Asia/Seoul", 1659177614}, + {"Asia/Pyongyang", 1659177614}, + {"Asia/Urumqi", 1659177614}, + {"Asia/Anadyr", 1659177614}, + {"PST8PDT", 1659177614}, + {"HST", 1659177614}, + {"EST5EDT", 1659177614}, +}; + +static time_t gTime = 1659177614; + +/** + * @tc.name : mktime_0100 + * @tc.desc : according to different time zones, convert time to seconds in duration since 1970-1-1 + * @tc.level : Level 0 + */ +void mktime_0100(void) +{ + for (int32_t i = 0; i < (int32_t)(sizeof(gResultData) / sizeof(gResultData[0])); i++) { + const char *tz = gResultData[i].tz; + const char *handlerChar; +#ifdef TIME_ZONE_SUB_TAG + char *str = strrchr(tz, TIME_ZONE_SUB_TAG); + if (str) { + handlerChar = ++str; + } else { + handlerChar = tz; + } +#else + handlerChar = tz; +#endif + setenv("TZ", handlerChar, 1); + tzset(); + struct tm *timeptr = localtime(&gTime); + if (!timeptr) { + EXPECT_PTRNE("mktime_0100", timeptr, NULL); + return; + } + time_t mk = mktime(timeptr); + EXPECT_EQ("mktime_0100", mk, gResultData[i].result); + } +} + +int main(void) +{ + mktime_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/nanosleep.c b/libc-test/src/functionalext/supplement/time/nanosleep.c new file mode 100755 index 00000000..b7fccdb3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/nanosleep.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int COUNT_ZERO = 0; + +/* + * @tc.name : nanosleep_0100 + * @tc.desc : Verify that the execution of the program can be paused + * @tc.level : Level 0 + */ +void nanosleep_0100(void) +{ + struct timespec n_sleep; + n_sleep.tv_sec = 0; + n_sleep.tv_nsec = 5e8L; + int data; + data = nanosleep(&n_sleep, NULL); + EXPECT_EQ("nanosleep_0100", data, COUNT_ZERO); +} + +TEST_FUN G_Fun_Array[] = { + nanosleep_0100, + +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/test_src_functionalext_supplement_time.gni b/libc-test/src/functionalext/supplement/time/test_src_functionalext_supplement_time.gni new file mode 100644 index 00000000..05922d0d --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/test_src_functionalext_supplement_time.gni @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_time_test = [ + "difftime", + "gmtime_r", + "gmtime", + "mktime", + "time", + "timer_create", + "timer_delete", + "timer_settime", + "timer_gettime", + "timer_getoverrun", + "times", + "timespec_get", + "utime", + "wcsftime", + "wcsftime_l", + "nanosleep", + "clock_nanosleep", + "gettimeofday", + "clock", + "clock_getcpuclockid", + "clock_settime", + "clock_getres", +] diff --git a/libc-test/src/functionalext/supplement/time/time.c b/libc-test/src/functionalext/supplement/time/time.c new file mode 100644 index 00000000..50a8bdaa --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/time.c @@ -0,0 +1,81 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define __TEST_DATA_YEAR__ 121 +#define __TEST_DATA_MONTH__ 9 +#define __TEST_DATA_DAY__ 3 +#define __TEST_DATA_HOUR__ 9 +#define __TEST_DATA_MINUTE__ 12 + +struct time_struct { + const char *tz; +}; + +static const struct time_struct gResultData[] = { + {"Asia/Shanghai"}, + {"Asia/Tokyo"}, + {"Europe/Moscow"}, + {"America/New_York"}, + {"Europe/Berlin"}, +}; + +/** + * @tc.name : time_0100 + * @tc.desc : according to different time zones, get time + * @tc.level : Level 0 + */ +void time_0100(void) +{ + for (int32_t i = 0; i < (int32_t)(sizeof(gResultData) / sizeof(gResultData[0])); i++) { + const char *tz = gResultData[i].tz; + const char *handlerChar; +#ifdef TIME_ZONE_SUB_TAG + char *str = strrchr(tz, TIME_ZONE_SUB_TAG); + if (str) { + handlerChar = ++str; + } else { + handlerChar = tz; + } +#else + handlerChar = tz; +#endif + setenv("TZ", handlerChar, 1); + tzset(); + system("date '2021-10-3 9:12:12' > /dev/NULL"); + time_t curClock; + time_t t = time(&curClock); + EXPECT_TRUE("time_0100", t > 0); + struct tm *localtm = localtime(&curClock); + if (!localtm) { + EXPECT_PTRNE("time_0100", localtm, NULL); + return; + } + EXPECT_EQ("time_0100", __TEST_DATA_YEAR__, localtm->tm_year); + EXPECT_EQ("time_0100", __TEST_DATA_MONTH__, localtm->tm_mon); + EXPECT_EQ("time_0100", __TEST_DATA_DAY__, localtm->tm_mday); + EXPECT_EQ("time_0100", __TEST_DATA_HOUR__, localtm->tm_hour); + EXPECT_EQ("time_0100", __TEST_DATA_MINUTE__, localtm->tm_min); + } +} + +int main(void) +{ + time_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/timer_create.c b/libc-test/src/functionalext/supplement/time/timer_create.c new file mode 100644 index 00000000..1aca66bf --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/timer_create.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "test.h" + +static int count = 0; + +void handler(int sig) +{ + count++; + + return; +} + +/** + * @tc.name : timer_create_0100 + * @tc.desc : create a per-process timer + * @tc.level : Level 0 + */ +void timer_create_0100(void) +{ + struct sigevent sev; + timer_t timerid; + + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIGRTMIN; + sev.sigev_value.sival_ptr = &timerid; + + signal(SIGRTMIN, handler); + + int result = timer_create(CLOCK_REALTIME, &sev, &timerid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + struct itimerspec its; + its.it_value.tv_sec = 1; + its.it_value.tv_nsec = 0; + its.it_interval.tv_sec = its.it_value.tv_sec; + its.it_interval.tv_nsec = its.it_value.tv_nsec; + + result = timer_settime(timerid, 0, &its, NULL); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + while (count <= 0) { + sleep(1); + } + + result = timer_delete(timerid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : timer_create_0200 + * @tc.desc : create a per-process timer with invalid parameters + * @tc.level : Level 2 + */ +void timer_create_0200(void) +{ + errno = 0; + int result = timer_create(-1, NULL, NULL); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno != EINVAL) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + timer_create_0100(); + timer_create_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/time/timer_delete.c b/libc-test/src/functionalext/supplement/time/timer_delete.c new file mode 100644 index 00000000..f493d0eb --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/timer_delete.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +#define MAX (3) +static int count = 0; + +void timerHandler(int sig) +{ + if (count < MAX) { + count++; + } + printf("timer handler return\n"); + return; +} + +/** + * @tc.name : timer_delete_0100 + * @tc.desc : Create a timer with a timeout of 1s and delete it + * @tc.level : Level 0 + */ +void timer_delete_0100(void) +{ + timer_t timerid; + struct sigevent sev; + struct itimerspec its; + + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIGUSR1; + sev.sigev_value.sival_ptr = &timerid; + signal(SIGUSR1, timerHandler); + + if (timer_create(CLOCK_MONOTONIC, &sev, &timerid) == -1) { + t_error("%s timer create failed", __func__); + return; + } + + its.it_value.tv_sec = 1; + its.it_value.tv_nsec = 0; + its.it_interval.tv_sec = its.it_value.tv_sec; + its.it_interval.tv_nsec = its.it_value.tv_nsec; + + if (timer_settime(timerid, 0, &its, NULL) == -1) { + t_error("%s timer set time failed", __func__); + return; + } + + while (count != MAX) { + sleep(1); + } + + if (timer_delete(timerid) == -1 && errno == EINVAL) { + t_error("%s timer delete failed", __func__); + } +} + +int main(int argc, char *argv[]) +{ + timer_delete_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/timer_getoverrun.c b/libc-test/src/functionalext/supplement/time/timer_getoverrun.c new file mode 100644 index 00000000..c2e79cfc --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/timer_getoverrun.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "test.h" + +static int count = 0; +static timer_t timerid; + +void handler(int sig) +{ + count++; + usleep(1000000); + int ret = timer_getoverrun(timerid); + if (ret < 0) { + t_error("%s timer_getoverrun failed, ret is %d\n", __func__, ret); + } + return; +} + +/** + * @tc.name : timer_getoverrun_0100 + * @tc.desc : Get overrun count for a per-process timer + * @tc.level : Level 0 + */ +void timer_getoverrun_0100(void) +{ + struct sigevent sev; + + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIGRTMIN; + sev.sigev_value.sival_ptr = &timerid; + + signal(SIGRTMIN, handler); + + int result = timer_create(CLOCK_REALTIME, &sev, &timerid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + struct itimerspec its; + its.it_value.tv_sec = 0; + its.it_value.tv_nsec = 1000000; + its.it_interval.tv_sec = 0; + its.it_interval.tv_nsec = 0; + + result = timer_settime(timerid, 0, &its, NULL); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + while (count <= 0) { + sleep(1); + } + result = timer_delete(timerid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : timer_getoverrun_0200 + * @tc.desc : Invalid timerid + * @tc.level : Level 2 + */ +void timer_getoverrun_0200(void) +{ + int result = timer_getoverrun(NULL); + if (result != -1) { + t_error("%s timer_getoverrun failed, ret is %d\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + timer_getoverrun_0100(); + timer_getoverrun_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/time/timer_gettime.c b/libc-test/src/functionalext/supplement/time/timer_gettime.c new file mode 100644 index 00000000..9bc47de1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/timer_gettime.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +#define Nanoseconds (1000000000) +static int count = 0; + +void timerHandler(int sig) +{ + count++; + return; +} + +void exception_handler(int sig) +{ + exit(t_status); +} + +/** + * @tc.name : timer_gettime_0100 + * @tc.desc : Get the remaining time of the timer + * @tc.level : Level 0 + */ +void timer_gettime_0100(void) +{ + timer_t timerid; + struct sigevent sev; + struct itimerspec its; + struct itimerspec tmp; + + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIGUSR1; + sev.sigev_value.sival_ptr = &timerid; + signal(SIGUSR1, timerHandler); + + if (timer_create(CLOCK_MONOTONIC, &sev, &timerid) == -1) { + t_error("%s timer create failed", __func__); + return; + } + + its.it_value.tv_sec = 1; + its.it_value.tv_nsec = 0; + its.it_interval.tv_sec = 1; + its.it_interval.tv_nsec = 0; + + if (timer_settime(timerid, 0, &its, NULL) == -1) { + t_error("%s timer set time failed", __func__); + return; + } + + if (timer_gettime(timerid, &tmp) == -1 && errno == EINVAL) { + t_error("%s timer gettimer failed", __func__); + } + + if (tmp.it_value.tv_sec >= 1 || tmp.it_value.tv_nsec >= Nanoseconds) { + t_error("%s get time failed", __func__); + } + + while (count <= 0) { + sleep(1); + } + + if (timer_delete(timerid) != 0) { + t_error("%s timer_delete failed", __func__); + } +} + +/** + * @tc.name : timer_gettime_0200 + * @tc.desc : The return value of the function when the parameter is abnormal + * @tc.level : Level 2 + */ +void timer_gettime_0200(void) +{ + int result = timer_gettime(NULL, NULL); + if (result != -1 && errno != EINVAL) { + t_error("%s failed result = %d", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + timer_gettime_0100(); + timer_gettime_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/timer_settime.c b/libc-test/src/functionalext/supplement/time/timer_settime.c new file mode 100644 index 00000000..dbb942d1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/timer_settime.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "test.h" + +static int count = 0; + +void handler(int sig) +{ + count++; + + return; +} + +void exception_handler(int sig) +{ + exit(t_status); +} + +/** + * @tc.name : timer_settime_0100 + * @tc.desc : arms the timer + * @tc.level : Level 0 + */ +void timer_settime_0100(void) +{ + struct sigevent sev; + timer_t timerid; + + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIGRTMIN; + sev.sigev_value.sival_ptr = &timerid; + + signal(SIGRTMIN, handler); + + int result = timer_create(CLOCK_REALTIME, &sev, &timerid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + struct itimerspec its; + its.it_value.tv_sec = 1; + its.it_value.tv_nsec = 0; + its.it_interval.tv_sec = 0; + its.it_interval.tv_nsec = 0; + + result = timer_settime(timerid, 0, &its, NULL); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + while (count <= 0) { + sleep(1); + } + + result = timer_delete(timerid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : timer_settime_0200 + * @tc.desc : arms the timer with invalid parameters + * @tc.level : Level 2 + */ +void timer_settime_0200(void) +{ + signal(SIGSEGV, exception_handler); + + timer_settime(NULL, 0, NULL, NULL); +} + +int main(int argc, char *argv[]) +{ + timer_settime_0100(); + timer_settime_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/time/times.c b/libc-test/src/functionalext/supplement/time/times.c new file mode 100644 index 00000000..8d85a991 --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/times.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +/** + * @tc.name : times_0100 + * @tc.desc : get process times + * @tc.level : Level 0 + */ +void times_0100(void) +{ + struct tms buf; + clock_t result = times(&buf); + if (result < 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + if (buf.tms_utime < 0) { + t_error("%s failed: buf.tms_utime = %d\n", __func__, buf.tms_utime); + } + + if (buf.tms_stime < 0) { + t_error("%s failed: buf.tms_stime = %d\n", __func__, buf.tms_stime); + } + + if (buf.tms_cutime < 0) { + t_error("%s failed: buf.tms_cutime = %d\n", __func__, buf.tms_cutime); + } + + if (buf.tms_cstime < 0) { + t_error("%s failed: buf.tms_cstime = %d\n", __func__, buf.tms_cstime); + } +} + +/** + * @tc.name : times_0200 + * @tc.desc : get process times with NULL + * @tc.level : Level 2 + */ +void times_0200(void) +{ + clock_t result = times(NULL); + if (result < 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } +} + +int main(int argc, char *argv[]) +{ + times_0100(); + times_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/time/timespec_get.c b/libc-test/src/functionalext/supplement/time/timespec_get.c new file mode 100644 index 00000000..2818de6a --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/timespec_get.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +#define NANOSECOND (1000000000) + +/** + * @tc.name : timespec_get_0100 + * @tc.desc : Base is not TIME_UTC + * @tc.level : Level 0 + */ +void timespec_get_0100(void) +{ + struct timespec ts; + int result = timespec_get(&ts, 0); + if (result != 0) { + t_error("%s timespec_get failed, result is %d", __func__, result); + } +} + +/** + * @tc.name : timespec_get_0200 + * @tc.desc : Base is TIME_UTC + * @tc.level : Level 1 + */ +void timespec_get_0200(void) +{ + struct timespec ts; + int result = timespec_get(&ts, TIME_UTC); + if (result != TIME_UTC) { + t_error("%s timespec_get failed, result is %d", __func__, result); + } + if (ts.tv_nsec < 0 || ts.tv_nsec >= NANOSECOND) { + t_error("%s ts invalid", __func__); + } +} + +int main(int argc, char *argv[]) +{ + timespec_get_0100(); + timespec_get_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/utime.c b/libc-test/src/functionalext/supplement/time/utime.c new file mode 100644 index 00000000..76a573cf --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/utime.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : utime_0100 + * @tc.desc : Specify file modification and access times + * @tc.level : Level 0 + */ +void utime_0100(void) +{ + int fd; + char file[] = "/data/utime1.txt"; + struct utimbuf ubuf; + struct stat info; + + if ((fd = creat(file, S_IWUSR)) < 0) { + t_error("%s creat failed", __func__); + } else { + close(fd); + stat(file, &info); + ubuf.modtime = 0; + time(&ubuf.actime); + if (utime(file, &ubuf) != 0) { + t_error("%s utime failed", __func__); + } else { + stat(file, &info); + if (info.st_mtim.tv_sec != 0) { + t_error("%s modify file time failed", __func__); + } + } + } + remove(file); +} + +/** + * @tc.name : utime_0200 + * @tc.desc : When times is a NULL pointer, the access and modification times are set to the current time + * @tc.level : Level 1 + */ +void utime_0200(void) +{ + const char *path = "/data/utime.txt"; + int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); + if (fd == -1) { + t_error("%s write create file error", __func__); + return; + } + close(fd); + struct stat buf1; + struct stat buf2; + time_t t_mold, t_aold, t_now, t_mnew, t_anew; + stat(path, &buf1); + + t_mold = buf1.st_mtime; + t_aold = buf1.st_atime; + t_now = time(NULL); + if (utime(path, NULL) != 0) { + stat(path, &buf2); + t_mnew = buf2.st_mtime; + t_anew = buf2.st_atime; + if (t_mnew != t_now && t_anew != t_now) { + t_error("%s utime failed", __func__); + } + } + remove(path); +} + +int main(int argc, char *argv[]) +{ + utime_0100(); + utime_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/wcsftime.c b/libc-test/src/functionalext/supplement/time/wcsftime.c new file mode 100644 index 00000000..5bd05f87 --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/wcsftime.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcsftime_0100 + * @tc.desc : Format system time + * @tc.level : Level 0 + */ +void wcsftime_0100(void) +{ + time_t rtime; + struct tm *timeinfo; + wchar_t buffer[80]; + time(&rtime); + timeinfo = localtime(&rtime); + size_t result = wcsftime(buffer, 80, L"%I:%M%p", timeinfo); + if (!result) { + t_error("%s wcsftime failed", __func__); + } +} + +int main(int argc, char *argv[]) +{ + wcsftime_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/time/wcsftime_l.c b/libc-test/src/functionalext/supplement/time/wcsftime_l.c new file mode 100644 index 00000000..54022ff5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/time/wcsftime_l.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : wcsftime_l_0100 + * @tc.desc : Format system time + * @tc.level : Level 0 + */ +void wcsftime_l_0100(void) +{ + time_t rtime; + struct tm *timeinfo; + wchar_t buffer[80]; + time(&rtime); + timeinfo = localtime(&rtime); + locale_t newlocale_ = newlocale(LC_ALL_MASK, "en-US", NULL); + size_t result = wcsftime_l(buffer, 80, L"%I:%M%p", timeinfo, newlocale_); + if (!result) { + t_error("%s wcsftime_l failed\n", __func__); + } + if (newlocale_) { + freelocale(newlocale_); + newlocale_ = NULL; + } +} + +/** + * @tc.name : wcsftime_l_0200 + * @tc.desc : Format the given tm time + * @tc.level : Level 1 + */ +void wcsftime_l_0200(void) +{ + wchar_t buff[40]; + struct tm mtime = { + .tm_year = 122, + .tm_mon = 5, + .tm_mday = 6, + .tm_hour = 8, + .tm_min = 10, + .tm_sec = 20, + }; + locale_t newlocale_ = newlocale(LC_ALL_MASK, "en-US", NULL); + size_t result = wcsftime_l(buff, sizeof buff, L"%A %c", &mtime, newlocale_); + if (!result) { + t_error("%s wcsftime_l failed\n", __func__); + } + if (wcscmp(buff, L"Sunday Sun Jun 6 08:10:20 2022")) { + t_error("%s wrong format result is %ls\n", __func__, buff); + } + if (newlocale_) { + freelocale(newlocale_); + newlocale_ = NULL; + } +} + +int main(int argc, char *argv[]) +{ + wcsftime_l_0100(); + wcsftime_l_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/BUILD.gn b/libc-test/src/functionalext/supplement/unistd/BUILD.gn new file mode 100644 index 00000000..2d34b3be --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_unistd.gni") + +foreach(s, functionalext_supplement_unistd_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/unistd" + } +} + +group("functionalext_supplement_unistd_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_unistd_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/unistd/access.c b/libc-test/src/functionalext/supplement/unistd/access.c new file mode 100644 index 00000000..f5bf0caf --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/access.c @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +const int SUCCESS = 0; +const int FAILED = -1; + +/** + * @tc.name : access_0100 + * @tc.desc : The parameter filename is the specified file and exists, + * the parameter amode is F_OK,function returns successfully. + * @tc.level : Level 0 + */ +void access_0100(void) +{ + const char *ptr = "accesstest.txt"; + FILE *fptr = fopen(ptr, "w"); + int isExist = access(ptr, F_OK); + EXPECT_EQ("access_0100", isExist, SUCCESS); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : access_0200 + * @tc.desc : The parameter filename is the specified directory and exists, + * the parameter amode is F_OK,function returns SUCCESSfully. + * @tc.level : Level 0 + */ +void access_0200(void) +{ + char passbuff[90]; + const char *ptr = "accesstest.txt"; + FILE *fptr = fopen(ptr, "w"); + getcwd(passbuff, sizeof(passbuff)); + int isExist = access(passbuff, F_OK); + EXPECT_EQ("access_0200", isExist, SUCCESS); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : access_0300 + * @tc.desc : The parameter filename is the specified file and not exists, + * the parameter amode is F_OK,function returns failure. + * @tc.level : Level 2 + */ +void access_0300(void) +{ + const char *ptr = "noaccesstest.txt"; + int isExist = access(ptr, F_OK); + EXPECT_EQ("access_0300", isExist, FAILED); + remove(ptr); +} + +/** + * @tc.name : access_0400 + * @tc.desc : The parameter filename is the specified directory and not exists, + * the parameter amode is F_OK,function returns failure. + * @tc.level : Level 2 + */ +void access_0400(void) +{ + const char *ptr = "./noaccesstest"; + int isExist = access(ptr, F_OK); + EXPECT_EQ("access_0400", isExist, FAILED); + remove(ptr); +} + +/** + * @tc.name : access_0500 + * @tc.desc : The file attribute specified by the parameter filename is readable, + * the parameter amode is R_OK,function returns successfully. + * @tc.level : Level 0 + */ +void access_0500(void) +{ + const char *ptr = "accesstest.txt"; + FILE *fptr = fopen(ptr, "w"); + fptr = fopen(ptr, "w"); + int isRead = access(ptr, R_OK); + EXPECT_EQ("access_0500", isRead, SUCCESS); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : access_0600 + * @tc.desc : The file attribute specified by the parameter filename is writable, + * the parameter amode is W_OK,function returns successfully. + * @tc.level : Level 0 + */ +void access_0600(void) +{ + const char *ptr = "accesstest.txt"; + FILE *fptr = fopen(ptr, "w"); + int isWrite = access(ptr, W_OK); + EXPECT_EQ("access_0600", isWrite, SUCCESS); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : access_0700 + * @tc.desc : The file attribute specified by the parameter filename is executable, + * the parameter amode is W_OK,function returns successfully. + * @tc.level : Level 0 + */ +void access_0700(void) +{ + const char *ptr = "accesstest.txt"; + FILE *fptr = fopen(ptr, "w"); + system("chmod 777 ./accesstest.txt"); + int isExecute = access(ptr, X_OK); + EXPECT_EQ("access_0700", isExecute, SUCCESS); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : access_0800 + * @tc.desc : The file attribute specified by the parameter filename is not executable, + * the parameter amode is R_OK,function returns failure. + * @tc.level : Level 2 + */ +void access_0800(void) +{ + const char *ptr = "accesstest.txt"; + FILE *fptr = fopen(ptr, "w"); + int isExecute = access(ptr, X_OK); + EXPECT_EQ("access_0800", isExecute, FAILED); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +TEST_FUN G_Fun_Array[] = { + access_0100, + access_0200, + access_0300, + access_0400, + access_0500, + access_0600, + access_0700, + access_0800, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/acct.c b/libc-test/src/functionalext/supplement/unistd/acct.c new file mode 100644 index 00000000..33c54e0a --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/acct.c @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : acct_0100 + * @tc.desc : Verify that the recording function is enabled (parameters are valid) + * @tc.level : Level 0 + */ +void acct_0100(void) +{ + errno = 0; + const char *filePath = "/data/tests/libc-test/src/functionalext/supplement/unistd/accttest.txt"; + int fd = open(filePath, O_RDWR | O_CREAT, 0777); + if (fd < 0) { + t_error("%s open failed\n", __func__); + } + int result = acct(filePath); + if (result != 0) { + t_error("%s result is %d, except zero\n", __func__, result); + } +} + +/** + * @tc.name : acct_0200 + * @tc.desc : Verify logging is disabled (parameter is NULL) + * @tc.level : Level 2 + */ +void acct_0200(void) +{ + int result = acct(NULL); + EXPECT_EQ("acct_0200", result, -1); +} + +/** + * @tc.name : acct_0300 + * @tc.desc : Verify logging is disabled (parameter is file does not exist) + * @tc.level : Level 2 + */ +void acct_0300(void) +{ + const char *filePath = "/data/tests/libc-test/src/functionalext/supplement/unistd/accttest.txt"; + FILE *fptr = fopen(filePath, "w"); + fclose(fptr); + int result = acct(filePath); + EXPECT_EQ("acct_0300", result, -1); + remove(filePath); +} + +int main(void) +{ + // acct_0100(); + acct_0200(); + acct_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/alarm.c b/libc-test/src/functionalext/supplement/unistd/alarm.c new file mode 100755 index 00000000..73de0a1a --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/alarm.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +#define SLEEP_TIME 6 +int time_out = 0; +void handler() +{ + time_out = 1; +} + +/** + * @tc.name : alarm_0100 + * @tc.desc : Set the alarm time for the process. + * @tc.level : Level 0 + */ +void alarm_0100() +{ + int i; + signal(SIGALRM, handler); + unsigned int result; + result = alarm(SLEEP_TIME); + FLOAT_EQUAL("alarm_0100", result, 0); +} + +TEST_FUN G_Fun_Array[] = { + alarm_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/chdir.c b/libc-test/src/functionalext/supplement/unistd/chdir.c new file mode 100755 index 00000000..d351a0d3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/chdir.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +/* + * @tc.name : chdir_0100 + * @tc.desc : Verify that the directory can be switched (parameters are valid) + * @tc.level : Level 0 + */ +void chdir_0100(void) +{ + int num; + if (NULL == opendir("/data/dir")) + mkdir("/data/dir", 0777); + num = chdir("/data/dir"); + EXPECT_EQ("chdir_0100", num, 0); +} + +int main() +{ + chdir_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/chown.c b/libc-test/src/functionalext/supplement/unistd/chown.c new file mode 100644 index 00000000..1ec44380 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/chown.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +const int COUNT_ZERO = 0; +const int COUNT_NEFATIVE_ONE = -1; + +/** + * @tc.name : chown_0100 + * @tc.desc : Verify the owner user and group of the changed file + * @tc.level : Level 0 + */ +void chown_0100(void) +{ + struct stat buf; + const char *ptr = "test.txt"; + FILE *fptr = fopen(ptr, "w+"); + int result = chown("test.txt", 0, 0); + stat("test.txt", &buf); + EXPECT_EQ("chown_0100", result, COUNT_ZERO); + EXPECT_EQ("chown_0100", buf.st_uid, COUNT_ZERO); + EXPECT_EQ("chown_0100", buf.st_gid, COUNT_ZERO); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : chown_0200 + * @tc.desc : Verify the owner user of the changed file + * @tc.level : Level 0 + */ +void chown_0200(void) +{ + struct stat buf; + const char *ptr = "test.txt"; + FILE *fptr = fopen(ptr, "w+"); + int result = chown("test.txt", 0, -1); + stat("test.txt", &buf); + EXPECT_EQ("chown_0200", result, COUNT_ZERO); + EXPECT_EQ("chown_0200", buf.st_uid, COUNT_ZERO); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : chown_0300 + * @tc.desc : Verify the group that changed the owner of the file + * @tc.level : Level 0 + */ +void chown_0300(void) +{ + struct stat buf; + const char *ptr = "test.txt"; + FILE *fptr = fopen(ptr, "w+"); + int result = chown("test.txt", -1, 0); + stat("test.txt", &buf); + EXPECT_EQ("chown_0300", result, COUNT_ZERO); + EXPECT_EQ("chown_0300", buf.st_gid, COUNT_ZERO); + fclose(fptr); + remove(ptr); +} + +/** + * @tc.name : chown_0400 + * @tc.desc : Verify that the user and group cannot change the owner of the file (parameter path is invalid) + * @tc.level : Level 2 + */ +void chown_0400(void) +{ + const char *ptr = "test.txt"; + FILE *fptr = fopen(ptr, "w+"); + fclose(fptr); + remove(ptr); + int result = chown("test.txt", 0, 0); + EXPECT_EQ("chown_0400", result, COUNT_NEFATIVE_ONE); +} + +/** + * @tc.name : chown_0500 + * @tc.desc : Verify user and group that cannot change the owner of the file (parameter path is NULL) + * @tc.level : Level 2 + */ +void chown_0500(void) +{ + const char *ptr = NULL; + int result = chown(ptr, 0, 0); + EXPECT_EQ("chown_0500", result, COUNT_NEFATIVE_ONE); +} + +int main() +{ + chown_0100(); + chown_0200(); + chown_0300(); + chown_0400(); + chown_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/ctermid.c b/libc-test/src/functionalext/supplement/unistd/ctermid.c new file mode 100755 index 00000000..738b4053 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/ctermid.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : ctermid_0100 + * @tc.desc : Verify the path name of the control terminal that gets the current process (parameter valid) + * @tc.level : Level 0 + */ +void ctermid_0100(void) +{ + char termid[1025]; + bool flag = false; + char *result = NULL; + result = ctermid(termid); + if (result != NULL) { + flag = true; + } + EXPECT_TRUE("ctermid_0100", flag); +} + +/** + * @tc.name : ctermid_0200 + * @tc.desc : Verify the default pathname of the control terminal that got the current process + * (the s parameter is invalid) + * @tc.level : Level 1 + */ +void ctermid_0200(void) +{ + char termid[1025] = "ssad"; + bool flag = false; + char *result = NULL; + result = ctermid(termid); + if (result != NULL) { + flag = true; + } + EXPECT_TRUE("ctermid_0200", flag); +} + +int main() +{ + ctermid_0100(); + ctermid_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/dup3.c b/libc-test/src/functionalext/supplement/unistd/dup3.c new file mode 100644 index 00000000..8d86491d --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/dup3.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +const int FAILED = -1; + +/** + * @tc.name : dup3_0100 + * @tc.desc : The parameter flags is O_CLOEXEC, which can assign the old file descriptor to the new file descriptor + * @tc.level : Level 0 + */ +void dup3_0100(void) +{ + int fd = open("/data/dup3test.txt", O_RDWR | O_CREAT); + EXPECT_TRUE("dup3_0100", fd >= 0); + int ret = dup3(fd, fileno(stderr), O_CLOEXEC); + EXPECT_EQ("dup3_0100", ret, fileno(stderr)); + close(fd); + remove("/data/dup3test.txt"); +} + +/** + * @tc.name : dup3_0200 + * @tc.desc : The parameter old is invalid, the old file descriptor cannot be assigned to the new file descriptor. + * @tc.level : Level 2 + */ +void dup3_0200(void) +{ + int fd = -1; + int ret = dup3(fd, fileno(stderr), O_CLOEXEC); + EXPECT_EQ("dup3_0200", ret, FAILED); +} + +/** + * @tc.name : dup3_0300 + * @tc.desc : The parameter new is invalid, the old file descriptor cannot be assigned to the new file descriptor. + * @tc.level : Level 2 + */ +void dup3_0300(void) +{ + int newfd = -1; + int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); + EXPECT_TRUE("dup3_0300", fd >= 0); + int ret = dup3(fd, newfd, O_CLOEXEC); + EXPECT_EQ("dup3_0300", ret, FAILED); + close(fd); + remove("/data/readtest.txt"); +} + +int main() +{ + dup3_0100(); + dup3_0200(); + dup3_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/exit.c b/libc-test/src/functionalext/supplement/unistd/exit.c new file mode 100755 index 00000000..4f959ee9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/exit.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/* + * @tc.name : exit_0100 + * @tc.desc : Verify that the file content of the auxiliary application output information + * is viewed by calling the exit(0) function. + * @tc.level : Level 0 + */ +void exit_0100(void) +{ + system("cd /data/tests/libc-test/src/functionalext/supplement/unistd/; ./exittest01"); + char abc[100] = {0}; + bool successflag = false; + const char *ptr = "/data/Exittest01.txt"; + FILE *fptr = fopen(ptr, "r"); + fseek(fptr, 0, SEEK_SET); + int32_t rsize = fread(abc, sizeof(abc), 1, fptr); + if (strcmp(abc, "exit before") == 0) { + successflag = true; + } + if (strcmp(abc, "exit after") == 0) { + successflag = false; + } + EXPECT_TRUE("exit_0100", successflag); + fclose(fptr); + remove(ptr); +} + +/* + * @tc.name : exit_0200 + * @tc.desc : Verify that the file content of the auxiliary application output information + * is viewed by calling the exit(1) function. + * @tc.level : Level 0 + */ +void exit_0200(void) +{ + system("cd /data/tests/libc-test/src/functionalext/supplement/unistd/; ./exittest02"); + char abc[100] = {0}; + bool successflag = false; + const char *ptr = "/data/Exittest02.txt"; + FILE *fptr = fopen(ptr, "r"); + fseek(fptr, 0, SEEK_SET); + char *content = fgets(abc, 27, fptr); + if (strcmp(content, "exit before") == 0) { + successflag = true; + } + if (strcmp(content, "exit after") == 0) { + successflag = false; + } + EXPECT_TRUE("exit_0200", successflag); + fclose(fptr); + remove(ptr); +} + +TEST_FUN G_Fun_Array[] = { + exit_0100, + exit_0200, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/exittest01.c b/libc-test/src/functionalext/supplement/unistd/exittest01.c new file mode 100755 index 00000000..9f7ff432 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/exittest01.c @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +void exitfirsttest() +{ + FILE *fptr = fopen("/data/Exittest01.txt", "w+"); + fprintf(fptr, "%s", "exit before"); + exit(0); + fprintf(fptr, "%s", "exit after"); +} + +TEST_FUN G_Fun_Array[] = { + exitfirsttest, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/exittest02.c b/libc-test/src/functionalext/supplement/unistd/exittest02.c new file mode 100755 index 00000000..98735772 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/exittest02.c @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +void exitsecondtest() +{ + FILE *fptr = fopen("/data/Exittest02.txt", "w+"); + fprintf(fptr, "%s", "exit before"); + exit(1); + fprintf(fptr, "%s", "exit after"); +} + +TEST_FUN G_Fun_Array[] = { + exitsecondtest, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/faccessat.c b/libc-test/src/functionalext/supplement/unistd/faccessat.c new file mode 100644 index 00000000..e8e429f7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/faccessat.c @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int SUCCESS = 0; +const int FAILED = -1; + +/** + * @tc.name : faccessat_0100 + * @tc.desc : Test file exists, amode is F_OK. + * @tc.level : Level 0 + */ +void faccessat_0100(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + int fd = open(ptr, O_RDWR | O_CREAT); + EXPECT_TRUE("faccessat_0100", fd >= 0); + int isExist = faccessat(fd, ptr, F_OK, 0); + EXPECT_EQ("faccessat_0100", isExist, SUCCESS); + close(fd); + remove(ptr); + ptr = NULL; +} + +/** + * @tc.name : faccessat_0200 + * @tc.desc : The test file does not exist, amode is F_OK. + * @tc.level : Level 2 + */ +void faccessat_0200(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + int fd = -1; + int isExist = faccessat(fd, ptr, F_OK, 0); + EXPECT_EQ("faccessat_0200", isExist, FAILED); + close(fd); + remove(ptr); + ptr = NULL; +} + +/** + * @tc.name : faccessat_0300 + * @tc.desc : The test file has read permission and amode is R_OK. + * @tc.level : Level 0 + */ +void faccessat_0300(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + int fd = open(ptr, O_RDWR | O_CREAT, 00040); + EXPECT_TRUE("faccessat_0300", fd >= 0); + int isRead = faccessat(fd, ptr, R_OK, 0); + EXPECT_EQ("faccessat_0300", isRead, SUCCESS); + close(fd); + remove(ptr); + ptr = NULL; +} + +/** + * @tc.name : faccessat_0400 + * @tc.desc : The test file has write permission, and amode is W_OK. + * @tc.level : Level 0 + */ +void faccessat_0400(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + int fd = open(ptr, O_RDWR | O_CREAT, 00020); + EXPECT_TRUE("faccessat_0400", fd >= 0); + int isWrite = faccessat(fd, ptr, W_OK, 0); + EXPECT_EQ("faccessat_0400", isWrite, SUCCESS); + close(fd); + remove(ptr); + ptr = NULL; +} + +/** + * @tc.name : faccessat_0500 + * @tc.desc : The test file has executable permission, amode is X_OK. + * @tc.level : Level 0 + */ +void faccessat_0500(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + int fd = open(ptr, O_RDWR | O_CREAT, 00010); + system("chmod 777 /data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"); + EXPECT_TRUE("faccessat_0500", fd >= 0); + int isExecute = faccessat(fd, ptr, X_OK, 0); + EXPECT_EQ("faccessat_0500", isExecute, SUCCESS); + close(fd); + remove(ptr); + ptr = NULL; +} + +/** + * @tc.name : faccessat_0600 + * @tc.desc : The test file has no executable permission, amode is X_OK. + * @tc.level : Level 2 + */ +void faccessat_0600(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + int fd = open(ptr, O_RDWR | O_CREAT); + EXPECT_TRUE("faccessat_0600", fd >= 0); + int isExecute = faccessat(fd, ptr, X_OK, 0); + EXPECT_EQ("faccessat_0600", isExecute, FAILED); + close(fd); + remove(ptr); + ptr = NULL; +} + +/** + * @tc.name : faccessat_0700 + * @tc.desc : The test file has read, write and executable permissions, and amode is R_OK|W_OK|X_Ok. + * @tc.level : Level 0 + */ +void faccessat_0700(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + int fd = open(ptr, O_RDWR | O_CREAT, 00070); + EXPECT_TRUE("faccessat_0700", fd >= 0); + int isExecute = faccessat(fd, ptr, R_OK | W_OK | X_OK, 0); + EXPECT_EQ("faccessat_0700", isExecute, SUCCESS); + close(fd); + remove(ptr); + ptr = NULL; +} + +/** + * @tc.name : faccessat_0800 + * @tc.desc : The test file does not have read/write executable permission, and amode is R_OK|W_OK|X_OK. + * @tc.level : Level 2 + */ +void faccessat_0800(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + int fd = open(ptr, O_RDWR | O_CREAT); + EXPECT_TRUE("faccessat_0800", fd >= 0); + int isExecute = faccessat(fd, ptr, R_OK | W_OK | X_OK, 0); + EXPECT_EQ("faccessat_0800", isExecute, FAILED); + close(fd); + remove(ptr); + ptr = NULL; +} + +/** + * @tc.name : faccessat_0900 + * @tc.desc : Invalid flag parameter (AT_SYMLINK_NOFOLLOW), unable to test file permissions. + * @tc.level : Level 2 + */ +void faccessat_0900(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + int fd = open(ptr, O_RDWR | O_CREAT, 00070); + EXPECT_TRUE("faccessat_0900", fd >= 0); + int ret = faccessat(fd, ptr, R_OK, AT_SYMLINK_NOFOLLOW); + EXPECT_EQ("faccessat_0900", ret, -1); + EXPECT_EQ("faccessat_0900", errno, 22); + close(fd); + remove(ptr); + ptr = NULL; +} + +/** + * @tc.name : faccessat_1000 + * @tc.desc : The test file has read, write and executable permissions, fd is AT_FDCWD, + * and amode is R_OK|W_OK|X_OK. + * @tc.level : Level 0 + */ +void faccessat_1000(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + int fd = open(ptr, O_RDWR | O_CREAT, 00070); + EXPECT_TRUE("faccessat_1000", fd >= 0); + int isExecute = faccessat(AT_FDCWD, ptr, R_OK | W_OK | X_OK, AT_EACCESS); + EXPECT_EQ("faccessat_1000", isExecute, SUCCESS); + close(fd); + remove(ptr); + ptr = NULL; +} + +/** + * @tc.name : faccessat_1100 + * @tc.desc : The test file does not have read, write and execute permissions, fd is AT_FDCWD, + * and amode is R_OK|W_OK|X_OK. + * @tc.level : Level 2 + */ +void faccessat_1100(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + int fd = open(ptr, O_RDWR | O_CREAT); + EXPECT_TRUE("faccessat_1100", fd >= 0); + int isExecute = faccessat(AT_FDCWD, ptr, R_OK | W_OK | X_OK, AT_EACCESS); + EXPECT_EQ("faccessat_1100", isExecute, FAILED); + close(fd); + remove(ptr); + ptr = NULL; +} + +TEST_FUN G_Fun_Array[] = { + faccessat_0100, + faccessat_0200, + faccessat_0300, + faccessat_0400, + faccessat_0500, + faccessat_0600, + faccessat_0700, + faccessat_0800, + faccessat_0900, + faccessat_1000, + faccessat_1100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/fchown.c b/libc-test/src/functionalext/supplement/unistd/fchown.c new file mode 100644 index 00000000..1ea185a5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/fchown.c @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); +const int COUNT_ZERO = 0; +const int COUNT_NEFATIVE = -1; + +/** + * @tc.name : fchown_0100 + * @tc.desc : Parameter is valid and can change the user and group of the file's owner + * @tc.level : Level 0 + */ +void fchown_0100() +{ + int fd = open("test.txt", O_RDONLY | O_CREAT); + int result = fchown(fd, 0, 0); + struct stat buff; + EXPECT_EQ("fchown_0100", result, COUNT_ZERO); + stat("test.txt", &buff); + EXPECT_EQ("fchown_0100", buff.st_uid, COUNT_ZERO); + close(fd); + remove("test.txt"); +} + +/** + * @tc.name : fchown_0200 + * @tc.desc : Parameter valid, can change the file owner of the user + * @tc.level : Level 0 + */ +void fchown_0200() +{ + int fd = open("test.txt", O_RDONLY | O_CREAT); + int result = fchown(fd, 0, -1); + struct stat buff; + EXPECT_EQ("fchown_0200", result, COUNT_ZERO); + stat("test.txt", &buff); + EXPECT_EQ("fchown_0200", buff.st_uid, COUNT_ZERO); + close(fd); + remove("test.txt"); +} + +/** + * @tc.name : fchown_0300 + * @tc.desc : Parameter valid to change the owner group of the file + * @tc.level : Level 0 + */ +void fchown_0300() +{ + int fd = open("test.txt", O_RDONLY | O_CREAT); + int result = fchown(fd, -1, 0); + struct stat buff; + EXPECT_EQ("fchown_0300", result, COUNT_ZERO); + stat("test.txt", &buff); + EXPECT_EQ("fchown_0300", buff.st_gid, COUNT_ZERO); + close(fd); + remove("test.txt"); +} + +/** + * @tc.name : fchown_0400 + * @tc.desc : The user and group of the file's owner cannot be changed + * @tc.level : Level 2 + */ +void fchown_0400() +{ + int fd = open("test.txt", O_RDONLY | O_CREAT); + close(fd); + int result = fchown(fd, 0, 0); + EXPECT_EQ("fchown_0400", result, COUNT_NEFATIVE); + remove("test.txt"); +} + +/** + * @tc.name : fchown_0500 + * @tc.desc : The user and group of the file's owner cannot be changed + * @tc.level : Level 2 + */ +void fchown_0500() +{ + int fd = open("test.txt", O_RDONLY | O_CREAT); + int result = fchown(-1, 0, 0); + EXPECT_EQ("fchown_0500", result, COUNT_NEFATIVE); + close(fd); + remove("test.txt"); +} + +TEST_FUN G_Fun_Array[] = { + fchown_0100, + fchown_0200, + fchown_0300, + fchown_0400, + fchown_0500, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/fchownat.c b/libc-test/src/functionalext/supplement/unistd/fchownat.c new file mode 100644 index 00000000..853b50dc --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/fchownat.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : fchownat_0100 + * @tc.desc : Parameter fd is not equal to AT_FDCWD, the user and group that can change the owner of the file. + * @tc.level : Level 0 + */ +void fchownat_0100(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/fchownattest.txt"; + int fd = open(ptr, O_RDWR | O_CREAT); + EXPECT_TRUE("fchownat_0100", fd >= 0); + int ret = fchownat(fd, ptr, 0, 0, AT_SYMLINK_NOFOLLOW); + EXPECT_EQ("fchownat_0100", ret, 0); + struct stat buf; + int st = stat(ptr, &buf); + EXPECT_EQ("fchownat_0100", st, 0); + EXPECT_EQ("fchownat_0100", buf.st_uid, 0); + EXPECT_EQ("fchownat_0100", buf.st_gid, 0); + close(fd); + remove(ptr); + ptr = NULL; +} + +/** + * @tc.name : fchownat_0200 + * @tc.desc : Parameter fd equal to AT_FDCWD, the user and group that can change the owner of the file. + * @tc.level : Level 1 + */ +void fchownat_0200(void) +{ + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/fchownattest.txt"; + int fd = open(ptr, O_RDWR | O_CREAT); + EXPECT_TRUE("fchownat_0200", fd >= 0); + int ret = fchownat(AT_FDCWD, ptr, 0, 0, AT_SYMLINK_NOFOLLOW); + EXPECT_EQ("fchownat_0200", ret, 0); + struct stat buf; + int st = stat(ptr, &buf); + EXPECT_EQ("fchownat_0200", st, 0); + EXPECT_EQ("fchownat_0200", buf.st_uid, 0); + EXPECT_EQ("fchownat_0200", buf.st_gid, 0); + close(fd); + remove(ptr); + ptr = NULL; +} + +int main() +{ + fchownat_0100(); + fchownat_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/fdatasync.c b/libc-test/src/functionalext/supplement/unistd/fdatasync.c new file mode 100755 index 00000000..bb194fdd --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/fdatasync.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : fdatasync_0100 + * @tc.desc : Verify flush kernel's cache (parameter valid) + * @tc.level : Level 0 + */ +void fdatasync_0100() +{ + char str[] = "hello"; + char buffer[1024] = {"\0"}; + int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); + int retwrite = write(fd, str, sizeof(str)); + lseek(fd, 0L, SEEK_SET); + read(fd, buffer, 1024); + int result = fdatasync(fd); + EXPECT_EQ("fdatasync_0100", result, 0); + EXPECT_STREQ("fdatasync_0100", buffer, "hello"); + close(fd); + remove("/data/readtest.txt"); +} + +/** + * @tc.name : fdatasync_0200 + * @tc.desc : Verify failed to flush kernel's cache (file close) + * @tc.level : Level 2 + */ +void fdatasync_0200() +{ + char str[] = "hello\n"; + char buffer[1024] = {"\0"}; + int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); + close(fd); + int result = fdatasync(fd); + EXPECT_EQ("fdatasync_0200", result, -1); + remove("/data/readtest.txt"); +} + +/** + * @tc.name : fdatasync_0300 + * @tc.desc : Validation failed to flush kernel's cache (invalid parameter) + * @tc.level : Level 2 + */ +void fdatasync_0300() +{ + int result = fdatasync(-1); + EXPECT_EQ("fdatasync_0300", result, -1); +} + +TEST_FUN G_Fun_Array[] = { + fdatasync_0100, + fdatasync_0200, + fdatasync_0300, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) + { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/fsync.c b/libc-test/src/functionalext/supplement/unistd/fsync.c new file mode 100644 index 00000000..3e35de58 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/fsync.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" +#include + +/** + * @tc.name : fsync_0100 + * @tc.desc : Verify that the kernel's cache can be flushed (parameter invalid) + * @tc.level : Level 0 + */ +void fsync_0100(void) +{ + const char *msg = "This is a c test code for write function"; + const char *path = "/data/tests/libc-test/src/functionalext/supplement/unistd/test_write.txt"; + int len = strlen(msg); + struct stat buf; + + int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0777); + EXPECT_TRUE("fsync_0100", fd >= 0); + + int assos = write(fd, msg, len); + EXPECT_EQ("fsync_0100", assos, 40); + + int result = fsync(fd); + EXPECT_EQ("fsync_0100", result, 0); + + close(fd); + remove(path); +} + +/** + * @tc.name : fsync_0200 + * @tc.desc : Verify that the kernel's cache cannot be flushed (fd parameter invalid file close) + * @tc.level : Level 2 + */ +void fsync_0200(void) +{ + int fd, size; + char w[] = "this is a good boy!\n"; + fd = open("data/test.txt", S_IRWXO); + write(fd, w, sizeof("w")); + int result = fsync(fd); + close(fd); + EXPECT_EQ("fsync_0200", result, -1); +} + +/** + * @tc.name : fsync_0300 + * @tc.desc : Verify that the kernel's cache cannot be flushed (fd parameter is invalid) + * @tc.level : Level 2 + */ +void fsync_0300(void) +{ + int fd = -1; + int result = fsync(fd); + EXPECT_EQ("fsync_0300", result, -1); +} + +int main() +{ + fsync_0100(); + fsync_0200(); + fsync_0300(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/ftruncate.c b/libc-test/src/functionalext/supplement/unistd/ftruncate.c new file mode 100644 index 00000000..1764f531 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/ftruncate.c @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; +const int FILE_ZERO = 0; +const int FILE_FIRST = 10; +const int FILE_SECOND = 100; + +/** + * @tc.name : ftruncate_0100 + * @tc.desc : The parameter length is 0, which can clear the file content. + * @tc.level : Level 0 + */ +void ftruncate_0100(void) +{ + const char *ptr = "test.txt"; + FILE *fptr = fopen(ptr, "w"); + struct stat statbuff; + fprintf(fptr, "%s", "this is a sample!"); + int freturn = ftruncate(fileno(fptr), 0); + EXPECT_EQ("ftruncate_0100", freturn, SUCCESS); + stat(ptr, &statbuff); + EXPECT_EQ("ftruncate_0100", statbuff.st_size, FILE_ZERO); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : ftruncate_0200 + * @tc.desc : The parameter length is greater than 0 and less than the file size, + * which can clear the file content. + * @tc.level : Level 0 + */ +void ftruncate_0200(void) +{ + const char *ptr = "test.txt"; + FILE *fptr = fopen(ptr, "w"); + struct stat statbuff; + fprintf(fptr, "%s", "this is a sample!"); + int freturn = ftruncate(fileno(fptr), 10); + EXPECT_EQ("ftruncate_0200", freturn, SUCCESS); + stat(ptr, &statbuff); + EXPECT_EQ("ftruncate_0200", (int)statbuff.st_size, FILE_FIRST); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : ftruncate_0300 + * @tc.desc : The parameter length is greater than the file size,which can clear the file content. + * @tc.level : Level 0 + */ +void ftruncate_0300(void) +{ + const char *ptr = "test.txt"; + FILE *fptr = fopen(ptr, "w"); + struct stat statbuff; + fprintf(fptr, "%s", "this is a sample!"); + int freturn = ftruncate(fileno(fptr), 100); + EXPECT_EQ("ftruncate_0300", freturn, SUCCESS); + stat(ptr, &statbuff); + EXPECT_EQ("ftruncate_0300", (int)statbuff.st_size, FILE_SECOND); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : ftruncate_0400 + * @tc.desc : The fd parameter is invalid,the file content cannot be cleared. + * @tc.level : Level 2 + */ +void ftruncate_0400(void) +{ + const char *ptr = "test.txt"; + FILE *fptr = fopen(ptr, "w"); + fprintf(fptr, "%s", "this is a sample!"); + fclose(fptr); + int freturn = ftruncate(fileno(fptr), 10); + EXPECT_EQ("ftruncate_0400", freturn, FAILED); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : ftruncate_0500 + * @tc.desc : The fd parameter is NULL,the file content cannot be cleared. + * @tc.level : Level 2 + */ +void ftruncate_0500(void) +{ + const char *ptr = "test.txt"; + FILE *fptr = fopen(ptr, "w"); + fprintf(fptr, "%s", "this is a sample!"); + int freturn = ftruncate(0, 10); + EXPECT_EQ("ftruncate_0500", freturn, FAILED); + fclose(fptr); + remove(ptr); + fptr = NULL; + ptr = NULL; +} + +int main() +{ + ftruncate_0100(); + ftruncate_0200(); + ftruncate_0300(); + ftruncate_0400(); + ftruncate_0500(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/getcwd.c b/libc-test/src/functionalext/supplement/unistd/getcwd.c new file mode 100755 index 00000000..687fbdde --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/getcwd.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +// Manual test result +char *manual = "/data/tests/libc-test/src/functionalext/supplement/unistd"; +// hdc shell test result +char *hdc_auto = "/"; + +/* + * @tc.name : getcwd_0100 + * @tc.desc : Verify that the absolute path of the current working directory can be obtained + * (parameters are valid) + * @tc.level : Level 0 + */ +void getcwd_0100(void) +{ + char *result; + char buf[200]; + result = getcwd(buf, sizeof(buf)); + + if (!(strcmp(result, manual) ^ strcmp(result, hdc_auto))) { + t_error("%s getcwd failed, except result is %s when manual or %s when hdc test\n", __func__, manual, hdc_auto); + } +} + +/* + * @tc.name : getcwd_0200 + * @tc.desc : Verify that the absolute path of the current working directory can be obtained (parameter is NULL) + * @tc.level : Level 1 + */ +void getcwd_0200(void) +{ + char *result; + char buf[200]; + result = getcwd(NULL, 200); + if (!(strcmp(result, manual) ^ strcmp(result, hdc_auto))) { + t_error("%s getcwd failed, except result is %s when manual or %s when hdc test\n", __func__, manual, hdc_auto); + } +} + +/* + * @tc.name : getcwd_0300 + * @tc.desc : Verify that the absolute path of the current working directory cannot be obtained (parameter is 0) + * @tc.level : Level 2 + */ +void getcwd_0300(void) +{ + char *result; + char buf[200]; + result = getcwd(buf, 0); + if (result) { + t_error("%s getcwd should failed, the result should be null\n", __func__); + } +} + +int main() +{ + getcwd_0100(); + getcwd_0200(); + getcwd_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/getegid.c b/libc-test/src/functionalext/supplement/unistd/getegid.c new file mode 100755 index 00000000..6811202e --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/getegid.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/* + * @tc.name : getegid_0100 + * @tc.desc : Verify that the group ID can be obtained + * @tc.level : Level 0 + */ +void getegid_0100(void) +{ + char struid[10]; + system("id -g > ./id.txt"); + FILE *fptr = fopen("id.txt", "r"); + fread(struid, sizeof(struid), 1, fptr); + int id = atoi(struid); + gid_t gid = getegid(); + remove("id.txt"); + EXPECT_EQ("getegid_0100", gid, id); +} + +int main() +{ + getegid_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/geteuid.c b/libc-test/src/functionalext/supplement/unistd/geteuid.c new file mode 100755 index 00000000..2587a5e4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/geteuid.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/* + * @tc.name : geteuid_0100 + * @tc.desc : Verify that the user ID can be obtained + * @tc.level : Level 0 + */ +void geteuid_0100(void) +{ + char struid[10]; + system("id -u > ./id.txt"); + FILE *fptr = fopen("id.txt", "r"); + fread(struid, sizeof(struid), 1, fptr); + int id = atoi(struid); + uid_t uid = getegid(); + remove("id.txt"); + EXPECT_EQ("geteuid_0100", (int)uid, id); +} +int main() +{ + geteuid_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/getgid.c b/libc-test/src/functionalext/supplement/unistd/getgid.c new file mode 100755 index 00000000..d060ec7c --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/getgid.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + + +/* + * @tc.name : getgid_0100 + * @tc.desc : Verify that the current user group ID can be obtained + * @tc.level : Level 0 + */ +void getgid_0100(void) +{ + char struid[10]; + system("id -g > ./id.txt"); + FILE* fptr = fopen("id.txt", "r"); + fread(struid, sizeof(struid), 1, fptr); + int id = atoi(struid); + gid_t gid = getgid(); + remove("id.txt"); + EXPECT_EQ("getgid_0100", (int)gid, id); +} + + +int main() +{ + getgid_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/getgroups.c b/libc-test/src/functionalext/supplement/unistd/getgroups.c new file mode 100755 index 00000000..4ec05cf7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/getgroups.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +/* + * @tc.name : getgroups_0100 + * @tc.desc : Verify that the group ID can be obtained (parameter valid) + * @tc.level : Level 0 + */ +void getgroups_0100(void) +{ + char buffer[1024] = {0}; + gid_t list[500]; + system("id -g > id.txt"); + FILE *fptr = fopen("id.txt", "r"); + fread(buffer, sizeof(buffer), 1, fptr); + int id = atoi(buffer); + int result = getgroups(id, list); + EXPECT_EQ("getgroups_0100", result, id); +} + +/* + * @tc.name : getgroups_0200 + * @tc.desc : Verify that the group ID cannot be obtained (parameter invalid) + * @tc.level : Level 2 + */ +void getgroups_0200(void) +{ + char buffer[1024] = {0}; + gid_t list[500]; + system("id -g > id.txt"); + FILE *fptr = fopen("id.txt", "r"); + fread(buffer, sizeof(buffer), 1, fptr); + int id = atoi(buffer); + int result = getgroups(-1, list); + EXPECT_EQ("getgroups_0200", result, -1); +} + +int main() +{ + getgroups_0100(); + getgroups_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/gethostname.c b/libc-test/src/functionalext/supplement/unistd/gethostname.c new file mode 100644 index 00000000..c9683c32 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/gethostname.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : gethostname_0100 + * @tc.desc : Get the hostname through the gethostname method + * @tc.level : Level 0 + */ +void gethostname_0100(void) +{ + char hostname[65]; + int result = gethostname(hostname, sizeof(hostname)); + if (result != 0) { + t_error("%s gethostname get result is %d are not want 0\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + gethostname_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/getlogin.c b/libc-test/src/functionalext/supplement/unistd/getlogin.c new file mode 100644 index 00000000..a6ac40e9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/getlogin.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getlogin_0100 + * @tc.desc : Successfully obtained the logged in username. + * @tc.level : Level 0 + */ +void getlogin_0100(void) +{ + char *ret; + ret = getlogin(); + if (ret == NULL) { + int senv = setenv("LOGNAME", "newlogname", 1); + EXPECT_EQ("getlogin_0100", senv, 0); + ret = getlogin(); + EXPECT_TRUE("getlogin_0100", strcmp(ret, "newlogname") == 0); + unsetenv("LOGNAME"); + } else { + char *genv; + genv = getenv("LOGNAME"); + EXPECT_TRUE("getlogin_0100", strcmp(ret, genv) == 0); + } +} + +int main() +{ + getlogin_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/getlogin_r.c b/libc-test/src/functionalext/supplement/unistd/getlogin_r.c new file mode 100644 index 00000000..51ca895f --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/getlogin_r.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getlogin_r_0100 + * @tc.desc : Successfully obtained the logged in username. + * @tc.level : Level 0 + */ +void getlogin_r_0100(void) +{ + char login[256]; + int ret = getlogin_r(login, 256); + if (ret == 6) { + int senv = setenv("LOGNAME", "newlogname", 10); + EXPECT_EQ("getlogin_0100", senv, 0); + + ret = getlogin_r(login, 256); + EXPECT_EQ("getlogin_0100", ret, 0); + unsetenv("LOGNAME"); + } else { + EXPECT_EQ("getlogin_0100", ret, 0); + } +} + +/** + * @tc.name : getlogin_r_0200 + * @tc.desc : The parameter is invalid. Failed to get the logged in user name. + * @tc.level : Level 2 + */ +void getlogin_r_0200(void) +{ + int ret = 0; + char login[256]; + ret = getlogin_r("login", 0); + EXPECT_NE("getlogin_r_0200", ret, 0); +} + +int main() +{ + getlogin_r_0100(); + getlogin_r_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/getpgid.c b/libc-test/src/functionalext/supplement/unistd/getpgid.c new file mode 100644 index 00000000..1f209f31 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/getpgid.c @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_POSITIVE_PID 9999999 +#define TEST_NEGTIVE_PID (-100) + +/** + * @tc.name : getpgid_0100 + * @tc.desc : Get process groupid + * @tc.level : Level 0 + */ +void getpgid_0100(void) +{ + pid_t pid = getpgid(0); + EXPECT_TRUE("getpgid_0100", pid >= 0); + pid = getpgid(TEST_POSITIVE_PID); + EXPECT_EQ("getpgid_0100", pid, -1); + pid = getpgid(TEST_NEGTIVE_PID); + EXPECT_EQ("getpgid_0100", pid, -1); +} + +int main(void) +{ + getpgid_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/getpgrp.c b/libc-test/src/functionalext/supplement/unistd/getpgrp.c new file mode 100755 index 00000000..7f0ac6f5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/getpgrp.c @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getpgrp_0100 + * @tc.desc : Whether the child process is in the same process group as the parent process + * @tc.level : Level 0 + */ +void getpgrp_0100(void) +{ + pid_t gpid = getpgrp(); + pid_t child = fork(); + EXPECT_TRUE("getpgrp_0100", child >= 0); + + if (child == 0) { + pid_t gpid_child = getpgrp(); + EXPECT_EQ("getpgrp_0100", gpid_child, gpid); + } else if (child > 0) { + wait(NULL); + } +} + +int main(void) +{ + getpgrp_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/getpid.c b/libc-test/src/functionalext/supplement/unistd/getpid.c new file mode 100755 index 00000000..e70428aa --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/getpid.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +typedef void (*TEST_FUN)(); + +/** + * @tc.name : getpid_0100 + * @tc.desc : Verify to get the current process ID (shell command and call getpid function). + * @tc.level : Level 0 + */ +void getpid_0100(void) +{ + system("ps -eo command,pid | grep -E \"PID|getpid\" > " + "/data/tests/libc-test/src/functionalext/supplement/unistd/ps.txt"); + char abc[256] = {0}; + bool successflag = false; + const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/ps.txt"; + FILE *fptr = fopen(ptr, "r"); + if (fptr) { + while (!feof(fptr)) { + fread(abc, sizeof(abc), 1, fptr); + char num[8] = {0}; + int index = 0; + for (int i = 0; i < (int)strlen(abc); i++) { + if (abc[i] >= '0' && abc[i] <= '9') { + num[index++] += abc[i]; + } + } + int32_t intuid = atoi(num); + pid_t uid = getpid(); + if (intuid == uid) { + successflag = true; + } + } + } + EXPECT_TRUE("getpid_0100", successflag); + fclose(fptr); + remove(ptr); +} + +TEST_FUN G_Fun_Array[] = { + getpid_0100, +}; + +int main() +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/getppid.c b/libc-test/src/functionalext/supplement/unistd/getppid.c new file mode 100755 index 00000000..e65e9067 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/getppid.c @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getppid_0100 + * @tc.desc : Get the parent process id of the calling process + * @tc.level : Level 0 + */ +void getppid_0100(void) +{ + pid_t ppid = getpid(); + pid_t pid = fork(); + if (pid == 0) { + pid_t child_ppid = getppid(); + EXPECT_EQ("getppid_0100", child_ppid, ppid); + _exit(0); + } else if (pid > 0) { + wait(NULL); + } else { + EXPECT_FALSE("getppid_0100", 1); + } +} + +int main(void) +{ + getppid_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/getsid.c b/libc-test/src/functionalext/supplement/unistd/getsid.c new file mode 100644 index 00000000..355d3eef --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/getsid.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getsid_0100 + * @tc.desc : Verify getsid process success + * @tc.level : Level 0 + */ +void getsid_0100(void) +{ + pid_t sid = getsid(0); + EXPECT_EQ("getsid_0100", sid, getsid(0)); +} + +int main(void) +{ + getsid_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/getsockopt.c b/libc-test/src/functionalext/supplement/unistd/getsockopt.c new file mode 100755 index 00000000..cbd7a9cd --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/getsockopt.c @@ -0,0 +1,431 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "functionalext.h" + +#define IPPROTO_IP 0 +#define IP_HDRINCL 3 +#define IP_TTL 2 +#define TCP_MAXSEG 2 +#define TCP_NODELAY 1 +#define IP_TOS 1 +#define IP_OPTIONS 4 + + +/* + * @tc.name : getsockopt_0100 + * @tc.desc : Verify that the parameters are SO_DEBUG, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_0100(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_DEBUG,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0100",content,0); +} + +/* + * @tc.name : getsockopt_0200 + * @tc.desc : Verify that the parameters are SO_REUSEADDR, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_0200(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0200",content,0); + +} + +/* + * @tc.name : getsockopt_0300 + * @tc.desc : Verify that the parameters are SO_TYPE, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_0300(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_TYPE,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0300",content,0); + +} + +/* + * @tc.name : getsockopt_0400 + * @tc.desc : Verify that the parameters are SO_ERROR, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_0400(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_ERROR,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0400",content,0); + +} + +/* + * @tc.name : getsockopt_0500 + * @tc.desc : Verify that the parameters are SO_DONTROUTE, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_0500(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_DONTROUTE,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0500",content,0); + +} + +/* + * @tc.name : getsockopt_0600 + * @tc.desc : Verify that the parameters are SO_BROADCAST, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_0600(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_BROADCAST,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0600",content,0); +} + +/* + * @tc.name : getsockopt_0700 + * @tc.desc : Verify that the parameters are SO_SNDBUF, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_0700(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_SNDBUF,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0700",content,0); + +} + +/* + * @tc.name : getsockopt_0800 + * @tc.desc : Verify that the parameters are SO_RCVBUF, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_0800(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_RCVBUF,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0800",content,0); +} + +/* + * @tc.name : getsockopt_0900 + * @tc.desc : Verify that the parameters are SO_KEEPALIVE, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_0900(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_KEEPALIVE,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_0900",content,0); +} + +/* + * @tc.name : getsockopt_1000 + * @tc.desc : Verify that the parameters are SO_OOBINLINE, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_1000(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_OOBINLINE,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1000",content,0); + +} + +/* + * @tc.name : getsockopt_1100 + * @tc.desc : Verify that the parameters are SO_LINGER, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_1100(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_LINGER,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1100",content,0); + +} + +/* + * @tc.name : getsockopt_1200 + * @tc.desc : Verify that the parameters are SO_RCVLOWAT, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_1200(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_RCVLOWAT,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1200",content,0); + +} + +/* + * @tc.name : getsockopt_1300 + * @tc.desc : Verify that the parameters are SO_SNDLOWAT, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_1300(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_SNDLOWAT,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1300",content,0); + +} + +/* + * @tc.name : getsockopt_1400 + * @tc.desc : Verify that the parameters are SO_RCVTIMEO, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_1400(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_RCVTIMEO,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1400",content,0); + +} + +/* + * @tc.name : getsockopt_1500 + * @tc.desc : Verify that the parameters are SO_SNDTIMEO, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_1500(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_SNDTIMEO,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1500",content,0); + +} + +/* + * @tc.name : getsockopt_1600 + * @tc.desc : Verify that the parameters are SO_TIMESTAMP, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_1600(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_TIMESTAMP,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1600",content,0); + +} + +/* + * @tc.name : getsockopt_1700 + * @tc.desc : Verify that the parameters are SO_TIMESTAMPNS, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_1700(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_TIMESTAMPNS,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1700",content,0); + +} + +/* + * @tc.name : getsockopt_1800 + * @tc.desc : Verify that the parameters are IP_HDRINCL, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_1800(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,IPPROTO_IP,IP_HDRINCL,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1800",content,0); +} + +/* + * @tc.name : getsockopt_1900 + * @tc.desc : Verify that the parameters are IP_OPTIONS, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_1900(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,IPPROTO_IP,IP_OPTIONS,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_1900",content,0); + +} + +/* + * @tc.name : getsockopt_2000 + * @tc.desc : Verify that the parameters are IP_TOS, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_2000(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,IPPROTO_IP,IP_TOS,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_2000",content,0); + +} + +/* + * @tc.name : getsockopt_2100 + * @tc.desc : Verify that the parameters are IP_TTL, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_2100(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,IPPROTO_IP,IP_TTL,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_2100",content,0); + + +} + +/* + * @tc.name : getsockopt_2200 + * @tc.desc : Verify that the parameters are TCP_MAXSEG, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_2200(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,IPPROTO_IP,TCP_MAXSEG,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_2200",content,0); + +} + +/* + * @tc.name : getsockopt_2300 + * @tc.desc : Verify that the parameters are TCP_NODELAY, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_2300(void) +{ + int optval; + int optlen = 0; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,IPPROTO_IP,TCP_NODELAY,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_2300",content,0); + +} + +/* + * @tc.name : getsockopt_2400 + * @tc.desc : Verify that the parameters are SO_RCVBUF, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_2400(void) +{ + int optval; + int optlen = 0; + int content = getsockopt(-1,SOL_SOCKET,SO_RCVBUF,&optval,(socklen_t *)(&optlen)); + EXPECT_EQ("getsockopt_2400",content,-1); + +} + +/* + * @tc.name : getsockopt_2500 + * @tc.desc : Verify that the parameters are SO_DEBUG, get the file status successfully + * @tc.level : Level 0 + */ +void getsockopt_2500(void) +{ + int optval; + int sockfd = socket(AF_INET,SOCK_STREAM,0); + int content = getsockopt(sockfd,SOL_SOCKET,SO_DEBUG,&optval,NULL); + EXPECT_EQ("getsockopt_2500",content,-1); + +} + + +int main() +{ + getsockopt_0100(); + getsockopt_0200(); + getsockopt_0300(); + getsockopt_0400(); + getsockopt_0500(); + getsockopt_0600(); + getsockopt_0700(); + getsockopt_0800(); + getsockopt_0900(); + getsockopt_1000(); + getsockopt_1100(); + getsockopt_1200(); + getsockopt_1300(); + getsockopt_1400(); + getsockopt_1500(); + getsockopt_1600(); + getsockopt_1700(); + getsockopt_1800(); + getsockopt_1900(); + getsockopt_2000(); + getsockopt_2100(); + getsockopt_2200(); + getsockopt_2300(); + getsockopt_2400(); + getsockopt_2500(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/getuid.c b/libc-test/src/functionalext/supplement/unistd/getuid.c new file mode 100644 index 00000000..307ea59f --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/getuid.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : getuid_0100 + * @tc.desc : Can get the UID of the current process. + * @tc.level : Level 0 + */ +void getuid_0100(void) +{ + char struid[10]; + bool successflag = false; + system("id -u > ./id.txt"); + FILE *fptr = fopen("id.txt", "r"); + fread(struid, sizeof(struid), 1, fptr); + int intuid = atoi(struid); + uid_t uid = getuid(); + remove("id.txt"); + EXPECT_EQ("getuid_0100", uid, intuid); +} + +int main() +{ + getuid_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/lchown.c b/libc-test/src/functionalext/supplement/unistd/lchown.c new file mode 100755 index 00000000..8e5a1ad2 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/lchown.c @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "functionalext.h" + +#define TEST_ID_VALUE 100 + +/** + * @tc.name : lchown_0100 + * @tc.desc : Change ownership of a file + * @tc.level : Level 0 + */ +void lchown_0100(void) +{ + const char *pathname = "/data/tests/libc-test/src/functionalext/supplement/unistd/lchown"; + int ret = lchown(pathname, TEST_ID_VALUE, TEST_ID_VALUE); + EXPECT_EQ("lchown_0100", ret, CMPFLAG); +} + +int main(void) +{ + lchown_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/link.c b/libc-test/src/functionalext/supplement/unistd/link.c new file mode 100644 index 00000000..55fb44b9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/link.c @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : link_0100 + * @tc.desc : Determine whether the created connection is successful and whether the file exists + * @tc.level : Level 0 + */ +void link_0100(void) +{ + system("touch /etc/a.txt"); + int result = link("/etc/a.txt", "/etc/a_link.txt"); + EXPECT_EQ("link_0100", result, 0); + EXPECT_EQ("link_0100", access("/etc/a_link.txt", F_OK), 0); + system("rm -f /etc/a_link.txt"); +} + +/** + * @tc.name : link_0200 + * @tc.desc : Determine whether the file is successfully created when creating a hard link file with the same name + * @tc.level : Level 2 + */ +void link_0200(void) +{ + if (access("/etc/a_link.txt", F_OK) != 0) { + int result = link("/etc/a.txt", "/etc/a_link.txt"); + EXPECT_EQ("link_0200", result, 0); + } + EXPECT_NE("link_0200", link("/etc/a.txt", "/etc/a_link.txt"), 0); + EXPECT_EQ("link_0200", errno, EEXIST); + system("rm -f /etc/a_link.txt"); +} + +/** + * @tc.name : link_0300 + * @tc.desc : Outlier judgment + * @tc.level : Level 2 + */ +void link_0300(void) +{ + int result = link(NULL, NULL); + EXPECT_EQ("link_0300", result, ERREXPECT); + EXPECT_EQ("link_0300", errno, EFAULT); + + if (access("/etc/a.txt", F_OK) == 0) { + system("rm -f /etc/a.txt"); + } + + if (access("/etc/a_link.txt", F_OK) == 0) { + system("rm -f /etc/a_link.txt"); + } +} + +int main(void) +{ + // link_0100(); + // link_0200(); + // link_0300(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/linkat.c b/libc-test/src/functionalext/supplement/unistd/linkat.c new file mode 100644 index 00000000..644748b3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/linkat.c @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int32_t CREAT_MODE = 666; + +/** + * @tc.name : linkat_0100 + * @tc.desc : Vertify linkat process success. + * @tc.level : Level 0 + */ +void linkat_0100(void) +{ + int fd1 = creat("/etc/test.txt", CREAT_MODE); + int fd2 = -1; + if (fd1 < 0) { + EXPECT_MT("linkat_0100", fd1, 0); + return; + } else { + close(fd1); + } + int result = linkat(fd1, "/etc/test.txt", fd2, "/etc/linkat.txt", AT_SYMLINK_FOLLOW); + EXPECT_EQ("linkat_0100", result, 0); + EXPECT_EQ("linkat_0100", access("/etc/linkat.txt", F_OK), 0); + system("rm -f /etc/linkat.txt"); +} + +/** + * @tc.name : linkat_0200 + * @tc.desc : Vertify linkat process fail. Beceause creating a hard linkat file with the same name. + * @tc.level : Level 2 + */ +void linkat_0200(void) +{ + int fd1 = creat("/etc/test.txt", CREAT_MODE); + int fd2 = -1; + if (access("/etc/linkat.txt", F_OK) != 0) { + system("touch /etc/test.txt"); + if (fd1 < 0) { + EXPECT_MT("linkat_0100", fd1, 0); + return; + } else { + close(fd1); + } + int result = linkat(fd1, "/etc/test.txt", fd2, "/etc/linkat.txt", AT_SYMLINK_FOLLOW); + EXPECT_EQ("linkat_0200", result, 0); + } + EXPECT_NE("linkat_0200", linkat(fd1, "/etc/test.txt", fd2, "/etc/linkat.txt", AT_SYMLINK_FOLLOW), 0); + EXPECT_EQ("linkat_0200", errno, EEXIST); + system("rm -f /etc/linkat.txt"); +} + +/** + * @tc.name : linkat_0300 + * @tc.desc : Vertify linkat process fail. Beceause param is invalid. + * @tc.level : Level 2 + */ +void linkat_0300(void) +{ + int result = linkat(-1, NULL, -1, NULL, -1); + EXPECT_EQ("linkat_0300", result, ERREXPECT); + EXPECT_EQ("linkat_0300", errno, EINVAL); + + if (access("/etc/test.txt", F_OK) == 0) { + system("rm -f /etc/test.txt"); + } + + if (access("/etc/linkat.txt", F_OK) == 0) { + system("rm -f /etc/linkat.txt"); + } +} + +int main(void) +{ + linkat_0100(); + linkat_0200(); + linkat_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/lseek.c b/libc-test/src/functionalext/supplement/unistd/lseek.c new file mode 100644 index 00000000..cf3cc2e8 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/lseek.c @@ -0,0 +1,178 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "functionalext.h" + +#define TEST_BUFFER_SIZE 4 + +typedef void (*TEST_FUN)(); +const int FILE_ZERO = 0; +const int FILE_NEGA = -1; +const int FILE_EIGHT = 8; +const int FILE_TEN = 10; +const int FILE_TWENTWO = 22; +const int FILE_THIRTYTHREE = 33; + +/** + * @tc.name : lseek64_0100 + * @tc.desc : Determine whether the file read position is as expected + * @tc.level : Level 2 + */ +void lseek64_0100(void) +{ + off64_t DataArry[TEST_BUFFER_SIZE] = {1, 2, 4, 8}; + off64_t offset = 0; + int fd = open("lseek64_function_test.c", O_RDWR | O_CREAT); + if (fd < 0) { + t_error("open file failed\n"); + return; + } + for (int i = 0; i < TEST_BUFFER_SIZE; i++) { + lseek64(fd, 0, SEEK_SET); + offset = lseek64(fd, DataArry[i], SEEK_SET); + if (offset != DataArry[i]) { + EXPECT_FALSE("lseek64_0100", 1); + } + } + close(fd); + int ret = access("lseek64_function_test.c", F_OK); + if (ret != -1) { + ret = remove("./lseek64_function_test.c"); + } +} + +/** + * @tc.name : lseek_0100 + * @tc.desc : Verify that the file pointer is moved to the beginning of the file + * @tc.level : Level 0 + */ +void lseek_0100(void) +{ + char *wrstring = "This is a test sample!"; + int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); + int retwrite = write(fd, wrstring, sizeof(wrstring)); + off_t data = lseek(fd, 0L, SEEK_SET); + EXPECT_EQ("lseek_0100", (int)data, FILE_ZERO); + close(fd); + remove("/data/readtest.txt"); +} + +/** + * @tc.name : lseek_0200 + * @tc.desc : Verify that the file pointer is moved anywhere in the file + * @tc.level : Level 0 + */ +void lseek_0200(void) +{ + char *wrstring = "This is a test sample!"; + int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); + int retwrite = write(fd, wrstring, sizeof(wrstring)); + off_t data = lseek(fd, 8L, SEEK_SET); + EXPECT_EQ("lseek_0200", (int)data, FILE_EIGHT); + close(fd); + remove("/data/readtest.txt"); +} + +/** + * @tc.name : lseek_0300 + * @tc.desc : Verify moves the file pointer to the current file position + * @tc.level : Level 0 + */ +void lseek_0300(void) +{ + char *wrstring = "This is a test sample!"; + int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); + int retwrite = write(fd, wrstring, sizeof(wrstring)); + off_t data = lseek(fd, 10L, SEEK_SET); + data = lseek(fd, 0L, SEEK_CUR); + EXPECT_EQ("lseek_0300", (int)data, FILE_TEN); + close(fd); + remove("/data/readtest.txt"); +} + +/** + * @tc.name : lseek_0400 + * @tc.desc : Verify that the file pointer is moved to the end of the file + * @tc.level : Level 0 + */ +void lseek_0400(void) +{ + char str[] = "This is a test sample!"; + int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); + int retwrite = write(fd, str, sizeof(str)); + off_t data = lseek(fd, -1L, SEEK_END); + EXPECT_EQ("lseek_0400", (int)data, FILE_TWENTWO); + close(fd); + remove("/data/readtest.txt"); +} + +/** + * @tc.name : lseek_0500 + * @tc.desc : Verify that the move file pointer position is past the start position + * @tc.level : Level 2 + */ +void lseek_0500(void) +{ + char str[] = "This is a test sample!"; + int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); + int retwrite = write(fd, str, sizeof(str)); + off_t data = lseek(fd, -10L, SEEK_SET); + EXPECT_EQ("lseek_0500", (int)data, FILE_NEGA); + close(fd); + remove("/data/readtest.txt"); +} + +/** + * @tc.name : lseek_0600 + * @tc.desc : Verify that the moved file pointer position is past the end position + * @tc.level : Level 1 + */ +void lseek_0600(void) +{ + char str[] = "This is a test sample!"; + int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); + int retwrite = write(fd, str, sizeof(str)); + off_t data = lseek(fd, 10L, SEEK_END); + EXPECT_EQ("lseek_0600", (int)data, FILE_THIRTYTHREE); + close(fd); + remove("/data/readtest.txt"); +} + +TEST_FUN G_Fun_Array[] = { + lseek64_0100, + lseek_0100, + lseek_0200, + lseek_0300, + lseek_0400, + lseek_0500, + lseek_0600, +}; + +int main(void) +{ + int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); + for (int pos = 0; pos < num; ++pos) { + G_Fun_Array[pos](); + } + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/nice.c b/libc-test/src/functionalext/supplement/unistd/nice.c new file mode 100644 index 00000000..434622c1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/nice.c @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define TEST_NICE_RAT (-2) + +/** + * @tc.name : msync_0100 + * @tc.desc : Modified scheduling priority + * @tc.level : Level 0 + */ +void nice_0100(void) +{ + int rev = -1; + rev = nice(NZERO); + EXPECT_TRUE("nice_0100", rev > 0); + + rev = nice((TEST_NICE_RAT)*NZERO); + EXPECT_EQ("nice_0100", rev, -NZERO); +} + +/** + * @tc.name : nice_0200 + * @tc.desc : Exception parameters, modify scheduling priority + * @tc.level : Level 2 + */ +void nice_0200(void) +{ + int rev = nice(NZERO - 1); + EXPECT_EQ("nice_0200", rev, -1); +} + +int main(void) +{ + nice_0100(); + nice_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/pause.c b/libc-test/src/functionalext/supplement/unistd/pause.c new file mode 100755 index 00000000..3326d508 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/pause.c @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define TEST_ALARM_TIME 2 + +int gtest_pause_flag = 0; +static void signal_func(int signum) +{ + if (signum == SIGALRM) { + gtest_pause_flag = 1; + } +} + +/** + * @tc.name : pause_0100 + * @tc.desc : Wake up a suspended process with a signal + * @tc.level : Level 0 + */ +void pause_0100(void) +{ + struct sigaction act; + act.sa_handler = signal_func; + act.sa_flags = 0; + sigaction(SIGALRM, &act, NULL); + + alarm(TEST_ALARM_TIME); + EXPECT_FALSE("pause_0100", gtest_pause_flag); + int ret = pause(); + EXPECT_EQ("pause_0100", ret, ERREXPECT); + EXPECT_EQ("pause_0100", errno, EINTR); + EXPECT_TRUE("pause_0100", gtest_pause_flag); +} + +int main(void) +{ + // pause_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/pipe2.c b/libc-test/src/functionalext/supplement/unistd/pipe2.c new file mode 100755 index 00000000..7b7da2ce --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/pipe2.c @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define TEST_FD_SIZE 2 +#define TEST_BUFFER_SIZE 2 + +static void pipe2_test(const char *msg, int flag) +{ + int pipefd[TEST_FD_SIZE]; + char buf[TEST_BUFFER_SIZE]; + int ret = pipe2(pipefd, flag); + EXPECT_EQ(msg, ret, CMPFLAG); + if (ret != 0) { + return; + } + + memset(buf, 0x0, sizeof(buf)); + pid_t pid = fork(); + if (pid == 0) { + close(pipefd[1]); + while (read(pipefd[0], buf, 1) > 0) { + EXPECT_STREQ(msg, buf, "a"); + } + close(pipefd[0]); + _exit(0); + } else if (pid > 0) { + buf[0] = 'a'; + close(pipefd[0]); + write(pipefd[1], buf, 1); + close(pipefd[1]); + wait(NULL); + } else { + close(pipefd[0]); + close(pipefd[1]); + EXPECT_FALSE(msg, 1); + } +} + +/** + * @tc.name : pipe2_0100 + * @tc.desc : Create pipelines in two ways: O_CLOEXEC and O_NONBLOCK, and implement data transfer + * @tc.level : Level 0 + */ +void pipe2_0100(void) +{ + pipe2_test("pipe2_0100", 0); + pipe2_test("pipe2_0100", O_CLOEXEC); + pipe2_test("pipe2_0100", O_NONBLOCK); +} + +int main(void) +{ + pipe2_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/pread.c b/libc-test/src/functionalext/supplement/unistd/pread.c new file mode 100644 index 00000000..0f4264c5 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/pread.c @@ -0,0 +1,100 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +#define TEST_BUFFER_SIZE 64 + +/** + * @tc.name : pread_0100 + * @tc.desc : Read data from a file into a buffer + * @tc.level : Level 1 + */ +void pread_0100(void) +{ + const char *txt = "This is pread_0100 test."; + char buffer[TEST_BUFFER_SIZE]; + memset(buffer, 0x0, sizeof(buffer)); + FILE *fp = tmpfile(); + if (!fp) { + EXPECT_PTRNE("pread_0100", fp, NULL); + return; + } + int fd = fileno(fp); + pwrite(fd, txt, strlen(txt), 0); + lseek(fd, 0, SEEK_SET); + size_t cnt = pread(fd, buffer, TEST_BUFFER_SIZE, 0); + EXPECT_EQ("pread_0100", cnt, strlen(txt)); + EXPECT_STREQ("pread_0100", txt, buffer); + int ret = fclose(fp); + EXPECT_EQ("pread_0100", ret, 0); +} + +/** + * @tc.name : pread_0200 + * @tc.desc : The current position is at the end, read data from a file into a buffer + * @tc.level : Level 1 + */ +void pread_0200(void) +{ + const char *txt = "This is pread_0200 test."; + char buffer[TEST_BUFFER_SIZE]; + memset(buffer, 0x0, sizeof(buffer)); + FILE *fp = tmpfile(); + if (!fp) { + EXPECT_PTRNE("pread_0200", fp, NULL); + return; + } + int fd = fileno(fp); + pwrite(fd, txt, strlen(txt), 0); + size_t cnt = pread(fd, buffer, TEST_BUFFER_SIZE, 0); + EXPECT_EQ("pread_0200", cnt, strlen(txt)); + EXPECT_STREQ("pread_0200", txt, buffer); + int ret = fclose(fp); + EXPECT_EQ("pread_0200", ret, 0); +} + +/** + * @tc.name : pread_0300 + * @tc.desc : The current position is at the end, read the following data + * @tc.level : Level 2 + */ +void pread_0300(void) +{ + const char *txt = "This is pread_0300 test."; + char buffer[TEST_BUFFER_SIZE]; + memset(buffer, 0x0, sizeof(buffer)); + FILE *fp = tmpfile(); + if (!fp) { + EXPECT_PTRNE("pread_0300", fp, NULL); + return; + } + int fd = fileno(fp); + pwrite(fd, txt, strlen(txt), 0); + size_t cnt = pread(fd, buffer, TEST_BUFFER_SIZE, strlen(txt)); + EXPECT_EQ("pread_0300", cnt, 0); + int ret = fclose(fp); + EXPECT_EQ("pread_0300", ret, 0); +} + +int main(void) +{ + pread_0100(); + pread_0200(); + pread_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/preadv.c b/libc-test/src/functionalext/supplement/unistd/preadv.c new file mode 100755 index 00000000..35837015 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/preadv.c @@ -0,0 +1,92 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define BUFFER_SIZE 8 + +/** + * @tc.name : preadv_0100 + * @tc.desc : Create and open the preadv_function_value.c file, write data to the file, call the preadv function + * to read the data in the file from the beginning of the file, close and delete the created file + * @tc.level : Level 1 + */ +void preadv_0100(void) +{ + char buf1[BUFFER_SIZE]; + char buf2[BUFFER_SIZE]; + struct iovec iov[2]; + + memset(buf1, '\0', BUFFER_SIZE); + memset(buf2, '\0', BUFFER_SIZE); + + iov[0].iov_base = buf1; + iov[0].iov_len = sizeof(buf1) / sizeof(char); + iov[1].iov_base = buf2; + iov[1].iov_len = sizeof(buf2) / sizeof(char); + + int fd = open("./preadv_function_value.c", O_RDWR | O_CREAT); + if (fd == -1) { + EXPECT_NE("preadv_0100", fd, ERREXPECT); + return; + } + char data[] = "preadv test"; + int arraysize = sizeof(data) / sizeof(char); + int ret = write(fd, data, sizeof(data)); + if (ret < 0) { + EXPECT_NE("preadv_0100", ret, EOF); + return; + } + int count = sizeof(iov) / sizeof(struct iovec); + ret = preadv(fd, iov, count, 0); + EXPECT_EQ("preadv_0100", ret, arraysize); + + close(fd); + ret = access("preadv_function_value.c", F_OK); + if (ret != -1) { + ret = remove("./preadv_function_value.c"); + EXPECT_EQ("preadv_0100", ret, CMPFLAG); + } +} + +/** + * @tc.name : preadv_0200 + * @tc.desc : Pass in the abnormal file descriptor and call the preadv function to read the data(failed) + * @tc.level : Level 2 + */ +void preadv_0200(void) +{ + char buf1[8]; + char buf2[8]; + struct iovec iov[2]; + + iov[0].iov_base = buf1; + iov[0].iov_len = sizeof(buf1) / sizeof(char); + iov[1].iov_base = buf2; + iov[1].iov_len = sizeof(buf2) / sizeof(char); + int count = sizeof(iov) / sizeof(struct iovec); + int ret = preadv(-1, iov, count, 0); + EXPECT_EQ("preadv_0200", ret, EOF); +} + +int main(void) +{ + preadv_0100(); + preadv_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/pwrite.c b/libc-test/src/functionalext/supplement/unistd/pwrite.c new file mode 100755 index 00000000..133381d3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/pwrite.c @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +#define TEST_BUFFER_SIZE 64 +#define TEST_MODE 0777 + +void rm_file(const char *name) +{ + if (access(name, F_OK) == 0) { + unlink(name); + } +} + +/** + * @tc.name : pwrite_0100 + * @tc.desc : Write to a file descriptor at a given offset + * @tc.level : Level 0 + */ +void pwrite_0100(void) +{ + const char *txt = "This is pwrite_0100 test."; + char buffer[TEST_BUFFER_SIZE]; + memset(buffer, 0x0, sizeof(buffer)); + + int fd = open("pwrite_0100", O_CREAT | O_RDWR, TEST_MODE); + EXPECT_NE("pwrite_0100", fd, ERREXPECT); + if (fd == -1) { + return; + } + size_t cnt = pwrite(fd, txt, strlen(txt), 0); + EXPECT_EQ("pwrite_0100", cnt, strlen(txt)); + + lseek(fd, 0, SEEK_SET); + cnt = pread(fd, buffer, TEST_BUFFER_SIZE, 0); + EXPECT_EQ("pwrite_0100", cnt, strlen(txt)); + EXPECT_STREQ("pwrite_0100", txt, buffer); + close(fd); + rm_file("pwrite_0100"); +} + +/** + * @tc.name : pwrite_0200 + * @tc.desc : Provide illegal parameter data, write data to the open file + * @tc.level : Level 2 + */ +void pwrite_0200(void) +{ + const char *txt = "This is pwrite_0200 test."; + size_t cnt = pwrite(-1, txt, strlen(txt), 0); + EXPECT_EQ("pwrite_0200", cnt, (size_t)(-1)); + + int fd = open("pwrite_0200", O_CREAT | O_RDWR, TEST_MODE); + EXPECT_NE("pwrite_0200", fd, -1); + if (fd == -1) { + return; + } + + cnt = pwrite(fd, txt, 0, 0); + EXPECT_EQ("pwrite_0200", cnt, CMPFLAG); + + cnt = pwrite(fd, NULL, 0, 0); + EXPECT_EQ("pwrite_0200", cnt, CMPFLAG); + close(fd); + rm_file("pwrite_0200"); +} + +int main(void) +{ + pwrite_0100(); + pwrite_0200(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/pwritev.c b/libc-test/src/functionalext/supplement/unistd/pwritev.c new file mode 100755 index 00000000..353129af --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/pwritev.c @@ -0,0 +1,109 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +/** + * @tc.name : pwritev_0100 + * @tc.desc : Create a temporary file and centrally write the contents of multiple buffers to the file(success) + * @tc.level : Level 0 + */ +void pwritev_0100(void) +{ + char buf1[] = "preadv"; + char buf2[] = "and pwritev"; + struct iovec iov[2]; + + iov[0].iov_base = buf1; + iov[0].iov_len = sizeof(buf1) / sizeof(char); + iov[1].iov_base = buf2; + iov[1].iov_len = sizeof(buf2) / sizeof(char); + + int fd = open("pwritev_function_value.c", O_RDWR | O_CREAT); + int count = sizeof(iov) / sizeof(struct iovec); + int ret = pwritev(fd, iov, count, 0); + EXPECT_NE("pwritev_0100", ret, EOF); + + close(fd); + ret = access("pwritev_function_value.c", F_OK); + if (ret == 0) { + ret = remove("pwritev_function_value.c"); + EXPECT_EQ("pwritev_0100", ret, CMPFLAG); + } +} + +/** + * @tc.name : pwritev_0200 + * @tc.desc : Create a temporary file and centrally write the contents of multiple buffers to the file(failed) + * @tc.level : Level 2 + */ +void pwritev_0200(void) +{ + char buf1[] = "pwritev1"; + char buf2[] = "pwritev2"; + struct iovec iov[2]; + + iov[0].iov_base = buf1; + iov[0].iov_len = sizeof(buf1) / sizeof(char); + iov[1].iov_base = buf2; + iov[1].iov_len = sizeof(buf2) / sizeof(char); + + int fd = open("pwritev_function_value.c", O_RDWR | O_CREAT); + if (fd == -1) { + EXPECT_NE("pwritev_0200", fd, ERREXPECT); + return; + } + int count = sizeof(iov) / sizeof(struct iovec); + int ret = pwritev(fd, iov, count + 1, 0); + EXPECT_EQ("pwritev_0200", ret, EOF); + + close(fd); + ret = access("pwritev_function_value.c", F_OK); + if (ret == 0) { + ret = remove("pwritev_function_value.c"); + EXPECT_EQ("pwritev_0200", ret, CMPFLAG); + } +} + +/** + * @tc.name : pwritev_0300 + * @tc.desc : Write multiple buffer contents to invalid file descriptor + * @tc.level : Level 2 + */ +void pwritev_0300(void) +{ + char buf1[] = "pwritev1"; + char buf2[] = "pwritev2"; + struct iovec iov[2]; + + iov[0].iov_base = buf1; + iov[0].iov_len = sizeof(buf1) / sizeof(char); + iov[1].iov_base = buf2; + iov[1].iov_len = sizeof(buf2) / sizeof(char); + int count = sizeof(iov) / sizeof(struct iovec); + int ret = pwritev(-1, iov, count, 0); + EXPECT_EQ("pwritev_0300", ret, EOF); +} + +int main(void) +{ + pwritev_0100(); + pwritev_0200(); + pwritev_0300(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/read.c b/libc-test/src/functionalext/supplement/unistd/read.c new file mode 100644 index 00000000..c30a07bb --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/read.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int SIZE = 20; + +/** + * @tc.name : read_0100 + * @tc.desc : The parameters are valid and the actual number of characters can be read. + * @tc.level : Level 0 + */ +void read_0100(void) +{ + char str[] = "this is a readtest\n"; + char buffer[1024] = {0}; + int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); + EXPECT_TRUE("read_0100", fd >= 0); + int retwrite = write(fd, str, sizeof(str)); + EXPECT_EQ("read_0100", retwrite, SIZE); + lseek(fd, 0, SEEK_SET); + int size = read(fd, buffer, 1024); + EXPECT_EQ("read_0100", size, SIZE); + close(fd); + remove("/data/readtest.txt"); +} + +int main() +{ + read_0100(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/readlink.c b/libc-test/src/functionalext/supplement/unistd/readlink.c new file mode 100644 index 00000000..ba60913c --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/readlink.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +/** + * @tc.name : readlink_0100 + * @tc.desc : Symlink to path exists and bufsize is large enough to return the number of characters correctly. + * @tc.level : Level 0 + */ +void readlink_0100(void) +{ + struct stat sb; + char *buf; + int ret; + char *wstr = "this is a test\n"; + const char *softptr = "./readlink.txt.soft"; + buf = malloc(sb.st_size + 1); + const char *ptr = "readlink.txt"; + FILE *fptr = fopen(ptr, "w"); + EXPECT_TRUE("readlink_0100", fptr != NULL); + int size = fwrite(wstr, sizeof(char), strlen(wstr), fptr); + EXPECT_EQ("readlink_0100", size, strlen(wstr)); + fclose(fptr); + int link = symlink("./readlink.txt", softptr); + EXPECT_EQ("readlink_0100", link, 0); + ret = readlink(softptr, buf, sizeof(buf)); + EXPECT_EQ("readlink_0100", ret, sizeof(buf)); + remove(ptr); + remove(softptr); + buf = NULL; + wstr = NULL; + softptr = NULL; + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : readlink_0200 + * @tc.desc : Symlink to path exists and the bufsize is not large enough to + * return the number of characters correctly. + * @tc.level : Level 1 + */ +void readlink_0200(void) +{ + struct stat sb; + char *buf; + int ret; + char *wstr = "this is a test\n"; + const char *softptr = "./readlink.txt.soft"; + buf = malloc(sb.st_size + 1); + const char *ptr = "readlink.txt"; + FILE *fptr = fopen(ptr, "w"); + EXPECT_TRUE("readlink_0200", fptr != NULL); + int size = fwrite(wstr, sizeof(char), strlen(wstr), fptr); + EXPECT_EQ("readlink_0200", size, strlen(wstr)); + fclose(fptr); + int link = symlink("./readlink.txt", softptr); + EXPECT_EQ("readlink_0200", link, 0); + ret = readlink(softptr, buf, sizeof(buf) - 2); + EXPECT_EQ("readlink_0200", ret, sizeof(buf) - 2); + remove(ptr); + remove(softptr); + buf = NULL; + wstr = NULL; + softptr = NULL; + fptr = NULL; + ptr = NULL; +} + +/** + * @tc.name : readlink_0300 + * @tc.desc : Symbolic link that does not exist in path cannot have the correct number of characters. + * @tc.level : Level 2 + */ +void readlink_0300(void) +{ + struct stat sb; + char *buf; + int ret; + const char *softptr = "./noreadlink.txt.soft"; + buf = malloc(sb.st_size + 1); + ret = readlink(softptr, buf, sizeof(buf)); + EXPECT_TRUE("readlink_0300", ret < 0); + buf = NULL; + softptr = NULL; +} + +int main() +{ + readlink_0100(); + readlink_0200(); + readlink_0300(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/readlinkat.c b/libc-test/src/functionalext/supplement/unistd/readlinkat.c new file mode 100644 index 00000000..c149ef83 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/readlinkat.c @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "test.h" + +const char *path = "/data/tests/file.txt"; +const char *linkpath = "/data/tests/linkfile.txt"; +const char buf[] = "hello"; +const char *dirname = "/data/tests"; +const char *filename = "./file.txt"; +const char *linkfilename = "./linkfile.txt"; + +int create_file(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + if (fd < 0) { + return -1; + } + + ssize_t bytes = write(fd, buf, sizeof(buf)); + if (bytes <= 0) { + return -1; + } + + int result = close(fd); + if (result != 0) { + return -1; + } + + return 0; +} + +/** + * @tc.name : readlinkat_0100 + * @tc.desc : read value of a symbolic link + * @tc.level : Level 0 + */ +void readlinkat_0100(void) +{ + int result = create_file(); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + remove(linkpath); + + result = symlink(path, linkpath); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + int fd = open(linkpath, O_RDONLY); + if (fd < 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + return; + } + + char rbuf[BUFSIZ] = {0}; + ssize_t bytes = readlinkat(fd, linkpath, rbuf, sizeof(rbuf)); + if (bytes != strlen(rbuf)) { + t_error("%s failed: bytes = %ld\n", __func__, bytes); + } + + if (strcmp(rbuf, path)) { + t_error("%s failed: rbuf = %s\n", __func__, rbuf); + } + + remove(linkpath); + remove(path); +} + +/** + * @tc.name : readlinkat_0200 + * @tc.desc : read value of a symbolic link with a dir fd + * @tc.level : Level 1 + */ +void readlinkat_0200(void) +{ + int result = create_file(); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + DIR *dir = opendir(dirname); + if (dir == NULL) { + t_error("%s failed: dirname = %s\n", __func__, dirname); + return; + } + + int fd = dirfd(dir); + if (fd < 0) { + t_error("%s failed: fd = %d\n", __func__, fd); + } + + remove(linkpath); + + result = symlinkat(filename, fd, linkfilename); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + char rbuf[BUFSIZ] = {0}; + ssize_t bytes = readlinkat(fd, linkfilename, rbuf, sizeof(rbuf)); + if (bytes != strlen(rbuf)) { + t_error("%s failed: bytes = %ld\n", __func__, bytes); + } + + if (strcmp(rbuf, filename)) { + t_error("%s failed: rbuf = %s\n", __func__, rbuf); + } + + remove(linkpath); + remove(path); +} + +/** + * @tc.name : readlinkat_0300 + * @tc.desc : read value of a symbolic link with invalid parameters + * @tc.level : Level 2 + */ +void readlinkat_0300(void) +{ + ssize_t bytes = readlinkat(-1, NULL, NULL, 0); + if (bytes >= 0) { + t_error("%s failed: bytes = %ld\n", __func__, bytes); + } +} + +int main(int argc, char *argv[]) +{ + readlinkat_0100(); + readlinkat_0200(); + readlinkat_0300(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/readv.c b/libc-test/src/functionalext/supplement/unistd/readv.c new file mode 100644 index 00000000..5d761554 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/readv.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "test.h" + +const char *path = "/data/tests/libc-test/src/file.txt"; + +/** + * @tc.name : readv_0100 + * @tc.desc : read data into multiple buffers + * @tc.level : Level 0 + */ +void readv_0100(void) +{ + int fd = open(path, O_RDWR | O_CREAT); + + char buf1[] = "hello"; + char buf2[] = "world"; + struct iovec ios[] = {{buf1, strlen(buf1)}, {buf2, strlen(buf2)}}; + + ssize_t result = writev(fd, ios, sizeof(ios) / sizeof(struct iovec)); + if (result != strlen(buf1) + strlen(buf2)) { + t_error("%s failed: result = %ld\n", __func__, result); + } + + lseek(fd, 0, SEEK_SET); + + memset(buf1, 0, sizeof(buf1)); + memset(buf2, 0, sizeof(buf2)); + + result = readv(fd, ios, sizeof(ios) / sizeof(struct iovec)); + if (result != strlen(buf1) + strlen(buf2)) { + t_error("%s failed: result = %ld\n", __func__, result); + } + + if (strcmp(buf1, "hello")) { + t_error("%s failed: buf1 = %s\n", __func__, buf1); + } + + if (strcmp(buf2, "world")) { + t_error("%s failed: buf2 = %s\n", __func__, buf2); + } + + remove(path); +} + +/** + * @tc.name : readv_0200 + * @tc.desc : read data into multiple buffers with invalid parameters + * @tc.level : Level 2 + */ +void readv_0200(void) +{ + errno = 0; + ssize_t result = readv(-1, NULL, -1); + if (result == 0) { + t_error("%s failed: result = %ld\n", __func__, result); + } + + if (errno == 0) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + readv_0100(); + readv_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/renameat.c b/libc-test/src/functionalext/supplement/unistd/renameat.c new file mode 100644 index 00000000..0a607715 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/renameat.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : renameat_0100 + * @tc.desc : When newname already exists, test the renameat function + * @tc.level : Level 0 + */ +void renameat_0100(void) +{ + int oldfd, newfd; + char oldPath[] = "/data/renameat.txt"; + char newPath[] = "/data/newrenameat.txt"; + const char *msg = "test code"; + int len = strlen(msg); + char buf[1024] = {0}; + + if ((oldfd = creat(oldPath, S_IWUSR)) < 0) { + t_error("%s creat oldfd failed\n", __func__); + } + if ((newfd = creat(newPath, S_IWUSR)) < 0) { + t_error("%s creat newfd failed\n", __func__); + } + close(oldfd); + close(newfd); + oldfd = open(oldPath, O_RDWR); + int wresult = write(oldfd, msg, len); + if (wresult != len) { + t_error("%s write get result is %d not want %d\n", __func__, wresult, len); + } + close(oldfd); + if (renameat(oldfd, oldPath, newfd, newPath) == -1) { + t_error("%s renameat failed\n", __func__); + return; + } + newfd = open(newPath, O_RDWR); + int bytes = read(newfd, buf, len); + if (bytes == -1) { + t_error("%s read file failed\n", __func__); + return; + } + if (strcmp(msg, buf)) { + t_error("%s wrong string written to file\n", __func__); + return; + } + close(newfd); + remove(newPath); +} + +int main(int argc, char *argv[]) +{ + renameat_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/rmdir.c b/libc-test/src/functionalext/supplement/unistd/rmdir.c new file mode 100644 index 00000000..1d36cd6d --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/rmdir.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "functionalext.h" + +const int SUCCESS = 0; +const int FAILED = -1; + +/** + * @tc.name : rmdir_0100 + * @tc.desc : The parameter is valid, and the file directory can be deleted. + * @tc.level : Level 0 + */ +void rmdir_0100(void) +{ + char *path = "testnormal"; + if (access(path, F_OK) != 0) { + int ret = mkdir(path, 0777); + EXPECT_EQ("rmdir_0100", ret, SUCCESS); + int rm = rmdir(path); + EXPECT_EQ("rmdir_0100", rm, SUCCESS); + } else { + remove(path); + int ret = mkdir(path, 0777); + EXPECT_EQ("rmdir_0100", ret, SUCCESS); + int rm = rmdir(path); + EXPECT_EQ("rmdir_0100", rm, SUCCESS); + } + path = NULL; +} + +/** + * @tc.name : rmdir_0200 + * @tc.desc : The parameter is invalid, the directory cannot be deleted. + * @tc.level : Level 2 + */ +void rmdir_0200(void) +{ + char *path = "testerror"; + if (access(path, F_OK) != 0) { + int rm = rmdir(path); + EXPECT_EQ("rmdir_0200", rm, FAILED); + } else { + int rm = rmdir(path); + EXPECT_EQ("rmdir_0200", rm, SUCCESS); + rm = rmdir(path); + EXPECT_EQ("rmdir_0200", rm, FAILED); + } + path = NULL; +} + +int main() +{ + rmdir_0100(); + rmdir_0200(); + + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/setdomainname.c b/libc-test/src/functionalext/supplement/unistd/setdomainname.c new file mode 100644 index 00000000..d0bbe1f7 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/setdomainname.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +const char name[] = "www.example.com"; + +/** + * @tc.name : setdomainname_0100 + * @tc.desc : set NIS domain name + * @tc.level : Level 0 + */ +void setdomainname_0100(void) +{ + // store current NIS domain name + char cbuf[BUFSIZ] = {0}; + int result = getdomainname(cbuf, sizeof(cbuf)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + result = setdomainname(name, strlen(name)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + char buf[BUFSIZ] = {0}; + result = getdomainname(buf, sizeof(buf)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (strcmp(buf, name)) { + t_error("%s failed: buf = %s\n", __func__, buf); + } + + // restore NIS domain name + result = setdomainname(cbuf, strlen(cbuf)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } +} + +/** + * @tc.name : setdomainname_0200 + * @tc.desc : set an empty NIS domain name + * @tc.level : Level 1 + */ +void setdomainname_0200(void) +{ + // store current NIS domain name + char cbuf[BUFSIZ] = {0}; + int result = getdomainname(cbuf, sizeof(cbuf)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + result = setdomainname(NULL, 0); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + char buf[BUFSIZ] = {0}; + result = getdomainname(buf, sizeof(buf)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (strlen(buf) != 0) { + t_error("%s failed: buf = %s\n", __func__, buf); + } + + // restore NIS domain name + result = setdomainname(cbuf, strlen(cbuf)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } +} + +/** + * @tc.name : setdomainname_0300 + * @tc.desc : set NIS domain name with an invalid length + * @tc.level : Level 2 + */ +void setdomainname_0300(void) +{ + int result = setdomainname(NULL, -1); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + setdomainname_0100(); + setdomainname_0200(); + setdomainname_0300(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/setegid.c b/libc-test/src/functionalext/supplement/unistd/setegid.c new file mode 100644 index 00000000..422b7dcd --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/setegid.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "test.h" + +/** + * @tc.name : setegid_0100 + * @tc.desc : set effective group ID + * @tc.level : Level 0 + */ +void setegid_0100(void) +{ + gid_t cegid = getegid(); + + gid_t segid = 1; + int result = setegid(segid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + gid_t egid = getegid(); + if (egid != segid) { + t_error("%s failed: egid = %d\n", __func__, egid); + } + + result = setegid(cegid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : setegid_0200 + * @tc.desc : set effective group ID with the current effective group ID + * @tc.level : Level 1 + */ +void setegid_0200(void) +{ + gid_t cegid = getegid(); + + gid_t segid = cegid; + int result = setegid(segid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + gid_t egid = getegid(); + if (egid != segid) { + t_error("%s failed: egid = %d\n", __func__, egid); + } +} + +int main(int argc, char *argv[]) +{ + setegid_0100(); + setegid_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/seteuid.c b/libc-test/src/functionalext/supplement/unistd/seteuid.c new file mode 100644 index 00000000..09d8479f --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/seteuid.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : seteuid_0100 + * @tc.desc : Call the seteuid method to set the process uid + * @tc.level : Level 0 + */ +void seteuid_0100(void) +{ + uid_t uid = 0; + int result = seteuid(uid); + if (result != 0) { + t_error("%s seteuid error get result is %d are not 0\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + seteuid_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/setgid.c b/libc-test/src/functionalext/supplement/unistd/setgid.c new file mode 100644 index 00000000..14c134e9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/setgid.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : setgid_0100 + * @tc.desc : Call the setgid method to set the process gid + * @tc.level : Level 0 + */ +void setgid_0100(void) +{ + uid_t gid = 0; + int result = setgid(gid); + if (result != 0) { + t_error("%s setgid error get result is %d are not 0\n", __func__, result); + } + if (getgid() != gid) { + t_error("%s setgid failed", __func__); + } +} + +int main(int argc, char *argv[]) +{ + setgid_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/sethostname.c b/libc-test/src/functionalext/supplement/unistd/sethostname.c new file mode 100644 index 00000000..820a1ac9 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/sethostname.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "test.h" + +const char name[] = "www.example.com"; + +/** + * @tc.name : sethostname_0100 + * @tc.desc : set hostname + * @tc.level : Level 0 + */ +void sethostname_0100(void) +{ + // store current hostname + char cbuf[BUFSIZ] = {0}; + int result = gethostname(cbuf, sizeof(cbuf)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + result = sethostname(name, strlen(name)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + char buf[BUFSIZ] = {0}; + result = gethostname(buf, sizeof(buf)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (strcmp(buf, name)) { + t_error("%s failed: buf = %s\n", __func__, buf); + } + + // restore hostname + result = sethostname(cbuf, strlen(cbuf)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } +} + +/** + * @tc.name : sethostname_0200 + * @tc.desc : set an empty hostname + * @tc.level : Level 1 + */ +void sethostname_0200(void) +{ + // store current hostname + char cbuf[BUFSIZ] = {0}; + int result = gethostname(cbuf, sizeof(cbuf)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + result = sethostname(NULL, 0); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + char buf[BUFSIZ] = {0}; + result = gethostname(buf, sizeof(buf)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (strlen(buf) != 0) { + t_error("%s failed: buf = %s\n", __func__, buf); + } + + // restore hostname + result = sethostname(cbuf, strlen(cbuf)); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } +} + +/** + * @tc.name : sethostname_0300 + * @tc.desc : set hostname with an invalid length + * @tc.level : Level 2 + */ +void sethostname_0300(void) +{ + int result = sethostname(NULL, -1); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + sethostname_0100(); + sethostname_0200(); + sethostname_0300(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/setpgid.c b/libc-test/src/functionalext/supplement/unistd/setpgid.c new file mode 100644 index 00000000..7f4cfdd1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/setpgid.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : setpgid_0100 + * @tc.desc : Sets the process group ID of the process specified by pid to pgid + * @tc.level : Level 0 + */ +void setpgid_0100(void) +{ + pid_t pid = 0; + pid_t pgid = 0; + int result = setpgid(pid, pgid); + if (result < 0) { + t_error("%s setpgid failed", __func__); + } + if (getgid() != result) { + t_error("%s setpgid invalid", __func__); + } +} + +int main(int argc, char *argv[]) +{ + setpgid_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/setpgrp.c b/libc-test/src/functionalext/supplement/unistd/setpgrp.c new file mode 100644 index 00000000..1d5225e4 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/setpgrp.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : setpgrp_0100 + * @tc.desc : Set the group ID of the current process as the process ID of the current process + * @tc.level : Level 0 + */ +void setpgrp_0100(void) +{ + pid_t pt = setpgrp(); + if (pt == -1 && getpgrp() != getpid()) { + t_error("%s setpgrp failed\n", __func__); + } +} + +int main(int argc, char *argv[]) +{ + setpgrp_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/setregid.c b/libc-test/src/functionalext/supplement/unistd/setregid.c new file mode 100644 index 00000000..3e867aed --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/setregid.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "test.h" + +/** + * @tc.name : setregid_0100 + * @tc.desc : set real and/or effective group ID + * @tc.level : Level 0 + */ +void setregid_0100(void) +{ + gid_t cgid = getgid(); + gid_t cegid = getegid(); + + gid_t srgid = 1; + gid_t segid = 2; + int result = setregid(srgid, segid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + gid_t gid = getgid(); + gid_t egid = getegid(); + if (gid != srgid || egid != segid) { + t_error("%s failed: gid = %d\n", __func__, gid); + t_error("%s failed: egid = %d\n", __func__, egid); + } + + result = setregid(cgid, cegid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : setregid_0200 + * @tc.desc : set real and/or effective group ID with the current effective group ID + * @tc.level : Level 1 + */ +void setregid_0200(void) +{ + gid_t cgid = getgid(); + gid_t cegid = getegid(); + + gid_t srgid = cgid; + gid_t segid = cegid; + int result = setregid(srgid, segid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + gid_t gid = getgid(); + gid_t egid = getegid(); + if (gid != srgid || egid != segid) { + t_error("%s failed: gid = %d\n", __func__, gid); + t_error("%s failed: egid = %d\n", __func__, egid); + } +} + +int main(int argc, char *argv[]) +{ + setregid_0100(); + setregid_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/setresgid.c b/libc-test/src/functionalext/supplement/unistd/setresgid.c new file mode 100644 index 00000000..d12cf1bd --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/setresgid.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "test.h" + +/** + * @tc.name : setresgid_0100 + * @tc.desc : set real, effective, and saved group ID + * @tc.level : Level 0 + */ +void setresgid_0100(void) +{ + gid_t crgid = 0; + gid_t cegid = 0; + gid_t csgid = 0; + int result = getresgid(&crgid, &cegid, &csgid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + gid_t srgid = 1; + gid_t segid = 2; + gid_t ssgid = 3; + result = setresgid(srgid, segid, ssgid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + gid_t rgid = 0; + gid_t egid = 0; + gid_t sgid = 0; + result = getresgid(&rgid, &egid, &sgid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if ((rgid != srgid) || (egid != segid) || (sgid != ssgid)) { + t_error("%s failed: rgid = %d\n", __func__, rgid); + t_error("%s failed: egid = %d\n", __func__, egid); + t_error("%s failed: sgid = %d\n", __func__, sgid); + } + + result = setresgid(crgid, cegid, csgid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : setresgid_0200 + * @tc.desc : set real, effective, and saved group ID with the current values + * @tc.level : Level 1 + */ +void setresgid_0200(void) +{ + gid_t crgid = 0; + gid_t cegid = 0; + gid_t csgid = 0; + int result = getresgid(&crgid, &cegid, &csgid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + gid_t srgid = crgid; + gid_t segid = crgid; + gid_t ssgid = crgid; + result = setresgid(srgid, segid, ssgid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + gid_t rgid = 0; + gid_t egid = 0; + gid_t sgid = 0; + result = getresgid(&rgid, &egid, &sgid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if ((rgid != srgid) || (egid != segid) || (sgid != ssgid)) { + t_error("%s failed: rgid = %d\n", __func__, rgid); + t_error("%s failed: egid = %d\n", __func__, egid); + t_error("%s failed: sgid = %d\n", __func__, sgid); + } +} + +int main(int argc, char *argv[]) +{ + setresgid_0100(); + setresgid_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/setresuid.c b/libc-test/src/functionalext/supplement/unistd/setresuid.c new file mode 100644 index 00000000..417889fe --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/setresuid.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : setresuid_0100 + * @tc.desc : Test calling setresuid to set the real, effective and saved user or group ID + * @tc.level : Level 0 + */ +void setresuid_0100(void) +{ + uid_t uid = 0; + int result = setresuid(uid, uid, uid); + if (result != 0) { + t_error("%s setresuid error get result is %d are not 0\n", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + setresuid_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/setreuid.c b/libc-test/src/functionalext/supplement/unistd/setreuid.c new file mode 100644 index 00000000..bc77b7d1 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/setreuid.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "test.h" + +/** + * @tc.name : setreuid_0100 + * @tc.desc : set real and/or effective user ID + * @tc.level : Level 0 + */ +void setreuid_0100(void) +{ + uid_t cuid = getuid(); + uid_t ceuid = geteuid(); + + uid_t sruid = 1; + uid_t seuid = 2; + int result = setreuid(sruid, seuid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + uid_t uid = getuid(); + uid_t euid = geteuid(); + if ((uid != sruid) || (euid != seuid)) { + t_error("%s failed: uid = %d\n", __func__, uid); + t_error("%s failed: euid = %d\n", __func__, euid); + } + + result = setreuid(cuid, ceuid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } +} + +/** + * @tc.name : setreuid_0200 + * @tc.desc : set real and/or effective user ID with the current effective user ID + * @tc.level : Level 1 + */ +void setreuid_0200(void) +{ + uid_t cuid = getuid(); + uid_t ceuid = geteuid(); + + uid_t sruid = cuid; + uid_t seuid = ceuid; + int result = setreuid(sruid, seuid); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + uid_t uid = getuid(); + uid_t euid = geteuid(); + if ((uid != sruid) || (euid != seuid)) { + t_error("%s failed: uid = %d\n", __func__, uid); + t_error("%s failed: euid = %d\n", __func__, euid); + } +} + +int main(int argc, char *argv[]) +{ + setreuid_0100(); + setreuid_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/setsid.c b/libc-test/src/functionalext/supplement/unistd/setsid.c new file mode 100644 index 00000000..4d33fe1f --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/setsid.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +/** + * @tc.name : setsid_0100 + * @tc.desc : creates a session and sets the process group ID + * @tc.level : Level 0 + */ +void setsid_0100(void) +{ + pid_t pid = fork(); + if (pid < 0) { + t_error("%s failed: pid = %d\n", __func__, pid); + } else if (pid == 0) { + pid_t result = setsid(); + if (result < 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + pid = getpid(); + if (pid < 0) { + t_error("%s failed: pid = %d\n", __func__, pid); + } + + pid_t sid = getsid(pid); + if (sid < 0) { + t_error("%s failed: sid = %d\n", __func__, sid); + } + + if (result != sid) { + t_error("%s failed: result = %d, sid = %d\n", __func__, result, sid); + } + } else { + return; + } +} + +int main(int argc, char *argv[]) +{ + setsid_0100(); + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/setuid.c b/libc-test/src/functionalext/supplement/unistd/setuid.c new file mode 100644 index 00000000..067673fd --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/setuid.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "test.h" + +/** + * @tc.name : setuid_0100 + * @tc.desc : Call the setuid method to set the process uid + * @tc.level : Level 0 + */ +void setuid_0100(void) +{ + uid_t uid = 0; + int result = setuid(uid); + if (result != 0) { + t_error("%s setuid error get result is %d are not 0\n", __func__, result); + } + if (getuid() != uid) { + t_error("%s setuid failed", __func__); + } +} + +int main(int argc, char *argv[]) +{ + setuid_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/sleep.c b/libc-test/src/functionalext/supplement/unistd/sleep.c new file mode 100644 index 00000000..2a3c69fc --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/sleep.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : sleep_0100 + * @tc.desc : Pause the program for a while with sleep + * @tc.level : Level 0 + */ +void sleep_0100(void) +{ + struct timespec old_time; + clock_gettime(CLOCK_MONOTONIC, &old_time); + int result = sleep(2); + struct timespec new_time; + clock_gettime(CLOCK_MONOTONIC, &new_time); + if (result != 0) { + t_error("%s sleep get result is %d is not 0", __func__, result); + } + long int difference = new_time.tv_sec - old_time.tv_sec - 2000; + if (difference > 2) { + t_error("%s sleep get result is %ld is greater than 2 ms", __func__, difference); + } +} + +int main(int argc, char *argv[]) +{ + sleep_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/symlink.c b/libc-test/src/functionalext/supplement/unistd/symlink.c new file mode 100644 index 00000000..40248c1a --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/symlink.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : symlink_0100 + * @tc.desc : Test the symlink function to create a new file link + * @tc.level : Level 0 + */ +void symlink_0100(void) +{ + char *file_name = "/data/temp.txt"; + char *link_name = "/data/linktemp.txt"; + FILE *f = fopen(file_name, "w"); + fclose(f); + int result = symlink(file_name, link_name); + if (result != 0) { + t_error("%s symlink get result is %d are not 0\n", __func__, result); + } + if (access(link_name, 0) != 0) { + t_error("%s symlink error link not exist\n", __func__); + } + unlink(file_name); + unlink(link_name); +} + +/** + * @tc.name : symlink_0200 + * @tc.desc : old file does not exist + * @tc.level : Level 1 + */ +void symlink_0200(void) +{ + char *file_name = "/data/temp.txt"; + char *link_name = "/data/linktemp.txt"; + int result = symlink(file_name, link_name); + if (result != 0) { + t_error("%s symlink get result is %d are not 0\n", __func__, result); + } + if (access(link_name, 0) == 0) { + t_error("%s symlink error link exist\n", __func__); + } + unlink(link_name); +} + +int main(int argc, char *argv[]) +{ + symlink_0100(); + symlink_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/symlinkat.c b/libc-test/src/functionalext/supplement/unistd/symlinkat.c new file mode 100644 index 00000000..316675d6 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/symlinkat.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : symlinkat_0100 + * @tc.desc : Create a symbolic link to the specified file + * @tc.level : Level 0 + */ +void symlinkat_0100(void) +{ + char buffer[BUFSIZ]; + char *path_name = "/data"; + char *file_name = "/data/symlinkat.txt"; + char *symlink_name = "mysymlinkat"; + ssize_t sz; + DIR *dp; + int fdd, fdf; + + fdf = creat(file_name, O_RDWR | O_CREAT); + if (fdf == -1) { + t_error("%s creat failed", __func__); + } + + dp = opendir(path_name); + if (dp == NULL) { + t_error("%s opendir failed", __func__); + return; + } + + fdd = dirfd(dp); + if (fdd < 0) { + t_error("%s dirfd failed", __func__); + return; + } + + if (symlinkat(file_name, fdd, symlink_name) < 0) { + t_error("%s symlinkat failed", __func__); + return; + } + + memset(buffer, 0, sizeof(buffer)); + sz = readlinkat(fdd, symlink_name, buffer, sizeof(buffer)); + if (sz < 0) { + t_error("%s readlinkat failed", __func__); + return; + } + + if (strcmp(buffer, file_name)) { + t_error("%s buffer is %s, not %s", __func__, buffer, file_name); + } + + unlinkat(fdd, symlink_name, 0); + unlink(file_name); +} + +/** + * @tc.name : symlinkat_0200 + * @tc.desc : The file pointed to by the parameter existing does not exist + * @tc.level : Level 1 + */ +void symlinkat_0200(void) +{ + char buffer[BUFSIZ]; + char *path_name = "/data"; + char *file_name = "/data/symlinkat.txt"; + char *symlink_name = "mysymlinkat"; + ssize_t sz; + DIR *dp; + int fd; + + dp = opendir(path_name); + if (dp == NULL) { + t_error("%s opendir failed", __func__); + return; + } + + fd = dirfd(dp); + if (fd < 0) { + t_error("%s dirfd failed", __func__); + return; + } + + if (symlinkat(file_name, fd, symlink_name) < 0) { + t_error("%s symlinkat failed", __func__); + return; + } + + unlinkat(fd, symlink_name, 0); +} + +int main(int argc, char *argv[]) +{ + symlinkat_0100(); + symlinkat_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/test_src_functionalext_supplement_unistd.gni b/libc-test/src/functionalext/supplement/unistd/test_src_functionalext_supplement_unistd.gni new file mode 100644 index 00000000..98a7fbdd --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/test_src_functionalext_supplement_unistd.gni @@ -0,0 +1,85 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_unistd_test = [ + "gethostname", + "getpgid", + "getsid", + "link", + "linkat", + "lseek", + "nice", + "pread", + "readlinkat", + "readv", + "renameat", + "setdomainname", + "setegid", + "seteuid", + "setgid", + "sethostname", + "setpgid", + "setpgrp", + "setregid", + "setresgid", + "setresuid", + "setreuid", + "setsid", + "sleep", + "symlink", + "symlinkat", + "setuid", + "truncate", + "ttyname_r", + "unlink", + "unlinkat", + "usleep", + "write", + "writev", + "exit", + "getpid", + "alarm", + "fchown", + "fdatasync", + "chown", + "access", + "ftruncate", + "getuid", + "read", + "readlink", + "rmdir", + "dup3", + "ctermid", + "acct", + "faccessat", + "fchownat", + "getlogin", + "getlogin_r", + "getpgrp", + "getppid", + "lchown", + "pause", + "pipe2", + "preadv", + "pwrite", + "pwritev", + "fsync", + "getgid", + "getgroups", + "geteuid", + "getegid", + "getcwd", + "getsockopt", + "exittest01", + "exittest02", +] diff --git a/libc-test/src/functionalext/supplement/unistd/truncate.c b/libc-test/src/functionalext/supplement/unistd/truncate.c new file mode 100644 index 00000000..fada943a --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/truncate.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "test.h" + +const int nlen = -1; +const int vlen = 5; +const char *path = "/data/tests/libc-test/src/file.txt"; +const char *path_n = "/data/tests/libc-test/src/files.txt"; +const char *content = "Hello world!"; + +#define CONTENT_LENGTH (13) + +/** + * @tc.name : truncate_0100 + * @tc.desc : truncate a file to a specified length + * @tc.level : Level 0 + */ +void truncate_0100(void) +{ + FILE *f = fopen(path_n, "a"); + if (f == NULL) { + t_error("%s failed: fopen\n", __func__); + return; + } + fputs(content, f); + fclose(f); + int result = truncate(path_n, 0); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + remove(path_n); +} + +/** + * @tc.name : truncate_0200 + * @tc.desc : truncate a file to a specified length + * @tc.level : Level 1 + */ +void truncate_0200(void) +{ + FILE *f = fopen(path, "a"); + if (f == NULL) { + t_error("%s failed: fopen\n", __func__); + return; + } + + fputs(content, f); + fclose(f); + + int result = truncate(path, vlen); + if (result != 0) { + remove(path); + + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + f = fopen(path, "r"); + if (f == NULL) { + t_error("%s failed: fopen\n", __func__); + return; + } + + char buf[CONTENT_LENGTH] = {0}; + fgets(buf, sizeof(buf) / sizeof(char), f); + fclose(f); + + if (strlen(buf) != vlen) { + remove(path); + + t_error("%s failed: buf = %s\n", __func__, buf); + return; + } +} + +/** + * @tc.name : truncate_0300 + * @tc.desc : truncate a file to a negative length + * @tc.level : Level 2 + */ +void truncate_0300(void) +{ + int result = truncate(path, nlen); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + if (errno != EINVAL) { + t_error("%s failed: errno = %d\n", __func__, errno); + return; + } +} + +/** + * @tc.name : truncate_0400 + * @tc.desc : truncate a directory + * @tc.level : Level 2 + */ +void truncate_0400(void) +{ + int result = truncate("/", 0); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + return; + } + + if (errno != EISDIR) { + t_error("%s failed: errno = %d\n", __func__, errno); + return; + } +} + +int main(int argc, char *argv[]) +{ + truncate_0100(); + truncate_0200(); + truncate_0300(); + truncate_0400(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/ttyname_r.c b/libc-test/src/functionalext/supplement/unistd/ttyname_r.c new file mode 100644 index 00000000..37166798 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/ttyname_r.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : ttyname_r_0100 + * @tc.desc : Call ttyname_r to get the file name through the file handle + * @tc.level : Level 0 + */ +void ttyname_r_0100(void) +{ + int fd = open("/data/tempfile_forttyname.txt", O_CREAT); + char buf[128]; + int want = 25; + int result = ttyname_r(fd, buf, sizeof(buf)); + if (result != want) { + t_error("%s ttyname_r error get result is %d are not want 25\n", __func__, result); + } + close(fd); + unlink("/data/tempfile_forttyname.txt"); +} + +/** + * @tc.name : ttyname_r_0200 + * @tc.desc : Test the ttyname_r result when a non-existing file is passed in + * @tc.level : Level 1 + */ +void ttyname_r_0200(void) +{ + int fd = open("/dev/null", O_WRONLY); + char buf[1]; + int result = ttyname_r(fd, buf, sizeof(buf)); + if (result != errno) { + t_error("%s ttyname_r error get result is %d are not want errno\n", __func__, result); + } + close(fd); +} + +int main(int argc, char *argv[]) +{ + ttyname_r_0100(); + ttyname_r_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/unlink.c b/libc-test/src/functionalext/supplement/unistd/unlink.c new file mode 100644 index 00000000..c1256c4f --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/unlink.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : unlink_0100 + * @tc.desc : Test the timegm result when tm exceeds the limit + * @tc.level : Level 0 + */ +void unlink_0100(void) +{ + int fd = open("/data/tests/libc-test/src/test_unlink.txt", O_CREAT); + int error_code = -1; + if (fd == error_code) { + t_error("%s unlink create file error", __func__); + return; + } + close(fd); + int result = unlink("/data/tests/libc-test/src/test_unlink.txt"); + if (result != 0) { + t_error("%s unlink get result is %d not want 0", __func__, result); + } +} + +/** + * @tc.name : unlink_0200 + * @tc.desc : Test the timegm result when tm exceeds the limit + * @tc.level : Level 1 + */ +void unlink_0200(void) +{ + int result = unlink("/data/tests/libc-test/src/unexist_test_unlink.txt"); + int error_code = -1; + if (result != error_code) { + t_error("%s unlink get result is %d not want -1", __func__, result); + } +} + +int main(int argc, char *argv[]) +{ + unlink_0100(); + unlink_0200(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/unlinkat.c b/libc-test/src/functionalext/supplement/unistd/unlinkat.c new file mode 100644 index 00000000..89ec83a3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/unlinkat.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "test.h" + +const char *path = "/data/tests/libc-test/src/file.txt"; + +/** + * @tc.name : unlinkat_0100 + * @tc.desc : delete a name and possibly the file it refers to + * @tc.level : Level 0 + */ +void unlinkat_0100(void) +{ + int fd = open(path, O_CREAT, 0664); + + int result = unlinkat(fd, path, 0); + if (result != 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + close(fd); +} + +/** + * @tc.name : unlinkat_0200 + * @tc.desc : delete a name and possibly the file it refers to with AT_REMOVEDIR flag + * @tc.level : Level 2 + */ +void unlinkat_0200(void) +{ + errno = 0; + int result = unlinkat(AT_FDCWD, path, AT_REMOVEDIR); + if (result == 0) { + t_error("%s failed: result = %d\n", __func__, result); + } + + if (errno != ENOENT) { + t_error("%s failed: errno = %d\n", __func__, errno); + } +} + +int main(int argc, char *argv[]) +{ + unlinkat_0100(); + unlinkat_0200(); + + return t_status; +} diff --git a/libc-test/src/functionalext/supplement/unistd/usleep.c b/libc-test/src/functionalext/supplement/unistd/usleep.c new file mode 100644 index 00000000..e63eb29f --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/usleep.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test.h" + +/** + * @tc.name : usleep_0100 + * @tc.desc : Pause the program for a while with usleep + * @tc.level : Level 0 + */ +void usleep_0100(void) +{ + struct timespec old_time; + clock_gettime(CLOCK_MONOTONIC, &old_time); + int result = usleep(2000000); + struct timespec new_time; + clock_gettime(CLOCK_MONOTONIC, &new_time); + if (result != 0) { + t_error("%s usleep get result is %d is not 0", __func__, result); + } + long int difference = new_time.tv_sec - old_time.tv_sec - 2000; + if (difference > 2) { + t_error("%s usleep get result is %ld is greater than 2 ms", __func__, difference); + } +} + +int main(int argc, char *argv[]) +{ + usleep_0100(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/write.c b/libc-test/src/functionalext/supplement/unistd/write.c new file mode 100644 index 00000000..315b7e88 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/write.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : write_0100 + * @tc.desc : Test the write function, the return value is the specified buf length + * @tc.level : Level 0 + */ +void write_0100(void) +{ + const char *msg = "This is a c test code for write function"; + const char *path = "/data/tests/libc-test/src/test_write.txt"; + int len = strlen(msg); + char buf[1024] = {0}; + int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); + if (fd == -1) { + t_error("%s write create file error", __func__); + return; + } + int result = write(fd, msg, len); + if (result != len) { + t_error("%s write get result is %d not want %d", __func__, result, len); + } + close(fd); + fd = open(path, O_RDWR); + int bytes = read(fd, buf, len); + if (bytes == -1) { + t_error("%s read file failed", __func__); + return; + } + if (strcmp(msg, buf)) { + t_error("%s wrong string written to file", __func__); + } + close(fd); + remove(path); +} + +/** + * @tc.name : write_0200 + * @tc.desc : test the return value of write when the count parameter is 0 + * @tc.level : Level 1 + */ +void write_0200(void) +{ + const char *msg = "This is a c test code for write function"; + const char *path = "/data/tests/libc-test/src/test_write.txt"; + int len = 0; + int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); + if (fd == -1) { + t_error("%s write create file error", __func__); + return; + } + int result = write(fd, msg, len); + if (result != len) { + t_error("%s write get result is %d not want %d", __func__, result, len); + } + close(fd); + remove(path); +} + +/** + * @tc.name : write_0300 + * @tc.desc : test the return result of write when count is greater than the length of buf + * @tc.level : Level 1 + */ +void write_0300(void) +{ + const char *msg = "This is a c test code for write function"; + const char *path = "/data/tests/libc-test/src/test_write.txt"; + int len = strlen(msg) + 1; + int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); + if (fd == -1) { + t_error("%s write create file error", __func__); + return; + } + int result = write(fd, msg, len); + if (result == -1) { + t_error("%s write get result is %d not want -1", __func__, result); + } + close(fd); + remove(path); +} + +/** + * @tc.name : write_0400 + * @tc.desc : test the return value of write when fd is abnormal + * @tc.level : Level 2 + */ +void write_0400(void) +{ + const char *msg = "This is a c test code for write function"; + const char *path = "/data/tests/libc-test/src/test_write.txt"; + int len = strlen(msg); + int fd = open(path, O_RDWR); + int result = write(fd, msg, len); + if (result != -1) { + t_error("%s write get result is %d not want -1", __func__, result); + } + close(fd); + remove(path); +} + +/** + * @tc.name : write_0500 + * @tc.desc : test the return value of write when buf is NULL + * @tc.level : Level 2 + */ +void write_0500(void) +{ + const char *msg = NULL; + const char *path = "/data/tests/libc-test/src/test_write.txt"; + int len = 1; + int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); + if (fd == -1) { + t_error("%s write create file error", __func__); + return; + } + int result = write(fd, msg, len); + if (result != -1) { + t_error("%s write get result is %d not want -1", __func__, result); + } + close(fd); + remove(path); +} + +int main(int argc, char *argv[]) +{ + write_0100(); + write_0200(); + write_0300(); + write_0400(); + write_0500(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/unistd/writev.c b/libc-test/src/functionalext/supplement/unistd/writev.c new file mode 100644 index 00000000..94cac678 --- /dev/null +++ b/libc-test/src/functionalext/supplement/unistd/writev.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "test.h" + +/** + * @tc.name : writev_0100 + * @tc.desc : Writes iovcnt buffers of data described by iov to the file associated with fd + * @tc.level : Level 0 + */ +void writev_0100(void) +{ + char *str0 = "test "; + char *str1 = "writev\n"; + struct iovec iov[2]; + + iov[0].iov_base = str0; + iov[0].iov_len = strlen(str0) + 1; + iov[1].iov_base = str1; + iov[1].iov_len = strlen(str1) + 1; + + ssize_t result = writev(STDOUT_FILENO, iov, 2); + if (result != (iov[0].iov_len + iov[1].iov_len)) { + t_error("%s writev falied", __func__); + } +} + +/** + * @tc.name : writev_0200 + * @tc.desc : When iovlen is equal to 0, the data in the structure iov will not be read + * @tc.level : Level 1 + */ +void writev_0200(void) +{ + char *str0 = "test "; + char *str1 = "writev\n"; + struct iovec iov[2]; + + iov[0].iov_base = str0; + iov[0].iov_len = 0; + iov[1].iov_base = str1; + iov[1].iov_len = strlen(str1) + 1; + + ssize_t result = writev(STDOUT_FILENO, iov, 2); + if (result != (iov[0].iov_len + iov[1].iov_len)) { + t_error("%s writev falied", __func__); + } +} + +/** + * @tc.name : writev_0300 + * @tc.desc : Invalid parameter input + * @tc.level : Level 2 + */ +void writev_0300(void) +{ + ssize_t result = writev(-1, NULL, -1); + if (result != -1) { + t_error("%s writev should falied", __func__); + } +} + +int main(int argc, char *argv[]) +{ + writev_0100(); + writev_0200(); + writev_0300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/wctype/BUILD.gn b/libc-test/src/functionalext/supplement/wctype/BUILD.gn new file mode 100644 index 00000000..86c7cb7c --- /dev/null +++ b/libc-test/src/functionalext/supplement/wctype/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +import("../../../../test_template.gni") +import("test_src_functionalext_supplement_wctype.gni") + +foreach(s, functionalext_supplement_wctype_test) { + test_unittest(s) { + target_dir = "functionalext/supplement/wctype" + } +} + +group("functionalext_supplement_wctype_test") { + testonly = true + deps = [] + foreach(s, functionalext_supplement_wctype_test) { + deps += [ ":${s}" ] + } +} diff --git a/libc-test/src/functionalext/supplement/wctype/iswalnum_l.c b/libc-test/src/functionalext/supplement/wctype/iswalnum_l.c new file mode 100644 index 00000000..5bf7e797 --- /dev/null +++ b/libc-test/src/functionalext/supplement/wctype/iswalnum_l.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int COUNT = 62; +const int SIZE = 128; + +/** + * @tc.name : iswalnum_l_0100 + * @tc.desc : Verify iswalnum_l process success. The parameter c is an English letter, + * and it is judged that the input character is a letter. + * @tc.level : Level 0 + */ +void iswalnum_l_0100(void) +{ + wchar_t c = 'a'; + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswalnum_l(c, m_locale); + EXPECT_NE("iswalnum_l_0100", ret, 0); +} + +/** + * @tc.name : iswalnum_l_0200 + * @tc.desc : Verify iswalnum_l process success. The parameter c is an English number, + * and it is judged that the input character is a number. + * @tc.level : Level 0 + */ +void iswalnum_l_0200(void) +{ + wchar_t c = '1'; + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswalnum_l('1', m_locale); + EXPECT_NE("iswalnum_l_0200", ret, 0); +} + +/** + * @tc.name : iswalnum_l_0300 + * @tc.desc : Verify iswalnum_l process success. The parameter c is an special character, + * and it is judged that the input character is not a letter or a number. + * @tc.level : Level 2 + */ +void iswalnum_l_0300(void) +{ + wchar_t c = '*'; + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswalnum_l('*', m_locale); + EXPECT_EQ("iswalnum_l_0300", ret, 0); +} + +/** + * @tc.name : iswalnum_l_0400 + * @tc.desc : Verify iswalnum_l process success. Determine the number of letters and numbers in the ascii + * code table. + * @tc.level : Level 1 + */ +void iswalnum_l_0400(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int total = 0; + for (int i = 0; i < SIZE; i++) { + int ret = iswalnum_l((wchar_t)i, m_locale); + if (ret) { + total++; + } + } + EXPECT_EQ("iswalnum_l_0400", total, COUNT); +} + +int main(void) +{ + iswalnum_l_0100(); + iswalnum_l_0200(); + iswalnum_l_0300(); + iswalnum_l_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/wctype/iswctype_l.c b/libc-test/src/functionalext/supplement/wctype/iswctype_l.c new file mode 100644 index 00000000..5401005b --- /dev/null +++ b/libc-test/src/functionalext/supplement/wctype/iswctype_l.c @@ -0,0 +1,247 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "functionalext.h" + +const int COUNT = 62; + +/** + * @tc.name : iswctype_l_0100 + * @tc.desc : Verify iswctype_l process success. The parameter c is a WCTYPE_ALNUM, + * and it is judged that the input character is a WCTYPE_ALNUM. + * @tc.level : Level 0 + */ +void iswctype_l_0100(void) +{ + wchar_t c = L'0'; + wctype_t wt = wctype("alnum"); + EXPECT_NE("iswctype_l_0100", wt, -1); + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswctype_l(c, wt, m_locale); + EXPECT_NE("iswctype_l_0100", ret, 0); +} + +/** + * @tc.name : iswctype_l_0200 + * @tc.desc : Verify iswctype_l process success. The parameter c is a WCTYPE_ALPHA, + * and it is judged that the input character is a WCTYPE_ALPHA. + * @tc.level : Level 0 + */ +void iswctype_l_0200(void) +{ + wchar_t c = L'a'; + wctype_t wt = wctype("alpha"); + EXPECT_NE("iswctype_l_0200", wt, -1); + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswctype_l(c, wt, m_locale); + EXPECT_NE("iswctype_l_0200", ret, 0); +} + +/** + * @tc.name : iswctype_l_0300 + * @tc.desc : Verify iswctype_l process success. The parameter c is a WCTYPE_BLANK, + * and it is judged that the input character is a WCTYPE_BLANK. + * @tc.level : Level 0 + */ +void iswctype_l_0300(void) +{ + wchar_t c = L' '; + wctype_t wt = wctype("blank"); + EXPECT_NE("iswctype_l_0300", wt, -1); + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswctype_l(c, wt, m_locale); + EXPECT_NE("iswctype_l_0300", ret, 0); +} + +/** + * @tc.name : iswctype_l_0400 + * @tc.desc : Verify iswctype_l process success. The parameter c is a WCTYPE_CNTRL, + * and it is judged that the input character is a WCTYPE_CNTRL. + * @tc.level : Level 0 + */ +void iswctype_l_0400(void) +{ + wchar_t c = L'\n'; + wctype_t wt = wctype("cntrl"); + EXPECT_NE("iswctype_l_0400", wt, -1); + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswctype_l(c, wt, m_locale); + EXPECT_NE("iswctype_l_0400", ret, 0); +} + +/** + * @tc.name : iswctype_l_0500 + * @tc.desc : Verify iswctype_l process success. The parameter c is a WCTYPE_DIGIT, + * and it is judged that the input character is a WCTYPE_DIGIT. + * @tc.level : Level 0 + */ +void iswctype_l_0500(void) +{ + wchar_t c = L'1'; + wctype_t wt = wctype("digit"); + EXPECT_NE("iswctype_l_0500", wt, -1); + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswctype_l(c, wt, m_locale); + EXPECT_NE("iswctype_l_0500", ret, 0); +} + +/** + * @tc.name : iswctype_l_0600 + * @tc.desc : Verify iswctype_l process success. The parameter c is a WCTYPE_GRAPH, + * and it is judged that the input character is a WCTYPE_GRAPH. + * @tc.level : Level 0 + */ +void iswctype_l_0600(void) +{ + wchar_t c = L'!'; + wctype_t wt = wctype("graph"); + EXPECT_NE("iswctype_l_0600", wt, -1); + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswctype_l(c, wt, m_locale); + EXPECT_NE("iswctype_l_0600", ret, 0); +} + +/** + * @tc.name : iswctype_l_0700 + * @tc.desc : Verify iswctype_l process success. The parameter c is a WCTYPE_LOWER, + * and it is judged that the input character is a WCTYPE_LOWER. + * @tc.level : Level 0 + */ +void iswctype_l_0700(void) +{ + wchar_t c = L'z'; + wctype_t wt = wctype("lower"); + EXPECT_NE("iswctype_l_0700", wt, -1); + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswctype_l(c, wt, m_locale); + EXPECT_NE("iswctype_l_0700", ret, 0); +} + +/** + * @tc.name : iswctype_l_0800 + * @tc.desc : Verify iswctype_l process success. The parameter c is a WCTYPE_PRINT, + * and it is judged that the input character is a WCTYPE_PRINT. + * @tc.level : Level 0 + */ +void iswctype_l_0800(void) +{ + wchar_t c = L'p'; + wctype_t wt = wctype("print"); + EXPECT_NE("iswctype_l_0800", wt, -1); + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswctype_l(c, wt, m_locale); + EXPECT_NE("iswctype_l_0800", ret, 0); +} + +/** + * @tc.name : iswctype_l_0900 + * @tc.desc : Verify iswctype_l process success. The parameter c is a WCTYPE_PUNCT, + * and it is judged that the input character is a WCTYPE_PUNCT. + * @tc.level : Level 0 + */ +void iswctype_l_0900(void) +{ + wchar_t c = L'/'; + wctype_t wt = wctype("punct"); + EXPECT_NE("iswctype_l_0900", wt, -1); + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswctype_l(c, wt, m_locale); + EXPECT_NE("iswctype_l_0900", ret, 0); +} + +/** + * @tc.name : iswctype_l_1000 + * @tc.desc : Verify iswctype_l process success. The parameter c is a WCTYPE_SPACE, + * and it is judged that the input character is a WCTYPE_SPACE. + * @tc.level : Level 0 + */ +void iswctype_l_1000(void) +{ + wchar_t c = L'\n'; + wctype_t wt = wctype("space"); + EXPECT_NE("iswctype_l_1000", wt, -1); + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswctype_l(c, wt, m_locale); + EXPECT_NE("iswctype_l_1000", ret, 0); +} + +/** + * @tc.name : iswctype_l_1100 + * @tc.desc : Verify iswctype_l process success. The parameter c is a WCTYPE_UPPER, + * and it is judged that the input character is a WCTYPE_UPPER. + * @tc.level : Level 0 + */ +void iswctype_l_1100(void) +{ + wchar_t c = L'A'; + wctype_t wt = wctype("upper"); + EXPECT_NE("iswctype_l_1100", wt, -1); + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswctype_l(c, wt, m_locale); + EXPECT_NE("iswctype_l_1100", ret, 0); +} + +/** + * @tc.name : iswctype_l_1200 + * @tc.desc : Verify iswctype_l process success. The parameter c is a WCTYPE_XDIGIT, + * and it is judged that the input character is a WCTYPE_XDIGIT. + * @tc.level : Level 0 + */ +void iswctype_l_1200(void) +{ + wchar_t c = L'd'; + wctype_t wt = wctype("xdigit"); + EXPECT_NE("iswctype_l_1200", wt, -1); + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswctype_l(c, wt, m_locale); + EXPECT_NE("iswctype_l_1200", ret, 0); +} + +/** + * @tc.name : iswctype_l_1300 + * @tc.desc : Verify iswctype_l process success. The parameter c is a error type, + * and it is judged that the input character is a error type. + * @tc.level : Level 2 + */ +void iswctype_l_1300(void) +{ + wchar_t c = L'【'; + wctype_t wt = wctype("xdigit"); + EXPECT_NE("iswctype_l_1300", wt, -1); + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswctype_l(c, wt, m_locale); + EXPECT_EQ("iswctype_l_1300", ret, 0); +} + +int main(void) +{ + iswctype_l_0100(); + iswctype_l_0200(); + iswctype_l_0300(); + iswctype_l_0400(); + iswctype_l_0500(); + iswctype_l_0600(); + iswctype_l_0700(); + iswctype_l_0800(); + iswctype_l_0900(); + iswctype_l_1000(); + iswctype_l_1100(); + iswctype_l_1200(); + iswctype_l_1300(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/wctype/iswgraph.c b/libc-test/src/functionalext/supplement/wctype/iswgraph.c new file mode 100644 index 00000000..b420b7fb --- /dev/null +++ b/libc-test/src/functionalext/supplement/wctype/iswgraph.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int COUNT = 94; +const int SIZE = 128; + +/* + * @tc.name : iswgraph_0100 + * @tc.desc : Verify iswgraph process success. When that the entered character is a letter (parameter is 'a' + * has a graphical representation). + * @tc.level : Level 0 + */ +void iswgraph_0100(void) +{ + wchar_t c = 'a'; + int ret = iswgraph(c); + EXPECT_NE("iswgraph_0100", ret, 0); +} + +/* + * @tc.name : iswgraph_0200 + * @tc.desc : Verify iswgraph process success. When that the entered character is not a letter (parameter is '!' + * has a graphical representation). + * @tc.level : Level 0 + */ +void iswgraph_0200(void) +{ + wchar_t c = '!'; + int ret = iswgraph(c); + EXPECT_NE("iswgraph_0200", ret, 0); +} + +/* + * @tc.name : iswgraph_0300 + * @tc.desc : Verify iswgraph process success. When that the entered character is not has a graphical representation. + * @tc.level : Level 2 + */ +void iswgraph_0300(void) +{ + wchar_t c = ' '; + int ret = iswgraph(c); + EXPECT_EQ("iswgraph_0300", ret, 0); +} + +/** + * @tc.name : iswgraph_0400 + * @tc.desc : Verify iswgraph process success. Determine the number of control characters in the ascii code table. + * @tc.level : Level 1 + */ +void iswgraph_0400(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int total = 0; + for (int i = 0; i < SIZE; i++) { + int ret = iswgraph((wchar_t)i); + if (ret) { + total++; + } + } + EXPECT_EQ("iswgraph_0400", total, COUNT); +} + +int main(void) +{ + iswgraph_0100(); + iswgraph_0200(); + iswgraph_0300(); + iswgraph_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/wctype/iswgraph_l.c b/libc-test/src/functionalext/supplement/wctype/iswgraph_l.c new file mode 100644 index 00000000..45200339 --- /dev/null +++ b/libc-test/src/functionalext/supplement/wctype/iswgraph_l.c @@ -0,0 +1,92 @@ + +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "functionalext.h" + +const int COUNT = 94; +const int SIZE = 128; + +/* + * @tc.name : iswgraph_l_0100 + * @tc.desc : Verify iswgraph_l process success. When that the entered character is a letter (parameter is 'a' + * has a graphical representation). + * @tc.level : Level 0 + */ +void iswgraph_l_0100(void) +{ + wchar_t c = 'a'; + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswgraph_l(c, m_locale); + EXPECT_NE("iswgraph_l_0100", ret, 0); +} + +/* + * @tc.name : iswgraph_l_0200 + * @tc.desc : Verify iswgraph_l process success. When that the entered character is not a letter (parameter is '!' + * has a graphical representation). + * @tc.level : Level 2 + */ +void iswgraph_l_0200(void) +{ + wchar_t c = '!'; + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswgraph_l(c, m_locale); + EXPECT_NE("iswgraph_l_0200", ret, 0); +} + +/* + * @tc.name : iswgraph_l_0300 + * @tc.desc : Verify iswgraph_l process success. When that the entered character is not has a graphical representation. + * @tc.level : Level 2 + */ +void iswgraph_l_0300(void) +{ + wchar_t c = ' '; + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int ret = iswgraph_l(c, m_locale); + EXPECT_EQ("iswgraph_l_0300", ret, 0); +} + +/** + * @tc.name : iswgraph_l_0400 + * @tc.desc : Verify iswgraph_l process success. Determine the number of control characters in the ascii code table. + * @tc.level : Level 1 + */ +void iswgraph_l_0400(void) +{ + locale_t m_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", NULL); + int total = 0; + for (int i = 0; i < SIZE; i++) { + int ret = iswgraph_l((wchar_t)i, m_locale); + if (ret) { + total++; + } + } + EXPECT_EQ("iswgraph_l_0400", total, COUNT); +} + +int main() +{ + iswgraph_l_0100(); + iswgraph_l_0200(); + iswgraph_l_0300(); + iswgraph_l_0400(); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/wctype/test_src_functionalext_supplement_wctype.gni b/libc-test/src/functionalext/supplement/wctype/test_src_functionalext_supplement_wctype.gni new file mode 100644 index 00000000..c7bacbe3 --- /dev/null +++ b/libc-test/src/functionalext/supplement/wctype/test_src_functionalext_supplement_wctype.gni @@ -0,0 +1,19 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 +# +# 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. + +functionalext_supplement_wctype_test = [ + "iswalnum_l", + "iswctype_l", + "iswgraph", + "iswgraph_l", +] diff --git a/libc-test/src/functionalext/test_src_functionalext.gni b/libc-test/src/functionalext/test_src_functionalext.gni index 4d9a2373..e6080d85 100644 --- a/libc-test/src/functionalext/test_src_functionalext.gni +++ b/libc-test/src/functionalext/test_src_functionalext.gni @@ -22,6 +22,7 @@ functionalext_list = [ "info:functionalext_info_test", "ldso_randomization:functionalext_ldso_randomization_test", "relro:functionalext_relro_test", + "supplement:functionalext_supplement_test", "fortify:functionalext_fortify_test", "symver:functionalext_symver_test", ] diff --git a/libc-test/test_template.gni b/libc-test/test_template.gni index e1320d44..f5bf7067 100644 --- a/libc-test/test_template.gni +++ b/libc-test/test_template.gni @@ -30,11 +30,17 @@ template("test_unittest") { target("ohos_unittest", "${target_name}") { module_out_path = "libc-test/src/${target_dir}" + if (target_cpu == "arm64") { + defines = [ "_ARM64_" ] + } + sources = [ "${target_name}.c" ] include_dirs = [ "//${test_dir}/src/common", "//${musl_include_dir}", "//${test_dir}/src/functionalext/common", + "//${musl_base_dir}/include/arpa", + "//${musl_base_dir}/src/process", ] cflags = [] diff --git a/scripts/runtest.sh b/scripts/runtest.sh index 88dce0f4..4184cdc3 100755 --- a/scripts/runtest.sh +++ b/scripts/runtest.sh @@ -1,6 +1,6 @@ cd /data/tests/libc-test -rm src/REPORT +rm src/REPORT touch src/REPORT function FileSuffix() { @@ -10,28 +10,58 @@ function FileSuffix() { fi } +#Test cases that need to be shielded +ShieldedList=("trace_stresstest" "fatal_message" "tgkill" "exittest01" "exittest02" +"syslog" "vsyslog" "ldso_randomization_manual" "ldso_randomization_test" "dlopen_ext_relro_test") + +function ShieldedCases() { + for filename in ${ShieldedList[*]} + do + if [ "$1" = "$filename" ]; + then + echo "ShieldedCases" + fi + done +} + for dir in src/* do if [ -d $dir ]; then - if [ "$dir" = "src/functionalext" ] + if [ "$dir" = "src/functionalext" ] then # continue for subdir in $dir/* do - for file in `ls $subdir` - do - if [ "$(FileSuffix ${file})" = "so" ] \ - || [ "$file" = "trace_stresstest" ] \ - || [ "$file" = "fatal_message" ] \ - || [ "$file" = "tgkill" ] \ - || [ -d ./$subdir/$file ] - then - continue - else - # echo file=$subdir/$file - src/common/runtest -w '' ./$subdir/$file >> src/REPORT - fi - done + if [ "$subdir" = "src/functionalext/supplement" ] + then + for supplementsubdir in $subdir/* + do + for subfile in `ls $supplementsubdir` + do + if [ "$(FileSuffix ${subfile})" = "so" ] \ + || [ "$(ShieldedCases ${subfile})" = "ShieldedCases" ] \ + || [ -d ./$supplementsubdir/$subfile ] + then + continue + else + src/common/runtest -w '' ./$supplementsubdir/$subfile >> src/REPORT + fi + done + done + else + for file in `ls $subdir` + do + if [ "$(FileSuffix ${file})" = "so" ] \ + || [ "$(ShieldedCases ${file})" = "ShieldedCases" ] \ + || [ -d ./$subdir/$file ] + then + continue + else + # echo file=$subdir/$file + src/common/runtest -w '' ./$subdir/$file >> src/REPORT + fi + done + fi done else # continue @@ -39,7 +69,7 @@ do do if [ "$file" = "runtest" ] \ || [ "$(FileSuffix ${file})" = "so" ] \ - || [ -d $file ] + || [ -d $file ] then continue else diff --git a/scripts/runtest_Windows.bat b/scripts/runtest_Windows.bat index 472f623e..7bd45e83 100644 --- a/scripts/runtest_Windows.bat +++ b/scripts/runtest_Windows.bat @@ -51,6 +51,27 @@ for /D %%i in (%TESTDIR%\*) do ( for /D %%j in (%%i\*) do ( echo [MKdir] %REMOTE%/%%~ni/%%~nj hdc shell mkdir %REMOTE%/%%~ni/%%~nj + @REM Check local subdirectory + for /D %%m in (%%j\*) do ( + echo [MKdir] %REMOTE%/%%~ni/%%~nj/%%~nm + hdc shell mkdir %REMOTE%/%%~ni/%%~nj/%%~nm + @REM Check local subdirectory + for /D %%p in (%%m\*) do ( + echo [MKdir] %REMOTE%/%%~ni/%%~nj/%%~nm/%%~np + hdc shell mkdir %REMOTE%/%%~ni/%%~nj/%%~nm/%%~np + @REM Send test cases to remote subdirectory + for %%q in (%%~p\*) do ( + echo Sending %%q %REMOTE%/%%~ni/%%~nj/%%~nm/%%~np + hdc file send %%q %REMOTE%/%%~ni/%%~nj/%%~nm/%%~np + ) + ) + @REM Send test cases to remote subdirectory + for %%o in (%%~m\*) do ( + echo Sending %%o %REMOTE%/%%~ni/%%~nj/%%~nm + hdc file send %%o %REMOTE%/%%~ni/%%~nj/%%~nm + ) + hdc shell chmod +x %REMOTE%/%%~ni/%%~nj/%%~nm/* + ) @REM Send test cases to remote subdirectory for %%k in (%%~j\*) do ( echo Sending %%k %REMOTE%/%%~ni/%%~nj @@ -92,9 +113,13 @@ hdc file send %DYNLIB%\libldso_randomization_dep_e.so %REMOTEFEXT%/ldso_randomiz hdc file send %DYNLIB%\libdlopen_ext_relro_dso.so %REMOTEFEXT%/relro/libdlopen_ext_relro_dso.so @REM 构造测试所需环境 +hdc shell mkdir %REMOTE%/functionalext/dlns/A hdc shell mkdir %REMOTE%/functionalext/dlns/B hdc shell mkdir %REMOTE%/functionalext/dlns/C hdc shell mkdir %REMOTE%/functionalext/dlns/D +hdc file send %DYNLIB%\libdlns_dlsym_dep_a.so %REMOTEFEXT%/dlns/A/libdlns_dlsym_dep_a.so +hdc file send %DYNLIB%\libdlns_dlsym_dep_b.so %REMOTEFEXT%/dlns/B/libdlns_dlsym_dep_b.so +hdc file send %DYNLIB%\libdlns_dlsym_dep_c.so %REMOTEFEXT%/dlns/C/libdlns_dlsym_dep_c.so hdc shell cp %REMOTEFEXT%/dlns/libdlopen_ns_dso.so %REMOTEFEXT%/dlns/sharedlibtest.so hdc shell cp %REMOTEFEXT%/dlns/libdlopen_ns_dso.so %REMOTEFEXT%/dlns/B/libB.so hdc shell cp %REMOTEFEXT%/dlns/libdlopen_ns_dso.so %REMOTEFEXT%/dlns/C/libC.so @@ -169,13 +194,13 @@ set /a endM=%time:~3,2% set /a diffS_=%endS%-%startS% set /a diffM_=%endM%-%startM% -@REM REPORT文件比较 +@REM REPORT文件比较 start python %LOCAL%\third_party\musl\scripts\compare.py if exist "%LOCAL%\third_party\musl\scripts\\result.html" ( echo Test failed,please checking result.html! ) else ( echo Test successful! -) +) echo file compareing finished echo All items finished. -- GitLab