~ubuntu-branches/ubuntu/saucy/nspr/saucy-updates

« back to all changes in this revision

Viewing changes to mozilla/nsprpub/pr/tests/socket.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2009-08-10 11:34:26 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090810113426-3uv4diflrkcbdimm
Tags: 4.8-0ubuntu1
* New upstream release: 4.8 (LP: #387812)
* adjust patches to changed upstreanm codebase
  - update debian/patches/99_configure.patch
* update shlibs symbols to include new API elements
  - update debian/libnspr4-0d.symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
static int _debug_on = 0;
65
65
static int test_cancelio = 0;
66
66
 
67
 
#ifdef XP_MAC
68
 
#include "prlog.h"
69
 
#include "prsem.h"
70
 
int fprintf(FILE *stream, const char *fmt, ...)
71
 
{
72
 
    PR_LogPrint(fmt);
73
 
    return 0;
74
 
}
75
 
#define printf PR_LogPrint
76
 
extern void SetupMacPrintfLog(char *logFile);
77
 
#else
78
67
#include "obsolete/prsem.h"
79
 
#endif
80
68
 
81
69
#ifdef XP_PC
82
70
#define mode_t int
88
76
char *TEST_DIR = "prdir";
89
77
char *SMALL_FILE_NAME = "prsmallf";
90
78
char *LARGE_FILE_NAME = "prlargef";
 
79
#elif defined(SYMBIAN)
 
80
char *TEST_DIR = "c:\\data\\prsocket";
 
81
char *SMALL_FILE_NAME = "c:\\data\\prsocket\\small_file";
 
82
char *LARGE_FILE_NAME = "c:\\data\\prsocket\\large_file";
91
83
#else
92
84
char *TEST_DIR = "/tmp/prsocket_test_dir";
93
85
char *SMALL_FILE_NAME = "/tmp/prsocket_test_dir/small_file";
125
117
#define NUM_TCP_CLIENTS            5    /* for a listen queue depth of 5 */
126
118
#define NUM_UDP_CLIENTS            10
127
119
 
128
 
#ifndef XP_MAC
 
120
#ifdef SYMBIAN
 
121
#define NUM_TRANSMITFILE_CLIENTS    1
 
122
#else
129
123
#define NUM_TRANSMITFILE_CLIENTS    4
130
 
#else
131
 
/* Mac can't handle more than 2* (3Mb) allocations for large file size buffers */
132
 
#define NUM_TRANSMITFILE_CLIENTS    2
133
124
#endif
134
125
 
135
126
#define NUM_TCP_CONNECTIONS_PER_CLIENT    5
306
297
            failed_already=1;
307
298
            goto exit;
308
299
        }
 
300
        /* Shutdown only RCV will cause error on Symbian OS */
 
301
#if !defined(SYMBIAN)
309
302
        /*
310
303
         * shutdown reads, after the last read
311
304
         */
313
306
            if (PR_Shutdown(sockfd, PR_SHUTDOWN_RCV) < 0) {
314
307
                fprintf(stderr,"prsocket_test: ERROR - PR_Shutdown\n");
315
308
            }
 
309
#endif
316
310
        DPRINTF(("Serve_Client [0x%lx]: inbuf[0] = 0x%lx\n",PR_GetCurrentThread(),
317
311
            (*((int *) in_buf->data))));
318
312
        if (writen(sockfd, in_buf->data, bytes) < bytes) {
731
725
         */
732
726
        if (PR_Shutdown(sockfd, PR_SHUTDOWN_BOTH) < 0) {
733
727
            fprintf(stderr,"prsocket_test: ERROR - PR_Shutdown\n");
 
728
#if defined(SYMBIAN)
 
729
            if (EPIPE != errno)
 
730
#endif
734
731
            failed_already=1;
735
732
        }
736
733
        PR_Close(sockfd);
1089
1086
        /*
1090
1087
         * Cause every other client thread to connect udp sockets
1091
1088
         */
1092
 
#ifndef XP_MAC
1093
1089
        cparamp->udp_connect = udp_connect;
1094
 
#else
1095
 
        /* No support for UDP connects on Mac */
1096
 
        cparamp->udp_connect = 0;
1097
 
#endif
1098
1090
        if (udp_connect)
1099
1091
            udp_connect = 0;
1100
1092
        else
1182
1174
        failed_already=1;
1183
1175
        return;
1184
1176
    }
1185
 
#ifdef XP_UNIX
 
1177
#if defined(XP_UNIX) && !defined(SYMBIAN)
 
1178
    /* File transmission test can not be done because of large file's size */
1186
1179
    if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0){
1187
1180
        fprintf(stderr,
1188
1181
            "prsocket_test: TransmitFile_Client ERROR - small file header data corruption\n");
1206
1199
        failed_already=1;
1207
1200
        return;
1208
1201
    }
1209
 
#ifdef XP_UNIX
 
1202
#if defined(XP_UNIX) && !defined(SYMBIAN)
1210
1203
    if (memcmp(large_file_addr, large_buf, LARGE_FILE_SIZE) != 0) {
1211
1204
        fprintf(stderr,
1212
1205
            "prsocket_test: TransmitFile_Client ERROR - large file data corruption\n");
1229
1222
        failed_already=1;
1230
1223
        return;
1231
1224
    }
1232
 
#ifdef XP_UNIX
 
