blob: 0e390183f8d0081f9f0a2084b39f86c26621a740 [file] [edit]
## Test writing a z/OS archive.
# RUN: rm -rf %t.dir %t.a %t.odd.a %t.long.a %t.sym.a %t.blank-sym.a && mkdir -p %t.dir
# RUN: split-file %s %t.dir
## Create a z/OS archive from a plain text file with symbol table writing disabled.
# RUN: printf 'abcd' > %t.dir/test.txt
# RUN: llvm-ar rcSD --format=zos %t.a %t.dir/test.txt
## The archive should be written and read back successfully through llvm-ar.
# RUN: llvm-ar t %t.a | FileCheck %s --check-prefix=LIST
# RUN: llvm-ar p %t.a test.txt | FileCheck %s --check-prefix=CONTENT
## Check raw bytes:
## - The first 8 bytes are the z/OS archive magic in EBCDIC.
## - Bytes 66..67 are the first member header terminator (`\n in EBCDIC => 79 15).
# RUN: %python -c "d=open(r'%t.a','rb').read(); print(d[:8].hex()); print(d[66:68].hex())" | FileCheck %s --check-prefix=BYTES
# LIST: test.txt
# CONTENT: abcd
# BYTES: 5a4c819983886e15
# BYTES-NEXT: 7915
## Odd-sized members should be padded with EBCDIC newline (0x15).
# RUN: printf 'abc' > %t.dir/odd.txt
# RUN: llvm-ar rcSD --format=zos %t.odd.a %t.dir/odd.txt
# RUN: %python -c "d=open(r'%t.odd.a','rb').read(); print(f'{d[-1]:02x}')" | FileCheck %s --check-prefix=PAD
# PAD: 15
## Long member names should use their exact byte length and be read back
## correctly. The 25-byte name plus the 3-byte contents is already even-sized,
## so the archive should not contain a trailing padding byte.
# RUN: printf 'xyz' > %t.dir/very_long_member_name.txt
# RUN: llvm-ar rcSD --format=zos %t.long.a %t.dir/very_long_member_name.txt
# RUN: llvm-ar t %t.long.a | FileCheck %s --check-prefix=LONG-LIST
# RUN: llvm-ar p %t.long.a very_long_member_name.txt | FileCheck %s --check-prefix=LONG-CONTENT
# RUN: %python -c "d=open(r'%t.long.a','rb').read(); print(d[8:24].decode('cp037').strip()); print(len(d))" | FileCheck %s --check-prefix=LONG-BYTES
# LONG-LIST: very_long_member_name.txt
# LONG-CONTENT: xyz
# LONG-BYTES: #1/25
# LONG-BYTES-NEXT: 96
## Use LLVM bitcode here so the test remains target-independent. The archive
## writer only needs a symbolic input in order to emit the archive symbol table.
## A z/OS archive with real symbols should write a readable symbol table.
# RUN: llvm-as %t.dir/mytest.ll -o %t.dir/mytest.bc
# RUN: llvm-ar rcD --format=zos %t.sym.a %t.dir/mytest.bc
# RUN: llvm-nm --print-armap %t.sym.a | FileCheck %s --check-prefix=SYMTAB
# SYMTAB: Archive map
# SYMTAB-NEXT: mytest in mytest.bc
# SYMTAB-NOT: in mytest.bc
## A z/OS archive with no real symbols should still write the dummy blank symbol.
# RUN: llvm-as %t.dir/blank.ll -o %t.dir/blank.bc
# RUN: llvm-ar rcD --format=zos %t.blank-sym.a %t.dir/blank.bc
# RUN: llvm-nm --print-armap %t.blank-sym.a | FileCheck %s --check-prefix=EMPTY-SYMTAB
# EMPTY-SYMTAB: Archive map
# EMPTY-SYMTAB-NEXT: in blank.bc
# EMPTY-SYMTAB-NOT: in blank.bc
#--- mytest.ll
define i32 @mytest() {
entry:
ret i32 87
}
#--- blank.ll
source_filename = "blank.ll"