예제 #1
0
TYPED_TEST_P(TcTest, CompressDeepPaths)
{
	const char *PATHS[] = { "TcTest-CompressDeepPaths/a/b/c0/001.dat",
				"TcTest-CompressDeepPaths/a/b/c0/002.dat",
				"TcTest-CompressDeepPaths/a/b/c1/001.dat",
				"TcTest-CompressDeepPaths/a/b/c1/002.dat",
				"TcTest-CompressDeepPaths/a/b/c1/002.dat",
				"TcTest-CompressDeepPaths/a/b/c1/002.dat", };
	const int N = sizeof(PATHS)/sizeof(PATHS[0]);

	tc_ensure_dir("TcTest-CompressDeepPaths/a/b/c0", 0755, NULL);
	tc_ensure_dir("TcTest-CompressDeepPaths/a/b/c1", 0755, NULL);

	tc_unlinkv(PATHS, N);
	struct tc_iovec *iovs = (struct tc_iovec *)calloc(N, sizeof(*iovs));
	for (int i = 0; i < N; ++i) {
		if (i == 0 || strcmp(PATHS[i], PATHS[i-1])) {
			tc_iov4creation(&iovs[i], PATHS[i], 4_KB,
					new char[4_KB]);
		} else {
			tc_iov2path(&iovs[i], PATHS[i], 0, 4_KB,
				    new char[4_KB]);
		}
	}

	EXPECT_OK(tc_writev(iovs, N, false));
	for (int i = 0; i < N; ++i) {
		EXPECT_STREQ(iovs[i].file.path, PATHS[i]);
		delete[] iovs[i].data;
	}

	tc_attrs *attrs = new tc_attrs[N];
	for (int i = 0; i < N; ++i) {
		attrs[i].file = iovs[i].file;
		attrs[i].masks = TC_ATTRS_MASK_ALL;
	}
	EXPECT_OK(tc_getattrsv(attrs, N, false));

	free(iovs);
	delete[] attrs;
}
예제 #2
0
TYPED_TEST_P(TcTest, CopyFirstHalfAsSecondHalf)
{
	const int N = 8096;
	struct tc_extent_pair pairs[2];
	struct tc_iovec iov;
	struct tc_iovec read_iov;

	pairs[0].src_path = "OriginalFile.txt";
	pairs[0].src_offset = 0;
	pairs[0].dst_path = "ReversedFile.txt";
	pairs[0].dst_offset = N / 2;
	pairs[0].length = N / 2;

	pairs[1].src_path = "OriginalFile.txt";
	pairs[1].src_offset = N / 2;
	pairs[1].dst_path = "ReversedFile.txt";
	pairs[1].dst_offset = 0;
	pairs[1].length = UINT64_MAX;  // from src_offset to EOF, i.e., N/2

	// create source files
	tc_iov4creation(&iov, pairs[0].src_path, N, getRandomBytes(N));
	EXPECT_NOTNULL(iov.data);
	EXPECT_OK(tc_writev(&iov, 1, false));

	// remove dest files
	Removev(&pairs[0].dst_path, 1);

	// reverse a file using copy
	EXPECT_OK(tc_copyv(pairs, 2, false));

	tc_iov2path(&read_iov, pairs[1].dst_path, 0, N, (char *)malloc(N));
	EXPECT_NOTNULL(read_iov.data);

	EXPECT_OK(tc_readv(&read_iov, 1, false));

	EXPECT_EQ(0, memcmp(iov.data, read_iov.data + N / 2, N / 2));
	EXPECT_EQ(0, memcmp(iov.data + N / 2, read_iov.data, N / 2));

	free(iov.data);
	free(read_iov.data);
}
예제 #3
0
TYPED_TEST_P(TcTest, ListAnEmptyDirectory)
{
	const char *PATH = "TcTest-EmptyDir";
	tc_attrs *contents;
	int count;

	tc_ensure_dir(PATH, 0755, NULL);
	EXPECT_OK(
	    tc_listdir(PATH, TC_ATTRS_MASK_ALL, 1, false, &contents, &count));
	EXPECT_EQ(0, count);
	EXPECT_EQ(NULL, contents);
}
예제 #4
0
TYPED_TEST_P(TcTest, SymlinkBasics)
{
	const char *TARGETS[] = { "TcTest-SymlinkBasics/001.file",
				  "TcTest-SymlinkBasics/002.file",
				  "TcTest-SymlinkBasics/003.file",
				  "TcTest-SymlinkBasics/004.file",
				  "TcTest-SymlinkBasics/005.file", };
	const char *LINKS[] = { "TcTest-SymlinkBasics/001.link",
				"TcTest-SymlinkBasics/002.link",
				"TcTest-SymlinkBasics/003.link",
				"TcTest-SymlinkBasics/004.link",
				"TcTest-SymlinkBasics/005.link", };
	const char *CONTENTS[] = { "001.file", "002.file", "003.file",
				   "004.file", "005.file", };
	const int N = sizeof(TARGETS) / sizeof(TARGETS[0]);
	char **bufs = new char*[N];
	size_t *bufsizes = new size_t[N];

	EXPECT_OK(tc_ensure_dir("TcTest-SymlinkBasics", 0755, NULL));
	Removev(TARGETS, N);
	Removev(LINKS, N);

	for (int i = 0; i < N; ++i) {
		tc_touch(TARGETS[i], 4_KB);
		bufs[i] = new char[PATH_MAX];
		bufsizes[i] = PATH_MAX;
	}

	EXPECT_OK(tc_symlinkv(CONTENTS, LINKS, N, false));

	EXPECT_OK(tc_readlinkv(LINKS, bufs, bufsizes, N, false));

	for (int i = 0; i < N; ++i) {
		EXPECT_EQ(strlen(CONTENTS[i]), bufsizes[i]);
		EXPECT_EQ(0, strncmp(CONTENTS[i], bufs[i], bufsizes[i]));
		delete[] bufs[i];
	}
	delete[] bufs;
	delete[] bufsizes;
}
예제 #5
0
/*
 * Set attributes of many files.
 */
