File: cdi.bats

package info (click to toggle)
charliecloud 0.43-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,116 kB
  • sloc: python: 6,021; sh: 4,284; ansic: 3,863; makefile: 598
file content (266 lines) | stat: -rw-r--r-- 7,775 bytes parent folder | download
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
load ../common
tag=CDI

setup () {
    [[ $ch_libc = glibc ]] || skip 'glibc only'
    nvidia_json=$BATS_TMPDIR/nvidia.json
    warn_tag='warning'
    if command -v nvidia-smi > /dev/null; then
        have_nvidia_smi=yes
    fi
    if command -v nvidia-ctk > /dev/null; then
        have_nvidia_ctk=yes
    fi
    if [[ -f /proc/driver/nvidia/version ]]; then
        have_nvidia_driver=yes
    fi
    if [[ $have_nvidia_smi && $have_nvidia_ctk && $have_nvidia_driver ]]; then
        have_nvidia=yes
    fi
}

glibc_version_ok () {
    # glibc 2.34 and later are incompatible with older versions, i.e.,
    # binaries built on a host with glibc ≥ 2.34 cannot run in a container
    # with < 2.34. See #1430 & https://news.ycombinator.com/item?id=32479545.
    host=$(ldd --version | grep -oE '[0-9.]+[^.]$')
    guest=$(ch-run "$1" -- ldd --version | grep -oE '[0-9.]+[^.]$')
    # Check version compatibility. If host glibc ≥ 2.34 and guest glibc < 2.34,
    # skip the test.
    if [[    $(printf "%s\n2.34" "$host"  | sort -V | head -1)  = 2.34 \
          && $(printf "%s\n2.34" "$guest" | sort -V | head -1) != 2.34 ]]; then
        pedantic_fail "glibc: host $host ≥ 2.34 > guest $guest"
    fi
}

img_use () {
    export LC_ALL=C  # target image has no locales
    name=$1
    img="${CH_TEST_IMGDIR}/${name}"
    echo "img: $name ($img)"
    if [[ ! -e $img ]]; then
        skip "image not found: $img"
    fi
    prerequisites_ok "$img"
    glibc_version_ok "$img"
    bb=/ch/cdim/$(echo "$PWD" | tr '/' '_')_sotest  # varies by install path
    echo "bind base: ${bb}"
}

nvidia_ok () {
    [[ $have_nvidia ]] || skip 'nVidia driver & user-space required'
}


@test "$tag: generate nvidia.json" {
    scope standard
    nvidia_ok

    nvidia-ctk cdi generate --output "$nvidia_json"
    printf 'wrote %s\n' "$nvidia_json"
    printf 'found CDI version: '
    sed -En 's/^.+"cdiVersion"\s*:\s*"([0-9.]+).+$/\1/p' < "$nvidia_json"
}


@test "$tag: Debian: file locations" {
    scope standard
    img_use debian_12ch

    # nothing on the host image
    if [[ $CH_TEST_PACK_FMT == *-unpack ]]; then
        test -e "${img}/ch/cdim" && exit 1
        [[ 0 = $(find "$img" -xdev -name '*sotest*' -printf . | wc -c) ]]
    fi

    printf '\n*** guest files\n'
    run ch-run --cdi=./sotest/cdi.json "$img" -- \
          find / -xdev -name "*sotest*" -printf "%y: %p -> %l\n"
    echo "$output"
    [[ $status -eq 0 ]]
    files=$(echo "$output" | grep -Fv "$warn_tag" | sed -E 's/ -> $//' | sort)
    #echo '-- actual file list --'
    #echo "$files"
    files_blessed=$(cat <<EOF
d: ${bb}_bin
d: ${bb}_lib
d: ${bb}_lib_libfabric
l: /usr/bin/sotest -> ${bb}_bin/sotest
l: /usr/lib/libfabric/libsotest.so.1.0 -> ${bb}_lib_libfabric/libsotest-fi.so
l: /usr/lib/libsotest.so.1 -> libsotest.so.1.0
l: /usr/lib/libsotest.so.1.0 -> ${bb}_lib/libsotest.so.1.0
EOF
)
    #echo '-- diff vs. expected --'
    diff -u <(echo "$files_blessed") <(echo "$files")
}


@test "$tag: Debian: sotest: file path" {
    scope standard
    img_use debian_12ch

    run ch-run --cdi=./sotest/cdi.json "$img" -- sotest
    echo "$output"
    [[ $status -eq 0 ]]
    out_blessed=$(cat <<'EOF'
libsotest says 8675308 incremented is 8675309
EOF
)
    diff -u <(echo "$out_blessed") <(echo "$output" | grep -Fv "$warn_tag")
}


@test "$tag: Debian: sotest: all resources" {
    scope standard
    img_use debian_12ch

    # command line option
    ch-run -d -v --cdi-dirs=./sotest "$img" -- sotest

    # environment variable
    export CH_RUN_CDI_DIRS=$PWD/sotest
    ch-run -d "$img" -- sotest
}


