1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "gtest/gtest.h"
16 #include "include/cephfs/libcephfs.h"
20 TEST(LibCephFS, ReaddirRCB) {
21 struct ceph_mount_info *cmount;
22 ASSERT_EQ(0, ceph_create(&cmount, NULL));
23 ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
24 ASSERT_EQ(0, ceph_mount(cmount, "/"));
27 sprintf(c_dir, "/readdir_r_cb_tests_%d", getpid());
28 struct ceph_dir_result *dirp;
29 ASSERT_EQ(0, ceph_mkdirs(cmount, c_dir, 0777));
30 ASSERT_LE(0, ceph_opendir(cmount, c_dir, &dirp));
32 // dir is empty, check that it only contains . and ..
34 char *buf = new char[buflen];
35 // . is 2, .. is 3 (for null terminators)
36 ASSERT_EQ(5, ceph_getdnames(cmount, dirp, buf, buflen));
38 sprintf(c_file, "/readdir_r_cb_tests_%d/foo", getpid());
39 int fd = ceph_open(cmount, c_file, O_CREAT, 0777);
41 ASSERT_EQ(0, ceph_close(cmount, fd));
43 // check correctness with one entry
44 ASSERT_LE(0, ceph_closedir(cmount, dirp));
45 ASSERT_LE(0, ceph_opendir(cmount, c_dir, &dirp));
46 ASSERT_EQ(9, ceph_getdnames(cmount, dirp, buf, buflen)); // ., .., foo
48 // check correctness if buffer is too small
49 ASSERT_LE(0, ceph_closedir(cmount, dirp));
50 ASSERT_GE(0, ceph_opendir(cmount, c_dir, &dirp));
51 ASSERT_EQ(-ERANGE, ceph_getdnames(cmount, dirp, buf, 1));
53 //check correctness if it needs to split listing
54 ASSERT_LE(0, ceph_closedir(cmount, dirp));
55 ASSERT_LE(0, ceph_opendir(cmount, c_dir, &dirp));
56 ASSERT_EQ(5, ceph_getdnames(cmount, dirp, buf, 6));
57 ASSERT_EQ(4, ceph_getdnames(cmount, dirp, buf, 6));
59 // free cmount after finishing testing
60 ASSERT_LE(0, ceph_closedir(cmount, dirp));
61 ASSERT_EQ(0, ceph_unmount(cmount));
62 ASSERT_EQ(0, ceph_release(cmount));