TYPED_TEST_P(TcTest, SetAttrsOfManyFiles)
{
	const int N = 32;
	const char *PATHS[N];

	for (int i = 0; i < N; ++i) {
		char *p = (char *)malloc(64);
		snprintf(p, 64, "SetAttrsOfFile-%03d", i);
		PATHS[i] = p;
	}
	struct tc_attrs *attrs1 = (tc_attrs *)calloc(N, sizeof(struct tc_attrs));
	struct tc_attrs *attrs2 = (tc_attrs *)calloc(N, sizeof(struct tc_attrs));
	EXPECT_NOTNULL(attrs1);
	EXPECT_NOTNULL(attrs2);

	tc_file *tcfs = tc_openv_simple(PATHS, N, O_RDWR | O_CREAT, 0);
	EXPECT_NOTNULL(tcfs);

	for (int i = 0; i < N; ++i) {
		attrs2[i].file = attrs1[i].file = tcfs[i];
	}

	set_tc_attrs(attrs1, N);
	EXPECT_OK(tc_setattrsv(attrs1, N, false));

	for (int i = 0; i < N; ++i) {
		attrs2[i].masks = attrs1[i].masks;
	}
	EXPECT_OK(tc_getattrsv(attrs2, N, false));

	EXPECT_TRUE(compare_attrs(attrs1, attrs2, N));

	tc_closev(tcfs, N);

	for (int i = 0; i < N; ++i) {
		free((void *)PATHS[i]);
	}
	free(attrs1);
	free(attrs2);
}
예제 #6
0
TYPED_TEST_P(TcTest, RecursiveCopyDirWithSymlinks)
{
#define TCT_RCD_DIR "RecursiveCopyDirWithSymlinks"
	tc_rm_recursive(TCT_RCD_DIR);
	tc_rm_recursive("RCDest");
	EXPECT_OK(tc_ensure_dir(TCT_RCD_DIR, 0755, NULL));
	const int NFILES = 8;
	const char * files[NFILES];
	for (int i = 0; i < NFILES; ++i) {
		files[i] =
		    new_auto_path(TCT_RCD_DIR "/file-%d", i);
	}
	tc_touchv(files, NFILES, false);
	EXPECT_EQ(0, tc_symlink("file-0", TCT_RCD_DIR "/link"));

	EXPECT_OK(
	    tc_cp_recursive(TCT_RCD_DIR, "RCDest", false, true));
	char buf[PATH_MAX];
	EXPECT_EQ(0, tc_readlink("RCDest/link", buf, PATH_MAX));
	EXPECT_STREQ("file-0", buf);
#undef TCT_RCD_DIR
}
예제 #7
0
/**
 * Test listing and removing a big directory.
 *
 * Wrap a big directory "RmMany/bb" with two small directories (i.e.,
 * "RmMany/aa" and "RmMany/cc") and make sure big directory are handled
 * correctly.
 */
TYPED_TEST_P(TcTest, TcRmManyFiles)
{
	EXPECT_OK(tc_ensure_dir("RmMany", 0755, NULL));
	EXPECT_OK(tc_ensure_dir("RmMany/aa", 0755, NULL));
	EXPECT_OK(tc_ensure_dir("RmMany/bb", 0755, NULL));
	tc_touch("RmMany/aa/foo", 1_KB);
	const int N_PER_CPD = 64;
	char *scratch = (char *)malloc(PATH_MAX * N_PER_CPD);
	for (int i = 0; i < 32; ++i) {
		const char *FILES[N_PER_CPD];
		for (int j = 0; j < N_PER_CPD; ++j) {
			char *p = scratch + j * PATH_MAX;
			snprintf(p, PATH_MAX, "RmMany/bb/file-%d-%d", i, j);
			FILES[j] = p;
		}
		tc_touchv(FILES, N_PER_CPD, 64);
	}
	free(scratch);
	EXPECT_OK(tc_ensure_dir("RmMany/cc", 0755, NULL));
	tc_touch("RmMany/cc/bar", 1_KB);
	EXPECT_TRUE(tc_rm_recursive("RmMany"));
}
예제 #8
0
TYPED_TEST_P(TcTest, ListLargeDir)
{
	EXPECT_OK(tc_ensure_dir("TcTest-ListLargeDir", 0755, 0));
	buf_t *name = new_auto_buf(PATH_MAX);
	const int N = 512;
	for (int i = 1; i <= N; ++i) {
		buf_printf(name, "TcTest-ListLargeDir/large-file%05d", i);
		tc_touch(asstr(name), i);
	}

	tc_attrs *contents;
	int count = 0;
	EXPECT_OK(tc_listdir("TcTest-ListLargeDir", TC_ATTRS_MASK_ALL, 0,
			     false, &contents, &count));
	EXPECT_EQ(N, count);
	qsort(contents, count, sizeof(*contents), tc_cmp_attrs_by_name);
	for (int i = 1; i <= N; ++i) {
		buf_printf(name, "TcTest-ListLargeDir/large-file%05d", i);
		EXPECT_STREQ(asstr(name), contents[i - 1].file.path);
	}
	tc_free_attrs(contents, count, true);
}
void
GMPRemoveTest::Setup()
{
  GeneratePlugin();
  EXPECT_OK(GetServiceParent()->RemovePluginDirectory(mOriginalPath));

  GetServiceParent()->AddPluginDirectory(mTmpPath);

  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
  obs->AddObserver(this, GMP_DELETED_TOPIC, false /* strong ref */);

  GetService()->GetThread(getter_AddRefs(mGMPThread));
}
예제 #10
0
/**
 * Append test case
 */