@test "$tag: Debian: sotest: by kind" {
    scope standard
    img_use debian_12ch
    export CH_RUN_CDI_DIRS=$PWD/sotest:/doesnotexist  # see #2065

    for kind in weird/al weird/al=all; do
        run ch-run -v --cdi="$kind" "$img" -- sotest
        echo "$output"
        [[ $status -eq 0 ]]
        [[ $output = *"CDI: looking for resource files in: $PWD/sotest"* ]]
        [[ $output = *"CDI: spec read OK: weird/al: $PWD/sotest/cdi.json"* ]]
        [[ $output = *"CDI: directory not found, skipping: /doesnotexist"* ]]
    done
}


@test "$tag: Debian: sotest: no specs found" {
    scope standard
    img_use debian_12ch

    printf '\n*** file: not found\n'
    run ch-run -v --cdi=/doesnotexist.json "$img" -- sotest
    echo "$output"
    [[ $status -eq $CH_ERR_MISC ]]
    [[ $output = *"error: can't stat CDI resource file: /doesnotexist.json"* ]]

    printf '\n*** kind: resource files found but not what we wanted\n'
    run ch-run -v --cdi-dirs="$PWD/sotest" --cdi=doesnot/exist "$img" -- sotest
    echo "$output"
    [[ $status -eq $CH_ERR_MISC ]]
    [[ $output = *'error: CDI: no matching resources found'* ]]

    printf '\n*** kind: CDI directories don’t exist\n'
    run ch-run -v --cdi-dirs=/nope1:/nope2 --cdi=doesnot/exist "$img" -- sotest
    echo "$output"
    [[ $status -eq $CH_ERR_MISC ]]
    [[ $output = *'error: CDI: no directories found: /nope1:/nope2'* ]]

    printf '\n*** kind: CDI directories have no resource files\n'
    run ch-run -v --cdi-dirs=/usr/bin --cdi=doesnot/exist "$img" -- sotest
    echo "$output"
    [[ $status -eq $CH_ERR_MISC ]]
    [[ $output = *'error: CDI: no resource files found: /usr/bin'* ]]

    printf '\n*** all: CDI directories don’t exist\n'
    run ch-run -v --cdi --cdi-dirs=/nope1:/nope2 "$img" -- sotest
    echo "$output"
    [[ $status -eq $CH_ERR_MISC ]]
    [[ $output = *'error: CDI: no directories found: /nope1:/nope2'* ]]

    printf '\n*** kind: CDI directories have no resource files\n'
    run ch-run -v --cdi --cdi-dirs=/usr/bin "$img" -- sotest
    echo "$output"
    [[ $status -eq $CH_ERR_MISC ]]
    [[ $output = *'error: CDI: no resource files found: /usr/bin'* ]]
}


@test "$tag: warnings" {
    scope standard
    img_use debian_12ch

    run ch-run --cdi=./sotest/cdi.json "$img" -- true
    echo "$output"
    [[ $status -eq 0 ]]
    out_blessed=$(cat <<'EOF'
ch-run[XXX]: warning: CDI: ignoring unknown hook: createContainer: unknown-hook (json.c:YYY)
ch-run[XXX]: warning: CDI: ignoring non-bind mount: /dev/sda -> /mnt/sda (json.c:YYY)
EOF
)
    diff -u <(echo "$out_blessed") \
            <(  echo "$output" \
              | grep -F "$warn_tag" \
              | sed -E -e 's/\[[0-9]+\]/[XXX]/g' \
                       -e 's/:[0-9]+\)$/:YYY)/g' \
                       -e '/reprinting first/,$d' )
}


@test "$tag: with --seccomp" {
    scope standard
    img_use debian_12ch
    ch-run --seccomp --cdi=./sotest/cdi.json "$img" -- sotest
}


@test "$tag: nvidia.json: no warnings" {
    scope standard
    img_use debian_12ch
    nvidia_ok

    run ch-run -v --cdi="$nvidia_json" "$img" -- true
    echo "$output"
    [[ $output == *'spec read OK'* ]]
    [[ $output != *'warning'* ]]
}


@test "$tag: nvidia-smi" {
    scope standard
    img_use debian_12ch
    nvidia_ok

    host_output=$(nvidia-smi -L)
    echo "host nvidia-smi(1):"
    echo "$host_output"

    run ch-run --cdi="$nvidia_json" "$img" -- nvidia-smi -L
    echo "guest nvidia-smi(1):"
    echo "$output"
    [[ $status -eq 0 ]]
    echo "diff:"
    diff -u <(echo "$host_output") <(echo "$output")
}


@test "$tag: matrixMulCUBLAS" {
    scope standard
    img_use nvidia
    nvidia_ok
    export CH_RUN_CDI_DIRS=$BATS_TMPDIR

    # Without CDI: failure.
    run ch-run "$img" -- matrixMulCUBLAS
    echo "$output"
    [[ $status -ne 0 ]]
    [[ $output = *'CUDA error at'*'cudaGetDeviceCount'* ]]

    # With CDI: runs OK and output looks OK.
    run ch-run -d "$img" -- matrixMulCUBLAS
    echo "$output"
    [[ $status -eq 0 ]]
    [[ $output = *'GPU Device 0'* ]]
    [[ $output = *'Comparing CUBLAS Matrix Multiply with CPU results: PASS'* ]]
}


# FIXME: errors
# FIXME: AlmaLinux
# FIXME: multi-GPU