Home | History | Annotate | Download | only in tests-mx32
      1 /*
      2  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv (at) altlinux.org>
      3  * Copyright (c) 2015-2018 The strace developers.
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include "tests.h"
     30 #include <stdio.h>
     31 #include <stdint.h>
     32 #include <time.h>
     33 #include <unistd.h>
     34 #include <asm/unistd.h>
     35 
     36 #if defined __NR_clock_getres \
     37  && defined __NR_clock_gettime \
     38  && defined __NR_clock_settime
     39 
     40 int
     41 main(void)
     42 {
     43 	struct {
     44 		struct timespec ts;
     45 		uint32_t pad[2];
     46 	} t = {
     47 		.pad = { 0xdeadbeef, 0xbadc0ded }
     48 	};
     49 	long rc;
     50 
     51 	if (syscall(__NR_clock_getres, CLOCK_REALTIME, &t.ts))
     52 		perror_msg_and_skip("clock_getres CLOCK_REALTIME");
     53 	printf("clock_getres(CLOCK_REALTIME, {tv_sec=%lld, tv_nsec=%llu})"
     54 	       " = 0\n",
     55 	       (long long) t.ts.tv_sec,
     56 	       zero_extend_signed_to_ull(t.ts.tv_nsec));
     57 
     58 	if (syscall(__NR_clock_gettime, CLOCK_PROCESS_CPUTIME_ID, &t.ts))
     59 		perror_msg_and_skip("clock_gettime CLOCK_PROCESS_CPUTIME_ID");
     60 	printf("clock_gettime(CLOCK_PROCESS_CPUTIME_ID"
     61 	       ", {tv_sec=%lld, tv_nsec=%llu}) = 0\n",
     62 	       (long long) t.ts.tv_sec,
     63 	       zero_extend_signed_to_ull(t.ts.tv_nsec));
     64 
     65 	t.ts.tv_sec = 0xdeface1;
     66 	t.ts.tv_nsec = 0xdeface2;
     67 	rc = syscall(__NR_clock_settime, CLOCK_THREAD_CPUTIME_ID, &t.ts);
     68 	printf("clock_settime(CLOCK_THREAD_CPUTIME_ID"
     69 	       ", {tv_sec=%lld, tv_nsec=%llu}) = %s\n",
     70 	       (long long) t.ts.tv_sec,
     71 	       zero_extend_signed_to_ull(t.ts.tv_nsec), sprintrc(rc));
     72 
     73 	t.ts.tv_sec = 0xdeadbeefU;
     74 	t.ts.tv_nsec = 0xfacefeedU;
     75 	rc = syscall(__NR_clock_settime, CLOCK_THREAD_CPUTIME_ID, &t.ts);
     76 	printf("clock_settime(CLOCK_THREAD_CPUTIME_ID"
     77 	       ", {tv_sec=%lld, tv_nsec=%llu}) = %s\n",
     78 	       (long long) t.ts.tv_sec,
     79 	       zero_extend_signed_to_ull(t.ts.tv_nsec), sprintrc(rc));
     80 
     81 	t.ts.tv_sec = (time_t) 0xcafef00ddeadbeefLL;
     82 	t.ts.tv_nsec = (long) 0xbadc0dedfacefeedLL;
     83 	rc = syscall(__NR_clock_settime, CLOCK_THREAD_CPUTIME_ID, &t.ts);
     84 	printf("clock_settime(CLOCK_THREAD_CPUTIME_ID"
     85 	       ", {tv_sec=%lld, tv_nsec=%llu}) = %s\n",
     86 	       (long long) t.ts.tv_sec,
     87 	       zero_extend_signed_to_ull(t.ts.tv_nsec), sprintrc(rc));
     88 
     89 	puts("+++ exited with 0 +++");
     90 	return 0;
     91 }
     92 
     93 #else
     94 
     95 SKIP_MAIN_UNDEFINED("__NR_clock_getres && __NR_clock_gettime && __NR_clock_settime")
     96 
     97 #endif
     98