<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p><font size="4">Hi Petr,</font></p>
<p><font size="4">can TST_TEST_CONF be used even if </font>TST_NO_DEFAULT_MAIN
is defined?<br>
</p>
<p>Andrea<br>
</p>
<div class="moz-cite-prefix">On 4/4/22 12:33, Petr Vorel wrote:<br>
</div>
<blockquote type="cite" cite="mid:YkrJfb0vZq6WSZmX@pevik">
<pre class="moz-quote-pre" wrap="">Hi Andrea,
BTW it'd help reviewers a bit if you include a changelog.
Reviewed-by: Petr Vorel <a class="moz-txt-link-rfc2396E" href="mailto:pvorel@suse.cz"><pvorel@suse.cz></a>
TL;DR: TST_TEST_TCONF() in userns06_capcheck.c
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">diff --git a/testcases/kernel/containers/userns/userns06_capcheck.c b/testcases/kernel/containers/userns/userns06_capcheck.c
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">...
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">-/*
- * Verify that:
+/*\
+ * [Description]
+ *
* When a process with non-zero user IDs performs an execve(), the
* process's capability sets are cleared. When a process with zero
* user IDs performs an execve(), the process's capability sets
* are set.
*/
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">nit: I wonder if we want to have docparse documentation in both userns06.c and
userns06_capcheck.c, they now look as 2 separate tests. Maybe describe
everything in userns06.c.
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "config.h"
+
+#ifdef HAVE_LIBCAP
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">...
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">+ if (argc < 2)
+ tst_brk(TBROK, "userns06_capcheck <privileged|unprivileged>");
+
+ tst_reinit();
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">I'm not sure if tst_reinit() shouldn't be called even before tst_brk(TBROK, ...).
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">+
+ SAFE_FILE_SCANF("/proc/sys/kernel/cap_last_cap", "%d", &last_cap);
+
if (strcmp("privileged", argv[1]))
expected_flag = 0;
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">nit: It might help debugging to print argv[1] in TINF0.
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap=""> caps = cap_get_proc();
- SAFE_FILE_SCANF(NULL, "/proc/sys/kernel/cap_last_cap", "%d", &last_cap);
+
for (i = 0; i <= last_cap; i++) {
cap_get_flag(caps, i, CAP_EFFECTIVE, &flag_val);
if (flag_val != expected_flag)
break;
+
cap_get_flag(caps, i, CAP_PERMITTED, &flag_val);
if (flag_val != expected_flag)
break;
}
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">- if (flag_val != expected_flag) {
- printf("unexpected effective/permitted caps at %d\n", i);
- exit(1);
- }
+ if (flag_val != expected_flag)
+ tst_res(TFAIL, "unexpected effective/permitted caps at %d", i);
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">The flags are CAP_EFFECTIVE and CAP_PERMITTED only here, right?
(i.e. no CAP_INHERITABLE). Not sure how helpful would be to print here which
flag was the failing one.
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">+ else
+ tst_res(TPASS, "expected caps at %d", i);
+}
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap=""> #else
- printf("System is missing libcap.\n");
-#endif
- tst_exit();
+int main(void)
+{
+ tst_brk(TBROK, "System is missing libcap");
}
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">Why don't you also use TST_TEST_TCONF() here?
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">+#endif
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
Kind regards,
Petr
</pre>
</blockquote>
</body>
</html>