TYPED_TEST_P(TcTest, Append)
{
	const char *PATH = "TcTest-Append.txt";
	int i = 0;
	const int N = 4096;
	struct stat st;
	char *data;
	char *data_read;
	struct tc_iovec iov;

	Removev(&PATH, 1);

	data = (char *)getRandomBytes(3 * N);
	data_read = (char *)malloc(3 * N);
	EXPECT_NOTNULL(data);
	EXPECT_NOTNULL(data_read);

	tc_iov4creation(&iov, PATH, N, data);

	EXPECT_OK(tc_writev(&iov, 1, false));

	for (i = 0; i < 2; ++i) {
		iov.offset = TC_OFFSET_END;
		iov.data = data + N * (i + 1);
		iov.is_creation = false;
		EXPECT_OK(tc_writev(&iov, 1, false));
	}

	iov.offset = 0;
	iov.length = 3 * N;
	iov.data = data_read;
	EXPECT_OK(tc_readv(&iov, 1, false));
	EXPECT_TRUE(iov.is_eof);
	EXPECT_EQ(3 * N, iov.length);
	EXPECT_EQ(0, memcmp(data, data_read, 3 * N));

	free(data);
	free(data_read);
}
예제 #11
0
bool TestRevoke(Volume::Version version, bool fvm) {
    BEGIN_TEST;

    TestDevice device;
    ASSERT_TRUE(device.Bind(version, fvm));

    fbl::unique_ptr<Volume> volume;
    ASSERT_OK(Volume::Unlock(device.parent(), device.key(), 0, &volume));

    // Bad slot
    EXPECT_ZX(volume->Revoke(volume->num_slots()), ZX_ERR_INVALID_ARGS);

    // Valid, even if slot isn't enrolled
    EXPECT_OK(volume->Revoke(volume->num_slots() - 1));

    // Valid, even if last slot
    EXPECT_OK(volume->Revoke(0));
    EXPECT_ZX(Volume::Unlock(device.parent(), device.key(), 0, &volume),
              ZX_ERR_ACCESS_DENIED);

    END_TEST;
}
예제 #12
0
// Test high-level querying functions.
TEST_F(ClDeviceTest, highLevelQuery) {
    d->extensionsList(error); EXPECT_OK(error);
    d->image2DMaxDimensions(error); EXPECT_OK(error);
    d->image3DMaxDimensions(error); EXPECT_OK(error);
    d->getGlobalMemSizeMB(error); EXPECT_OK(error);
    d->supportsOutOfOrderExecMode(error); EXPECT_OK(error);
    d->supportsProfiling(error); EXPECT_OK(error);
}
예제 #13
0
TYPED_TEST_P(TcTest, SuccessiveWrites)
{
	const char *path = "SuccesiveWrites.dat";
	char *data = (char *)getRandomBytes(16_KB);
	/**
	 * open file one for actual writing
	 * other descriptor to verify
	 */
	tc_file *tcf = tc_open(path, O_RDWR | O_CREAT, 0755);
	EXPECT_NOTNULL(tcf);
	tc_file *tcf2 = tc_open(path, O_RDONLY, 0);
	EXPECT_NE(tcf->fd, tcf2->fd);

	struct tc_iovec iov;
	tc_iov2file(&iov, tcf, TC_OFFSET_CUR, 4_KB, data);
	EXPECT_OK(tc_writev(&iov, 1, false));
	tc_iov2file(&iov, tcf, TC_OFFSET_CUR, 4_KB, data + 4_KB);
	EXPECT_OK(tc_writev(&iov, 1, false));

	char *readbuf = (char *)malloc(16_KB);
	tc_iov2file(&iov, tcf2, 0, 8_KB, readbuf);
	EXPECT_OK(tc_readv(&iov, 1, false));
	EXPECT_EQ(iov.length, 8_KB);
	EXPECT_EQ(0, memcmp(data, readbuf, 8_KB));

	tc_iov2file(&iov, tcf, TC_OFFSET_CUR, 8_KB, data + 8_KB);
	EXPECT_OK(tc_writev(&iov, 1, false));

	tc_iov2file(&iov, tcf2, 0, 16_KB, readbuf);
	EXPECT_OK(tc_readv(&iov, 1, false));
	EXPECT_EQ(iov.length, 16_KB);
	EXPECT_EQ(0, memcmp(data, readbuf, 16_KB));

	tc_close(tcf);
	tc_close(tcf2);
	free(data);
	free(readbuf);
}
예제 #14
0
TYPED_TEST_P(TcTest, ManyLinksDontFitInOneCompound)
{
	const int NLINKS = 64;
	const char *targets[NLINKS];
	const char *links[NLINKS];
	char *bufs[NLINKS];
	size_t bufsizes[NLINKS];

	EXPECT_TRUE(tc_rm_recursive("ManyLinks"));
	for (int i = 0; i < NLINKS; ++i) {
		targets[i] = new_auto_path("ManyLinks/file%d", i);
		links[i] = new_auto_path("ManyLinks/a%d/b/c/d/e/f/h/link", i);
		tc_ensure_parent_dir(links[i]);
		bufs[i] = (char *)alloca(PATH_MAX);
		bufsizes[i] = PATH_MAX;
	}
	tc_touchv(targets, NLINKS, 1_KB);
	EXPECT_OK(tc_symlinkv(targets, links, NLINKS, false));
	EXPECT_OK(tc_readlinkv(links, bufs, bufsizes, NLINKS, false));
	for (int i = 0; i < NLINKS; ++i) {
		EXPECT_STREQ(targets[i], bufs[i]);
	}
}
예제 #15
0
/*
 * TC-Set/Get Attributes test
 * using File Descriptor
 */
