Skip to content

Commit 247add6

Browse files
author
Owen Reynolds
committed
[llvm-ar][test] Add coverage for replace and update key letters
Some more tests to increase llvm-ar test coverage, this time for replace 'r' and update 'u'. Differential Revision: https://reviews.llvm.org/D64803 llvm-svn: 366309
1 parent 37e403d commit 247add6

File tree

2 files changed

+367
-0
lines changed

2 files changed

+367
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
## Test that the replace command with "u" updates the relevant members.
2+
3+
# RUN: rm -rf %t && mkdir -p %t/new/other
4+
5+
# RUN: yaml2obj %s -o %t/1.o --docnum=1
6+
# RUN: yaml2obj %s -o %t/2.o --docnum=2
7+
# RUN: yaml2obj %s -o %t/3.o --docnum=3
8+
9+
# RUN: env TZ=GMT touch -t 200001020304 %t/1.o
10+
# RUN: env TZ=GMT touch -t 200001020304 %t/2.o
11+
# RUN: env TZ=GMT touch -t 200001020304 %t/3.o
12+
13+
# RUN: yaml2obj %s -o %t/new/1.o --docnum=4
14+
# RUN: yaml2obj %s -o %t/new/3.o --docnum=5
15+
16+
# RUN: yaml2obj %s -o %t/new/other/1.o --docnum=6
17+
18+
# RUN: env TZ=GMT touch -t 200001020304 %t/new/other/1.o
19+
20+
## Replace single member with newer file:
21+
# RUN: llvm-ar rcU %t/single.a %t/1.o %t/2.o %t/3.o
22+
# RUN: llvm-ar ruU %t/single.a %t/new/1.o
23+
# RUN: llvm-ar t %t/single.a \
24+
# RUN: | FileCheck %s --check-prefix=SINGLE --implicit-check-not {{.}}
25+
26+
# SINGLE: 1.o
27+
# SINGLE-NEXT: 2.o
28+
# SINGLE-NEXT: 3.o
29+
30+
# RUN: llvm-nm --print-armap %t/single.a \
31+
# RUN: | FileCheck %s --check-prefix=SINGLE-SYM
32+
33+
# SINGLE-SYM: symbolnew1
34+
# SINGLE-SYM-NEXT: symbol2
35+
# SINGLE-SYM-NEXT: symbol3
36+
37+
## Replace new single member with older file:
38+
# RUN: llvm-ar ruU %t/single.a %t/1.o
39+
# RUN: llvm-ar t %t/single.a \
40+
# RUN: | FileCheck %s --check-prefix=SINGLE --implicit-check-not {{.}}
41+
42+
# RUN: llvm-nm --print-armap %t/single.a \
43+
# RUN: | FileCheck %s --check-prefix=SINGLE-SYM
44+
45+
## Replace multiple members with newer files:
46+
# RUN: llvm-ar rcuU %t/multiple.a %t/1.o %t/2.o %t/3.o
47+
# RUN: llvm-ar ruU %t/multiple.a %t/new/1.o %t/new/3.o
48+
# RUN: llvm-ar t %t/multiple.a \
49+
# RUN: | FileCheck %s --check-prefix=MULTIPLE --implicit-check-not {{.}}
50+
51+
# MULTIPLE: 1.o
52+
# MULTIPLE-NEXT: 2.o
53+
# MULTIPLE-NEXT: 3.o
54+
55+
# RUN: llvm-nm --print-armap %t/multiple.a \
56+
# RUN: | FileCheck %s --check-prefix=MULTIPLE-SYM
57+
58+
# MULTIPLE-SYM: symbolnew1
59+
# MULTIPLE-SYM-NEXT: symbol2
60+
# MULTIPLE-SYM-NEXTs: symbolnew3
61+
62+
## Replace newer members with multiple older files:
63+
# RUN: llvm-ar ruU %t/multiple.a %t/1.o %t/2.o
64+
# RUN: llvm-ar t %t/multiple.a \
65+
# RUN: | FileCheck %s --check-prefix=MULTIPLE --implicit-check-not {{.}}
66+
67+
# RUN: llvm-nm --print-armap %t/multiple.a \
68+
# RUN: | FileCheck %s --check-prefix=MULTIPLE-SYM
69+
70+
## Replace same member with newer files:
71+
# RUN: llvm-ar rcuU %t/same.a %t/1.o %t/2.o %t/3.o
72+
# RUN: llvm-ar ruU %t/same.a %t/new/1.o %t/new/other/1.o
73+
# RUN: llvm-ar t %t/same.a \
74+
# RUN: | FileCheck %s --check-prefix=SAME -DFILE=%t/2.o --implicit-check-not {{.}}
75+
76+
# SAME: 1.o
77+
# SAME-NEXT: 2.o
78+
# SAME-NEXT: 3.o
79+
# SAME-NEXT: 1.o
80+
81+
# RUN: llvm-nm --print-armap %t/same.a \
82+
# RUN: | FileCheck %s --check-prefix=SAME-SYM
83+
84+
# SAME-SYM: symbolnew1
85+
# SAME-SYM-NEXT: symbol2
86+
# SAME-SYM-NEXT: symbol3
87+
# SAME-SYM-NEXT: symbolother1
88+
89+
## Replace multiple members with an older file and a newer file:
90+
# RUN: llvm-ar rcuU %t/old-new.a %t/new/1.o %t/2.o %t/3.o
91+
# RUN: llvm-ar ruU %t/old-new.a %t/1.o %t/new/3.o
92+
# RUN: llvm-ar t %t/old-new.a \
93+
# RUN: | FileCheck %s --check-prefix=MULTIPLE --implicit-check-not {{.}}
94+
95+
# RUN: llvm-nm --print-armap %t/old-new.a \
96+
# RUN: | FileCheck %s --check-prefix=MULTIPLE-SYM
97+
98+
## Replace same member with an older file and a newer file:
99+
# RUN: llvm-ar rcuU %t/old-new-same.a %t/new/1.o %t/2.o %t/3.o
100+
# RUN: llvm-ar ruU %t/old-new-same.a %t/1.o %t/new/other/1.o
101+
# RUN: llvm-ar t %t/old-new-same.a \
102+
# RUN: | FileCheck %s --check-prefix=SAME -DFILE=%t/2.o --implicit-check-not {{.}}
103+
104+
# RUN: llvm-nm --print-armap %t/same.a \
105+
# RUN: | FileCheck %s --check-prefix=SAME-SYM
106+
107+
--- !ELF
108+
FileHeader:
109+
Class: ELFCLASS64
110+
Data: ELFDATA2LSB
111+
Type: ET_REL
112+
Machine: EM_X86_64
113+
Sections:
114+
- Name: .text
115+
Type: SHT_PROGBITS
116+
Symbols:
117+
- Name: symbol1
118+
Binding: STB_GLOBAL
119+
Section: .text
120+
121+
--- !ELF
122+
FileHeader:
123+
Class: ELFCLASS64
124+
Data: ELFDATA2LSB
125+
Type: ET_REL
126+
Machine: EM_X86_64
127+
Sections:
128+
- Name: .text
129+
Type: SHT_PROGBITS
130+
Symbols:
131+
- Name: symbol2
132+
Binding: STB_GLOBAL
133+
Section: .text
134+
135+
--- !ELF
136+
FileHeader:
137+
Class: ELFCLASS64
138+
Data: ELFDATA2LSB
139+
Type: ET_REL
140+
Machine: EM_X86_64
141+
Sections:
142+
- Name: .text
143+
Type: SHT_PROGBITS
144+
Symbols:
145+
- Name: symbol3
146+
Binding: STB_GLOBAL
147+
Section: .text
148+
149+
--- !ELF
150+
FileHeader:
151+
Class: ELFCLASS64
152+
Data: ELFDATA2LSB
153+
Type: ET_REL
154+
Machine: EM_X86_64
155+
Sections:
156+
- Name: .text
157+
Type: SHT_PROGBITS
158+
Symbols:
159+
- Name: symbolnew1
160+
Binding: STB_GLOBAL
161+
Section: .text
162+
163+
--- !ELF
164+
FileHeader:
165+
Class: ELFCLASS64
166+
Data: ELFDATA2LSB
167+
Type: ET_REL
168+
Machine: EM_X86_64
169+
Sections:
170+
- Name: .text
171+
Type: SHT_PROGBITS
172+
Symbols:
173+
- Name: symbolnew3
174+
Binding: STB_GLOBAL
175+
Section: .text
176+
177+
--- !ELF
178+
FileHeader:
179+
Class: ELFCLASS64
180+
Data: ELFDATA2LSB
181+
Type: ET_REL
182+
Machine: EM_X86_64
183+
Sections:
184+
- Name: .text
185+
Type: SHT_PROGBITS
186+
Symbols:
187+
- Name: symbolother1
188+
Binding: STB_GLOBAL
189+
Section: .text

