[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;
|
---|
[1363] | 40 | unsigned msTotal = 0;
|
---|
| 41 | unsigned cFiles = 0;
|
---|
| 42 | unsigned cIncrements = 0;
|
---|
| 43 | int fStreams;
|
---|
[1360] | 44 | PGINFOSEG pGIS = GETGINFOSEG();
|
---|
[1362] | 45 | #define MAX_FHS 10000
|
---|
[1360] | 46 | static FILE *apFiles[MAX_FHS];
|
---|
[1362] | 47 | static int aiFiles[MAX_FHS];
|
---|
[1360] | 48 |
|
---|
| 49 | DosSetRelMaxFH(&lFHDelta, &cFHs);
|
---|
| 50 | printf("cFHs=%d\n", cFHs);
|
---|
| 51 |
|
---|
[1363] | 52 | /* check for args */
|
---|
| 53 | fStreams = argc >= 2;
|
---|
| 54 |
|
---|
[1360] | 55 | cFHLast = cFHs;
|
---|
| 56 | msLastInc = pGIS->msecs;
|
---|
| 57 | for (i = 0; i < MAX_FHS; i++)
|
---|
| 58 | {
|
---|
[1361] | 59 | msStart = pGIS->msecs;
|
---|
[1363] | 60 | if (fStreams)
|
---|
| 61 | apFiles[i] = fopen(argv[argc - 1], "rb");
|
---|
| 62 | else
|
---|
| 63 | aiFiles[i] = open(argv[argc - 1], O_BINARY | O_RDONLY);
|
---|
[1360] | 64 | msEnd = pGIS->msecs;
|
---|
[1363] | 65 | if (fStreams ? apFiles[i] == NULL : aiFiles[i] < 0)
|
---|
[1360] | 66 | {
|
---|
| 67 | printf("error %d!\n", i + 1);
|
---|
| 68 | break;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | lFHDelta = cFHs = 0;
|
---|
| 72 | DosSetRelMaxFH(&lFHDelta, &cFHs);
|
---|
| 73 | lFHDelta = cFHs = 0;
|
---|
| 74 | DosSetRelMaxFH(&lFHDelta, &cFHs);
|
---|
| 75 | if (cFHs != cFHLast)
|
---|
| 76 | {
|
---|
[1362] | 77 | printf("Max FH change %i (fh=%d): %d -> %d (inc: %d ms since last: %d ms)\n",
|
---|
[1363] | 78 | i + 1, fStreams ? fileno(apFiles[i]) : aiFiles[i],
|
---|
| 79 | cFHLast, cFHs, msEnd - msStart, msStart - msLastInc);
|
---|
| 80 | /* stats */
|
---|
| 81 | cIncrements++;
|
---|
| 82 | msTotal += msEnd - msLastInc;
|
---|
| 83 | msEnd = msLastInc = pGIS->msecs;
|
---|
[1360] | 84 | }
|
---|
| 85 | cFHLast = cFHs;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[1363] | 88 | msTotal += msEnd - msLastInc;
|
---|
| 89 | cFiles = i;
|
---|
| 90 |
|
---|
[1360] | 91 | lFHDelta = cFHs = 0;
|
---|
| 92 | DosSetRelMaxFH(&lFHDelta, &cFHs);
|
---|
| 93 | printf("cFHs=%d\n", cFHs);
|
---|
[1363] | 94 | printf("msTotal=%d cIncrements=%d cFiles=%d i.e. %d handles per second\n",
|
---|
| 95 | msTotal, cIncrements, cFiles, cFiles * 1000 / msTotal);
|
---|
[1361] | 96 |
|
---|
| 97 | /*
|
---|
| 98 | * Free the files.
|
---|
| 99 | */
|
---|
| 100 | msStart = pGIS->msecs;
|
---|
[1363] | 101 | if (fStreams)
|
---|
| 102 | {
|
---|
| 103 | for (j = 0; j < i; j++)
|
---|
| 104 | fclose(apFiles[j]);
|
---|
| 105 | }
|
---|
| 106 | else
|
---|
| 107 | {
|
---|
| 108 | for (j = 0; j < i; j++)
|
---|
| 109 | close(aiFiles[j]);
|
---|
| 110 | }
|
---|
[1361] | 111 | msEnd = pGIS->msecs;
|
---|
[1362] | 112 | printf("close of %d files took %d ms\n", j, msEnd - msStart);
|
---|
[1361] | 113 |
|
---|
| 114 | /*
|
---|
| 115 | * Report the result.
|
---|
| 116 | */
|
---|
[1360] | 117 | if (i < 9900)
|
---|
| 118 | {
|
---|
| 119 | printf("1023-maxfilehandles: failed, could only open %d handles, expected > 9900\n", i);
|
---|
| 120 | return 1;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | printf("1023-maxfilehandles: succeeded opening %d handles.\n", i);
|
---|
| 124 | return 0;
|
---|
| 125 | }
|
---|