/** * 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); }
/** * Set the TC test Attributes */ static tc_attrs *set_tc_attrs(struct tc_attrs *attrs, int count) { int i = 0; const int N = 3; uid_t uid[N] = { 2711, 456, 789 }; gid_t gid[N] = { 87, 4566, 2311 }; mode_t mode[N] = { S_IRUSR | S_IRGRP | S_IROTH, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH, S_IRWXU }; size_t size[N] = { 256, 56, 125 }; time_t atime[N] = { time(NULL), 1234, 567 }; for (i = 0; i < count; ++i) { int j = i % N; tc_attrs_set_mode(attrs + i, mode[j]); tc_attrs_set_size(attrs + i, size[j]); tc_attrs_set_uid(attrs + i, uid[j]); tc_attrs_set_gid(attrs + i, gid[j]); tc_attrs_set_atime(attrs + i, totimespec(atime[j], 0)); tc_attrs_set_atime(attrs + i, totimespec(time(NULL), 0)); } return attrs; }
/*** Sleep with nanosecond precision. @function nanosleep @tparam PosixTimespec requested sleep time @treturn[1] int `0` if requested time has elapsed @return[2] nil @treturn[2] string error message @treturn[2] int errnum @treturn[2] PosixTimespec unslept time remaining, if interrupted @see nanosleep(2) @see posix.unistd.sleep */ static int Pnanosleep(lua_State *L) { struct timespec req; struct timespec rem; int r; totimespec(L, 1, &req); checknargs(L, 1); r = pushresult (L, nanosleep(&req, &rem), "nanosleep"); if (r == 3 && errno == EINTR) r = r + pushtimespec (L, &rem); return r; }