testParallel.c
4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*=============================================================
* testParallel.c
* Test concurrent access of DD_Server
* May 2015, V.1.0, Renard
*=============================================================*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <DD.h>
#include <time.h>
#include <string.h>
#include <sys/time.h>
//Structrure used to define a request
typedef struct {
char ViName[100];
char StartTime[17];
char TimeInt[17];
char TimeName[20];
char ParName[20];
} RequestData;
//Number of requests to run
#define NB_REQUESTS 60
//Array of all requests data
RequestData requestDataList[NB_REQUESTS];
/*-------------------------*/
#define IMF_VI "ace:imf:all\0"
#define IMF_PAR "IMF\0"
#define IMF_TIME "Time\0"
#define IMF_START "2008000000000000\0"
#define IMF_TI "0000030000000000\0"
#define DST_VI "ground:based:dst\0"
#define DST_PAR "DST\0"
#define DST_TIME "Time\0"
#define DST_START "2008000000000000\0"
#define DST_TI "0000060000000000\0"
#define MESMAG_VI "mes:mag:orb\0"
#define MESMAG_PAR "B_MSO\0"
#define MESMAG_TIME "Time\0"
#define MESMAG_START "2012000000000000\0"
#define MESMAG_TI "0000004000000000\0"
/*-------------------------*/
/*
* Init requests data
*/
void initRequestDataList()
{
memset(&requestDataList, 0, NB_REQUESTS*sizeof(RequestData));
int i;
for (i = 0; i < NB_REQUESTS; ++i)
{
if (i%3 == 0)
{
strcpy(requestDataList[i].ViName,MESMAG_VI);
strcpy(requestDataList[i].StartTime,MESMAG_START);
strcpy(requestDataList[i].TimeInt,MESMAG_TI);
strcpy(requestDataList[i].TimeName,MESMAG_TIME);
strcpy(requestDataList[i].ParName,MESMAG_PAR);
}
else if (i%2 == 0)
{
strcpy(requestDataList[i].ViName,DST_VI);
strcpy(requestDataList[i].StartTime,DST_START);
strcpy(requestDataList[i].TimeInt,DST_TI);
strcpy(requestDataList[i].TimeName,DST_TIME);
strcpy(requestDataList[i].ParName,DST_PAR);
}
else
{
strcpy(requestDataList[i].ViName,IMF_VI);
strcpy(requestDataList[i].StartTime,IMF_START);
strcpy(requestDataList[i].TimeInt,IMF_TI);
strcpy(requestDataList[i].TimeName,IMF_TIME);
strcpy(requestDataList[i].ParName,IMF_PAR);
}
}
}
/*
* Run a request
*/
int runRequest(char* ViName, char* StartTime, char* TimeInt, int NbPar, char** ParNames)
{
int ID, error;
double RealTime;
DD_data_t *data;
ID = DD_SetVariable(ViName);
if(ID < 0)
{
error = DD_Close(99);
return 0;
}
error = DD_SetTimeInfo(ID, StartTime, &RealTime);
if(error < 0)
{
error = DD_Close(ID);
return 0;
}
do
{
error = DD_GetMultiData(ID, NbPar, ParNames, TimeInt, &data, 1);
if(error < 0)
{
error = DD_Close(ID);
return 0;
}
if(error == MOREDELAY)
{
error = MOREDATA;
}
}
while(error == MOREDATA);
error = DD_Close(ID);
return 1;
}
/*
* Main
*/
int main()
{
initRequestDataList();
pid_t pid;
int crtRequest = 0;
do {
pid = fork();
if (pid == 0)
{
char *ParNames[2] = {(char *)requestDataList[crtRequest].TimeName, (char *)requestDataList[crtRequest].ParName};
printf("Run Request %s %s %s %s\n",requestDataList[crtRequest].ViName,requestDataList[crtRequest].ParName,requestDataList[crtRequest].StartTime,requestDataList[crtRequest].TimeInt);
if (!runRequest(requestDataList[crtRequest].ViName, requestDataList[crtRequest].StartTime, requestDataList[crtRequest].TimeInt, 2, ParNames))
printf("Error detected %s %s %s %s\n",requestDataList[crtRequest].ViName,requestDataList[crtRequest].ParName,requestDataList[crtRequest].StartTime,requestDataList[crtRequest].TimeInt);
else
printf("OK %s %s %s %s\n",requestDataList[crtRequest].ViName,requestDataList[crtRequest].ParName,requestDataList[crtRequest].StartTime,requestDataList[crtRequest].TimeInt);
}
else
{
++crtRequest;
if (crtRequest == NB_REQUESTS)
{
wait(0);
}
}
} while ((pid != 0) && (crtRequest < NB_REQUESTS));
return 1;
}