Debian Codegraph @

tests/fs-tests/stress/atoms/rndrm00.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 rndrm00cxx . . $ rndrm00(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, "rndrm00_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 /* Create and remove sub-dirs and small files, */
51 /* but tending to grow */
52 do {
53 if (tests_random_nocxx . . $ tests_random_no(ecdaa1632f49f591).(3)) {
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 } else {
59 this_size = tests_remove_entrycxx . . $ tests_remove_entry(da6335ded91d79c2).();
60 size -= this_size;
61 if (size < 0)
62 size = 0;
63 if (!this_size)
64 this_size = 1;
65 }
66 } while (this_size &&
67 (tests_size_parametercxx . . $ tests_size_parameter. == 0 ||
68 size < tests_size_parametercxx . . $ tests_size_parameter.));
69 /* Create and remove sub-dirs and small files, but */
70 /* but tending to shrink */
71 do {
72 if (!tests_random_nocxx . . $ tests_random_no(ecdaa1632f49f591).(3)) {
73 this_size = tests_create_entrycxx . . $ tests_create_entry(d2cd1729a8aa36c).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
74 size += this_size;
75 } else {
76 this_size = tests_remove_entrycxx . . $ tests_remove_entry(da6335ded91d79c2).();
77 size -= this_size;
78 if (size < 0)
79 size = 0;
80 }
81 } while ((tests_size_parametercxx . . $ tests_size_parameter. != 0 &&
82 size > tests_size_parametercxx . . $ tests_size_parameter. / 10) ||
83 (tests_size_parametercxx . . $ tests_size_parameter. == 0 && size > 100000));
84 /* Break if repeat count exceeded */
85 if (tests_repeat_parametercxx . . $ tests_repeat_parameter. > 0 && --repeat <= 0)
86 break;
87 /* Sleep */
88 if (tests_sleep_parametercxx . . $ tests_sleep_parameter. > 0) {
89 unsigned us = tests_sleep_parametercxx . . $ tests_sleep_parameter. * 1000;
90 unsigned rand_divisor = RAND_MAXcxx . . $ `<external>/10696550936717951914/stdlib.h:87:9`! / us;
91 unsigned s = (us / 2) + (randcxx . . $ rand(b126dc7c1de90089).() / rand_divisor);
92 usleepcxx . . $ usleep(4c679297bf94b9eb).(s);
93 }
94 }
95 /* Tidy up by removing everything */
96 tests_clear_dircxx . . $ tests_clear_dir(85c52e162fed56f9).(".");
97 CHECKcxx . . $ `tests/fs-tests/lib/tests.h:27:9`!(chdir("..") != -1);
98 CHECKcxx . . $ `tests/fs-tests/lib/tests.h:27:9`!(rmdir(dir_name) != -1);
99 }
100
101 /* Title of this test */
102
103 static const char *rndrm00_get_titlecxx . . $ rndrm00_get_title(33a1f659e94feb42).(void)
104 {
105 return "Randomly create and remove directories and files";
106 }
107
108 /* Description of this test */
109
110 static const char *rndrm00_get_descriptioncxx . . $ rndrm00_get_description(33a1f659e94feb42).(void)
111 {
112 return
113 "Create a directory named rndrm00_test_dir_pid, where " \
114 "pid is the process id. Within that directory, " \
115 "randomly create and remove " \
116 "a number of sub-directories and small files, " \
117 "but do more creates than removes. " \
118 "When the total size of all sub-directories and files " \
119 "is greater than the size specified by the size parameter, " \
120 "start to do more removes than creates. " \
121 "The size parameter is given by the -z or --size option, " \
122 "otherwise it defaults to 1000000. " \
123 "A size of zero fills the file system until there is no "
124 "space left. " \
125 "The task repeats, sleeping in between each iteration. " \
126 "The repeat count is set by the -n or --repeat option, " \
127 "otherwise it defaults to 1. " \
128 "A repeat count of zero repeats forever. " \
129 "The sleep value is given by the -p or --sleep option, " \
130 "otherwise it defaults to 0. "
131 "Sleep is specified in milliseconds.";
132 }
133
134 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
135 {
136 int run_test;
137
138 /* Set default test size */
139 tests_size_parametercxx . . $ tests_size_parameter. = 1000000;
140
141 /* Set default test repetition */
142 tests_repeat_parametercxx . . $ tests_repeat_parameter. = 1;
143
144 /* Set default test sleep */
145 tests_sleep_parametercxx . . $ tests_sleep_parameter. = 0;
146
147 /* Handle common arguments */
148 run_test = tests_get_argscxx . . $ tests_get_args(bd0b62ce3c119765).(argc, argv, rndrm00_get_titlecxx . . $ rndrm00_get_title(33a1f659e94feb42).(),
149 rndrm00_get_descriptioncxx . . $ rndrm00_get_description(33a1f659e94feb42).(), "znp");
150 if (!run_test)
151 return 1;
152 /* Change directory to the file system and check it is ok for testing */
153 tests_check_test_file_systemcxx . . $ tests_check_test_file_system(49f6e7a06ebc5aa8).();
154 /* Do the actual test */
155 rndrm00cxx . . $ rndrm00(49f6e7a06ebc5aa8).();
156 return 0;
157 }