1 | /****************************************************************************
|
---|
2 | * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. *
|
---|
3 | * *
|
---|
4 | * Permission is hereby granted, free of charge, to any person obtaining a *
|
---|
5 | * copy of this software and associated documentation files (the *
|
---|
6 | * "Software"), to deal in the Software without restriction, including *
|
---|
7 | * without limitation the rights to use, copy, modify, merge, publish, *
|
---|
8 | * distribute, distribute with modifications, sublicense, and/or sell *
|
---|
9 | * copies of the Software, and to permit persons to whom the Software is *
|
---|
10 | * furnished to do so, subject to the following conditions: *
|
---|
11 | * *
|
---|
12 | * The above copyright notice and this permission notice shall be included *
|
---|
13 | * in all copies or substantial portions of the Software. *
|
---|
14 | * *
|
---|
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
---|
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
---|
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
---|
18 | * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
---|
19 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
---|
20 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
---|
21 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
---|
22 | * *
|
---|
23 | * Except as contained in this notice, the name(s) of the above copyright *
|
---|
24 | * holders shall not be used in advertising or otherwise to promote the *
|
---|
25 | * sale, use or other dealings in this Software without prior written *
|
---|
26 | * authorization. *
|
---|
27 | ****************************************************************************/
|
---|
28 | /*
|
---|
29 | * hashtest.c -- test hash mapping
|
---|
30 | *
|
---|
31 | * Generate timing statistics for vertical-motion optimization.
|
---|
32 | *
|
---|
33 | * $Id: hashtest.c,v 1.31 2010/11/13 23:43:15 tom Exp $
|
---|
34 | */
|
---|
35 |
|
---|
36 | #include <test.priv.h>
|
---|
37 |
|
---|
38 | #define LO_CHAR ' '
|
---|
39 | #define HI_CHAR '~'
|
---|
40 |
|
---|
41 | static bool continuous = FALSE;
|
---|
42 | static bool reverse_loops = FALSE;
|
---|
43 | static bool single_step = FALSE;
|
---|
44 | static bool extend_corner = FALSE;
|
---|
45 | static int foot_lines = 0;
|
---|
46 | static int head_lines = 0;
|
---|
47 |
|
---|
48 | static void
|
---|
49 | cleanup(void)
|
---|
50 | {
|
---|
51 | move(LINES - 1, 0);
|
---|
52 | clrtoeol();
|
---|
53 | refresh();
|
---|
54 | endwin();
|
---|
55 | }
|
---|
56 |
|
---|
57 | static RETSIGTYPE
|
---|
58 | finish(int sig GCC_UNUSED)
|
---|
59 | {
|
---|
60 | cleanup();
|
---|
61 | ExitProgram(EXIT_FAILURE);
|
---|
62 | }
|
---|
63 |
|
---|
64 | static void
|
---|
65 | genlines(int base)
|
---|
66 | {
|
---|
67 | int i, j;
|
---|
68 |
|
---|
69 | #if USE_TRACE
|
---|
70 | if (base == 'a')
|
---|
71 | Trace(("Resetting screen"));
|
---|
72 | else
|
---|
73 | Trace(("Painting `%c' screen", base));
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | /* Do this so writes to lower-right corner don't cause a spurious
|
---|
77 | * scrolling operation. This _shouldn't_ break the scrolling
|
---|
78 | * optimization, since that's computed in the refresh() call.
|
---|
79 | */
|
---|
80 | scrollok(stdscr, FALSE);
|
---|
81 |
|
---|
82 | move(0, 0);
|
---|
83 | for (i = 0; i < head_lines; i++)
|
---|
84 | for (j = 0; j < COLS; j++)
|
---|
85 | addch(UChar((j % 8 == 0) ? ('A' + j / 8) : '-'));
|
---|
86 |
|
---|
87 | move(head_lines, 0);
|
---|
88 | for (i = head_lines; i < LINES - foot_lines; i++) {
|
---|
89 | chtype c = (chtype) ((base - LO_CHAR + i) % (HI_CHAR - LO_CHAR + 1)
|
---|
90 | + LO_CHAR);
|
---|
91 | int hi = (extend_corner || (i < LINES - 1)) ? COLS : COLS - 1;
|
---|
92 | for (j = 0; j < hi; j++)
|
---|
93 | addch(c);
|
---|
94 | }
|
---|
95 |
|
---|
96 | for (i = LINES - foot_lines; i < LINES; i++) {
|
---|
97 | move(i, 0);
|
---|
98 | for (j = 0; j < (extend_corner ? COLS : COLS - 1); j++)
|
---|
99 | addch(UChar((j % 8 == 0) ? ('A' + j / 8) : '-'));
|
---|
100 | }
|
---|
101 |
|
---|
102 | scrollok(stdscr, TRUE);
|
---|
103 | if (single_step) {
|
---|
104 | move(LINES - 1, 0);
|
---|
105 | getch();
|
---|
106 | } else
|
---|
107 | refresh();
|
---|
108 | }
|
---|
109 |
|
---|
110 | static void
|
---|
111 | one_cycle(int ch)
|
---|
112 | {
|
---|
113 | if (continuous) {
|
---|
114 | genlines(ch);
|
---|
115 | } else if (ch != 'a') {
|
---|
116 | genlines('a');
|
---|
117 | genlines(ch);
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | static void
|
---|
122 | run_test(bool optimized GCC_UNUSED)
|
---|
123 | {
|
---|
124 | char ch;
|
---|
125 | int lo = continuous ? LO_CHAR : 'a' - LINES;
|
---|
126 | int hi = continuous ? HI_CHAR : 'a' + LINES;
|
---|
127 |
|
---|
128 | if (lo < LO_CHAR)
|
---|
129 | lo = LO_CHAR;
|
---|
130 | if (hi > HI_CHAR)
|
---|
131 | hi = HI_CHAR;
|
---|
132 |
|
---|
133 | #if defined(TRACE) || defined(NCURSES_TEST)
|
---|
134 | if (optimized) {
|
---|
135 | Trace(("With hash mapping"));
|
---|
136 | _nc_optimize_enable |= OPTIMIZE_HASHMAP;
|
---|
137 | } else {
|
---|
138 | Trace(("Without hash mapping"));
|
---|
139 | _nc_optimize_enable &= ~OPTIMIZE_HASHMAP;
|
---|
140 | }
|
---|
141 | #endif
|
---|
142 |
|
---|
143 | if (reverse_loops)
|
---|
144 | for (ch = (char) hi; ch >= lo; ch--)
|
---|
145 | one_cycle(ch);
|
---|
146 | else
|
---|
147 | for (ch = (char) lo; ch <= hi; ch++)
|
---|
148 | one_cycle(ch);
|
---|
149 | }
|
---|
150 |
|
---|
151 | static void
|
---|
152 | usage(void)
|
---|
153 | {
|
---|
154 | static const char *const tbl[] =
|
---|
155 | {
|
---|
156 | "Usage: hashtest [options]"
|
---|
157 | ,""
|
---|
158 | ,"Options:"
|
---|
159 | ," -c continuous (don't reset between refresh's)"
|
---|
160 | ," -f num leave 'num' lines constant for footer"
|
---|
161 | ," -h num leave 'num' lines constant for header"
|
---|
162 | ," -l num repeat test 'num' times"
|
---|
163 | ," -n test the normal optimizer"
|
---|
164 | ," -o test the hashed optimizer"
|
---|
165 | ," -r reverse the loops"
|
---|
166 | ," -s single-step"
|
---|
167 | ," -x assume lower-right corner extension"
|
---|
168 | };
|
---|
169 | size_t n;
|
---|
170 |
|
---|
171 | for (n = 0; n < SIZEOF(tbl); n++)
|
---|
172 | fprintf(stderr, "%s\n", tbl[n]);
|
---|
173 | ExitProgram(EXIT_FAILURE);
|
---|
174 | }
|
---|
175 |
|
---|
176 | int
|
---|
177 | main(int argc, char *argv[])
|
---|
178 | {
|
---|
179 | int c;
|
---|
180 | int test_loops = 1;
|
---|
181 | int test_normal = FALSE;
|
---|
182 | int test_optimize = FALSE;
|
---|
183 |
|
---|
184 | setlocale(LC_ALL, "");
|
---|
185 |
|
---|
186 | while ((c = getopt(argc, argv, "cf:h:l:norsx")) != -1) {
|
---|
187 | switch (c) {
|
---|
188 | case 'c':
|
---|
189 | continuous = TRUE;
|
---|
190 | break;
|
---|
191 | case 'f':
|
---|
192 | foot_lines = atoi(optarg);
|
---|
193 | break;
|
---|
194 | case 'h':
|
---|
195 | head_lines = atoi(optarg);
|
---|
196 | break;
|
---|
197 | case 'l':
|
---|
198 | test_loops = atoi(optarg);
|
---|
199 | assert(test_loops >= 0);
|
---|
200 | break;
|
---|
201 | case 'n':
|
---|
202 | test_normal = TRUE;
|
---|
203 | break;
|
---|
204 | case 'o':
|
---|
205 | test_optimize = TRUE;
|
---|
206 | break;
|
---|
207 | case 'r':
|
---|
208 | reverse_loops = TRUE;
|
---|
209 | break;
|
---|
210 | case 's':
|
---|
211 | single_step = TRUE;
|
---|
212 | break;
|
---|
213 | case 'x':
|
---|
214 | extend_corner = TRUE;
|
---|
215 | break;
|
---|
216 | default:
|
---|
217 | usage();
|
---|
218 | }
|
---|
219 | }
|
---|
220 | if (!test_normal && !test_optimize) {
|
---|
221 | test_normal = TRUE;
|
---|
222 | test_optimize = TRUE;
|
---|
223 | }
|
---|
224 | #if USE_TRACE
|
---|
225 | trace(TRACE_TIMES);
|
---|
226 | #endif
|
---|
227 |
|
---|
228 | CATCHALL(finish); /* arrange interrupts to terminate */
|
---|
229 |
|
---|
230 | (void) initscr(); /* initialize the curses library */
|
---|
231 | keypad(stdscr, TRUE); /* enable keyboard mapping */
|
---|
232 | (void) nonl(); /* tell curses not to do NL->CR/NL on output */
|
---|
233 | (void) cbreak(); /* take input chars one at a time, no wait for \n */
|
---|
234 | (void) noecho(); /* don't echo input */
|
---|
235 | scrollok(stdscr, TRUE);
|
---|
236 |
|
---|
237 | while (test_loops-- > 0) {
|
---|
238 | if (test_normal)
|
---|
239 | run_test(FALSE);
|
---|
240 | if (test_optimize)
|
---|
241 | run_test(TRUE);
|
---|
242 | }
|
---|
243 |
|
---|
244 | cleanup(); /* we're done */
|
---|
245 | ExitProgram(EXIT_SUCCESS);
|
---|
246 | }
|
---|
247 | /* hashtest.c ends here */
|
---|