llvm/test/tools/llvm-ar/replace.test

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
## Test the replace command without modifiers replaces the relevant members.
2+
3+
# RUN: rm -rf %t && mkdir -p %t/new/other
4+
# RUN: yaml2obj %s -o %t/1.o --docnum=1
5+
# RUN: yaml2obj %s -o %t/2.o --docnum=2
6+
# RUN: yaml2obj %s -o %t/3.o --docnum=3
7+
8+
# RUN: yaml2obj %s -o %t/new/1.o --docnum=4
9+
# RUN: yaml2obj %s -o %t/new/3.o --docnum=5
10+
11+
# RUN: yaml2obj %s -o %t/new/other/1.o --docnum=6
12+
13+
## Replace single member:
14+
# RUN: llvm-ar rc %t/single.a %t/1.o %t/2.o %t/3.o
15+
# RUN: llvm-ar r %t/single.a %t/new/1.o
16+
# RUN: llvm-ar t %t/single.a \
17+
# RUN: | FileCheck %s --check-prefix=SINGLE --implicit-check-not {{.}}
18+
19+
# SINGLE: 1.o
20+
# SINGLE-NEXT: 2.o
21+
# SINGLE-NEXT: 3.o
22+
23+
# RUN: llvm-nm --print-armap %t/single.a \
24+
# RUN: | FileCheck %s --check-prefix=SINGLE-SYM
25+
26+
# SINGLE-SYM: symbolnew1
27+
# SINGLE-SYM-NEXT: symbol2
28+
# SINGLE-SYM-NEXT: symbol3
29+
30+
## Replace multiple members:
31+
# RUN: llvm-ar rc %t/multiple.a %t/1.o %t/2.o %t/3.o
32+
# RUN: llvm-ar r %t/multiple.a %t/new/1.o %t/new/3.o
33+
# RUN: llvm-ar t %t/multiple.a \
34+
# RUN: | FileCheck %s --check-prefix=MULTIPLE --implicit-check-not {{.}}
35+
36+
# MULTIPLE: 1.o
37+
# MULTIPLE-NEXT: 2.o
38+
# MULTIPLE-NEXT: 3.o
39+
40+
# RUN: llvm-nm --print-armap %t/multiple.a \
41+
# RUN: | FileCheck %s --check-prefix=MULTIPLE-SYM
42+
43+
# MULTIPLE-SYM: symbolnew1
44+
# MULTIPLE-SYM-NEXT: symbol2
45+
# MULTIPLE-SYM-NEXT: symbolnew3
46+
47+
## Replace same member:
48+
# RUN: llvm-ar rc %t/same.a %t/1.o %t/2.o %t/3.o
49+
# RUN: llvm-ar r %t/same.a %t/new/1.o %t/new/other/1.o
50+
# RUN: llvm-ar t %t/same.a \
51+
# RUN: | FileCheck %s --check-prefix=SAME --implicit-check-not {{.}}
52+
53+
# SAME: 1.o
54+
# SAME-NEXT: 2.o
55+
# SAME-NEXT: 3.o
56+
# SAME-NEXT: 1.o
57+
58+
# RUN: llvm-nm --print-armap %t/same.a \
59+
# RUN: | FileCheck %s --check-prefix=SAME-SYM
60+
61+
# SAME-SYM: symbolnew1
62+
# SAME-SYM-NEXT: symbol2
63+
# SAME-SYM-NEXT: symbol3
64+
# SAME-SYM-NEXT: symbolother1
65+
66+
## Replace without member:
67+
# RUN: llvm-ar rc %t/without.a %t/1.o %t/2.o %t/3.o
68+
# RUN: llvm-ar r %t/without.a
69+
# RUN: llvm-ar t %t/without.a \
70+
# RUN: | FileCheck %s --check-prefix=WITHOUT --implicit-check-not {{.}}
71+
72+
# WITHOUT: 1.o
73+
# WITHOUT-NEXT: 2.o
74+
# WITHOUT-NEXT: 3.o
75+
76+
# RUN: llvm-nm --print-armap %t/without.a \
77+
# RUN: | FileCheck %s --check-prefix=WITHOUT-SYM
78+
79+
# WITHOUT-SYM: symbol1
80+
# WITHOUT-SYM-NEXT: symbol2
81+
# WITHOUT-SYM-NEXT: symbol3
82+
83+
## No archive:
84+
# RUN: not llvm-ar r 2>&1 \
85+
# RUN: | FileCheck %s --check-prefix=NO-ARCHIVE
86+
87+
# NO-ARCHIVE: error: An archive name must be specified.
88+
89+
## Member does not exist:
90+
# RUN: llvm-ar rc %t/missing.a %t/1.o %t/2.o %t/3.o
91+
# RUN: not llvm-ar r %t/missing.a %t/missing.txt 2>&1 \
92+
# RUN: | FileCheck %s --check-prefix=MISSING-FILE -DFILE=%t/missing.txt
93+
94+
# MISSING-FILE: error: [[FILE]]: {{[Nn]}}o such file or directory.
95+
96+
--- !ELF
97+
FileHeader:
98+
Class: ELFCLASS64
99+
Data: ELFDATA2LSB
100+
Type: ET_REL
101+
Machine: EM_X86_64
102+
Sections:
103+
- Name: .text
104+
Type: SHT_PROGBITS
105+
Symbols:
106+
- Name: symbol1
107+
Binding: STB_GLOBAL
108+
Section: .text
109+
110+
--- !ELF
111+
FileHeader:
112+
Class: ELFCLASS64
113+
Data: ELFDATA2LSB
114+
Type: ET_REL
115+
Machine: EM_X86_64
116+
Sections:
117+
- Name: .text
118+
Type: SHT_PROGBITS
119+
Symbols:
120+
- Name: symbol2
121+
Binding: STB_GLOBAL
122+
Section: .text
123+
124+
--- !ELF
125+
FileHeader:
126+
Class: ELFCLASS64
127+
Data: ELFDATA2LSB
128+
Type: ET_REL
129+
Machine: EM_X86_64
130+
Sections:
131+
- Name: .text
132+
Type: SHT_PROGBITS
133+
Symbols:
134+
- Name: symbol3
135+
Binding: STB_GLOBAL
136+
Section: .text
137+
138+
--- !ELF
139+
FileHeader:
140+
Class: ELFCLASS64
141+
Data: ELFDATA2LSB
142+
Type: ET_REL
143+
Machine: EM_X86_64
144+
Sections:
145+
- Name: .text
146+
Type: SHT_PROGBITS
147+
Symbols:
148+
- Name: symbolnew1
149+
Binding: STB_GLOBAL
150+
Section: .text
151+
152+
--- !ELF
153+
FileHeader:
154+
Class: ELFCLASS64
155+
Data: ELFDATA2LSB
156+
Type: ET_REL
157+
Machine: EM_X86_64
158+
Sections:
159+
- Name: .text
160+
Type: SHT_PROGBITS
161+
Symbols:
162+
- Name: symbolnew3
163+
Binding: STB_GLOBAL
164+
Section: .text
165+
166+
--- !ELF
167+
FileHeader:
168+
Class: ELFCLASS64
169+
Data: ELFDATA2LSB
170+
Type: ET_REL
171+
Machine: EM_X86_64
172+
Sections:
173+
- Name: .text
174+
Type: SHT_PROGBITS
175+
Symbols:
176+
- Name: symbolother1
177+
Binding: STB_GLOBAL
178+
Section: .text

0 commit comments

Comments
 (0)