fix: 内核告警修复

【背景】
经代码扫描工具检测,内核代码中存在
可以修复的告警

【修改方案】
1.将单语句的if, while等加上括号
2.将C语言风格的类型转换变为C++风格

【影响】
对现有的产品编译不会有影响。

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: I7d4a04a8904abb3c33e843049bf15f4386d3efd8
This commit is contained in:
yinjiaming
2022-09-09 11:50:48 +08:00
parent 71e51d8813
commit 96b2d557ac
155 changed files with 532 additions and 460 deletions

View File

@@ -118,7 +118,7 @@ static UINT32 testcase(VOID)
locale_t newloc = nullptr;
char *pathList[] = {"/storage/zh_CN.UTF-8"};
char *streamList[] = {(char *)fileWords};
char *streamList[] = {reinterpret_cast<char *>(fileWords)};
int streamLen[] = {sizeof(fileWords) - 2};
newloc = duplocale(oldloc);

View File

@@ -41,8 +41,8 @@ static UINT32 testcase(VOID) {
setlocale(LC_NUMERIC, "");
/* echo the nl_langinfo_l */
printf("%s\n", nl_langinfo_l(CODESET, (locale_t)"en_US.UTF-8"));
printf("%s\n", nl_langinfo_l(RADIXCHAR, (locale_t)"en_US.UTF-8"));
printf("%s\n", nl_langinfo_l(CODESET, reinterpret_cast<locale_t>(const_cast<char *>("en_US.UTF-8"))));
printf("%s\n", nl_langinfo_l(RADIXCHAR, reinterpret_cast<locale_t>(const_cast<char *>("en_US.UTF-8"))));
/* set the locale info */
setenv("MUSL_LOCPATH", "/storage", 1);
@@ -53,10 +53,10 @@ static UINT32 testcase(VOID) {
setlocale(LC_NUMERIC, "");
/* echo the nl_langinfo */
printf("%s\n", nl_langinfo_l(CODESET, (locale_t)"zh_CN.UTF-8"));
printf("%s\n", nl_langinfo_l(RADIXCHAR, (locale_t)"zh_CN.UTF-8"));
printf("%s\n", nl_langinfo_l(CODESET, reinterpret_cast<locale_t>(const_cast<char *>("zh_CN.UTF-8"))));
printf("%s\n", nl_langinfo_l(RADIXCHAR, reinterpret_cast<locale_t>(const_cast<char *>("zh_CN.UTF-8"))));
char *string = nl_langinfo_l(CRNCYSTR, (locale_t)"zh_CN.UTF-8");
char *string = nl_langinfo_l(CRNCYSTR, reinterpret_cast<locale_t>(const_cast<char *>("zh_CN.UTF-8")));
ICUNIT_ASSERT_NOT_EQUAL_NULL(string, NULL, string);
setlocale(LC_ALL, "C");

View File

@@ -44,7 +44,7 @@ static UINT32 testcase(VOID)
char fileWords[] = "/dev/disk/by-uuid/c4992556-a86e-45e8-ba5f-190b16a9073x /usr1 ext3 errors=remount-ro,nofail 0 1";
char *pathList[] = {"/etc/fstab"};
char *streamList[] = {(char *)fileWords};
char *streamList[] = {static_cast<char *>(fileWords)};
int streamLen[] = {sizeof(fileWords)};
int flag = PrepareFileEnv(pathList, streamList, streamLen, 1);

View File

@@ -31,9 +31,9 @@
#include "It_test_misc.h"
#include "sys/utsname.h"
#define INVALID_ADDR_FIRST_PAGE ((struct utsname *)0x1200000)
#define INVALID_ADDR_USER_ADDR ((struct utsname *)0x1000000)
#define INVALID_ADDR_KERNEL_READONLY_ADDR ((struct utsname *)0x4016c75c)
#define INVALID_ADDR_FIRST_PAGE (reinterpret_cast<struct utsname *>(0x1200000))
#define INVALID_ADDR_USER_ADDR (reinterpret_cast<struct utsname *>(0x1000000))
#define INVALID_ADDR_KERNEL_READONLY_ADDR (reinterpret_cast<struct utsname *>(0x4016c75c))
static UINT32 TestCase(VOID)
{

View File

@@ -43,11 +43,11 @@ static VOID *PthreadF01(VOID *mq)
LOS_AtomicInc(&g_testCount);
pthread_exit((void *)0);
pthread_exit(nullptr);
return NULL;
EXIT:
pthread_exit((void *)0);
pthread_exit(nullptr);
g_testCount = 0;
return NULL;
}
@@ -64,11 +64,11 @@ static VOID *PthreadF02(VOID *mq)
}
LOS_AtomicInc(&g_testCount);
pthread_exit((void *)0);
pthread_exit(nullptr);
return NULL;
EXIT:
pthread_exit((void *)0);
pthread_exit(nullptr);
g_testCount = 0;
return NULL;
}
@@ -85,11 +85,11 @@ static VOID *PthreadF03(VOID *mq)
}
LOS_AtomicInc(&g_testCount);
pthread_exit((void *)0);
pthread_exit(nullptr);
return NULL;
EXIT:
pthread_exit((void *)0);
pthread_exit(nullptr);
g_testCount = 0;
return NULL;
}
@@ -107,11 +107,11 @@ static VOID *PthreadF04(VOID *mq)
LOS_AtomicInc(&g_testCount);
pthread_exit((void *)0);
pthread_exit(nullptr);
return NULL;
EXIT:
pthread_exit((void *)0);
pthread_exit(nullptr);
g_testCount = 0;
return NULL;
}

