Testing root-only features Lassi Kortela 16 Sep 2020 07:28 UTC
Unix system calls are generally called via wrapper functions in libc. There are several C libraries that override these wrapper functions with ones that have custom behavior, such as pretending to be root or pretending that the file system has different files than it actually does. As one of many examples, an open() wrapper can do its own pathname translation before opening the file. These are called LD_PRELOAD hacks. LD_PRELOAD is an environment variable that lets you inject libraries (.so) which the OS will load when starting new processes with a higher precedence than the usual libraries. <https://stackoverflow.com/questions/426230/what-is-the-ld-preload-trick> A tool called "pseudo" (https://packages.debian.org/stable/source/pseudo) may be the most popular one of this type. >> Perhaps you could split the tests into two groups: one that requires >> root and one that doesn't. That way, people without root rights could >> at least run some of the tests. > > Rather than that, since this is a POSIX SRFI with a user-effective-uid > procedure, I just conditionalize the tests based on it being 0 or not. Good ideas. Not sure which is the better way to do it. > The only tricky bit is that for debugging purposes the set of small > files is left after a test run and deleted before beginning a new one, > so before you switch back to being a non-privileged user you need to > manually delete them. Is there a particular reason the test suite cleanup code can't delete the temp files?