Skip to content
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

Merged
merged 3 commits into from May 6, 2016
Merged

Conversation

yangdongsheng
Copy link
Contributor

When we run unittest_chain_xattr, if there is a default xattr enabled, such as security.selinux, this test would fail.

  attr security.selinux
  attr user.foo
  attr user.foo@1
[       OK ] chain_xattr.chunk_aligned (2 ms)
[ RUN      ] chain_xattr.listxattr
test/objectstore/chain_xattr.cc:251: Failure
Value of: ::memcmp(expected, actual, buffer_size)
  Actual: 117
Expected: 0
[  FAILED  ] chain_xattr.listxattr (1 ms)
[----------] 3 tests from chain_xattr (333 ms total)

[----------] Global test environment tear-down
[==========] 3 tests from 1 test case ran. (333 ms total)
[  PASSED  ] 2 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] chain_xattr.listxattr

 1 FAILED TEST
FAIL unittest_chain_xattr (exit status: 1)

This patch record the original xattr in the expected buffer, then unittest_chain_xattr works well now.

@yangdongsheng yangdongsheng changed the title Chain xattr Fix unittest for chain_xattr. Mar 24, 2016
@@ -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;
Copy link
Contributor

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.

Copy link
Contributor

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.

@yangdongsheng
Copy link
Contributor Author

@tchaikov Updated, please help to review again, thanx :)

@wjwithagen
Copy link
Contributor

@yangdongsheng @tchaikov
There is one major problem with the code in this test, when run on FreeBSD.
in " ASSERT_EQ(0, ::memcmp(expected, actual, buffer_size));" is assumed that the attributes are returned in the same order as they are inserted. At which point the memcmp works.
FreeBSD does not do this.
And in the manual pages both in Linux and in FreeBSD there is no guarantee that such a feature actually is guaranteed. eg. it could be that a different filesystem also has a different return strategy.
But that would require a masivve rewrite of this one line compare. Which I have not (yet) done.

@yangdongsheng
Copy link
Contributor Author

@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 .

@tchaikov tchaikov removed the needs-qa label Mar 25, 2016
chain_flistxattr(fd, orig_buffer, orig_size);
orig_str = string(orig_buffer);
orig_size = orig_str.size();
}
Copy link
Contributor

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());

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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. :)

Copy link
Contributor

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

@yangdongsheng yangdongsheng force-pushed the chain_xattr branch 3 times, most recently from ff4ebba to 7cff788 Compare March 30, 2016 02:18
@yangdongsheng
Copy link
Contributor Author

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>
Copy link
Contributor

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?

Copy link
Contributor Author

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. :)

@yangdongsheng
Copy link
Contributor Author

@tchaikov Could you help to take a look again? thanx :)

@tchaikov
Copy link
Contributor

tchaikov commented Apr 7, 2016

lgtm

@tchaikov tchaikov self-assigned this Apr 7, 2016
@wjwithagen
Copy link
Contributor

lgtm
On FreeBSD it now passed without excluding any tests.
Nice work.

@yangdongsheng
Copy link
Contributor Author

@tchaikov It sounds ready to go, mind merging it now? :)

@tchaikov
Copy link
Contributor

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).

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use ASSERT_TRUE()

@yangdongsheng yangdongsheng force-pushed the chain_xattr branch 2 times, most recently from 50fd466 to 401cae8 Compare April 25, 2016 04:56
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>
@yangdongsheng
Copy link
Contributor Author

@tchaikov thanx for the review. Branch is updated and rebased. please help to review again. :)

@wjwithagen
Copy link
Contributor

LGTM
Tested it last night on FreeBSD, and passed

@tchaikov
Copy link
Contributor

lgtm

wjwithagen added a commit to wjwithagen/ceph that referenced this pull request May 6, 2016
 - 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>
@liewegas liewegas merged commit 83ae5d6 into ceph:master May 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants