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
24 /* global so the 'atexit' handler can access it */
27 cleanup_vtape_dir(char *device_path)
29 char *quoted = g_shell_quote(device_path);
30 char *cmd = vstralloc("rm -rf ", quoted, NULL);
32 /* would you rather write 'rm -rf' here? */
33 if (system(cmd) == -1) {
44 char *cwd = g_get_current_dir();
45 char *device_path = NULL;
46 char *data_dir = NULL;
48 device_path = vstralloc(cwd, "/vfs-test-XXXXXX", NULL);
51 if (mkdtemp(device_path) == NULL) {
52 fprintf(stderr, "Could not create temporary directory in %s\n", cwd);
56 /* append "/data/" to that for the VFS device*/
57 data_dir = vstralloc(device_path, "/data/", NULL);
58 if (mkdir(data_dir, 0777) == -1) {
59 fprintf(stderr, "Could not create %s: %s\n", cwd, strerror(errno));
69 setup_device(char *device_path)
72 char *device_name = NULL;
74 device_name = vstralloc("file:", device_path, NULL);
75 device = device_open(device_name);
77 fprintf(stderr, "Could not open device %s\n", device_name);
85 check_free_space(Device *device)
90 bzero(&value, sizeof(value));
91 if (!device_property_get(device, PROPERTY_FREE_SPACE, &value)) {
92 fprintf(stderr, "Could not get property_free_space\n");
96 qsize = *(QualifiedSize*)g_value_get_boxed(&value);
97 g_value_unset(&value);
99 if (qsize.accuracy != SIZE_ACCURACY_REAL) {
100 fprintf(stderr, "property_free_space accuracy is not SIZE_ACCURACY_REAL\n");
104 if (qsize.bytes == 0) {
105 fprintf(stderr, "property_free_space returned bytes=0\n");
113 main(int argc G_GNUC_UNUSED, char **argv G_GNUC_UNUSED)
115 Device *device = NULL;
117 char *device_path = NULL;
121 amanda_thread_init(NULL);
123 device_path = setup_vtape_dir();
125 /* run the tests in a subprocess so we can clean up even if they fail */
126 switch (pid = fork()) {
129 g_assert_not_reached();
134 device = setup_device(device_path);
138 ok = ok && check_free_space(device);
140 g_object_unref(device);
144 g_assert_not_reached();
146 default: /* parent */
147 if (waitpid(pid, &status, 0) == -1)
151 cleanup_vtape_dir(device_path);
154 /* figure our own return status */
155 if (WIFEXITED(status))
156 return WEXITSTATUS(status);
157 else if (WIFSIGNALED(status)) {
158 fprintf(stderr, "Test failed with signal %d\n", (int)WTERMSIG(status));
164 g_assert_not_reached();