interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / kernel / tests / test_fbcon.c

112 lines · 4266 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* test_fbcon.c -- host tests of core/fbcon.c (the GOP framebuffer console)
18 * and core/font8x8.h: every printable glyph is distinct (the screen gate's
19 * checker decodes cells by exact match), the scale rule, lazy newline, line
20 * wrap, half-scroll, and the exact pixels of one glyph. */
21#include <string.h>
22#include "ck_test.h"
23#include "fbcon.h"
24#include "font8x8.h"
25
26static uint32_t px[800 * 600];
27static struct ck_fbcon con;
28
29/* Text of row r as the text copy holds it (0 cells end it). */
30static const char *row_text(uint32_t r)
31{
32 static char b[CK_FBCON_MAX_COLS + 1];
33 uint32_t n = 0;
34 while (n < con.cols && con.text[r][n])
35 b[n] = con.text[r][n], n++;
36 b[n] = 0;
37 return b;
38}
39
40static void put(const char *s) { ck_fbcon_write(&con, s, strlen(s)); }
41
42int main(void)
43{
44 /* glyphs 0x20..0x7e pairwise distinct; only the space is blank */
45 int distinct = 1, blank = 0;
46 for (int a = 0; a <= CK_FONT_LAST - CK_FONT_FIRST; a++) {
47 uint8_t z[8] = {0};
48 blank += !memcmp(ck_font8x8[a], z, 8);
49 for (int b = a + 1; b <= CK_FONT_LAST - CK_FONT_FIRST; b++)
50 if (!memcmp(ck_font8x8[a], ck_font8x8[b], 8))
51 distinct = 0;
52 }
53 CHECK(distinct);
54 CHECK(blank == 1);
55
56 /* scale: 1080p -> 2, 4K -> 4, 800x600 -> 1, 1280x1024 -> 1 (80 columns) */
57 CHECK(ck_fbcon_scale_for(1920, 1080) == 2);
58 CHECK(ck_fbcon_scale_for(3840, 2160) == 4);
59 CHECK(ck_fbcon_scale_for(800, 600) == 1);
60 CHECK(ck_fbcon_scale_for(1280, 1024) == 1);
61 CHECK(ck_fbcon_scale_for(640, 480) == 1);
62
63 /* refusals: format 2, pitch < width, too small for one cell */
64 CHECK(ck_fbcon_setup(&con, px, 800, 600, 800, 2) == -1);
65 CHECK(ck_fbcon_setup(&con, px, 800, 600, 799, 1) == -1);
66 CHECK(ck_fbcon_setup(&con, px, 7, 600, 800, 1) == -1);
67
68 memset(px, 0x55, sizeof px);
69 CHECK(ck_fbcon_setup(&con, px, 800, 600, 800, 1) == 0);
70 CHECK(con.scale == 1 && con.cols == 100 && con.rows == 60);
71 CHECK(px[0] == CK_FBCON_BG && px[800 * 600 - 1] == CK_FBCON_BG); /* cleared */
72
73 /* 'A' at cell (0,0): row 0 of the glyph is 0x0C -> pixels 2 and 3 lit */
74 put("A");
75 CHECK(px[0] == CK_FBCON_BG && px[1] == CK_FBCON_BG && px[2] == CK_FBCON_FG && px[3] == CK_FBCON_FG &&
76 px[4] == CK_FBCON_BG);
77 CHECK(px[8 * 800 + 2] == CK_FBCON_BG); /* gap row 8 stays black */
78
79 /* lazy newline: the trailing '\n' does not move to the next row yet */
80 put("BC\n");
81 CHECK(con.row == 0 && con.pending_nl == 1);
82 CHECK(!strcmp(row_text(0), "ABC"));
83 put("\r\nD"); /* "\r\n" from the UART stream behaves like one more '\n' */
84 CHECK(con.row == 2 && !strcmp(row_text(2), "D"));
85
86 /* wrap at 100 columns */
87 put("\n");
88 for (int i = 0; i < 105; i++)
89 put("x");
90 CHECK(con.row == 4 && con.col == 5);
91
92 /* half-scroll: fill to the bottom; the newest 30 rows move to the top */
93 CHECK(ck_fbcon_setup(&con, px, 800, 600, 800, 0) == 0);
94 char line[16];
95 for (int i = 0; i < 61; i++) {
96 snprintf(line, sizeof line, "%sL%02d", i ? "\n" : "", i);
97 put(line);
98 }
99 CHECK(con.scrolls == 1);
100 CHECK(!strcmp(row_text(0), "L30"));
101 CHECK(!strcmp(row_text(29), "L59"));
102 CHECK(!strcmp(row_text(30), "L60"));
103 CHECK(con.row == 30 && con.text[31][0] == 0);
104 /* the redrawn row 0 shows "L30": 'L' row 0 is 0x0F -> pixels 0..3 lit */
105 CHECK(px[0] == CK_FBCON_FG && px[3] == CK_FBCON_FG && px[4] == CK_FBCON_BG);
106
107 /* bytes outside 0x20..0x7e are drawn as '?' */
108 put("\n\x01\xff");
109 CHECK(!strcmp(row_text(31), "??"));
110
111 return ck_t_verdict("test_fbcon");
112}