summaryrefslogtreecommitdiffhomepage
path: root/tests/zos/datasets.sh
blob: 02d75358e61c87b3623a7913da89bc42dbef75ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# z/OS: moving data between the shell and MVS data sets.
#
# Needs tso(1) (TSO/E from the shell) and a high-level qualifier the user
# may create data sets under: ZASH_TEST_HLQ, else the user ID.  Skipped
# (status 77) when tso is not available.  Everything created is deleted
# at the end, also when the test fails part way.
#
# zash does not open data sets itself; this checks that data flows
# correctly between the shell and the z/OS utilities that do: quoting of
# //'DSN(MEMBER)' names, exit statuses, pipes, here-documents, and large
# amounts of data.
#
# VERIFY: written from the z/OS UNIX Command Reference and not yet run.
# In particular: cp -T into and out of fixed-length records (trailing
# blanks), cp reading /dev/fd/0, and the exact LISTDS output.
command -v tso >/dev/null 2>&1 || exit 77
hlq=${ZASH_TEST_HLQ:-$(id -un | tr '[:lower:]' '[:upper:]')}
q=Z$(($$ % 9999999))
pds=$hlq.ZASHTEST.$q
seq=$hlq.ZASHTEST.$q.SEQ
cleanup() {
    tso -t "DELETE '$pds'" >/dev/null 2>&1
    tso -t "DELETE '$seq'" >/dev/null 2>&1
}
trap cleanup EXIT

# Allocate a PDS of 80-byte records and a sequential data set.
tso -t "ALLOCATE DATASET('$pds') NEW CATALOG TRACKS SPACE(5,5) DIR(10) RECFM(F,B) LRECL(80) BLKSIZE(3120) DSORG(PO)" >/dev/null 2>&1
echo "allocate pds: $?"
tso -t "FREE DATASET('$pds')" >/dev/null 2>&1
tso -t "ALLOCATE DATASET('$seq') NEW CATALOG TRACKS SPACE(5,5) RECFM(V,B) LRECL(255) BLKSIZE(3120) DSORG(PS)" >/dev/null 2>&1
echo "allocate seq: $?"
tso -t "FREE DATASET('$seq')" >/dev/null 2>&1

# 1. A file into a member and back.  Fixed records come back padded to
#    80 bytes, so trailing blanks are stripped before comparing.
printf 'line one\nline two\n' >src
cp -T src "//'$pds(MEM1)'"
echo "cp file to member: $?"
cp -T "//'$pds(MEM1)'" back
echo "cp member to file: $?"
sed 's/ *$//' back

# 2. The data set name in a variable, with the quotes inside the value.
dsn="//'$pds(MEM2)'"
printf 'from a variable\n' >src2
cp -T src2 "$dsn" && cp -T "$dsn" back2 && sed 's/ *$//' back2

# 3. Piping into a member: a pipeline feeds cp through /dev/fd/0.
printf 'piped %s\n' a b c | tr a-z A-Z | cp -T /dev/fd/0 "//'$pds(PIPED)'"
echo "pipe to member: $?"
cp -T "//'$pds(PIPED)'" /dev/fd/1 | sed 's/ *$//'

# 4. A here-document into a member, then the member into a pipeline.
cp -T /dev/fd/0 "//'$pds(HERE)'" <<EOF
$hlq is the owner
$((6 * 7)) is computed by the shell
EOF
cp -T "//'$pds(HERE)'" /dev/fd/1 | sed 's/ *$//' | sed "s/^$hlq /HLQ /"

# 5. A member read into a variable with command substitution.
v=$(cp -T "//'$pds(MEM1)'" /dev/fd/1 | sed 's/ *$//')
echo "lines in variable: $(printf '%s\n' "$v" | wc -l | tr -d ' ')"

# 6. Many records through a pipe into a sequential data set and back.
awk 'BEGIN { for (i = 1; i <= 5000; i++) printf "record %05d\n", i }' |
    cp -T /dev/fd/0 "//'$seq'"
echo "5000 records to seq: $?"
cp -T "//'$seq'" /dev/fd/1 | wc -l | tr -d ' '
cp -T "//'$seq'" /dev/fd/1 | tail -n 1

# 7. The members are there.  LISTDS is an authorized command where RACF
#    profiles TSO commands and then does not run at all, so copy each
#    member out instead of asking the catalog.
for m in MEM1 MEM2 PIPED HERE; do
    cp -T "//'$pds($m)'" "got-$m" 2>/dev/null && echo "$m"
done | wc -l | tr -d ' '

# 8. Failures come back as non-zero statuses.
cp -T "//'$pds(NOSUCH)'" x 2>/dev/null
[ $? -ne 0 ] && echo "missing member fails"
cp -T src "//'$hlq.ZASHTEST.NOT.ALLOCATED.$q'" 2>/dev/null
tso -t "DELETE '$hlq.ZASHTEST.NOT.ALLOCATED.$q'" >/dev/null 2>&1
tso -t "LISTDS 'NO.SUCH.DATASET.$q'" >/dev/null 2>&1
[ $? -ne 0 ] && echo "tso failure status"

# 9. A shell redirection from a data set name is an ordinary path to
#    zash (native data set redirection is not implemented yet): it fails
#    cleanly.  Reading, not writing, so that a superuser running the test
#    cannot create a stray file in /.
(cat <"//'$pds(MEM1)'") 2>/dev/null
echo "redirection from a data set name: $?"