1 /****************************************************************************
2 * Copyright 2019,2020 Thomas E. Dickey *
3 * Copyright 1998-2013,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 * hashtest.c -- test hash mapping
32 * Generate timing statistics for vertical-motion optimization.
34 * $Id: hashtest.c,v 1.36 2020/02/02 23:34:34 tom Exp $
37 #include <test.priv.h>
42 static bool continuous = FALSE;
43 static bool reverse_loops = FALSE;
44 static bool single_step = FALSE;
45 static bool extend_corner = FALSE;
46 static int foot_lines = 0;
47 static int head_lines = 0;
59 finish(int sig GCC_UNUSED)
62 ExitProgram(EXIT_FAILURE);
72 Trace(("Resetting screen"));
74 Trace(("Painting `%c' screen", base));
77 /* Do this so writes to lower-right corner don't cause a spurious
78 * scrolling operation. This _shouldn't_ break the scrolling
79 * optimization, since that's computed in the refresh() call.
81 scrollok(stdscr, FALSE);
84 for (i = 0; i < head_lines; i++)
85 for (j = 0; j < COLS; j++)
86 AddCh(UChar((j % 8 == 0) ? ('A' + j / 8) : '-'));
89 for (i = head_lines; i < LINES - foot_lines; i++) {
90 chtype c = (chtype) ((base - LO_CHAR + i) % (HI_CHAR - LO_CHAR + 1)
92 int hi = (extend_corner || (i < LINES - 1)) ? COLS : COLS - 1;
93 for (j = 0; j < hi; j++)
97 for (i = LINES - foot_lines; i < LINES; i++) {
99 for (j = 0; j < (extend_corner ? COLS : COLS - 1); j++)
100 AddCh(UChar((j % 8 == 0) ? ('A' + j / 8) : '-'));
103 scrollok(stdscr, TRUE);
116 } else if (ch != 'a') {
123 run_test(bool optimized GCC_UNUSED)
126 int lo = continuous ? LO_CHAR : 'a' - LINES;
127 int hi = continuous ? HI_CHAR : 'a' + LINES;
134 #if defined(TRACE) || defined(NCURSES_TEST)
136 Trace(("With hash mapping"));
137 _nc_optimize_enable |= OPTIMIZE_HASHMAP;
139 Trace(("Without hash mapping"));
140 _nc_optimize_enable &= ~OPTIMIZE_HASHMAP;
145 for (ch = (char) hi; ch >= lo; ch--)
148 for (ch = (char) lo; ch <= hi; ch++)
155 static const char *const tbl[] =
157 "Usage: hashtest [options]"
160 ," -c continuous (don't reset between refresh's)"
161 ," -f num leave 'num' lines constant for footer"
162 ," -h num leave 'num' lines constant for header"
163 ," -l num repeat test 'num' times"
164 ," -n test the normal optimizer"
165 ," -o test the hashed optimizer"
166 ," -r reverse the loops"
168 ," -x assume lower-right corner extension"
172 for (n = 0; n < SIZEOF(tbl); n++)
173 fprintf(stderr, "%s\n", tbl[n]);
174 ExitProgram(EXIT_FAILURE);
178 main(int argc, char *argv[])
182 int test_normal = FALSE;
183 int test_optimize = FALSE;
185 setlocale(LC_ALL, "");
187 while ((c = getopt(argc, argv, "cf:h:l:norsx")) != -1) {
193 foot_lines = atoi(optarg);
196 head_lines = atoi(optarg);
199 test_loops = atoi(optarg);
200 assert(test_loops >= 0);
206 test_optimize = TRUE;
209 reverse_loops = TRUE;
215 extend_corner = TRUE;
221 if (!test_normal && !test_optimize) {
223 test_optimize = TRUE;
226 curses_trace(TRACE_TIMES);
229 InitAndCatch(initscr(), finish);
230 keypad(stdscr, TRUE); /* enable keyboard mapping */
231 (void) nonl(); /* tell curses not to do NL->CR/NL on output */
232 (void) cbreak(); /* take input chars one at a time, no wait for \n */
233 (void) noecho(); /* don't echo input */
234 scrollok(stdscr, TRUE);
236 while (test_loops-- > 0) {
243 cleanup(); /* we're done */
244 ExitProgram(EXIT_SUCCESS);
246 /* hashtest.c ends here */