source: trunk/testcase/1023-maxfilehandles.c@ 1362

Last change on this file since 1362 was 1362, checked in by bird, 21 years ago

...

  • Property cvs2svn:cvs-rev set to 1.3
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
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>
25#include <io.h>
26#include <fcntl.h>
27#include <string.h>
28
29
30
31int main(int argc, const char **argv)
32{
33 int i,j;
34 LONG lFHDelta = 0;
35 ULONG cFHs = 0;
36 ULONG cFHLast;
37 unsigned msLastInc;
38 unsigned msEnd;
39 unsigned msStart;
40 PGINFOSEG pGIS = GETGINFOSEG();
41#define MAX_FHS 10000
42#ifdef TEST_STREAMS
43 static FILE *apFiles[MAX_FHS];
44#else
45 static int aiFiles[MAX_FHS];
46#endif
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 {
55 msStart = pGIS->msecs;
56#ifdef TEST_STREAMS
57 apFiles[i] = fopen(argv[argc - 1], "rb");
58#else
59 aiFiles[i] = open(argv[argc - 1], O_BINARY | O_RDONLY);
60#endif
61 msEnd = pGIS->msecs;
62#ifdef TEST_STREAMS
63 if (apFiles[i] == NULL)
64#else
65 if (aiFiles[i] < 0)
66#endif
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 {
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,
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);
95
96 /*
97 * Free the files.
98 */
99 msStart = pGIS->msecs;
100 for (j = 0; j < i; j++)
101#ifdef TEST_STREAMS
102 fclose(apFiles[j]);
103#else
104 close(aiFiles[j]);
105#endif
106 msEnd = pGIS->msecs;
107 printf("close of %d files took %d ms\n", j, msEnd - msStart);
108
109 /*
110 * Report the result.
111 */
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}
Note: See TracBrowser for help on using the repository browser.