2 * Copyright (c) 2005 Zmanda, Inc. All Rights Reserved.
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 2.1 as
6 * published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11 * License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 * Contact information: Zmanda Inc., 505 N Mathlida Ave, Suite 120
18 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
25 /* global so the 'atexit' handler can access it */
28 cleanup_vtape_dir(char *device_path)
30 char *quoted = g_shell_quote(device_path);
31 char *cmd = vstralloc("rm -rf ", quoted, NULL);
33 /* would you rather write 'rm -rf' here? */
34 if (system(cmd) == -1) {
45 char *cwd = g_get_current_dir();
46 char *device_path = NULL;
47 char *data_dir = NULL;
49 device_path = vstralloc(cwd, "/vfs-test-XXXXXX", NULL);
52 if (mkdtemp(device_path) == NULL) {
53 fprintf(stderr, "Could not create temporary directory in %s\n", cwd);
57 /* append "/data/" to that for the VFS device*/
58 data_dir = vstralloc(device_path, "/data/", NULL);
59 if (mkdir(data_dir, 0777) == -1) {
60 fprintf(stderr, "Could not create %s: %s\n", cwd, strerror(errno));
70 setup_device(char *device_path)
73 char *device_name = NULL;
75 device_name = vstralloc("file:", device_path, NULL);
76 device = device_open(device_name);
78 fprintf(stderr, "Could not open device %s\n", device_name);
86 check_free_space(Device *device)
91 bzero(&value, sizeof(value));
92 if (!device_property_get(device, PROPERTY_FREE_SPACE, &value)) {
93 fprintf(stderr, "Could not get property_free_space\n");
97 qsize = *(QualifiedSize*)g_value_get_boxed(&value);
98 g_value_unset(&value);
100 if (qsize.accuracy != SIZE_ACCURACY_REAL) {
101 fprintf(stderr, "property_free_space accuracy is not SIZE_ACCURACY_REAL\n");
105 if (qsize.bytes == 0) {
106 fprintf(stderr, "property_free_space returned bytes=0\n");
114 main(int argc G_GNUC_UNUSED, char **argv G_GNUC_UNUSED)
116 Device *device = NULL;
118 char *device_path = NULL;
122 amanda_thread_init();
124 device_path = setup_vtape_dir();
126 /* run the tests in a subprocess so we can clean up even if they fail */
127 switch (pid = fork()) {
130 g_assert_not_reached();
135 device = setup_device(device_path);
139 ok = ok && check_free_space(device);
141 g_object_unref(device);
145 g_assert_not_reached();
147 default: /* parent */
148 if (waitpid(pid, &status, 0) == -1)
152 cleanup_vtape_dir(device_path);
155 /* figure our own return status */
156 if (WIFEXITED(status))
157 return WEXITSTATUS(status);
158 else if (WIFSIGNALED(status)) {
159 fprintf(stderr, "Test failed with signal %d\n", (int)WTERMSIG(status));
165 g_assert_not_reached();