diff --git a/fs/proc/os_adapt/plimits_proc.c b/fs/proc/os_adapt/plimits_proc.c index 0782cbe69da116fcd49194a120e5953a1a5b0df7..81f2f8efc63d28682146456c8f73f919fd007d78 100644 --- a/fs/proc/os_adapt/plimits_proc.c +++ b/fs/proc/os_adapt/plimits_proc.c @@ -68,8 +68,6 @@ static ssize_t PidLimitReadPriorityLimit(struct SeqBuf *seqBuf, VOID *data); static ssize_t PriorityLimitVariableWrite(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos); static ssize_t PidsMaxVariableWrite(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos); static ssize_t ProcLimitsShowLimiters(struct SeqBuf *seqBuf, VOID *data); -static ssize_t ProcLimitsDeleteLimiters(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos); -static ssize_t ProcLimitsAddLimiters(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos); static int ProcfsPlimitsMkdir(struct ProcDirEntry *parent, const char *dirName, mode_t mode, struct ProcDirEntry **pde); static int ProcfsPlimitsRmdir(struct ProcDirEntry *parent, struct ProcDirEntry *pde, const char *name); #ifdef LOSCFG_KERNEL_MEM_PLIMIT @@ -120,24 +118,6 @@ static struct PLimitsEntryOpt g_plimitsEntryOpts[] = { .read = ProcLimitsShowLimiters, } }, - { - .id = PROCESS_LIMITER_COUNT, - .name = "plimits.limiter_add", - .mode = PLIMIT_FILE_MODE_READ_WRITE, - .offset = UNITPTR_NULL, - .ops = { - .write = ProcLimitsAddLimiters, - }, - }, - { - .id = PROCESS_LIMITER_COUNT, - .name = "plimits.limiter_delete", - .mode = PLIMIT_FILE_MODE_READ_WRITE, - .offset = UNITPTR_NULL, - .ops = { - .write = ProcLimitsDeleteLimiters, - }, - }, { .id = PROCESS_LIMITER_COUNT, .name = "plimits.procs", @@ -458,152 +438,6 @@ static ssize_t ProcLimitsShowLimiters(struct SeqBuf *seqBuf, VOID *data) return LOS_OK; } -static ssize_t ProcLimitsAddLimiters(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos) -{ - (VOID)ppos; - unsigned int ret; - struct ProcDirEntry *dirEntry = pf->pPDE; - ProcLimiterSet *plimits = GetProcLimiterSetFromDirEntry(dirEntry); - char *kbuf = NULL; - - ret = MemUserCopy(buf, count, &kbuf); - if (ret != 0) { - return -ret; - } else if ((ret == 0) && (kbuf != NULL)) { - buf = (const char *)kbuf; - } - - enum ProcLimiterID procLimiterID = 0; - if (strcmp(buf, "pids") == 0) { - procLimiterID = PROCESS_LIMITER_ID_PIDS; -#ifdef LOSCFG_KERNEL_MEM_PLIMIT - } else if (strcmp(buf, "memory") == 0) { - procLimiterID = PROCESS_LIMITER_ID_MEM; -#endif -#ifdef LOSCFG_KERNEL_IPC_PLIMIT - } else if (strcmp(buf, "ipc") == 0) { - procLimiterID = PROCESS_LIMITER_ID_IPC; -#endif -#ifdef LOSCFG_KERNEL_DEV_PLIMIT - } else if (strcmp(buf, "devices") == 0) { - procLimiterID = PROCESS_LIMITER_ID_DEV; -#endif -#ifdef LOSCFG_KERNEL_SCHED_PLIMIT - } else if (strcmp(buf, "sched") == 0) { - procLimiterID = PROCESS_LIMITER_ID_SCHED; -#endif - } else { - (void)LOS_MemFree(m_aucSysMem1, kbuf); - PRINTK("enter error, please check the params.\n"); - return -EINVAL; - } - (void)LOS_MemFree(m_aucSysMem1, kbuf); - - ret = OsPLimitsAddLimiters(plimits, procLimiterID); - if (ret != LOS_OK) { - return -ret; - } - - ProcLimiterDirEntryInit(dirEntry, BIT(procLimiterID), PLIMIT_FILE_MODE_MASK_NONE); - return count; -} - -static struct ProcDirEntry *PLimitsProcFindEntry(const char *name, struct ProcDirEntry *parent) -{ - int len = strlen(name); - struct ProcDirEntry *pn = NULL; - for (pn = parent->subdir; pn != NULL; pn = pn->next) { - if (ProcMatch(len, name, pn)) { - break; - } - } - return pn; -} - -static int DeleteProcEntry(const char *buf, struct ProcDirEntry *currDirectory) -{ - struct ProcDirEntry *entry = PLimitsProcFindEntry(buf, currDirectory); - if (entry == NULL) { - return EINVAL; - } - ProcDetachNode(entry); - ProcEntryClearVnode(entry); - ProcFreeEntry(entry); - return 0; -} - -static int PLimitsDeleteProcEntry(enum ProcLimiterID procLimiterID, struct ProcDirEntry *currDirectory) -{ - for (int index = 0; index < (sizeof(g_plimitsEntryOpts) / sizeof(struct PLimitsEntryOpt)); index++) { - struct PLimitsEntryOpt *entryOpt = &g_plimitsEntryOpts[index]; - if (entryOpt->id != procLimiterID) { - continue; - } - (void)DeleteProcEntry(entryOpt->name, currDirectory); - } - return 0; -} - -static ssize_t ProcLimitsDeleteLimiters(struct ProcFile *pf, const CHAR *buf, size_t count, loff_t *ppos) -{ - (VOID)ppos; - unsigned ret; - unsigned mask = 0; - enum ProcLimiterID procLimiterID = 0; - char *kbuf = NULL; - - if ((pf == NULL) || (pf->pPDE == NULL)) { - return -EINVAL; - } - - struct ProcDirEntry *pde = pf->pPDE; - struct ProcDirEntry *currDirectory = GetCurrDirectory(pde); - if ((currDirectory == NULL) || (currDirectory->data == NULL)) { - return -EINVAL; - } - ProcLimiterSet *plimits = (ProcLimiterSet *)currDirectory->data; - - ret = MemUserCopy(buf, count, &kbuf); - if (ret != 0) { - return -ret; - } else if ((ret == 0) && (kbuf != NULL)) { - buf = (const char *)kbuf; - } - - if (strcmp(buf, "pids") == 0) { - procLimiterID = PROCESS_LIMITER_ID_PIDS; -#ifdef LOSCFG_KERNEL_MEM_PLIMIT - } else if (strcmp(buf, "memory") == 0) { - procLimiterID = PROCESS_LIMITER_ID_MEM; -#endif -#ifdef LOSCFG_KERNEL_IPC_PLIMIT - } else if (strcmp(buf, "ipc") == 0) { - procLimiterID = PROCESS_LIMITER_ID_IPC; -#endif -#ifdef LOSCFG_KERNEL_DEV_PLIMIT - } else if (strcmp(buf, "devices") == 0) { - procLimiterID = PROCESS_LIMITER_ID_DEV; -#endif -#ifdef LOSCFG_KERNEL_SCHED_PLIMIT - } else if (strcmp(buf, "sched") == 0) { - procLimiterID = PROCESS_LIMITER_ID_SCHED; -#endif - } else { - PRINTK("the input information or format is incorrect.\n"); - (void)LOS_MemFree(m_aucSysMem1, kbuf); - return -EINVAL; - } - (void)LOS_MemFree(m_aucSysMem1, kbuf); - - ret = OsPLimitsDeleteLimiters(plimits, procLimiterID, &mask); - if (ret != LOS_OK) { - return -ret; - } - - PLimitsDeleteProcEntry(procLimiterID, currDirectory); - return count; -} - #define PLIMITS_PID_STR_LENGTH 4 static int ShowPids(struct SeqBuf *seqBuf, VOID *data) { diff --git a/fs/proc/src/proc_file.c b/fs/proc/src/proc_file.c index 879d4507430fdb71e5276c223d2ac772c615f731..92415022508bbdd8067f3960ea73d99d61925610 100644 --- a/fs/proc/src/proc_file.c +++ b/fs/proc/src/proc_file.c @@ -645,15 +645,11 @@ int WriteProcFile(struct ProcDirEntry *pde, const void *buf, size_t len) return -EISDIR; } -#ifndef LOSCFG_KERNEL_PLIMITS spin_lock(&procfsLock); -#endif if ((pde->procFileOps != NULL) && (pde->procFileOps->write != NULL)) { result = pde->procFileOps->write(pde->pf, (const char *)buf, len, &(pde->pf->fPos)); } -#ifndef LOSCFG_KERNEL_PLIMITS spin_unlock(&procfsLock); -#endif return result; } diff --git a/kernel/extended/plimit/los_devicelimit.c b/kernel/extended/plimit/los_devicelimit.c index eedb4681a45c3c0e7f2aec2760c33a5ce1f3e002..00e5930a52fcce9fc60defd60b9273e68c877b6a 100644 --- a/kernel/extended/plimit/los_devicelimit.c +++ b/kernel/extended/plimit/los_devicelimit.c @@ -58,7 +58,6 @@ VOID *OsDevLimitAlloc(VOID) (VOID)memset_s(plimit, sizeof(ProcDevLimit), 0, sizeof(ProcDevLimit)); LOS_ListInit(&(plimit->accessList)); plimit->behavior = DEVLIMIT_DEFAULT_NONE; - LOS_AtomicSet(&plimit->rc, 1); return (VOID *)plimit; } @@ -79,11 +78,8 @@ VOID OsDevLimitFree(UINTPTR limit) return; } - LOS_AtomicDec(&devLimit->rc); - if (LOS_AtomicRead(&devLimit->rc) <= 0) { - DevAccessListDelete(devLimit); - LOS_KernelFree(devLimit); - } + DevAccessListDelete(devLimit); + LOS_KernelFree(devLimit); } STATIC UINT32 DevLimitCopyAccess(ProcDevLimit *devLimitDest, ProcDevLimit *devLimitSrc) @@ -110,16 +106,6 @@ VOID OsDevLimitCopy(UINTPTR dest, UINTPTR src) devLimitDest->parent = (ProcDevLimit *)src; } -VOID OsDevLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process) -{ - (VOID)currLimit; - ProcDevLimit *parentDevLimit = (ProcDevLimit *)parentLimit; - LosProcessCB *pcb = (LosProcessCB *)process; - if (pcb == NULL) { - LOS_AtomicInc(&parentDevLimit->rc); - } -} - STATIC INLINE INT32 IsSpace(INT32 c) { return (c == ' ' || (unsigned)c - '\t' < BUF_SEPARATOR); diff --git a/kernel/extended/plimit/los_devicelimit.h b/kernel/extended/plimit/los_devicelimit.h index a2310144114fc088f80ed6d6247a33b55809f265..06247398f7a51dae42a4c2ba4a1b293bb23884a9 100644 --- a/kernel/extended/plimit/los_devicelimit.h +++ b/kernel/extended/plimit/los_devicelimit.h @@ -32,7 +32,6 @@ #define _LOS_DEVICELIMIT_H #include "los_typedef.h" -#include "los_atomic.h" #include "los_list.h" #include "vfs_config.h" @@ -74,7 +73,6 @@ typedef struct DevAccessItem { typedef struct ProcDevLimit { struct ProcDevLimit *parent; - Atomic rc; UINT8 allowFile; UINT8 denyFile; LOS_DL_LIST accessList; // device belong to devicelimite @@ -85,7 +83,6 @@ VOID OsDevLimitInit(UINTPTR limit); VOID *OsDevLimitAlloc(VOID); VOID OsDevLimitFree(UINTPTR limit); VOID OsDevLimitCopy(UINTPTR dest, UINTPTR src); -VOID OsDevLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process); UINT32 OsDevLimitWriteAllow(ProcLimitSet *plimit, const CHAR *buf, UINT32 size); UINT32 OsDevLimitWriteDeny(ProcLimitSet *plimit, const CHAR *buf, UINT32 size); UINT32 OsDevLimitShow(ProcDevLimit *devLimit, struct SeqBuf *seqBuf); diff --git a/kernel/extended/plimit/los_ipclimit.c b/kernel/extended/plimit/los_ipclimit.c index c2d6816004a13fe1b3e4197389d563526bddd30e..dc92ba94bc27d251d1adfa96be4d92b185ad5247 100644 --- a/kernel/extended/plimit/los_ipclimit.c +++ b/kernel/extended/plimit/los_ipclimit.c @@ -50,7 +50,6 @@ VOID *OsIPCLimitAlloc(VOID) return NULL; } (VOID)memset_s(plimite, sizeof(ProcIPCLimit), 0, sizeof(ProcIPCLimit)); - LOS_AtomicSet(&plimite->rc, 1); return (VOID *)plimite; } @@ -61,10 +60,7 @@ VOID OsIPCLimitFree(UINTPTR limite) return; } - LOS_AtomicDec(&plimite->rc); - if (LOS_AtomicRead(&plimite->rc) <= 0) { - LOS_KernelFree((VOID *)plimite); - } + LOS_KernelFree((VOID *)plimite); } VOID OsIPCLimitCopy(UINTPTR dest, UINTPTR src) @@ -101,7 +97,6 @@ VOID OsIPCLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process) parentIpcLimit->mqFailedCount += currIpcLimit->mqFailedCount; parentIpcLimit->shmSize += currIpcLimit->shmSize; parentIpcLimit->shmFailedCount += currIpcLimit->shmFailedCount; - LOS_AtomicInc(&parentIpcLimit->rc); return; } diff --git a/kernel/extended/plimit/los_ipclimit.h b/kernel/extended/plimit/los_ipclimit.h index d5ea14e31434f1a0deaf9bdd7a94489749a44aa7..39b967f4b3b2a2586dd0d3988f1b1932b31444f4 100644 --- a/kernel/extended/plimit/los_ipclimit.h +++ b/kernel/extended/plimit/los_ipclimit.h @@ -32,7 +32,6 @@ #define _LOS_IPCLIMIT_H #include "los_typedef.h" -#include "los_atomic.h" #ifdef __cplusplus #if __cplusplus @@ -41,7 +40,6 @@ extern "C" { #endif /* __cplusplus */ typedef struct ProcIPCLimit { - Atomic rc; UINT32 mqCount; UINT32 mqFailedCount; UINT32 mqCountLimit; diff --git a/kernel/extended/plimit/los_memlimit.c b/kernel/extended/plimit/los_memlimit.c index 2d473231cf9c85feed0e12ad47bae13636d3a562..a1af5bdf5133e8d374716a65cebbd9dc2e50a9e0 100644 --- a/kernel/extended/plimit/los_memlimit.c +++ b/kernel/extended/plimit/los_memlimit.c @@ -57,7 +57,6 @@ VOID *OsMemLimiterAlloc(VOID) return NULL; } (VOID)memset_s(plimite, sizeof(ProcMemLimiter), 0, sizeof(ProcMemLimiter)); - LOS_AtomicSet(&plimite->rc, 1); return (VOID *)plimite; } @@ -68,10 +67,7 @@ VOID OsMemLimiterFree(UINTPTR limite) return; } - LOS_AtomicDec(&plimite->rc); - if (LOS_AtomicRead(&plimite->rc) <= 0) { - LOS_KernelFree((VOID *)limite); - } + LOS_KernelFree((VOID *)limite); } VOID OsMemLimiterCopy(UINTPTR dest, UINTPTR src) @@ -104,7 +100,6 @@ VOID OsMemLimiterMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process if (parentMemLimit->peak < parentMemLimit->usage) { parentMemLimit->peak = parentMemLimit->usage; } - LOS_AtomicInc(&parentMemLimit->rc); return; } diff --git a/kernel/extended/plimit/los_memlimit.h b/kernel/extended/plimit/los_memlimit.h index 35c5ee9e572e681737000db151b3a674ca063eab..f176cc013cef561e5aa624e1c0bfca4bc7ed3599 100644 --- a/kernel/extended/plimit/los_memlimit.h +++ b/kernel/extended/plimit/los_memlimit.h @@ -32,7 +32,6 @@ #define _LOS_MEMLIMIT_H #include "los_typedef.h" -#include "los_atomic.h" #ifdef __cplusplus #if __cplusplus @@ -41,7 +40,6 @@ extern "C" { #endif /* __cplusplus */ typedef struct ProcMemLimiter { - Atomic rc; UINT64 usage; UINT64 limit; UINT64 peak; diff --git a/kernel/extended/plimit/los_plimits.c b/kernel/extended/plimit/los_plimits.c index 8f357016a472a66adbccc0aa320286c41a3e9a55..2e42097843c7ed38fec528d49954d5757f7b9db3 100644 --- a/kernel/extended/plimit/los_plimits.c +++ b/kernel/extended/plimit/los_plimits.c @@ -56,7 +56,7 @@ static PlimiteOperations g_limiteOps[PROCESS_LIMITER_COUNT] = { .LimiterAddProcess = OsPidLimitAddProcess, .LimiterDelProcess = OsPidLimitDelProcess, .LimiterMigrateCheck = PidLimitMigrateCheck, - .LimiterMigrate = OsPidLimiterMigrate, + .LimiterMigrate = NULL, }, #ifdef LOSCFG_KERNEL_MEM_PLIMIT [PROCESS_LIMITER_ID_MEM] = { @@ -81,7 +81,7 @@ static PlimiteOperations g_limiteOps[PROCESS_LIMITER_COUNT] = { .LimiterAddProcess = NULL, .LimiterDelProcess = NULL, .LimiterMigrateCheck = NULL, - .LimiterMigrate = OsSchedLimitMigrate, + .LimiterMigrate = NULL, }, #endif #ifdef LOSCFG_KERNEL_DEV_PLIMIT @@ -94,7 +94,7 @@ static PlimiteOperations g_limiteOps[PROCESS_LIMITER_COUNT] = { .LimiterAddProcess = NULL, .LimiterDelProcess = NULL, .LimiterMigrateCheck = NULL, - .LimiterMigrate = OsDevLimitMigrate, + .LimiterMigrate = NULL, }, #endif #ifdef LOSCFG_KERNEL_IPC_PLIMIT @@ -360,79 +360,6 @@ ProcLimiterSet *OsPLimitsCreate(ProcLimiterSet *parentPLimits) return newPLimits; } -UINT32 OsPLimitsAddLimiters(ProcLimiterSet *procLimiterSet, enum ProcLimiterID plimiteID) -{ - UINT32 intSave; - UINT32 mask = BIT(plimiteID); - if ((procLimiterSet == NULL) || (plimiteID > PROCESS_LIMITER_COUNT)) { - return EINVAL; - } - - SCHEDULER_LOCK(intSave); - if (procLimiterSet->level == 0) { - SCHEDULER_UNLOCK(intSave); - return EPERM; - } - - if (procLimiterSet->mask & mask) { - SCHEDULER_UNLOCK(intSave); - return EINVAL; - } - - UINTPTR currLimit = procLimiterSet->limitsList[plimiteID]; - UINTPTR parentPLimit = procLimiterSet->parent->limitsList[plimiteID]; - procLimiterSet->limitsList[plimiteID] = (UINTPTR)g_limiteOps[plimiteID].LimiterAlloc(); - if (procLimiterSet->limitsList[plimiteID] == (UINTPTR)NULL) { - procLimiterSet->limitsList[plimiteID] = parentPLimit; - SCHEDULER_UNLOCK(intSave); - return ENOMEM; - } - - g_limiteOps[plimiteID].LimiterCopy(procLimiterSet->limitsList[plimiteID], parentPLimit); - g_limiteOps[plimiteID].LimiterMigrate(procLimiterSet->limitsList[plimiteID], - parentPLimit, (UINTPTR)OsCurrProcessGet()); - g_limiteOps[plimiteID].LimiterFree(currLimit); - SCHEDULER_UNLOCK(intSave); - return LOS_OK; -} - -UINT32 OsPLimitsDeleteLimiters(ProcLimiterSet *procLimiterSet, enum ProcLimiterID plimiteID, UINT32 *mask) -{ - UINT32 intSave; - - if ((procLimiterSet == NULL) || (plimiteID > PROCESS_LIMITER_COUNT) || (mask == NULL)) { - return EINVAL; - } - - SCHEDULER_LOCK(intSave); - if (!(procLimiterSet->mask & BIT(plimiteID))) { - SCHEDULER_UNLOCK(intSave); - return EINVAL; - } - - if (procLimiterSet->level == 0) { - SCHEDULER_UNLOCK(intSave); - return EPERM; - } - - UINTPTR currLimit = procLimiterSet->limitsList[plimiteID]; - UINTPTR parentPLimit = procLimiterSet->parent->limitsList[plimiteID]; - if ((g_limiteOps[plimiteID].LimiterMigrateCheck != NULL) && - !g_limiteOps[plimiteID].LimiterMigrateCheck(currLimit, parentPLimit)) { - SCHEDULER_UNLOCK(intSave); - return EINVAL; - } - - g_limiteOps[plimiteID].LimiterMigrate(currLimit, parentPLimit, 0); - procLimiterSet->limitsList[plimiteID] = parentPLimit; - g_limiteOps[plimiteID].LimiterFree(currLimit); - - procLimiterSet->mask &= (~BIT(plimiteID)); - *mask = procLimiterSet->mask; - SCHEDULER_UNLOCK(intSave); - return LOS_OK; -} - #ifdef LOSCFG_KERNEL_MEM_PLIMIT UINT32 OsPLimitsMemUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size) { diff --git a/kernel/extended/plimit/los_plimits.h b/kernel/extended/plimit/los_plimits.h index 6c06540e0580e35affa5007feaa01e980d1096db..f3c44fda18bd0fc9c37aadf67b9659ef9e825883 100644 --- a/kernel/extended/plimit/los_plimits.h +++ b/kernel/extended/plimit/los_plimits.h @@ -101,9 +101,6 @@ UINT32 OsPLimitsFree(ProcLimiterSet *currPLimits); ProcLimiterSet *OsPLimitsCreate(ProcLimiterSet *parentProcLimiterSet); UINT32 OsProcLimiterSetInit(VOID); -UINT32 OsPLimitsAddLimiters(ProcLimiterSet *procLimiterSet, enum ProcLimiterID plimiteID); -UINT32 OsPLimitsDeleteLimiters(ProcLimiterSet *procLimiterSet, enum ProcLimiterID plimiteID, UINT32 *mask); - UINT32 OsPLimitsMemUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size); UINT32 OsPLimitsIPCStatGet(ProcLimiterSet *plimits, ProcIPCLimit *ipc, UINT32 size); UINT32 OsPLimitsSchedUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size); diff --git a/kernel/extended/plimit/los_processlimit.c b/kernel/extended/plimit/los_processlimit.c index 7211f9512b8c8ab96c3bea467c00cad5b429b5df..ea21c6f28b655d17767ecbb5992439e9ddaa2e9e 100644 --- a/kernel/extended/plimit/los_processlimit.c +++ b/kernel/extended/plimit/los_processlimit.c @@ -57,7 +57,6 @@ VOID *PidLimiterAlloc(VOID) return NULL; } (VOID)memset_s(plimite, sizeof(PidLimit), 0, sizeof(PidLimit)); - LOS_AtomicSet(&plimite->rc, 1); return (VOID *)plimite; } @@ -68,10 +67,7 @@ VOID PidLimterFree(UINTPTR limit) return; } - LOS_AtomicDec(&pidLimit->rc); - if (LOS_AtomicRead(&pidLimit->rc) <= 0) { - LOS_KernelFree((VOID *)limit); - } + LOS_KernelFree((VOID *)limit); } BOOL PidLimitMigrateCheck(UINTPTR curr, UINTPTR parent) @@ -88,18 +84,6 @@ BOOL PidLimitMigrateCheck(UINTPTR curr, UINTPTR parent) return TRUE; } -VOID OsPidLimiterMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process) -{ - (VOID)currLimit; - - PidLimit *parentPidLimit = (PidLimit *)parentLimit; - LosProcessCB *pcb = (LosProcessCB *)process; - - if (pcb == NULL) { - LOS_AtomicInc(&parentPidLimit->rc); - } -} - BOOL OsPidLimitAddProcessCheck(UINTPTR limit, UINTPTR process) { (VOID)process; diff --git a/kernel/extended/plimit/los_processlimit.h b/kernel/extended/plimit/los_processlimit.h index 997218a07095aa893e7612964fa4c8052427d4e1..b18908dea5b2215a87f3928b4dd23db170886e44 100644 --- a/kernel/extended/plimit/los_processlimit.h +++ b/kernel/extended/plimit/los_processlimit.h @@ -33,7 +33,6 @@ #include "los_list.h" #include "los_typedef.h" -#include "los_atomic.h" #ifdef __cplusplus #if __cplusplus @@ -42,7 +41,6 @@ extern "C" { #endif /* __cplusplus */ typedef struct PidLimit { - Atomic rc; UINT32 pidLimit; UINT32 priorityLimit; UINT32 pidCount; @@ -53,7 +51,6 @@ VOID *PidLimiterAlloc(VOID); VOID PidLimterFree(UINTPTR limit); VOID PidLimiterCopy(UINTPTR curr, UINTPTR parent); BOOL PidLimitMigrateCheck(UINTPTR curr, UINTPTR parent); -VOID OsPidLimiterMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process); BOOL OsPidLimitAddProcessCheck(UINTPTR limit, UINTPTR process); VOID OsPidLimitAddProcess(UINTPTR limit, UINTPTR process); VOID OsPidLimitDelProcess(UINTPTR limit, UINTPTR process); diff --git a/kernel/extended/plimit/los_schedlimit.c b/kernel/extended/plimit/los_schedlimit.c index acdf881f924073ea387af21fb6788abfada11b33..c91359d6ea1b00de52331e2d293b589aa8784be4 100644 --- a/kernel/extended/plimit/los_schedlimit.c +++ b/kernel/extended/plimit/los_schedlimit.c @@ -49,7 +49,6 @@ VOID *OsSchedLimitAlloc(VOID) return NULL; } (VOID)memset_s(plimit, sizeof(ProcSchedLimiter), 0, sizeof(ProcSchedLimiter)); - LOS_AtomicSet(&plimit->rc, 1); return (VOID *)plimit; } @@ -60,10 +59,7 @@ VOID OsSchedLimitFree(UINTPTR limit) return; } - LOS_AtomicDec(&schedLimit->rc); - if (LOS_AtomicRead(&schedLimit->rc) <= 0) { - LOS_KernelFree((VOID *)limit); - } + LOS_KernelFree((VOID *)limit); } VOID OsSchedLimitCopy(UINTPTR dest, UINTPTR src) @@ -75,16 +71,6 @@ VOID OsSchedLimitCopy(UINTPTR dest, UINTPTR src) return; } -VOID OsSchedLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process) -{ - (VOID)currLimit; - ProcSchedLimiter *parentSchedLimit = (ProcSchedLimiter *)parentLimit; - LosProcessCB *pcb = (LosProcessCB *)process; - if (pcb == NULL) { - LOS_AtomicInc(&parentSchedLimit->rc); - } -} - VOID OsSchedLimitUpdateRuntime(LosTaskCB *runTask, UINT64 currTime, INT32 incTime) { LosProcessCB *run = (LosProcessCB *)runTask->processCB; diff --git a/kernel/extended/plimit/los_schedlimit.h b/kernel/extended/plimit/los_schedlimit.h index 13ac9daa9a9c98c785d13e78a16ed79953e47d22..65919a76fbcf4b6a34045031d13ee038de075cbf 100644 --- a/kernel/extended/plimit/los_schedlimit.h +++ b/kernel/extended/plimit/los_schedlimit.h @@ -32,7 +32,6 @@ #define _LOS_SCHEDLIMIT_H #include "los_typedef.h" -#include "los_atomic.h" #ifdef __cplusplus #if __cplusplus @@ -44,7 +43,6 @@ extern "C" { typedef struct TagTaskCB LosTaskCB; typedef struct ProcSchedLimiter { - Atomic rc; UINT64 startTime; UINT64 endTime; UINT64 period; @@ -58,7 +56,6 @@ VOID OsSchedLimitInit(UINTPTR limit); VOID *OsSchedLimitAlloc(VOID); VOID OsSchedLimitFree(UINTPTR limit); VOID OsSchedLimitCopy(UINTPTR dest, UINTPTR src); -VOID OsSchedLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process); VOID OsSchedLimitUpdateRuntime(LosTaskCB *runTask, UINT64 currTime, INT32 incTime); UINT32 OsSchedLimitSetPeriod(ProcSchedLimiter *schedLimit, UINT64 value); UINT32 OsSchedLimitSetQuota(ProcSchedLimiter *schedLimit, UINT64 value); diff --git a/testsuites/unittest/BUILD.gn b/testsuites/unittest/BUILD.gn index 56af2ae2983e53db75140f869f23e95cc29bdd51..9ee2f17efda18eb14afde3570d824884c829e8f2 100644 --- a/testsuites/unittest/BUILD.gn +++ b/testsuites/unittest/BUILD.gn @@ -138,6 +138,9 @@ group("unittest") { if (LOSCFG_USER_TEST_PROCESS_FS == true) { deps += [ "process/fs:liteos_a_process_fs_unittest_door" ] } + if (LOSCFG_USER_TEST_PROCESS_PLIMITS == true) { + deps += [ "process/plimits:liteos_a_process_plimits_unittest_door" ] + } } if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_MIDDLE) { deps += [ "process/basic:liteos_a_process_basic_unittest" ] @@ -145,6 +148,9 @@ group("unittest") { if (LOSCFG_USER_TEST_PROCESS_FS == true) { deps += [ "process/fs:liteos_a_process_fs_unittest" ] } + if (LOSCFG_USER_TEST_PROCESS_PLIMITS == true) { + deps += [ "process/plimits:liteos_a_process_plimits_unittest" ] + } } } diff --git a/testsuites/unittest/config.gni b/testsuites/unittest/config.gni index d659f216692f2e3508ef0b6a2713b9259d7d5cdd..50df5755010396d79f5c7456e602989f0c17622c 100644 --- a/testsuites/unittest/config.gni +++ b/testsuites/unittest/config.gni @@ -165,6 +165,11 @@ if (defined(LOSCFG_KERNEL_CONTAINER) || liteos_container_test_enable == true) { } } +LOSCFG_USER_TEST_PROCESS_PLIMITS = false +if (defined(LOSCFG_KERNEL_PLIMITS) || liteos_container_test_enable == true) { + LOSCFG_USER_TEST_PROCESS_PLIMITS = true +} + ########## fuzz test ########## LOSCFG_USER_FUZZ_TEST = false if (liteos_fuzz_test_enable == true) { diff --git a/testsuites/unittest/process/plimits/BUILD.gn b/testsuites/unittest/process/plimits/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0901b3f2078d6c87bcd864051882cd39602040ed --- /dev/null +++ b/testsuites/unittest/process/plimits/BUILD.gn @@ -0,0 +1,58 @@ +# Copyright (c) 2023-2023 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. + +import("//build/lite/config/test.gni") +import("//kernel/liteos_a/testsuites/unittest/config.gni") +import("./config.gni") + +if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) { + unittest("liteos_a_process_plimits_unittest_door") { + output_extension = "bin" + output_dir = "$root_out_dir/test/unittest/kernel" + include_dirs = common_include_dirs + sources = sources_entry + sources += sources_smoke + sources_full = [] + sources += sources_full + configs = [ "../..:public_config_for_door" ] + deps = [ "//third_party/bounds_checking_function:libsec_shared" ] + } +} + +if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_MIDDLE) { + unittest("liteos_a_process_plimits_unittest") { + output_extension = "bin" + output_dir = "$root_out_dir/test/unittest/kernel" + include_dirs = common_include_dirs + sources = sources_entry + sources += sources_smoke + sources += sources_full + configs = [ "../..:public_config_for_all" ] + deps = [ "//third_party/bounds_checking_function:libsec_shared" ] + } +} diff --git a/testsuites/unittest/process/plimits/It_process_plimits.h b/testsuites/unittest/process/plimits/It_process_plimits.h new file mode 100644 index 0000000000000000000000000000000000000000..7596c83afaf13e8af8b36de544510b311b627680 --- /dev/null +++ b/testsuites/unittest/process/plimits/It_process_plimits.h @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2023-2023 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 _IT_PROCESS_PLIMITS_H +#define _IT_PROCESS_PLIMITS_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "osTest.h" + +#define MEM_PAGE_SIZE 4096 +#define MEM_SLEEP_TIME 5 +#define MEM_RESERVED_PAGE 2 +#define CHILD_FUNC_ARG (0x2088) +#define STACK_SIZE (1024 * 1024) +#define PROCESS_LIMIT_AMOUNT (64) +#define TEST_BUFFER_SIZE (512) +#define CPUP10S_INDEX (11) +#define CPUP1S_INDEX (12) +#define WAIT_CPUP_STABLE (7) +#define WAIT_CPUP_STABLE_FOR_100 (17) +#define STATISTIC_TIMES (11) +#define PERIOD_10_SEC_IN_US (10 * 1000 * 1000) +#define QUOTA_2_SEC_IN_US (2 * 1000 * 1000) +#define QUOTA_5_SEC_IN_US (5 * 1000 * 1000) +#define QUOTA_6_SEC_IN_US (6 * 1000 * 1000) +#define QUOTA_7_SEC_IN_US (7 * 1000 * 1000) +#define QUOTA_10_SEC_IN_US (10 * 1000 * 1000) +#define QUOTA_PERCENT_20 (20) +#define QUOTA_PERCENT_50 (50) +#define QUOTA_PERCENT_60 (60) +#define QUOTA_PERCENT_70 (70) +#define QUOTA_PERCENT_100 (100) +#define HARDWARE_CORE_AMOUNT (2) +#define TOLERANCE_ERROR (5) + +int WriteFile(const char *filepath, const char *buf); +int RmdirLimiterFile(std::string path); +int RmdirControlFile(std::string path); +int ReadFile(const char *filepath, char *buf); +int GetLine(char *buf, int count, int maxLen, char **array); +int RmdirTest (std::string path); +extern UINT32 LosCurTaskIDGet(); + +int ForkChilds(int num, int *pidArray); +int CreatePlimitGroup(const char* groupName, char *childPidFiles, + unsigned long long periodUs, unsigned long long quotaUs); +int AddPidIntoSchedLimiters(int num, int *pidArray, const char *procspath); +int WaitForCpupStable(int expectedCpupPercent); +double CalcCpupUsage(int childAmount, int *childPidArray, int expectedCpupPercent); +double CheckCpupUsage(double sumAllChildsCpup, int expectedCpupPercent); +int TerminateChildProcess(int *childPidArray, int childAmount, int sig); +double TestCpupInPlimit(int childAmount, const char* groupName, + unsigned long long periodUs, unsigned long long quotaUs, int expectedCpupPercent); +double TestCpupWithoutLimit(int childAmount, const char* groupName, int expectedCpupPercent); + +#if defined(LOSCFG_USER_TEST_SMOKE) +void ItProcessPlimits001(void); +void ItProcessPlimits002(void); +void ItProcessPlimits003(void); +void ItProcessPlimits004(void); +void ItProcessPlimits005(void); +void ItProcessPlimits006(void); +void ItProcessPlimits007(void); +void ItProcessPlimits008(void); +void ItProcessPlimitsMemory001(void); +void ItProcessPlimitsMemory002(void); +void ItProcessPlimitsPid001(void); +void ItProcessPlimitsPid002(void); +void ItProcessPlimitsPid003(void); +void ItProcessPlimitsPid004(void); +void ItProcessPlimitsPid005(void); +void ItProcessPlimitsPid006(void); +void ItProcessPlimitsSched001(VOID); +void ItProcessPlimitsSched002(VOID); +void ItProcessPlimitsSched003(VOID); +void ItProcessPlimitsSched004(VOID); +void ItProcessPlimitsDevices001(void); +void ItProcessPlimitsDevices002(void); +void ItProcessPlimitsDevices003(void); +void ItProcessPlimitsDevices004(void); +void ItProcessPlimitsDevices005(void); +void ItProcessPlimitsDevices006(void); +void ItProcessPlimitsDevices007(void); +void ItProcessPlimitsDevices008(void); +void ItProcessPlimitsDevices009(void); +void ItProcessPlimitsIpc002(void); +void ItProcessPlimitsIpc003(void); +void ItProcessPlimitsIpc004(void); +void ItProcessPlimitsIpc005(void); +void ItProcessPlimitsIpc006(void); +void ItProcessPlimitsIpc007(void); +void ItProcessPlimitsIpc008(void); +void ItProcessPlimitsIpc009(void); +void ItProcessPlimitsIpc010(void); +void ItProcessPlimitsIpc011(void); +void ItProcessPlimitsIpc012(void); +void ItProcessPlimitsIpc013(void); +#endif +#endif /* _IT_PROCESS_PLIMITS_H */ diff --git a/testsuites/unittest/process/plimits/config.gni b/testsuites/unittest/process/plimits/config.gni new file mode 100644 index 0000000000000000000000000000000000000000..35cbe4b14e7cc9226f58b45fd768d9323ddc293f --- /dev/null +++ b/testsuites/unittest/process/plimits/config.gni @@ -0,0 +1,100 @@ +# Copyright (c) 2023-2023 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. + +import("//build/lite/config/test.gni") +import("//kernel/liteos_a/testsuites/unittest/config.gni") + +common_include_dirs = [ + "//third_party/googletest/googletest/include", + "../../common/include", +] + +sources_entry = [ "../../common/osTest.cpp" ] + +sources_smoke = [] + +sources_full = [] + +process_plimits_include_dirs = [ "$TEST_UNITTEST_DIR/process/plimits" ] + +process_plimits_sources_entry = + [ "$TEST_UNITTEST_DIR/process/plimits/process_plimits_test.cpp" ] + +process_plimits_sources_smoke = [ + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_001.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_002.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_003.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_004.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_005.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_006.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_007.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_008.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_001.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_002.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_003.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_004.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_005.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_006.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_memory_001.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_memory_002.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_sched_001.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_sched_002.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_sched_003.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_sched_004.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_001.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_002.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_003.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_004.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_005.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_006.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_007.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_008.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_009.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_002.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_003.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_004.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_005.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_006.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_007.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_008.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_009.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_010.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_011.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_012.cpp", + "$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_013.cpp", +] + +process_plimits_sources_full = [] + +# plimits module +if (LOSCFG_USER_TEST_PROCESS == true) { + common_include_dirs += process_plimits_include_dirs + sources_entry += process_plimits_sources_entry + sources_smoke += process_plimits_sources_smoke + sources_full += process_plimits_sources_full +} diff --git a/testsuites/unittest/process/plimits/process_plimits_test.cpp b/testsuites/unittest/process/plimits/process_plimits_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a4ca09b947937612fc47b71256ed03d72adb7dd7 --- /dev/null +++ b/testsuites/unittest/process/plimits/process_plimits_test.cpp @@ -0,0 +1,901 @@ +/* + + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +using namespace std; +using namespace testing::ext; +namespace OHOS { +class ProcessPlimitsTest : public testing::Test { +public: + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} + +protected: + virtual void SetUp(); + virtual void TearDown(); + +private: + inline bool IsFile(const std::string &file); + inline bool IsDir(const std::string &path); + inline bool IsSpecialDir(const std::string &path); +}; + +#if defined(LOSCFG_USER_TEST_SMOKE) +/** +* @tc.name: plimits_Test_001 +* @tc.desc: plimits function test case +* @tc.type: FUNC +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimits001, TestSize.Level0) +{ + ItProcessPlimits001(); +} + +/** +* @tc.name: plimits_Test_002 +* @tc.desc: plimits function test case +* @tc.type: FUNC +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimits002, TestSize.Level0) +{ + ItProcessPlimits002(); +} + +/** +* @tc.name: plimits_Test_003 +* @tc.desc: plimits function test case +* @tc.type: FUNC +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimits003, TestSize.Level0) +{ + ItProcessPlimits003(); +} + +/** +* @tc.name: plimits_Test_004 +* @tc.desc: plimits function test case +* @tc.type: FUNC +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimits004, TestSize.Level0) +{ + ItProcessPlimits004(); +} + +/** +* @tc.name: plimits_Test_005 +* @tc.desc: plimits function test case +* @tc.type: FUNC +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimits005, TestSize.Level0) +{ + ItProcessPlimits005(); +} + +/** +* @tc.name: plimits_Test_006 +* @tc.desc: plimits function test case +* @tc.type: FUNC +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimits006, TestSize.Level0) +{ + ItProcessPlimits006(); +} + +/** +* @tc.name: plimits_Test_007 +* @tc.desc: plimits function test case +* @tc.type: FUNC +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimits007, TestSize.Level0) +{ + ItProcessPlimits007(); +} + +/** +* @tc.name: plimits_Test_008 +* @tc.desc: plimits function test case +* @tc.type: FUNC +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimits008, TestSize.Level0) +{ + ItProcessPlimits008(); +} + +/** +* @tc.name: plimits_pid_Test_001 +* @tc.desc: pid plimit function test case +* @tc.type: FUNC +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsPid001, TestSize.Level0) +{ + ItProcessPlimitsPid001(); +} + +/** +* @tc.name: plimits_pid_Test_002 +* @tc.desc: pid plimit function test case +* @tc.type: FUNC +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsPid002, TestSize.Level0) +{ + ItProcessPlimitsPid002(); +} + +/** +* @tc.name: plimits_pid_Test_003 +* @tc.desc: pid plimit function test case +* @tc.type: FUNC +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsPid003, TestSize.Level0) +{ + ItProcessPlimitsPid003(); +} + +/** +* @tc.name: plimits_pid_Test_004 +* @tc.desc: pid plimit function test case +* @tc.type: FUNC +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsPid004, TestSize.Level0) +{ + ItProcessPlimitsPid004(); +} + +/** +* @tc.name: plimits_pid_Test_005 +* @tc.desc: pid plimit function test case +* @tc.type: FUNC +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsPid005, TestSize.Level0) +{ + ItProcessPlimitsPid005(); +} + +/** +* @tc.name: plimits_pid_Test_006 +* @tc.desc: pid plimit function test case +* @tc.type: FUNC +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsPid006, TestSize.Level0) +{ + ItProcessPlimitsPid006(); +} + +/** +* @tc.name: plimits_Mem_Test_001 +* @tc.desc: mem plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsMemory001, TestSize.Level0) +{ + ItProcessPlimitsMemory001(); +} + +/** +* @tc.name: plimits_Mem_Test_002 +* @tc.desc: mem plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsMemory002, TestSize.Level0) +{ + ItProcessPlimitsMemory002(); +} + +/** +* @tc.name: plimits_Dev_Test_001 +* @tc.desc: devices plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices001, TestSize.Level0) +{ + ItProcessPlimitsDevices001(); +} + +/** +* @tc.name: plimits_Dev_Test_002 +* @tc.desc: devices plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices002, TestSize.Level0) +{ + ItProcessPlimitsDevices002(); +} + +/** +* @tc.name: plimits_Dev_Test_003 +* @tc.desc: devices plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices003, TestSize.Level0) +{ + ItProcessPlimitsDevices003(); +} + +/** +* @tc.name: plimits_Dev_Test_004 +* @tc.desc: devices plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices004, TestSize.Level0) +{ + ItProcessPlimitsDevices004(); +} + +/** +* @tc.name: plimits_Dev_Test_005 +* @tc.desc: devices plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices005, TestSize.Level0) +{ + ItProcessPlimitsDevices005(); +} + +/** +* @tc.name: plimits_Dev_Test_006 +* @tc.desc: devices plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices006, TestSize.Level0) +{ + ItProcessPlimitsDevices006(); +} + +/** +* @tc.name: plimits_Dev_Test_007 +* @tc.desc: devices plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices007, TestSize.Level0) +{ + ItProcessPlimitsDevices007(); +} + +/** +* @tc.name: plimits_Dev_Test_008 +* @tc.desc: devices plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices008, TestSize.Level0) +{ + ItProcessPlimitsDevices008(); +} + +/** +* @tc.name: plimits_Dev_Test_009 +* @tc.desc: devices plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsDevices009, TestSize.Level0) +{ + ItProcessPlimitsDevices009(); +} + +/** +* @tc.name: plimits_Ipc_Test_002 +* @tc.desc: ipc plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc002, TestSize.Level0) +{ + ItProcessPlimitsIpc002(); +} + +/** +* @tc.name: plimits_Ipc_Test_003 +* @tc.desc: ipc plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc003, TestSize.Level0) +{ + ItProcessPlimitsIpc003(); +} + +/** +* @tc.name: plimits_Ipc_Test_004 +* @tc.desc: ipc plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc004, TestSize.Level0) +{ + ItProcessPlimitsIpc004(); +} + +/** +* @tc.name: plimits_Ipc_Test_005 +* @tc.desc: ipc plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc005, TestSize.Level0) +{ + ItProcessPlimitsIpc005(); +} + +/** +* @tc.name: plimits_Ipc_Test_006 +* @tc.desc: ipc plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc006, TestSize.Level0) +{ + ItProcessPlimitsIpc006(); +} + +/** +* @tc.name: plimits_Ipc_Test_007 +* @tc.desc: ipc plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc007, TestSize.Level0) +{ + ItProcessPlimitsIpc007(); +} + +/** +* @tc.name: plimits_Ipc_Test_008 +* @tc.desc: ipc plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc008, TestSize.Level0) +{ + ItProcessPlimitsIpc008(); +} + +/** +* @tc.name: plimits_Ipc_Test_009 +* @tc.desc: ipc plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc009, TestSize.Level0) +{ + ItProcessPlimitsIpc009(); +} + +/** +* @tc.name: plimits_Ipc_Test_010 +* @tc.desc: ipc plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc010, TestSize.Level0) +{ + ItProcessPlimitsIpc010(); +} + +/** +* @tc.name: plimits_Ipc_Test_011 +* @tc.desc: ipc plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc011, TestSize.Level0) +{ + ItProcessPlimitsIpc011(); +} + +/** +* @tc.name: plimits_Ipc_Test_012 +* @tc.desc: ipc plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc012, TestSize.Level0) +{ + ItProcessPlimitsIpc012(); +} + +/** +* @tc.name: plimits_Ipc_Test_013 +* @tc.desc: ipc plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, ItProcessPlimitsIpc013, TestSize.Level0) +{ + ItProcessPlimitsIpc013(); +} + +/** +* @tc.name: plimits_Sched_Test_001 +* @tc.desc: sched plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, IItProcessPlimitsSched001, TestSize.Level0) +{ + ItProcessPlimitsSched001(); +} + +/** +* @tc.name: plimits_Sched_Test_002 +* @tc.desc: sched plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, IItProcessPlimitsSched002, TestSize.Level0) +{ + ItProcessPlimitsSched002(); +} + +/** +* @tc.name: plimits_Sched_Test_003 +* @tc.desc: sched plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, IItProcessPlimitsSched003, TestSize.Level0) +{ + ItProcessPlimitsSched003(); +} + +/** +* @tc.name: plimits_Sched_Test_004 +* @tc.desc: sched plimit function test case +* @tc.require: issueI6GVPL +* @tc.author: +*/ +HWTEST_F(ProcessPlimitsTest, IItProcessPlimitsSched004, TestSize.Level0) +{ + ItProcessPlimitsSched004(); +} +#endif +} // namespace OHOS + + +namespace OHOS { +void ProcessPlimitsTest::SetUp() +{ + (void)rmdir("/proc/plimits/test"); +} + +void ProcessPlimitsTest::TearDown() +{ + (void)rmdir("/proc/plimits/test"); +} + +bool ProcessPlimitsTest::IsFile(const std::string &file) +{ + struct stat statbuf; + return (lstat(file.c_str(), &statbuf) == 0) && S_ISREG(statbuf.st_mode); +} + +bool ProcessPlimitsTest::IsDir(const std::string &path) +{ + struct stat statbuf; + return (lstat(path.c_str(), &statbuf) == 0) && S_ISDIR(statbuf.st_mode); +} + +bool ProcessPlimitsTest::IsSpecialDir(const std::string &path) +{ + return strcmp(path.c_str(), ".") == 0 || strcmp(path.c_str(), "..") == 0; +} +} // namespace OHOS + +int ReadFile(const char *filepath, char *buf) +{ + FILE *fpid = nullptr; + fpid = fopen(filepath, "r"); + if (fpid == nullptr) { + return -1; + } + size_t trd = fread(buf, 1, 512, fpid); + (void)fclose(fpid); + return trd; +} + +int WriteFile(const char *filepath, const char *buf) +{ + int fd = open(filepath, O_WRONLY); + if (fd == -1) { + return -1; + } + size_t twd = write(fd, buf, strlen(buf)); + if (twd == -1) { + (void)close(fd); + return -1; + } + (void)close(fd); + return twd; +} + +int GetLine(char *buf, int count, int maxLen, char **array) +{ + char *head = buf; + char *tail = buf; + char index = 0; + if ((buf == NULL) || (strlen(buf) == 0)) { + return 0; + } + while (*tail != '\0') { + if (*tail != '\n') { + tail++; + continue; + } + if (index >= count) { + return index + 1; + } + + array[index] = head; + index++; + *tail = '\0'; + if (strlen(head) > maxLen) { + return index + 1; + } + tail++; + head = tail; + tail++; + } + return (index + 1); +} + +int RmdirTest(std::string path) +{ + int ret; + RmdirControlFile(path); + ret = rmdir(path.c_str()); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + return 0; +} + +int WaitForCpupStable(int expectedCpupPercent) +{ + int sleepTime; + if (expectedCpupPercent >= QUOTA_PERCENT_100) { + sleepTime = WAIT_CPUP_STABLE_FOR_100; + } else { + sleepTime = WAIT_CPUP_STABLE; + } + return sleep(sleepTime); +} + +static int SampleRound(void) +{ + return STATISTIC_TIMES; +} + +static vector GetProcessInfo(pid_t pid) +{ + vector contentArr; + char buf[TEST_BUFFER_SIZE + 1] = {0}; + string strpid = to_string(pid); + + ifstream infile; + infile.open("/proc/process"); + while (!infile.eof()) { + infile.getline(buf, TEST_BUFFER_SIZE); + regex e("^\\s+"+strpid); + int matchResult = regex_search(buf, e); + if (matchResult == 1) { + istringstream str(buf); + string out; + while (str >> out) { + contentArr.push_back(out); + } + break; + } + (void)memset_s(buf, TEST_BUFFER_SIZE, 0, TEST_BUFFER_SIZE); + } + infile.close(); + (void)memset_s(buf, TEST_BUFFER_SIZE, 0, TEST_BUFFER_SIZE); + return contentArr; +} + + +static void SigQuit(int s) +{ + exit(0); +} + +static int ChildRunCpup() +{ + struct sigaction act; + act.sa_handler = SigQuit; + (void)sigaction(SIGUSR1, &act, NULL); + + unsigned long x = 1; + unsigned long y = 1; + while (1) { + y++; + x *= y; + } + + return 0; +} + +int ForkChilds(int num, int *pidArray) +{ + pid_t childPid; + pid_t pidArrayLocal[PROCESS_LIMIT_AMOUNT]; + + for (int idx = 0; idx < num; idx++) { + childPid = fork(); + if (childPid == 0) { + (void)ChildRunCpup(); + } else if (childPid > 0) { + pidArrayLocal[idx] = childPid; + *pidArray = childPid; + pidArray++; + } else { + return -errno; + } + } + return 0; +} + +static double GetCpup(pid_t pid) +{ + auto content = GetProcessInfo(pid); + double cpup10s = atof(content[CPUP10S_INDEX].c_str()); + return cpup10s; +} + +static int CollectCpupData(int childAmount, int sampleSeconds, int *pidArray, vector> &cpupValuesArray) +{ + double cpup10s; + for (int i = 0; i < sampleSeconds; i++) { + for (int j = 0; j < childAmount;j++) { + cpup10s = GetCpup(pidArray[j]); + cpupValuesArray[j].push_back(cpup10s); + } + sleep(1); + } + return 0; +} + +static int CalcAverageCpup(int num, vector> &cpupValuesArray, double *cpupAverageArray) +{ + double cpup10sAverage; + for (int idx = 0; idx < num; idx++) { + auto size = cpupValuesArray[idx].size(); + cpup10sAverage = std::accumulate(cpupValuesArray[idx].begin(), cpupValuesArray[idx].end(), 0.0) / size; + cpupAverageArray[idx] = cpup10sAverage; + } + return 0; +} + +int CreatePlimitGroup(const char* groupName, char *childPidFiles, + unsigned long long periodUs, unsigned long long quotaUs) +{ + int ret; + mode_t mode = 0777; + char dirpath[TEST_BUFFER_SIZE]; + char procspath[TEST_BUFFER_SIZE]; + char periodpath[TEST_BUFFER_SIZE]; + char quotapath[TEST_BUFFER_SIZE]; + char periodValue[TEST_BUFFER_SIZE]; + char quotaValue[TEST_BUFFER_SIZE]; + + if (sprintf_s(dirpath, TEST_BUFFER_SIZE, "/proc/plimits/%s", groupName) < 0) { + return -1; + } + if (sprintf_s(procspath, TEST_BUFFER_SIZE, "%s/plimits.procs", dirpath) < 0) { + return -1; + } + if (sprintf_s(periodpath, TEST_BUFFER_SIZE, "%s/sched.period", dirpath) < 0) { + return -1; + } + if (sprintf_s(quotapath, TEST_BUFFER_SIZE, "%s/sched.quota", dirpath) < 0) { + return -1; + } + + ret = access(dirpath, 0); + ICUNIT_ASSERT_EQUAL(ret, -1, ret); + + ret = mkdir(dirpath, mode); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + if (sprintf_s(periodValue, TEST_BUFFER_SIZE, "%llu", periodUs) < 0) { + return -1; + } + if (sprintf_s(quotaValue, TEST_BUFFER_SIZE, "%llu", quotaUs) < 0) { + return -1; + } + ret = WriteFile(periodpath, periodValue); + if (ret < 0) { + printf("%s %d\n", __FUNCTION__, __LINE__); + return ret; + } + ret = WriteFile(quotapath, quotaValue); + if (ret < 0) { + printf("%s %d\n", __FUNCTION__, __LINE__); + return ret; + } + if (sprintf_s(childPidFiles, TEST_BUFFER_SIZE, "%s", procspath) < 0) { + return -1; + } + return 0; +} + +int CreatePlimitGroupWithoutLimit(const char* groupName, char *childPidFiles) +{ + int ret; + mode_t mode = 0777; + char dirpath[TEST_BUFFER_SIZE]; + char procspath[TEST_BUFFER_SIZE]; + + if (sprintf_s(dirpath, TEST_BUFFER_SIZE, "/proc/plimits/%s", groupName) < 0) { + return -1; + } + if (sprintf_s(procspath, TEST_BUFFER_SIZE, "%s/plimits.procs", dirpath) < 0) { + return -1; + } + + ret = access(dirpath, 0); + ICUNIT_ASSERT_EQUAL(ret, -1, ret); + ret = mkdir(dirpath, mode); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + if (sprintf_s(childPidFiles, TEST_BUFFER_SIZE, "%s", procspath) < 0) { + return -1; + } + return 0; +} + +int TerminateChildProcess(int *childPidArray, int childAmount, int sig) +{ + int idx; + for (idx = 0; idx < childAmount; idx++) { + (void)kill(childPidArray[idx], SIGUSR1); + + int status; + (void)waitpid(childPidArray[idx], &status, 0); + } + + (void)signal(SIGUSR1, SIG_DFL); + return 0; +} + +double CalcCpupUsage(int childAmount, int *childPidArray, int expectedCpupPercent) +{ + int idx; + int sampleSeconds = SampleRound(); + vector> cpupValuesArray(PROCESS_LIMIT_AMOUNT); + (void)CollectCpupData(childAmount, sampleSeconds, &childPidArray[0], cpupValuesArray); + + double actualCpup10sArray[PROCESS_LIMIT_AMOUNT]; + (void)CalcAverageCpup(childAmount, cpupValuesArray, &actualCpup10sArray[0]); + + double sumAllChildsCpup = 0; + for (idx = 0; idx < childAmount; idx++) { + sumAllChildsCpup += actualCpup10sArray[idx]; + } + return sumAllChildsCpup; +} + +double CheckCpupUsage(double sumAllChildsCpup, int expectedCpupPercent) +{ + if (expectedCpupPercent <= 0.0) { + return 500.0; /* 500.0: errno */ + } + double errorRate = fabs(sumAllChildsCpup / expectedCpupPercent - 1.0); + return errorRate; +} + +int checkCpupUsageGreaterThan(double sumAllChildsCpup, int expectedCpupPercent) +{ + if (sumAllChildsCpup > expectedCpupPercent) { + return 0; + } else { + return -1; + } +} + +double TestCpupInPlimit(int childAmount, const char* groupName, + unsigned long long periodUs, unsigned long long quotaUs, int expectedCpupPercent) +{ + char dirpath[TEST_BUFFER_SIZE]; + pid_t childPidArray[PROCESS_LIMIT_AMOUNT]; + char procspath[TEST_BUFFER_SIZE]; + double sumAllChildsCpup = 0; + + int ret = CreatePlimitGroup(groupName, procspath, periodUs, quotaUs); + if (ret < 0) { + printf("%s %d, ret=%d\n", __FUNCTION__, __LINE__, ret); + return 100.0; /* 100.0: errno */ + } + ret = ForkChilds(childAmount, &childPidArray[0]); + if (ret != 0) { + printf("%s %d, ret=%d\n", __FUNCTION__, __LINE__, ret); + return 200.0; /* 200.0: errno */ + } + (void)WaitForCpupStable(expectedCpupPercent); + sumAllChildsCpup = CalcCpupUsage(childAmount, &childPidArray[0], 0); + double errorRate = CheckCpupUsage(sumAllChildsCpup, expectedCpupPercent); + + (void)TerminateChildProcess(&childPidArray[0], childAmount, SIGUSR1); + + if (sprintf_s(dirpath, TEST_BUFFER_SIZE, "/proc/plimits/%s", groupName) < 0) { + return 300.0; /* 300.0: errno */ + } + ret = rmdir(dirpath); + if (ret != 0) { + printf("%s %d, ret=%d\n", __FUNCTION__, __LINE__, errno); + return 400.0; /* 400.0: errno */ + } + return errorRate; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_001.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_001.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f3665a56f4512e34da5687c25da5c9ff8fd8bd05 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_001.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimits001(void) +{ + DIR *dirp = opendir("/proc/plimits"); + ASSERT_NE(dirp, nullptr); + (void)closedir(dirp); + + int ret; + std::string path = "/proc/plimits/test1"; + ret = mkdir(path.c_str(), S_IRWXU); // create directory + ASSERT_EQ(ret, 0); + + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_002.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_002.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e2bf4ef13a0ef60fd76829e9458200778324f505 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_002.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include "It_process_plimits.h" + +void ItProcessPlimits002(void) +{ + (void)rmdir("/proc/plimits"); + DIR *dirp = opendir("/proc/plimits/"); + ASSERT_NE(dirp, nullptr); + (void)closedir(dirp); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_003.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_003.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0d5771e82b51bc2b6b9b641b6df493b6af9c6af3 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_003.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include "It_process_plimits.h" + +void ItProcessPlimits003(void) +{ + int ret; + const char *path = "/proc/text.txt"; + ret = open(path, O_CREAT); + ASSERT_EQ(ret, -1); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_004.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_004.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6b54fc0099941509f3b7732c99a67fa894a49fa3 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_004.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimits004(void) +{ + int ret, matchResult; + const size_t BUFFER_SIZE = 512; + char buf[BUFFER_SIZE + 1] = {0}; + std::string path = "/proc/plimits/test"; + mode_t mode; + + ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + (void)ReadFile("/proc/plimits/test/plimits.limiters", buf); + printf("/proc/plimits/test/plimits.limiters: %s\n", buf); + matchResult = strncmp(buf, "pids memory ipc devices sched", 29); /* 29: buf len */ + ASSERT_EQ(matchResult, 0); + + ret = rmdir("/proc/plimits/test"); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_005.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_005.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b103931e78fbd416bae71cfd8c5abfd4917bd7dc --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_005.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include "It_process_plimits.h" + +void ItProcessPlimits005(void) +{ + int ret; + const char *path = "/proc/plimits/text.txt"; + ret = open(path, O_CREAT); + ASSERT_EQ(ret, -1); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_006.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_006.cpp new file mode 100644 index 0000000000000000000000000000000000000000..971fa18ab0fce0970e3056bd18d7828093793bc0 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_006.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include "It_process_plimits.h" + +void ItProcessPlimits006(void) +{ + int ret; + const char *path3 = "/proc/plimits/plimits.procs"; + ret = remove(path3); + ASSERT_EQ(ret, -1); + + const char *path4 = "/proc/plimits/pids.max"; + ret = remove(path4); + ASSERT_EQ(ret, -1); + + const char *path5 = "/proc/plimits/pids.priority"; + ret = remove(path5); + ASSERT_EQ(ret, -1); + + const char *path6 = "/proc/plimits/sched.period"; + ret = remove(path6); + ASSERT_EQ(ret, -1); + + const char *path7 = "/proc/plimits/sched.quota"; + ret = remove(path7); + ASSERT_EQ(ret, -1); + + const char *path8 = "/proc/plimits/sched.stat"; + ret = remove(path8); + ASSERT_EQ(ret, -1); + + const char *path9 = "/proc/plimits/memory.limit"; + ret = remove(path9); + ASSERT_EQ(ret, -1); + + const char *path10 = "/proc/plimits/memory.stat"; + ret = remove(path10); + ASSERT_EQ(ret, -1); + + const char *path11 = "/proc/plimits/ipc.mq_limit"; + ret = remove(path11); + ASSERT_EQ(ret, -1); + + const char *path12 = "/proc/plimits/ipc.shm_limit"; + ret = remove(path12); + ASSERT_EQ(ret, -1); + + const char *path13 = "/proc/plimits/ipc.stat"; + ret = remove(path13); + ASSERT_EQ(ret, -1); + + const char *path14 = "/proc/plimits/devices.list"; + ret = remove(path14); + ASSERT_EQ(ret, -1); + + const char *path15 = "/proc/plimits/devices.deny"; + ret = remove(path15); + ASSERT_EQ(ret, -1); + + const char *path16 = "/proc/plimits/devices.allow"; + ret = remove(path16); + ASSERT_EQ(ret, -1); + + const char *path17 = "/proc/plimits/limiters"; + ret = remove(path17); + ASSERT_EQ(ret, -1); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_007.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_007.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f7edc0edca4ee3ead2acdc3224ecfc2d594a1a13 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_007.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimits007(void) +{ + mode_t mode = S_IRWXU; + std::string path0 = "/proc/plimits/test"; + std::string path1 = "/proc/plimits/test/subtest"; + std::string path2 = "/proc/plimits/test/subtest/subtest"; + std::string path3 = "/proc/plimits/test/subtest/subtest/subtest"; + std::string path4 = "/proc/plimits/test/subtest/subtest/subtest/subtest"; + int ret = mkdir(path0.c_str(), mode); + ASSERT_EQ(ret, 0); + + ret = mkdir(path1.c_str(), mode); + ASSERT_EQ(ret, -1); + + ret = mkdir(path2.c_str(), mode); + ASSERT_EQ(ret, -1); + + ret = mkdir(path3.c_str(), mode); + ASSERT_EQ(ret, -1); + + ret = mkdir(path4.c_str(), mode); + ASSERT_EQ(ret, -1); + + ret = rmdir(path0.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_008.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_008.cpp new file mode 100644 index 0000000000000000000000000000000000000000..625f78a478ae27d9d29c217002f5a64b9bdea458 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_008.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +static std::string GetFileMode(const char* filePath) +{ + const int MODE_COUNT = 11; + char fileProperty[MODE_COUNT] = "----------"; + char fileMode[MODE_COUNT] = "-rwxrwxrwx"; + struct stat buf; + stat(filePath, &buf); + unsigned int off = 256; + const int LOOP_VARY = 10; + for (int i = 1; i < LOOP_VARY; i++) { + if (buf.st_mode & (off >> (i - 1))) { + fileProperty[i] = fileMode[i]; + } + } + return fileProperty; +} + +static int IsFilePropertyR1(const char* filePath) +{ + std::string fileOrg = "-r--r--r--"; + std::string fileProperty = GetFileMode(filePath); + return strcmp(fileProperty.c_str(), fileOrg.c_str()); +} + +void ItProcessPlimits008(void) +{ + std::string filePath = "/proc/plimits/"; + std::vector fileName; + fileName.push_back("plimits.procs"); + fileName.push_back("plimits.limiters"); + fileName.push_back("pids.max"); + fileName.push_back("sched.period"); + fileName.push_back("sched.quota"); + fileName.push_back("sched.stat"); + fileName.push_back("memory.failcnt"); + fileName.push_back("memory.limit"); + fileName.push_back("memory.peak"); + fileName.push_back("memory.usage"); + fileName.push_back("memory.stat"); + + for (auto iter = fileName.begin(); iter != fileName.end(); ++iter) { + std::string fileFullPath = filePath + *iter; + int ret = IsFilePropertyR1(fileFullPath.c_str()); + ASSERT_EQ(ret, 0); + } + + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_001.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_001.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f4b9d0784c231f55acfa5b612b56eefddfbc6c26 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_001.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsDevices001(void) +{ + int fd; + int ret; + mode_t mode; + char writeBuf[8]; + std::string test_dev = "/dev/hi_mipi"; + std::string path = "/proc/plimits/test"; + std::string procsTestPath = "/proc/plimits/test/plimits.procs"; + + ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + (void)memset_s(writeBuf, sizeof(writeBuf), 0, sizeof(writeBuf)); + ret = sprintf_s(writeBuf, sizeof(writeBuf), "%d", getpid()); + ASSERT_NE(ret, -1); + + ret = WriteFile(procsTestPath.c_str(), writeBuf); + ASSERT_NE(ret, 0); + + fd = open(test_dev.c_str(), O_RDWR|O_CREAT); + ASSERT_NE(fd, -1); + (void)close(fd); + + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_002.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_002.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b6743b514844fe45b23916672f70b6ba4fff8124 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_002.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsDevices002(void) +{ + int fd; + int ret; + mode_t mode; + std::string test_dev = "/dev/hi_mipi"; + std::string device_a = "a * rwm"; + std::string device_a_r = "a * r"; + std::string path = "/proc/plimits/test"; + std::string devicesDenyPath = "/proc/plimits/test/devices.deny"; + std::string devicesAllowPath = "/proc/plimits/test/devices.allow"; + + ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str()); + ASSERT_NE(ret, -1); + + ret = WriteFile(devicesAllowPath.c_str(), device_a_r.c_str()); + ASSERT_NE(ret, -1); + + fd = open(test_dev.c_str(), O_RDWR|O_CREAT); + ASSERT_NE(fd, -1); + (void)close(fd); + + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_003.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_003.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4c4f315c22345060254b4809f3d2276a7976a422 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_003.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsDevices003(void) +{ + int fd; + int ret; + mode_t mode; + std::string test_dev = "/dev/hi_mipi"; + std::string device_a = "a * rwm"; + std::string device_a_w = "a * w"; + std::string path = "/proc/plimits/test"; + std::string devicesDenyPath = "/proc/plimits/test/devices.deny"; + std::string devicesAllowPath = "/proc/plimits/test/devices.allow"; + + ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str()); + ASSERT_NE(ret, -1); + ret = WriteFile(devicesAllowPath.c_str(), device_a_w.c_str()); + ASSERT_NE(ret, -1); + + fd = open(test_dev.c_str(), O_RDWR|O_CREAT); + ASSERT_NE(fd, -1); + (void)close(fd); + + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_004.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_004.cpp new file mode 100644 index 0000000000000000000000000000000000000000..94a92241fa66e0b2c1025600c773efa0e4579a0f --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_004.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsDevices004(void) +{ + int fd; + int ret; + mode_t mode; + std::string test_dev = "/dev/hi_mipi"; + std::string device_a = "a * rwm"; + std::string device_a_m = "a * m"; + std::string path = "/proc/plimits/test"; + std::string devicesDenyPath = "/proc/plimits/test/devices.deny"; + std::string devicesAllowPath = "/proc/plimits/test/devices.allow"; + + ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str()); + ASSERT_NE(ret, -1); + ret = WriteFile(devicesAllowPath.c_str(), device_a_m.c_str()); + ASSERT_NE(ret, -1); + + fd = open(test_dev.c_str(), O_CREAT); + ASSERT_NE(fd, -1); + (void)close(fd); + + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_005.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_005.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0464ef5b33b992c2f64098b9f40913ce09fcc583 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_005.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsDevices005(void) +{ + int fd; + int ret; + mode_t mode; + std::string test_dev = "/dev/mem"; + std::string device_a = "a * rwm"; + std::string device_c = "c * rwm"; + std::string path = "/proc/plimits/test"; + std::string devicesDenyPath = "/proc/plimits/test/devices.deny"; + std::string devicesAllowPath = "/proc/plimits/test/devices.allow"; + + ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str()); + ASSERT_NE(ret, -1); + ret = WriteFile(devicesAllowPath.c_str(), device_c.c_str()); + ASSERT_NE(ret, -1); + + fd = open(test_dev.c_str(), O_RDWR|O_CREAT); + ASSERT_NE(fd, -1); + (void)close(fd); + + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_006.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_006.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1b76142ecc7dfac3a918bc69dd9a99d5748c98b4 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_006.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsDevices006(void) +{ + int fd; + int ret; + mode_t mode; + std::string test_dev = "/dev/mem"; + std::string device_a = "a * rwm"; + std::string device_c_r = "c * r"; + std::string path = "/proc/plimits/test"; + std::string devicesDenyPath = "/proc/plimits/test/devices.deny"; + std::string devicesAllowPath = "/proc/plimits/test/devices.allow"; + + ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str()); + ASSERT_NE(ret, -1); + ret = WriteFile(devicesAllowPath.c_str(), device_c_r.c_str()); + ASSERT_NE(ret, -1); + + fd = open(test_dev.c_str(), O_RDONLY); + ASSERT_NE(fd, -1); + (void)close(fd); + + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_007.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_007.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cd75c6d91101991e3db04380969eb2a264a02bfb --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_007.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsDevices007(void) +{ + int fd; + int ret; + mode_t mode; + std::string test_dev = "/dev/mem"; + std::string device_a = "a * rwm"; + std::string device_c_w = "c * w"; + std::string path = "/proc/plimits/test"; + std::string devicesDenyPath = "/proc/plimits/test/devices.deny"; + std::string devicesAllowPath = "/proc/plimits/test/devices.allow"; + + ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str()); + ASSERT_NE(ret, -1); + ret = WriteFile(devicesAllowPath.c_str(), device_c_w.c_str()); + ASSERT_NE(ret, -1); + + fd = open(test_dev.c_str(), O_WRONLY); + ASSERT_NE(fd, -1); + (void)close(fd); + + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_008.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_008.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4e3b19fba38d702e609b43df76182e98765934a2 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_008.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsDevices008(void) +{ + int fd; + int ret; + mode_t mode; + std::string test_dev = "/dev/mem"; + std::string device_a = "a * rwm"; + std::string device_c_m = "c * rm"; + std::string path = "/proc/plimits/test"; + std::string devicesDenyPath = "/proc/plimits/test/devices.deny"; + std::string devicesAllowPath = "/proc/plimits/test/devices.allow"; + + ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str()); + ASSERT_NE(ret, -1); + ret = WriteFile(devicesAllowPath.c_str(), device_c_m.c_str()); + ASSERT_NE(ret, -1); + + fd = open(test_dev.c_str(), O_CREAT, O_RDONLY); + ASSERT_NE(fd, -1); + (void)close(fd); + + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_009.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_009.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c1fa4a582bfc104d7462a9c21bd42bba9e51afe6 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_009.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsDevices009(void) +{ + int fd; + int ret; + mode_t mode; + std::string test_dev = "/dev/hi_mipi"; + std::string device_a = "a"; + std::string path = "/proc/plimits/test"; + std::string devicesDenyPath = "/proc/plimits/test/devices.deny"; + + ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(devicesDenyPath.c_str(), device_a.c_str()); + ASSERT_NE(ret, -1); + + fd = open(test_dev.c_str(), O_RDONLY|O_CREAT); + ASSERT_EQ(fd, -1); + (void)close(fd); + + fd = open(test_dev.c_str(), O_WRONLY|O_CREAT); + ASSERT_EQ(fd, -1); + (void)close(fd); + + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_002.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_002.cpp new file mode 100644 index 0000000000000000000000000000000000000000..93a7de370422cb0399db794b98f866e083ddd56a --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_002.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsIpc002(void) +{ + mode_t mode; + int ret; + int fd; + std::string plimitsRootPath = "/proc/plimits/"; + std::vector ipcConfFileName; + ipcConfFileName.push_back("ipc.mq_limit"); + ipcConfFileName.push_back("ipc.shm_limit"); + ipcConfFileName.push_back("ipc.stat"); + + for (auto iter = ipcConfFileName.begin(); iter != ipcConfFileName.end(); ++iter) { + std::string fullPath = plimitsRootPath + *iter; + fd = access(fullPath.c_str(), W_OK | X_OK); + ASSERT_EQ(fd, -1); + fd = access(fullPath.c_str(), F_OK | R_OK); + ASSERT_EQ(fd, 0); + } + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_003.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_003.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ffd36030dd599b4043ce8acbed3d49b3a2085065 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_003.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsIpc003(void) +{ + mode_t mode; + int ret; + std::string plimitsPath = "/proc/plimits/test"; + std::string configFileMqCount = "/proc/plimits/test/ipc.mq_limit"; + std::string configFileShmSize = "/proc/plimits/test/ipc.shm_limit"; + std::string configFileStat = "/proc/plimits/test/ipc.stat"; + + ret = mkdir(plimitsPath.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + int fd = access(configFileMqCount.c_str(), F_OK | W_OK | R_OK); + ASSERT_EQ(fd, 0); + + fd = access(configFileShmSize.c_str(), F_OK | W_OK | R_OK); + ASSERT_EQ(fd, 0); + + fd = access(configFileStat.c_str(), F_OK | R_OK); + ASSERT_EQ(fd, 0); + + fd = access(configFileStat.c_str(), W_OK | X_OK); + ASSERT_EQ(fd, -1); + + ret = rmdir(plimitsPath.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_004.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_004.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b70dfa577afa4c1722a662d8e496605b6e9ecd4a --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_004.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsIpc004(void) +{ + mode_t mode; + mode_t chmodMode = 0777; + int ret; + int fd; + std::string rootplimitsPath = "/proc/plimits"; + std::string subPlimitsPath = "/proc/plimits/test"; + + std::vector ipcConfFileName; + ipcConfFileName.push_back("ipc.mq_limit"); + ipcConfFileName.push_back("ipc.shm_limit"); + ipcConfFileName.push_back("ipc.stat"); + + ret = mkdir(subPlimitsPath.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + for (auto iter = ipcConfFileName.begin(); iter != ipcConfFileName.end(); ++iter) { + std::string fullPath = rootplimitsPath + "/" + *iter; + ret = chmod(fullPath.c_str(), mode); + ASSERT_EQ(ret, -1); + } + + for (auto iter = ipcConfFileName.begin(); iter != ipcConfFileName.end(); ++iter) { + std::string fullPath = subPlimitsPath + "/" + *iter; + ret = chmod(fullPath.c_str(), mode); + ASSERT_EQ(ret, -1); + } + + ret = rmdir(subPlimitsPath.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_005.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_005.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d4d984fbdcfdc477cf35839e2a42e35eff28c829 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_005.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +static const int g_buffSize = 512; +static const int g_arryLen = 4; +static const int MQ_MAX_PER_PROCESS_COUNT = 255; +static const int MQUEUE_STANDARD_NAME_LENGTH = 50; + +void ItProcessPlimitsIpc005(void) +{ + INT32 ret; + mode_t mode; + char buf[g_buffSize] = { 0 }; + CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + mqd_t mqueue[MQ_MAX_PER_PROCESS_COUNT]; + struct mq_attr attr = { 0 }; + int index = 0; + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = 1; + + std::string plimitsPath = "/proc/plimits/test"; + + ret = mkdir(plimitsPath.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = ReadFile("/proc/plimits/test/ipc.mq_limit", buf); + ASSERT_STREQ(buf, "1024\n"); + + for (index = 0; index < MQ_MAX_PER_PROCESS_COUNT; ++index) { + ret = snprintf_s(mqname, sizeof(mqname), MQUEUE_STANDARD_NAME_LENGTH, "/mq_005_%d_%d", + index, LosCurTaskIDGet()); + ASSERT_NE(ret, -1); + mqueue[index] = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ASSERT_NE(mqueue[index], (mqd_t)-1); + } + for (int k = 0; k < MQ_MAX_PER_PROCESS_COUNT; ++k) { + ret = mq_close(mqueue[k]); + ASSERT_NE(ret, -1); + ret = snprintf_s(mqname, sizeof(mqname), MQUEUE_STANDARD_NAME_LENGTH, "/mq_005_%d_%d", k, LosCurTaskIDGet()); + ASSERT_NE(ret, -1); + ret = mq_unlink(mqname); + ASSERT_EQ(ret, 0); + } + + ret = rmdir(plimitsPath.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_006.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_006.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1e5b25f4f14473124701859a4854db6f9eedfede --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_006.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +static const int MQUEUE_STANDARD_NAME_LENGTH = 50; +static const int g_buffSize = 512; +static const int g_arryLen = 4; +static const int g_readLen = 254; +static const int MQ_MAX_LIMIT_COUNT = 10; + +static int FreeResource(mqd_t *mqueue, int index, char *mqname) +{ + int ret = -1; + for (int k = 0; k < index; ++k) { + if (snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH, "/mq_006_%d_%d", + k, LosCurTaskIDGet()) < 0) { + return -1; + } + ret = mq_close(mqueue[k]); + if (ret != 0) { + return -2; /* 2: errno */ + } + ret = mq_unlink(mqname); + if (ret != 0) { + return -3; /* 3: errno */ + } + (void)memset_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, 0, MQUEUE_STANDARD_NAME_LENGTH); + } + return ret; +} + +// plimits_ipc_07, plimits_ipc_14, plimits_ipc_17 +void ItProcessPlimitsIpc006(void) +{ + INT32 ret; + mode_t mode; + char buf[g_buffSize] = { 0 }; + char *array[g_arryLen] = { nullptr }; + int mqSuccessCount = -1, mqFailedCount = -1; + CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + mqd_t mqueue[g_readLen]; + std::string subPlimitsPath = "/proc/plimits/test"; + std::string configFileMqCount = "/proc/plimits/test/ipc.mq_limit"; + std::string limitMqCount = "10"; + struct mq_attr attr = { 0 }; + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = 1; + int index = 0; + + ret = mkdir(subPlimitsPath.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(configFileMqCount.c_str(), limitMqCount.c_str()); + ASSERT_NE(ret, -1); + + for (index = 0; index < MQ_MAX_LIMIT_COUNT; ++index) { + ret = snprintf_s(mqname, sizeof(mqname), MQUEUE_STANDARD_NAME_LENGTH, "/mq_006_%d_%d", + index, LosCurTaskIDGet()); + ASSERT_NE(ret, -1); + mqueue[index] = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ASSERT_NE(mqueue[index], (mqd_t)-1); + (void)memset_s(mqname, sizeof(mqname), 0, sizeof(mqname)); + } + ret = snprintf_s(mqname, sizeof(mqname), MQUEUE_STANDARD_NAME_LENGTH, "/mq_006_%d_%d", index, LosCurTaskIDGet()); + ASSERT_NE(ret, -1); + mqueue[index] = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ASSERT_EQ(mqueue[index], (mqd_t)-1); + (void)memset_s(mqname, sizeof(mqname), 0, sizeof(mqname)); + + ret = ReadFile("/proc/plimits/test/ipc.stat", buf); + printf("/proc/plimits/test/ipc.stat: %s\n", buf); + GetLine(buf, g_arryLen, g_readLen, array); + mqSuccessCount = atoi(array[0] + strlen("mq count: ")); + mqFailedCount = atoi((array[1] + strlen("mq failed count: "))); + ASSERT_EQ(mqSuccessCount, MQ_MAX_LIMIT_COUNT); + ASSERT_EQ(mqFailedCount, 1); + ret = FreeResource(mqueue, index, mqname); + ASSERT_EQ(ret, 0); + + ret = rmdir(subPlimitsPath.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_007.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_007.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e2ed88424227fe635c43429208b387ca67aa2cf3 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_007.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsIpc007(void) +{ + mode_t mode; + int ret; + std::string plimitsPath = "/proc/plimits/test"; + std::string configFileMqCount = "/proc/plimits/test/ipc.mq_limit"; + std::string mqLimitCount = "0123"; + + ret = mkdir(plimitsPath.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(configFileMqCount.c_str(), mqLimitCount.c_str()); + ASSERT_NE(ret, -1); + + ret = rmdir(plimitsPath.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_008.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_008.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f259beb9f8b37380f83b477a696e4a0ad5889d2a --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_008.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsIpc008(void) +{ + mode_t mode; + int ret; + std::string plimitsPath = "/proc/plimits/test"; + std::string configFileMqCount = "/proc/plimits/test/ipc.mq_limit"; + std::string mqLimitCount_0 = "111*"; + std::string mqLimitCount_1 = "123abc"; + std::string mqLimitCount_2 = "\"123 456\""; + std::string mqLimitCount_3 = "\123"; + std::string mqLimitCount_4 = "10000000000000000000000000000000001"; + std::string mqLimitCount_5 = "\1\2\3"; + + ret = mkdir(plimitsPath.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(configFileMqCount.c_str(), mqLimitCount_0.c_str()); + ASSERT_EQ(ret, -1); + + ret = WriteFile(configFileMqCount.c_str(), mqLimitCount_1.c_str()); + ASSERT_EQ(ret, -1); + + ret = WriteFile(configFileMqCount.c_str(), mqLimitCount_2.c_str()); + ASSERT_EQ(ret, -1); + + ret = WriteFile(configFileMqCount.c_str(), mqLimitCount_3.c_str()); + ASSERT_EQ(ret, -1); + + ret = WriteFile(configFileMqCount.c_str(), mqLimitCount_4.c_str()); + ASSERT_EQ(ret, -1); + + ret = WriteFile(configFileMqCount.c_str(), mqLimitCount_5.c_str()); + ASSERT_EQ(ret, -1); + + ret = rmdir(plimitsPath.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_009.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_009.cpp new file mode 100644 index 0000000000000000000000000000000000000000..938d06edafd7f3f8bd57eb6d5113ca9a11d69f16 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_009.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +static const int g_buffSize = 512; +static const int g_arryLen = 4; +static const int g_readLen = 254; + +void ItProcessPlimitsIpc009(void) +{ + mode_t mode; + char buf[g_buffSize] = { 0 }; + int ret; + int shmid; + void *shared = nullptr; + mode_t acessMode = 0666; + std::string subPlimitsPath = "/proc/plimits/test"; + + ret = mkdir(subPlimitsPath.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = ReadFile("/proc/plimits/test/ipc.shm_limit", buf); + ASSERT_STREQ(buf, "104857600\n"); + + shmid = shmget(IPC_PRIVATE, PAGE_SIZE, acessMode | IPC_CREAT); + ASSERT_NE(shmid, -1); + shared = shmat(shmid, nullptr, 0); + ASSERT_NE(shared, (void *)-1); + ret = shmdt(shared); + ASSERT_NE(ret, -1); + ret = shmctl(shmid, IPC_RMID, nullptr); + ASSERT_NE(ret, -1); + + ret = rmdir(subPlimitsPath.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_010.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_010.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4c0abd3500ab04738af86684ba8ecdf1edef303c --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_010.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +static const int g_buffSize = 512; +static const int g_arryLen = 4; +static const int g_readLen = 254; + +void ItProcessPlimitsIpc010(void) +{ + mode_t mode; + mode_t shmAcess = 0666; + char buf[g_buffSize] = { 0 }; + char *array[g_arryLen] = { nullptr }; + int mqSuccessCount; + int mqFailedCount; + int shmSuccessSize; + int shmFailedCount; + int shmid = -1; + int shmid_1 = -1; + int index = 0; + int shmCkeckSize = PAGE_SIZE * 9; + void *shared = nullptr; + size_t shmSize = PAGE_SIZE * 9; + std::string subPlimitsPath = "/proc/plimits/test"; + std::string configFileShmSize = "/proc/plimits/test/ipc.shm_limit"; + char shmemLimit[6] = "40960"; + + int ret = mkdir(subPlimitsPath.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(configFileShmSize.c_str(), shmemLimit); + ASSERT_NE(ret, -1); + + shmid = shmget(IPC_PRIVATE, shmSize, shmAcess | IPC_CREAT); + ASSERT_NE(shmid, -1); + shmid_1 = shmget(IPC_PRIVATE, 2 * PAGE_SIZE, shmAcess | IPC_CREAT); /* 2: PAGE num */ + ASSERT_EQ(shmid_1, -1); + + ret = ReadFile("/proc/plimits/test/ipc.stat", buf); + GetLine(buf, g_arryLen, g_readLen, array); + mqSuccessCount = atoi(array[index++] + strlen("mq count: ")); + mqFailedCount = atoi(array[index++] + strlen("mq failed count: ")); + shmSuccessSize = atoi(array[index++] + strlen("shm size: ")); + shmFailedCount = atoi(array[index++] + strlen("shm failed count: ")); + + ASSERT_EQ(shmSuccessSize, shmCkeckSize); + ASSERT_EQ(shmFailedCount, 1); + + shared = shmat(shmid, nullptr, 0); + ASSERT_NE(shared, (void *)-1); + + ret = shmdt(shared); + ASSERT_NE(ret, -1); + + ret = shmctl(shmid, IPC_RMID, nullptr); + ASSERT_NE(ret, -1); + shmctl(shmid_1, IPC_RMID, nullptr); + shmctl(shmid, IPC_RMID, nullptr); + + ret = rmdir(subPlimitsPath.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_011.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_011.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d2a2c4a89c5fa0e4285a0eb896c9097e48817fb9 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_011.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsIpc011(void) +{ + mode_t mode; + int ret; + char buf[512] = { 0 }; + std::string plimitsPath = "/proc/plimits/test"; + std::string configFileShmSize = "/proc/plimits/test/ipc.shm_limit"; + std::string shmLimitSize = "0123"; + + ret = mkdir(plimitsPath.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(configFileShmSize.c_str(), shmLimitSize.c_str()); + ASSERT_NE(ret, -1); + + ret = rmdir(plimitsPath.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_012.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_012.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5b3ead3fafbc6942d8b6908b4c70d7a6a1428fb6 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_012.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsIpc012(void) +{ + mode_t mode; + int ret; + std::string plimitsPath = "/proc/plimits/test"; + std::string configFileShmSize = "/proc/plimits/test/ipc.shm_limit"; + std::string shmLimitSize_0 = "111*"; + std::string shmLimitSize_1 = "123abc"; + std::string shmLimitSize_2 = "\"123 456\""; + std::string shmLimitSize_3 = "\123"; + std::string shmLimitSize_4 = "10000000000000000000000000000000001"; + std::string shmLimitSize_5 = "\1\2\3"; + + ret = mkdir(plimitsPath.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(configFileShmSize.c_str(), shmLimitSize_0.c_str()); + ASSERT_EQ(ret, -1); + + ret = WriteFile(configFileShmSize.c_str(), shmLimitSize_1.c_str()); + ASSERT_EQ(ret, -1); + + ret = WriteFile(configFileShmSize.c_str(), shmLimitSize_2.c_str()); + ASSERT_EQ(ret, -1); + + ret = WriteFile(configFileShmSize.c_str(), shmLimitSize_3.c_str()); + ASSERT_EQ(ret, -1); + + ret = WriteFile(configFileShmSize.c_str(), shmLimitSize_4.c_str()); + ASSERT_EQ(ret, -1); + + ret = WriteFile(configFileShmSize.c_str(), shmLimitSize_5.c_str()); + ASSERT_EQ(ret, -1); + + ret = rmdir(plimitsPath.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_013.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_013.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0dc5d5a5d8f59f12cfe550612efe202dee97b1e2 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_013.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +static const int MQUEUE_STANDARD_NAME_LENGTH = 50; +static const int MQUEUE_STANDARD_NAME_LENGTH_MAX = 102500; +static const int g_buff = 512; +static const int MQ_MAX_LIMIT_COUNT = 10; + +static int FreeResource(mqd_t *mqueue, int index, char *mqname) +{ + int ret = -1; + for (int k = 0; k < index; ++k) { + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH, "/mq_006_%d_%d", + k, LosCurTaskIDGet()); + if (ret < 0) { + return -1; /* 1: errno */ + } + ret = mq_close(mqueue[k]); + if (ret < 0) { + return -2; /* 2: errno */ + } + ret = mq_unlink(mqname); + if (ret < 0) { + return -3; /* 3: errno */ + } + (void)memset_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, 0, MQUEUE_STANDARD_NAME_LENGTH); + } + return ret ; +} + +void ItProcessPlimitsIpc013(void) +{ + INT32 ret; + mode_t mode; + CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + mqd_t mqueue[g_buff]; + std::string subPlimitsPath = "/proc/plimits/test"; + std::string configFileMqCount = "/proc/plimits/test/ipc.mq_limit"; + std::string limitMqCount = "11"; + struct mq_attr attr = { 0 }; + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = 1; + struct mq_attr attr_err = { 0 }; + attr_err.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH_MAX; + attr_err.mq_maxmsg = 1; + int index = 0; + + ret = mkdir(subPlimitsPath.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + ret = WriteFile(configFileMqCount.c_str(), limitMqCount.c_str()); + ASSERT_NE(ret, -1); + + for (index = 0; index < MQ_MAX_LIMIT_COUNT; ++index) { + ret = snprintf_s(mqname, sizeof(mqname), MQUEUE_STANDARD_NAME_LENGTH, "/mq_006_%d_%d", + index, LosCurTaskIDGet()); + ASSERT_NE(ret, -1); + mqueue[index] = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ASSERT_NE(mqueue[index], (mqd_t)-1); + (void)memset_s(mqname, sizeof(mqname), 0, sizeof(mqname)); + } + + ret = snprintf_s(mqname, sizeof(mqname), MQUEUE_STANDARD_NAME_LENGTH, "/mq_006_%d_%d", index, LosCurTaskIDGet()); + ASSERT_NE(ret, -1); + mqueue[index] = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr_err); + ASSERT_EQ(mqueue[index], (mqd_t)-1); + (void)memset_s(mqname, sizeof(mqname), 0, sizeof(mqname)); + ret = FreeResource(mqueue, index, mqname); + ASSERT_EQ(ret, 0); + + ret = rmdir(subPlimitsPath.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_memory_001.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_memory_001.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9bdfe06aa63c6454c3c679bb923390a320877cc5 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_memory_001.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2023-2023 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 "It_process_plimits.h" + +static char *testStr1 = nullptr; + +static int limitWrite(const char *filepath, const char *buf) +{ + int fd = open(filepath, O_WRONLY); + size_t ret = write(fd, buf, strlen(buf)); + close(fd); + return ret; +} + +static int CloneOne(void *arg) +{ + const unsigned int testSize = 11534336; + + testStr1 = (char *)malloc(testSize); + EXPECT_STRNE(testStr1, NULL); + + (void)memset_s(testStr1, testSize, 1, testSize); + return 0; +} + +void ItProcessPlimitsMemory001(void) +{ + mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; + int ret, pid, status; + std::string path = "/proc/plimits/test"; + std::string limitTestPath = "/proc/plimits/test/memory.limit"; + std::string usageTestPath = "/proc/plimits/test/memory.stat"; + const char *buffer = "10485760"; + char buf[512]; + int twoM = 2 * 1024 * 1024; + + char *stack = (char *)mmap(NULL, twoM, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); + EXPECT_STRNE(stack, NULL); + ret = access(path.c_str(), 0); + EXPECT_EQ(ret, -1); + ret = mkdir(path.c_str(), S_IFDIR | mode); + EXPECT_EQ(ret, 0); + ret = limitWrite(limitTestPath.c_str(), buffer); + EXPECT_NE(ret, -1); + pid = clone(CloneOne, stack, 0, NULL); + ret = waitpid(pid, &status, 0); + ASSERT_EQ(ret, pid); + ret = WIFEXITED(status); + ASSERT_EQ(ret, 0); + + (void)memset_s(buf, sizeof(buf), 0, sizeof(buf)); + ret = ReadFile(usageTestPath.c_str(), buf); + EXPECT_NE(ret, -1); + printf("%s: %s\n", usageTestPath.c_str(), buf); + + ret = rmdir(path.c_str()); + EXPECT_EQ(ret, 0); +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_memory_002.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_memory_002.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b9b2478d74c554b52ce421478dc822040aafd6b5 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_memory_002.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023-2023 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 "It_process_plimits.h" + +static char *testStr1 = nullptr; + +static int limitWrite(const char *filepath, const char *buf) +{ + int fd = open(filepath, O_WRONLY); + size_t ret = write(fd, buf, strlen(buf)); + close(fd); + return ret; +} + +static int CloneOne(void *arg) +{ + const unsigned int testSize = 1153; + + testStr1 = (char *)malloc(testSize); + EXPECT_STRNE(testStr1, NULL); + + (void)memset_s(testStr1, testSize, 1, testSize); + free(testStr1); + testStr1 = nullptr; + return 0; +} +void ItProcessPlimitsMemory002(void) +{ + mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; + int ret, pid, status; + std::string path = "/proc/plimits/test"; + std::string limitTestPath = "/proc/plimits/test/memory.limit"; + std::string usageTestPath = "/proc/plimits/test/memory.stat"; + char buf[512]; + const char *buffer = "10485760"; + int twoM = 2 * 1024 * 1024; + + char *stack = (char *)mmap(NULL, twoM, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); + EXPECT_STRNE(stack, NULL); + ret = access(path.c_str(), 0); + EXPECT_EQ(ret, -1); + ret = mkdir(path.c_str(), S_IFDIR | mode); + EXPECT_EQ(ret, 0); + ret = limitWrite(limitTestPath.c_str(), buffer); + EXPECT_NE(ret, -1); + pid = clone(CloneOne, stack, 0, NULL); + ret = waitpid(pid, &status, 0); + ASSERT_EQ(ret, pid); + ret = WIFEXITED(status); + ASSERT_NE(ret, 0); + int exitCode = WEXITSTATUS(status); + ASSERT_EQ(exitCode, 0); + + (void)memset_s(buf, sizeof(buf), 0, sizeof(buf)); + ret = ReadFile(usageTestPath.c_str(), buf); + EXPECT_NE(ret, -1); + printf("%s: %s\n", usageTestPath.c_str(), buf); + + ret = rmdir(path.c_str()); + EXPECT_EQ(ret, 0); +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_001.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_001.cpp new file mode 100644 index 0000000000000000000000000000000000000000..592aa6f23fe384e10d8e18c43b99b55e5d4a7488 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_001.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include "It_process_plimits.h" + +static int g_pidGroup[10] = {0}; +static int g_index = 0; +static int g_sleepTime = 5; + +static int PidWrite(const char *filepath, char *buf) +{ + int fd = open(filepath, O_WRONLY); + if (fd <= 0) { + return 2; /* 2: errno */ + } + size_t ret = write(fd, buf, strlen(buf)); + if (ret < 0) { + printf("filepath: %s buf: %s, errno=%d\n", filepath, buf, errno); + } + close(fd); + return ret; +} + +static int PidFork(const char *filepath, int index) +{ + pid_t fpid = fork(); + if (fpid == 0) { // children proc + sleep(g_sleepTime); + exit(0); + } else if (fpid > 0) { + g_pidGroup[index] = fpid; + return 0; + } + return -1; +} + +void ItProcessPlimitsPid001(void) +{ + mode_t mode = 0; + int status; + const char *pidMaxPath = "/proc/plimits/test/pids.max"; + const char *procsPath = "/proc/plimits/test/plimits.procs"; + std::string path = "/proc/plimits/test"; + char writeBuf[3]; + int i = 0; + int pidnum = 5; + int mainpid = getpid(); + int ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + (void)memset_s(writeBuf, sizeof(writeBuf), 0, sizeof(writeBuf)); + ret = sprintf_s(writeBuf, sizeof(writeBuf), "%d", pidnum); + ASSERT_NE(ret, -1); + ret = PidWrite(pidMaxPath, writeBuf); + ASSERT_NE(ret, -1); + + for (i = g_index; i < pidnum; i++) { + ret = PidFork(procsPath, i); + if (i != (pidnum - 1)) { + ASSERT_EQ(ret, 0); + } else { + ASSERT_EQ(ret, -1); + } + } + + for (i = 0; i < pidnum - 1; ++i) { + pid_t pid = waitpid(g_pidGroup[i], &status, 0); + ASSERT_EQ(pid, g_pidGroup[i]); + ASSERT_EQ(WEXITSTATUS(status), 0); + } + + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_002.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_002.cpp new file mode 100644 index 0000000000000000000000000000000000000000..65ac2eb0714790d894a09c4d023a5f6afa496fc9 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_002.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include "It_process_plimits.h" + +static int g_pidGroup[10] = {0}; +static int g_index = 0; +static int g_sleepTime = 5; + +static int PidWrite(const char *filepath, char *buf) +{ + int fd = open(filepath, O_WRONLY); + size_t ret = write(fd, buf, strlen(buf)); + close(fd); + return ret; +} + +static void PidFork(int index) +{ + pid_t fpid = fork(); + if (fpid == 0) { // children proc + sleep(g_sleepTime); + exit(0); + } else if (fpid > 0) { + g_pidGroup[index] = fpid; + return; + } +} + +void ItProcessPlimitsPid002(void) +{ + mode_t mode = 0; + int status; + const char *pidMaxPath = "/proc/plimits/test/pids.max"; + const char *procsPath = "/proc/plimits/test/plimits.procs"; + std::string path = "/proc/plimits/test"; + char writeBuf[3]; + int num = 4; + int i = 0; + pid_t fpid; + int pidnum = 5; + int ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + (void)memset_s(writeBuf, sizeof(writeBuf), 0, sizeof(writeBuf)); + ret = sprintf_s(writeBuf, sizeof(writeBuf), "%d", pidnum); + ASSERT_NE(ret, -1); + ret = PidWrite(pidMaxPath, writeBuf); + ASSERT_NE(ret, -1); + + (void)memset_s(writeBuf, sizeof(writeBuf), 0, sizeof(writeBuf)); + ret = sprintf_s(writeBuf, sizeof(writeBuf), "%d", getpid()); + ASSERT_NE(ret, -1); + ret = PidWrite(procsPath, writeBuf); + ASSERT_NE(ret, -1); + + for (i = g_index; i < num; ++i) { + PidFork(i); + } + g_index = i; + fpid = fork(); + if (fpid == 0) { + exit(0); + } else if (fpid > 0) { + waitpid(fpid, &status, 0); + } + + for (i = 0; i < g_index; ++i) { + waitpid(g_pidGroup[i], &status, 0); + ASSERT_EQ(WEXITSTATUS(status), 0); + } + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_003.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_003.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f29181f80c54adce4f804a27a19728544a8aaee8 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_003.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include "It_process_plimits.h" + +static int PidWrite(const char *filepath, char *buf) +{ + int fd = open(filepath, O_WRONLY); + size_t ret = write(fd, buf, strlen(buf)); + close(fd); + return ret; +} + +void ItProcessPlimitsPid003(void) +{ + mode_t mode = 0; + int status; + struct sched_param param = { 0 }; + const char *pidMaxPath = "/proc/plimits/test/pids.priority"; + std::string path = "/proc/plimits/test"; + char writeBuf[3]; + int pidnum = 15; /* 15: priority limit */ + int ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + (void)memset_s(writeBuf, sizeof(writeBuf), 0, sizeof(writeBuf)); + ret = sprintf_s(writeBuf, sizeof(writeBuf), "%d", pidnum); + ASSERT_NE(ret, -1); + + ret = PidWrite(pidMaxPath, writeBuf); + ASSERT_NE(ret, -1); + + int currProcessPri = getpriority(PRIO_PROCESS, getpid()); + + param.sched_priority = pidnum - 1; + ret = sched_setscheduler(getpid(), SCHED_RR, ¶m); + ASSERT_NE(ret, 0); + + ret = setpriority(PRIO_PROCESS, getpid(), param.sched_priority); + ASSERT_NE(ret, 0); + + ret = sched_setparam(getpid(), ¶m); + ASSERT_NE(ret, 0); + + param.sched_priority = currProcessPri + 1; + ret = sched_setscheduler(getpid(), SCHED_RR, ¶m); + ASSERT_EQ(ret, 0); + + param.sched_priority++; + ret = setpriority(PRIO_PROCESS, getpid(), param.sched_priority); + ASSERT_EQ(ret, 0); + + param.sched_priority++; + ret = sched_setparam(getpid(), ¶m); + ASSERT_EQ(ret, 0); + + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_004.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_004.cpp new file mode 100644 index 0000000000000000000000000000000000000000..246921b4aefccff4b04ba8104dbc9165bee8f7c2 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_004.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsPid004(void) +{ + mode_t mode = 0; + int ret; + const char *res = nullptr; + const size_t BUFFER_SIZE = 512; + std::string path = "/proc/plimits/test"; + DIR *dirp = opendir("/proc/plimits"); + ASSERT_NE(dirp, nullptr); + closedir(dirp); + + ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + char buff[BUFFER_SIZE] = {0}; + ret = ReadFile("/proc/plimits/pids.max", buff); + res = strstr(buff, "64"); + ASSERT_STRNE(res, nullptr); + (void)memset_s(buff, BUFFER_SIZE, 0, BUFFER_SIZE); + + ret = ReadFile("/proc/plimits/test/pids.max", buff); + res = strstr(buff, "64"); + ASSERT_STRNE(res, nullptr); + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_005.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_005.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a5a1cf5a402f35ba38ab515c9400dc8c9411e3fc --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_005.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include +#include +#include +#include +#include "It_process_plimits.h" + +static int g_processOs = 8; + +void ItProcessPlimitsPid005(void) +{ + mode_t mode = 0; + std::string path = "/proc/plimits/test"; + std::string filepath = "/proc/plimits/test/plimits.procs"; + int pid = getpid(); + int vprocessId = 90; + std::string missPid = std::to_string(vprocessId); + std::string runPid = std::to_string(pid); + + int ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + int fd = open(filepath.c_str(), O_WRONLY); + ASSERT_NE(fd, -1); + + for (int i = 1; i <= g_processOs; i++) { + std::string fWrite = std::to_string(i); + ret = write(fd, fWrite.c_str(), (fWrite.length())); + ASSERT_EQ(ret, -1); + } + + ret = write(fd, missPid.c_str(), (missPid.length())); + ASSERT_EQ(ret, -1); + + ret = write(fd, path.c_str(), (path.length())); + ASSERT_EQ(ret, -1); + + ret = write(fd, runPid.c_str(), (runPid.length())); + ASSERT_NE(ret, -1); + close(fd); + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_006.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_006.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4e612a32d89a5eb7f1c380835ac308cb40b8fa23 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_006.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023-2023 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 +#include +#include +#include "It_process_plimits.h" + +void ItProcessPlimitsPid006(void) +{ + mode_t mode = 0; + int ret; + const char *res = nullptr; + const size_t BUFFER_SIZE = 512; + std::string path = "/proc/plimits/test"; + DIR *dirp = opendir("/proc/plimits"); + ASSERT_NE(dirp, nullptr); + closedir(dirp); + + ret = mkdir(path.c_str(), S_IFDIR | mode); + ASSERT_EQ(ret, 0); + + char buff[BUFFER_SIZE] = {0}; + ret = ReadFile("/proc/plimits/pids.max", buff); + res = strstr(buff, "64"); + ASSERT_STRNE(res, nullptr); + (void)memset_s(buff, BUFFER_SIZE, 0, BUFFER_SIZE); + + ret = ReadFile("/proc/plimits/test/pids.max", buff); + res = strstr(buff, "64"); + ASSERT_STRNE(res, nullptr); + ret = rmdir(path.c_str()); + ASSERT_EQ(ret, 0); + return; +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_001.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_001.cpp new file mode 100644 index 0000000000000000000000000000000000000000..85ea5489c4c67344d485398c62ac9a81e855a2ee --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_001.cpp @@ -0,0 +1,42 @@ +/* + * 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 "It_process_plimits.h" + +using namespace std; + +VOID ItProcessPlimitsSched001(void) +{ + const int childAmount = 1; + double errorRate = TestCpupInPlimit(childAmount, "testcpup101", PERIOD_10_SEC_IN_US, + QUOTA_2_SEC_IN_US, QUOTA_PERCENT_20); + ASSERT_GE(errorRate, 0); + ASSERT_LE(errorRate, TOLERANCE_ERROR); +} + diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_002.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_002.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a46fb3cac5cf26159aeb71af8f4e6e79bcfed269 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_002.cpp @@ -0,0 +1,42 @@ +/* + * 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 "It_process_plimits.h" + +using namespace std; + +VOID ItProcessPlimitsSched002(void) +{ + const int childAmount = 1; + double errorRate = TestCpupInPlimit(childAmount, "testcpup102", PERIOD_10_SEC_IN_US, + QUOTA_6_SEC_IN_US, QUOTA_PERCENT_60); + ASSERT_GE(errorRate, 0); + ASSERT_LE(errorRate, TOLERANCE_ERROR); +} + diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_003.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_003.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e3d87374dbaa8f5ba925d1940ac9ee13d2f1e272 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_003.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023-2023 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 "It_process_plimits.h" + +using namespace std; + +VOID ItProcessPlimitsSched003(void) +{ + const int childAmount = 1; + double errorRate = TestCpupInPlimit(childAmount, "testcpup104", PERIOD_10_SEC_IN_US, + QUOTA_10_SEC_IN_US, QUOTA_PERCENT_100); + ASSERT_GE(errorRate, 0); + ASSERT_LE(errorRate, TOLERANCE_ERROR); +} diff --git a/testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_004.cpp b/testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_004.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7e6d0d71ca97f8ba1c2c8e3a166856bc6d9cc427 --- /dev/null +++ b/testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_004.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023-2023 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 "It_process_plimits.h" + +using namespace std; + +VOID ItProcessPlimitsSched004(void) +{ + const int childAmount = 2; + double errorRate = TestCpupInPlimit(childAmount, "testcpup105", PERIOD_10_SEC_IN_US, + QUOTA_10_SEC_IN_US, QUOTA_PERCENT_100); + ASSERT_GE(errorRate, 0); + ASSERT_LE(errorRate, TOLERANCE_ERROR); +}