1 /* 2 * Copyright (c) 2017 The Chromium OS Authors. All rights reserved. 3 * Use of this source code is governed by a BSD-style license that can be 4 * found in the LICENSE file. 5 */ 6 7 /* Required for clock_adjtime(3). */ 8 #define _GNU_SOURCE 9 10 #include <errno.h> 11 #include <string.h> 12 #include <time.h> 13 14 #include <sys/time.h> 15 #include <sys/timex.h> 16 17 /* This program is expected to run under android alt-syscall. */ main(void)18int main(void) { 19 struct timex buf; 20 int ret; 21 22 /* Test read operation. Should succeed (i.e. not returning -1). */ 23 memset(&buf, 0, sizeof(buf)); 24 ret = clock_adjtime(CLOCK_REALTIME, &buf); 25 if (ret == -1) 26 return 1; 27 28 /* Test with nullptr buffer. Should fail with EFAULT. */ 29 ret = clock_adjtime(CLOCK_REALTIME, NULL); 30 if (ret != -1 || errno != EFAULT) 31 return 2; 32 33 /* 34 * Test a write operation. Under android alt-syscall, should fail with 35 * EPERM. 36 */ 37 buf.modes = ADJ_MAXERROR; 38 ret = clock_adjtime(CLOCK_REALTIME, &buf); 39 if (ret != -1 || errno != EPERM) 40 return 3; 41 42 /* Passed successfully */ 43 return 0; 44 } 45