| [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 <[email protected]>
|
|---|
| 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>
|
|---|
| 25 | #include <string.h>
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 | int main(int argc, const char **argv)
|
|---|
| 30 | {
|
|---|
| 31 | int i;
|
|---|
| 32 | LONG lFHDelta = 0;
|
|---|
| 33 | ULONG cFHs = 0;
|
|---|
| 34 | ULONG cFHLast;
|
|---|
| 35 | unsigned msLastInc;
|
|---|
| 36 | PGINFOSEG pGIS = GETGINFOSEG();
|
|---|
| 37 | #define MAX_FHS 32768
|
|---|
| 38 | static FILE *apFiles[MAX_FHS];
|
|---|
| 39 |
|
|---|
| 40 | DosSetRelMaxFH(&lFHDelta, &cFHs);
|
|---|
| 41 | printf("cFHs=%d\n", cFHs);
|
|---|
| 42 |
|
|---|
| 43 | cFHLast = cFHs;
|
|---|
| 44 | msLastInc = pGIS->msecs;
|
|---|
| 45 | for (i = 0; i < MAX_FHS; i++)
|
|---|
| 46 | {
|
|---|
| 47 | unsigned msEnd;
|
|---|
| 48 | unsigned msStart = pGIS->msecs;
|
|---|
| 49 | apFiles[i] = fopen("\\dev\\nul", "rb");
|
|---|
| 50 | msEnd = pGIS->msecs;
|
|---|
| 51 | if (apFiles[i] == NULL)
|
|---|
| 52 | {
|
|---|
| 53 | printf("error %d!\n", i + 1);
|
|---|
| 54 | break;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | lFHDelta = cFHs = 0;
|
|---|
| 58 | DosSetRelMaxFH(&lFHDelta, &cFHs);
|
|---|
| 59 | lFHDelta = cFHs = 0;
|
|---|
| 60 | DosSetRelMaxFH(&lFHDelta, &cFHs);
|
|---|
| 61 | if (cFHs != cFHLast)
|
|---|
| 62 | {
|
|---|
| 63 | printf("Max FH change %i: %d -> %d (inc: %d ms since last: %d ms)\n", i + 1, cFHLast, cFHs,
|
|---|
| 64 | msEnd - msStart, msStart - msLastInc);
|
|---|
| 65 | msLastInc = msEnd;
|
|---|
| 66 | }
|
|---|
| 67 | cFHLast = cFHs;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | lFHDelta = cFHs = 0;
|
|---|
| 71 | DosSetRelMaxFH(&lFHDelta, &cFHs);
|
|---|
| 72 | printf("cFHs=%d\n", cFHs);
|
|---|
| 73 | if (i < 9900)
|
|---|
| 74 | {
|
|---|
| 75 | printf("1023-maxfilehandles: failed, could only open %d handles, expected > 9900\n", i);
|
|---|
| 76 | return 1;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | printf("1023-maxfilehandles: succeeded opening %d handles.\n", i);
|
|---|
| 80 | return 0;
|
|---|
| 81 | }
|
|---|