Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Show more breadcrumbs
dCache
cta
Commits
da0768ec
Commit
da0768ec
authored
5 years ago
by
Steven Murray
Browse files
Options
Downloads
Patches
Plain Diff
Improved cta-immutable-file-test
parent
753727ec
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/ImmutableFileTest.cpp
+74
-37
74 additions, 37 deletions
tests/ImmutableFileTest.cpp
tests/ImmutableFileTest.hpp
+3
-1
3 additions, 1 deletion
tests/ImmutableFileTest.hpp
with
77 additions
and
38 deletions
tests/ImmutableFileTest.cpp
+
74
−
37
View file @
da0768ec
...
...
@@ -65,10 +65,10 @@ int ImmutableFileTest::main(const int argc, char *const *const argv) {
// Reaching this point means the command has failed, an exception was throw
// and errorMessage has been set accordingly
m_
err
<<
errorMessage
<<
std
::
endl
;
m_
out
<<
errorMessage
<<
std
::
endl
;
if
(
cmdLineNotParsed
)
{
m_
err
<<
std
::
endl
;
ImmutableFileTestCmdLineArgs
::
printUsage
(
m_
err
);
m_
out
<<
std
::
endl
;
ImmutableFileTestCmdLineArgs
::
printUsage
(
m_
out
);
}
return
1
;
}
...
...
@@ -84,8 +84,11 @@ int ImmutableFileTest::exceptionThrowingMain(const int argc, char *const *const
return
0
;
}
if
(
userConfirmsDestroyFile
(
cmdLine
.
fileUrl
.
GetURL
()))
{
m_out
<<
"Starting destructive test on file "
<<
cmdLine
.
fileUrl
.
GetURL
()
<<
std
::
endl
;
const
bool
runTests
=
userConfirmsDestroyFile
(
cmdLine
.
fileUrl
.
GetURL
());
m_out
<<
std
::
endl
;
if
(
runTests
)
{
m_out
<<
"Starting destructive test on "
<<
cmdLine
.
fileUrl
.
GetURL
()
<<
std
::
endl
;
}
else
{
m_out
<<
"Aborting"
<<
std
::
endl
;
return
0
;
...
...
@@ -96,32 +99,56 @@ int ImmutableFileTest::exceptionThrowingMain(const int argc, char *const *const
ex
.
getMessage
()
<<
cmdLine
.
fileUrl
.
GetURL
()
<<
" is local"
;
throw
ex
;
}
m_out
<<
std
::
endl
;
if
(
fileExists
(
cmdLine
.
fileUrl
))
{
m_out
<<
cmdLine
.
fileUrl
.
GetURL
()
<<
" already exists"
<<
std
::
endl
;
m_out
<<
"About to delete "
<<
cmdLine
.
fileUrl
.
GetURL
()
<<
std
::
endl
;
deleteFile
(
cmdLine
.
fileUrl
);
m_out
<<
"Deleted "
<<
cmdLine
.
fileUrl
.
GetURL
()
<<
std
::
endl
;
}
else
{
m_out
<<
cmdLine
.
fileUrl
.
GetURL
()
<<
" does not exist yet"
<<
std
::
endl
;
}
m_out
<<
"Ready to create "
<<
cmdLine
.
fileUrl
.
GetURL
()
<<
std
::
endl
;
m_out
<<
std
::
endl
;
bool
oneOrMoreTestsFailed
=
true
;
// Guilty until proven innocent
try
{
testOpenCloseFile
(
cmdLine
.
fileUrl
,
XrdCl
::
OpenFlags
::
New
,
0
);
testOpenCloseFile
(
cmdLine
.
fileUrl
,
XrdCl
::
OpenFlags
::
Delete
|
XrdCl
::
OpenFlags
::
Write
,
0
);
testOpenCloseFile
(
cmdLine
.
fileUrl
,
XrdCl
::
OpenFlags
::
Write
,
kXR_NotAuthorized
);
testOpenCloseFile
(
cmdLine
.
fileUrl
,
XrdCl
::
OpenFlags
::
Update
,
kXR_NotAuthorized
);
testOpenCloseFile
(
cmdLine
.
fileUrl
,
XrdCl
::
OpenFlags
::
Append
,
kXR_NotAuthorized
);
// Create the file
testFile
(
cmdLine
.
fileUrl
,
XrdCl
::
OpenFlags
::
New
,
"CONTENTS1"
,
0
);
// Re-create the file
testFile
(
cmdLine
.
fileUrl
,
XrdCl
::
OpenFlags
::
Delete
|
XrdCl
::
OpenFlags
::
Write
,
"CONTENTS2"
,
0
);
// Try to open the file for modification
testFile
(
cmdLine
.
fileUrl
,
XrdCl
::
OpenFlags
::
Write
,
""
,
kXR_NotAuthorized
);
testFile
(
cmdLine
.
fileUrl
,
XrdCl
::
OpenFlags
::
Update
,
""
,
kXR_NotAuthorized
);
testFile
(
cmdLine
.
fileUrl
,
XrdCl
::
OpenFlags
::
Append
,
""
,
kXR_NotAuthorized
);
oneOrMoreTestsFailed
=
false
;
}
catch
(
exception
::
Exception
&
ex
)
{
m_out
<<
ex
.
getMessage
().
str
()
<<
std
::
endl
;
}
catch
(
std
::
exception
&
se
)
{
m_out
<<
se
.
what
()
<<
std
::
endl
;
}
catch
(...)
{
m_out
<<
"Caught an unknown exception"
<<
std
::
endl
;
}
m_out
<<
std
::
endl
;
if
(
fileExists
(
cmdLine
.
fileUrl
))
{
m_out
<<
"Test file still exists after the tests"
<<
std
::
endl
;
try
{
deleteFile
(
cmdLine
.
fileUrl
);
m_out
<<
"Successfully deleted test file"
<<
std
::
endl
;
}
catch
(
exception
::
Exception
&
ex
)
{
m_out
<<
"Failed to delete test file: "
<<
ex
.
getMessage
().
str
()
<<
std
::
endl
;
}
catch
(
std
::
exception
&
se
)
{
m_out
<<
"Failed to delete test file: "
<<
se
.
what
()
<<
std
::
endl
;
}
catch
(...)
{
// Do nothing
m_out
<<
"Failed to delete test file: Caught an unknown exception"
<<
std
::
endl
;
}
throw
;
}
else
{
m_out
<<
cmdLine
.
fileUrl
.
GetURL
()
<<
" does not exist after the tests"
<<
std
::
endl
;
}
return
0
;
return
oneOrMoreTestsFailed
?
1
:
0
;
}
//------------------------------------------------------------------------------
...
...
@@ -129,7 +156,7 @@ int ImmutableFileTest::exceptionThrowingMain(const int argc, char *const *const
//------------------------------------------------------------------------------
bool
ImmutableFileTest
::
userConfirmsDestroyFile
(
const
std
::
string
&
fileUrl
)
const
{
m_out
<<
"WARNING"
<<
std
::
endl
;
m_out
<<
"You are about to destroy
file
"
<<
fileUrl
<<
std
::
endl
;
m_out
<<
"You are about to destroy
the file with URL
"
<<
fileUrl
<<
std
::
endl
;
m_out
<<
"Are you sure you want to continue?"
<<
std
::
endl
;
std
::
string
userResponse
;
...
...
@@ -148,7 +175,6 @@ bool ImmutableFileTest::fileExists(const XrdCl::URL &url) {
XrdCl
::
FileSystem
fs
(
url
);
XrdCl
::
StatInfo
*
info
=
0
;
const
XrdCl
::
XRootDStatus
statStatus
=
fs
.
Stat
(
url
.
GetPath
(),
info
);
if
(
!
statStatus
.
IsOK
())
m_out
<<
statStatus
.
ToStr
()
<<
std
::
endl
;
return
statStatus
.
IsOK
();
}
...
...
@@ -167,59 +193,70 @@ void ImmutableFileTest::deleteFile(const XrdCl::URL &url) {
}
//------------------------------------------------------------------------------
// test
OpenClose
File
// testFile
//------------------------------------------------------------------------------
void
ImmutableFileTest
::
testOpenCloseFile
(
const
XrdCl
::
URL
&
url
,
const
XrdCl
::
OpenFlags
::
Flags
openFlags
,
const
uint32_t
expectedOpenErrNo
)
{
bool
testPassed
=
false
;
std
::
ostringstream
msg
;
void
ImmutableFileTest
::
testFile
(
const
XrdCl
::
URL
&
url
,
const
XrdCl
::
OpenFlags
::
Flags
openFlags
,
const
std
::
string
&
contents
,
const
uint32_t
expectedOpenErrNo
)
{
bool
testPassed
=
true
;
// Innocent until proven guilty
const
bool
expectedSuccess
=
0
==
expectedOpenErrNo
;
XrdCl
::
File
file
;
m_out
<<
"START OF TEST: Opening "
<<
url
.
GetURL
()
<<
" with flags
\"
"
<<
openFlagsToString
(
openFlags
)
<<
"
\"
"
<<
m_out
<<
std
::
endl
;
m_out
<<
"START OF TEST"
<<
std
::
endl
;
m_out
<<
"Opening file with flags
\"
"
<<
openFlagsToString
(
openFlags
)
<<
"
\"
"
<<
" expecting "
<<
xErrorCodeToString
(
expectedOpenErrNo
)
<<
std
::
endl
;
const
XrdCl
::
Access
::
Mode
openMode
=
XrdCl
::
Access
::
UR
|
XrdCl
::
Access
::
UW
;
const
XrdCl
::
XRootDStatus
openStatus
=
file
.
Open
(
url
.
GetURL
(),
openFlags
,
openMode
);
{
if
(
expectedSuccess
)
{
if
(
openStatus
.
IsOK
())
{
testPassed
=
true
;
msg
<<
"Succeeded to open file as expected"
;
if
(
openStatus
.
IsOK
())
{
m_out
<<
"Succeeded to open file as expected"
<<
std
::
endl
;
}
else
{
testPassed
=
false
;
m
sg
<<
"Failure when success was expected: Failed to open file: "
<<
openStatus
.
ToStr
();
m
_out
<<
"Failure when success was expected: Failed to open file: "
<<
openStatus
.
ToStr
()
<<
std
::
endl
;
}
}
else
{
if
(
openStatus
.
IsOK
())
{
testPassed
=
false
;
m
sg
<<
"Success when failure was expected: Successfully opened file"
;
m
_out
<<
"Success when failure was expected: Successfully opened file"
<<
std
::
endl
;
}
else
{
if
(
expectedOpenErrNo
==
openStatus
.
errNo
)
{
testPassed
=
true
;
msg
<<
"Successfully got "
<<
xErrorCodeToString
(
expectedOpenErrNo
);
m_out
<<
"Successfully got "
<<
xErrorCodeToString
(
expectedOpenErrNo
)
<<
std
::
endl
;
}
else
{
testPassed
=
false
;
m
sg
<<
"Unexpectedly got "
<<
xErrorCodeToString
(
openStatus
.
errNo
);
m
_out
<<
"Unexpectedly got "
<<
xErrorCodeToString
(
openStatus
.
errNo
)
<<
std
::
endl
;
}
}
}
}
if
(
openStatus
.
IsOK
()){
if
(
testPassed
&&
!
contents
.
empty
())
{
const
uint64_t
offset
=
0
;
const
uint16_t
timeout
=
0
;
const
XrdCl
::
XRootDStatus
writeStatus
=
file
.
Write
(
offset
,
contents
.
size
(),
contents
.
c_str
(),
timeout
);
if
(
writeStatus
.
IsOK
())
{
m_out
<<
"Successfully wrote
\"
"
<<
contents
<<
"
\"
to the beginning of the file"
<<
std
::
endl
;
}
else
{
testPassed
=
false
;
m_out
<<
"Failed to write to file: "
<<
writeStatus
.
ToStr
()
<<
std
::
endl
;
}
}
if
(
openStatus
.
IsOK
())
{
const
XrdCl
::
XRootDStatus
closeStatus
=
file
.
Close
();
if
(
!
closeStatus
.
IsOK
())
{
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"Failed to close
\"
"
<<
url
.
GetURL
()
<<
"
\"
:"
<<
closeStatus
.
ToStr
();
throw
ex
;
testPassed
=
false
;
m_out
<<
"Failed to close file:"
<<
closeStatus
.
ToStr
()
<<
std
::
endl
;
}
}
if
(
testPassed
)
{
m_out
<<
"
END OF
TEST
:
PASSED
: "
<<
msg
.
str
()
<<
std
::
endl
;
m_out
<<
"TEST PASSED
"
<<
std
::
endl
;
}
else
{
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"
END OF
TEST
:
FAILED
: "
<<
msg
.
str
()
;
ex
.
getMessage
()
<<
"TEST FAILED
"
;
throw
ex
;
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/ImmutableFileTest.hpp
+
3
−
1
View file @
da0768ec
...
...
@@ -103,9 +103,11 @@ private:
*
* @param url The XRootD URL of the file to be tested.
* @param openFlags The XRootD flags to be used when opening the file.
* @param contents Optional contents to be written to the file. An empty
* string means don't write anything.
* @param expectecErrNo The expected errNo result of opening the file.
*/
void
test
OpenClose
File
(
const
XrdCl
::
URL
&
url
,
const
XrdCl
::
OpenFlags
::
Flags
openFlags
,
void
testFile
(
const
XrdCl
::
URL
&
url
,
const
XrdCl
::
OpenFlags
::
Flags
openFlags
,
const
std
::
string
&
contents
,
const
uint32_t
expectedOpenErrNo
);
/**
...
...
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