TYPED_TEST_P(TcTest, AttrsTestFileDesc)
{
	const char *PATHS[] = { "WritevCanCreateFiles4.txt",
			       "WritevCanCreateFiles5.txt",
			       "WritevCanCreateFiles6.txt" };
	int i = 0;
	const int count = 3;
	tc_file *tcfs;
	struct tc_attrs *attrs1 = (tc_attrs *)calloc(count, sizeof(tc_attrs));
	struct tc_attrs *attrs2 = (tc_attrs *)calloc(count, sizeof(tc_attrs));

	EXPECT_NOTNULL(attrs1);
	EXPECT_NOTNULL(attrs2);

	Removev(PATHS, count);
	tcfs = tc_openv_simple(PATHS, count, O_RDWR | O_CREAT, 0);
	EXPECT_NOTNULL(tcfs);

	for (int i = 0; i < count; ++i) {
		attrs2[i].file = attrs1[i].file = tcfs[i];
	}

	set_tc_attrs(attrs1, count);
	EXPECT_OK(tc_setattrsv(attrs1, count, false));

	for (i = 0; i < count; ++i) {
		attrs2[i].masks = attrs1[i].masks;
	}
	EXPECT_OK(tc_getattrsv(attrs2, count, false));

	EXPECT_TRUE(compare_attrs(attrs1, attrs2, count));

	tc_closev(tcfs, count);

	free(attrs1);
	free(attrs2);
}
예제 #16
0
/**
 * TC-Set/Get Attributes test
 * with symlinks
 */
