Skip to content

Commit 1159fe3

Browse files
author
Owen Reynolds
committed
Reapply [llvm-ar][test] Increase llvm-ar test coverage
This change adds tests to cover existing llvm-ar functionality. Differential Revision: https://reviews.llvm.org/D63935 llvm-svn: 365318
1 parent 0c5fe7a commit 1159fe3

File tree

10 files changed

+433
-17
lines changed

10 files changed

+433
-17
lines changed

llvm/test/tools/llvm-ar/create.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Test the creation warning and supression of that warning.
2+
3+
RUN: touch %t1.txt
4+
RUN: touch %t2.txt
5+
6+
RUN: rm -f %t.warning.ar
7+
RUN: llvm-ar r %t.warning.ar %t1.txt %t2.txt 2>&1 \
8+
RUN: | FileCheck %s -DOUTPUT=%t.warning.ar
9+
10+
CHECK: warning: creating [[OUTPUT]]
11+
12+
RUN: rm -f %t.supressed.ar
13+
RUN: llvm-ar cr %t.supressed.ar %t1.txt %t2.txt 2>&1 \
14+
RUN: | FileCheck --allow-empty /dev/null --implicit-check-not={{.}}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Test the use of dash before key letters.
2+
3+
RUN: touch %t1.txt
4+
RUN: touch %t2.txt
5+
6+
RUN: rm -f %t.ar
7+
RUN: llvm-ar s -cr %t.ar %t1.txt
8+
RUN: llvm-ar -r -s %t.ar %t2.txt -s
9+
RUN: llvm-ar -t %t.ar | FileCheck %s
10+
11+
CHECK: 1.txt
12+
CHECK-NEXT: 2.txt
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
11
RUN: yaml2obj %S/Inputs/macho.yaml -o %t-macho.o
22
RUN: yaml2obj %S/Inputs/coff.yaml -o %t-coff.o
3+
RUN: yaml2obj %S/Inputs/elf.yaml -o %t-elf.o
34

45
RUN: rm -f %t.ar
56
RUN: llvm-ar crs %t.ar %t-macho.o
67
RUN: grep -q __.SYMDEF %t.ar
7-
Test that an option string prefixed by a dash works.
8-
RUN: llvm-ar -crs %t.ar %t-coff.o
9-
RUN: grep -q __.SYMDEF %t.ar
108

119
RUN: rm -f %t.ar
1210
RUN: llvm-ar crs %t.ar %t-coff.o
1311
RUN: not grep -q __.SYMDEF %t.ar
1412
RUN: llvm-ar crs %t.ar %t-macho.o
1513
RUN: not grep -q __.SYMDEF %t.ar
16-
17-
RUN: rm -f %t.ar
18-
Test that multiple dashed options works.
19-
RUN: llvm-ar -c -r -s %t.ar %t-macho.o
20-
RUN: grep -q __.SYMDEF %t.ar
21-
Test with duplicated options.
22-
RUN: llvm-ar -c -r -s -c -s %t.ar %t-coff.o
23-
RUN: grep -q __.SYMDEF %t.ar
14+
RUN: llvm-ar crs %t.ar %t-elf.o
15+
RUN: not grep -q __.SYMDEF %t.ar
2416

2517
RUN: rm -f %t.ar
2618
Test with the options in a different order.
2719
RUN: llvm-ar rsc %t.ar %t-macho.o
2820
RUN: grep -q __.SYMDEF %t.ar
29-
Test with options everywhere.
30-
RUN: llvm-ar rsc -cs -sc %t.ar %t-coff.o -cs -sc
31-
RUN: grep -q __.SYMDEF %t.ar
32-
33-
Ensure that we select the existing format when updating.
34-

