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