Bug #3418
closed
Unit tests requiring root should be skipped when run as normal user
Added by susmit shannigrahi almost 9 years ago.
Updated about 8 years ago.
Description
NFD has a few unit tests that needs to be run as root. When run as normal user, these unit tests should be skipped and not throw errors.
../daemon/face/udp-factory.cpp(203): fatal error in "std::shared_ptr<nfd::face::Face> nfd::UdpFactory::createMulticastFace(const Endpoint&, const Endpoint&, const string&)": std::runtime_error: Cannot bind multicast face to virbr0: Operation not permitted
../tests/daemon/mgmt/face-manager-process-config.t.cpp(176): error in "ProcessSectionUdp": exception thrown by parseConfig(CONFIG, false)
../tests/daemon/mgmt/face-manager-process-config.t.cpp(305): error in "ProcessSectionUdpMulticastReinit": exception thrown by parseConfig(CONFIG_WITH_MCAST, false)
../tests/daemon/mgmt/general-config-section.t.cpp(79): error in "UserAndGroupConfig": exception thrown by configFile.parse(CONFIG, true, "test-general-config-section")
../tests/daemon/mgmt/general-config-section.t.cpp(93): error in "NoUserConfig": exception thrown by configFile.parse(CONFIG, true, "test-general-config-section")
- Category set to Management
- Target version set to v0.5
An alternate to the suggested solution is to require sudo
in README-dev.md
"running unit tests" section.
- Category changed from Management to Faces
Junxiao Shi wrote:
An alternate to the suggested solution is to require sudo
in README-dev.md
"running unit tests" section.
Not really.
If I want to run unit tests when packaging on a Fedora(or any other) build-system, I won't have sudo. Running unit tests for packaging is required for sanity checking.
susmit shannigrahi wrote:
Junxiao Shi wrote:
An alternate to the suggested solution is to require sudo
in README-dev.md
"running unit tests" section.
Not really.
If I want to run unit tests when packaging on a Fedora(or any other) build-system, I won't have sudo.
+1. Requiring sudo to run unit tests is not a valid solution for packagers.
- Assignee set to Weiwei Liu
@Weiwei: consult @Davide on how to properly solve this bug.
- Status changed from New to In Progress
Could someone give me some idea about how to solve this bug? Am I supposed to modify the waf script?
Thanks a lot.
No. I think unit tests should be aware of whether they are running as root or normal users. Anything that requires root should be skipped with a message.
There is an example in tests/core/privilege-helper.t.cpp
.
You also need to update jenkins script in .jenkins.d/20-tests.sh
@Alex, thanks for your reply.
Do you mean for each test case that needs to run as root, I need to add the following code to skip it:
if (::geteuid() != 0) {
BOOST_TEST_MESSAGE("This test case needs to be run as super user, skipping");
return;
}
If this is the case why do we still need to update .jenkins.d/20-tests.sh?
Besides, how am I supposed to reproduce this bug?
Thank you very much.
Weiwei Liu wrote:
I tried to run the NFD daemon tests with ./build/unit-tests-daemon -l test_suite
, but I didn't get the errors as showed in this bug, instead, for each failed test case, I'm getting the following error:
[...]
Does anyone know what's going wrong?
Per our discussion yesterday, this happens in only Fedora. I haven't personally tested any other distribution.
- Status changed from In Progress to Code review
- % Done changed from 0 to 80
Should we add a step to Jenkins build script that executes unit testing without root and without adding capabilities?
- Status changed from Code review to Resolved
- % Done changed from 80 to 100
Patch is merged. This issue is waiting for an answer to note-13 question, and waiting for Susmit's test on his original environment.
- Status changed from Resolved to In Progress
- Assignee changed from Weiwei Liu to Davide Pesavento
- % Done changed from 100 to 50
20160607 conference call decides to run all tests without added capabilities, and then re-run those tests that need sudo with added capabilities.
- Status changed from In Progress to Code review
- % Done changed from 50 to 90
- Description updated (diff)
- Status changed from Code review to Closed
- % Done changed from 90 to 100
Also available in: Atom
PDF