2 ** Copyright (C) 1991, 1997 Free Software Foundation, Inc.
4 ** This file is part of TACK.
6 ** TACK is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2, or (at your option)
11 ** TACK is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
16 ** You should have received a copy of the GNU General Public License
17 ** along with TACK; see the file COPYING. If not, write to
18 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 ** Boston, MA 02110-1301, USA
28 MODULE_ID("$Id: control.c,v 1.8 2005/09/17 19:49:16 tom Exp $")
30 /* terminfo test program control subroutines */
33 #define MY_TIMER struct timeval
35 #define MY_TIMER time_t
39 int test_complete; /* counts number of tests completed */
41 char txt_longer_test_time[80]; /* +) use longer time */
42 char txt_shorter_test_time[80]; /* -) use shorter time */
43 static int pad_test_duration = 1; /* number of seconds for a pad test */
44 int auto_pad_mode; /* run the time tests */
45 int no_alarm_event; /* TRUE if the alarm has not gone off yet */
46 unsigned long usec_run_time; /* length of last test in microseconds */
47 static MY_TIMER stop_watch[MAX_TIMERS]; /* Hold the start timers */
49 char txt_longer_augment[80]; /* >) use bigger augment */
50 char txt_shorter_augment[80]; /* <) use smaller augment */
52 /* caps under test data base */
53 int tt_delay_max; /* max number of milliseconds we can delay */
54 int tt_delay_used; /* number of milliseconds consumed in delay */
55 const char *tt_cap[TT_MAX]; /* value of string */
56 int tt_affected[TT_MAX]; /* lines or columns effected (repetition factor) */
57 int tt_count[TT_MAX]; /* Number of times sent */
58 int tt_delay[TT_MAX]; /* Number of milliseconds delay */
59 int ttp; /* number of entries used */
61 /* Saved value of the above data base */
62 const char *tx_cap[TT_MAX]; /* value of string */
63 int tx_affected[TT_MAX]; /* lines or columns effected (repetition factor) */
64 int tx_count[TT_MAX]; /* Number of times sent */
65 int tx_index[TT_MAX]; /* String index */
66 int tx_delay[TT_MAX]; /* Number of milliseconds delay */
67 int txp; /* number of entries used */
68 int tx_characters; /* printing characters sent by test */
69 unsigned long tx_cps; /* characters per second */
70 static struct test_list *tx_source; /* The test that generated this data */
72 #define RESULT_BLOCK 1024
73 static int blocks; /* number of result blocks available */
74 static struct test_results *results; /* pointer to next available */
75 static struct test_results *pads[STRCOUNT]; /* save pad results here */
78 ** event_start(number)
80 ** Begin the stopwatch at the current time-of-day.
86 (void) gettimeofday(&stop_watch[n], (struct timezone *)0);
88 stop_watch[n] = time((time_t *)0);
95 ** Return the number of milliseconds since this stop watch began.
100 #if HAVE_GETTIMEOFDAY
101 MY_TIMER current_time;
103 (void) gettimeofday(¤t_time, (struct timezone *)0);
104 return ((current_time.tv_sec - stop_watch[n].tv_sec) * 1000000)
105 + current_time.tv_usec - stop_watch[n].tv_usec;
107 return (time((time_t *)0) - stop_watch[n]) * 1000;
111 /*****************************************************************************
113 * Execution control for string capability tests
115 *****************************************************************************/
120 ** Get a results block for pad test data.
122 static struct test_results *
126 results = (struct test_results *)
127 malloc(sizeof(struct test_results) * RESULT_BLOCK);
129 ptextln("Malloc failed");
130 return (struct test_results *) 0;
132 blocks = RESULT_BLOCK;
141 ** Initialize the augment menu selections
144 set_augment_txt(void)
146 sprintf(txt_longer_augment,
147 ">) Change lines/characters effected to %d", augment << 1);
148 sprintf(txt_shorter_augment,
149 "<) Change lines/characters effected to %d", augment >> 1);
155 sprintf(txt_longer_test_time, "+) Change test time to %d seconds",
156 pad_test_duration + 1);
157 sprintf(txt_shorter_test_time, "-) Change test time to %d seconds",
158 pad_test_duration - 1);
163 ** msec_cost(cap, affected-count)
165 ** Return the number of milliseconds delay needed by the cap.
169 const char *const cap,
172 int dec, value, total, star, ch;
179 for (cp = cap; *cp; cp++) {
180 if (*cp == '$' && cp[1] == '<') {
183 for (cp += 2; (ch = *cp); cp++) {
184 if (ch >= '0' && ch <= '9') {
185 value = value * 10 + (ch - '0');
199 total += (value * star) / dec;
201 total += (value * star);
211 ** Return the cap without padding
216 static char cb[1024];
222 for (ts = cb; (*ts = *cap); ++cap) {
223 if (*cap == '$' && cap[1] == '<') {
241 ** send CR/LF or go home and bump letter
246 if (line_count + 2 >= lines) {
255 ** skip_pad_test(test-list-entry, state, ch, text)
257 ** Print the start test line. Handle start up commands.
258 ** Return TRUE if a return is requested.
262 struct test_list *test,
273 if ((test->flags & MENU_LC_MASK)) {
274 sprintf(rep_text, " *%d", augment);
280 /* Skip is converted to next */
285 /* Quit is converted to help */
289 if (*ch == '\r' || *ch == '\n' || *ch == 'n' || *ch == 'r') {
290 /* this is the only response that allows the test to run */
293 if (subtest_menu(pad_test_list, state, ch)) {
301 ** pad_done_message(test_list)
303 ** Print the Done message and request input.
307 struct test_list *test,
311 int default_action = 0;
312 char done_message[128];
316 if ((test->flags & MENU_LC_MASK)) {
317 sprintf(rep_text, "*%d", augment);
321 if (test->caps_done) {
322 sprintf(done_message, "(%s)%s Done ", test->caps_done,
332 if (debug_level & 2) {
333 dump_test_stats(test, state, ch);
337 if (*ch == '\r' || *ch == '\n') {
338 *ch = default_action;
341 if (*ch == 's' || *ch == 'n') {
345 if (strchr(pad_repeat_test, *ch)) {
346 /* default action is now repeat */
347 default_action = 'r';
349 if (subtest_menu(pad_test_list, state, ch)) {
357 ** sliding_scale(dividend, factor, divisor)
359 ** Return (dividend * factor) / divisor
365 unsigned long divisor)
370 d = (d * (double) factor) / (double) divisor;
371 return (int) (d + 0.5);
377 ** pad_test_startup()
379 ** Do the stuff needed to begin a test.
389 raw_characters_sent = 0;
390 test_complete = ttp = char_count = tt_delay_used = 0;
391 letter = letters[letter_number = 0];
392 if (pad_test_duration <= 0) {
393 pad_test_duration = 1;
395 tt_delay_max = pad_test_duration * 1000;
396 set_alarm_clock(pad_test_duration);
397 event_start(TIME_TEST);
403 ** This function is called to see if the test loop should be terminated.
410 return EXIT_CONDITION;
414 ** pad_test_shutdown()
416 ** Do the stuff needed to end a test.
424 int counts; /* total counts */
425 int ss; /* Save string index */
426 int cpo; /* characters per operation */
427 int delta; /* difference in characters */
428 int bogus; /* Time is inaccurate */
429 struct test_results *r; /* Results of current test */
430 int ss_index[TT_MAX]; /* String index */
432 if (tty_can_sync == SYNC_TESTED) {
433 bogus = tty_sync_error();
437 usec_run_time = event_time(TIME_TEST);
439 tx_characters = raw_characters_sent;
440 tx_cps = sliding_scale(tx_characters, 1000000, usec_run_time);
442 /* save the data base */
443 for (txp = ss = counts = 0; txp < ttp; txp++) {
444 tx_cap[txp] = tt_cap[txp];
445 tx_count[txp] = tt_count[txp];
446 tx_delay[txp] = tt_delay[txp];
447 tx_affected[txp] = tt_affected[txp];
448 tx_index[txp] = get_string_cap_byvalue(tt_cap[txp]);
449 if (tx_index[txp] >= 0) {
450 if (cap_match(t->caps_done, strnames[tx_index[txp]])) {
451 ss_index[ss++] = txp;
452 counts += tx_count[txp];
460 if (counts == 0 || tty_cps == 0 || bogus) {
464 /* calculate the suggested pad times */
465 delta = usec_run_time - sliding_scale(tx_characters, 1000000, tty_cps);
467 /* probably should bump tx_characters */
470 cpo = delta / counts;
471 for (i = 0; i < ss; i++) {
472 if (!(r = get_next_block())) {
475 r->next = pads[tx_index[ss_index[i]]];
476 pads[tx_index[ss_index[i]]] = r;
478 r->reps = tx_affected[ss_index[i]];
484 ** show_cap_results(index)
486 ** Display the previous results
492 struct test_results *r; /* a result */
496 sprintf(temp, "(%s)", strnames[x]);
499 sprintf(temp, "$<%d>", r->delay / 1000);
500 put_columns(temp, (int) strlen(temp), 10);
506 delay = r->delay / (r->reps * 100);
507 sprintf(temp, "$<%d.%d*>", delay / 10, delay % 10);
508 put_columns(temp, (int) strlen(temp), 10);
517 ** dump_test_stats(test_list, status, ch)
519 ** Dump the statistics about the last test
532 if (tx_source && tx_source->caps_done) {
533 cap_index(tx_source->caps_done, x);
535 sprintf(temp, "Caps summary for (%s)",
536 tx_source->caps_done);
538 for (i = 0; x[i] >= 0; i++) {
539 show_cap_results(x[i]);
544 sprintf(tbuf, "%011lu", usec_run_time);
545 sprintf(temp, "Test time: %lu.%s, characters per second %lu, characters %d",
546 usec_run_time / 1000000UL, &tbuf[5], tx_cps, tx_characters);
548 for (i = 0; i < txp; i++) {
549 if ((j = get_string_cap_byvalue(tx_cap[i])) >= 0) {
550 sprintf(tbuf, "(%s)", strnames[j]);
554 sprintf(temp, "%8d %3d $<%3d> %8s %s",
555 tx_count[i], tx_affected[i], tx_delay[i],
556 tbuf, expand(tx_cap[i]));
559 generic_done_message(t, state, ch);
563 ** longer_test_time(test_list, status, ch)
565 ** Extend the number of seconds for each test.
569 struct test_list *t GCC_UNUSED,
570 int *state GCC_UNUSED,
573 pad_test_duration += 1;
574 sprintf(txt_longer_test_time, "+) Change test time to %d seconds",
575 pad_test_duration + 1);
576 sprintf(txt_shorter_test_time, "-) Change test time to %d seconds",
577 pad_test_duration - 1);
578 sprintf(temp, "Tests will run for %d seconds", pad_test_duration);
580 *ch = REQUEST_PROMPT;
584 ** shorter_test_time(test_list, status, ch)
586 ** Shorten the number of seconds for each test.
590 struct test_list *t GCC_UNUSED,
591 int *state GCC_UNUSED,
594 if (pad_test_duration > 1) {
595 pad_test_duration -= 1;
596 sprintf(txt_longer_test_time, "+) Change test time to %d seconds",
597 pad_test_duration + 1);
598 sprintf(txt_shorter_test_time, "-) Change test time to %d seconds",
599 pad_test_duration - 1);
601 sprintf(temp, "Tests will run for %d second%s", pad_test_duration,
602 pad_test_duration > 1 ? "s" : "");
604 *ch = REQUEST_PROMPT;
608 ** longer_augment(test_list, status, ch)
610 ** Lengthen the number of lines/characters effected
615 int *state GCC_UNUSED,
623 sprintf(temp, "The pad tests will effect %d %s.", augment,
624 ((t->flags & MENU_LC_MASK) == MENU_lines) ?
625 "lines" : "characters");
627 *ch = REQUEST_PROMPT;
631 ** shorter_augment(test_list, status, ch)
633 ** Shorten the number of lines/characters effected
638 int *state GCC_UNUSED,
642 /* don't let the augment go to zero */
649 sprintf(temp, "The pad tests will effect %d %s.", augment,
650 ((t->flags & MENU_LC_MASK) == MENU_lines) ?
651 "lines" : "characters");
653 *ch = REQUEST_PROMPT;