1186681Sed/*-
2186681Sed * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
3186681Sed * All rights reserved.
4186681Sed *
5186681Sed * Redistribution and use in source and binary forms, with or without
6186681Sed * modification, are permitted provided that the following conditions
7186681Sed * are met:
8186681Sed * 1. Redistributions of source code must retain the above copyright
9186681Sed *    notice, this list of conditions and the following disclaimer.
10186681Sed * 2. Redistributions in binary form must reproduce the above copyright
11186681Sed *    notice, this list of conditions and the following disclaimer in the
12186681Sed *    documentation and/or other materials provided with the distribution.
13186681Sed *
14186681Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15186681Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16186681Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17186681Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18186681Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19186681Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20186681Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21186681Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22186681Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23186681Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24186681Sed * SUCH DAMAGE.
25186681Sed *
26186681Sed * $FreeBSD$
27186681Sed */
28186681Sed
29186681Sed#include <sys/cdefs.h>
30186681Sed
31186681Sed#include <fcntl.h>
32186681Sed#include <inttypes.h>
33186681Sed#include <stdio.h>
34186681Sed#include <stdlib.h>
35186681Sed#include <unistd.h>
36186681Sed
37221698Sed#include <teken.h>
38186681Sed
39186681Sedstatic tf_bell_t	stress_bell;
40186681Sedstatic tf_cursor_t	stress_cursor;
41186681Sedstatic tf_putchar_t	stress_putchar;
42186681Sedstatic tf_fill_t	stress_fill;
43186681Sedstatic tf_copy_t	stress_copy;
44186681Sedstatic tf_param_t	stress_param;
45186681Sedstatic tf_respond_t	stress_respond;
46186681Sed
47186681Sedstatic teken_funcs_t tf = {
48186681Sed	.tf_bell	= stress_bell,
49186681Sed	.tf_cursor	= stress_cursor,
50186681Sed	.tf_putchar	= stress_putchar,
51186681Sed	.tf_fill	= stress_fill,
52186681Sed	.tf_copy	= stress_copy,
53186681Sed	.tf_param	= stress_param,
54186681Sed	.tf_respond	= stress_respond,
55186681Sed};
56186681Sed
57186681Sedstatic void
58186681Sedstress_bell(void *s __unused)
59186681Sed{
60186681Sed}
61186681Sed
62186681Sedstatic void
63186681Sedstress_cursor(void *s __unused, const teken_pos_t *p __unused)
64186681Sed{
65186681Sed}
66186681Sed
67186681Sedstatic void
68186681Sedstress_putchar(void *s __unused, const teken_pos_t *p __unused,
69186681Sed    teken_char_t c __unused, const teken_attr_t *a __unused)
70186681Sed{
71186681Sed}
72186681Sed
73186681Sedstatic void
74186681Sedstress_fill(void *s __unused, const teken_rect_t *r __unused,
75186681Sed    teken_char_t c __unused, const teken_attr_t *a __unused)
76186681Sed{
77186681Sed}
78186681Sed
79186681Sedstatic void
80186681Sedstress_copy(void *s __unused, const teken_rect_t *r __unused,
81186681Sed    const teken_pos_t *p __unused)
82186681Sed{
83186681Sed}
84186681Sed
85186681Sedstatic void
86193940Sedstress_param(void *s __unused, int cmd __unused, unsigned int value __unused)
87186681Sed{
88186681Sed}
89186681Sed
90186681Sedstatic void
91186681Sedstress_respond(void *s __unused, const void *buf __unused, size_t len __unused)
92186681Sed{
93186681Sed}
94186681Sed
95197519Sedstatic const char replacement[] =
96197519Sed    { 0x1b, '[', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ';' };
97197519Sed
98186681Sedint
99186681Sedmain(int argc __unused, char *argv[] __unused)
100186681Sed{
101186681Sed	teken_t t;
102197519Sed	unsigned int i, iteration = 0;
103197519Sed	unsigned char buf[2048];
104186681Sed
105186681Sed
106186681Sed	teken_init(&t, &tf, NULL);
107186681Sed
108186681Sed	for (;;) {
109226100Sed		arc4random_buf(buf, sizeof buf);
110197519Sed		for (i = 0; i < sizeof buf; i++) {
111197519Sed			if (buf[i] >= 0x80)
112197519Sed				buf[i] =
113197519Sed				    replacement[buf[i] % sizeof replacement];
114197519Sed		}
115197519Sed
116186681Sed		teken_input(&t, buf, sizeof buf);
117186681Sed
118186681Sed		iteration++;
119186681Sed		if ((iteration % 10000) == 0)
120186681Sed			printf("Processed %u frames\n", iteration);
121186681Sed	}
122186681Sed}
123