llvm/test/tools/llvm-ar/delete.test

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
## Test the deletion of members and that symbols are removed from the symbol table.
2+
3+
# RUN: yaml2obj %s -o %t-delete.o --docnum=1
4+
# RUN: yaml2obj %s -o %t-keep.o --docnum=2
5+
# RUN: touch %t1.txt
6+
# RUN: touch %t2.txt
7+
8+
## Add file:
9+
# RUN: rm -f %t.a
10+
# RUN: llvm-ar rc %t.a %t1.txt %t-delete.o %t-keep.o %t2.txt
11+
# RUN: llvm-nm --print-armap %t.a \
12+
# RUN: | FileCheck %s --check-prefix=SYMBOL-ADDED
13+
# RUN: llvm-ar t %t.a | FileCheck %s --check-prefix=FILE-ADDED
14+
15+
# SYMBOL-ADDED: symbol1
16+
# SYMBOL-ADDED-NEXT: symbol2
17+
18+
# FILE-ADDED: 1.txt
19+
# FILE-ADDED-NEXT: delete.o
20+
# FILE-ADDED-NEXT: keep.o
21+
# FILE-ADDED-NEXT: 2.txt
22+
23+
## Delete file that is not a member:
24+
# RUN: cp %t.a %t-archive-copy.a
25+
# RUN: llvm-ar d %t.a t/missing.o
26+
# RUN: cmp %t.a %t-archive-copy.a
27+
28+
## Delete file:
29+
# RUN: llvm-ar d %t.a %t-delete.o
30+
# RUN: llvm-nm --print-armap %t.a \
31+
# RUN: | FileCheck %s --check-prefix=SYMBOL-DELETED --implicit-check-not symbol1
32+
# RUN: llvm-ar t %t.a \
33+
# RUN: | FileCheck %s --check-prefix=FILE-DELETED --implicit-check-not delete.o
34+
35+
# SYMBOL-DELETED: symbol2
36+
37+
# FILE-DELETED: 1.txt
38+
# FILE-DELETED-NEXT: keep.o
39+
# FILE-DELETED-NEXT: 2.txt
40+
41+
--- !ELF
42+
FileHeader:
43+
Class: ELFCLASS64
44+
Data: ELFDATA2LSB
45+
Type: ET_REL
46+
Machine: EM_X86_64
47+
Sections:
48+
- Name: .text
49+
Type: SHT_PROGBITS
50+
Symbols:
51+
- Name: symbol1
52+
Binding: STB_GLOBAL
53+
Section: .text
54+
55+
--- !ELF
56+
FileHeader:
57+
Class: ELFCLASS64
58+
Data: ELFDATA2LSB
59+
Type: ET_REL
60+
Machine: EM_X86_64
61+
Sections:
62+
- Name: .text
63+
Type: SHT_PROGBITS
64+
Symbols:
65+
- Name: symbol2
66+
Binding: STB_GLOBAL
67+
Section: .text

