NAME=dsc suffix entries with unused space after the array
FILE=malloc://2048
ARGS=-nw
CMDS=<<EOF
e log.level=1
wx 64796c645f7631202061726d36346500
wv4 0x208 @ 0x10
wv8 0x800 @ 0x28
wv4 0x240 @ 0x138
wv4 1 @ 0x13c
wv4 0x300 @ 0x188
wv4 1 @ 0x18c
wv4 0x680 @ 0x200
wx 0102030405060708090a0b0c0d0e0f10 @ 0x300
wx 2e6461746100 @ 0x318
wx 756e73657400 @ 0x350
wtf .tmp_dsc_suffix 2048
wv8 0x400 @ 0x28
wv4 0 @ 0x18c
wx 0102030405060708090a0b0c0d0e0f10 @ 0x58
wx 41424344 @ 0x380
wtf .tmp_dsc_suffix.data 1024
on dsc://.tmp_dsc_suffix
p8 4 @ 0xb80
o-*
rm .tmp_dsc_suffix
rm .tmp_dsc_suffix.data
EOF
EXPECT=<<EOF
41424344
EOF
RUN

NAME=dsc numbered subcaches with pre-cacheSubType header
FILE=malloc://2048
ARGS=-nw
CMDS=<<EOF
e log.level=1
wx 64796c645f7631202061726d36346500
wv4 0x1c8 @ 0x10
wv8 0x800 @ 0x28
wv4 0x240 @ 0x138
wv4 1 @ 0x13c
wv4 0x300 @ 0x188
wv4 2 @ 0x18c
wx 0102030405060708090a0b0c0d0e0f10 @ 0x300
wx 1112131415161718191a1b1c1d1e1f20 @ 0x318
wx 2f @ 0x330
wtf .tmp_dsc_v1 2048
wv8 0x400 @ 0x28
wv4 0 @ 0x18c
wx 0102030405060708090a0b0c0d0e0f10 @ 0x58
wx 31313131 @ 0x380
wtf .tmp_dsc_v1.1 1024
wx 1112131415161718191a1b1c1d1e1f20 @ 0x58
wx 32323232 @ 0x380
wtf .tmp_dsc_v1.2 1024
on dsc://.tmp_dsc_v1
p8 4 @ 0xb80
p8 4 @ 0xf80
o-*
rm .tmp_dsc_v1
rm .tmp_dsc_v1.1
rm .tmp_dsc_v1.2
EOF
EXPECT=<<EOF
31313131
32323232
EOF
RUN

NAME=dsc filter with a later header declaring more images
FILE=malloc://4096
ARGS=-nw
CMDS=<<EOF
e log.level=1
wx 64796c645f763120207838365f363400
wv4 0x200 @ 0x10
wv4 1 @ 0x14
wv4 0x220 @ 0x18
wv4 1 @ 0x1c
wv8 0x180000000 @ 0x20
wv8 0x800 @ 0x28
wv8 0x180000000 @ 0x200
wv8 0x800 @ 0x208
wv4 5 @ 0x218
wv4 5 @ 0x21c
wx 0006008001000000000000000000000000000000000000000005000000000000 @ 0x220
w /usr/lib/libobjc.A.dylib @ 0x500
wx cffaedfe0700000103000000060000000000000000000000 @ 0x600
wx 64796c645f763120207838365f363400 @ 0x800
wv4 0x200 @ 0x810
wv4 1 @ 0x814
wv4 0x220 @ 0x818
wv4 32 @ 0x81c
wv8 0x180000000 @ 0x820
wv8 0x800 @ 0x828
wv8 0x180000800 @ 0xa00
wv8 0x800 @ 0xa08
wv4 5 @ 0xa18
wv4 5 @ 0xa1c
b 1024
wX 000e008001000000000000000000000000000000000000000005000000000000 @ 0xa20
b 256
w /usr/lib/libobjc.A.dylib @ 0xd00
wx cffaedfe0700000103000000060000000000000000000000 @ 0xe00
wtf .tmp_dsc_filter 4096
%R_DYLDCACHE_FILTER=libsystem_c
o dsc://.tmp_dsc_filter
i~format
o-*
rm .tmp_dsc_filter
EOF
EXPECT=<<EOF
format   dyldcache
EOF
RUN


NAME=dsc rebase only the part of the read covered by the slide info
FILE=malloc://8192
ARGS=-nw
CMDS=<<EOF
e log.level=1
wx 64796c645f763120202061726d363400
wv4 0x70 @ 0x10
wv4 2 @ 0x14
wv8 0x100000 @ 0x28
wv8 0x200 @ 0x38
wv8 0x100 @ 0x40
wv8 0x1000 @ 0x78
wv8 0x10 @ 0x98
wv8 0x1000 @ 0xa0
wv4 2 @ 0x200
wv4 0x1000 @ 0x204
wv4 40 @ 0x208
wv4 1 @ 0x20c
wv8 0x00ff000000000000 @ 0x218
wv8 0x100000 @ 0x220
wv2 2 @ 0x228
wv8 0x0006000000001000 @ 0x1008
wv8 0x2000 @ 0x1020
wtf .tmp_dsc_rebase 8192
on dsc://.tmp_dsc_rebase
p8 40 @ 0x1000
p8 24 @ 0xff8
o-*
rm .tmp_dsc_rebase
EOF
EXPECT=<<EOF
00000000000000000010100000000000000000000000000000000000000000000020000000000000
000000000000000000000000000000000010100000000000
EOF
RUN