View File

@@ -50,11 +50,11 @@ static VOID *PthreadF01(VOID *info)
LOS_AtomicInc(&g_testCount);
pthread_exit((void *)0);
pthread_exit(nullptr);
return NULL;
EXIT:
pthread_exit((void *)0);
pthread_exit(nullptr);
g_testCount = 0;
return NULL;
}
@@ -74,11 +74,11 @@ static VOID *PthreadF02(VOID *info)
LOS_AtomicInc(&g_testCount);
pthread_exit((void *)0);
pthread_exit(nullptr);
return NULL;
EXIT:
pthread_exit((void *)0);
pthread_exit(nullptr);
g_testCount = 0;
return NULL;
}

View File

@@ -41,11 +41,11 @@ static VOID *PthreadF01(VOID *arg)
}
LOS_AtomicInc(&g_testCount);
pthread_exit((void *)0);
pthread_exit(nullptr);
return NULL;
EXIT:
pthread_exit((void *)0);
pthread_exit(nullptr);
g_testCount = 0;
return NULL;
}
@@ -63,12 +63,12 @@ static VOID *PthreadF02(VOID *arg)
LOS_AtomicInc(&g_testCount);
pthread_exit((void *)0);
pthread_exit(nullptr);
return NULL;
EXIT:
g_testCount = 0;
pthread_exit((void *)0);
pthread_exit(nullptr);
return NULL;
}

View File

