Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Commits
e5f29862
There was an error fetching the commit references. Please try again later.
Commit
e5f29862
authored
8 years ago
by
Jakub Klinkovský
Browse files
Options
Downloads
Patches
Plain Diff
Fixed FileTest
parent
2c25f398
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/UnitTests/CMakeLists.txt
+1
-2
1 addition, 2 deletions
src/UnitTests/CMakeLists.txt
src/UnitTests/FileTest.h
+27
-58
27 additions, 58 deletions
src/UnitTests/FileTest.h
with
28 additions
and
60 deletions
src/UnitTests/CMakeLists.txt
+
1
−
2
View file @
e5f29862
...
...
@@ -6,8 +6,7 @@ TARGET_LINK_LIBRARIES( UniquePointerTest${mpiExt}${debugExt} ${GTEST_BOTH_LIBRAR
tnl
${
mpiExt
}${
debugExt
}
-
${
tnlVersion
}
)
IF
(
BUILD_CUDA
)
CUDA_ADD_EXECUTABLE
(
FileTest
${
mpiExt
}${
debugExt
}
FileTest.h FileTest.cu
)
SET_TARGET_PROPERTIES
(
FileTest
${
mpiExt
}${
debugExt
}
PROPERTIES COMPILE_FLAGS
"
${
CXX_TESTS_FLAGS
}
"
)
CUDA_ADD_EXECUTABLE
(
FileTest
${
mpiExt
}${
debugExt
}
FileTest.h FileTest.cu OPTIONS
"
${
CXX_TESTS_FLAGS
}
"
)
TARGET_LINK_LIBRARIES
(
FileTest
${
mpiExt
}${
debugExt
}
${
GTEST_BOTH_LIBRARIES
}
tnl
${
mpiExt
}${
debugExt
}
-
${
tnlVersion
}
)
ELSE
(
BUILD_CUDA
)
...
...
This diff is collapsed.
Click to expand it.
src/UnitTests/FileTest.h
+
27
−
58
View file @
e5f29862
...
...
@@ -24,47 +24,23 @@ using namespace TNL;
TEST
(
FileTest
,
WriteAndRead
)
{
File
file
;
if
(
!
file
.
open
(
String
(
"test-file.tnl"
),
tnlWriteMode
)
)
{
std
::
cerr
<<
"Unable to create file test-file.tnl for the testing."
<<
std
::
endl
;
return
;
}
ASSERT_TRUE
(
file
.
open
(
String
(
"test-file.tnl"
),
tnlWriteMode
)
);
int
intData
(
5
);
#ifdef HAVE_NOT_CXX11
file
.
write
<
int
,
Devices
::
Host
>
(
&
intData
);
#else
file
.
write
(
&
intData
);
#endif
double
doubleData
[
3
]
=
{
1.0
,
2.0
,
3.0
};
#ifdef HAVE_NOT_CXX11
file
.
write
<
double
,
Devices
::
Host
>
(
doubleData
,
3
);
#else
file
.
write
(
doubleData
,
3
);
#endif
if
(
!
file
.
close
()
)
{
std
::
cerr
<<
"Unable to close the file test-file.tnl"
<<
std
::
endl
;
return
;
}
if
(
!
file
.
open
(
String
(
"test-file.tnl"
),
tnlReadMode
)
)
{
std
::
cerr
<<
"Unable to open the file test-file.tnl for the testing."
<<
std
::
endl
;
return
;
}
ASSERT_TRUE
(
file
.
write
(
&
intData
)
);
ASSERT_TRUE
(
file
.
write
(
doubleData
,
3
)
);
ASSERT_TRUE
(
file
.
close
()
);
ASSERT_TRUE
(
file
.
open
(
String
(
"test-file.tnl"
),
tnlReadMode
)
);
int
newIntData
;
double
newDoubleData
[
3
];
#ifdef HAVE_NOT_CXX11
file
.
read
<
int
,
Devices
::
Host
>
(
&
newIntData
);
file
.
read
<
double
,
Devices
::
Host
>
(
newDoubleData
,
3
);
#else
file
.
read
(
&
newIntData
,
1
);
file
.
read
(
newDoubleData
,
3
);
#endif
ASSERT_TRUE
(
file
.
read
(
&
newIntData
,
1
)
);
ASSERT_TRUE
(
file
.
read
(
newDoubleData
,
3
)
);
ASSER
T_EQ
(
newIntData
,
intData
);
EXPEC
T_EQ
(
newIntData
,
intData
);
for
(
int
i
=
0
;
i
<
3
;
i
++
)
ASSER
T_EQ
(
newDoubleData
[
i
],
doubleData
[
i
]
);
EXPEC
T_EQ
(
newDoubleData
[
i
],
doubleData
[
i
]
);
};
#ifdef HAVE_CUDA
...
...
@@ -85,34 +61,27 @@ TEST( FileTest, WriteAndReadCUDA )
floatData
,
3
*
sizeof
(
float
),
cudaMemcpyHostToDevice
);
File
file
;
if
(
!
file
.
open
(
String
(
"test-file.tnl"
),
tnlWriteMode
)
)
{
std
::
cerr
<<
"Unable to create file test-file.tnl for the testing."
<<
std
::
endl
;
return
;
}
file
.
write
<
int
,
Devices
::
Cuda
>
(
cudaIntData
);
file
.
write
<
float
,
Devices
::
Cuda
,
int
>
(
cudaFloatData
,
3
);
if
(
!
file
.
close
()
)
{
std
::
cerr
<<
"Unable to close the file test-file.tnl"
<<
std
::
endl
;
return
;
}
if
(
!
file
.
open
(
String
(
"test-file.tnl"
),
tnlReadMode
)
)
{
std
::
cerr
<<
"Unable to open the file test-file.tnl for the testing."
<<
std
::
endl
;
return
;
}
ASSERT_TRUE
(
file
.
open
(
String
(
"test-file.tnl"
),
tnlWriteMode
)
);
bool
status
=
file
.
write
<
int
,
Devices
::
Cuda
>
(
cudaIntData
);
ASSERT_TRUE
(
status
);
status
=
file
.
write
<
float
,
Devices
::
Cuda
,
int
>
(
cudaFloatData
,
3
);
ASSERT_TRUE
(
status
);
ASSERT_TRUE
(
file
.
close
()
);
ASSERT_TRUE
(
file
.
open
(
String
(
"test-file.tnl"
),
tnlReadMode
)
);
int
newIntData
;
float
newFloatData
[
3
];
int
*
newCudaIntData
;
float
*
newCudaFloatData
;
cudaMalloc
(
(
void
**
)
&
newCudaIntData
,
sizeof
(
int
)
);
cudaMalloc
(
(
void
**
)
&
newCudaFloatData
,
3
*
sizeof
(
float
)
);
file
.
read
<
int
,
Devices
::
Cuda
>
(
newCudaIntData
,
1
);
file
.
read
<
float
,
Devices
::
Cuda
,
int
>
(
newCudaFloatData
,
3
);
status
=
file
.
read
<
int
,
Devices
::
Cuda
>
(
newCudaIntData
,
1
);
ASSERT_TRUE
(
status
);
status
=
file
.
read
<
float
,
Devices
::
Cuda
,
int
>
(
newCudaFloatData
,
3
);
ASSERT_TRUE
(
status
);
cudaMemcpy
(
&
newIntData
,
newCudaIntData
,
sizeof
(
int
),
...
...
@@ -122,9 +91,9 @@ TEST( FileTest, WriteAndReadCUDA )
3
*
sizeof
(
float
),
cudaMemcpyDeviceToHost
);
ASSER
T_EQ
(
newIntData
,
intData
);
EXPEC
T_EQ
(
newIntData
,
intData
);
for
(
int
i
=
0
;
i
<
3
;
i
++
)
ASSER
T_EQ
(
newFloatData
[
i
],
floatData
[
i
]
);
EXPEC
T_EQ
(
newFloatData
[
i
],
floatData
[
i
]
);
};
#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