summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-27 18:15:26 -0600
committerGitHub <noreply@github.com>2026-11-27 18:15:26 -0600
commit83e8fbc692b36be5ac9011ccf26b1b232d560008 (patch)
treeab62a06c6a49b343b33d41b502487b233128ad80 /tests
parent4c95e6490d189b47cad050744de9768465e0307b (diff)
parentb5bb63d4760f6f6e0282fc9f7eec36b41705458c (diff)
downloadztop-main.tar.gz
Merge pull request #7 from skurtz97/feature/views-and-dec-glyphsHEADmain
views: PS, FS and LOG, and a DEC-graphics frame
Diffstat (limited to 'tests')
-rw-r--r--tests/__pycache__/screen.cpython-315-pytest-9.1.1.pycbin4406 -> 0 bytes
-rw-r--r--tests/screen.py37
-rw-r--r--tests/test_mdb.c90
-rw-r--r--tests/test_sys.c2
-rw-r--r--tests/test_vsm.c33
5 files changed, 150 insertions, 12 deletions
diff --git a/tests/__pycache__/screen.cpython-315-pytest-9.1.1.pyc b/tests/__pycache__/screen.cpython-315-pytest-9.1.1.pyc
deleted file mode 100644
index ff0f12c..0000000
--- a/tests/__pycache__/screen.cpython-315-pytest-9.1.1.pyc
+++ /dev/null
Binary files differ
diff --git a/tests/screen.py b/tests/screen.py
index 844ec7f..431d423 100644
--- a/tests/screen.py
+++ b/tests/screen.py
@@ -19,17 +19,37 @@ import time
W, H = 100, 30
grid = [[' '] * W for _ in range(H)]
row = col = 0
+# G0 set: DEC Special Graphics letters when ESC(0 selected it, else ASCII.
+# The library draws its frame that way; paint what the terminal would show.
+acs = False
+pending = b''
+DEC = {'l': '\u250c', 'k': '\u2510', 'm': '\u2514', 'j': '\u2518',
+ 'q': '\u2500', 'x': '\u2502', 't': '\u251c', 'u': '\u2524',
+ 'w': '\u252c', 'v': '\u2534', 'n': '\u253c', 'a': '\u2592'}
def feed(data):
- global row, col
+ global row, col, acs, pending
+ data = pending + data
+ pending = b''
i = 0
while i < len(data):
b = data[i]
- if b == 0x1b and i + 1 < len(data) and data[i + 1] == ord('['):
+ if b == 0x1b and i + 1 >= len(data):
+ pending = data[i:]
+ return
+ if b == 0x1b and data[i + 1] == ord('('):
+ if i + 3 > len(data):
+ pending = data[i:]
+ return
+ acs = data[i + 2] == ord('0')
+ i += 3
+ continue
+ if b == 0x1b and data[i + 1] == ord('['):
j = i + 2
while j < len(data) and not (0x40 <= data[j] <= 0x7e):
j += 1
if j >= len(data):
+ pending = data[i:]
return
params = data[i + 2:j].decode('latin1')
final = chr(data[j])
@@ -51,7 +71,8 @@ def feed(data):
row = min(H - 1, row + 1)
elif b >= 0x20:
if row < H and col < W:
- grid[row][col] = chr(b)
+ c = chr(b)
+ grid[row][col] = DEC.get(c, c) if acs else c
col += 1
i += 1
@@ -77,10 +98,14 @@ def pump(t):
return
feed(d)
+def show(what):
+ print('===', what)
+ for line in grid:
+ print(''.join(line).rstrip())
+
pump(2.0)
+show('initial')
for k in [b'\t', b'\t', b'\t', b'\t', b'?', b'?', b'q']:
os.write(fd, k)
pump(1.0)
- print('=== after', k)
- for line in grid:
- print(''.join(line).rstrip())
+ show(f'after {k!r}')
diff --git a/tests/test_mdb.c b/tests/test_mdb.c
new file mode 100644
index 0000000..0e63255
--- /dev/null
+++ b/tests/test_mdb.c
@@ -0,0 +1,90 @@
+/**
+ * @file test_mdb.c
+ * @brief The message-block walk, against blocks built byte by byte.
+ *
+ * The shape is the one IEAVM105 documents: a 12-byte header, then objects
+ * of two bytes of length and two of type. A general object carries the
+ * job name at +48 and a text object its line at +9.
+ */
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "mdb.h"
+
+/** A general object: 56 bytes, job name at +48. */
+static void put_general(unsigned char *p, const char *job) {
+ p[0] = 0;
+ p[1] = 56;
+ p[2] = 0;
+ p[3] = 1;
+ (void)memset(p + 48, ' ', 8);
+ (void)memcpy(p + 48, job, strlen(job));
+}
+
+/** A text object: the line starts at +9, so the length is 9 + the line. */
+static void put_text(unsigned char *p, const char *line) {
+ int n = (int)strlen(line);
+
+ p[0] = (unsigned char)((9 + n) >> 8);
+ p[1] = (unsigned char)(9 + n);
+ p[2] = 0;
+ p[3] = 4;
+ (void)memcpy(p + 9, line, (size_t)n);
+}
+
+int main(void) {
+ static unsigned char mdb[512];
+ char job[16];
+ char text[MDB_TEXT_MAX];
+
+ /* Job and line, in the order the service writes them. */
+ (void)memset(mdb, 0, sizeof mdb);
+ put_general(mdb + 12, "JOB1");
+ put_text(mdb + 12 + 56, "IEF403I JOB1 - STARTED");
+ assert(mdb_line((const char *)mdb, 12 + 56 + 9 + 22, job, sizeof job, text,
+ sizeof text));
+ assert(strcmp(job, "JOB1") == 0);
+ assert(strcmp(text, "IEF403I") == 0); /* trimmed at the first blank */
+
+ /* A line of one word keeps the word. */
+ (void)memset(mdb, 0, sizeof mdb);
+ put_general(mdb + 12, "J2");
+ put_text(mdb + 12 + 56, "STARTED");
+ assert(mdb_line((const char *)mdb, 12 + 56 + 9 + 7, job, sizeof job, text,
+ sizeof text));
+ assert(strcmp(job, "J2") == 0 && strcmp(text, "STARTED") == 0);
+
+ /* No text object: nothing to show, and the job is still known. */
+ (void)memset(mdb, 0, sizeof mdb);
+ put_general(mdb + 12, "J3");
+ assert(!mdb_line((const char *)mdb, 12 + 56, job, sizeof job, text,
+ sizeof text));
+ assert(strcmp(job, "J3") == 0 && text[0] == '\0');
+
+ /* A length that runs past the copy stops the walk: the block comes
+ * from another address space, so its lengths are input. */
+ (void)memset(mdb, 0, sizeof mdb);
+ put_text(mdb + 12, "SHOULD NOT APPEAR");
+ mdb[12] = 0x7F; /* claims 32k */
+ mdb[13] = 0xFF;
+ assert(!mdb_line((const char *)mdb, 12 + 9 + 16, job, sizeof job, text,
+ sizeof text));
+
+ /* Empty and short blocks are refused, not walked. */
+ assert(!mdb_line(nullptr, 8, job, sizeof job, text, sizeof text));
+ assert(!mdb_line((const char *)mdb, 8, job, sizeof job, text, sizeof text));
+ assert(!mdb_line((const char *)mdb, 0, job, sizeof job, text, sizeof text));
+
+ /* A zero-length object ends the walk without reading further. */
+ (void)memset(mdb, 0, sizeof mdb);
+ mdb[12] = 0;
+ mdb[13] = 0;
+ mdb[14] = 0;
+ mdb[15] = 4;
+ assert(
+ !mdb_line((const char *)mdb, 32, job, sizeof job, text, sizeof text));
+
+ (void)printf("test_mdb: ok\n");
+ return 0;
+}
diff --git a/tests/test_sys.c b/tests/test_sys.c
index b807859..ab20ddc 100644
--- a/tests/test_sys.c
+++ b/tests/test_sys.c
@@ -8,7 +8,7 @@
#include "sys.h"
int main(void) {
- struct zipl z;
+ zipl z;
/* CBT, IPLed at 17:02:47 on 21 September 2026 (day 264). */
assert(zipl_decode(0x0126264Fu, 6136760u, &z));
diff --git a/tests/test_vsm.c b/tests/test_vsm.c
index 371b7ad..284d9b6 100644
--- a/tests/test_vsm.c
+++ b/tests/test_vsm.c
@@ -48,7 +48,7 @@ static int fail_line(int line, const char *what) {
} while (0)
static int test_csa(void) {
- struct vsm_info v;
+ vsm_info v;
len = 0;
put32(2);
@@ -89,7 +89,7 @@ static int test_csa(void) {
}
static int test_merge(void) {
- struct vsm_info v;
+ vsm_info v;
len = 0;
put32(1);
@@ -108,8 +108,30 @@ static int test_merge(void) {
return 0;
}
+static int test_line16(void) {
+ vsm_info v;
+
+ len = 0;
+ put32(1);
+ desc(230, 0x08, 0, 8);
+ put32(2);
+ block(0x00FF0000, 0x1000); /* ends exactly at the line: below */
+ put32(0);
+ block(0x01000000, 0x1000); /* starts at the line: above */
+ put32(0);
+
+ vsm_reset(&v, VSM_CSA, VSM_FREE);
+ CHECK(vsm_parse_alloc(&v, buf, len));
+ CHECK(v.used == 0x2000);
+ CHECK(v.below == 0x1000);
+ CHECK(v.above == 0x1000);
+ CHECK(v.sub[0].below == 0x1000);
+ CHECK(v.sub[0].above == 0x1000);
+ return 0;
+}
+
static int test_pvt(void) {
- struct vsm_info v;
+ vsm_info v;
len = 0;
put32(1);
@@ -131,7 +153,7 @@ static int test_pvt(void) {
}
static int test_unalloc(void) {
- struct vsm_info v;
+ vsm_info v;
len = 0;
put32(2);
@@ -157,7 +179,7 @@ static int test_unalloc(void) {
}
static int test_bad(void) {
- struct vsm_info v;
+ vsm_info v;
/* descriptor length below the documented minimum */
len = 0;
@@ -213,6 +235,7 @@ int main(void) {
rc |= test_csa();
rc |= test_merge();
+ rc |= test_line16();
rc |= test_pvt();
rc |= test_unalloc();
rc |= test_bad();