@@ -34,9 +34,9 @@ static VOID *pthread_f01(void *argument)
{
g_testCount = pthread_self();
pthread_exit((void *)8);
pthread_exit(static_cast<void *>(8)); // 8: exit value for testing
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)
{

View File

@@ -42,12 +42,13 @@ static VOID *pthread_f01(void *argument)
{
g_testCount++;
pthread_cleanup_push(PthreadCleanF01, (void *)8);
if (argument)
return (void *)8;
pthread_cleanup_push(PthreadCleanF01, static_cast<void *>(8)); // 8:arg that routine is called with
if (argument) {
return static_cast<void *>(8); // 8: return value for testing if argument is not NULL
}
pthread_cleanup_pop(0);
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -42,11 +42,11 @@ static VOID *pthread_f01(void *argument)
{
g_testCount++;
pthread_cleanup_push(PthreadCleanF01, (void *)8);
pthread_exit((void *)8);
pthread_cleanup_push(PthreadCleanF01, static_cast<void *>(8)); // 8: arg that routine is called with
pthread_exit(static_cast<void *>(8)); // 8: exit value for testing
pthread_cleanup_pop(1);
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -43,11 +43,11 @@ static VOID *pthread_f01(void *argument)
g_testCount++;
LosTaskDelay(5);
pthread_cleanup_push(PthreadCleanF01, (void *)8);
pthread_cleanup_push(PthreadCleanF01, static_cast<void *>(8)); // 8: arg that routine is called with
pthread_testcancel();
pthread_cleanup_pop(1);
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -46,13 +46,13 @@ static VOID *pthread_f01(void *argument)
{
g_testCount++;
pthread_cleanup_push(PthreadCleanF01, (void *)9);
pthread_cleanup_push(PthreadCleanF01, (void *)8);
pthread_exit((void *)8);
pthread_cleanup_push(PthreadCleanF01, static_cast<void *>(9)); // 9: arg that routine is called with
pthread_cleanup_push(PthreadCleanF01, static_cast<void *>(8)); // 8: arg that routine is called with
pthread_exit(static_cast<void *>(8)); // 8: exit value for testing
pthread_cleanup_pop(1);
pthread_cleanup_pop(1);
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -34,7 +34,7 @@ static VOID *pthread_f01(void *argument)
{
g_testCount++;
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -34,8 +34,8 @@ static VOID *pthread_f01(void *argument)
{
g_testCount++;
pthread_exit((void *)8);
return (void *)9;
pthread_exit(static_cast<void *>(8)); // 8: exit value for testing
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)
{

View File

@@ -37,7 +37,7 @@ static VOID *pthread_f01(void *argument)
pthread_testcancel();
g_testCount++;
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)
{

View File

@@ -39,7 +39,7 @@ static VOID *pthread_f01(void *argument)
ret = pthread_join(g_newTh, NULL);
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -43,7 +43,7 @@ static VOID *pthread_f01(void *argument)
g_testCount++;
ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT);
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static VOID *pthread_f02(void *argument)
@@ -59,7 +59,7 @@ static VOID *pthread_f02(void *argument)
g_testCount++;
ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT);
EXIT:
return (void *)8;
return static_cast<void *>(8); // 8: return value for testing
}
static VOID *PthreadF03(void *argument)
@@ -76,7 +76,7 @@ static VOID *PthreadF03(void *argument)
ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT);
EXIT:
return (void *)7;
return static_cast<void *>(7); // 7: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -47,7 +47,7 @@ static VOID *pthread_f01(void *argument)
g_testCnt1++;
ICUNIT_GOTO_EQUAL(g_testCnt1, 4, g_testCnt1, EXIT);
EXIT:
return (void *)9;
return reinterpret_cast<void *>(9); // 9: return value for testing
}
static VOID *pthread_f02(void *argument)
@@ -67,7 +67,7 @@ static VOID *pthread_f02(void *argument)
g_testCnt1++;
ICUNIT_GOTO_EQUAL(g_testCnt1, 5, g_testCnt1, EXIT);
EXIT:
return (void *)8;
return reinterpret_cast<void *>(8); // 8:return value for testing
}
static VOID *PthreadF03(void *argument)
@@ -88,7 +88,7 @@ static VOID *PthreadF03(void *argument)
ICUNIT_GOTO_EQUAL(g_testCnt1, 6, g_testCnt1, EXIT);
EXIT:
return (void *)7;
return reinterpret_cast<void *>(7); // 7: return value for testing
}
static UINT32 Testcase(VOID)
{
@@ -108,8 +108,9 @@ static UINT32 Testcase(VOID)
ret = pthread_create(&newTh3, NULL, PthreadF03, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
while (g_testCnt1 < 6)
while (g_testCnt1 < 6) { // 6: threshold for calling sleep
sleep(1);
}
ICUNIT_ASSERT_EQUAL(g_testCnt1, 6, g_testCnt1);

View File

@@ -36,7 +36,7 @@ static VOID *PthreadF01(void *argument)
LosTaskDelay(2);
pthread_testcancel();
g_testCount++;
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -36,7 +36,7 @@ static VOID *pthread_f01(void *argument)
LosTaskDelay(2);
g_testCount++;
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)
{

View File

@@ -36,7 +36,7 @@ static VOID *pthread_f01(void *argument)
LosTaskDelay(2);
g_testCount++;
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)
{

View File

@@ -47,7 +47,7 @@ static VOID *pthread_f02(void *argument)
ICUNIT_GOTO_EQUAL(param.sched_priority, 3, param.sched_priority, EXIT);
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static VOID *pthread_f01(void *argument)
@@ -89,7 +89,7 @@ static VOID *pthread_f01(void *argument)
ret = pthread_attr_destroy(&attr);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)
{

View File

@@ -39,7 +39,7 @@ static VOID *pthread_f01(void *argument)
g_testCount++;
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -37,7 +37,7 @@ static VOID *pthread_f01(void *argument)
g_testCount++;
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -49,7 +49,7 @@ static VOID *pthread_f01(void *argument)
ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // not reachable
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)
{

View File

@@ -53,7 +53,7 @@ static VOID *pthread_f01(void *argument)
g_testCount++;
ICUNIT_GOTO_EQUAL(g_testCount, 4, g_testCount, EXIT);
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static VOID *pthread_f02(void *argument)
@@ -79,7 +79,7 @@ static VOID *pthread_f02(void *argument)
g_testCount++;
ICUNIT_GOTO_EQUAL(g_testCount, 6, g_testCount, EXIT);
EXIT:
return (void *)8;
return static_cast<void *>(8); // 8: return value for testing
}
static VOID *PthreadF03(void *argument)
@@ -107,7 +107,7 @@ static VOID *PthreadF03(void *argument)
ICUNIT_GOTO_EQUAL(g_testCount, 8, g_testCount, EXIT);
EXIT:
return (void *)7;
return static_cast<void *>(7); // 7: return value for testing
}
static void PthreadKeyF01(void *threadLog)

View File

@@ -71,7 +71,7 @@ static VOID *pthread_f01(void *argument)
g_testCount++;
ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT);
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static VOID *pthread_f02(void *argument)
@@ -115,7 +115,7 @@ static VOID *pthread_f02(void *argument)
g_testCount++;
ICUNIT_GOTO_EQUAL(g_testCount, 7, g_testCount, EXIT);
EXIT:
return (void *)8;
return static_cast<void *>(8); // 8: return value for testing
}
static void PthreadKeyF01(void *threadLog)
{

View File

@@ -49,9 +49,9 @@ static VOID *pthread_f01(void *argument)
g_testCount++;
ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT);
pthread_exit((void *)7);
pthread_exit(static_cast<void *>(7)); // 7: exit value for testing
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static void PthreadKeyF01(void *threadLog)

View File

@@ -51,7 +51,7 @@ static VOID *pthread_f01(void *argument)
pthread_testcancel();
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static void PthreadKeyF01(void *threadLog)

View File

