Advertisement
ffilz

gtest.hh additions

May 23rd, 2018
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.51 KB | None | 0 0
  1.   class GaeshaFSALBaseTest : public gtest::GaneshaBaseTest {
  2.   protected:
  3.  
  4.     virtual void SetUp() {
  5.       fsal_status_t status;
  6.       struct attrlist attrs_out;
  7.  
  8.       gtest::GaneshaBaseTest::SetUp();
  9.  
  10.       a_export = get_gsh_export(export_id);
  11.       ASSERT_NE(a_export, nullptr);
  12.  
  13.       status = nfs_export_get_root_entry(a_export, &root_entry);
  14.       ASSERT_EQ(status.major, 0);
  15.       ASSERT_NE(root_entry, nullptr);
  16.  
  17.       /* Ganesha call paths need real or forged context info */
  18.       memset(&user_credentials, 0, sizeof(struct user_cred));
  19.       memset(&req_ctx, 0, sizeof(struct req_op_context));
  20.       memset(&attrs, 0, sizeof(attrs));
  21.       memset(&exp_perms, 0, sizeof(struct export_perms));
  22.  
  23.       req_ctx.ctx_export = a_export;
  24.       req_ctx.fsal_export = a_export->fsal_export;
  25.       req_ctx.creds = &user_credentials;
  26.       req_ctx.export_perms = &exp_perms;
  27.  
  28.       /* stashed in tls */
  29.       op_ctx = &req_ctx;
  30.  
  31.       // create root directory for test
  32.       FSAL_SET_MASK(attrs.valid_mask,
  33.                     ATTR_MODE | ATTR_OWNER | ATTR_GROUP);
  34.       attrs.mode = 0777; /* XXX */
  35.       attrs.owner = 667;
  36.       attrs.group = 766;
  37.       fsal_prepare_attrs(&attrs_out, 0);
  38.  
  39.       status = fsal_create(root_entry, TEST_ROOT, DIRECTORY, &attrs, NULL,
  40.                            &test_root, &attrs_out);
  41.       ASSERT_EQ(status.major, 0);
  42.       ASSERT_NE(test_root, nullptr);
  43.  
  44.       fsal_release_attrs(&attrs_out);
  45.     }
  46.  
  47.     virtual void TearDown() {
  48.       fsal_status_t status;
  49.  
  50.       status = test_root->obj_ops.unlink(root_entry, test_root, TEST_ROOT);
  51.       EXPECT_EQ(0, status.major);
  52.       test_root->obj_ops.put_ref(test_root);
  53.       test_root = NULL;
  54.  
  55.       root_entry->obj_ops.put_ref(root_entry);
  56.       root_entry = NULL;
  57.  
  58.       gtest::GaneshaBaseTest::TearDown();
  59.     }
  60.  
  61.     struct req_op_context req_ctx;
  62.     struct user_cred user_credentials;
  63.     struct attrlist attrs;
  64.     struct export_perms exp_perms;
  65.  
  66.     struct gsh_export* a_export = nullptr;
  67.     struct fsal_obj_handle *root_entry = nullptr;
  68.     struct fsal_obj_handle *test_root = nullptr;
  69.   }
  70.  
  71.   class GaeshaNFS4BaseTest : public gtest::GaneshaBaseTest {
  72.   protected:
  73.  
  74.     virtual void SetUp() {
  75.       bool fhres;
  76.  
  77.       gtest::GaeshaFSALBaseTest::SetUp();
  78.  
  79.       memset(&data, 0, sizeof(struct compound_data));
  80.       memset(&arg, 0, sizeof(nfs_arg_t));
  81.       memset(&resp, 0, sizeof(struct nfs_resop4));
  82.  
  83.       arg.arg_compound4.argarray.argarray_len = 1;
  84.       arg.arg_compound4.argarray.argarray_val = (struct nfs_argop4 *)
  85.           gsh_calloc(1, sizeof(struct nfs_argop4));
  86.  
  87.       op = &arg.arg_compound4.argarray.argarray_val[0];
  88.  
  89.       /* Setup some basic stuff (that will be overrode) so TearDown works. */
  90.       data.minorversion = 0;
  91.       op->argop = NFS4_OP_PUTROOTFH;
  92.  
  93.       /* Convert root_obj to a file handle in the args */
  94.       fhres = nfs4_FSALToFhandle(true, &data.currentFH, test_root,
  95.                                  op_ctx->ctx_export);
  96.       EXPECT_EQ(fhres, true);
  97.     }
  98.  
  99.     virtual void TearDown() {
  100.       bool rc;
  101.  
  102.       set_current_entry(&data, nullptr);
  103.  
  104.       nfs4_Compound_FreeOne(&resp);
  105.  
  106.       /* Free the compound data and response */
  107.       compound_data_Free(&data);
  108.  
  109.       /* Free the args structure. */
  110.       rc = xdr_free((xdrproc_t) xdr_COMPOUND4args, &arg);
  111.       EXPECT_EQ(rc, true);
  112.  
  113.       gtest::GaeshaFSALBaseTest::TearDown();
  114.     }
  115.  
  116.     struct compound_data data;
  117.     struct nfs_argop4 *op;
  118.     nfs_arg_t arg;
  119.     struct nfs_resop4 resp;
  120.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement