~ubuntu-branches/debian/stretch/ion/stretch

« back to all changes in this revision

Viewing changes to ltp/test/ltpdriver.c

  • Committer: Package Import Robot
  • Author(s): Leo Iannacone
  • Date: 2012-02-01 09:46:31 UTC
  • Revision ID: package-import@ubuntu.com-20120201094631-qpfwehc1b7ftkjgx
Tags: upstream-2.5.3~dfsg1
ImportĀ upstreamĀ versionĀ 2.5.3~dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        ltpdriver.c:    sender for LTP benchmark test.
 
3
                                                                        */
 
4
/*                                                                      */
 
5
/*      Copyright (c) 2007, California Institute of Technology.         */
 
6
/*      All rights reserved.                                            */
 
7
/*      Author: Scott Burleigh, Jet Propulsion Laboratory               */
 
8
/*                                                                      */
 
9
 
 
10
#include "platform.h"
 
11
#include "zco.h"
 
12
#include "ltpP.h"
 
13
 
 
14
#define DEFAULT_ADU_LENGTH      (60000)
 
15
 
 
16
static int      run_ltpdriver(unsigned long destEngineId, int clientId,
 
17
                        int cyclesRemaining, int greenLength, int sduLength)
 
18
{
 
19
        static char     buffer[DEFAULT_ADU_LENGTH] = "test...";
 
20
        Sdr             sdr;
 
21
        int             running = 1;
 
22
        int             aduFile;
 
23
        int             randomSduLength = 0;
 
24
        int             bytesRemaining;
 
25
        int             bytesToWrite;
 
26
        Object          fileRef;
 
27
        Object          zcoRef;
 
28
        LtpSessionId    sessionId;
 
29
        int             bytesSent = 0;
 
30
        time_t          startTime;
 
31
        int             redLength;
 
32
        time_t          endTime;
 
33
        long            interval;
 
34
        int             cycles = cyclesRemaining;
 
35
 
 
36
        if (destEngineId == 0 || clientId < 1
 
37
        || cyclesRemaining < 1 || greenLength < 0 || sduLength < 1)
 
38
        {
 
39
                PUTS("Usage: ltpdriver <destination engine ID> <client ID> \
 
40
<number of cycles> <'green' length> [<payload size>]");
 
41
                PUTS("  Payload size defaults to 60000 bytes.");
 
42
                PUTS("");
 
43
                PUTS("  To use payload sizes chosen at random from the");
 
44
                PUTS("  range 1024 to 62464, in multiples of 1024,");
 
45
                PUTS("  specify payload size 1.");
 
46
                PUTS("");
 
47
                PUTS("  Expected destination (receiving) application is");
 
48
                PUTS("  ltpcounter.");
 
49
                return 0;
 
50
        }
 
51
 
 
52
        if (ltp_attach() < 0)
 
53
        {
 
54
                putErrmsg("ltpdriver can't initialize LTP.", NULL);
 
55
                return 1;
 
56
        }
 
57
 
 
58
        sdr = getIonsdr();
 
59
        if (sduLength == 1)
 
60
        {
 
61
                randomSduLength = 1;
 
62
        }
 
63
 
 
64
        aduFile = iopen("ltpdriverSduFile", O_WRONLY | O_CREAT, 0666);
 
65
        if (aduFile < 0)
 
66
        {
 
67
                putSysErrmsg("Can't create ADU file", NULL);
 
68
                return 0;
 
69
        }
 
70
 
 
71
        if (randomSduLength)
 
72
        {
 
73
                bytesRemaining = 65536;
 
74
        }
 
75
        else
 
76
        {
 
77
                bytesRemaining = sduLength;
 
78
        }
 
79
 
 
80
        while (bytesRemaining > 0)
 
81
        {
 
82
                if (bytesRemaining < DEFAULT_ADU_LENGTH)
 
83
                {
 
84
                        bytesToWrite = bytesRemaining;
 
85
                }
 
86
                else
 
87
                {
 
88
                        bytesToWrite = DEFAULT_ADU_LENGTH;
 
89
                }
 
90
 
 
91
                if (write(aduFile, buffer, bytesToWrite) < 0)
 
92
                {
 
93
                        close(aduFile);
 
94
                        putSysErrmsg("Error writing to ADU file", NULL);
 
95
                        return 0;
 
96
                }
 
97
 
 
98
                bytesRemaining -= bytesToWrite;
 
99
        }
 
100
 
 
101
//sdr_start_trace(sdr, 10000000, NULL);
 
102
        close(aduFile);
 
103
        sdr_begin_xn(sdr);
 
104
        fileRef = zco_create_file_ref(sdr, "ltpdriverSduFile", NULL);
 
105
        if (sdr_end_xn(sdr) < 0 || fileRef == 0)
 
106
        {
 
107
                putErrmsg("ltpdriver can't create file ref.", NULL);
 
108
                return 0;
 
109
        }
 
110
        
 
111
        startTime = time(NULL);
 
112
        while (running && cyclesRemaining > 0)
 
113
        {
 
114
                if (randomSduLength)
 
115
                {
 
116
                        sduLength = ((rand() % 60) + 1) * 1024;
 
117
                }
 
118
 
 
119
                redLength = sduLength - greenLength;
 
120
                if (redLength < 0)
 
121
                {
 
122
                        redLength = 0;
 
123
                }
 
124
 
 
125
                sdr_begin_xn(sdr);
 
126
                zcoRef = zco_create(sdr, ZcoFileSource, fileRef, 0,
 
127
                                sduLength);
 
128
                if (sdr_end_xn(sdr) < 0 || zcoRef == 0)
 
129
                {
 
130
                        putErrmsg("ltpdriver can't create ZCO.", NULL);
 
131
                        return 0;
 
132
                }
 
133
 
 
134
                switch (ltp_send(destEngineId, clientId, zcoRef, redLength,
 
135
                                &sessionId))
 
136
                {
 
137
                case 0:
 
138
                        putErrmsg("ltpdriver can't send SDU.",
 
139
                                        itoa(sduLength));
 
140
                        break;          /*      Out of switch.          */
 
141
 
 
142
                case -1:
 
143
                        putErrmsg("ltp_send failed.", NULL);
 
144
                        running = 0;
 
145
                        continue;
 
146
                }
 
147
 
 
148
                bytesSent += sduLength;
 
149
//putchar('^');
 
150
//fflush(stdout);
 
151
                cyclesRemaining--;
 
152
                if ((cyclesRemaining % 100) == 0)
 
153
                {
 
154
//sdr_clear_trace(sdr);
 
155
//sdr_print_trace(sdr, 0);
 
156
                        PUTS(itoa(cyclesRemaining));
 
157
                }
 
158
        }
 
159
 
 
160
        endTime = time(NULL);
 
161
        writeErrmsgMemos();
 
162
        interval = endTime - startTime;
 
163
        PUTMEMO("Time (seconds)", itoa(interval));
 
164
        if (randomSduLength)
 
165
        {
 
166
                PUTS("Data size random.");
 
167
        }
 
168
        else
 
169
        {
 
170
                PUTMEMO("Data size (bytes)", itoa(sduLength));
 
171
        }
 
172
 
 
173
        PUTMEMO("Cycles", itoa(cycles));
 
174
        PUTMEMO("Bytes", itoa(bytesSent));
 
175
        if (interval <= 0)
 
176
        {
 
177
                PUTS("Interval is too short to measure rate.");
 
178
        }
 
179
        else
 
180
        {
 
181
                PUTMEMO("Throughput (bytes per second)",
 
182
                                itoa(bytesSent / interval));
 
183
        }
 
184
 
 
185
//sdr_stop_trace(sdr);
 
186
        sdr_begin_xn(sdr);
 
187
        zco_destroy_file_ref(sdr, fileRef);
 
188
        if (sdr_end_xn(sdr) < 0)
 
189
        {
 
190
                putErrmsg("ltpdriver can't destroy file reference.", NULL);
 
191
        }
 
192
 
 
193
        ltp_detach();
 
194
        return 0;
 
195
}
 
196
 
 
197
#if defined (VXWORKS) || defined (RTEMS)
 
198
int     ltpdriver(int a1, int a2, int a3, int a4, int a5,
 
199
                int a6, int a7, int a8, int a9, int a10)
 
200
{
 
201
        unsigned long   destEngineId = (unsigned long) a1;
 
202
        int             clientId = a2;
 
203
        int             cycles = a3;
 
204
        int             greenLen = a4;
 
205
        int             aduLen = (a5 == 0 ? DEFAULT_ADU_LENGTH : a5);
 
206
#else
 
207
int     main(int argc, char **argv)
 
208
{
 
209
        unsigned long   destEngineId = 0;
 
210
        int             clientId = 0;
 
211
        int             cycles = 0;
 
212
        int             greenLen = 0;
 
213
        int             aduLen = DEFAULT_ADU_LENGTH;
 
214
 
 
215
        if (argc > 6) argc = 6;
 
216
        switch (argc)
 
217
        {
 
218
        case 6:
 
219
                aduLen = strtol(argv[5], NULL, 0);
 
220
 
 
221
        case 5:
 
222
                greenLen = strtol(argv[4], NULL, 0);
 
223
 
 
224
        case 4:
 
225
                cycles = strtol(argv[3], NULL, 0);
 
226
 
 
227
        case 3:
 
228
                clientId = strtol(argv[2], NULL, 0);
 
229
 
 
230
        case 2:
 
231
                destEngineId = strtoul(argv[1], NULL, 0);
 
232
 
 
233
        default:
 
234
                break;
 
235
        }
 
236
#endif
 
237
        return run_ltpdriver(destEngineId, clientId, cycles, greenLen, aduLen);
 
238
}