@@ -41,7 +41,7 @@ static VOID *pthread_f01(void *argument)
ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT); // failed, =2
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -33,7 +33,7 @@
static VOID *pthread_f02(void *argument)
{
g_testCount++;
return (void *)8;
return static_cast<void *>(8); // 8: return value for testing
}
static VOID *pthread_f01(void *argument)
{
@@ -54,7 +54,7 @@ static VOID *pthread_f01(void *argument)
ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT);
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -50,7 +50,7 @@ static VOID *pthread_f01(void *argument)
ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT);
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)
{

View File

@@ -45,7 +45,7 @@ static VOID *pthread_f01(void *argument)
ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT);
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -51,7 +51,7 @@ static VOID *pthread_f01(void *argument)
ICUNIT_GOTO_EQUAL(g_testCount, 0, g_testCount, EXIT);
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)
{

View File

@@ -52,7 +52,7 @@ static VOID *pthread_f01(void *argument)
ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT);
EXIT:
return (void *)9;
return reinterpret_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)
{

View File

@@ -44,7 +44,7 @@ static VOID *pthread_f02(void *argument)
ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT);
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static VOID *pthread_f01(void *argument)
@@ -86,7 +86,7 @@ static VOID *pthread_f01(void *argument)
ICUNIT_GOTO_EQUAL(g_testCount, 4, g_testCount, EXIT);
#endif
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -69,8 +69,9 @@ static UINT32 Testcase(VOID)
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
}
while (g_startNum < THREAD_NUM)
while (g_startNum < THREAD_NUM) {
usleep(1000 * 10 * 2);
}
/*
* Acquire the mutex to make sure that all waiters are currently

View File

@@ -74,8 +74,9 @@ static UINT32 Testcase(VOID)
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
}
while (g_startNum < THREAD_NUM)
while (g_startNum < THREAD_NUM) {
usleep(1000 * 10 * 2);
}
/*
* Acquire the mutex to make sure that all waiters are currently
* blocked on pthread_cond_wait

View File

@@ -81,8 +81,9 @@ static UINT32 Testcase(VOID)
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
}
while (g_startNum < THREAD_NUM)
while (g_startNum < THREAD_NUM) {
usleep(1000 * 10 * 2);
}
/*
* Acquire the mutex to make sure that all waiters are currently

View File

@@ -70,8 +70,9 @@ static UINT32 Testcase(VOID)
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
}
while (g_startNum < THREAD_NUM)
while (g_startNum < THREAD_NUM) {
usleep(1000 * 10 * 2);
}
/*
* Acquire the mutex to make sure that all waiters are currently

View File

@@ -73,8 +73,9 @@ static UINT32 Testcase(VOID)
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
}
while (g_startNum < THREAD_NUM)
while (g_startNum < THREAD_NUM) {
usleep(1000 * 10 * 2);
}
/*
* Acquire the mutex to make sure that all waiters are currently

View File

@@ -68,8 +68,9 @@ static UINT32 Testcase(VOID)
rc = pthread_create(&thread1, NULL, pthread_f01, NULL);
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
while (!g_t1Start) /* wait for thread1 started */
while (!g_t1Start) { /* wait for thread1 started */
usleep(1000 * 10 * 2);
}
/* acquire the mutex released by pthread_cond_wait() within thread 1 */
rc = pthread_mutex_lock(&g_td.mutex);

View File

@@ -57,7 +57,7 @@ static void *pthread_f01(void *arg)
rc = pthread_mutex_unlock(&g_td.mutex);
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
EXIT:
pthread_exit((void *)5);
pthread_exit(static_cast<void *>(5)); // 5: return value for testing
}
static UINT32 Testcase(VOID)
@@ -78,9 +78,9 @@ static UINT32 Testcase(VOID)
rc = pthread_create(&thread1, NULL, pthread_f01, NULL);
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
while (!g_t1Start) /* wait for thread1 started */
while (!g_t1Start) { /* wait for thread1 started */
usleep(1000 * 10 * 2);
}
/* acquire the mutex released by pthread_cond_wait() within thread 1 */
rc = pthread_mutex_lock(&g_td.mutex);
@@ -92,7 +92,7 @@ static UINT32 Testcase(VOID)
g_signaled = 1;
rc = pthread_join(thread1, &thRet);
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
ICUNIT_ASSERT_EQUAL((long)thRet, 5, (long)thRet);
ICUNIT_ASSERT_EQUAL(static_cast<long>(thRet), 5, static_cast<long>(thRet)); // 5: return value for testing
g_signaled = 0;
rc = pthread_cond_destroy(&g_td.cond);

View File

@@ -108,8 +108,9 @@ static void *pthread_f02(void *tmp)
clock_gettime(CLOCK_REALTIME, &startTime);
while (1) {
clock_gettime(CLOCK_REALTIME, &currentTime);
if (PthreadTimeF01(currentTime, startTime) > RUNTIME)
if (PthreadTimeF01(currentTime, startTime) > RUNTIME) {
break;
}
}
g_lowDone = 1;
EXIT:

View File

@@ -111,8 +111,9 @@ static void *pthread_f02(void *tmp)
clock_gettime(CLOCK_REALTIME, &startTime);
while (1) {
clock_gettime(CLOCK_REALTIME, &currentTime);
if (PthreadTimeF01(currentTime, startTime) > RUNTIME)
if (PthreadTimeF01(currentTime, startTime) > RUNTIME) {
break;
}
}
g_lowDone = 1;
EXIT:

View File

@@ -40,8 +40,9 @@ static void *pthread_f01(void *arg)
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
g_startNum++;
if (g_startNum > 5)
if (g_startNum > 5) { // 5: threshold for calling usleep
usleep(1000 * 10 * 2);
}
printf("pthread start_num: %d \n", g_startNum);
rc = pthread_cond_wait(&g_td.cond, &g_td.mutex);

View File

@@ -48,7 +48,7 @@ static VOID *pthread_f01(void *argument)
ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT);
EXIT:
return (void *)9;
return reinterpret_cast<void *>(9); // 9: return value for testing
}
static VOID *pthread_f02(void *argument)
@@ -72,7 +72,7 @@ static VOID *pthread_f02(void *argument)
printf("11\n");
ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // failed , =3
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)
{

View File

@@ -42,8 +42,9 @@ static void *pthread_f01(void *arg)
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
g_startNum++;
if (g_startNum > 5)
if (g_startNum > 5) { // 5: threshold for calling usleep
usleep(1000 * 10 * 2);
}
printf("pthread start_num: %d \n", g_startNum);
rc = pthread_cond_wait(&g_td.cond, &g_td.mutex);

View File

@@ -45,7 +45,7 @@ static VOID *pthread_f02(void *argument)
ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT);
g_testCount++;
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static VOID *pthread_f01(void *argument)
@@ -75,7 +75,7 @@ static VOID *pthread_f01(void *argument)
g_testCount++;
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -50,7 +50,7 @@ static VOID *pthread_f02(void *argument)
g_testCnt1++;
EXIT:
return (void *)9;
return reinterpret_cast<void *>(9); // 9: return value for testing
}
static VOID *pthread_f01(void *argument)
@@ -83,7 +83,7 @@ static VOID *pthread_f01(void *argument)
g_testCnt1++;
EXIT:
return (void *)9;
return static_cast<void *>(9); // 9: return value for testing
}
static UINT32 Testcase(VOID)

View File

@@ -32,7 +32,7 @@
static VOID *pthread_f01(void *t)
{
long myId = (long)t;
long myId = static_cast<long>(t);
int rc;
rc = pthread_mutex_lock(&g_pthreadMutexTest1);
@@ -58,7 +58,7 @@ EXIT:
static VOID *pthread_f02(void *t)
{
int i;
long myId = (long)t;
long myId = static_cast<long>(t);
int rc;
ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT);
@@ -74,7 +74,7 @@ static VOID *pthread_f02(void *t)
ICUNIT_GOTO_EQUAL(g_testCount, 4, g_testCount, EXIT);
g_testCount++;
rc = pthread_mutex_unlock(&g_pthreadMutexTest1); /* Ϊ<>߳<EFBFBD><DFB3><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ */
rc = pthread_mutex_unlock(&g_pthreadMutexTest1); /* Ϊ<>߳<EFBFBD><DFB3><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ */
ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT);
LosTaskDelay(2);
@@ -87,11 +87,11 @@ static UINT32 Testcase(VOID)
long t1 = 1, t2 = 2, t3 = 3;
int rc;
pthread_t threads[3];
pthread_attr_t attr; /* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
pthread_attr_t attr; /* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
g_testCount = 0;
pthread_mutex_init(&g_pthreadMutexTest1, NULL);
pthread_cond_init(&g_pthreadCondTest1, NULL); /* <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>ʱ<EFBFBD><CAB1>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ */
pthread_cond_init(&g_pthreadCondTest1, NULL); /* <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>ʱ<EFBFBD><CAB1>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ */
pthread_attr_init(&attr);
rc = pthread_create(&threads[0], &attr, pthread_f01, (void *)t1);
@@ -101,13 +101,13 @@ static UINT32 Testcase(VOID)
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
/* <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD> */
/* <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD> */
for (i = 0; i < 2; i++) {
rc = pthread_join(threads[i], NULL);
ICUNIT_ASSERT_EQUAL(rc, 0, rc);
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD> */
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD> */
rc = pthread_attr_destroy(&attr);
ICUNIT_ASSERT_EQUAL(rc, 0, rc);

View File

@@ -51,8 +51,9 @@ static UINT32 Testcase(VOID)
ICUNIT_ASSERT_EQUAL(ret, PTHREAD_NO_ERROR, ret);
/* Make sure the thread was created before we join it. */
while (g_pthreadSem == PTHREAD_INTHREAD_TEST)
while (g_pthreadSem == PTHREAD_INTHREAD_TEST) {
sleep(1);
}
ret = pthread_join(newTh, &valuePtr);
ICUNIT_ASSERT_EQUAL(ret, PTHREAD_NO_ERROR, ret);

View File

@@ -52,8 +52,9 @@ static VOID *pthread_f01(VOID *tmp)
g_pthreadSem = 1;
while (1)
while (1) {
sleep(5);
}
return NULL;
}
@@ -69,8 +70,9 @@ static UINT32 Testcase(VOID)
ret = pthread_create(&newTh, NULL, pthread_f01, NULL);
ICUNIT_ASSERT_EQUAL(ret, PTHREAD_NO_ERROR, ret);
while (g_pthreadSem == 0)
while (g_pthreadSem == 0) {
sleep(1);
}
ret = pthread_cancel(newTh);
ICUNIT_ASSERT_EQUAL(ret, PTHREAD_NO_ERROR, ret);

View File

@@ -44,8 +44,9 @@ static VOID *pthread_f01(VOID *argument)
g_pthreadSem = PTHREAD_INMAIN_TEST;
while (g_pthreadSem == PTHREAD_INMAIN_TEST)
while (g_pthreadSem == PTHREAD_INMAIN_TEST) {
sleep(1);
}
pthread_testcancel();
@@ -66,8 +67,9 @@ static UINT32 Testcase(VOID)
ret = pthread_create(&newTh, NULL, pthread_f01, NULL);
ICUNIT_ASSERT_EQUAL(ret, PTHREAD_NO_ERROR, ret);
while (g_pthreadSem == PTHREAD_INTHREAD_TEST)
while (g_pthreadSem == PTHREAD_INTHREAD_TEST) {
sleep(1);
}
ret = pthread_cancel(newTh);
ICUNIT_ASSERT_EQUAL(ret, PTHREAD_NO_ERROR, ret);

View File

@@ -41,8 +41,9 @@ static VOID *pthread_f01(VOID *argument)
g_pthreadSem = PTHREAD_INMAIN_TEST;
while (g_pthreadSem == PTHREAD_INMAIN_TEST)
while (g_pthreadSem == PTHREAD_INMAIN_TEST) {
sleep(1);
}
pthread_testcancel();
@@ -62,8 +63,9 @@ static UINT32 Testcase(VOID)
ret = pthread_create(&newTh, NULL, pthread_f01, NULL);
ICUNIT_ASSERT_EQUAL(ret, PTHREAD_NO_ERROR, ret);
while (g_pthreadSem == PTHREAD_INTHREAD_TEST)
while (g_pthreadSem == PTHREAD_INTHREAD_TEST) {
sleep(1);
}
ret = pthread_cancel(newTh);
ICUNIT_ASSERT_EQUAL(ret, PTHREAD_NO_ERROR, ret);

View File

@@ -41,8 +41,9 @@ static VOID *pthread_f01(VOID *argument)
g_pthreadSem = PTHREAD_INMAIN_TEST;
while (g_pthreadSem == PTHREAD_INMAIN_TEST)
while (g_pthreadSem == PTHREAD_INMAIN_TEST) {
sleep(1);
}
pthread_testcancel();
@@ -63,8 +64,9 @@ static UINT32 Testcase(VOID)
ret = pthread_create(&newTh, NULL, pthread_f01, NULL);
ICUNIT_ASSERT_EQUAL(ret, PTHREAD_NO_ERROR, ret);
while (g_pthreadSem == PTHREAD_INTHREAD_TEST)
while (g_pthreadSem == PTHREAD_INTHREAD_TEST) {
sleep(1);
}
ret = pthread_cancel(newTh);
ICUNIT_ASSERT_EQUAL(ret, PTHREAD_NO_ERROR, ret);

View File

