[LTP] [PATCH v2 4/4] syscalls/statfs: Accept segfault instead of EFAULT
Cyril Hrubis
chrubis@suse.cz
Mon Aug 22 16:11:13 CEST 2022
> int main(int ac, char **av)
> {
> int lc;
> @@ -67,23 +73,20 @@ int main(int ac, char **av)
> tst_count = 0;
>
> for (i = 0; i < TST_TOTAL; i++) {
> + sig_caught = 0;
> + if (sigsetjmp(env, 1) == 0)
> + fstatfs_verify(&TC[i]);
>
> - TEST(fstatfs(TC[i].fd, TC[i].sbuf));
> + if (!sig_caught)
> + continue;
>
> - if (TEST_RETURN != -1) {
> - tst_resm(TFAIL, "call succeeded unexpectedly");
> + if (TC[i].error == EFAULT && sig_caught == SIGSEGV) {
> + tst_resm(TINFO, "received SIGSEGV instead of returning EFAULT");
> + tst_resm(TPASS | TTERRNO, "expected failure");
This can be just a signle message tst_resm(TPASS | TERRNO, "Got SIGSEGV intead of EFAULT");
> continue;
> }
>
> - if (TEST_ERRNO == TC[i].error) {
> - tst_resm(TPASS, "expected failure - "
> - "errno = %d : %s", TEST_ERRNO,
> - strerror(TEST_ERRNO));
> - } else {
> - tst_resm(TFAIL, "unexpected error - %d : %s - "
> - "expected %d", TEST_ERRNO,
> - strerror(TEST_ERRNO), TC[i].error);
> - }
> + tst_resm(TFAIL, "Received an unexpected signal: %d", sig_caught);
> }
> }
> cleanup();
> @@ -91,9 +94,16 @@ int main(int ac, char **av)
> tst_exit();
> }
>
> +static void sighandler(int sig)
> +{
> + sig_caught = sig;
> + siglongjmp(env, 1);
> +
> +}
> +
> static void setup(void)
> {
> - tst_sig(NOFORK, DEF_HANDLER, cleanup);
> + tst_sig(NOFORK, sighandler, cleanup);
Can we just setup handler for the SIGSEGV signal and keep everything
else for the DEF_HANDLER?
> TEST_PAUSE;
>
> @@ -103,6 +113,24 @@ static void setup(void)
> #endif
> }
>
> +static void fstatfs_verify(const struct test_case_t *test)
> +{
> + TEST(fstatfs(test->fd, test->sbuf));
> +
> + if (TEST_RETURN != -1) {
> + tst_resm(TFAIL, "call succeeded unexpectedly");
> + return;
> + }
> +
> + if (TEST_ERRNO == test->error) {
> + tst_resm(TPASS, "expected failure - errno = %d : %s",
> + TEST_ERRNO, strerror(TEST_ERRNO));
> + } else {
> + tst_resm(TFAIL, "unexpected error - %d : %s - expected %d",
> + TEST_ERRNO, strerror(TEST_ERRNO), test->error);
> + }
> +}
If we converted the test to the new test API this would be a single line as:
TST_EXP_FAIL(fstatfs(test->fd, test->sbuf), test->error, "fstatfs()");
Generally with the new test api the code would be much shorter...
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list