New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix unittest for chain_xattr. #8290
Conversation
c9d3632
to
79d59ae
Compare
@@ -230,13 +230,32 @@ TEST(chain_xattr, listxattr) { | |||
const string x(LARGE_BLOCK_LEN, 'X'); | |||
const int y = 1234; | |||
|
|||
int orig_size = chain_listxattr(file, NULL, 0); | |||
char *orig_buffer = NULL; | |||
string orig_str; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to have an orig_str
. memcpy(3)
would suffice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm, i see you are using strcpy()
here and the target is malloc'ed.
79d59ae
to
f64f7fe
Compare
@tchaikov Updated, please help to review again, thanx :) |
@yangdongsheng @tchaikov |
@wjwithagen thanx, good point. My solution about it would be split the expected and actual into name list and then do a sorting. then compare them one by one. But I am really a newbie to C++ :(. I am not sure how to implement it currently, but I am glad to do an investigation. Thanx . |
chain_flistxattr(fd, orig_buffer, orig_size); | ||
orig_str = string(orig_buffer); | ||
orig_size = orig_str.size(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yangdongsheng you can use the boost for splitting the concatenated xattrs, like:
using strings = std::vector<std::string>;
std::string s;
int size = chain_listxattr(file, NULL, 0);
s.resize(size);
chain_flistxattr(fd, &s[0], s.size());
strings attrs;
boost::split(attrs, s, boost::is_from_range('\0', '\0'));
std::sort(attrs.begin(), attrs.end());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tchaikov
That's using the power of boost. Something I'm not fully into also.
It's like in Java: some many classes to choose from that it is hard to fully understand all of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed. it's difficult to fully understand all of them. but if something goes wrong, guess we can also try to dive into it to figure out the root cause.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tchaikov Thanx for your tip.
@wjwithagen 'boost' is widely used in ceph, I don't think that's a problem to take a use of boost here.
Anyway, I will update this branch next week, thanx guys. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Still working for me
ff4ebba
to
7cff788
Compare
Hi @wjwithagen and @tchaikov it's updated and rebased against master. Please help to take a look. |
@@ -18,6 +18,7 @@ | |||
* GNU Library Public License for more details. | |||
* | |||
*/ | |||
#include <boost/algorithm/string.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you choose to reinvent the split()
, maybe we can dispense with this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tchaikov yes, you are right, This is not necessary any more. :)
7cff788
to
50fd466
Compare
@tchaikov Could you help to take a look again? thanx :) |
lgtm |
lgtm |
@tchaikov It sounds ready to go, mind merging it now? :) |
as it has not passed the rados qa run, and it is not a bug fix targeting jewel. maybe we need to wait until the release of jewel (10.2.1). |
50fd466
to
6d13ef9
Compare
ASSERT_LT(buffer_size, chain_listxattr(file, NULL, 0)); // size evaluation is conservative | ||
chain_listxattr(file, actual, buffer_size); | ||
ASSERT_EQ(0, ::memcmp(expected, actual, buffer_size)); | ||
ASSERT_EQ(true, listxattr_cmp(expected, actual, buffer_size)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could use ASSERT_TRUE()
50fd466
to
401cae8
Compare
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
As there is no assert after chain_listxattr(), and memset actual to '\0' immediately, we did not test chain_listxattr() at all. This patch add an assert to do the unittest for chain_listxattr(). Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
As there would be some other default xattr for the file, such as security.selinux, we got unittest_chain_xattr failed. This patch save the original xattr and make it as a part of expected result. then the unittest works well now. Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
401cae8
to
5abc95d
Compare
@tchaikov thanx for the review. Branch is updated and rebased. please help to review again. :) |
LGTM |
lgtm |
- There is no guartee that the order of inserted attributes is equal to the order that these attributes are retreived again. So comparing needs to be done in a more carefull way. Code-by: yangdongsheng ceph#8290 Signed-off-by: Willem Jan Withagen <wjw@digiware.nl>
When we run unittest_chain_xattr, if there is a default xattr enabled, such as security.selinux, this test would fail.
This patch record the original xattr in the expected buffer, then unittest_chain_xattr works well now.