TYPED_TEST_P(TcTest, AttrsTestSymlinks)
{
	const char *PATHS[] = { "AttrsTestSymlinks-Linked1.txt",
				"AttrsTestSymlinks-Linked2.txt",
				"AttrsTestSymlinks-Linked3.txt" };
	const char *LPATHS[] = { "AttrsTestSymlinks-Link1.txt",
				 "AttrsTestSymlinks-Link2.txt",
				 "AttrsTestSymlinks-Link3.txt" };
	tc_res res = { 0 };
	struct tc_iovec iov;
	int i;
	const int count = 3;
	struct tc_attrs *attrs1 = (tc_attrs *)calloc(count, sizeof(tc_attrs));
	struct tc_attrs *attrs2 = (tc_attrs *)calloc(count, sizeof(tc_attrs));

	EXPECT_NOTNULL(attrs1);
	EXPECT_NOTNULL(attrs2);

	Removev(PATHS, count);
	Removev(LPATHS, count);

	EXPECT_OK(tc_symlinkv(PATHS, LPATHS, count, false));

	for (i = 0; i < count; ++i) {
		tc_iov4creation(&iov, PATHS[i], 100, getRandomBytes(100));
		EXPECT_NOTNULL(iov.data);
		EXPECT_OK(tc_writev(&iov, 1, false));

		attrs1[i].file = tc_file_from_path(LPATHS[i]);
		tc_attrs_set_mode(&attrs1[i], S_IRUSR);
		tc_attrs_set_atime(&attrs1[i], totimespec(time(NULL), 0));
		attrs2[i] = attrs1[i];
	}

	EXPECT_OK(tc_setattrsv(attrs1, count, false));
	EXPECT_OK(tc_getattrsv(attrs2, count, false));
	EXPECT_TRUE(compare_attrs(attrs1, attrs2, count));

	tc_attrs_set_mode(&attrs1[0], S_IRUSR | S_IRGRP);
	EXPECT_OK(tc_setattrsv(attrs1, count, false));
	EXPECT_OK(tc_lgetattrsv(attrs2, count, false));

	EXPECT_FALSE(S_IROTH & attrs1[0].mode);
	EXPECT_TRUE(S_IROTH & attrs2[0].mode);
	EXPECT_FALSE(compare_attrs(attrs1, attrs2, count));

	EXPECT_OK(tc_getattrsv(attrs2, count, false));
	EXPECT_TRUE(compare_attrs(attrs1, attrs2, count));

	free(attrs1);
	free(attrs2);
}
예제 #17
0
/* Get "cannot access" error when listing 2nd-level dir.  */
TYPED_TEST_P(TcTest, List2ndLevelDir)
{
	const char *DIR_PATH = "TcTest-Dir/nested-dir";
	const char *FILE_PATH = "TcTest-Dir/nested-dir/foo";
	tc_attrs *attrs;
	int count;

	tc_ensure_dir(DIR_PATH, 0755, NULL);
	tc_touch(FILE_PATH, 0);
	EXPECT_OK(
	    tc_listdir(DIR_PATH, TC_ATTRS_MASK_ALL, 1, false, &attrs, &count));
	EXPECT_EQ(1, count);
	EXPECT_EQ(0, attrs->size);
	tc_free_attrs(attrs, count, true);
}
예제 #18
0
TYPED_TEST_P(TcTest, MakeDirectories)
{
	mode_t mode[] = { S_IRWXU, S_IRUSR | S_IRGRP | S_IROTH,
			  S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH };
	const char *path[] = { "a", "b", "c" };
	struct tc_attrs dirs[3];

	Removev(path, 3);

	for (int i = 0; i < 3; ++i) {
		tc_set_up_creation(&dirs[i], path[i], 0755);
	}

	EXPECT_OK(tc_mkdirv(dirs, 3, false));
}
예제 #19
0
TYPED_TEST_P(TcTest, WriteManyDontFitInOneCompound)
{
	const int NFILES = 64; // 64 * 8 == 512
	struct tc_iovec iovs[NFILES];
	const char *ROOTDIR = "WriteMany";

	EXPECT_TRUE(tc_rm_recursive(ROOTDIR));
	for (int i = 0; i < NFILES; ++i) {
		char *p =
		    new_auto_path("WriteMany/a%03d/b/c/d/e/f/g/h/file", i);
		tc_ensure_parent_dir(p);
		tc_iov4creation(&iovs[i], p, strlen(p), p);
	}
	EXPECT_OK(tc_writev(iovs, NFILES, false));
}
예제 #20
0
// Checked unnecessary SAVEFH and RESTOREFH are not used thanks to
// optimization.
TYPED_TEST_P(TcTest, CompressPathForRemove)
{
	tc_ensure_dir("TcTest-CompressPathForRemove/a/b/c/d1", 0755, NULL);
	tc_ensure_dir("TcTest-CompressPathForRemove/a/b/c/d2", 0755, NULL);
	const int FILES_PER_DIR = 8;
	tc_file *files = (tc_file *)alloca(FILES_PER_DIR * 2 * sizeof(tc_file));
	for (int i = 0; i < FILES_PER_DIR; ++i) {
		char *p1 = new_auto_path(
		    "TcTest-CompressPathForRemove/a/b/c/d1/%d", i);
		char *p2 = new_auto_path(
		    "TcTest-CompressPathForRemove/a/b/c/d2/%d", i);
		const char *paths[2] = {p1, p2};
		tc_touchv(paths, 2, 4_KB);
		files[i] = tc_file_from_path(p1);
		files[i + FILES_PER_DIR] = tc_file_from_path(p2);
	}
	EXPECT_OK(tc_removev(files, FILES_PER_DIR * 2, false));
}
예제 #21
0
static void tc_touchv(const char **paths, int count, int filesize)
{
	tc_iovec *iovs;
	char *buf;

	iovs = (tc_iovec *)alloca(count * sizeof(*iovs));
	buf = filesize ? getRandomBytes(filesize) : NULL;

	for (int i = 0; i < count; ++i) {
		tc_iov4creation(&iovs[i], paths[i], filesize, buf);
	}

	EXPECT_OK(tc_writev(iovs, count, false));

	if (buf) {
		free(buf);
	}
}
예제 #22
0
TYPED_TEST_P(TcTest, SuccessiveReads)
{
	const char *path = "TcTest-SuccesiveReads.txt";
	struct tc_iovec iov;
	const int N = 4096;
	char *data;
	char *read;
	tc_file *tcf;

	Removev(&path, 1);

	data = (char *)getRandomBytes(5 * N);
	tc_iov4creation(&iov, path, 5 * N, data);

	EXPECT_OK(tc_writev(&iov, 1, false));

	read = (char *)malloc(5 * N);
	EXPECT_NOTNULL(read);

	tcf = tc_open(path, O_RDONLY, 0);
	EXPECT_EQ(0, tc_fseek(tcf, 0, SEEK_CUR));
	EXPECT_NOTNULL(tcf);
	tc_iov2file(&iov, tcf, TC_OFFSET_CUR, N, read);
	EXPECT_OK(tc_readv(&iov, 1, false));
	EXPECT_EQ(N, tc_fseek(tcf, 0, SEEK_CUR));

	iov.data = read + N;
	EXPECT_OK(tc_readv(&iov, 1, false));
	EXPECT_EQ(2 * N, tc_fseek(tcf, 0, SEEK_CUR));

	EXPECT_EQ(3 * N, tc_fseek(tcf, N, SEEK_CUR));
	iov.data = read + 3 * N;
	EXPECT_OK(tc_readv(&iov, 1, false));

	EXPECT_EQ(2 * N, tc_fseek(tcf, 2 * N, SEEK_SET));
	iov.data = read + 2 * N;
	EXPECT_OK(tc_readv(&iov, 1, false));

	EXPECT_EQ(4 * N, tc_fseek(tcf, -N, SEEK_END));
	iov.data = read + 4 * N;
	EXPECT_OK(tc_readv(&iov, 1, false));
	EXPECT_TRUE(iov.is_eof);

	EXPECT_EQ(0, memcmp(data, read, 5 * N));

	free(data);
	free(read);
	tc_close(tcf);
}
예제 #23
0
/**
 * Rename File Test
 */
TYPED_TEST_P(TcTest, RenameFile)
{
	int i = 0;
	const char *src_path[] = { "WritevCanCreateFiles1.txt",
				   "WritevCanCreateFiles2.txt",
				   "WritevCanCreateFiles3.txt",
				   "WritevCanCreateFiles4.txt" };

	const char *dest_path[] = { "rename1.txt", "rename2.txt",
				    "rename3.txt", "rename4.txt" };
	std::vector<tc_file_pair> files(4);
	for (i = 0; i < 4; ++i) {
		files[i].src_file = tc_file_from_path(src_path[i]);
		files[i].dst_file = tc_file_from_path(dest_path[i]);
	}

	EXPECT_OK(tc_renamev(files.data(), 4, false));

	/* TODO use listdir to check src files no longer exist */
}
예제 #24
0
bool TestShred(Volume::Version version, bool fvm) {
    BEGIN_TEST;

    TestDevice device;
    ASSERT_TRUE(device.Bind(version, fvm));

    fbl::unique_ptr<Volume> volume;
    ASSERT_OK(Volume::Unlock(device.parent(), device.key(), 0, &volume));

    // Valid
    EXPECT_OK(volume->Shred());

    // No further methods work
    EXPECT_ZX(volume->Enroll(device.key(), 0), ZX_ERR_BAD_STATE);
    EXPECT_ZX(volume->Revoke(0), ZX_ERR_BAD_STATE);
    EXPECT_ZX(Volume::Unlock(device.parent(), device.key(), 0, &volume),
              ZX_ERR_ACCESS_DENIED);

    END_TEST;
}
예제 #25
0
TYPED_TEST_P(TcTest, CopyManyFilesDontFitInOneCompound)
{
	const int NFILES = 64;
	struct tc_extent_pair pairs[NFILES];
	char path[PATH_MAX];

	for (int i = 0; i < NFILES; ++i) {
		snprintf(path, PATH_MAX, "CopyMany/a%d/b/c/d/e/f/g/h", i);
		tc_ensure_dir(path, 0755, NULL);

		snprintf(path, PATH_MAX, "CopyMany/a%d/b/c/d/e/f/g/h/foo", i);
		tc_touch(path, 4_KB);

		char *dest_file = (char *)alloca(PATH_MAX);
		snprintf(dest_file, PATH_MAX, "CopyMany/foo%d", i);
		tc_fill_extent_pair(&pairs[i], path, 0, dest_file, 0,
				    UINT64_MAX);
	}

	EXPECT_OK(tc_copyv(pairs, NFILES, false));
}
TEST_F(IGraphicBufferProducerTest, Query_Succeeds) {
    ASSERT_NO_FATAL_FAILURE(ConnectProducer());

    int32_t value = -1;
    EXPECT_OK(mProducer->query(NATIVE_WINDOW_WIDTH, &value));
    EXPECT_EQ(DEFAULT_WIDTH, static_cast<uint32_t>(value));

    EXPECT_OK(mProducer->query(NATIVE_WINDOW_HEIGHT, &value));
    EXPECT_EQ(DEFAULT_HEIGHT, static_cast<uint32_t>(value));

    EXPECT_OK(mProducer->query(NATIVE_WINDOW_FORMAT, &value));
    EXPECT_EQ(DEFAULT_FORMAT, value);

    EXPECT_OK(mProducer->query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &value));
    EXPECT_LE(0, value);
    EXPECT_GE(BufferQueue::NUM_BUFFER_SLOTS, value);

    EXPECT_OK(mProducer->query(NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND, &value));
    EXPECT_FALSE(value); // Can't run behind when we haven't touched the queue

    EXPECT_OK(mProducer->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, &value));
    EXPECT_EQ(DEFAULT_CONSUMER_USAGE_BITS, value);

}
 // Return length of property read; value is written into mValue
 int SetAndGetProperty(const char* value, const char* defaultValue = PROPERTY_TEST_VALUE_DEFAULT) {
     EXPECT_OK(property_set(PROPERTY_TEST_KEY, value)) << "value: '" << value << "'";
     return property_get(PROPERTY_TEST_KEY, mValue, defaultValue);
 }
TEST_F(PropertiesTest, SetString) {

    // Null key -> unsuccessful set
    {
        // Null key -> fails
        EXPECT_GT(0, property_set(/*key*/NULL, PROPERTY_TEST_VALUE_DEFAULT));
    }

    // Null value -> returns default value
    {
        // Null value -> OK , and it clears the value
        EXPECT_OK(property_set(PROPERTY_TEST_KEY, /*value*/NULL));
        ResetValue();

        // Since the value is null, default value will be returned
        size_t len = property_get(PROPERTY_TEST_KEY, mValue, PROPERTY_TEST_VALUE_DEFAULT);
        EXPECT_EQ(strlen(PROPERTY_TEST_VALUE_DEFAULT), len);
        EXPECT_STREQ(PROPERTY_TEST_VALUE_DEFAULT, mValue);
    }

    // Trivial case => get returns what was set
    {
        size_t len = SetAndGetProperty("hello_world");
        EXPECT_EQ(strlen("hello_world"), len) << "hello_world key";
        EXPECT_STREQ("hello_world", mValue);
        ResetValue();
    }

    // Set to empty string => get returns default always
    {
        const char* EMPTY_STRING_DEFAULT = "EMPTY_STRING";
        size_t len = SetAndGetProperty("", EMPTY_STRING_DEFAULT);
        EXPECT_EQ(strlen(EMPTY_STRING_DEFAULT), len) << "empty key";
        EXPECT_STREQ(EMPTY_STRING_DEFAULT, mValue);
        ResetValue();
    }

    // Set to max length => get returns what was set
    {
        std::string maxLengthString = std::string(PROPERTY_VALUE_MAX-1, 'a');

        int len = SetAndGetProperty(maxLengthString.c_str());
        EXPECT_EQ(PROPERTY_VALUE_MAX-1, len) << "max length key";
        EXPECT_STREQ(maxLengthString.c_str(), mValue);
        ResetValue();
    }

    // Set to max length + 1 => set fails
    {
        const char* VALID_TEST_VALUE = "VALID_VALUE";
        ASSERT_OK(property_set(PROPERTY_TEST_KEY, VALID_TEST_VALUE));

        std::string oneLongerString = std::string(PROPERTY_VALUE_MAX, 'a');

        // Expect that the value set fails since it's too long
        EXPECT_GT(0, property_set(PROPERTY_TEST_KEY, oneLongerString.c_str()));
        size_t len = property_get(PROPERTY_TEST_KEY, mValue, PROPERTY_TEST_VALUE_DEFAULT);

        EXPECT_EQ(strlen(VALID_TEST_VALUE), len) << "set should've failed";
        EXPECT_STREQ(VALID_TEST_VALUE, mValue);
        ResetValue();
    }
}
예제 #29
0
TYPED_TEST_P(TcTest, RequestDoesNotFitIntoOneCompound)
{
	const int NFILES = 64; // 64 * 8 == 512
	const char *paths[NFILES];
	int flags[NFILES];
	struct tc_attrs attrs[NFILES];
	const char *new_paths[NFILES];
	struct tc_file_pair pairs[NFILES];
	const char *ROOTDIR = "DontFit";

	EXPECT_TRUE(tc_rm_recursive(ROOTDIR));
	for (int i = 0; i < NFILES; ++i) {
		paths[i] = new_auto_path("DontFit/a%03d/b/c/d/e/f/g/h/file", i);
		tc_ensure_parent_dir(paths[i]);
		flags[i] = O_WRONLY | O_CREAT;
		attrs[i].file = tc_file_from_path(paths[i]);
		new_paths[i] = new_auto_path("DontFit/file-%d", i);
		pairs[i].src_file = tc_file_from_path(paths[i]);
		pairs[i].dst_file = tc_file_from_path(new_paths[i]);
	}
	tc_file *files = tc_openv(paths, NFILES, flags, NULL);
	EXPECT_NOTNULL(files);
	EXPECT_OK(tc_closev(files, NFILES));
	EXPECT_OK(tc_getattrsv(attrs, NFILES, false));

	struct tc_attrs_masks listdir_mask = { .has_mode = true };
	std::set<std::string> objs;
	EXPECT_OK(tc_listdirv(&ROOTDIR, 1, listdir_mask, 0, true,
			      listdir_test_cb, &objs, false));
	std::set<std::string> expected;
	for (int i = 0; i < NFILES; ++i) {
		std::string p(paths[i]);
		size_t n = p.length();
		while (n != std::string::npos) {
			expected.emplace(p.data(), n);
			n = p.find_last_of('/', n - 1);
		}
	}
	expected.erase("DontFit");
	EXPECT_THAT(objs, testing::ContainerEq(expected));

	EXPECT_OK(tc_renamev(pairs, NFILES, false));
	EXPECT_OK(tc_unlinkv(new_paths, NFILES));
}

static bool is_same_stat(const struct stat *st1, const struct stat *st2)
{
	return st1->st_ino == st2->st_ino
	    && st1->st_mode == st2->st_mode
	    && st1->st_nlink == st2->st_nlink
	    && st1->st_uid == st2->st_uid
	    && st1->st_gid == st2->st_gid
	    && st1->st_rdev == st2->st_rdev
	    && st1->st_size == st2->st_size
	    && st1->st_mtime == st2->st_mtime
	    && st1->st_ctime == st2->st_ctime;
	    //&& st1->st_dev == st2->st_dev
	    //&& st1->st_blksize == st2->st_blksize
	    //&& st1->st_blocks == st2->st_blocks
}

TYPED_TEST_P(TcTest, TcStatBasics)
{
	const char *FPATH = "TcTest-TcStatFile.txt";
	const char *LPATH = "TcTest-TcStatLink.txt";

	tc_unlink(FPATH);
	tc_unlink(LPATH);
	tc_touch(FPATH, 4_KB);
	EXPECT_EQ(0, tc_symlink(FPATH, LPATH));

	struct stat st1;
	EXPECT_EQ(0, tc_stat(LPATH, &st1));

	struct stat st2;
	tc_file *tcf = tc_open(FPATH, O_RDONLY, 0);
	EXPECT_EQ(0, tc_fstat(tcf, &st2));
	EXPECT_TRUE(is_same_stat(&st1, &st2));
	tc_close(tcf);

	struct stat st3;
	EXPECT_EQ(0, tc_lstat(LPATH, &st3));
	EXPECT_TRUE(S_ISLNK(st3.st_mode));
	EXPECT_FALSE(is_same_stat(&st1, &st3));
}

