feat: support EDF
方案描述: 1、liteos_a调度框架支持EDF调度算法,默认优先调度EDF策略的任务 2、用户态musl_c库适配新增调度算法,同步修改相关接口以支持用户态创建EDF进程与线程 BREAKING CHANGE: support EDF对外变更描述: 以下接口支持SCHED_DEADLINE调度策略: pthread_attr_getschedparam pthread_attr_setschedparam pthread_getschedparam pthread_setschedparam pthread_create sched_getscheduler sched_getparam sched_setparam sched_setscheduler Close:#I6T3P3 Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com> Change-Id: Ic9fe6896fcae42ae4ee7fe5dfb8e858a6ed19740
This commit is contained in:
@@ -55,6 +55,14 @@ pthread_sources_smoke = [
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_017.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_018.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_019.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_020.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_021.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_022.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_023.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_024.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_025.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_026.cpp",
|
||||
"$TEST_UNITTEST_DIR/process/basic/pthread/smoke/pthread_test_027.cpp",
|
||||
]
|
||||
|
||||
pthread_sources_full = [
|
||||
|
||||
@@ -74,6 +74,14 @@ extern void ItTestPthread016(void);
|
||||
extern void ItTestPthread017(void);
|
||||
extern void ItTestPthread018(void);
|
||||
extern void ItTestPthread019(void);
|
||||
extern void ItTestPthread020(void);
|
||||
extern void ItTestPthread021(void);
|
||||
extern void ItTestPthread022(void);
|
||||
extern void ItTestPthread023(void);
|
||||
extern void ItTestPthread024(void);
|
||||
extern void ItTestPthread025(void);
|
||||
extern void ItTestPthread026(void);
|
||||
extern void ItTestPthread027(void);
|
||||
extern void ItTestPthreadAtfork001(void);
|
||||
extern void ItTestPthreadAtfork002(void);
|
||||
extern void ItTestPthreadOnce001(void);
|
||||
|
||||
@@ -186,6 +186,104 @@ HWTEST_F(ProcessPthreadTest, ItTestPthread019, TestSize.Level0)
|
||||
ItTestPthread019();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_020
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6T3P3
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread020, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread020();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_021
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6T3P3
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread021, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread021();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_022
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6T3P3
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread022, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread022();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_024
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6T3P3
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread024, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread024();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_026
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6T3P3
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread026, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread026();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_027
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6T3P3
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread027, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread027();
|
||||
}
|
||||
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_023
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6T3P3
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread023, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread023();
|
||||
}
|
||||
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_025
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6T3P3
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessPthreadTest, ItTestPthread025, TestSize.Level0)
|
||||
{
|
||||
ItTestPthread025();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: it_test_pthread_017
|
||||
* @tc.desc: function for ProcessPthreadTest
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static int ChildProcess(void)
|
||||
{
|
||||
int ret, currPolicy = 0;
|
||||
volatile unsigned int count = 0;
|
||||
struct sched_param currSchedParam = { 0 };
|
||||
struct sched_param param = {
|
||||
.sched_deadline = 4000000, /* 4000000, 4s */
|
||||
.sched_runtime = 200000, /* 200000, 200ms */
|
||||
.sched_period = 5000000, /* 5000000, 5s */
|
||||
};
|
||||
|
||||
ret = sched_getparam(getpid(), &currSchedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
currPolicy = sched_getscheduler(getpid());
|
||||
ICUNIT_ASSERT_EQUAL(currPolicy, SCHED_RR, LOS_NOK);
|
||||
currSchedParam.sched_runtime = 0;
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_deadline, 0, LOS_NOK);
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_runtime, 0, LOS_NOK);
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_period, 0, LOS_NOK);
|
||||
|
||||
ret = sched_setscheduler(getpid(), SCHED_DEADLINE, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
currPolicy = sched_getscheduler(getpid());
|
||||
ICUNIT_ASSERT_EQUAL(currPolicy, SCHED_DEADLINE, LOS_NOK);
|
||||
|
||||
ret = sched_getparam(getpid(), &currSchedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_deadline, 4000000, LOS_NOK); /* 4000000, 4s */
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_runtime, 200000, LOS_NOK); /* 200000, 200ms */
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_period, 5000000, LOS_NOK); /* 5000000, 5s */
|
||||
|
||||
printf("--- 1 edf thread start ---\n\r");
|
||||
do {
|
||||
for (volatile int i = 0; i < 100000; i++) { /* 100000, no special meaning */
|
||||
for (volatile int j = 0; j < 10; j++) { /* 10, no special meaning */
|
||||
int tmp = i - j;
|
||||
}
|
||||
}
|
||||
if (count % 20 == 0) { /* 20, no special meaning */
|
||||
printf("--- 2 edf thread running ---\n\r");
|
||||
}
|
||||
count++;
|
||||
} while (count <= 100); /* 100, no special meaning */
|
||||
printf("--- 3 edf thread end ---\n\r");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret, pid, status;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ret = ChildProcess();
|
||||
if (ret != 0) {
|
||||
exit(-1);
|
||||
}
|
||||
exit(0);
|
||||
} else if (pid > 0) {
|
||||
waitpid(pid, &status, 0);
|
||||
} else {
|
||||
exit(__LINE__);
|
||||
}
|
||||
|
||||
return WEXITSTATUS(status) == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
void ItTestPthread020(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_020", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static void *ThreadFuncTest(void *args)
|
||||
{
|
||||
int pt = (int)args;
|
||||
int ret, currPolicy;
|
||||
struct sched_param currSchedParam;
|
||||
volatile unsigned int count = 0;
|
||||
int currTID = Syscall(SYS_gettid, 0, 0, 0, 0);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), & currPolicy, &currSchedParam);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, LOS_NOK, EXIT);
|
||||
ICUNIT_GOTO_EQUAL( currPolicy, SCHED_DEADLINE, LOS_NOK, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(currSchedParam.sched_deadline, 3000000, LOS_NOK, EXIT); /* 3000000, 3s */
|
||||
ICUNIT_GOTO_EQUAL(currSchedParam.sched_runtime, 200000, LOS_NOK, EXIT); /* 200000, 200ms */
|
||||
ICUNIT_GOTO_EQUAL(currSchedParam.sched_period, 5000000, LOS_NOK, EXIT); /* 5000000, 5s */
|
||||
|
||||
printf("--- 1 edf Tid[%d] PTid[%d] thread start ---\n\r", currTID, pt);
|
||||
do {
|
||||
for (volatile int i = 0; i < 100000; i++) { /* 100000, no special meaning */
|
||||
for (volatile int j = 0; j < 5; j++) { /* 5, no special meaning */
|
||||
volatile int tmp = i - j;
|
||||
}
|
||||
}
|
||||
if (count % 20 == 0) { /* 20, no special meaning */
|
||||
printf("--- 2 edf Tid[%d] PTid[%d] thread running ---\n\r", currTID, pt);
|
||||
}
|
||||
count++;
|
||||
} while (count <= 100); /* 100, no special meaning */
|
||||
printf("--- 3 edf Tid[%d] PTid[%d] thread end ---\n\r", currTID, pt);
|
||||
|
||||
ret = LOS_OK;
|
||||
return (void *)(&ret);
|
||||
EXIT:
|
||||
ret = LOS_NOK;
|
||||
return (void *)(&ret);
|
||||
}
|
||||
|
||||
static int ChildProcess(void)
|
||||
{
|
||||
int *childThreadRetval = nullptr;
|
||||
pthread_t newUserThread;
|
||||
int ret, currPolicy = 0;
|
||||
volatile unsigned int count = 0;
|
||||
struct sched_param currSchedParam = { 0 };
|
||||
int currTID = Syscall(SYS_gettid, 0, 0, 0, 0);
|
||||
struct sched_param param = {
|
||||
.sched_deadline = 3000000, /* 3000000, 3s */
|
||||
.sched_runtime = 200000, /* 200000, 200ms */
|
||||
.sched_period = 5000000, /* 5000000, 5s */
|
||||
};
|
||||
|
||||
ret = sched_setscheduler(getpid(), SCHED_DEADLINE, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), & currPolicy, &currSchedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(currPolicy, SCHED_DEADLINE, LOS_NOK);
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_deadline, 3000000, LOS_NOK); /* 3000000, 3s */
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_runtime, 200000, LOS_NOK); /* 200000, 200ms */
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_period, 5000000, LOS_NOK); /* 5000000, 5s */
|
||||
|
||||
ret = pthread_create(&newUserThread, NULL, ThreadFuncTest, (void *)currTID);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
printf("--- 1 edf Tid[%d] thread start ---\n\r", currTID);
|
||||
do {
|
||||
for (volatile int i = 0; i < 100000; i++) { /* 100000, no special meaning */
|
||||
for (volatile int j = 0; j < 5; j++) { /* 5, no special meaning */
|
||||
int tmp = i - j;
|
||||
}
|
||||
}
|
||||
if (count % 20 == 0) { /* 20, no special meaning */
|
||||
printf("--- 2 edf Tid[%d] thread running ---\n\r", currTID);
|
||||
}
|
||||
count++;
|
||||
} while (count <= 100); /* 100, no special meaning */
|
||||
printf("--- 3 edf Tid[%d] thread end ---\n\r", currTID);
|
||||
|
||||
ret = pthread_join(newUserThread, (void **)&childThreadRetval);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(*childThreadRetval, 0, *childThreadRetval);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret, pid, status;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ret = ChildProcess();
|
||||
if (ret != 0) {
|
||||
exit(-1);
|
||||
}
|
||||
exit(0);
|
||||
} else if (pid > 0) {
|
||||
waitpid(pid, &status, 0);
|
||||
} else {
|
||||
exit(__LINE__);
|
||||
}
|
||||
|
||||
return WEXITSTATUS(status) == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
void ItTestPthread021(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_021", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static int EdfProcess(void)
|
||||
{
|
||||
int ret;
|
||||
int currPolicy = 0;
|
||||
struct sched_param currSchedParam = { 0 };
|
||||
volatile unsigned int count = 0;
|
||||
int currTID = Syscall(SYS_gettid, 0, 0, 0, 0);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &currPolicy, &currSchedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(currPolicy, SCHED_DEADLINE, LOS_NOK);
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_deadline, 3000000, LOS_NOK); /* 3000000, 3s */
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_runtime, 200000, LOS_NOK); /* 200000, 200ms */
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_period, 5000000, LOS_NOK); /* 5000000, 5s */
|
||||
|
||||
printf("--- edf2 -- 1 -- Tid[%d] thread start ---\n\r", currTID);
|
||||
do {
|
||||
for (volatile int i = 0; i < 100000; i++) { /* 100000, no special meaning */
|
||||
for (volatile int j = 0; j < 5; j++) { /* 5, no special meaning */
|
||||
int tmp = i - j;
|
||||
}
|
||||
}
|
||||
if (count % 20 == 0) { /* 20, no special meaning */
|
||||
printf("--- edf2 -- 2 -- Tid[%d] thread running ---\n\r", currTID);
|
||||
}
|
||||
count++;
|
||||
} while (count <= 100); /* 100, no special meaning */
|
||||
printf("--- edf2 -- 3 -- Tid[%d] thread end ---\n\r", currTID);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ChildProcess(void)
|
||||
{
|
||||
int *childThreadRetval = nullptr;
|
||||
pthread_t newUserThread;
|
||||
int pid, status, ret;
|
||||
int currPolicy = 0;
|
||||
volatile unsigned int count = 0;
|
||||
struct sched_param currSchedParam = { 0 };
|
||||
int currTID = Syscall(SYS_gettid, 0, 0, 0, 0);
|
||||
struct sched_param param = {
|
||||
.sched_deadline = 3000000, /* 3000000, 3s */
|
||||
.sched_runtime = 200000, /* 200000, 200ms */
|
||||
.sched_period = 5000000, /* 5000000, 5s */
|
||||
};
|
||||
|
||||
ret = sched_setscheduler(getpid(), SCHED_DEADLINE, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &currPolicy, &currSchedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(currPolicy, SCHED_DEADLINE, LOS_NOK);
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_deadline, 3000000, LOS_NOK); /* 3000000, 3s */
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_runtime, 200000, LOS_NOK); /* 200000, 200ms */
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_period, 5000000, LOS_NOK); /* 5000000, 5s */
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ret = EdfProcess();
|
||||
if (ret != 0) {
|
||||
exit(-1);
|
||||
}
|
||||
exit(0);
|
||||
} else if (pid > 0) {
|
||||
printf("--- edf1 -- 1 -- Tid[%d] thread start ---\n\r", currTID);
|
||||
do {
|
||||
for (volatile int i = 0; i < 500000; i++) { /* 500000, no special meaning */
|
||||
int tmp = i + 1;
|
||||
}
|
||||
if (count % 20 == 0) { /* 20, no special meaning */
|
||||
printf("--- edf1 -- 2 -- Tid[%d] thread running ---\n\r", currTID);
|
||||
}
|
||||
count++;
|
||||
} while (count <= 100); /* 100, no special meaning */
|
||||
printf("--- edf1 -- 3 -- Tid[%d] thread end ---\n\r", currTID);
|
||||
waitpid(pid, &status, 0);
|
||||
} else {
|
||||
exit(__LINE__);
|
||||
}
|
||||
|
||||
return WEXITSTATUS(status) == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret, pid, status;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ret = ChildProcess();
|
||||
if (ret != 0) {
|
||||
exit(-1);
|
||||
}
|
||||
exit(0);
|
||||
} else if (pid > 0) {
|
||||
waitpid(pid, &status, 0);
|
||||
} else {
|
||||
exit(__LINE__);
|
||||
}
|
||||
|
||||
return WEXITSTATUS(status) == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
void ItTestPthread022(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_022", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static void *ThreadFuncTest(void *args)
|
||||
{
|
||||
return (void *)NULL;
|
||||
}
|
||||
|
||||
static int ChildProcess(void)
|
||||
{
|
||||
int ret;
|
||||
int currPolicy = 0;
|
||||
int oldPolicy;
|
||||
pthread_t newUserThread;
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param hpfparam = { 0 };
|
||||
volatile unsigned int count = 0;
|
||||
struct sched_param currSchedParam = { 0 };
|
||||
int currTID = Syscall(SYS_gettid, 0, 0, 0, 0);
|
||||
struct sched_param param = {
|
||||
.sched_deadline = 3000000, /* 3000000, 3s */
|
||||
.sched_runtime = 200000, /* 200000, 200ms */
|
||||
.sched_period = 5000000, /* 5000000, 5s */
|
||||
};
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &oldPolicy, &hpfparam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
|
||||
ret = sched_setscheduler(getpid(), SCHED_DEADLINE, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &currPolicy, &currSchedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(currPolicy, SCHED_DEADLINE, LOS_NOK);
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_deadline, 3000000, LOS_NOK); /* 3000000, 3s */
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_runtime, 200000, LOS_NOK); /* 200000, 200ms */
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_period, 5000000, LOS_NOK); /* 5000000, 5s */
|
||||
|
||||
ret = pthread_attr_init(&a);
|
||||
pthread_attr_setschedpolicy(&a, SCHED_RR);
|
||||
pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED);
|
||||
ret = pthread_create(&newUserThread, &a, ThreadFuncTest, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
printf("--- edf2 -- 1 -- Tid[%d] thread end ---\n\r", currTID);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret, pid, status;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ret = ChildProcess();
|
||||
if (ret != 0) {
|
||||
exit(-1);
|
||||
}
|
||||
exit(0);
|
||||
} else if (pid > 0) {
|
||||
waitpid(pid, &status, 0);
|
||||
} else {
|
||||
exit(__LINE__);
|
||||
}
|
||||
|
||||
return WEXITSTATUS(status) == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
void ItTestPthread023(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_023", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -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_pthread_test.h"
|
||||
|
||||
static void *ThreadFuncTest(void *args)
|
||||
{
|
||||
(void)args;
|
||||
printf("hpf thread run...\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ChildProcess(void)
|
||||
{
|
||||
int ret, currThreadPolicy;
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param hpfparam = { 0 };
|
||||
pthread_t newUserThread;
|
||||
volatile unsigned int count = 0;
|
||||
int currTID = Syscall(SYS_gettid, 0, 0, 0, 0);
|
||||
struct sched_param param = {
|
||||
.sched_deadline = 3000000, /* 3000000, 3s */
|
||||
.sched_runtime = 200000, /* 200000, 200ms */
|
||||
.sched_period = 5000000, /* 5000000, 5s */
|
||||
};
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &currThreadPolicy, &hpfparam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
ret = pthread_attr_init(&a);
|
||||
hpfparam.sched_priority = hpfparam.sched_priority - 1;
|
||||
pthread_attr_setschedparam(&a, &hpfparam);
|
||||
ret = pthread_create(&newUserThread, &a, ThreadFuncTest, (void *)currTID);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sched_setscheduler(getpid(), SCHED_DEADLINE, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret, pid, status;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ret = ChildProcess();
|
||||
if (ret != 0) {
|
||||
exit(-1);
|
||||
}
|
||||
exit(0);
|
||||
} else if (pid > 0) {
|
||||
waitpid(pid, &status, 0);
|
||||
} else {
|
||||
exit(__LINE__);
|
||||
}
|
||||
|
||||
return WEXITSTATUS(status) == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
void ItTestPthread024(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_024", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static void *ThreadFuncTest(void *args)
|
||||
{
|
||||
(void)args;
|
||||
printf("hpf thread run...\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ChildProcess(void)
|
||||
{
|
||||
int currThreadPolicy;
|
||||
pthread_attr_t a = { 0 };
|
||||
struct sched_param hpfparam = { 0 };
|
||||
int *childThreadRetval = nullptr;
|
||||
pthread_t newUserThread;
|
||||
int ret;
|
||||
int currPolicy = 0;
|
||||
volatile unsigned int count = 0;
|
||||
struct sched_param currSchedParam = { 0 };
|
||||
int currTID = Syscall(SYS_gettid, 0, 0, 0, 0);
|
||||
struct sched_param param = {
|
||||
.sched_deadline = 3000000, /* 3000000, 3s */
|
||||
.sched_runtime = 200000, /* 200000, 200ms */
|
||||
.sched_period = 5000000, /* 5000000, 5s */
|
||||
};
|
||||
|
||||
ret = pthread_getschedparam(pthread_self(), &currThreadPolicy, &hpfparam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, -ret);
|
||||
ret = pthread_attr_init(&a);
|
||||
hpfparam.sched_priority = hpfparam.sched_priority - 1;
|
||||
pthread_attr_setschedparam(&a, &hpfparam);
|
||||
ret = pthread_create(&newUserThread, &a, ThreadFuncTest, (void *)currTID);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(newUserThread, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sched_setscheduler(getpid(), SCHED_DEADLINE, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret, pid, status;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ret = ChildProcess();
|
||||
if (ret != 0) {
|
||||
exit(-1);
|
||||
}
|
||||
exit(0);
|
||||
} else if (pid > 0) {
|
||||
waitpid(pid, &status, 0);
|
||||
} else {
|
||||
exit(__LINE__);
|
||||
}
|
||||
|
||||
return WEXITSTATUS(status) == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
void ItTestPthread025(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_025", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static int ChildProcess(void)
|
||||
{
|
||||
int ret;
|
||||
int currPolicy = 0;
|
||||
volatile unsigned int count = 0;
|
||||
struct sched_param currSchedParam = { 0 };
|
||||
struct sched_param param = {
|
||||
.sched_deadline = 4000000, /* 4000000, 4s */
|
||||
.sched_runtime = 200000, /* 200000, 200ms */
|
||||
.sched_period = 5000000, /* 5000000, 5s */
|
||||
};
|
||||
|
||||
ret = sched_getparam(getpid(), &currSchedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
currPolicy = sched_getscheduler(getpid());
|
||||
ICUNIT_ASSERT_EQUAL(currPolicy, SCHED_RR, LOS_NOK);
|
||||
currSchedParam.sched_runtime = 0;
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_deadline, 0, LOS_NOK);
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_runtime, 0, LOS_NOK);
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_period, 0, LOS_NOK);
|
||||
|
||||
ret = sched_setscheduler(getpid(), SCHED_DEADLINE, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
currPolicy = sched_getscheduler(getpid());
|
||||
ICUNIT_ASSERT_EQUAL(currPolicy, SCHED_DEADLINE, LOS_NOK);
|
||||
|
||||
ret = sched_getparam(getpid(), &currSchedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_deadline, 4000000, LOS_NOK); /* 4000000, 4s */
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_runtime, 200000, LOS_NOK); /* 200000, 200ms */
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_period, 5000000, LOS_NOK); /* 5000000, 5s */
|
||||
|
||||
printf("--- 1 edf thread start ---\n\r");
|
||||
do {
|
||||
for (volatile int i = 0; i < 100000; i++) { /* 100000, no special meaning */
|
||||
for (volatile int j = 0; j < 10; j++) { /* 10, no special meaning */
|
||||
int tmp = i - j;
|
||||
}
|
||||
}
|
||||
if (count % 20 == 0) { /* 20, no special meaning */
|
||||
printf("--- 2 edf thread running ---\n\r");
|
||||
}
|
||||
count++;
|
||||
} while (count <= 100); /* 100, no special meaning */
|
||||
printf("--- 3 edf thread end ---\n\r");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret, pid, status;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ret = ChildProcess();
|
||||
if (ret != 0) {
|
||||
exit(-1);
|
||||
}
|
||||
exit(0);
|
||||
} else if (pid > 0) {
|
||||
waitpid(pid, &status, 0);
|
||||
} else {
|
||||
exit(__LINE__);
|
||||
}
|
||||
|
||||
return WEXITSTATUS(status) == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
void ItTestPthread026(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_026", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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_pthread_test.h"
|
||||
|
||||
static int ChildProcess(void)
|
||||
{
|
||||
int ret;
|
||||
int currPolicy = 0;
|
||||
volatile unsigned int count = 0;
|
||||
struct sched_param currSchedParam = { 0 };
|
||||
struct sched_param param = {
|
||||
.sched_deadline = 4000000, /* 4000000, 4s */
|
||||
.sched_runtime = 200000, /* 200000, 200ms */
|
||||
.sched_period = 5000000, /* 5000000, 5s */
|
||||
};
|
||||
|
||||
ret = sched_getparam(getpid(), &currSchedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
currPolicy = sched_getscheduler(getpid());
|
||||
ICUNIT_ASSERT_EQUAL(currPolicy, SCHED_RR, LOS_NOK);
|
||||
currSchedParam.sched_runtime = 0;
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_deadline, 0, LOS_NOK);
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_runtime, 0, LOS_NOK);
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_period, 0, LOS_NOK);
|
||||
|
||||
ret = sched_setscheduler(getpid(), SCHED_DEADLINE, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
currPolicy = sched_getscheduler(getpid());
|
||||
ICUNIT_ASSERT_EQUAL(currPolicy, SCHED_DEADLINE, LOS_NOK);
|
||||
|
||||
ret = sched_getparam(getpid(), &currSchedParam);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_deadline, 4000000, LOS_NOK); /* 4000000, 4s */
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_runtime, 200000, LOS_NOK); /* 200000, 200ms */
|
||||
ICUNIT_ASSERT_EQUAL(currSchedParam.sched_period, 5000000, LOS_NOK); /* 5000000, 5s */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestCase(void)
|
||||
{
|
||||
int ret, pid, status;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
ret = ChildProcess();
|
||||
if (ret != 0) {
|
||||
exit(-1);
|
||||
}
|
||||
exit(0);
|
||||
} else if (pid > 0) {
|
||||
waitpid(pid, &status, 0);
|
||||
} else {
|
||||
exit(__LINE__);
|
||||
}
|
||||
|
||||
return WEXITSTATUS(status) == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
void ItTestPthread027(void)
|
||||
{
|
||||
TEST_ADD_CASE("IT_POSIX_PTHREAD_027", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
Reference in New Issue
Block a user