Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright (c) 2015 Dmitry V. Levin <ldv (at) altlinux.org>
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. The name of the author may not be used to endorse or promote products
     14  *    derived from this software without specific prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #include <stdio.h>
     29 #include <stdint.h>
     30 #include <unistd.h>
     31 #include <sys/time.h>
     32 #include <sys/syscall.h>
     33 
     34 int
     35 main(void)
     36 {
     37 	struct {
     38 		struct timeval tv;
     39 		uint32_t pad0[2];
     40 		struct timezone tz;
     41 		uint32_t pad1[2];
     42 	} t = {
     43 		.pad0 = { 0xdeadbeef, 0xbadc0ded },
     44 		.pad1 = { 0xdeadbeef, 0xbadc0ded }
     45 	};
     46 
     47 	if (syscall(__NR_gettimeofday, &t.tv, NULL))
     48 		return 77;
     49 	printf("gettimeofday({%jd, %jd}, NULL) = 0\n",
     50 	       (intmax_t) t.tv.tv_sec, (intmax_t) t.tv.tv_usec);
     51 
     52 	if (syscall(__NR_gettimeofday, &t.tv, &t.tz))
     53 		return 77;
     54 	printf("gettimeofday({%jd, %jd}"
     55 	       ", {tz_minuteswest=%d, tz_dsttime=%d}) = 0\n",
     56 	       (intmax_t) t.tv.tv_sec, (intmax_t) t.tv.tv_usec,
     57 	       t.tz.tz_minuteswest, t.tz.tz_dsttime);
     58 
     59 	t.tv.tv_sec = -1;
     60 	t.tv.tv_usec = 1000000000;
     61 	if (!settimeofday(&t.tv, &t.tz))
     62 		return 77;
     63 	printf("settimeofday({%jd, %jd}"
     64 	       ", {tz_minuteswest=%d, tz_dsttime=%d})"
     65 	       " = -1 EINVAL (Invalid argument)\n",
     66 	       (intmax_t) t.tv.tv_sec, (intmax_t) t.tv.tv_usec,
     67 	       t.tz.tz_minuteswest, t.tz.tz_dsttime);
     68 
     69 	puts("+++ exited with 0 +++");
     70 	return 0;
     71 }
     72