NAME=dsc slide info v2 pointer straddling the start of a read
FILE=malloc://2048
ARGS=-nw
CMDS=<<EOF
e log.level=1
wx 64796c645f763120202061726d363400
wv4 0x70 @ 0x10
wv4 2 @ 0x14
wv8 0x800 @ 0x28
wv8 0x200 @ 0x38
wv8 0x100 @ 0x40
wv8 0x180000000 @ 0x70
wv8 0x400 @ 0x78
wv8 0x180000400 @ 0x90
wv8 0x400 @ 0x98
wv8 0x400 @ 0xa0
wv4 2 @ 0x200
wv4 0x1000 @ 0x204
wv4 40 @ 0x208
wv4 1 @ 0x20c
wv8 0x00ffff0000000000 @ 0x218
wv8 0x1000 @ 0x220
wv8 0x0000010000000000 @ 0x400
wv8 0x0000020000000100 @ 0x404
wv8 0x55 @ 0x40c
wtf .tmp_dsc_slide2 2048
on dsc://.tmp_dsc_slide2
b 16
p8 16 @ 0x408
o-*
rm .tmp_dsc_slide2
EOF
EXPECT=<<EOF
00020000551000000000000000000000
EOF
RUN

NAME=dsc slide info v2 chain going backwards
FILE=malloc://2048
ARGS=-nw
CMDS=<<EOF
e log.level=1
wx 64796c645f763120202061726d363400
wv4 0x70 @ 0x10
wv4 2 @ 0x14
wv8 0x800 @ 0x28
wv8 0x200 @ 0x38
wv8 0x100 @ 0x40
wv8 0x180000000 @ 0x70
wv8 0x400 @ 0x78
wv8 0x180000400 @ 0x90
wv8 0x400 @ 0x98
wv8 0x400 @ 0xa0
wv4 2 @ 0x200
wv4 0x1000 @ 0x204
wv4 40 @ 0x208
wv4 1 @ 0x20c
wv8 0xfffffffffffffffc @ 0x218
wv2 2 @ 0x228
wv8 0xfffffffffffffffc @ 0x408
wtf .tmp_dsc_back 2048
on dsc://.tmp_dsc_back
b 16
p8 16 @ 0x408
o-*
rm .tmp_dsc_back
EOF
EXPECT=<<EOF
00000000000000000000000000000000
EOF
RUN

NAME=dsc slide info v1 read shorter than a pointer
FILE=malloc://2048
ARGS=-nw
CMDS=<<EOF
e log.level=1
wx 64796c645f763120202061726d363400
wv4 0x70 @ 0x10
wv4 2 @ 0x14
wv8 0x800 @ 0x28
wv8 0x200 @ 0x38
wv8 0x100 @ 0x40
wv8 0x180000000 @ 0x70
wv8 0x400 @ 0x78
wv8 0x180000400 @ 0x90
wv8 0x400 @ 0x98
wv8 0x400 @ 0xa0
wv4 1 @ 0x200
wv4 24 @ 0x204
wv4 1 @ 0x208
wv4 32 @ 0x20c
wv4 1 @ 0x210
wv4 128 @ 0x214
wx ff @ 0x220
wx 41424344 @ 0x400
wtf .tmp_dsc_slide1 2048
on dsc://.tmp_dsc_slide1
b 4
p8 4 @ 0x400
o-*
rm .tmp_dsc_slide1
EOF
EXPECT=<<EOF
41424344
EOF
RUN

NAME=dsc slide info v2 chain looping before the read
FILE=malloc://2048
TIMEOUT=10
ARGS=-nw
CMDS=<<EOF
e log.level=1
wx 64796c645f763120202061726d363400
wv4 0x70 @ 0x10
wv4 2 @ 0x14
wv8 0x800 @ 0x28
wv8 0x200 @ 0x38
wv8 0x100 @ 0x40
wv8 0x180000000 @ 0x70
wv8 0x400 @ 0x78
wv8 0x180000400 @ 0x90
wv8 0x400 @ 0x98
wv8 0x400 @ 0xa0
wv4 2 @ 0x200
wv4 0x1000 @ 0x204
wv4 40 @ 0x208
wv4 1 @ 0x20c
wv8 0xfffffffffffffffc @ 0x218
wv8 8 @ 0x400
wv8 0xfffffffffffffff8 @ 0x408
wv8 0x55 @ 0x410
wtf .tmp_dsc_loop 2048
on dsc://.tmp_dsc_loop
b 16
p8 16 @ 0x410
o-*
rm .tmp_dsc_loop
EOF
EXPECT=<<EOF
55000000000000000000000000000000
EOF
RUN

NAME=dsc mapping entries sharing one slide info are bounded by the file size
FILE=dsc://bins/dsc/shared-slide-info
ARGS=-n
CMDS=<<EOF
p8 8
EOF
EXPECT=<<EOF
64796c645f763120
EOF
EXPECT_ERR=<<EOF
ERROR: Slide infos are larger than the cache file
EOF
RUN

NAME=dsc concatenated headers sharing one slide info are bounded by the file size
FILE=dsc://bins/dsc/legacy-shared-slide-info
ARGS=-n
CMDS=<<EOF
p8 8
EOF
EXPECT=<<EOF
64796c645f763120
EOF
EXPECT_ERR=<<EOF
ERROR: Slide infos are larger than the cache file
EOF
RUN

NAME=dsc subcache naming the cache itself is rejected
FILE=-
CMDS=<<EOF
o dsc://bins/dsc/self-subcache
EOF
EXPECT=
EXPECT_ERR=<<EOF
ERROR: Subcache bins/dsc/self-subcache is already loaded
ERROR: Cannot open file dsc://bins/dsc/self-subcache
EOF
RUN
