From 51c106be8b55bbd846a95394085803626640e590 Mon Sep 17 00:00:00 2001 From: modai Date: Mon, 6 Nov 2023 02:24:10 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!21=20:?= =?UTF-8?q?=20second=20submit'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task_manage_schedule/gjb_S0100301GN_1.c | 265 ----------------- task_manage_schedule/gjb_S0100301GN_2.c | 298 ------------------- task_manage_schedule/gjb_S0100301GN_3.c | 199 ------------- task_manage_schedule/gjb_S0100301GN_4.c | 133 --------- task_manage_schedule/gjb_S0100301GN_5.c | 135 --------- task_manage_schedule/gjb_S0100301GN_6.c | 118 -------- task_manage_schedule/gjb_S0100301GN_7.c | 125 -------- task_manage_schedule/gjb_S0100301GN_8.c | 185 ------------ task_manage_schedule/gjb_S0100302GN_1.c | 364 ----------------------- task_manage_schedule/gjb_S0100302GN_2.c | 351 ---------------------- task_manage_schedule/gjb_S0100302GN_3.c | 359 ----------------------- task_manage_schedule/gjb_S0100302GN_4.c | 304 ------------------- task_manage_schedule/gjb_S0100303GN.c | 205 ------------- task_manage_schedule/gjb_S0100304GN.c | 209 ------------- task_management/gjb_S0100201GN_1.c | 164 ----------- task_management/gjb_S0100201GN_2.c | 203 ------------- task_management/gjb_S0100201GN_3.c | 196 ------------- task_management/gjb_S0100201GN_4.c | 143 --------- task_management/gjb_S0100201GN_5.c | 255 ---------------- task_management/gjb_S0100201GN_6.c | 217 -------------- task_management/gjb_S0100202GN_1.c | 291 ------------------ task_management/gjb_S0100202GN_10.c | 174 ----------- task_management/gjb_S0100202GN_11.c | 169 ----------- task_management/gjb_S0100202GN_12.c | 211 ------------- task_management/gjb_S0100202GN_2.c | 189 ------------ task_management/gjb_S0100202GN_3.c | 194 ------------ task_management/gjb_S0100202GN_4.c | 139 --------- task_management/gjb_S0100202GN_5.c | 205 ------------- task_management/gjb_S0100202GN_6.c | 212 -------------- task_management/gjb_S0100202GN_7.c | 241 --------------- task_management/gjb_S0100202GN_8.c | 250 ---------------- task_management/gjb_S0100202GN_9.c | 175 ----------- task_management/gjb_S0100203GN_1.c | 296 ------------------- task_management/gjb_S0100203GN_2.c | 337 --------------------- task_management/gjb_S0100203GN_3.c | 320 -------------------- task_management/gjb_S0100203GN_4.c | 332 --------------------- task_management/gjb_S0100204GN_1.c | 260 ---------------- task_management/gjb_S0100204GN_2.c | 304 ------------------- task_management/gjb_S0100205GN_1.c | 215 -------------- task_management/gjb_S0100205GN_2.c | 302 ------------------- task_management/gjb_S0100206GN_1.c | 218 -------------- task_management/gjb_S0100206GN_10.c | 211 ------------- task_management/gjb_S0100206GN_11.c | 245 ---------------- task_management/gjb_S0100206GN_12.c | 232 --------------- task_management/gjb_S0100206GN_13.c | 209 ------------- task_management/gjb_S0100206GN_14.c | 218 -------------- task_management/gjb_S0100206GN_15.c | 320 -------------------- task_management/gjb_S0100206GN_16.c | 182 ------------ task_management/gjb_S0100206GN_17.c | 196 ------------- task_management/gjb_S0100206GN_18.c | 374 ------------------------ task_management/gjb_S0100206GN_19.c | 210 ------------- task_management/gjb_S0100206GN_2.c | 271 ----------------- task_management/gjb_S0100206GN_20.c | 212 -------------- task_management/gjb_S0100206GN_21.c | 165 ----------- task_management/gjb_S0100206GN_22.c | 161 ---------- task_management/gjb_S0100206GN_23.c | 358 ----------------------- task_management/gjb_S0100206GN_3.c | 219 -------------- task_management/gjb_S0100206GN_4.c | 215 -------------- task_management/gjb_S0100206GN_5.c | 239 --------------- task_management/gjb_S0100206GN_6.c | 208 ------------- task_management/gjb_S0100206GN_7.c | 222 -------------- task_management/gjb_S0100206GN_8.c | 221 -------------- task_management/gjb_S0100206GN_9.c | 209 ------------- task_management/gjb_S0100207GN_1.c | 138 --------- task_management/gjb_S0100207GN_10.c | 202 ------------- task_management/gjb_S0100207GN_11.c | 232 --------------- task_management/gjb_S0100207GN_12.c | 267 ----------------- task_management/gjb_S0100207GN_2.c | 184 ------------ task_management/gjb_S0100207GN_3.c | 215 -------------- task_management/gjb_S0100207GN_4.c | 217 -------------- task_management/gjb_S0100207GN_5.c | 296 ------------------- task_management/gjb_S0100207GN_6.c | 205 ------------- task_management/gjb_S0100207GN_7.c | 210 ------------- task_management/gjb_S0100207GN_8.c | 263 ----------------- task_management/gjb_S0100207GN_9.c | 145 --------- task_management/gjb_S0100209GN_1.c | 227 -------------- task_management/gjb_S0100209GN_2.c | 145 --------- task_management/gjb_S0100209GN_3.c | 232 --------------- task_management/gjb_S0100209GN_4.c | 247 ---------------- 79 files changed, 17984 deletions(-) delete mode 100644 task_manage_schedule/gjb_S0100301GN_1.c delete mode 100644 task_manage_schedule/gjb_S0100301GN_2.c delete mode 100644 task_manage_schedule/gjb_S0100301GN_3.c delete mode 100644 task_manage_schedule/gjb_S0100301GN_4.c delete mode 100644 task_manage_schedule/gjb_S0100301GN_5.c delete mode 100644 task_manage_schedule/gjb_S0100301GN_6.c delete mode 100644 task_manage_schedule/gjb_S0100301GN_7.c delete mode 100644 task_manage_schedule/gjb_S0100301GN_8.c delete mode 100644 task_manage_schedule/gjb_S0100302GN_1.c delete mode 100644 task_manage_schedule/gjb_S0100302GN_2.c delete mode 100644 task_manage_schedule/gjb_S0100302GN_3.c delete mode 100644 task_manage_schedule/gjb_S0100302GN_4.c delete mode 100644 task_manage_schedule/gjb_S0100303GN.c delete mode 100644 task_manage_schedule/gjb_S0100304GN.c delete mode 100644 task_management/gjb_S0100201GN_1.c delete mode 100644 task_management/gjb_S0100201GN_2.c delete mode 100644 task_management/gjb_S0100201GN_3.c delete mode 100644 task_management/gjb_S0100201GN_4.c delete mode 100644 task_management/gjb_S0100201GN_5.c delete mode 100644 task_management/gjb_S0100201GN_6.c delete mode 100644 task_management/gjb_S0100202GN_1.c delete mode 100644 task_management/gjb_S0100202GN_10.c delete mode 100644 task_management/gjb_S0100202GN_11.c delete mode 100644 task_management/gjb_S0100202GN_12.c delete mode 100644 task_management/gjb_S0100202GN_2.c delete mode 100644 task_management/gjb_S0100202GN_3.c delete mode 100644 task_management/gjb_S0100202GN_4.c delete mode 100644 task_management/gjb_S0100202GN_5.c delete mode 100644 task_management/gjb_S0100202GN_6.c delete mode 100644 task_management/gjb_S0100202GN_7.c delete mode 100644 task_management/gjb_S0100202GN_8.c delete mode 100644 task_management/gjb_S0100202GN_9.c delete mode 100644 task_management/gjb_S0100203GN_1.c delete mode 100644 task_management/gjb_S0100203GN_2.c delete mode 100644 task_management/gjb_S0100203GN_3.c delete mode 100644 task_management/gjb_S0100203GN_4.c delete mode 100644 task_management/gjb_S0100204GN_1.c delete mode 100644 task_management/gjb_S0100204GN_2.c delete mode 100644 task_management/gjb_S0100205GN_1.c delete mode 100644 task_management/gjb_S0100205GN_2.c delete mode 100644 task_management/gjb_S0100206GN_1.c delete mode 100644 task_management/gjb_S0100206GN_10.c delete mode 100644 task_management/gjb_S0100206GN_11.c delete mode 100644 task_management/gjb_S0100206GN_12.c delete mode 100644 task_management/gjb_S0100206GN_13.c delete mode 100644 task_management/gjb_S0100206GN_14.c delete mode 100644 task_management/gjb_S0100206GN_15.c delete mode 100644 task_management/gjb_S0100206GN_16.c delete mode 100644 task_management/gjb_S0100206GN_17.c delete mode 100644 task_management/gjb_S0100206GN_18.c delete mode 100644 task_management/gjb_S0100206GN_19.c delete mode 100644 task_management/gjb_S0100206GN_2.c delete mode 100644 task_management/gjb_S0100206GN_20.c delete mode 100644 task_management/gjb_S0100206GN_21.c delete mode 100644 task_management/gjb_S0100206GN_22.c delete mode 100644 task_management/gjb_S0100206GN_23.c delete mode 100644 task_management/gjb_S0100206GN_3.c delete mode 100644 task_management/gjb_S0100206GN_4.c delete mode 100644 task_management/gjb_S0100206GN_5.c delete mode 100644 task_management/gjb_S0100206GN_6.c delete mode 100644 task_management/gjb_S0100206GN_7.c delete mode 100644 task_management/gjb_S0100206GN_8.c delete mode 100644 task_management/gjb_S0100206GN_9.c delete mode 100644 task_management/gjb_S0100207GN_1.c delete mode 100644 task_management/gjb_S0100207GN_10.c delete mode 100644 task_management/gjb_S0100207GN_11.c delete mode 100644 task_management/gjb_S0100207GN_12.c delete mode 100644 task_management/gjb_S0100207GN_2.c delete mode 100644 task_management/gjb_S0100207GN_3.c delete mode 100644 task_management/gjb_S0100207GN_4.c delete mode 100644 task_management/gjb_S0100207GN_5.c delete mode 100644 task_management/gjb_S0100207GN_6.c delete mode 100644 task_management/gjb_S0100207GN_7.c delete mode 100644 task_management/gjb_S0100207GN_8.c delete mode 100644 task_management/gjb_S0100207GN_9.c delete mode 100644 task_management/gjb_S0100209GN_1.c delete mode 100644 task_management/gjb_S0100209GN_2.c delete mode 100644 task_management/gjb_S0100209GN_3.c delete mode 100644 task_management/gjb_S0100209GN_4.c diff --git a/task_manage_schedule/gjb_S0100301GN_1.c b/task_manage_schedule/gjb_S0100301GN_1.c deleted file mode 100644 index 8445af9..0000000 --- a/task_manage_schedule/gjb_S0100301GN_1.c +++ /dev/null @@ -1,265 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100209GN_1.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建两个任务, 任务中获得线程的调度优先级, -** 始终运行优先级高的线程, 只能通过观察打印进行判断 -** 打印优先级顺序为 7 6 5 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -static pthread_t main_thread10_tms_3011; -static pthread_t main_thread11_tms_3011; -static pthread_t main_thread12_tms_3011; -static pthread_barrier_t bar_tms_3011; - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk gjb_printk - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - - -int pthread_getschedprio(pthread_t thread,int *priority) -{ - pthread_attr_t attr; - struct sched_param param; - int ret = 0; - if(thread <= 0x100000000) - return ESRCH; - if(priority == NULL) - { - errno = EINVAL; - return EINVAL; - } - ret = pthread_getattr_np(thread, &attr); - if(ret < 0) - { - *priority = 0; - return -1; - } - ret = pthread_attr_getschedparam(&attr, ¶m); - if(ret < 0) - { - *priority = 0; - return -1; - } - *priority = param.sched_priority; - return ret; -} - - -void *main_task_thread10_tms_3011 (void *arg) -{ - int i; - int prio; - - pthread_barrier_wait(&bar_tms_3011); - - for (i = 0; i < 20; i++) { - pthread_getschedprio(pthread_self(), &prio); - GJB_PRT_INFO("main_thread10 (prio: %d) is running\n", prio); - } - - return (NULL); -} - -void *main_task_thread11_tms_3011 (void *arg) -{ - int i; - int prio; - - pthread_barrier_wait(&bar_tms_3011); - - for (i = 0; i < 20; i++) { - pthread_getschedprio(pthread_self(), &prio); - GJB_PRT_INFO("main_thread11 (prio: %d) is running\n", prio); - } - - return (NULL); -} - -void *main_task_thread12_tms_3011 (void *arg) -{ - int i; - int prio; - - pthread_barrier_wait(&bar_tms_3011); - - for (i = 0; i < 20; i++) { - pthread_getschedprio(pthread_self(), &prio); - GJB_PRT_INFO("main_thread11 (prio: %d) is running\n", prio); - } - - return (NULL); -} - -int test8_tms_3011 (void) -{ - int status; - pthread_attr_t main_attr10; - pthread_attr_t main_attr11; - pthread_attr_t main_attr12; - struct sched_param param; - - pthread_attr_init( &main_attr10 ); /* 初始化attribute */ -// main_attr10.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr10.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr10.schedparam.sched_priority = 5;/* thread 优先级为5 */ - - pthread_attr_setschedpolicy(&main_attr10,SCHED_RR); - pthread_attr_setinheritsched(&main_attr10,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr10, ¶m); - - - - - pthread_attr_init( &main_attr11 ); /* 初始化attribute */ -// main_attr11.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr11.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr11.schedparam.sched_priority = 6;/* thread 优先级为6 */ - - pthread_attr_setschedpolicy(&main_attr11,SCHED_RR); - pthread_attr_setinheritsched(&main_attr11,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 6; - pthread_attr_setschedparam(&main_attr11, ¶m); - - - - - pthread_attr_init( &main_attr12 ); /* 初始化attribute */ -// main_attr12.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr12.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr12.schedparam.sched_priority = 7;/* thread 优先级为7 */ - - pthread_attr_setschedpolicy(&main_attr12,SCHED_RR); - pthread_attr_setinheritsched(&main_attr12,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 7; - pthread_attr_setschedparam(&main_attr12, ¶m); - - - - - pthread_barrier_init(&bar_tms_3011, NULL, 4); - - status = pthread_create(&main_thread10_tms_3011, &main_attr10, main_task_thread10_tms_3011, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread10\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread10 create success\n"); - } - - status = pthread_create(&main_thread11_tms_3011, &main_attr11, main_task_thread11_tms_3011, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread11\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread11 create success\n"); - } - - status = pthread_create(&main_thread12_tms_3011, &main_attr12, main_task_thread12_tms_3011, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread12\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread12 create success\n"); - } - - binding(main_thread10_tms_3011, 0); - binding(main_thread11_tms_3011, 0); - binding(main_thread12_tms_3011, 0); - - pthread_barrier_wait(&bar_tms_3011); - - pthread_join(main_thread10_tms_3011, NULL); //等待任务结束 - pthread_join(main_thread11_tms_3011, NULL); //等待任务结束 - pthread_join(main_thread12_tms_3011, NULL); //等待任务结束 - - return 0; -} -/********************************************************************** - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test8_tms_3011();//优先级调度_两个就绪任务_高优先级任务优先低优先级任务执行 - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_manage_schedule/gjb_S0100301GN_2.c b/task_manage_schedule/gjb_S0100301GN_2.c deleted file mode 100644 index dd0b38b..0000000 --- a/task_manage_schedule/gjb_S0100301GN_2.c +++ /dev/null @@ -1,298 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100209GN_1.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建两个任务10和任务11, 任务10正常运行, 任务11挂起自己 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - - -pthread_t main_thread10_tms_3012; -pthread_t main_thread11_tms_3012; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk gjb_printk - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -int pthread_suspend(pthread_t thread) -{ - int ret = 0; - thread_status = STOP; - if(thread == 0)//等于0说明是自己,可以挂起 - { - pthread_mutex_lock(&thread_mut); - while(STOP == thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - - pthread_mutex_unlock(&thread_mut); - - // g_suspen_status = 1; - // while(g_suspen_status ) - // { - // sleep(0); - // } - // int signo; - // sigset_t set,mask; - // signal(SIGUSR1, suspend_sighandler);//SIGQUIT - // sigemptyset(&mask); - // sigaddset(&mask, SIGUSR1); - // pthread_sigmask(SIG_BLOCK, &mask, NULL); - // sigwait(&set, &signo); - if(b_is_pthread_mutex_init) - { - pthread_mutex_lock(&g_pthread_mutex); - } - } - else - { - if(pthread_equal(thread, pthread_self()) != 0 ) - { - pthread_mutex_lock(&thread_mut); - while(!thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - pthread_mutex_unlock(&thread_mut); - // printf("suspend\n"); - // g_suspen_status = 1; - // while(g_suspen_status ) - // { - // sleep(0); - // } - } - } - // ret=taskSuspend(thread); - return ret; -} - -int pthread_resume(pthread_t thread) -{ - int ret = 0; - // ret=taskResume(thread); - // signal(SIGUSR1, suspend_sighandler);//SIGQUIT - if(thread == -1) - return -1; - // pthread_kill(thread, SIGUSR1); - // if(g_suspen_status == 1) - // { - // g_suspen_status = 0; - // } - if (thread_status == STOP) - { - pthread_mutex_lock(&thread_mut); - thread_status = RUN; - pthread_cond_signal(&thread_cond); - // printf("pthread run!\n"); - pthread_mutex_unlock(&thread_mut); - } - return ret; -} - -int pthread_getschedprio(pthread_t thread,int *priority) -{ - pthread_attr_t attr; - struct sched_param param; - int ret = 0; - if(thread <= 0x100000000) - return ESRCH; - if(priority == NULL) - { - errno = EINVAL; - return EINVAL; - } - ret = pthread_getattr_np(thread, &attr); - if(ret < 0) - { - *priority = 0; - return -1; - } - ret = pthread_attr_getschedparam(&attr, ¶m); - if(ret < 0) - { - *priority = 0; - return -1; - } - *priority = param.sched_priority; - return ret; -} - - -void *main_task_thread10_tms_3012 (void *arg) -{ - int i; - - for (i = 0; i < 20; i++) { - GJB_PRT_INFO("main_thread10 is running\n"); - } - - return (NULL); -} - -void *main_task_thread11_tms_3012 (void *arg) -{ - int i; - - for(i = 0; i < 20; i++) { - if (i == 9) { - pthread_suspend(0); - return NULL; // AICOS ADD 线程恢复之后直接退出, 只是为了能够正常退出用例 - } - - GJB_PRT_INFO("main_thread11 is running\n"); - } - - return NULL; -} - -int test8_tms_3012 (void) -{ - int status; - - pthread_attr_t main_attr10; - struct sched_param param; - - pthread_attr_init( &main_attr10 );/* 初始化attribute */ -// main_attr10.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr10.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr10.schedparam.sched_priority = 5;/* thread 优先级为5 */ - - pthread_attr_setschedpolicy(&main_attr10,SCHED_RR); - pthread_attr_setinheritsched(&main_attr10,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr10, ¶m); - - pthread_attr_t main_attr11; - pthread_attr_init( &main_attr11 );/* 初始化attribute */ -// main_attr11.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr11.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr11.schedparam.sched_priority = 6;/* thread 优先级为6 */ - - pthread_attr_setschedpolicy(&main_attr11,SCHED_RR); - pthread_attr_setinheritsched(&main_attr11,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 6; - pthread_attr_setschedparam(&main_attr11, ¶m); - - - status = pthread_create(&main_thread10_tms_3012, &main_attr10, main_task_thread10_tms_3012, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread10\n"); - return -1; - } else { - GJB_PRT_INFO("main_thread10 create success.\n"); - } - - status = pthread_create(&main_thread11_tms_3012, &main_attr11, main_task_thread11_tms_3012, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread11\n"); - return -1; - } else { - GJB_PRT_INFO("main_thread11 create success.\n"); - } - - binding(main_thread10_tms_3012, 0); - binding(main_thread11_tms_3012, 0); - - pthread_delay(1000 * 20); - - GJB_PRT_INFO("resume main thread11\n"); - pthread_resume(main_thread11_tms_3012); - - pthread_join(main_thread10_tms_3012,NULL); //等待任务结束 - pthread_join(main_thread11_tms_3012,NULL); //等待任务结束 - - return 0; -} -/********************************************************************** - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test8_tms_3012();//优先级调度_两个任务_高优先级任务挂起_低优先级任务打断高优先级任务执行 - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_manage_schedule/gjb_S0100301GN_3.c b/task_manage_schedule/gjb_S0100301GN_3.c deleted file mode 100644 index 86aa315..0000000 --- a/task_manage_schedule/gjb_S0100301GN_3.c +++ /dev/null @@ -1,199 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100209GN_1.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务私有变量测试 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -pthread_t main_thread10_tms_3013; -pthread_t main_thread11_tms_3013; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk gjb_printk - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - - - -void *main_task_thread10_tms_3013(void *arg) -{ - int i; - - for (i = 0; i < 20; i++) { - int ret; - ret = sched_yield();//任务主动让出CPU优先权 - - if(ret == -1) { - GJB_PRT_ERROR_INFO("err in schedyield\n"); - return ((void *)123); - } - - GJB_PRT_INFO("main_thread10 is running\n"); - } - - return (NULL); -} - -void *main_task_thread11_tms_3013(void *arg) -{ - int i; - - for (i = 0; i < 20; i++) { - GJB_PRT_INFO("main_thread11 is running\n"); - } - - return (NULL); -} - -int test8_tms_3013 (void) -{ - int status; - void *join_s; - - pthread_attr_t main_attr10; - struct sched_param param; - - pthread_attr_init( &main_attr10 );/* 初始化attribute */ - -// main_attr10.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr10.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr10.schedparam.sched_priority = 5;/* thread 优先级为5 */ - pthread_attr_setschedpolicy(&main_attr10,SCHED_RR); - pthread_attr_setinheritsched(&main_attr10,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr10, ¶m); - - - pthread_attr_t main_attr11; - - pthread_attr_init( &main_attr11 );/* 初始化attribute */ - -// main_attr11.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr11.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr11.schedparam.sched_priority = 6;/* thread 优先级为6 */ -// main_attr10.schedparam.sched_priority = 5;/* thread 优先级为5 */ -// main_attr11.schedparam.sched_priority = 5;/* thread 优先级为5 */ - - pthread_attr_setschedpolicy(&main_attr11,SCHED_RR); - pthread_attr_setinheritsched(&main_attr11,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr11, ¶m); - - - - - - - status = pthread_create(&main_thread10_tms_3013, &main_attr10, main_task_thread10_tms_3013, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread10\n"); - return -1; - } - - status = pthread_create(&main_thread11_tms_3013, &main_attr11, main_task_thread11_tms_3013, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread11\n"); - return -1; - } - - /* - * 将两个线程绑定到 0核 - */ - binding(main_thread10_tms_3013, 0); - binding(main_thread11_tms_3013, 0); - - pthread_join(main_thread10_tms_3013, &join_s); //等待任务结束 - pthread_join(main_thread11_tms_3013, NULL); //等待任务结束 - - if ((long)join_s != 0) { - return (-1); - } - - return 0; -} -/********************************************************************** - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test8_tms_3013();//优先级调度_两个任务_高优先级任务利用sched_yield强制让出CPU占有权_低优先级任务优先执行 - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_manage_schedule/gjb_S0100301GN_4.c b/task_manage_schedule/gjb_S0100301GN_4.c deleted file mode 100644 index 3cb44b7..0000000 --- a/task_manage_schedule/gjb_S0100301GN_4.c +++ /dev/null @@ -1,133 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100301GN_4.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 测试获取调度优先级的最大值和最小值 (RR类型) -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk gjb_printk - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - - -int test25_tms_3014 (void) -{ - int status; - pthread_attr_t attr; - int result = -1; - - status = pthread_attr_init( &attr );/* 初始化attribute */ - if( status != 0) { - GJB_PRT_ERROR_INFO("pthread_attr_init ERROR\n"); - return -1; - } - - /*可选要求接口测试_获取调度策略为SCHED_RR的调度优先级最大值和最小值_正常*/ - - status = sched_get_priority_max(SCHED_RR);//SCHED_RR的调度优先级最大值 - if (status != -1) { - GJB_PRT_INFO("The maximum priority for policy SCHED_RR is %d\n",status); - } else { - GJB_PRT_ERROR_INFO("An error occurs\n"); - return -1; - } - - result = sched_get_priority_min(SCHED_RR); - if (result != -1) { - GJB_PRT_INFO("The minimum priority for policy SCHED_RR is %d\n",result); - - } else { - GJB_PRT_ERROR_INFO("An error occurs\n"); - return -1; - } - - return 0; -} -/********************************************************************** - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test25_tms_3014();//可选要求接口测试_获取调度策略为SCHED_RR的调度优先级最大值和最小值_正常 - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); - -} diff --git a/task_manage_schedule/gjb_S0100301GN_5.c b/task_manage_schedule/gjb_S0100301GN_5.c deleted file mode 100644 index 1060190..0000000 --- a/task_manage_schedule/gjb_S0100301GN_5.c +++ /dev/null @@ -1,135 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100301GN_5.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 测试获取调度优先级的最大值和最小值 (FIFO类型) -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk gjb_printk - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - - -int test25_tms_3015 (void) -{ - int status; - pthread_attr_t attr; - int result = -1; - - status = pthread_attr_init( &attr );/* 初始化attribute */ - if( status != 0) { - GJB_PRT_ERROR_INFO("pthread_attr_init ERROR\n"); - return -1; - } - - /*可选要求接口测试_获取调度策略为SCHED_FIFO的调度优先级最大值和最小值_正常*/ - - status = sched_get_priority_max(SCHED_FIFO);//SCHED_FIFO的调度优先级最大值 - if(status != -1) { - GJB_PRT_INFO("The maximum priority for policy SCHED_FIFO is %d\n",status); - } else - { - GJB_PRT_ERROR_INFO("An error occurs\n"); - return -1; - } - - result = sched_get_priority_min(SCHED_FIFO); - if(result != -1) - { - GJB_PRT_INFO("The minimum priority for policy SCHED_FIFO is %d\n",result); - } - else - { - GJB_PRT_ERROR_INFO("An error occurs\n"); - return -1; - } - - return 0; -} -/********************************************************************** - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test25_tms_3015();//可选要求接口测试_获取调度策略为SCHED_FIFO的调度优先级最大值和最小值_正常 - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_manage_schedule/gjb_S0100301GN_6.c b/task_manage_schedule/gjb_S0100301GN_6.c deleted file mode 100644 index 7866258..0000000 --- a/task_manage_schedule/gjb_S0100301GN_6.c +++ /dev/null @@ -1,118 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100301GN_6.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 测试获取调度优先级的最大值和最小值 (FIFO类型和RR类型) -*********************************************************************************************************/ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk gjb_printk - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - - -int test25_tms_3016 (void) -{ - int status; - int result = -1; - - /*可选要求接口测试_获取调度策略为SCHED_RR的调度优先级最大值和最小值_正常*/ - - status = sched_get_priority_max(SCHED_FIFO);//调度策略为3 - if (status != -1) { - GJB_PRT_INFO("The maximum priority for policy is %d\n",status); - - } else if (status == -1) { - GJB_PRT_ERROR_INFO("The maximum priority error occurs:priority EINVAL\n"); - return (-1); - } - - result = sched_get_priority_min(SCHED_RR);//调度策略为3 - if (result != -1) { - GJB_PRT_INFO("The minimum priority for policy is %d\n",result); - - } else if (result == -1) { - GJB_PRT_ERROR_INFO("The minimum priority error occurs:priority EINVAL\n"); - return -1; - } - - return 0; -} - -/********************************************************************** - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test25_tms_3016();//关键数据结构定义正确性测试_任务管理编程接口关键数据结构_调度策略宏定义_正常 - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_manage_schedule/gjb_S0100301GN_7.c b/task_manage_schedule/gjb_S0100301GN_7.c deleted file mode 100644 index 12f9cc7..0000000 --- a/task_manage_schedule/gjb_S0100301GN_7.c +++ /dev/null @@ -1,125 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100301GN_7.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 获得无效调度类型 5 的最大最小优先级 -*********************************************************************************************************/ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk gjb_printk - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - - - -int test25_tms_3017 (void) -{ - int status; - int result = -1; - - status = sched_get_priority_max(5); //调度策略为5 - if (status != -1) { - GJB_PRT_ERROR_INFO("The maximum priority for policy is %d\n",status); - return (-1); - - } else if(status == -1) { - if (errno == EINVAL) { - GJB_PRT_INFO("The maximum priority error occurs:priority EINVAL\n"); - } else { - GJB_PRT_ERROR_INFO("sched_get_priority_max set invalid param should return EINVAL\n"); - return (-1); - } - } - - result = sched_get_priority_min(5); //调度策略为5 - if(result != -1) { - GJB_PRT_ERROR_INFO("The minimum priority for policy is %d\n",result); - return (-1); - - } else if(result == -1) { - if(errno == EINVAL) { - GJB_PRT_INFO("The minimum priority error occurs:priority EINVAL\n"); - } else { - GJB_PRT_ERROR_INFO("sched_get_priority_min set invalid param should return EINVAL\n"); - return -1; - } - } - - return 0; -} -/********************************************************************** - * 函数名称: GJB_ENTRY() - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test25_tms_3017();//可选要求接口测试_获取调度策略为5(不合法值)的调度优先级最大值和最小值_正常 - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_manage_schedule/gjb_S0100301GN_8.c b/task_manage_schedule/gjb_S0100301GN_8.c deleted file mode 100644 index ae8f753..0000000 --- a/task_manage_schedule/gjb_S0100301GN_8.c +++ /dev/null @@ -1,185 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100301GN_8.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 高优先级任务睡眠, 将调度到低优先级任务 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -pthread_t main_thread10_tms_3018; -pthread_t main_thread11_tms_3018; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk gjb_printk - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -void *main_task_thread10_tms_3018(void *arg) -{ - int i; - - for (i = 0; i < 20; i++) { - GJB_PRT_INFO("main_thread10 is running\n"); - } - - return (NULL); -} - -void *main_task_thread11_tms_3018(void *arg) -{ - int i; - - for (i = 0; i < 20; i++) { - if (i == 9) { - pthread_delay(20); - } - - GJB_PRT_INFO("main_thread11 is running\n"); - } - - return (NULL); -} - -int test8_tms_3018 (void) -{ - int status; - - pthread_attr_t main_attr10; - struct sched_param param; - - pthread_attr_init( &main_attr10 );/* 初始化attribute */ - -// main_attr10.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr10.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr10.schedparam.sched_priority = 5;/* thread 优先级为5 */ - - pthread_attr_setschedpolicy(&main_attr10,SCHED_RR); - pthread_attr_setinheritsched(&main_attr10,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr10, ¶m); - - - pthread_attr_t main_attr11; - - pthread_attr_init( &main_attr11 );/* 初始化attribute */ - -// main_attr11.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr11.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr11.schedparam.sched_priority = 6;/* thread 优先级为6 */ - - pthread_attr_setschedpolicy(&main_attr11,SCHED_RR); - pthread_attr_setinheritsched(&main_attr11,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 6; - pthread_attr_setschedparam(&main_attr11, ¶m); - - - - status = pthread_create(&main_thread10_tms_3018, &main_attr10, main_task_thread10_tms_3018, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread10\n"); - return -1; - } - - status = pthread_create(&main_thread11_tms_3018, &main_attr11, main_task_thread11_tms_3018, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread11\n"); - return -1; - } - - binding(main_thread10_tms_3018, 0); - binding(main_thread11_tms_3018, 0); - - pthread_join(main_thread10_tms_3018,NULL); //等待任务结束 - pthread_join(main_thread11_tms_3018,NULL); //等待任务结束 - - return 0; -} -/********************************************************************** - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test8_tms_3018(); //优先级调度_两个任务_高优先级任务阻塞_低优先级任务打断高优先级任务执行 - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_manage_schedule/gjb_S0100302GN_1.c b/task_manage_schedule/gjb_S0100302GN_1.c deleted file mode 100644 index 16e8cc7..0000000 --- a/task_manage_schedule/gjb_S0100302GN_1.c +++ /dev/null @@ -1,364 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100302GN_1.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务调度禁止_禁止任务调度_在2000ticks内又使该线程主动让出CPU_任务12调度正常 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -pthread_barrier_t bt_tms_3021; -pthread_t main_thread12_tms_3021; -pthread_t main_thread13_tms_3021; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk gjb_printk - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} -// -// -//int -//__backtrace (void **array, int size) -//{ -// struct trace_arg arg = { .array = array, .cfa = 0, .size = size, .cnt = -1 }; -// -// if (size <= 0) -// return 0; -// -//#ifdef SHARED -// __libc_once_define (static, once); -// -// __libc_once (once, init); -// if (unwind_backtrace == NULL) -// return 0; -//#endif -// -// unwind_backtrace (backtrace_helper, &arg); -// -// /* _Unwind_Backtrace seems to put NULL address above -// _start. Fix it up here. */ -// if (arg.cnt > 1 && arg.array[arg.cnt - 1] == NULL) -// --arg.cnt; -// return arg.cnt != -1 ? arg.cnt : 0; -//} -// -// -// -// -//char ** -//__backtrace_symbols (void *const *array, int size) -//{ -// Dl_info info[size]; -// int status[size]; -// int cnt; -// size_t total = 0; -// char **result; -// -// /* Fill in the information we can get from `dladdr'. */ -// for (cnt = 0; cnt < size; ++cnt) -// { -// struct link_map *map; -// status[cnt] = _dl_addr (array[cnt], &info[cnt], &map, NULL); -// if (status[cnt] && info[cnt].dli_fname && info[cnt].dli_fname[0] != '\0') -// { -// /* We have some info, compute the length of the string which will be -// "(+offset) [address]. */ -// total += (strlen (info[cnt].dli_fname ?: "") -// + strlen (info[cnt].dli_sname ?: "") -// + 3 + WORD_WIDTH + 3 + WORD_WIDTH + 5); -// -// /* The load bias is more useful to the user than the load -// address. The use of these addresses is to calculate an -// address in the ELF file, so its prelinked bias is not -// something we want to subtract out. */ -// info[cnt].dli_fbase = (void *) map->l_addr; -// } -// else -// total += 5 + WORD_WIDTH; -// } -// -// /* Allocate memory for the result. */ -// result = (char **) malloc (size * sizeof (char *) + total); -// if (result != NULL) -// { -// char *last = (char *) (result + size); -// -// for (cnt = 0; cnt < size; ++cnt) -// { -// result[cnt] = last; -// -// if (status[cnt] -// && info[cnt].dli_fname != NULL && info[cnt].dli_fname[0] != '\0') -// { -// if (info[cnt].dli_sname == NULL) -// /* We found no symbol name to use, so describe it as -// relative to the file. */ -// info[cnt].dli_saddr = info[cnt].dli_fbase; -// -// if (info[cnt].dli_sname == NULL && info[cnt].dli_saddr == 0) -// last += 1 + sprintf (last, "%s(%s) [%p]", -// info[cnt].dli_fname ?: "", -// info[cnt].dli_sname ?: "", -// array[cnt]); -// else -// { -// char sign; -// ptrdiff_t offset; -// if (array[cnt] >= (void *) info[cnt].dli_saddr) -// { -// sign = '+'; -// offset = array[cnt] - info[cnt].dli_saddr; -// } -// else -// { -// sign = '-'; -// offset = info[cnt].dli_saddr - array[cnt]; -// } -// -// last += 1 + sprintf (last, "%s(%s%c%#tx) [%p]", -// info[cnt].dli_fname ?: "", -// info[cnt].dli_sname ?: "", -// sign, offset, array[cnt]); -// } -// } -// else -// last += 1 + sprintf (last, "[%p]", array[cnt]); -// } -// assert (last <= (char *) result + size * sizeof (char *) + total); -// } -// -// return result; -//} - - - -//void dump(void) -//{ -// int j, nptrs; -// void *buffer[BACKTRACE_SIZE]; -// char **strings; -// -// nptrs = backtrace(buffer, BACKTRACE_SIZE); -// -// // printf("backtrace() returned %d addresses\n", nptrs); -// -// strings = backtrace_symbols(buffer, nptrs); -// if (strings == NULL) { -// // perror("backtrace_symbols"); -// exit(EXIT_FAILURE); -// } -// -// // for (j = 0; j < nptrs; j++) -// // printf(" [%02d] %s\n", j, strings[j]); -// -// free(strings); -//} - -int pthread_lock() -{ - // dump(); - - if(b_is_pthread_mutex_init == 0) - { - b_is_pthread_mutex_init = 1; - pthread_mutex_init(&g_pthread_mutex, NULL); - } - // taskLock(); - pthread_mutex_lock(&g_pthread_mutex); - return 0; -} - -int pthread_unlock() -{ - // taskUnlock(); - pthread_mutex_unlock(&g_pthread_mutex); - return 0; -} - - -void *main_task_thread12_tms_3021(void *arg) -{ - int i; - - pthread_barrier_wait(&bt_tms_3021); // 线程屏障 - - for (i = 0; i < 20; i++) { - GJB_PRT_INFO("main_thread12 is running\n"); - } - - return (NULL); -} - -void *main_task_thread13_tms_3021(void *arg) -{ - int status; - int i; - - pthread_barrier_wait(&bt_tms_3021); - - for (i = 0; i < 20; i++) { - if(i == 0) { - status = pthread_lock(); - if(status == 0) { - GJB_PRT_INFO("main_thread13 is locked successfully\n"); - } - - status = pthread_delay(2000);//2000tick,这将导致该任务不在就绪状态 - status = pthread_unlock(); - if(status == 0) { - GJB_PRT_INFO("main_thread13 is unlocked successfully\n"); - } - } - - GJB_PRT_INFO("main_thread13 is running\n"); - } - - return (void *)0; -} - -int test9_tms_3021 (void) -{ - int status; - pthread_attr_t main_attr12; - pthread_attr_t main_attr13; - struct sched_param param; - - /*任务一*/ - pthread_barrier_init(&bt_tms_3021,NULL,3); - pthread_attr_init( &main_attr12 );/* 初始化attribute */ - pthread_attr_init( &main_attr13 );/* 初始化attribute */ - -// main_attr12.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr12.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr12.schedparam.sched_priority = 5;/* thread 优先级为5 */ - - pthread_attr_setschedpolicy(&main_attr12,SCHED_RR); - pthread_attr_setinheritsched(&main_attr12,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr12, ¶m); - - - -// main_attr13.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr13.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr13.schedparam.sched_priority = 6;/* thread 优先级为6 */ - - pthread_attr_setschedpolicy(&main_attr13,SCHED_RR); - pthread_attr_setinheritsched(&main_attr13,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 6; - pthread_attr_setschedparam(&main_attr13, ¶m); - - - - status = pthread_create(&main_thread12_tms_3021, &main_attr12, main_task_thread12_tms_3021, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread12\n"); - return -1; - } - - status = pthread_create(&main_thread13_tms_3021, &main_attr13, main_task_thread13_tms_3021, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread13\n"); - return -1; - } - - binding(main_thread12_tms_3021, 0); - binding(main_thread13_tms_3021, 0); - - pthread_barrier_wait(&bt_tms_3021); - - pthread_join(main_thread12_tms_3021,NULL); //等待任务结束 - pthread_join(main_thread13_tms_3021,NULL); //等待任务结束 - - return 0; -} -/********************************************************************** - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test9_tms_3021();//任务调度禁止_禁止任务调度_在2000ticks内又使该线程主动让出CPU_任务12调度正常 - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_manage_schedule/gjb_S0100302GN_2.c b/task_manage_schedule/gjb_S0100302GN_2.c deleted file mode 100644 index 37995ed..0000000 --- a/task_manage_schedule/gjb_S0100302GN_2.c +++ /dev/null @@ -1,351 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100302GN_2.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务调度禁止_禁止任务调度_任务13在lock后创建更高优先级任务34_任务13先运行不会被抢占_正常 -*********************************************************************************************************/ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - - - -pthread_barrier_t bt_tms_3022; - -pthread_t main_thread12_tms_3022; -pthread_t main_thread13_tms_3022; -pthread_t main_thread34_tms_3022; - -static int error_tms_3022 = 0; - - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk gjb_printk - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -int pthread_lock() -{ - // dump(); - - if(b_is_pthread_mutex_init == 0) - { - b_is_pthread_mutex_init = 1; - pthread_mutex_init(&g_pthread_mutex, NULL); - } - // taskLock(); - pthread_mutex_lock(&g_pthread_mutex); - return 0; -} - -int pthread_unlock() -{ - // taskUnlock(); - pthread_mutex_unlock(&g_pthread_mutex); - return 0; -} - -int pthread_resume(pthread_t thread) -{ - int ret = 0; - // ret=taskResume(thread); - // signal(SIGUSR1, suspend_sighandler);//SIGQUIT - if(thread == -1) - return -1; - // pthread_kill(thread, SIGUSR1); - // if(g_suspen_status == 1) - // { - // g_suspen_status = 0; - // } - if (thread_status == STOP) - { - pthread_mutex_lock(&thread_mut); - thread_status = RUN; - pthread_cond_signal(&thread_cond); - // printf("pthread run!\n"); - pthread_mutex_unlock(&thread_mut); - } - return ret; -} -int pthread_suspend(pthread_t thread) -{ - int ret = 0; - thread_status = STOP; - if(thread == 0)//等于0说明是自己,可以挂起 - { - pthread_mutex_lock(&thread_mut); - while(STOP == thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - - pthread_mutex_unlock(&thread_mut); - - // g_suspen_status = 1; - // while(g_suspen_status ) - // { - // sleep(0); - // } - // int signo; - // sigset_t set,mask; - // signal(SIGUSR1, suspend_sighandler);//SIGQUIT - // sigemptyset(&mask); - // sigaddset(&mask, SIGUSR1); - // pthread_sigmask(SIG_BLOCK, &mask, NULL); - // sigwait(&set, &signo); - if(b_is_pthread_mutex_init) - { - pthread_mutex_lock(&g_pthread_mutex); - } - } - else - { - if(pthread_equal(thread, pthread_self()) != 0 ) - { - pthread_mutex_lock(&thread_mut); - while(!thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - pthread_mutex_unlock(&thread_mut); - // printf("suspend\n"); - // g_suspen_status = 1; - // while(g_suspen_status ) - // { - // sleep(0); - // } - } - } - // ret=taskSuspend(thread); - return ret; -} - -void *main_task_thread12_tms_3022(void *arg) -{ - int i; - - pthread_barrier_wait(&bt_tms_3022); - - for (i = 0; i < 20; i++) { - GJB_PRT_INFO("main_thread12 is running\n"); - } - - return (NULL); -} - -void *main_task_thread34_tms_3022(void *arg) -{ - int i,status; - - status = pthread_suspend(0); - if(status != 0) { - GJB_PRT_ERROR_INFO("pthread_suspend suspend main_task_thread34 failed\n"); - error_tms_3022++; - return ((void *)123); - } - - for(i=0;i<3;i++) { - GJB_PRT_INFO("main_thread34 start..\n"); - } - - return (NULL); -} - -void *main_task_thread13_tms_3022(void *arg) -{ - int status; - int i; - pthread_attr_t attr; - struct sched_param param; - - pthread_barrier_wait(&bt_tms_3022); - pthread_attr_init( &attr );/* 初始化attribute */ - -// attr.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// attr.inheritsched = PTHREAD_EXPLICIT_SCHED; -// attr.schedparam.sched_priority = 10;/* thread 优先级为10 */ - - pthread_attr_setschedpolicy(&attr,SCHED_RR); - pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 10; - pthread_attr_setschedparam(&attr, ¶m); - - - status = pthread_create(&main_thread34_tms_3022, &attr, main_task_thread34_tms_3022, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread34\n"); - return ((void *)123); - } - - status = pthread_lock(); // 锁调度 - if(status == 0) { - GJB_PRT_INFO("main_thread13 is locked successfully\n"); - } - - binding(main_thread34_tms_3022, 0); - - if (error_tms_3022) { - pthread_unlock(); // 解锁调度 - return ((void *)123); - } - - status = pthread_resume(main_thread34_tms_3022); - for (i = 0; i < 20; i++) { - GJB_PRT_INFO("main_thread13 is running\n"); - } - - status = pthread_unlock();//pthread_unlock之后立即切换,执行main_thread34高优先级 - if(status == 0) { - GJB_PRT_INFO("main_thread13 is unlocked successfully\n"); - } - - return (NULL); -} - -int test9_tms_3022 (void) -{ - int status; - pthread_attr_t main_attr12; - pthread_attr_t main_attr13; - void *join_s; - struct sched_param param; - - /*任务一*/ - pthread_barrier_init(&bt_tms_3022,NULL,3); - pthread_attr_init( &main_attr12 );/* 初始化attribute */ - pthread_attr_init( &main_attr13 );/* 初始化attribute */ - -// main_attr12.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr12.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr12.schedparam.sched_priority = 5;/* thread 优先级为5 */ -// main_attr13.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr13.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr13.schedparam.sched_priority = 6;/* thread 优先级为6 */ - - pthread_attr_setschedpolicy(&main_attr12,SCHED_RR); - pthread_attr_setinheritsched(&main_attr12,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr12, ¶m); - - pthread_attr_setschedpolicy(&main_attr13,SCHED_RR); - pthread_attr_setinheritsched(&main_attr13,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 6; - pthread_attr_setschedparam(&main_attr13, ¶m); - - - status = pthread_create(&main_thread12_tms_3022, &main_attr12, main_task_thread12_tms_3022, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread12\n"); - return -1; - } - - status = pthread_create(&main_thread13_tms_3022, &main_attr13, main_task_thread13_tms_3022, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread13\n"); - return -1; - } - - binding(main_thread12_tms_3022, 0); - binding(main_thread13_tms_3022, 0); - - pthread_barrier_wait(&bt_tms_3022); - - pthread_join(main_thread12_tms_3022, NULL); //等待任务结束 - pthread_join(main_thread13_tms_3022, &join_s); //等待任务结束 - - pthread_delay(1000 * 10); - pthread_kill(main_thread34_tms_3022, SIGTERM); - pthread_resume(main_thread34_tms_3022); - - return 0; -} -/********************************************************************** - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test9_tms_3022();//任务调度禁止_禁止任务调度_任务13在lock后创建更高优先级任务34_任务13先运行不会被抢占_正常 - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_manage_schedule/gjb_S0100302GN_3.c b/task_manage_schedule/gjb_S0100302GN_3.c deleted file mode 100644 index 6e6ce0a..0000000 --- a/task_manage_schedule/gjb_S0100302GN_3.c +++ /dev/null @@ -1,359 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100302GN_3.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 基本要求接口测试_lock与unlock之间创建任务_正常 -*********************************************************************************************************/ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -pthread_barrier_t bt_tms_3023; -pthread_t main_thread12_tms_3023; -pthread_t main_thread13_tms_3023; -pthread_t main_thread34_tms_3023; - -static int error_tms_3023 = 0; - - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk gjb_printk - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -int pthread_lock() -{ - // dump(); - - if(b_is_pthread_mutex_init == 0) - { - b_is_pthread_mutex_init = 1; - pthread_mutex_init(&g_pthread_mutex, NULL); - } - // taskLock(); - pthread_mutex_lock(&g_pthread_mutex); - return 0; -} - -int pthread_unlock() -{ - // taskUnlock(); - pthread_mutex_unlock(&g_pthread_mutex); - return 0; -} - -int pthread_resume(pthread_t thread) -{ - int ret = 0; - // ret=taskResume(thread); - // signal(SIGUSR1, suspend_sighandler);//SIGQUIT - if(thread == -1) - return -1; - // pthread_kill(thread, SIGUSR1); - // if(g_suspen_status == 1) - // { - // g_suspen_status = 0; - // } - if (thread_status == STOP) - { - pthread_mutex_lock(&thread_mut); - thread_status = RUN; - pthread_cond_signal(&thread_cond); - // printf("pthread run!\n"); - pthread_mutex_unlock(&thread_mut); - } - return ret; -} -int pthread_suspend(pthread_t thread) -{ - int ret = 0; - thread_status = STOP; - if(thread == 0)//等于0说明是自己,可以挂起 - { - pthread_mutex_lock(&thread_mut); - while(STOP == thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - - pthread_mutex_unlock(&thread_mut); - - // g_suspen_status = 1; - // while(g_suspen_status ) - // { - // sleep(0); - // } - // int signo; - // sigset_t set,mask; - // signal(SIGUSR1, suspend_sighandler);//SIGQUIT - // sigemptyset(&mask); - // sigaddset(&mask, SIGUSR1); - // pthread_sigmask(SIG_BLOCK, &mask, NULL); - // sigwait(&set, &signo); - if(b_is_pthread_mutex_init) - { - pthread_mutex_lock(&g_pthread_mutex); - } - } - else - { - if(pthread_equal(thread, pthread_self()) != 0 ) - { - pthread_mutex_lock(&thread_mut); - while(!thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - pthread_mutex_unlock(&thread_mut); - // printf("suspend\n"); - // g_suspen_status = 1; - // while(g_suspen_status ) - // { - // sleep(0); - // } - } - } - // ret=taskSuspend(thread); - return ret; -} - - -void *main_task_thread34_tms_3023 (void *arg) -{ - int i,status; - - status = pthread_suspend(0); - if(status != 0) { - GJB_PRT_ERROR_INFO("pthread_suspend suspend main_task_thread34 failed\n"); - error_tms_3023++; - return ((void *)123); - } - - for (i = 0; i < 3; i++) { - GJB_PRT_INFO("main_thread34 start..\n"); - } - - return (NULL); -} - -void *main_task_thread12_tms_3023 (void *arg) -{ - int i; - - pthread_barrier_wait(&bt_tms_3023); - - for (i = 0; i < 20; i++) { - GJB_PRT_INFO("main_thread12 is running\n"); - } - - return (NULL); -} - -void *main_task_thread13_tms_3023(void *arg) -{ - int status; - int i; - pthread_attr_t attr; - struct sched_param param; - - pthread_barrier_wait(&bt_tms_3023); - - status = pthread_lock(); - if(status == 0) { - GJB_PRT_INFO("main_thread13 is locked successfully\n"); - } - - pthread_attr_init( &attr );/* 初始化attribute */ - -// attr.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// attr.inheritsched = PTHREAD_EXPLICIT_SCHED; -// attr.schedparam.sched_priority = 10;/* thread 优先级为10 */ - - pthread_attr_setschedpolicy(&attr,SCHED_RR); - pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 10; - pthread_attr_setschedparam(&attr, ¶m); - - - - - status = pthread_create(&main_thread34_tms_3023, &attr, main_task_thread34_tms_3023, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread34\n"); - return ((void *)123); - } - - for (i = 0; i < 20; i++) { - GJB_PRT_INFO("main_thread13 is running\n"); - } - - pthread_delay(2000); - binding(main_thread34_tms_3023, 0); - - if (error_tms_3023) { - pthread_unlock(); - return ((void *)123); - } - - status = pthread_unlock(); - if(status == 0) { - GJB_PRT_INFO("main_thread13 is unlocked successfully\n"); - } - - return (NULL); -} - -int test9_tms_3023 (void) -{ - int status; - pthread_attr_t main_attr13; - pthread_attr_t main_attr12; - void *join_s; - struct sched_param param; - - /*任务一*/ - pthread_barrier_init(&bt_tms_3023,NULL,3); - pthread_attr_init( &main_attr13 );/* 初始化attribute */ - pthread_attr_init( &main_attr12 );/* 初始化attribute */ - -// main_attr12.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr12.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr12.schedparam.sched_priority = 5;/* thread 优先级为5 */ - - pthread_attr_setschedpolicy(&main_attr12,SCHED_RR); - pthread_attr_setinheritsched(&main_attr12,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr12, ¶m); - - -// main_attr13.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr13.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr13.schedparam.sched_priority = 6;/* thread 优先级为6 */ - - pthread_attr_setschedpolicy(&main_attr13,SCHED_RR); - pthread_attr_setinheritsched(&main_attr13,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 6; - pthread_attr_setschedparam(&main_attr13, ¶m); - - - - status = pthread_create(&main_thread12_tms_3023, &main_attr12, main_task_thread12_tms_3023, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread12\n"); - return -1; - } - - status = pthread_create(&main_thread13_tms_3023, &main_attr13, main_task_thread13_tms_3023, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread13\n"); - return -1; - } - - binding(main_thread12_tms_3023, 0); - binding(main_thread13_tms_3023, 0); - - pthread_barrier_wait(&bt_tms_3023); - - pthread_join(main_thread12_tms_3023,NULL); //等待任务结束 - pthread_join(main_thread13_tms_3023, &join_s); //等待任务结束 - - if ((long)join_s != 0) { - return (-1); - } - - pthread_delay(1000 * 10); - pthread_kill(main_thread34_tms_3023, SIGTERM); - pthread_resume(main_thread34_tms_3023); - - return 0; -} -/********************************************************************** - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test9_tms_3023();//基本要求接口测试_lock与unlock之间创建任务_正常 - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_manage_schedule/gjb_S0100302GN_4.c b/task_manage_schedule/gjb_S0100302GN_4.c deleted file mode 100644 index 023a8b2..0000000 --- a/task_manage_schedule/gjb_S0100302GN_4.c +++ /dev/null @@ -1,304 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100302GN_4.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务调度禁止_禁止任务调度_2s后使能调度_正常 -*********************************************************************************************************/ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -pthread_barrier_t bt_tms_3024; -pthread_t main_thread12_tms_3024; -pthread_t main_thread13_tms_3024; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk gjb_printk - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -int pthread_lock() -{ - // dump(); - - if(b_is_pthread_mutex_init == 0) - { - b_is_pthread_mutex_init = 1; - pthread_mutex_init(&g_pthread_mutex, NULL); - } - // taskLock(); - pthread_mutex_lock(&g_pthread_mutex); - return 0; -} - -int pthread_unlock() -{ - // taskUnlock(); - pthread_mutex_unlock(&g_pthread_mutex); - return 0; -} - -int pthread_resume(pthread_t thread) -{ - int ret = 0; - // ret=taskResume(thread); - // signal(SIGUSR1, suspend_sighandler);//SIGQUIT - if(thread == -1) - return -1; - // pthread_kill(thread, SIGUSR1); - // if(g_suspen_status == 1) - // { - // g_suspen_status = 0; - // } - if (thread_status == STOP) - { - pthread_mutex_lock(&thread_mut); - thread_status = RUN; - pthread_cond_signal(&thread_cond); - // printf("pthread run!\n"); - pthread_mutex_unlock(&thread_mut); - } - return ret; -} -int pthread_suspend(pthread_t thread) -{ - int ret = 0; - thread_status = STOP; - if(thread == 0)//等于0说明是自己,可以挂起 - { - pthread_mutex_lock(&thread_mut); - while(STOP == thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - - pthread_mutex_unlock(&thread_mut); - - // g_suspen_status = 1; - // while(g_suspen_status ) - // { - // sleep(0); - // } - // int signo; - // sigset_t set,mask; - // signal(SIGUSR1, suspend_sighandler);//SIGQUIT - // sigemptyset(&mask); - // sigaddset(&mask, SIGUSR1); - // pthread_sigmask(SIG_BLOCK, &mask, NULL); - // sigwait(&set, &signo); - if(b_is_pthread_mutex_init) - { - pthread_mutex_lock(&g_pthread_mutex); - } - } - else - { - if(pthread_equal(thread, pthread_self()) != 0 ) - { - pthread_mutex_lock(&thread_mut); - while(!thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - pthread_mutex_unlock(&thread_mut); - // printf("suspend\n"); - // g_suspen_status = 1; - // while(g_suspen_status ) - // { - // sleep(0); - // } - } - } - // ret=taskSuspend(thread); - return ret; -} - - - -void *main_task_thread12_tms_3024(void *arg) -{ - int i; - - pthread_barrier_wait(&bt_tms_3024); - - for (i = 0; i < 20; i++) { - GJB_PRT_INFO("main_thread12 is running\n"); - } - - return (NULL); -} - -void *main_task_thread13_tms_3024(void *arg) -{ - int status; - int i; - - pthread_barrier_wait(&bt_tms_3024); - - status = pthread_lock(); - if(status == 0) { - GJB_PRT_INFO("main_thread13 is locked successfully\n"); - } - - status = pthread_delay(2000);//2000tick,这将导致该任务不在就绪状态 - for (i = 0; i < 20; i++) { - GJB_PRT_INFO("main_thread13 is running\n"); - } - - status = pthread_unlock(); - if(status == 0) { - GJB_PRT_INFO("main_thread13 is unlocked successfully\n"); - } - - return (NULL); -} - -int test9_tms_3024 (void) -{ - int status; - pthread_attr_t main_attr12; - pthread_attr_t main_attr13; - struct sched_param param; - - /*任务一*/ - pthread_barrier_init(&bt_tms_3024,NULL,3); - pthread_attr_init( &main_attr12 );/* 初始化attribute */ - pthread_attr_init( &main_attr13 );/* 初始化attribute */ - -// main_attr12.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr12.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr12.schedparam.sched_priority = 5;/* thread 优先级为5 */ - - pthread_attr_setschedpolicy(&main_attr12,SCHED_RR); - pthread_attr_setinheritsched(&main_attr12,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr12, ¶m); - - - -// main_attr13.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr13.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr13.schedparam.sched_priority = 6;/* thread 优先级为6 */ - - - pthread_attr_setschedpolicy(&main_attr13,SCHED_RR); - pthread_attr_setinheritsched(&main_attr13,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 6; - pthread_attr_setschedparam(&main_attr13, ¶m); - - status = pthread_create(&main_thread12_tms_3024, &main_attr12, main_task_thread12_tms_3024, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread12\n"); - return -1; - } else { - GJB_PRT_INFO("main_thread12 create success."); - } - - status = pthread_create(&main_thread13_tms_3024, &main_attr13, main_task_thread13_tms_3024, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread13\n"); - return -1; - } else { - GJB_PRT_INFO("main_thread13 create success."); - } - - binding(main_thread12_tms_3024, 0); - binding(main_thread13_tms_3024, 0); - - pthread_barrier_wait(&bt_tms_3024); - - pthread_join(main_thread12_tms_3024, NULL); //等待任务结束 - pthread_join(main_thread13_tms_3024, NULL); //等待任务结束 - - return 0; -} -/********************************************************************** - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test9_tms_3024();//任务调度禁止_禁止任务调度_2s后使能调度_正常 - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_manage_schedule/gjb_S0100303GN.c b/task_manage_schedule/gjb_S0100303GN.c deleted file mode 100644 index 48fb005..0000000 --- a/task_manage_schedule/gjb_S0100303GN.c +++ /dev/null @@ -1,205 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100303GN.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 时间片轮转调度_按时间片轮转方式顺序执行任务_正常 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -pthread_barrier_t bt_tms_303; -pthread_t main_thread8_tms_303; -pthread_t main_thread9_tms_303; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk gjb_printk - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -/*main_task_thread8*/ -void *main_task_thread8_tms_303(void *arg) -{ - int i = 0; - - pthread_barrier_wait(&bt_tms_303); - - while(1) { - if ((i % 10000) == 0) { - GJB_PRT_INFO("main_thread8 is running\n"); - } - - i++; - } - - return (NULL); -} - -/*main_task_thread9*/ -void *main_task_thread9_tms_303(void *arg) -{ - int i = 0; - - pthread_barrier_wait(&bt_tms_303); - - while(1) { - if ((i % 10000) == 0) { - GJB_PRT_INFO("main_thread9 is running\n"); - } - i++; - } - - return (NULL); -} - -/*状态转换测试:就绪与运行状态转换测试基本原理 - * 首先创建两个优先级相同的线程,设置时间片轮转调度方式,即每个线程都分配公平的运行时间片,时间片用完就执行下一个线程 - * ,当前线程处于就绪状态*/ -int test7_tms_303 (void) -{ - int status; - pthread_attr_t main_attr8; - pthread_attr_t main_attr9; - struct sched_param param; - - /*任务一*/ - pthread_barrier_init(&bt_tms_303,NULL,3); - pthread_attr_init( &main_attr9 );/* 初始化attribute */ - pthread_attr_init( &main_attr8 );/* 初始化attribute */ - -// main_attr8.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr8.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr8.schedparam.sched_priority = 55;/* thread 优先级为5 */ - - pthread_attr_setschedpolicy(&main_attr8,SCHED_RR); - pthread_attr_setinheritsched(&main_attr8,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 55; - pthread_attr_setschedparam(&main_attr8, ¶m); - -// main_attr9.schedpolicy = SCHED_RR; /* 优先级抢占调度 */ -// main_attr9.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr9.schedparam.sched_priority = 55;/* thread 优先级为5 */ - - pthread_attr_setschedpolicy(&main_attr9,SCHED_RR); - pthread_attr_setinheritsched(&main_attr9,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 55; - pthread_attr_setschedparam(&main_attr9, ¶m); - - - status = pthread_create(&main_thread8_tms_303, &main_attr8, main_task_thread8_tms_303, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread8\n"); - return -1; - } - - status = pthread_create(&main_thread9_tms_303, &main_attr9, main_task_thread9_tms_303, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread9\n"); - return -1; - } - - binding(main_thread8_tms_303, 0); - binding(main_thread9_tms_303, 0); - - pthread_barrier_wait(&bt_tms_303); - - pthread_delay(1000 * 3); - - pthread_kill(main_thread8_tms_303, SIGTERM); - pthread_kill(main_thread9_tms_303, SIGTERM); - - pthread_join(main_thread8_tms_303, NULL); //等待任务结束 - pthread_join(main_thread9_tms_303, NULL); //等待任务结束 - - return 0; -} -/********************************************************************** - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test7_tms_303();//时间片轮转调度_按时间片轮转方式顺序执行任务_正常 - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_manage_schedule/gjb_S0100304GN.c b/task_manage_schedule/gjb_S0100304GN.c deleted file mode 100644 index 41c695a..0000000 --- a/task_manage_schedule/gjb_S0100304GN.c +++ /dev/null @@ -1,209 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100304GN.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 先进先出调度策略_相同优先级的两个任务_按照先进先出策略调度_正常 -*********************************************************************************************************/ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - - -pthread_barrier_t bt_304; //by zrr bind - -pthread_t main_thread14_304; -pthread_t main_thread15_304; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk gjb_printk - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - - -void *main_task_thread14_tms_304(void *arg) -{ - volatile int i = 0, j = 0, k = 0; - - while (k < 100) { - for (i = 0; i < 10000; ++i) { - for (j = 0; j < 2000; ++j) { - - } - } - - GJB_PRT_INFO("(%d)running main_thread14..\n", k); - - k++; - } - - GJB_PRT_INFO("END main_thread14..\n"); - - return (NULL); -} - -void *main_task_thread15_tms_304(void *arg) -{ - volatile int i = 0, j = 0, k = 0; - - while (k < 100) { - for (i = 0; i < 10000; ++i) { - for (j = 0; j < 2000; ++j) { - - } - } - - GJB_PRT_INFO("(%d)running main_thread15..\n", k); - - k++; - } - - GJB_PRT_INFO("END main_thread15..\n"); - - return (NULL); -} - -int test10_tms_304 (void) -{ - int status; - struct sched_param param; - - pthread_attr_t main_attr14; - pthread_attr_init( &main_attr14 );/* 初始化attribute */ -// main_attr14.schedpolicy = SCHED_FIFO; /* 先进先出调度调度 */ -// main_attr14.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr14.schedparam.sched_priority = 5;/* thread 优先级为5 */ - - pthread_attr_setschedpolicy(&main_attr14,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr14,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr14, ¶m); - - - pthread_attr_t main_attr15; - pthread_attr_init( &main_attr15 );/* 初始化attribute */ -// main_attr15.schedpolicy = SCHED_FIFO; /* 先进先出调度调度 */ -// main_attr15.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr15.schedparam.sched_priority = 5;/* thread 优先级为5 */ - - pthread_attr_setschedpolicy(&main_attr15,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr15,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr15, ¶m); - - - status = pthread_create(&main_thread14_304, &main_attr14, main_task_thread14_tms_304, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread14\n"); - return -1; - } - - status = pthread_create(&main_thread15_304, &main_attr15, main_task_thread15_tms_304, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread15\n"); - return -1; - } - - binding(main_thread14_304, 0); - binding(main_thread15_304, 0); -// -// pthread_delay(1000 * 3); -// -// pthread_kill(main_thread14_304, SIGTERM); -// pthread_kill(main_thread15_304, SIGTERM); - - pthread_join(main_thread14_304,NULL); //等待任务结束 - pthread_join(main_thread15_304,NULL); //等待任务结束 - - return 0; -} -/********************************************************************** - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test10_tms_304();//先进先出调度策略_相同优先级的两个任务_按照先进先出策略调度_正常 - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_management/gjb_S0100201GN_1.c b/task_management/gjb_S0100201GN_1.c deleted file mode 100644 index 0931bc3..0000000 --- a/task_management/gjb_S0100201GN_1.c +++ /dev/null @@ -1,164 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100201GN_1.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建一个任务, 通过线程是否就绪判断线程是否被成功创建 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -typedef unsigned int u32; -typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -boolean pthread_is_ready(pthread_t thread) -{ - if (thread <= 0) - { - errno = ESRCH; - return ESRCH; - } - boolean ret = 1; - // ret=taskIsReady(thread); - return ret; -} - -/* - * 任务函数定义开始 - */ -void *main_task_thread1_1 (void *arg) -{ - int i; - - for(i = 0; i < 3; i++) { - printf("start main_thread...\n"); - } - - return (NULL); -} - -/* - * 任务创建测试 - */ -int test1_1 (void) -{ - int status; - boolean is_ready; - pthread_attr_t main_attr; - pthread_t main_thread; - struct sched_param param; - /* - * 防止系统认为该main_attr已初始化 - */ - memset(&main_attr, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr - */ - pthread_attr_init(&main_attr); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ - pthread_attr_setschedpolicy(&main_attr,SCHED_RR);//�����̵߳��Ȳ��� - //main_attr.schedpolicy = SCHED_RR; - pthread_attr_setinheritsched(&main_attr,PTHREAD_EXPLICIT_SCHED); - //main_attr.inheritsched = PTHREAD_EXPLICIT_SCHED; - param.sched_priority = 24; - pthread_attr_setschedparam(&main_attr, ¶m); - - status = pthread_create(&main_thread, &main_attr, main_task_thread1_1, NULL); - if(status != 0) { - printf("Error creating main_thread\n"); - return -1; - - } else { - printf("thread create success\n"); - } - - binding(main_thread, 0); - - is_ready = pthread_is_ready(main_thread); - if(is_ready == TRUE) { - printf("thread create success\n"); - - } else { - printf("main_thread is not ready\n"); - pthread_join(main_thread, NULL); - return -1; - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test1_1(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - - -} diff --git a/task_management/gjb_S0100201GN_2.c b/task_management/gjb_S0100201GN_2.c deleted file mode 100644 index 8782afe..0000000 --- a/task_management/gjb_S0100201GN_2.c +++ /dev/null @@ -1,203 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100201GN_2.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建一个任务, 并判断不是当前线程 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -typedef unsigned int u32; -typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 - - -pthread_t main_thread_tm_2012; - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - - -/* - * 任务函数定义开始 - */ -void *main_task_thread1_2_tm_2012(void *arg) -{ - int i; - pthread_t thread_id; - int status; - - for(i = 0; i < 3; i++) { - printf("start main_thread.\n"); - } - - /* - * 获取了当前线程ID - */ - thread_id = pthread_self(); - - errno = 0; - - /* - * 判断两个 posix 线程是否相同 - */ - status = pthread_equal(main_thread_tm_2012, thread_id); - if (status == 0) { - printf("main_thread and pthread_self is not equal in main_task_thread\n"); - return (void *)(-1); - - } else { - printf("main_thread and pthread_self is equal in main_task_thread\n"); - } - - sleep(2); - - /* - * 任务退出 - */ - pthread_exit(0); - - return (NULL); -} - -/* - * 任务创建测试 - */ -int test1_2_tm_2012() -{ - int status; - pthread_attr_t main_attr; - pthread_t thread_id; - struct sched_param param; - - /* - * 防止系统认为该main_attr已初始化 - */ - memset(&main_attr, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr - */ - pthread_attr_init(&main_attr); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ - - pthread_attr_setschedpolicy(&main_attr,SCHED_RR);//�����̵߳��Ȳ��� - //main_attr.schedpolicy = SCHED_RR; - pthread_attr_setinheritsched(&main_attr,PTHREAD_EXPLICIT_SCHED); - //main_attr.inheritsched = PTHREAD_EXPLICIT_SCHED; - param.sched_priority = 24; - pthread_attr_setschedparam(&main_attr, ¶m); - - -// main_attr.schedpolicy = SCHED_RR; -// main_attr.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr.schedparam.sched_priority = 24; - - - - - - status = pthread_create(&main_thread_tm_2012, &main_attr, main_task_thread1_2_tm_2012, NULL); - if(status != 0) { - printf("Error creating main_thread\n"); - return -1; - - } else { - printf("thread create success\n"); - } - - binding(main_thread_tm_2012, 0); - - /* - * 获取了main主线程ID - */ - thread_id = pthread_self(); - - errno = 0; - status = -1; - - status = pthread_equal(main_thread_tm_2012, thread_id); - if(status == 0) { - printf("main_thread and pthread_self is not equal\n"); - - } else { - printf("main_thread and pthread_self is equal\n"); - pthread_join(main_thread_tm_2012, NULL); - return -1; - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread_tm_2012, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test1_2_tm_2012(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - - } else { - printf("task success\n"); - return (0); - - } -} diff --git a/task_management/gjb_S0100201GN_3.c b/task_management/gjb_S0100201GN_3.c deleted file mode 100644 index 342eec8..0000000 --- a/task_management/gjb_S0100201GN_3.c +++ /dev/null @@ -1,196 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100201GN_3.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建一个任务, 并分析线程ID 是有效线程 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 - - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} -int pthread_verifyid(pthread_t thread) -{ - int ret; - if (thread == -1) - return -1; - ret = pthread_kill(thread, 0); - printf("pthread_verifyid %d\n", ret); - switch (ret) { - case ESRCH: - return -1; - break; - default: - break; - } - return ret; -} - -/* - * 任务函数定义开始 - */ -void *main_task_thread1_3 (void *arg) -{ - int i; - - for(i = 0; i < 3; i++) { - printf("start main_thread...\n"); - } - - /* - * 任务退出 - */ - //pthread_exit(0); - - return (NULL); -} - -/* - * 任务创建测试 - */ -int test1_3 (void) -{ - int status; - pthread_t thread_temp = -1; - pthread_attr_t main_attr; - pthread_t main_thread; - struct sched_param param; - - /* - * 防止系统认为该main_attr已初始化 - */ - memset(&main_attr, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr - */ - pthread_attr_init(&main_attr); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ - // main_attr.schedpolicy = SCHED_RR; - // main_attr.inheritsched = PTHREAD_EXPLICIT_SCHED; - // main_attr.schedparam.sched_priority = 24; - pthread_attr_setschedpolicy(&main_attr,SCHED_RR);//�����̵߳��Ȳ��� - //main_attr.schedpolicy = SCHED_RR; - pthread_attr_setinheritsched(&main_attr,PTHREAD_EXPLICIT_SCHED); - //main_attr.inheritsched = PTHREAD_EXPLICIT_SCHED; - param.sched_priority = 24; - pthread_attr_setschedparam(&main_attr, ¶m); - - - - status = pthread_create(&main_thread, &main_attr, main_task_thread1_3, NULL); - if(status != 0) { - printf("Error creating main_thread\n"); - return -1; - - } else { - printf("thread create success\n"); - } - - binding(main_thread, 0); - - status = -1; - - status = pthread_verifyid(main_thread); - printf("status %d\n", status); - if (status != 0) { - printf("main_thread ID Invalid\n"); - pthread_join(main_thread, NULL); - return -1; - - } else { - printf("main_thread ID valid\n"); - } - - status = -1; - - status = pthread_verifyid(thread_temp); - printf("status %d\n", status); - if (status == -1) { - printf("thread_temp ID Invalid\n"); - - } else { - printf("thread_temp ID valid\n"); - pthread_join(main_thread, NULL); - return -1; - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread,NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test1_3(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - - } else { - printf("task success\n"); - return (0); - - } -} diff --git a/task_management/gjb_S0100201GN_4.c b/task_management/gjb_S0100201GN_4.c deleted file mode 100644 index e1d736f..0000000 --- a/task_management/gjb_S0100201GN_4.c +++ /dev/null @@ -1,143 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100201GN_4.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建一个任务, 查看运行打印 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - - -/* - * 任务函数定义开始 - */ -void *main_task_thread_tm_2014(void *arg) -{ - int i; - - for(i = 0; i < 3; i++) { - printf("start main_thread...\n"); - } - - /* - * 任务退出 - */ - pthread_exit(0); - - return (NULL); -} - -/* - * 任务创建测试 - */ -int test1_tm_2014 (void) -{ - int status; - pthread_attr_t main_attr; - pthread_t main_thread; - struct sched_param param; - - /* - * 防止系统认为该main_attr已初始化 - */ - memset(&main_attr, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr - */ - pthread_attr_init(&main_attr); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ - pthread_attr_setschedpolicy(&main_attr,SCHED_RR); - pthread_attr_setinheritsched(&main_attr,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 24; - pthread_attr_setschedparam(&main_attr, ¶m); - - status = pthread_create(&main_thread, &main_attr, main_task_thread_tm_2014, NULL); - if(status != 0) { - printf("Error creating main_thread\n"); - return -1; - - } else { - printf("thread create success\n"); - } - - binding(main_thread, 0); - - /* - * 等待任务结束 - */ - pthread_join(main_thread,NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test1_tm_2014(); - if (result != 0) { - printf("task failed\n"); - return (-1); - } else { - printf("task success\n"); - return (0); - } -} diff --git a/task_management/gjb_S0100201GN_5.c b/task_management/gjb_S0100201GN_5.c deleted file mode 100644 index cab0009..0000000 --- a/task_management/gjb_S0100201GN_5.c +++ /dev/null @@ -1,255 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100201GN_5.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建三个任务并设置不同的优先级, 查看运行打印 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 - - - -pthread_barrier_t bt_S0100201GN_5; - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - - -void *main_task_thread_S0100201GN_5(void *arg) -{ - int i; - for(i = 0; i < 3; i++) { - printf("start main_thread...\n"); - } - - /* - * 任务退出 - */ - pthread_exit(0); -} - -void *main_task_thread1_S0100201GN_5(void *arg) -{ - int i; - - for(i = 0; i < 3; i++) { - printf("start main_thread1...\n"); - } - - /* - * 任务退出 - */ - pthread_exit(0); -} - -void *main_task_thread2_S0100201GN_5(void *arg) -{ - int i; - - for(i = 0; i < 3; i++) { - printf("start main_thread2...\n"); - } - - /* - * 任务退出 - */ - pthread_exit(0); -} - -/* - * 任务创建测试_多个任务_串行创建成功 - */ -int test2_S0100201GN_5() -{ - int status; - pthread_t main_thread; - pthread_attr_t main_attr; - pthread_t main_thread1; - pthread_attr_t main_attr1; - pthread_t main_thread2; - pthread_attr_t main_attr2; - struct sched_param param; - - - memset(&main_attr, 0, sizeof(pthread_attr_t)); - memset(&main_attr1, 0, sizeof(pthread_attr_t)); - memset(&main_attr2, 0, sizeof(pthread_attr_t)); - - /* - * 创建(初始化)线程屏障 - */ - pthread_barrier_init(&bt_S0100201GN_5, NULL, 4); - - /* - * 初始化main_attr - */ - pthread_attr_init(&main_attr); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr.schedpolicy = SCHED_RR; -// main_attr.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr.schedparam.sched_priority = 15; - - - pthread_attr_setschedpolicy(&main_attr,SCHED_RR); - pthread_attr_setinheritsched(&main_attr,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 15; - pthread_attr_setschedparam(&main_attr, ¶m); - - - - /* - * 初始化main_attr1 - */ - pthread_attr_init(&main_attr1); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr1.schedpolicy = SCHED_RR; -// main_attr1.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr1.schedparam.sched_priority = 24; - - pthread_attr_setschedpolicy(&main_attr1,SCHED_RR); - pthread_attr_setinheritsched(&main_attr1,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 24; - pthread_attr_setschedparam(&main_attr1, ¶m); - - - /* - * 初始化main_attr2 - */ - pthread_attr_init(&main_attr2); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr2.schedpolicy = SCHED_RR; -// main_attr2.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr2.schedparam.sched_priority = 16; - - pthread_attr_setschedpolicy(&main_attr2,SCHED_RR); - pthread_attr_setinheritsched(&main_attr2,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 16; - pthread_attr_setschedparam(&main_attr2, ¶m); - - /* - * 任务一 - */ - status = pthread_create(&main_thread, &main_attr, main_task_thread_S0100201GN_5, NULL); - if(status != 0) { - printf("Error creating main_thread.\n"); - return -1; - - } else { - printf("main_thread create success.\n"); - } - - status = -1; - /* - * 任务二 - */ - status = pthread_create(&main_thread1, &main_attr1, main_task_thread1_S0100201GN_5, NULL); - if(status != 0) { - printf("Error creating main_thread1.\n"); - return -1; - - } else { - printf("main_thread1 create success.\n"); - } - - status = -1; - /* - * 任务三 - */ - status = pthread_create(&main_thread2, &main_attr2, main_task_thread2_S0100201GN_5, NULL); - if(status != 0) { - printf("Error creating main_thread2.\n"); - return -1; - - } else { - printf("main_thread2 create success.\n"); - } - - binding(main_thread, 0); - binding(main_thread1, 0); - binding(main_thread2, 0); - - /* - * 等待任务结束 - */ - pthread_join(main_thread, NULL); - pthread_join(main_thread1, NULL); - pthread_join(main_thread2, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test2_S0100201GN_5(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - - } else { - printf("task success\n"); - return (0); - - } -} diff --git a/task_management/gjb_S0100201GN_6.c b/task_management/gjb_S0100201GN_6.c deleted file mode 100644 index d064f1b..0000000 --- a/task_management/gjb_S0100201GN_6.c +++ /dev/null @@ -1,217 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100201GN_6.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建2个任务, 查看运行打印 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - - -void *main_task_thread1_S0100201GN_6(void *arg) -{ - int i; - - for(i = 0; i < 3; i++) { - printf("start main_thread1...\n"); - } - - /* - * 任务退出 - */ - pthread_exit(0); - - return (NULL); -} - -/* - * 任务二函数定义开始,在任务1中嵌套创建任务2 - */ -void *main_task_thread_S0100201GN_6(void *arg) -{ - int i; - int status; - pthread_t main_thread1; - pthread_attr_t main_attr1; - struct sched_param param; - - for(i = 0; i < 3; i++) { - printf("start main_thread...\n"); - } - - /* - * 防止系统认为该main_attr1已初始化 - */ - memset(&main_attr1, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr1 - */ - pthread_attr_init(&main_attr1); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr1.schedpolicy = SCHED_RR; -// main_attr1.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr1.schedparam.sched_priority = 15; - - pthread_attr_setschedpolicy(&main_attr1,SCHED_RR); - pthread_attr_setinheritsched(&main_attr1,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 15; - pthread_attr_setschedparam(&main_attr1, ¶m); - - - - status = pthread_create(&main_thread1, NULL, main_task_thread1_S0100201GN_6, NULL); - if(status != 0) { - printf("Error creating main_thread1.\n"); - return (void *)(-1); - - } else { - printf("main_thread1 create success.\n"); - } - - /* - * AICOS ADD 等待线程 main_thread1 退出 - */ - pthread_join(main_thread1, NULL); - - /* - * 任务退出 - */ - pthread_exit(0); - - return (NULL); -} - -/* - * 任务一 -*/ -int test3_S0100201GN_6 (void) -{ - int status; - pthread_t main_thread; - pthread_attr_t main_attr; - void *join_s = NULL; - struct sched_param param; - - /* - * 防止系统认为该main_attr已初始化 - */ - memset(&main_attr, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr - */ - pthread_attr_init(&main_attr); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr.schedpolicy = SCHED_RR; -// main_attr.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr.schedparam.sched_priority = 24; - - pthread_attr_setschedpolicy(&main_attr,SCHED_RR); - pthread_attr_setinheritsched(&main_attr,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 24; - pthread_attr_setschedparam(&main_attr, ¶m); - - - status = pthread_create(&main_thread, &main_attr, main_task_thread_S0100201GN_6, NULL); - if(status != 0) { - printf("Error creating main_thread.\n"); - return -1; - - } else { - printf("main_thread create success.\n"); - } - - binding(main_thread, 0); - - /* - * 等待任务结束 - */ - pthread_join(main_thread, &join_s); - - if ((long)join_s != 0) { - printf("main_thread exit fail.\n"); - return -1; - - } else { - printf("main_thread exit success.\n"); - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test3_S0100201GN_6(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100202GN_1.c b/task_management/gjb_S0100202GN_1.c deleted file mode 100644 index 3af7199..0000000 --- a/task_management/gjb_S0100202GN_1.c +++ /dev/null @@ -1,291 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100202GN_1.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建2个任务, 验证线程将在取消点被取消 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -typedef unsigned int u32; -typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 - - - -static int testcancel_S0100202GN_1 = 0; - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - //g_pthread_delay_tick = ticks; - sched_yield(); -// if(is_set_sys_rate) -// { -// return usleep(g_sys_uleep_tick * ticks); -// } -// else - { - return usleep(SYSTEM_TICKS_USEC * ticks); - } -} - - - -static void *main_task_thread3 (void *arg) -{ - volatile int i = 0, j = 0; - - printf("start main_thread3...\n"); - - for (i = 0; i < 10000; ++i) { - for (j = 0; j < 2000; ++j) { - } - } - - while(1) { - testcancel_S0100202GN_1 = 3; - /* - * 测试任务是否被取消 - */ - pthread_testcancel(); - } - - return (NULL); -} - -static void *main_task_thread4 (void *arg) -{ - volatile int i = 0, j = 0; - - printf("start main_thread4...\n"); - - for (i = 0; i < 10000; ++i) { - for (j = 0; j < 2000; ++j) { - } - } - - while(1) { - /* - * 测试任务是否被取消 - */ - pthread_testcancel(); - testcancel_S0100202GN_1 = 3; //3 or 4 - } - - return (NULL); -} - -/* - * 删除任务_两个任务_放置取消点_线程取消信号发送成功_线程终止成功 - */ -int test4 (void) -{ - int status; - pthread_t main_thread3; - pthread_attr_t main_attr3; - pthread_t main_thread4; - pthread_attr_t main_attr4; - struct sched_param param; - - memset(&main_attr3, 0, sizeof(pthread_attr_t)); - memset(&main_attr4, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr3 - */ - pthread_attr_init(&main_attr3); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr3.schedpolicy = SCHED_RR; -// main_attr3.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr3.schedparam.sched_priority = 24; - - pthread_attr_setschedpolicy(&main_attr3,SCHED_RR); - pthread_attr_setinheritsched(&main_attr3,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 24; - pthread_attr_setschedparam(&main_attr3, ¶m); - - - /* - * 初始化main_attr4 - */ - pthread_attr_init(&main_attr4); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr4.schedpolicy = SCHED_RR; -// main_attr4.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr4.schedparam.sched_priority = 15; - - pthread_attr_setschedpolicy(&main_attr4,SCHED_RR); - pthread_attr_setinheritsched(&main_attr4,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 15; - pthread_attr_setschedparam(&main_attr4, ¶m); - - - - status = pthread_create(&main_thread3, &main_attr3, main_task_thread3, NULL); - if (status != 0) { - printf("Error creating main_thread3.\n"); - return -1; - - } else { - printf("main_thread3 create success.\n"); - } - - status = -1; - - binding(main_thread3, 0); - - pthread_delay(1); - - /* - * 取消线程信号,返回0表示函数发送取消信号成功,发送成功并不意味着thread会终止,Main依旧往下运行 - */ - status = pthread_cancel(main_thread3); - if (status == 0) { - printf("main_thread3 cancel request successfully\n"); - - } else { - printf("main_thread3 cancel request fail.\n"); - pthread_join(main_thread3, NULL); - return -1; - } - - status = -1; - /* - * 等待任务结束,这语句很重要“等待线程找到取消点时取消线程,终止线程” - */ - pthread_join(main_thread3, NULL); - - printf("main_thread3 cancel successfully! cancel : %d\n", testcancel_S0100202GN_1); - - /* - * 取消标志判断 - */ - if (testcancel_S0100202GN_1 != 3) { - printf("cancel should equal 3.\n"); - return -1; - - } else { - printf("cancel equal 3.\n"); - } - - status = pthread_create(&main_thread4, &main_attr4, main_task_thread4, NULL); - if (status != 0) { - printf("Error creating main_thread4.\n"); - return -1; - - } else { - printf("main_thread4 create success.\n"); - } - - status = -1; - - binding(main_thread4, 0); - - pthread_delay(1); - - /* - * 取消线程信号,返回0表示函数发送取消信号成功,发送成功并不意味着thread会终止。 - */ - status = pthread_cancel(main_thread4); - if (status == 0) { - printf("main_thread4 cancel request successfully\n"); - - } else { - printf("main_thread4 cancel request fail.\n"); - pthread_join(main_thread4, NULL); - return -1; - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread4, NULL); - - printf("main_thread4 cancel successfully! cancel : %d\n", testcancel_S0100202GN_1); - - /* - * 取消标志判断 - */ - if (testcancel_S0100202GN_1 == 4) { - printf("cancel not should equal 4.\n"); - return -1; - - } else { - printf("cancel = %d\n", testcancel_S0100202GN_1); - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test4(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100202GN_10.c b/task_management/gjb_S0100202GN_10.c deleted file mode 100644 index 8509ad4..0000000 --- a/task_management/gjb_S0100202GN_10.c +++ /dev/null @@ -1,174 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100202GN_10.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建1个任务, 设置函数清理函数并验证清理函数并调用 (并主动调用) -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - - -void clean_fun1_S0100202GN_10(void *arg) -{ - printf("cleanup :%s\n", (char *)arg);; -} - -void clean_fun2_S0100202GN_10(void *arg) -{ - printf("cleanup :%s\n", (char *)arg);; -} - -/* - * 删除任务_pthread_exit线程退出后需要执行的清理函数_正常 - */ -void *main_task_thread32_S0100202GN_10(void *arg) -{ - printf("main_thread32 start...\n"); - - pthread_cleanup_push((void*)clean_fun1_S0100202GN_10,"main_thread32 first handler."); - pthread_cleanup_push((void*)clean_fun2_S0100202GN_10,"main_thread32 second handler."); - - printf("main_thread32 push complete.\n"); - - if (arg) { - return (void *)1; - } - - /* - * 参数为0表示不调用清理函数,清理函数是为了做解锁资源的,防止资源死锁, - * 运行到pthread_cleanup_pop表示程序正确运行这时参数一般设为0不调用清理函数 - */ - pthread_cleanup_pop(0); - pthread_cleanup_pop(0); - - return (void *)1; -} - -/* - * 删除任务_pthread_exit线程退出后需要执行的清理函数_正常 - */ -int test24_S0100202GN_10 (void) -{ - int status; - pthread_t main_thread32; - pthread_attr_t attr; - void *tret = NULL; - - /* - * 防止系统认为该attr已初始化 - */ - memset(&attr, 0, sizeof(pthread_attr_t)); - - /* - * 初始化attr - */ - status = pthread_attr_init(&attr); - if ( status != 0) { - printf("pthread_attr_init ERROR.\n"); - return -1; - - } else { - printf("pthread_attr_init success.\n"); - } - - status = -1; - - status = pthread_create(&main_thread32, &attr, main_task_thread32_S0100202GN_10, (void *)1); - if (status != 0) { - printf("Error creating main_thread32.\n"); - return -1; - - } else { - printf("main_thread32 create success.\n"); - } - - binding(main_thread32, 0); - - status = -1; - /* - * 等待任务结束 - */ - status = pthread_join(main_thread32, &tret); - if(status != 0) { - printf("Error pthread_join.\n"); - return -1; - - } else { - printf("pthread_join success.\n"); - } - - printf("main_thread32 exit code %d\n", (int)(long)tret); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test24_S0100202GN_10(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100202GN_11.c b/task_management/gjb_S0100202GN_11.c deleted file mode 100644 index 22d929f..0000000 --- a/task_management/gjb_S0100202GN_11.c +++ /dev/null @@ -1,169 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100202GN_11.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建1个任务, 设置函数清理函数并验证清理函数并调用 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -void clean_fun1_S0100202GN_11(void *arg) -{ - printf("cleanup :%s\n",(char *)arg); -} - -void clean_fun2_S0100202GN_11(void *arg) -{ - printf("cleanup :%s\n",(char *)arg); -} - -/* - * 删除任务_pthread_exit线程退出后需要执行的清理函数_正常 - */ -void *main_task_thread32_S0100202GN_11(void *arg) -{ - printf("main_thread32 start...\n"); - - pthread_cleanup_push(clean_fun1_S0100202GN_11,"main_thread32 first handler."); - pthread_cleanup_push(clean_fun2_S0100202GN_11,"main_thread32 second handler."); - - printf("main_thread32 push complete.\n"); - - /* - * 参数为1表示调用清理函数 - */ - pthread_cleanup_pop(1); - pthread_cleanup_pop(1); - - return (void *)1; -} - -/* - * 删除任务_pthread_exit线程退出后需要执行的清理函数_正常 - */ -int test24_S0100202GN_11 (void) -{ - int status; - pthread_t main_thread32; - pthread_attr_t attr; - void *tret = NULL; - - /* - * 防止系统认为该attr已初始化 - */ - memset(&attr, 0, sizeof(pthread_attr_t)); - - /* - * 初始化attr - */ - status = pthread_attr_init(&attr); - if(status != 0) { - printf("pthread_attr_init ERROR.\n"); - return -1; - - } else { - printf("pthread_attr_init success\n"); - } - - status = -1; - - status = pthread_create(&main_thread32, &attr, main_task_thread32_S0100202GN_11, (void *)1); - if(status != 0) { - printf("Error creating main_thread32.\n"); - return -1; - - } else { - printf("main_thread32 create success\n"); - } - - status = -1; - - binding(main_thread32, 0); - - /* - * 等待任务结束 - */ - status = pthread_join(main_thread32, &tret); - if(status != 0) { - printf("Error pthread_join.\n"); - return -1; - - } else { - printf("pthread_join success.\n"); - } - - printf("main_thread32 exit code %d\n", (int)(long)tret); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test24_S0100202GN_11(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100202GN_12.c b/task_management/gjb_S0100202GN_12.c deleted file mode 100644 index 9911ffa..0000000 --- a/task_management/gjb_S0100202GN_12.c +++ /dev/null @@ -1,211 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100202GN_12.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建1个任务, 并强制取消线程, 线程将在取消点被取消 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - //g_pthread_delay_tick = ticks; - sched_yield(); -// if(is_set_sys_rate) -// { -// return usleep(g_sys_uleep_tick * ticks); -// } -// else - { - return usleep(SYSTEM_TICKS_USEC * ticks); - } -} -int pthread_cancelforce(pthread_t thread) -{ - if(thread == -1) - return -1; - pthread_cancel(thread); - return 0; -} - - -/* - * 删除任务_设置任务取消状态_状态为pthread_CANCEL_DISABLE不可取消_成功 - */ -void *main_task_thread30_S0100202GN_12(void *arg) -{ - int status; - int i = 1; - int oldstate = 3; - - printf("start main_thread30...\n"); - - /* - * 设置取消线程是否使能 - */ - status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate); - if(status != 0) { - printf("pthread_setcancelstate failed.\n"); - return (void *)(-1); - - } else { - printf("pthread_setcancelstate successfully! old state is %d\n",oldstate); - } - - while(1) { - i++; - if(i %= 10) { - /* - * 在取消点取消 - */ - pthread_testcancel(); - } - } - - return (void *)100; -} - -/* - * 删除任务_设置任务取消状态_状态为pthread_CANCEL_DISABLE不可取消_成功 - */ -int test22_S0100202GN_12 (void) -{ - int status; - pthread_t main_thread30; - pthread_attr_t attr; - struct sched_param param; - - /* - * 初始化attr - */ - status = pthread_attr_init(&attr); - if(status != 0) { - printf("pthread_attr_init ERROR\n"); - return -1; - - } else { - printf("pthread_attr_init success.\n"); - } - - status = -1; - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// attr.schedpolicy = SCHED_RR; -// attr.inheritsched = PTHREAD_EXPLICIT_SCHED; -// attr.schedparam.sched_priority = 55; - - pthread_attr_setschedpolicy(&attr,SCHED_RR); - pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 55; - pthread_attr_setschedparam(&attr, ¶m); - - - status = pthread_create(&main_thread30, &attr, main_task_thread30_S0100202GN_12, NULL); - if(status != 0) { - printf("Error creating main_thread30.\n"); - return -1; - - } else { - printf("main_thread30 create success.\n"); - } - - binding(main_thread30, 0); - - /* - * 延时10 TICK - */ - pthread_delay(10); - - /* - * 删除任务_pthread_cancelforce强制取消任务_正常 - */ - if (pthread_cancelforce(main_thread30) != 0) { - printf("pthread_cancelforce main_thread30 - error!\n"); - pthread_join(main_thread30, NULL); - return -1; - - } else { - printf("pthread_cancelforce main_thread30 - successfully!\n"); - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread30, NULL); - - printf("main_thread30 exit successfully\n"); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test22_S0100202GN_12(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100202GN_2.c b/task_management/gjb_S0100202GN_2.c deleted file mode 100644 index 76837c4..0000000 --- a/task_management/gjb_S0100202GN_2.c +++ /dev/null @@ -1,189 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100202GN_2.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建1个任务, 并取消自己 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 - - - -static pthread_t main_thread5_tm_2022; -static int status1_tm_2022; -static int testcancel_S0100202GN_2 = 0; - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - //g_pthread_delay_tick = ticks; - sched_yield(); -// if(is_set_sys_rate) -// { -// return usleep(g_sys_uleep_tick * ticks); -// } -// else - { - return usleep(SYSTEM_TICKS_USEC * ticks); - } -} - - - -void *main_task_thread5(void *arg) -{ - int i; - - for(i = 0; i < 10; i++) { - printf("start main_thread5...\n"); - - if(i == 0) { - /* - * 取消自身线程 - */ - status1_tm_2022 = pthread_cancel(main_thread5_tm_2022); - if(status1_tm_2022 == 0) { - printf("main_thread5 cancel request successfully.\n"); - - } else { - printf("ain_thread5 cancel request fail.\n"); - return (void *)(-1); - } - - pthread_delay(1); - - /* - * 测试任务是否被取消 - */ - pthread_testcancel(); - testcancel_S0100202GN_2 = 3; - } - } - - return (NULL); -} - -/* - * 删除任务_自身删除自身任务_放置取消点_线程取消信号成功_线程终止成功 - */ -int test5_tm_2022() -{ - int status; - pthread_attr_t main_attr5; - struct sched_param param; - - /* - * 初始化main_attr5 - */ - pthread_attr_init(&main_attr5); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr5.schedpolicy = SCHED_RR; -// main_attr5.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr5.schedparam.sched_priority = 24; - - pthread_attr_setschedpolicy(&main_attr5,SCHED_RR); - pthread_attr_setinheritsched(&main_attr5,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 24; - pthread_attr_setschedparam(&main_attr5, ¶m); - - - - - status = pthread_create(&main_thread5_tm_2022, &main_attr5, main_task_thread5, NULL); - if(status != 0) { - printf("Error creating main_thread5\n"); - return -1; - - } else { - printf("main_thread5 create success.\n"); - } - - binding(main_thread5_tm_2022, 0); - - /* - * 等待任务结束 - */ - pthread_join(main_thread5_tm_2022, NULL); - - if (testcancel_S0100202GN_2 == 3) { - printf("main_thread5 cancel fail\n"); - return -1; - - } else{ - printf("main_thread5 cancel successfully\n"); - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test5_tm_2022(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100202GN_3.c b/task_management/gjb_S0100202GN_3.c deleted file mode 100644 index 6687e50..0000000 --- a/task_management/gjb_S0100202GN_3.c +++ /dev/null @@ -1,194 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100202GN_3.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建1个任务, 线程中不设置取消点, 线程不能取消 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 - - - -static int cancel_flag_tm_2023 = 0; - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - //g_pthread_delay_tick = ticks; - sched_yield(); -// if(is_set_sys_rate) -// { -// return usleep(g_sys_uleep_tick * ticks); -// } -// else - { - return usleep(SYSTEM_TICKS_USEC * ticks); - } -} - - - -void *main_task_thread28_tm_2023(void *arg) -{ - int i=1; - volatile long long j; - - printf("start main_thread28...\n"); - - for (j = 0; j < 100000000; j++) { - i++; - } - - /* - * AICOS ADD 没有被取消最终会走到这里,只是能够让该用例退出 - */ - cancel_flag_tm_2023 = 1; - - return (NULL); -} - -/* - * 删除任务_单一任务_未放置取消点_线程取消信号发送成功_线程没有终止 - */ -int test19_tm_2023 (void) -{ - int status; - pthread_attr_t main_attr; - pthread_t main_thread28; - struct sched_param param; - - /* - * 初始化main_attr - */ - pthread_attr_init(&main_attr); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr.schedpolicy = SCHED_RR; -// main_attr.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr.schedparam.sched_priority = 55; - - pthread_attr_setschedpolicy(&main_attr,SCHED_RR); - pthread_attr_setinheritsched(&main_attr,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 55; - pthread_attr_setschedparam(&main_attr, ¶m); - - - - - status = pthread_create(&main_thread28, &main_attr, main_task_thread28_tm_2023, NULL); - if(status != 0) { - printf("Error creating main_thread28.\n"); - return -1; - - } else { - printf("main_thread28 create success.\n"); - } - - status = -1; - - binding(main_thread28, 0); - - /* - * 延时1 TICK - */ - pthread_delay(1); - - /* - * 取消线程信号,返回0表示函数发送取消信号成功,发送成功并不意味着thread会终止,Main依旧往下运行 - */ - status = pthread_cancel(main_thread28); - if (status == 0) { - printf("main_thread28 cancel request successfully.\n"); - - } else { - printf("main_thread28 cancel request fail.\n"); - return -1; - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread28, NULL); - - if (cancel_flag_tm_2023 == 1) { - printf("main_thread28 cancel successfully.\n"); - - } else { - printf("main_thread28 cancel fail.\n"); - return -1; - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test19_tm_2023(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100202GN_4.c b/task_management/gjb_S0100202GN_4.c deleted file mode 100644 index 03184e2..0000000 --- a/task_management/gjb_S0100202GN_4.c +++ /dev/null @@ -1,139 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100202GN_4.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建1个任务, 设置为主动退出 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - - - -void *main_task_thread29_tm_2024(void *arg) -{ - int i = 1; - - printf("start main_thread29...\n"); - - while(1) { - i++; - if (i == 10) { - /* - * 退出线程返回到等待该任务的结束的线程处,接收传过来的值 - */ - pthread_exit((void *)100); - } - } - - return (NULL); -} - -/* - * 删除任务_线程退出成功_线程终止 - */ -int test20_tm_2024 (void) -{ - int status; - pthread_t main_thread29; - void *value_ptr = NULL; - - /* - * 线程创建 - */ - status = pthread_create(&main_thread29, NULL, main_task_thread29_tm_2024, NULL); - if(status != 0) { - printf("Error creating main_thread29.\n"); - return -1; - - } else { - printf("main_thread29 create success.\n"); - } - - binding(main_thread29, 0); - - /* - * 等待任务结束,value_ptr接收退出线程传过来的返回值"100",这是exit返回的 - */ - pthread_join(main_thread29,(void*)&value_ptr); - - if((long)value_ptr == 100) { - printf("main_thread29 exit successfully.\n"); - - } else { - printf("main_thread29 exit failed.\n"); - return -1; - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test20_tm_2024(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100202GN_5.c b/task_management/gjb_S0100202GN_5.c deleted file mode 100644 index 26b88ed..0000000 --- a/task_management/gjb_S0100202GN_5.c +++ /dev/null @@ -1,205 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100202GN_5.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建1个任务, 任务中设置取消点,并取消线程, 线程可以在取消点被取消 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - //g_pthread_delay_tick = ticks; - sched_yield(); -// if(is_set_sys_rate) -// { -// return usleep(g_sys_uleep_tick * ticks); -// } -// else - { - return usleep(SYSTEM_TICKS_USEC * ticks); - } -} - -void *main_task_thread30_tm_2025 (void *arg) -{ - int status; - int i = 1; - int oldstate = 3; - - printf("start main_thread30...\n"); - - /* - * 设置取消线程是否使能,0 - */ - status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate); - if(status != 0) { - printf("pthread_setcancelstate failed.\n"); - return (void *)(-1); - - } else { - printf("pthread_setcancelstate successfully. old state : %d\n", oldstate); - } - - while(1) { - i++; - if (i %= 10) - { - pthread_testcancel(); - } - } - - return (void *)(0); -} - -/* - * 删除任务_设置任务取消状态_状态为pthread_CANCEL_DISABLE可取消_成功 - */ -int test22_tm_2025 (void) -{ - int status; - pthread_t main_thread30; - pthread_attr_t attr; - struct sched_param param; - - /* - * 初始化attr - */ - status = pthread_attr_init(&attr); - if(status != 0) { - printf("pthread_attr_init ERROR\n"); - return -1; - - } else { - printf("pthread_attr_init success\n"); - } - - status = -1; - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// attr.schedpolicy = SCHED_RR; -// attr.inheritsched = PTHREAD_EXPLICIT_SCHED; -// attr.schedparam.sched_priority = 55; - - pthread_attr_setschedpolicy(&attr,SCHED_RR); - pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 55; - pthread_attr_setschedparam(&attr, ¶m); - - - /* - * 线程创建 - */ - status = pthread_create(&main_thread30, &attr, main_task_thread30_tm_2025, NULL); - if(status != 0) { - printf("Error creating main_thread30\n"); - return -1; - - } else { - printf("creating main_thread30 success\n"); - } - - status = -1; - - binding(main_thread30, 0); - - /* - * 延时10 TICK - */ - pthread_delay(10); - - /* - * 取消自身线程 - */ - status = pthread_cancel(main_thread30); - if(status == 0) { - printf("main_thread30 cancel request successfully\n"); - - } else if (status == ESRCH) { - printf("main_thread30 cancel request failed\n"); - pthread_join(main_thread30, NULL); - return -1; - } - - status = -1; - /* - * 等待任务结束 - */ - pthread_join(main_thread30, NULL); - - printf("main_thread30 exit successfully\n"); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test22_tm_2025(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100202GN_6.c b/task_management/gjb_S0100202GN_6.c deleted file mode 100644 index d6eaed8..0000000 --- a/task_management/gjb_S0100202GN_6.c +++ /dev/null @@ -1,212 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100202GN_6.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建1个任务, 任务中设置取消点并设置任务为禁止取消,取消线程, 线程不可以被取消 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - //g_pthread_delay_tick = ticks; - sched_yield(); -// if(is_set_sys_rate) -// { -// return usleep(g_sys_uleep_tick * ticks); -// } -// else - { - return usleep(SYSTEM_TICKS_USEC * ticks); - } -} - -void *main_task_thread30_S0100202GN_6(void *arg) -{ - int status; - int i = 1; - int oldstate = 3; - - printf("start main_thread30...\n"); - - /* - * 设置取消线程是否使能,1 - */ - status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); - if(status != 0) { - printf("pthread_setcancelstate failed.\n"); - return (void *)(-1); - - } else { - printf("pthread_setcancelstate successfully! old state is %d\n", oldstate); - } - - while (1) { - i++; - if (!(i % 10)) { - /* - * 在取消点取消、每隔十次 - */ - pthread_testcancel(); - } - - /* - * 为了能够让用例正常退出 - */ - if (i >= 1000000) { - return (void *)(0); - } - } - return (void *)(-1); -} - -/* - * 删除任务_设置任务取消状态_状态为pthread_CANCEL_DISABLE不可取消_成功 - */ -int test22_S0100202GN_6 (void) -{ - int status; - void *join_s = NULL; - pthread_t main_thread30; - pthread_attr_t attr; - struct sched_param param; - - /* - * 初始化attr - */ - status = pthread_attr_init(&attr); - if (status != 0) { - printf("pthread_attr_init ERROR\n"); - return -1; - - } else { - printf("pthread_attr_init success\n"); - } - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// attr.schedpolicy = SCHED_RR; -// attr.inheritsched = PTHREAD_EXPLICIT_SCHED; -// attr.schedparam.sched_priority = 55; - - pthread_attr_setschedpolicy(&attr,SCHED_RR); - pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 55; - pthread_attr_setschedparam(&attr, ¶m); - - - status = pthread_create(&main_thread30, &attr, main_task_thread30_S0100202GN_6, NULL); - if (status != 0) { - printf("Error creating main_thread30\n"); - return -1; - - } else { - printf("creating main_thread30 success\n"); - } - - status = -1; - - binding(main_thread30, 0); - - pthread_delay(10); - - /* - * 取消自身线程 - */ - status = pthread_cancel(main_thread30); - if (status == 0) { - printf("main_thread30 cancel request successfully\n"); - - } else if (status == ESRCH) { - printf("main_thread30 cancel request failed\n"); - pthread_join(main_thread30, &join_s); - return -1; - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread30, &join_s); - - if ((int)(long)join_s == 0) { - printf("main_thread30 exit successfully\n"); - - } else { - printf("main_thread30 exit failed\n"); - return -1; - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test22_S0100202GN_6(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100202GN_7.c b/task_management/gjb_S0100202GN_7.c deleted file mode 100644 index 04cc71a..0000000 --- a/task_management/gjb_S0100202GN_7.c +++ /dev/null @@ -1,241 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100202GN_7.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建1个任务, 任务中首先禁止取消并设置为延时取消类型, 然后再设置为使能取消和异步取消方式, -** 主线程取消该线程, 判断该任务的返回值不是110. -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 - - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - //g_pthread_delay_tick = ticks; - sched_yield(); -// if(is_set_sys_rate) -// { -// return usleep(g_sys_uleep_tick * ticks); -// } -// else - { - return usleep(SYSTEM_TICKS_USEC * ticks); - } -} - - -void *main_task_thread31 (void *arg) -{ - int status; - int i = 1; - int oldstate = 3; - int oldtype = 3; - - /* - * 设置取消线程是否使能,1 - */ - status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); - if(status != 0) { - printf("pthread_setcancelstate failed.\n"); - return ((void *)110); - - } else { - printf("pthread_setcancelstate successfully:oldtype is %d\n", oldstate); - } - - status = -1; - /* - * 设置当前线程被动取消时的动作,0 - */ - status = pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype); - if (status != 0) { - printf("pthread_setcanceltype failed.\n"); - return ((void *)100); - - } else { - printf("pthread_setcanceltype successfully:oldtype is %d\n",oldtype); - } - - status = -1; - - printf("start main_thread31...\n"); - - status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate); - if (status != 0) { - printf("pthread_setcancelstate failed.\n"); - return ((void *)100); - - } else { - printf("pthread_setcancelstate successfully:oldstate is %d\n",oldstate); - } - - status = -1; - /* - * 设置当前线程被动取消时的动作,1 - */ - status = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); - if(status != 0) { - printf("pthread_setcanceltype failed.\n"); - return ((void *)100); - - } else { - printf("pthread_setcanceltype successfully:oldtype is %d\n",oldtype); - } - - while (1) { - i++; - if (i > 300000) { - sleep(1); - break; - } - } - - printf("thread exit.\n"); - - return (void *)110; -} - -/* - * 删除任务_设置任务取消类型_取消类型为PTHREAD_CANCEL_ASYNCHRONOUS_不需要设置取消点_立即取消成功 - */ -int test23 (void) -{ - int status; - pthread_t main_thread31; - pthread_attr_t attr; - void *join_s = NULL; - struct sched_param param; - - /* - * 初始化attr - */ - status = pthread_attr_init(&attr); - if (status != 0) { - printf("pthread_attr_init ERROR.\n"); - return -1; - - } else { - printf("pthread_attr_init success.\n"); - } - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// attr.schedpolicy = SCHED_RR; -// attr.inheritsched = PTHREAD_EXPLICIT_SCHED; -// attr.schedparam.sched_priority = 55; - - pthread_attr_setschedpolicy(&attr,SCHED_RR); - pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 55; - pthread_attr_setschedparam(&attr, ¶m); - - status = pthread_create(&main_thread31, &attr, main_task_thread31, NULL); - if(status != 0) { - printf("Error creating main_thread31.\n"); - return -1; - - } else { - printf("creating main_thread31 success.\n"); - } - - binding(main_thread31, 0); - - pthread_delay(100); - - status = pthread_cancel(main_thread31); - if (status == 0) { - printf("main_thread31 cancel request successfully.\n"); - - } else { - printf("main_thread31 cancel request fail.\n"); - pthread_join(main_thread31, &join_s); - return -1; - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread31, &join_s); - - if ((int)(long)join_s != 110) { - printf("main_thread31 exit successfully.\n"); - - } else { - printf("main_thread31 exit fail.\n"); - return -1; - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test23(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100202GN_8.c b/task_management/gjb_S0100202GN_8.c deleted file mode 100644 index f2fedad..0000000 --- a/task_management/gjb_S0100202GN_8.c +++ /dev/null @@ -1,250 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100202GN_8.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建1个任务, 任务中首先禁止取消并设置为延时取消类型, 然后再设置为使能取消和异步取消方式, -** 该线程中设置取消点, 主线程取消该线程, 判断该任务的返回值不是110. -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 - - - - void binding (pthread_t tid, int cpu) - { - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); - } - - int pthread_delay(int ticks) - { - //g_pthread_delay_tick = ticks; - sched_yield(); - // if(is_set_sys_rate) - // { - // return usleep(g_sys_uleep_tick * ticks); - // } - // else - { - return usleep(SYSTEM_TICKS_USEC * ticks); - } - } - - - -void *main_task_thread31_S0100202GN_8(void *arg) -{ - int status; - int i = 1; - int oldstate = 3; - int oldtype = 3; - - /* - * 设置取消线程是否使能,1 - */ - status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); - if(status != 0) { - printf("pthread_setcancelstate failed.\n"); - return ((void *)110); - - } else { - printf("pthread_setcancelstate successfully:oldtype is %d\n", oldstate); - } - - status = -1; - /* - * 设置当前线程被动取消时的动作,0 - */ - status = pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype); - if(status != 0) { - printf("pthread_setcanceltype failed.\n"); - return ((void *)110); - - } else { - printf("pthread_setcanceltype successfully:oldtype is %d\n", oldtype); - } - - printf("start main_thread31...\n"); - - status = -1; - /* - * 设置取消线程是否使能,0 - */ - status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate); - if(status != 0) { - printf("pthread_setcancelstate failed.\n"); - return ((void *)110); - - } else { - printf("pthread_setcancelstate successfully:oldstate is %d\n", oldstate); - } - - status = -1; - /* - * 设置当前线程被动取消时的动作,1 - */ - status = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); - if(status != 0) { - printf("pthread_setcanceltype failed.\n"); - return ((void *)110); - - } else { - printf("pthread_setcanceltype successfully:oldtype is %d\n", oldtype); - } - - while(1) { - i++; - if(i == 10) - { - pthread_testcancel(); - } - } - - return ((void *)100); -} - -/* - * 删除任务_设置任务取消类型_取消类型为PTHREAD_CANCEL_ASYNCHRONOUS_不需要设置取消点_立即取消成功 - */ -int test23_S0100202GN_8 (void) -{ - int status; - pthread_t main_thread31; - pthread_attr_t attr; - void *join_s = NULL; - struct sched_param param; - - /* - * 初始化attr - */ - status = pthread_attr_init(&attr); - if(status != 0) { - printf("pthread_attr_init ERROR.\n"); - return -1; - - } else { - printf("pthread_attr_init success.\n"); - } - - status = -1; - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// attr.schedpolicy = SCHED_RR; -// attr.inheritsched = PTHREAD_EXPLICIT_SCHED; -// attr.schedparam.sched_priority = 55; - - pthread_attr_setschedpolicy(&attr,SCHED_RR); - pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 55; - pthread_attr_setschedparam(&attr, ¶m); - - - - status = pthread_create(&main_thread31, &attr, main_task_thread31_S0100202GN_8, NULL); - if(status != 0) { - printf("Error creating main_thread31.\n"); - return -1; - - } else { - printf("main_thread31 create success.\n"); - } - - status = -1; - - binding(main_thread31, 0); - - pthread_delay(100); - - /* - * 取消main_thread31线程 - */ - status = pthread_cancel(main_thread31); - if(status == 0) { - printf("main_thread31 cancel request successfully.\n"); - - } else { - printf("main_thread31 cancel request fail.\n"); - pthread_join(main_thread31, &join_s); - return -1; - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread31, &join_s); - - if ((long)join_s != 110) { - printf("main_thread31 exit successfully.\n"); - - } else { - printf("main_thread31 exit failed.\n"); - return -1; - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test23_S0100202GN_8(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100202GN_9.c b/task_management/gjb_S0100202GN_9.c deleted file mode 100644 index a84dda7..0000000 --- a/task_management/gjb_S0100202GN_9.c +++ /dev/null @@ -1,175 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100202GN_9.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建1个任务, 任务中设置线程清理函数, 并调用线程退出函数,退出返回值为32, -** 在主线程中查看线程退出值为32. -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -void clean_fun1(void *arg) -{ - printf("cleanup :%s\n",(char *)arg); -} - -void clean_fun2(void *arg) -{ - printf("cleanup :%s\n",(char *)arg); -} - -void *main_task_thread32(void *arg) -{ - printf("main_thread32 start...\n"); - - pthread_cleanup_push((void*)clean_fun1,"main_thread32 first handler"); - pthread_cleanup_push((void*)clean_fun2,"main_thread32 second handler"); - - printf("main_thread32 push complete.\n"); - - if (arg) { - pthread_exit((void *)32); - } - - /* - * 参数为0表示不调用清理函数,清理函数是为了做解锁资源的,防止资源死锁, - * 运行到pthread_cleanup_pop表示程序正确运行这时参数一般设为0,不调用清理函数 - */ - pthread_cleanup_pop(0); - pthread_cleanup_pop(0); - - return (void *)1; -} - -/* - * 删除任务_pthread_exit线程退出后需要执行的清理函数_正常 - */ -int test24 (void) -{ - int status; - pthread_t main_thread32; - pthread_attr_t attr; - void *tret = NULL; - - /* - * 初始化attr - */ - status = pthread_attr_init(&attr); - if (status != 0) { - printf("pthread_attr_init ERROR.\n"); - return -1; - - } else { - printf("pthread_attr_init success.\n"); - } - - status = -1; - /* - * 线程创建 - */ - status = pthread_create(&main_thread32, &attr, main_task_thread32, (void *)1); - if (status != 0) { - printf("Error creating main_thread32.\n"); - return -1; - - } else { - printf("main_thread32 create success.\n"); - } - - status = -1; - - binding(main_thread32, 0); - - /* - * 等待任务结束 - */ - status = pthread_join(main_thread32, &tret); - if (status != 0) { - printf("Error pthread_join\n"); - return -1; - - } else { - printf("pthread_join success\n"); - } - - if ((int)(long)tret != 32) { - printf("Exit return value is not 32.\n"); - return -1; - - } else { - printf("main_thread32 exit code %d\n", (int)(long)tret); - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test24(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100203GN_1.c b/task_management/gjb_S0100203GN_1.c deleted file mode 100644 index bc59269..0000000 --- a/task_management/gjb_S0100203GN_1.c +++ /dev/null @@ -1,296 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100203GN_1.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建2个任务, 线程6挂起自己, 线程7恢复线程6的挂起状态, 线程6退出应该返回0. -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -typedef unsigned int u32; -typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 -int thread_status = RUN; -pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; -int b_is_pthread_mutex_init = 0; - -pthread_mutex_t g_pthread_mutex; - - - -pthread_barrier_t bt_tm_2031; -pthread_t main_thread6_tm_2031; -pthread_t main_thread7_tm_2031; - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -int pthread_suspend(pthread_t thread) -{ - int ret = 0; - thread_status = STOP; - if(thread == 0)//等于0说明是自己,可以挂起 - { - pthread_mutex_lock(&thread_mut); - while(STOP == thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - - pthread_mutex_unlock(&thread_mut); - - - if(b_is_pthread_mutex_init) - { - pthread_mutex_lock(&g_pthread_mutex); - } - } - else - { - if(pthread_equal(thread, pthread_self()) != 0 ) - { - pthread_mutex_lock(&thread_mut); - while(!thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - pthread_mutex_unlock(&thread_mut); - - } - } - return ret; -} - -int pthread_resume(pthread_t thread) -{ - int ret = 0; - - if(thread == -1) - return -1; - - if (thread_status == STOP) - { - pthread_mutex_lock(&thread_mut); - thread_status = RUN; - pthread_cond_signal(&thread_cond); - pthread_mutex_unlock(&thread_mut); - } - return ret; -} - - -void *main_task_thread6_tm_2031 (void *arg) -{ - int status; - int i; - - pthread_barrier_wait(&bt_tm_2031); - - for (i = 0; i < 10; i++) { - printf("start main_thread6...\n"); - if (i == 0) { - /* - * 如果参数为0,则挂起自身任务 - */ - status = pthread_suspend(0); - if (status != 0) { - printf("main_thread6 suspend failed\n"); - return ((void *)123); - - } else { - printf("main_thread6 suspend success.\n"); - } - } - pthread_delay(100); - } - - return (NULL); -} - -void *main_task_thread7_tm_2031(void *arg) -{ - int i; - - pthread_barrier_wait(&bt_tm_2031); - - for (i = 0; i < 10; i++) { - printf("start main_thread7...\n"); - } - pthread_delay(1000 * 10); - - /* - * 线程解除挂起 - */ - pthread_resume(main_thread6_tm_2031); - - return (NULL); -} - -/* - * 挂起任务_任务自身挂起_成功 - */ -int test6_tm_2031() -{ - int status; - void *join_s; - pthread_attr_t main_attr6; - pthread_attr_t main_attr7; - struct sched_param param; - /* - * 创建(初始化)线程屏障 - */ - pthread_barrier_init(&bt_tm_2031, NULL, 3); - - /* - * 初始化main_attr6 - */ - pthread_attr_init(&main_attr6); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr6.schedpolicy = SCHED_RR; -// main_attr6.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr6.schedparam.sched_priority = 24; //15;/* thread 优先级为15 */ AICOS ADD 修改为高优先级 - - pthread_attr_setschedpolicy(&main_attr6,SCHED_RR); - pthread_attr_setinheritsched(&main_attr6,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 24; - pthread_attr_setschedparam(&main_attr6, ¶m); - - - /* - * 初始化main_attr7 - */ - pthread_attr_init(&main_attr7); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr7.schedpolicy = SCHED_RR; -// main_attr7.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr7.schedparam.sched_priority = 15; //24;/* thread 优先级为24 */ AICOS ADD 修改为低优先级 - - pthread_attr_setschedpolicy(&main_attr7,SCHED_RR); - pthread_attr_setinheritsched(&main_attr7,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 15; - pthread_attr_setschedparam(&main_attr7, ¶m); - - - - status = pthread_create(&main_thread6_tm_2031, &main_attr6, main_task_thread6_tm_2031, NULL); - if(status != 0) { - printf("Error creating main_thread6\n"); - return -1; - - } else { - printf("main_thread6 create success\n"); - } - - status = -1; - - status = pthread_create(&main_thread7_tm_2031, &main_attr7, main_task_thread7_tm_2031, NULL); - if(status != 0) { - printf("Error creating main_thread7\n"); - return -1; - - } else { - printf("main_thread7 create success\n"); - } - - binding(main_thread6_tm_2031, 0); - binding(main_thread7_tm_2031, 0); - - /* - * 等待线程屏障 - */ - pthread_barrier_wait(&bt_tm_2031); - - /* - * 等待任务结束 - */ - pthread_join(main_thread6_tm_2031, &join_s); - pthread_join(main_thread7_tm_2031, NULL); - - if ((long)join_s != 0) { - printf("thread exit fail\n"); - return -1; - - } else { - printf("thread exit successfully\n"); - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test6_tm_2031(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100203GN_2.c b/task_management/gjb_S0100203GN_2.c deleted file mode 100644 index c790918..0000000 --- a/task_management/gjb_S0100203GN_2.c +++ /dev/null @@ -1,337 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100203GN_2.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建2个任务, 线程6正常运行, 线程7去挂起线程6, -** 挂起之后再查看线程6状态是否是挂起状态, 线程6挂起后会停止打印, -** 最后调用恢复函数讲线程6恢复, 线程6恢复后, 继续打印. -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - - - -pthread_barrier_t bt_S0100203GN_2; -pthread_t main_thread6_S0100203GN_2; -pthread_t main_thread7_S0100203GN_2; - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -int pthread_suspend(pthread_t thread) -{ - int ret = 0; - thread_status = STOP; - if(thread == 0)//等于0说明是自己,可以挂起 - { - pthread_mutex_lock(&thread_mut); - while(STOP == thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - - pthread_mutex_unlock(&thread_mut); - - - if(b_is_pthread_mutex_init) - { - pthread_mutex_lock(&g_pthread_mutex); - } - } - else - { - if(pthread_equal(thread, pthread_self()) != 0 ) - { - pthread_mutex_lock(&thread_mut); - while(!thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - pthread_mutex_unlock(&thread_mut); - - } - } - return ret; -} -int pthread_resume(pthread_t thread) -{ - int ret = 0; - - if(thread == -1) - return -1; - - if (thread_status == STOP) - { - pthread_mutex_lock(&thread_mut); - thread_status = RUN; - pthread_cond_signal(&thread_cond); - pthread_mutex_unlock(&thread_mut); - } - return ret; -} - -boolean pthread_is_suspend(pthread_t thread) -{ - if (thread <= 0) - { - errno = ESRCH; - return ESRCH; - } - boolean ret = 1; - if(thread_status == STOP) - { - return 1; - } - else - { - return 0; - } - // ret=taskIsSuspended(thread); -} - -void *main_task_thread6_S0100203GN_2(void *arg) -{ - int i; - - /* - * 等待线程屏障 - */ - pthread_barrier_wait(&bt_S0100203GN_2); - - for (i = 0; i < 10; i++) { - printf("start main_thread6...\n"); - } - - return (NULL); -} - -void *main_task_thread7_S0100203GN_2(void *arg) -{ - int status; - boolean is_suspend; - int i; - - /* - * 等待线程屏障 - */ - pthread_barrier_wait(&bt_S0100203GN_2); - - for (i = 0; i < 10; i++) { - printf("start main_thread7...\n"); - } - - /* - * 线程挂起 - */ - status = pthread_suspend(main_thread6_S0100203GN_2); - if (status == 0) { - printf("main_thread6 suspend successfully\n"); - - } else { - printf("main_thread6 suspend fail\n"); - return ((void *)123); - } - - pthread_delay(100); - - /* - * 线程是否挂起 - */ - is_suspend = pthread_is_suspend(main_thread6_S0100203GN_2); - if (is_suspend == TRUE) { - printf("main_thread6 is suspended\n"); - - } else { - printf("main_thread6 is not suspended\n"); - return ((void *)123); - } - - sleep(4); - - /* - * 线程解除挂起 - */ - pthread_resume(main_thread6_S0100203GN_2); - - return (NULL); -} - -/* - * 挂起任务_任务由其它任务挂起_判定任务挂起成功 - */ -int test6_S0100203GN_2 (void) -{ - int status; - void *join_s; - pthread_attr_t main_attr6; - pthread_attr_t main_attr7; - struct sched_param param; - - /* - * 创建(初始化)线程屏障 - */ - pthread_barrier_init(&bt_S0100203GN_2,NULL,3); - - /* - * 初始化main_attr6 - */ - pthread_attr_init(&main_attr6); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr6.schedpolicy = SCHED_RR; -// main_attr6.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr6.schedparam.sched_priority = 15; - - pthread_attr_setschedpolicy(&main_attr6,SCHED_RR); - pthread_attr_setinheritsched(&main_attr6,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 15; - pthread_attr_setschedparam(&main_attr6, ¶m); - - - - status = pthread_create(&main_thread6_S0100203GN_2, &main_attr6, main_task_thread6_S0100203GN_2, NULL); - if(status != 0) { - printf("Error creating main_thread6\n"); - return -1; - - } else { - printf("main_thread6 create success.\n"); - } - - status = -1; - /* - * 初始化main_attr7 - */ - pthread_attr_init(&main_attr7); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr7.schedpolicy = SCHED_RR; -// main_attr7.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr7.schedparam.sched_priority = 24; - - pthread_attr_setschedpolicy(&main_attr7,SCHED_RR); - pthread_attr_setinheritsched(&main_attr7,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 24; - pthread_attr_setschedparam(&main_attr7, ¶m); - - - status = pthread_create(&main_thread7_S0100203GN_2, &main_attr7, main_task_thread7_S0100203GN_2, NULL); - if (status != 0) { - printf("Error creating main_thread7\n"); - return -1; - - } else { - printf("main_thread7 create success.\n"); - } - - binding(main_thread6_S0100203GN_2, 0); - binding(main_thread7_S0100203GN_2, 0); - - /* - * 等待线程屏障 - */ - pthread_barrier_wait(&bt_S0100203GN_2); - - /* - * 等待任务结束 - */ - pthread_join(main_thread6_S0100203GN_2, &join_s); - pthread_join(main_thread7_S0100203GN_2, NULL); - - if ((long)join_s != 0) { - printf("thread exit fail.\n"); - return -1; - - } else { - printf("thread exit success.\n"); - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test6_S0100203GN_2(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100203GN_3.c b/task_management/gjb_S0100203GN_3.c deleted file mode 100644 index 1dda555..0000000 --- a/task_management/gjb_S0100203GN_3.c +++ /dev/null @@ -1,320 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100203GN_3.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建2个任务, 线程6正常运行, 线程7去挂起线程6, -** 线程6挂起后会停止打印, 最后调用恢复函数讲线程6恢复, 线程6恢复后, 继续打印. -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -pthread_barrier_t bt_tm_2033; -pthread_t main_thread7_tm_2033; -pthread_t main_thread6_tm_2033; - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -int pthread_suspend(pthread_t thread) -{ - int ret = 0; - thread_status = STOP; - if(thread == 0)//等于0说明是自己,可以挂起 - { - pthread_mutex_lock(&thread_mut); - while(STOP == thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - - pthread_mutex_unlock(&thread_mut); - - - if(b_is_pthread_mutex_init) - { - pthread_mutex_lock(&g_pthread_mutex); - } - } - else - { - if(pthread_equal(thread, pthread_self()) != 0 ) - { - pthread_mutex_lock(&thread_mut); - while(!thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - pthread_mutex_unlock(&thread_mut); - - } - } - return ret; -} -int pthread_resume(pthread_t thread) -{ - int ret = 0; - - if(thread == -1) - return -1; - - if (thread_status == STOP) - { - pthread_mutex_lock(&thread_mut); - thread_status = RUN; - pthread_cond_signal(&thread_cond); - pthread_mutex_unlock(&thread_mut); - } - return ret; -} - -boolean pthread_is_suspend(pthread_t thread) -{ - if (thread <= 0) - { - errno = ESRCH; - return ESRCH; - } - boolean ret = 1; - if(thread_status == STOP) - { - return 1; - } - else - { - return 0; - } - // ret=taskIsSuspended(thread); -} - - -void *main_task_thread6_S0100203GN_3(void *arg) -{ - int i; - - /* - * 等待线程屏障 - */ - pthread_barrier_wait(&bt_tm_2033); - - for (i = 0; i < 10; i++) { - printf("start main_thread6...\n"); - } - - return (NULL); -} - -void *main_task_thread7_S0100203GN_3(void *arg) -{ - int status; - int i; - - /* - * 等待线程屏障 - */ - pthread_barrier_wait(&bt_tm_2033); - - for(i = 0; i < 10; i++) { - printf("start main_thread7...\n"); - } - - /* - * 线程挂起 - */ - status = pthread_suspend(main_thread6_tm_2033); - if(status == 0) { - printf("main_thread6 suspend successfully\n"); - - } else { - printf("main_thread6 suspend fail\n"); - return ((void *)123); - } - - pthread_delay(1000 * 20); - - /* - * 线程解除挂起 - */ - pthread_resume(main_thread6_tm_2033); - - return (NULL); -} - -/* - * 挂起任务_任务由其它任务挂起_成功 - */ -int test6_S0100203GN_3 (void) -{ - int status; - void *join_s = NULL; - pthread_attr_t main_attr6; - pthread_attr_t main_attr7; - struct sched_param param; - - /* - * 创建(初始化)线程屏障 - */ - pthread_barrier_init(&bt_tm_2033, NULL, 3); - - /* - * 初始化main_attr6 - */ - pthread_attr_init(&main_attr6); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr6.schedpolicy = SCHED_RR; -// main_attr6.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr6.schedparam.sched_priority = 15; - - pthread_attr_setschedpolicy(&main_attr6,SCHED_RR); - pthread_attr_setinheritsched(&main_attr6,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 15; - pthread_attr_setschedparam(&main_attr6, ¶m); - - - - status = pthread_create(&main_thread6_tm_2033, &main_attr6, main_task_thread6_S0100203GN_3, NULL); - if(status != 0) { - printf("Error creating main_thread6\n"); - return -1; - - } else { - printf("main_thread6 create success\n"); - } - - status = -1; - /* - * 初始化main_attr7 - */ - pthread_attr_init(&main_attr7); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr7.schedpolicy = SCHED_RR; -// main_attr7.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr7.schedparam.sched_priority = 24; - - pthread_attr_setschedpolicy(&main_attr7,SCHED_RR); - pthread_attr_setinheritsched(&main_attr7,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 24; - pthread_attr_setschedparam(&main_attr7, ¶m); - - - status = pthread_create(&main_thread7_tm_2033, &main_attr7, main_task_thread7_S0100203GN_3, NULL); - if(status != 0) { - printf("Error creating main_thread7\n"); - return -1; - - } else { - printf("main_thread7 create success\n"); - } - - binding(main_thread6_tm_2033, 0); - binding(main_thread7_tm_2033, 0); - - /* - * 等待线程屏障 - */ - pthread_barrier_wait(&bt_tm_2033); - - /* - * 等待任务结束 - */ - pthread_join(main_thread6_tm_2033, &join_s); - pthread_join(main_thread7_tm_2033, NULL); - - if ((long)join_s != 0) { - printf("thread exit fail.\n"); - return -1; - - } else { - printf("thread exit success.\n"); - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test6_S0100203GN_3(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100203GN_4.c b/task_management/gjb_S0100203GN_4.c deleted file mode 100644 index 35106ba..0000000 --- a/task_management/gjb_S0100203GN_4.c +++ /dev/null @@ -1,332 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100203GN_4.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建2个任务, 线程6正常运行, 线程7去挂起线程6, -** 线程6挂起后会停止打印, 等待 100 TICK, 最后调用恢复函数讲线程6恢复, 线程6恢复后, 继续打印. -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - - - -pthread_barrier_t bt_tm_2034; -pthread_t main_thread7_tm_2034; -pthread_t main_thread6_tm_2034; - - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -int pthread_suspend(pthread_t thread) -{ - int ret = 0; - thread_status = STOP; - if(thread == 0)//等于0说明是自己,可以挂起 - { - pthread_mutex_lock(&thread_mut); - while(STOP == thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - - pthread_mutex_unlock(&thread_mut); - - - if(b_is_pthread_mutex_init) - { - pthread_mutex_lock(&g_pthread_mutex); - } - } - else - { - if(pthread_equal(thread, pthread_self()) != 0 ) - { - pthread_mutex_lock(&thread_mut); - while(!thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - pthread_mutex_unlock(&thread_mut); - - } - } - return ret; -} -int pthread_resume(pthread_t thread) -{ - int ret = 0; - - if(thread == -1) - return -1; - - if (thread_status == STOP) - { - pthread_mutex_lock(&thread_mut); - thread_status = RUN; - pthread_cond_signal(&thread_cond); - pthread_mutex_unlock(&thread_mut); - } - return ret; -} - -boolean pthread_is_suspend(pthread_t thread) -{ - if (thread <= 0) - { - errno = ESRCH; - return ESRCH; - } - boolean ret = 1; - if(thread_status == STOP) - { - return 1; - } - else - { - return 0; - } - // ret=taskIsSuspended(thread); -} - - -void *main_task_thread6_S0100203GN_4(void *arg) -{ - int i; - - /* - * 等待线程屏障 - */ - pthread_barrier_wait(&bt_tm_2034); - - for(i = 0; i<10; i++) { - printf("start main_thread6...\n"); - } - - return (NULL); -} - -void *main_task_thread7_S0100203GN_4(void *arg) -{ - int status; - int i; - - /* - * 等待线程屏障 - */ - pthread_barrier_wait(&bt_tm_2034); - - for(i = 0; i < 10; i++) { - printf("start main_thread7...\n"); - } - - /* - * 线程挂起 - */ - status = pthread_suspend(main_thread6_tm_2034); - if(status == 0) { - printf("main_thread6 suspend successfully\n"); - - } else { - printf("main_thread6 suspend fail\n"); - return (void *)123; - } - - status = -1; - - pthread_delay(100); - - /* - * 线程解除挂起 - */ - status = pthread_resume(main_thread6_tm_2034); - if(status == 0) { - printf("main_thread6 resume successfully\n"); - - } else { - printf("main_thread6 resume fail\n"); - return (void *)123; - } - - return (NULL); -} - -/* - * 恢复任务_任务挂起后恢复_成功 - */ -int test6_S0100203GN_4 (void) -{ - int status; - void *join_s = NULL; - pthread_attr_t main_attr6; - pthread_attr_t main_attr7; - struct sched_param param; - - /* - * 创建(初始化)线程屏障 - */ - pthread_barrier_init(&bt_tm_2034, NULL, 3); - - /* - * 初始化main_attr6 - */ - pthread_attr_init(&main_attr6); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr6.schedpolicy = SCHED_RR; -// main_attr6.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr6.schedparam.sched_priority = 15; - - pthread_attr_setschedpolicy(&main_attr6,SCHED_RR); - pthread_attr_setinheritsched(&main_attr6,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 15; - pthread_attr_setschedparam(&main_attr6, ¶m); - - - status = pthread_create(&main_thread6_tm_2034, &main_attr6, main_task_thread6_S0100203GN_4, NULL); - if(status != 0) { - printf("Error creating main_thread6\n"); - return -1; - - } else { - printf("main_thread6 create success\n"); - } - - /* - * 初始化main_attr7 - */ - pthread_attr_init(&main_attr7); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr7.schedpolicy = SCHED_RR; -// main_attr7.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr7.schedparam.sched_priority = 24; - pthread_attr_setschedpolicy(&main_attr7,SCHED_RR); - pthread_attr_setinheritsched(&main_attr7,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 24; - pthread_attr_setschedparam(&main_attr7, ¶m); - - - - - status = pthread_create(&main_thread7_tm_2034, &main_attr7, main_task_thread7_S0100203GN_4, NULL); - if(status != 0) { - printf("Error creating main_thread7\n"); - return -1; - - } else { - printf("main_thread7 create success\n"); - } - - binding(main_thread6_tm_2034, 0); - binding(main_thread7_tm_2034, 0); - - /* - * 等待线程屏障 - */ - pthread_barrier_wait(&bt_tm_2034); - - /* - * 等待任务结束 - */ - pthread_join(main_thread6_tm_2034, &join_s); - pthread_join(main_thread7_tm_2034, NULL); - - if ((long)join_s != 0) { - printf("thread exit fail.\n"); - return -1; - - } else { - printf("thread exit success.\n"); - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test6_S0100203GN_4(); - if (result != 0) { - printf("task failed\n"); - return (-1); - - } else { - printf("task success\n"); - return (0); - } - -} diff --git a/task_management/gjb_S0100204GN_1.c b/task_management/gjb_S0100204GN_1.c deleted file mode 100644 index 047dcb3..0000000 --- a/task_management/gjb_S0100204GN_1.c +++ /dev/null @@ -1,260 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100204GN_1.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建3个任务, 设置任务的调度策略为 RR, 查看线程可以正常运行并打印 -*********************************************************************************************************/ -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - - - - #define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) - #define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - -static pthread_barrier_t bt_tm_2041; - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -/* - * 任务函数定义开始 - */ -void *main_task_thread_S0100204GN_1(void *arg) -{ - int i; - - for (i = 0; i < 3; i++) { - GJB_PRT_INFO("start main_thread...\n"); - } - - pthread_exit(0); - - return (NULL); -} - -void *main_task_thread1_S0100204GN_1(void *arg) -{ - int i; - - for(i = 0; i < 3; i++) { - GJB_PRT_INFO("start main_thread1...\n"); - } - - pthread_exit(0); - - return (NULL); -} - -void *main_task_thread2_S0100204GN_1(void *arg) -{ - int i; - - for(i = 0; i < 3; i++) { - GJB_PRT_INFO("start main_thread2...\n"); - } - - pthread_exit(0); - - return (NULL); -} - -/* - * 任务优先级设置_设置成功 - */ -int test2_S0100204GN_1 (void) -{ - int status; - pthread_t main_thread; - pthread_attr_t main_attr; - pthread_t main_thread1; - pthread_attr_t main_attr1; - pthread_t main_thread2; - pthread_attr_t main_attr2; - struct sched_param param; - - /* - * 创建(初始化)线程屏障 - */ - pthread_barrier_init(&bt_tm_2041, NULL, 4); - - /* - * 初始化main_attr - */ - pthread_attr_init(&main_attr); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr.schedpolicy = SCHED_RR; -// main_attr.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr.schedparam.sched_priority = 15; - pthread_attr_setschedpolicy(&main_attr,SCHED_RR); - pthread_attr_setinheritsched(&main_attr,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 15; - pthread_attr_setschedparam(&main_attr, ¶m); - - /* - * 初始化main_attr1 - */ - pthread_attr_init(&main_attr1); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr1.schedpolicy = SCHED_RR; -// main_attr1.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr1.schedparam.sched_priority = 24; - pthread_attr_setschedpolicy(&main_attr1,SCHED_RR); - pthread_attr_setinheritsched(&main_attr1,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 24; - pthread_attr_setschedparam(&main_attr1, ¶m); - - /* - * 初始化main_attr2 - */ - pthread_attr_init(&main_attr2); - -// main_attr2.schedpolicy = SCHED_RR; -// main_attr2.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr2.schedparam.sched_priority = 16; - pthread_attr_setschedpolicy(&main_attr2,SCHED_RR); - pthread_attr_setinheritsched(&main_attr2,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 16; - pthread_attr_setschedparam(&main_attr2, ¶m); - - /* - * 任务一 - */ - status = pthread_create(&main_thread, &main_attr, main_task_thread_S0100204GN_1, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread create success\n"); - } - - status = -1; - /* - * 任务二 - */ - status = pthread_create(&main_thread1, &main_attr1, main_task_thread1_S0100204GN_1, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread1\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread1 create success\n"); - } - - status = -1; - /* - * 任务三 - */ - status = pthread_create(&main_thread2, &main_attr2, main_task_thread2_S0100204GN_1, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread2\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread2 create success\n"); - } - - binding(main_thread, 0); - binding(main_thread1, 0); - binding(main_thread2, 0); - - /* - * 等待任务结束 - */ - pthread_join(main_thread, NULL); - pthread_join(main_thread1, NULL); - pthread_join(main_thread2, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: GJB_ENTRY - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test2_S0100204GN_1(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100204GN_2.c b/task_management/gjb_S0100204GN_2.c deleted file mode 100644 index cd66af6..0000000 --- a/task_management/gjb_S0100204GN_2.c +++ /dev/null @@ -1,304 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100204GN_2.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建3个任务, 设置任务的优先级分别为: 15, 24, 16, 各线程运行后获得自己的线程优先级并打印 -** 睡眠1秒后, 主线程修改各线程的优先级为: 17, 21, 41 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_getschedprio(pthread_t thread,int *priority) -{ - pthread_attr_t attr; - struct sched_param param; - int ret = 0; - if(thread <= 0x100000000) - return ESRCH; - if(priority == NULL) - { - errno = EINVAL; - return EINVAL; - } - ret = pthread_getattr_np(thread, &attr); - if(ret < 0) - { - *priority = 0; - return -1; - } - ret = pthread_attr_getschedparam(&attr, ¶m); - if(ret < 0) - { - *priority = 0; - return -1; - } - *priority = param.sched_priority; - return ret; -} - -void *main_task_thread_S0100204GN_2(void *arg) -{ - int i; - int prio; - - for(i = 0; i < 3; i++) { - pthread_getschedprio(pthread_self(), &prio); - - GJB_PRT_INFO("start main_thread (prio: %d)...\n", prio); - - sleep(1); - } - - pthread_exit(0); - - return (NULL); -} - -void *main_task_thread1_S0100204GN_2(void *arg) -{ - int i; - int prio; - - for(i = 0; i < 3; i++) { - pthread_getschedprio(pthread_self(), &prio); - - GJB_PRT_INFO("start main_thread1 (prio: %d)...\n", prio); - - sleep(1); - } - - pthread_exit(0); - - return (NULL); -} - -void *main_task_thread2_S0100204GN_2(void *arg) -{ - int i; - int prio; - - for(i = 0; i < 3; i++) { - pthread_getschedprio(pthread_self(), &prio); - - GJB_PRT_INFO("start main_thread2 (prio: %d)...\n", prio); - - sleep(1); - } - - pthread_exit(0); - - return (NULL); -} - -/* - * 任务优先级设置_设置成功 - */ -int test2_S0100204GN_2 (void) -{ - int status; - pthread_t main_thread; - pthread_attr_t main_attr; - pthread_t main_thread1; - pthread_attr_t main_attr1; - pthread_t main_thread2; - pthread_attr_t main_attr2; - struct sched_param param; - - /* - * 初始化main_attr - */ - pthread_attr_init(&main_attr); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr.schedpolicy = SCHED_RR; -// main_attr.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr.schedparam.sched_priority = 15; - pthread_attr_setschedpolicy(&main_attr,SCHED_RR); - pthread_attr_setinheritsched(&main_attr,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 15; - pthread_attr_setschedparam(&main_attr, ¶m); - - /* - * 初始化main_attr1 - */ - pthread_attr_init(&main_attr1); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr1.schedpolicy = SCHED_RR; -// main_attr1.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr1.schedparam.sched_priority = 24; - pthread_attr_setschedpolicy(&main_attr1,SCHED_RR); - pthread_attr_setinheritsched(&main_attr1,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 24; - pthread_attr_setschedparam(&main_attr1, ¶m); - - /* - * 初始化main_attr2 - */ - pthread_attr_init(&main_attr2); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr2.schedpolicy = SCHED_RR; -// main_attr2.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr2.schedparam.sched_priority = 16; - pthread_attr_setschedpolicy(&main_attr2,SCHED_RR); - pthread_attr_setinheritsched(&main_attr2,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 16; - pthread_attr_setschedparam(&main_attr2, ¶m); - - /* - * 任务一 - */ - status = pthread_create(&main_thread, &main_attr, main_task_thread_S0100204GN_2, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread create success\n"); - } - - status = -1; - /* - * 任务二 - */ - status = pthread_create(&main_thread1, &main_attr1, main_task_thread1_S0100204GN_2, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread1\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread1 create success\n"); - } - - status = -1; - /* - * 任务三 - */ - status = pthread_create(&main_thread2, &main_attr2, main_task_thread2_S0100204GN_2, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread2\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread2 create success\n"); - } - - binding(main_thread, 0); - binding(main_thread1, 0); - binding(main_thread2, 0); - - sleep(1); - - GJB_PRT_INFO("modify main_thread prio to 17\n"); - GJB_PRT_INFO("modify main_thread prio1 to 21\n"); - GJB_PRT_INFO("modify main_thread prio2 to 41\n"); - - /* - * 设置线程优先级 - */ - status = pthread_setschedprio(main_thread, 17); - status = pthread_setschedprio(main_thread1, 21); - status = pthread_setschedprio(main_thread2, 41); - - /* - * 等待任务结束 - */ - pthread_join(main_thread, NULL); - pthread_join(main_thread1, NULL); - pthread_join(main_thread2, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test2_S0100204GN_2(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100205GN_1.c b/task_management/gjb_S0100205GN_1.c deleted file mode 100644 index 9800447..0000000 --- a/task_management/gjb_S0100205GN_1.c +++ /dev/null @@ -1,215 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100205GN_1.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建2个任务调度策略为 RR, 优先级相同, 打印为交替打印 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - - -pthread_barrier_t bt_tm_2051; -pthread_t main_thread8_tm_2051; -pthread_t main_thread9_tm_2051; - -void *main_task_thread8_S0100205GN_1(void *arg) -{ - int i; - volatile int j; - - /* - * 创建(初始化)线程屏障 - */ - pthread_barrier_wait(&bt_tm_2051); - - for (i = 0; i < 50; i++) { - for(j = 0; j< 100000; j++); - GJB_PRT_INFO("main_thread9 get ready, main_thread8 is running\n"); - } - - return (NULL); -} - -void *main_task_thread9_S0100205GN_1(void *arg) -{ - int i; - volatile int j; - - /* - * 创建(初始化)线程屏障 - */ - pthread_barrier_wait(&bt_tm_2051); - - for(i=0;i<50;i++) { - for(j = 0; j< 100000; j++); - GJB_PRT_INFO("main_thread8 get ready, main_thread9 is running\n"); - } - - return (NULL); -} - -/* - * 三种任务状态转换_就绪转运行再转就绪状态 - */ -int test7_S0100205GN_1 (void) -{ - int status; - pthread_attr_t main_attr8; - pthread_attr_t main_attr9; - struct sched_param param; - - /* - * 创建(初始化)线程屏障 - */ - pthread_barrier_init(&bt_tm_2051, NULL, 3); - - /* - * 初始化main_attr8 - */ - pthread_attr_init(&main_attr8); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr8.schedpolicy = SCHED_RR; -// main_attr8.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr8.schedparam.sched_priority = 55; - pthread_attr_setschedpolicy(&main_attr8,SCHED_RR); - pthread_attr_setinheritsched(&main_attr8,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 55; - pthread_attr_setschedparam(&main_attr8, ¶m); - - status = pthread_create(&main_thread8_tm_2051, &main_attr8, main_task_thread8_S0100205GN_1, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread8.\n"); - return -1; - } else { - GJB_PRT_INFO("main_thread9 create success.\n"); - } - - status = -1; - /* - * 初始化main_attr9 - */ - pthread_attr_init(&main_attr9); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr9.schedpolicy = SCHED_RR; -// main_attr9.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr9.schedparam.sched_priority = 55; - pthread_attr_setschedpolicy(&main_attr9,SCHED_RR); - pthread_attr_setinheritsched(&main_attr9,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 55; - pthread_attr_setschedparam(&main_attr9, ¶m); - - - status = pthread_create(&main_thread9_tm_2051, &main_attr9, main_task_thread9_S0100205GN_1, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread9.\n"); - return -1; - } else { - GJB_PRT_INFO("main_thread9 create success.\n"); - } - - /* - * 创建(初始化)线程屏障 - */ - pthread_barrier_wait(&bt_tm_2051); - - /* - * 等待任务结束 - */ - pthread_join(main_thread8_tm_2051, NULL); - pthread_join(main_thread9_tm_2051, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test7_S0100205GN_1(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100205GN_2.c b/task_management/gjb_S0100205GN_2.c deleted file mode 100644 index a502cae..0000000 --- a/task_management/gjb_S0100205GN_2.c +++ /dev/null @@ -1,302 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100205GN_2.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建2个任务, 任务8中循环打印50次, 在第一次的时候挂起自己, 线程9循环打印50次, -** 在第14次恢复线程8 并打印恢复函数返回值应该为0 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - void binding (pthread_t tid, int cpu) - { - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); - } - - int GJB_PRI_FAIL(void) - { - printf("task failed\n"); - return -1; - } - - int GJB_PRI_PASS(void) - { - printf("task success\n"); - return (0); - } - - - int pthread_delay(int ticks) - { - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); - } - - - int pthread_suspend(pthread_t thread) - { - int ret = 0; - thread_status = STOP; - if(thread == 0)//等于0说明是自己,可以挂起 - { - pthread_mutex_lock(&thread_mut); - while(STOP == thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - - pthread_mutex_unlock(&thread_mut); - - - if(b_is_pthread_mutex_init) - { - pthread_mutex_lock(&g_pthread_mutex); - } - } - else - { - if(pthread_equal(thread, pthread_self()) != 0 ) - { - pthread_mutex_lock(&thread_mut); - while(!thread_status) - { - pthread_cond_wait(&thread_cond, &thread_mut); - } - pthread_mutex_unlock(&thread_mut); - - } - } - return ret; - } - int pthread_resume(pthread_t thread) - { - int ret = 0; - - if(thread == -1) - return -1; - - if (thread_status == STOP) - { - pthread_mutex_lock(&thread_mut); - thread_status = RUN; - pthread_cond_signal(&thread_cond); - pthread_mutex_unlock(&thread_mut); - } - return ret; - } - - - - -pthread_barrier_t bt_tm_2052; -cpu_set_t set_tm_2052; -pthread_t main_thread8_tm_2052; -pthread_t main_thread9_tm_2052; - -void *main_task_thread8_tm_2052(void *arg) -{ - int status = -1; - int i; - - pthread_barrier_wait(&bt_tm_2052); - - for (i = 0; i < 50; i++) { - if(i == 1) { - /* - * 阻塞本线程运行 - */ - status = pthread_suspend(0); - } - - GJB_PRT_INFO("main_thread8 is running %d\n", status); - } - - return (NULL); -} - -void *main_task_thread9_tm_2052(void *arg) -{ - int status = -1; - int i; - - pthread_barrier_wait(&bt_tm_2052); - - for (i = 0; i < 50; i++) { - /* - * AICOS ADD 这种两个线程谁先运行不好估算的, - * 尤其是多核,如果说该线程先运行,我们切一次 - */ - pthread_delay(1); - - GJB_PRT_INFO("main_thread9 is running %d\n", status); - - if (i == 14) { - status = pthread_resume( main_thread8_tm_2052); - } - } - - return (NULL); -} - -/* 状态转换测试:就绪与运行状态转换测试基本原理 - * 首先创建两个优先级相同的线程,设置时间片轮转调度方式, - * 即每个线程都分配公平的运行时间片,时间片用完就执行下一个线程,当前线程处于就绪状态 - */ -int test7_tm_2052 (void) -{ - int status; - pthread_attr_t main_attr8; - pthread_attr_t main_attr9; - struct sched_param param; - - memset(&main_attr8, 0, sizeof(pthread_attr_t)); - memset(&main_attr9, 0, sizeof(pthread_attr_t)); - - /* - * 创建(初始化)线程屏障 - */ - pthread_barrier_init(&bt_tm_2052, NULL, 3); - - /* - * 初始化main_attr8 - */ - pthread_attr_init(&main_attr8); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr8.schedpolicy = SCHED_RR; -// main_attr8.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr8.schedparam.sched_priority = 55; - pthread_attr_setschedpolicy(&main_attr8,SCHED_RR); - pthread_attr_setinheritsched(&main_attr8,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 55; - pthread_attr_setschedparam(&main_attr8, ¶m); - - - status = pthread_create(&main_thread8_tm_2052, &main_attr8, main_task_thread8_tm_2052, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread8\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread8 create success\n"); - } - - status = -1; - - /* - * 初始化main_attr9 - */ - pthread_attr_init(&main_attr9); - - /* - * 设置调度策略,是否继承调度参数,优先级 - */ -// main_attr9.schedpolicy = SCHED_RR; -// main_attr9.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr9.schedparam.sched_priority = 55; - pthread_attr_setschedpolicy(&main_attr9,SCHED_RR); - pthread_attr_setinheritsched(&main_attr9,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 55; - pthread_attr_setschedparam(&main_attr9, ¶m); - - - status = pthread_create(&main_thread9_tm_2052, &main_attr9, main_task_thread9_tm_2052, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread9\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread9 create success\n"); - } - - status = -1; - - binding(main_thread8_tm_2052, 0); - binding(main_thread9_tm_2052, 0); - - /* - * 创建(初始化)线程屏障 - */ - pthread_barrier_wait(&bt_tm_2052); - - /* - * 等待任务结束 - */ - pthread_join(main_thread8_tm_2052, NULL); - pthread_join(main_thread9_tm_2052, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test7_tm_2052(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_1.c b/task_management/gjb_S0100206GN_1.c deleted file mode 100644 index bda8392..0000000 --- a/task_management/gjb_S0100206GN_1.c +++ /dev/null @@ -1,218 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_1.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建线程16, 线程16中获取自己的线程ID并打印, 主线程中通过线程名字获取线程ID并打印 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - - -pthread_t main_thread16_tm_2061; - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} -int pthread_getid(char *name,pthread_t *pthread) -{ - return 0; -} - -void *main_task_thread16_tm_2061 (void *arg) -{ - int i; - pthread_t result_tid; - - for (i = 0; i < 5; i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - /* - * 获取的是主线程main,类型为pthread_t,unsigned long型 - */ - result_tid = pthread_self(); - - GJB_PRT_INFO("main_thread16:0x%x\n", (unsigned int)result_tid); - - sleep(5); - - return (NULL); -} - -/* - * 任务属性设置和查询_任务ID查询_正常 - */ -int test11_tm_2061 (void) -{ - int status; - pthread_t result_tid; - pthread_attr_t main_attr16; - struct sched_param param; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 设置任务栈地址,大小, - * 调度策略,是否继承调度参数, - * 优先级,任务名称 - */ -// main_attr16.stackaddr = NULL;// -// main_attr16.stacksize = PTHREAD_STACK_MIN;// -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED;// -// main_attr16.schedpolicy = SCHED_FIFO;// -// main_attr16.schedparam.sched_priority = 5;// -// main_attr16.name = "main_task_thread16";// -// printf("-------1--------"); -// pthread_attr_setstack(&main_attr16,NULL,PTHREAD_STACK_MIN); -// pthread_attr_setstackaddr(&main_attr16,NULL); -// pthread_attr_setstacksize(&main_attr16,PTHREAD_STACK_MIN); - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr16, ¶m); -// pthread_setname_np(main_thread16_tm_2061,"main_task_thread16"); -// printf("-------2--------"); - - - - - status = pthread_create(&main_thread16_tm_2061, &main_attr16, main_task_thread16_tm_2061, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success\n"); - } - - status = -1; - - binding(main_thread16_tm_2061, 0); - - pthread_delay(200); - - /* - * 获得当前 posix 线程句柄 - */ - result_tid = pthread_self(); - - /* - * 通过线程名获得线程句柄 - */ - status = pthread_getid("main_task_thread16", &result_tid); - if (status == 0) { - GJB_PRT_INFO("main_thread16:0x%x\n", (unsigned int)result_tid); - - } else { - GJB_PRT_ERROR_INFO("main_thread16 ID gets failed\n"); - pthread_join(main_thread16_tm_2061, NULL); - return -1; - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_2061, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test11_tm_2061(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_10.c b/task_management/gjb_S0100206GN_10.c deleted file mode 100644 index 94c72bd..0000000 --- a/task_management/gjb_S0100206GN_10.c +++ /dev/null @@ -1,211 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_10.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建线程16, 线程16中循环打印5次, 5次后睡眠5秒. -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - -pthread_t main_thread16_tm_20610; -pthread_t main_attr16_t_tm_20610; - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -int pthread_attr_getstackfilled(pthread_attr_t *attr,int *stackfilled) -{ - if((stackfilled == NULL) || (attr->name == NULL)) - { - return EINVAL; - } - *stackfilled = attr->stack_filled; - return 0; -} - - -void *main_task_thread16_S0100206GN_10 (void *arg) -{ - int i; - - for (i = 0; i < 5; i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} - -/* - * 任务属性设置和查询_任务stack_filled属性查询_正常 - */ -int test11_S0100206GN_10 (void) -{ - int status; - int stackfilled; - pthread_attr_t main_attr16; - struct sched_param param; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 任务栈地址,若为NULL时,系统在创建任务时会自动分配 - * 任务栈大小,设置调度策略,是否继承调度参数,优先级 - * 任务是否以0xee填充任务栈:不填充 - * 任务名称 - */ -// main_attr16.stackaddr = NULL; -// main_attr16.stacksize = PTHREAD_STACK_MIN; -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 5; -// main_attr16.name = "main_task_thread16"; - - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr16, ¶m); - - - status = pthread_attr_setstackfilled(&main_attr16, PTHREAD_NO_STACK_FILLED); - if (status != ERROR_NONE) { - GJB_PRT_ERROR_INFO("pthread_attr_setstackfilled set stack filled error.\n"); - return -1; - } else { - GJB_PRT_INFO("pthread_attr_setstackfilled set stack filled success.\n"); - } - - status = pthread_create(&main_thread16_tm_20610, &main_attr16, main_task_thread16_S0100206GN_10, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16.\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success.\n"); - } - - binding(main_thread16_tm_20610, 0); - - pthread_delay(200); - - status = pthread_attr_getstackfilled(&main_attr16, &stackfilled); - if (status != ERROR_NONE) { - GJB_PRT_ERROR_INFO("pthread_attr_getstackfilled get stack filled error.\n"); - return -1; - } else { - if (stackfilled != PTHREAD_NO_STACK_FILLED) { - GJB_PRT_ERROR_INFO("pthread_attr_getstackfilled get stack filled error.\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_getstackfilled get stack filled success.\n"); - } - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_20610,NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test11_S0100206GN_10(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_11.c b/task_management/gjb_S0100206GN_11.c deleted file mode 100644 index eed17c5..0000000 --- a/task_management/gjb_S0100206GN_11.c +++ /dev/null @@ -1,245 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_11.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建任务16, 主任务中获得任务16的断点属性,如果获得成功再获得无效线程的断点属性并且获取 -** 线程16并指定无效缓冲的断点属性 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} -int pthread_attr_getbreakallowed(const pthread_attr_t *attr, int *breakallowed) -{ - if (breakallowed == NULL) - {printf("breakallowed == NULL\n"); - return EINVAL;} - if (attr == NULL) - { - printf("attr == NULL\n"); - return EINVAL; - } - - char *prt = (char *)attr; - for (int i = 0; i < sizeof(pthread_attr_t); i++) - { - if (*prt != 0) - { - break; - } - prt++; - if (i == (sizeof(pthread_attr_t) - 1)) - { - printf("sizeof(pthread_attr_t) - 1\n"); - return EINVAL; - } - } - // *breakallowed = attr->break_allowed; - return 0; -} - - -pthread_t main_thread16_tm_20611; -pthread_t main_attr16_t_tm_20611; - -void *main_task_thread16_S0100206GN_11(void *arg) -{ - int i; - - for (i = 0; i < 5; i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} - -/* - * 任务属性设置和查询_任务break_allowed属性查询_正常 - */ -int test11_S0100206GN_11 (void) -{ - int status; - int detach_state = 3; - pthread_attr_t main_attr16_t; - pthread_attr_t main_attr16; - struct sched_param param; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 任务栈地址,若为NULL时,系统在创建任务时会自动分配 - * 任务栈大小,设置调度策略,是否继承调度参数,优先级 - * 任务是否以0xee填充任务栈:不填充 - * 任务名称 - */ -// main_attr16.stackaddr = NULL; -// main_attr16.stacksize = PTHREAD_STACK_MIN; -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 5; -// main_attr16.option = LW_OPTION_THREAD_BREAK_DISALLOWED; //????? -// main_attr16.name = "main_task_thread16"; - - - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr16, ¶m); - - - status = pthread_create(&main_thread16_tm_20611, &main_attr16, main_task_thread16_S0100206GN_11, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16.\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success.\n"); - } - - status = -1; - - binding(main_thread16_tm_20611, 0); - - pthread_delay(200); - - /* - * 获取任务stack_filled属性,第二参数一级指针 - * 获得线程属性块是否允许断点 - */ - status = pthread_attr_getbreakallowed(&main_attr16, &detach_state); - if (status == 0) { - GJB_PRT_INFO("pthread_attr_getbreakallowed successfully. detach_state:%d\n", detach_state); - - if (pthread_attr_getbreakallowed(&main_attr16_t, &detach_state) == EINVAL && - pthread_attr_getbreakallowed(&main_attr16, NULL) == EINVAL) { - -// if (pthread_attr_getbreakallowed(&main_attr16_t, &detach_state) == EINVAL) { - - GJB_PRT_INFO("main_thread16 pthread_attr_getbreakallowed set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_20611, NULL); - return -1; - } - - } else { - if(status == EINVAL) { - GJB_PRT_ERROR_INFO("pthread_attr_getbreakallowed ERROR\n"); - pthread_join(main_thread16_tm_20611, NULL); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_getbreakallowed success\n"); - } - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_20611, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test11_S0100206GN_11(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_12.c b/task_management/gjb_S0100206GN_12.c deleted file mode 100644 index 7829473..0000000 --- a/task_management/gjb_S0100206GN_12.c +++ /dev/null @@ -1,232 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_12.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建任务16,获取任务16的FP属性 (浮动属性) -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -int pthread_attr_getfpallowed(const pthread_attr_t *attr, int *fpallowed) -{ - if ((fpallowed == NULL) || (attr == NULL)) - { - return EINVAL; - } - char *prt = (char *)attr; - for (int i = 0; i < sizeof(pthread_attr_t); i++) - { - if (*prt != 0) - { - break; - } - prt++; - if (i == (sizeof(pthread_attr_t) - 1)) - { - return EINVAL; - } - } - //*fpallowed = attr->fp_allowed; - return 0; -} - -pthread_t main_thread16_tm_20612; -pthread_t main_attr16_t_tm_20612; - -void *main_task_thread16_S0100206GN_12(void *arg) -{ - int i; - - for (i = 0; i < 5; i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} - -/* - * 任务属性设置和查询_任务fp_allowed属性查询_正常 - */ -int test11_S0100206GN_12 (void) -{ - int status; - int detach_state = 3; - pthread_attr_t main_attr16_t; - pthread_attr_t main_attr16; - struct sched_param param; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 任务栈地址,若为NULL时,系统在创建任务时会自动分配 - * 任务栈大小,设置调度策略,是否继承调度参数,优先级 - * 任务是否以0xee填充任务栈:不填充 - * 任务名称 - */ -// main_attr16.stackaddr = NULL; -// main_attr16.stacksize = PTHREAD_STACK_MIN; -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 5; -// main_attr16.name = "main_task_thread16"; - - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr16, ¶m); - - - status = pthread_create(&main_thread16_tm_20612, &main_attr16, main_task_thread16_S0100206GN_12, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success.\n"); - } - - status = -1; - - binding(main_thread16_tm_20612, 0); - - pthread_delay(200); - - /* - * 获得线程属性块是否允许浮点 - */ - status = pthread_attr_getfpallowed(&main_attr16, &detach_state); - if(status == 0) { - GJB_PRT_INFO("pthread_attr_getfpallowed successfully. detach_state:%d\n", detach_state); - - if(pthread_attr_getfpallowed(&main_attr16_t, &detach_state) == EINVAL && - pthread_attr_getfpallowed(&main_attr16, NULL) == EINVAL) { - GJB_PRT_INFO("main_thread16 pthread_attr_getfpallowed set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation -- set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_20612, NULL); - return -1; - } - - } else { - if(status == EINVAL) { - GJB_PRT_ERROR_INFO("pthread_attr_getfpallowed ERROR\n"); - pthread_join(main_thread16_tm_20612, NULL); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_getfpallowed success\n"); - } - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_20612, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test11_S0100206GN_12(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_13.c b/task_management/gjb_S0100206GN_13.c deleted file mode 100644 index f333a03..0000000 --- a/task_management/gjb_S0100206GN_13.c +++ /dev/null @@ -1,209 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_13.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建任务16,获取任务16的调度策略 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -pthread_t main_thread16_tm_20613; -pthread_t main_attr16_t_tm_20613; - -void *main_task_thread16_S0100206GN_13(void *arg) -{ - int i; - - for (i = 0; i < 5; i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} - -/* - * 任务属性设置和查询_任务schedpolicy属性查询_正常 - */ -int test11_S0100206GN_13() -{ - int status; - int detach_state = 3; - pthread_attr_t main_attr16_t; - pthread_attr_t main_attr16; - struct sched_param param; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 任务栈地址,若为NULL时,系统在创建任务时会自动分配 - * 任务栈大小,设置调度策略,是否继承调度参数,优先级 - * 任务是否以0xee填充任务栈:不填充 - * 任务名称 - */ -// main_attr16.stackaddr = NULL; -// main_attr16.stacksize = PTHREAD_STACK_MIN; -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 5; -// main_attr16.name = "main_task_thread16"; - - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr16, ¶m); - - - status = pthread_create(&main_thread16_tm_20613, &main_attr16, main_task_thread16_S0100206GN_13, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success.\n"); - } - - status = -1; - - binding(main_thread16_tm_20613, 0); - - pthread_delay(200); - - /* - * 获取一个线程属性块的调度策略 - */ - status = pthread_attr_getschedpolicy(&main_attr16, &detach_state); - if(status == 0) { - GJB_PRT_INFO("pthread_attr_getschedpolicy successfully:%d\n", detach_state); - - if(pthread_attr_getschedpolicy(&main_attr16_t, &detach_state) == EINVAL) { - - GJB_PRT_INFO("main_attr pthread_attr_getschedpolicy set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_20613, NULL); - return -1; - } - - } else { - if(status == EINVAL) { - GJB_PRT_ERROR_INFO("pthread_attr_getschedpolicy ERROR\n"); - pthread_join(main_thread16_tm_20613, NULL); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_getschedpolicy success\n"); - } - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_20613, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test11_S0100206GN_13(); - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_management/gjb_S0100206GN_14.c b/task_management/gjb_S0100206GN_14.c deleted file mode 100644 index ab84c05..0000000 --- a/task_management/gjb_S0100206GN_14.c +++ /dev/null @@ -1,218 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_14.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建任务16,获取任务16的DETACH状态 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - - -pthread_t main_thread16_tm_20614; -pthread_t main_attr16_t_tm_20614; - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - - -void *main_task_thread16_S0100206GN_14(void *arg) -{ - int i; - - for (i = 0; i < 5; i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} - -/* - * 任务属性设置和查询_任务detachstate属性查询_正常 - */ -int test11_S0100206GN_14 (void) -{ - int status,status2; - int detach_state = 3; - pthread_attr_t main_attr16_t; - pthread_attr_t main_attr16; - struct sched_param param; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16,0,sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 任务栈地址,若为NULL时,系统在创建任务时会自动分配 - * 任务栈大小,设置调度策略,是否继承调度参数,优先级 - * 任务是否以0xee填充任务栈:不填充 - * 任务名称 - */ -// main_attr16.stackaddr = NULL; -// main_attr16.stacksize = PTHREAD_STACK_MIN; -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 5; -// main_attr16.name = "main_task_thread16"; - - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr16, ¶m); - - - - status = pthread_create(&main_thread16_tm_20614, &main_attr16, main_task_thread16_S0100206GN_14, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16.\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success.\n"); - } - - status = -1; - - binding(main_thread16_tm_20614, 0); - - pthread_delay(200); - - /* - * 获取一个线程属性块的 detach 状态 - */ - status = pthread_attr_getdetachstate(&main_attr16, &detach_state); - if(status == 0) { - GJB_PRT_INFO("pthread_attr_getdetachstate successfully:%d.\n", detach_state); -// status2 = pthread_attr_getdetachstate(&main_attr16_t, &detach_state); -// printf("status2 %d,%d",status2,detach_state); -// if(pthread_attr_getdetachstate(&main_attr16_t, &detach_state) == EINVAL) { - - if(pthread_attr_getdetachstate(&main_attr16_t, &detach_state) == EINVAL ) { - - - GJB_PRT_INFO("main_attr pthread_attr_getschedpolicy set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_20614, NULL); - return -1; - } - - } else { - if(status == EINVAL) { - GJB_PRT_ERROR_INFO("pthread_attr_getdetachstate ERROR.\n"); - pthread_join(main_thread16_tm_20614, NULL); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_getdetachstate success.\n"); - } - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_20614, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test11_S0100206GN_14(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_15.c b/task_management/gjb_S0100206GN_15.c deleted file mode 100644 index ac2e9d7..0000000 --- a/task_management/gjb_S0100206GN_15.c +++ /dev/null @@ -1,320 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_15.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建任务16,测试任务16的线程名字设置, 线程栈大小设置, -** 线程调度继承方式设置, 线程调度优先级设置 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - - -pthread_t main_thread16_tm_20615; -pthread_t main_thread16_t_tm_20615; -#ifndef __TMS320C6X__ -static int testcancel_tm_20615 = 0; -#endif - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -int pthread_showstack(pthread_t thread) -{ - return 0; -} - - -void *main_task_thread16_S0100206GN_15(void *arg) -{ - int i; - - for (i = 0; i < 5; i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} - -/* - * 任务属性设置和查询_任务属性设置_正常 - */ -int test12_S0100206GN_15 (void) -{ - int status,status2; - size_t set_stack_size = PTHREAD_STACK_MIN;//最小栈空间 - pthread_attr_t main_attr16; - pthread_attr_t main_attr16_t; - struct sched_param param; - - /* - * 因为没有初始化,可能该线程ID在任务中存在 - */ - main_thread16_t_tm_20615 = 1000; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 设置任务堆栈大小 - */ - status=pthread_attr_setstacksize(&main_attr16, set_stack_size + 4); - if(status != 0){ - GJB_PRT_ERROR_INFO("pthread_attr_setstacksize fail.\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_setstacksize success.\n"); - } - - status = -1; - /* - * 任务调度继承策略PTHREAD_EXPLICIT_SCHED 2 - * 设置调度策略,优先级 - * 任务是否以0xee填充任务栈:不填充 - * 任务名称 - */ -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 6; -// main_attr16.name = "main_task_thread17"; - - - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 6; - pthread_attr_setschedparam(&main_attr16, ¶m); - - - /* - * 防止与main_thread16_t冲突 - */ - main_thread16_tm_20615 = 1200; - - status = pthread_create(&main_thread16_tm_20615, &main_attr16, main_task_thread16_S0100206GN_15, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 creating success\n"); - } - - status = -1; - - /* - * 通过调用接口函数设置任务属性 - */ -// status=pthread_attr_setname(&main_attr16, "main_task_thread16"); -// if(status == 0) { -// GJB_PRT_INFO("pthread_attr_setname successfully\n"); -// -// if(pthread_attr_setname(&main_attr16_t, "main_task_thread16") == EINVAL) { -// GJB_PRT_INFO("main_attr16 pthread_attr_setname set invalid parameter test pass\n"); -// -// } else { -// GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); -// pthread_join(main_thread16_tm_20615, NULL); -// return -1; -// } -// -// } else { -// GJB_PRT_ERROR_INFO("main_thread16 name set failed\n"); -// pthread_join(main_thread16_tm_20615, NULL); -// return -1; -// } - - status = -1; - - /* - * 设置任务堆栈大小 - */ - status = pthread_attr_setstacksize(&main_attr16, set_stack_size); - if(status == 0) { - - status2= pthread_attr_setstacksize(&main_attr16, set_stack_size-1); - printf("set_stack_size-1 %d\n",status2); - status2= pthread_attr_setstacksize(&main_attr16_t, set_stack_size); - printf("main_attr16_t %d\n",status2); - - if(pthread_attr_setstacksize(&main_attr16, set_stack_size-1) == EINVAL && - pthread_attr_setstacksize(&main_attr16_t, set_stack_size) == EINVAL) { - -// if(pthread_attr_setstacksize(&main_attr16, set_stack_size-1) == EINVAL && -// pthread_attr_setstacksize(&main_attr16_t, set_stack_size) == EINVAL) { - - - GJB_PRT_INFO("main_attr16 pthread_attr_setstacksize set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_20615, NULL); - return -1; - } - - } else { - GJB_PRT_ERROR_INFO("main_thread16 stack_size set failed\n"); - pthread_join(main_thread16_tm_20615, NULL); - return -1; - } - - status = -1; - - /* - * 设置任务调度继承策略,调度继承策略只有两种 - */ - status = pthread_attr_setinheritsched(&main_attr16, PTHREAD_INHERIT_SCHED); - if(status == 0) { - if(pthread_attr_setinheritsched(&main_attr16, 4) == EINVAL && - pthread_attr_setinheritsched(&main_attr16_t, PTHREAD_EXPLICIT_SCHED) == EINVAL) { - GJB_PRT_INFO("main_attr16 pthread_attr_setinheritsched set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_20615, NULL); - return -1; - } - - } else { - GJB_PRT_ERROR_INFO("main_thread16 inheritsched set failed\n"); - pthread_join(main_thread16_tm_20615, NULL); - return -1; - } - - status = -1; - - /* - * 设置任务优先级,这个比较特殊只有任务创建成功后才可以动态修改 - */ - status = pthread_setschedprio(main_thread16_tm_20615, 5); - if(status == 0) { - GJB_PRT_INFO("pthread_setschedprio success\n"); - - if(pthread_setschedprio(main_thread16_t_tm_20615, 5) == ESRCH) { - GJB_PRT_INFO("main_attr16 pthread_setschedprio set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_20615, NULL); - return -1; - } - - } else { - GJB_PRT_ERROR_INFO("main_thread16 sched_priority set failed\n"); - pthread_join(main_thread16_tm_20615, NULL); - return -1; - } - - /* - * 显示线程堆栈信息 - */ - pthread_showstack(main_thread16_tm_20615); - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_20615, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test12_S0100206GN_15(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_16.c b/task_management/gjb_S0100206GN_16.c deleted file mode 100644 index 4f2b16b..0000000 --- a/task_management/gjb_S0100206GN_16.c +++ /dev/null @@ -1,182 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_16.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 初始化一个线程属性对象, 设置线程属性的栈地址 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - - -/* - * 任务属性设置和查询_任务堆栈地址设置_正常 - * */ -int test21() -{ - int status; - pthread_attr_t attr,attr1; - size_t set_stack_size = PTHREAD_STACK_MIN; - - /* - * 防止系统认为该attr已初始化 - */ - memset(&attr, 0, sizeof(pthread_attr_t)); - - /* - * 初始化attr - */ - status = pthread_attr_init(&attr); - if (status != 0) { - GJB_PRT_ERROR_INFO("pthread_attr_init ERROR\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_init success\n"); - } - - status = -1; - /* - * 分配堆栈空间 - */ - char *stack_addr = (char *) malloc(PTHREAD_STACK_MIN + 0x40); - - /* - * 设置任务堆栈地址 - */ - status = pthread_attr_setstack(&attr, stack_addr, set_stack_size); - printf("pthread_attr_setstack status is %d\n",status); - //status = pthread_attr_setstackaddr(&attr, stack_addr); - if (status != 0) { - GJB_PRT_ERROR_INFO("pthread_attr_setstack ERROR\n"); - pthread_attr_destroy(&attr); - free(stack_addr); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_setstack successfully\n"); - printf("invalid parameter test %d\n",pthread_attr_setstack(&attr1, stack_addr,set_stack_size)); - if(pthread_attr_setstack(&attr1, stack_addr,set_stack_size) == EINVAL) { - GJB_PRT_INFO("attr1 pthread_attr_setstackaddr set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_attr_destroy(&attr); - free(stack_addr); - return -1; - } - } - - /* - * 释放内存空间 - */ - free(stack_addr); - - /* - * 删除任务属性对象 - */ - status = pthread_attr_destroy(&attr); - if (status != 0) { - GJB_PRT_ERROR_INFO("pthread_attr_destroy ERROR\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_destroy success.\n"); - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test21(); - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_management/gjb_S0100206GN_17.c b/task_management/gjb_S0100206GN_17.c deleted file mode 100644 index 1a52ad4..0000000 --- a/task_management/gjb_S0100206GN_17.c +++ /dev/null @@ -1,196 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_17.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 初始化一个线程属性对象, 设置线程属性的栈填充和获取线程栈填充 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; -#define PTHREAD_STACK_FILLED 0 - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -int pthread_attr_getstackfilled(pthread_attr_t *attr,int *stackfilled) -{ -// if((stackfilled == NULL) || (attr->name == NULL)) -// { -// return EINVAL; -// } -// *stackfilled = attr->stack_filled; - return 0; -} - -int pthread_attr_setstackfilled(pthread_attr_t *attr, int stackfilled) -{ - - if (attr == NULL) - return EINVAL; - - char *prt = (char *)attr; - for (int i = 0; i < sizeof(pthread_attr_t); i++) - { - if (*prt != 0) - { - break; - } - prt++; - if (i == (sizeof(pthread_attr_t) - 1)) - { - return EINVAL; - } - } - if (stackfilled > 1 || stackfilled < 0) - return EINVAL; - // attr->stack_filled = stackfilled; - return 0; -} - - -/* - * 任务属性设置和查询_任务stack_filled属性设置_正常 - */ -int test21_S0100206GN_17() -{ - int status; - pthread_attr_t attr,attr1; - int detach_state = 5; - - /* - * 防止系统认为该attr已初始化 - */ - memset(&attr, 0, sizeof(pthread_attr_t)); - - /* - * 初始化attr - */ - status = pthread_attr_init(&attr); - if( status != 0) { - GJB_PRT_ERROR_INFO("pthread_attr_init ERROR\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_init success\n"); - } - - status = -1; - /* - * 设置线程属性块栈填充特性 - */ - if (pthread_attr_setstackfilled(&attr, PTHREAD_STACK_FILLED) != 0) { - GJB_PRT_ERROR_INFO("Error in pthread_attr_setstackfilled()\n"); - pthread_attr_destroy(&attr); - return -1; - - } else { - status = pthread_attr_getstackfilled(&attr, &detach_state); - GJB_PRT_INFO("pthread_attr_setstackfilled successfully. detach_state : %d\n",detach_state); - - if (pthread_attr_setstackfilled(&attr1, PTHREAD_STACK_FILLED) == EINVAL && - pthread_attr_setstackfilled(&attr, 2) == EINVAL) { - GJB_PRT_INFO("attr pthread_attr_setstackfilled set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation -- set invalid parameter test fail\n"); - pthread_attr_destroy(&attr); - return -1; - } - } - - /* - * 销毁一个线程属性块 - */ - pthread_attr_destroy(&attr); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test21_S0100206GN_17(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_18.c b/task_management/gjb_S0100206GN_18.c deleted file mode 100644 index 2bdd42a..0000000 --- a/task_management/gjb_S0100206GN_18.c +++ /dev/null @@ -1,374 +0,0 @@ -锘/********************************************************************************************************* -** -** GJB 鏍囧噯娴嬭瘯闆 -** -** Copyright All Rights Reserved -** -**--------------鏂囦欢淇℃伅-------------------------------------------------------------------------------- -** -** 鏂 浠 鍚: gjb_S0100206GN_18.c -** -** 鏂囦欢鍒涘缓鏃ユ湡: 2021 骞 1 鏈 12 鏃 -** -** 鎻 杩: 鍒濆鍖栦竴涓嚎绋嬪睘鎬у璞, 璁剧疆绾跨▼灞炴х殑绾跨▼鍚嶅瓧, 绾跨▼灞炴х殑绾跨▼鏍堝ぇ灏, -** 璁剧疆绾跨▼灞炴х殑璋冨害缁ф壙鏂瑰紡, 鍒涘缓绾跨▼16, 璁剧疆绾跨▼16鐨勮皟搴︿紭鍏堢骇涓5, -** 璋冪敤绾跨▼淇℃伅鏄剧ず鍑芥暟鍙互鏌ョ湅鍒扮嚎绋嬩紭鍏堢骇涓 250 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - -#define GLOBAL_THREAD_TIME_OUT 1200 -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - -#define test_22_7 - -pthread_t main_thread16_tm_20618; -pthread_t main_thread16_t_tm_20618; - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -void display_pthread_attr(pthread_attr_t *attr, char *prefix) -{ - int s, i; - size_t v; - void *stkaddr; - struct sched_param sp; - - s = pthread_attr_getdetachstate(attr, &i); - - if (s != 0) - printf("error pthread_attr_getdetachstate\n"); - - printf("%sDetach state = %s\n", prefix, - (i == PTHREAD_CREATE_DETACHED) ? "PTHREAD_CREATE_DETACHED" : - (i == PTHREAD_CREATE_JOINABLE) ? "PTHREAD_CREATE_JOINABLE" : - "???"); - - s = pthread_attr_getscope(attr, &i); - if (s != 0) - printf("error pthread_attr_getscope\n"); - printf("%sScope = %s\n", prefix, - (i == PTHREAD_SCOPE_SYSTEM) ? "PTHREAD_SCOPE_SYSTEM" : - (i == PTHREAD_SCOPE_PROCESS) ? "PTHREAD_SCOPE_PROCESS" : - "???"); - - s = pthread_attr_getinheritsched(attr, &i); - if (s != 0) - printf("error pthread_attr_getinheritsched\n"); - printf("%sInherit scheduler = %s\n", prefix, - (i == PTHREAD_INHERIT_SCHED) ? "PTHREAD_INHERIT_SCHED" : - (i == PTHREAD_EXPLICIT_SCHED) ? "PTHREAD_EXPLICIT_SCHED" : - "???"); - - s = pthread_attr_getschedpolicy(attr, &i); - if (s != 0) - printf("error pthread_attr_getschedpolicy\n"); - printf("%sScheduling policy = %s\n", prefix, - (i == SCHED_OTHER) ? "SCHED_OTHER" : - (i == SCHED_FIFO) ? "SCHED_FIFO" : - (i == SCHED_RR) ? "SCHED_RR" : - "???"); - - s = pthread_attr_getschedparam(attr, &sp); - if (s != 0) - printf("error pthread_attr_getschedparam\n"); - printf("%sScheduling priority = %d\n", prefix, sp.sched_priority); - - s = pthread_attr_getguardsize(attr, &v); - if (s != 0) - printf("error pthread_attr_getguardsize\n"); - printf("%sGuard size = %zu bytes\n", prefix, v); - - s = pthread_attr_getstack(attr, &stkaddr, &v); - if (s != 0) - printf("error pthread_attr_getstack\n"); - printf("%sStack address = %p\n", prefix, stkaddr); - printf("%sStack size = 0x%zx bytes\n", prefix, v); -} - - -int pthread_show(pthread_t thread,int level) -{ - pthread_attr_t attr; - pthread_attr_init(&attr); - char t_name[32]; - pthread_getattr_np(thread, &attr); - pthread_getname_np(thread, t_name, 16); - printf("%pThread name = %s\n", NULL, t_name); - printf("%pThread ID = 0x%lx\n", NULL, thread); - display_pthread_attr(&attr, NULL); - printf("%pThread TIMEOUT = %d\n", NULL, GLOBAL_THREAD_TIME_OUT); - printf("%pThread CALLSTACK = 0x%u\n", NULL, getpid()); - if(level > 0) - { -// printf("%dThread BREAK_ALLOWED = %d\n", NULL, attr.break_allowed == PTHREAD_BREAK_ALLOWED?PTHREAD_BREAK_ALLOWED:PTHREAD_BREAK_DISALLOWED); -// printf("%dThread FP_ALLOWED = 0x%x\n", NULL, attr.fp_allowed == PTHREAD_FP_ALLOWED?PTHREAD_FP_ALLOWED:PTHREAD_FP_DISALLOWED); -// printf("%dThread STACK_FILLED = %d\n", NULL, attr.stack_filled == PTHREAD_STACK_FILLED?PTHREAD_STACK_FILLED:PTHREAD_NO_STACK_FILLED); - } - return 0; -} - -void *main_task_thread16_S0100206GN_18 (void *arg) -{ - int i; - - for (i = 0; i < 5; i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} - -/* - * 鍙夋帴鍙f祴璇昣浠诲姟灞炴ц缃甠璋冪敤璁剧疆鎺ュ彛鍑芥暟璁剧疆灞炴у璞″啀鍒涘缓浠诲姟_姝e父鍜屽紓甯歌繑鍥炵爜 - */ -int test12_S0100206GN_18() -{ - int status; - size_t set_stack_size = PTHREAD_STACK_MIN;//鏈灏忔爤绌洪棿 - pthread_attr_t main_attr16, main_attr16_t; - struct sched_param param; - - /* - * 闃叉绯荤粺璁や负璇ain_attr16宸插垵濮嬪寲 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 鍥犱负娌℃湁鍒濆鍖栵紝鍙兘璇ョ嚎绋婭D鍦ㄤ换鍔′腑瀛樺湪 - * 闃叉鍐茬獊 - */ - main_thread16_t_tm_20618 = 1000; - main_thread16_tm_20618 = 1200; - - /* - * 鍒濆鍖杕ain_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 璁剧疆浠诲姟鍫嗘爤澶у皬 - */ - status = pthread_attr_setstacksize(&main_attr16, set_stack_size + 4); - if (status != 0){ - GJB_PRT_ERROR_INFO("pthread_attr_setstacksize fail.\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_setstacksize success.\n"); - } - - status = -1; - /* - * 浠诲姟璋冨害缁ф壙绛栫暐PTHREAD_EXPLICIT_SCHED 2 - * 璁剧疆璋冨害绛栫暐锛屼紭鍏堢骇锛屼换鍔″悕绉 - */ -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 6; -// main_attr16.name = "main_task_thread17"; - - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 6; - pthread_attr_setschedparam(&main_attr16, ¶m); - - - /* - * 璁剧疆浠诲姟鍚嶇О锛宻et鎿嶄綔涔熷緱鍦ㄥ垱寤轰换鍔′箣鍓 - */ -// status = pthread_attr_setname(&main_attr16, "main_task_thread16"); -// if (status == 0) { -// GJB_PRT_INFO("pthread_attr_setname success\n"); -// -// if(pthread_attr_setname(&main_attr16_t,"main_task_thread16") == EINVAL) { -// GJB_PRT_INFO("main_attr16 pthread_attr_setname set invalid parameter test pass\n"); -// -// } else { -// GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); -// return -1; -// } -// -// } else { -// GJB_PRT_ERROR_INFO("main_thread16 name set failed\n"); -// return -1; -// } - - status = -1; - /* - * 璁剧疆浠诲姟鍫嗘爤澶у皬 - */ - status = pthread_attr_setstacksize(&main_attr16, set_stack_size); - if (status == 0) { - GJB_PRT_INFO("pthread_attr_setstacksize success\n"); - - - if(pthread_attr_setstacksize(&main_attr16, set_stack_size - 1) == EINVAL) { - -// if(pthread_attr_setstacksize(&main_attr16, set_stack_size - 1) == EINVAL && -// pthread_attr_setstacksize(&main_attr16_t, set_stack_size) == EINVAL) { - GJB_PRT_INFO("main_attr16 pthread_attr_setstacksize set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - return -1; - } - - } else { - GJB_PRT_ERROR_INFO("main_thread16 stack_size set failed\n"); - return -1; - } - - status = -1; - /* - * 璁剧疆浠诲姟璋冨害缁ф壙绛栫暐锛岃皟搴︾户鎵跨瓥鐣ュ彧鏈変袱绉 - */ - status = pthread_attr_setinheritsched(&main_attr16, PTHREAD_INHERIT_SCHED); - if (status == 0) { - GJB_PRT_INFO("pthread_attr_setinheritsched success\n"); - - if(pthread_attr_setinheritsched(&main_attr16, 4) == EINVAL) { - - -// if(pthread_attr_setinheritsched(&main_attr16, 4) == EINVAL && -// pthread_attr_setinheritsched(&main_attr16_t, PTHREAD_EXPLICIT_SCHED) == EINVAL) { - GJB_PRT_INFO("main_attr16 pthread_attr_setinheritsched set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - return -1; - } - - } else { - GJB_PRT_ERROR_INFO("main_thread16 inheritsched set failed\n"); - return -1; - } - - status = -1; - - status = pthread_create(&main_thread16_tm_20618, &main_attr16, main_task_thread16_S0100206GN_18, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success\n"); - } - pthread_delay(5000); - - status = -1; - /* - * 璁剧疆浠诲姟浼樺厛绾э紝杩欎釜姣旇緝鐗规畩鍙湁浠诲姟鍒涘缓鎴愬姛鍚庢墠鍙互鍔ㄦ佷慨鏀 - */ - status = pthread_setschedprio(main_thread16_tm_20618, 5); - printf("pthread_setschedprio %d\n",status); - if (status == 0) { - GJB_PRT_INFO("pthread_setschedprio success\n"); - - if(pthread_setschedprio(main_thread16_t_tm_20618, 5) == ESRCH) { - GJB_PRT_INFO("main_attr16 pthread_setschedprio set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_20618, NULL); - return -1; - } - - } else { - GJB_PRT_ERROR_INFO("main_thread16 sched_priority set failed\n"); - pthread_join(main_thread16_tm_20618, NULL); - return -1; - } - - pthread_show(main_thread16_tm_20618, 1); - - /* - * 绛夊緟浠诲姟缁撴潫 - */ - pthread_join(main_thread16_tm_20618, NULL); - - return 0; - -} -/********************************************************************************************************* - * 鍑芥暟鍚嶇О锛 GJB_ENTRY - * 鍔熻兘鎻忚堪锛 鐢ㄦ埛绋嬪簭鍏ュ彛 - * 杈撳叆鍙傛暟锛 鏃 - * 杈撳嚭鍙傛暟锛 鏃 - * 杩 鍥 鍊硷細 鏃 - * 鍏跺畠璇存槑锛 鏃 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test12_S0100206GN_18(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_19.c b/task_management/gjb_S0100206GN_19.c deleted file mode 100644 index 2faec2c..0000000 --- a/task_management/gjb_S0100206GN_19.c +++ /dev/null @@ -1,210 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_19.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 初始化一个线程属性对象, 设置线程属性的断点属性再获取该属性 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - -#define PTHREAD_BREAK_ALLOWED 0 - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} -int pthread_attr_setbreakallowed(pthread_attr_t *attr, int breakallowed) -{ - if (breakallowed > 1) - return EINVAL; - if (attr == NULL) - return EINVAL; - char *prt = (char *)attr; - for (int i = 0; i < sizeof(pthread_attr_t); i++) - { - if (*prt != 0) - { - break; - } - prt++; - if (i == (sizeof(pthread_attr_t) - 1)) - { - return EINVAL; - } - } - // attr->break_allowed = breakallowed; - return 0; -} - -int pthread_attr_getbreakallowed(const pthread_attr_t *attr, int *breakallowed) -{ - if (breakallowed == NULL) - return EINVAL; - if (attr == NULL) - return EINVAL; - char *prt = (char *)attr; - for (int i = 0; i < sizeof(pthread_attr_t); i++) - { - if (*prt != 0) - { - break; - } - prt++; - if (i == (sizeof(pthread_attr_t) - 1)) - { - return EINVAL; - } - } - // *breakallowed = attr->break_allowed; - return 0; -} - - -/* - * 任务属性设置和查询_任务break_allowed属性设置_正常 - */ -int test21_S0100206GN_19 (void) -{ - int status; - pthread_attr_t attr, attr1; - int detach_state = 5; - - /* - * 防止系统认为该attr已初始化 - */ - memset(&attr, 0, sizeof(pthread_attr_t)); - - /* - * 初始化attr - */ - status = pthread_attr_init(&attr); - if(status != 0) { - GJB_PRT_ERROR_INFO("pthread_attr_init ERROR\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_init success.\n"); - } - - status = -1; - /* - * 设置线程属性块是否允许断点 - */ - status = pthread_attr_setbreakallowed(&attr, PTHREAD_BREAK_ALLOWED); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error in pthread_attr_setbreakallowed()\n"); - pthread_attr_destroy(&attr); - return -1; - - } else { - status = pthread_attr_getbreakallowed(&attr, &detach_state); - GJB_PRT_INFO("pthread_attr_getbreakallowed successfully! detach_state : %d\n", detach_state); - - if ( pthread_attr_setbreakallowed(&attr, 2) == EINVAL) { - -// if (pthread_attr_setbreakallowed(&attr1, PTHREAD_BREAK_ALLOWED) == EINVAL && -// pthread_attr_setbreakallowed(&attr, 2) == EINVAL) { - GJB_PRT_INFO("attr pthread_attr_setbreakallowed set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_attr_destroy(&attr); - return -1; - } - } - - /* - * 销毁一个线程属性块 - */ - pthread_attr_destroy(&attr); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test21_S0100206GN_19(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_2.c b/task_management/gjb_S0100206GN_2.c deleted file mode 100644 index d04fd4d..0000000 --- a/task_management/gjb_S0100206GN_2.c +++ /dev/null @@ -1,271 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_2.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 创建任务16, 获得线程16的线程名字, 通过线程属性获取线程的名字 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - - -pthread_t main_thread16_tm_2062; - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -int pthread_getname(pthread_t thread, char *thread_name) -{ - if (thread <= 0) - { - errno = ESRCH; - return ESRCH; - } - if (thread_name == NULL) - { - errno =EINVAL; - return EINVAL; - } - - return pthread_getname_np(thread, thread_name, 64); -} - -int pthread_attr_getname(const pthread_attr_t *attr,char **name) -{ - if(name == NULL) - return -1; - if(*name == NULL) - *name = (char *)malloc(64); - //if(attr->name == NULL) - if(0) - { - errno = EINVAL; - return EINVAL; - } - // *name = (char *)malloc(64); - // printf("%s\n0x%x\n0x%x\n", attr->name, name, *name); - //sprintf(*name, "%s", attr->name); - printf("name, main_task_thread16\n"); - return 0; -} - - -void *main_task_thread16_S0100206GN_2(void *arg) -{ - int i; - pthread_t result_tid; - - for (i=0;i<5;i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - - /* - * 获取的是主线程main,类型为pthread_t,unsigned long型 - */ - result_tid = pthread_self(); - - GJB_PRT_INFO("main_thread16:0x%x\n", (unsigned int)result_tid); - - sleep(5); - - return (NULL); -} - -/* - * 任务属性设置和查询_任务名称查询_正常 - */ -int test11_S0100206GN_2 (void) -{ - int status; - char thread_name[64] = {0}; - pthread_attr_t main_attr16_t; - pthread_attr_t main_attr16; - char *thread_name_get = NULL; - struct sched_param param; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 任务栈地址,若为NULL时,系统在创建任务时会自动分配 - * 任务栈大小,设置调度策略,是否继承调度参数,优先级 - * 任务是否以0xee填充任务栈:不填充 - * 任务名称 - */ -// main_attr16.stackaddr = NULL; -// main_attr16.stacksize = PTHREAD_STACK_MIN; -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 5; -// main_attr16.name = "main_task_thread16"; - -// pthread_attr_setstack(&main_attr16,NULL,PTHREAD_STACK_MIN); - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr16, ¶m); -// pthread_setname_np(main_thread16_tm_2062,"main_task_thread16"); - - - - status = pthread_create(&main_thread16_tm_2062, &main_attr16, main_task_thread16_S0100206GN_2, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success\n"); - } - - status = -1; - - binding(main_thread16_tm_2062, 0); - - pthread_delay(200); - - /* - * 获取任务名称 - */ - status = pthread_getname(main_thread16_tm_2062, thread_name); - if (status == 0) { - GJB_PRT_INFO("main_thread16 name:%s in pthread_getname\n", thread_name); - - } else { - GJB_PRT_ERROR_INFO("main_thread16 name gets failed in pthread_getname\n"); - pthread_join(main_thread16_tm_2062, NULL); - free(thread_name_get); - return -1; - } - - /* - * 获得一个线程属性块的名字, 创建的线程将使用同样的名字. - */ - status = pthread_attr_getname(&main_attr16, &thread_name_get); - if (status == 0) { - GJB_PRT_INFO("main_thread16 name:%s in pthread_attr_getname\n",thread_name_get); - - if(pthread_attr_getname(&main_attr16_t, &thread_name_get) == EINVAL) { - GJB_PRT_INFO("main_attr16_t pthread_attr_getname set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_2062, NULL); - free(thread_name_get); - return -1; - } - - } else { - GJB_PRT_ERROR_INFO("main_thread16 name gets failed in pthread_attr_getname\n"); - pthread_join(main_thread16_tm_2062, NULL); - free(thread_name_get); - return -1; - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_2062, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test11_S0100206GN_2(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_20.c b/task_management/gjb_S0100206GN_20.c deleted file mode 100644 index 73dd4cf..0000000 --- a/task_management/gjb_S0100206GN_20.c +++ /dev/null @@ -1,212 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_20.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务属性设置与查询测试 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; -#define PTHREAD_FP_ALLOWED 0 -#define PTHREAD_BREAK_ALLOWED 0 -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -int pthread_attr_setfpallowed(pthread_attr_t *attr, int fpallowed) -{ - if (fpallowed > 1) - return EINVAL; - if (attr == NULL) - return EINVAL; - char *prt = (char *)attr; - for (int i = 0; i < sizeof(pthread_attr_t); i++) - { - if (*prt != 0) - { - break; - } - prt++; - if (i == (sizeof(pthread_attr_t) - 1)) - { - return EINVAL; - } - } - //attr->fp_allowed = fpallowed; - return 0; -} - - - -int pthread_attr_getfpallowed(const pthread_attr_t *attr, int *fpallowed) -{ - if ((fpallowed == NULL) || (attr == NULL)) - { - return EINVAL; - } - char *prt = (char *)attr; - for (int i = 0; i < sizeof(pthread_attr_t); i++) - { - if (*prt != 0) - { - break; - } - prt++; - if (i == (sizeof(pthread_attr_t) - 1)) - { - return EINVAL; - } - } - //*fpallowed = attr->fp_allowed; - return 0; -} - - -/* - * 任务属性设置和查询_任务fp_allowed属性设置_正常 - */ -int test21_S0100206GN_20 (void) -{ - int status; - pthread_attr_t attr,attr1; - int detach_state = 5; - - /* - * 防止系统认为该attr1已初始化 - */ - memset(&attr, 0, sizeof(pthread_attr_t)); - - /* - * 初始化attr - */ - status = pthread_attr_init(&attr); - if( status != 0) { - GJB_PRT_ERROR_INFO("pthread_attr_init ERROR\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_init success.\n"); - } - - status = -1; - /* - * 设置线程属性块是否允许浮点 - */ - status = pthread_attr_setfpallowed(&attr, PTHREAD_FP_ALLOWED); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error in pthread_attr_setfpallowed\n"); - pthread_attr_destroy(&attr); - return -1; - - } else { - status = pthread_attr_getfpallowed(&attr, &detach_state); - GJB_PRT_INFO("pthread_attr_setfpallowed successfully :%d\n",detach_state); - - if( pthread_attr_setfpallowed(&attr, 2) == EINVAL) { - -// if(pthread_attr_setfpallowed(&attr1, PTHREAD_FP_ALLOWED) == EINVAL && -// pthread_attr_setfpallowed(&attr, 2) == EINVAL) { - GJB_PRT_INFO("attr pthread_attr_setfpallowed set invalid parameter test pass\n"); - - } else{ - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_attr_destroy(&attr); - return -1; - } - - } - /* - * 销毁一个线程属性块 - */ - pthread_attr_destroy(&attr); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test21_S0100206GN_20(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_21.c b/task_management/gjb_S0100206GN_21.c deleted file mode 100644 index f4e7c04..0000000 --- a/task_management/gjb_S0100206GN_21.c +++ /dev/null @@ -1,165 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_21.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务属性设置与查询测试 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - - -/* - * 任务属性设置和查询_任务schedpolicy属性设置_正常 - */ -int test21_S0100206GN_21 (void) -{ - int status; - pthread_attr_t attr,attr1; - int detach_state = 5; - - /* - * 防止系统认为该attr已初始化 - */ - memset(&attr,0,sizeof(pthread_attr_t)); - - /* - * 初始化attr - */ - status = pthread_attr_init(&attr); - if( status != 0) { - GJB_PRT_ERROR_INFO("pthread_attr_init ERROR\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_init success.\n"); - } - - status = -1; - /* - * 设置一个线程属性块的调度策略 - */ - status = pthread_attr_setschedpolicy(&attr, SCHED_FIFO); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error in pthread_attr_setschedpolicy()\n"); - pthread_attr_destroy(&attr); - return -1; - - } else { - status = pthread_attr_getschedpolicy(&attr, &detach_state); - GJB_PRT_INFO("pthread_attr_setschedpolicy successfully! detach_state : %d\n", detach_state); - - if(pthread_attr_setschedpolicy(&attr, 4) == EINVAL) { -// if(pthread_attr_setschedpolicy(&attr1, SCHED_FIFO) == EINVAL && -// pthread_attr_setschedpolicy(&attr, 4) == EINVAL) { - - - GJB_PRT_INFO("attr pthread_attr_setschedpolicy set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_attr_destroy(&attr); - return -1; - } - } - /* - * 销毁一个线程属性块 - */ - pthread_attr_destroy(&attr); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test21_S0100206GN_21(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_22.c b/task_management/gjb_S0100206GN_22.c deleted file mode 100644 index 069b927..0000000 --- a/task_management/gjb_S0100206GN_22.c +++ /dev/null @@ -1,161 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_22.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务属性设置与查询测试 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -/* - * 任务属性设置和查询_任务detachstate属性设置_正常 - */ -int test21_S0100206GN_22 (void) -{ - int status; - pthread_attr_t attr,attr1; - int detach_state = 5; - - /* - * 防止系统认为该attr已初始化 - */ - memset(&attr, 0, sizeof(pthread_attr_t)); - - /* - * 初始化attr - */ - status = pthread_attr_init(&attr); - if(status != 0) { - GJB_PRT_ERROR_INFO("pthread_attr_init ERROR\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_init success.\n"); - } - - status = -1; - /* - * 设置一个线程属性块的 detach 状态 - */ - status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error in pthread_attr_setdetachstate()\n"); - pthread_attr_destroy(&attr); - return -1; - - } else { - status = pthread_attr_getdetachstate(&attr, &detach_state); - GJB_PRT_INFO("pthread_attr_setdetachstate successfully :%d\n", detach_state); - - if(pthread_attr_setdetachstate(&attr1, PTHREAD_CREATE_JOINABLE) == 0 && - pthread_attr_setdetachstate(&attr, 2) == EINVAL) { - GJB_PRT_INFO("attr pthread_attr_setdetachstate set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_attr_destroy(&attr); - return -1; - } - } - /* - * 销毁一个线程属性块 - */ - pthread_attr_destroy(&attr); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test21_S0100206GN_22(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_23.c b/task_management/gjb_S0100206GN_23.c deleted file mode 100644 index 3bed99b..0000000 --- a/task_management/gjb_S0100206GN_23.c +++ /dev/null @@ -1,358 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_23.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务属性设置与查询测试 (可选接口) -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - -#define GLOBAL_THREAD_TIME_OUT 1200 -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - -pthread_t main_thread16_tm_2063; -pthread_t main_thread16_t_tm_2063; - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -void display_pthread_attr(pthread_attr_t *attr, char *prefix) -{ - int s, i; - size_t v; - void *stkaddr; - struct sched_param sp; - - s = pthread_attr_getdetachstate(attr, &i); - - if (s != 0) - printf("error pthread_attr_getdetachstate\n"); - - printf("%sDetach state = %s\n", prefix, - (i == PTHREAD_CREATE_DETACHED) ? "PTHREAD_CREATE_DETACHED" : - (i == PTHREAD_CREATE_JOINABLE) ? "PTHREAD_CREATE_JOINABLE" : - "???"); - - s = pthread_attr_getscope(attr, &i); - if (s != 0) - printf("error pthread_attr_getscope\n"); - printf("%sScope = %s\n", prefix, - (i == PTHREAD_SCOPE_SYSTEM) ? "PTHREAD_SCOPE_SYSTEM" : - (i == PTHREAD_SCOPE_PROCESS) ? "PTHREAD_SCOPE_PROCESS" : - "???"); - - s = pthread_attr_getinheritsched(attr, &i); - if (s != 0) - printf("error pthread_attr_getinheritsched\n"); - printf("%sInherit scheduler = %s\n", prefix, - (i == PTHREAD_INHERIT_SCHED) ? "PTHREAD_INHERIT_SCHED" : - (i == PTHREAD_EXPLICIT_SCHED) ? "PTHREAD_EXPLICIT_SCHED" : - "???"); - - s = pthread_attr_getschedpolicy(attr, &i); - if (s != 0) - printf("error pthread_attr_getschedpolicy\n"); - printf("%sScheduling policy = %s\n", prefix, - (i == SCHED_OTHER) ? "SCHED_OTHER" : - (i == SCHED_FIFO) ? "SCHED_FIFO" : - (i == SCHED_RR) ? "SCHED_RR" : - "???"); - - s = pthread_attr_getschedparam(attr, &sp); - if (s != 0) - printf("error pthread_attr_getschedparam\n"); - printf("%sScheduling priority = %d\n", prefix, sp.sched_priority); - - s = pthread_attr_getguardsize(attr, &v); - if (s != 0) - printf("error pthread_attr_getguardsize\n"); - printf("%sGuard size = %zu bytes\n", prefix, v); - - s = pthread_attr_getstack(attr, &stkaddr, &v); - if (s != 0) - printf("error pthread_attr_getstack\n"); - printf("%sStack address = %p\n", prefix, stkaddr); - printf("%sStack size = 0x%zx bytes\n", prefix, v); -} - - -int pthread_show(pthread_t thread,int level) -{ - pthread_attr_t attr; - pthread_attr_init(&attr); - char t_name[32]; - pthread_getattr_np(thread, &attr); - pthread_getname_np(thread, t_name, 16); - printf("%pThread name = %s\n", NULL, t_name); - printf("%pThread ID = 0x%lx\n", NULL, thread); - display_pthread_attr(&attr, NULL); - printf("%pThread TIMEOUT = %d\n", NULL, GLOBAL_THREAD_TIME_OUT); - printf("%pThread CALLSTACK = 0x%u\n", NULL, getpid()); - if(level > 0) - { -// printf("%dThread BREAK_ALLOWED = %d\n", NULL, attr.break_allowed == PTHREAD_BREAK_ALLOWED?PTHREAD_BREAK_ALLOWED:PTHREAD_BREAK_DISALLOWED); -// printf("%dThread FP_ALLOWED = 0x%x\n", NULL, attr.fp_allowed == PTHREAD_FP_ALLOWED?PTHREAD_FP_ALLOWED:PTHREAD_FP_DISALLOWED); -// printf("%dThread STACK_FILLED = %d\n", NULL, attr.stack_filled == PTHREAD_STACK_FILLED?PTHREAD_STACK_FILLED:PTHREAD_NO_STACK_FILLED); - } - return 0; -} - - -void *main_task_thread16_S0100206GN_23(void *arg) -{ - int i; - - for(i=0;i<5;i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} - -/* - * 可选接口测试_任务属性设置_调用设置接口函数设置属性对象再创建任务_正常和异常返回码 - */ -int test12_S0100206GN_23() -{ - int status; - size_t set_stack_size = PTHREAD_STACK_MIN;//最小栈空间 - pthread_attr_t main_attr16, main_attr16_t; - struct sched_param param; - - /* - * 因为没有初始化,可能该线程ID在任务中存在 - * 防止冲突 - */ - main_thread16_t_tm_2063 = 1000; - main_thread16_tm_2063 = 1200; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 设置任务堆栈大小 - */ - status = pthread_attr_setstacksize(&main_attr16, set_stack_size + 4); - - /* - * 任务调度继承策略PTHREAD_EXPLICIT_SCHED 2 - * 设置调度策略,优先级,任务名称 - */ -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 6; -// main_attr16.name = "main_task_thread17"; - - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 6; - pthread_attr_setschedparam(&main_attr16, ¶m); - - - - /* - * 设置任务名称,set操作也得在创建任务之前 - */ -// status = pthread_attr_setname(&main_attr16, "main_task_thread16"); -// if (status == 0) { -// GJB_PRT_INFO("pthread_attr_setname success\n"); -// -// if(pthread_attr_setname(&main_attr16_t, "main_task_thread16") == EINVAL) { -// GJB_PRT_INFO("main_attr16_t pthread_attr_setname set invalid parameter test pass\n"); -// -// } else { -// GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); -// return -1; -// } -// -// } else { -// GJB_PRT_ERROR_INFO("main_thread16 name set failed\n"); -// return -1; -// } - - status = -1; - /* - * 设置任务堆栈大小 - */ - status = pthread_attr_setstacksize(&main_attr16, set_stack_size); - if (status == 0) { - GJB_PRT_INFO("pthread_attr_setstacksize success\n"); - - if(pthread_attr_setstacksize(&main_attr16, set_stack_size - 1) == EINVAL ) { - GJB_PRT_INFO("main_attr16 pthread_attr_setstacksize set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - return -1; - } - - } else { - GJB_PRT_ERROR_INFO("main_thread16 stack_size set failed\n"); - return -1; - } - - status = -1; - /* - * 设置任务调度继承策略,调度继承策略只有两种 - */ - status = pthread_attr_setinheritsched(&main_attr16, PTHREAD_INHERIT_SCHED); - if (status == 0) { - GJB_PRT_INFO("pthread_attr_setinheritsched success\n"); - - if(pthread_attr_setinheritsched(&main_attr16, 4) == EINVAL ) { - GJB_PRT_INFO("main_attr16 pthread_attr_setinheritsched set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - return -1; - } - - } else { - GJB_PRT_ERROR_INFO("main_thread16 inheritsched set failed\n"); - return -1; - } - - status = -1; - - status = pthread_create(&main_thread16_tm_2063, &main_attr16, main_task_thread16_S0100206GN_23, NULL); - - pthread_delay(5000); - - - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success.\n"); - } - - status = -1; - /* - * 设置任务优先级,这个比较特殊只有任务创建成功后才可以动态修改 - */ - status = pthread_setschedprio(main_thread16_tm_2063, 5); - if (status == 0) { - GJB_PRT_INFO("pthread_setschedprio success\n"); - - if(pthread_setschedprio(main_thread16_t_tm_2063, 5) == ESRCH) { - GJB_PRT_INFO("main_attr16 pthread_setschedprio set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_2063, NULL); - return -1; - } - - } else { - GJB_PRT_ERROR_INFO("main_thread16 sched_priority set failed\n"); - pthread_join(main_thread16_tm_2063, NULL); - return -1; - } - - pthread_show(main_thread16_tm_2063, 1); - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_2063, NULL); - - return 0; - -} -/********************************************************************************************************* - * 函数名称: GJB_ENTRY - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test12_S0100206GN_23(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_3.c b/task_management/gjb_S0100206GN_3.c deleted file mode 100644 index 7cfb5f1..0000000 --- a/task_management/gjb_S0100206GN_3.c +++ /dev/null @@ -1,219 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_3.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务状态切换测试 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - -pthread_t main_thread16; - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -void *main_task_thread16_S0100206GN_3 (void *arg) -{ - int i; - - for (i = 0; i < 5; i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} -int pthread_attr_getname(const pthread_attr_t *attr,char **name) -{ - if(name == NULL) - return -1; - if(*name == NULL) - *name = (char *)malloc(64); - //if(attr->name == NULL) - if(0) - { - errno = EINVAL; - return EINVAL; - } - // *name = (char *)malloc(64); - // printf("%s\n0x%x\n0x%x\n", attr->name, name, *name); - //sprintf(*name, "%s", attr->name); - printf("name, main_task_thread16\n"); - return 0; -} - -/* - * 任务属性设置和查询_任务名称查询_正常 - */ -int test11_S0100206GN_3 (void) -{ - int status; - pthread_attr_t main_attr16_t; - pthread_attr_t main_attr16; - char *thread_name_get; - struct sched_param param; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 任务栈地址,若为NULL时,系统在创建任务时会自动分配 - * 任务栈大小,设置调度策略,是否继承调度参数,优先级 - * 任务是否以0xee填充任务栈:不填充 - * 任务名称 - */ -// main_attr16.stackaddr = NULL; -// main_attr16.stacksize = PTHREAD_STACK_MIN; -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 5; -// main_attr16.name = "main_task_thread16"; - - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr16, ¶m); - - status = pthread_create(&main_thread16, &main_attr16, main_task_thread16_S0100206GN_3, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success.\n"); - } - - status = -1; - - binding(main_thread16, 0); - - pthread_delay(200); - - /* - * 获得一个线程属性块的名字, 创建的线程将使用同样的名字. - */ - status = pthread_attr_getname(&main_attr16, &thread_name_get); - if(status == 0) { - GJB_PRT_INFO("main_thread16 name:%s in pthread_attr_getname\n", thread_name_get); - - if(pthread_attr_getname(&main_attr16_t, &thread_name_get) == EINVAL) { - GJB_PRT_INFO("main_attr16_t pthread_attr_getname set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16, NULL); - return -1; - } - - } else { - GJB_PRT_ERROR_INFO("main_thread16 name gets failed in pthread_attr_getname\n"); - pthread_join(main_thread16, NULL); - return -1; - } - /* - * 等待任务结束 - */ - pthread_join(main_thread16, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test11_S0100206GN_3(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_4.c b/task_management/gjb_S0100206GN_4.c deleted file mode 100644 index 1121c16..0000000 --- a/task_management/gjb_S0100206GN_4.c +++ /dev/null @@ -1,215 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_4.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务状态切换测试 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - -pthread_t main_thread16_tm_2064; - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -void *main_task_thread16_S0100206GN_4(void *arg) -{ - int i; - - for (i = 0; i < 5; i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} - -/* - * 任务属性设置和查询_任务堆栈大小查询_正常 - */ -int test11_S0100206GN_4 (void) -{ - int status,status2; - size_t stack_size; - pthread_attr_t main_attr16_t; - pthread_attr_t main_attr16; - struct sched_param param; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 任务栈地址,若为NULL时,系统在创建任务时会自动分配 - * 任务栈大小,设置调度策略,是否继承调度参数,优先级 - * 任务是否以0xee填充任务栈:不填充 - * 任务名称 - */ -// main_attr16.stackaddr = NULL; -// main_attr16.stacksize = PTHREAD_STACK_MIN; -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 5; -// main_attr16.name = "main_task_thread16"; - -// pthread_attr_setstack(&main_attr16,NULL,PTHREAD_STACK_MIN); - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr16, ¶m); - - status = pthread_create(&main_thread16_tm_2064, &main_attr16, main_task_thread16_S0100206GN_4, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success.\n"); - } - - status = -1; - - binding(main_thread16_tm_2064, 0); - - pthread_delay( 200 ); - - /* - * 获取任务堆栈大小 - */ - status = pthread_attr_getstacksize(&main_attr16, &stack_size); - if(status==0) { - GJB_PRT_INFO("main_thread16 stack_size:%zd\n", stack_size); - - // if(pthread_attr_getstacksize(&main_attr16, NULL) == EINVAL && - // pthread_attr_getstacksize(&main_attr16_t, &stack_size) == EINVAL) - status2=pthread_attr_getstacksize(&main_attr16_t, &stack_size); - printf("undefined: %d\n",status2); - printf("undefined: stack_size %ld\n",stack_size); - - pthread_attr_destroy(&main_attr16_t); - status2=pthread_attr_getstacksize(&main_attr16_t, &stack_size); - printf("destroy %d\n",status2); - printf("destroy stack_size %ld\n",stack_size); - - if(pthread_attr_getstacksize(&main_attr16_t, &stack_size) == EINVAL) - { - GJB_PRT_INFO("main_attr16_t pthread_attr_getstacksize set invalid parameter test pass"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail"); - pthread_join(main_thread16_tm_2064, NULL); - return -1; - } - - } else { - GJB_PRT_ERROR_INFO("main_thread16 stack_size gets failed\n"); - pthread_join(main_thread16_tm_2064, NULL); - return -1; - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_2064, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test11_S0100206GN_4(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_5.c b/task_management/gjb_S0100206GN_5.c deleted file mode 100644 index bc76f30..0000000 --- a/task_management/gjb_S0100206GN_5.c +++ /dev/null @@ -1,239 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_5.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务状态切换测试 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -pthread_t main_thread16_tm_2065; - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -int pthread_getschedprio(pthread_t thread,int *priority) -{ - pthread_attr_t attr; - struct sched_param param; - int ret = 0; - if(thread <= 0x100000000) - return ESRCH; - if(priority == NULL) - { - errno = EINVAL; - return EINVAL; - } - ret = pthread_getattr_np(thread, &attr); - if(ret < 0) - { - *priority = 0; - return -1; - } - ret = pthread_attr_getschedparam(&attr, ¶m); - if(ret < 0) - { - *priority = 0; - return -1; - } - *priority = param.sched_priority; - return ret; -} - - -void *main_task_thread16_S0100206GN_5(void *arg) -{ - int i; - - for (i = 0; i < 5; i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} - -/* - * 任务属性设置和查询_任务调度策略查询_正常 - */ -int test11_S0100206GN_5 (void) -{ - int status; - pthread_t main_thread16_t = 10000; - int prio; - pthread_attr_t main_attr16; - struct sched_param param; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 任务栈地址,若为NULL时,系统在创建任务时会自动分配 - * 任务栈大小,设置调度策略,是否继承调度参数,优先级 - * 任务是否以0xee填充任务栈:不填充 - * 任务名称 - */ -// main_attr16.stackaddr = NULL; -// main_attr16.stacksize = PTHREAD_STACK_MIN; -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 5; -// main_attr16.name = "main_task_thread16"; - - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr16, ¶m); - - status = pthread_create(&main_thread16_tm_2065, &main_attr16, main_task_thread16_S0100206GN_5, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success.\n"); - } - - status = -1; - - binding(main_thread16_tm_2065, 0); - - pthread_delay(200); - - /* - * 获取任务调度策略 - */ - status = pthread_getschedprio(main_thread16_tm_2065, &prio); - if (status == 0) { - GJB_PRT_INFO("main_thread16 schedpolicy:%d\n", prio); - - if (pthread_getschedprio(main_thread16_t, &prio) == ESRCH) { - GJB_PRT_INFO("main_thread16 pthread_getschedprio set invalid parameter test pass - ESRCH\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_2065, NULL); - return -1; - } - - if (pthread_getschedprio(main_thread16_tm_2065, NULL) == EINVAL) { - GJB_PRT_INFO("main_thread16 pthread_getschedprio set invalid parameter test pass - EINVAL\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_2065, NULL); - return -1; - } - - } else { - GJB_PRT_ERROR_INFO("main_thread16 schedpolicy gets failed\n"); - pthread_join(main_thread16_tm_2065, NULL); - return -1; - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_2065, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test11_S0100206GN_5(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_6.c b/task_management/gjb_S0100206GN_6.c deleted file mode 100644 index f518cef..0000000 --- a/task_management/gjb_S0100206GN_6.c +++ /dev/null @@ -1,208 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_6.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务状态切换测试 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - - -pthread_t main_thread16_tm_2066; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -void *main_task_thread16_S0100206GN_6(void *arg) -{ - int i; - - for (i = 0; i < 5; i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} - -/* - * 任务属性设置和查询_任务调度继承策略查询_正常 - */ -int test11_S0100206GN_6 (void) -{ - int status; - int inheritsched; - pthread_attr_t main_attr16_t; - pthread_attr_t main_attr16; - struct sched_param param; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 任务栈地址,若为NULL时,系统在创建任务时会自动分配 - * 任务栈大小,设置调度策略,是否继承调度参数,优先级 - * 任务是否以0xee填充任务栈:不填充 - * 任务名称 - */ -// main_attr16.stackaddr = NULL; -// main_attr16.stacksize = PTHREAD_STACK_MIN; -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 5; -// main_attr16.name ="main_task_thread16"; - - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr16, ¶m); - - status = pthread_create(&main_thread16_tm_2066, &main_attr16, main_task_thread16_S0100206GN_6, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success.\n"); - } - - status = -1; - - binding(main_thread16_tm_2066, 0); - - pthread_delay(200); - - /* - * 获取任务调度继承策略 - */ - status = pthread_attr_getinheritsched(&main_attr16, &inheritsched); - if (status == 0) { - GJB_PRT_INFO("main_thread16 inheritsched:%d\n", inheritsched); - -// if(pthread_attr_getinheritsched(&main_attr16, NULL) == EINVAL && -// pthread_attr_getinheritsched(&main_attr16_t, &inheritsched) == EINVAL) - if(pthread_attr_getinheritsched(&main_attr16_t, &inheritsched) == 0) - { - GJB_PRT_INFO("main_thread pthread_attr_getinheritsched set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_2066, NULL); - return -1; - } - - } else { - GJB_PRT_ERROR_INFO("main_thread16 inheritsched gets failed\n"); - pthread_join(main_thread16_tm_2066, NULL); - return -1; - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_2066, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test11_S0100206GN_6(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_7.c b/task_management/gjb_S0100206GN_7.c deleted file mode 100644 index cf53ab0..0000000 --- a/task_management/gjb_S0100206GN_7.c +++ /dev/null @@ -1,222 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_7.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务状态切换测试 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -pthread_t main_thread16_tm_2067; - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -int pthread_getschedprio(pthread_t thread,int *priority) -{ - pthread_attr_t attr; - struct sched_param param; - int ret = 0; - if(thread <= 0x100000000) - return ESRCH; - if(priority == NULL) - { - errno = EINVAL; - return EINVAL; - } - ret = pthread_getattr_np(thread, &attr); - if(ret < 0) - { - *priority = 0; - return -1; - } - ret = pthread_attr_getschedparam(&attr, ¶m); - if(ret < 0) - { - *priority = 0; - return -1; - } - *priority = param.sched_priority; - return ret; -} - - -void *main_task_thread16_S0100206GN_7(void *arg) -{ - int i; - - for (i = 0; i < 5; i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} - -/* - * 任务属性设置和查询_任务优先级查询_调度策略非法_正常 - */ -int test11_S0100206GN_7 (void) -{ - int status; - int prio; - pthread_attr_t main_attr16; - struct sched_param param; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 任务栈地址,若为NULL时,系统在创建任务时会自动分配 - * 任务栈大小,设置调度策略,是否继承调度参数,优先级 - * 任务是否以0xee填充任务栈:不填充 - * 任务名称 - */ -// main_attr16.stackaddr = NULL; -// main_attr16.stacksize = PTHREAD_STACK_MIN; -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 5; -// main_attr16.name = "main_task_thread16"; - - - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr16, ¶m); - - - status = pthread_create(&main_thread16_tm_2067, &main_attr16, main_task_thread16_S0100206GN_7, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success.\n"); - } - - status = -1; - - binding(main_thread16_tm_2067, 0); - - pthread_delay( 200 ); - - /* - * 获取任务优先级 - */ - status = pthread_getschedprio(main_thread16_tm_2067, &prio); - if(status == ENOTSUP) { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_2067, NULL); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 sched_priority:%d\n", prio); - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_2067, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test11_S0100206GN_7(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_8.c b/task_management/gjb_S0100206GN_8.c deleted file mode 100644 index 0680bf7..0000000 --- a/task_management/gjb_S0100206GN_8.c +++ /dev/null @@ -1,221 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_8.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务状态切换测试 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -int pthread_getschedprio(pthread_t thread,int *priority) -{ - pthread_attr_t attr; - struct sched_param param; - int ret = 0; - if(thread <= 0x100000000) - return ESRCH; - if(priority == NULL) - { - errno = EINVAL; - return EINVAL; - } - ret = pthread_getattr_np(thread, &attr); - if(ret < 0) - { - *priority = 0; - return -1; - } - ret = pthread_attr_getschedparam(&attr, ¶m); - if(ret < 0) - { - *priority = 0; - return -1; - } - *priority = param.sched_priority; - return ret; -} - -pthread_t main_thread16_tm_2068; - -void *main_task_thread16_S0100206GN_8(void *arg) -{ - int i; - - for(i=0;i<5;i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} - -/* - * 任务属性设置和查询_任务优先级查询_调度优先级非法_正常 - */ -int test11_S0100206GN_8 (void) -{ - int status; - int prio; - pthread_attr_t main_attr16; - struct sched_param param; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 任务栈地址,若为NULL时,系统在创建任务时会自动分配 - * 任务栈大小,设置调度策略,是否继承调度参数,优先级 - * 任务是否以0xee填充任务栈:不填充 - * 任务名称 - */ -// main_attr16.stackaddr = NULL; -// main_attr16.stacksize = PTHREAD_STACK_MIN; -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.name = "main_task_thread16"; -// main_attr16.schedparam.sched_priority = 1; - - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 1; - pthread_attr_setschedparam(&main_attr16, ¶m); - - status = pthread_create(&main_thread16_tm_2068, &main_attr16, main_task_thread16_S0100206GN_8, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success.\n"); - } - - status = -1; - - binding(main_thread16_tm_2068, 0); - - pthread_delay(200); - - /* - * 获取任务优先级 - */ - status = pthread_getschedprio(main_thread16_tm_2068, &prio); - if (status == EINVAL) { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_2068, NULL); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 sched_priority:%d\n", prio); - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_2068, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test11_S0100206GN_8(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100206GN_9.c b/task_management/gjb_S0100206GN_9.c deleted file mode 100644 index dacb6ed..0000000 --- a/task_management/gjb_S0100206GN_9.c +++ /dev/null @@ -1,209 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100206GN_9.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务状态切换测试 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - -void binding (pthread_t tid, int cpu) -{ - cpu_set_t set; - CPU_ZERO(&set); - CPU_SET(cpu, &set); - pthread_setaffinity_np(tid, sizeof(set), &set); -} - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -pthread_t main_thread16_tm_2069; - -void *main_task_thread16_S0100206GN_9(void *arg) -{ - int i; - - for (i = 0; i < 5; i++) { - GJB_PRT_INFO("start main_thread16...\n"); - } - - sleep(5); - - return (NULL); -} - -/* - * 任务属性设置和查询_任务堆栈地址查询_正常 - */ -int test11_S0100206GN_9 (void) -{ - int status; - pthread_attr_t main_attr16; - void *stack_addr; - size_t stacksize; - pthread_attr_t main_attr16_t; - struct sched_param param; - - /* - * 防止系统认为该main_attr16已初始化 - */ - memset(&main_attr16, 0, sizeof(pthread_attr_t)); - - /* - * 初始化main_attr16 - */ - pthread_attr_init(&main_attr16); - - /* - * 任务栈地址,若为NULL时,系统在创建任务时会自动分配 - * 任务栈大小,设置调度策略,是否继承调度参数,优先级 - * 任务是否以0xee填充任务栈:不填充 - * 任务名称 - */ -// main_attr16.stackaddr = NULL; -// main_attr16.stacksize = PTHREAD_STACK_MIN; -// main_attr16.inheritsched = PTHREAD_EXPLICIT_SCHED; -// main_attr16.schedpolicy = SCHED_FIFO; -// main_attr16.schedparam.sched_priority = 5; -// main_attr16.name = "main_task_thread16"; - - pthread_attr_setschedpolicy(&main_attr16,SCHED_FIFO); - pthread_attr_setinheritsched(&main_attr16,PTHREAD_EXPLICIT_SCHED); - param.sched_priority = 5; - pthread_attr_setschedparam(&main_attr16, ¶m); - - - status = pthread_create(&main_thread16_tm_2069, &main_attr16, main_task_thread16_S0100206GN_9, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread16\n"); - return -1; - - } else { - GJB_PRT_INFO("main_thread16 create success\n"); - } - - status = -1; - - binding(main_thread16_tm_2069, 0); - - pthread_delay(200); - - /* - * 获取任务堆栈地址 - */ - - //status = pthread_attr_getstackaddr(&main_attr16, &stack_addr); - pthread_attr_getstack(&main_attr16, &stack_addr,&stacksize); - if(status == 0) { - GJB_PRT_INFO("pthread_attr_getstack successfully. stack_addr : %p\n", (unsigned int*)stack_addr); - - if(pthread_attr_getstack(&main_attr16_t, &stack_addr,&stacksize) == EINVAL ){ - GJB_PRT_INFO("main_thread pthread_attr_getstackaddr set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - pthread_join(main_thread16_tm_2069, NULL); - return -1; - } - - } else { - if(status == EINVAL) { - GJB_PRT_ERROR_INFO("pthread_attr_getstack ERROR\n"); - pthread_join(main_thread16_tm_2069, NULL); - return -1; - - } else { - GJB_PRT_INFO("pthread_attr_getstack success\n"); - } - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread16_tm_2069, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - binding(pthread_self(), 0); - - result = test11_S0100206GN_9(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100207GN_1.c b/task_management/gjb_S0100207GN_1.c deleted file mode 100644 index 50d05e7..0000000 --- a/task_management/gjb_S0100207GN_1.c +++ /dev/null @@ -1,138 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100207GN_1.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务创建钩子函数测试 -*********************************************************************************************************/ -#ifdef SYLIXOS -#define __SYLIXOS_KERNEL -#endif - - - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -typedef int (*_FUNC_CREATE_HOOK_PTR) (pthread_t thread_t); - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) - - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -_FUNC_CREATE_HOOK_PTR create_hook_ptr = NULL; - -int pthread_create_hook_add(void * create_hook) -{ - if (create_hook == NULL) - { - return EINVAL; - } - if (create_hook_ptr == NULL) - { - create_hook_ptr = create_hook; - } - else - { - return EAGAIN; - } - - return 0; -} - - -/* - * 可选要求接口测试_pthread_create_hook_add_添加任务创建的钩子函数中参数为NULL_返回错误码 - */ -int test13 (void) -{ - int status; - - /* - * 添加任务创建的钩子函数 - */ - status = pthread_create_hook_add(NULL); - if (status != EINVAL) { - GJB_PRT_ERROR_INFO("pthread_create_hook_add - OS_ERROR! create_hook is NULL pointer\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_create_hook_add success\n"); - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test13(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100207GN_10.c b/task_management/gjb_S0100207GN_10.c deleted file mode 100644 index 3421ed9..0000000 --- a/task_management/gjb_S0100207GN_10.c +++ /dev/null @@ -1,202 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100207GN_10.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务扩展点测试, 任务钩子函数测试 -*********************************************************************************************************/ -#ifdef SYLIXOS -#define __SYLIXOS_KERNEL -#endif - - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - - typedef int OS_STATUS; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - - - -typedef int (*_FUNC_CLOSE_HOOK_PTR) (pthread_t thread_t); - -_FUNC_CLOSE_HOOK_PTR close_hook_ptr = NULL; - -int pthread_close_hook_add(void * close_hook) -{ - if (close_hook == NULL) - { - printf("add close_hook == NULL\n"); - return EINVAL; - } - if (close_hook_ptr == NULL) - { - printf("add close_hook_ptr == NULL\n"); - close_hook_ptr = close_hook; - } - else - { - - printf("add EAGAIN\n"); - return EAGAIN; - } - - return 0; -} - -int pthread_close_hook_delete(void* close_hook) -{ - if (close_hook_ptr == NULL) - { - printf("delete close_hook_ptr == NULL\n"); - return EINVAL; - } - if (close_hook == NULL) - { - - printf("delete close_hook == NULL\n"); - return EINVAL; - } - if (close_hook_ptr != close_hook) - { - printf("delete close_hook_ptr != close_hook\n"); - return EINVAL; - } - close_hook_ptr = NULL; - return 0; -} - - - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - - - - -/* - * 任务扩展点功能_添加任务删除的钩子函数_正确,任务删除时调用该函数 - */ -OS_STATUS closeHook_S0100207GN_10(pthread_t thread_t) -{ - gjb_os_printk("close hook function called\n"); - gjb_os_printk("thread_t:0x%x close\n", (unsigned int)thread_t); - - return (0); -} - -/* - * 可选要求接口测试_pthread_close_hook_add_循环添加删除钩子函数11次失败_返回错误码 - */ -int test13_S0100207GN_10 (void) -{ - int status; - int i; - - for (i = 0; i < 17; i++) { - /* - * 添加任务删除的钩子函数 - */ - status = pthread_close_hook_add(closeHook_S0100207GN_10); - if (status == EAGAIN) { - GJB_PRT_INFO("closeHook - OS_ERROR! EINVAL %d\n", i); - for (i = 0; i< 17; i++) { - /* - * 删除已经添加的任务删除的钩子函数 - */ - status = pthread_close_hook_delete(closeHook_S0100207GN_10); - if (status == EINVAL) { - GJB_PRT_INFO("closeHook - OS_ERROR! EINVAL %d\n", i); - break; - - } else if ((status != 0) && (status != EINVAL)) { - GJB_PRT_ERROR_INFO("pthread_close_hook_delete empty table should return EAGAIN\n"); - return -1; - } - } - - return 0; - - } else if ((status != 0) && (status != EAGAIN)) { - GJB_PRT_ERROR_INFO("pthread_close_hook_add full table should return EAGAIN\n"); - return -1; - } - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test13_S0100207GN_10(); - - if (result != 0) { - return (GJB_PRI_FAIL()); - } - - return (GJB_PRI_PASS()); -} diff --git a/task_management/gjb_S0100207GN_11.c b/task_management/gjb_S0100207GN_11.c deleted file mode 100644 index 74bbbb5..0000000 --- a/task_management/gjb_S0100207GN_11.c +++ /dev/null @@ -1,232 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100207GN_11.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务扩展点测试, 任务关闭钩子函数测试, 钩子函数将在任务关闭的时候调用 -*********************************************************************************************************/ -#ifdef SYLIXOS -#define __SYLIXOS_KERNEL -#endif - - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -pthread_t myFunc_thread_tm_20711; -static int enterHook_times1_tm_20711 = 0; - - -typedef int OS_STATUS; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - - - -typedef int (*_FUNC_CLOSE_HOOK_PTR) (pthread_t thread_t); - -_FUNC_CLOSE_HOOK_PTR close_hook_ptr = NULL; - -int pthread_close_hook_add(void * close_hook) -{ - if (close_hook == NULL) - { - printf("add close_hook == NULL\n"); - return EINVAL; - } - if (close_hook_ptr == NULL) - { - printf("add close_hook_ptr == NULL\n"); - close_hook_ptr = close_hook; - } - else - { - - printf("add EAGAIN\n"); - return EAGAIN; - } - - return 0; -} - -int pthread_close_hook_delete(void* close_hook) -{ - if (close_hook_ptr == NULL) - { - printf("delete close_hook_ptr == NULL\n"); - return EINVAL; - } - if (close_hook == NULL) - { - - printf("delete close_hook == NULL\n"); - return EINVAL; - } - if (close_hook_ptr != close_hook) - { - printf("delete close_hook_ptr != close_hook\n"); - return EINVAL; - } - close_hook_ptr = NULL; - return 0; -} - - - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - - - - - - -/* - * 任务扩展点功能_添加任务创建的钩子函数_正确,任务扩展点功能_添加任务删除的钩子函数_正确,创建的线程 - */ -void *myFunc_S0100207GN_11(void *arg) -{ - GJB_PRT_INFO("Hello, I am thread 0x%x\n", (unsigned int)pthread_self()); - - return NULL; -} - -/* - * 任务扩展点功能_添加任务删除的钩子函数_正确,任务删除时调用该函数 - */ -OS_STATUS closeHook_S0100207GN_11(pthread_t thread_t) -{ - enterHook_times1_tm_20711++; - - return 0; -} - -/* - * 任务扩展点功能_添加任务创建的钩子函数_正确 - * 可选要求接口测试_pthread_close_hook_add_循环添加删除钩子函数11次失败_返回错误码 - */ -int test13_S0100207GN_11 (void) -{ - int status; - - /* - * 添加任务删除的钩子函数 - */ - status = pthread_close_hook_add(closeHook_S0100207GN_11); - if (status != 0) { - GJB_PRT_ERROR_INFO("closeHook - OS_ERROR!\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_close_hook_add add hook success\n"); - } - - status = -1; - - status = pthread_create(&myFunc_thread_tm_20711, NULL, myFunc_S0100207GN_11, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating myFunc_thread\n"); - return -1; - - } else { - GJB_PRT_INFO("myFunc_thread add create success\n"); - } - - /* - * 等待任务结束 - */ - pthread_join(myFunc_thread_tm_20711,NULL); - - /* - * 删除列表中的closeHook钩子函数 - */ - if (pthread_close_hook_delete(NULL) == EINVAL && - pthread_close_hook_delete((OS_STATUS (*)(pthread_t))myFunc_S0100207GN_11) == EINVAL) { - GJB_PRT_INFO("pthread_close_hook_delete set invalid parameter test pass\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation --set invalid parameter test fail\n"); - return -1; - } - - GJB_PRT_INFO("enterHook_times1: %d\n", enterHook_times1_tm_20711); - if (enterHook_times1_tm_20711 == 0) { - return -1; - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test13_S0100207GN_11(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100207GN_12.c b/task_management/gjb_S0100207GN_12.c deleted file mode 100644 index 6b21924..0000000 --- a/task_management/gjb_S0100207GN_12.c +++ /dev/null @@ -1,267 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100207GN_12.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务扩展点测试, 任务关闭钩子函数测试 -*********************************************************************************************************/ -#ifdef SYLIXOS -#define __SYLIXOS_KERNEL -#endif - - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -pthread_t myFunc_thread_tm_20712; -static int enterHook_times_12_tm_20712 = 0; - - -typedef int OS_STATUS; - - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - - - -typedef int (*_FUNC_CLOSE_HOOK_PTR) (pthread_t thread_t); - -_FUNC_CLOSE_HOOK_PTR close_hook_ptr = NULL; - -int pthread_close_hook_add(void * close_hook) -{ - if (close_hook == NULL) - { - printf("add close_hook == NULL\n"); - return EINVAL; - } - if (close_hook_ptr == NULL) - { - printf("add close_hook_ptr == NULL\n"); - close_hook_ptr = close_hook; - } - else - { - - printf("add EAGAIN\n"); - return EAGAIN; - } - - return 0; -} - -int pthread_close_hook_delete(void* close_hook) -{ - if (close_hook_ptr == NULL) - { - printf("delete close_hook_ptr == NULL\n"); - return EINVAL; - } - if (close_hook == NULL) - { - - printf("delete close_hook == NULL\n"); - return EINVAL; - } - if (close_hook_ptr != close_hook) - { - printf("delete close_hook_ptr != close_hook\n"); - return EINVAL; - } - close_hook_ptr = NULL; - return 0; -} - - - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - - - - - - - - -/* - * 任务扩展点功能_添加任务创建的钩子函数_正确,任务扩展点功能_添加任务删除的钩子函数_正确,创建的线程 - */ -void *myFunc_S0100207GN_12 (void *arg) -{ - int status; - int i; - - GJB_PRT_INFO("Hello, I am thread 0x%x\n", (unsigned int)pthread_self()); - - for (i = 0; i < 10; i++) { - if (i == 0) { - /* - * 取消线程 - */ - status = pthread_cancel(myFunc_thread_tm_20712); - if(status != 0) { - GJB_PRT_ERROR_INFO("myFunc_thread cancel failed\n"); - return ((void *)123); - - } else { - GJB_PRT_INFO("myFunc_thread cancel success\n"); - } - - } else { - /* - * 设置取消点 - */ - pthread_testcancel(); - } - } - - return ((void *)123); -} - -/* - * 任务扩展点功能_添加任务删除的钩子函数_正确,任务删除时调用该函数 - */ -OS_STATUS closeHook_S0100207GN_12(pthread_t thread_t) -{ - enterHook_times_12_tm_20712++; - - return 0; -} - -/* - * 任务扩展点功能_添加任务创建的钩子函数_正确 - */ -int test13_S0100207GN_12 (void) -{ - int status; - void *join_s = NULL; - - /* - * 添加任务删除的钩子函数 - */ - status = pthread_close_hook_add(closeHook_S0100207GN_12); - if (status != 0) { - GJB_PRT_ERROR_INFO("add closeHook - OS_ERROR!\n"); - return -1; - - } else { - GJB_PRT_INFO("add closeHook success\n"); - } - - status = pthread_create(&myFunc_thread_tm_20712, NULL, myFunc_S0100207GN_12, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating myFunc_thread\n"); - pthread_close_hook_delete(closeHook_S0100207GN_12); - return -1; - - } else { - GJB_PRT_INFO("creating myFunc_thread success\n"); - } - - /* - * 等待任务结束 - */ - pthread_join(myFunc_thread_tm_20712, &join_s); - - if ((long)join_s == 123) { - GJB_PRT_ERROR_INFO("myFunc_thread pthread_testcancel fail\n"); - pthread_close_hook_delete(closeHook_S0100207GN_12); - return -1; - - } else { - GJB_PRT_INFO("myFunc_thread pthread_testcancel success\n"); - } - - /* - * 删除列表中的closeHook钩子函数 - */ - if (pthread_close_hook_delete(closeHook_S0100207GN_12) == 0) { - GJB_PRT_INFO("pthread_close_hook_delete - successfully!\n"); - - } else { - GJB_PRT_ERROR_INFO("pthread_close_hook_delete - FAILED\n"); - return -1; - } - - GJB_PRT_INFO("enterHook_times_12: %d\n", enterHook_times_12_tm_20712); - if (enterHook_times_12_tm_20712 == 0) { - return -1; - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test13_S0100207GN_12(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100207GN_2.c b/task_management/gjb_S0100207GN_2.c deleted file mode 100644 index 917b599..0000000 --- a/task_management/gjb_S0100207GN_2.c +++ /dev/null @@ -1,184 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100207GN_2.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务属性设置与查询测试 -*********************************************************************************************************/ -#ifdef SYLIXOS -#define __SYLIXOS_KERNEL -#endif - - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - - typedef int OS_STATUS; - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -//#define gjb_printk(fmt, arg...) printk(fmt, ##arg) - -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - - -typedef int (*_FUNC_CREATE_HOOK_PTR) (pthread_t thread_t); - - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -_FUNC_CREATE_HOOK_PTR create_hook_ptr = NULL; - - -int pthread_create_hook_add(void * create_hook) -{ - if (create_hook == NULL) - { - return EINVAL; - } - if (create_hook_ptr == NULL) - { - create_hook_ptr = create_hook; - } - else - { - return EAGAIN; - } - - return 0; -} - -int pthread_create_hook_delete(void* create_hook) -{ - if (create_hook_ptr == NULL) - { - return EINVAL; - } - if (create_hook == NULL) - { - return EINVAL; - } - if (create_hook_ptr != create_hook) - { - return EINVAL; - } - create_hook_ptr = NULL; - return 0; -} - - -/* - * 任务扩展点功能_添加任务创建的钩子函数_正确,任务创建时调用该函数 - */ -OS_STATUS TaskHook_S0100207GN_2(pthread_t thread_t) -{ - gjb_os_printk("task hook function called\n"); - gjb_os_printk("thread_t:0x%x task\n", (unsigned int)thread_t); - - return 0; -} - -/* - * 任务扩展点功能_添加任务创建的钩子函数_正确 - * 可选要求接口测试_pthread_create_hook_add_for循环添加任务创建的钩子函数_返回错误码 - */ -int test13_S0100207GN_2 (void) -{ - int status; - int i; - - - for (i = 0; i < 17; i++) { /* 17 需要根据不同的操作系统进行修改 */ - /* - * 添加任务创建的钩子函数 - */ - status = pthread_create_hook_add(TaskHook_S0100207GN_2); - if (status == EAGAIN) { - GJB_PRT_INFO("pthread_create_hook_add set invalid parameter test pass --create_hook is NULL pointer %d\n", i); - - for (i--; i >= 0; i--) { - pthread_create_hook_delete(TaskHook_S0100207GN_2); - } - - return 0; - - } else if ((status != 0) && (status != EAGAIN)) { - GJB_PRT_ERROR_INFO("pthread_create_hook_add hook table full should return EAGAIN\n"); - return -1; - - } - - } - return 0; -} -/********************************************************************************************************* - * 函数名称: GJB_ENTRY - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test13_S0100207GN_2(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100207GN_3.c b/task_management/gjb_S0100207GN_3.c deleted file mode 100644 index 99d10aa..0000000 --- a/task_management/gjb_S0100207GN_3.c +++ /dev/null @@ -1,215 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100207GN_3.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务扩展点测试 -*********************************************************************************************************/ -#ifdef SYLIXOS -#define __SYLIXOS_KERNEL -#endif - - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - typedef int OS_STATUS; - - -pthread_t myFunc_thread_tm_2073; -static int enterHook_times_3_tm_2073 = 0; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - - -typedef int (*_FUNC_CREATE_HOOK_PTR) (pthread_t thread_t); - - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -_FUNC_CREATE_HOOK_PTR create_hook_ptr = NULL; - - -int pthread_create_hook_add(void * create_hook) -{ - if (create_hook == NULL) - { - return EINVAL; - } - if (create_hook_ptr == NULL) - { - create_hook_ptr = create_hook; - } - else - { - return EAGAIN; - } - - return 0; -} - -int pthread_create_hook_delete(void* create_hook) -{ - if (create_hook_ptr == NULL) - { - return EINVAL; - } - if (create_hook == NULL) - { - return EINVAL; - } - if (create_hook_ptr != create_hook) - { - return EINVAL; - } - create_hook_ptr = NULL; - return 0; -} - - - -/* - * 任务扩展点功能_添加任务创建的钩子函数_正确,任务创建时调用该函数 - */ -OS_STATUS TaskHook_S0100207GN_3 (pthread_t thread_t) -{ - enterHook_times_3_tm_2073++; - return 0; -} - -/* - * 任务扩展点功能_添加任务创建的钩子函数_正确,任务扩展点功能_添加任务删除的钩子函数_正确,创建的线程 - */ -void *myFunc_S0100207GN_3 (void *arg) -{ - GJB_PRT_INFO("Hello, I am thread 0x%x\n", (unsigned int)pthread_self()); - - return (NULL); -} - -/* - * 可选要求接口测试_pthread_create_hook_delete_删除不存在的钩子函数以及删除NULL指针_返回错误码 - */ -int test13_S0100207GN_3 (void) -{ - int status; - - /* - * 添加任务创建的钩子函数 - */ - status = pthread_create_hook_add(TaskHook_S0100207GN_3); - if (status != 0) { - GJB_PRT_ERROR_INFO("pthread_create_hook_add - OS_ERROR!\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_create_hook_add add hook success\n"); - } - - status = -1; - - status = pthread_create(&myFunc_thread_tm_2073, NULL, myFunc_S0100207GN_3, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating myFunc_thread\n"); - return -1; - - } else { - GJB_PRT_INFO("myFunc_thread create success\n"); - } - - /* - * 等待任务结束 - */ - pthread_join(myFunc_thread_tm_2073, NULL); - - /* - * 删除列表中的TaskHook钩子函数 - */ - if(pthread_create_hook_delete((OS_STATUS (*)(pthread_t))myFunc_S0100207GN_3) == EINVAL && - pthread_create_hook_delete(NULL) == EINVAL) { - GJB_PRT_INFO("pthread_create_hook_delete - OS_ERROR! EINVAL\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation -- Invalid parameter : EINVAL\n"); - return -1; - } - - GJB_PRT_INFO("enterHook_times_3: %d\n", enterHook_times_3_tm_2073); - if (enterHook_times_3_tm_2073 == 0) { - return -1; - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test13_S0100207GN_3(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100207GN_4.c b/task_management/gjb_S0100207GN_4.c deleted file mode 100644 index c0ef774..0000000 --- a/task_management/gjb_S0100207GN_4.c +++ /dev/null @@ -1,217 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100207GN_4.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务扩展点测试, 任务创建钩子函数测试 -*********************************************************************************************************/ -#ifdef SYLIXOS -#define __SYLIXOS_KERNEL -#endif - - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - typedef int OS_STATUS; - -pthread_t myFunc_thread_tm_2074; -static int enterHook_times_4_tm_2074 = 0; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - - -typedef int (*_FUNC_CREATE_HOOK_PTR) (pthread_t thread_t); - - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -_FUNC_CREATE_HOOK_PTR create_hook_ptr = NULL; - - -int pthread_create_hook_add(void * create_hook) -{ - if (create_hook == NULL) - { - return EINVAL; - } - if (create_hook_ptr == NULL) - { - create_hook_ptr = create_hook; - } - else - { - return EAGAIN; - } - - return 0; -} - -int pthread_create_hook_delete(void* create_hook) -{ - if (create_hook_ptr == NULL) - { - return EINVAL; - } - if (create_hook == NULL) - { - return EINVAL; - } - if (create_hook_ptr != create_hook) - { - return EINVAL; - } - create_hook_ptr = NULL; - return 0; -} - - -/* - * 任务扩展点功能_添加任务创建的钩子函数_正确,任务创建时调用该函数 - */ -OS_STATUS TaskHook_S0100207GN_4 (pthread_t thread_t) -{ - enterHook_times_4_tm_2074++; - - return 0; -} - -/* - * 任务扩展点功能_添加任务创建的钩子函数_正确, - * 任务扩展点功能_添加任务删除的钩子函数_正确, 创建的线程 - */ -void *myFunc_S0100207GN_4 (void *arg) -{ - GJB_PRT_INFO("Hello, I am thread 0x%x\n", (unsigned int)pthread_self()); - - return (NULL); -} - -/* - * 任务扩展点功能_添加任务创建的钩子函数_正确 - */ -int test13_S0100207GN_4 (void) -{ - int status; - - /* - * 添加任务创建的钩子函数 - */ - status = pthread_create_hook_add(TaskHook_S0100207GN_4); - if (status != 0) { - GJB_PRT_ERROR_INFO("pthread_create_hook_add - OS_ERROR!\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_create_hook_add hook add success.\n"); - } - - status = -1; - - status = pthread_create(&myFunc_thread_tm_2074, NULL, myFunc_S0100207GN_4, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating myFunc_thread\n"); - return -1; - - } else { - GJB_PRT_INFO("myFunc_thread create success.\n"); - } - - status = -1; - /* - * 等待任务结束 - */ - pthread_join(myFunc_thread_tm_2074,NULL); - - /* - * 删除列表中的TaskHook钩子函数 - */ - status = pthread_create_hook_delete(TaskHook_S0100207GN_4); - if (status == 0) { - GJB_PRT_INFO("delete TaskHook - successfully!\n"); - - } else { - GJB_PRT_ERROR_INFO("delete TaskHook - fail\n"); - return -1; - } - - GJB_PRT_INFO("enterHook_times_4: %d\n", enterHook_times_4_tm_2074); - if (enterHook_times_4_tm_2074 == 0) { - return -1; - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: GJB_ENTRY() - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test13_S0100207GN_4(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100207GN_5.c b/task_management/gjb_S0100207GN_5.c deleted file mode 100644 index 18a6cb3..0000000 --- a/task_management/gjb_S0100207GN_5.c +++ /dev/null @@ -1,296 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100207GN_5.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务扩展点测试 -*********************************************************************************************************/ -#ifdef SYLIXOS -#define __SYLIXOS_KERNEL -#endif - - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - -static int enterHook_times_5_tm_2075 = 0; - - -typedef int OS_STATUS; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - - -typedef int (*_FUNC_CREATE_HOOK_PTR) (pthread_t thread_t); -typedef int (*_FUNC_SWITCH_HOOK_PTR) (pthread_t thread_t1,pthread_t thread_t2); - - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} -_FUNC_CREATE_HOOK_PTR create_hook_ptr = NULL; - - -int pthread_create_hook_add(void * create_hook) -{ - if (create_hook == NULL) - { - return EINVAL; - } - if (create_hook_ptr == NULL) - { - create_hook_ptr = create_hook; - } - else - { - return EAGAIN; - } - - return 0; -} - -int pthread_create_hook_delete(void* create_hook) -{ - if (create_hook_ptr == NULL) - { - return EINVAL; - } - if (create_hook == NULL) - { - return EINVAL; - } - if (create_hook_ptr != create_hook) - { - return EINVAL; - } - create_hook_ptr = NULL; - return 0; -} - - -_FUNC_SWITCH_HOOK_PTR switch_hook_ptr = NULL; -int pthread_switch_hook_add(void * switch_hook) -{ - pthread_t thread1 = 0, thread2= 0; - if (switch_hook == NULL) - { - return EINVAL; - } - if (switch_hook_ptr == NULL) - { - switch_hook_ptr = switch_hook; - } - else - { - return EAGAIN; - } - if (switch_hook_ptr!= NULL) - { - srand(time(NULL)); - int a = rand() % 11; - for (size_t i = 0; i < a; i++) - { - switch_hook_ptr(thread1,thread2); - } - } - return 0; -} - -int pthread_switch_hook_delete(void * switch_hook) -{ - if (switch_hook_ptr == NULL) - { - return EINVAL; - } - if (switch_hook == NULL) - { - return EINVAL; - } - if (switch_hook_ptr != switch_hook) - { - return EINVAL; - } - switch_hook_ptr = NULL; - return 0; -} - - -/* - * 任务扩展点功能_添加任务切换的钩子函数_正确,任务切换时调用该函数 - */ -OS_STATUS switchHook_S0100207GN_5 (pthread_t thread_t1, pthread_t thread_t2) -{ - enterHook_times_5_tm_2075++; - return (0); -} - -/* - * 任务扩展点功能_添加任务切换的钩子函数_正确,创建的线程1 - */ -void *myFuncthread_t1_S0100207GN_5(void *arg) -{ - int i; - - for (i = 0; i < 9; i++) { - GJB_PRT_INFO("Hello, I am thread1 0x%x\n", (unsigned int)pthread_self()); - } - - return (NULL); -} - -/* - * 任务扩展点功能_添加任务切换的钩子函数_正确,创建的线程2 - */ -void *myFuncthread_t2_S0100207GN_5(void *arg) -{ - int i; - - for (i = 0; i < 9; i++) { - GJB_PRT_INFO("Hello, I am thread2 0x%x\n", (unsigned int)pthread_self()); - } - - return (NULL); -} - -/* - * 任务扩展点功能_添加任务创建的钩子函数_正确 - * 可选要求接口测试_pthread_switch_hook_delete_切换钩子函数删除失败_返回错误码 - */ -int test13_S0100207GN_5 (void) -{ - int status; - pthread_t myFunc_thread1, myFunc_thread2; - - /* - * 添加任务切换的钩子函数 - */ - status = pthread_switch_hook_add(switchHook_S0100207GN_5); - if (status != 0) { - GJB_PRT_ERROR_INFO("pthread_switch_hook_add - OS_ERROR!\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_switch_hook_add success\n"); - } - - status = -1; - - status = pthread_create(&myFunc_thread1, NULL, myFuncthread_t1_S0100207GN_5, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating myFunc_thread1\n"); - return -1; - - } else { - GJB_PRT_INFO("creating myFunc_thread1 success\n"); - } - - status = -1; - - status = pthread_create(&myFunc_thread2, NULL, myFuncthread_t2_S0100207GN_5, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating myFunc_thread2\n"); - return -1; - - } else { - GJB_PRT_INFO("creating myFunc_thread2 success\n"); - } - - status = -1; - /* - * 等待任务结束 - */ - pthread_join(myFunc_thread1, NULL); - pthread_join(myFunc_thread2, NULL); - - /* - * 删除列表中的switchHook钩子函数 - */ - status = pthread_switch_hook_delete(switchHook_S0100207GN_5); - if(pthread_switch_hook_delete((OS_STATUS (*)(pthread_t, pthread_t))myFuncthread_t1_S0100207GN_5) == EINVAL && - pthread_switch_hook_delete(NULL) == EINVAL) { - GJB_PRT_INFO("pthread_switch_hook_delete - OS_ERROR! EINVAL\n"); - - } else { - GJB_PRT_ERROR_INFO("Inconsistent with expectation -- Invalid parameter : EINVAL\n"); - return -1; - } - - GJB_PRT_INFO("enterHook_times_5: %d\n", enterHook_times_5_tm_2075); - if (enterHook_times_5_tm_2075 == 0) { - return -1; - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test13_S0100207GN_5(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100207GN_6.c b/task_management/gjb_S0100207GN_6.c deleted file mode 100644 index 7b9a7a7..0000000 --- a/task_management/gjb_S0100207GN_6.c +++ /dev/null @@ -1,205 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100207GN_6.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务扩展点测试, 任务切换钩子函数测试 -*********************************************************************************************************/ -#ifdef SYLIXOS -#define __SYLIXOS_KERNEL -#endif - - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - typedef int OS_STATUS; - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - - -typedef int (*_FUNC_SWITCH_HOOK_PTR) (pthread_t thread_t1,pthread_t thread_t2); - - - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - - - - -_FUNC_SWITCH_HOOK_PTR switch_hook_ptr = NULL; -int pthread_switch_hook_add(void * switch_hook) -{ - pthread_t thread1 = 0, thread2= 0; - if (switch_hook == NULL) - { - return EINVAL; - } - if (switch_hook_ptr == NULL) - { - switch_hook_ptr = switch_hook; - } - else - { - return EAGAIN; - } - if (switch_hook_ptr!= NULL) - { - srand(time(NULL)); - int a = rand() % 11; - for (size_t i = 0; i < a; i++) - { - switch_hook_ptr(thread1,thread2); - } - } - return 0; -} - -int pthread_switch_hook_delete(void * switch_hook) -{ - if (switch_hook_ptr == NULL) - { - return EINVAL; - } - if (switch_hook == NULL) - { - return EINVAL; - } - if (switch_hook_ptr != switch_hook) - { - return EINVAL; - } - switch_hook_ptr = NULL; - return 0; -} - - - - - -/* - * 任务扩展点功能_添加任务切换的钩子函数_正确,创建的线程1 - */ -void *myFuncthread_t1_S0100207GN_6(void *arg) -{ - int i; - - for(i = 0; i < 9; i++) { - GJB_PRT_INFO("Hello, I am thread1 0x%x\n", (unsigned int)pthread_self()); - } - - return (NULL); -} - -/* - * 任务扩展点功能_添加任务创建的钩子函数_正确 - * 可选要求接口测试_pthread_switch_hook_add_添加切换钩子函数失败_返回错误码 - */ -int test13_S0100207GN_6 (void) -{ - int status; - pthread_t myFunc_thread1; - - /* - * 添加任务切换的钩子函数 - */ - status = pthread_switch_hook_add(NULL); - if (status != EINVAL) { - GJB_PRT_ERROR_INFO("pthread_switch_hook_add - OS_ERROR! NO EINVAL\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_switch_hook_add add hook success.\n"); - } - - status = -1; - - status = pthread_create(&myFunc_thread1, NULL, myFuncthread_t1_S0100207GN_6, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating myFunc_thread1\n"); - return -1; - - } else { - GJB_PRT_INFO("myFunc_thread1 create success.\n"); - } - - /* - * 等待线程结束 - */ - pthread_join(myFunc_thread1, NULL); - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test13_S0100207GN_6(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100207GN_7.c b/task_management/gjb_S0100207GN_7.c deleted file mode 100644 index e50aa18..0000000 --- a/task_management/gjb_S0100207GN_7.c +++ /dev/null @@ -1,210 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100207GN_7.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务扩展点测试, 任务切换钩子测试 -*********************************************************************************************************/ -#ifdef SYLIXOS -#define __SYLIXOS_KERNEL -#endif - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -static int i_tm_2077 = 0; - -typedef int OS_STATUS; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - - -typedef int (*_FUNC_SWITCH_HOOK_PTR) (pthread_t thread_t1,pthread_t thread_t2); - - - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - - -_FUNC_SWITCH_HOOK_PTR switch_hook_ptr = NULL; -int pthread_switch_hook_add(void * switch_hook) -{ - pthread_t thread1 = 0, thread2= 0; - if (switch_hook == NULL) - { - return EINVAL; - } - if (switch_hook_ptr == NULL) - { - switch_hook_ptr = switch_hook; - } - else - { - return EAGAIN; - } - if (switch_hook_ptr!= NULL) - { - srand(time(NULL)); - int a = rand() % 11; - for (size_t i = 0; i < a; i++) - { - switch_hook_ptr(thread1,thread2); - } - } - return 0; -} - -int pthread_switch_hook_delete(void * switch_hook) -{ - if (switch_hook_ptr == NULL) - { - return EINVAL; - } - if (switch_hook == NULL) - { - return EINVAL; - } - if (switch_hook_ptr != switch_hook) - { - return EINVAL; - } - switch_hook_ptr = NULL; - return 0; -} - -/* - * 任务扩展点功能_添加任务切换的钩子函数_正确,任务切换时调用该函数 - */ -OS_STATUS switchHook_S0100207GN_7 (pthread_t thread_t1, pthread_t thread_t2) -{ - if (i_tm_2077 < 10) { - gjb_os_printk("switch hook function called\n"); - - gjb_os_printk("thread_t1:0x%x and thread_t2:0x%x switch\n", (unsigned int)thread_t1, (unsigned int)thread_t2); - } - - i_tm_2077++; - - if (i_tm_2077 >= 12) { - i_tm_2077 = 12; - } - - return (0); -} - -/* - * 可选要求接口测试_pthread_switch_hook_add_循环添加切换钩子函数10次失败_返回错误码 - */ -int test13_S0100207GN_7 (void) -{ - int status; - int i; - - for (i = 0; i < 17; i++) { - /* - * 添加任务切换的钩子函数 - */ - status = pthread_switch_hook_add(switchHook_S0100207GN_7); - if (status == EAGAIN) { - GJB_PRT_INFO("pthread_switch_hook_add - OS_ERROR! EAGAIN i = %d test pass\n", i); - - /* - * 等待一段时间, 保证 HOOK 函数可以执行 - */ - pthread_delay(1000); - - for (i--; i >= 0; --i) { - pthread_switch_hook_delete(switchHook_S0100207GN_7); - } - break; - - } else if ((status != 0) && (status != EAGAIN)) { - GJB_PRT_ERROR_INFO("pthread_switch_hook_add hook table full should return EAGAIN\n"); - return -1; - } - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test13_S0100207GN_7(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100207GN_8.c b/task_management/gjb_S0100207GN_8.c deleted file mode 100644 index ec4c273..0000000 --- a/task_management/gjb_S0100207GN_8.c +++ /dev/null @@ -1,263 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100207GN_8.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务扩展点测试, 任务切换钩子测试 -*********************************************************************************************************/ -#ifdef SYLIXOS -#define __SYLIXOS_KERNEL -#endif - - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - -static int enterHook_times_8_tm_2078 = 0; - -typedef int OS_STATUS; - - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - - -typedef int (*_FUNC_SWITCH_HOOK_PTR) (pthread_t thread_t1,pthread_t thread_t2); - - - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - - - - -_FUNC_SWITCH_HOOK_PTR switch_hook_ptr = NULL; -int pthread_switch_hook_add(void * switch_hook) -{ - pthread_t thread1 = 0, thread2= 0; - if (switch_hook == NULL) - { - return EINVAL; - } - if (switch_hook_ptr == NULL) - { - switch_hook_ptr = switch_hook; - } - else - { - return EAGAIN; - } - if (switch_hook_ptr!= NULL) - { - srand(time(NULL)); - int a = rand() % 11; - for (size_t i = 0; i < a; i++) - { - switch_hook_ptr(thread1,thread2); - } - } - return 0; -} - -int pthread_switch_hook_delete(void * switch_hook) -{ - if (switch_hook_ptr == NULL) - { - return EINVAL; - } - if (switch_hook == NULL) - { - return EINVAL; - } - if (switch_hook_ptr != switch_hook) - { - return EINVAL; - } - switch_hook_ptr = NULL; - return 0; -} - - - - - -/* - * 任务扩展点功能_添加任务切换的钩子函数_正确,任务切换时调用该函数 - */ -OS_STATUS switchHook_S0100207GN_8(pthread_t thread_t1,pthread_t thread_t2) -{ - enterHook_times_8_tm_2078++; - - return 0; -} - -/* - * 任务扩展点功能_添加任务切换的钩子函数_正确,创建的线程1 - */ -void *myFuncthread_t1_S0100207GN_8 (void *arg) -{ - int i; - - for (i = 0; i < 9; i++) { - GJB_PRT_INFO("Hello, I am thread1 0x%x\n", (unsigned int)pthread_self()); - } - - return (NULL); -} - -/* - * 任务扩展点功能_添加任务切换的钩子函数_正确,创建的线程2 - */ -void *myFuncthread_t2_S0100207GN_8(void *arg) -{ - int i; - - for (i=0;i<9;i++) { - GJB_PRT_INFO("Hello, I am thread2 0x%x\n", (unsigned int)pthread_self()); - } - - return (NULL); -} - -/* - * 任务扩展点功能_添加任务切换的钩子函数_正确 - */ -int test13_S0100207GN_8() -{ - int status; - pthread_t myFunc_thread1, myFunc_thread2; - - /* - * 添加任务切换的钩子函数 - */ - status = pthread_switch_hook_add(switchHook_S0100207GN_8); - if (status != 0) { - GJB_PRT_ERROR_INFO("pthread_switch_hook_add - OS_ERROR!\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_switch_hook_add switchHook success.\n"); - } - - status = -1; - - status = pthread_create(&myFunc_thread1, NULL, myFuncthread_t1_S0100207GN_8, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating myFunc_thread1\n"); - return -1; - - } else { - GJB_PRT_INFO("creating myFunc_thread1 success.\n"); - } - - status = -1; - - status = pthread_create(&myFunc_thread2, NULL, myFuncthread_t2_S0100207GN_8, NULL); - if(status != 0) { - GJB_PRT_ERROR_INFO("Error creating myFunc_thread2\n"); - return -1; - - } else { - GJB_PRT_INFO("creating myFunc_thread2 success.\n"); - } - - status = -1; - /* - * 等待任务结束 - */ - pthread_join(myFunc_thread1,NULL); - pthread_join(myFunc_thread2,NULL); - - /* - * 删除列表中的switchHook钩子函数 - */ - status = pthread_switch_hook_delete(switchHook_S0100207GN_8); - if(status == 0) { - GJB_PRT_INFO("pthread_switch_hook_delete - successfully!\n"); - - } else { - GJB_PRT_ERROR_INFO("pthread_switch_hook_delete fail.\n"); - return -1; - } - - GJB_PRT_INFO("enterHook_times_8: %d\n", enterHook_times_8_tm_2078); - if (enterHook_times_8_tm_2078 == 0) { - return -1; - } - - return 0; -} - -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test13_S0100207GN_8(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100207GN_9.c b/task_management/gjb_S0100207GN_9.c deleted file mode 100644 index f84af5c..0000000 --- a/task_management/gjb_S0100207GN_9.c +++ /dev/null @@ -1,145 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100207GN_9.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务扩展点测试, 任务关闭钩子测试 -*********************************************************************************************************/ -#ifdef SYLIXOS -#define __SYLIXOS_KERNEL -#endif - - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - typedef int OS_STATUS; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - - - -typedef int (*_FUNC_CLOSE_HOOK_PTR) (pthread_t thread_t); - -_FUNC_CLOSE_HOOK_PTR close_hook_ptr = NULL; - -int pthread_close_hook_add(void * close_hook) -{ - if (close_hook == NULL) - { - return EINVAL; - } - if (close_hook_ptr == NULL) - { - close_hook_ptr = close_hook; - } - else - { - return EINVAL; - } - - return 0; -} - - - - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - - - - -/* - * 可选要求接口测试_pthread_close_hook_add_添加NULL删除钩子函数_返回错误码 - */ -int test13_S0100207GN_9 (void) -{ - int status; - - /* - * 添加任务删除的钩子函数 - */ - status = pthread_close_hook_add(NULL); - if(status != EINVAL) { - GJB_PRT_ERROR_INFO("Inconsistent with expectation -- Invalid parameter : EINVAL\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_close_hook_add set invalid parameter test pass\n"); - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test13_S0100207GN_9(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100209GN_1.c b/task_management/gjb_S0100209GN_1.c deleted file mode 100644 index 2a269df..0000000 --- a/task_management/gjb_S0100209GN_1.c +++ /dev/null @@ -1,227 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100209GN_1.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务私有变量测试, 全局变量在不同线程中私有 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -/* - * 私有数据,全局变量 - */ -static pthread_key_t key_1_tm_2091 = 1; - -/* - * main_task_thread17对全局变量key设置私有数据 - */ -void *main_task_thread17_tm_2091(void *arg) -{ - int temp = 10; - int i = temp; - void *p; - - GJB_PRT_INFO("main_task_thread17 set key value %d\n", temp); - - /* - * 设置私有数据 - */ - pthread_setspecific(key_1_tm_2091, (void *)(long)i); - - pthread_delay(200); - - /* - * 获取任务私有数据 - */ - if ((p = pthread_getspecific(key_1_tm_2091)) != NULL) { - GJB_PRT_INFO("pthread_getspecific successfully, main_task_thread17 key %x value is %d\n", - (unsigned int)key_1_tm_2091, (int)(long)p); - - } else { - GJB_PRT_ERROR_INFO("pthread_getspecific failed\n"); - return ((void *)-1); - } - - return (NULL); -} - -/* - * main_task_thread18对全局变量key设置私有数据 - */ -void *main_task_thread18_tm_2091 (void *arg) -{ - int temp = 20; - int i = temp; - void *p; - - GJB_PRT_INFO("main_task_thread18 set key value %d\n", temp); - - /* - * 设置私有数据 - */ - pthread_setspecific(key_1_tm_2091, (void *)(long)i); - - pthread_delay(100); - - /* - * 获取任务私有数据 - */ - if ((p = pthread_getspecific(key_1_tm_2091)) != NULL) { - GJB_PRT_INFO("pthread_getspecific successfully,main_task_thread18 key %x value is %d\n", - (unsigned int)key_1_tm_2091, (int)(long)p); - - } else { - GJB_PRT_ERROR_INFO("pthread_getspecific failed\n"); - return ((void *)-1); - } - - return (NULL); -} - -/* - * 任务变量测试_同一全局变量在不同线程中私有_正常 - */ -int test14_tm_2091 (void) -{ - int status; - pthread_t main_thread17, main_thread18; - - /* - * 创建一个数据键 - */ - status = pthread_key_create(&key_1_tm_2091, NULL); - if (status == 0) { - GJB_PRT_INFO("pthread_key_create successfully! key:%x\n", (unsigned int)key_1_tm_2091); - - } else { - GJB_PRT_ERROR_INFO("Error: pthread_key_create() failed\n"); - return -1; - } - - status = -1; - - status = pthread_create(&main_thread17, NULL, main_task_thread17_tm_2091, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread17\n"); - return -1; - - } else { - GJB_PRT_INFO("creating main_thread17 success\n"); - } - - status = -1; - - status = pthread_create(&main_thread18, NULL, main_task_thread18_tm_2091, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread18\n"); - return -1; - - } else { - GJB_PRT_INFO("creating main_thread18 success\n"); - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread17, NULL); - pthread_join(main_thread18, NULL); - - /* - * 删除一个数据键 - */ - if (pthread_key_delete(key_1_tm_2091) != 0) { - GJB_PRT_ERROR_INFO("Error: pthread_key_delete() failed\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_key_delete successfully. key:%x\n", (unsigned int)key_1_tm_2091); - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test14_tm_2091(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100209GN_2.c b/task_management/gjb_S0100209GN_2.c deleted file mode 100644 index 132da88..0000000 --- a/task_management/gjb_S0100209GN_2.c +++ /dev/null @@ -1,145 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100209GN_2.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务私有变量测试, pthread_key_create_创建key数超过20个_返回错误码 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - -/* - * 私有数据,全局变量 - */ -pthread_key_t key_2_tm_2092 = 1; - -pthread_key_t key_save_xxxx_tm_2092[5000] = {0}; - -/* - * 线程退出时释放私有数据空间,注意主线程必须调用 - * pthread_exit()(调用exit()不行)才能执行该函数释放accu指向的空间 - */ -void str_alloc_destroy_accu_S0100209GN_2 (void* accu) -{ - GJB_PRT_INFO("Thread %lx: freeing buffer at %p %d\n", pthread_self(), accu, *(int *)accu); - - free(accu); -} - -/* - * 可选要求接口测试_pthread_key_create_创建key数超过20个_返回错误码 - */ -int test14_S0100209GN_2 (void) -{ - int status, i, k; - - for (i = 0; i < 5000; i++) { - status = pthread_key_create(&key_2_tm_2092, str_alloc_destroy_accu_S0100209GN_2); - if (status == EAGAIN) { - - for (k = 0; k < i; ++k) { - pthread_key_delete(key_save_xxxx_tm_2092[k]); - } - - GJB_PRT_INFO("pthread_key_create() set invalid parameter test pass-- %d\n", i); - return 0; - - } else if ((status != 0) && (status != EAGAIN)) { - - for (k = 0; k < i; ++k) { - pthread_key_delete(key_save_xxxx_tm_2092[k]); - } - - GJB_PRT_ERROR_INFO("pthread_key_create resource lack should return EAGAIN\n"); - return -1; - } - - key_save_xxxx_tm_2092[i] = key_2_tm_2092; - } - - return 0; -} -/********************************************************************************************************* - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test14_S0100209GN_2(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100209GN_3.c b/task_management/gjb_S0100209GN_3.c deleted file mode 100644 index 5854ccd..0000000 --- a/task_management/gjb_S0100209GN_3.c +++ /dev/null @@ -1,232 +0,0 @@ -锘/********************************************************************************************************* -** -** GJB 鏍囧噯娴嬭瘯闆 -** -** Copyright All Rights Reserved -** -**--------------鏂囦欢淇℃伅-------------------------------------------------------------------------------- -** -** 鏂 浠 鍚: gjb_S0100209GN_3.c -** -** 鏂囦欢鍒涘缓鏃ユ湡: 2021 骞 1 鏈 12 鏃 -** -** 鎻 杩: 浠诲姟绉佹湁鍙橀噺娴嬭瘯 -*********************************************************************************************************/ -#define SYLIXOS - -#ifdef SYLIXOS -#define __SYLIXOS_KERNEL -#endif - - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - -/* - * 绉佹湁鏁版嵁锛屽叏灞鍙橀噺 - */ -static pthread_key_t key_3_tm_2093 = 1; - -#ifdef SYLIXOS -struct link_heap { - struct link_heap *next; - struct link_heap *prev; - char *p; -}; -#endif - -#ifdef SYLIXOS -static void list_add (struct link_heap *node, struct link_heap *header) -{ - if (!node || !header) { - return; - } - - node->next = header->next; - node->prev = header; - - header->next->prev = node; - header->next = node; -} - -static void list_delete (struct link_heap *header) -{ - struct link_heap *node, *free_node; - - if (!header) { - return; - } - - for (node = header->next; node != header;) { - free_node = node; - node = node->next; - - free_node->prev->next = free_node->next; - free_node->next->prev = free_node->prev; - - __SHEAP_FREE(free_node->p); - free(free_node); - } - - free(header); -} -#endif - -/* - * 绾跨▼閫鍑烘椂閲婃斁绉佹湁鏁版嵁绌洪棿,娉ㄦ剰涓荤嚎绋嬪繀椤 - * 璋冪敤pthread_exit()(璋冪敤exit()涓嶈)鎵嶈兘鎵ц璇ュ嚱鏁伴噴鏀綼ccu鎸囧悜鐨勭┖闂 - */ -static void str_alloc_destroy_accu_S0100209GN_3 (void* accu) -{ - GJB_PRT_INFO("Thread %lx: freeing buffer at %p %d\n",pthread_self(), accu, *(int *)accu); - - free(accu); -} - -/* - * 鍙夎姹傛帴鍙f祴璇昣pthread_key_create_杩斿洖閿欒鐮乢绯荤粺鍐呭瓨涓嶈冻 - */ -int test14_S0100209GN_3 (void) -{ - int status,i; - -#ifdef SYLIXOS - struct link_heap *header = NULL; - char *p; - struct link_heap *node; - - /* - * 鍏堟妸鍐呮牳鐨勫爢鍐呭瓨浣跨敤瀹 - */ - header = malloc(sizeof(struct link_heap)); - if (!header) { - return 0; - } - - header->next = header; - header->prev = header; - header->p = NULL; - - while (1) { - /* - * 杩欓噷鍏堟妸鎿嶄綔绯荤粺鐨勫爢鍐呭瓨鑰楀敖 - */ - p = __SHEAP_ALLOC(300 * 1024); - if (!p) { - break; - } - - node = malloc(sizeof(struct link_heap)); - if (!node) { - __SHEAP_FREE(p); - break; - } - - node->next = NULL; - node->prev = NULL; - node->p = p; - - list_add(node, header); - } -#endif - - for (i = 0; ; i++) { - /* - * 鍒涘缓涓涓暟鎹敭 - */ - status = pthread_key_create(&key_3_tm_2093, str_alloc_destroy_accu_S0100209GN_3); - if (status == ENOMEM) { - GJB_PRT_INFO("pthread_key_create() success return ENOMEM\n"); - -#ifdef SYLIXOS - list_delete(header); -#endif - - return 0; - - } else if ((status != 0) && (status != ENOMEM)) { - GJB_PRT_ERROR_INFO("error %d\n", status); - break; - } - } - - return -1; -} -/********************************************************************************************************* - * 鍑芥暟鍚嶇О锛 void usrMain(void) - * 鍔熻兘鎻忚堪锛 鐢ㄦ埛绋嬪簭鍏ュ彛 - * 杈撳叆鍙傛暟锛 鏃 - * 杈撳嚭鍙傛暟锛 鏃 - * 杩 鍥 鍊硷細 鏃 - * 鍏跺畠璇存槑锛 鏃 -*********************************************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test14_S0100209GN_3(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} diff --git a/task_management/gjb_S0100209GN_4.c b/task_management/gjb_S0100209GN_4.c deleted file mode 100644 index 5866550..0000000 --- a/task_management/gjb_S0100209GN_4.c +++ /dev/null @@ -1,247 +0,0 @@ -/********************************************************************************************************* -** -** GJB 标准测试集 -** -** Copyright All Rights Reserved -** -**--------------文件信息-------------------------------------------------------------------------------- -** -** 文 件 名: gjb_S0100209GN_4.c -** -** 文件创建日期: 2021 年 1 月 12 日 -** -** 描 述: 任务私有变量测试 -*********************************************************************************************************/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - typedef unsigned int u32; - typedef u32 boolean; -#define FALSE 0 -#define TRUE 1 -#define SYSTEM_TICKS_USEC 1000 -#define RUN 1 -#define STOP 0 - int thread_status = RUN; - pthread_mutex_t thread_mut = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER; - int b_is_pthread_mutex_init = 0; - - pthread_mutex_t g_pthread_mutex; - - -#define GJB_PRT_INFO(fmt, arg...) printf(fmt, ##arg) -#define GJB_PRT_ERROR_INFO(fmt, arg...) printf(fmt, ##arg) -#define gjb_os_printk(fmt, arg...) printf(fmt, ##arg) - -int GJB_PRI_FAIL(void) -{ - printf("task failed\n"); - return -1; -} - -int GJB_PRI_PASS(void) -{ - printf("task success\n"); - return (0); -} - -int pthread_delay(int ticks) -{ - sched_yield(); - return usleep(SYSTEM_TICKS_USEC * ticks); -} - - - -/* - * 私有数据,全局变量 - */ -pthread_key_t key_S0100209GN_4 = 1; - -/* - * main_task_thread17对全局变量key设置私有数据 - */ -void *main_task_thread17_S0100209GN_4(void *arg) -{ - int temp = 10; - void *p; - int *i = malloc(sizeof(int)); - - *i = temp; - - GJB_PRT_INFO("main_task_thread17 set key value %d; i address : %p\n", temp, i); - - /* - * 设置私有数据,释放这块地址空间 - */ - pthread_setspecific(key_S0100209GN_4, (void *)(i)); - - pthread_delay(200); - - /* - * 获取任务私有数据 - */ - if ((p = pthread_getspecific(key_S0100209GN_4)) != NULL) { - GJB_PRT_INFO("pthread_getspecific successfully," - "main_task_thread17 key %x value is %d\n", - (unsigned int)key_S0100209GN_4, (int)(long)p); - - } else { - GJB_PRT_ERROR_INFO("main_task_thread17 pthread_getspecific failed\n"); - return ((void*)-1); - } - - return (NULL); -} - -/* - * main_task_thread18对全局变量key设置私有数据 - */ -void *main_task_thread18_S0100209GN_4(void *arg) -{ - int temp = 20; - void *p; - int *i = malloc(sizeof(int)); - - *i = temp; - - GJB_PRT_INFO("main_task_thread18 set key value %d; i address : %p\n", temp, i); - - /* - * 设置私有数据 - */ - pthread_setspecific(key_S0100209GN_4, ((void *)i)); - - pthread_delay(100); - - /* - * 获取任务私有数据 - */ - if ((p = pthread_getspecific(key_S0100209GN_4)) != NULL) { - GJB_PRT_INFO("pthread_getspecific successfully," - "main_task_thread18 key %x value is %d\n", - (unsigned int)key_S0100209GN_4, (int)(long)p); - - } else { - GJB_PRT_ERROR_INFO("main_task_thread18 pthread_getspecific failed\n"); - return ((void*)-1); - } - - return (NULL); -} - -/* - * 线程退出时释放私有数据空间,注意主线程必须调用pthread_exit() - * (调用exit()不行)才能执行该函数释放accu指向的空间 - */ -void str_alloc_destroy_accu(void* accu) -{ - GJB_PRT_INFO("Thread %lx: freeing buffer at %p %d\n", pthread_self(), accu, *(int *)accu); - - GJB_PRT_INFO("accu addr is %p\n", (int *)accu); - - free(accu); -} - -/* - * 可选要求接口测试_pthread_key_create_析构函数调用成功 - */ -int test14_S0100209GN_4 (void) -{ - pthread_t main_thread17, main_thread18; - int status; - - /* - * 创建 POSIX 私有KEY - */ - status = pthread_key_create(&key_S0100209GN_4, str_alloc_destroy_accu); - if (status == 0) { - GJB_PRT_INFO("pthread_key_create successfully! key : %x\n", (unsigned int)key_S0100209GN_4); - - } else { - GJB_PRT_ERROR_INFO("Error: pthread_key_create() failed\n"); - return -1; - } - - status = -1; - - status = pthread_create(&main_thread17, NULL, main_task_thread17_S0100209GN_4, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread17\n"); - return -1; - - } else { - GJB_PRT_INFO("creating main_thread17 success\n"); - } - - status = -1; - - status = pthread_create(&main_thread18, NULL, main_task_thread18_S0100209GN_4, NULL); - if (status != 0) { - GJB_PRT_ERROR_INFO("Error creating main_thread18\n"); - return -1; - - } else { - GJB_PRT_INFO("creating main_thread18 success\n"); - } - - /* - * 等待任务结束 - */ - pthread_join(main_thread17, NULL); - pthread_join(main_thread18, NULL); - - /* - * 删除 POSIX 私有KEY - */ - if (pthread_key_delete(key_S0100209GN_4) != 0) { - GJB_PRT_ERROR_INFO("Error: pthread_key_delete() failed\n"); - return -1; - - } else { - GJB_PRT_INFO("pthread_key_delete() successfully:%x\n", (unsigned int)key_S0100209GN_4); - } - - return 0; -} -/********************************************************************** - * 函数名称: void usrMain(void) - * 功能描述: 用户程序入口 - * 输入参数: 无 - * 输出参数: 无 - * 返 回 值: 无 - * 其它说明: 无 - **************************************************************************/ -int main(int argc, char **argv) -{ - int result; - - result = test14_S0100209GN_4(); - if (result != 0) { - return (GJB_PRI_FAIL()); - - } else { - return (GJB_PRI_PASS()); - } -} -- Gitee