@@ -62,24 +62,24 @@ sem_t g_pthreadSem1;
sem_t g_pthreadSem2;
__scenario g_scenarii[] = {
CASE_POS(0, 0, 0, 0, 0, 0, 0, 0, (char *)"default"),
CASE_POS(1, 0, 0, 0, 0, 0, 0, 0, (char *)"detached"),
CASE_POS(0, 1, 0, 0, 0, 0, 0, 0, (char *)"Explicit sched"),
CASE_UNK(0, 0, 1, 0, 0, 0, 0, 0, (char *)"FIFO Policy"),
CASE_UNK(0, 0, 2, 0, 0, 0, 0, 0, (char *)"RR Policy"),
CASE_UNK(0, 0, 0, 1, 0, 0, 0, 0, (char *)"Max sched param"),
CASE_UNK(0, 0, 0, -1, 0, 0, 0, 0, (char *)"Min sched param"),
CASE_POS(0, 0, 0, 0, 1, 0, 0, 0, (char *)"Alternative contension scope"),
CASE_POS(0, 0, 0, 0, 0, 1, 0, 0, (char *)"Alternative stack"),
CASE_POS(0, 0, 0, 0, 0, 0, 1, 0, (char *)"No guard size"),
CASE_UNK(0, 0, 0, 0, 0, 0, 2, 0, (char *)"1p guard size"),
CASE_POS(0, 0, 0, 0, 0, 0, 0, 1, (char *)"Min stack size"),
CASE_POS(0, 0, 0, 0, 0, 0, 0, 0, const_cast<char *>("default")),
CASE_POS(1, 0, 0, 0, 0, 0, 0, 0, const_cast<char *>("detached")),
CASE_POS(0, 1, 0, 0, 0, 0, 0, 0, const_cast<char *>("Explicit sched")),
CASE_UNK(0, 0, 1, 0, 0, 0, 0, 0, const_cast<char *>("FIFO Policy")),
CASE_UNK(0, 0, 2, 0, 0, 0, 0, 0, const_cast<char *>("RR Policy")),
CASE_UNK(0, 0, 0, 1, 0, 0, 0, 0, const_cast<char *>("Max sched param")),
CASE_UNK(0, 0, 0, -1, 0, 0, 0, 0, const_cast<char >("Min sched param")),
CASE_POS(0, 0, 0, 0, 1, 0, 0, 0, const_cast<char *>("Alternative contension scope")),
CASE_POS(0, 0, 0, 0, 0, 1, 0, 0, const_cast<char *>("Alternative stack")),
CASE_POS(0, 0, 0, 0, 0, 0, 1, 0, const_cast<char *>("No guard size")),
CASE_UNK(0, 0, 0, 0, 0, 0, 2, 0, const_cast<char *>("1p guard size")),
CASE_POS(0, 0, 0, 0, 0, 0, 0, 1, const_cast<char *>("Min stack size")),
/* Stack play */
CASE_POS(0, 0, 0, 0, 0, 0, 1, 1, (char *)"Min stack size, no guard"),
CASE_UNK(0, 0, 0, 0, 0, 0, 2, 1, (char *)"Min stack size, 1p guard"),
CASE_POS(1, 0, 0, 0, 0, 1, 0, 0, (char *)"Detached, Alternative stack"),
CASE_POS(1, 0, 0, 0, 0, 0, 1, 1, (char *)"Detached, Min stack size, no guard"),
CASE_UNK(1, 0, 0, 0, 0, 0, 2, 1, (char *)"Detached, Min stack size, 1p guard"),
CASE_POS(0, 0, 0, 0, 0, 0, 1, 1, const_cast<char *>("Min stack size, no guard")),
CASE_UNK(0, 0, 0, 0, 0, 0, 2, 1, const_cast<char *>("Min stack size, 1p guard")),
CASE_POS(1, 0, 0, 0, 0, 1, 0, 0, const_cast<char *>("Detached, Alternative stack")),
CASE_POS(1, 0, 0, 0, 0, 0, 1, 1, const_cast<char *>("Detached, Min stack size, no guard")),
CASE_UNK(1, 0, 0, 0, 0, 0, 2, 1, const_cast<char *>("Detached, Min stack size, 1p guard")),
};
pthread_t g_pthreadTestTh;

View File

@@ -32,7 +32,7 @@
static void *ThreadF01(void *arg)
{
pthread_exit((void *)2);
pthread_exit(static_cast<void *>(2)); // 2: return value for testing
return NULL;
}
static UINT32 Testcase(VOID)

View File

@@ -38,7 +38,7 @@ static void *ThreadF01(void *arg)
* function did not succeed. */
// uart_printf_func("Could not send cancel request correctly\n");
// ICUNIT_TRACK_EQUAL(1, 0, errno);
pthread_exit((void *)0);
pthread_exit(nullptr);
return NULL;
}
static UINT32 Testcase(VOID)

View File

@@ -37,7 +37,7 @@ static void *ThreadF01(void *arg)
// while (1)
sleep(1);
pthread_exit((void *)0);
pthread_exit(nullptr);
return NULL;
}

View File

@@ -39,9 +39,9 @@ static UINT32 TestCase(VOID)
int cflags;
regex_t reg;
char *a = NULL;
char *b = (char *)"No error";
char *testStr = (char *)"Hello World";
char *regStr = (char *)"H.*";
char *b = const_cast<char *>("No error");
char *testStr = const_cast<char *>("Hello World");
char *regStr = const_cast<char *>("H.*");
cflags = REG_EXTENDED | REG_ICASE | REG_NOSUB;

View File

