xref: /llvm-project/llvm/test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test (revision 17b4e695ce0ef89eac4a37df2df49d4c0e700766)
1## Test that permissions for ouput files are mirrored
2## from their input files.
3
4## The Unix version of this test must use umask(1) because
5## llvm-objcopy respects the umask in setting output permissions.
6## Setting the umask to 0 ensures deterministic permissions across
7## test environments.
8# UNSUPPORTED: system-windows
9# REQUIRES: shell
10
11# RUN: touch %t
12# RUN: chmod 0777 %t
13# RUN: ls -l %t | cut -f 1 -d ' ' > %t.0777
14# RUN: chmod 0666 %t
15# RUN: ls -l %t | cut -f 1 -d ' ' > %t.0666
16# RUN: chmod 0640 %t
17# RUN: ls -l %t | cut -f 1 -d ' ' > %t.0640
18
19## Set umask to be permissive of all permissions,
20## only test mirroring of permissions.
21# RUN: umask 0
22
23# RUN: yaml2obj %s -o %t
24
25# RUN: chmod 0777 %t
26# RUN: llvm-objcopy %t %t1
27# RUN: ls -l %t1 | cut -f 1 -d ' ' > %t1.perms
28# RUN: cmp %t1.perms %t.0777
29
30# RUN: chmod 0666 %t
31# RUN: llvm-objcopy %t %t1
32# RUN: ls -l %t1 | cut -f 1 -d ' ' > %t1.perms
33# RUN: cmp %t1.perms %t.0666
34
35# RUN: chmod 0640 %t
36# RUN: llvm-objcopy %t %t1
37# RUN: ls -l %t1 | cut -f 1 -d ' ' > %t1.perms
38# RUN: cmp %t1.perms %t.0640
39
40## Drop S_ISUID/S_ISGID bits.
41# RUN: chmod 6640 %t
42# RUN: llvm-objcopy %t %t1
43# RUN: ls -l %t1 | cut -f 1 -d ' ' > %t1.perms
44# RUN: cmp %t1.perms %t.0640
45
46## Don't set the permission of a character special file, otherwise there will
47## be an EPERM error (or worse: root may change the permission).
48# RUN: ls -l /dev/null | cut -f 1 -d ' ' > %tnull.perms
49# RUN: llvm-objcopy %t /dev/null
50# RUN: ls -l /dev/null | cut -f 1 -d ' ' | diff - %tnull.perms
51
52## Ignore umask if the output filename is the same as the input filename.
53# RUN: umask 022
54# RUN: cp %t %t1 && chmod 0777 %t1 && llvm-objcopy %t1
55# RUN: ls -l %t1 | cut -f 1 -d ' ' > %t1.perms
56# RUN: cmp %t1.perms %t.0777
57
58--- !ELF
59FileHeader:
60  Class:   ELFCLASS64
61  Data:    ELFDATA2LSB
62  Type:    ET_EXEC
63  Machine: EM_X86_64
64