Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pmdk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Egorov, Sergey (PG/R - Comp Sci & Elec Eng)
pmdk
Commits
c6fb7003
Commit
c6fb7003
authored
4 years ago
by
Weronika Lewandowska
Browse files
Options
Downloads
Patches
Plain Diff
test: add tests for pmem2_source_get_handle/fd
parent
ab4911e4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/test/pmem2_source/TESTS.py
+24
-0
24 additions, 0 deletions
src/test/pmem2_source/TESTS.py
src/test/pmem2_source/pmem2_source.c
+99
-0
99 additions, 0 deletions
src/test/pmem2_source/pmem2_source.c
with
123 additions
and
0 deletions
src/test/pmem2_source/TESTS.py
+
24
−
0
View file @
c6fb7003
...
@@ -94,3 +94,27 @@ class TEST11(PMEM2_SOURCE):
...
@@ -94,3 +94,27 @@ class TEST11(PMEM2_SOURCE):
def
run
(
self
,
ctx
):
def
run
(
self
,
ctx
):
ctx
.
exec
(
'
pmem2_source
'
,
self
.
test_case
,
ctx
.
testdir
)
ctx
.
exec
(
'
pmem2_source
'
,
self
.
test_case
,
ctx
.
testdir
)
@t.windows_only
class
TEST12
(
PMEM2_SOURCE
):
"""
get handle from the source
"""
test_case
=
"
test_get_handle
"
@t.windows_exclude
class
TEST13
(
PMEM2_SOURCE
):
"""
get file descriptor from the source
"""
test_case
=
"
test_get_fd
"
@t.windows_only
class
TEST14
(
PMEM2_SOURCE_NO_DIR
):
"""
get handle from the invalid source type
"""
test_case
=
"
test_get_handle_inval_type
"
@t.windows_exclude
class
TEST15
(
PMEM2_SOURCE_NO_DIR
):
"""
get file descriptor from the invalid source type
"""
test_case
=
"
test_get_fd_inval_type
"
This diff is collapsed.
Click to expand it.
src/test/pmem2_source/pmem2_source.c
+
99
−
0
View file @
c6fb7003
...
@@ -293,6 +293,54 @@ test_set_mutex_handle(const struct test_case *tc, int argc, char *argv[])
...
@@ -293,6 +293,54 @@ test_set_mutex_handle(const struct test_case *tc, int argc, char *argv[])
return
0
;
return
0
;
}
}
/*
* test_get_handle - test getting handle value
*/
static
int
test_get_handle
(
const
struct
test_case
*
tc
,
int
argc
,
char
*
argv
[])
{
if
(
argc
<
1
)
UT_FATAL
(
"usage: test_get_handle <file>"
);
char
*
file
=
argv
[
0
];
HANDLE
h
=
CreateFile
(
file
,
GENERIC_READ
|
GENERIC_WRITE
,
0
,
NULL
,
OPEN_ALWAYS
,
0
,
NULL
);
UT_ASSERTne
(
h
,
INVALID_HANDLE_VALUE
);
struct
pmem2_source
*
src
;
int
ret
=
pmem2_source_from_handle
(
&
src
,
h
);
UT_PMEM2_EXPECT_RETURN
(
ret
,
0
);
HANDLE
handle_from_pmem2
;
ret
=
pmem2_source_get_handle
(
src
,
&
handle_from_pmem2
);
UT_ASSERTeq
(
handle_from_pmem2
,
h
);
UT_PMEM2_EXPECT_RETURN
(
ret
,
0
);
CloseHandle
(
h
);
pmem2_source_delete
(
&
src
);
return
1
;
}
/*
* test_get_handle_inval_type - test getting handle value from invalid type
*/
static
int
test_get_handle_inval_type
(
const
struct
test_case
*
tc
,
int
argc
,
char
*
argv
[])
{
struct
pmem2_source
*
src
;
int
ret
=
pmem2_source_from_anon
(
&
src
,
0
);
UT_PMEM2_EXPECT_RETURN
(
ret
,
0
);
HANDLE
handle_from_pmem2
;
ret
=
pmem2_source_get_handle
(
src
,
&
handle_from_pmem2
);
UT_PMEM2_EXPECT_RETURN
(
ret
,
PMEM2_E_FILE_HANDLE_NOT_SET
);
pmem2_source_delete
(
&
src
);
return
0
;
}
#else
#else
/*
/*
* test_set_directory_handle - test setting directory's fd
* test_set_directory_handle - test setting directory's fd
...
@@ -315,6 +363,53 @@ test_set_directory_fd(const struct test_case *tc, int argc, char *argv[])
...
@@ -315,6 +363,53 @@ test_set_directory_fd(const struct test_case *tc, int argc, char *argv[])
return
1
;
return
1
;
}
}
/*
* test_get_fd - test getting file descriptor value
*/
static
int
test_get_fd
(
const
struct
test_case
*
tc
,
int
argc
,
char
*
argv
[])
{
if
(
argc
<
1
)
UT_FATAL
(
"usage: test_get_fd <file>"
);
char
*
file
=
argv
[
0
];
int
fd
=
OPEN
(
file
,
O_RDONLY
);
UT_ASSERTne
(
fd
,
-
1
);
struct
pmem2_source
*
src
;
int
ret
=
pmem2_source_from_fd
(
&
src
,
fd
);
UT_PMEM2_EXPECT_RETURN
(
ret
,
0
);
int
fd_from_pmem2
;
ret
=
pmem2_source_get_fd
(
src
,
&
fd_from_pmem2
);
UT_ASSERTeq
(
fd_from_pmem2
,
fd
);
UT_PMEM2_EXPECT_RETURN
(
ret
,
0
);
CLOSE
(
fd
);
pmem2_source_delete
(
&
src
);
return
1
;
}
/*
* test_get_fd_inval_type - test getting fd value from invalid type
*/
static
int
test_get_fd_inval_type
(
const
struct
test_case
*
tc
,
int
argc
,
char
*
argv
[])
{
struct
pmem2_source
*
src
;
int
ret
=
pmem2_source_from_anon
(
&
src
,
0
);
UT_PMEM2_EXPECT_RETURN
(
ret
,
0
);
int
fd_from_pmem2
;
ret
=
pmem2_source_get_fd
(
src
,
&
fd_from_pmem2
);
UT_PMEM2_EXPECT_RETURN
(
ret
,
PMEM2_E_FILE_DESCRIPTOR_NOT_SET
);
pmem2_source_delete
(
&
src
);
return
0
;
}
#endif
#endif
/*
/*
...
@@ -333,8 +428,12 @@ static struct test_case test_cases[] = {
...
@@ -333,8 +428,12 @@ static struct test_case test_cases[] = {
TEST_CASE
(
test_set_invalid_handle
),
TEST_CASE
(
test_set_invalid_handle
),
TEST_CASE
(
test_set_directory_handle
),
TEST_CASE
(
test_set_directory_handle
),
TEST_CASE
(
test_set_mutex_handle
),
TEST_CASE
(
test_set_mutex_handle
),
TEST_CASE
(
test_get_handle
),
TEST_CASE
(
test_get_handle_inval_type
),
#else
#else
TEST_CASE
(
test_set_directory_fd
),
TEST_CASE
(
test_set_directory_fd
),
TEST_CASE
(
test_get_fd
),
TEST_CASE
(
test_get_fd_inval_type
),
#endif
#endif
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment