!666 复sys部分用例因依赖passwd、group文件而失败

Merge pull request !666 from lnlan/sys_test_fixed
This commit is contained in:
openharmony_ci 2021-10-28 01:36:46 +00:00 committed by Gitee
commit 557f4ccb66
12 changed files with 398 additions and 248 deletions

View File

@ -107,6 +107,8 @@
#define HWI_NUM_INTVALID OS_HWI_MAX_NUM
#define writel(value, address) WRITE_UINT32(value, address)
extern UINT32 PrepareFileEnv(CHAR *pathList[], CHAR *streamList[], INT32 streamLen[], INT32 listCnt);
extern UINT32 RecoveryFileEnv(CHAR *pathList[], INT32 listCnt);
extern UINT32 PosixPthreadInit(pthread_attr_t *attr, int pri);
extern UINT32 PosixPthreadDestroy(pthread_attr_t *attr, pthread_t thread);
@ -233,18 +235,6 @@ UINT32 LosTaskDelay(UINT32 tick);
#define TEST_TASKDELAY_20TICK 20
#define TEST_TASKDELAY_50TICK 50
#ifdef TEST3731
#define TestTimer2ValueGet(temp) READ_UINT32(temp, TIMER1_REG_BASE + TIMER_VALUE)
#elif defined TEST3559
#define TestTimer2ValueGet(temp) READ_UINT32(temp, TIMER3_REG_BASE + TIMER_VALUE)
#else
#define TestTimer2ValueGet(temp) READ_UINT32(temp, TIMER2_REG_BASE + TIMER_VALUE)
#endif
extern void TestTimer2Config(void);
#define REALTIME(time) (UINT32)((UINT64)(0xffffffff - time) * 1000 / OS_SYS_CLOCK) /* accuracy:ms */
#define HW_TMI(time) (UINT32)((UINT64)(0xffffffff - time) * 1000 / (OS_SYS_CLOCK / 1000000)) /* accuracy:ns */
#define uart_printf_func printf
#ifndef VFS_STAT_PRINTF
@ -268,7 +258,6 @@ extern void TestTimer2Config(void);
#endif
extern UINT32 g_shellTestQueueID;
extern int g_min_mempool_size;
extern UINT32 g_testCount;
extern UINT32 g_testCount1;
extern UINT32 g_testCount2;
@ -400,10 +389,6 @@ void Test_usb_shellcmd(controller_type ctype, device_type dtype, usb_test_type t
extern int Gettid(void);
#define COLOR(c) "\033[" c "m"
#define COLOR_RED(text) COLOR("1;31") text COLOR("0")
#define COLOR_GREEN(text) COLOR("1;32") text COLOR("0")
/* like the ctime/asctime api, use static buffer, though not thread-safe. */
static inline const char *Curtime()
{

View File

@ -129,6 +129,70 @@ VOID test_init_spinor(VOID);
VOID test_deinit_jffs(VOID);
VOID test_mtd_jffs(VOID);
UINT32 PrepareFileEnv(CHAR *pathList[], CHAR *streamList[], INT32 streamLen[], INT32 listCnt)
{
CHAR nameBuf[256] = {0};
for (UINT32 i = 0; i < listCnt; i++) {
UINT32 ret = access(pathList[i], 0);
if (ret == 0) {
ret = memcpy_s(nameBuf, sizeof(nameBuf), pathList[i], strlen(pathList[i]) + 1);
if (ret != 0) {
return -1;
}
ret = strcat_s(nameBuf, sizeof(nameBuf), "_bak_for_test");
if (ret != 0) {
return -1;
}
ret = rename(pathList[i], nameBuf);
if (ret != 0) {
return -1;
}
}
FILE *fp = fopen(pathList[i], "w");
if (fp == NULL) {
return -1;
}
ret = fwrite(streamList[i], 1, streamLen[i], fp);
if (ret != streamLen[i]) {
(VOID)fclose(fp);
return -1;
}
ret = fclose(fp);
if (ret != 0) {
printf("%d\n", errno);
}
}
return 0;
}
UINT32 RecoveryFileEnv(CHAR *pathList[], INT32 listCnt)
{
UINT32 ret;
CHAR nameBuf[256] = {0};
for (UINT32 i = 0; i < listCnt; i++) {
ret = remove(pathList[i]);
if (ret != 0) {
printf("ret = %d, err = %d\n", ret, errno);
}
ret = memcpy_s(nameBuf, sizeof(nameBuf), pathList[i], strlen(pathList[i]) + 1);
if (ret != 0) {
return -1;
}
ret = strcat_s(nameBuf, sizeof(nameBuf), "_bak_for_test");
if (ret != 0) {
return -1;
}
ret = access(nameBuf, 0);
if (ret == 0) {
ret = rename(nameBuf, pathList[i]);
if (ret != 0) {
return -1;
}
}
}
return 0;
}
VOID Wfi(VOID)
{
__asm__ __volatile__("wfi" : : : "memory");

View File

@ -51,6 +51,8 @@
#define FE_UPWARD 0x800
#define FE_TOWARDZERO 0xc00
extern CHAR *g_groupFileStream;
extern CHAR *g_passwdFileStream;
extern VOID ItTestSys001(VOID);
extern VOID IT_TEST_SYS_002(VOID);
extern VOID IT_TEST_SYS_003(VOID);
@ -78,7 +80,7 @@ extern VOID ItTestSys024(VOID);
extern VOID ItTestSys025(VOID);
extern VOID ItTestSys026(VOID);
extern VOID ItTestSys027(VOID);
extern VOID IT_TEST_SYS_028(VOID);
extern VOID ItTestSys028(VOID);
extern VOID ItTestSys029(VOID);
extern VOID IT_TEST_SYS_030(VOID);
extern VOID IT_TEST_SYS_031(VOID);

View File

@ -30,51 +30,66 @@
*/
#include "It_test_sys.h"
static UINT32 TestCase(VOID)
STATIC UINT32 TestCase(VOID)
{
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
INT32 ret;
CHAR *pathList[] = {"/etc/group", "/etc/passwd"};
CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream};
INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)};
ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */
if (ret != 0) {
printf("error: need some env file, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
user1 = getpwnam("root");
ICUNIT_ASSERT_NOT_EQUAL(user1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
ICUNIT_GOTO_NOT_EQUAL(user1, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT);
user2 = getpwnam("daemon");
ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_NOT_EQUAL(user2, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_uid, 1, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_gid, 1, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_gecos, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
user3 = getpwnam("bin");
ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_NOT_EQUAL(user3, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_name, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user3->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_EQUAL(user3->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_STRING_EQUAL(user3->pw_gecos, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_dir, "/bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
user4 = getpwnam("lyw");
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT);
user4 = getpwnam("");
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT);
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return 0;
ERROUT:
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
VOID ItTestSys018(VOID)

View File

@ -30,7 +30,7 @@
*/
#include "It_test_sys.h"
static UINT32 TestCase(VOID)
STATIC UINT32 TestCase(VOID)
{
struct passwd pwd;
struct passwd *user1 = nullptr;
@ -38,61 +38,75 @@ static UINT32 TestCase(VOID)
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
struct passwd *user5 = nullptr;
char buf1[1024] = { 0 };
char buf2[2] = { 0 };
int ret;
CHAR buf1[1024] = { 0 }; /* 1024, buffer for test */
CHAR buf2[2] = { 0 }; /* 2, for test,this buffer is not enough large to save data */
INT32 ret;
CHAR *pathList[] = {"/etc/group", "/etc/passwd"};
CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream};
INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)};
ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */
if (ret != 0) {
printf("error: need some env file, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
ret = getpwnam_r("root", &pwd, buf1, sizeof(buf1), &user1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(user1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT);
ICUNIT_GOTO_NOT_EQUAL(user1, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(pwd.pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(pwd.pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_shell, "/bin/bash", -1);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(pwd.pw_uid, 0, -1, ERROUT);
ICUNIT_GOTO_EQUAL(pwd.pw_gid, 0, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_gecos, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_dir, "/root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_shell, "/bin/bash", -1, ERROUT);
ret = getpwnam_r("daemon", &pwd, buf1, sizeof(buf1), &user2);
ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_NOT_EQUAL(user2, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_uid, 1, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_gid, 1, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_gecos, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
ret = getpwnam_r("bin", &pwd, buf1, sizeof(buf1), &user3);
ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_NOT_EQUAL(user3, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_name, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user3->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_EQUAL(user3->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_STRING_EQUAL(user3->pw_gecos, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_dir, "/bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
ret = getpwnam_r("root", &pwd, buf2, sizeof(buf2), &user4);
ICUNIT_ASSERT_EQUAL(ret, ERANGE, ret);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ICUNIT_GOTO_EQUAL(ret, ERANGE, ret, ERROUT);
ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT);
ret = getpwnam_r(nullptr, &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_EQUAL(ret, 0, -1);
ICUNIT_GOTO_EQUAL(ret, 0, -1, ERROUT);
ret = getpwnam_r("", &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT);
ret = getpwnam_r("sssssss", &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT);
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return 0;
ERROUT:
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
VOID ItTestSys019(VOID)

View File

@ -30,53 +30,68 @@
*/
#include "It_test_sys.h"
static UINT32 TestCase(VOID)
STATIC UINT32 TestCase(VOID)
{
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
INT32 ret;
CHAR *pathList[] = {"/etc/group", "/etc/passwd"};
CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream};
INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)};
ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */
if (ret != 0) {
printf("error: need some env file, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
user1 = getpwuid(0);
ICUNIT_ASSERT_NOT_EQUAL(user1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
ICUNIT_GOTO_NOT_EQUAL(user1, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT);
user2 = getpwuid(1);
ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_NOT_EQUAL(user2, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_uid, 1, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_gid, 1, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_gecos, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
user3 = getpwuid(2);
ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1);
user3 = getpwuid(2); /* 2, from etc/group */
ICUNIT_GOTO_NOT_EQUAL(user3, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_name, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user3->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_EQUAL(user3->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_STRING_EQUAL(user3->pw_gecos, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_dir, "/bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
user4 = getpwuid(200);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT);
user4 = getpwuid(-100);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT);
user4 = getpwuid(100000);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT);
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return 0;
ERROUT:
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
VOID ItTestSys020(VOID)

View File

@ -30,7 +30,7 @@
*/
#include "It_test_sys.h"
static UINT32 TestCase(VOID)
STATIC UINT32 TestCase(VOID)
{
struct passwd pwd;
struct passwd *user1 = nullptr;
@ -38,69 +38,83 @@ static UINT32 TestCase(VOID)
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
struct passwd *user5 = nullptr;
char buf1[1024] = { 0 };
char buf2[2] = { 0 };
int ret;
CHAR buf1[1024] = { 0 }; /* 1024, buffer for test */
CHAR buf2[2] = { 0 }; /* 2, for test,this buffer is not enough large to save data */
INT32 ret;
CHAR *pathList[] = {"/etc/group", "/etc/passwd"};
CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream};
INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)};
ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */
if (ret != 0) {
printf("error: need some env file, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
ret = getpwuid_r(0, &pwd, buf1, sizeof(buf1), &user1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT);
ICUNIT_GOTO_NOT_EQUAL(user1, NULL, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(pwd.pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(pwd.pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_shell, "/bin/bash", -1);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(pwd.pw_uid, 0, -1, ERROUT);
ICUNIT_GOTO_EQUAL(pwd.pw_gid, 0, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_gecos, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_dir, "/root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(pwd.pw_shell, "/bin/bash", -1, ERROUT);
ret = getpwuid_r(1, &pwd, buf1, sizeof(buf1), &user2);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT);
ICUNIT_GOTO_NOT_EQUAL(user2, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_uid, 1, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user2->pw_gid, 1, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_gecos, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
ret = getpwuid_r(2, &pwd, buf1, sizeof(buf1), &user3);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1);
ret = getpwuid_r(2, &pwd, buf1, sizeof(buf1), &user3); /* 2, from etc/group */
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT);
ICUNIT_GOTO_NOT_EQUAL(user3, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_name, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user3->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_EQUAL(user3->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_STRING_EQUAL(user3->pw_gecos, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_dir, "/bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
ret = getpwuid_r(0, &pwd, buf2, sizeof(buf2), &user4);
ICUNIT_ASSERT_EQUAL(ret, ERANGE, ret);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ICUNIT_GOTO_EQUAL(ret, ERANGE, ret, ERROUT);
ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT);
ret = getpwuid_r(200, &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_EQUAL(user5, nullptr, -1);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
ret = getpwuid_r(200, &pwd, buf1, sizeof(buf1), &user5); /* 200, invalid param for test */
ICUNIT_GOTO_EQUAL(user5, nullptr, -1, ERROUT);
ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT);
ret = getpwuid_r(100000, &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_EQUAL(user5, nullptr, -1);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
ret = getpwuid_r(100000, &pwd, buf1, sizeof(buf1), &user5); /* 100000, invalid param for test */
ICUNIT_GOTO_EQUAL(user5, nullptr, -1, ERROUT);
ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT);
ret = getpwuid_r(-100, &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_EQUAL(user5, nullptr, -1);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
ret = getpwuid_r(-100, &pwd, buf1, sizeof(buf1), &user5); /* -100, invalid param for test */
ICUNIT_GOTO_EQUAL(user5, nullptr, -1, ERROUT);
ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT);
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return 0;
ERROUT:
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
VOID ItTestSys021(VOID)

View File

@ -30,47 +30,64 @@
*/
#include "It_test_sys.h"
static UINT32 TestCase(VOID)
STATIC UINT32 TestCase(VOID)
{
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
INT32 ret;
CHAR *pathList[] = {"/etc/group", "/etc/passwd"};
CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream};
INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)};
ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */
if (ret != 0) {
printf("error: need some env file, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
user1 = getpwent();
ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
ICUNIT_GOTO_NOT_EQUAL(user1, NULL, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT);
user1 = getpwent();
ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_NOT_EQUAL(user1, NULL, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_uid, 1, -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_gid, 1, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/usr/sbin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
user1 = getpwent();
ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/usr/sbin/nologin", -1);
ICUNIT_GOTO_NOT_EQUAL(user1, NULL, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(user1->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_EQUAL(user1->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */
ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/usr/sbin/nologin", -1, ERROUT);
setpwent();
user2 = getpwent();
ICUNIT_ASSERT_NOT_EQUAL(user2, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, user1->pw_name, -1);
ICUNIT_GOTO_NOT_EQUAL(user2, NULL, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, user1->pw_name, -1, ERROUT);
setpwent();
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return 0;
ERROUT:
setpwent();
(VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */
return -1;
}
VOID ItTestSys022(VOID)

View File

@ -31,39 +31,55 @@
#include "It_test_sys.h"
#include "grp.h"
static UINT32 TestCase(VOID)
STATIC UINT32 TestCase(VOID)
{
struct group *grp1 = nullptr;
struct group *grp2 = nullptr;
struct group *grp3 = nullptr;
struct group *grp4 = nullptr;
INT32 ret;
CHAR *pathList[] = {"/etc/group"};
CHAR *streamList[] = {g_groupFileStream};
INT32 streamLen[] = {strlen(g_groupFileStream)};
ret = PrepareFileEnv(pathList, streamList, streamLen, 1);
if (ret != 0) {
printf("error: need some env file, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 1);
return -1;
}
grp1 = getgrent();
ICUNIT_ASSERT_NOT_EQUAL(grp1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(grp1->gr_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(grp1->gr_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(grp1->gr_gid, 0, -1);
ICUNIT_GOTO_NOT_EQUAL(grp1, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(grp1->gr_name, "root", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(grp1->gr_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(grp1->gr_gid, 0, -1, ERROUT);
grp2 = getgrent();
ICUNIT_ASSERT_NOT_EQUAL(grp2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(grp2->gr_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(grp2->gr_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(grp2->gr_gid, 1, -1);
ICUNIT_GOTO_NOT_EQUAL(grp2, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(grp2->gr_name, "daemon", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(grp2->gr_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(grp2->gr_gid, 1, -1, ERROUT);
grp3 = getgrent();
ICUNIT_ASSERT_NOT_EQUAL(grp3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(grp3->gr_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(grp3->gr_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(grp3->gr_gid, 2, -1);
ICUNIT_GOTO_NOT_EQUAL(grp3, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(grp3->gr_name, "bin", -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(grp3->gr_passwd, "x", -1, ERROUT);
ICUNIT_GOTO_EQUAL(grp3->gr_gid, 2, -1, ERROUT); /* 2, from etc/group */
setgrent();
grp4 = getgrent();
ICUNIT_ASSERT_NOT_EQUAL(grp4, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(grp1->gr_name, grp4->gr_name, -1);
ICUNIT_GOTO_NOT_EQUAL(grp4, nullptr, -1, ERROUT);
ICUNIT_GOTO_STRING_EQUAL(grp1->gr_name, grp4->gr_name, -1, ERROUT);
setgrent();
(VOID)RecoveryFileEnv(pathList, 1);
return 0;
ERROUT:
setgrent();
(VOID)RecoveryFileEnv(pathList, 1);
return -1;
}
VOID ItTestSys023(VOID)

View File

@ -34,17 +34,17 @@
#define GROUPFILE "/etc/group"
static int TestCase0(void)
STATIC INT32 TestCase0(void)
{
struct group getNam1 = { nullptr };
struct group *getNam2 = nullptr;
struct group getData1 = { nullptr };
struct group *getData2 = nullptr;
struct group *groupRet = nullptr;
char buf[1000];
size_t len = 1000;
CHAR buf[1000]; /* 1000, buffer for test */
size_t len = sizeof(buf);
int ret = getgrgid_r(0, &getNam1, buf, len, &getNam2);
INT32 ret = getgrgid_r(0, &getNam1, buf, len, &getNam2);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(getNam2, nullptr, getNam2);
@ -73,17 +73,17 @@ static int TestCase0(void)
return 0;
}
static int TestCase1(void)
STATIC INT32 TestCase1(void)
{
int len = 1000;
char buf[1000];
INT32 len = 1000;
CHAR buf[1000];
struct group getNam1 = { nullptr };
struct group *getNam2 = nullptr;
struct group getData1 = { nullptr };
struct group *getData2 = nullptr;
struct group *groupRet = nullptr;
int ret = getgrgid_r(-1, &getNam1, buf, len, &getNam2);
INT32 ret = getgrgid_r(-1, &getNam1, buf, len, &getNam2);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, EAFNOSUPPORT, errno);
errno = 0;
@ -103,39 +103,33 @@ static int TestCase1(void)
ICUNIT_ASSERT_EQUAL(errno, EAFNOSUPPORT, errno);
errno = 0;
remove(GROUPFILE);
ret = getgrgid_r(0, &getNam1, buf, len, &getNam2);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
errno = 0;
groupRet = getgrgid(0);
ICUNIT_ASSERT_EQUAL(groupRet, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
errno = 0;
groupRet = getgrnam("root");
ICUNIT_ASSERT_EQUAL(groupRet, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
errno = 0;
ret = getgrnam_r("root", &getData1, buf, len, &getData2);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
return 0;
}
static int TestCase(void)
STATIC INT32 TestCase(void)
{
int ret = TestCase0();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
CHAR *pathList[] = {"/etc/group"};
CHAR *streamList[] = {g_groupFileStream};
INT32 streamLen[] = {strlen(g_groupFileStream)};
INT32 ret = PrepareFileEnv(pathList, streamList, streamLen, 1);
if (ret != 0) {
printf("error: need some env file, but prepare is not ok");
(VOID)RecoveryFileEnv(pathList, 1);
return -1;
}
ret = TestCase0();
ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT);
ret = TestCase1();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_GOTO_EQUAL(ret, 0, re, ERROUT);
(VOID)RecoveryFileEnv(pathList, 1);
return 0;
ERROUT:
(VOID)RecoveryFileEnv(pathList, 1);
return -1;
}
VOID ItTestSys025(VOID)

View File

@ -31,20 +31,30 @@
static UINT32 TestCase(VOID)
{
int ret;
int ret, status;
pid_t pid = fork();
if (pid == 0) {
ret = setpriority(PRIO_PROCESS, 0, 15); /* 15, set priority for test */
if (ret != 0) {
exit(0);
}
ret = nice(0);
ICUNIT_ASSERT_EQUAL(ret, 15, ret);
exit(ret);
} else {
ret = nice(-15);
ret = waitpid(pid, &status, 0);
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
status = WEXITSTATUS(status);
ICUNIT_ASSERT_EQUAL(status, 15, status); /* 15, set priority for test */
ret = nice(-40); /* -40, set invaild priority for test */
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
}
return 0;
}
VOID IT_TEST_SYS_028(VOID)
VOID ItTestSys028(VOID)
{
TEST_ADD_CASE(IT_TEST_SYS_028, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
TEST_ADD_CASE(ItTestSys028, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}

View File

@ -34,6 +34,10 @@
#include "It_test_sys.h"
CHAR *g_groupFileStream = "root:x:0:\ndaemon:x:1:\nbin:x:2:\n";
CHAR *g_passwdFileStream = "root:x:0:0:root:/root:/bin/bash\n" \
"daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin\nbin:x:2:2:bin:/bin:/usr/sbin/nologin\n";
using namespace testing::ext;
namespace OHOS {
class SysTest : public testing::Test {
@ -343,14 +347,14 @@ HWTEST_F(SysTest, ItTestSys027, TestSize.Level0)
}
/* *
* @tc.name: IT_TEST_SYS_028
* @tc.name: ItTestSys028
* @tc.desc: function for nice:set pthread priority
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, IT_TEST_SYS_028, TestSize.Level0)
HWTEST_F(SysTest, ItTestSys028, TestSize.Level0)
{
IT_TEST_SYS_028();
ItTestSys028();
}
#endif
} // namespace OHOS