From 8b23ffca0d7e7c247f2bbac7a31de3bf01c3d605 Mon Sep 17 00:00:00 2001 From: guanzehui Date: Wed, 14 Apr 2021 11:01:36 +0800 Subject: [PATCH] Description: opensource check,modify posix and unittest,add unit fuzz test case Team: OTHERS Feature or Bugfix:Feature Binary Source:No PrivateCode(Yes/No):No Change-Id: Ia95966e595109db01440cffa062cf3aff4faa3b8 ChangeID:13651229 --- kal/posix/include/wchar.h | 1 + kal/posix/musl_src/internal/atomic.h | 318 +++++++++++++++++ kal/posix/musl_src/internal/libc.h | 19 + kal/posix/musl_src/internal/locale_impl.h | 7 +- kal/posix/musl_src/internal/pthread_impl.h | 136 ++++++++ kal/posix/musl_src/internal/stdio_impl.h | 1 + kal/posix/musl_src/locale/__lctrans.c | 19 + kal/posix/musl_src/locale/c_locale.c | 15 + kal/posix/musl_src/locale/langinfo.c | 73 ++++ kal/posix/musl_src/time/__month_to_secs.c | 10 + kal/posix/musl_src/time/__tm_to_secs.c | 24 ++ kal/posix/musl_src/time/__tz.c | 234 +++++++++++++ kal/posix/musl_src/time/__year_to_secs.c | 47 +++ kal/posix/musl_src/time/strftime.c | 18 +- kal/posix/musl_src/time/time_impl.h | 2 +- .../unittest/fuzz/src/ctype/isdigit_fuzz.c | 68 ++++ .../unittest/fuzz/src/ctype/islower_fuzz.c | 68 ++++ .../unittest/fuzz/src/ctype/isxdigit_fuzz.c | 68 ++++ .../fuzz/src/ctype/test_isalnum_fuzz.c | 67 ++++ .../fuzz/src/ctype/test_isascii_fuzz.c | 67 ++++ .../fuzz/src/ctype/test_isprint_fuzz.c | 67 ++++ .../fuzz/src/ctype/test_isspace_fuzz.c | 67 ++++ .../fuzz/src/ctype/test_isupper_fuzz.c | 67 ++++ .../unittest/fuzz/src/ctype/tolower_fuzz.c | 67 ++++ .../unittest/fuzz/src/ctype/toupper_fuzz.c | 68 ++++ testsuits/unittest/fuzz/src/fuzz_posix.c | 94 +++++ testsuits/unittest/fuzz/src/fuzz_posix.h | 109 ++++++ .../unittest/fuzz/src/libgen/dirname_fuzz.c | 73 ++++ testsuits/unittest/fuzz/src/math/log_fuzz.c | 70 ++++ testsuits/unittest/fuzz/src/math/pow_fuzz.c | 71 ++++ testsuits/unittest/fuzz/src/math/round_fuzz.c | 70 ++++ testsuits/unittest/fuzz/src/math/sqrt_fuzz.c | 70 ++++ .../fuzz/src/regex/it_test_regex_fuzz.c | 109 ++++++ .../fuzz/src/semaphore/sem_timedwait_fuzz.c | 88 +++++ testsuits/unittest/fuzz/src/socket/net_fuzz.c | 330 ++++++++++++++++++ .../fuzz/src/stdarg/test_stdarg_fuzz.c | 100 ++++++ .../unittest/fuzz/src/stdio/clearerr_fuzz.c | 78 +++++ testsuits/unittest/fuzz/src/stdio/feof_fuzz.c | 82 +++++ .../unittest/fuzz/src/stdio/perror_fuzz.c | 71 ++++ testsuits/unittest/fuzz/src/stdlib/abs_fuzz.c | 70 ++++ .../unittest/fuzz/src/stdlib/atoi_fuzz.c | 71 ++++ .../unittest/fuzz/src/stdlib/atol_fuzz.c | 71 ++++ .../unittest/fuzz/src/stdlib/atoll_fuzz.c | 70 ++++ .../unittest/fuzz/src/stdlib/realloc_fuzz.c | 84 +++++ .../unittest/fuzz/src/stdlib/strtol_fuzz.c | 81 +++++ .../unittest/fuzz/src/stdlib/strtoul_fuzz.c | 81 +++++ .../unittest/fuzz/src/stdlib/strtoull_fuzz.c | 81 +++++ .../unittest/fuzz/src/string/memcmp_fuzz.c | 73 ++++ .../unittest/fuzz/src/string/memcpy_fuzz.c | 68 ++++ .../unittest/fuzz/src/string/memset_fuzz.c | 77 ++++ .../unittest/fuzz/src/string/strchr_fuzz.c | 74 ++++ .../unittest/fuzz/src/string/strcmp_fuzz.c | 73 ++++ .../unittest/fuzz/src/string/strcspn_fuzz.c | 73 ++++ .../unittest/fuzz/src/string/strdup_fuzz.c | 75 ++++ .../unittest/fuzz/src/string/strerror_fuzz.c | 68 ++++ .../unittest/fuzz/src/string/strstr_fuzz.c | 73 ++++ .../fuzz/src/string/test_strlen_fuzz.c | 72 ++++ .../fuzz/src/string/test_strncmp_fuzz.c | 74 ++++ .../fuzz/src/string/test_strrchr_fuzz.c | 74 ++++ .../fuzz/src/strings/it_test_strings_fuzz.c | 79 +++++ .../fuzz/src/strings/test_strncasecmp_fuzz.c | 74 ++++ .../fuzz/src/sys/time/gettimeofday_fuzz.c | 72 ++++ .../unittest/fuzz/src/sys/times/times_fuzz.c | 68 ++++ .../unittest/fuzz/src/time/gmtime_fuzz.c | 69 ++++ .../unittest/fuzz/src/time/localtime_fuzz.c | 69 ++++ .../unittest/fuzz/src/time/localtime_r_fuzz.c | 70 ++++ .../unittest/fuzz/src/time/mktime_fuzz.c | 83 +++++ .../unittest/fuzz/src/time/strftime_fuzz.c | 84 +++++ .../unittest/fuzz/src/time/strptime_fuzz.c | 71 ++++ testsuits/unittest/fuzz/src/time/time_fuzz.c | 67 ++++ .../unittest/fuzz/src/unistd/usleep_fuzz.c | 71 ++++ .../posix/src/ctype/ctype_func_test.c | 50 +-- .../unittest/posix/src/ctype/isdigit_test.c | 22 +- .../unittest/posix/src/ctype/islower_test.c | 26 +- .../unittest/posix/src/ctype/isxdigit_test.c | 56 +-- .../unittest/posix/src/ctype/tolower_test.c | 22 +- .../unittest/posix/src/ctype/toupper_test.c | 22 +- .../unittest/posix/src/errno/strerror_test.c | 18 +- .../posix/src/fs/posix_fs_func_test.c | 158 +++++++++ testsuits/unittest/posix/src/log.h | 9 +- .../unittest/posix/src/math/math_func_test.c | 58 ++- .../posix/src/regex/regex_func_test.c | 24 +- .../posix/src/semaphore/semaphore_func_test.c | 20 +- .../unittest/posix/src/stdlib/atoi_test.c | 42 +-- .../unittest/posix/src/stdlib/atol_test.c | 38 +- .../unittest/posix/src/stdlib/atoll_test.c | 44 +-- .../unittest/posix/src/stdlib/strtol_test.c | 54 +-- .../unittest/posix/src/stdlib/strtoul_test.c | 46 +-- .../unittest/posix/src/stdlib/strtoull_test.c | 48 +-- .../posix/src/string/memory_func_test.c | 24 +- .../unittest/posix/src/string/strchr_test.c | 26 +- .../posix/src/string/string_func_test_02.c | 16 +- .../posix/src/string/string_func_test_03.c | 8 +- .../unittest/posix/src/string/strstr_test.c | 54 +-- .../posix/src/time/time_func_test_01.c | 228 +++++------- 95 files changed, 5972 insertions(+), 514 deletions(-) create mode 100644 kal/posix/musl_src/internal/atomic.h create mode 100644 kal/posix/musl_src/internal/libc.h create mode 100644 kal/posix/musl_src/internal/pthread_impl.h create mode 100644 kal/posix/musl_src/locale/__lctrans.c create mode 100644 kal/posix/musl_src/locale/c_locale.c create mode 100644 kal/posix/musl_src/locale/langinfo.c create mode 100644 kal/posix/musl_src/time/__month_to_secs.c create mode 100644 kal/posix/musl_src/time/__tm_to_secs.c create mode 100644 kal/posix/musl_src/time/__tz.c create mode 100644 kal/posix/musl_src/time/__year_to_secs.c create mode 100644 testsuits/unittest/fuzz/src/ctype/isdigit_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/ctype/islower_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/ctype/isxdigit_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/ctype/test_isalnum_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/ctype/test_isascii_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/ctype/test_isprint_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/ctype/test_isspace_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/ctype/test_isupper_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/ctype/tolower_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/ctype/toupper_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/fuzz_posix.c create mode 100644 testsuits/unittest/fuzz/src/fuzz_posix.h create mode 100644 testsuits/unittest/fuzz/src/libgen/dirname_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/math/log_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/math/pow_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/math/round_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/math/sqrt_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/regex/it_test_regex_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/semaphore/sem_timedwait_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/socket/net_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/stdarg/test_stdarg_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/stdio/clearerr_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/stdio/feof_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/stdio/perror_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/stdlib/abs_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/stdlib/atoi_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/stdlib/atol_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/stdlib/atoll_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/stdlib/realloc_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/stdlib/strtol_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/stdlib/strtoul_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/stdlib/strtoull_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/string/memcmp_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/string/memcpy_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/string/memset_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/string/strchr_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/string/strcmp_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/string/strcspn_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/string/strdup_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/string/strerror_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/string/strstr_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/string/test_strlen_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/string/test_strncmp_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/string/test_strrchr_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/strings/it_test_strings_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/strings/test_strncasecmp_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/sys/time/gettimeofday_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/sys/times/times_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/time/gmtime_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/time/localtime_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/time/localtime_r_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/time/mktime_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/time/strftime_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/time/strptime_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/time/time_fuzz.c create mode 100644 testsuits/unittest/fuzz/src/unistd/usleep_fuzz.c create mode 100644 testsuits/unittest/posix/src/fs/posix_fs_func_test.c diff --git a/kal/posix/include/wchar.h b/kal/posix/include/wchar.h index 6369f116..d542bddb 100644 --- a/kal/posix/include/wchar.h +++ b/kal/posix/include/wchar.h @@ -17,6 +17,7 @@ extern "C" { #define __NEED_wchar_t #define __NEED_wint_t #define __NEED_mbstate_t +#define __NEED_off_t #if __STDC_VERSION__ < 201112L #define __NEED_struct__IO_FILE diff --git a/kal/posix/musl_src/internal/atomic.h b/kal/posix/musl_src/internal/atomic.h new file mode 100644 index 00000000..f938879b --- /dev/null +++ b/kal/posix/musl_src/internal/atomic.h @@ -0,0 +1,318 @@ +#ifndef _ATOMIC_H +#define _ATOMIC_H + +#include + +#include "atomic_arch.h" + +#ifdef a_ll + +#ifndef a_pre_llsc +#define a_pre_llsc() +#endif + +#ifndef a_post_llsc +#define a_post_llsc() +#endif + +#ifndef a_cas +#define a_cas a_cas +static inline int a_cas(volatile int *p, int t, int s) +{ + int old; + a_pre_llsc(); + do old = a_ll(p); + while (old==t && !a_sc(p, s)); + a_post_llsc(); + return old; +} +#endif + +#ifndef a_swap +#define a_swap a_swap +static inline int a_swap(volatile int *p, int v) +{ + int old; + a_pre_llsc(); + do old = a_ll(p); + while (!a_sc(p, v)); + a_post_llsc(); + return old; +} +#endif + +#ifndef a_fetch_add +#define a_fetch_add a_fetch_add +static inline int a_fetch_add(volatile int *p, int v) +{ + int old; + a_pre_llsc(); + do old = a_ll(p); + while (!a_sc(p, (unsigned)old + v)); + a_post_llsc(); + return old; +} +#endif + +#ifndef a_fetch_and +#define a_fetch_and a_fetch_and +static inline int a_fetch_and(volatile int *p, int v) +{ + int old; + a_pre_llsc(); + do old = a_ll(p); + while (!a_sc(p, old & v)); + a_post_llsc(); + return old; +} +#endif + +#ifndef a_fetch_or +#define a_fetch_or a_fetch_or +static inline int a_fetch_or(volatile int *p, int v) +{ + int old; + a_pre_llsc(); + do old = a_ll(p); + while (!a_sc(p, old | v)); + a_post_llsc(); + return old; +} +#endif + +#endif + +#ifdef a_ll_p + +#ifndef a_cas_p +#define a_cas_p a_cas_p +static inline void *a_cas_p(volatile void *p, void *t, void *s) +{ + void *old; + a_pre_llsc(); + do old = a_ll_p(p); + while (old==t && !a_sc_p(p, s)); + a_post_llsc(); + return old; +} +#endif + +#endif + +#ifndef a_cas +#error missing definition of a_cas +#endif + +#ifndef a_swap +#define a_swap a_swap +static inline int a_swap(volatile int *p, int v) +{ + int old; + do old = *p; + while (a_cas(p, old, v) != old); + return old; +} +#endif + +#ifndef a_fetch_add +#define a_fetch_add a_fetch_add +static inline int a_fetch_add(volatile int *p, int v) +{ + int old; + do old = *p; + while (a_cas(p, old, (unsigned)old+v) != old); + return old; +} +#endif + +#ifndef a_fetch_and +#define a_fetch_and a_fetch_and +static inline int a_fetch_and(volatile int *p, int v) +{ + int old; + do old = *p; + while (a_cas(p, old, old&v) != old); + return old; +} +#endif +#ifndef a_fetch_or +#define a_fetch_or a_fetch_or +static inline int a_fetch_or(volatile int *p, int v) +{ + int old; + do old = *p; + while (a_cas(p, old, old|v) != old); + return old; +} +#endif + +#ifndef a_and +#define a_and a_and +static inline void a_and(volatile int *p, int v) +{ + a_fetch_and(p, v); +} +#endif + +#ifndef a_or +#define a_or a_or +static inline void a_or(volatile int *p, int v) +{ + a_fetch_or(p, v); +} +#endif + +#ifndef a_inc +#define a_inc a_inc +static inline void a_inc(volatile int *p) +{ + a_fetch_add(p, 1); +} +#endif + +#ifndef a_dec +#define a_dec a_dec +static inline void a_dec(volatile int *p) +{ + a_fetch_add(p, -1); +} +#endif + +#ifndef a_store +#define a_store a_store +static inline void a_store(volatile int *p, int v) +{ +#ifdef a_barrier + a_barrier(); + *p = v; + a_barrier(); +#else + a_swap(p, v); +#endif +} +#endif + +#ifndef a_barrier +#define a_barrier a_barrier +static void a_barrier() +{ + volatile int tmp = 0; + a_cas(&tmp, 0, 0); +} +#endif + +#ifndef a_spin +#define a_spin a_barrier +#endif + +#ifndef a_and_64 +#define a_and_64 a_and_64 +static inline void a_and_64(volatile uint64_t *p, uint64_t v) +{ + union { uint64_t v; uint32_t r[2]; } u = { v }; + if (u.r[0]+1) a_and((int *)p, u.r[0]); + if (u.r[1]+1) a_and((int *)p+1, u.r[1]); +} +#endif + +#ifndef a_or_64 +#define a_or_64 a_or_64 +static inline void a_or_64(volatile uint64_t *p, uint64_t v) +{ + union { uint64_t v; uint32_t r[2]; } u = { v }; + if (u.r[0]) a_or((int *)p, u.r[0]); + if (u.r[1]) a_or((int *)p+1, u.r[1]); +} +#endif + +#ifndef a_cas_p +typedef char a_cas_p_undefined_but_pointer_not_32bit[-sizeof(char) == 0xffffffff ? 1 : -1]; +#define a_cas_p a_cas_p +static inline void *a_cas_p(volatile void *p, void *t, void *s) +{ + return (void *)a_cas((volatile int *)p, (int)t, (int)s); +} +#endif + +#ifndef a_or_l +#define a_or_l a_or_l +static inline void a_or_l(volatile void *p, long v) +{ + if (sizeof(long) == sizeof(int)) a_or(p, v); + else a_or_64(p, v); +} +#endif + +#ifndef a_crash +#define a_crash a_crash +static inline void a_crash() +{ + *(volatile char *)0=0; +} +#endif + +#ifndef a_ctz_32 +#define a_ctz_32 a_ctz_32 +static inline int a_ctz_32(uint32_t x) +{ +#ifdef a_clz_32 + return 31-a_clz_32(x&-x); +#else + static const char debruijn32[32] = { + 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, + 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 + }; + return debruijn32[(x&-x)*0x076be629 >> 27]; +#endif +} +#endif + +#ifndef a_ctz_64 +#define a_ctz_64 a_ctz_64 +static inline int a_ctz_64(uint64_t x) +{ + static const char debruijn64[64] = { + 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, + 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, + 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, + 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 + }; + if (sizeof(long) < 8) { + uint32_t y = x; + if (!y) { + y = x>>32; + return 32 + a_ctz_32(y); + } + return a_ctz_32(y); + } + return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58]; +} +#endif + +static inline int a_ctz_l(unsigned long x) +{ + return (sizeof(long) < 8) ? a_ctz_32(x) : a_ctz_64(x); +} + +#ifndef a_clz_64 +#define a_clz_64 a_clz_64 +static inline int a_clz_64(uint64_t x) +{ +#ifdef a_clz_32 + if (x>>32) + return a_clz_32(x>>32); + return a_clz_32(x) + 32; +#else + uint32_t y; + int r; + if (x>>32) y=x>>32, r=0; else y=x, r=32; + if (y>>16) y>>=16; else r |= 16; + if (y>>8) y>>=8; else r |= 8; + if (y>>4) y>>=4; else r |= 4; + if (y>>2) y>>=2; else r |= 2; + return r | !(y>>1); +#endif +} +#endif + +#endif diff --git a/kal/posix/musl_src/internal/libc.h b/kal/posix/musl_src/internal/libc.h new file mode 100644 index 00000000..85a102e6 --- /dev/null +++ b/kal/posix/musl_src/internal/libc.h @@ -0,0 +1,19 @@ +#ifndef LIBC_H +#define LIBC_H + +#include +#include +#include + +struct __locale_map; + +struct __locale_struct { + const struct __locale_map *cat[6]; +}; + +#define __NEED_locale_t +#include + + + +#endif diff --git a/kal/posix/musl_src/internal/locale_impl.h b/kal/posix/musl_src/internal/locale_impl.h index c8425658..47b7c9e1 100644 --- a/kal/posix/musl_src/internal/locale_impl.h +++ b/kal/posix/musl_src/internal/locale_impl.h @@ -1,9 +1,12 @@ #ifndef _LOCALE_IMPL_H #define _LOCALE_IMPL_H +#define __NEED_locale_t + #include #include #include "libc.h" +#include "pthread_impl.h" #include "../include/features.h" #define LOCALE_NAME_MAX 23 @@ -27,7 +30,6 @@ hidden const char *__lctrans_impl(const char *, const struct __locale_map *); hidden int __loc_is_allocated(locale_t); hidden char *__gettextdomain(void); - #define LOC_MAP_FAILED ((const struct __locale_map *)-1) #define LCTRANS(msg, lc, loc) __lctrans(msg, (loc)->cat[(lc)]) @@ -36,6 +38,9 @@ hidden char *__gettextdomain(void); #define C_LOCALE ((locale_t)&__c_locale) #define UTF8_LOCALE ((locale_t)&__c_dot_utf8_locale) +#define CURRENT_LOCALE ((locale_t)&__c_locale) + +#define CURRENT_UTF8 (!!((locale_t)&__c_dot_utf8_locale)->cat[LC_CTYPE]) #undef MB_CUR_MAX #define MB_CUR_MAX (CURRENT_UTF8 ? 4 : 1) diff --git a/kal/posix/musl_src/internal/pthread_impl.h b/kal/posix/musl_src/internal/pthread_impl.h new file mode 100644 index 00000000..76b3ec9b --- /dev/null +++ b/kal/posix/musl_src/internal/pthread_impl.h @@ -0,0 +1,136 @@ +#ifndef _PTHREAD_IMPL_H +#define _PTHREAD_IMPL_H + +#include +#include +#include +#include +#include "libc.h" +// #include "atomic.h" +#include "../include/features.h" + +enum { + DT_EXITING = 0, + DT_JOINABLE, + DT_DETACHED, +}; + +struct __timer { + int timerid; + pthread_t thread; +}; + +#define __SU (sizeof(size_t)/sizeof(int)) + +#define _a_stacksize __u.__s[0] +#define _a_guardsize __u.__s[1] +#define _a_stackaddr __u.__s[2] +#define _a_detach __u.__i[3*__SU+0] +#define _a_sched __u.__i[3*__SU+1] +#define _a_policy __u.__i[3*__SU+2] +#define _a_prio __u.__i[3*__SU+3] +#define _m_type __u.__i[0] +#define _m_lock __u.__vi[1] +#define _m_waiters __u.__vi[2] +#define _m_prev __u.__p[3] +#define _m_next __u.__p[4] +#define _m_count __u.__i[5] +#define _c_shared __u.__p[0] +#define _c_seq __u.__vi[2] +#define _c_waiters __u.__vi[3] +#define _c_clock __u.__i[4] +#define _c_lock __u.__vi[8] +#define _c_head __u.__p[1] +#define _c_tail __u.__p[5] +#define _rw_lock __u.__vi[0] +#define _rw_waiters __u.__vi[1] +#define _rw_shared __u.__i[2] +#define _b_lock __u.__vi[0] +#define _b_waiters __u.__vi[1] +#define _b_limit __u.__i[2] +#define _b_count __u.__vi[3] +#define _b_waiters2 __u.__vi[4] +#define _b_inst __u.__p[3] + +#ifndef CANARY +#define CANARY canary +#endif + +#ifndef DTP_OFFSET +#define DTP_OFFSET 0 +#endif + +#ifndef tls_mod_off_t +#define tls_mod_off_t size_t +#endif + +#define SIGTIMER 32 +#define SIGCANCEL 33 +#define SIGSYNCCALL 34 + +#define SIGALL_SET ((sigset_t *)(const unsigned long long [2]){ -1,-1 }) +#define SIGPT_SET \ + ((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ + [sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) }) +#define SIGTIMER_SET \ + ((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ + 0x80000000 }) + +void *__tls_get_addr(tls_mod_off_t *); +hidden int __init_tp(void *); +hidden void *__copy_tls(unsigned char *); +hidden void __reset_tls(void); + +hidden void __membarrier_init(void); +hidden void __dl_thread_cleanup(void); +hidden void __testcancel(void); +hidden void __do_cleanup_push(struct pthread_cleanup_buffer *); +hidden void __do_cleanup_pop(struct pthread_cleanup_buffer *); +hidden void __pthread_tsd_run_dtors(void); + +hidden void __pthread_key_delete_synccall(void (*)(void *), void *); +hidden int __pthread_key_delete_impl(pthread_key_t); + +extern hidden volatile size_t __pthread_tsd_size; +extern hidden void *__pthread_tsd_main[]; +extern hidden volatile int __aio_fut; +extern hidden volatile int __eintr_valid_flag; + +hidden int __clone(int (*)(void *), void *, int, void *, ...); +hidden int __thread_clone(int (*func)(void *), int flags, pthread_t *thread, unsigned char *sp); +hidden int __set_thread_area(void *); +hidden int __libc_sigaction(int, const struct sigaction *, struct sigaction *); +hidden void __unmapself(void *, size_t); + +hidden int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int); +hidden int __timedwait_cp(volatile int *, int, clockid_t, const struct timespec *, int); +hidden void __wait(volatile int *, volatile int *, int, int); + +hidden void __acquire_ptc(void); +hidden void __release_ptc(void); +hidden void __inhibit_ptc(void); + +hidden void __tl_lock(void); +hidden void __tl_unlock(void); +hidden void __tl_sync(pthread_t); + +extern hidden volatile int __thread_list_lock; + +extern hidden unsigned __default_stacksize; +extern hidden unsigned __default_guardsize; + +#define DEFAULT_STACK_SIZE 131072 +#define DEFAULT_GUARD_SIZE 8192 + +#define DEFAULT_STACK_MAX (8<<20) +#define DEFAULT_GUARD_MAX (1<<20) + +#define __ATTRP_C11_THREAD ((void*)(uintptr_t)-1) + +#define MUSL_TYPE_THREAD (-1) +#define MUSL_TYPE_PROCESS (0) + +#define PTHREAD_MUTEX_TYPE_MASK 3 +#define PTHREAD_PRIORITY_LOWEST 31 + +#endif diff --git a/kal/posix/musl_src/internal/stdio_impl.h b/kal/posix/musl_src/internal/stdio_impl.h index 8b32cbd3..fa94606a 100644 --- a/kal/posix/musl_src/internal/stdio_impl.h +++ b/kal/posix/musl_src/internal/stdio_impl.h @@ -4,6 +4,7 @@ #define __NEED_struct__IO_FILE #include +#include #include "../include/features.h" #define UNGET 8 diff --git a/kal/posix/musl_src/locale/__lctrans.c b/kal/posix/musl_src/locale/__lctrans.c new file mode 100644 index 00000000..9fbe762a --- /dev/null +++ b/kal/posix/musl_src/locale/__lctrans.c @@ -0,0 +1,19 @@ +#include +#include "locale_impl.h" + +static const char *dummy(const char *msg, const struct __locale_map *lm) +{ + return msg; +} + +weak_alias(dummy, __lctrans_impl); + +const char *__lctrans(const char *msg, const struct __locale_map *lm) +{ + return __lctrans_impl(msg, lm); +} + +const char *__lctrans_cur(const char *msg) +{ + return __lctrans_impl(msg, CURRENT_LOCALE->cat[LC_MESSAGES]); +} diff --git a/kal/posix/musl_src/locale/c_locale.c b/kal/posix/musl_src/locale/c_locale.c new file mode 100644 index 00000000..77ccf587 --- /dev/null +++ b/kal/posix/musl_src/locale/c_locale.c @@ -0,0 +1,15 @@ +#include "locale_impl.h" +#include + +static const uint32_t empty_mo[] = { 0x950412de, 0, -1, -1, -1 }; + +const struct __locale_map __c_dot_utf8 = { + .map = empty_mo, + .map_size = sizeof empty_mo, + .name = "C.UTF-8" +}; + +const struct __locale_struct __c_locale = { 0 }; +const struct __locale_struct __c_dot_utf8_locale = { + .cat[LC_CTYPE] = &__c_dot_utf8 +}; diff --git a/kal/posix/musl_src/locale/langinfo.c b/kal/posix/musl_src/locale/langinfo.c new file mode 100644 index 00000000..7953c384 --- /dev/null +++ b/kal/posix/musl_src/locale/langinfo.c @@ -0,0 +1,73 @@ +#include +#include +#include "locale_impl.h" + +static const char c_time[] = + "Sun\0" "Mon\0" "Tue\0" "Wed\0" "Thu\0" "Fri\0" "Sat\0" + "Sunday\0" "Monday\0" "Tuesday\0" "Wednesday\0" + "Thursday\0" "Friday\0" "Saturday\0" + "Jan\0" "Feb\0" "Mar\0" "Apr\0" "May\0" "Jun\0" + "Jul\0" "Aug\0" "Sep\0" "Oct\0" "Nov\0" "Dec\0" + "January\0" "February\0" "March\0" "April\0" + "May\0" "June\0" "July\0" "August\0" + "September\0" "October\0" "November\0" "December\0" + "AM\0" "PM\0" + "%a %b %e %T %Y\0" + "%m/%d/%y\0" + "%H:%M:%S\0" + "%I:%M:%S %p\0" + "\0" + "\0" + "%m/%d/%y\0" + "0123456789\0" + "%a %b %e %T %Y\0" + "%H:%M:%S"; + +static const char c_messages[] = "^[yY]\0" "^[nN]\0" "yes\0" "no"; +static const char c_numeric[] = ".\0" ""; + +char *__nl_langinfo_l(nl_item item, locale_t loc) +{ + int cat = item >> 16; + int idx = item & 65535; + const char *str; + + if (item == CODESET) return loc->cat[LC_CTYPE] ? "UTF-8" : "ASCII"; + + /* _NL_LOCALE_NAME extension */ + if (idx == 65535 && cat < LC_ALL) + return loc->cat[cat] ? (char *)loc->cat[cat]->name : "C"; + + switch (cat) { + case LC_NUMERIC: + if (idx > 1) return ""; + str = c_numeric; + break; + case LC_TIME: + if (idx > 0x31) return ""; + str = c_time; + break; + case LC_MONETARY: + if (idx > 0) return ""; + str = ""; + break; + case LC_MESSAGES: + if (idx > 3) return ""; + str = c_messages; + break; + default: + return ""; + } + + for (; idx; idx--, str++) for (; *str; str++); + if (cat != LC_NUMERIC && *str) str = LCTRANS(str, cat, loc); + return (char *)str; +} + +char *__nl_langinfo(nl_item item) +{ + return __nl_langinfo_l(item, CURRENT_LOCALE); +} + +weak_alias(__nl_langinfo, nl_langinfo); +weak_alias(__nl_langinfo_l, nl_langinfo_l); diff --git a/kal/posix/musl_src/time/__month_to_secs.c b/kal/posix/musl_src/time/__month_to_secs.c new file mode 100644 index 00000000..43248fb3 --- /dev/null +++ b/kal/posix/musl_src/time/__month_to_secs.c @@ -0,0 +1,10 @@ +int __month_to_secs(int month, int is_leap) +{ + static const int secs_through_month[] = { + 0, 31*86400, 59*86400, 90*86400, + 120*86400, 151*86400, 181*86400, 212*86400, + 243*86400, 273*86400, 304*86400, 334*86400 }; + int t = secs_through_month[month]; + if (is_leap && month >= 2) t+=86400; + return t; +} diff --git a/kal/posix/musl_src/time/__tm_to_secs.c b/kal/posix/musl_src/time/__tm_to_secs.c new file mode 100644 index 00000000..c29fa985 --- /dev/null +++ b/kal/posix/musl_src/time/__tm_to_secs.c @@ -0,0 +1,24 @@ +#include "time_impl.h" + +long long __tm_to_secs(const struct tm *tm) +{ + int is_leap; + long long year = tm->tm_year; + int month = tm->tm_mon; + if (month >= 12 || month < 0) { + int adj = month / 12; + month %= 12; + if (month < 0) { + adj--; + month += 12; + } + year += adj; + } + long long t = __year_to_secs(year, &is_leap); + t += __month_to_secs(month, is_leap); + t += 86400LL * (tm->tm_mday-1); + t += 3600LL * tm->tm_hour; + t += 60LL * tm->tm_min; + t += tm->tm_sec; + return t; +} diff --git a/kal/posix/musl_src/time/__tz.c b/kal/posix/musl_src/time/__tz.c new file mode 100644 index 00000000..49c2f4bf --- /dev/null +++ b/kal/posix/musl_src/time/__tz.c @@ -0,0 +1,234 @@ +#include "time_impl.h" +#include +#include +#include +#include +#include +#include "libc.h" +#include + +long __timezone = 0; +int __daylight = 0; +char *__tzname[2] = { 0, 0 }; + +weak_alias(__timezone, timezone); +weak_alias(__daylight, daylight); +weak_alias(__tzname, tzname); + +#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP +#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_MUTEX_INITIALIZER +#endif + +static pthread_mutex_t locallock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; + +static int LOCK(void) +{ + return pthread_mutex_lock(&locallock); +} + +static void UNLOCK(void) +{ + (void)pthread_mutex_unlock(&locallock); +} + + +const char __utc[] = "UTC"; + +static int dst_off; +static int r0[5], r1[5]; + +static const unsigned char *zi, *trans, *index_local, *types, *abbrevs, *abbrevs_end; + +#define VEC(...) ((const unsigned char[]){__VA_ARGS__}) + +static uint32_t zi_read32(const unsigned char *z) +{ + return (unsigned)z[0]<<24 | z[1]<<16 | z[2]<<8 | z[3]; +} + +static void do_tzset(void) +{ +} + +/* Search zoneinfo rules to find the one that applies to the given time, + * and determine alternate opposite-DST-status rule that may be needed. */ + +static size_t scan_trans(long long t, int local, size_t *alt) +{ + int scale = 3 - (trans == zi+44); + uint64_t x; + int off = 0; + + size_t a = 0, n = (index_local-trans)>>scale, m; + + if (!n) { + if (alt) *alt = 0; + return 0; + } + + /* Binary search for 'most-recent rule before t'. */ + while (n > 1) { + m = a + n/2; + x = zi_read32(trans + (m<>scale; + if (a == n-1) return -1; + if (a == 0) { + x = zi_read32(trans + (a<>(m-1))&1); +} + +/* Convert a POSIX DST rule plus year to seconds since epoch. */ + +static long long rule_to_secs(const int *rule, int year) +{ + int is_leap; + long long t = __year_to_secs(year, &is_leap); + int x, m, n, d; + if (rule[0]!='M') { + x = rule[1]; + if (rule[0]=='J' && (x < 60 || !is_leap)) x--; + t += 86400 * x; + } else { + m = rule[1]; + n = rule[2]; + d = rule[3]; + t += __month_to_secs(m-1, is_leap); + int wday = (int)((t + 4*86400) % (7*86400)) / 86400; + int days = d - wday; + if (days < 0) days += 7; + if (n == 5 && days+28 >= days_in_month(m, is_leap)) n = 4; + t += 86400 * (days + 7*(n-1)); + } + t += rule[4]; + return t; +} + +/* Determine the time zone in effect for a given time in seconds since the + * epoch. It can be given in local or universal time. The results will + * indicate whether DST is in effect at the queried time, and will give both + * the GMT offset for the active zone/DST rule and the opposite DST. This + * enables a caller to efficiently adjust for the case where an explicit + * DST specification mismatches what would be in effect at the time. */ + +void __secs_to_zone(long long t, int local, int *isdst, long *offset, long *oppoff, const char **zonename) +{ + LOCK(); + + do_tzset(); + + if (zi) { + size_t alt, i = scan_trans(t, local, &alt); + if (i != -1) { + *isdst = types[6*i+4]; + *offset = (int32_t)zi_read32(types+6*i); + *zonename = (const char *)abbrevs + types[6*i+5]; + if (oppoff) *oppoff = (int32_t)zi_read32(types+6*alt); + UNLOCK(); + return; + } + } + + if (!__daylight) goto std; + + /* FIXME: may be broken if DST changes right at year boundary? + * Also, this could be more efficient.*/ + long long y = t / 31556952 + 70; + while (__year_to_secs(y, 0) > t) y--; + while (__year_to_secs(y+1, 0) < t) y++; + + long long t0 = rule_to_secs(r0, y); + long long t1 = rule_to_secs(r1, y); + + if (!local) { + t0 += __timezone; + t1 += dst_off; + } + if (t0 < t1) { + if (t >= t0 && t < t1) goto dst; + goto std; + } else { + if (t >= t1 && t < t0) goto std; + goto dst; + } +std: + *isdst = 0; + *offset = -__timezone; + if (oppoff) *oppoff = -dst_off; + *zonename = __tzname[0]; + UNLOCK(); + return; +dst: + *isdst = 1; + *offset = -dst_off; + if (oppoff) *oppoff = -__timezone; + *zonename = __tzname[1]; + UNLOCK(); +} + +static void __tzset(void) +{ + LOCK(); + do_tzset(); + UNLOCK(); +} + +weak_alias(__tzset, tzset); + +const char *__tm_to_tzname(const struct tm *tm) +{ + const void *p = tm->__tm_zone; + LOCK(); + do_tzset(); + if (p != __utc && p != __tzname[0] && p != __tzname[1] && + (!zi || (uintptr_t)p-(uintptr_t)abbrevs >= abbrevs_end - abbrevs)) + p = ""; + UNLOCK(); + return p; +} diff --git a/kal/posix/musl_src/time/__year_to_secs.c b/kal/posix/musl_src/time/__year_to_secs.c new file mode 100644 index 00000000..2824ec6d --- /dev/null +++ b/kal/posix/musl_src/time/__year_to_secs.c @@ -0,0 +1,47 @@ +long long __year_to_secs(long long year, int *is_leap) +{ + if (year-2ULL <= 136) { + int y = year; + int leaps = (y-68)>>2; + if (!((y-68)&3)) { + leaps--; + if (is_leap) *is_leap = 1; + } else if (is_leap) *is_leap = 0; + return 31536000*(y-70) + 86400*leaps; + } + + int cycles, centuries, leaps, rem; + + if (!is_leap) is_leap = &(int){0}; + cycles = (year-100) / 400; + rem = (year-100) % 400; + if (rem < 0) { + cycles--; + rem += 400; + } + if (!rem) { + *is_leap = 1; + centuries = 0; + leaps = 0; + } else { + if (rem >= 200) { + if (rem >= 300) centuries = 3, rem -= 300; + else centuries = 2, rem -= 200; + } else { + if (rem >= 100) centuries = 1, rem -= 100; + else centuries = 0; + } + if (!rem) { + *is_leap = 0; + leaps = 0; + } else { + leaps = rem / 4U; + rem %= 4U; + *is_leap = !rem; + } + } + + leaps += 97*cycles + 24*centuries - *is_leap; + + return (year-100) * 31536000LL + leaps * 86400LL + 946684800 + 86400; +} diff --git a/kal/posix/musl_src/time/strftime.c b/kal/posix/musl_src/time/strftime.c index c8fd32d2..cc53d536 100644 --- a/kal/posix/musl_src/time/strftime.c +++ b/kal/posix/musl_src/time/strftime.c @@ -8,8 +8,6 @@ #include "locale_impl.h" #include "time_impl.h" -#define CURRENT_LOCALE NULL - static int is_leap(int y) { /* Avoid overflow */ @@ -181,8 +179,12 @@ const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm * tm->__tm_gmtoff/3600*100 + tm->__tm_gmtoff%3600/60); return *s; case 'Z': - // unsupport tz - return 0; + if (tm->tm_isdst < 0) { + *l = 0; + return ""; + } + fmt = __tm_to_tzname(tm); + goto string; case '%': *l = 1; return "%"; @@ -198,14 +200,12 @@ number: } return *s; nl_strcat: - // unsuport loc - return 0; + fmt = __nl_langinfo_l(item, loc); string: *l = strlen(fmt); return fmt; nl_strftime: - // unsuport loc - return 0; + fmt = __nl_langinfo_l(item, loc); recu_strftime: *l = __strftime_l(*s, sizeof *s, fmt, tm, loc); if (!*l) return 0; @@ -275,7 +275,7 @@ size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const st size_t strftime(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm) { - return __strftime_l(s, n, f, tm, NULL); + return __strftime_l(s, n, f, tm, CURRENT_LOCALE); } weak_alias(__strftime_l, strftime_l); diff --git a/kal/posix/musl_src/time/time_impl.h b/kal/posix/musl_src/time/time_impl.h index c3c136d8..cd945433 100644 --- a/kal/posix/musl_src/time/time_impl.h +++ b/kal/posix/musl_src/time/time_impl.h @@ -1,5 +1,5 @@ #include -#include "features.h" +#include "../include/features.h" hidden int __days_in_month(int, int); hidden int __month_to_secs(int, int); diff --git a/testsuits/unittest/fuzz/src/ctype/isdigit_fuzz.c b/testsuits/unittest/fuzz/src/ctype/isdigit_fuzz.c new file mode 100644 index 00000000..df851a80 --- /dev/null +++ b/testsuits/unittest/fuzz/src/ctype/isdigit_fuzz.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void IsdigitFuzzTest(void) +{ + int c; + + printf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + c = *(int *)DT_SetGetS32(&g_element[0], '0'); + (void)isdigit(c); + } + + printf("Fuzz test in line [%d] isdigit ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + return; +} diff --git a/testsuits/unittest/fuzz/src/ctype/islower_fuzz.c b/testsuits/unittest/fuzz/src/ctype/islower_fuzz.c new file mode 100644 index 00000000..7bd96af6 --- /dev/null +++ b/testsuits/unittest/fuzz/src/ctype/islower_fuzz.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void IslowerFuzzTest(void) +{ + int c; + + printf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + c = *(int *)DT_SetGetS32(&g_element[0], 'a'); + (void)islower(c); + } + + printf("Fuzz test in line [%d] islower ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + return; +} diff --git a/testsuits/unittest/fuzz/src/ctype/isxdigit_fuzz.c b/testsuits/unittest/fuzz/src/ctype/isxdigit_fuzz.c new file mode 100644 index 00000000..3fd91930 --- /dev/null +++ b/testsuits/unittest/fuzz/src/ctype/isxdigit_fuzz.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void IsxdigitFuzzTest(void) +{ + int c; + + printf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + c = *(int *)DT_SetGetS32(&g_element[0], '0'); + (void)isxdigit(c); + } + + printf("Fuzz test in line [%d] isxdigit ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + return; +} diff --git a/testsuits/unittest/fuzz/src/ctype/test_isalnum_fuzz.c b/testsuits/unittest/fuzz/src/ctype/test_isalnum_fuzz.c new file mode 100644 index 00000000..9ab61916 --- /dev/null +++ b/testsuits/unittest/fuzz/src/ctype/test_isalnum_fuzz.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int IsalnumFuzz(void) +{ + int i; + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (i = 0; i < g_iteration; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + unsigned char ctypeVal = *(unsigned char *)DT_SetGetU8(&g_element[0], 0); + (void)isalnum(ctypeVal); + } + + printf("Fuzz test in line [%d] isalnum ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + if (i == g_iteration) { + } + + return 0; +} \ No newline at end of file diff --git a/testsuits/unittest/fuzz/src/ctype/test_isascii_fuzz.c b/testsuits/unittest/fuzz/src/ctype/test_isascii_fuzz.c new file mode 100644 index 00000000..8416dc85 --- /dev/null +++ b/testsuits/unittest/fuzz/src/ctype/test_isascii_fuzz.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int IsasciiFuzz(void) +{ + int i; + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (i = 0; i < g_iteration; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + unsigned char ctypeVal = *(unsigned char *)DT_SetGetU8(&g_element[0], 0); + (void)isascii(ctypeVal); + } + + printf("Fuzz test in line [%d] isascii ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + if (i == g_iteration) { + } + + return 0; +} \ No newline at end of file diff --git a/testsuits/unittest/fuzz/src/ctype/test_isprint_fuzz.c b/testsuits/unittest/fuzz/src/ctype/test_isprint_fuzz.c new file mode 100644 index 00000000..e6b45aed --- /dev/null +++ b/testsuits/unittest/fuzz/src/ctype/test_isprint_fuzz.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int IsprintFuzz(void) +{ + int i; + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (i = 0; i < g_iteration; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + int ctypeVal = *((int *)DT_SetGetS32(&g_element[0], 0)); + (void)isprint(ctypeVal); + } + + printf("Fuzz test in line [%d] isprint ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + if (i == g_iteration) { + } + + return 0; +} \ No newline at end of file diff --git a/testsuits/unittest/fuzz/src/ctype/test_isspace_fuzz.c b/testsuits/unittest/fuzz/src/ctype/test_isspace_fuzz.c new file mode 100644 index 00000000..600a1d0d --- /dev/null +++ b/testsuits/unittest/fuzz/src/ctype/test_isspace_fuzz.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int IsspaceFuzz(void) +{ + int i; + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (i = 0; i < g_iteration; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + unsigned char ctypeVal = *(unsigned char *)DT_SetGetU8(&g_element[0], 0); + (void)isspace(ctypeVal); + } + + printf("Fuzz test in line [%d] isspace ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + if (i == g_iteration) { + } + + return 0; +} \ No newline at end of file diff --git a/testsuits/unittest/fuzz/src/ctype/test_isupper_fuzz.c b/testsuits/unittest/fuzz/src/ctype/test_isupper_fuzz.c new file mode 100644 index 00000000..99e96ab5 --- /dev/null +++ b/testsuits/unittest/fuzz/src/ctype/test_isupper_fuzz.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int IsupperFuzz(void) +{ + int i; + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (i = 0; i < g_iteration; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + unsigned char ctypeVal = *(unsigned char *)DT_SetGetU8(&g_element[0], 0); + (void)isupper(ctypeVal); + } + + printf("Fuzz test in line [%d] isupper ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + if (i == g_iteration) { + } + + return 0; +} \ No newline at end of file diff --git a/testsuits/unittest/fuzz/src/ctype/tolower_fuzz.c b/testsuits/unittest/fuzz/src/ctype/tolower_fuzz.c new file mode 100644 index 00000000..514f9053 --- /dev/null +++ b/testsuits/unittest/fuzz/src/ctype/tolower_fuzz.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void TolowerFuzzTest(void) +{ + int c; + + printf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + c = *(int *)DT_SetGetS32(&g_element[0], 'A'); + (void)tolower(c); + } + printf("Fuzz test in line [%d] tolower ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + return; +} diff --git a/testsuits/unittest/fuzz/src/ctype/toupper_fuzz.c b/testsuits/unittest/fuzz/src/ctype/toupper_fuzz.c new file mode 100644 index 00000000..98677d09 --- /dev/null +++ b/testsuits/unittest/fuzz/src/ctype/toupper_fuzz.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void ToupperFuzzTest(void) +{ + int c; + + printf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + c = *(int *)DT_SetGetS32(&g_element[0], 'a'); + (void)toupper(c); + } + + printf("Fuzz test in line [%d] toupper ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + return; +} diff --git a/testsuits/unittest/fuzz/src/fuzz_posix.c b/testsuits/unittest/fuzz/src/fuzz_posix.c new file mode 100644 index 00000000..368a7dc4 --- /dev/null +++ b/testsuits/unittest/fuzz/src/fuzz_posix.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +void ItSuiteFuzz(void) +{ + IsdigitFuzzTest(); + + IslowerFuzzTest(); + IsxdigitFuzzTest(); + TolowerFuzzTest(); + ToupperFuzzTest(); + AtoiFuzzTest(); + AtolFuzzTest(); + AtollFuzzTest(); + StrtolFuzzTest(); + StrtoulFuzzTest(); + StrtoullFuzzTest(); + StrchrFuzzTest(); + StrstrFuzzTest(); + + IsalnumFuzz(); + IsasciiFuzz(); + IsprintFuzz(); + IsspaceFuzz(); + IsupperFuzz(); + StdargFuzz(); + + ItSuiteRegexFuzz(); + ReallocFuzzTest(); + MemcmpFuzzTest(); + MemcpyFuzzTest(); + MemsetFuzzTest(); + StrcmpFuzzTest(); + StrcspnFuzzTest(); + StrdupFuzzTest(); + StrerrorFuzzTest(); + StrlenFuzz(); + StrncmpFuzz(); + StrrchrFuzz(); + StrncasecmpFuzz(); + StrptimeFuzzTest(); + + AbsFuzzTest(); + GettimeofdayFuzzTest(); + TimesFuzzTest(); + GmtimeFuzzTest(); + LocaltimeFuzzTest(); + LocaltimerFuzzTest(); + TimeFuzzTest(); + StrftimeFuzzTest(); + MktimeFuzzTest(); + + UsleepFuzzTest(); + + LogFuzzTest(); + PowFuzzTest(); + RoundFuzzTest(); + SqrtFuzzTest(); + SemTimedWaitFuzzTest(); +} diff --git a/testsuits/unittest/fuzz/src/fuzz_posix.h b/testsuits/unittest/fuzz/src/fuzz_posix.h new file mode 100644 index 00000000..4e723b9f --- /dev/null +++ b/testsuits/unittest/fuzz/src/fuzz_posix.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _FUZZ_POSIX_H +#define _FUZZ_POSIX_H + + +#define RET_FALSE (-1) +#define RET_OK 0 +#define RET_TRUE 1 + +#define NUM_0_INDEX 0 +#define NUM_1_INDEX 1 +#define NUM_2_INDEX 2 +#define NUM_3_INDEX 3 +#define NUM_4_INDEX 4 +#define NUM_5_INDEX 5 + +#define ELEMENT_LEN 10 + +void ItSuiteFuzz(void); + +void IsdigitFuzzTest(void); +extern void IslowerFuzzTest(void); +extern void IsxdigitFuzzTest(void); +extern void TolowerFuzzTest(void); +extern void ToupperFuzzTest(void); +extern void AtoiFuzzTest(void); +extern void AtolFuzzTest(void); +extern void AtollFuzzTest(void); +extern void StrtolFuzzTest(void); +extern void StrtoulFuzzTest(void); +extern void StrtoullFuzzTest(void); +extern void StrchrFuzzTest(void); +extern void StrstrFuzzTest(void); +extern void NetFuzzTest(void); + +extern void ItSuiteRegexFuzz(void); +extern void ItSuiteStringsFuzz(void); + +extern int IsalnumFuzz(void); +extern int IsasciiFuzz(void); +extern int IsprintFuzz(void); +extern int IsspaceFuzz(void); +extern int IsupperFuzz(void); +extern int StdargFuzz(void); +extern void ReallocFuzzTest(void); +extern int MemcmpFuzzTest(void); +extern int MemcpyFuzzTest(void); +extern int MemsetFuzzTest(void); +extern int StrcmpFuzzTest(void); +extern int StrcspnFuzzTest(void); +extern int StrdupFuzzTest(void); +extern int StrerrorFuzzTest(void); +extern int StrlenFuzz(void); +extern int StrncmpFuzz(void); +extern int StrrchrFuzz(void); +extern int StrncasecmpFuzz(void); +extern int StrptimeFuzzTest(void); + +extern void DirnameFuzzTest(void); +extern void LogFuzzTest(void); +extern void PowFuzzTest(void); +extern void RoundFuzzTest(void); +extern void SqrtFuzzTest(void); +extern void SemTimedWaitFuzzTest(void); +extern void ClearerrFuzzTest(void); +extern void FeofFuzzTest(void); +extern void PerrorFuzzTest(void); +extern void AbsFuzzTest(void); +extern void GettimeofdayFuzzTest(void); +extern void TimesFuzzTest(void); +extern void GmtimeFuzzTest(void); +extern void LocaltimeFuzzTest(void); +extern void LocaltimerFuzzTest(void); +extern void MktimeFuzzTest(void); +extern void StrftimeFuzzTest(void); +extern void TimeFuzzTest(void); +extern void UsleepFuzzTest(void); + +#endif \ No newline at end of file diff --git a/testsuits/unittest/fuzz/src/libgen/dirname_fuzz.c b/testsuits/unittest/fuzz/src/libgen/dirname_fuzz.c new file mode 100644 index 00000000..2ce9eb36 --- /dev/null +++ b/testsuits/unittest/fuzz/src/libgen/dirname_fuzz.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define DEFAULT_TIME_VALUE 0 +#define STR_LEN 1 +#define MAX_STR_LEN 10 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void DirnameFuzzTest(void) +{ + char *dirName = NULL; + + printf("Fuzz test in line [%d] dirname start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + dirName = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "test"); + (void)dirname(dirName); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] dirname ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/math/log_fuzz.c b/testsuits/unittest/fuzz/src/math/log_fuzz.c new file mode 100644 index 00000000..13817d1b --- /dev/null +++ b/testsuits/unittest/fuzz/src/math/log_fuzz.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define DEFAULT_LOG_VALUE 1.0 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void LogFuzzTest(void) +{ + double x; + + printf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + x = *(double *)DT_SetGetDouble(&g_element[0], DEFAULT_LOG_VALUE); + (void)log(x); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] log ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/math/pow_fuzz.c b/testsuits/unittest/fuzz/src/math/pow_fuzz.c new file mode 100644 index 00000000..5a72b2f0 --- /dev/null +++ b/testsuits/unittest/fuzz/src/math/pow_fuzz.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define DEFAULT_POW_VALUE 1.0 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void PowFuzzTest(void) +{ + double x; + double y; + + printf("Fuzz test in line [%d] pow start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + x = *(double *)DT_SetGetDouble(&g_element[0], DEFAULT_POW_VALUE); + y = *(double *)DT_SetGetDouble(&g_element[1], DEFAULT_POW_VALUE); + (void)pow(x, y); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] pow ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/math/round_fuzz.c b/testsuits/unittest/fuzz/src/math/round_fuzz.c new file mode 100644 index 00000000..363f1b3a --- /dev/null +++ b/testsuits/unittest/fuzz/src/math/round_fuzz.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define DEFAULT_ROUND_VALUE 0 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void RoundFuzzTest(void) +{ + double x; + + printf("Fuzz test in line [%d] round start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + x = *(double *)DT_SetGetDouble(&g_element[0], DEFAULT_ROUND_VALUE); + (void)round(x); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] round ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/math/sqrt_fuzz.c b/testsuits/unittest/fuzz/src/math/sqrt_fuzz.c new file mode 100644 index 00000000..79aab378 --- /dev/null +++ b/testsuits/unittest/fuzz/src/math/sqrt_fuzz.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define DEFAULT_SQRT_VALUE 1.0 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void SqrtFuzzTest(void) +{ + double x; + + printf("Fuzz test in line [%d] sqrt start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + x = *(double *)DT_SetGetDouble(&g_element[0], DEFAULT_SQRT_VALUE); + (void)sqrt(x); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] sqrt ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/regex/it_test_regex_fuzz.c b/testsuits/unittest/fuzz/src/regex/it_test_regex_fuzz.c new file mode 100644 index 00000000..7c96edb1 --- /dev/null +++ b/testsuits/unittest/fuzz/src/regex/it_test_regex_fuzz.c @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define FUZZ_SYS_NAME_LEN 80 +#define MAX_STR_BUF_LEN 10 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +static uint32_t RegexFuzz(void) +{ + int fd; + int ret; + regex_t preg; + regmatch_t pmatch[1]; + const size_t nmatch = 1; + + const int initIntValue = 6; + const int initStrLen = 4; + const int maxStrLen = 5; + const int maxNumRange = 6; + const int maxNum1Range = 3; + int spid; + int num; + int num1; + char *string1 = NULL; + char str1[MAX_STR_BUF_LEN] = {0}; + char *string2 = NULL; + char str2[MAX_STR_BUF_LEN] = {0}; + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + printf("RegexFuzz starts,count=%d\n", CYCLE_TOTAL_TIMES); + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + string1 = DT_SetGetString(&g_element[NUM_0_INDEX], initStrLen, maxStrLen, "CHN"); + (void)strncpy_s(str1, MAX_STR_BUF_LEN, string1, maxStrLen); + str1[MAX_STR_BUF_LEN - 1] = '\0'; + string2 = DT_SetGetString(&g_element[NUM_1_INDEX], initStrLen, maxStrLen, "CHN"); + (void)strncpy_s(str2, MAX_STR_BUF_LEN, string2, maxStrLen); + str2[MAX_STR_BUF_LEN - 1] = '\0'; + + num = *((int *)DT_SetGetS32(&g_element[NUM_2_INDEX], initIntValue)); + num = num % maxNumRange; + num1 = *((UINT32 *)DT_SetGetU32(&g_element[NUM_3_INDEX], initIntValue)); + num1 = num1 % maxNum1Range; + + ret = regcomp(&preg, str1, num); + if (ret != 0) { + regfree(&preg); + continue; + } + regexec(&preg, str2, nmatch, pmatch, num1); + regfree(&preg); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] regcomp/regexec/regfree ok\n", __LINE__); + + return 0; +} + +void ItSuiteRegexFuzz(void) +{ + RegexFuzz(); +} \ No newline at end of file diff --git a/testsuits/unittest/fuzz/src/semaphore/sem_timedwait_fuzz.c b/testsuits/unittest/fuzz/src/semaphore/sem_timedwait_fuzz.c new file mode 100644 index 00000000..0d5b76a9 --- /dev/null +++ b/testsuits/unittest/fuzz/src/semaphore/sem_timedwait_fuzz.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define DEFAULT_SHARED_VALUE 0 +#define MAX_SEM_VALUE 32 +#define NSEC_MODE_VALUE 100000000 +#define SEC_MODE_VALUE 2 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void SemTimedWaitFuzzTest(void) +{ + const int elemSecIndex = 4; + const int elemNsecIndex = 5; + struct timespec absTimeout; + sem_t sem; + int pshared, value, getvalue; + + printf("Fuzz test in line [%d] sem_timedwait start\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + absTimeout.tv_sec = (*(int *)DT_SetGetS32(&g_element[elemSecIndex], 0)) % SEC_MODE_VALUE; + absTimeout.tv_nsec = (*(int *)DT_SetGetS32(&g_element[elemNsecIndex], 0) % NSEC_MODE_VALUE); + memset_s(&sem, sizeof(sem), 0, sizeof(sem_t)); + pshared = (*(int *)DT_SetGetS32(&g_element[1], DEFAULT_SHARED_VALUE)); + value = (*(unsigned int *)DT_SetGetU32(&g_element[1], 0)) % MAX_SEM_VALUE; + sem_init(&sem, pshared, value); + sem_post(&sem); + sem_wait(&sem); + sem_post(&sem); + sem_post(&sem); + + sem_timedwait(&sem, &absTimeout); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] sem_timedwait ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/socket/net_fuzz.c b/testsuits/unittest/fuzz/src/socket/net_fuzz.c new file mode 100644 index 00000000..e702c084 --- /dev/null +++ b/testsuits/unittest/fuzz/src/socket/net_fuzz.c @@ -0,0 +1,330 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include "ctype.h" +#include "stdlib.h" +#include "string.h" +#include "socket.h" +#include "in.h" +#include "los_task.h" +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#ifndef TASK_PRIO_TEST +#define TASK_PRIO_TEST 2 +#endif + +#ifndef TASK_STACK_SIZE_TEST +#define TASK_STACK_SIZE_TEST 0x400 +#endif +#define LOS_TASK_STATUS_DETACHED 0x0100 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +static UINT32 g_testTaskID01; + +#define BUF_SIZE 40 +static char g_udpIp[16]; +static UINT16 g_udpPort; +#define UDPMSG "ABCDEEFG" +#define SLEEP_SECONDS 2 + +static void *SampleUdpServer() +{ + int fd; + struct sockaddr_in srvAddr = { 0 }; + + struct sockaddr_in clnAddr = { 0 }; + socklen_t clnAddrLen = sizeof(clnAddr); + char buf[BUF_SIZE] = { 0 }; + int flag; + struct msghdr msg = { 0 }; + struct iovec iov[2] = { }; + + printf("s0\r\n"); + fd = socket(AF_INET, SOCK_DGRAM, 0); + + printf("s1\r\n"); + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_udpIp); + srvAddr.sin_port = htons(g_udpPort); + int ret = bind(fd, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + + printf("s1.1, ret = %d\r\n", ret); + (void)recvfrom(fd, buf, sizeof(buf), 0x40, (struct sockaddr *)&clnAddr, &clnAddrLen); + + printf("s2, buf = %s\r\n", buf); + usleep(SLEEP_SECONDS); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = 1; + iov[0].iov_base = buf; + iov[0].iov_len = strlen(buf); + (void)sendmsg(fd, &msg, 0); + + printf("s3\r\n"); + close(fd); + return NULL; +} + +static void *SampleUdpClient() +{ + int fd = 0; + const int sleepSec = 5; + struct sockaddr_in clnAddr = { 0 }; + + char buf[BUF_SIZE] = { 0 }; + int flag; + + struct msghdr msg; + struct iovec iov[2]; + + printf("c1\r\n"); + fd = socket(AF_INET, SOCK_DGRAM, 0); + + printf("c2\r\n"); + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(g_udpIp); + clnAddr.sin_port = htons(g_udpPort); + + printf("c3\r\n"); + strcpy_s(buf, sizeof(buf), UDPMSG); + + usleep(sleepSec); + printf("c4, %s, %d\r\n", buf, strlen(buf)); + (void)sendto(fd, buf, strlen(buf), 0, (struct sockaddr *)&clnAddr, (socklen_t)sizeof(clnAddr)); + + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = 1; + iov[0].iov_base = buf; + iov[0].iov_len = sizeof(buf); + (void)recvmsg(fd, &msg, 0x40); + printf("c6\r\n"); + + close(fd); + return NULL; +} + +static UINT32 UdpFun(VOID) +{ + int i; + + UINT8 num1; + UINT8 num2; + UINT8 num3; + UINT8 num4; + UINT8 num5; + + INIT_FuzzEnvironment(); + printf("UDPFun starts\n"); + + for (i = 0; i < g_iteration; i++) { + num1 = *(UINT8 *)DT_SetGetU8(&g_element[NUM_0_INDEX], 1); + num2 = *(UINT8 *)DT_SetGetU8(&g_element[NUM_1_INDEX], 1); + num3 = *(UINT8 *)DT_SetGetU8(&g_element[NUM_2_INDEX], 1); + num4 = *(UINT8 *)DT_SetGetU8(&g_element[NUM_3_INDEX], 1); + num5 = *(UINT8 *)DT_SetGetU8(&g_element[NUM_4_INDEX], 1); + + (void)snprintf_s(g_udpIp, sizeof(g_udpIp), sizeof(g_udpIp) - 1, "%d.%d.%d.%d", num1, num2, num3, num4); + g_udpPort = *(UINT16 *)DT_SetGetU16(&g_element[NUM_5_INDEX], 0); + + { + TSK_INIT_PARAM_S stTask1 = { 0 }; + stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)SampleUdpServer; + stTask1.uwStackSize = TASK_STACK_SIZE_TEST; + stTask1.pcName = "Tsk001A"; + stTask1.usTaskPrio = TASK_PRIO_TEST; + stTask1.uwResved = LOS_TASK_STATUS_DETACHED; + (void)LOS_TaskCreate(&g_testTaskID01, &stTask1); + } + + { + TSK_INIT_PARAM_S stTask1 = { 0 }; + stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)SampleUdpClient; + stTask1.uwStackSize = TASK_STACK_SIZE_TEST; + stTask1.pcName = "Tsk001A"; + stTask1.usTaskPrio = TASK_PRIO_TEST; + stTask1.uwResved = LOS_TASK_STATUS_DETACHED; + (void)LOS_TaskCreate(&g_testTaskID01, &stTask1); + } + } + + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + printf("UDPFun end ....\n"); + + return 0; +} + +#define LOCAL_HOST "127.0.0.1" +#define STACK_IP LOCAL_HOST +#define STACK_PORT 2277 +#define PEER_PORT STACK_PORT +#define PEER_IP LOCAL_HOST +#define SRV_MSG "Hi, I am TCP server" +#define CLI_MSG "Hi, I am TCP client" + +static void *SampleTcpServer() +{ + char buf[BUF_SIZE + 1] = { 0 }; + int sfd; + int lsfd; + struct sockaddr_in srvAddr = { 0 }; + struct sockaddr_in clnAddr = { 0 }; + int ret; + + // socket had fuzz test in udpfun. now must create a useful fd, wwx520273 + lsfd = socket(AF_INET, SOCK_STREAM, 0); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(STACK_IP); + srvAddr.sin_port = htons(STACK_PORT); + (void)bind(lsfd, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + + int num1 = *(int *)DT_SetGetS32(&g_element[NUM_0_INDEX], 0); + + (void)listen(lsfd, num1); + + int num2 = *(int *)DT_SetGetS32(&g_element[NUM_1_INDEX], 0); + sfd = accept(lsfd, (struct sockaddr *)&clnAddr, &num2); + + int num3 = *(int *)DT_SetGetS32(&g_element[NUM_2_INDEX], 0); + ret = recv(lsfd, buf, sizeof(buf), num3); + + int num4 = *(int *)DT_SetGetS32(&g_element[NUM_3_INDEX], 0); + ret = shutdown(sfd, num4); + if (ret != 0) { + shutdown(sfd, SHUT_RDWR); + } + + close(sfd); + close(lsfd); + return (void *)(intptr_t)ret; +} + +static void *SampleTcpClient() +{ + char buf[BUF_SIZE + 1] = { 0 }; + int sfd = -1; + struct sockaddr_in srvAddr = { 0 }; + struct sockaddr_in clnAddr = { 0 }; + int ret; + + struct sockaddr addr; + socklen_t addrLen = sizeof(addr); + /* tcp client connection */ + sfd = socket(AF_INET, SOCK_STREAM, 0); + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(PEER_IP); + srvAddr.sin_port = htons(PEER_PORT); + connect(sfd, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); + + int num1 = *(int *)DT_SetGetS32(&g_element[0], 0); + (void)getpeername(num1, &addr, &addrLen); + (void)getsockname(num1, &addr, &addrLen); + + /* send */ + ret = memset_s(buf, sizeof(buf), 0, BUF_SIZE); + if (err != EOK) { + return (void *)(intptr_t)ret; + } + strcpy_s(buf, sizeof(buf), CLI_MSG); + + int num2 = *(int *)DT_SetGetS32(&g_element[1], 0); + send(num1, buf, strlen(CLI_MSG), num2); + + ret = shutdown(sfd, SHUT_RDWR); + + close(sfd); + return (void *)(intptr_t)ret; +} + +static UINT32 TcpFun(VOID) +{ + int i; + + INIT_FuzzEnvironment(); + printf("TcpFun starts\n"); + + for (i = 0; i < g_iteration; i++) { + { + TSK_INIT_PARAM_S stTask1 = { 0 }; + stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)SampleTcpServer; + stTask1.uwStackSize = TASK_STACK_SIZE_TEST; + stTask1.pcName = "Tsk001A"; + stTask1.usTaskPrio = TASK_PRIO_TEST; + stTask1.uwResved = LOS_TASK_STATUS_DETACHED; + (void)LOS_TaskCreate(&g_testTaskID01, &stTask1); + } + + { + TSK_INIT_PARAM_S stTask1 = { 0 }; + stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)SampleTcpClient; + stTask1.uwStackSize = TASK_STACK_SIZE_TEST; + stTask1.pcName = "Tsk001A"; + stTask1.usTaskPrio = TASK_PRIO_TEST; + stTask1.uwResved = LOS_TASK_STATUS_DETACHED; + (void)LOS_TaskCreate(&g_testTaskID01, &stTask1); + } + }; + + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + printf("TcpFun end ....\n"); + + return 0; +} + +void NetFuzzTest(void) +{ + DnCompFun(); + + UdpFun(); + TcpFun(); + + InetFun(); + + ProtoentFun(); + ConvertFun(); + + SocketFun(); +} diff --git a/testsuits/unittest/fuzz/src/stdarg/test_stdarg_fuzz.c b/testsuits/unittest/fuzz/src/stdarg/test_stdarg_fuzz.c new file mode 100644 index 00000000..4c21902a --- /dev/null +++ b/testsuits/unittest/fuzz/src/stdarg/test_stdarg_fuzz.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +static int VaFunc(int argsNum, ...) +{ + int sum1 = 0; + int sum2 = 0; + va_list argPtr1; + va_start(argPtr1, argsNum); + va_list argPtr2; + va_copy(argPtr2, argPtr1); + + for (int i = 0; i < argsNum; i++) { + sum1 += va_arg(argPtr1, int); + sum2 += va_arg(argPtr2, int); + } + int sum = sum1 + sum2; + + va_end(argPtr1); + va_end(argPtr2); + + return sum; +} + +int StdargFuzz(void) +{ + int i; + const int initValue1 = 5; + const int initValue2 = 10; + const int initValue3 = 15; + const int argNum = 3; + const int count = 2; + + printf("Fuzz test in line [%d] stdarg start\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (i = 0; i < g_iteration; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + unsigned int stdargVal1 = *((unsigned int *)DT_SetGetU32(&g_element[NUM_0_INDEX], initValue1)); + unsigned int stdargVal2 = *((unsigned int *)DT_SetGetU32(&g_element[NUM_1_INDEX], initValue2)); + unsigned int stdargVal3 = *((unsigned int *)DT_SetGetU32(&g_element[NUM_2_INDEX], initValue3)); + int ret = VaFunc(argNum, stdargVal1, stdargVal2, stdargVal3); + int sum = (stdargVal1 + stdargVal2 + stdargVal3) * count; + if (ret == sum) { + printf("VA_FUNC_TEST(3, %d, %d, %d) = %d", stdargVal1, stdargVal2, stdargVal3, ret); + return RET_TRUE; + } + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] va_start/va_copy/va_end ok\n", __LINE__); + + return 0; +} \ No newline at end of file diff --git a/testsuits/unittest/fuzz/src/stdio/clearerr_fuzz.c b/testsuits/unittest/fuzz/src/stdio/clearerr_fuzz.c new file mode 100644 index 00000000..7e43c1a7 --- /dev/null +++ b/testsuits/unittest/fuzz/src/stdio/clearerr_fuzz.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define DEFAULT_TIME_VALUE 0 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void ClearerrFuzzTest(void) +{ + FILE *stream = NULL; + char fileName[] = "./test.txt"; + + printf("Fuzz test in line [%d] clearerr start\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + stream = fopen(fileName, "rw"); + if (stream == NULL) { + printf("fopen(%s) fail\n", fileName); + return; + } + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + (void)clearerr(stream); + } + + (void)fclose(stream); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] clearerr ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/stdio/feof_fuzz.c b/testsuits/unittest/fuzz/src/stdio/feof_fuzz.c new file mode 100644 index 00000000..9f76da98 --- /dev/null +++ b/testsuits/unittest/fuzz/src/stdio/feof_fuzz.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define DEFAULT_TIME_VALUE 0 +#define MAX_BUFFER_SIZE 100 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void FeofFuzzTest(void) +{ + FILE *stream = NULL; + char fileName[] = "./test.txt"; + char str[MAX_BUFFER_SIZE] = {0}; + + printf("Fuzz test in line [%d] feof start\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + stream = fopen(fileName, "rw"); + if (stream == NULL) { + printf("fopen(%s) fail\n", fileName); + return; + } + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + (void)fread(str, MAX_BUFFER_SIZE, 1, stream); + + (void)feof(stream); + } + + (void)fclose(stream); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] feof ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/stdio/perror_fuzz.c b/testsuits/unittest/fuzz/src/stdio/perror_fuzz.c new file mode 100644 index 00000000..a9312816 --- /dev/null +++ b/testsuits/unittest/fuzz/src/stdio/perror_fuzz.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define STR_LEN 1 +#define MAX_STR_LEN 1024 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void PerrorFuzzTest(void) +{ + char *str = NULL; + + printf("Fuzz test in line [%d] perror start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "syserror"); + (void)perror(str); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] perror ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/stdlib/abs_fuzz.c b/testsuits/unittest/fuzz/src/stdlib/abs_fuzz.c new file mode 100644 index 00000000..9bc78ddf --- /dev/null +++ b/testsuits/unittest/fuzz/src/stdlib/abs_fuzz.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define DEFAULT_ABS_VALUE 0 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void AbsFuzzTest(void) +{ + int absNum; + + dprintf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + absNum = *(int *)DT_SetGetS32(&g_element[0], DEFAULT_ABS_VALUE); + (void)abs(absNum); + } + + printf("Fuzz test in line [%d] abs ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + return; +} diff --git a/testsuits/unittest/fuzz/src/stdlib/atoi_fuzz.c b/testsuits/unittest/fuzz/src/stdlib/atoi_fuzz.c new file mode 100644 index 00000000..9be736da --- /dev/null +++ b/testsuits/unittest/fuzz/src/stdlib/atoi_fuzz.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define STR_LEN 1 +#define MAX_STR_LEN 10 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void AtoiFuzzTest(void) +{ + char *str = NULL; + + printf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "1"); + (void)atoi(str); + } + + printf("Fuzz test in line [%d] atoi ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + return; +} diff --git a/testsuits/unittest/fuzz/src/stdlib/atol_fuzz.c b/testsuits/unittest/fuzz/src/stdlib/atol_fuzz.c new file mode 100644 index 00000000..102f1db3 --- /dev/null +++ b/testsuits/unittest/fuzz/src/stdlib/atol_fuzz.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define STR_LEN 1 +#define MAX_STR_LEN 10 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void AtolFuzzTest(void) +{ + char *str = NULL; + + printf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "1"); + (void)atol(str); + } + + printf("Fuzz test in line [%d] atol ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + return; +} diff --git a/testsuits/unittest/fuzz/src/stdlib/atoll_fuzz.c b/testsuits/unittest/fuzz/src/stdlib/atoll_fuzz.c new file mode 100644 index 00000000..a7408656 --- /dev/null +++ b/testsuits/unittest/fuzz/src/stdlib/atoll_fuzz.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define STR_LEN 1 +#define MAX_STR_LEN 19 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void AtollFuzzTest(void) +{ + char *str = NULL; + + printf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "1"); + (void)atoll(str); + } + printf("Fuzz test in line [%d] atoll ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + return; +} diff --git a/testsuits/unittest/fuzz/src/stdlib/realloc_fuzz.c b/testsuits/unittest/fuzz/src/stdlib/realloc_fuzz.c new file mode 100644 index 00000000..96a6d97e --- /dev/null +++ b/testsuits/unittest/fuzz/src/stdlib/realloc_fuzz.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define TEST_BUF_LEN 256 +#define TEST_MAX_BUF_LEN 1024 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void ReallocFuzzTest(void) +{ + char *source = NULL; + int c; + + printf("Fuzz test in line [%d] realloc start\n", __LINE__); + + source = (char *)malloc(TEST_BUF_LEN); + if (source == NULL) { + printf("Fuzz test in line [%d] malloc fail.\n", __LINE__); + return; + } + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + c = *(int *)DT_SetGetS32(&g_element[0], TEST_BUF_LEN); + if ((c <= 0) || (c > TEST_MAX_BUF_LEN)) { + c = TEST_BUF_LEN; + } + source = (char *)realloc(source, c); + } + + if (source == NULL) { + free(source); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] realloc ok\n", __LINE__); + + return 0; +} diff --git a/testsuits/unittest/fuzz/src/stdlib/strtol_fuzz.c b/testsuits/unittest/fuzz/src/stdlib/strtol_fuzz.c new file mode 100644 index 00000000..dfdbb949 --- /dev/null +++ b/testsuits/unittest/fuzz/src/stdlib/strtol_fuzz.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define STR_LEN 1 +#define MAX_STR_LEN 10 +#define MAX_BASE_VALUE 32 +#define MIN_BASE_VALUE 2 +#define DEFAULT_BASE_VALUE 0 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void StrtolFuzzTest(void) +{ + int base = DEFAULT_BASE_VALUE; + char *str = NULL; + char *endPtr = NULL; + + printf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + base = *(int *)DT_SetGetS32(&g_element[0], DEFAULT_BASE_VALUE); + if ((base > MAX_BASE_VALUE) || ((base < MIN_BASE_VALUE) && (base != DEFAULT_BASE_VALUE))) { + base = DEFAULT_BASE_VALUE; + } + + str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "1"); + (void)strtol(str, endPtr, base); + } + + printf("Fuzz test in line [%d] strtol ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + return; +} diff --git a/testsuits/unittest/fuzz/src/stdlib/strtoul_fuzz.c b/testsuits/unittest/fuzz/src/stdlib/strtoul_fuzz.c new file mode 100644 index 00000000..134a365e --- /dev/null +++ b/testsuits/unittest/fuzz/src/stdlib/strtoul_fuzz.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define STR_LEN 1 +#define MAX_STR_LEN 10 +#define MAX_BASE_VALUE 32 +#define MIN_BASE_VALUE 2 +#define DEFAULT_BASE_VALUE 0 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void StrtoulFuzzTest(void) +{ + int base = DEFAULT_BASE_VALUE; + char *str = NULL; + char *endPtr = NULL; + + printf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + base = *(int *)DT_SetGetS32(&g_element[0], DEFAULT_BASE_VALUE); + if ((base > MAX_BASE_VALUE) || ((base < MIN_BASE_VALUE) && (base != DEFAULT_BASE_VALUE))) { + base = DEFAULT_BASE_VALUE; + } + + str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "1"); + (void)strtoul(str, endPtr, base); + } + + printf("Fuzz test in line [%d] strtoul ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + return; +} diff --git a/testsuits/unittest/fuzz/src/stdlib/strtoull_fuzz.c b/testsuits/unittest/fuzz/src/stdlib/strtoull_fuzz.c new file mode 100644 index 00000000..26444de0 --- /dev/null +++ b/testsuits/unittest/fuzz/src/stdlib/strtoull_fuzz.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define STR_LEN 1 +#define MAX_STR_LEN 20 +#define MAX_BASE_VALUE 32 +#define MIN_BASE_VALUE 2 +#define DEFAULT_BASE_VALUE 0 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void StrtoullFuzzTest(void) +{ + int base = DEFAULT_BASE_VALUE; + char *str = NULL; + char *endPtr = NULL; + + printf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + base = *(int *)DT_SetGetS32(&g_element[0], DEFAULT_BASE_VALUE); + if ((base > MAX_BASE_VALUE) || ((base < MIN_BASE_VALUE) && (base != DEFAULT_BASE_VALUE))) { + base = DEFAULT_BASE_VALUE; + } + + str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "1"); + (void)strtoull(str, endPtr, base); + } + + printf("Fuzz test in line [%d] strtoull ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + return; +} diff --git a/testsuits/unittest/fuzz/src/string/memcmp_fuzz.c b/testsuits/unittest/fuzz/src/string/memcmp_fuzz.c new file mode 100644 index 00000000..fc9cfd93 --- /dev/null +++ b/testsuits/unittest/fuzz/src/string/memcmp_fuzz.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define STR_LEN 1 +#define MAX_STR_LEN 256 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int MemcmpFuzzTest(void) +{ + char *source = NULL; + char *dest = NULL; + + printf("Fuzz test in line [%d] memcmp start\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + source = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "pin"); + dest = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "pin"); + (void)memcmp(source, dest, strlen(source)); + } + + printf("Fuzz test in line [%d] memcmp ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + return 0; +} diff --git a/testsuits/unittest/fuzz/src/string/memcpy_fuzz.c b/testsuits/unittest/fuzz/src/string/memcpy_fuzz.c new file mode 100644 index 00000000..cc5ac4fe --- /dev/null +++ b/testsuits/unittest/fuzz/src/string/memcpy_fuzz.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define STR_LEN 1 +#define MAX_STR_LEN 256 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int MemcpyFuzzTest(void) +{ + char dest[MAX_STR_LEN + 1] = { 0 }; + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + char *source = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "pin"); + (void)memcpy(dest, source, MAX_STR_LEN); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] memcpy ok\n", __LINE__); + + return 0; +} diff --git a/testsuits/unittest/fuzz/src/string/memset_fuzz.c b/testsuits/unittest/fuzz/src/string/memset_fuzz.c new file mode 100644 index 00000000..cc5fc7e3 --- /dev/null +++ b/testsuits/unittest/fuzz/src/string/memset_fuzz.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define STR_LEN 1 +#define MAX_STR_LEN 256 +#define DEFAULT_S32_VALUE 0 +#define DEFAULT_U8_VALUE 0 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int MemsetFuzzTest(void) +{ + char source[MAX_STR_LEN + 1] = { 0 }; + char dest; + int c; + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + c = *(int *)DT_SetGetS32(&g_element[0], DEFAULT_S32_VALUE); + if (c > MAX_STR_LEN || c < 0) { + c = MAX_STR_LEN; + } + dest = (char)(DT_SetGetU8(&g_element[0], DEFAULT_U8_VALUE)); + (void)memset(source, dest, c); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] memset ok\n", __LINE__); + + return 0; +} diff --git a/testsuits/unittest/fuzz/src/string/strchr_fuzz.c b/testsuits/unittest/fuzz/src/string/strchr_fuzz.c new file mode 100644 index 00000000..e086b812 --- /dev/null +++ b/testsuits/unittest/fuzz/src/string/strchr_fuzz.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define STR_LEN 1 +#define MAX_STR_LEN 256 +#define DEFAULT_S32_VALUE 0 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void StrchrFuzzTest(void) +{ + int c; + char *str = NULL; + + printf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + c = *(int *)DT_SetGetS32(&g_element[0], DEFAULT_S32_VALUE); + str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "abcdefghijklmnopqrstuvwxyz"); + (void)strchr(str, c); + } + + printf("Fuzz test in line [%d] strchr ok\n", __LINE__); + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + return; +} diff --git a/testsuits/unittest/fuzz/src/string/strcmp_fuzz.c b/testsuits/unittest/fuzz/src/string/strcmp_fuzz.c new file mode 100644 index 00000000..60e94dd1 --- /dev/null +++ b/testsuits/unittest/fuzz/src/string/strcmp_fuzz.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define STR_LEN 1 +#define MAX_STR_LEN 256 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int StrcmpFuzzTest(void) +{ + char *source = NULL; + char *dest = NULL; + + printf("Fuzz test in line [%d] strcmp start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + source = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "pin"); + dest = (char *)DT_SetGetString(&g_element[1], STR_LEN, MAX_STR_LEN, "pin"); + (void)strcmp(source, dest); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] strcmp ok\n", __LINE__); + + return 0; +} diff --git a/testsuits/unittest/fuzz/src/string/strcspn_fuzz.c b/testsuits/unittest/fuzz/src/string/strcspn_fuzz.c new file mode 100644 index 00000000..aa31430e --- /dev/null +++ b/testsuits/unittest/fuzz/src/string/strcspn_fuzz.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define STR_LEN 1 +#define MAX_STR_LEN 256 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int StrcspnFuzzTest(void) +{ + char *source = NULL; + char *dest = NULL; + + printf("Fuzz test in line [%d] strcspn start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + source = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "pin"); + dest = (char *)DT_SetGetString(&g_element[1], STR_LEN, MAX_STR_LEN, "pin"); + (void)strcspn(source, dest); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] strcspn ok\n", __LINE__); + + return 0; +} diff --git a/testsuits/unittest/fuzz/src/string/strdup_fuzz.c b/testsuits/unittest/fuzz/src/string/strdup_fuzz.c new file mode 100644 index 00000000..034135a9 --- /dev/null +++ b/testsuits/unittest/fuzz/src/string/strdup_fuzz.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define STR_LEN 1 +#define MAX_STR_LEN 256 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int StrdupFuzzTest(void) +{ + char *source = NULL; + char *dest = NULL; + + printf("Fuzz test in line [%d] strdup start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + source = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "pin"); + dest = strdup(source); + if (dest != NULL) { + free(dest); + dest = NULL; + } + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] strdup ok\n", __LINE__); + + return 0; +} diff --git a/testsuits/unittest/fuzz/src/string/strerror_fuzz.c b/testsuits/unittest/fuzz/src/string/strerror_fuzz.c new file mode 100644 index 00000000..3eac940c --- /dev/null +++ b/testsuits/unittest/fuzz/src/string/strerror_fuzz.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int StrerrorFuzzTest(void) +{ + int c; + + printf("Fuzz test in line [%d] strerror start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + c = *(int *)DT_SetGetS32(&g_element[0], 0); + (void)strerror(c); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] strerror ok\n", __LINE__); + + return 0; +} diff --git a/testsuits/unittest/fuzz/src/string/strstr_fuzz.c b/testsuits/unittest/fuzz/src/string/strstr_fuzz.c new file mode 100644 index 00000000..f5fee9f3 --- /dev/null +++ b/testsuits/unittest/fuzz/src/string/strstr_fuzz.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define STR_LEN 1 +#define MAX_STR_LEN 256 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void StrstrFuzzTest(void) +{ + char *str = NULL; + char *substr = NULL; + + printf("Fuzz test in line [%d]\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "abcdefghijklmnopqrstuvwxyz"); + substr = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "bcd"); + (void)strstr(str, substr); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] strstr ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/string/test_strlen_fuzz.c b/testsuits/unittest/fuzz/src/string/test_strlen_fuzz.c new file mode 100644 index 00000000..1604e5f9 --- /dev/null +++ b/testsuits/unittest/fuzz/src/string/test_strlen_fuzz.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define STR_LEN 1 +#define MAX_STR_LEN 256 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int StrlenFuzz(void) +{ + int i; + char *str = NULL; + + printf("Fuzz test in line [%d] strlen start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, ""); + (void)strlen(str); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] strlen ok\n", __LINE__); + + return 0; +} \ No newline at end of file diff --git a/testsuits/unittest/fuzz/src/string/test_strncmp_fuzz.c b/testsuits/unittest/fuzz/src/string/test_strncmp_fuzz.c new file mode 100644 index 00000000..56a0fc5d --- /dev/null +++ b/testsuits/unittest/fuzz/src/string/test_strncmp_fuzz.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define STR_LEN 1 +#define MAX_STR_LEN 256 + +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int StrncmpFuzz(void) +{ + int i; + char *stringVal1 = NULL; + char *stringVal2 = NULL; + + printf("Fuzz test in line [%d] strncmp start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + stringVal1 = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "string"); + stringVal2 = (char *)DT_SetGetString(&g_element[1], STR_LEN, MAX_STR_LEN, "STring"); + (void)strncmp(stringVal1, stringVal2, strlen(stringVal1)); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] strncmp ok\n", __LINE__); + + return 0; +} \ No newline at end of file diff --git a/testsuits/unittest/fuzz/src/string/test_strrchr_fuzz.c b/testsuits/unittest/fuzz/src/string/test_strrchr_fuzz.c new file mode 100644 index 00000000..1fd23f94 --- /dev/null +++ b/testsuits/unittest/fuzz/src/string/test_strrchr_fuzz.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define STR_LEN 1 +#define MAX_STR_LEN 256 +#define DEFAULT_S32_VALUE 0 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int StrrchrFuzz(void) +{ + int i; + int c; + char *str = NULL; + + printf("Fuzz test in line [%d] strrchr start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + c = *(int *)DT_SetGetS32(&g_element[0], DEFAULT_S32_VALUE); + str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, ""); + (void)strrchr(str, c); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] strrchr ok\n", __LINE__); + + return 0; +} \ No newline at end of file diff --git a/testsuits/unittest/fuzz/src/strings/it_test_strings_fuzz.c b/testsuits/unittest/fuzz/src/strings/it_test_strings_fuzz.c new file mode 100644 index 00000000..15b5bbff --- /dev/null +++ b/testsuits/unittest/fuzz/src/strings/it_test_strings_fuzz.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define STR_LEN 1 +#define MAX_STR_LEN 256 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +static uint32_t StrcasecmpFuzz(void) +{ + int i; + char *lstring = NULL; + char *rstring = NULL; + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + printf("StrcasecmpFuzz starts\n"); + + for (i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + lstring = DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, ""); + rstring = DT_SetGetString(&g_element[1], STR_LEN, MAX_STR_LEN, ""); + (void)strcasecmp(lstring, rstring); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] strcasecmp ok\n", __LINE__); + + return 0; +} + +void ItSuiteStringsFuzz(void) +{ + StrcasecmpFuzz(); +} \ No newline at end of file diff --git a/testsuits/unittest/fuzz/src/strings/test_strncasecmp_fuzz.c b/testsuits/unittest/fuzz/src/strings/test_strncasecmp_fuzz.c new file mode 100644 index 00000000..a91576fd --- /dev/null +++ b/testsuits/unittest/fuzz/src/strings/test_strncasecmp_fuzz.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "strings.h" +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define STR_LEN 1 +#define MAX_STR_LEN 256 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int StrncasecmpFuzz(void) +{ + int i; + char *stringVal1 = NULL; + char *stringVal2 = NULL; + const size_t size = 2; + + printf("Fuzz test in line [%d] strncasecmp start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + stringVal1 = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, ""); + stringVal2 = (char *)DT_SetGetString(&g_element[1], STR_LEN, MAX_STR_LEN, ""); + (void)strncasecmp(stringVal1, stringVal2, size); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] strncasecmp ok\n", __LINE__); + + return 0; +} \ No newline at end of file diff --git a/testsuits/unittest/fuzz/src/sys/time/gettimeofday_fuzz.c b/testsuits/unittest/fuzz/src/sys/time/gettimeofday_fuzz.c new file mode 100644 index 00000000..7bbcb597 --- /dev/null +++ b/testsuits/unittest/fuzz/src/sys/time/gettimeofday_fuzz.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define _GNU_SOURCE +#define __NEED_suseconds_t +#define __NEED_struct_timeval +#include +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void GettimeofdayFuzzTest(void) +{ + struct timeval tv; + struct timezone tz; + + printf("Fuzz test in line [%d] gettimeofday start\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + (void)gettimeofday(&tv, &tz); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] gettimeofday ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/sys/times/times_fuzz.c b/testsuits/unittest/fuzz/src/sys/times/times_fuzz.c new file mode 100644 index 00000000..4679d3a2 --- /dev/null +++ b/testsuits/unittest/fuzz/src/sys/times/times_fuzz.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "time.h" +#include "times.h" +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void TimesFuzzTest(void) +{ + struct tms buf; + + printf("Fuzz test in line [%d] times start\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + (void)times(&buf); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] times ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/time/gmtime_fuzz.c b/testsuits/unittest/fuzz/src/time/gmtime_fuzz.c new file mode 100644 index 00000000..e238633c --- /dev/null +++ b/testsuits/unittest/fuzz/src/time/gmtime_fuzz.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define DEFAULT_TIME_VALUE 0 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void GmtimeFuzzTest(void) +{ + time_t timep; + + printf("Fuzz test in line [%d] gmtime start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + timep = DT_SetGetS64(&g_element[0], DEFAULT_TIME_VALUE); + (void)gmtime(&timep); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] gmtime ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/time/localtime_fuzz.c b/testsuits/unittest/fuzz/src/time/localtime_fuzz.c new file mode 100644 index 00000000..e4356074 --- /dev/null +++ b/testsuits/unittest/fuzz/src/time/localtime_fuzz.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define DEFAULT_TIME_VALUE 0 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void LocaltimeFuzzTest(void) +{ + time_t timep; + + printf("Fuzz test in line [%d] localtime start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + timep = DT_SetGetS64(&g_element[0], DEFAULT_TIME_VALUE); + (void)localtime(&timep); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] localtime ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/time/localtime_r_fuzz.c b/testsuits/unittest/fuzz/src/time/localtime_r_fuzz.c new file mode 100644 index 00000000..c9d5796f --- /dev/null +++ b/testsuits/unittest/fuzz/src/time/localtime_r_fuzz.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define DEFAULT_TIME_VALUE 0 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void LocaltimerFuzzTest(void) +{ + time_t timep; + struct tm result; + + printf("Fuzz test in line [%d] localtime_r start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + timep = DT_SetGetS64(&g_element[0], DEFAULT_TIME_VALUE); + (void)localtime_r(&timep, &result); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] localtime_r ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/time/mktime_fuzz.c b/testsuits/unittest/fuzz/src/time/mktime_fuzz.c new file mode 100644 index 00000000..cdb18b4e --- /dev/null +++ b/testsuits/unittest/fuzz/src/time/mktime_fuzz.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define MAX_RAMD_TIME_POS 65535 +#define MIN_RAMD_TIME_POS 0 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void MktimeFuzzTest(void) +{ + struct tm *ptm = NULL; + time_t timeValue; + int c; + + printf("Fuzz test in line [%d] mktime start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + (void)time(&timeValue); + ptm = localtime(&timeValue); + if (ptm == NULL) { + printf("Fuzz test in line [%d] mktime ptm == NULL,count:%d.\n", __LINE__, i); + return; + } + + c = *(int *)DT_SetGetS32(&g_element[0], MIN_RAMD_TIME_POS); + if (c < MIN_RAMD_TIME_POS || (c > MAX_RAMD_TIME_POS)) { + c = MIN_RAMD_TIME_POS; + } + ptm->tm_sec += c; + (void)mktime(ptm); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] mktime ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/time/strftime_fuzz.c b/testsuits/unittest/fuzz/src/time/strftime_fuzz.c new file mode 100644 index 00000000..24482076 --- /dev/null +++ b/testsuits/unittest/fuzz/src/time/strftime_fuzz.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define MAX_S_LEN 64 +#define MAX_RAMD_TIME_POS 65535 +#define MIN_RAMD_TIME_POS 0 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void StrftimeFuzzTest(void) +{ + time_t timeValue; + struct tm *ptm = NULL; + char s[MAX_S_LEN]; + int c; + + printf("Fuzz test in line [%d] strftime start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + (void)time(&timeValue); + ptm = localtime(&timeValue); + if (ptm == NULL) { + printf("Fuzz test in line [%d] strftime ptm == NULL,count:%d.\n", __LINE__, i); + return; + } + c = *(int *)DT_SetGetS32(&g_element[0], MIN_RAMD_TIME_POS); + if (c < MIN_RAMD_TIME_POS || (c > MAX_RAMD_TIME_POS)) { + c = MIN_RAMD_TIME_POS; + } + ptm->tm_sec += c; + (void)strftime(s, MAX_S_LEN, "%Y-%m-%d %H:%M:%S.%f", ptm); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] strftime ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/time/strptime_fuzz.c b/testsuits/unittest/fuzz/src/time/strptime_fuzz.c new file mode 100644 index 00000000..e65ded4a --- /dev/null +++ b/testsuits/unittest/fuzz/src/time/strptime_fuzz.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +#define STR_LEN 1 +#define MAX_STR_LEN 256 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +int StrptimeFuzzTest(void) +{ + char *str = NULL; + struct tm tm; + + printf("Fuzz test in line [%d] strptime start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "20210304133500"); + (void)strptime(str, "%Y%m%d%H%M%S", &tm); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] strptime ok\n", __LINE__); + + return 0; +} diff --git a/testsuits/unittest/fuzz/src/time/time_fuzz.c b/testsuits/unittest/fuzz/src/time/time_fuzz.c new file mode 100644 index 00000000..3d4153fe --- /dev/null +++ b/testsuits/unittest/fuzz/src/time/time_fuzz.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1024 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void TimeFuzzTest(void) +{ + time_t tloc; + + printf("Fuzz test in line [%d] time start.\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + (void)time(&tloc); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] time ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/fuzz/src/unistd/usleep_fuzz.c b/testsuits/unittest/fuzz/src/unistd/usleep_fuzz.c new file mode 100644 index 00000000..3a45a72c --- /dev/null +++ b/testsuits/unittest/fuzz/src/unistd/usleep_fuzz.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define __NEED_useconds_t +#include +#include "ohos_types.h" +#include "los_config.h" +#include "Public.h" +#include "PCommon.h" +#include "fuzz_posix.h" + +#define CYCLE_TOTAL_TIMES 1000 +#define DEFAULT_USECONDS_VALUE 1 +#define USECONDS_MODE_VALUE 500 +extern S_ElementInit g_element[ELEMENT_LEN]; +extern int g_iteration; + +void UsleepFuzzTest(void) +{ + useconds_t usec; + + printf("Fuzz test in line [%d] usleep start\n", __LINE__); + + INIT_FuzzEnvironment(); + CreatPrecondForQueue(); + + for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + hi_watchdog_feed(); + heartbeatPrint(i); + + usec = (*(useconds_t *)DT_SetGetS64(&g_element[0], DEFAULT_USECONDS_VALUE)) % USECONDS_MODE_VALUE; + (void)usleep(usec); + } + + CleanPrecondForQueue(); + DT_Clear(g_element); + CLOSE_Log(); + CLEAR_FuzzEnvironment(); + + printf("Fuzz test in line [%d] usleep ok\n", __LINE__); + + return; +} diff --git a/testsuits/unittest/posix/src/ctype/ctype_func_test.c b/testsuits/unittest/posix/src/ctype/ctype_func_test.c index b86f764e..0c2faab7 100644 --- a/testsuits/unittest/posix/src/ctype/ctype_func_test.c +++ b/testsuits/unittest/posix/src/ctype/ctype_func_test.c @@ -74,7 +74,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum001, Function | MediumTe { int src = 'A'; int ret = isalnum(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -86,7 +86,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum002, Function | MediumTe { int src = '1'; int ret = isalnum(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -98,7 +98,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum003, Function | MediumTe { int src = '@'; int ret = isalnum(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_EQUAL_INT(0, ret); } /* * @@ -110,7 +110,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum004, Function | MediumTe { int src = ' '; int ret = isalnum(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_EQUAL_INT(0, ret); } /* * @@ -122,7 +122,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum005, Function | MediumTe { int src = '\f'; // 0x0c 14 int ret = isalnum(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_EQUAL_INT(0, ret); } @@ -135,7 +135,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii001, Function | MediumTe { const int src = -1; int ret = isascii(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_EQUAL_INT(0, ret); } /* * @@ -147,7 +147,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii002, Function | MediumTe { const int src = 0; int ret = isascii(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -159,7 +159,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii003, Function | MediumTe { const int src = 127; int ret = isascii(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -171,7 +171,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii004, Function | MediumTe { const int src = 128; int ret = isascii(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_EQUAL_INT(0, ret); } /* * @@ -183,7 +183,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii005, Function | MediumTe { int src = '\f'; // 0x0c 14 int ret = isascii(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -195,7 +195,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint001, Function | MediumTe { int src = 'A'; int ret = isprint(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -207,7 +207,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint002, Function | MediumTe { int src = '1'; int ret = isprint(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -219,7 +219,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint003, Function | MediumTe { int src = '@'; int ret = isprint(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -231,7 +231,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint004, Function | MediumTe { int src = ' '; int ret = isprint(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -243,7 +243,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint005, Function | MediumTe { int src = '\f'; // 0x0c int ret = isprint(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_EQUAL_INT(0, ret); } @@ -256,7 +256,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace001, Function | MediumTe { int src = 'A'; int ret = isspace(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_EQUAL_INT(0, ret); } /* * @@ -268,7 +268,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace002, Function | MediumTe { int src = '1'; int ret = isspace(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_EQUAL_INT(0, ret); } /* * @@ -280,7 +280,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace003, Function | MediumTe { int src = '@'; int ret = isspace(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_EQUAL_INT(0, ret); } /* * @@ -292,7 +292,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace004, Function | MediumTe { int src = ' '; int ret = isspace(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -304,7 +304,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace005, Function | MediumTe { int src = '\t'; int ret = isspace(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } @@ -317,7 +317,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper001, Function | MediumTe { int src = 'A'; int ret = isupper(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -329,7 +329,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper002, Function | MediumTe { int src = 'a'; int ret = isupper(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_EQUAL_INT(0, ret); } /* * @@ -341,7 +341,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper003, Function | MediumTe { const int src = 0x45; int ret = isupper(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -353,7 +353,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper004, Function | MediumTe { int src = ' '; int ret = isupper(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_EQUAL_INT(0, ret); } /* * @@ -365,7 +365,7 @@ LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper005, Function | MediumTe { int src = '\t'; int ret = isupper(src); - TEST_ASSERT_EQUAL_INT(RET_TRUE, ret); + TEST_ASSERT_EQUAL_INT(0, ret); } RUN_TEST_SUITE(PosixCtypeFuncTestSuite); diff --git a/testsuits/unittest/posix/src/ctype/isdigit_test.c b/testsuits/unittest/posix/src/ctype/isdigit_test.c index 9d946da9..20dd3e2f 100644 --- a/testsuits/unittest/posix/src/ctype/isdigit_test.c +++ b/testsuits/unittest/posix/src/ctype/isdigit_test.c @@ -60,7 +60,7 @@ static BOOL PosixCTypeIsdigitTestSetUp(void) */ static BOOL PosixCTypeIsdigitTestTearDown(void) { - printf("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -74,10 +74,10 @@ LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit001, Function | MediumTest int a = '0'; int ret = isdigit(a); if (ret != 0) { - printf("[DEMO] posix ctype test case 1:isdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 1:isdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 1:isdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 1:isdigit(%c) fail.\n", a); } TEST_ASSERT_EQUAL_INT(1, ret); } @@ -92,10 +92,10 @@ LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit002, Function | MediumTest int a = '5'; int ret = isdigit(a); if (ret != 0) { - printf("[DEMO] posix ctype test case 2:isdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 2:isdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 2:isdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 2:isdigit(%c) fail.\n", a); } TEST_ASSERT_EQUAL_INT(1, ret); } @@ -110,10 +110,10 @@ LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit003, Function | MediumTest int a = '9'; int ret = isdigit(a); if (ret != 0) { - printf("[DEMO] posix ctype test case 3:isdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 3:isdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 3:isdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 3:isdigit(%c) fail.\n", a); } TEST_ASSERT_EQUAL_INT(1, ret); } @@ -128,10 +128,10 @@ LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit004, Function | MediumTest int a = '0' - 1; int ret = isdigit(a); if (ret == 0) { - printf("[DEMO] posix ctype test case 4(except):isdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 4(except):isdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 4(except):isdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 4(except):isdigit(%c) fail.\n", a); } TEST_ASSERT_EQUAL_INT(0, ret); } @@ -146,10 +146,10 @@ LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit005, Function | MediumTest int a = '9' + 1; int ret = isdigit(a); if (ret == 0) { - printf("[DEMO] posix ctype test case 5(except):isdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 5(except):isdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 5(except):isdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 5(except):isdigit(%c) fail.\n", a); } TEST_ASSERT_EQUAL_INT(0, ret); } diff --git a/testsuits/unittest/posix/src/ctype/islower_test.c b/testsuits/unittest/posix/src/ctype/islower_test.c index 44456c8a..2eed489d 100644 --- a/testsuits/unittest/posix/src/ctype/islower_test.c +++ b/testsuits/unittest/posix/src/ctype/islower_test.c @@ -60,7 +60,7 @@ static BOOL PosixCTypeIslowerTestSetUp(void) */ static BOOL PosixCTypeIslowerTestTearDown(void) { - printf("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -74,9 +74,9 @@ LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower001, Function | MediumTest int a = 'a'; int ret = islower(a); if (ret != 0) { - printf("[DEMO] posix ctype test case 1:islower(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 1:islower(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 1:islower(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 1:islower(%c) fail.\n", a); } TEST_ASSERT_EQUAL_INT(1, ret); } @@ -91,9 +91,9 @@ LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower002, Function | MediumTest int a = 'z'; int ret = islower(a); if (ret != 0) { - printf("[DEMO] posix ctype test case 2:islower(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 2:islower(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 2:islower(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 2:islower(%c) fail.\n", a); } TEST_ASSERT_EQUAL_INT(1, ret); } @@ -108,9 +108,9 @@ LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower003, Function | MediumTest int a = 'f'; int ret = islower(a); if (ret != 0) { - printf("[DEMO] posix ctype test case 3:islower(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 3:islower(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 3:islower(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 3:islower(%c) fail.\n", a); } TEST_ASSERT_EQUAL_INT(1, ret); } @@ -125,9 +125,9 @@ LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower004, Function | MediumTest int a = 'a' - 1; int ret = islower(a); if (ret == 0) { - printf("[DEMO] posix ctype test case 4(except):islower(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 4(except):islower(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 4(except):islower(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 4(except):islower(%c) fail.\n", a); } TEST_ASSERT_EQUAL_INT(0, ret); } @@ -142,9 +142,9 @@ LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower005, Function | MediumTest int a = 'z' + 1; int ret = islower(a); if (ret == 0) { - printf("[DEMO] posix ctype test case 5(except):islower(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 5(except):islower(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 5(except):islower(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 5(except):islower(%c) fail.\n", a); } TEST_ASSERT_EQUAL_INT(0, ret); } @@ -159,9 +159,9 @@ LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower006, Function | MediumTest int a = 'A'; int ret = islower(a); if (ret == 0) { - printf("[DEMO] posix ctype test case 6(except):islower(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 6(except):islower(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 6(except):islower(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 6(except):islower(%c) fail.\n", a); } TEST_ASSERT_EQUAL_INT(0, ret); } diff --git a/testsuits/unittest/posix/src/ctype/isxdigit_test.c b/testsuits/unittest/posix/src/ctype/isxdigit_test.c index 95ee4442..424f422e 100644 --- a/testsuits/unittest/posix/src/ctype/isxdigit_test.c +++ b/testsuits/unittest/posix/src/ctype/isxdigit_test.c @@ -60,7 +60,7 @@ static BOOL PosixCTypeIsxdigitTestSetUp(void) */ static BOOL PosixCTypeIsxdigitTestTearDown(void) { - printf("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -74,11 +74,11 @@ LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit001, Function | MediumTe int a = '0'; int ret = isxdigit(a); if (ret != 0) { - printf("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a); } - TEST_ASSERT_EQUAL_INT(1, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -91,11 +91,11 @@ LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit002, Function | MediumTe int a = '5'; int ret = isxdigit(a); if (ret != 0) { - printf("[DEMO] posix ctype test case 2:isxdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 2:isxdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 2:isxdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 2:isxdigit(%c) fail.\n", a); } - TEST_ASSERT_EQUAL_INT(1, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -108,11 +108,11 @@ LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit003, Function | MediumTe int a = '9'; int ret = isxdigit(a); if (ret != 0) { - printf("[DEMO] posix ctype test case 3:isxdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 3:isxdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 3:isxdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 3:isxdigit(%c) fail.\n", a); } - TEST_ASSERT_EQUAL_INT(1, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -125,11 +125,11 @@ LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit004, Function | MediumTe int a = 'a'; int ret = isxdigit(a); if (ret != 0) { - printf("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a); } - TEST_ASSERT_EQUAL_INT(1, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -142,11 +142,11 @@ LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit005, Function | MediumTe int a = 'f'; int ret = isxdigit(a); if (ret != 0) { - printf("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a); } - TEST_ASSERT_EQUAL_INT(1, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -159,11 +159,11 @@ LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit006, Function | MediumTe int a = 'A'; int ret = isxdigit(a); if (ret != 0) { - printf("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a); } - TEST_ASSERT_EQUAL_INT(1, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -176,11 +176,11 @@ LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit007, Function | MediumTe int a = 'F'; int ret = isxdigit(a); if (ret != 0) { - printf("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a); } - TEST_ASSERT_EQUAL_INT(1, ret); + TEST_ASSERT_NOT_EQUAL(0, ret); } /* * @@ -193,9 +193,9 @@ LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit008, Function | MediumTe int a = 'F' + 1; int ret = isxdigit(a); if (ret == 0) { - printf("[DEMO] posix ctype test case 5(except):isxdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 5(except):isxdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 5(except):isxdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 5(except):isxdigit(%c) fail.\n", a); } TEST_ASSERT_EQUAL_INT(0, ret); } @@ -210,9 +210,9 @@ LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit009, Function | MediumTe int a = '0' - 1; int ret = isxdigit(a); if (ret == 0) { - printf("[DEMO] posix ctype test case 4(except):isxdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 4(except):isxdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 4(except):isxdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 4(except):isxdigit(%c) fail.\n", a); } TEST_ASSERT_EQUAL_INT(0, ret); } @@ -227,9 +227,9 @@ LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit010, Function | MediumTe int a = '9' + 1; int ret = isxdigit(a); if (ret == 0) { - printf("[DEMO] posix ctype test case 5(except):isxdigit(%c) ok.\n", a); + LOG("[DEMO] posix ctype test case 5(except):isxdigit(%c) ok.\n", a); } else { - printf("[DEMO] posix ctype test case 5(except):isxdigit(%c) fail.\n", a); + LOG("[DEMO] posix ctype test case 5(except):isxdigit(%c) fail.\n", a); } TEST_ASSERT_EQUAL_INT(0, ret); } diff --git a/testsuits/unittest/posix/src/ctype/tolower_test.c b/testsuits/unittest/posix/src/ctype/tolower_test.c index 5a9f69f9..7d35a6b5 100644 --- a/testsuits/unittest/posix/src/ctype/tolower_test.c +++ b/testsuits/unittest/posix/src/ctype/tolower_test.c @@ -60,7 +60,7 @@ static BOOL PosixCTypeTolowerTestSetUp(void) */ static BOOL PosixCTypeTolowerTestTearDown(void) { - printf("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -74,9 +74,9 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower001, Function | MediumTest int a = 'a'; int ret = tolower(a); if (ret == 'a') { - printf("[DEMO] posix ctype test case 1:tolower(%c)==%c ok.\n", a, ret); + LOG("[DEMO] posix ctype test case 1:tolower(%c)==%c ok.\n", a, ret); } else { - printf("[DEMO] posix ctype test case 1:tolower(%c)!=%c fail.\n", a); + LOG("[DEMO] posix ctype test case 1:tolower(%c)!=%c fail.\n", a); } TEST_ASSERT_TRUE(ret == 'a'); } @@ -91,9 +91,9 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower002, Function | MediumTest int a = 'A'; int ret = tolower(a); if (ret == 'a') { - printf("[DEMO] posix ctype test case 2:tolower(%c)==%c ok.\n", a, ret); + LOG("[DEMO] posix ctype test case 2:tolower(%c)==%c ok.\n", a, ret); } else { - printf("[DEMO] posix ctype test case 2:tolower(%c)!=%c fail.\n", a); + LOG("[DEMO] posix ctype test case 2:tolower(%c)!=%c fail.\n", a); } TEST_ASSERT_TRUE(ret == 'a'); } @@ -108,9 +108,9 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower003, Function | MediumTest int a = 'z'; int ret = tolower(a); if (ret == 'z') { - printf("[DEMO] posix ctype test case 3:tolower(%c)==%c ok.\n", a, ret); + LOG("[DEMO] posix ctype test case 3:tolower(%c)==%c ok.\n", a, ret); } else { - printf("[DEMO] posix ctype test case 3:tolower(%c)!=%c fail.\n", a); + LOG("[DEMO] posix ctype test case 3:tolower(%c)!=%c fail.\n", a); } TEST_ASSERT_TRUE(ret == 'z'); } @@ -125,9 +125,9 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower004, Function | MediumTest int a = 'Z'; int ret = tolower(a); if (ret == 'z') { - printf("[DEMO] posix ctype test case 4:tolower(%c)==%c ok.\n", a, ret); + LOG("[DEMO] posix ctype test case 4:tolower(%c)==%c ok.\n", a, ret); } else { - printf("[DEMO] posix ctype test case 4:tolower(%c)!=%c fail.\n", a); + LOG("[DEMO] posix ctype test case 4:tolower(%c)!=%c fail.\n", a); } TEST_ASSERT_TRUE(ret == 'z'); } @@ -142,9 +142,9 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower005, Function | MediumTest int a = '1'; int ret = tolower(a); if (ret == '1') { - printf("[DEMO] posix ctype test case 5(except):tolower(%c)==%c ok.\n", a, ret); + LOG("[DEMO] posix ctype test case 5(except):tolower(%c)==%c ok.\n", a, ret); } else { - printf("[DEMO] posix ctype test case 5(except):tolower(%c)!=%c fail.\n", a); + LOG("[DEMO] posix ctype test case 5(except):tolower(%c)!=%c fail.\n", a); } TEST_ASSERT_TRUE(ret == '1'); } diff --git a/testsuits/unittest/posix/src/ctype/toupper_test.c b/testsuits/unittest/posix/src/ctype/toupper_test.c index d242be24..1da2f490 100644 --- a/testsuits/unittest/posix/src/ctype/toupper_test.c +++ b/testsuits/unittest/posix/src/ctype/toupper_test.c @@ -60,7 +60,7 @@ static BOOL PosixCTypeToupperTestSetUp(void) */ static BOOL PosixCTypeToupperTestTearDown(void) { - printf("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -74,9 +74,9 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper001, Function | MediumTest int a = 'a'; int ret = toupper(a); if (ret == 'A') { - printf("[DEMO] posix ctype test case 1:toupper(%c)==%c ok.\n", a, ret); + LOG("[DEMO] posix ctype test case 1:toupper(%c)==%c ok.\n", a, ret); } else { - printf("[DEMO] posix ctype test case 1:toupper(%c)!=%c fail.\n", a); + LOG("[DEMO] posix ctype test case 1:toupper(%c)!=%c fail.\n", a); } TEST_ASSERT_TRUE(ret == 'A'); } @@ -91,9 +91,9 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper002, Function | MediumTest int a = 'A'; int ret = toupper(a); if (ret == 'A') { - printf("[DEMO] posix ctype test case 2:toupper(%c)==%c ok.\n", a, ret); + LOG("[DEMO] posix ctype test case 2:toupper(%c)==%c ok.\n", a, ret); } else { - printf("[DEMO] posix ctype test case 2:toupper(%c)!=%c fail.\n", a); + LOG("[DEMO] posix ctype test case 2:toupper(%c)!=%c fail.\n", a); } TEST_ASSERT_TRUE(ret == 'A'); } @@ -108,9 +108,9 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper003, Function | MediumTest int a = 'z'; int ret = toupper(a); if (ret == 'Z') { - printf("[DEMO] posix ctype test case 3:toupper(%c)==%c ok.\n", a, ret); + LOG("[DEMO] posix ctype test case 3:toupper(%c)==%c ok.\n", a, ret); } else { - printf("[DEMO] posix ctype test case 3:toupper(%c)!=%c fail.\n", a); + LOG("[DEMO] posix ctype test case 3:toupper(%c)!=%c fail.\n", a); } TEST_ASSERT_TRUE(ret == 'Z'); } @@ -125,9 +125,9 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper004, Function | MediumTest int a = 'Z'; int ret = toupper(a); if (ret == 'Z') { - printf("[DEMO] posix ctype test case 4:toupper(%c)==%c ok.\n", a, ret); + LOG("[DEMO] posix ctype test case 4:toupper(%c)==%c ok.\n", a, ret); } else { - printf("[DEMO] posix ctype test case 4:toupper(%c)!=%c fail.\n", a); + LOG("[DEMO] posix ctype test case 4:toupper(%c)!=%c fail.\n", a); } TEST_ASSERT_TRUE(ret == 'Z'); } @@ -142,9 +142,9 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper005, Function | MediumTest int a = '1'; int ret = toupper(a); if (ret == '1') { - printf("[DEMO] posix ctype test case 5(except):toupper(%c)==%c ok.\n", a, ret); + LOG("[DEMO] posix ctype test case 5(except):toupper(%c)==%c ok.\n", a, ret); } else { - printf("[DEMO] posix ctype test case 5(except):toupper(%c)!=%c fail.\n", a); + LOG("[DEMO] posix ctype test case 5(except):toupper(%c)!=%c fail.\n", a); } TEST_ASSERT_TRUE(ret == '1'); } diff --git a/testsuits/unittest/posix/src/errno/strerror_test.c b/testsuits/unittest/posix/src/errno/strerror_test.c index 18a011f4..ec389710 100644 --- a/testsuits/unittest/posix/src/errno/strerror_test.c +++ b/testsuits/unittest/posix/src/errno/strerror_test.c @@ -37,13 +37,6 @@ #include "kernel_test.h" #include "log.h" -#undef E -#define E(a, b) b "\0" -static const char G_ERRMSG[] = { -#include "__strerror.h" -} -; - /* * * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency * @param : subsystem name is utils @@ -79,19 +72,18 @@ static BOOL PosixSysFuncTestSuiteTearDown(void) */ LITE_TEST_CASE(PosixSysFuncTestSuite, testOsSysStrerror001, Function | MediumTest | Level1) { - for (int i = 0; i < sizeof(G_ERRMSG) / sizeof(G_ERRMSG[0]); i++) { + for (int i = EPERM; i < EHWPOISON; i++) { char *s = strerror(i); TEST_ASSERT_NOT_NULL(s); - TEST_ASSERT_EQUAL_STRING(G_ERRMSG[i], s); - - if (NULL != s) { - printf("Test Result :%s\r\n", s); - } } + LOG("strerror(-1) = %s\n", strerror(-1)); TEST_ASSERT_EQUAL_STRING("No error information", strerror(-1)); + LOG("strerror(0) = %s\n", strerror(0)); TEST_ASSERT_EQUAL_STRING("No error information", strerror(0)); + LOG("strerror(2) = %s\n", strerror(2)); TEST_ASSERT_EQUAL_STRING("No such file or directory", strerror(2)); + LOG("strerror(10) = %s\n", strerror(10)); TEST_ASSERT_EQUAL_STRING("No child process", strerror(10)); }; diff --git a/testsuits/unittest/posix/src/fs/posix_fs_func_test.c b/testsuits/unittest/posix/src/fs/posix_fs_func_test.c new file mode 100644 index 00000000..f4328e13 --- /dev/null +++ b/testsuits/unittest/posix/src/fs/posix_fs_func_test.c @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __NEED_mode_t +#define __NEED_mode_t +#endif + +#include +#include +#include +#include "ohos_types.h" +#include "hctest.h" +#include "los_config.h" +#include "kernel_test.h" +#include "log.h" +#include + +/* * + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is PosixFsFuncTestSuite + */ +LITE_TEST_SUIT(Posix, PosixFs, PosixFsFuncTestSuite); + +/* * + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL PosixFsFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/* * + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL PosixFsFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +#define FILE0 "FILE0" +#define FILE1 "/opt/test/FILE1" +#define DIR1 "/opt/test/DIR1/" + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_001 + * @tc.name dirname basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsDirname001, Function | MediumTest | Level1) +{ + char path[] = FILE0; + char *workDir = dirname((char *)path); + TEST_ASSERT_NOT_NULL(workDir); + TEST_ASSERT_EQUAL_STRING(".", workDir); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_002 + * @tc.name dirname basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsDirname002, Function | MediumTest | Level1) +{ + char path[] = FILE1; + char *workDir = dirname((char *)path); + TEST_ASSERT_NOT_NULL(workDir); + TEST_ASSERT_EQUAL_STRING("/opt/test", workDir); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_003 + * @tc.name dirname basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsDirname003, Function | MediumTest | Level1) +{ + // get dir + char path[] = DIR1; + char *workDir = dirname((char *)path); + TEST_ASSERT_NOT_NULL(workDir); + TEST_ASSERT_EQUAL_STRING("/opt/test", workDir); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_004 + * @tc.name dirname basic function test for special input + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsDirname004, Function | MediumTest | Level1) +{ + // get dir + char *workDir = dirname(""); + TEST_ASSERT_NOT_NULL(workDir); + TEST_ASSERT_EQUAL_STRING(".", workDir); + + workDir = dirname(NULL); + TEST_ASSERT_NOT_NULL(workDir); + TEST_ASSERT_EQUAL_STRING(".", workDir); + + workDir = dirname("/"); + TEST_ASSERT_NOT_NULL(workDir); + TEST_ASSERT_EQUAL_STRING("/", workDir); + + workDir = dirname(".."); + TEST_ASSERT_NOT_NULL(workDir); + TEST_ASSERT_EQUAL_STRING(".", workDir); + + workDir = dirname("."); + TEST_ASSERT_NOT_NULL(workDir); + TEST_ASSERT_EQUAL_STRING(".", workDir); +} + +RUN_TEST_SUITE(PosixFsFuncTestSuite); + + +void PosixFsFuncTest() +{ + LOG("begin PosixFsFuncTest...."); + RUN_ONE_TESTCASE(testFsDirname001); + RUN_ONE_TESTCASE(testFsDirname002); + RUN_ONE_TESTCASE(testFsDirname003); + RUN_ONE_TESTCASE(testFsDirname004); + + return; +} \ No newline at end of file diff --git a/testsuits/unittest/posix/src/log.h b/testsuits/unittest/posix/src/log.h index 98af94b6..8cfb30dc 100644 --- a/testsuits/unittest/posix/src/log.h +++ b/testsuits/unittest/posix/src/log.h @@ -32,6 +32,9 @@ #ifndef TEST_LOG #define TEST_LOG +// define if need print debug info +#define DEBUG_LOG_OUT + #include #include @@ -39,7 +42,11 @@ extern "C" { #endif -#define LOG(fmt, args...) PRINT_EMG(fmt, ##args) +#ifdef DEBUG_LOG_OUT + #define LOG printf +#else + #define LOG(...) +#endif #ifdef __cplusplus } diff --git a/testsuits/unittest/posix/src/math/math_func_test.c b/testsuits/unittest/posix/src/math/math_func_test.c index b0d8adc2..98a78ffe 100644 --- a/testsuits/unittest/posix/src/math/math_func_test.c +++ b/testsuits/unittest/posix/src/math/math_func_test.c @@ -35,7 +35,7 @@ #include "hctest.h" #include "los_config.h" #include "kernel_test.h" -#include "los_debug.h" +#include "log.h" #define RET_OK 0 #define TEST_VALUE_X 0 @@ -89,7 +89,7 @@ static BOOL PosixMathFuncTestSuiteSetUp(void) */ static BOOL PosixMathFuncTestSuiteTearDown(void) { - PRINT_EMG("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -106,7 +106,7 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathAbs001, Function | MediumTest | L int ret; for (int i = 0; i < testCount; ++i) { ret = abs(testValues[i]); - PRINT_EMG("\n [POSIXTEST][abs]abs(%d) = %d, expected is %d", testValues[i], ret, expected[i]); + LOG("\n [POSIXTEST][abs]abs(%d) = %d, expected is %d", testValues[i], ret, expected[i]); TEST_ASSERT_EQUAL_INT(expected[i], ret); } }; @@ -124,7 +124,7 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathAbs002, Function | MediumTest | L int ret; for (int i = 0; i < testCount; ++i) { ret = abs(testValues[i]); - PRINT_EMG("\n [POSIXTEST][abs]abs(%d) = %d, expected is %d", testValues[i], ret, expected[i]); + LOG("\n [POSIXTEST][abs]abs(%d) = %d, expected is %d", testValues[i], ret, expected[i]); TEST_ASSERT_EQUAL_INT(expected[i], ret); } }; @@ -140,9 +140,11 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathLog001, Function | MediumTest | L double testValues[] = { 0.5, 5.5, 1}; double expected[] = { -0.69314718055994528623, 1.70474809223842527217, 0.00000000000000000000}; double ret; + PRINT_EMG("GZHTESTLOG PRINT_EMG: %f, %f, %f", testValues[0], testValues[1], testValues[2]); + LOG("GZHTESTLOG LOG: %f, %f, %f", testValues[0], testValues[1], testValues[2]); for (int i = 0; i < testCount; ++i) { ret = log(testValues[i]); - PRINT_EMG("\n [POSIXTEST][log]log(%f) = %f, expected is %f", testValues[i], ret, expected[i]); + LOG("\n [POSIXTEST][log]log(%f) = %f, expected is %f", testValues[i], ret, expected[i]); TEST_ASSERT_EQUAL_FLOAT(expected[i], ret); TEST_ASSERT_TRUE(DoubleEquals(expected[i], ret)); } @@ -160,12 +162,12 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathLog002, Function | MediumTest | L double expected[] = { -INFINITY, NAN, NAN, NAN}; double ret; - PRINT_EMG("\n (math_errhandling & MATH_ERRNO) = %d", (math_errhandling & MATH_ERRNO)); - PRINT_EMG("\n (math_errhandling & MATH_ERREXCEPT) = %d", (math_errhandling & MATH_ERREXCEPT)); + LOG("\n (math_errhandling & MATH_ERRNO) = %d", (math_errhandling & MATH_ERRNO)); + LOG("\n (math_errhandling & MATH_ERREXCEPT) = %d", (math_errhandling & MATH_ERREXCEPT)); for (int i = 0; i < testCount; ++i) { ret = log(testValues[i]); - PRINT_EMG("\n [POSIXTEST][log]log(%f) = %f, expected is %f", testValues[i], ret, expected[i]); + LOG("\n [POSIXTEST][log]log(%f) = %f, expected is %f", testValues[i], ret, expected[i]); TEST_ASSERT_EQUAL_FLOAT(expected[i], ret); } }; @@ -183,7 +185,7 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathSqrt001, Function | MediumTest | double ret; for (int i = 0; i < testCount; ++i) { ret = sqrt(testValues[i]); - PRINT_EMG("\n [POSIXTEST][sqrt]sqrt(%f) = %f, expected is %f", testValues[i], ret, expected[i]); + LOG("\n [POSIXTEST][sqrt]sqrt(%f) = %f, expected is %f", testValues[i], ret, expected[i]); TEST_ASSERT_EQUAL_FLOAT(expected[i], ret); TEST_ASSERT_TRUE(DoubleEquals(expected[i], ret)); } @@ -202,7 +204,7 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathSqrt002, Function | MediumTest | double ret; for (int i = 0; i < testCount; ++i) { ret = sqrt(testValues[i]); - PRINT_EMG("\n [POSIXTEST][sqrt]sqrt(%f) = %f, expected is %f", testValues[i], ret, expected[i]); + LOG("\n [POSIXTEST][sqrt]sqrt(%f) = %f, expected is %f", testValues[i], ret, expected[i]); TEST_ASSERT_EQUAL_FLOAT(expected[i], ret); } }; @@ -225,7 +227,7 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow001, Function | MediumTest | L double ret; for (int i = 0; i < testCount; ++i) { ret = pow(testValues[i][TEST_VALUE_X], testValues[i][TEST_VALUE_Y]); - PRINT_EMG("\n [POSIXTEST][pow]pow1(%f,%f) = %f, expected is %f", testValues[i][TEST_VALUE_X], + LOG("\n [POSIXTEST][pow]pow1(%f,%f) = %f, expected is %f", testValues[i][TEST_VALUE_X], testValues[i][TEST_VALUE_Y], ret, testValues[i][TEST_EXPECTED]); TEST_ASSERT_EQUAL_FLOAT(testValues[i][TEST_EXPECTED], ret); TEST_ASSERT_TRUE(DoubleEquals(testValues[i][TEST_EXPECTED], ret)); @@ -261,7 +263,7 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow002, Function | MediumTest | L ret = pow(testValues[i][TEST_VALUE_X], testValues[i][TEST_VALUE_Y]); TEST_ASSERT_EQUAL_FLOAT(testValues[i][TEST_EXPECTED], ret); TEST_ASSERT_TRUE(DoubleEquals(testValues[i][TEST_EXPECTED], ret)); - PRINT_EMG("\n [POSIXTEST][pow]pow1(%f,%f) = %f, expected is %f", testValues[i][TEST_VALUE_X], + LOG("\n [POSIXTEST][pow]pow1(%f,%f) = %f, expected is %f", testValues[i][TEST_VALUE_X], testValues[i][TEST_VALUE_Y], ret, testValues[i][TEST_EXPECTED]); } }; @@ -274,8 +276,8 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow002, Function | MediumTest | L LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow003, Function | MediumTest | Level1) { double testValues[][TEST_EXPECTED + 1] = { - {0.0, -7, HUGE_VAL}, - {-0.0, -6.22, HUGE_VAL}, + {0.0, -7, -HUGE_VAL}, + {-0.0, -6.22, -HUGE_VAL}, {-7.23, 3.57, NAN}, {121223, 5674343, HUGE_VAL} }; @@ -285,7 +287,7 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow003, Function | MediumTest | L for (int i = 0; i < testCount; ++i) { ret = pow(testValues[i][TEST_VALUE_X], testValues[i][TEST_VALUE_Y]); TEST_ASSERT_EQUAL_FLOAT(testValues[i][TEST_EXPECTED], ret); - PRINT_EMG("\n [POSIXTEST][pow]pow1(%f,%f) = %f, expected is %f", testValues[i][TEST_VALUE_X], + LOG("\n [POSIXTEST][pow]pow1(%f,%f) = %f, expected is %f", testValues[i][TEST_VALUE_X], testValues[i][TEST_VALUE_Y], ret, testValues[i][TEST_EXPECTED]); TEST_ASSERT_TRUE(DoubleEquals(testValues[i][TEST_EXPECTED], ret)); } @@ -305,7 +307,7 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathRound001, Function | MediumTest | double ret; for (int i = 0; i < testCount; ++i) { ret = round(testValues[i]); - PRINT_EMG("\n [POSIXTEST][round]round1(%f) = %f, expected is %f", testValues[i], ret, expected[i]); + LOG("\n [POSIXTEST][round]round1(%f) = %f, expected is %f", testValues[i], ret, expected[i]); TEST_ASSERT_EQUAL_FLOAT(expected[i], ret); TEST_ASSERT_TRUE(DoubleEquals(expected[i], ret)); } @@ -324,36 +326,17 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathRound002, Function | MediumTest | double ret; for (int i = 0; i < testCount; ++i) { ret = round(testValues[i]); - PRINT_EMG("\n [POSIXTEST][round]round1(%f) = %f, expected is %f", testValues[i], ret, expected[i]); + LOG("\n [POSIXTEST][round]round1(%f) = %f, expected is %f", testValues[i], ret, expected[i]); TEST_ASSERT_EQUAL_FLOAT(expected[i], ret); TEST_ASSERT_TRUE(DoubleEquals(expected[i], ret)); } }; -/* * - * @tc.number SUB_KERNEL_MATH_ROUND_002 - * @tc.name round basic function test - * @tc.desc [C- SOFTWARE -0100] - */ -LITE_TEST_CASE(PosixMathFuncTestSuite, testMathRound003, Function | MediumTest | Level1) -{ - double testValues[] = { NAN, -INFINITY, INFINITY, 0}; - double expected[] = { NAN, -INFINITY, INFINITY, 0.00000000000000000000}; - const int testCount = sizeof(testValues) / sizeof(double); - double ret; - for (int i = 0; i < testCount; ++i) { - ret = round(testValues[i]); - PRINT_EMG("\n [POSIXTEST][round]round1_fortest(%f) = %f, expected is %f", testValues[i], ret, expected[i]); - TEST_ASSERT_EQUAL_FLOAT(expected[i], ret); - TEST_ASSERT_FALSE(DoubleEquals(expected[i], ret)); - } -}; - RUN_TEST_SUITE(PosixMathFuncTestSuite); void PosixMathFuncTest() { - PRINT_EMG("begin PosixMathFuncTest...."); + LOG("begin PosixMathFuncTest...."); RUN_ONE_TESTCASE(testMathAbs001); RUN_ONE_TESTCASE(testMathAbs002); RUN_ONE_TESTCASE(testMathLog001); @@ -365,7 +348,6 @@ void PosixMathFuncTest() RUN_ONE_TESTCASE(testMathPow003); RUN_ONE_TESTCASE(testMathRound001); RUN_ONE_TESTCASE(testMathRound002); - RUN_ONE_TESTCASE(testMathRound003); return; } \ No newline at end of file diff --git a/testsuits/unittest/posix/src/regex/regex_func_test.c b/testsuits/unittest/posix/src/regex/regex_func_test.c index f9babb91..19323b6a 100644 --- a/testsuits/unittest/posix/src/regex/regex_func_test.c +++ b/testsuits/unittest/posix/src/regex/regex_func_test.c @@ -32,9 +32,9 @@ #include "ohos_types.h" #include "hctest.h" #include "los_config.h" -#include "los_debug.h" #include "kernel_test.h" #include +#include "log.h" #define EQUAL 0 @@ -52,9 +52,9 @@ LITE_TEST_SUIT(Posix, PosixRegexTest, PosixRegexFuncTestSuite); */ static BOOL PosixRegexFuncTestSuiteSetUp(void) { - PRINT_EMG("+-------------------------------------------+\n"); - PRINT_EMG("+--------PosixRegexFuncTestSuiteSetUp-------+\n"); - PRINT_EMG("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); + LOG("+--------PosixRegexFuncTestSuiteSetUp-------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -64,9 +64,9 @@ static BOOL PosixRegexFuncTestSuiteSetUp(void) */ static BOOL PosixRegexFuncTestSuiteTearDown(void) { - PRINT_EMG("+-------------------------------------------+\n"); - PRINT_EMG("+-------PosixRegexFuncTestSuiteTearDown-----+\n"); - PRINT_EMG("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); + LOG("+-------PosixRegexFuncTestSuiteTearDown-----+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -81,16 +81,16 @@ void TestRegex(int flag, const char *pattern, const char *buf, const int expecte int status = regexec(®, buf, nmatch, pmatch, 0); TEST_ASSERT_EQUAL_INT(status, expectedStatus); if (status == REG_NOMATCH) { - PRINT_EMG("no match"); + LOG("no match"); } else if (status == 0) { - PRINT_EMG("Match:"); + LOG("Match:"); for (int i = pmatch[0].rm_so; i < pmatch[0].rm_eo; i++) { putchar(buf[i]); res[j] = buf[i]; j++; } res[j] = 0; - PRINT_EMG("\n"); + LOG("\n"); TEST_ASSERT_EQUAL_STRING(res, expectedRes); } regfree(®); @@ -100,7 +100,7 @@ void TestRegcomp(int flag, const char *pattern, const int expectedStatus) { regex_t reg; int status = regcomp(®, pattern, flag); - PRINT_EMG("pattern : %s ,real status : %d \n", pattern, status); + LOG("pattern : %s ,real status : %d \n", pattern, status); TEST_ASSERT_EQUAL_INT(status, expectedStatus); regfree(®); } @@ -180,7 +180,7 @@ RUN_TEST_SUITE(PosixRegexFuncTestSuite); void PosixRegexFuncTest() { - PRINT_EMG("begin PosixRegexFuncTest...."); + LOG("begin PosixRegexFuncTest...."); RUN_ONE_TESTCASE(testRegexExtended001); RUN_ONE_TESTCASE(testRegexIcase001); RUN_ONE_TESTCASE(testRegexNewline001); diff --git a/testsuits/unittest/posix/src/semaphore/semaphore_func_test.c b/testsuits/unittest/posix/src/semaphore/semaphore_func_test.c index 6a22f160..9dc767b6 100644 --- a/testsuits/unittest/posix/src/semaphore/semaphore_func_test.c +++ b/testsuits/unittest/posix/src/semaphore/semaphore_func_test.c @@ -71,12 +71,14 @@ static BOOL PosixSemaphoreFuncTestSuiteTearDown(void) // get cur-time plus ms struct timespec GetDelayedTime(unsigned int ms) { + LOG("GetDelayedTime ms = %lu", ms); struct timespec ts = { 0 }; const unsigned int nsecPerSec = 1000000000; const unsigned int nsecPerMs = 1000000; - unsigned int setTimeNs = ms * nsecPerMs; + unsigned long long setTimeNs = ms * nsecPerMs; struct timespec tsNow = { 0 }; clock_gettime(CLOCK_REALTIME, &tsNow); + LOG("Cur time tv_sec: %lld, tv_nsec: %ld", tsNow.tv_sec, tsNow.tv_nsec); ts.tv_sec = tsNow.tv_sec + (tsNow.tv_nsec + setTimeNs) / nsecPerSec; ts.tv_nsec = (tsNow.tv_nsec + setTimeNs) % nsecPerSec; return ts; @@ -85,10 +87,11 @@ struct timespec GetDelayedTime(unsigned int ms) // calculate time difference, in ms int GetTimeDiff(struct timespec ts1, struct timespec ts2) { - const unsigned int nsecPerSec = 1000000000; - const unsigned int nsecPerMs = 1000000; + const int nsecPerSec = 1000000000; + const int nsecPerMs = 1000000; int ms = (ts1.tv_sec - ts2.tv_sec) * nsecPerSec + (ts1.tv_nsec - ts2.tv_nsec); ms = ms / nsecPerMs; + LOG("different result: %ld (ms)", ms); return ms; } @@ -107,7 +110,7 @@ LITE_TEST_CASE(PosixSemaphoreFuncTestSuite, testIpcSem_Timedwait001, Function | TEST_ASSERT_EQUAL_INT(0, sem_init((sem_t *)&sem, 0, 0)); ts = GetDelayedTime(100); - LOG("\n ts %d, %d", ts.tv_sec, ts.tv_nsec); + LOG("predicted time:%lld, %d", ts.tv_sec, ts.tv_nsec); if (sem_timedwait((sem_t *)&sem, &ts) == -1) { TEST_ASSERT_EQUAL_INT(ETIMEDOUT, errno); } else { @@ -115,11 +118,10 @@ LITE_TEST_CASE(PosixSemaphoreFuncTestSuite, testIpcSem_Timedwait001, Function | } clock_gettime(CLOCK_REALTIME, &tsNow); - LOG("\n tsNow %d, %d", tsNow.tv_sec, tsNow.tv_nsec); + LOG("tsNow %lld, %d", tsNow.tv_sec, tsNow.tv_nsec); int timeDiff = GetTimeDiff(tsNow, ts); // calculate time different - LOG("\n timeDiff %d", timeDiff); - TEST_ASSERT_GREATER_THAN_INT(0, timeDiff); - TEST_ASSERT_LESS_THAN_INT(20, timeDiff); + LOG("timeDiff %d", timeDiff); + TEST_ASSERT_LESS_THAN_INT(20, abs(timeDiff)); TEST_ASSERT_EQUAL_INT(0, sem_destroy((sem_t *)&sem)); } @@ -140,7 +142,7 @@ LITE_TEST_CASE(PosixSemaphoreFuncTestSuite, testIpcSem_Timedwait002, Function | TEST_ASSERT_EQUAL_INT(0, sem_init((sem_t *)&sem, 0, 1)); ts = GetDelayedTime(100); - LOG("\n ts %d, %d", ts.tv_sec, ts.tv_nsec); + LOG("\n ts %lld, %d", ts.tv_sec, ts.tv_nsec); clock_gettime(CLOCK_REALTIME, &tsBegin); int ret = sem_timedwait((sem_t *)&sem, &ts); clock_gettime(CLOCK_REALTIME, &tsNow); diff --git a/testsuits/unittest/posix/src/stdlib/atoi_test.c b/testsuits/unittest/posix/src/stdlib/atoi_test.c index a4f40cc9..e8f2f3a3 100644 --- a/testsuits/unittest/posix/src/stdlib/atoi_test.c +++ b/testsuits/unittest/posix/src/stdlib/atoi_test.c @@ -61,7 +61,7 @@ static BOOL PosixStdlibAtoiTestSetUp(void) */ static BOOL PosixStdlibAtoiTestTearDown(void) { - printf("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -74,9 +74,9 @@ LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi001, Function | MediumTest | L { int value = atoi("2147483647"); if (value == 2147483647) { - printf("[DEMO] posix stdlib test case 1:atoi(%d) ok.\n", value); + LOG("[DEMO] posix stdlib test case 1:atoi(%d) ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 1:atoi(%d) fail.\n", value); + LOG("[DEMO] posix stdlib test case 1:atoi(%d) fail.\n", value); } TEST_ASSERT_EQUAL_INT(2147483647, value); } @@ -90,9 +90,9 @@ LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi002, Function | MediumTest | L { int value = atoi("-2147483648"); if (value == -2147483648) { - printf("[DEMO] posix stdlib test case 2:atoi(%d) ok.\n", value); + LOG("[DEMO] posix stdlib test case 2:atoi(%d) ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 2:atoi(%d) fail.\n", value); + LOG("[DEMO] posix stdlib test case 2:atoi(%d) fail.\n", value); } TEST_ASSERT_EQUAL_INT(-2147483648, value); } @@ -106,9 +106,9 @@ LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi003, Function | MediumTest | L { int value = atoi("100"); if (value == 100) { - printf("[DEMO] posix stdlib test case 3:atoi(%d) ok.\n", value); + LOG("[DEMO] posix stdlib test case 3:atoi(%d) ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 3:atoi(%d) fail.\n", value); + LOG("[DEMO] posix stdlib test case 3:atoi(%d) fail.\n", value); } TEST_ASSERT_EQUAL_INT(100, value); } @@ -122,9 +122,9 @@ LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi004, Function | MediumTest | L { int value = atoi("2147483648"); if (value == -2147483648) { - printf("[DEMO] posix stdlib test case 4(except):atoi(%d) != 2147483648 ok.\n", value); + LOG("[DEMO] posix stdlib test case 4(except):atoi(%d) != 2147483648 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 4(except):atoi(%d) fail.\n", value); + LOG("[DEMO] posix stdlib test case 4(except):atoi(%d) fail.\n", value); } TEST_ASSERT_EQUAL_INT(-2147483648, value); } @@ -138,9 +138,9 @@ LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi005, Function | MediumTest | L { int value = atoi("-2147483649"); if (value == 2147483647) { - printf("[DEMO] posix stdlib test case 5(except):atoi(%d) != -2147483649 ok.\n", value); + LOG("[DEMO] posix stdlib test case 5(except):atoi(%d) != -2147483649 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 5(except):atoi(%d) fail.\n", value); + LOG("[DEMO] posix stdlib test case 5(except):atoi(%d) fail.\n", value); } TEST_ASSERT_EQUAL_INT(2147483647, value); } @@ -154,9 +154,9 @@ LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi006, Function | MediumTest | L { int value = atoi("+100"); if (value == 100) { - printf("[DEMO] posix stdlib test case 6:atoi(%d) == +100 ok.\n", value); + LOG("[DEMO] posix stdlib test case 6:atoi(%d) == +100 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 6:atoi(%d) fail.\n", value); + LOG("[DEMO] posix stdlib test case 6:atoi(%d) fail.\n", value); } TEST_ASSERT_EQUAL_INT(100, value); } @@ -170,9 +170,9 @@ LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi007, Function | MediumTest | L { int value = atoi("-100"); if (value == -100) { - printf("[DEMO] posix stdlib test case 7:atoi(%d) == -100 ok.\n", value); + LOG("[DEMO] posix stdlib test case 7:atoi(%d) == -100 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 7:atoi(%d) fail.\n", value); + LOG("[DEMO] posix stdlib test case 7:atoi(%d) fail.\n", value); } TEST_ASSERT_EQUAL_INT(-100, value); } @@ -186,9 +186,9 @@ LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi008, Function | MediumTest | L { int value = atoi("+-100"); if (value == 0) { - printf("[DEMO] posix stdlib test case 8(except):atoi(%d) == +-100 ok.\n", value); + LOG("[DEMO] posix stdlib test case 8(except):atoi(%d) == +-100 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 8(except):atoi(%d) fail.\n", value); + LOG("[DEMO] posix stdlib test case 8(except):atoi(%d) fail.\n", value); } TEST_ASSERT_EQUAL_INT(0, value); } @@ -202,9 +202,9 @@ LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi009, Function | MediumTest | L { int value = atoi("12+-100"); if (value == 12) { - printf("[DEMO] posix stdlib test case 9(except):atoi(%d) ok == 12+-100.\n", value); + LOG("[DEMO] posix stdlib test case 9(except):atoi(%d) ok == 12+-100.\n", value); } else { - printf("[DEMO] posix stdlib test case 9(except):atoi(%d) fail.\n", value); + LOG("[DEMO] posix stdlib test case 9(except):atoi(%d) fail.\n", value); } TEST_ASSERT_EQUAL_INT(12, value); } @@ -218,9 +218,9 @@ LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi010, Function | MediumTest | L { int value = atoi("21474836470"); if (value == -10) { - printf("[DEMO] posix stdlib test case 10(except):atoi(%d) ok == 21474836470.\n", value); + LOG("[DEMO] posix stdlib test case 10(except):atoi(%d) ok == 21474836470.\n", value); } else { - printf("[DEMO] posix stdlib test case 10(except):atoi(%d) fail.\n", value); + LOG("[DEMO] posix stdlib test case 10(except):atoi(%d) fail.\n", value); } TEST_ASSERT_EQUAL_INT(-10, value); } diff --git a/testsuits/unittest/posix/src/stdlib/atol_test.c b/testsuits/unittest/posix/src/stdlib/atol_test.c index 8cb512a6..1918b83f 100644 --- a/testsuits/unittest/posix/src/stdlib/atol_test.c +++ b/testsuits/unittest/posix/src/stdlib/atol_test.c @@ -61,7 +61,7 @@ static BOOL PosixStdlibAtolTestSetUp(void) */ static BOOL PosixStdlibAtolTestTearDown(void) { - printf("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -74,9 +74,9 @@ LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol001, Function | MediumTest | L { const long value = atol("2147483647"); if (value == 2147483647) { - printf("[DEMO] posix stdlib test case 1:atol(%ld) ok.\n", value); + LOG("[DEMO] posix stdlib test case 1:atol(%ld) ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 1:atol(%ld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 1:atol(%ld) fail.\n", value); } TEST_ASSERT_EQUAL_INT32(2147483647, value); } @@ -90,9 +90,9 @@ LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol002, Function | MediumTest | L { const long value = atol("-2147483648"); if (value == -2147483648) { - printf("[DEMO] posix stdlib test case 2:atol(%ld) ok.\n", value); + LOG("[DEMO] posix stdlib test case 2:atol(%ld) ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 2:atol(%ld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 2:atol(%ld) fail.\n", value); } TEST_ASSERT_EQUAL_INT32(-2147483648, value); } @@ -106,9 +106,9 @@ LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol003, Function | MediumTest | L { const long value = atol("100"); if (value == 100) { - printf("[DEMO] posix stdlib test case 3:atol(%ld) ok.\n", value); + LOG("[DEMO] posix stdlib test case 3:atol(%ld) ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 3:atol(%ld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 3:atol(%ld) fail.\n", value); } TEST_ASSERT_EQUAL_INT32(100, value); } @@ -122,9 +122,9 @@ LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol004, Function | MediumTest | L { const long value = atol("2147483648"); if (value != 2147483648) { - printf("[DEMO] posix stdlib test case 4(except):atol(%ld) != 2147483648 ok.\n", value); + LOG("[DEMO] posix stdlib test case 4(except):atol(%ld) != 2147483648 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 4(except):atol(%ld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 4(except):atol(%ld) fail.\n", value); } TEST_ASSERT_EQUAL_INT32(-2147483648, value); } @@ -138,9 +138,9 @@ LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol005, Function | MediumTest | L { const long value = atol("-2147483649"); if (value == 2147483647) { - printf("[DEMO] posix stdlib test case 5(except):atoi(%d) != -2147483649 ok.\n", value); + LOG("[DEMO] posix stdlib test case 5(except):atoi(%d) != -2147483649 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 5(except):atoi(%d) fail.\n", value); + LOG("[DEMO] posix stdlib test case 5(except):atoi(%d) fail.\n", value); } TEST_ASSERT_EQUAL_INT32(2147483647, value); } @@ -154,9 +154,9 @@ LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol006, Function | MediumTest | L { const long value = atol("+100"); if (value == 100) { - printf("[DEMO] posix stdlib test case 6:atol(%ld) == +100 ok.\n", value); + LOG("[DEMO] posix stdlib test case 6:atol(%ld) == +100 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 6:atol(%ld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 6:atol(%ld) fail.\n", value); } TEST_ASSERT_EQUAL_INT32(100, value); } @@ -170,9 +170,9 @@ LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol007, Function | MediumTest | L { const long value = atol("-100"); if (value == -100) { - printf("[DEMO] posix stdlib test case 7:atol(%ld) == -100 ok.\n", value); + LOG("[DEMO] posix stdlib test case 7:atol(%ld) == -100 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 7:atoi(%ld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 7:atoi(%ld) fail.\n", value); } TEST_ASSERT_EQUAL_INT32(-100, value); } @@ -186,9 +186,9 @@ LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol008, Function | MediumTest | L { long value = atol("+-100"); if (value == 0) { - printf("[DEMO] posix stdlib test case 8(except):atol(%ld) == +-100 ok.\n", value); + LOG("[DEMO] posix stdlib test case 8(except):atol(%ld) == +-100 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 8(except):atol(%ld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 8(except):atol(%ld) fail.\n", value); } TEST_ASSERT_EQUAL_INT32(0, value); } @@ -202,9 +202,9 @@ LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol009, Function | MediumTest | L { long value = atol("12+-100"); if (value == 12) { - printf("[DEMO] posix stdlib test case 9(except):atol(%ld) ok == 12+-100.\n", value); + LOG("[DEMO] posix stdlib test case 9(except):atol(%ld) ok == 12+-100.\n", value); } else { - printf("[DEMO] posix stdlib test case 9(except):atol(%ld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 9(except):atol(%ld) fail.\n", value); } TEST_ASSERT_EQUAL_INT32(12, value); } diff --git a/testsuits/unittest/posix/src/stdlib/atoll_test.c b/testsuits/unittest/posix/src/stdlib/atoll_test.c index 14224e67..7e66dcd7 100644 --- a/testsuits/unittest/posix/src/stdlib/atoll_test.c +++ b/testsuits/unittest/posix/src/stdlib/atoll_test.c @@ -34,6 +34,7 @@ #include "los_config.h" #include "kernel_test.h" #include "ctype.h" +#include "limits.h" #include "stdlib.h" #include "string.h" #include "log.h" @@ -61,7 +62,7 @@ static BOOL PosixStdlibAtollTestSetUp(void) */ static BOOL PosixStdlibAtollTestTearDown(void) { - printf("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -74,9 +75,9 @@ LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll001, Function | MediumTest | { long long value = atoll("9223372036854775807"); if (value == 9223372036854775807LL) { - printf("[DEMO] posix stdlib test case 1:atoll(%lld) ok.\n", value); + LOG("[DEMO] posix stdlib test case 1:atoll(%lld) ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 1:atoll(%lld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 1:atoll(%lld) fail.\n", value); } TEST_ASSERT_TRUE(value == 9223372036854775807LL); } @@ -90,9 +91,9 @@ LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll002, Function | MediumTest | { long long value = atoll("-9223372036854775808"); if (value == -9223372036854775808LL) { - printf("[DEMO] posix stdlib test case 2:atoll(%lld) ok.\n", value); + LOG("[DEMO] posix stdlib test case 2:atoll(%lld) ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 2:atoll(%lld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 2:atoll(%lld) fail.\n", value); } TEST_ASSERT_TRUE(value == -9223372036854775808LL); } @@ -106,9 +107,9 @@ LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll003, Function | MediumTest | { long long value = atoll("100"); if (value == 100LL) { - printf("[DEMO] posix stdlib test case 3:atoll(%lld) ok.\n", value); + LOG("[DEMO] posix stdlib test case 3:atoll(%lld) ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 3:atoll(%lld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 3:atoll(%lld) fail.\n", value); } TEST_ASSERT_TRUE(value == 100LL); } @@ -122,11 +123,11 @@ LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll004, Function | MediumTest | { long long value = atoll("9223372036854775808"); if (value == -9223372036854775808LL) { - printf("[DEMO] posix stdlib test case 4(except):atoll(%lld) != 9223372036854775808 ok.\n", value); + LOG("[DEMO] posix stdlib test case 4(except):atoll(%lld) != 9223372036854775808 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 4(except):atoll(%lld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 4(except):atoll(%lld) fail.\n", value); } - TEST_ASSERT_TRUE(value == -9223372036854775808LL); + TEST_ASSERT_EQUAL_INT64(LLONG_MIN, value); } /* * @@ -138,11 +139,12 @@ LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll005, Function | MediumTest | { long long value = atoll("-9223372036854775809"); if (value == 9223372036854775807LL) { - printf("[DEMO] posix stdlib test case 5(except):atoll(%lld) != -9223372036854775809 ok.\n", value); + LOG("[DEMO] posix stdlib test case 5(except):atoll(%lld) != -9223372036854775809 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 5(except):atoll(%lld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 5(except):atoll(%lld) fail.\n", value); } - TEST_ASSERT_TRUE(value == 9223372036854775807LL); + + TEST_ASSERT_EQUAL_INT64(LLONG_MAX, value); } /* * @@ -154,9 +156,9 @@ LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll006, Function | MediumTest | { long long value = atoll("+100"); if (value == 100LL) { - printf("[DEMO] posix stdlib test case 6:atoll(%lld) == +100 ok.\n", value); + LOG("[DEMO] posix stdlib test case 6:atoll(%lld) == +100 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 6:atoll(%lld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 6:atoll(%lld) fail.\n", value); } TEST_ASSERT_TRUE(value == 100LL); } @@ -170,9 +172,9 @@ LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll007, Function | MediumTest | { long long value = atoll("-100"); if (value == -100LL) { - printf("[DEMO] posix stdlib test case 7:atoll(%lld) == -100 ok.\n", value); + LOG("[DEMO] posix stdlib test case 7:atoll(%lld) == -100 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 7:atoll(%lld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 7:atoll(%lld) fail.\n", value); } TEST_ASSERT_TRUE(value == -100LL); } @@ -186,9 +188,9 @@ LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll008, Function | MediumTest | { long long value = atoll("+-100"); if (value == 0LL) { - printf("[DEMO] posix stdlib test case 8(except):atoll(%lld) == +-100 ok.\n", value); + LOG("[DEMO] posix stdlib test case 8(except):atoll(%lld) == +-100 ok.\n", value); } else { - printf("[DEMO] posix stdlib test case 8(except):atoll(%lld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 8(except):atoll(%lld) fail.\n", value); } TEST_ASSERT_TRUE(value == 0LL); } @@ -202,9 +204,9 @@ LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll009, Function | MediumTest | { long long value = atoll("12+-100"); if (value == 12LL) { - printf("[DEMO] posix stdlib test case 9(except):atoll(%lld) ok == 12+-100.\n", value); + LOG("[DEMO] posix stdlib test case 9(except):atoll(%lld) ok == 12+-100.\n", value); } else { - printf("[DEMO] posix stdlib test case 9(except):atoll(%lld) fail.\n", value); + LOG("[DEMO] posix stdlib test case 9(except):atoll(%lld) fail.\n", value); } TEST_ASSERT_TRUE(value == 12LL); } diff --git a/testsuits/unittest/posix/src/stdlib/strtol_test.c b/testsuits/unittest/posix/src/stdlib/strtol_test.c index 66a947f9..3f8d1303 100644 --- a/testsuits/unittest/posix/src/stdlib/strtol_test.c +++ b/testsuits/unittest/posix/src/stdlib/strtol_test.c @@ -61,7 +61,7 @@ static BOOL PosixStdlibStrtolTestSetUp(void) */ static BOOL PosixStdlibStrtolTestTearDown(void) { - printf("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -76,9 +76,9 @@ LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol001, Function | MediumTest char *endPtr16 = NULL; long ret = strtol(nPtr16, &endPtr16, 16); if (ret == 16) { - printf("[DEMO] posix stdlib test case 1:strtol(base=16) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr16, endPtr16); + LOG("[DEMO] posix stdlib test case 1:strtol(base=16) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr16, endPtr16); } else { - printf("[DEMO] posix stdlib test case 1:strtol(base=16) ret:%ld,%s fail.\n", ret, nPtr16); + LOG("[DEMO] posix stdlib test case 1:strtol(base=16) ret:%ld,%s fail.\n", ret, nPtr16); } TEST_ASSERT_EQUAL_INT32(16, ret); TEST_ASSERT_EQUAL_STRING(endPtr16, ""); @@ -95,9 +95,9 @@ LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol002, Function | MediumTest char *endPtr16 = NULL; long ret = strtol(nPtr16, &endPtr16, 0); if (ret == 16) { - printf("[DEMO] posix stdlib test case 2:strtol(base=16) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr16, endPtr16); + LOG("[DEMO] posix stdlib test case 2:strtol(base=16) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr16, endPtr16); } else { - printf("[DEMO] posix stdlib test case 2:strtol(base=16) ret:%ld,%s fail.\n", ret, nPtr16); + LOG("[DEMO] posix stdlib test case 2:strtol(base=16) ret:%ld,%s fail.\n", ret, nPtr16); } TEST_ASSERT_EQUAL_INT32(16, ret); TEST_ASSERT_EQUAL_STRING(endPtr16, ""); @@ -114,9 +114,9 @@ LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol003, Function | MediumTest char *endPtr10 = NULL; long ret = strtol(nPtr10, &endPtr10, 10); if (ret == 10) { - printf("[DEMO] posix stdlib test case 3:strtol(base=10) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10, endPtr10); + LOG("[DEMO] posix stdlib test case 3:strtol(base=10) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10, endPtr10); } else { - printf("[DEMO] posix stdlib test case 3:strtol(base=10) ret:%ld,%s fail.\n", ret, nPtr10); + LOG("[DEMO] posix stdlib test case 3:strtol(base=10) ret:%ld,%s fail.\n", ret, nPtr10); } TEST_ASSERT_EQUAL_INT32(10, ret); TEST_ASSERT_EQUAL_STRING(endPtr10, ""); @@ -133,9 +133,9 @@ LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol004, Function | MediumTest char *endPtr10 = NULL; long ret = strtol(nPtr10, &endPtr10, 10); if (ret == -10) { - printf("[DEMO] posix stdlib test case 4:strtol(base=10) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10, endPtr10); + LOG("[DEMO] posix stdlib test case 4:strtol(base=10) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10, endPtr10); } else { - printf("[DEMO] posix stdlib test case 4:strtol(base=10) ret:%ld,%s fail.\n", ret, nPtr10); + LOG("[DEMO] posix stdlib test case 4:strtol(base=10) ret:%ld,%s fail.\n", ret, nPtr10); } TEST_ASSERT_EQUAL_INT32(-10, ret); TEST_ASSERT_EQUAL_STRING(endPtr10, ""); @@ -152,9 +152,9 @@ LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol005, Function | MediumTest char *endPtr10_3 = NULL; long ret = strtol(nPtr10_3, &endPtr10_3, 0); if (ret == 10) { - printf("[DEMO] posix stdlib test case 5:strtol(base=0) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10_3, endPtr10_3); + LOG("[DEMO] posix stdlib test case 5:strtol(base=0) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10_3, endPtr10_3); } else { - printf("[DEMO] posix stdlib test case 5:strtol(base=0) ret:%ld,%s fail.\n", ret, nPtr10_3); + LOG("[DEMO] posix stdlib test case 5:strtol(base=0) ret:%ld,%s fail.\n", ret, nPtr10_3); } TEST_ASSERT_EQUAL_INT32(10, ret); TEST_ASSERT_EQUAL_STRING(endPtr10_3, ""); @@ -171,9 +171,9 @@ LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol006, Function | MediumTest char *endPtr8 = NULL; long ret = strtol(nPtr8, &endPtr8, 8); if (ret == 8) { - printf("[DEMO] posix stdlib test case 6:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8, endPtr8); + LOG("[DEMO] posix stdlib test case 6:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8, endPtr8); } else { - printf("[DEMO] posix stdlib test case 6:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8); + LOG("[DEMO] posix stdlib test case 6:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8); } TEST_ASSERT_EQUAL_INT32(8, ret); TEST_ASSERT_EQUAL_STRING(endPtr8, ""); @@ -190,9 +190,9 @@ LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol007, Function | MediumTest char *endPtr8_2 = NULL; long ret = strtol(nPtr8_2, &endPtr8_2, 8); if (ret == 8) { - printf("[DEMO] posix stdlib test case 7:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8_2, endPtr8_2); + LOG("[DEMO] posix stdlib test case 7:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8_2, endPtr8_2); } else { - printf("[DEMO] posix stdlib test case 7:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8_2); + LOG("[DEMO] posix stdlib test case 7:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8_2); } TEST_ASSERT_EQUAL_INT32(8, ret); TEST_ASSERT_EQUAL_STRING(endPtr8_2, ""); @@ -209,9 +209,9 @@ LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol008, Function | MediumTest char *endPtr8_3 = NULL; long ret = strtol(nPtr8_3, &endPtr8_3, 0); if (ret == 8) { - printf("[DEMO] posix stdlib test case 8:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8_3, endPtr8_3); + LOG("[DEMO] posix stdlib test case 8:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8_3, endPtr8_3); } else { - printf("[DEMO] posix stdlib test case 8:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8_3); + LOG("[DEMO] posix stdlib test case 8:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8_3); } TEST_ASSERT_EQUAL_INT32(8, ret); TEST_ASSERT_EQUAL_STRING(endPtr8_3, ""); @@ -228,9 +228,9 @@ LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol009, Function | MediumTest char *endPtr2 = NULL; long ret = strtol(nPtr2, &endPtr2, 2); if (ret == 2) { - printf("[DEMO] posix stdlib test case 9:strtol(base=2) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr2, endPtr2); + LOG("[DEMO] posix stdlib test case 9:strtol(base=2) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr2, endPtr2); } else { - printf("[DEMO] posix stdlib test case 9:strtol(base=2) ret:%ld,%s fail.\n", ret, nPtr2); + LOG("[DEMO] posix stdlib test case 9:strtol(base=2) ret:%ld,%s fail.\n", ret, nPtr2); } TEST_ASSERT_EQUAL_INT32(2, ret); TEST_ASSERT_EQUAL_STRING(endPtr2, ""); @@ -247,9 +247,9 @@ LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol010, Function | MediumTest char *endPtr = NULL; long ret = strtol(nPtr, &endPtr, 10); if (ret == 12) { - printf("[DEMO] posix stdlib test case 10:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr); + LOG("[DEMO] posix stdlib test case 10:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 10:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr); + LOG("[DEMO] posix stdlib test case 10:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr); } TEST_ASSERT_EQUAL_INT32(12, ret); TEST_ASSERT_EQUAL_STRING(endPtr, " 0110 0XDEFE 0666 -1.6"); @@ -266,9 +266,9 @@ LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol011, Function | MediumTest char *endPtr = NULL; long ret = strtol(nPtr, &endPtr, 65); if (ret == 67) { - printf("[DEMO] posix stdlib test case 11:strtol(base=65) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr); + LOG("[DEMO] posix stdlib test case 11:strtol(base=65) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 11:strtol(base=65) ret:%ld, %s fail.\n", ret, endPtr); + LOG("[DEMO] posix stdlib test case 11:strtol(base=65) ret:%ld, %s fail.\n", ret, endPtr); } TEST_ASSERT_EQUAL_INT32(67, ret); TEST_ASSERT_EQUAL_STRING(endPtr, " 1.5"); @@ -280,9 +280,9 @@ LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol012, Function | MediumTest char *endPtr = NULL; long ret = strtol(nPtr, &endPtr, 10); if (ret == 2147483647) { - printf("[DEMO] posix stdlib test case 12:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr); + LOG("[DEMO] posix stdlib test case 12:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 12:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr); + LOG("[DEMO] posix stdlib test case 12:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr); } TEST_ASSERT_EQUAL_INT32(2147483647, ret); TEST_ASSERT_EQUAL_STRING(endPtr, " -2147483648"); @@ -299,9 +299,9 @@ LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol013, Function | MediumTest char *endPtr = NULL; long ret = strtol(nPtr, &endPtr, 10); if (ret == -2147483648) { - printf("[DEMO] posix stdlib test case 13:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr); + LOG("[DEMO] posix stdlib test case 13:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 13:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr); + LOG("[DEMO] posix stdlib test case 13:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr); } TEST_ASSERT_EQUAL_INT32(-2147483648, ret); TEST_ASSERT_EQUAL_STRING(endPtr, ""); diff --git a/testsuits/unittest/posix/src/stdlib/strtoul_test.c b/testsuits/unittest/posix/src/stdlib/strtoul_test.c index d775a761..1d196c6d 100644 --- a/testsuits/unittest/posix/src/stdlib/strtoul_test.c +++ b/testsuits/unittest/posix/src/stdlib/strtoul_test.c @@ -36,6 +36,7 @@ #include "ctype.h" #include "stdlib.h" #include "string.h" +#include "limits.h" #include "log.h" /* * @@ -61,7 +62,7 @@ static BOOL PosixStdlibStrtoulTestSetUp(void) */ static BOOL PosixStdlibStrtoulTestTearDown(void) { - printf("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -76,9 +77,9 @@ LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul001, Function | MediumTe char *endPtr = NULL; unsigned long ret = strtoul(nPtr, &endPtr, 10); if (ret == 12UL) { - printf("[DEMO] posix stdlib test case 1:strtoul(base=10) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 1:strtoul(base=10) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 1:strtoul(base=10) ret:%lu,%s fail.\n", ret, nPtr); + LOG("[DEMO] posix stdlib test case 1:strtoul(base=10) ret:%lu,%s fail.\n", ret, nPtr); } TEST_ASSERT_EQUAL_UINT32(12UL, ret); TEST_ASSERT_EQUAL_STRING(endPtr, " 0110 0XDEFE 0666 4294967295 4294967296 12.34"); @@ -95,9 +96,9 @@ LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul002, Function | MediumTe char *endPtr = NULL; unsigned long ret = strtoul(nPtr, &endPtr, 2); if (ret == 6UL) { - printf("[DEMO] posix stdlib test case 2:strtoul(base=2) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 2:strtoul(base=2) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 2:strtoul(base=2) ret:%lu,%s fail.\n", ret, endPtr); + LOG("[DEMO] posix stdlib test case 2:strtoul(base=2) ret:%lu,%s fail.\n", ret, endPtr); } TEST_ASSERT_EQUAL_UINT32(6UL, ret); TEST_ASSERT_EQUAL_STRING(endPtr, " 0XDEFE 0666 4294967295 4294967296 12.34"); @@ -114,9 +115,9 @@ LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul003, Function | MediumTe char *endPtr = NULL; unsigned long ret = strtoul(nPtr, &endPtr, 16); if (ret == 0XDEFEUL) { - printf("[DEMO] posix stdlib test case 3:strtoul(base=16) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 3:strtoul(base=16) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 3:strtoul(base=16) ret:%lu,%s fail.\n", ret, endPtr); + LOG("[DEMO] posix stdlib test case 3:strtoul(base=16) ret:%lu,%s fail.\n", ret, endPtr); } TEST_ASSERT_EQUAL_UINT32(0XDEFEUL, ret); TEST_ASSERT_EQUAL_STRING(endPtr, " 0666 4294967295 4294967296 12.34"); @@ -133,9 +134,9 @@ LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul004, Function | MediumTe char *endPtr = NULL; unsigned long ret = strtoul(nPtr, &endPtr, 8); if (ret == 0666UL) { - printf("[DEMO] posix stdlib test case 4:strtoul(base=8) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 4:strtoul(base=8) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 4:strtoul(base=8) ret:%lu,%s fail.\n", ret, endPtr); + LOG("[DEMO] posix stdlib test case 4:strtoul(base=8) ret:%lu,%s fail.\n", ret, endPtr); } TEST_ASSERT_EQUAL_UINT32(0666UL, ret); TEST_ASSERT_EQUAL_STRING(endPtr, " 4294967295 4294967296 12.34"); @@ -152,9 +153,9 @@ LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul005, Function | MediumTe char *endPtr = NULL; unsigned long ret = strtoul(nPtr, &endPtr, 0); if (ret == 4294967295UL) { - printf("[DEMO] posix stdlib test case 5:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 5:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 5:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr); + LOG("[DEMO] posix stdlib test case 5:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr); } TEST_ASSERT_EQUAL_UINT32(4294967295UL, ret); TEST_ASSERT_EQUAL_STRING(endPtr, " 4294967296 12.34"); @@ -171,11 +172,12 @@ LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul006, Function | MediumTe char *endPtr = NULL; unsigned long ret = strtoul(nPtr, &endPtr, 0); if (ret == 0UL) { - printf("[DEMO] posix stdlib test case 6:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 6:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 6:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr); + LOG("[DEMO] posix stdlib test case 6:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr); } - TEST_ASSERT_EQUAL_UINT32(0UL, ret); + + TEST_ASSERT_EQUAL_UINT32(ULONG_MAX, ret); TEST_ASSERT_EQUAL_STRING(endPtr, " 12.34"); } @@ -190,9 +192,9 @@ LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul007, Function | MediumTe char *endPtr = NULL; unsigned long ret = strtoul(nPtr, &endPtr, 65); if (ret == 67UL) { - printf("[DEMO] posix stdlib test case 7:strtoul(base=65) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 7:strtoul(base=65) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 7:strtoul(base=65) ret:%lu,%s fail.\n", ret, endPtr); + LOG("[DEMO] posix stdlib test case 7:strtoul(base=65) ret:%lu,%s fail.\n", ret, endPtr); } TEST_ASSERT_EQUAL_UINT32(67UL, ret); TEST_ASSERT_EQUAL_STRING(endPtr, ".34"); @@ -209,9 +211,9 @@ LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul008, Function | MediumTe char *endPtr = NULL; unsigned long ret = strtoul(nPtr, &endPtr, 0); if (ret == 0UL) { - printf("[DEMO] posix stdlib test case 8:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 8:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 8:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr); + LOG("[DEMO] posix stdlib test case 8:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr); } TEST_ASSERT_EQUAL_UINT32(0UL, ret); TEST_ASSERT_EQUAL_STRING(endPtr, ".34"); @@ -228,9 +230,9 @@ LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul009, Function | MediumTe char *endPtr = NULL; unsigned long ret = strtoul(nPtr, &endPtr, 0); if (ret == 0XDEFE) { - printf("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr); + LOG("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr); } TEST_ASSERT_EQUAL_UINT32(0XDEFE, ret); TEST_ASSERT_EQUAL_STRING(endPtr, " 0666"); @@ -247,9 +249,9 @@ LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul010, Function | MediumTe char *endPtr = NULL; unsigned long ret = strtoul(nPtr, &endPtr, 0); if (ret == 0666) { - printf("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr); + LOG("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr); } TEST_ASSERT_EQUAL_UINT32(0666, ret); TEST_ASSERT_EQUAL_STRING(endPtr, ""); diff --git a/testsuits/unittest/posix/src/stdlib/strtoull_test.c b/testsuits/unittest/posix/src/stdlib/strtoull_test.c index a15f78a7..0d327d39 100644 --- a/testsuits/unittest/posix/src/stdlib/strtoull_test.c +++ b/testsuits/unittest/posix/src/stdlib/strtoull_test.c @@ -34,6 +34,8 @@ #include "los_config.h" #include "kernel_test.h" #include "ctype.h" +#include "errno.h" +#include "limits.h" #include "stdlib.h" #include "string.h" #include "log.h" @@ -61,7 +63,7 @@ static BOOL PosixStdlibStrtoullTestSetUp(void) */ static BOOL PosixStdlibStrtoullTestTearDown(void) { - printf("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -76,9 +78,9 @@ LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull001, Function | Medium char *endPtr = NULL; unsigned long long ret = strtoull(nPtr, &endPtr, 10); if (ret == 12ULL) { - printf("[DEMO] posix stdlib test case 1:strtoull(base=10) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 1:strtoull(base=10) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 1:strtoull(base=10) ret:%llu,%s fail.\n", ret, nPtr); + LOG("[DEMO] posix stdlib test case 1:strtoull(base=10) ret:%llu,%s fail.\n", ret, nPtr); } TEST_ASSERT_TRUE(ret == 12ULL); TEST_ASSERT_EQUAL_STRING(endPtr, " 0110 0XDEFE 0666 1.6"); @@ -95,9 +97,9 @@ LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull002, Function | Medium char *endPtr = NULL; unsigned long long ret = strtoull(nPtr, &endPtr, 2); if (ret == 6ULL) { - printf("[DEMO] posix stdlib test case 2:strtoull(base=2) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 2:strtoull(base=2) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 2:strtoull(base=2) ret:%llu,%s fail.\n", ret, nPtr); + LOG("[DEMO] posix stdlib test case 2:strtoull(base=2) ret:%llu,%s fail.\n", ret, nPtr); } TEST_ASSERT_TRUE(ret == 6ULL); TEST_ASSERT_EQUAL_STRING(endPtr, " 0XDEFE 0666 1.6"); @@ -114,9 +116,9 @@ LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull003, Function | Medium char *endPtr = NULL; unsigned long long ret = strtoull(nPtr, &endPtr, 16); if (ret == 0XDEFEULL) { - printf("[DEMO] posix stdlib test case 3:strtoull(base=16) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 3:strtoull(base=16) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 3:strtoull(base=16) ret:%llu,%s fail.\n", ret, nPtr); + LOG("[DEMO] posix stdlib test case 3:strtoull(base=16) ret:%llu,%s fail.\n", ret, nPtr); } TEST_ASSERT_TRUE(ret == 0XDEFEULL); TEST_ASSERT_EQUAL_STRING(endPtr, " 0666 1.6"); @@ -133,9 +135,9 @@ LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull004, Function | Medium char *endPtr = NULL; unsigned long long ret = strtoull(nPtr, &endPtr, 8); if (ret == 0666ULL) { - printf("[DEMO] posix stdlib test case 4:strtoull(base=8) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 4:strtoull(base=8) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 4:strtoull(base=8) ret:%llu,%s fail.\n", ret, nPtr); + LOG("[DEMO] posix stdlib test case 4:strtoull(base=8) ret:%llu,%s fail.\n", ret, nPtr); } TEST_ASSERT_TRUE(ret == 0666ULL); TEST_ASSERT_EQUAL_STRING(endPtr, " 1.6"); @@ -152,9 +154,9 @@ LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull005, Function | Medium char *endPtr = NULL; unsigned long long ret = strtoull(nPtr, &endPtr, 65); if (ret == 1ULL) { - printf("[DEMO] posix stdlib test case 5:strtoull(base=65) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 5:strtoull(base=65) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 5:strtoull(base=65) ret:%llu,%s fail.\n", ret, nPtr); + LOG("[DEMO] posix stdlib test case 5:strtoull(base=65) ret:%llu,%s fail.\n", ret, nPtr); } TEST_ASSERT_TRUE(ret == 1ULL); TEST_ASSERT_EQUAL_STRING(endPtr, ".6"); @@ -171,9 +173,9 @@ LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull006, Function | Medium char *endPtr = NULL; unsigned long long ret = strtoull(nPtr, &endPtr, 0); if (ret == 0ULL) { - printf("[DEMO] posix stdlib test case 6:strtoull(base=0) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 6:strtoull(base=0) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 6:strtoull(base=0) ret:%llu,%s fail.\n", ret, nPtr); + LOG("[DEMO] posix stdlib test case 6:strtoull(base=0) ret:%llu,%s fail.\n", ret, nPtr); } TEST_ASSERT_TRUE(ret == 0ULL); TEST_ASSERT_EQUAL_STRING(endPtr, ".6"); @@ -190,9 +192,9 @@ LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull007, Function | Medium char *endPtr = NULL; unsigned long long ret = strtoull(nPtr, &endPtr, 10); if (ret == 18446744073709551615ULL) { - printf("[DEMO] posix stdlib test case 7:strtoull(base=10) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 7:strtoull(base=10) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 7:strtoull(base=10) ret:%llu,%s fail.\n", ret, nPtr); + LOG("[DEMO] posix stdlib test case 7:strtoull(base=10) ret:%llu,%s fail.\n", ret, nPtr); } TEST_ASSERT_TRUE(ret == 18446744073709551615ULL); TEST_ASSERT_EQUAL_STRING(endPtr, " 18446744073709551616"); @@ -209,11 +211,13 @@ LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull008, Function | Medium char *endPtr = NULL; unsigned long long ret = strtoull(nPtr, &endPtr, 10); if (ret == 0ULL) { - printf("[DEMO] posix stdlib test case 8:strtoull(base=10) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 8:strtoull(base=10) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 8:strtoull(base=10) ret:%llu,%s fail.\n", ret, nPtr); + LOG("[DEMO] posix stdlib test case 8:strtoull(base=10) ret:%llu,%s fail.\n", ret, nPtr); } - TEST_ASSERT_TRUE(ret == 0ULL); + + TEST_ASSERT_EQUAL_UINT64(ULLONG_MAX, ret); + TEST_ASSERT_EQUAL_INT(errno, ERANGE); TEST_ASSERT_EQUAL_STRING(endPtr, ""); } @@ -228,9 +232,9 @@ LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull009, Function | Medium char *endPtr = NULL; unsigned long long ret = strtoull(nPtr, &endPtr, 0); if (ret == 0XDEFEULL) { - printf("[DEMO] posix stdlib test case 9:strtoull(base=0) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 9:strtoull(base=0) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 9:strtoull(base=0) ret:%llu,%s fail.\n", ret, nPtr); + LOG("[DEMO] posix stdlib test case 9:strtoull(base=0) ret:%llu,%s fail.\n", ret, nPtr); } TEST_ASSERT_TRUE(ret == 0XDEFEULL); TEST_ASSERT_EQUAL_STRING(endPtr, " 0666"); @@ -247,9 +251,9 @@ LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull010, Function | Medium char *endPtr = NULL; unsigned long long ret = strtoull(nPtr, &endPtr, 0); if (ret == 0666ULL) { - printf("[DEMO] posix stdlib test case 10:strtoull(base=0) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); + LOG("[DEMO] posix stdlib test case 10:strtoull(base=0) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr); } else { - printf("[DEMO] posix stdlib test case 10:strtoull(base=0) ret:%llu,%s fail.\n", ret, nPtr); + LOG("[DEMO] posix stdlib test case 10:strtoull(base=0) ret:%llu,%s fail.\n", ret, nPtr); } TEST_ASSERT_TRUE(ret == 0666ULL); TEST_ASSERT_EQUAL_STRING(endPtr, ""); diff --git a/testsuits/unittest/posix/src/string/memory_func_test.c b/testsuits/unittest/posix/src/string/memory_func_test.c index 23920045..6faf65f7 100644 --- a/testsuits/unittest/posix/src/string/memory_func_test.c +++ b/testsuits/unittest/posix/src/string/memory_func_test.c @@ -141,7 +141,7 @@ LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcpy002, Function | MediumTest break; } } - TEST_ASSERT_EQUAL_INT(failure, 0); + TEST_ASSERT_EQUAL_INT(0, failure); }; @@ -179,10 +179,8 @@ LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcmp001, Function | MediumTest char dest[]={"memory refers to the computer hardware devices used to store information for " "immediate use in a computer\r\n"}; - TEST_ASSERT_EQUAL_STRING(source, dest); - retValue = memcmp(source, dest, sizeof(source) / sizeof(source[0])); - TEST_ASSERT_EQUAL_INT(retValue, 0); + TEST_ASSERT_EQUAL_INT(0, retValue); char orign[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; @@ -194,16 +192,16 @@ LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcmp001, Function | MediumTest int len = sizeof(orign); ret = memcmp(orign, lt, len); - TEST_ASSERT_LESS_THAN(ret, 0); + TEST_ASSERT_GREATER_THAN(0, ret); ret = memcmp(eq, orign, len); - TEST_ASSERT_EQUAL_INT(ret, 0); + TEST_ASSERT_EQUAL_INT(0, ret); ret = memcmp(orign, gt, len); - TEST_ASSERT_GREATER_THAN(ret, 0); + TEST_ASSERT_LESS_THAN(0, ret); ret = memcmp(gt, orign, 0); - TEST_ASSERT_EQUAL_INT(ret, 0); + TEST_ASSERT_EQUAL_INT(0, ret); }; @@ -219,16 +217,16 @@ LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcmp002, Function | MediumTest "immediate use in a computer\r\n"}; char dest[]={"Hello, Richard, how are you?\r\n"}; retValue = memcmp(source, dest, sizeof(dest) / sizeof(dest[0])); - TEST_ASSERT_EQUAL_INT(retValue, 1); + TEST_ASSERT_GREATER_THAN(0, retValue); int ret = memcmp(L"CBCDEFG", L"BBCDEFG", 7); - TEST_ASSERT_LESS_THAN(ret, 0); + TEST_ASSERT_GREATER_THAN(0, ret); ret = memcmp(L"ABCDEFG", L"abcdefg", 2); - TEST_ASSERT_GREATER_THAN(ret, 0); + TEST_ASSERT_LESS_THAN(0, ret); ret = memcmp(L"ABCDEFG", L"ABCDEFG", 6); - TEST_ASSERT_EQUAL_INT(ret, 0); + TEST_ASSERT_EQUAL_INT(0, ret); }; @@ -244,7 +242,7 @@ LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcmp003, Function | MediumTest char dest[]={"memory refers to the computer hardware devices used to store information for " "immediate use in a computer\r\n"}; retValue = memcmp(source, dest, sizeof(source) / sizeof(source[0])); - TEST_ASSERT_EQUAL_INT(retValue, -1); + TEST_ASSERT_LESS_THAN(0, retValue); }; diff --git a/testsuits/unittest/posix/src/string/strchr_test.c b/testsuits/unittest/posix/src/string/strchr_test.c index 653c14da..08a83e20 100644 --- a/testsuits/unittest/posix/src/string/strchr_test.c +++ b/testsuits/unittest/posix/src/string/strchr_test.c @@ -61,7 +61,7 @@ static BOOL PosixStringStrchrTestSetUp(void) */ static BOOL PosixStringStrchrTestTearDown(void) { - printf("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -75,9 +75,9 @@ LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr001, Function | MediumTest char src[] = "hello !! world"; char *ret = strchr(src, '!'); if (strcmp(ret, "!! world") == 0) { - printf("[DEMO] posix string test case 1:strchr(!) %s ok.\n", src); + LOG("[DEMO] posix string test case 1:strchr(!) %s ok.\n", src); } else { - printf("[DEMO] posix string test case 1:strchr(!) %s fail.\n", src); + LOG("[DEMO] posix string test case 1:strchr(!) %s fail.\n", src); } TEST_ASSERT_EQUAL_STRING(ret, "!! world"); } @@ -92,9 +92,9 @@ LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr002, Function | MediumTest char src[] = "hello !! world"; char *ret = strchr(src, 'l'); if (strcmp(ret, "llo !! world") == 0) { - printf("[DEMO] posix string test case 2:strchr(l) %s ok.\n", src); + LOG("[DEMO] posix string test case 2:strchr(l) %s ok.\n", src); } else { - printf("[DEMO] posix string test case 2:strchr(l) %s fail.\n", src); + LOG("[DEMO] posix string test case 2:strchr(l) %s fail.\n", src); } TEST_ASSERT_EQUAL_STRING(ret, "llo !! world"); } @@ -109,9 +109,9 @@ LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr003, Function | MediumTest char src[] = "hello !! world"; char *ret = strchr(src, '\0'); if (ret != NULL) { - printf("[DEMO] posix string test case 3:strchr(\'\\0\') %s ok.\n", src); + LOG("[DEMO] posix string test case 3:strchr(\'\\0\') %s ok.\n", src); } else { - printf("[DEMO] posix string test case 3:strchr(\'\\0\') %s fail.\n", src); + LOG("[DEMO] posix string test case 3:strchr(\'\\0\') %s fail.\n", src); } TEST_ASSERT_NOT_NULL(ret); } @@ -126,9 +126,9 @@ LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr004, Function | MediumTest char src[] = "hello !! world"; char *ret = strchr(src, '?'); if (ret == NULL) { - printf("[DEMO] posix string test case 4(except):strchr(?) %s ok.\n", src); + LOG("[DEMO] posix string test case 4(except):strchr(?) %s ok.\n", src); } else { - printf("[DEMO] posix string test case 4(except):strchr(?) %s fail.\n", src); + LOG("[DEMO] posix string test case 4(except):strchr(?) %s fail.\n", src); } TEST_ASSERT_NULL(ret); } @@ -143,9 +143,9 @@ LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr005, Function | MediumTest char src[] = "hello !! world"; char *ret = strchr(src, 'm'); if (ret == NULL) { - printf("[DEMO] posix string test case 5(except):strchr(m) %s ok.\n", src); + LOG("[DEMO] posix string test case 5(except):strchr(m) %s ok.\n", src); } else { - printf("[DEMO] posix string test case 5(except):strchr(m) %s fail.\n", src); + LOG("[DEMO] posix string test case 5(except):strchr(m) %s fail.\n", src); } TEST_ASSERT_NULL(ret); } @@ -160,9 +160,9 @@ LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr006, Function | MediumTest char src[] = "hello !! world"; char *ret = strchr(src, 0); if (ret != NULL) { - printf("[DEMO] posix string test case 6(except):strchr(0) %s ok.\n", src); + LOG("[DEMO] posix string test case 6(except):strchr(0) %s ok.\n", src); } else { - printf("[DEMO] posix string test case 6(except):strchr(0) %s fail.\n", src); + LOG("[DEMO] posix string test case 6(except):strchr(0) %s fail.\n", src); } TEST_ASSERT_NOT_NULL(ret); } diff --git a/testsuits/unittest/posix/src/string/string_func_test_02.c b/testsuits/unittest/posix/src/string/string_func_test_02.c index 2b2e54de..0fc9a311 100644 --- a/testsuits/unittest/posix/src/string/string_func_test_02.c +++ b/testsuits/unittest/posix/src/string/string_func_test_02.c @@ -32,8 +32,8 @@ #include "ohos_types.h" #include "hctest.h" #include "los_config.h" -#include "los_debug.h" #include "kernel_test.h" +#include "log.h" #define EQUAL 0 @@ -52,9 +52,9 @@ LITE_TEST_SUIT(Posix, PosixStrings, PosixStringsFuncTestSuite); */ static BOOL PosixStringsFuncTestSuiteSetUp(void) { - PRINT_EMG("+-------------------------------------------+\n"); - PRINT_EMG("+------PosixStringsFuncTestSuiteSetUp-------+\n"); - PRINT_EMG("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); + LOG("+------PosixStringsFuncTestSuiteSetUp-------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -64,9 +64,9 @@ static BOOL PosixStringsFuncTestSuiteSetUp(void) */ static BOOL PosixStringsFuncTestSuiteTearDown(void) { - PRINT_EMG("+-------------------------------------------+\n"); - PRINT_EMG("+-----PosixStringsFuncTestSuiteTearDown-----+\n"); - PRINT_EMG("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); + LOG("+-----PosixStringsFuncTestSuiteTearDown-----+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -97,7 +97,7 @@ RUN_TEST_SUITE(PosixStringsFuncTestSuite); void PosixStringStrcasecmpFuncTest() { - PRINT_EMG("begin PosixStringStrcasecmpFuncTest...."); + LOG("begin PosixStringStrcasecmpFuncTest...."); RUN_ONE_TESTCASE(testStrCaseCmp001); return; diff --git a/testsuits/unittest/posix/src/string/string_func_test_03.c b/testsuits/unittest/posix/src/string/string_func_test_03.c index 248f2c4f..658babe4 100644 --- a/testsuits/unittest/posix/src/string/string_func_test_03.c +++ b/testsuits/unittest/posix/src/string/string_func_test_03.c @@ -176,16 +176,16 @@ LITE_TEST_CASE(PosixStringFuncTestSuite, testStrStrcspn001, Function | MediumTes char dest1[] ={"H"}; retValue = strcspn(source, dest1); - TEST_ASSERT_EQUAL_INT(retValue, 19U); + TEST_ASSERT_EQUAL_INT(18U, retValue); const char dest[] = "hello world !"; const char src[] = "!"; size_t ret = strcspn(dest, src); - TEST_ASSERT_EQUAL_INT(ret, 12U); + TEST_ASSERT_EQUAL_INT(12U, ret); const char srcS[] = "a"; ret = strcspn(dest, srcS); - TEST_ASSERT_EQUAL_INT(ret, 13U); + TEST_ASSERT_EQUAL_INT(13U, ret); }; /* * @@ -200,7 +200,7 @@ LITE_TEST_CASE(PosixStringFuncTestSuite, testStrStrcspn002, Function | MediumTes char dest[] ={"or"}; retValue = strcspn(source, dest); - TEST_ASSERT_LESS_OR_EQUAL(retValue, 0); + TEST_ASSERT_EQUAL_INT(1, retValue); }; /* * diff --git a/testsuits/unittest/posix/src/string/strstr_test.c b/testsuits/unittest/posix/src/string/strstr_test.c index 05f67e41..fd2428fe 100644 --- a/testsuits/unittest/posix/src/string/strstr_test.c +++ b/testsuits/unittest/posix/src/string/strstr_test.c @@ -59,7 +59,7 @@ static BOOL PosixStringStrStrTestSetUp(void) */ static BOOL PosixStringStrStrTestTearDown(void) { - printf("+-------------------------------------------+\n"); + LOG("+-------------------------------------------+\n"); return TRUE; } @@ -75,9 +75,9 @@ LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr001, Function | MediumTest char *ret = strstr(destS, srcS); if (strcmp(ret, destS) == 0) { - printf("[DEMO] posix string test case 1:strstr(%s) %s ok.\n", srcS, destS); + LOG("[DEMO] posix string test case 1:strstr(%s) %s ok.\n", srcS, destS); } else { - printf("[DEMO] posix string test case 1:strstr(%s) %s fail.\n", srcS, destS); + LOG("[DEMO] posix string test case 1:strstr(%s) %s fail.\n", srcS, destS); } TEST_ASSERT_EQUAL_STRING(ret, destS); } @@ -94,9 +94,9 @@ LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr002, Function | MediumTest char *ret = strstr(destS, srcS); if (strcmp(ret, "this is string") == 0) { - printf("[DEMO] posix string test case 2:strstr(%s) %s ok.\n", srcS, destS); + LOG("[DEMO] posix string test case 2:strstr(%s) %s ok.\n", srcS, destS); } else { - printf("[DEMO] posix string test case 2:strstr(%s) %s fail.\n", srcS, destS); + LOG("[DEMO] posix string test case 2:strstr(%s) %s fail.\n", srcS, destS); } TEST_ASSERT_EQUAL_STRING(ret, "this is string"); } @@ -113,9 +113,9 @@ LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr003, Function | MediumTest char *ret = strstr(dest, srcT); if (strcmp(ret, dest) == 0) { - printf("[DEMO] posix string test case 3:strstr(%s) %s ok.\n", srcT, dest); + LOG("[DEMO] posix string test case 3:strstr(%s) %s ok.\n", srcT, dest); } else { - printf("[DEMO] posix string test case 3:strstr(%s) %s fail.\n", srcT, dest); + LOG("[DEMO] posix string test case 3:strstr(%s) %s fail.\n", srcT, dest); } TEST_ASSERT_EQUAL_STRING(ret, dest); } @@ -132,9 +132,9 @@ LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr004, Function | MediumTest char *ret = strstr(dest, src); if (ret == NULL) { - printf("[DEMO] posix string test case 4(except):strstr(%s) %s ok.\n", src, dest); + LOG("[DEMO] posix string test case 4(except):strstr(%s) %s ok.\n", src, dest); } else { - printf("[DEMO] posix string test case 4(except):strstr(%s) %s fail.\n", src, dest); + LOG("[DEMO] posix string test case 4(except):strstr(%s) %s fail.\n", src, dest); } TEST_ASSERT_NULL(ret); } @@ -151,9 +151,9 @@ LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr005, Function | MediumTest char *ret = strstr(dest, src); if (ret == NULL) { - printf("[DEMO] posix string test case 5(except):strstr(%s) %s ok.\n", src, dest); + LOG("[DEMO] posix string test case 5(except):strstr(%s) %s ok.\n", src, dest); } else { - printf("[DEMO] posix string test case 5(except):strstr(%s) %s fail.\n", src, dest); + LOG("[DEMO] posix string test case 5(except):strstr(%s) %s fail.\n", src, dest); } TEST_ASSERT_NULL(ret); } @@ -170,9 +170,9 @@ LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr006, Function | MediumTest char *ret = strstr(destS, srcOne); if (strcmp(ret, "tring this is string") == 0) { - printf("[DEMO] posix string test case 6:strstr(%s) %s ok.\n", srcOne, destS); + LOG("[DEMO] posix string test case 6:strstr(%s) %s ok.\n", srcOne, destS); } else { - printf("[DEMO] posix string test case 6:strstr(%s) %s fail.\n", srcOne, destS); + LOG("[DEMO] posix string test case 6:strstr(%s) %s fail.\n", srcOne, destS); } TEST_ASSERT_EQUAL_STRING(ret, "tring this is string"); } @@ -189,9 +189,9 @@ LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr007, Function | MediumTest char *ret = strstr(destS, srcOne); if (ret == NULL) { - printf("[DEMO] posix string test case 7(except):strstr(%s) %s ok.\n", srcOne, destS); + LOG("[DEMO] posix string test case 7(except):strstr(%s) %s ok.\n", srcOne, destS); } else { - printf("[DEMO] posix string test case 7(except):strstr(%s) %s fail.\n", srcOne, destS); + LOG("[DEMO] posix string test case 7(except):strstr(%s) %s fail.\n", srcOne, destS); } TEST_ASSERT_NULL(ret); } @@ -208,9 +208,9 @@ LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr008, Function | MediumTest char *ret = strstr(destS, srcTwo); if (strcmp(ret, "this is string") == 0) { - printf("[DEMO] posix string test case 8:strstr(%s) %s ok.\n", srcTwo, destS); + LOG("[DEMO] posix string test case 8:strstr(%s) %s ok.\n", srcTwo, destS); } else { - printf("[DEMO] posix string test case 8:strstr(%s) %s fail.\n", srcTwo, destS); + LOG("[DEMO] posix string test case 8:strstr(%s) %s fail.\n", srcTwo, destS); } TEST_ASSERT_EQUAL_STRING(ret, "this is string"); } @@ -227,9 +227,9 @@ LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr009, Function | MediumTest char *ret = strstr(destS, srcTwo2); if (ret == NULL) { - printf("[DEMO] posix string test case 9(except):strstr(%s) %s ok.\n", srcTwo2, destS); + LOG("[DEMO] posix string test case 9(except):strstr(%s) %s ok.\n", srcTwo2, destS); } else { - printf("[DEMO] posix string test case 9(except):strstr(%s) %s fail.\n", srcTwo2, destS); + LOG("[DEMO] posix string test case 9(except):strstr(%s) %s fail.\n", srcTwo2, destS); } TEST_ASSERT_NULL(ret); } @@ -246,9 +246,9 @@ LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr010, Function | MediumTest char *ret = strstr(destS, srcThree); if (strcmp(ret, "this is string") == 0) { - printf("[DEMO] posix string test case 10:strstr(%s) %s ok.\n", srcThree, destS); + LOG("[DEMO] posix string test case 10:strstr(%s) %s ok.\n", srcThree, destS); } else { - printf("[DEMO] posix string test case 10:strstr(%s) %s fail.\n", srcThree, destS); + LOG("[DEMO] posix string test case 10:strstr(%s) %s fail.\n", srcThree, destS); } TEST_ASSERT_EQUAL_STRING(ret, "this is string"); } @@ -265,9 +265,9 @@ LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr011, Function | MediumTest char *ret = strstr(destS, srcThree); if (ret == NULL) { - printf("[DEMO] posix string test case 11(except):strstr(%s) %s ok.\n", srcThree, destS); + LOG("[DEMO] posix string test case 11(except):strstr(%s) %s ok.\n", srcThree, destS); } else { - printf("[DEMO] posix string test case 11(except):strstr(%s) %s fail.\n", srcThree, destS); + LOG("[DEMO] posix string test case 11(except):strstr(%s) %s fail.\n", srcThree, destS); } TEST_ASSERT_NULL(ret); } @@ -284,9 +284,9 @@ LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr012, Function | MediumTest char *ret = strstr(destS, srcFour); if (strcmp(ret, "this is string") == 0) { - printf("[DEMO] posix string test case 12:strstr(%s) %s ok.\n", srcFour, destS); + LOG("[DEMO] posix string test case 12:strstr(%s) %s ok.\n", srcFour, destS); } else { - printf("[DEMO] posix string test case 12:strstr(%s) %s fail.\n", srcFour, destS); + LOG("[DEMO] posix string test case 12:strstr(%s) %s fail.\n", srcFour, destS); } TEST_ASSERT_EQUAL_STRING(ret, "this is string"); } @@ -303,9 +303,9 @@ LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr013, Function | MediumTest char *ret = strstr(destS, srcFour); if (ret == NULL) { - printf("[DEMO] posix string test case 13(except):strstr(%s) %s ok.\n", srcFour, destS); + LOG("[DEMO] posix string test case 13(except):strstr(%s) %s ok.\n", srcFour, destS); } else { - printf("[DEMO] posix string test case 13(except):strstr(%s) %s fail.\n", srcFour, destS); + LOG("[DEMO] posix string test case 13(except):strstr(%s) %s fail.\n", srcFour, destS); } TEST_ASSERT_NULL(ret); } diff --git a/testsuits/unittest/posix/src/time/time_func_test_01.c b/testsuits/unittest/posix/src/time/time_func_test_01.c index 6495d60e..90a9310f 100644 --- a/testsuits/unittest/posix/src/time/time_func_test_01.c +++ b/testsuits/unittest/posix/src/time/time_func_test_01.c @@ -34,12 +34,12 @@ #include #include #include -#include #include "ohos_types.h" #include "hctest.h" #include "los_config.h" #include "securec.h" #include "kernel_test.h" +#include "log.h" #define RET_OK 0 @@ -58,7 +58,9 @@ (tmSt).tm_mday = (day); \ (tmSt).tm_mon = (mon); \ (tmSt).tm_year = (year) - 1900; \ - (tmSt).tm_wday = 7; \ + (tmSt).tm_wday = wday; \ + (tmSt).__tm_gmtoff = 0; \ + (tmSt).__tm_zone = ""; \ } while (0) /* * @@ -92,7 +94,7 @@ static int KeepRun(int msec) struct timespec time1 = { 0, 0 }; struct timespec time2 = { 0, 0 }; clock_gettime(CLOCK_MONOTONIC, &time1); - PRINT_EMG("KeepRun start : tv_sec=%ld, tv_nsec=%ld\n", time1.tv_sec, time1.tv_nsec); + LOG("KeepRun start : tv_sec=%ld, tv_nsec=%ld\n", time1.tv_sec, time1.tv_nsec); int loop = 0; int runned = 0; while (runned < msec) { @@ -102,7 +104,7 @@ static int KeepRun(int msec) runned += (time2.tv_nsec - time1.tv_nsec) / NANOSECONDS_PER_MILLISECOND; } - PRINT_EMG("KeepRun end : tv_sec=%ld, tv_nsec=%ld\n", time2.tv_sec, time2.tv_nsec); + LOG("KeepRun end : tv_sec=%ld, tv_nsec=%ld\n", time2.tv_sec, time2.tv_nsec); return loop; } @@ -141,7 +143,7 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeUSleep001, Function | MediumTest // wifiiot无法支持10ms以下的sleep int interval[] = {15*1000, 20*1000, 30*1000, 300*1000}; for (unsigned int j = 0; j < sizeof(interval) / sizeof(int); j++) { - PRINT_EMG("\ntest interval:%d\n", interval[j]); + LOG("\ntest interval:%d\n", interval[j]); struct timespec time1 = { 0 }, time2 = { 0 }; long duration; // unit: us double d = 0.0; @@ -151,11 +153,11 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeUSleep001, Function | MediumTest clock_gettime(CLOCK_MONOTONIC, &time2); TEST_ASSERT_EQUAL_INT(RET_OK, rt); duration = (time2.tv_sec - time1.tv_sec) * 1000000 + (time2.tv_nsec - time1.tv_nsec) / 1000; - PRINT_EMG("testloop %d, actual usleep duration: %ld us\n", i, duration); + LOG("testloop %d, actual usleep duration: %ld us\n", i, duration); d += duration; } d = d / ACCURACY_TEST_LOOPS; // average - PRINT_EMG("interval:%u, average duration: %.2f\n", interval[j], d); + LOG("interval:%u, average duration: %.2f\n", interval[j], d); TEST_ASSERT_GREATER_OR_EQUAL(interval[j], d); TEST_ASSERT_INT32_WITHIN(SLEEP_ACCURACY, interval[j], d); } @@ -174,28 +176,9 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeUSleep002, Function | MediumTest int rt = usleep(0); clock_gettime(CLOCK_MONOTONIC, &time2); TEST_ASSERT_EQUAL_INT(RET_OK, rt); - long duration = (time2.tv_sec - time1.tv_sec) * 1000000 + (time2.tv_nsec - time1.tv_nsec) / 1000; - PRINT_EMG("\n usleep(0), actual usleep duration: %ld us\n", duration); - TEST_ASSERT_LESS_OR_EQUAL_UINT32(1000, duration); -} - -/* * - * @tc.number SUB_KERNEL_TIME_USLEEP_003 - * @tc.name usleep test for invlid delay - * @tc.desc [C- SOFTWARE -0200] - */ -LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeUSleep003, Function | MediumTest | Level1) -{ - struct timespec time1 = { 0 }; - struct timespec time2 = { 0 }; - clock_gettime(CLOCK_MONOTONIC, &time1); - int rt = usleep(1000000); - clock_gettime(CLOCK_MONOTONIC, &time2); - TEST_ASSERT_NOT_EQUAL(RET_OK, rt); - TEST_ASSERT_EQUAL_INT(EINVAL, errno); - long duration = (time2.tv_sec - time1.tv_sec) * 1000000 + (time2.tv_nsec - time1.tv_nsec) / 1000; - PRINT_EMG("\n usleep(1000000), actual usleep duration: %ld us\n", duration); - TEST_ASSERT_LESS_OR_EQUAL_UINT32(1000, duration); + long long duration = (time2.tv_sec - time1.tv_sec) * 1000000 + (time2.tv_nsec - time1.tv_nsec) / 1000; + LOG("\n usleep(0), actual usleep duration: %lld us\n", duration); + TEST_ASSERT_LESS_OR_EQUAL_INT64(1000, duration); } /* * @@ -207,28 +190,28 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeGmtime001, Function | MediumTest { time_t time1 = 18880; char timeStr[TIME_STR_LEN] = {0}; - PRINT_EMG("\nsizeof(time_t) = %d", sizeof(time_t)); + LOG("\nsizeof(time_t) = %d, sizeof(struct tm) = %d", sizeof(time_t), sizeof(struct tm)); struct tm *stm = gmtime(&time1); TEST_ASSERT_EQUAL_STRING("1970/1/1 05:14:40 WEEK(4)", TmToStr(stm, timeStr, TIME_STR_LEN)); time1 = LONG_MAX; stm = gmtime(&time1); - PRINT_EMG("\n LONG_MAX = %ld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN)); + LOG("\n LONG_MAX = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN)); TEST_ASSERT_EQUAL_STRING("2038/1/19 03:14:07 WEEK(2)", TmToStr(stm, timeStr, TIME_STR_LEN)); time1 = LONG_MAX - 1; stm = gmtime(&time1); - PRINT_EMG("\n LONG_MAX - 1 = %ld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN)); + LOG("\n LONG_MAX - 1 = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN)); TEST_ASSERT_EQUAL_STRING("2038/1/19 03:14:06 WEEK(2)", TmToStr(stm, timeStr, TIME_STR_LEN)); time1 = LONG_MIN; stm = gmtime(&time1); - PRINT_EMG("\n LONG_MIN = %ld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN)); + LOG("\n LONG_MIN = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN)); TEST_ASSERT_EQUAL_STRING("1901/12/13 20:45:52 WEEK(5)", TmToStr(stm, timeStr, TIME_STR_LEN)); time1 = LONG_MIN + 1; stm = gmtime(&time1); - PRINT_EMG("\n LONG_MIN + 1 = %ld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN)); + LOG("\n LONG_MIN + 1 = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN)); TEST_ASSERT_EQUAL_STRING("1901/12/13 20:45:53 WEEK(5)", TmToStr(stm, timeStr, TIME_STR_LEN)); }; @@ -252,16 +235,16 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltime001, Function | MediumTe time(&tStart); sleep(2); time(&tEnd); - TEST_ASSERT_EQUAL_INT(ret, 0); + TEST_ASSERT_EQUAL_INT(0, ret); struct tm *tmStart = localtime(&tStart); strftime(cTime, sizeof(cTime), "%H:%M:%S", tmStart); TEST_ASSERT_EQUAL_STRING("23:59:59", cTime); - PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime); + LOG("\n time_t=%lld, first time:%s", tStart, cTime); struct tm *tmEnd = localtime(&tEnd); strftime(cTime, sizeof(cTime), "%H:%M:%S", tmEnd); TEST_ASSERT_EQUAL_STRING("00:00:01", cTime); - PRINT_EMG("\n time_t=%ld, first time:%s", tEnd, cTime); + LOG("\n time_t=%lld, first time:%s", tEnd, cTime); } /* * @@ -275,26 +258,26 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltime002, Function | MediumTe time_t tStart = LONG_MAX; struct tm *tmStart = localtime(&tStart); strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart); - TEST_ASSERT_EQUAL_STRING("38-01-19 03:14:07", cTime); - PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime); + TEST_ASSERT_EQUAL_STRING("38-01-19 11:14:07", cTime); + LOG("\n time_t=%lld, first time:%s", tStart, cTime); tStart = LONG_MIN; tmStart = localtime(&tStart); strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart); - TEST_ASSERT_EQUAL_STRING("01-12-13 20:45:52", cTime); - PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime); + TEST_ASSERT_EQUAL_STRING("01-12-14 04:45:52", cTime); + LOG("\n time_t=%lld, first time:%s", tStart, cTime); tStart = 0; tmStart = localtime(&tStart); strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart); - TEST_ASSERT_EQUAL_STRING("70-01-01 00:00:00", cTime); - PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime); + TEST_ASSERT_EQUAL_STRING("70-01-01 08:00:00", cTime); + LOG("\n time_t=%lld, first time:%s", tStart, cTime); tStart = -1; tmStart = localtime(&tStart); strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart); - TEST_ASSERT_EQUAL_STRING("69-12-31 23:59:59", cTime); - PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime); + TEST_ASSERT_EQUAL_STRING("70-01-01 07:59:59", cTime); + LOG("\n time_t=%lld, first time:%s", tStart, cTime); } /* * @@ -318,7 +301,7 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltimer001, Function | MediumT time(&tStart); sleep(2); time(&tEnd); - TEST_ASSERT_EQUAL_INT(ret, 0); + TEST_ASSERT_EQUAL_INT(0, ret); struct tm *tmrStartPtr = localtime_r(&tStart, &tmrStart); struct tm *tmrEndPtr = localtime_r(&tEnd, &tmrEnd); @@ -346,26 +329,26 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltimer002, Function | MediumT time_t tStart = LONG_MAX; struct tm *tmStart = localtime_r(&tStart, &tmrResult); strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart); - TEST_ASSERT_EQUAL_STRING("38-01-19 03:14:07", cTime); - PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime); + TEST_ASSERT_EQUAL_STRING("38-01-19 11:14:07", cTime); + LOG("\n time_t=%lld, first time:%s", tStart, cTime); tStart = LONG_MIN; tmStart = localtime_r(&tStart, &tmrResult); strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart); - TEST_ASSERT_EQUAL_STRING("01-12-13 20:45:52", cTime); - PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime); + TEST_ASSERT_EQUAL_STRING("01-12-14 04:45:52", cTime); + LOG("\n time_t=%lld, first time:%s", tStart, cTime); tStart = 0; tmStart = localtime_r(&tStart, &tmrResult); strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart); - TEST_ASSERT_EQUAL_STRING("70-01-01 00:00:00", cTime); - PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime); + TEST_ASSERT_EQUAL_STRING("70-01-01 08:00:00", cTime); + LOG("\n time_t=%lld, first time:%s", tStart, cTime); tStart = -1; tmStart = localtime_r(&tStart, &tmrResult); strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart); - TEST_ASSERT_EQUAL_STRING("69-12-31 23:59:59", cTime); - PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime); + TEST_ASSERT_EQUAL_STRING("70-01-01 07:59:59", cTime); + LOG("\n time_t=%lld, first time:%s", tStart, cTime); } /* * @@ -375,32 +358,40 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltimer002, Function | MediumT */ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime001, Function | MediumTest | Level1) { + // default time zone east 8 struct tm timeptr = { 0 }; time_t testTime = 18880; + char timeStr[TIME_STR_LEN] = {0}; - INIT_TM(timeptr, 2020, 7, 9, 10, 10, 0, 7); + INIT_TM(timeptr, 2020, 7, 9, 18, 10, 0, 7); time_t timeRet = mktime(&timeptr); + LOG("\n 2020-7-9 18:10:00, mktime Ret = %lld", timeRet); TEST_ASSERT_EQUAL_INT(1596967800, timeRet); - INIT_TM(timeptr, 1970, 0, 1, 0, 0, 0, 0); + INIT_TM(timeptr, 1970, 0, 1, 8, 0, 0, 0); timeRet = mktime(&timeptr); - PRINT_EMG("\n 1970-1-1 00:00:00, mktime Ret = %ld", timeRet); + LOG("\n 1970-1-1 08:00:00, mktime Ret = %lld", timeRet); TEST_ASSERT_EQUAL_INT(0, timeRet); - timeRet = mktime(localtime(&testTime)); + struct tm *stm = localtime(&testTime); + LOG("\n testTime 18880, tm : %s", TmToStr(stm, timeStr, TIME_STR_LEN)); + timeRet = mktime(stm); TEST_ASSERT_EQUAL_INT(18880, timeRet); + LOG("\n input 18880, mktime Ret = %lld", timeRet); testTime = LONG_MAX; - timeRet = mktime(localtime(&testTime)); + stm = localtime(&testTime); + LOG("\n testTime LONG_MAX, tm : %s", TmToStr(stm, timeStr, TIME_STR_LEN)); + timeRet = mktime(stm); TEST_ASSERT_EQUAL_INT(LONG_MAX, timeRet); - - testTime = LONG_MIN; - timeRet = mktime(localtime(&testTime)); - TEST_ASSERT_EQUAL_INT(LONG_MIN, timeRet); + LOG("\n input LONG_MAX, mktime Ret = %lld", timeRet); testTime = 0; - timeRet = mktime(localtime(&testTime)); + stm = localtime(&testTime); + LOG("\n testTime 0, tm : %s", TmToStr(stm, timeStr, TIME_STR_LEN)); + timeRet = mktime(stm); TEST_ASSERT_EQUAL_INT(0, timeRet); + LOG("\n input 0, mktime Ret = %lld", timeRet); } /* * @@ -411,32 +402,11 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime001, Function | MediumTest LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime002, Function | MediumTest | Level1) { struct tm timeptr = { 0 }; - - INIT_TM(timeptr, 1800, 7, 9, 10, 10, 0, 7); + LOG("\n sizeof(time_t) = %d", sizeof(time_t)); + INIT_TM(timeptr, 1969, 7, 9, 10, 10, 0, 7); time_t timeRet = mktime(&timeptr); - PRINT_EMG("\n 1800-8-9 10:10:00, mktime Ret = %ld", timeRet); - TEST_ASSERT_EQUAL_INT(-1, timeRet); - TEST_ASSERT_EQUAL_INT(EOVERFLOW, errno); - - INIT_TM(timeptr, 2800, 1, 1, 1, 10, 0, 7); - timeRet = mktime(&timeptr); - PRINT_EMG("\n 2800-1-1 01:10:00, mktime Ret = %ld", timeRet); - TEST_ASSERT_EQUAL_INT(-1, timeRet); - TEST_ASSERT_EQUAL_INT(EOVERFLOW, errno); - - // for LONG_MAX + 1 DATETIME - INIT_TM(timeptr, 2038, 0, 19, 3, 14, 8, 2); - timeRet = mktime(&timeptr); - PRINT_EMG("\n 2038-1-19 03:14:08, mktime Ret = %ld", timeRet); - TEST_ASSERT_EQUAL_INT(-1, timeRet); - TEST_ASSERT_EQUAL_INT(EOVERFLOW, errno); - - // for LONG_MIN - 1 DATETIME - INIT_TM(timeptr, 1901, 11, 13, 20, 45, 51, 5); - timeRet = mktime(&timeptr); - PRINT_EMG("\n 1901-12-13 20:45:51, mktime Ret = %ld", timeRet); - TEST_ASSERT_EQUAL_INT(-1, timeRet); - TEST_ASSERT_EQUAL_INT(EOVERFLOW, errno); + LOG("\n 1800-8-9 10:10:00, mktime Ret lld = %lld", timeRet); + TEST_ASSERT_EQUAL_INT(0, timeRet); } @@ -454,31 +424,31 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeStrftime001, Function | MediumTes mtime = LONG_MAX; ftime = strftime(buffer, 80, "%y-%m-%d %H:%M:%S", localtime(&mtime)); TEST_ASSERT_GREATER_THAN_INT(0, ftime); - TEST_ASSERT_EQUAL_STRING("38-01-19 03:14:07", buffer); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "38-01-19 03:14:07"); + TEST_ASSERT_EQUAL_STRING("38-01-19 11:14:07", buffer); + LOG("\nresult: %s, expected : %s", buffer, "38-01-19 11:14:07"); mtime = LONG_MIN; ftime = strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", localtime(&mtime)); TEST_ASSERT_GREATER_THAN_INT(0, ftime); - TEST_ASSERT_EQUAL_STRING("1901-12-13 20:45:52", buffer); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "1901-12-13 20:45:52"); + TEST_ASSERT_EQUAL_STRING("1901-12-14 04:45:52", buffer); + LOG("\nresult: %s, expected : %s", buffer, "1901-12-14 04:45:52"); mtime = 18880; ftime = strftime(buffer, 80, "%F %T", localtime(&mtime)); TEST_ASSERT_GREATER_THAN_INT(0, ftime); - TEST_ASSERT_EQUAL_STRING("1970-01-01 05:14:40", buffer); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40"); + TEST_ASSERT_EQUAL_STRING("1970-01-01 13:14:40", buffer); + LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40"); mtime = 18880; ftime = strftime(buffer, 80, "%D %w %H:%M:%S", localtime(&mtime)); TEST_ASSERT_GREATER_THAN_INT(0, ftime); - TEST_ASSERT_EQUAL_STRING("01/01/70 4 05:14:40", buffer); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "01/01/70 4 05:14:40"); + TEST_ASSERT_EQUAL_STRING("01/01/70 4 13:14:40", buffer); + LOG("\nresult: %s, expected : %s", buffer, "01/01/70 4 13:14:40"); }; /* * * @tc.number SUB_KERNEL_TIME_STRFTIME_002 - * @tc.name test strftime api for unsupport param + * @tc.name test strftime api base case * @tc.desc [C- SOFTWARE -0200] */ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeStrftime002, Function | MediumTest | Level3) @@ -489,20 +459,19 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeStrftime002, Function | MediumTes struct tm *tmTime = localtime(&mtime); ftime = strftime(buffer, 80, "%Ex %EX %A", tmTime); - TEST_ASSERT_EQUAL_INT(0, ftime); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40"); + TEST_ASSERT_GREATER_THAN_INT(0, ftime); + TEST_ASSERT_EQUAL_STRING("01/01/70 13:14:40 Thursday", buffer); + LOG("\nresult: %s, expected : %s", buffer, "01/01/70 13:14:40 Thursday"); ftime = strftime(buffer, 80, "%x %X", tmTime); - TEST_ASSERT_EQUAL_INT(0, ftime); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40"); + TEST_ASSERT_GREATER_THAN_INT(0, ftime); + TEST_ASSERT_EQUAL_STRING("01/01/70 13:14:40", buffer); + LOG("\nresult: %s, expected : %s", buffer, "01/01/70 13:14:40"); ftime = strftime(buffer, 80, "%D %A %H:%M:%S", tmTime); - TEST_ASSERT_EQUAL_INT(0, ftime); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40"); - - ftime = strftime(buffer, 80, "%F %T %Z", tmTime); - TEST_ASSERT_EQUAL_INT(0, ftime); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40"); + TEST_ASSERT_GREATER_THAN_INT(0, ftime); + TEST_ASSERT_EQUAL_STRING("01/01/70 Thursday 13:14:40", buffer); + LOG("\nresult: %s, expected : %s", buffer, "01/01/70 Thursday 13:14:40"); }; /* * @@ -519,32 +488,24 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeStrftime003, Function | MediumTes ftime = strftime(buffer, 12, "%Y-%m-%d %H:%M:%S", tmTime); TEST_ASSERT_EQUAL_INT(0, ftime); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40"); - - ftime = strftime(NULL, 80, "%Y-%m-%d %H:%M:%S", tmTime); - TEST_ASSERT_EQUAL_INT(0, ftime); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40"); + LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40"); ftime = strftime(buffer, 80, "", tmTime); TEST_ASSERT_EQUAL_INT(0, ftime); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40"); - - ftime = strftime(buffer, 80, NULL, tmTime); - TEST_ASSERT_EQUAL_INT(0, ftime); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40"); - - ftime = strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", NULL); - TEST_ASSERT_EQUAL_INT(0, ftime); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40"); + LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40"); ftime = strftime(buffer, 19, "%Y-%m-%d %H:%M:%S", tmTime); TEST_ASSERT_EQUAL_INT(0, ftime); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40"); + LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40"); ftime = strftime(buffer, 20, "%Y-%m-%d %H:%M:%S", tmTime); TEST_ASSERT_EQUAL_INT(19, ftime); - TEST_ASSERT_EQUAL_STRING("1970-01-01 05:14:40", buffer); - PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40"); + TEST_ASSERT_EQUAL_STRING("1970-01-01 13:14:40", buffer); + LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40"); + + ftime = strftime(buffer, 80, "%F %T %Z", tmTime); + TEST_ASSERT_EQUAL_INT(0, ftime); + LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40"); }; /* * @@ -559,18 +520,18 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimes, Function | MediumTest | Level1 struct tms start = { 0 }; struct tms end = { 0 }; clock_t stTime = times(&start); - PRINT_EMG("start_clock: stTime: %ld", stTime); - PRINT_EMG("start_clock: tms_utime: %ld, tms_stime: %ld, tms_cutime:%ld, tms_cstime:%ld", start.tms_utime, + LOG("start_clock: stTime: %ld", stTime); + LOG("start_clock: tms_utime: %ld, tms_stime: %ld, tms_cutime:%ld, tms_cstime:%ld", start.tms_utime, start.tms_stime, start.tms_cutime, start.tms_cstime); KeepRun(testClockt * msPerClock); clock_t endTime = times(&end); - PRINT_EMG("end_clock: endTime: %ld", endTime); - PRINT_EMG("end_clock: tms_utime: %ld, tms_stime: %ld, tms_cutime:%ld, tms_cstime:%ld", end.tms_utime, end.tms_stime, + LOG("end_clock: endTime: %ld", endTime); + LOG("end_clock: tms_utime: %ld, tms_stime: %ld, tms_cutime:%ld, tms_cstime:%ld", end.tms_utime, end.tms_stime, end.tms_cutime, end.tms_cstime); - PRINT_EMG("Real Time: %ld, User Time %ld, System Time %ld\n", (long)(endTime - stTime), + LOG("Real Time: %ld, User Time %ld, System Time %ld\n", (long)(endTime - stTime), (long)(end.tms_utime - start.tms_utime), (long)(end.tms_stime - start.tms_stime)); if (!CheckValueClose((end.tms_utime - start.tms_utime), testClockt, 0.02)) { @@ -583,13 +544,13 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimes, Function | MediumTest | Level1 RUN_TEST_SUITE(PosixTimeFuncTestSuite); - void PosixTimeFuncTest() { - PRINT_EMG("begin PosixTimeFuncTest...."); + LOG("begin PosixTimeFuncTest...."); + RUN_ONE_TESTCASE(testTimeUSleep001); RUN_ONE_TESTCASE(testTimeUSleep002); - RUN_ONE_TESTCASE(testTimeUSleep003); + RUN_ONE_TESTCASE(testTimeGmtime001); RUN_ONE_TESTCASE(testTimeLocaltime001); RUN_ONE_TESTCASE(testTimeLocaltime002); @@ -600,7 +561,6 @@ void PosixTimeFuncTest() RUN_ONE_TESTCASE(testTimeStrftime001); RUN_ONE_TESTCASE(testTimeStrftime002); RUN_ONE_TESTCASE(testTimeStrftime003); - RUN_ONE_TESTCASE(testTimes); return; }