Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5c5d593e
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5c5d593e
编写于
1月 19, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test cases
上级
c20af74a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
136 addition
and
4 deletion
+136
-4
source/libs/tfs/src/tfs.c
source/libs/tfs/src/tfs.c
+3
-2
source/libs/tfs/test/tfsTest.cpp
source/libs/tfs/test/tfsTest.cpp
+133
-2
未找到文件。
source/libs/tfs/src/tfs.c
浏览文件 @
5c5d593e
...
...
@@ -291,6 +291,8 @@ int32_t tfsRename(STfs *pTfs, char *orname, char *nrname) {
snprintf
(
oaname
,
TMPNAME_LEN
,
"%s%s%s"
,
pDisk
->
path
,
TD_DIRSEP
,
orname
);
snprintf
(
naname
,
TMPNAME_LEN
,
"%s%s%s"
,
pDisk
->
path
,
TD_DIRSEP
,
nrname
);
if
(
taosRenameFile
(
oaname
,
naname
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
fError
(
"failed to rename %s to %s since %s"
,
oaname
,
naname
,
terrstr
());
return
-
1
;
}
}
...
...
@@ -402,8 +404,7 @@ static int32_t tfsCheckAndFormatCfg(STfs *pTfs, SDiskCfg *pCfg) {
}
if
(
tfsFormatDir
(
pCfg
->
dir
,
dirName
)
<
0
)
{
fError
(
"failed to mount %s to FS since invalid dir format"
,
pCfg
->
dir
);
terrno
=
TSDB_CODE_FS_INVLD_CFG
;
fError
(
"failed to mount %s to FS since %s"
,
pCfg
->
dir
,
terrstr
());
return
-
1
;
}
...
...
source/libs/tfs/test/tfsTest.cpp
浏览文件 @
5c5d593e
...
...
@@ -12,16 +12,147 @@
#include <gtest/gtest.h>
#include "os.h"
#include "tfs.h"
class
TfsTest
:
public
::
testing
::
Test
{
protected:
static
void
SetUpTestSuite
()
{}
static
void
SetUpTestSuite
()
{
root
=
"/tmp/tfsTest"
;
}
static
void
TearDownTestSuite
()
{}
public:
void
SetUp
()
override
{}
void
TearDown
()
override
{}
static
const
char
*
root
;
};
const
char
*
TfsTest
::
root
;
TEST_F
(
TfsTest
,
01
_Open_Close
)
{
SDiskCfg
dCfg
=
{
0
};
tstrncpy
(
dCfg
.
dir
,
root
,
TSDB_FILENAME_LEN
);
dCfg
.
level
=
0
;
dCfg
.
primary
=
1
;
taosRemoveDir
(
root
);
STfs
*
pTfs
=
tfsOpen
(
&
dCfg
,
1
);
ASSERT_EQ
(
pTfs
,
nullptr
);
taosMkDir
(
root
);
pTfs
=
tfsOpen
(
&
dCfg
,
1
);
ASSERT_NE
(
pTfs
,
nullptr
);
tfsUpdateSize
(
pTfs
);
SDiskSize
size
=
tfsGetSize
(
pTfs
);
EXPECT_GT
(
size
.
avail
,
0
);
EXPECT_GT
(
size
.
used
,
0
);
EXPECT_GT
(
size
.
total
,
size
.
avail
);
EXPECT_GT
(
size
.
total
,
size
.
used
);
tfsClose
(
pTfs
);
}
TEST_F
(
TfsTest
,
02
_AllocDisk
)
{
int32_t
code
=
0
;
SDiskCfg
dCfg
=
{
0
};
tstrncpy
(
dCfg
.
dir
,
root
,
TSDB_FILENAME_LEN
);
dCfg
.
level
=
0
;
dCfg
.
primary
=
1
;
taosMkDir
(
root
);
STfs
*
pTfs
=
tfsOpen
(
&
dCfg
,
1
);
ASSERT_NE
(
pTfs
,
nullptr
);
SDiskID
did
;
did
.
id
=
0
;
did
.
level
=
0
;
code
=
tfsAllocDisk
(
pTfs
,
0
,
&
did
);
EXPECT_EQ
(
code
,
0
);
EXPECT_EQ
(
did
.
id
,
0
);
EXPECT_EQ
(
did
.
level
,
0
);
did
.
id
=
1
;
did
.
level
=
1
;
code
=
tfsAllocDisk
(
pTfs
,
0
,
&
did
);
EXPECT_EQ
(
code
,
0
);
EXPECT_EQ
(
did
.
id
,
0
);
EXPECT_EQ
(
did
.
level
,
0
);
did
.
id
=
1
;
did
.
level
=
2
;
code
=
tfsAllocDisk
(
pTfs
,
0
,
&
did
);
EXPECT_EQ
(
code
,
0
);
EXPECT_EQ
(
did
.
id
,
0
);
EXPECT_EQ
(
did
.
level
,
0
);
did
.
id
=
1
;
did
.
level
=
3
;
code
=
tfsAllocDisk
(
pTfs
,
0
,
&
did
);
EXPECT_EQ
(
code
,
0
);
EXPECT_EQ
(
did
.
id
,
0
);
EXPECT_EQ
(
did
.
level
,
0
);
const
char
*
primary
=
tfsGetPrimaryPath
(
pTfs
);
EXPECT_STREQ
(
primary
,
root
);
const
char
*
path
=
tfsGetDiskPath
(
pTfs
,
did
);
EXPECT_STREQ
(
path
,
root
);
tfsClose
(
pTfs
);
}
TEST_F
(
TfsTest
,
03
_Dir
)
{
int32_t
code
=
0
;
SDiskCfg
dCfg
=
{
0
};
tstrncpy
(
dCfg
.
dir
,
root
,
TSDB_FILENAME_LEN
);
dCfg
.
level
=
0
;
dCfg
.
primary
=
1
;
taosMkDir
(
root
);
STfs
*
pTfs
=
tfsOpen
(
&
dCfg
,
1
);
ASSERT_NE
(
pTfs
,
nullptr
);
char
p1
[]
=
"p1"
;
char
ap1
[
128
]
=
{
0
};
snprintf
(
ap1
,
128
,
"%s%s%s"
,
root
,
TD_DIRSEP
,
p1
);
EXPECT_NE
(
taosDirExist
(
ap1
),
0
);
EXPECT_EQ
(
tfsMkdir
(
pTfs
,
p1
),
0
);
EXPECT_EQ
(
taosDirExist
(
ap1
),
0
);
char
p2
[]
=
"p2"
;
char
ap2
[
128
]
=
{
0
};
snprintf
(
ap2
,
128
,
"%s%s%s"
,
root
,
TD_DIRSEP
,
p2
);
SDiskID
did
=
{
0
};
EXPECT_NE
(
taosDirExist
(
ap2
),
0
);
EXPECT_EQ
(
tfsMkdirAt
(
pTfs
,
p2
,
did
),
0
);
EXPECT_EQ
(
taosDirExist
(
ap2
),
0
);
char
p3
[]
=
"p3/p2/p1/p0"
;
char
ap3
[
128
]
=
{
0
};
snprintf
(
ap3
,
128
,
"%s%s%s"
,
root
,
TD_DIRSEP
,
p3
);
EXPECT_NE
(
taosDirExist
(
ap3
),
0
);
EXPECT_NE
(
tfsMkdir
(
pTfs
,
p3
),
0
);
EXPECT_NE
(
tfsMkdirAt
(
pTfs
,
p3
,
did
),
0
);
EXPECT_EQ
(
tfsMkdirRecurAt
(
pTfs
,
p3
,
did
),
0
);
EXPECT_EQ
(
taosDirExist
(
ap3
),
0
);
EXPECT_EQ
(
tfsRmdir
(
pTfs
,
p3
),
0
);
EXPECT_NE
(
taosDirExist
(
ap3
),
0
);
char
p45
[]
=
"p5"
;
char
p44
[]
=
"p4"
;
char
p4
[]
=
"p4/p2/p1/p0"
;
char
ap4
[
128
]
=
{
0
};
snprintf
(
ap4
,
128
,
"%s%s%s"
,
root
,
TD_DIRSEP
,
p4
);
EXPECT_NE
(
taosDirExist
(
ap4
),
0
);
EXPECT_EQ
(
tfsMkdirRecurAt
(
pTfs
,
p4
,
did
),
0
);
EXPECT_EQ
(
taosDirExist
(
ap4
),
0
);
EXPECT_EQ
(
tfsRename
(
pTfs
,
p44
,
p45
),
0
);
EXPECT_EQ
(
tfsRmdir
(
pTfs
,
p4
),
0
);
EXPECT_NE
(
taosDirExist
(
ap4
),
0
);
tfsClose
(
pTfs
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录