2 * hashtest.c -- test hash mapping
4 * Generate timing statistics for vertical-motion optimization.
6 * $Id: hashtest.c,v 1.24 2005/04/16 16:36:54 tom Exp $
10 #define Trace(p) _tracef p
13 #define Trace(p) /* nothing */
17 #include <test.priv.h>
22 static bool continuous = FALSE;
23 static bool reverse_loops = FALSE;
24 static bool single_step = FALSE;
25 static bool extend_corner = FALSE;
26 static int foot_lines = 0;
27 static int head_lines = 0;
39 finish(int sig GCC_UNUSED)
42 ExitProgram(EXIT_FAILURE);
52 Trace(("Resetting screen"));
54 Trace(("Painting `%c' screen", base));
57 /* Do this so writes to lower-right corner don't cause a spurious
58 * scrolling operation. This _shouldn't_ break the scrolling
59 * optimization, since that's computed in the refresh() call.
61 scrollok(stdscr, FALSE);
64 for (i = 0; i < head_lines; i++)
65 for (j = 0; j < COLS; j++)
66 addch(UChar((j % 8 == 0) ? ('A' + j / 8) : '-'));
69 for (i = head_lines; i < LINES - foot_lines; i++) {
70 chtype c = (base - LO_CHAR + i) % (HI_CHAR - LO_CHAR + 1) + LO_CHAR;
71 int hi = (extend_corner || (i < LINES - 1)) ? COLS : COLS - 1;
72 for (j = 0; j < hi; j++)
76 for (i = LINES - foot_lines; i < LINES; i++) {
78 for (j = 0; j < (extend_corner ? COLS : COLS - 1); j++)
79 addch(UChar((j % 8 == 0) ? ('A' + j / 8) : '-'));
82 scrollok(stdscr, TRUE);
95 } else if (ch != 'a') {
102 run_test(bool optimized GCC_UNUSED)
105 int lo = continuous ? LO_CHAR : 'a' - LINES;
106 int hi = continuous ? HI_CHAR : 'a' + LINES;
113 #if defined(TRACE) || defined(NCURSES_TEST)
115 Trace(("With hash mapping"));
116 _nc_optimize_enable |= OPTIMIZE_HASHMAP;
118 Trace(("Without hash mapping"));
119 _nc_optimize_enable &= ~OPTIMIZE_HASHMAP;
124 for (ch = hi; ch >= lo; ch--)
127 for (ch = lo; ch <= hi; ch++)
134 static const char *const tbl[] =
136 "Usage: hashtest [options]"
139 ," -c continuous (don't reset between refresh's)"
140 ," -f num leave 'num' lines constant for footer"
141 ," -h num leave 'num' lines constant for header"
142 ," -l num repeat test 'num' times"
143 ," -n test the normal optimizer"
144 ," -o test the hashed optimizer"
145 ," -r reverse the loops"
147 ," -x assume lower-right corner extension"
151 for (n = 0; n < SIZEOF(tbl); n++)
152 fprintf(stderr, "%s\n", tbl[n]);
153 ExitProgram(EXIT_FAILURE);
157 main(int argc, char *argv[])
161 int test_normal = FALSE;
162 int test_optimize = FALSE;
164 setlocale(LC_ALL, "");
166 while ((c = getopt(argc, argv, "cf:h:l:norsx")) != EOF) {
172 foot_lines = atoi(optarg);
175 head_lines = atoi(optarg);
178 test_loops = atoi(optarg);
184 test_optimize = TRUE;
187 reverse_loops = TRUE;
193 extend_corner = TRUE;
199 if (!test_normal && !test_optimize) {
201 test_optimize = TRUE;
207 (void) signal(SIGINT, finish); /* arrange interrupts to terminate */
209 (void) initscr(); /* initialize the curses library */
210 keypad(stdscr, TRUE); /* enable keyboard mapping */
211 (void) nonl(); /* tell curses not to do NL->CR/NL on output */
212 (void) cbreak(); /* take input chars one at a time, no wait for \n */
213 (void) noecho(); /* don't echo input */
214 scrollok(stdscr, TRUE);
216 while (test_loops-- > 0) {
223 cleanup(); /* we're done */
224 ExitProgram(EXIT_SUCCESS);
226 /* hashtest.c ends here */