On Thu, Sep 5, 2019 at 7:40 PM Stanislav Fomichev <sdf@xxxxxxxxxx> wrote: > > test__join_cgroup() combines the following operations that usually > go hand in hand and returns cgroup fd: > > * setup cgroup environment (make sure cgroupfs is mounted) > * mkdir cgroup > * join cgroup > > It also marks a test as a "cgroup cleanup needed" and removes cgroup > state after the test is done. > > Signed-off-by: Stanislav Fomichev <sdf@xxxxxxxxxx> > --- First of all, thanks a lot for all these improvements to test_progs and converting existing tests to test_progs tests, it's great to see this consolidation! [...] > @@ -17,6 +18,7 @@ struct prog_test_def { > int error_cnt; > int skip_cnt; > bool tested; > + bool need_cgroup_cleanup; > > const char *subtest_name; > int subtest_num; > @@ -122,6 +124,39 @@ void test__fail(void) > env.test->error_cnt++; > } > > +int test__join_cgroup(const char *path) This doesn't seem to be testing-specific functionality, tbh. It's certainly useful helper, but I don't think it warrants test__ prefix. As for test->need_cgroup_cleanup field, this approach won't scale if we need other types of custom/optional clean up after test ends. Generic test framework code will need to know about every possible custom setup to be able to cleanup/undo it. I wonder if generalizing it to be able to add custom clean up code (some test frameworks have "teardown" overrides for this) would be cleaner and more maintainable solution. Something like: typedef void (* test_teardown_fn)(struct test *test, void *ctx); /* somewhere at the beginning of test: */ test__schedule_teardown(test_teardown_fn cb, void *ctx); [...] > + > + if (test->need_cgroup_cleanup) > + cleanup_cgroup_environment(); Then in generic framework we'll just process a list of callbacks and call each one with stored ctx per each callback (in case we need some custom data to be stored, of course). Thoughts? [...]