MCPcopy Create free account
hub / github.com/axboe/liburing / test_exec

Function test_exec

test/defer-taskrun.c:169–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167}
168
169static int test_exec(const char *filename)
170{
171 int ret;
172 int fd;
173 struct io_uring ring;
174 pid_t fork_pid;
175 static char * const new_argv[] = {"1", "2", "3", NULL};
176 static char * const new_env[] = {NULL};
177 char *buff;
178
179 fork_pid = fork();
180 CHECK(fork_pid >= 0);
181 if (fork_pid > 0) {
182 int wstatus;
183
184 CHECK(waitpid(fork_pid, &wstatus, 0) != (pid_t)-1);
185 if (!WIFEXITED(wstatus) || WEXITSTATUS(wstatus) == T_EXIT_FAIL) {
186 fprintf(stderr, "child failed %i\n", WEXITSTATUS(wstatus));
187 return -1;
188 }
189 return T_EXIT_PASS;
190 }
191
192 ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER |
193 IORING_SETUP_DEFER_TASKRUN);
194 if (ret)
195 return ret;
196
197 if (filename) {
198 fd = open(filename, O_RDONLY | O_DIRECT);
199 if (fd < 0 && (errno == EINVAL || errno == EPERM || errno == EACCES))
200 return T_EXIT_SKIP;
201 } else {
202 t_create_file(EXEC_FILENAME, EXEC_FILESIZE);
203 fd = open(EXEC_FILENAME, O_RDONLY | O_DIRECT);
204 if (fd < 0 && (errno == EINVAL || errno == EPERM || errno == EACCES)) {
205 unlink(EXEC_FILENAME);
206 return T_EXIT_SKIP;
207 }
208 unlink(EXEC_FILENAME);
209 }
210 buff = (char*)malloc(EXEC_FILESIZE);
211 CHECK(posix_memalign((void **)&buff, 4096, EXEC_FILESIZE) == 0);
212 CHECK(buff);
213
214 CHECK(fd >= 0);
215 io_uring_prep_read(io_uring_get_sqe(&ring), fd, buff, EXEC_FILESIZE, 0);
216 io_uring_submit(&ring);
217 ret = execve("/proc/self/exe", new_argv, new_env);
218 /* if we get here it failed anyway */
219 fprintf(stderr, "execve failed %d\n", ret);
220 return T_EXIT_FAIL;
221}
222
223static int test_flag(void)
224{

Callers 1

mainFunction · 0.70

Calls 4

io_uring_queue_initFunction · 0.85
t_create_fileFunction · 0.85
io_uring_submitFunction · 0.85
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected