fix:codex及合规问题修复

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I5a738c243a07325b7cc314956a1658a69e768559
This commit is contained in:
arvinzzz
2022-03-07 16:56:26 +08:00
parent 31403e0e45
commit 64ddb1ff07
10 changed files with 52 additions and 264 deletions

View File

@@ -54,28 +54,6 @@ struct _scenar_028 {
#define NSCENAR (sizeof(g_scenarii028) / sizeof(g_scenarii028[0]))
/* pthread_mutex_destroy 2-2.c
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* This sample test aims to check the following assertion:
*
* pthread_mutex_init() can be used to re-initialize a destroyed mutex.
* The steps are:
* -> Initialize a mutex with a given attribute.
* -> Destroy the mutex
* -> Initialize again the mutex with another attribute.
*/
static UINT32 Testcase(VOID)
{
int ret;
@@ -85,25 +63,20 @@ static UINT32 Testcase(VOID)
pthread_mutexattr_t *pma[NSCENAR + 2];
long pshared;
/* System abilities */
pshared = sysconf(_SC_THREAD_PROCESS_SHARED);
/* Initialize the mutex attributes objects */
for (i = 0; i < NSCENAR; i++) {
ret = pthread_mutexattr_init(&ma[i]);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
}
/* Default mutexattr object */
ret = pthread_mutexattr_init(&ma[i]);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* Initialize the pointer array */
/* 2, The loop frequency. */
for (i = 0; i < NSCENAR + 2; i++)
for (i = 0; i < NSCENAR + 2; i++) // 2, The loop frequency.
/* NULL pointer */
pma[i] = NULL;
/* Ok, we can now proceed to the test */
for (i = 0; i < NSCENAR + 2; i++) { // 2, The loop frequency.
for (j = 0; j < NSCENAR + 2; j++) { // 2, The loop frequency.
ret = pthread_mutex_init(&mtx, pma[i]);

View File

@@ -40,51 +40,15 @@ extern "C" {
static pthread_mutex_t g_mutex038;
static sem_t g_sem038;
/* pthread_mutex_lock 4-1.c
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* This sample test aims to check the following assertion:
*
* If the mutex type is PTHREAD_MUTEX_RECURSIVE,
* then the mutex maintains the concept of a lock count.
* When a thread successfully acquires a mutex for the first time,
* the lock count is set to one. Every time a thread relocks this mutex,
* the lock count is incremented by one.
* Each time the thread unlocks the mutex,
* the lock count is decremented by one.
* When the lock count reaches zero,
* the mutex becomes available and others threads can acquire it.
* The steps are:
* ->Create a mutex with recursive attribute
* ->Create a threads
* ->Parent locks the mutex twice, unlocks once.
* ->Child attempts to lock the mutex.
* ->Parent unlocks the mutex.
* ->Parent unlocks the mutex (shall fail)
* ->Child unlocks the mutex.
*/
static void *TaskF01(void *arg)
{
int ret;
/* Try to lock the mutex once. The call must fail here. */
ret = pthread_mutex_trylock(&g_mutex038);
if (ret == 0) {
ICUNIT_GOTO_EQUAL(1, 0, ret, EXIT);
}
/* Free the parent thread and lock the mutex (must success) */
if ((ret = sem_post(&g_sem038))) {
ICUNIT_GOTO_EQUAL(1, 0, ret, EXIT);
}
@@ -93,12 +57,10 @@ static void *TaskF01(void *arg)
ICUNIT_GOTO_EQUAL(1, 0, ret, EXIT);
}
/* Wait for the parent to let us go on */
if ((ret = sem_post(&g_sem038))) {
ICUNIT_GOTO_EQUAL(1, 0, ret, EXIT);
}
/* Unlock and exit */
if ((ret = pthread_mutex_unlock(&g_mutex038))) {
ICUNIT_GOTO_EQUAL(1, 0, ret, EXIT);
}
@@ -113,12 +75,10 @@ static UINT32 Testcase(VOID)
pthread_mutexattr_t ma;
pthread_t child;
/* Initialize the semaphore */
if ((ret = sem_init(&g_sem038, 0, 0))) {
ICUNIT_ASSERT_EQUAL(1, 0, ret);
}
/* We initialize the recursive mutex */
if ((ret = pthread_mutexattr_init(&ma))) {
ICUNIT_ASSERT_EQUAL(1, 0, ret);
}
@@ -135,9 +95,6 @@ static UINT32 Testcase(VOID)
ICUNIT_ASSERT_EQUAL(1, 0, ret);
}
/* -- The mutex is now ready for testing -- */
/* First, we lock it twice and unlock once */
if ((ret = pthread_mutex_lock(&g_mutex038))) {
ICUNIT_ASSERT_EQUAL(1, 0, ret);
}
@@ -150,40 +107,31 @@ static UINT32 Testcase(VOID)
ICUNIT_ASSERT_EQUAL(1, 0, ret);
}
/* Here this thread owns the mutex and the internal count is "1" */
/* We create the child thread */
if ((ret = pthread_create(&child, NULL, TaskF01, NULL))) {
ICUNIT_ASSERT_EQUAL(1, 0, ret);
}
/* then wait for child to be ready */
if ((ret = sem_wait(&g_sem038))) {
ICUNIT_ASSERT_EQUAL(1, 0, ret);
}
/* We can now unlock the mutex */
if ((ret = pthread_mutex_unlock(&g_mutex038))) {
ICUNIT_ASSERT_EQUAL(1, 0, ret);
}
/* We wait for the child to lock the mutex */
if ((ret = sem_wait(&g_sem038))) {
ICUNIT_ASSERT_EQUAL(1, 0, ret);
}
/* Then, try to unlock the mutex (owned by the child or unlocked) */
ret = pthread_mutex_unlock(&g_mutex038);
if (ret == ENOERR) {
ICUNIT_ASSERT_EQUAL(1, 0, ret);
}
/* Everything seems OK here */
if ((ret = pthread_join(child, NULL))) {
ICUNIT_ASSERT_EQUAL(1, 0, ret);
}
/* Simple loop to double-check */
for (i = 0; i < 50; i++) { // 50, The loop frequency.
if ((ret = pthread_mutex_lock(&g_mutex038))) {
ICUNIT_ASSERT_EQUAL(1, 0, ret);
@@ -199,7 +147,6 @@ static UINT32 Testcase(VOID)
if (ret == 0) {
ICUNIT_ASSERT_EQUAL(1, 0, ret);
}
/* The test passed, we destroy the mutex */
if ((ret = pthread_mutex_destroy(&g_mutex038))) {
ICUNIT_ASSERT_EQUAL(1, 0, ret);
}

View File

@@ -39,29 +39,6 @@ extern "C" {
static pthread_mutex_t g_mutex042;
/* pthread_mutex_unlock 5-1.c
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This sample test aims to check the following assertion:
* If the mutex type is PTHREAD_MUTEX_RECURSIVE,
* and a thread attempts to unlock a mutex that it does not own,
* an uwErr is returned.
* The steps are:
* -> Initialize and lock a recursive mutex
* -> create a child thread which tries to unlock this mutex. *
*/
static void *TaskF01(void *arg)
{
int ret;

View File

@@ -36,31 +36,6 @@ extern "C" {
#endif /* __cpluscplus */
#endif /* __cpluscplus */
/* pthread_mutex_unlock 5-2.c
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This sample test aims to check the following assertion:
* If the mutex type is PTHREAD_MUTEX_RECURSIVE,
* and a thread attempts to unlock an unlocked mutex,
* an uwErr is returned.
* The steps are:
* -> Initialize a recursive mutex
* -> Attempt to unlock the mutex when it is unlocked
* and when it has been locked then unlocked.
*/
static UINT32 Testcase(VOID)
{
int ret;

View File

@@ -39,33 +39,6 @@ extern "C" {
static pthread_mutex_t g_mutex045;
/* pthread_mutex_trylock 1-2.c
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* This sample test aims to check the following assertion:
*
* The pthread_mutex_trylock() function locks the mutex object
* when it is unlocked.
* The steps are:
*
* -> For each kind of mutex,
* -> trylock the mutex. It shall suceed.
* -> trylock the mutex again. It shall fail (except in case of recursive mutex).
* -> create a new child (either thread or process)
* -> the new child trylock the mutex. It shall fail.
* -> undo everything.
*/
static VOID *TaskF01(void *argument)
{
int ret;

View File

@@ -39,36 +39,6 @@ extern "C" {
static pthread_mutex_t g_mutex046;
static UINT32 g_nID;
/* pthread_mutex_trylock 2-1.c
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* This sample test aims to check the following assertion:
*
* If the mutex is of type PTHREAD_MUTEX_RECURSIVE,
* and the calling thread already owns the mutex,
* the call is successful (the lock count is incremented).
* The steps are:
*
* -> trylock the mutex. It shall suceed.
* -> trylock the mutex again. It shall suceed again
* -> unlock once
* -> create a new child (either thread or process)
* -> the new child trylock the mutex. It shall fail.
* -> Unlock. It shall succeed.
* -> Unlock again. It shall fail.
* -> undo everything.
*/
static void *TaskF01(void *arg)
{
int ret;

View File

@@ -39,31 +39,6 @@ extern "C" {
static pthread_mutex_t g_mutex049;
/* pthread_mutex_trylock 4-2.c
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* This sample test aims to check the following assertion:
*
* If the mutex was already locked, the call returns EBUSY immediatly.
* The steps are:
* -> Set a timeout.
* -> For each kind of mutex,
* -> Lock the mutex.
* -> create a new child (either thread or process)
* -> the new child trylock the mutex. It shall fail.
* -> undo everything.
*/
static VOID *TaskF01(void *argument)
{
int ret;

View File

@@ -41,38 +41,6 @@ static pthread_mutex_t *g_mtx;
static sem_t g_semA, g_semB;
static pthread_mutex_t g_mtxNull, g_mtxDef;
/* pthread_mutex_init 1-2.c
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* This sample test aims to check the following assertion:
*
* If the mutex attribute pointer passed to pthread_mutex_init is NULL,
* the effects on the mutex are the same as if a default mutex attribute object had been passed.
*
* The steps are:
* * create two mutexes. One is initialized with NULL attribute, the other with a default attribute object.
* * Compare the following features between the two mutexes:
* -> Can it cause / detect a deadlock? (attempt to lock a mutex the thread already owns).
* If detected, do both mutexes cause the same uwErr code?
* -> Is an uwErr returned when unlocking the mutex in unlocked state?
* When unlocking the mutex owned by another thread?
*
* The test will pass if the results of each feature are the same for the two mutexes
* (making no assumption on what is the default behavior).
* The test will be unresolved if any initialization fails.
* The test will fail if a feature differs between the two mutex objects.
*/
static void *TaskF01(void *arg)
{
int ret;