Home | History | Annotate | Download | only in futex
      1 /*
      2  * Copyright (C) 2015 Cyril Hrubis <chrubis (at) suse.cz>
      3  *
      4  * Based on futextest (futext_wait_uninitialized_heap.c)
      5  * written by KOSAKI Motohiro <kosaki.motohiro (at) jp.fujitsu.com>
      6  *
      7  * Licensed under the GNU GPLv2 or later.
      8  * This program is free software;  you can redistribute it and/or modify
      9  * it under the terms of the GNU General Public License as published by
     10  * the Free Software Foundation; either version 2 of the License, or
     11  * (at your option) any later version.
     12  *
     13  * This program is distributed in the hope that it will be useful,
     14  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
     15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     16  * the GNU General Public License for more details.
     17  *
     18  * You should have received a copy of the GNU General Public License
     19  * along with this program;  if not, write to the Free Software
     20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     21  */
     22  /*
     23   * Wait on uninitialized heap. It shold be zero and FUTEX_WAIT should return
     24   * immediately. This test tests zero page handling in futex code.
     25   */
     26 
     27 #include <errno.h>
     28 
     29 #include "test.h"
     30 #include "safe_macros.h"
     31 #include "futextest.h"
     32 
     33 const char *TCID="futex_wait04";
     34 const int TST_TOTAL=1;
     35 static struct timespec to = {.tv_sec = 0, .tv_nsec = 10000};
     36 
     37 static void verify_futex_wait(void)
     38 {
     39 	int res;
     40 	void *buf;
     41 	size_t pagesize = getpagesize();
     42 	buf = SAFE_MMAP(NULL, NULL, pagesize, PROT_READ|PROT_WRITE,
     43                         MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
     44 
     45 	res = futex_wait(buf, 1, &to, 0);
     46 
     47 	if (res == -1 && errno == EWOULDBLOCK)
     48 		tst_resm(TPASS | TERRNO, "futex_wait() returned %i", res);
     49 	else
     50 		tst_resm(TFAIL | TERRNO, "futex_wait() returned %i", res);
     51 
     52 	SAFE_MUNMAP(NULL, buf, pagesize);
     53 }
     54 
     55 int main(int argc, char *argv[])
     56 {
     57 	int lc;
     58 
     59 	tst_parse_opts(argc, argv, NULL, NULL);
     60 
     61 	for (lc = 0; TEST_LOOPING(lc); lc++)
     62 		verify_futex_wait();
     63 
     64 	tst_exit();
     65 }
     66