TYPED_TEST_P(TcTest, TcRmBasic)
{
#define TCRM_PREFIX "/vfs0/tc_nfs4_test/TcRmBasic"
	EXPECT_OK(tc_ensure_dir(TCRM_PREFIX "/dir-a/subdir-a1", 0755, NULL));
	EXPECT_OK(tc_ensure_dir(TCRM_PREFIX "/dir-a/subdir-a2", 0755, NULL));
	EXPECT_OK(tc_ensure_dir(TCRM_PREFIX "/dir-b/subdir-b1", 0755, NULL));

	tc_touch(TCRM_PREFIX "/dir-a/subdir-a1/a1-file1", 4_KB);
	tc_touch(TCRM_PREFIX "/dir-a/subdir-a1/a1-file2", 4_KB);
	tc_touch(TCRM_PREFIX "/dir-a/subdir-a1/a1-file3", 4_KB);
	tc_touch(TCRM_PREFIX "/dir-a/subdir-a2/a2-file1", 4_KB);
	tc_touch(TCRM_PREFIX "/dir-a/subdir-a2/a2-file2", 4_KB);
	tc_touch(TCRM_PREFIX "/dir-b/subdir-b1/b1-file1", 4_KB);
	tc_touch(TCRM_PREFIX "/dir-b/subdir-b1/b1-file2", 4_KB);
	tc_touch(TCRM_PREFIX "/dir-b/subdir-b1/b1-file3", 4_KB);
	tc_touch(TCRM_PREFIX "/file1", 4_KB);
	tc_touch(TCRM_PREFIX "/file2", 4_KB);

	const char *objs[4] = {
		TCRM_PREFIX "/dir-a",
		TCRM_PREFIX "/dir-b",
		TCRM_PREFIX "/file1",
		TCRM_PREFIX "/file2",
	};

	EXPECT_OK(tc_rm(objs, 4, true));
#undef TCRM_PREFIX
}
예제 #30
0
TYPED_TEST_P(TcTest, CopyLargeDirectory)
{
	int i;
	int count;
	struct tc_attrs *contents;
	struct tc_attrs_masks masks = TC_ATTRS_MASK_NONE;
	struct tc_extent_pair *dir_copy_pairs = NULL;
	const char **oldpaths = NULL;
	const char **newpaths = NULL;
	struct tc_attrs *copied_attrs;
	char *dst_path;
	int file_count = 0;
	//Cannot be larger than 9999 or will not fit in str
	#define FILE_COUNT 10
	#define FILE_LENGTH_BYTES (100)
	struct tc_iovec iov[FILE_COUNT];

	EXPECT_OK(tc_ensure_dir("TcTest-CopyLargeDirectory", 0755, NULL));
	EXPECT_OK(tc_ensure_dir("TcTest-CopyLargeDirectory-Dest", 0755, NULL));

	for (i = 0; i < FILE_COUNT; i++) {
		char *path = (char*) alloca(PATH_MAX);
		char *str = (char*) alloca(5);
		sprintf(str, "%d", i);
		tc_path_join("TcTest-CopyLargeDirectory", str, path, PATH_MAX);
		tc_iov4creation(&iov[i], path, FILE_LENGTH_BYTES,
				getRandomBytes(FILE_LENGTH_BYTES));
		EXPECT_NOTNULL(iov[i].data);
	}
	EXPECT_OK(tc_writev(iov, FILE_COUNT, false));

	masks.has_mode = true;

	EXPECT_OK(tc_listdir("TcTest-CopyLargeDirectory", masks, 0, true,
			     &contents, &count));

	dir_copy_pairs = (struct tc_extent_pair *)alloca(
	    sizeof(struct tc_extent_pair) * count);
	copied_attrs =
	    (struct tc_attrs *)alloca(sizeof(struct tc_attrs) * count);

	for (i = 0; i < count; i++) {
		dst_path = (char *) malloc(sizeof(char) * PATH_MAX);
		const char *dst_suffix = contents[i].file.path;

		while (*dst_suffix++ != '/')

			tc_path_join("TcTest-CopyLargeDirectory-Dest",
				     dst_suffix, dst_path, PATH_MAX);

		if (!S_ISDIR(contents[i].mode)) {
			dir_copy_pairs[file_count].src_path =
			    contents[i].file.path;
			dir_copy_pairs[file_count].dst_path = dst_path;
			dir_copy_pairs[file_count].src_offset = 0;
			dir_copy_pairs[file_count].dst_offset = 0;
			dir_copy_pairs[file_count].length = 0;

			file_count++;
		} else {
			EXPECT_OK(tc_ensure_dir (dst_path, 0755, NULL));
			free(dst_path);
		}

	}


	EXPECT_OK(tc_copyv(dir_copy_pairs, file_count, false));
	for (i = 0; i < file_count; i++) {
		free((char *) dir_copy_pairs[i].dst_path);
	}
}