1 /****************************************************************************
2 * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. *
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: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
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. *
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 *
27 ****************************************************************************/
29 * hashtest.c -- test hash mapping
31 * Generate timing statistics for vertical-motion optimization.
33 * $Id: hashtest.c,v 1.31 2010/11/13 23:43:15 tom Exp $
36 #include <test.priv.h>
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;
58 finish(int sig GCC_UNUSED
)
61 ExitProgram(EXIT_FAILURE
);
71 Trace(("Resetting screen"));
73 Trace(("Painting `%c' screen", base
));
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.
80 scrollok(stdscr
, FALSE
);
83 for (i
= 0; i
< head_lines
; i
++)
84 for (j
= 0; j
< COLS
; j
++)
85 addch(UChar((j
% 8 == 0) ? ('A' + j
/ 8) : '-'));
88 for (i
= head_lines
; i
< LINES
- foot_lines
; i
++) {
89 chtype c
= (chtype
) ((base
- LO_CHAR
+ i
) % (HI_CHAR
- LO_CHAR
+ 1)
91 int hi
= (extend_corner
|| (i
< LINES
- 1)) ? COLS
: COLS
- 1;
92 for (j
= 0; j
< hi
; j
++)
96 for (i
= LINES
- foot_lines
; i
< LINES
; i
++) {
98 for (j
= 0; j
< (extend_corner
? COLS
: COLS
- 1); j
++)
99 addch(UChar((j
% 8 == 0) ? ('A' + j
/ 8) : '-'));
102 scrollok(stdscr
, TRUE
);
115 } else if (ch
!= 'a') {
122 run_test(bool optimized GCC_UNUSED
)
125 int lo
= continuous
? LO_CHAR
: 'a' - LINES
;
126 int hi
= continuous
? HI_CHAR
: 'a' + LINES
;
133 #if defined(TRACE) || defined(NCURSES_TEST)
135 Trace(("With hash mapping"));
136 _nc_optimize_enable
|= OPTIMIZE_HASHMAP
;
138 Trace(("Without hash mapping"));
139 _nc_optimize_enable
&= ~OPTIMIZE_HASHMAP
;
144 for (ch
= (char) hi
; ch
>= lo
; ch
--)
147 for (ch
= (char) lo
; ch
<= hi
; ch
++)
154 static const char *const tbl
[] =
156 "Usage: hashtest [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"
167 ," -x assume lower-right corner extension"
171 for (n
= 0; n
< SIZEOF(tbl
); n
++)
172 fprintf(stderr
, "%s\n", tbl
[n
]);
173 ExitProgram(EXIT_FAILURE
);
177 main(int argc
, char *argv
[])
181 int test_normal
= FALSE
;
182 int test_optimize
= FALSE
;
184 setlocale(LC_ALL
, "");
186 while ((c
= getopt(argc
, argv
, "cf:h:l:norsx")) != -1) {
192 foot_lines
= atoi(optarg
);
195 head_lines
= atoi(optarg
);
198 test_loops
= atoi(optarg
);
199 assert(test_loops
>= 0);
205 test_optimize
= TRUE
;
208 reverse_loops
= TRUE
;
214 extend_corner
= TRUE
;
220 if (!test_normal
&& !test_optimize
) {
222 test_optimize
= TRUE
;
228 CATCHALL(finish
); /* arrange interrupts to terminate */
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
);
237 while (test_loops
-- > 0) {
244 cleanup(); /* we're done */
245 ExitProgram(EXIT_SUCCESS
);
247 /* hashtest.c ends here */