• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  * conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  * of conditions and the following disclaimer in the documentation and/or other materials
12  * provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  * to endorse or promote products derived from this software without specific prior written
16  * permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef IT_POSIX_QUEUE_H
32 #define IT_POSIX_QUEUE_H
33 #undef  _XOPEN_SOURCE
34 #define _XOPEN_SOURCE 600
35 
36 #include <stdlib.h>
37 #include <mqueue.h>
38 #include <fcntl.h>
39 #include <errno.h>
40 #include <limits.h>
41 #include <sched.h>
42 #include <signal.h>
43 #include <osTest.h>
44 #include "pthread.h"
45 #include "unistd.h"
46 
47 #define MAXMSG5 5
48 #define MSGLEN 10
49 #define MAXMSG 10
50 
51 #define MQUEUE_SEND_STRING_TEST "0123456789"
52 #define MQUEUE_SHORT_ARRAY_LENGTH 10 // 10: strlen(MQUEUE_SEND_STRING_TEST)
53 #define MQUEUE_STANDARD_NAME_LENGTH 50
54 
55 #define MQUEUE_PTHREAD_PRIORITY_TEST1 3
56 #define MQUEUE_PTHREAD_PRIORITY_TEST2 4
57 #define MQUEUE_PATH_MAX_TEST PATH_MAX
58 #define MQUEUE_NAME_MAX_TEST NAME_MAX
59 #define MQUEUE_PTHREAD_NUM_TEST 5
60 #define MQUEUE_PRIORITY_TEST 0
61 #define MQUEUE_TIMEOUT_TEST 7
62 #define MQUEUE_PRIORITY_NUM_TEST 3
63 #define MQ_MAX_MSG_NUM 16
64 #define MQ_MAX_MSG_LEN 64
65 #undef  HWI_NUM_TEST
66 #define HWI_NUM_TEST 1
67 #undef  HWI_NUM_TEST1
68 #define HWI_NUM_TEST1 2
69 
70 #if (LOSCFG_LIBC_NEWLIB == 1)
71 #define MQ_PRIO_MAX 1
72 #endif
73 
74 #undef  LOSCFG_BASE_IPC_QUEUE_CONFIG
75 #define LOSCFG_BASE_IPC_QUEUE_CONFIG 1024
76 #define LOS_AtomicInc(a) (++*(a))
77 #define MqueueTaskDelay(tick) (usleep((tick) * 10000))
78 
79 #ifdef __LP64__
80 #define PER_ADDED_VALUE 8
81 #else
82 #define PER_ADDED_VALUE 4
83 #endif
84 
85 #define ICUNIT_GOTO_WITHIN_EQUAL(param, value1, value2, retcode, label) \
86     do {                                                                \
87         if ((param) < (value1) || (param) > (value2)) {                 \
88             ICunitSaveErr(__LINE__, (iiUINT32)(retcode));               \
89             goto label;                                                 \
90         }                                                               \
91     } while (0)
92 
93 typedef UINT32 TSK_HANDLE_T;
94 typedef UINT32 SEM_HANDLE_T ;
95 
96 extern SEM_HANDLE_T g_mqueueSem;
97 
98 extern TSK_HANDLE_T g_mqueueTaskPID;
99 extern CHAR g_gqname[MQUEUE_STANDARD_NAME_LENGTH];
100 extern CHAR g_mqueueName[LOSCFG_BASE_IPC_QUEUE_CONFIG + 1][MQUEUE_STANDARD_NAME_LENGTH];
101 extern mqd_t g_mqueueId[LOSCFG_BASE_IPC_QUEUE_CONFIG + 1];
102 
103 extern CHAR *g_mqueueMsessage[MQUEUE_SHORT_ARRAY_LENGTH];
104 extern mqd_t g_messageQId;
105 extern mqd_t g_gqueue;
106 
107 extern VOID ItSuitePosixMqueue(VOID);
108 extern UINT32 PosixPthreadInit(pthread_attr_t *attr, int pri);
109 extern UINT32 PosixPthreadDestroy(pthread_attr_t *attr, pthread_t thread);
110 extern VOID TestAssertWaitDelay(UINT32 *testCount, UINT32 flag);
111 extern void TestExtraTaskDelay(UINT32 tick);
112 
113 VOID ItPosixQueue001(VOID);
114 VOID ItPosixQueue002(VOID);
115 VOID ItPosixQueue003(VOID);
116 VOID ItPosixQueue004(VOID);
117 VOID ItPosixQueue005(VOID);
118 VOID ItPosixQueue006(VOID);
119 VOID ItPosixQueue007(VOID);
120 VOID ItPosixQueue008(VOID);
121 VOID ItPosixQueue009(VOID);
122 VOID ItPosixQueue010(VOID);
123 VOID ItPosixQueue011(VOID);
124 VOID ItPosixQueue012(VOID);
125 VOID ItPosixQueue013(VOID);
126 VOID ItPosixQueue014(VOID);
127 VOID ItPosixQueue015(VOID);
128 VOID ItPosixQueue016(VOID);
129 VOID ItPosixQueue017(VOID);
130 VOID ItPosixQueue018(VOID);
131 VOID ItPosixQueue019(VOID);
132 VOID ItPosixQueue020(VOID);
133 VOID ItPosixQueue021(VOID);
134 VOID ItPosixQueue022(VOID);
135 VOID ItPosixQueue023(VOID);
136 VOID ItPosixQueue024(VOID);
137 VOID ItPosixQueue025(VOID);
138 VOID ItPosixQueue026(VOID);
139 VOID ItPosixQueue027(VOID);
140 VOID ItPosixQueue028(VOID);
141 VOID ItPosixQueue029(VOID);
142 VOID ItPosixQueue030(VOID);
143 VOID ItPosixQueue031(VOID);
144 VOID ItPosixQueue032(VOID);
145 VOID ItPosixQueue033(VOID);
146 VOID ItPosixQueue034(VOID);
147 VOID ItPosixQueue035(VOID);
148 VOID ItPosixQueue036(VOID);
149 VOID ItPosixQueue037(VOID);
150 VOID ItPosixQueue038(VOID);
151 VOID ItPosixQueue039(VOID);
152 VOID ItPosixQueue040(VOID);
153 VOID ItPosixQueue041(VOID);
154 VOID ItPosixQueue042(VOID);
155 VOID ItPosixQueue043(VOID);
156 VOID ItPosixQueue044(VOID);
157 VOID ItPosixQueue045(VOID);
158 VOID ItPosixQueue046(VOID);
159 VOID ItPosixQueue047(VOID);
160 VOID ItPosixQueue048(VOID);
161 VOID ItPosixQueue049(VOID);
162 VOID ItPosixQueue050(VOID);
163 VOID ItPosixQueue051(VOID);
164 VOID ItPosixQueue052(VOID);
165 #endif
166