Home | History | Annotate | Download | only in futex
      1 /*
      2  * Copyright (C) 2015-2017 Cyril Hrubis <chrubis (at) suse.cz>
      3  *
      4  * Licensed under the GNU GPLv2 or later.
      5  * This program is free software;  you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License as published by
      7  * the Free Software Foundation; either version 2 of the License, or
      8  * (at your option) any later version.
      9  *
     10  * This program is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     13  * the GNU General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU General Public License
     16  * along with this program;  if not, write to the Free Software
     17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     18  */
     19  /*
     20   * 1. Block on a futex and wait for timeout.
     21   * 2. Check that the futex waited for expected time.
     22   */
     23 
     24 #include <errno.h>
     25 
     26 #include "tst_timer_test.h"
     27 #include "futextest.h"
     28 
     29 int sample_fn(int clk_id, long long usec)
     30 {
     31 	struct timespec to = tst_us_to_timespec(usec);
     32 	futex_t futex = FUTEX_INITIALIZER;
     33 
     34 	tst_timer_start(clk_id);
     35 	TEST(futex_wait(&futex, futex, &to, 0));
     36 	tst_timer_stop();
     37 	tst_timer_sample();
     38 
     39 	if (TEST_RETURN != -1) {
     40 		tst_res(TFAIL, "futex_wait() returned %li, expected -1",
     41 		         TEST_RETURN);
     42 		return 1;
     43 	}
     44 
     45 	if (TEST_ERRNO != ETIMEDOUT) {
     46 		tst_res(TFAIL | TTERRNO, "expected errno=%s",
     47 		        tst_strerrno(ETIMEDOUT));
     48 		return 1;
     49 	}
     50 
     51 	return 0;
     52 }
     53 
     54 static struct tst_test test = {
     55 	.scall = "futex_wait()",
     56 	.sample = sample_fn,
     57 };
     58