1225
#if defined(XP_UNIX) && !defined(SYMBIAN)
1233
1226
    if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0){
1234
1227
        fprintf(stderr,
1235
1228
            "SendFile 1. ERROR - small file header corruption\n");
1263
1256
        failed_already=1;
1264
1257
        return;
1265
1258
    }
1266
 
#ifdef XP_UNIX
 
1259
#if defined(XP_UNIX) && !defined(SYMBIAN)
1267
1260
    if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0){
1268
1261
        fprintf(stderr,
1269
1262
            "SendFile 2. ERROR - large file header corruption\n");
1296
1289
        failed_already=1;
1297
1290
        return;
1298
1291
    }
1299
 
#ifdef XP_UNIX
 
1292
#if defined(XP_UNIX) && !defined(SYMBIAN)
1300
1293
    if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0){
1301
1294
        fprintf(stderr,
1302
1295
            "SendFile 3. ERROR - small file header corruption\n");
1321
1314
        failed_already=1;
1322
1315
        return;
1323
1316
    }
1324
 
#ifdef XP_UNIX
 
1317
#if defined(XP_UNIX) && !defined(SYMBIAN)
1325
1318
    if (memcmp((char *) small_file_addr + SMALL_FILE_OFFSET_2, small_buf,
1326
1319
                                                                        SMALL_FILE_LEN_2) != 0) {
1327
1320
        fprintf(stderr,
1347
1340
        failed_already=1;
1348
1341
        return;
1349
1342
    }
1350
 
#ifdef XP_UNIX
 
1343
#if defined(XP_UNIX) && !defined(SYMBIAN)
1351
1344
    if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0){
1352
1345
        fprintf(stderr,
1353
1346
            "SendFile 5. ERROR - large file header corruption\n");
1373
1366
        failed_already=1;
1374
1367
        return;
1375
1368
    }
1376
 
#ifdef XP_UNIX
 
1369
#if defined(XP_UNIX) && !defined(SYMBIAN)
1377
1370
    if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0){
1378
1371
        fprintf(stderr,
1379
1372
            "SendFile 6. ERROR - small file header corruption\n");
1411
1404
        failed_already=1;
1412
1405
        return;
1413
1406
    }
1414
 
#ifdef XP_UNIX
 
1407
#if defined(XP_UNIX) && !defined(SYMBIAN)
1415
1408
    if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0){
1416
1409
        fprintf(stderr,
1417
1410
            "SendFile 7. ERROR - large file header corruption\n");
1439
1432
        failed_already=1;
1440
1433
        return;
1441
1434
    }
1442
 
#ifdef XP_UNIX
 
1435
#if defined(XP_UNIX) && !defined(SYMBIAN)
1443
1436
    if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0){
1444
1437
        fprintf(stderr,
1445
1438
            "SendFile 2. ERROR - large file header corruption\n");
2028
2021
        }
2029
2022
        count += bytes;
2030
2023
    } while (count < LARGE_FILE_SIZE);
2031
 
#ifdef XP_UNIX
 
2024
#if defined(XP_UNIX) && !defined(SYMBIAN)
2032
2025
    /*
2033
2026
     * map the large file; used in checking for data corruption
2034
2027
     */
2161
2154
    if (buf) {
2162
2155
        PR_DELETE(buf);
2163
2156
    }
2164
 
#ifdef XP_UNIX
 
2157
#if defined(XP_UNIX) && !defined(SYMBIAN)
2165
2158
    munmap((char*)small_file_addr, SMALL_FILE_SIZE);
2166
2159
    munmap((char*)large_file_addr, LARGE_FILE_SIZE);
2167
2160
#endif
2197
2190
 * Test Socket NSPR APIs
2198
2191
 */
2199
2192
 
2200
 
int
2201
 
main(int argc, char **argv)
 
2193
int main(int argc, char **argv)
2202
2194
{
2203
2195
    /*
2204
2196
     * -d           debug mode
2223
2215
    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
2224
2216
    PR_STDIO_INIT();
2225
2217
 
2226
 
#ifdef XP_MAC
2227
 
    SetupMacPrintfLog("socket.log");
2228
 
#endif
2229
2218
    PR_SetConcurrency(4);
2230
2219
 
2231
2220
    emuSendFileIdentity = PR_GetUniqueIdentity("Emulated SendFile");
2275
2264
    } else
2276
2265
        printf("TCP_Socket_Client_Server_Test Passed\n");
2277
2266
        test_cancelio = 0;
 
2267
        
 
2268
#if defined(SYMBIAN) && !defined(__WINSCW__)
 
2269
        /* UDP tests only run on Symbian devices but not emulator */
2278
2270
    /*
2279
2271
     * run client-server test with UDP, IPv4/IPv4
2280
2272
     */
2319
2311
        goto done;
2320
2312
    } else
2321
2313
        printf("UDP_Socket_Client_Server_Test Passed\n");
 
2314
#endif
 
2315
    
2322
2316
    /*
2323
2317
     * Misc socket tests - including transmitfile, etc.
2324
2318
     */
2325
2319
 
2326
 
#if !defined(WIN16)
 
2320
    /* File transmission test can not be done in Symbian OS because of 
 
2321
     * large file's size and the incomplete mmap() implementation. */
 
2322
#if !defined(WIN16) && !defined(SYMBIAN)
2327
2323
    /*
2328
2324
** The 'transmit file' test does not run because
2329
2325
** transmit file is not implemented in NSPR yet.