]> granicus.if.org Git - strace/blob - tests/getcpu.c
6e1f548471c8e467fa730bc677c6e7a3972dbf54
[strace] / tests / getcpu.c
1 /*
2  * Check decoding of getcpu syscall.
3  *
4  * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5  * Copyright (c) 2016-2017 The strace developers.
6  * All rights reserved.
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #include "tests.h"
12
13 #include <asm/unistd.h>
14
15 #ifdef __NR_getcpu
16
17 # include <stdio.h>
18 # include <unistd.h>
19
20 int
21 main(void)
22 {
23         unsigned *bogus_cpu =
24                 (unsigned *) tail_alloc(sizeof(*bogus_cpu)) + 1;
25         unsigned *bogus_node =
26                 (unsigned *) tail_alloc(sizeof(*bogus_node)) + 1;
27         unsigned *bogus_tcache =
28                 (unsigned *) tail_alloc(sizeof(*bogus_tcache)) + 1;
29
30         long res;
31         TAIL_ALLOC_OBJECT_CONST_PTR(unsigned, cpu);
32         TAIL_ALLOC_OBJECT_CONST_PTR(unsigned, node);
33         long *tcache = tail_alloc(128);
34
35         res = syscall(__NR_getcpu, NULL, NULL, NULL);
36         printf("getcpu(NULL, NULL, NULL) = %s\n", sprintrc(res));
37
38         res = syscall(__NR_getcpu, bogus_cpu, bogus_node, bogus_tcache);
39         printf("getcpu(%p, %p, %p) = %s\n",
40                bogus_cpu, bogus_node, bogus_tcache, sprintrc(res));
41
42         res = syscall(__NR_getcpu, cpu, node, tcache);
43         if (res != 0)
44                 perror_msg_and_skip("getcpu");
45
46         printf("getcpu([%u], [%u], %p) = 0\n", *cpu, *node, tcache);
47
48         puts("+++ exited with 0 +++");
49
50         return 0;
51 }
52
53 #else
54
55 SKIP_MAIN_UNDEFINED("__NR_getcpu");
56
57 #endif