Debian Codegraph @

tests/fs-tests/stress/atoms/rmdir00.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2007 Nokia Corporation.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16 * 02110-1301 USA
17 *
18 * Author: Adrian Hunter
19 */
20
21 #include <unistd.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdint.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <fcntl.h>
29 #include <errno.h>
30
31 #include "tests.h"cxx . . $ `<file>/tests/fs-tests/lib/tests.h`/
32
33 static void rmdir00cxx . . $ rmdir00(49f6e7a06ebc5aa8).(void)
34 {
35 int64_tcxx . . $ int64_t# repeat;
36 int64_tcxx . . $ int64_t# size, this_size;
37 pid_tcxx . . $ pid_t# pid;
38 char dir_name[256];
39
40 /* Create a directory to test in */
41 pid = getpidcxx . . $ getpid(b126dc7c1de90089).();
42 tests_cat_pidcxx . . $ tests_cat_pid(3366d352079c3ed6).(dir_name, "rmdir00_test_dir_", pid);
43 if (chdircxx . . $ chdir(5c4306d8553b3696).(dir_name) == -1)
44 CHECKcxx . . $ `tests/fs-tests/lib/tests.h:27:9`!(mkdir(dir_name, 0777) != -1);
45 CHECKcxx . . $ `tests/fs-tests/lib/tests.h:27:9`!(chdir(dir_name) != -1);
46 /* Repeat loop */
47 repeat = tests_repeat_parametercxx . . $ tests_repeat_parameter.;
48 size = 0;
49 for (;;) {
50 /* Remove everything in the directory */
51 tests_clear_dircxx . . $ tests_clear_dir(85c52e162fed56f9).(".");
52 /* Fill with sub-dirs and small files */
53 do {
54 this_size = tests_create_entrycxx . . $ tests_create_entry(d2cd1729a8aa36c).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
55 if (!this_size)
56 break;
57 size += this_size;
58 } while (this_size &&
59 (tests_size_parametercxx . . $ tests_size_parameter. == 0 ||
60 size < tests_size_parametercxx . . $ tests_size_parameter.));
61 /* Break if repeat count exceeded */
62 if (tests_repeat_parametercxx . . $ tests_repeat_parameter. > 0 && --repeat <= 0)
63 break;
64 /* Sleep */
65 if (tests_sleep_parametercxx . . $ tests_sleep_parameter. > 0) {
66 unsigned us = tests_sleep_parametercxx . . $ tests_sleep_parameter. * 1000;
67 unsigned rand_divisor = RAND_MAXcxx . . $ `<external>/10696550936717951914/stdlib.h:87:9`! / us;
68 unsigned s = (us / 2) + (randcxx . . $ rand(b126dc7c1de90089).() / rand_divisor);
69 usleepcxx . . $ usleep(4c679297bf94b9eb).(s);
70 }
71 }
72 /* Tidy up by removing everything */
73 tests_clear_dircxx . . $ tests_clear_dir(85c52e162fed56f9).(".");
74 CHECKcxx . . $ `tests/fs-tests/lib/tests.h:27:9`!(chdir("..") != -1);
75 CHECKcxx . . $ `tests/fs-tests/lib/tests.h:27:9`!(rmdir(dir_name) != -1);
76 }
77
78 /* Title of this test */
79
80 static const char *rmdir00_get_titlecxx . . $ rmdir00_get_title(33a1f659e94feb42).(void)
81 {
82 return "Create and remove directories and files";
83 }
84
85 /* Description of this test */
86
87 static const char *rmdir00_get_descriptioncxx . . $ rmdir00_get_description(33a1f659e94feb42).(void)
88 {
89 return
90 "Create a directory named rmdir00_test_dir_pid, where " \
91 "pid is the process id. Within that directory, create " \
92 "a number of sub-directories and small files. " \
93 "The total size of all sub-directories and files " \
94 "is specified by the size parameter. " \
95 "The size parameter is given by the -z or --size option, " \
96 "otherwise it defaults to 1000000. " \
97 "A size of zero fills the file system until there is no "
98 "space left. " \
99 "The task repeats, sleeping in between each iteration, " \
100 "and then removing the sub-directories and files created " \
101 "during the last iteration. " \
102 "The repeat count is set by the -n or --repeat option, " \
103 "otherwise it defaults to 1. " \
104 "A repeat count of zero repeats forever. " \
105 "The sleep value is given by the -p or --sleep option, " \
106 "otherwise it defaults to 0. "
107 "Sleep is specified in milliseconds.";
108 }
109
110 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
111 {
112 int run_test;
113
114 /* Set default test size */
115 tests_size_parametercxx . . $ tests_size_parameter. = 1000000;
116
117 /* Set default test repetition */
118 tests_repeat_parametercxx . . $ tests_repeat_parameter. = 1;
119
120 /* Set default test sleep */
121 tests_sleep_parametercxx . . $ tests_sleep_parameter. = 0;
122
123 /* Handle common arguments */
124 run_test = tests_get_argscxx . . $ tests_get_args(bd0b62ce3c119765).(argc, argv, rmdir00_get_titlecxx . . $ rmdir00_get_title(33a1f659e94feb42).(),
125 rmdir00_get_descriptioncxx . . $ rmdir00_get_description(33a1f659e94feb42).(), "znp");
126 if (!run_test)
127 return 1;
128 /* Change directory to the file system and check it is ok for testing */
129 tests_check_test_file_systemcxx . . $ tests_check_test_file_system(49f6e7a06ebc5aa8).();
130 /* Do the actual test */
131 rmdir00cxx . . $ rmdir00(49f6e7a06ebc5aa8).();
132 return 0;
133 }