commit
36d55955ef
|
@ -49,6 +49,7 @@ typedef struct {
|
||||||
int sem_init(sem_t *sem, int shared, unsigned value);
|
int sem_init(sem_t *sem, int shared, unsigned value);
|
||||||
int sem_destroy(sem_t *sem);
|
int sem_destroy(sem_t *sem);
|
||||||
int sem_wait(sem_t *sem);
|
int sem_wait(sem_t *sem);
|
||||||
|
int sem_trywait(sem_t *sem);
|
||||||
int sem_post(sem_t *sem);
|
int sem_post(sem_t *sem);
|
||||||
int sem_timedwait(sem_t *__restrict sem, const struct timespec *__restrict timeout);
|
int sem_timedwait(sem_t *__restrict sem, const struct timespec *__restrict timeout);
|
||||||
int sem_getvalue(sem_t *__restrict sem, int *__restrict currVal);
|
int sem_getvalue(sem_t *__restrict sem, int *__restrict currVal);
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
#define _POSIX_THREAD_PRIORITY_SCHEDULING
|
#define _POSIX_THREAD_PRIORITY_SCHEDULING
|
||||||
#define _UNIX98_THREAD_MUTEX_ATTRIBUTES
|
#define _UNIX98_THREAD_MUTEX_ATTRIBUTES
|
||||||
#define _POSIX_THREAD_PROCESS_SHARED
|
#define _POSIX_THREAD_PROCESS_SHARED
|
||||||
|
#define _POSIX_PRIORITY_SCHEDULING
|
||||||
|
|
||||||
#include_next <sys/features.h>
|
#include_next <sys/features.h>
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,6 @@
|
||||||
#define PTHREAD_EXISTED_SEM_NUM SEM_EXISTED_NUM
|
#define PTHREAD_EXISTED_SEM_NUM SEM_EXISTED_NUM
|
||||||
|
|
||||||
/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
|
/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
|
||||||
#define _POSIX_C_SOURCE 200112L
|
|
||||||
|
|
||||||
#define PRIORITY_OTHER (-1)
|
#define PRIORITY_OTHER (-1)
|
||||||
#define PRIORITY_FIFO 20
|
#define PRIORITY_FIFO 20
|
||||||
|
|
|
@ -76,7 +76,7 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower001, Function | MediumTest
|
||||||
if (ret == 'a') {
|
if (ret == 'a') {
|
||||||
LOG("[DEMO] posix ctype test case 1:tolower(%c)==%c ok.\n", a, ret);
|
LOG("[DEMO] posix ctype test case 1:tolower(%c)==%c ok.\n", a, ret);
|
||||||
} else {
|
} else {
|
||||||
LOG("[DEMO] posix ctype test case 1:tolower(%c)!=%c fail.\n", a);
|
LOG("[DEMO] posix ctype test case 1:tolower(%c)!=%c fail.\n", a, ret);
|
||||||
}
|
}
|
||||||
TEST_ASSERT_TRUE(ret == 'a');
|
TEST_ASSERT_TRUE(ret == 'a');
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -94,7 +94,7 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower002, Function | MediumTest
|
||||||
if (ret == 'a') {
|
if (ret == 'a') {
|
||||||
LOG("[DEMO] posix ctype test case 2:tolower(%c)==%c ok.\n", a, ret);
|
LOG("[DEMO] posix ctype test case 2:tolower(%c)==%c ok.\n", a, ret);
|
||||||
} else {
|
} else {
|
||||||
LOG("[DEMO] posix ctype test case 2:tolower(%c)!=%c fail.\n", a);
|
LOG("[DEMO] posix ctype test case 2:tolower(%c)!=%c fail.\n", a, ret);
|
||||||
}
|
}
|
||||||
TEST_ASSERT_TRUE(ret == 'a');
|
TEST_ASSERT_TRUE(ret == 'a');
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -112,7 +112,7 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower003, Function | MediumTest
|
||||||
if (ret == 'z') {
|
if (ret == 'z') {
|
||||||
LOG("[DEMO] posix ctype test case 3:tolower(%c)==%c ok.\n", a, ret);
|
LOG("[DEMO] posix ctype test case 3:tolower(%c)==%c ok.\n", a, ret);
|
||||||
} else {
|
} else {
|
||||||
LOG("[DEMO] posix ctype test case 3:tolower(%c)!=%c fail.\n", a);
|
LOG("[DEMO] posix ctype test case 3:tolower(%c)!=%c fail.\n", a, ret);
|
||||||
}
|
}
|
||||||
TEST_ASSERT_TRUE(ret == 'z');
|
TEST_ASSERT_TRUE(ret == 'z');
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -130,7 +130,7 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower004, Function | MediumTest
|
||||||
if (ret == 'z') {
|
if (ret == 'z') {
|
||||||
LOG("[DEMO] posix ctype test case 4:tolower(%c)==%c ok.\n", a, ret);
|
LOG("[DEMO] posix ctype test case 4:tolower(%c)==%c ok.\n", a, ret);
|
||||||
} else {
|
} else {
|
||||||
LOG("[DEMO] posix ctype test case 4:tolower(%c)!=%c fail.\n", a);
|
LOG("[DEMO] posix ctype test case 4:tolower(%c)!=%c fail.\n", a, ret);
|
||||||
}
|
}
|
||||||
TEST_ASSERT_TRUE(ret == 'z');
|
TEST_ASSERT_TRUE(ret == 'z');
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -148,7 +148,7 @@ LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower005, Function | MediumTest
|
||||||
if (ret == '1') {
|
if (ret == '1') {
|
||||||
LOG("[DEMO] posix ctype test case 5(except):tolower(%c)==%c ok.\n", a, ret);
|
LOG("[DEMO] posix ctype test case 5(except):tolower(%c)==%c ok.\n", a, ret);
|
||||||
} else {
|
} else {
|
||||||
LOG("[DEMO] posix ctype test case 5(except):tolower(%c)!=%c fail.\n", a);
|
LOG("[DEMO] posix ctype test case 5(except):tolower(%c)!=%c fail.\n", a, ret);
|
||||||
}
|
}
|
||||||
TEST_ASSERT_TRUE(ret == '1');
|
TEST_ASSERT_TRUE(ret == '1');
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -76,7 +76,7 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper001, Function | MediumTest
|
||||||
if (ret == 'A') {
|
if (ret == 'A') {
|
||||||
LOG("[DEMO] posix ctype test case 1:toupper(%c)==%c ok.\n", a, ret);
|
LOG("[DEMO] posix ctype test case 1:toupper(%c)==%c ok.\n", a, ret);
|
||||||
} else {
|
} else {
|
||||||
LOG("[DEMO] posix ctype test case 1:toupper(%c)!=%c fail.\n", a);
|
LOG("[DEMO] posix ctype test case 1:toupper(%c)!=%c fail.\n", a, ret);
|
||||||
}
|
}
|
||||||
TEST_ASSERT_TRUE(ret == 'A');
|
TEST_ASSERT_TRUE(ret == 'A');
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -94,7 +94,7 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper002, Function | MediumTest
|
||||||
if (ret == 'A') {
|
if (ret == 'A') {
|
||||||
LOG("[DEMO] posix ctype test case 2:toupper(%c)==%c ok.\n", a, ret);
|
LOG("[DEMO] posix ctype test case 2:toupper(%c)==%c ok.\n", a, ret);
|
||||||
} else {
|
} else {
|
||||||
LOG("[DEMO] posix ctype test case 2:toupper(%c)!=%c fail.\n", a);
|
LOG("[DEMO] posix ctype test case 2:toupper(%c)!=%c fail.\n", a, ret);
|
||||||
}
|
}
|
||||||
TEST_ASSERT_TRUE(ret == 'A');
|
TEST_ASSERT_TRUE(ret == 'A');
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -112,7 +112,7 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper003, Function | MediumTest
|
||||||
if (ret == 'Z') {
|
if (ret == 'Z') {
|
||||||
LOG("[DEMO] posix ctype test case 3:toupper(%c)==%c ok.\n", a, ret);
|
LOG("[DEMO] posix ctype test case 3:toupper(%c)==%c ok.\n", a, ret);
|
||||||
} else {
|
} else {
|
||||||
LOG("[DEMO] posix ctype test case 3:toupper(%c)!=%c fail.\n", a);
|
LOG("[DEMO] posix ctype test case 3:toupper(%c)!=%c fail.\n", a, ret);
|
||||||
}
|
}
|
||||||
TEST_ASSERT_TRUE(ret == 'Z');
|
TEST_ASSERT_TRUE(ret == 'Z');
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -130,7 +130,7 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper004, Function | MediumTest
|
||||||
if (ret == 'Z') {
|
if (ret == 'Z') {
|
||||||
LOG("[DEMO] posix ctype test case 4:toupper(%c)==%c ok.\n", a, ret);
|
LOG("[DEMO] posix ctype test case 4:toupper(%c)==%c ok.\n", a, ret);
|
||||||
} else {
|
} else {
|
||||||
LOG("[DEMO] posix ctype test case 4:toupper(%c)!=%c fail.\n", a);
|
LOG("[DEMO] posix ctype test case 4:toupper(%c)!=%c fail.\n", a, ret);
|
||||||
}
|
}
|
||||||
TEST_ASSERT_TRUE(ret == 'Z');
|
TEST_ASSERT_TRUE(ret == 'Z');
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -148,7 +148,7 @@ LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper005, Function | MediumTest
|
||||||
if (ret == '1') {
|
if (ret == '1') {
|
||||||
LOG("[DEMO] posix ctype test case 5(except):toupper(%c)==%c ok.\n", a, ret);
|
LOG("[DEMO] posix ctype test case 5(except):toupper(%c)==%c ok.\n", a, ret);
|
||||||
} else {
|
} else {
|
||||||
LOG("[DEMO] posix ctype test case 5(except):toupper(%c)!=%c fail.\n", a);
|
LOG("[DEMO] posix ctype test case 5(except):toupper(%c)!=%c fail.\n", a, ret);
|
||||||
}
|
}
|
||||||
TEST_ASSERT_TRUE(ret == '1');
|
TEST_ASSERT_TRUE(ret == '1');
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -71,7 +71,7 @@ static BOOL PosixSemaphoreFuncTestSuiteTearDown(void)
|
||||||
// get cur-time plus ms
|
// get cur-time plus ms
|
||||||
struct timespec GetDelayedTime(unsigned int ms)
|
struct timespec GetDelayedTime(unsigned int ms)
|
||||||
{
|
{
|
||||||
LOG("GetDelayedTime ms = %lu", ms);
|
LOG("GetDelayedTime ms = %u", ms);
|
||||||
struct timespec ts = { 0 };
|
struct timespec ts = { 0 };
|
||||||
const unsigned int nsecPerSec = 1000000000;
|
const unsigned int nsecPerSec = 1000000000;
|
||||||
const unsigned int nsecPerMs = 1000000;
|
const unsigned int nsecPerMs = 1000000;
|
||||||
|
@ -91,7 +91,7 @@ int GetTimeDiff(struct timespec ts1, struct timespec ts2)
|
||||||
const int nsecPerMs = 1000000;
|
const int nsecPerMs = 1000000;
|
||||||
int ms = (ts1.tv_sec - ts2.tv_sec) * nsecPerSec + (ts1.tv_nsec - ts2.tv_nsec);
|
int ms = (ts1.tv_sec - ts2.tv_sec) * nsecPerSec + (ts1.tv_nsec - ts2.tv_nsec);
|
||||||
ms = ms / nsecPerMs;
|
ms = ms / nsecPerMs;
|
||||||
LOG("different result: %ld (ms)", ms);
|
LOG("different result: %d (ms)", ms);
|
||||||
return ms;
|
return ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ LITE_TEST_CASE(PosixSemaphoreFuncTestSuite, testIpcSem_Timedwait001, Function |
|
||||||
TEST_ASSERT_EQUAL_INT(0, sem_init((sem_t *)&sem, 0, 0));
|
TEST_ASSERT_EQUAL_INT(0, sem_init((sem_t *)&sem, 0, 0));
|
||||||
|
|
||||||
ts = GetDelayedTime(100);
|
ts = GetDelayedTime(100);
|
||||||
LOG("predicted time:%lld, %d", ts.tv_sec, ts.tv_nsec);
|
LOG("predicted time:%lld, %ld", ts.tv_sec, ts.tv_nsec);
|
||||||
if (sem_timedwait((sem_t *)&sem, &ts) == -1) {
|
if (sem_timedwait((sem_t *)&sem, &ts) == -1) {
|
||||||
TEST_ASSERT_EQUAL_INT(ETIMEDOUT, errno);
|
TEST_ASSERT_EQUAL_INT(ETIMEDOUT, errno);
|
||||||
} else {
|
} else {
|
||||||
|
@ -117,7 +117,7 @@ LITE_TEST_CASE(PosixSemaphoreFuncTestSuite, testIpcSem_Timedwait001, Function |
|
||||||
}
|
}
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &tsNow);
|
clock_gettime(CLOCK_REALTIME, &tsNow);
|
||||||
LOG("tsNow %lld, %d", tsNow.tv_sec, tsNow.tv_nsec);
|
LOG("tsNow %lld, %ld", tsNow.tv_sec, tsNow.tv_nsec);
|
||||||
int timeDiff = GetTimeDiff(tsNow, ts); // calculate time different
|
int timeDiff = GetTimeDiff(tsNow, ts); // calculate time different
|
||||||
LOG("timeDiff %d", timeDiff);
|
LOG("timeDiff %d", timeDiff);
|
||||||
TEST_ASSERT_LESS_THAN_INT(20, abs(timeDiff));
|
TEST_ASSERT_LESS_THAN_INT(20, abs(timeDiff));
|
||||||
|
@ -141,26 +141,26 @@ LITE_TEST_CASE(PosixSemaphoreFuncTestSuite, testIpcSem_Timedwait002, Function |
|
||||||
TEST_ASSERT_EQUAL_INT(0, sem_init((sem_t *)&sem, 0, 1));
|
TEST_ASSERT_EQUAL_INT(0, sem_init((sem_t *)&sem, 0, 1));
|
||||||
|
|
||||||
ts = GetDelayedTime(100);
|
ts = GetDelayedTime(100);
|
||||||
LOG("\n ts %lld, %d", ts.tv_sec, ts.tv_nsec);
|
LOG("\n ts %lld, %ld", ts.tv_sec, ts.tv_nsec);
|
||||||
clock_gettime(CLOCK_REALTIME, &tsBegin);
|
clock_gettime(CLOCK_REALTIME, &tsBegin);
|
||||||
int ret = sem_timedwait((sem_t *)&sem, &ts);
|
int ret = sem_timedwait((sem_t *)&sem, &ts);
|
||||||
clock_gettime(CLOCK_REALTIME, &tsNow);
|
clock_gettime(CLOCK_REALTIME, &tsNow);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT(0, ret);
|
TEST_ASSERT_EQUAL_INT(0, ret);
|
||||||
|
|
||||||
LOG("\n tsBegin %ld, %ld, tsNow %ld, %ld", tsBegin.tv_sec, tsBegin.tv_nsec, tsNow.tv_sec, tsNow.tv_nsec);
|
LOG("\n tsBegin %lld, %ld, tsNow %lld, %ld", tsBegin.tv_sec, tsBegin.tv_nsec, tsNow.tv_sec, tsNow.tv_nsec);
|
||||||
int timeDiff = GetTimeDiff(tsNow, tsBegin); // calculate time different
|
int timeDiff = GetTimeDiff(tsNow, tsBegin); // calculate time different
|
||||||
LOG("\n timeDiff %d", timeDiff);
|
LOG("\n timeDiff %d", timeDiff);
|
||||||
TEST_ASSERT_LESS_THAN_INT(20, timeDiff);
|
TEST_ASSERT_LESS_THAN_INT(20, timeDiff);
|
||||||
|
|
||||||
// try get semaphore again
|
// try get semaphore again
|
||||||
ts = GetDelayedTime(100);
|
ts = GetDelayedTime(100);
|
||||||
LOG("\n ts %d, %d", ts.tv_sec, ts.tv_nsec);
|
LOG("\n ts %lld, %ld", ts.tv_sec, ts.tv_nsec);
|
||||||
ret = sem_timedwait((sem_t *)&sem, &ts);
|
ret = sem_timedwait((sem_t *)&sem, &ts);
|
||||||
clock_gettime(CLOCK_REALTIME, &tsNow);
|
clock_gettime(CLOCK_REALTIME, &tsNow);
|
||||||
TEST_ASSERT_EQUAL_INT(-1, ret);
|
TEST_ASSERT_EQUAL_INT(-1, ret);
|
||||||
TEST_ASSERT_EQUAL_INT(ETIMEDOUT, errno);
|
TEST_ASSERT_EQUAL_INT(ETIMEDOUT, errno);
|
||||||
LOG("\n tsNow %ld, %ld", tsNow.tv_sec, tsNow.tv_nsec);
|
LOG("\n tsNow %lld, %ld", tsNow.tv_sec, tsNow.tv_nsec);
|
||||||
timeDiff = GetTimeDiff(tsNow, tsBegin); // calculate time different
|
timeDiff = GetTimeDiff(tsNow, tsBegin); // calculate time different
|
||||||
LOG("\n wait timeDiff %d", timeDiff);
|
LOG("\n wait timeDiff %d", timeDiff);
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ static int KeepRun(int msec)
|
||||||
struct timespec time1 = { 0, 0 };
|
struct timespec time1 = { 0, 0 };
|
||||||
struct timespec time2 = { 0, 0 };
|
struct timespec time2 = { 0, 0 };
|
||||||
clock_gettime(CLOCK_MONOTONIC, &time1);
|
clock_gettime(CLOCK_MONOTONIC, &time1);
|
||||||
LOG("KeepRun start : tv_sec=%ld, tv_nsec=%ld\n", time1.tv_sec, time1.tv_nsec);
|
LOG("KeepRun start : tv_sec=%lld, tv_nsec=%ld\n", time1.tv_sec, time1.tv_nsec);
|
||||||
int loop = 0;
|
int loop = 0;
|
||||||
int ran = 0;
|
int ran = 0;
|
||||||
while (ran < msec) {
|
while (ran < msec) {
|
||||||
|
@ -111,7 +111,7 @@ static int KeepRun(int msec)
|
||||||
ran += (time2.tv_nsec - time1.tv_nsec) / NANOSECONDS_PER_MILLISECOND;
|
ran += (time2.tv_nsec - time1.tv_nsec) / NANOSECONDS_PER_MILLISECOND;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG("KeepRun end : tv_sec=%ld, tv_nsec=%ld\n", time2.tv_sec, time2.tv_nsec);
|
LOG("KeepRun end : tv_sec=%lld, tv_nsec=%ld\n", time2.tv_sec, time2.tv_nsec);
|
||||||
return loop;
|
return loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue