Skip to content

Comments

[cgroups2] Device controller tests.#538

Closed
DevinLeamy wants to merge 1 commit intoapache:masterfrom
DevinLeamy:device-tests
Closed

[cgroups2] Device controller tests.#538
DevinLeamy wants to merge 1 commit intoapache:masterfrom
DevinLeamy:device-tests

Conversation

@DevinLeamy
Copy link
Contributor

Added tests for the programs created by the the Device Controller.

// read-write is blocked
vector<Access>{{os::DEV_NULL, O_RDWR}}
},
DeviceControllerTestParams{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this one? This?

// Allow write-only access to /dev/null using any device type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows read access to /dev/null. The check that read-only is allowed and that read-write is not allowed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably easier to just have one comment that explains what each test case here does rather than these fine grained comments, for example there's no comment on the "b 1:3 rwm" test, so it's hard for the reader to know what that case is checking (e.g. different device type so not actually /dev/null?)

Comment on lines 328 to 362
DeviceControllerTestParams{
vector<devices::Entry>{*devices::Entry::parse("b 1:3 r")},
vector<devices::Entry>{},
vector<Access>{},
// /dev/null is blocked
vector<Access>{{os::DEV_NULL, O_RDWR}, {os::DEV_NULL, O_RDONLY}}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what we're testing?

// Allow access to /dev/null but with the wrong device type, therefore access is denied.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/dev/null is a character device. This tests that if we allow a block device to be read, and then try and read from a character device with the same type, then that request will be blocked.

Comment on lines 260 to 294
if (pid == 0) {
// Check that we can only do the "allowedAccesses".
foreach(const Access& access, allowedAccesses) {
ASSERT_SOME(os::open(access.first, access.second));
}
foreach(const Access& access, blockedAccesses) {
ASSERT_ERROR(os::open(access.first, access.second));
}

ASSERT_SOME(ebpf::cgroups2::detach(path, attached->at(0)));

// Check that we can do both the "allowedAccesses" and "blockedAccesses".
foreach(const Access& access, allowedAccesses) {
ASSERT_SOME(os::open(access.first, access.second));
}
foreach(const Access& access, blockedAccesses) {
ASSERT_SOME(os::open(access.first, access.second));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use ASSERT in the child process, as they won't fail the test. Looks like the strategy in cgroups_tests.cpp is to use a pipe and communicate back to the parent process to indicate whether the child process' tests succeeded.

@DevinLeamy DevinLeamy force-pushed the device-tests branch 3 times, most recently from 4e5e8bb to 840b97e Compare March 28, 2024 22:48
Added tests for the programs created by the the Device Controller.
Copy link
Contributor

@bmahler bmahler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, the test looks clean! We should really have some tests that actually use multiple device rules though?

#include <vector>

#include <process/reap.hpp>
#include <process/gmock.hpp>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't look like this is used?

public ::testing::WithParamInterface<DeviceControllerTestParams> {};


TEST_P(DeviceControllerTestFixture, ROOT_CGROUPS2_DeviceController) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: brace on next line

ASSERT_SOME(attached);
ASSERT_EQ(0u, attached->size());

EXPECT_SOME(devices::configure(cgroup, allow, deny));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASSERT since we don't want to continue the test if this fails?

Comment on lines +307 to +316
DeviceControllerTestParams{
vector<devices::Entry>{},
vector<devices::Entry>{},
vector<OpenArgs>{},
// Block accesses by default.
vector<OpenArgs>{{os::DEV_NULL, O_RDWR}, {os::DEV_NULL, O_RDWR}}
},
DeviceControllerTestParams{
vector<devices::Entry>{},
vector<devices::Entry>{*devices::Entry::parse("c 1:3 rwm")},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation is inconsistent here

vector<devices::Entry>{*devices::Entry::parse("b 1:3 rwm")},
vector<devices::Entry>{},
vector<OpenArgs>{},
// /dev/null is blocked
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only because the entry has the wrong device type though, which isn't very clear here

@bmahler bmahler closed this in b58bd7c Mar 29, 2024
@DevinLeamy DevinLeamy deleted the device-tests branch April 1, 2024 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants