llvm.org GIT mirror llvm / 6f45ec0
[llvm-ar][test] Add to llvm-ar test coverage This change adds tests to cover existing llvm-ar functionality. print.test is omitted due to failing on Darwin. Differential Revision: https://reviews.llvm.org/D64330 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366209 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Reynolds 2 months ago
3 changed file(s) with 252 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 ## Test the move command without modifiers moves members to the end
1
2 # RUN: rm -rf %t && mkdir -p %t
3 # RUN: yaml2obj %s -o %t/1.o --docnum=1
4 # RUN: yaml2obj %s -o %t/2.o --docnum=2
5 # RUN: yaml2obj %s -o %t/3.o --docnum=3
6
7 ## Move single member:
8 # RUN: llvm-ar rc %t/single.a %t/1.o %t/2.o %t/3.o
9 # RUN: llvm-ar m %t/single.a %t/1.o
10 # RUN: llvm-ar t %t/single.a \
11 # RUN: | FileCheck %s --check-prefix=SINGLE --match-full-lines --implicit-check-not {{.}}
12
13 # SINGLE: 2.o
14 # SINGLE-NEXT: 3.o
15 # SINGLE-NEXT: 1.o
16
17 # RUN: llvm-nm --print-armap %t/single.a \
18 # RUN: | FileCheck %s --check-prefix=SINGLE-SYM
19
20 # SINGLE-SYM: symbol2
21 # SINGLE-SYM-NEXT: symbol3
22 # SINGLE-SYM-NEXT: symbol1
23
24 ## Move multiple members:
25 # RUN: llvm-ar rc %t/multiple.a %t/1.o %t/2.o %t/3.o
26 # RUN: llvm-ar m %t/multiple.a %t/1.o %t/2.o
27 # RUN: llvm-ar t %t/multiple.a \
28 # RUN: | FileCheck %s --check-prefix=MULTIPLE --match-full-lines --implicit-check-not {{.}}
29
30 # MULTIPLE: 3.o
31 # MULTIPLE-NEXT: 1.o
32 # MULTIPLE-NEXT: 2.o
33
34 # RUN: llvm-nm --print-armap %t/multiple.a \
35 # RUN: | FileCheck %s --check-prefix=MULTIPLE-SYM
36
37 # MULTIPLE-SYM: symbol3
38 # MULTIPLE-SYM-NEXT: symbol1
39 # MULTIPLE-SYM-NEXT: symbol2
40
41 ## Move same member:
42 # RUN: llvm-ar rc %t/same.a %t/1.o %t/2.o %t/3.o
43 # RUN: llvm-ar m %t/same.a %t/1.o %t/1.o
44 # RUN: llvm-ar t %t/same.a \
45 # RUN: | FileCheck %s --check-prefix=SAME -DFILE=%t/2.o
46
47 # SAME: 2.o
48 # SAME-NEXT: 3.o
49 # SAME-NEXT: 1.o
50
51 # RUN: llvm-nm --print-armap %t/same.a \
52 # RUN: | FileCheck %s --check-prefix=SAME-SYM
53
54 # SAME-SYM: symbol2
55 # SAME-SYM-NEXT: symbol3
56 # SAME-SYM-NEXT: symbol1
57
58 ## Move without member:
59 # RUN: llvm-ar rc %t/without.a %t/1.o %t/2.o %t/3.o
60 # RUN: llvm-ar m %t/without.a
61 # RUN: llvm-ar t %t/without.a \
62 # RUN: | FileCheck %s --match-full-lines --check-prefix=WITHOUT --implicit-check-not {{.}}
63
64 # WITHOUT: 1.o
65 # WITHOUT-NEXT: 2.o
66 # WITHOUT-NEXT: 3.o
67
68 # RUN: llvm-nm --print-armap %t/without.a \
69 # RUN: | FileCheck %s --check-prefix=WITHOUT-SYM
70
71 # WITHOUT-SYM: symbol1
72 # WITHOUT-SYM-NEXT: symbol2
73 # WITHOUT-SYM-NEXT: symbol3
74
75 ## No archive:
76 # RUN: not llvm-ar m 2>&1 \
77 # RUN: | FileCheck %s --check-prefix=NO-ARCHIVE
78
79 # NO-ARCHIVE: error: An archive name must be specified.
80
81 ## Member does not exist:
82 # RUN: llvm-ar rc %t/missing.a %t/1.o %t/2.o %t/3.o
83 # RUN: not llvm-ar m %t/missing.a %t/missing.txt 2>&1 \
84 # RUN: | FileCheck %s --check-prefix=MISSING-FILE -DFILE=%t/missing.txt
85
86 # MISSING-FILE: error: [[FILE]]: {{[nN]}}o such file or directory.
87
88 --- !ELF
89 FileHeader:
90 Class: ELFCLASS64
91 Data: ELFDATA2LSB
92 Type: ET_REL
93 Machine: EM_X86_64
94 Sections:
95 - Name: .text
96 Type: SHT_PROGBITS
97 Symbols:
98 - Name: symbol1
99 Binding: STB_GLOBAL
100 Section: .text
101
102 --- !ELF
103 FileHeader:
104 Class: ELFCLASS64
105 Data: ELFDATA2LSB
106 Type: ET_REL
107 Machine: EM_X86_64
108 Sections:
109 - Name: .text
110 Type: SHT_PROGBITS
111 Symbols:
112 - Name: symbol2
113 Binding: STB_GLOBAL
114 Section: .text
115
116 --- !ELF
117 FileHeader:
118 Class: ELFCLASS64
119 Data: ELFDATA2LSB
120 Type: ET_REL
121 Machine: EM_X86_64
122 Sections:
123 - Name: .text
124 Type: SHT_PROGBITS
125 Symbols:
126 - Name: symbol3
127 Binding: STB_GLOBAL
128 Section: .text
0 ## Test quick append
1
2 # RUN: rm -rf %t && mkdir -p %t
3 # RUN: yaml2obj %s -o %t/1.o --docnum=1
4 # RUN: yaml2obj %s -o %t/2.o --docnum=2
5
6 ## Append single member:
7 # RUN: llvm-ar qc %t/single.a %t/1.o
8 # RUN: llvm-ar t %t/single.a \
9 # RUN: | FileCheck %s --check-prefix=SINGLE --match-full-lines --implicit-check-not {{.}}
10
11 # SINGLE: 1.o
12
13 # RUN: llvm-nm --print-armap %t/single.a \
14 # RUN: | FileCheck %s --check-prefix=SINGLE-SYM
15
16 # SINGLE-SYM: symbol1
17
18 ## Append multiple members:
19 # RUN: llvm-ar qc %t/multiple.a %t/1.o %t/2.o
20 # RUN: llvm-ar t %t/multiple.a \
21 # RUN: | FileCheck %s --check-prefix=MULTIPLE --match-full-lines --implicit-check-not {{.}}
22
23 # MULTIPLE: 1.o
24 # MULTIPLE-NEXT: 2.o
25
26 # RUN: llvm-nm --print-armap %t/multiple.a \
27 # RUN: | FileCheck %s --check-prefix=MULTIPLE-SYM
28
29 # MULTIPLE-SYM: symbol1
30 # MULTIPLE-SYM-NEXT: symbol2
31
32 ## Append same member:
33 # RUN: llvm-ar qc %t/same.a %t/1.o %t/1.o
34 # RUN: llvm-ar t %t/same.a \
35 # RUN: | FileCheck %s --check-prefix=SAME -DFILE=%t/2.o --match-full-lines --implicit-check-not {{.}}
36
37 # SAME: 1.o
38 # SAME-NEXT: 1.o
39
40 # RUN: llvm-nm --print-armap %t/same.a \
41 # RUN: | FileCheck %s --check-prefix=SAME-SYM
42
43 # SAME-SYM: symbol1
44 # SAME-SYM-NEXT: symbol1
45
46 ## Append without member:
47 # RUN: llvm-ar qc %t/without.a
48 # RUN: llvm-ar t %t/without.a \
49 # RUN: | FileCheck /dev/null --allow-empty --implicit-check-not={{.}}
50
51 # RUN: llvm-nm --print-armap %t/without.a \
52 # RUN: | FileCheck /dev/null --allow-empty --implicit-check-not={{.}}
53
54 ## No archive:
55 # RUN: not llvm-ar qc 2>&1 \
56 # RUN: | FileCheck %s --check-prefix=NO-ARCHIVE
57
58 # NO-ARCHIVE: error: An archive name must be specified.
59
60 ## Member does not exist:
61 # RUN: not llvm-ar qc %t/missing.a %t/missing.txt 2>&1 \
62 # RUN: | FileCheck %s --check-prefix=MISSING-FILE -DFILE=%t/missing.txt
63
64 # MISSING-FILE: error: [[FILE]]: {{[nN]}}o such file or directory.
65
66 --- !ELF
67 FileHeader:
68 Class: ELFCLASS64
69 Data: ELFDATA2LSB
70 Type: ET_REL
71 Machine: EM_X86_64
72 Sections:
73 - Name: .text
74 Type: SHT_PROGBITS
75 Symbols:
76 - Name: symbol1
77 Binding: STB_GLOBAL
78 Section: .text
79
80 --- !ELF
81 FileHeader:
82 Class: ELFCLASS64
83 Data: ELFDATA2LSB
84 Type: ET_REL
85 Machine: EM_X86_64
86 Sections:
87 - Name: .text
88 Type: SHT_PROGBITS
89 Symbols:
90 - Name: symbol2
91 Binding: STB_GLOBAL
92 Section: .text
0 ## Test that read-only archives cannot be edited
1
2 # RUN: rm -rf %t && mkdir -p %t
3 # RUN: touch %t/1.txt
4 # RUN: touch %t/2.txt
5 # RUN: touch %t/3.txt
6
7 # RUN: llvm-ar rc %t/archive.a %t/1.txt %t/2.txt
8
9 ## Make read only:
10 # RUN: chmod 444 %t/archive.a
11
12 # RUN: not llvm-ar r %t/archive.a %t/3.txt \
13 # RUN: FileCheck %s --check-prefix=ERROR -DFILE=%t/archive.a
14
15 # ERROR: error: [[FILE]]: no such file or directory.
16
17 # RUN: not llvm-ar q %t/archive.a %t/3.txt \
18 # RUN: FileCheck %s --check-prefix=ERROR -DFILE=%t/archive.a
19
20 # RUN: not llvm-ar m %t/archive.a t/1.txt \
21 # RUN: FileCheck %s --check-prefix=ERROR-2 -DFILE=%t/archive.a
22
23 # ERROR-2: error: [[FILE]]: permission denied.
24
25 # RUN: llvm-ar t %t/archive.a \
26 # RUN: | FileCheck %s --check-prefix=ARCHIVE --match-full-lines --implicit-check-not {{.}}
27
28 # ARCHIVE: 1.txt
29 # ARCHIVE-NEXT: 2.txt