summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-27 17:59:16 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-27 17:59:16 -0600
commit1b00c3d4749038add86bb799d453f1bcd71b52af (patch)
tree6ebe6285e847be8fec1439e7f9903660e5828fc4
parent3ec1d6930b9a1146b97153e225b90a7a13696169 (diff)
downloadzash-1b00c3d4749038add86bb799d453f1bcd71b52af.tar.gz
tests: pin the CSI type byte in both character sets, and a gzip archive
The CSI entry type byte is converted from EBCDIC in an ASCII build and must be used as it is in an EBCDIC build (notes/review-2026-11-27.md, item 12). Nothing but Tab completion on z/OS reaches that code, so the test drives the decoder directly: tests/tools/csi.c builds a work area with one data set, one user catalog connector and one catalog entry, and asks csi_parse() for the names. On z/OS the Makefile builds it twice, once per character set, and tests/zos/csi-parse.sh runs both; each prints a verdict, so one expectation covers both builds. tests/zos/tagging.sh gains the case the review asked for: a gzip archive made through zash (with its stdout tagged and converting) must be byte for byte the archive /bin/sh's redirect makes. It is: gzip turns conversion off for its own output, and the 1047 tag is the one /bin/sh leaves on this host too (_BPXK_AUTOCVT=ON, _CEE_RUNOPTS=FILETAG(AUTOCVT,AUTOTAG)).
-rw-r--r--Makefile31
-rw-r--r--tests/tools/csi.c118
-rw-r--r--tests/zos/csi-parse.exp5
-rw-r--r--tests/zos/csi-parse.sh16
-rw-r--r--tests/zos/tagging.exp4
-rw-r--r--tests/zos/tagging.sh21
6 files changed, 186 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 3f054c5..c22ace4 100644
--- a/Makefile
+++ b/Makefile
@@ -205,7 +205,8 @@ zash-mvslint: $(COMMON) src/sys_posix.c $(HDRS)
$(COMMON) src/sys_posix.c $(LDLIBS)
mvs-asan: zash-mvslint
- ASAN_OPTIONS=detect_leaks=1 sh tests/run.sh ./zash-mvslint
+ ASAN_OPTIONS=detect_leaks=1 ZASH_TEST_SKIP='perf/startup' \
+ sh tests/run.sh ./zash-mvslint
zash-asan: $(COMMON) src/sys_posix.c $(HDRS)
$(CC) $(CPPFLAGS) $(CSTD) $(WARN) $(SANFLAGS) -o $@ $(COMMON) src/sys_posix.c \
@@ -259,13 +260,31 @@ $(ZTOOLS)/spawn: tests/tools/spawn.c
$(CC) $(CPPFLAGS) $(CSTD) -O2 -Wall -Wextra -o $@ tests/tools/spawn.c; \
fi
+# A CSI work area read back through the shell's own decoder: tests/zos/
+# csi-parse.sh. On z/OS it is built twice, because the character set is
+# chosen when src/mvsfmt.c is compiled and that choice is what the test is
+# about: an ASCII build converts the entry type byte from EBCDIC, an EBCDIC
+# build must use it as it is.
+$(ZTOOLS)/csi: tests/tools/csi.c src/mvsfmt.c src/mvsfmt.h src/charset.h
+ @mkdir -p $(ZTOOLS)
+ @if uname -s | grep -q OS/390; then \
+ $(ZCC) $(ZCPPFLAGS) $(CSTD) -O2 -m32 -Wall -Wextra -Isrc \
+ -o $@ tests/tools/csi.c src/mvsfmt.c; \
+ $(ZCC) $(ZCPPFLAGS) $(CSTD) -O2 -m32 -Wall -Wextra -Isrc \
+ -fzos-le-char-mode=ascii -o $@-ascii \
+ tests/tools/csi.c src/mvsfmt.c; \
+ else \
+ $(CC) $(CPPFLAGS) $(CSTD) -O2 -Wall -Wextra -Isrc \
+ -o $@ tests/tools/csi.c src/mvsfmt.c; \
+ fi
+
# On z/OS the `zash` build above wants clang and posix_spawn, so run the z/OS
# build and both its test passes instead.
check:
@if uname -s | grep OS/390 >/dev/null; then \
$(MAKE) zos-check; \
else \
- $(MAKE) zash && sh tests/run.sh ./zash; \
+ $(MAKE) zash $(ZTOOLS)/now && sh tests/run.sh ./zash; \
fi
# z/OS has no ASan, but Language Environment can put a check zone after
@@ -294,7 +313,8 @@ zos-leakcheck: zos-ascii $(ZTOOLS)/sleep
@echo "reports in build/leaks: $$(ls build/leaks | wc -l)"
asan: zash-asan
- ASAN_OPTIONS=detect_leaks=1:abort_on_error=0 sh tests/run.sh ./zash-asan
+ ASAN_OPTIONS=detect_leaks=1:abort_on_error=0 ZASH_TEST_SKIP='perf/startup' \
+ sh tests/run.sh ./zash-asan
# Valgrind emulates posix_spawn() with fork+exec and so cannot hand an exec
# failure back to the caller, and it does not let a program lower its own
@@ -325,11 +345,12 @@ fuzz: fuzz-mvsfmt
valgrind: zash
ZASH_TEST_WRAP="valgrind -q --error-exitcode=99 --trace-children=no --leak-check=full --errors-for-leak-kinds=definite" \
- ZASH_TEST_SKIP="posix/execfail scripts/library zash/ulimit" sh tests/run.sh ./zash
+ ZASH_TEST_SKIP="posix/execfail scripts/library zash/ulimit perf/startup" \
+ sh tests/run.sh ./zash
# z/OS: behaviour only (no sanitizers or Valgrind there), against the
# ./zash that zos-ascii or zos-ebcdic built.
-zos-check: zos-ascii zos-ebcdic $(ZTOOLS)/sleep
+zos-check: zos-ascii zos-ebcdic $(ZTOOLS)/sleep $(ZTOOLS)/csi
PATH="$$(pwd)/$(ZTOOLS):$$PATH" sh tests/run.sh ./zash
PATH="$$(pwd)/$(ZTOOLS):$$PATH" sh tests/run.sh ./zash-ebcdic zos/ebcdic
diff --git a/tests/tools/csi.c b/tests/tools/csi.c
new file mode 100644
index 0000000..25333d8
--- /dev/null
+++ b/tests/tools/csi.c
@@ -0,0 +1,118 @@
+/**
+ * @file csi.c
+ * @brief Hand csi_parse() a Catalog Search Interface work area and check
+ * what it makes of each entry.
+ *
+ * tests/zos/csi-parse.sh runs this in both character sets. The entry type
+ * byte is the point: an ASCII build converts it from EBCDIC, an EBCDIC build
+ * must use it as it is (notes/review-2026-11-27.md, item 12 -- an EBCDIC
+ * build converted it a second time, so every entry arrived with a type that
+ * was not its own).
+ *
+ * The result is printed as a verdict, not as the decoded text: the same words
+ * then come out of an ASCII build and an EBCDIC build, and one expectation
+ * serves both.
+ *
+ * The byte layout is the one src/mvsfmt.c documents above csi_parse(); the
+ * constants here are offsets into that layout, not parameters.
+ */
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "mvsfmt.h"
+
+/** @brief Offsets in a CSI return work area (src/mvsfmt.c). */
+enum {
+ WORK = 4096, /**< size passed to csi_parse() */
+ USDLN = 8, /**< +8: bytes of return information used */
+ FIRST = 14, /**< offset of the first entry */
+ NAME = 2, /**< name, within an entry */
+ FIXED = 46, /**< flags, type and name */
+ RETINFO = 50, /**< an entry with 4 bytes of return information */
+ TOTAL = 12, /**< CSITOTLN with one 6-byte field */
+ VOLSER = 6, /**< bytes of that field */
+ EB_CATALOG = 0xf0, /**< type '0': a catalog entry, no name to list */
+ EB_CLUSTER = 0xc1, /**< type 'A': a non-VSAM data set */
+ EB_USER = 0xe4 /**< type 'U': a user catalog connector */
+};
+
+/** @brief Store a big-endian halfword. */
+static void put16(unsigned char *p, unsigned v) {
+ p[0] = (unsigned char)(v >> 8);
+ p[1] = (unsigned char)v;
+}
+
+/** @brief Store a big-endian fullword. */
+static void put32(unsigned char *p, unsigned long v) {
+ p[0] = (unsigned char)(v >> 24);
+ p[1] = (unsigned char)(v >> 16);
+ p[2] = (unsigned char)(v >> 8);
+ p[3] = (unsigned char)v;
+}
+
+/** @brief Store @p s blank-padded to @p n bytes, in EBCDIC. */
+static void put_field(unsigned char *p, const char *s, size_t n) {
+ size_t len = strlen(s) < n ? strlen(s) : n;
+ memset(p, 0x40, n); /* EBCDIC blanks, not converted */
+ memcpy(p, s, len);
+ mvs_to_ebcdic((char *)p, len);
+}
+
+/**
+ * @brief Append one entry with a VOLSER field.
+ * @param work The work area.
+ * @param off Offset to write at.
+ * @param type The EBCDIC CSI entry type byte.
+ * @param name The data set name.
+ * @return The offset after the entry.
+ */
+static size_t entry(unsigned char *work, size_t off, unsigned char type,
+ const char *name) {
+ unsigned char *e = work + off;
+ memset(e, 0, FIXED + TOTAL);
+ e[1] = type;
+ put_field(e + NAME, name, MVS_DSN_MAX);
+ put16(e + FIXED, TOTAL); /* CSITOTLN, counting itself */
+ put16(e + FIXED + 2, 0); /* reserved */
+ put16(e + FIXED + 4, VOLSER); /* length of the one field */
+ put_field(e + FIXED + 6, "TEST01", VOLSER);
+ return off + FIXED + TOTAL;
+}
+
+/** @brief What the listed entries came out as. */
+static int listed;
+static bool name_ok = true;
+static bool type_ok = true;
+
+/** @brief Called once per entry csi_parse() accepts. */
+static void check(const char *name, char type, void *arg) {
+ (void)arg;
+ listed++;
+ if (strcmp(name, "SYS1.TEST.PDS") != 0)
+ name_ok = false;
+ if (type != 'A')
+ type_ok = false;
+}
+
+int main(void) {
+ static unsigned char work[WORK];
+ size_t off = FIRST;
+ /* A data set, a user catalog connector and a catalog entry: only the
+ * first is a name to list. */
+ off = entry(work, off, EB_CLUSTER, "SYS1.TEST.PDS");
+ off = entry(work, off, EB_USER, "SYS1.UCAT");
+ memset(work + off, 0, RETINFO);
+ work[off + 1] = EB_CATALOG;
+ put_field(work + off + NAME, "CATALOG.TEST.MASTER", MVS_DSN_MAX);
+ off += RETINFO;
+ put32(work + USDLN, (unsigned long)off);
+ if (!csi_parse(work, WORK, check, NULL)) {
+ puts("csi_parse: malformed");
+ return 1;
+ }
+ printf("%d listed, type %s, name %s\n", listed, type_ok ? "ok" : "WRONG",
+ name_ok ? "ok" : "WRONG");
+ return listed == 1 && type_ok && name_ok ? 0 : 1;
+}
diff --git a/tests/zos/csi-parse.exp b/tests/zos/csi-parse.exp
new file mode 100644
index 0000000..351b301
--- /dev/null
+++ b/tests/zos/csi-parse.exp
@@ -0,0 +1,5 @@
+-- EBCDIC build
+1 listed, type ok, name ok
+-- ASCII build
+1 listed, type ok, name ok
+[status 0]
diff --git a/tests/zos/csi-parse.sh b/tests/zos/csi-parse.sh
new file mode 100644
index 0000000..5a79b5a
--- /dev/null
+++ b/tests/zos/csi-parse.sh
@@ -0,0 +1,16 @@
+# z/OS: csi_parse() decodes a Catalog Search Interface work area in both
+# character sets.
+#
+# The entry type byte is the point (notes/review-2026-11-27.md, item 12):
+# an ASCII build converts it from EBCDIC, an EBCDIC build must use it as it
+# is. Converting it twice made every entry arrive with the wrong type, which
+# only Tab completion ever noticed. The helpers are plain programs over
+# src/mvsfmt.c, built by the Makefile for both sets; each prints a verdict, so
+# one expectation serves both.
+tools=${TESTS:-.}/../build/zos-tools
+[ -x "$tools/csi" ] && [ -x "$tools/csi-ascii" ] || exit 77
+
+echo "-- EBCDIC build"
+"$tools/csi"
+echo "-- ASCII build"
+"$tools/csi-ascii"
diff --git a/tests/zos/tagging.exp b/tests/zos/tagging.exp
index e11d473..4a69c32 100644
--- a/tests/zos/tagging.exp
+++ b/tests/zos/tagging.exp
@@ -22,4 +22,8 @@ from-1047
from-819
from-819
untagged-1047
+-- binary output through a redirect
+stdout: same archive
+redirect: same archive
+text
[status 0]
diff --git a/tests/zos/tagging.sh b/tests/zos/tagging.sh
index 58315c1..7f254f8 100644
--- a/tests/zos/tagging.sh
+++ b/tests/zos/tagging.sh
@@ -9,10 +9,10 @@
# The shell's own CCSID is printed as "self" so that one .exp serves both
# builds: ISO8859-1 for an ASCII build, IBM-1047 for an EBCDIC build.
#
-# VERIFY: run on z/OS 3.1; the ls -T format is "t IBM-1047 T=on name".
-# An ASCII build writes IBM-1047 text through ">" with no tag variable set,
-# as /bin/sh does (src/sys_zos.c, tag_redir); DESIGN.md, "File tags", still
-# says the first writer's CCSID, which does not match the code yet.
+# Verified on z/OS 3.1; the ls -T format is "t IBM-1047 T=on name". An
+# ASCII build tags the file a ">" creates and converts its own writes to
+# IBM-1047, so the file holds what /bin/sh would have written (DESIGN.md,
+# "File tags and automatic conversion", has the table).
command -v chtag >/dev/null 2>&1 || exit 77
if [ "$(printf '\101')" = A ]; then self=ISO8859-1; else self=IBM-1047; fi
@@ -95,3 +95,16 @@ chtag -r u1047
"$TSH" s819
. ./s819
"$TSH" u1047
+
+echo "-- binary output through a redirect"
+# The tag and the conversion live on the descriptor, so a child inherits
+# both. A program that writes binary turns conversion off for its own
+# output, and the archive must then be the one /bin/sh's redirect makes.
+if command -v gzip >/dev/null 2>&1; then
+ /bin/sh -c 'gzip -c plain >g1'
+ "$TSH" -c 'gzip -c plain' >g2
+ "$TSH" -c 'gzip -c plain >g3'
+ cmp -s g1 g2 && echo "stdout: same archive"
+ cmp -s g1 g3 && echo "redirect: same archive"
+ gzip -dc g2 | head -n 1
+fi