llvm/test/tools/llvm-ar/extract.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Test extract operation.
2+
RUN: rm -rf %t && mkdir -p %t/extracted/
3+
4+
# Extracting from an empty archive should not warn or error:
5+
RUN: llvm-ar cr %t/empty.a
6+
RUN: llvm-ar x %t/empty.a 2>&1 \
7+
RUN: | FileCheck --allow-empty /dev/null --implicit-check-not={{.}}
8+
9+
RUN: echo filea > %t/a.txt
10+
RUN: echo fileb > %t/b.txt
11+
RUN: llvm-ar rc %t/archive.a %t/a.txt %t/b.txt
12+
13+
# Single member:
14+
RUN: cd %t/extracted && llvm-ar x %t/archive.a a.txt
15+
RUN: diff %t/a.txt %t/extracted/a.txt
16+
17+
# All members:
18+
RUN: rm %t/extracted/a.txt
19+
RUN: cd %t/extracted && llvm-ar x %t/archive.a
20+
RUN: diff %t/a.txt %t/extracted/a.txt
21+
RUN: diff %t/b.txt %t/extracted/b.txt
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
## Test inserting files after a file.
2+
3+
RUN: touch %t1.txt
4+
RUN: touch %t2.txt
5+
RUN: touch %t3.txt
6+
RUN: touch %t4.txt
7+
8+
# Insert one file:
9+
RUN: rm -f %t-one.a
10+
RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt
11+
RUN: llvm-ar ra %t1.txt %t-one.a %t3.txt
12+
RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE
13+
14+
ONE: 1.txt
15+
ONE-NEXT: 3.txt
16+
ONE-NEXT: 2.txt
17+
18+
# Insert file at back:
19+
RUN: rm -f %t-back.a
20+
RUN: llvm-ar rc %t-back.a %t1.txt %t2.txt
21+
RUN: llvm-ar ra %t2.txt %t-back.a %t3.txt
22+
RUN: llvm-ar t %t-back.a | FileCheck %s --check-prefix=BACK
23+
24+
BACK: 1.txt
25+
BACK-NEXT: 2.txt
26+
BACK-NEXT: 3.txt
27+
28+
# Insert multiple files:
29+
RUN: rm -f %t-multiple.a
30+
RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt
31+
RUN: llvm-ar ra %t1.txt %t-multiple.a %t4.txt %t3.txt
32+
RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE
33+
34+
MULTIPLE: 1.txt
35+
MULTIPLE-NEXT: 4.txt
36+
MULTIPLE-NEXT: 3.txt
37+
MULTIPLE-NEXT: 2.txt
38+
39+
# Insert after invalid file:
40+
RUN: rm -f %t-invalid.a
41+
RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt
42+
RUN: not llvm-ar ra invalid.txt %t-invalid.a %t2.txt 2>&1 \
43+
RUN: | FileCheck %s --check-prefix=ERROR
44+
RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID
45+
46+
ERROR: error: Insertion point not found.
47+
INVALID: 1.txt
48+
INVALID-NEXT: 2.txt
49+
INVALID-NEXT: 3.txt
50+
51+
# Insert file at the same position:
52+
RUN: rm -f %t-position.a
53+
RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt
54+
RUN: llvm-ar ra %t1.txt %t-position.a %t2.txt
55+
RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION
56+
57+
POSITION: 1.txt
58+
POSITION-NEXT: 2.txt
59+
POSITION-NEXT: 3.txt
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
## Test inserting files before a file.
2+
3+
RUN: touch %t1.txt
4+
RUN: touch %t2.txt
5+
RUN: touch %t3.txt
6+
RUN: touch %t4.txt
7+
8+
# Insert one file:
9+
RUN: rm -f %t-one.a
10+
RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt
11+
RUN: llvm-ar rb %t2.txt %t-one.a %t3.txt
12+
RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE
13+
14+
ONE: 1.txt
15+
ONE-NEXT: 3.txt
16+
ONE-NEXT: 2.txt
17+
18+
# Insert file at front:
19+
RUN: rm -f %t-front.a
20+
RUN: llvm-ar rc %t-front.a %t1.txt %t2.txt
21+
RUN: llvm-ar rb %t1.txt %t-front.a %t3.txt
22+
RUN: llvm-ar t %t-front.a | FileCheck %s --check-prefix=FRONT
23+
24+
FRONT: 3.txt
25+
FRONT-NEXT: 1.txt
26+
FRONT-NEXT: 2.txt
27+
28+
# Insert multiple files:
29+
RUN: rm -f %t-multiple.a
30+
RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt
31+
RUN: llvm-ar rb %t2.txt %t-multiple.a %t4.txt %t3.txt
32+
RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE
33+
34+
MULTIPLE: 1.txt
35+
MULTIPLE-NEXT: 4.txt
36+
MULTIPLE-NEXT: 3.txt
37+
MULTIPLE-NEXT: 2.txt
38+
39+
# Insert before an invalid file:
40+
RUN: rm -f %t-invalid.a
41+
RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt
42+
RUN: not llvm-ar rb invalid.txt %t-invalid.a %t2.txt 2>&1 \
43+
RUN: | FileCheck %s --check-prefix=ERROR
44+
RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID
45+
46+
ERROR: error: Insertion point not found.
47+
INVALID: 1.txt
48+
INVALID-NEXT: 2.txt
49+
INVALID-NEXT: 3.txt
50+
51+
# Insert file at the same position:
52+
RUN: rm -f %t-position.a
53+
RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt
54+
RUN: llvm-ar rb %t3.txt %t-position.a %t2.txt
55+
RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION
56+
57+
POSITION: 1.txt
58+
POSITION-NEXT: 2.txt
59+
POSITION-NEXT: 3.txt
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
## Test moving files after a file.
2+
3+
RUN: touch %t1.txt
4+
RUN: touch %t2.txt
5+
RUN: touch %t3.txt
6+
RUN: touch %t4.txt
7+
8+
# Move one file:
9+
RUN: rm -f %t-one.ar
10+
RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt %t3.txt
11+
RUN: llvm-ar ma %t1.txt %t-one.a %t3.txt
12+
RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE
13+
14+
ONE: 1.txt
15+
ONE-NEXT: 3.txt
16+
ONE-NEXT: 2.txt
17+
18+
# Move file to back:
19+
RUN: rm -f %t-back.ar
20+
RUN: llvm-ar rc %t-back.a %t1.txt %t2.txt %t3.txt
21+
RUN: llvm-ar ma %t2.txt %t-back.a %t1.txt
22+
RUN: llvm-ar t %t-back.a | FileCheck %s --check-prefix=BACK
23+
24+
BACK: 2.txt
25+
BACK-NEXT: 1.txt
26+
BACK-NEXT: 3.txt
27+
28+
# Move multiple files:
29+
RUN: rm -f %t-multiple.ar
30+
RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt %t3.txt %t4.txt
31+
RUN: llvm-ar ma %t1.txt %t-multiple.a %t4.txt %t3.txt
32+
RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE
33+
34+
MULTIPLE: 1.txt
35+
MULTIPLE-NEXT: 3.txt
36+
MULTIPLE-NEXT: 4.txt
37+
MULTIPLE-NEXT: 2.txt
38+
39+
# Move after invalid file:
40+
RUN: rm -f %t-invalid.ar
41+
RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt
42+
RUN: not llvm-ar ma invalid.txt %t-invalid.a %t2.txt 2>&1 \
43+
RUN: | FileCheck %s --check-prefix=ERROR
44+
RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID
45+
46+
ERROR: error: Insertion point not found.
47+
INVALID: 1.txt
48+
INVALID-NEXT: 2.txt
49+
INVALID-NEXT: 3.txt
50+
51+
# Move file to the same position:
52+
RUN: rm -f %t-position.ar
53+
RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt
54+
RUN: llvm-ar ma %t1.txt %t-position.a %t2.txt
55+
RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION
56+
57+
POSITION: 1.txt
58+
POSITION-NEXT: 2.txt
59+
POSITION-NEXT: 3.txt

0 commit comments

Comments
 (0)