Usage of chmod 400 in lld lit tests causes failures when run by root user

Hi,

There are 3 lld tests[1] that run the command `chmod 400` or `chmod u-w`
and then check that lld generates a permission denied error when trying to
write to the files. These tests fail when run as root,
because `chmod 400` is not enough to prevent root from writing to files.
Is there some other way we can tests this, or should we just not support
running tests as root?

A related question I have is how do these tests work on Windows since it doesn't
have chmod?

Thanks,
Tom

[1]

ELF/lto/thinlto-emit-imports.ll
ELF/lto/thinlto-cant-write-index.ll
COFF/thinlto-emit-imports.ll

Hi,

There are 3 lld tests[1] that run the command `chmod 400` or `chmod u-w`
and then check that lld generates a permission denied error when trying to
write to the files. These tests fail when run as root,
because `chmod 400` is not enough to prevent root from writing to files.
Is there some other way we can tests this, or should we just not support
running tests as root?

A quick search on preventing root from overwriting files brings up
chattr +i to set the immutable bit, however this only works when run
as root so it isn't feasible. Personally I would be happy with not
supporting the test suite running as root, or maybe documenting that
chmod tests will fail.

A related question I have is how do these tests work on Windows since it doesn't
have chmod?

Could it be related to the sentence "If you would like to run the LLVM
tests you will need Python. Version 2.7 and newer are known to work.
You will need GnuWin32 tools, too."
https://llvm.org/docs/GettingStartedVS.html
It is likely that GnuWin32 tools contain chmod in some form.
Unfortunately I don't have a Windows machine to hand to confirm.

Peter

Could it be related to the sentence “If you would like to run the LLVM
tests you will need Python. Version 2.7 and newer are known to work.
You will need GnuWin32 tools, too.”
https://llvm.org/docs/GettingStartedVS.html
It is likely that GnuWin32 tools contain chmod in some form.
Unfortunately I don’t have a Windows machine to hand to confirm.

I can confirm that GnuWin32 contains a version of chmod. How it interacts with the Windows file permissions, I can’t say, but it does work in this context at the very least.

James

I haven’t tried this so I don’t know if it will actually work but maybe you can try messing around with the lit.cfg file in those directories. For example:

import getpass

if getpass.getuser() == “root”:
config.excludes = [thinlto-emit-imports.ll, thinlto-cant-write-index.ll]

Or however you want to get the user name, that was first thing that showed up when I searched. Also maybe you need to append to config.excludes? I see it assigned to in llvm/test/lit.cfg.py.

Hopefully that works!