提交 ad6f249d 编写于 作者: L LiteOS2021

fix(posix unittest): posix unittest 融合

posix unittest 融合
Signed-off-by: NLiteOS2021 <dinglu@huawei.com>
上级 907dfc63
......@@ -29,8 +29,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef KERNEL_TEST_H
#define KERNEL_TEST_H
#ifndef COMMON_TEST_H
#define COMMON_TEST_H
#define TESTCOUNT_NUM_1 1
#define TESTCOUNT_NUM_2 2
......@@ -83,6 +83,14 @@
} \
} while (0)
#define ICUNIT_ASSERT_NOT_EQUAL_VOID(param, value, retcode) \
do { \
if ((param) == (value)) { \
TEST_ASSERT_EQUAL(param, value); \
return; \
} \
} while (0)
#define ICUNIT_TRACK_EQUAL(param, value, retcode) \
do { \
if ((param) != (value)) { \
......
......@@ -54,7 +54,7 @@
LITE_TEST_SUIT(Posix, PosixFs, PosixFsFuncTestSuite);
/* Corresponding to different platforms, only need to modify TEST_ROOT */
#define TEST_ROOT "/ram"
#define TEST_ROOT "/littlefs"
#define TEST_FILE_PTAH_RIGHT TEST_ROOT"/FILE0" /* file path, to open/rd/close */
......@@ -1459,6 +1459,7 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat003, Function | MediumTest | Leve
ssize_t size;
char writeBuf[TEST_BUF_SIZE] = "write test";
(void)memset_s(&buf, sizeof(buf), 0, sizeof(buf));
fd = open(tmpFileName, O_CREAT | O_RDWR, 0777);
TEST_ASSERT_TRUE(ret != -1);
......
......@@ -276,8 +276,8 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow002, Function | MediumTest | L
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow003, Function | MediumTest | Level1)
{
double testValues[][TEST_EXPECTED + 1] = {
{0.0, -7, -HUGE_VAL},
{-0.0, -6.22, -HUGE_VAL},
{0.0, -7, HUGE_VAL},
{-0.0, -6.22, HUGE_VAL},
{-7.23, 3.57, NAN},
{121223, 5674343, HUGE_VAL}
};
......
......@@ -34,8 +34,10 @@
#include <mqueue.h>
#include <fcntl.h>
#include "common_test.h"
#include "kernel_test.h"
#include "log.h"
#define MQUEUE_STANDARD_NAME_LENGTH 50
#define MQUEUE_STANDARD_NAME_LENGTH 52
#define MQUEUE_NO_ERROR 0
#define MQUEUE_SEND_STRING_TEST "mq_test"
#define MQUEUE_SHORT_ARRAY_LENGTH strlen(MQUEUE_SEND_STRING_TEST)
......@@ -49,7 +51,7 @@ const int MQ_MAX_MSG = 16; // mqueue message number
const char MQ_MSG[] = "MessageToSend"; // mqueue message to send
const int MQ_MSG_LEN = sizeof(MQ_MSG); // mqueue message len to send
const int MAX_MQ_NUMBER = 1024; // max mqueue number
const int MAX_MQ_NUMBER = LOSCFG_BASE_IPC_QUEUE_LIMIT - 1; // max mqueue number
const int MAX_MQ_NAME_LEN = 256; // max mqueue name length
const int MAX_MQ_MSG_SIZE = 65530; // max mqueue message size
......@@ -289,6 +291,7 @@ LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenENFILE, Function | MediumTest | Le
mqd_t queue[MAX_MQ_NUMBER + 1];
int flag = 0;
int i;
(void)memset_s(queue, sizeof(queue), 0, sizeof(queue));
for (i=0; i<MAX_MQ_NUMBER + 1; i++) {
sprintf_s(qName[i], MQ_NAME_LEN, "testMqOpenENFILE_%d", i);
}
......@@ -301,7 +304,7 @@ LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenENFILE, Function | MediumTest | Le
printf("break: i = %d", i);
break;
}
ICUNIT_TRACK_EQUAL(queue[i], (mqd_t)-1, queue[i]);
ICUNIT_TRACK_NOT_EQUAL(queue[i], (mqd_t)-1, queue[i]);
}
printf("func: i = %d", i);
......@@ -368,7 +371,7 @@ LITE_TEST_CASE(MqueueFuncTestSuite, testMqSendEAGAIN, Function | MediumTest | Le
attr.mq_msgsize = MQ_MSG_SIZE;
attr.mq_maxmsg = 1;
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
ICUNIT_ASSERT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ICUNIT_ASSERT_NOT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, 0);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
......@@ -400,7 +403,7 @@ LITE_TEST_CASE(MqueueFuncTestSuite, testMqSendEBADFEMSGSIZE, Function | MediumTe
attr.mq_msgsize = 1;
attr.mq_maxmsg = MQ_MAX_MSG;
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
ICUNIT_ASSERT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ICUNIT_ASSERT_NOT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(NULL, MQ_MSG, 1, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
......@@ -419,7 +422,7 @@ LITE_TEST_CASE(MqueueFuncTestSuite, testMqSendEBADFEMSGSIZE, Function | MediumTe
attr.mq_msgsize = MQ_MSG_SIZE;
attr.mq_maxmsg = MQ_MAX_MSG;
queue = mq_open(qName, O_CREAT | O_RDONLY | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
ICUNIT_ASSERT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ICUNIT_ASSERT_NOT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
......@@ -456,7 +459,7 @@ LITE_TEST_CASE(MqueueFuncTestSuite, testMqSendEINVAL, Function | MediumTest | Le
attr.mq_msgsize = MQ_MSG_SIZE;
attr.mq_maxmsg = MQ_MAX_MSG;
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
ICUNIT_ASSERT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ICUNIT_ASSERT_NOT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(queue, MQ_MSG, 0, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
......@@ -487,7 +490,7 @@ LITE_TEST_CASE(MqueueFuncTestSuite, testMqReceiveEAGAIN, Function | MediumTest |
attr.mq_msgsize = MQ_MSG_SIZE;
attr.mq_maxmsg = MQ_MAX_MSG;
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
ICUNIT_ASSERT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ICUNIT_ASSERT_NOT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
......
......@@ -35,7 +35,12 @@
#include "los_config.h"
#include "cmsis_os2.h"
#include "common_test.h"
#include "kernel_test.h"
#include "pthread.h"
#include "log.h"
#define TASK_PRIO_TEST LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO
#define OS_TSK_TEST_STACK_SIZE 0x1000
static UINT32 g_testCount;
/**
......
......@@ -239,11 +239,11 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltime001, Function | MediumTe
struct tm *tmStart = localtime(&tStart);
strftime(cTime, sizeof(cTime), "%H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("23:59:59", cTime);
TEST_ASSERT_EQUAL_STRING("07:59:59", cTime);
LOG("\n time_t=%lld, first time:%s", tStart, cTime);
struct tm *tmEnd = localtime(&tEnd);
strftime(cTime, sizeof(cTime), "%H:%M:%S", tmEnd);
TEST_ASSERT_EQUAL_STRING("00:00:01", cTime);
TEST_ASSERT_EQUAL_STRING("08:00:01", cTime);
LOG("\n time_t=%lld, first time:%s", tEnd, cTime);
}
......@@ -307,13 +307,13 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltimer001, Function | MediumT
struct tm *tmrEndPtr = localtime_r(&tEnd, &tmrEnd);
strftime(cTime, sizeof(cTime), "%H:%M:%S", &tmrStart);
TEST_ASSERT_EQUAL_STRING("23:59:59", cTime);
TEST_ASSERT_EQUAL_STRING("07:59:59", cTime);
strftime(cTime, sizeof(cTime), "%H:%M:%S", tmrStartPtr);
TEST_ASSERT_EQUAL_STRING("23:59:59", cTime);
TEST_ASSERT_EQUAL_STRING("07:59:59", cTime);
strftime(cTime, sizeof(cTime), "%H:%M:%S", &tmrEnd);
TEST_ASSERT_EQUAL_STRING("00:00:01", cTime);
TEST_ASSERT_EQUAL_STRING("08:00:01", cTime);
strftime(cTime, sizeof(cTime), "%H:%M:%S", tmrEndPtr);
TEST_ASSERT_EQUAL_STRING("00:00:01", cTime);
TEST_ASSERT_EQUAL_STRING("08:00:01", cTime);
}
/* *
......@@ -366,12 +366,12 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime001, Function | MediumTest
INIT_TM(timeptr, 2020, 7, 9, 18, 10, 0, 7);
time_t timeRet = mktime(&timeptr);
LOG("\n 2020-7-9 18:10:00, mktime Ret = %lld", timeRet);
TEST_ASSERT_EQUAL_INT(1596967800, timeRet);
TEST_ASSERT_EQUAL_INT(1596996600, timeRet);
INIT_TM(timeptr, 1970, 0, 1, 8, 0, 0, 0);
timeRet = mktime(&timeptr);
LOG("\n 1970-1-1 08:00:00, mktime Ret = %lld", timeRet);
TEST_ASSERT_EQUAL_INT(0, timeRet);
TEST_ASSERT_EQUAL_INT(28800, timeRet);
struct tm *stm = localtime(&testTime);
LOG("\n testTime 18880, tm : %s", TmToStr(stm, timeStr, TIME_STR_LEN));
......@@ -406,7 +406,7 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime002, Function | MediumTest
INIT_TM(timeptr, 1969, 7, 9, 10, 10, 0, 7);
time_t timeRet = mktime(&timeptr);
LOG("\n 1800-8-9 10:10:00, mktime Ret lld = %lld", timeRet);
TEST_ASSERT_EQUAL_INT(0, timeRet);
TEST_ASSERT_EQUAL_INT(-1, timeRet);
}
......@@ -503,8 +503,9 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeStrftime003, Function | MediumTes
TEST_ASSERT_EQUAL_STRING("1970-01-01 13:14:40", buffer);
LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40");
tmTime->__tm_zone = "UTC+8";
ftime = strftime(buffer, 80, "%F %T %Z", tmTime);
TEST_ASSERT_EQUAL_INT(0, ftime);
TEST_ASSERT_EQUAL_INT(20, ftime);
LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40");
};
......@@ -546,7 +547,7 @@ RUN_TEST_SUITE(PosixTimeFuncTestSuite);
void PosixTimeFuncTest()
{
LOG("begin PosixTimeFuncTest....");
LOG("begin PosixTimeFuncTest....\n");
RUN_ONE_TESTCASE(testTimeUSleep001);
RUN_ONE_TESTCASE(testTimeUSleep002);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册