[LTP] [PATCH 2/3] syscalls/alarm03: Rewrite to new library

Cyril Hrubis chrubis@suse.cz
Wed Jul 25 16:20:30 CEST 2018


Hi!
> +	TEST(alarm(100));
> +
> +	pid = SAFE_FORK();
> +	if (pid == 0) {
> +		TEST(alarm(0));
> +		if (TEST_RETURN != 0) {
> +			tst_res(TFAIL,
> +				"alarm(100), fork, alarm(0) child's "
> +				"alarm returned %ld", TEST_RETURN);
> +		} else {
> +			tst_res(TPASS,
> +				"alarm(100), fork, alarm(0) child's "
> +				"alarm returned %ld", TEST_RETURN);
>  		}
> -
> +		exit(0);
> +	} else {
> +		TEST(alarm(0));
> +		if (TEST_RETURN <= 0 || TEST_RETURN > 101) {
> +			tst_res(TFAIL,
> +				"alarm(100), fork, alarm(0) parent's "
> +				"alarm returned %ld", TEST_RETURN);
> +		} else {
> +			tst_res(TPASS,
> +				"alarm(100), fork, alarm(0) parent's "
> +				"alarm returned %ld", TEST_RETURN);
> +		}
> +		tst_reap_children();

There is no need for the else branch here as the child calls exit(0);

>  }
>  
> -void setup(void)
> +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
>  {
> -
> -	tst_sig(FORK, DEF_HANDLER, cleanup);
> -
> -	signal(SIGALRM, trapper);
> -
> -	TEST_PAUSE;
> +	SAFE_SIGNAL(SIGALRM, sighandler);

I do wonder why do we call the SAFE_SIGNAL() here?

It does not make much sense.

>  }
>  
> -void cleanup(void)
> +static void setup(void)
>  {
> +	SAFE_SIGNAL(SIGALRM, sighandler);
>  }
>  
> -void trapper(int sig)
> -{
> -	signal(SIGALRM, trapper);
> -}
> +static struct tst_test test = {
> +	.test_all = verify_alarm,
> +	.setup = setup,
> +	.forks_child = 1,
> +};
> -- 
> 1.8.3.1
> 
> 
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list