@@ -33,8 +33,8 @@
static UINT32 TestCase(VOID)
{
char *val = NULL;
const char *name = (char *)"ABC";
char *env = (char *)"test-test";
const char *name = "ABC";
char *env = const_cast<char *>("test-test");
int ret;
val = getenv(name);

View File

@@ -33,7 +33,7 @@
static UINT32 TestCase(VOID)
{
char *plocale = NULL;
char *buffer = (char *)"C";
char *buffer = const_cast<char *>("C");
int ret;
plocale = setlocale(LC_ALL, NULL);

View File

@@ -34,8 +34,8 @@ static UINT32 TestCase(VOID)
{
char *val = NULL;
char *val2 = NULL;
const char *name = (char *)"ABC";
char *env = (char *)"test-test";
const char *name = "ABC";
char *env = "test-test";
int ret;
val = getenv(name);

View File

@@ -38,7 +38,7 @@ struct q {
static struct q *New(int i)
{
struct q *q = (struct q *)malloc(sizeof *q);
struct q *q = static_cast<struct q *>(malloc(sizeof *q));
if (q != NULL) {
q->i = i;
}

View File

@@ -35,7 +35,7 @@ static UINT32 TestCase(VOID)
char *ptr = NULL;
int ret;
ptr = basename((char *)".");
ptr = basename(const_cast<char *>("."));
ret = strcmp(ptr, ".");
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);

View File

@@ -51,8 +51,8 @@ static int SleepTest(int64_t expectTime)
ret = clock_gettime(clk, &oldtp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
tp.tv_sec = expectTime / (long)1e9;
tp.tv_nsec = expectTime % (long)1e9;
tp.tv_sec = expectTime / static_cast<long>(1e9);
tp.tv_nsec = expectTime % static_cast<long>(1e9);
ret = clock_nanosleep(clk, 0, &tp, nullptr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
@@ -60,7 +60,7 @@ static int SleepTest(int64_t expectTime)
ret = clock_gettime(clk, &tp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
escapeTime = (tp.tv_sec - oldtp.tv_sec) * (int64_t)1e9 + (tp.tv_nsec - oldtp.tv_nsec);
escapeTime = (tp.tv_sec - oldtp.tv_sec) * static_cast<int64_t>(1e9) + (tp.tv_nsec - oldtp.tv_nsec);
LogPrintln("slept time (expected --> actual): %" PRId64 "ns --> %" PRId64 "ns, delta: %" PRId64 "ns\n", expectTime,
escapeTime, escapeTime - expectTime);

View File

@@ -94,8 +94,9 @@ static int SetTimerTest(void)
ret = clock_gettime(CLOCKID, &end);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
expected = its.it_value.tv_sec * (int64_t)1e9 + its.it_value.tv_nsec;
escaped = end.tv_sec * (int64_t)1e9 + end.tv_nsec - start.tv_sec * (int64_t)1e9 - start.tv_nsec;
expected = its.it_value.tv_sec * static_cast<int64_t>(1e9) + its.it_value.tv_nsec;
escaped = end.tv_sec * static_cast<int64_t>(1e9) + end.tv_nsec - start.tv_sec * static_cast<int64_t>(1e9) -
start.tv_nsec;
failed += (escaped < expected || (escaped - expected) >= 20000000); // 20000000, 2 ticks.
}

View File

@@ -52,7 +52,7 @@ static void SigHandler(int sig, siginfo_t *si, void *uc)
#ifdef TEST_ON_LINUX
timer_t timerid = *(timer_t *)si->si_value.sival_ptr;
#else // SA_SIGINFO not compatible with POSIX on HMOS
timer_t timerid = *(timer_t *)si;
timer_t timerid = *reinterpret_cast<timer_t *>(si);
#endif
g_tmrOverrun += timer_getoverrun(timerid);

View File

@@ -69,7 +69,7 @@ static int TimerTest(void)
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
sev.sigev_notify = SIGEV_THREAD;
sev.sigev_notify_function = TempSigHandler;
sev.sigev_value.sival_ptr = (void *)TempSigHandler01;
sev.sigev_value.sival_ptr = reinterpret_cast<void *>(TempSigHandler01);
/* Start the timer */
its.it_value.tv_sec = 3; // 3, timer time 3 seconds.
@@ -89,7 +89,7 @@ static int TimerTest(void)
its.it_interval.tv_sec = its.it_value.tv_sec;
its.it_interval.tv_nsec = its.it_value.tv_nsec;
sev.sigev_value.sival_ptr = (void *)TempSigHandler02;
sev.sigev_value.sival_ptr = reinterpret_cast<void *>(TempSigHandler02);
ret = timer_create(CLOCK_REALTIME, &sev, &timerid02);
LogPrintln("timer_settime %p: %d", timerid02, ret);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);

View File

@@ -42,7 +42,7 @@ static UINT32 testcase(VOID)
int ret = 0;
errno = 0;
ret = putenv((char *) "TZ=GMT-100");
ret = putenv(const_cast<char *>("TZ=GMT-100"));
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
tzset();

View File

@@ -49,10 +49,10 @@ static void *Xmalloc(unsigned n)
static int Compare(const void *pa, const void *pb)
{
if (*(int *)pa < *(int *)pb) {
if (*static_cast<int *>(const_cast<void *>(pa)) < *static_cast<int *>(const_cast<void *>(pb))) {
return -1;
}
if (*(int *)pa > *(int *)pb) {
if (*static_cast<int *>(const_cast<void *>(pa)) > *static_cast<int *>(const_cast<void *>(pb))) {
return 1;
}
return 0;
@@ -66,12 +66,14 @@ static void Action(const void *nodep, VISIT which, int depth)
case preorder:
break;
case postorder:
datap = *(int **)nodep;
datap = *static_cast<int **>(const_cast<void *>(nodep));
break;
case endorder:
break;
case leaf:
datap = *(int **)nodep;
datap = *static_cast<int **>(const_cast<void *>(nodep));
break;
default:
break;
}
}
@@ -86,7 +88,7 @@ static UINT32 TestCase(VOID)
for (i = 0; i < 12; i++) {
ptr = (int *)Xmalloc(sizeof(int));
*ptr = rand() & 0xff;
val = tsearch((void *)ptr, &g_root, Compare);
val = tsearch(static_cast<void *>(ptr), &g_root, Compare);
if (val == NULL) {
exit(EXIT_FAILURE);
} else if ((*(int **)val) != ptr) {