1 /****************************************************************************
2 * Copyright (c) 1998-2005,2006 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.26 2006/05/20 16:02:16 tom Exp $
37 #define Trace(p) _tracef p
40 #define Trace(p) /* nothing */
44 #include <test.priv.h>
49 static bool continuous = FALSE;
50 static bool reverse_loops = FALSE;
51 static bool single_step = FALSE;
52 static bool extend_corner = FALSE;
53 static int foot_lines = 0;
54 static int head_lines = 0;
66 finish(int sig GCC_UNUSED)
69 ExitProgram(EXIT_FAILURE);
79 Trace(("Resetting screen"));
81 Trace(("Painting `%c' screen", base));
84 /* Do this so writes to lower-right corner don't cause a spurious
85 * scrolling operation. This _shouldn't_ break the scrolling
86 * optimization, since that's computed in the refresh() call.
88 scrollok(stdscr, FALSE);
91 for (i = 0; i < head_lines; i++)
92 for (j = 0; j < COLS; j++)
93 addch(UChar((j % 8 == 0) ? ('A' + j / 8) : '-'));
96 for (i = head_lines; i < LINES - foot_lines; i++) {
97 chtype c = (base - LO_CHAR + i) % (HI_CHAR - LO_CHAR + 1) + LO_CHAR;
98 int hi = (extend_corner || (i < LINES - 1)) ? COLS : COLS - 1;
99 for (j = 0; j < hi; j++)
103 for (i = LINES - foot_lines; i < LINES; i++) {
105 for (j = 0; j < (extend_corner ? COLS : COLS - 1); j++)
106 addch(UChar((j % 8 == 0) ? ('A' + j / 8) : '-'));
109 scrollok(stdscr, TRUE);
122 } else if (ch != 'a') {
129 run_test(bool optimized GCC_UNUSED)
132 int lo = continuous ? LO_CHAR : 'a' - LINES;
133 int hi = continuous ? HI_CHAR : 'a' + LINES;
140 #if defined(TRACE) || defined(NCURSES_TEST)
142 Trace(("With hash mapping"));
143 _nc_optimize_enable |= OPTIMIZE_HASHMAP;
145 Trace(("Without hash mapping"));
146 _nc_optimize_enable &= ~OPTIMIZE_HASHMAP;
151 for (ch = hi; ch >= lo; ch--)
154 for (ch = lo; ch <= hi; ch++)
161 static const char *const tbl[] =
163 "Usage: hashtest [options]"
166 ," -c continuous (don't reset between refresh's)"
167 ," -f num leave 'num' lines constant for footer"
168 ," -h num leave 'num' lines constant for header"
169 ," -l num repeat test 'num' times"
170 ," -n test the normal optimizer"
171 ," -o test the hashed optimizer"
172 ," -r reverse the loops"
174 ," -x assume lower-right corner extension"
178 for (n = 0; n < SIZEOF(tbl); n++)
179 fprintf(stderr, "%s\n", tbl[n]);
180 ExitProgram(EXIT_FAILURE);
184 main(int argc, char *argv[])
188 int test_normal = FALSE;
189 int test_optimize = FALSE;
191 setlocale(LC_ALL, "");
193 while ((c = getopt(argc, argv, "cf:h:l:norsx")) != EOF) {
199 foot_lines = atoi(optarg);
202 head_lines = atoi(optarg);
205 test_loops = atoi(optarg);
211 test_optimize = TRUE;
214 reverse_loops = TRUE;
220 extend_corner = TRUE;
226 if (!test_normal && !test_optimize) {
228 test_optimize = TRUE;
234 CATCHALL(finish); /* arrange interrupts to terminate */
236 (void) initscr(); /* initialize the curses library */
237 keypad(stdscr, TRUE); /* enable keyboard mapping */
238 (void) nonl(); /* tell curses not to do NL->CR/NL on output */
239 (void) cbreak(); /* take input chars one at a time, no wait for \n */
240 (void) noecho(); /* don't echo input */
241 scrollok(stdscr, TRUE);
243 while (test_loops-- > 0) {
250 cleanup(); /* we're done */
251 ExitProgram(EXIT_SUCCESS);
253 /* hashtest.c ends here */