xref: /llvm-project/llvm/test/tools/llvm-size/radix.test (revision 47db32e542eb84ca9d4bed798bbdfd40200ac1ef)
1## Show that llvm-size prints sizes in different radixes when requested.
2
3# RUN: yaml2obj %s --docnum=1 -o %t1.o
4# RUN: yaml2obj %s --docnum=2 -o %t2.o
5
6## Case 1: Octal radix (Berkeley).
7# RUN: llvm-size %t1.o %t2.o --totals -B --radix=8 \
8# RUN:   | FileCheck %s --check-prefix=OCT-BERK -DFILE1=%t1.o -DFILE2=%t2.o
9# RUN: llvm-size %t1.o %t2.o --totals -B -o \
10# RUN:   | FileCheck %s --check-prefix=OCT-BERK -DFILE1=%t1.o -DFILE2=%t2.o
11
12# OCT-BERK:         text    data     bss     oct     hex filename
13# OCT-BERK-NEXT:      01      02      04       7       7 [[FILE1]]
14# OCT-BERK-NEXT:     010     020     040      70      38 [[FILE2]]
15# OCT-BERK-NEXT:     011     022     044      77      3f (TOTALS)
16
17## Case 2: Decimal radix (Berkeley).
18# RUN: llvm-size %t1.o %t2.o --totals -B --radix=10 \
19# RUN:   | FileCheck %s --check-prefix=DEC-BERK -DFILE1=%t1.o -DFILE2=%t2.o
20# RUN: llvm-size %t1.o %t2.o --totals -B -d \
21# RUN:   | FileCheck %s --check-prefix=DEC-BERK -DFILE1=%t1.o -DFILE2=%t2.o
22
23# DEC-BERK:         text    data     bss     dec     hex filename
24# DEC-BERK-NEXT:       1       2       4       7       7 [[FILE1]]
25# DEC-BERK-NEXT:       8      16      32      56      38 [[FILE2]]
26# DEC-BERK-NEXT:       9      18      36      63      3f (TOTALS)
27
28## Case 3: Hexadecimal radix (Berkeley).
29# RUN: llvm-size %t1.o %t2.o --totals -B --radix=16 \
30# RUN:   | FileCheck %s --check-prefix=HEX-BERK -DFILE1=%t1.o -DFILE2=%t2.o
31# RUN: llvm-size %t1.o %t2.o --totals -B -x \
32# RUN:   | FileCheck %s --check-prefix=HEX-BERK -DFILE1=%t1.o -DFILE2=%t2.o
33
34# HEX-BERK:         text    data     bss     dec     hex filename
35# HEX-BERK-NEXT:     0x1     0x2     0x4       7       7 [[FILE1]]
36# HEX-BERK-NEXT:     0x8    0x10    0x20      56      38 [[FILE2]]
37# HEX-BERK-NEXT:     0x9    0x12    0x24      63      3f (TOTALS)
38
39## Case 4: Octal radix (sysv).
40# RUN: llvm-size %t1.o %t2.o -A --radix=8 \
41# RUN:   | FileCheck %s --check-prefix=OCT-SYSV -DFILE1=%t1.o -DFILE2=%t2.o
42# RUN: llvm-size %t1.o %t2.o -A -o \
43# RUN:   | FileCheck %s --check-prefix=OCT-SYSV -DFILE1=%t1.o -DFILE2=%t2.o
44
45# OCT-SYSV:      [[FILE1]]  :
46# OCT-SYSV-NEXT: section     size   addr
47# OCT-SYSV-NEXT: .text         01     04
48# OCT-SYSV-NEXT: .data         02     02
49# OCT-SYSV-NEXT: .bss          04     01
50# OCT-SYSV-NEXT: Total         07
51# OCT-SYSV-EMPTY:
52# OCT-SYSV-EMPTY:
53# OCT-SYSV-NEXT: [[FILE2]]  :
54# OCT-SYSV-NEXT: section     size   addr
55# OCT-SYSV-NEXT: .blob        010    040
56# OCT-SYSV-NEXT: .blab        020    020
57# OCT-SYSV-NEXT: .blib        040    010
58# OCT-SYSV-NEXT: Total        070
59
60## Case 5: Decimal radix (sysv).
61# RUN: llvm-size %t1.o %t2.o -A --radix=10 \
62# RUN:   | FileCheck %s --check-prefix=DEC-SYSV -DFILE1=%t1.o -DFILE2=%t2.o
63# RUN: llvm-size %t1.o %t2.o -A -d \
64# RUN:   | FileCheck %s --check-prefix=DEC-SYSV -DFILE1=%t1.o -DFILE2=%t2.o
65
66# DEC-SYSV:      [[FILE1]]  :
67# DEC-SYSV-NEXT: section     size   addr
68# DEC-SYSV-NEXT: .text          1      4
69# DEC-SYSV-NEXT: .data          2      2
70# DEC-SYSV-NEXT: .bss           4      1
71# DEC-SYSV-NEXT: Total          7
72# DEC-SYSV-EMPTY:
73# DEC-SYSV-EMPTY:
74# DEC-SYSV-NEXT: [[FILE2]]  :
75# DEC-SYSV-NEXT: section     size   addr
76# DEC-SYSV-NEXT: .blob          8     32
77# DEC-SYSV-NEXT: .blab         16     16
78# DEC-SYSV-NEXT: .blib         32      8
79# DEC-SYSV-NEXT: Total         56
80
81## Case 6: Hexadecimal radix (sysv).
82# RUN: llvm-size %t1.o %t2.o -A --radix=16 \
83# RUN:   | FileCheck %s --check-prefix=HEX-SYSV -DFILE1=%t1.o -DFILE2=%t2.o
84# RUN: llvm-size %t1.o %t2.o -A -x \
85# RUN:   | FileCheck %s --check-prefix=HEX-SYSV -DFILE1=%t1.o -DFILE2=%t2.o
86
87# HEX-SYSV:      [[FILE1]]  :
88# HEX-SYSV-NEXT: section     size   addr
89# HEX-SYSV-NEXT: .text        0x1    0x4
90# HEX-SYSV-NEXT: .data        0x2    0x2
91# HEX-SYSV-NEXT: .bss         0x4    0x1
92# HEX-SYSV-NEXT: Total        0x7
93# HEX-SYSV-EMPTY:
94# HEX-SYSV-EMPTY:
95# HEX-SYSV-NEXT: [[FILE2]]  :
96# HEX-SYSV-NEXT: section     size   addr
97# HEX-SYSV-NEXT: .blob        0x8   0x20
98# HEX-SYSV-NEXT: .blab       0x10   0x10
99# HEX-SYSV-NEXT: .blib       0x20    0x8
100# HEX-SYSV-NEXT: Total       0x38
101
102## Case 7: Default Berkeley is decimal.
103# RUN: llvm-size %t1.o %t2.o --totals -B \
104# RUN:   | FileCheck %s --check-prefix=DEC-BERK -DFILE1=%t1.o -DFILE2=%t2.o
105
106## Case 8: Default sysv is decimal.
107# RUN: llvm-size %t1.o %t2.o -A \
108# RUN:   | FileCheck %s --check-prefix=DEC-SYSV -DFILE1=%t1.o -DFILE2=%t2.o
109
110## Case 9: Bad values.
111# RUN: not llvm-size %t1.o --radix=0 2>&1 \
112# RUN:   | FileCheck %s --check-prefix=BAD-VAL -DNUM=0
113# RUN: not llvm-size %t1.o --radix=1 2>&1 \
114# RUN:   | FileCheck %s --check-prefix=BAD-VAL -DNUM=1
115# RUN: not llvm-size %t1.o --radix=2 2>&1 \
116# RUN:   | FileCheck %s --check-prefix=BAD-VAL -DNUM=2
117# RUN: not llvm-size %t1.o --radix=32 2>&1 \
118# RUN:   | FileCheck %s --check-prefix=BAD-VAL -DNUM=32
119# RUN: not llvm-size %t1.o --radix=-1 2>&1 \
120# RUN:   | FileCheck %s --check-prefix=BAD-VAL -DNUM=-1
121# RUN: not llvm-size %t1.o --radix=bad 2>&1 \
122# RUN:   | FileCheck %s --check-prefix=BAD-VAL -DNUM=bad
123
124# BAD-VAL: {{.*}}llvm-size{{.*}}: error: --radix value should be one of: 8, 10, 16
125
126--- !ELF
127FileHeader:
128  Class:   ELFCLASS64
129  Data:    ELFDATA2LSB
130  Type:    ET_REL
131  Machine: EM_X86_64
132Sections:
133  - Name:    .text
134    Type:    SHT_PROGBITS
135    Flags:   [SHF_ALLOC, SHF_EXECINSTR]
136    Size:    1
137    Address: 4
138  - Name:    .data
139    Type:    SHT_PROGBITS
140    Flags:   [SHF_ALLOC, SHF_WRITE]
141    Size:    2
142    Address: 2
143  - Name:    .bss
144    Type:    SHT_NOBITS
145    Flags:   [SHF_ALLOC, SHF_WRITE]
146    Size:    4
147    Address: 1
148
149--- !ELF
150FileHeader:
151  Class:   ELFCLASS64
152  Data:    ELFDATA2LSB
153  Type:    ET_REL
154  Machine: EM_X86_64
155Sections:
156  - Name:    .blob
157    Type:    SHT_PROGBITS
158    Flags:   [SHF_ALLOC, SHF_EXECINSTR]
159    Size:    8
160    Address: 32
161  - Name:    .blab
162    Type:    SHT_PROGBITS
163    Flags:   [SHF_ALLOC, SHF_WRITE]
164    Size:    16
165    Address: 16
166  - Name:    .blib
167    Type:    SHT_NOBITS
168    Flags:   [SHF_ALLOC, SHF_WRITE]
169    Size:    32
170    Address: 8
171