diff --git a/time_management/gjb_S0101101GN.c b/time_management/gjb_S0101101GN.c new file mode 100644 index 0000000000000000000000000000000000000000..5678a5c668c6bb0836715c41404e94f4e6046b7e --- /dev/null +++ b/time_management/gjb_S0101101GN.c @@ -0,0 +1,141 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101101GN.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 获取内核节拍计数值功能测试;设置内核 TICK 后,以新值作为基数,设置内核 TICK 值会造成系统运行不稳定 +** 因此该用例测试完成后需要重启系统 +*********************************************************************************************************/ + +//设置内核节拍计数器功能 +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include + +#define SYSTEM_TICKS_USEC 1000 + +unsigned long long g_sys_tick; +unsigned long long g_pthread_delay_tick; +unsigned int g_sys_uleep_tick; +int is_set_sys_rate; +int is_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); + } +} + +unsigned long long tick_get(void) +{ + if(g_sys_tick == 0 && is_set == 0) + { + struct timeval tv; + gettimeofday(&tv, NULL); + g_sys_tick = tv.tv_sec * 1000000 + tv.tv_usec; + } + else + { + g_sys_tick = g_sys_tick + g_pthread_delay_tick; + } + return g_sys_tick; +} + + +void tick_set(unsigned long long ticks) +{ + g_sys_tick = ticks; + g_pthread_delay_tick = 0; + is_set = 1; +} + +int Test_get_set_tick_gn_1() +{ + unsigned long long ullRes,ullRes1,ullRes2; + + ullRes1=tick_get(); // 获取第一次 TICK 值 + pthread_delay(1000);//1000 ticks + ullRes2=tick_get(); // 获取第二次 TICK 值 + + if(ullRes2 == ullRes1 + 1000) { // 查看第二次比第一次多 1000 个TICK + printf("450--Pass--tick_get()\n"); + } else { + printf("451--Fail--tick_get()\n"); + } + + tick_set(1000000); // 设置系统节拍值为 1000000 + ullRes = tick_get(); + if(ullRes == 1000000) { // 查看节拍是否设置为 1000000 + printf("452--Pass--tick_set(1000000) tick_get()\n"); + } else { + printf("453--Fail--tick_set(1000000) tick_get()\n"); + return -1; + } + + tick_set(0); + ullRes=tick_get(); + if(ullRes == 0) + { + printf("454--Pass--tick_set(0) tick_get()\n"); + } + else + { + printf("455--Fail--tick_set(0) tick_get()\n"); + return -2; + } + + pthread_delay(100); + ullRes=tick_get(); + if(ullRes >= 100 && ullRes < 110) + { + printf("456--Pass--tick_get()\n"); + } + else + { + printf("457--Fail--tick_get()\n"); + return -3; + } + return 0; +} + +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main(int argc, char **argv) +{ + int result; + + result = Test_get_set_tick_gn_1(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/time_management/gjb_S0101102GN.c b/time_management/gjb_S0101102GN.c new file mode 100644 index 0000000000000000000000000000000000000000..5bcea6357ad1448f9b5f27c73d80d40a4703e74e --- /dev/null +++ b/time_management/gjb_S0101102GN.c @@ -0,0 +1,143 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101101GN.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 读取内核节拍计数值功能测试 +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include + +#define SYSTEM_TICKS_USEC 1000 + +unsigned long long g_sys_tick; +unsigned long long g_pthread_delay_tick; +unsigned int g_sys_uleep_tick; +int is_set_sys_rate; +int is_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 tick_set(unsigned long long ticks) +{ + g_sys_tick = ticks; + g_pthread_delay_tick = 0; + is_set = 1; +} + +unsigned long long tick_get(void) +{ + if(g_sys_tick == 0 && is_set == 0) + { + struct timeval tv; + gettimeofday(&tv, NULL); + g_sys_tick = tv.tv_sec * 1000000 + tv.tv_usec; + } + else + { + g_sys_tick = g_sys_tick + g_pthread_delay_tick; + } + return g_sys_tick; +} + +//设置内核节拍计数器功能 +int Test_get_set_tick_gn_2() +{ + unsigned long long ullRes,ullRes1,ullRes2; + ullRes1=tick_get(); + pthread_delay(1000);//1000 ticks + ullRes2=tick_get(); + if(ullRes2 == ullRes1 + 1000) + { + printf("450--Pass--tick_get()\n"); + } + else + { + printf("451--Fail--tick_get()\n"); + } + + tick_set(1000000); + ullRes=tick_get(); + if(ullRes == 1000000) + { + printf("452--Pass--tick_set(1000000) tick_get()\n"); + } + else + { + printf("453--Fail--tick_set(1000000) tick_get()\n"); + return -1; + } + + tick_set(0); + ullRes=tick_get(); + if(ullRes == 0) + { + printf("454--Pass--tick_set(0) tick_get()\n"); + } + else + { + printf("455--Fail--tick_set(0) tick_get()\n"); + return -2; + } + + pthread_delay(100); + ullRes=tick_get(); + if(ullRes >= 100 && ullRes < 110) + { + printf("456--Pass--tick_get()\n"); + } + else + { + printf("457--Fail--tick_get()\n"); + return -3; + } + return 0; +} + +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main(int argc, char **argv) +{ + int result; + + result = Test_get_set_tick_gn_2(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/time_management/gjb_S0101103GN.c b/time_management/gjb_S0101103GN.c new file mode 100644 index 0000000000000000000000000000000000000000..d9a3b16d5328fdd0fdb8b078eb7b776de0291448 --- /dev/null +++ b/time_management/gjb_S0101103GN.c @@ -0,0 +1,149 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101101GN.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 系统时钟设置和控制功能测试;获取和设置系统时钟,设置内核系统时钟频率会造成系统运行不稳定 +** 因此该用例测试完成后需要重启系统 +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include +#include + +#define SYSTEM_TICKS_USEC 1000 + +unsigned long long g_pthread_delay_tick; +int is_set_sys_rate; +int g_sys_uleep_tick; +int g_sys_rate; + +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 sys_clk_rate_set(int ticks_per_second) +{ + int ret = 0; + g_sys_rate = ticks_per_second; + is_set_sys_rate = 1; + g_sys_uleep_tick = 1000000 / g_sys_rate; + + return ret; +} + +unsigned int sys_clk_rate_get(void) +{ + + // 修改:新增 + if(is_set_sys_rate == 0 && g_sys_rate == 0) { + g_sys_rate = 1000; + } + + return g_sys_rate; +} + +int Test_get_set_clkRate_gn() +{ + unsigned int uiRes,uiTick,uiTick1,uiTick2; + unsigned long long oldtick; + + oldtick = sys_clk_rate_get(); // 获取系统时钟频率 + + uiTick1 = sys_clk_rate_get(); // 获取系统时钟频率 1 + + pthread_delay(100); + uiTick2 = sys_clk_rate_get(); // 获取系统时钟频率 2 + + if(uiTick2 == uiTick1) // 两次时钟频率应该相同 + { + printf("458--Pass--sys_clk_rate_get()\n"); + } + else + { + printf("459--Fail--sys_clk_rate_get()\n"); + return -1; + } + + uiRes = sys_clk_rate_set(60); // 设置系统时钟频率为 60 + + if (uiRes == 0) { + printf("460--Pass--syg_clk_rate--sys_clk_rate_get(60)\n"); + uiTick = sys_clk_rate_get(); + if(uiTick == 60){ + printf("461--Pass--syg_clk_rate--sys_clk_rate_get()\n"); + + } else { + printf("462--Fail--sys_clk_rate_get()\n"); + return -2; + } + } else { + printf("463--Fail--sys_clk_rate_set(60)\n"); + return -3; + } + + pthread_delay(10); + + uiRes = sys_clk_rate_set(1000); + if (uiRes == 0) { + printf("464--Pass--sys_clk_rate_set(1000)\n"); + uiTick = sys_clk_rate_get(); + if (uiTick == 1000) { + printf("465--Pass--sys_clk_rate_get()\n"); + } else { + printf("466--Fail--sys_clk_rate_get()\n"); + return -4; + } + } else { + printf("467--Fail--sys_clk_rate_set(1000)\n"); + return -5; + } + + uiRes= sys_clk_rate_set(oldtick); + return 0; +} + +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main(int argc, char **argv) +{ + int result; + + result = Test_get_set_clkRate_gn(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/time_management/gjb_S0101104GN.c b/time_management/gjb_S0101104GN.c new file mode 100644 index 0000000000000000000000000000000000000000..b2e121e11e57aca3e6d06080321cd9a10ddc9f33 --- /dev/null +++ b/time_management/gjb_S0101104GN.c @@ -0,0 +1,199 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101104GN.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 时间管理实时钟测试; +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include +#include +#include +#include + +#define SYSTEM_TICKS_USEC 1000 + +static struct timespec tp1,tp2,tp3; + +unsigned long long g_pthread_delay_tick; +int is_set_sys_rate; +unsigned int g_sys_uleep_tick; +unsigned int g_sys_rate; + +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 sys_clk_rate_set(int ticks_per_second) +{ + int ret = 0; + g_sys_rate = ticks_per_second; + is_set_sys_rate = 1; + g_sys_uleep_tick = 1000000 / g_sys_rate; + + return ret; +} + +unsigned int sys_clk_rate_get(void) +{ + // 修改:新增 + if(is_set_sys_rate == 0 && g_sys_rate == 0) { + g_sys_rate = 1000; + } + + return g_sys_rate; +} + +int Test_Clock_gn() +{ + int res; + volatile unsigned long long ullRes; + + ullRes=sys_clk_rate_get(); + + //实时钟 + res=clock_gettime(CLOCK_REALTIME,&tp1); // 获取系统时间 tp1 + if(res == 0) + { + printf("482--Pass--clock_gettime(CLOCK_REALTIME,&tp1)\n"); + } + else + { + printf("483--Fail--clock_gettime(CLOCK_REALTIME,&tp1)\n"); + return -1; + } + + pthread_delay(1*ullRes); // 延时1*ullRes TICK + + res=clock_gettime(CLOCK_REALTIME,&tp2); // 获取系统时间 tp2 + if(res == 0) + { + printf("484--Pass--clock_gettime(CLOCK_REALTIME,&tp2)\n"); + } + else + { + printf("485--Fail--clock_gettime(CLOCK_REALTIME,&tp2)\n"); + return -1; + } + + if(tp2.tv_sec - tp1.tv_sec == 1) //判断两次时间差为1 + { + printf("486--Pass--clock_gettime(CLOCK_REALTIME,&tp)\n"); + } + else + { + printf("487--Fail--clock_gettime(CLOCK_REALTIME,&tp)\n"); + return -1; + } + + pthread_delay(3*ullRes); + + res=clock_gettime(CLOCK_REALTIME,&tp3); + if(res == 0) + { + printf("488--Pass--clock_gettime(CLOCK_REALTIME,&tp3)\n"); + } + else + { + printf("489--Fail--clock_gettime(CLOCK_REALTIME,&tp3)\n"); + return -1; + } + + if(tp3.tv_sec - tp2.tv_sec ==3) + { + printf("490--Pass--clock_gettime(CLOCK_REALTIME,&tp)\n"); + } + else + { + printf("491--Fail--clock_gettime(CLOCK_REALTIME,&tp)\n"); + return -1; + } + + //set + // tp1.tv_sec = 500; + // tp1.tv_nsec = 1000; + // 修改 + tp1.tv_sec = 50000; + tp1.tv_nsec = 100000; + + res=clock_settime(CLOCK_REALTIME,&tp1); + + if(res == 0) + { + printf("492--Pass--clock_settime(CLOCK_REALTIME,&tp1)\n"); + } + else + { + printf("493--Fail--clock_settime(CLOCK_REALTIME,&tp)\n"); + return -1; + } + + pthread_delay(2*ullRes); + + res=clock_gettime(CLOCK_REALTIME,&tp2); + if(res == 0) + { + printf("494--Pass--clock_gettime(CLOCK_REALTIME,&tp2)\n"); + } + else + { + printf("495--Fail--clock_gettime(CLOCK_REALTIME,&tp)\n"); + return -1; + } + + if(tp2.tv_sec - tp1.tv_sec >=2 && tp2.tv_sec - tp1.tv_sec < 4 && tp2.tv_sec > 500) + { + printf("496--Pass--clock_gettime(CLOCK_REALTIME,&tp)\n"); + } + else + { + printf("497--Fail--clock_gettime(CLOCK_REALTIME,&tp)\n"); + return -1; + } + return 0; +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main(int argc, char **argv) +{ + int result; + + result = Test_Clock_gn(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/time_management/gjb_S0101106GN.c b/time_management/gjb_S0101106GN.c new file mode 100644 index 0000000000000000000000000000000000000000..4b301ac4e6f22985ad7a3130757f718f4fa81444 --- /dev/null +++ b/time_management/gjb_S0101106GN.c @@ -0,0 +1,167 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101106GN.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 任务执行计时功能测试, 获取任务执行时间 +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include "string.h" +#include +#include + +// #include "7714types.h" +// #include "gjb.h" +// #include "gjbext.h" + +#define CPU_ZERO(cpusetp) __CPU_ZERO_S (sizeof (cpu_set_t), cpusetp) +#define CPU_SET(cpu, cpusetp) __CPU_SET_S (cpu, sizeof (cpu_set_t), cpusetp) + +static struct timespec tp1, tp2, tp3; + +// TODO:函数未实现 +int pthread_setaffinity_np(pthread_t __th, size_t __cpusetsize, + const cpu_set_t *__cpuset) +{ + return 0; +} + +/* + * 将指定的线程 BIND 到指定CPU + */ +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 *Fun1_S0101106GN() +{ + int res; + /* + * 为了防止编译器优化, 需要加上volatile + */ + volatile int i, j; + + binding(pthread_self(), 0); + + res = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp1); // 获取 CLOCK_THREAD_CPUTIME_ID 类型的时间 tp1 + if (res != 0) { + printf("475--Fail--clock_gettime(CLOCK_THREAD_CPUTIME_ID,&tp1)\n"); + return ((int*)-1); + } + + /* + * 运行过程中不能添加其他打印信息, 因为打印可能会引起线程调度 + */ + for (i = 0; i < 1000; i++) { + for (j = 0; j < 100000; j++) { + ; + } + } + + res = clock_gettime(CLOCK_THREAD_CPUTIME_ID,&tp2); // 获取 CLOCK_THREAD_CPUTIME_ID 类型的时间 tp2 + if (res != 0) { + printf("477--Fail--clock_gettime(CLOCK_THREAD_CPUTIME_ID,&tp2)\n"); + return ((int*)-1); + } + + for (i = 0; i < 1000; i++) { + for (j = 0; j < 100000; j++) { + ; + } + } + + res = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp3); // 获取 CLOCK_THREAD_CPUTIME_ID 类型的时间 tp3 + if (res == 0) { // 成功返回0 + printf("478--Pass--clock_gettime(CLOCK_THREAD_CPUTIME_ID,&tp3)\n"); + + } else { // 失败返回非0值 + printf("479--Fail--clock_gettime(CLOCK_THREAD_CPUTIME_ID,&tp3)\n"); + return ((int*)-1); + } + + /* + * 因为线程的运行时间是从创建就开始计时的, 所以第一次获取不一定时从0开始 + * 所以这个0判断删除 + */ + if (/*tp1.tv_sec == 0 && */(tp3.tv_sec >= tp2.tv_sec) && (tp2.tv_sec >= tp1.tv_sec)) { + printf("480--Pass--clock_gettime(CLOCK_THREAD_CPUTIME_ID,&tp)\n"); + + } else { + printf("481--Fail--clock_gettime(CLOCK_THREAD_CPUTIME_ID,&tp)\n"); + return ((int*)-1); + } + + return (NULL); +} + +//任务计时 +int Test_Clock_gn_2() +{ + int res; + pthread_t thread_id1; + pthread_attr_t thread_attr1; + void *ret = NULL; + + pthread_attr_init(&thread_attr1); + + res = pthread_create( &thread_id1, &thread_attr1, Fun1_S0101106GN, NULL ); + if ( res == 0 ) { + printf( "916--Pass--pthread_create( &thread_id1,&thread_attr1, Fun1, NULL )\n"); + + } else { + printf( "917--Fail--pthread_create( &thread_id1,&thread_attr1, Fun1, NULL )\n"); + return -1; + } + + // 等待线程 fun1 + pthread_join(thread_id1, &ret); + if ((int*)ret == NULL) { + printf( "918--Pass--pthread_join(thread_id1,&ret) \n"); + } else { + printf( "919--Fail--pthread_join(thread_id1,&ret) \n"); + return -1; + } + + return 0; +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main(int argc, char **argv) +{ + int result; + + result = Test_Clock_gn_2(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} \ No newline at end of file diff --git a/time_management/gjb_S0101107GN.c b/time_management/gjb_S0101107GN.c new file mode 100644 index 0000000000000000000000000000000000000000..513d81c621199d5dce8f5b52f53bffce967b6b5e --- /dev/null +++ b/time_management/gjb_S0101107GN.c @@ -0,0 +1,152 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101107GN.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 任务执行延时等待功能测试 +*********************************************************************************************************/ + +#include +#include +#include +#include +#include + +#define SYSTEM_TICKS_USEC 1000 + +unsigned long long g_sys_tick; +int is_set; +unsigned long long g_pthread_delay_tick; +unsigned long long g_sys_tick; +int is_set_sys_rate; +unsigned int g_sys_uleep_tick; + +unsigned int g_sys_rate; + +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 tick_set(unsigned long long ticks) +{ + g_sys_tick = ticks; + g_pthread_delay_tick = 0; + is_set = 1; +} + +unsigned long long tick_get(void) +{ + if(g_sys_tick == 0 && is_set == 0) + { + struct timeval tv; + gettimeofday(&tv, NULL); + g_sys_tick = tv.tv_sec * 1000000 + tv.tv_usec; + } + else + { + g_sys_tick = g_sys_tick + g_pthread_delay_tick; + } + return g_sys_tick; +} + + +int sys_clk_rate_set(int ticks_per_second) +{ + int ret = 0; + g_sys_rate = ticks_per_second; + is_set_sys_rate = 1; + g_sys_uleep_tick = 1000000 / g_sys_rate; + return ret; +} + +unsigned int sys_clk_rate_get(void) +{ + if(is_set_sys_rate == 0 && g_sys_rate == 0) { + g_sys_rate = 1000; + } + return g_sys_rate; +} + +//任务延时 +int Test_pthread_delay_gn() +{ + unsigned long long ullRes,ullTick1,ullTick2; + unsigned long long oldtick; + + ullRes = sys_clk_rate_get(); // 获得系统时间频率 + + ullTick1 = tick_get(); // 获得系统TICK计数值 ullTick1 + pthread_delay(10); // 延时 10 TICK + ullTick2 = tick_get(); // 获得系统TICK计数值 ullTick2 + + if (ullTick2 - ullTick1 == 10) { + printf("468--Pass--pthread_delay(100)\n"); + } else { + printf("469--Fail--pthread_delay(100)\n"); + return -1; + } + + oldtick = sys_clk_rate_get(); + + sys_clk_rate_set(4500); // 设置系统时间频率 4500 + ullRes = sys_clk_rate_get(); + if (ullRes == 4500) { + printf("470--Pass--sys_clk_rate_set(4500)\n"); + } else { + printf("471--Fail--sys_clk_rate_set(4500)\n"); + return -1; + } + + ullTick1 = tick_get(); + pthread_delay(4500); //4500 + ullTick2 = tick_get(); + + if (ullTick2 - ullTick1 == 4500) { + printf("472--Pass--pthread_delay(45000)\n"); + } else { + printf("473--Fail--pthread_delay(45000) %lld\n", ullTick2 - ullTick1); + return -1; + } + + sys_clk_rate_set(oldtick); + + return 0; +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main(int argc, char **argv) +{ + int result; + + result = Test_pthread_delay_gn(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/timer_management/gjb_S0101201GN_1.c b/timer_management/gjb_S0101201GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..f8544033ffa3b65df0670a5fe99015f7aca5512e --- /dev/null +++ b/timer_management/gjb_S0101201GN_1.c @@ -0,0 +1,112 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101201GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 看门狗定时器创建功能测试 +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include +#include "signal.h" + +#define MAX_WDG_NUM 64 + +typedef void (*wdg_func)(void *); +typedef int wdg_t; +typedef struct __wdg_attr +{ + unsigned int used; + timer_t timerid; + int ticks; + int is_start; + int is_execed; + struct sigevent evp; + void *args; + wdg_func func; +}wdg_attr; +wdg_attr g_wdg[MAX_WDG_NUM]; + +long long unsigned int llunGett1_tma_2011,llunGett2_tma_2011; + +int wdg_create(wdg_t *wdg_id) +{ + int id = 0; + if(wdg_id == NULL) + return -1; + for(id = 1; id < MAX_WDG_NUM; id++) + { + if(g_wdg[id].used == 0) + break; + } + if(id == MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + g_wdg[id].used = 1; + g_wdg[id].is_start = 0; + // wdg_t id=wdCreate(); + *wdg_id = id; + // printf("wdg_create %d\n", *wdg_id); + return 0; +} + +/********************************************************************** + * 函数名称: int Test_Wdg_gn() + * 功能描述: 看门狗定时器创建 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int Test_Wdg_gn_tma_2011() +{ + wdg_t wdg_id; + int res; + //创建看门狗 + res = wdg_create(&wdg_id); // 创建一个 GJB 看门狗 + if (res == 0) { + printf("200--Pass--wdg_create(&wdg_id)\n"); + return 0; + } else { + printf("201--Fail--wdg_create(&wdg_id)\n"); + return -1; + } + + return 0; +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main() +{ + int result; + + result = Test_Wdg_gn_tma_2011(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/timer_management/gjb_S0101201GN_2.c b/timer_management/gjb_S0101201GN_2.c new file mode 100644 index 0000000000000000000000000000000000000000..8d207867612fc919c6ba2f6b37236c4fa1a5c3f2 --- /dev/null +++ b/timer_management/gjb_S0101201GN_2.c @@ -0,0 +1,141 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101201GN_2.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 看门狗定时器创建功能测试--异常创建:没有资源 +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include +#include "signal.h" + +#define MAX_WDG_NUM 64 + +typedef void (*wdg_func)(void *); +typedef int wdg_t; +typedef struct __wdg_attr +{ + unsigned int used; + timer_t timerid; + int ticks; + int is_start; + int is_execed; + struct sigevent evp; + void *args; + wdg_func func; +}wdg_attr; +wdg_attr g_wdg[MAX_WDG_NUM]; + +int wdg_create(wdg_t *wdg_id) +{ + int id = 0; + if(wdg_id == NULL) + return -1; + for(id = 1; id < MAX_WDG_NUM; id++) + { + if(g_wdg[id].used == 0) + break; + } + if(id == MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + g_wdg[id].used = 1; + g_wdg[id].is_start = 0; + // wdg_t id=wdCreate(); + *wdg_id = id; + // printf("wdg_create %d\n", *wdg_id); + return 0; +} + +int wdg_delete(wdg_t wdg_id) +{ + int ret = 0; + if(wdg_id < 1 || wdg_id > MAX_WDG_NUM) + { + return -1; + } + // ret=wdDelete(wdg_id); + // printf("wdg_delete %d\n", wdg_id); + if(g_wdg[wdg_id].is_start == 1) + ret = timer_delete(g_wdg[wdg_id].timerid); + g_wdg[wdg_id].used = 0; + g_wdg[wdg_id].is_start = 0; + return ret; +} + +/********************************************************************** + * 函数名称: int Test_Wdg_gn() + * 功能描述: 看门狗定时器异常创建 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int Test_Wdg_gn_tma_2012() +{ + wdg_t wdg_id[100]; + int res, i; + + //系统没有多余的看门狗资源 + res = 0; + i = 0; + + while (res == 0) { + res=wdg_create(&wdg_id[i]); // 创建一个 GJB 看门狗 + i++; + } + + printf("%d\n", i); + + if (res == -1 && errno == EAGAIN) { + printf("202--Pass--wdg_create(&wdg_id)-EAGAIN\n"); + i--; + //释放所有占用资源 + while (i > 0) { + wdg_delete(wdg_id[i]); // 删除一个 GJB 看门狗 + i--; + } + } else { + printf("203--Fail--wdg_create(&wdg_id)-EAGAIN\tres = %d\t errno = %d\n",res,errno); + return -1; + } + + return 0; +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main() +{ + int result; + + result = Test_Wdg_gn_tma_2012(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/timer_management/gjb_S0101201GN_4.c b/timer_management/gjb_S0101201GN_4.c new file mode 100644 index 0000000000000000000000000000000000000000..9bc9b977c5b5f272d492959ea1d4f8981e0f7331 --- /dev/null +++ b/timer_management/gjb_S0101201GN_4.c @@ -0,0 +1,111 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101201GN_4.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 看门狗定时器创建功能测试--非法ID 创建看门狗 +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include +#include "signal.h" + +#define MAX_WDG_NUM 64 + +typedef void (*wdg_func)(void *); +typedef int wdg_t; +typedef struct __wdg_attr +{ + unsigned int used; + timer_t timerid; + int ticks; + int is_start; + int is_execed; + struct sigevent evp; + void *args; + wdg_func func; +}wdg_attr; +wdg_attr g_wdg[MAX_WDG_NUM]; + +int wdg_create(wdg_t *wdg_id) +{ + int id = 0; + if(wdg_id == NULL) + return -1; + for(id = 1; id < MAX_WDG_NUM; id++) + { + if(g_wdg[id].used == 0) + break; + } + if(id == MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + g_wdg[id].used = 1; + g_wdg[id].is_start = 0; + // wdg_t id=wdCreate(); + *wdg_id = id; + // printf("wdg_create %d\n", *wdg_id); + return 0; +} + +/********************************************************************** + * 函数名称: int Test_Wdg_gn() + * 功能描述: 看门狗定时器异常创建 ID:NULL + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int Test_Wdg_gn_tma_2014() +{ + int res; + + res = wdg_create(NULL); // 创建一个GJB看门狗, 指定无效的句柄缓冲区 NULL + if(res==0) { + printf("207--Fail--wdg_create(NULL)\n"); + return -1; + } else if(res == -1) { + printf("208--Pass--wdg_create(NULL)\n"); + } else { + printf("209--Fail--wdg_create(NULL)\tres = %d\t errno = %d\n",res,errno); + return -1; + } + + return 0; +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main() +{ + int result; + + result = Test_Wdg_gn_tma_2014(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/timer_management/gjb_S0101201GN_5.c b/timer_management/gjb_S0101201GN_5.c new file mode 100644 index 0000000000000000000000000000000000000000..da6c5a18ebd4e8ecc268afedcf92acfc5e5eae75 --- /dev/null +++ b/timer_management/gjb_S0101201GN_5.c @@ -0,0 +1,163 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101201GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 看门狗定时器创建功能测试 +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include +#include +#include "signal.h" + +#define MAX_WDG_NUM 64 +#define SYSTEM_TICKS_USEC 1000 + +typedef void (*wdg_func)(void *); +typedef int wdg_t; +typedef struct __wdg_attr +{ + unsigned int used; + timer_t timerid; + int ticks; + int is_start; + int is_execed; + struct sigevent evp; + void *args; + wdg_func func; +}wdg_attr; +wdg_attr g_wdg[MAX_WDG_NUM]; + +unsigned long long g_pthread_delay_tick; +int is_set_sys_rate; +unsigned int g_sys_uleep_tick; + +int wdg_create(wdg_t *wdg_id) +{ + int id = 0; + if(wdg_id == NULL) + return -1; + for(id = 1; id < MAX_WDG_NUM; id++) + { + if(g_wdg[id].used == 0) + break; + } + if(id == MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + g_wdg[id].used = 1; + g_wdg[id].is_start = 0; + // wdg_t id=wdCreate(); + *wdg_id = id; + // printf("wdg_create %d\n", *wdg_id); + return 0; +} + +int wdg_delete(wdg_t wdg_id) +{ + int ret = 0; + if(wdg_id < 1 || wdg_id > MAX_WDG_NUM) + { + return -1; + } + // ret=wdDelete(wdg_id); + // printf("wdg_delete %d\n", wdg_id); + if(g_wdg[wdg_id].is_start == 1) + ret = timer_delete(g_wdg[wdg_id].timerid); + g_wdg[wdg_id].used = 0; + g_wdg[wdg_id].is_start = 0; + return ret; +} + +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 Test_Wdg_gn() + * 功能描述: 看门狗定时器删除后重新创建 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int Test_Wdg_gn_tma_2015() +{ + int res; + wdg_t wdg_id; + + printf("Test_wdg_create_start_cancel_delete02:\n\n"); + pthread_delay( 100 ); + + res=wdg_create(&wdg_id); // 创建一个看门狗 + if(res==0) { + printf("210--Pass--wdg_create(&wdg_id)\n"); + } else { + printf("211--Fail--wdg_create(&wdg_id)\tres = %d\t errno = %d\n",res,errno); + } + + sleep(1); + //看门狗未启动删除 + res = wdg_delete(wdg_id); + if (res == 0) { + printf("212--Pass--wdg_delete(wdg_id)\n"); + } else { + printf("213--Fail--wdg_delete(wdg_id)\tres = %d\t errno = %d\n",res,errno); + return -1; + } + //删除后再创建 + res = wdg_create(&wdg_id); + if(res==0) { + printf("214--Pass--wdg_create(&wdg_id)\n"); + } else { + printf("2155--Fail--wdg_create(&wdg_id)\tres = %d\t errno = %d\n",res,errno); + } + + return 0; +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main() +{ + int result; + + result = Test_Wdg_gn_tma_2015(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/timer_management/gjb_S0101202GN_1.c b/timer_management/gjb_S0101202GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..b729e5a13c99838de0cdfb2d8b0f32402e541d02 --- /dev/null +++ b/timer_management/gjb_S0101202GN_1.c @@ -0,0 +1,150 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101202GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 看门狗定时器删除功能测试 正常删除 +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include +#include +#include "signal.h" + +#define MAX_WDG_NUM 64 +#define SYSTEM_TICKS_USEC 1000 + +typedef void (*wdg_func)(void *); +typedef int wdg_t; +typedef struct __wdg_attr +{ + unsigned int used; + timer_t timerid; + int ticks; + int is_start; + int is_execed; + struct sigevent evp; + void *args; + wdg_func func; +}wdg_attr; +wdg_attr g_wdg[MAX_WDG_NUM]; + +unsigned long long g_pthread_delay_tick; +int is_set_sys_rate; +unsigned int g_sys_uleep_tick; + +long long unsigned int llunGett1_tma_2021,llunGett2_tma_2021; + +int wdg_create(wdg_t *wdg_id) +{ + int id = 0; + if(wdg_id == NULL) + return -1; + for(id = 1; id < MAX_WDG_NUM; id++) + { + if(g_wdg[id].used == 0) + break; + } + if(id == MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + g_wdg[id].used = 1; + g_wdg[id].is_start = 0; + // wdg_t id=wdCreate(); + *wdg_id = id; + // printf("wdg_create %d\n", *wdg_id); + return 0; +} + +int wdg_delete(wdg_t wdg_id) +{ + int ret = 0; + if(wdg_id < 1 || wdg_id > MAX_WDG_NUM) + { + return -1; + } + // ret=wdDelete(wdg_id); + // printf("wdg_delete %d\n", wdg_id); + if(g_wdg[wdg_id].is_start == 1) + ret = timer_delete(g_wdg[wdg_id].timerid); + g_wdg[wdg_id].used = 0; + g_wdg[wdg_id].is_start = 0; + return ret; +} + +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 Test_Wdg_gn_tma_2021() +{ + int res; + wdg_t wdg_id; + + printf("Test_wdg_create_start_cancel_delete02:\n\n"); + pthread_delay( 100 ); + + res=wdg_create(&wdg_id); + if (res == 0) { + printf("218--Pass--wdg_create(&wdg_id)\n"); + } else { + printf("219--Fail--wdg_create(&wdg_id)\tres = %d\t errno = %d\n",res,errno); + } + sleep(1); + //看门狗未启动删除 + res=wdg_delete(wdg_id); + if (res==0) { + printf("220--Pass--wdg_delete(wdg_id)\n"); + } else { + printf("221--Fail--wdg_delete(wdg_id)\tres = %d\t errno = %d\n",res,errno); + return -1; + } + + return 0; +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main() +{ + int result; + + result = Test_Wdg_gn_tma_2021(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/timer_management/gjb_S0101202GN_2.c b/timer_management/gjb_S0101202GN_2.c new file mode 100644 index 0000000000000000000000000000000000000000..42fd7cbf69b96a7e768095e40642400db72203cf --- /dev/null +++ b/timer_management/gjb_S0101202GN_2.c @@ -0,0 +1,240 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101202GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 看门狗定时器删除功能测试 启动后删除 +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include +#include +#include "signal.h" +#include + +#define MAX_WDG_NUM 64 +#define SYSTEM_TICKS_USEC 1000 +#define SYSTEM_TICKS_NANO 100000 + +typedef void (*wdg_func)(void *); +typedef int wdg_t; +typedef struct __wdg_attr +{ + unsigned int used; + timer_t timerid; + int ticks; + int is_start; + int is_execed; + struct sigevent evp; + void *args; + wdg_func func; +}wdg_attr; +wdg_attr g_wdg[MAX_WDG_NUM]; + +unsigned long long g_pthread_delay_tick; +int is_set_sys_rate; +unsigned int g_sys_uleep_tick; + +static int nCount_tma_2022=1; +long long unsigned int llunGett1_tma_2022,llunGett2_tma_2022; + +int wdg_create(wdg_t *wdg_id) +{ + int id = 0; + if(wdg_id == NULL) + return -1; + for(id = 1; id < MAX_WDG_NUM; id++) + { + if(g_wdg[id].used == 0) + break; + } + if(id == MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + g_wdg[id].used = 1; + g_wdg[id].is_start = 0; + // wdg_t id=wdCreate(); + *wdg_id = id; + // printf("wdg_create %d\n", *wdg_id); + return 0; +} + +int wdg_delete(wdg_t wdg_id) +{ + int ret = 0; + if(wdg_id < 1 || wdg_id > MAX_WDG_NUM) + { + return -1; + } + // ret=wdDelete(wdg_id); + // printf("wdg_delete %d\n", wdg_id); + if(g_wdg[wdg_id].is_start == 1) + ret = timer_delete(g_wdg[wdg_id].timerid); + g_wdg[wdg_id].used = 0; + g_wdg[wdg_id].is_start = 0; + return ret; +} + +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); + } +} + +// TODO:该函数与glibc-2.28/sysdeps/mach/hurd/setitimer.c的函数有冲突 +static void timer_thread(union sigval v) +{ + // printf("timer_thread function! %d %d 0x%lx 0x%lx\n", + // v.sival_int, + // g_wdg[v.sival_int].is_execed, + // &g_wdg[v.sival_int].is_execed, + // g_wdg[v.sival_int].func); + if(g_wdg[v.sival_int].func != NULL && (g_wdg[v.sival_int].is_execed == 0)) + { + g_wdg[v.sival_int].is_execed = 1; + g_wdg[v.sival_int].func(g_wdg[v.sival_int].args); + // printf("timer_thread set g_wdg[%d].is_execed %d 0x%lx\n", + // v.sival_int, + // g_wdg[v.sival_int].is_execed, + // &g_wdg[v.sival_int].is_execed); + } +} +int wdg_start(wdg_t wdg_id,int ticks,void (*func)(void *arg),void *arg) +{ + int val; + struct itimerspec it; + if(wdg_id < 1 || wdg_id >= MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + if ((func == NULL) && (arg == NULL)) + { + return 0; + } + if(func == NULL) + { + return -1; + } + // printf("wdg_start wdg_id %d\n", wdg_id); + memset(&g_wdg[wdg_id].evp, 0, sizeof(struct sigevent)); + g_wdg[wdg_id].evp.sigev_value.sival_int = wdg_id; //也是标识定时器的,回调函数可以获得 + g_wdg[wdg_id].evp.sigev_notify = SIGEV_THREAD; //线程通知的方式,派驻新线程 + g_wdg[wdg_id].evp.sigev_notify_function = timer_thread; //线程函数地址 + g_wdg[wdg_id].func = func; + g_wdg[wdg_id].args = arg; + + if(g_wdg[wdg_id].is_start == 0) + { + // printf("timer_create %d\n", ticks); + val = timer_create(CLOCK_REALTIME, &g_wdg[wdg_id].evp, &g_wdg[wdg_id].timerid); + if(val < 0) + { + printf("timer_create err %d %d\n", val, errno); + return val; + } + g_wdg[wdg_id].is_start = 1; + } + g_wdg[wdg_id].is_execed = 0; + // printf("set g_wdg[%d].is_execed %d 0x%lx\n", + // wdg_id, + // g_wdg[wdg_id].is_execed, + // &g_wdg[wdg_id].is_execed); + g_wdg[wdg_id].ticks = ticks; + it.it_interval.tv_sec = 0; + it.it_interval.tv_nsec = g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO; + it.it_value.tv_sec = 0; + it.it_value.tv_nsec = 1000;//g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO;//1000 + + // printf("timer_settime\n"); + // usleep(10); + val = timer_settime(g_wdg[wdg_id].timerid, 0, &it, NULL); + if(val < 0) + { + ; + // printf("timer_settime err %d %d\n", val, errno); + } + // printf("timer_settime %d\n", val); + // val=wdStart(wdg_id,ticks,func,arg); + return val; +} + +void FunWdg_tma_2022(void *arg) +{ + nCount_tma_2022++; +} + +int Test_Wdg_gn_tma_2022() +{ + int res; + wdg_t wdg_id; + + pthread_delay( 100 ); + + res = wdg_create(&wdg_id); // 创建一个看门狗 + if (res == 0) { + printf("230--Pass--wdg_create(&wdg_id)\n"); + } else { + printf("231--Fail--wdg_create(&wdg_id)\tres = %d\t errno = %d\n",res,errno); + return -1; + } + + sleep(1); + //看门狗启动 + wdg_start(wdg_id,1000*2,FunWdg_tma_2022,NULL); + + //看门狗启动后删除 + res = wdg_delete(wdg_id); + if (res == 0) { + printf("232--Pass--wdg_delete(wdg_id)\n"); + } else { + printf("233--Fail--wdg_delete(wdg_id)\tres = %d\t errno = %d\n",res,errno); + return -1; + } + + return 0; +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main() +{ + int result; + + result = Test_Wdg_gn_tma_2022(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/timer_management/gjb_S0101203GN_1.c b/timer_management/gjb_S0101203GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..4aa29e749cfd92010308e49d7e0019583c4b51b2 --- /dev/null +++ b/timer_management/gjb_S0101203GN_1.c @@ -0,0 +1,235 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101203GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 看门狗定时器绑定功能测试,正常绑定看门狗定时器 +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include +#include +#include "signal.h" +#include + +#define MAX_WDG_NUM 64 +#define SYSTEM_TICKS_USEC 1000 +#define ECALLEDINISR 11 +#define SYSTEM_TICKS_NANO 100000 + +typedef void (*wdg_func)(void *); +typedef int wdg_t; +typedef struct __wdg_attr +{ + unsigned int used; + timer_t timerid; + int ticks; + int is_start; + int is_execed; + struct sigevent evp; + void *args; + wdg_func func; +}wdg_attr; +wdg_attr g_wdg[MAX_WDG_NUM]; + +unsigned long long g_pthread_delay_tick; +int is_set_sys_rate; +unsigned int g_sys_uleep_tick; + +int Flag_tma_2031 = 0; + +int wdg_create(wdg_t *wdg_id) +{ + int id = 0; + if(wdg_id == NULL) + return -1; + for(id = 1; id < MAX_WDG_NUM; id++) + { + if(g_wdg[id].used == 0) + break; + } + if(id == MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + g_wdg[id].used = 1; + g_wdg[id].is_start = 0; + // wdg_t id=wdCreate(); + *wdg_id = id; + // printf("wdg_create %d\n", *wdg_id); + return 0; +} + +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); + } +} + +// TODO:该函数与glibc-2.28/sysdeps/mach/hurd/setitimer.c的函数有冲突 +static void timer_thread(union sigval v) +{ + // printf("timer_thread function! %d %d 0x%lx 0x%lx\n", + // v.sival_int, + // g_wdg[v.sival_int].is_execed, + // &g_wdg[v.sival_int].is_execed, + // g_wdg[v.sival_int].func); + if(g_wdg[v.sival_int].func != NULL && (g_wdg[v.sival_int].is_execed == 0)) + { + g_wdg[v.sival_int].is_execed = 1; + g_wdg[v.sival_int].func(g_wdg[v.sival_int].args); + // printf("timer_thread set g_wdg[%d].is_execed %d 0x%lx\n", + // v.sival_int, + // g_wdg[v.sival_int].is_execed, + // &g_wdg[v.sival_int].is_execed); + } +} +int wdg_start(wdg_t wdg_id,int ticks,void (*func)(void *arg),void *arg) +{ + int val; + struct itimerspec it; + if(wdg_id < 1 || wdg_id >= MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + if ((func == NULL) && (arg == NULL)) + { + return 0; + } + if(func == NULL) + { + return -1; + } + // printf("wdg_start wdg_id %d\n", wdg_id); + memset(&g_wdg[wdg_id].evp, 0, sizeof(struct sigevent)); + g_wdg[wdg_id].evp.sigev_value.sival_int = wdg_id; //也是标识定时器的,回调函数可以获得 + g_wdg[wdg_id].evp.sigev_notify = SIGEV_THREAD; //线程通知的方式,派驻新线程 + g_wdg[wdg_id].evp.sigev_notify_function = timer_thread; //线程函数地址 + g_wdg[wdg_id].func = func; + g_wdg[wdg_id].args = arg; + + if(g_wdg[wdg_id].is_start == 0) + { + // printf("timer_create %d\n", ticks); + val = timer_create(CLOCK_REALTIME, &g_wdg[wdg_id].evp, &g_wdg[wdg_id].timerid); + if(val < 0) + { + printf("timer_create err %d %d\n", val, errno); + return val; + } + g_wdg[wdg_id].is_start = 1; + } + g_wdg[wdg_id].is_execed = 0; + // printf("set g_wdg[%d].is_execed %d 0x%lx\n", + // wdg_id, + // g_wdg[wdg_id].is_execed, + // &g_wdg[wdg_id].is_execed); + g_wdg[wdg_id].ticks = ticks; + it.it_interval.tv_sec = 0; + it.it_interval.tv_nsec = g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO; + it.it_value.tv_sec = 0; + it.it_value.tv_nsec = 1000;//g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO;//1000 + + // printf("timer_settime\n"); + // usleep(10); + val = timer_settime(g_wdg[wdg_id].timerid, 0, &it, NULL); + if(val < 0) + { + ; + // printf("timer_settime err %d %d\n", val, errno); + } + // printf("timer_settime %d\n", val); + // val=wdStart(wdg_id,ticks,func,arg); + return val; +} + +void Fun1_tma_2031(void* arg) +{ + Flag_tma_2031 = *((int *)arg); + return; +} + +int Test_Wdg_gn_tma_2031() +{ + wdg_t wdg_id; + int res; + + //创建看门狗 + res=wdg_create(&wdg_id); + if(res==0) + { + printf("250--Pass--wdg_create(&wdg_id)\n"); + } + else + { + printf("251--Fail--wdg_create(&wdg_id)\n"); + return -1; + } + + //启动看门狗 + int start_arg = 100; + res=wdg_start(wdg_id,100,Fun1_tma_2031,&start_arg); + if(res==0) + { + pthread_delay(100); + if (Flag_tma_2031 == start_arg) { + printf("252--Pass--wdg_start(wdg_id,100,Fun1,NULL)\n"); + return 0; + } else { + printf("253--Fail--wdg_start(wdg_id,100,Fun1,NULL)\n"); + return -1; + } + + } + else + { + printf("253--Fail--wdg_start(wdg_id,100,Fun1,NULL)\n"); + return -1; + } + + return 0; +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main() +{ + int result; + + result = Test_Wdg_gn_tma_2031(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/timer_management/gjb_S0101204GN_1.c b/timer_management/gjb_S0101204GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..070843ac045c77d4d352301a17e46dbc75b60a71 --- /dev/null +++ b/timer_management/gjb_S0101204GN_1.c @@ -0,0 +1,213 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101204GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 看门狗定时器启动, 单次 +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include +#include +#include "signal.h" +#include + +#define MAX_WDG_NUM 64 +#define SYSTEM_TICKS_USEC 1000 +#define ECALLEDINISR 11 +#define SYSTEM_TICKS_NANO 100000 +#define EMNOTINITED 0x7A + +typedef void (*wdg_func)(void *); +typedef int wdg_t; +typedef struct __wdg_attr +{ + unsigned int used; + timer_t timerid; + int ticks; + int is_start; + int is_execed; + struct sigevent evp; + void *args; + wdg_func func; +}wdg_attr; +wdg_attr g_wdg[MAX_WDG_NUM]; + +static int nCount_tma_2041=0; + +int wdg_create(wdg_t *wdg_id) +{ + int id = 0; + if(wdg_id == NULL) + return -1; + for(id = 1; id < MAX_WDG_NUM; id++) + { + if(g_wdg[id].used == 0) + break; + } + if(id == MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + g_wdg[id].used = 1; + g_wdg[id].is_start = 0; + // wdg_t id=wdCreate(); + *wdg_id = id; + // printf("wdg_create %d\n", *wdg_id); + return 0; +} + +// TODO:该函数与glibc-2.28/sysdeps/mach/hurd/setitimer.c的函数有冲突 +static void timer_thread(union sigval v) +{ + // printf("timer_thread function! %d %d 0x%lx 0x%lx\n", + // v.sival_int, + // g_wdg[v.sival_int].is_execed, + // &g_wdg[v.sival_int].is_execed, + // g_wdg[v.sival_int].func); + if(g_wdg[v.sival_int].func != NULL && (g_wdg[v.sival_int].is_execed == 0)) + { + g_wdg[v.sival_int].is_execed = 1; + g_wdg[v.sival_int].func(g_wdg[v.sival_int].args); + // printf("timer_thread set g_wdg[%d].is_execed %d 0x%lx\n", + // v.sival_int, + // g_wdg[v.sival_int].is_execed, + // &g_wdg[v.sival_int].is_execed); + } +} +int wdg_start(wdg_t wdg_id,int ticks,void (*func)(void *arg),void *arg) +{ + int val; + struct itimerspec it; + if(wdg_id < 1 || wdg_id >= MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + if ((func == NULL) && (arg == NULL)) + { + return 0; + } + if(func == NULL) + { + return -1; + } + // printf("wdg_start wdg_id %d\n", wdg_id); + memset(&g_wdg[wdg_id].evp, 0, sizeof(struct sigevent)); + g_wdg[wdg_id].evp.sigev_value.sival_int = wdg_id; //也是标识定时器的,回调函数可以获得 + g_wdg[wdg_id].evp.sigev_notify = SIGEV_THREAD; //线程通知的方式,派驻新线程 + g_wdg[wdg_id].evp.sigev_notify_function = timer_thread; //线程函数地址 + g_wdg[wdg_id].func = func; + g_wdg[wdg_id].args = arg; + + if(g_wdg[wdg_id].is_start == 0) + { + // printf("timer_create %d\n", ticks); + val = timer_create(CLOCK_REALTIME, &g_wdg[wdg_id].evp, &g_wdg[wdg_id].timerid); + if(val < 0) + { + printf("timer_create err %d %d\n", val, errno); + return val; + } + g_wdg[wdg_id].is_start = 1; + } + g_wdg[wdg_id].is_execed = 0; + // printf("set g_wdg[%d].is_execed %d 0x%lx\n", + // wdg_id, + // g_wdg[wdg_id].is_execed, + // &g_wdg[wdg_id].is_execed); + g_wdg[wdg_id].ticks = ticks; + it.it_interval.tv_sec = 0; + it.it_interval.tv_nsec = g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO; + it.it_value.tv_sec = 0; + it.it_value.tv_nsec = 1000;//g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO;//1000 + + // printf("timer_settime\n"); + // usleep(10); + val = timer_settime(g_wdg[wdg_id].timerid, 0, &it, NULL); + if(val < 0) + { + ; + // printf("timer_settime err %d %d\n", val, errno); + } + // printf("timer_settime %d\n", val); + // val=wdStart(wdg_id,ticks,func,arg); + return val; +} + +void Fun1_tma_2041(void*arg) +{ + nCount_tma_2041++; + return; +} + +int Test_Wdg_gn_tma_2041() +{ + wdg_t wdg_id; + int res; + int cstr=100; + + //创建看门狗 + res=wdg_create(&wdg_id); + if(res==0) + { + printf("280--Pass--wdg_create(&wdg_id)\n"); + + } + else + { + printf("281--Fail--wdg_create(&wdg_id)\n"); + return -1; + } + + //启动看门狗 + res=wdg_start(wdg_id,100,Fun1_tma_2041,&cstr); + sleep(1); + if((res==0) && (nCount_tma_2041 == 1)) + { + printf("282--Pass--wdg_start(wdg_id,100,Fun1,&cstr)\n"); + return 0; + } + else + { + printf("283--Fail--wdg_start(wdg_id,100,Fun1,&cstr)\n"); + return -1; + + } + return 0; +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main() +{ + int result; + + result = Test_Wdg_gn_tma_2041(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/timer_management/gjb_S0101204GN_2.c b/timer_management/gjb_S0101204GN_2.c new file mode 100644 index 0000000000000000000000000000000000000000..24a01a52abf142030e768ace37bcfad6443072d6 --- /dev/null +++ b/timer_management/gjb_S0101204GN_2.c @@ -0,0 +1,208 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101204GN_2.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 看门狗定时器启动, 单次,延迟时间参数为负值(可以为0吗?) +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include +#include +#include "signal.h" +#include + +#define MAX_WDG_NUM 64 +#define SYSTEM_TICKS_USEC 1000 +#define ECALLEDINISR 11 +#define SYSTEM_TICKS_NANO 100000 +#define EMNOTINITED 0x7A + +typedef void (*wdg_func)(void *); +typedef int wdg_t; +typedef struct __wdg_attr +{ + unsigned int used; + timer_t timerid; + int ticks; + int is_start; + int is_execed; + struct sigevent evp; + void *args; + wdg_func func; +}wdg_attr; +wdg_attr g_wdg[MAX_WDG_NUM]; + +static int nCount_tma_2042 = 0; + +int wdg_create(wdg_t *wdg_id) +{ + int id = 0; + if(wdg_id == NULL) + return -1; + for(id = 1; id < MAX_WDG_NUM; id++) + { + if(g_wdg[id].used == 0) + break; + } + if(id == MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + g_wdg[id].used = 1; + g_wdg[id].is_start = 0; + // wdg_t id=wdCreate(); + *wdg_id = id; + // printf("wdg_create %d\n", *wdg_id); + return 0; +} + +// TODO:该函数与glibc-2.28/sysdeps/mach/hurd/setitimer.c的函数有冲突 +static void timer_thread(union sigval v) +{ + // printf("timer_thread function! %d %d 0x%lx 0x%lx\n", + // v.sival_int, + // g_wdg[v.sival_int].is_execed, + // &g_wdg[v.sival_int].is_execed, + // g_wdg[v.sival_int].func); + if(g_wdg[v.sival_int].func != NULL && (g_wdg[v.sival_int].is_execed == 0)) + { + g_wdg[v.sival_int].is_execed = 1; + g_wdg[v.sival_int].func(g_wdg[v.sival_int].args); + // printf("timer_thread set g_wdg[%d].is_execed %d 0x%lx\n", + // v.sival_int, + // g_wdg[v.sival_int].is_execed, + // &g_wdg[v.sival_int].is_execed); + } +} +int wdg_start(wdg_t wdg_id,int ticks,void (*func)(void *arg),void *arg) +{ + int val; + struct itimerspec it; + if(wdg_id < 1 || wdg_id >= MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + if ((func == NULL) && (arg == NULL)) + { + return 0; + } + if(func == NULL) + { + return -1; + } + // printf("wdg_start wdg_id %d\n", wdg_id); + memset(&g_wdg[wdg_id].evp, 0, sizeof(struct sigevent)); + g_wdg[wdg_id].evp.sigev_value.sival_int = wdg_id; //也是标识定时器的,回调函数可以获得 + g_wdg[wdg_id].evp.sigev_notify = SIGEV_THREAD; //线程通知的方式,派驻新线程 + g_wdg[wdg_id].evp.sigev_notify_function = timer_thread; //线程函数地址 + g_wdg[wdg_id].func = func; + g_wdg[wdg_id].args = arg; + + if(g_wdg[wdg_id].is_start == 0) + { + // printf("timer_create %d\n", ticks); + val = timer_create(CLOCK_REALTIME, &g_wdg[wdg_id].evp, &g_wdg[wdg_id].timerid); + if(val < 0) + { + printf("timer_create err %d %d\n", val, errno); + return val; + } + g_wdg[wdg_id].is_start = 1; + } + g_wdg[wdg_id].is_execed = 0; + // printf("set g_wdg[%d].is_execed %d 0x%lx\n", + // wdg_id, + // g_wdg[wdg_id].is_execed, + // &g_wdg[wdg_id].is_execed); + g_wdg[wdg_id].ticks = ticks; + it.it_interval.tv_sec = 0; + it.it_interval.tv_nsec = g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO; + it.it_value.tv_sec = 0; + it.it_value.tv_nsec = 1000;//g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO;//1000 + + // printf("timer_settime\n"); + // usleep(10); + val = timer_settime(g_wdg[wdg_id].timerid, 0, &it, NULL); + if(val < 0) + { + ; + // printf("timer_settime err %d %d\n", val, errno); + } + // printf("timer_settime %d\n", val); + // val=wdStart(wdg_id,ticks,func,arg); + return val; +} + +void Fun1_tma_2042 (void *arg) +{ + nCount_tma_2042++; +} + +int Test_Wdg_gn_tma_2042 (void) +{ + wdg_t wdg_id; + int res; + int cstr = 100; + + //创建看门狗 + res = wdg_create(&wdg_id); + if (res == 0) { + printf("290--Pass--wdg_create(&wdg_id)\n"); + + } else { + printf("291--Fail--wdg_create(&wdg_id)\n"); + return -1; + } + + //启动看门狗 + res = wdg_start(wdg_id, -1, Fun1_tma_2042, &cstr); + sleep(1); + + if ((res == -1) && (nCount_tma_2042 == 0)) { + printf("292--Pass--wdg_start(wdg_id,100,Fun1,&cstr)\n"); + return 0; + + } else { + printf("293--Fail--wdg_start(wdg_id,100,Fun1,&cstr)\n"); + return -1; + } + + return 0; +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main() +{ + int result; + + result = Test_Wdg_gn_tma_2042(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/timer_management/gjb_S0101204GN_3.c b/timer_management/gjb_S0101204GN_3.c new file mode 100644 index 0000000000000000000000000000000000000000..fae88fa37cc6756f7839b51ec2284e280ada88fa --- /dev/null +++ b/timer_management/gjb_S0101204GN_3.c @@ -0,0 +1,208 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101204GN_3.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 看门狗定时器启动, 单次, 使用无效看门狗ID; +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include +#include +#include "signal.h" +#include + +#define MAX_WDG_NUM 64 +#define SYSTEM_TICKS_USEC 1000 +#define ECALLEDINISR 11 +#define SYSTEM_TICKS_NANO 100000 +#define EMNOTINITED 0x7A + +typedef void (*wdg_func)(void *); +typedef int wdg_t; +typedef struct __wdg_attr +{ + unsigned int used; + timer_t timerid; + int ticks; + int is_start; + int is_execed; + struct sigevent evp; + void *args; + wdg_func func; +}wdg_attr; +wdg_attr g_wdg[MAX_WDG_NUM]; + +static int nCount_tma_2043 = 0; + +int wdg_create(wdg_t *wdg_id) +{ + int id = 0; + if(wdg_id == NULL) + return -1; + for(id = 1; id < MAX_WDG_NUM; id++) + { + if(g_wdg[id].used == 0) + break; + } + if(id == MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + g_wdg[id].used = 1; + g_wdg[id].is_start = 0; + // wdg_t id=wdCreate(); + *wdg_id = id; + // printf("wdg_create %d\n", *wdg_id); + return 0; +} + +// TODO:该函数与glibc-2.28/sysdeps/mach/hurd/setitimer.c的函数有冲突 +static void timer_thread(union sigval v) +{ + // printf("timer_thread function! %d %d 0x%lx 0x%lx\n", + // v.sival_int, + // g_wdg[v.sival_int].is_execed, + // &g_wdg[v.sival_int].is_execed, + // g_wdg[v.sival_int].func); + if(g_wdg[v.sival_int].func != NULL && (g_wdg[v.sival_int].is_execed == 0)) + { + g_wdg[v.sival_int].is_execed = 1; + g_wdg[v.sival_int].func(g_wdg[v.sival_int].args); + // printf("timer_thread set g_wdg[%d].is_execed %d 0x%lx\n", + // v.sival_int, + // g_wdg[v.sival_int].is_execed, + // &gGJB_PRT_INFO_wdg[v.sival_int].is_execed); + } +} +int wdg_start(wdg_t wdg_id,int ticks,void (*func)(void *arg),void *arg) +{ + int val; + struct itimerspec it; + if(wdg_id < 1 || wdg_id >= MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + if ((func == NULL) && (arg == NULL)) + { + return 0; + } + if(func == NULL) + { + return -1; + } + // printf("wdg_start wdg_id %d\n", wdg_id); + memset(&g_wdg[wdg_id].evp, 0, sizeof(struct sigevent)); + g_wdg[wdg_id].evp.sigev_value.sival_int = wdg_id; //也是标识定时器的,回调函数可以获得 + g_wdg[wdg_id].evp.sigev_notify = SIGEV_THREAD; //线程通知的方式,派驻新线程 + g_wdg[wdg_id].evp.sigev_notify_function = timer_thread; //线程函数地址 + g_wdg[wdg_id].func = func; + g_wdg[wdg_id].args = arg; + + if(g_wdg[wdg_id].is_start == 0) + { + // printf("timer_create %d\n", ticks); + val = timer_create(CLOCK_REALTIME, &g_wdg[wdg_id].evp, &g_wdg[wdg_id].timerid); + if(val < 0) + { + printf("timer_create err %d %d\n", val, errno); + return val; + }GJB_PRT_INFO + g_wdg[wdg_id].is_start = 1; + } + g_wdg[wdg_id].is_execed = 0; + // printf("set g_wdg[%d].is_execed %d 0x%lx\n", + // wdg_id, + // g_wdg[wdg_id].is_execed, + // &g_wdg[wdg_id].is_execed); + g_wdg[wdg_id].ticks = ticks; + it.it_interval.tv_sec = 0; + it.it_interval.tv_nsec = g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO; + it.it_value.tv_sec = 0; + it.it_value.tv_nsec = 1000;//g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO;//1000 + + // printf("timer_settime\n"); + // usleep(10); + val = timer_settime(g_wdg[wdg_id].timerid, 0, &it, NULL); + if(val < 0) + { + ; + // printf("timer_settime err %d %d\n", val, errno); + } + // printf("timer_settime %d\n", val); + // val=wdStart(wdg_id,ticks,func,arg); + return val; +} + + +void Fun1_tma_2043 (void* arg) +{ + nCount_tma_2043++; +} + +//看门狗测试入口函数 +int Test_Wdg_gn_tma_2043 (void) +{ + wdg_t wdg_id; + int res; + + //创建看门狗 + res = wdg_create(&wdg_id); + if (res == 0) { + printf("300--Pass--wdg_create(&wdg_id)\n"); + } else { + printf("301--Fail--wdg_create(&wdg_id)\n"); + return -1; + } + + //启动看门狗 + res = wdg_start(0, 100, Fun1_tma_2043, NULL); + sleep(1); + + if ((res == -1) && (nCount_tma_2043 == 0)) { + printf("302--Pass--wdg_start(wdg_id,100,Fun1,&cstr)\n"); + return 0; + + } else { + printf("303--Fail--wdg_start(wdg_id,100,Fun1,&cstr)\n"); + return -1; + } + + return 0; +} +/***************************GJB_PRT_INFO******************************************* + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main() +{ + int result; + + result = Test_Wdg_gn_tma_2043(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/timer_management/gjb_S0101205GN.c b/timer_management/gjb_S0101205GN.c new file mode 100644 index 0000000000000000000000000000000000000000..ded77a8ada1a31266c07e287a1d92bb391154f57 --- /dev/null +++ b/timer_management/gjb_S0101205GN.c @@ -0,0 +1,234 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101205GN.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 看门狗定时器启动多次 启动5次 +*********************************************************************************************************/ +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include +#include +#include "signal.h" +#include + +#define MAX_WDG_NUM 64 +#define SYSTEM_TICKS_USEC 1000 +#define ECALLEDINISR 11 +#define SYSTEM_TICKS_NANO 100000 +#define EMNOTINITED 0x7A + +typedef void (*wdg_func)(void *); +typedef int wdg_t; +typedef struct __wdg_attr +{ + unsigned int used; + timer_t timerid; + int ticks; + int is_start; + int is_execed; + struct sigevent evp; + void *args; + wdg_func func; +}wdg_attr; +wdg_attr g_wdg[MAX_WDG_NUM]; + +unsigned long long g_pthread_delay_tick; +int is_set_sys_rate; +unsigned int g_sys_uleep_tick; + +static int nCount_tma_205 = 5; +static wdg_t wdg_id_tma_205; + +int wdg_create(wdg_t *wdg_id) +{ + int id = 0; + if(wdg_id == NULL) + return -1; + for(id = 1; id < MAX_WDG_NUM; id++) + { + if(g_wdg[id].used == 0) + break; + } + if(id == MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + g_wdg[id].used = 1; + g_wdg[id].is_start = 0; + // wdg_t id=wdCreate(); + *wdg_id = id; + // printf("wdg_create %d\n", *wdg_id); + return 0; +} + +// TODO:该函数与glibc-2.28/sysdeps/mach/hurd/setitimer.c的函数有冲突 +static void timer_thread(union sigval v) +{ + // printf("timer_thread function! %d %d 0x%lx 0x%lx\n", + // v.sival_int, + // g_wdg[v.sival_int].is_execed, + // &g_wdg[v.sival_int].is_execed, + // g_wdg[v.sival_int].func); + if(g_wdg[v.sival_int].func != NULL && (g_wdg[v.sival_int].is_execed == 0)) + { + g_wdg[v.sival_int].is_execed = 1; + g_wdg[v.sival_int].func(g_wdg[v.sival_int].args); + // printf("timer_thread set g_wdg[%d].is_execed %d 0x%lx\n", + // v.sival_int, + // g_wdg[v.sival_int].is_execed, + // &g_wdg[v.sival_int].is_execed); + } +} +int wdg_start(wdg_t wdg_id,int ticks,void (*func)(void *arg),void *arg) +{ + int val; + struct itimerspec it; + if(wdg_id < 1 || wdg_id >= MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + if ((func == NULL) && (arg == NULL)) + { + return 0; + } + if(func == NULL) + { + return -1; + } + // printf("wdg_start wdg_id %d\n", wdg_id); + memset(&g_wdg[wdg_id].evp, 0, sizeof(struct sigevent)); + g_wdg[wdg_id].evp.sigev_value.sival_int = wdg_id; //也是标识定时器的,回调函数可以获得 + g_wdg[wdg_id].evp.sigev_notify = SIGEV_THREAD; //线程通知的方式,派驻新线程 + g_wdg[wdg_id].evp.sigev_notify_function = timer_thread; //线程函数地址 + g_wdg[wdg_id].func = func; + g_wdg[wdg_id].args = arg; + + if(g_wdg[wdg_id].is_start == 0) + { + // printf("timer_create %d\n", ticks); + val = timer_create(CLOCK_REALTIME, &g_wdg[wdg_id].evp, &g_wdg[wdg_id].timerid); + if(val < 0) + { + printf("timer_create err %d %d\n", val, errno); + return val; + } + g_wdg[wdg_id].is_start = 1; + } + g_wdg[wdg_id].is_execed = 0; + // printf("set g_wdg[%d].is_execed %d 0x%lx\n", + // wdg_id, + // g_wdg[wdg_id].is_execed, + // &g_wdg[wdg_id].is_execed); + g_wdg[wdg_id].ticks = ticks; + it.it_interval.tv_sec = 0; + it.it_interval.tv_nsec = g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO; + it.it_value.tv_sec = 0; + it.it_value.tv_nsec = 1000;//g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO;//1000 + + // printf("timer_settime\n"); + // usleep(10); + val = timer_settime(g_wdg[wdg_id].timerid, 0, &it, NULL); + if(val < 0) + { + ; + // printf("timer_settime err %d %d\n", val, errno); + } + // printf("timer_settime %d\n", val); + // val=wdStart(wdg_id,ticks,func,arg); + return val; +} + +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 Fun1_tma_205 (void* arg) +{ + if (nCount_tma_205 > 0) { + nCount_tma_205--; + pthread_delay(50); + wdg_start(wdg_id_tma_205, 100, Fun1_tma_205, NULL); + } +} + +int Test_Wdg_gn_tma_205() +{ + int res; + + //创建看门狗 + res = wdg_create(&wdg_id_tma_205); + if (res == 0) { + printf("320--Pass--wdg_create(&wdg_id)\n"); + + } else { + printf("321--Fail--wdg_create(&wdg_id)\n"); + return -1; + } + + //启动看门狗 + res = wdg_start(wdg_id_tma_205, 100, Fun1_tma_205, NULL); + if (res == 0) { + printf("Pass--wdg_start(wdg_id,100,Fun1,NULL)\n"); + return 0; + + } else { + printf("Fail--wdg_start(wdg_id,100,Fun1,&cstr)\n"); + return -1; + } + + return 0; +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main() +{ + int result; + + result = Test_Wdg_gn_tma_205(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + sleep(2); + + if (nCount_tma_205 != 0) { //5次是否执行完毕,则成功; + printf("info: -- nCount = %d\n ", nCount_tma_205); + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +} diff --git a/timer_management/gjb_S0101206GN_1.c b/timer_management/gjb_S0101206GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..293de10176852451414d59d4438b1887228c8e5d --- /dev/null +++ b/timer_management/gjb_S0101206GN_1.c @@ -0,0 +1,267 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101206GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 停止看门狗定时器 +*********************************************************************************************************/ + +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include +#include +#include +#include +#include +#include "signal.h" +#include + +#define MAX_WDG_NUM 64 +#define SYSTEM_TICKS_USEC 1000 +#define ECALLEDINISR 11 +#define SYSTEM_TICKS_NANO 100000 +#define EMNOTINITED 0x7A +#define FALSE 0 +#define TRUE 1 + +typedef unsigned char BOOL; +typedef void (*wdg_func)(void *); +typedef int wdg_t; +typedef struct __wdg_attr +{ + unsigned int used; + timer_t timerid; + int ticks; + int is_start; + int is_execed; + struct sigevent evp; + void *args; + wdg_func func; +}wdg_attr; +wdg_attr g_wdg[MAX_WDG_NUM]; + +unsigned long long g_pthread_delay_tick; +int is_set_sys_rate; +unsigned int g_sys_uleep_tick; +#include +static int nCount_tma_2061=5; + +wdg_t wdg_id_tma_2061; + +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 wdg_create(wdg_t *wdg_id) +{ + int id = 0; + if(wdg_id == NULL) + return -1; + for(id = 1; id < MAX_WDG_NUM; id++) + { + if(g_wdg[id].used == 0) + break; + } + if(id == MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + g_wdg[id].used = 1; + g_wdg[id].is_start = 0; + // wdg_t id=wdCreate(); + *wdg_id = id; + // printf("wdg_create %d\n", *wdg_id); + return 0; +}#include + +// TODO:该函数与glibc-2.28/sysdeps/mach/hurd/setitimer.c的函数有冲突 +static void timer_thread(union sigval v) +{ + // printf("timer_thread function! %d %d 0x%lx 0x%lx\n", + // v.sival_int, + // g_wdg[v.sival_int].is_execed, + // &g_wdg[v.sival_int].is_execed, + // g_wdg[v.sival_int].func); + if(g_wdg[v.sival_int].func != NULL && (g_wdg[v.sival_int].is_execed == 0)) + { + g_wdg[v.sival_int].is_execed = 1; + g_wdg[v.sival_int].func(g_wdg[v.sival_int].args); + // printf("timer_thread set g_wdg[%d].is_execed %d 0x%lx\n", + // v.sival_int, + // g_wdg[v.sival_int].is_execed, + // &g_wdg[v.sival_int].is_execed); + } +} +int wdg_start(wdg_t wdg_id,int ticks,void (*func)(void *arg),void *arg) +{ + int val; + struct itimerspec it; + if(wdg_id < 1 || wdg_id >= MAX_WDG_NUM) + { + errno = EAGAIN; + return -1; + } + if ((func == NULL) && (arg == NULL)) + { + return 0; + } + if(func == NULL) + { + return -1; + } + // printf("wdg_start wdg_id %d\n", wdg_id); + memset(&g_wdg[wdg_id].evp, 0, sizeof(struct sigevent)); + g_wdg[wdg_id].evp.sigev_value.sival_int = wdg_id; //也是标识定时器的,回调函数可以获得 + g_wdg[wdg_id].evp.sigev_notify = SIGEV_THREAD; //线程通知的方式,派驻新线程 + g_wdg[wdg_id].evp.sigev_notify_function = timer_thread; //线程函数地址 + g_wdg[wdg_id].func = func; + g_wdg[wdg_id].args = arg; + + if(g_wdg[wdg_id].is_start == 0) + { + // printf("timer_create %d\n", ticks); + val = timer_create(CLOCK_REALTIME, &g_wdg[wdg_id].evp, &g_wdg[wdg_id].timerid); + if(val < 0) + { + printf("timer_create err %d %d\n", val, errno); + return val; + } + g_wdg[wdg_id].is_start = 1; + } + g_wdg[wdg_id].is_execed = 0; + // printf("set g_wdg[%d].is_execed %d 0x%lx\n", + // wdg_id, + // g_wdg[wdg_id].is_execed, + // &g_wdg[wdg_id].is_execed); + g_wdg[wdg_id].ticks = ticks; + it.it_interval.tv_sec = 0; + it.it_interval.tv_nsec = g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO; + it.it_value.tv_sec = 0; + it.it_value.tv_nsec = 1000;//g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO;//1000 + + // printf("timer_settime\n"); + // usleep(10);#include + val = timer_settime(g_wdg[wdg_id].timerid, 0, &it, NULL); + if(val < 0) + { + ; + // printf("timer_settime err %d %d\n", val, errno); + } + // printf("timer_settime %d\n", val); + // val=wdStart(wdg_id,ticks,func,arg); + return val; +} + +int wdg_cancel(wdg_t wdg_id) +{ + if (wdg_id <= 0) + { + errno = EINVAL; + return -1; + } + int ret; + // ret=wdCancel(wdg_id); + struct itimerspec it; + it.it_interval.tv_sec = 864000; + it.it_interval.tv_nsec = g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO; + it.it_value.tv_sec = 0; + it.it_value.tv_nsec = 0;//g_wdg[wdg_id].ticks * SYSTEM_TICKS_NANO;//0 + g_wdg[wdg_id].is_execed = 1; + + ret = timer_settime(g_wdg[wdg_id].timerid, 0, &it, NULL); + return ret; +} + +void Fun1_tma_2061(void*arg) +{ + if (nCount_tma_2061 > 0) { + nCount_tma_2061--; + pthread_de0lay(50); + wdg_start(wdg_id_tma_2061,100,Fun1_tma_2061,NULL); // 启动看门狗 + + if(nCount_tma_2061 == 1 ) + { + wdg_cancel(wdg_id_tma_2061); + + //再次启动 + pthread_delay(50); + wdg_start(wdg_id_tma_2061,100,Fun1_tma_2061,NULL); + } + } +} + +int Test_Wdg_gn_tma_2061() +{ + int res; + //创建看门狗 + res=wdg_create(&wdg_id_tma_2061); + if(res==0) + { + printf("Pass--wdg_create(&wdg_id)\n"); + } + else + { + printf("Fail--wdg_create(&wdg_id)\n"); + return -1; + } + //启动看门狗 + res=wdg_start(wdg_id_tma_2061,100,Fun1_tma_2061,NULL); + if(res==0) + { + printf("Pass--wdg_start(wdg_id,100,Fun1,NULL)\n"); + return 0; + } + else + { + printf("Fail--wdg_start(wdg_id,100,Fun1,&cstr)\n"); + return -1; + } + return 0; +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main() +{ + int result; + + result = Test_Wdg_gn_tma_2061(); + if (result != 0) { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + sleep(2); + if (nCount_tma_2061!=0) //5次是否执行完毕,则成功 + { + printf("..................................................[GJB_FAILED]\n"); + return -1; + } + + printf("..................................................[GJB_PASS]\n"); + return 0; +}