]> granicus.if.org Git - strace/blob - tests/delete_module.c
tests: use fixed timestamps in utime related tests
[strace] / tests / delete_module.c
1 /*
2  * Check decoding of delete_module syscall.
3  *
4  * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include "tests.h"
31
32 #include <asm/unistd.h>
33
34 #if defined(__NR_delete_module)
35
36 # include <fcntl.h>
37 # include <stdio.h>
38 # include <unistd.h>
39
40 # include "init_delete_module.h"
41
42 int
43 main(void)
44 {
45         static const struct {
46                 kernel_ulong_t val;
47                 const char *str;
48                 unsigned int val_prefix, val_suffix;
49         } flags[] = {
50                 { ARG_STR(0), 0, 0 },
51                 { F8ILL_KULONG_MASK | O_NONBLOCK, "O_NONBLOCK", 0, 0 },
52                 { (kernel_ulong_t) 0xbadc0dedfacef157ULL & ~(O_NONBLOCK | O_TRUNC),
53                         " /* O_??? */", 0xfacef157U & ~(O_NONBLOCK | O_TRUNC), 0},
54                 { (kernel_ulong_t) (0xfacef157deade71cULL & ~O_NONBLOCK) | O_TRUNC,
55                         "O_TRUNC", 0, 0xdeade71c & ~(O_NONBLOCK | O_TRUNC)},
56                 { -1LL, "O_NONBLOCK|O_TRUNC", 0, -1U & ~(O_NONBLOCK | O_TRUNC)},
57         };
58
59         long rc;
60         char *bogus_param1 = tail_alloc(PARAM1_LEN);
61         char *bogus_param2 = tail_alloc(PARAM2_LEN);
62         const char *errstr;
63
64         fill_memory_ex(bogus_param1, PARAM1_LEN, PARAM1_BASE, PARAM1_LEN);
65         fill_memory_ex(bogus_param2, PARAM2_LEN, PARAM2_BASE, PARAM2_LEN);
66
67         rc = syscall(__NR_delete_module, NULL, F8ILL_KULONG_MASK);
68         printf("delete_module(NULL, 0) = %s\n", sprintrc(rc));
69
70         rc = syscall(__NR_delete_module, bogus_param1, flags[0].val);
71         errstr = sprintrc(rc);
72
73         printf("delete_module(\"");
74         print_str(PARAM1_BASE, MAX_STRLEN, false);
75         printf("\"..., %s) = %s\n", flags[0].str, errstr);
76
77         bogus_param1[PARAM1_LEN - 1] = '\0';
78
79         rc = syscall(__NR_delete_module, bogus_param1, flags[1].val);
80         errstr = sprintrc(rc);
81
82         printf("delete_module(\"");
83         print_str(PARAM1_BASE, MAX_STRLEN, false);
84         printf("\", %s) = %s\n", flags[1].str, errstr);
85
86         rc = syscall(__NR_delete_module, bogus_param2 + PARAM2_LEN,
87                 flags[2].val);
88         printf("delete_module(%p, %#x%s) = %s\n",
89                bogus_param2 + PARAM2_LEN, flags[2].val_prefix,
90                flags[2].str, sprintrc(rc));
91
92         rc = syscall(__NR_delete_module, bogus_param2, flags[3].val);
93         printf("delete_module(%p, %s|%#x) = %s\n",
94                bogus_param2, flags[3].str, flags[3].val_suffix, sprintrc(rc));
95
96         bogus_param2[PARAM2_LEN - 1] = '\0';
97
98         rc = syscall(__NR_delete_module, bogus_param2, flags[4].val);
99         errstr = sprintrc(rc);
100
101         printf("delete_module(\"");
102         print_str(PARAM2_BASE, PARAM2_LEN - 1, true);
103         printf("\", %s|%#x) = %s\n", flags[4].str, flags[4].val_suffix, errstr);
104
105         puts("+++ exited with 0 +++");
106
107         return 0;
108 }
109
110 #else
111
112 SKIP_MAIN_UNDEFINED("__NR_delete_module");
113
114 #endif