[1360] | 1 | /** @file
|
---|
| 2 | *
|
---|
| 3 | * Testcase for bug #1023 autoincrement of file handles.
|
---|
| 4 | *
|
---|
| 5 | * InnoTek Systemberatung GmbH confidential
|
---|
| 6 | *
|
---|
| 7 | * Copyright (c) 2004 InnoTek Systemberatung GmbH
|
---|
| 8 | * Author: knut st. osmundsen <bird-srcspam@anduin.net>
|
---|
| 9 | *
|
---|
| 10 | * All Rights Reserved
|
---|
| 11 | *
|
---|
| 12 | */
|
---|
| 13 |
|
---|
| 14 | /*******************************************************************************
|
---|
| 15 | * Header Files *
|
---|
| 16 | *******************************************************************************/
|
---|
| 17 | #define INCL_DOS
|
---|
| 18 | #define INCL_DOSINFOSEG
|
---|
| 19 | #ifdef __IBMC__
|
---|
| 20 | #include "../src/emx/include/os2emx.h"
|
---|
| 21 | #else
|
---|
| 22 | #include <os2.h>
|
---|
| 23 | #endif
|
---|
| 24 | #include <stdio.h>
|
---|
[1362] | 25 | #include <io.h>
|
---|
| 26 | #include <fcntl.h>
|
---|
[1360] | 27 | #include <string.h>
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | int main(int argc, const char **argv)
|
---|
| 32 | {
|
---|
[1361] | 33 | int i,j;
|
---|
[1360] | 34 | LONG lFHDelta = 0;
|
---|
| 35 | ULONG cFHs = 0;
|
---|
| 36 | ULONG cFHLast;
|
---|
| 37 | unsigned msLastInc;
|
---|
[1361] | 38 | unsigned msEnd;
|
---|
| 39 | unsigned msStart;
|
---|
[1360] | 40 | PGINFOSEG pGIS = GETGINFOSEG();
|
---|
[1362] | 41 | #define MAX_FHS 10000
|
---|
| 42 | #ifdef TEST_STREAMS
|
---|
[1360] | 43 | static FILE *apFiles[MAX_FHS];
|
---|
[1362] | 44 | #else
|
---|
| 45 | static int aiFiles[MAX_FHS];
|
---|
| 46 | #endif
|
---|
[1360] | 47 |
|
---|
| 48 | DosSetRelMaxFH(&lFHDelta, &cFHs);
|
---|
| 49 | printf("cFHs=%d\n", cFHs);
|
---|
| 50 |
|
---|
| 51 | cFHLast = cFHs;
|
---|
| 52 | msLastInc = pGIS->msecs;
|
---|
| 53 | for (i = 0; i < MAX_FHS; i++)
|
---|
| 54 | {
|
---|
[1361] | 55 | msStart = pGIS->msecs;
|
---|
[1362] | 56 | #ifdef TEST_STREAMS
|
---|
[1361] | 57 | apFiles[i] = fopen(argv[argc - 1], "rb");
|
---|
[1362] | 58 | #else
|
---|
| 59 | aiFiles[i] = open(argv[argc - 1], O_BINARY | O_RDONLY);
|
---|
| 60 | #endif
|
---|
[1360] | 61 | msEnd = pGIS->msecs;
|
---|
[1362] | 62 | #ifdef TEST_STREAMS
|
---|
[1360] | 63 | if (apFiles[i] == NULL)
|
---|
[1362] | 64 | #else
|
---|
| 65 | if (aiFiles[i] < 0)
|
---|
| 66 | #endif
|
---|
[1360] | 67 | {
|
---|
| 68 | printf("error %d!\n", i + 1);
|
---|
| 69 | break;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | lFHDelta = cFHs = 0;
|
---|
| 73 | DosSetRelMaxFH(&lFHDelta, &cFHs);
|
---|
| 74 | lFHDelta = cFHs = 0;
|
---|
| 75 | DosSetRelMaxFH(&lFHDelta, &cFHs);
|
---|
| 76 | if (cFHs != cFHLast)
|
---|
| 77 | {
|
---|
[1362] | 78 | printf("Max FH change %i (fh=%d): %d -> %d (inc: %d ms since last: %d ms)\n",
|
---|
| 79 | i + 1,
|
---|
| 80 | #ifdef TEST_STREAMS
|
---|
| 81 | fileno(apFiles[i]),
|
---|
| 82 | #else
|
---|
| 83 | aiFiles[i],
|
---|
| 84 | #endif
|
---|
| 85 | cFHLast, cFHs,
|
---|
[1360] | 86 | msEnd - msStart, msStart - msLastInc);
|
---|
| 87 | msLastInc = msEnd;
|
---|
| 88 | }
|
---|
| 89 | cFHLast = cFHs;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | lFHDelta = cFHs = 0;
|
---|
| 93 | DosSetRelMaxFH(&lFHDelta, &cFHs);
|
---|
| 94 | printf("cFHs=%d\n", cFHs);
|
---|
[1361] | 95 |
|
---|
| 96 | /*
|
---|
| 97 | * Free the files.
|
---|
| 98 | */
|
---|
| 99 | msStart = pGIS->msecs;
|
---|
| 100 | for (j = 0; j < i; j++)
|
---|
[1362] | 101 | #ifdef TEST_STREAMS
|
---|
[1361] | 102 | fclose(apFiles[j]);
|
---|
[1362] | 103 | #else
|
---|
| 104 | close(aiFiles[j]);
|
---|
| 105 | #endif
|
---|
[1361] | 106 | msEnd = pGIS->msecs;
|
---|
[1362] | 107 | printf("close of %d files took %d ms\n", j, msEnd - msStart);
|
---|
[1361] | 108 |
|
---|
| 109 | /*
|
---|
| 110 | * Report the result.
|
---|
| 111 | */
|
---|
[1360] | 112 | if (i < 9900)
|
---|
| 113 | {
|
---|
| 114 | printf("1023-maxfilehandles: failed, could only open %d handles, expected > 9900\n", i);
|
---|
| 115 | return 1;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | printf("1023-maxfilehandles: succeeded opening %d handles.\n", i);
|
---|
| 119 | return 0;
|
---|
| 120 | }
|
---|