1ecc16c8dSEd Schouten /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3fe267a55SPedro F. Giffuni *
4ecc16c8dSEd Schouten * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
5ecc16c8dSEd Schouten * All rights reserved.
6ecc16c8dSEd Schouten *
7ecc16c8dSEd Schouten * Redistribution and use in source and binary forms, with or without
8ecc16c8dSEd Schouten * modification, are permitted provided that the following conditions
9ecc16c8dSEd Schouten * are met:
10ecc16c8dSEd Schouten * 1. Redistributions of source code must retain the above copyright
11ecc16c8dSEd Schouten * notice, this list of conditions and the following disclaimer.
12ecc16c8dSEd Schouten * 2. Redistributions in binary form must reproduce the above copyright
13ecc16c8dSEd Schouten * notice, this list of conditions and the following disclaimer in the
14ecc16c8dSEd Schouten * documentation and/or other materials provided with the distribution.
15ecc16c8dSEd Schouten *
16ecc16c8dSEd Schouten * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17ecc16c8dSEd Schouten * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18ecc16c8dSEd Schouten * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19ecc16c8dSEd Schouten * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20ecc16c8dSEd Schouten * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21ecc16c8dSEd Schouten * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22ecc16c8dSEd Schouten * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23ecc16c8dSEd Schouten * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24ecc16c8dSEd Schouten * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25ecc16c8dSEd Schouten * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26ecc16c8dSEd Schouten * SUCH DAMAGE.
27ecc16c8dSEd Schouten */
28ecc16c8dSEd Schouten
29ecc16c8dSEd Schouten #include <sys/cdefs.h>
30ecc16c8dSEd Schouten
31ecc16c8dSEd Schouten #include <fcntl.h>
32ecc16c8dSEd Schouten #include <inttypes.h>
33ecc16c8dSEd Schouten #include <stdio.h>
34ecc16c8dSEd Schouten #include <stdlib.h>
35ecc16c8dSEd Schouten #include <unistd.h>
36ecc16c8dSEd Schouten
37ecc16c8dSEd Schouten #include <teken.h>
38ecc16c8dSEd Schouten
39ecc16c8dSEd Schouten static tf_bell_t stress_bell;
40ecc16c8dSEd Schouten static tf_cursor_t stress_cursor;
41ecc16c8dSEd Schouten static tf_putchar_t stress_putchar;
42ecc16c8dSEd Schouten static tf_fill_t stress_fill;
43ecc16c8dSEd Schouten static tf_copy_t stress_copy;
44ecc16c8dSEd Schouten static tf_param_t stress_param;
45ecc16c8dSEd Schouten static tf_respond_t stress_respond;
46ecc16c8dSEd Schouten
47ecc16c8dSEd Schouten static teken_funcs_t tf = {
48ecc16c8dSEd Schouten .tf_bell = stress_bell,
49ecc16c8dSEd Schouten .tf_cursor = stress_cursor,
50ecc16c8dSEd Schouten .tf_putchar = stress_putchar,
51ecc16c8dSEd Schouten .tf_fill = stress_fill,
52ecc16c8dSEd Schouten .tf_copy = stress_copy,
53ecc16c8dSEd Schouten .tf_param = stress_param,
54ecc16c8dSEd Schouten .tf_respond = stress_respond,
55ecc16c8dSEd Schouten };
56ecc16c8dSEd Schouten
57ecc16c8dSEd Schouten static void
stress_bell(void * s __unused)58ecc16c8dSEd Schouten stress_bell(void *s __unused)
59ecc16c8dSEd Schouten {
60ecc16c8dSEd Schouten }
61ecc16c8dSEd Schouten
62ecc16c8dSEd Schouten static void
stress_cursor(void * s __unused,const teken_pos_t * p __unused)63ecc16c8dSEd Schouten stress_cursor(void *s __unused, const teken_pos_t *p __unused)
64ecc16c8dSEd Schouten {
65ecc16c8dSEd Schouten }
66ecc16c8dSEd Schouten
67ecc16c8dSEd Schouten static void
stress_putchar(void * s __unused,const teken_pos_t * p __unused,teken_char_t c __unused,const teken_attr_t * a __unused)68ecc16c8dSEd Schouten stress_putchar(void *s __unused, const teken_pos_t *p __unused,
69ecc16c8dSEd Schouten teken_char_t c __unused, const teken_attr_t *a __unused)
70ecc16c8dSEd Schouten {
71ecc16c8dSEd Schouten }
72ecc16c8dSEd Schouten
73ecc16c8dSEd Schouten static void
stress_fill(void * s __unused,const teken_rect_t * r __unused,teken_char_t c __unused,const teken_attr_t * a __unused)74ecc16c8dSEd Schouten stress_fill(void *s __unused, const teken_rect_t *r __unused,
75ecc16c8dSEd Schouten teken_char_t c __unused, const teken_attr_t *a __unused)
76ecc16c8dSEd Schouten {
77ecc16c8dSEd Schouten }
78ecc16c8dSEd Schouten
79ecc16c8dSEd Schouten static void
stress_copy(void * s __unused,const teken_rect_t * r __unused,const teken_pos_t * p __unused)80ecc16c8dSEd Schouten stress_copy(void *s __unused, const teken_rect_t *r __unused,
81ecc16c8dSEd Schouten const teken_pos_t *p __unused)
82ecc16c8dSEd Schouten {
83ecc16c8dSEd Schouten }
84ecc16c8dSEd Schouten
85ecc16c8dSEd Schouten static void
stress_param(void * s __unused,int cmd __unused,unsigned int value __unused)86ecc16c8dSEd Schouten stress_param(void *s __unused, int cmd __unused, unsigned int value __unused)
87ecc16c8dSEd Schouten {
88ecc16c8dSEd Schouten }
89ecc16c8dSEd Schouten
90ecc16c8dSEd Schouten static void
stress_respond(void * s __unused,const void * buf __unused,size_t len __unused)91ecc16c8dSEd Schouten stress_respond(void *s __unused, const void *buf __unused, size_t len __unused)
92ecc16c8dSEd Schouten {
93ecc16c8dSEd Schouten }
94ecc16c8dSEd Schouten
95ecc16c8dSEd Schouten static const char replacement[] =
96ecc16c8dSEd Schouten { 0x1b, '[', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ';' };
97ecc16c8dSEd Schouten
98ecc16c8dSEd Schouten int
main(int argc __unused,char * argv[]__unused)99ecc16c8dSEd Schouten main(int argc __unused, char *argv[] __unused)
100ecc16c8dSEd Schouten {
101ecc16c8dSEd Schouten teken_t t;
102ecc16c8dSEd Schouten unsigned int i, iteration = 0;
103ecc16c8dSEd Schouten unsigned char buf[2048];
104ecc16c8dSEd Schouten
105ecc16c8dSEd Schouten
106ecc16c8dSEd Schouten teken_init(&t, &tf, NULL);
107ecc16c8dSEd Schouten
108ecc16c8dSEd Schouten for (;;) {
109073e2d2cSEd Schouten arc4random_buf(buf, sizeof buf);
110ecc16c8dSEd Schouten for (i = 0; i < sizeof buf; i++) {
111ecc16c8dSEd Schouten if (buf[i] >= 0x80)
112ecc16c8dSEd Schouten buf[i] =
113ecc16c8dSEd Schouten replacement[buf[i] % sizeof replacement];
114ecc16c8dSEd Schouten }
115ecc16c8dSEd Schouten
116ecc16c8dSEd Schouten teken_input(&t, buf, sizeof buf);
117ecc16c8dSEd Schouten
118ecc16c8dSEd Schouten iteration++;
119ecc16c8dSEd Schouten if ((iteration % 10000) == 0)
120ecc16c8dSEd Schouten printf("Processed %u frames\n", iteration);
121ecc16c8dSEd Schouten }
122ecc16c8dSEd Schouten }
123