From 20fbe81d8a34e28210d48101a2f7d76212a65bdc Mon Sep 17 00:00:00 2001 From: lijiande Date: Sat, 14 Oct 2023 09:43:53 +0800 Subject: [PATCH 1/2] commit test file --- Inter_management/gjb_S0101301GN.c | 168 +++++ .../gjb_S0101305GN_S0101306GN_2.c | 687 ++++++++++++++++++ 2 files changed, 855 insertions(+) create mode 100644 Inter_management/gjb_S0101301GN.c create mode 100644 Inter_management/gjb_S0101305GN_S0101306GN_2.c diff --git a/Inter_management/gjb_S0101301GN.c b/Inter_management/gjb_S0101301GN.c new file mode 100644 index 0000000..8c957cf --- /dev/null +++ b/Inter_management/gjb_S0101301GN.c @@ -0,0 +1,168 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101301GN.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 中断默认行为测试 (非龙芯平台) +*********************************************************************************************************/ +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include "gjb.h" + +static volatile int nCount_S0101301GN[256] = {0}; + +static pthread_attr_t thread_attr5; +static pthread_t thread_id5; + +/* + * 系统中所有中断进入服务函数的时候会自动调用该回调函数 + * 将中断的向量号记录到 数组中,通过查看数组中的值证明中断进入了 + * 注意: 不能直接在中断函数中打印, 因为中断对于整个系统的优先级是最高的 + * 如果打印,则会造成系统持续在中断中, 而影响系统的调度. + */ +typedef struct { + unsigned short offset_low; + unsigned short segment; + unsigned char zero; + unsigned char flags; + unsigned short offset_high; +} __attribute__((packed)) idt_entry_t; + +void default_int_show_action (unsigned long v, unsigned long net) +{ + nCount_S0101301GN[v] = v; +} + +/* + * 这个函数将我们的数组清0, 以防止随机数据影响我们的判断 + */ +void default_int_clear_my_array (void) +{ + int i; + + for (i = 0; i < 256; ++i) { + nCount_S0101301GN[i] = 0; + } +} + +void *Fun5_default_thread (void *arg) +{ + int i, j; + + gjb_int_show_start(default_int_show_action); + + for (j = 0; j < 10; j++) { + for (i = 0; i < 256; ++i) { + if (nCount_S0101301GN[i]) { + gjb_os_printk("find int %lu entry.\n", nCount_S0101301GN[i]); + } + } + + /* + * 将数组中的值清除 + */ + default_int_clear_my_array(); + sleep(1); + } + + gjb_int_show_end(default_int_show_action); + + return NULL; +} +/********************************************************************************************************* + * 函数名称: Test_interrup4_gn + * 功能描述: 缺省中断服务程序测试 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + ********************************************************************************************************/ +int Test_interrup4_gn (void) +{ + int res; + + /* + * 初始化一个线程属性对象 + */ + pthread_attr_init(&thread_attr5); + + //thread_attr5.schedparam.sched_priority = 100; + struct sched_param param; + param.sched_priority =100; + pthread_attr_setschedparam(&thread_attr5, ¶m); + + default_int_clear_my_array(); + /* + * 创建一个线程 + */ + res = pthread_create(&thread_id5, &thread_attr5, Fun5_default_thread, NULL); + if (res == 0) { + GJB_PRT_INFO("444--Pass--pthread_create( &thread_id1,&thread_attr5, Fun5, NULL )\n"); + } else { + GJB_PRT_ERROR_INFO("445--Fail--pthread_create( &thread_id1,&thread_attr1, Fun1, NULL )\n"); + goto error; + } + + sleep(5); + + /* + * !!!!!!! 通过命令中断查看打印以确认中断是否进入了 + */ + pthread_join(thread_id5, NULL); + + return (0); + +error: + return (-1); +} +/********************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main(int argc, char **argv) +{ + int result; + +#if !defined(__mips__) && !defined(__mips64) && !defined(__loongarch__) + gjb_os_init_vector(); + + result = Test_interrup4_gn(); /* int install */ + if (result != 0) { + return (GJB_PRI_FAIL()); + } +#else + + GJB_PRT_INFO("loongson platform need exec "); +#endif + + return (GJB_PRI_PASS()); +} + + +int NR_VECTORS=1024; +void gjb_os_init_vector(){ + idt_entry_t idt_table[NR_VECTORS]; // 外部定义 IDT 数组 + int i; + + // 遍历中断向量表 + for (i = 0; i < NR_VECTORS; i++) { + // 设置 IDT 的入口 + idt_table[i].zero = 0; + idt_table[i].flags = 0x8E; // 中断门,特权级为0,存在标志位 + } +} +void gjb_int_show_start(void (*default_int_show_action)()){} +void gjb_int_show_end(void (*default_int_show_action)()){} \ No newline at end of file diff --git a/Inter_management/gjb_S0101305GN_S0101306GN_2.c b/Inter_management/gjb_S0101305GN_S0101306GN_2.c new file mode 100644 index 0000000..2c06df8 --- /dev/null +++ b/Inter_management/gjb_S0101305GN_S0101306GN_2.c @@ -0,0 +1,687 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0101305GN_S0101306GN_2.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 中断 int_enable_pic int_disable_pic 测试 +** +** S0101305GN 测试使能向量中断功能 (单个中断) +** S0101306GN 测试屏蔽向量中断功能 (单个中断) +*********************************************************************************************************/ +#ifdef SYLIXOS +#define __SYLIXOS_KERNEL +#endif + +#include "gjb.h" + +#define VECNUM_START 90 +#define VECNUM_END 125 + +static int nCount1_int__pic = 0; +static int nCount2_int__pic = 0; +static char cstr_int_pic[2] = {'A','B'}; + +/********************************************************************************************************* + * 函数名称: Fun + * 功能描述: 中断处理函数 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + ********************************************************************************************************/ +void Fun3 (void *arg) +{ + gjb_os_printk("int triger."); + + nCount1_int__pic++; +} +/********************************************************************************************************* + * 函数名称: Test_interrup3_gn + * 功能描述: 单个中断锁定、解锁 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + ********************************************************************************************************/ +int Test_interrup3_gn (void) +{ + int res; /* 函数返回值 */ + char cname[] = "ITR Name"; + int vecnum; /* 中断向量号 */ + int priority; /* 中断优先级 */ + int error = 0; + + vecnum = 4; + priority = 20; + + /* + * 绑定中断处理函数 + */ + nCount1_int__pic = 1; + nCount2_int__pic = 1; + + for (vecnum = VECNUM_START; vecnum < VECNUM_END; vecnum++) { + if (gjb_os_exclude_vector(vecnum)) { + continue; + } + + res = int_install_handler(cname, vecnum, priority, Fun3, cstr_int_pic); + if (res == 0) { + GJB_PRT_INFO("430--Pass--int_install_handler(cname,vecnum,priority,Fun,cstr)\n"); + nCount2_int__pic++; + + } else { + GJB_PRT_ERROR_INFO("431--Fail--int_install_handler(cname,vecnum,priority,Fun,cstr)\tvecnum = %d\n", vecnum); + error++; + } + } + + if(nCount2_int__pic != nCount1_int__pic) { + GJB_PRT_INFO("432--Pass--int_install_handler\n"); + + } else { + GJB_PRT_ERROR_INFO("433--Fail--int_install_handler\n"); + error++; + } + + for (vecnum = VECNUM_START; vecnum < VECNUM_END; vecnum++) { + if (gjb_os_exclude_vector(vecnum)) { + continue; + } + + int_disable_pic(vecnum); + + nCount1_int__pic = 5; + gjb_os_triger_int(vecnum); + + if (nCount1_int__pic == 5) { + GJB_PRT_INFO("435--Pass--int_disable_pic\n"); + + } else { + GJB_PRT_ERROR_INFO("436--Fail--int_disable_pic\n"); + error++; + } + + usleep(50000); + int_enable_pic(vecnum); + usleep(50000); + + if (nCount1_int__pic == 6) { + GJB_PRT_INFO("441--Pass--int_enable_pic\n"); + + } else { + GJB_PRT_ERROR_INFO("442--Fail--int_enable_pic nCount1 = %d\n", nCount1_int__pic); + error++; + } + } + + for (vecnum = VECNUM_START; vecnum < VECNUM_END; vecnum++) { + if (gjb_os_exclude_vector(vecnum)) { + continue; + } + + int_uninstall_handler(vecnum); + } + + if (error) { + return (-1); + } + + return (0); +} +/************************************************************************** + * 函数名称: void usrMain(void) + * 功能描述: 用户程序入口 + * 输入参数: 无 + * 输出参数: 无 + * 返 回 值: 无 + * 其它说明: 无 + **************************************************************************/ +int main(int argc, char **argv) +{ + int result; + + gjb_os_init_vector(); + result = Test_interrup3_gn(); /* int install */ + if (result != 0) { + return (GJB_PRI_FAIL()); + } + + return (GJB_PRI_PASS()); +} + + + + +int g_tty_flag; +int g_tty_fd; +int b_isr_init; +int g_int_lock; +s_isr_attr ISR_REALITY[256]; +int g_lock_trigger_vector; +u64 g_pthread_delay_tick; +int is_set_sys_rate; +u32 g_sys_uleep_tick; + +void* ISR_TTY() +{ + unsigned char buf = '0'; + binding(pthread_self(), 3); + // printf("start ISR_TTY\n"); + // TODO:根据硬件条件修改串口设备 + g_tty_fd = init_com(0, 115200); + send_tty_msg(g_tty_fd, &buf, 1); + while(g_tty_flag) + { + // printf("recv ISR_TTY\n"); + rec_tty_msg(g_tty_fd, &buf, 1); + // printf("recv tty %x\n", buf); + // archIntHandle(58, LW_TRUE); + g_lock_trigger_vector = 58; + sleep(0); + } + g_lock_trigger_vector = -1; + close_com(g_tty_fd); + return NULL; +} + +void init_isr_reality(void) +{ + int i = 0, j = 0; + for (i = 0; i < 256; i++) + { + memset(ISR_REALITY[i].isr_name, 0, 256); + ISR_REALITY[i].isr_num = i; + ISR_REALITY[i].flag = 0; + for(j = 0; j < 16; j++) + { + ISR_REALITY[i].ISR_HANDLE[j]._handler = NULL; + ISR_REALITY[i].ISR_HANDLE[j].args = NULL; + } + ISR_REALITY[i].used = 0; + ISR_REALITY[i].triggerd = 0; + ISR_REALITY[i].enabled = 1; + ISR_REALITY[i].pic_thread = 0; + } + b_isr_init = 1; +} + +int int_install_handler(char *isr_name, int isr_num, int priority, _ISR_HANDLER isr_func, void * args) +{ + // int i = 0; + // int j = 0; + if( isr_num > 255 || isr_num < 0 || isr_func == NULL) + { + errno = EINVAL; + return EINVAL; + } + if ((priority <= 0 ) || (priority >= 100)) + { + errno = EINVAL; + return EINVAL; + } + if( args == NULL|| isr_name == NULL) + { + errno = EINVAL; + return EINVAL; + } + if(b_isr_init == 0) + { + init_isr_reality(); + } + ISR_REALITY[isr_num].isr_num = isr_num; + if(isr_name != NULL) + sprintf(ISR_REALITY[isr_num].isr_name, "%s", isr_name); + ISR_REALITY[isr_num].flag = priority; + // printf("int_install_handler 0 0x%x\n", isr_func); + ISR_REALITY[isr_num].ISR_HANDLE[0]._handler = isr_func; + ISR_REALITY[isr_num].ISR_HANDLE[0].args = args; + ISR_REALITY[isr_num].used = 1; + pid_t pid = getpid(); + struct sched_param param; + param.sched_priority = priority; + sched_setscheduler(pid, SCHED_RR, ¶m);//SCHED_FIFO SCHED_RR + pthread_setschedparam(pthread_self(), SCHED_RR, ¶m); + cpu_set_t mask; + CPU_ZERO(&mask); + CPU_SET(1, &mask); + CPU_SET(2, &mask); + sched_setaffinity(0, sizeof(cpu_set_t), &mask); + // printf("install ISR handler %d %d\n", isr_num, g_tty_flag); + if(isr_num == 58 || g_tty_flag == 0)//???? + { + g_tty_flag = 1; + // pthread_attr_t attr; + // struct sched_param param; + // pthread_attr_init(&attr); + // pthread_attr_setschedpolicy(&attr, SCHED_RR); + // param.sched_priority = 99; + // pthread_attr_setschedparam(&attr, ¶m); + // pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + + //pthread_create(&tty_t, NULL, ISR_TTY, NULL); + } + return 0; +} + +int int_uninstall_handler(int isr_num) +{ + int flag = 0; + if(isr_num > 255 || isr_num < 0) + return -1; + if(b_isr_init == 0) + { + init_isr_reality(); + } + int j = 0;; + { + for(j = 0; j < 16; j++) + { + if(ISR_REALITY[isr_num].ISR_HANDLE[j]._handler != 0) + flag = 1; + ISR_REALITY[isr_num].ISR_HANDLE[j]._handler = NULL; + ISR_REALITY[isr_num].ISR_HANDLE[j].args = NULL; + } + if(flag == 0) + return -1; + memset(ISR_REALITY[isr_num].isr_name, 0, 256); + ISR_REALITY[isr_num].flag = 0; + + ISR_REALITY[isr_num].used = 0; + ISR_REALITY[isr_num].triggerd = 0; + } + if(isr_num == 58 && g_tty_flag == 1) + { + g_tty_flag = 0; + } + return 0; +} + +int init_com(int com_index, int baud) +{ + int com_fd; + char dev[16]; + + sprintf(dev, "/dev/ttyS%d", com_index); + com_fd = open( dev, O_RDWR ); + if (-1 == com_fd) + { + printf("Can't Open Serial Port"); + return errno; + } + else + { + // printf("init_com ok\n"); + set_speed(com_fd,baud); + if(set_Parity(com_fd,8,1,'N') == -1) + { + printf("set_Parity error\n"); + return errno; + } + } + return com_fd; +} + +int send_tty_msg(int com_fd, unsigned char *buf, int size) +{ + return write(com_fd, buf, size); +} + +int rec_tty_msg(int com_fd,unsigned char *buf,int size) +{ + int err; + fd_set fdRead; + FD_ZERO(&fdRead); + FD_SET(com_fd, &fdRead); + + err = select(com_fd+1, &fdRead, NULL, NULL, NULL); + if(err > 0) + return read(com_fd, buf, 1); + else + return err; +} + +void archIntHandle(int vector, int bPreemptive) +{ + int j = 0; + if(b_isr_init == 0) + { + init_isr_reality(); + } + if(vector < 0 || vector > 255) + return; + // printf("%d %d %#x\n", vector, ISR_REALITY[vector].used, g_int_lock); + if(g_int_lock != UNLOCK_INT) + { + if(ISR_REALITY[vector].used) + { + if(g_lock_trigger_vector == -1) + { + g_lock_trigger_vector = vector; + + } + else + { + ISR_REALITY[g_lock_trigger_vector].triggerd = 0; + } + ISR_REALITY[vector].triggerd = 1; + } + return; + } + if(ISR_REALITY[vector].enabled == 0) + { + ISR_REALITY[vector].triggerd = 1; + return; + } + for(j = 0; j < 16; j++) + { + if(ISR_REALITY[vector].ISR_HANDLE[j]._handler != NULL) + { + // printf("trigger %d %d 0x%x\n", vector, j, ISR_REALITY[vector].ISR_HANDLE[j]._handler); + ISR_REALITY[vector].ISR_HANDLE[j]._handler(ISR_REALITY[vector].ISR_HANDLE[j].args); + } + } +} + +int set_Parity(int fd,int databits,int stopbits,int parity) +{ + struct termios options; + if ( tcgetattr( fd,&options) != 0) + { + perror("SetupSerial 1"); + return(-1); + } + options.c_cflag &= ~CSIZE; + switch (databits) /*设置数据位数*/ + { + case 7: + options.c_cflag |= CS7; + break; + case 8: + options.c_cflag |= CS8; + break; + default: + fprintf(stderr,"Unsupported data sizen"); return (-1); + } + switch (parity) + { + case 'n': + case 'N': + options.c_cflag &= ~PARENB; /* Clear parity enable */ + options.c_iflag &= ~INPCK; /* Enable parity checking */ + break; + case 'o': + case 'O': + options.c_cflag |= (PARODD | PARENB); /* 设置为奇效验*/ + options.c_iflag |= INPCK; /* Disnable parity checking */ + break; + case 'e': + case 'E': + options.c_cflag |= PARENB; /* Enable parity */ + options.c_cflag &= ~PARODD; /* 转换为偶效验*/ + options.c_iflag |= INPCK; /* Disnable parity checking */ + break; + case 'S': + case 's': /*as no parity*/ + options.c_cflag &= ~PARENB; + options.c_cflag &= ~CSTOPB;break; + default: + fprintf(stderr,"Unsupported parityn"); + return (-1); + } + /* 设置停止位*/ + switch (stopbits) + { + case 1: + options.c_cflag &= ~CSTOPB; + break; + case 2: + options.c_cflag |= CSTOPB; + break; + default: + fprintf(stderr,"Unsupported stop bitsn"); + return (-1); + } + /* Set input parity option */ + if (parity != 'n')options.c_iflag |=INPCK; + tcflush(fd,TCIFLUSH); + options.c_cc[VTIME] = 0; /* 设置超时0.2 seconds*/ + options.c_cc[VMIN] = 1; /* Update the options and do it NOW */ + //--------重要------------------------------------------------------ + options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); /*Input选择行方式输入:行方式输入是不经处理的*/ + //选择行方式输出 + options.c_oflag &= ~OPOST; /*Output*/ + + //取消软件流控制(不设置可能丢码) + options.c_iflag &=~(IXON | IXOFF | IXANY | ICRNL); + if (tcsetattr(fd,TCSANOW,&options) != 0) + { + perror("SetupSerial 3"); + return (-1); + } + return (0); +} + +void close_com(int com_fd) +{ + close(com_fd); +} + +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 set_speed(int fd, int speed) +{ + unsigned int i; + int status; + struct termios Opt; + int speed_arr[8] = {B115200, B38400, B19200, B9600, B4800, B2400, B1200, B300}; + int name_arr[8] = {115200, 38400, 19200, 9600, 4800, 2400, 1200, 300}; + tcgetattr(fd, &Opt); + for ( i= 0; i < 8; i++) + { + if (speed == name_arr[i]) + { + tcflush(fd, TCIOFLUSH); + cfsetispeed(&Opt, speed_arr[i]); + cfsetospeed(&Opt, speed_arr[i]); + status = tcsetattr(fd, TCSANOW, &Opt); + if (status != 0) + { + perror("tcsetattr fd1"); + return; + } + tcflush(fd,TCIOFLUSH); + } + } +} + +int pthread_setaffinity_np(pthread_t __th, size_t __cpusetsize, + const cpu_set_t *__cpuset) +{ + return 0; +} + +int gjb_os_get_vector(){ + // 示例中断号为0x80,可以根据实际情况修改 + int interrupt_number = 0x78; + uint32_t vector = 0; + uint64_t idt_base; + + // 获取IDT的基地址 + //__asm__ __volatile__("sidt %0" : "=m" (idt_base)); + + // 计算中断向量的地址 + uint64_t vector_address = (idt_base + (interrupt_number * 16)); + + // 读取中断向量的值 + //__asm__ __volatile__("movl %1, %0" : "=r" (vector) : "m" (*(uint32_t*)vector_address)); + + return vector; +} + +void gjb_os_init_vector(){ + init_isr_reality(); +} + +void gjb_trigger_inter (int vector) +{ + archIntHandle(vector, LW_TRUE); +} + +int int_lock() +{ + g_int_lock++; + // if(g_int_lock_thread == 0) + // { + // g_int_lock_thread = 1; + // // printf("ISR int_lock&&&&&&&&&&&&&&&&\n"); + // pthread_create(&isr_t, NULL, ISR_THREAD, NULL); + // // usleep(1000); + // } + return g_int_lock; +} + +int int_unlock(int lock) +{ + int j = 0; + if(g_int_lock == UNLOCK_INT) + return -1; + g_int_lock --; + if(g_int_lock == UNLOCK_INT) + { + if(g_lock_trigger_vector == 58 && ISR_REALITY[g_lock_trigger_vector].ISR_HANDLE[0]._handler != NULL) + { + ISR_REALITY[g_lock_trigger_vector].ISR_HANDLE[0]._handler(ISR_REALITY[g_lock_trigger_vector].ISR_HANDLE[0].args); + g_lock_trigger_vector = -1; + return 0; + } + if(g_lock_trigger_vector != -1) + { + if((ISR_REALITY[g_lock_trigger_vector].flag & SHARED_FLAG) != SHARED_FLAG) + { + if(ISR_REALITY[g_lock_trigger_vector].ISR_HANDLE[0]._handler != NULL) + { + ISR_REALITY[g_lock_trigger_vector].ISR_HANDLE[0]._handler(ISR_REALITY[g_lock_trigger_vector].ISR_HANDLE[0].args); + } + } + else + { + for(j = 0; j < 16; j++) + { + if(ISR_REALITY[g_lock_trigger_vector].ISR_HANDLE[j]._handler != NULL) + { + ISR_REALITY[g_lock_trigger_vector].ISR_HANDLE[j]._handler(ISR_REALITY[g_lock_trigger_vector].ISR_HANDLE[j].args); + } + } + } + } + // if(g_lock_trigger_vector != 58) + g_lock_trigger_vector = -1; + // pthread_join(isr_t, NULL); + } +} + +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 gjb_exclude_vector (int vector) +{ + /* + * 排除 30 ????向量??, + TODO: 这里??以???加更???, 如果没有需要排除的, 则返?? 0 即可 + */ + + if (vector == 30) { + return (1); + } + + return (0); +} + +int int_enable_pic(int vector) +{ + if(vector > 255 || vector < 0) + return -1; + // printf("int_enable_pic run in line %d\n",__LINE__); + if(ISR_REALITY[vector].enabled == 0) + { + ISR_REALITY[vector].enabled = 1; + // printf("int_enable_pic run in line %d\n",__LINE__); + pthread_join(ISR_REALITY[vector].pic_t, NULL); + } + // printf("int_enable_pic run in line %d\n",__LINE__); + usleep(10000); + return 0; +} + +void* ISR_THREAD_SELF(void *args) +{ + int j = 0; + long long int vector = (long long int)args; + + // printf("ISR_THREAD_SELF********** %d\n", vector); + while(ISR_REALITY[vector].enabled != 1) + { + sleep(0); + } + // printf("ISR enable********** %d %d\n", vector, ISR_REALITY[vector].triggerd); + if(ISR_REALITY[vector].triggerd == 1) + { + for(j = 0; j < 16; j++) + { + // printf("ISR_REALITY[vector].ISR_HANDLE[j]._handler %#x\n", ISR_REALITY[vector].ISR_HANDLE[j]._handler); + if(ISR_REALITY[vector].ISR_HANDLE[j]._handler != NULL) + { + // printf("ISR_THREAD_SELF call %d %d\n", vector, j); + ISR_REALITY[vector].ISR_HANDLE[j]._handler(ISR_REALITY[vector].ISR_HANDLE[j].args); + } + } + } + // printf("ISR int_unlock\n"); + return NULL; +} + +int int_disable_pic(int vector) +{ + if(b_isr_init == 0) + { + init_isr_reality(); + } + if(vector > 255 || vector < 0) + return -1; + ISR_REALITY[vector].enabled = 0; + if(ISR_REALITY[vector].pic_thread == 0) + { + ISR_REALITY[vector].pic_thread = 1; + pthread_create(&ISR_REALITY[vector].pic_t, NULL, ISR_THREAD_SELF,(void *)vector); + } + return 0; +} + -- Gitee From 171ed3b503cc1f228e9357f858a697af1e0237a3 Mon Sep 17 00:00:00 2001 From: lijiande Date: Fri, 20 Oct 2023 10:43:09 +0800 Subject: [PATCH 2/2] commit mutex testFile --- mutex/gjb_S0100501GN_1.c | 97 ++++++++++++++++++++++++++++++++++++++++ mutex/gjb_S0100501GN_3.c | 69 ++++++++++++++++++++++++++++ mutex/gjb_S0100502GN_1.c | 87 +++++++++++++++++++++++++++++++++++ mutex/gjb_S0100503GN_1.c | 83 ++++++++++++++++++++++++++++++++++ mutex/gjb_S0100503GN_3.c | 93 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 429 insertions(+) create mode 100644 mutex/gjb_S0100501GN_1.c create mode 100644 mutex/gjb_S0100501GN_3.c create mode 100644 mutex/gjb_S0100502GN_1.c create mode 100644 mutex/gjb_S0100503GN_1.c create mode 100644 mutex/gjb_S0100503GN_3.c diff --git a/mutex/gjb_S0100501GN_1.c b/mutex/gjb_S0100501GN_1.c new file mode 100644 index 0000000..204a393 --- /dev/null +++ b/mutex/gjb_S0100501GN_1.c @@ -0,0 +1,97 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0100501GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 互斥量创建测试, 验证正常参数, 异常参数测试 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char **argv) +{ + int rc = 0; + pthread_mutexattr_t mta; + pthread_mutex_t mutex1; + pthread_mutex_t mutex2; + + /* + * Initialize mutex attribute objects with default values + */ + if((rc = pthread_mutexattr_init(&mta)) == 0) { + printf("Initialize mutex attribute objects with default values successful.\n"); + + } else { + printf("Initialize mutex attribute objects with default values failed!, errno=%d\n",errno); + goto __errno_handle; + } + + /* + * Initialize the mutex with the default mutex attribute object + */ + if ((rc = pthread_mutex_init(&mutex1, &mta)) == 0) { + printf("Initialize the mutex with the default mutex attribute object successful. TEST PASS.\n"); + + } else { + printf("Initialize the mutex with the default mutex attribute object failed! errno=%d.TEST FAILED\n", errno); + pthread_mutexattr_destroy(&mta); + goto __errno_handle; + } + + /* + * Initialize the mutex using NULL + */ + if ((rc = pthread_mutex_init(&mutex2, NULL)) == 0) { + printf("Initialize the mutex using NULL successful. TEST PASS.\n"); + + } else { + printf("Initialize the mutex using NULL failed! errno=%d.TEST FAILED\n", errno); + pthread_mutexattr_destroy(&mta); + pthread_mutex_destroy(&mutex1); + goto __errno_handle; + } + + /* + * Destroy Mutex mutex1 + */ + if ((rc = pthread_mutex_destroy(&mutex1)) == 0) { + printf("Destroy Mutex mutex1 successful. TEST PASS.\n"); + } else { + printf("Destroy Mutex mutex1 failed! errno=%d.TEST FAILED\n",errno); + pthread_mutexattr_destroy(&mta); + pthread_mutex_destroy(&mutex2); + goto __errno_handle; + } + + /* Destroy Mutex mutex2*/ + if ((rc = pthread_mutex_destroy(&mutex2)) == 0) { + printf("Destroy Mutex mutex2 successful. TEST PASS.\n"); + } else { + printf("Destroy Mutex mutex2 failed! errno=%d.TEST FAILED\n",errno); + pthread_mutexattr_destroy(&mta); + pthread_mutex_destroy(&mutex2); + goto __errno_handle; + } + + pthread_mutexattr_destroy(&mta); + + printf("..................................................[PASS]\n"); + return 0; +__errno_handle: + printf("..................................................[FAILED]\n"); + return -1; +} diff --git a/mutex/gjb_S0100501GN_3.c b/mutex/gjb_S0100501GN_3.c new file mode 100644 index 0000000..e01f782 --- /dev/null +++ b/mutex/gjb_S0100501GN_3.c @@ -0,0 +1,69 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0100501GN_3.c +** +** 文件创建日期: 2021 年 1 月 13 日 +** +** 描 述: 互斥量创建测试, 验证正常参数, 异常参数测试 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#define PTHREAD_WAITQ_FIFO 0 +#define PTHREAD_CANCEL_SAFE 0 + +int main(int argc, char **argv) +{ + + int rc = 0; + pthread_mutex_t mutex1; + pthread_mutexattr_t mta = { + 1, + 0, + 1, + PTHREAD_PRIO_PROTECT, + PTHREAD_MUTEX_DEFAULT, + PTHREAD_WAITQ_FIFO, + PTHREAD_CANCEL_SAFE, + }; + + /* Initialization of Mutexes with Mutex Attribute Constant mta */ + if ((rc = pthread_mutex_init(&mutex1, &mta)) == 0) { + printf("Initialization of Mutexes with Mutex Attribute Constant mta successful.\n"); + + } else { + printf("Initialization of Mutexes with Mutex Attribute Constant mta failed!, errno=%d\n",errno); + pthread_mutexattr_destroy(&mta); + goto __errno_handle; + } + + /* Destroy Mutex mutex1*/ + if ((rc = pthread_mutex_destroy(&mutex1)) == 0) { + printf("Destroy Mutex mutex1 successful. TEST PASS.\n"); + } else { + printf("Destroy Mutex mutex1 failed! errno=%d.TEST FAILED\n",errno); + pthread_mutexattr_destroy(&mta); + pthread_mutex_destroy(&mutex1); + goto __errno_handle; + } + + pthread_mutexattr_destroy(&mta); + + printf("..................................................[PASS]\n"); + return 0; + +__errno_handle: + printf("..................................................[FAILED]\n"); + return -1; +} diff --git a/mutex/gjb_S0100502GN_1.c b/mutex/gjb_S0100502GN_1.c new file mode 100644 index 0000000..2436244 --- /dev/null +++ b/mutex/gjb_S0100502GN_1.c @@ -0,0 +1,87 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0100502GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 互斥量删除测试。编制测试用例代码,调用互斥量删除接口,给出合法输入;已经存在的互斥量被删除 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + int rc = 0; + pthread_mutexattr_t mta; + pthread_mutex_t mutex1; + pthread_mutex_t mutex2; + + /* Initialize mutex attribute objects with default values */ + if ((rc = pthread_mutexattr_init(&mta)) == 0) { + printf("Initialize mutex attribute objects with default values successful.\n"); + } else { + printf("Initialize mutex attribute objects with default values failed!, errno=%d\n",errno); + goto __errno_handle; + } + + /* Initialize the mutex with the default mutex attribute object*/ + if ((rc = pthread_mutex_init(&mutex1, &mta)) == 0) { + printf("Initialize the mutex with the default mutex attribute object successful. TEST PASS.\n"); + } else { + printf("Initialize the mutex with the default mutex attribute object failed! errno=%d.TEST FAILED\n",errno); + pthread_mutexattr_destroy(&mta); + goto __errno_handle; + } + + /* Initialize the mutex using NULL */ + if ((rc = pthread_mutex_init(&mutex2,NULL)) == 0) { + printf("Initialize the mutex using NULL successful. TEST PASS.\n"); + } else { + printf("Initialize the mutex using NULL failed! errno=%d.TEST FAILED\n",errno); + pthread_mutexattr_destroy(&mta); + pthread_mutex_destroy(&mutex1); + goto __errno_handle; + } + + /* Destroy Mutex mutex1*/ + if ((rc = pthread_mutex_destroy(&mutex1)) == 0) { + printf("Destroy Mutex mutex1 successful. TEST PASS.\n"); + + } else { + printf("Destroy Mutex mutex1 failed! errno=%d.TEST FAILED\n",errno); + pthread_mutexattr_destroy(&mta); + pthread_mutex_destroy(&mutex2); + goto __errno_handle; + } + + /* Destroy Mutex mutex2*/ + if ((rc = pthread_mutex_destroy(&mutex2)) == 0) { + printf("Destroy Mutex mutex2 successful. TEST PASS.\n"); + } else { + printf("Destroy Mutex mutex2 failed! errno=%d.TEST FAILED\n",errno); + pthread_mutexattr_destroy(&mta); + pthread_mutex_destroy(&mutex2); + goto __errno_handle; + } + + pthread_mutexattr_destroy(&mta); + + printf("..................................................[PASS]\n"); + return 0; + +__errno_handle: + printf("..................................................[FAILED]\n"); + return -1; +} diff --git a/mutex/gjb_S0100503GN_1.c b/mutex/gjb_S0100503GN_1.c new file mode 100644 index 0000000..5abce9b --- /dev/null +++ b/mutex/gjb_S0100503GN_1.c @@ -0,0 +1,83 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0100503GN_1.c +** +** 文件创建日期: 2021 年 1 月 12 日 +** +** 描 述: 非阻塞方式获取互斥量测试。编制测试用例代码,调用互斥量申请接口,申请模式为非阻塞模式; +** 当互斥量未被锁定时,当前任务/进程锁定互斥量, +** 并成功返回;如果互斥量不可用,那么直接返回错误. +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char **argv) +{ + int rc = 0; + pthread_mutexattr_t mta; + pthread_mutex_t mutex1; + + /* Initialize mutex attribute objects with default values */ + if ((rc = pthread_mutexattr_init(&mta)) == 0) { + printf("Initialize mutex attribute objects with default values successful.\n"); + } else { + printf("Initialize mutex attribute objects with default values failed!, errno=%d\n",errno); + goto __errno_handle; + } + + /* Initialize the mutex with the default mutex attribute object*/ + if ((rc = pthread_mutex_init(&mutex1,&mta)) == 0) { + printf("Initialize the mutex with the default mutex attribute object successful. TEST PASS.\n"); + } else { + printf("Initialize the mutex with the default mutex attribute object failed! errno=%d.TEST FAILED\n",errno); + pthread_mutexattr_destroy(&mta); + goto __errno_handle; + } + + // 以非阻塞方式获取互斥量, 如果获取失败则返回错误且不阻塞 + if ((rc = pthread_mutex_trylock(&mutex1)) == 0) { + printf("lock mutex successful. TEST PASS.\n"); + + } else { + printf("lock mutex failed! errno=%d.TEST FAILED.\n",errno); + pthread_mutex_destroy(&mutex1); + pthread_mutexattr_destroy(&mta); + goto __errno_handle; + } + + //unlock + if ((rc = pthread_mutex_unlock(&mutex1)) != 0) { + printf("unlock mutex failed. TEST failed.\n"); + } + + /* Destroy Mutex mutex1*/ + if ((rc = pthread_mutex_destroy(&mutex1)) == 0) { + printf("Destroy Mutex mutex1 successful. TEST PASS.\n"); + } else { + printf("Destroy Mutex mutex1 failed! errno=%d.TEST FAILED\n",errno); + pthread_mutexattr_destroy(&mta); + goto __errno_handle; + } + + pthread_mutexattr_destroy(&mta); + + printf("..................................................[PASS]\n"); + return 0; + +__errno_handle: + printf("..................................................[FAILED]\n"); + return -1; +} diff --git a/mutex/gjb_S0100503GN_3.c b/mutex/gjb_S0100503GN_3.c new file mode 100644 index 0000000..a529949 --- /dev/null +++ b/mutex/gjb_S0100503GN_3.c @@ -0,0 +1,93 @@ +/********************************************************************************************************* +** +** GJB 标准测试集 +** +** Copyright All Rights Reserved +** +**--------------文件信息-------------------------------------------------------------------------------- +** +** 文 件 名: gjb_S0100503GN_3.c +** +** 文件创建日期: 2021 年 1 月 13 日 +** +** 描 述: 非阻塞方式获取互斥量测试。编制测试用例代码,调用互斥量申请接口,申请模式为非阻塞模式; +** 当互斥量未被锁定时,当前任务/进程锁定互斥量, +** 并成功返回;如果互斥量不可用,那么直接返回错误 +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char **argv) +{ + int rc; + pthread_mutex_t mutex; + pthread_mutexattr_t mta; + + pthread_mutexattr_init(&mta); + + /* Set the type attribute of the mutex to PTHREAD_MUTEX_ERRORCHECK */ + if ((rc = pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK)) != 0) { + printf("Set the type attribute of the mutex to PTHREAD_MUTEX_ERRORCHECK failed!, errno=%d\n",errno); + goto __errno_handle; + } else { + printf("Set the type attribute of the mutex to PTHREAD_MUTEX_ERRORCHECK successful.\n"); + } + + if ((rc = pthread_mutex_init(&mutex, &mta)) != 0) { + printf("Initialization mutex failed!, errno=%d\n", errno); + goto __errno_handle; + } else { + printf("Initialization mutex successful.\n"); + } + + /* Locking unlocked mutexes in a non-blocking manner */ + rc = pthread_mutex_trylock(&mutex); + if (rc != 0) { + printf("Locking unlocked mutexes in a non-blocking manner failed!, errno=%d\n",errno); + pthread_mutex_destroy(&mutex); + goto __errno_handle; + + } else { + printf("Locking unlocked mutexes in a non-blocking manner successful.\n"); + } + + /* Locking locked mutexes in a non-blocking manner */ + rc = pthread_mutex_trylock(&mutex); + if (rc == 0) { + printf("Locking locked mutexes in a non-blocking manner successful.TEST FAILED!\n"); + pthread_mutex_destroy(&mutex); + goto __errno_handle; + + } else { + if (EBUSY == errno) + printf("Locking locked mutexes in a blocking manner failed!, errno=%d=EBUSY. TEST PASS!\n",errno); + else + printf("Locking locked mutexes in a blocking manner failed!, errno=%d!=EBUSY. TEST FAILED!\n",errno); + } + + if (pthread_mutex_unlock(&mutex) != 0) { + printf("Unlocking Mutex Failure, errno=%d\n",errno); + goto __errno_handle; + } + + /* Destroy Mutex */ + rc = pthread_mutex_destroy(&mutex); + if (rc != 0) { + printf("Destroy Mutex failed!, errno=%d\n",errno); + goto __errno_handle; + } + + printf("..................................................[PASS]\n"); + return 0; + +__errno_handle: + printf("..................................................[FAILED]\n"); + return -1; +} -- Gitee