Skip to content
Snippets Groups Projects
Commit b94793ee authored by Pekka Enberg's avatar Pekka Enberg
Browse files

tst-fs-link.so: Make paths configurable


Make the link source and target paths configurable so the test can be
run on Linux:

  $ g++ -std=c++11 tst-fs-link.cc && ./a.out foo foo2

Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent 81aacf3c
No related branches found
No related tags found
No related merge requests found
...@@ -25,12 +25,21 @@ static void report(bool ok, const char* msg) ...@@ -25,12 +25,21 @@ static void report(bool ok, const char* msg)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const char *oldpath, *newpath;
struct stat st[2]; struct stat st[2];
char buf[4] = { 0 }; char buf[4] = { 0 };
char buf2[4] = { 0 }; char buf2[4] = { 0 };
if (argc > 2) {
oldpath = argv[1];
newpath = argv[2];
} else {
oldpath = "/usr/foo";
newpath = "/usr/foo2";
}
// Create a temporary file that's used in testing. // Create a temporary file that's used in testing.
auto fd = open("/usr/foo", O_CREAT|O_TRUNC|O_RDWR, 0666); auto fd = open(oldpath, O_CREAT|O_TRUNC|O_RDWR, 0666);
write(fd, "test", 4); write(fd, "test", 4);
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
read(fd, buf, 4); read(fd, buf, 4);
...@@ -38,9 +47,9 @@ int main(int argc, char *argv[]) ...@@ -38,9 +47,9 @@ int main(int argc, char *argv[])
report(close(fd) == 0, "close the file"); report(close(fd) == 0, "close the file");
// Create a hard link // Create a hard link
report(link("/usr/foo", "/usr/foo2") == 0, "create a hard link"); report(link(oldpath, newpath) == 0, "create a hard link");
auto fd2 = open("/usr/foo2", O_RDONLY); auto fd2 = open(newpath, O_RDONLY);
lseek(fd2, 0, SEEK_SET); lseek(fd2, 0, SEEK_SET);
read(fd2, buf2, 4); read(fd2, buf2, 4);
close(fd2); close(fd2);
...@@ -49,19 +58,19 @@ int main(int argc, char *argv[]) ...@@ -49,19 +58,19 @@ int main(int argc, char *argv[])
// of the same inode. // of the same inode.
report(strncmp(buf, buf2, 4) == 0, "read content from another link"); report(strncmp(buf, buf2, 4) == 0, "read content from another link");
// Check that hard link count is increased // Check that hard link count is increased
report(stat("/usr/foo", &st[0]) == 0, "stat the file"); report(stat(oldpath, &st[0]) == 0, "stat the file");
report(st[0].st_nlink == 2, "hard link count is increased"); report(st[0].st_nlink == 2, "hard link count is increased");
// Check that hard link points to the same inode // Check that hard link points to the same inode
report(stat("/usr/foo2", &st[1]) == 0, "stat the hard link"); report(stat(newpath, &st[1]) == 0, "stat the hard link");
report(st[0].st_dev == st[1].st_dev, "stat device IDs match"); report(st[0].st_dev == st[1].st_dev, "stat device IDs match");
report(st[0].st_ino == st[1].st_ino, "stat inode numbers match"); report(st[0].st_ino == st[1].st_ino, "stat inode numbers match");
// Remove the hard link // Remove the hard link
report(unlink("/usr/foo2") == 0, "remove the hard link"); report(unlink(newpath) == 0, "remove the hard link");
// Check that hard link count is decreased // Check that hard link count is decreased
report(stat("/usr/foo", &st[0]) == 0, "stat the file"); report(stat(oldpath, &st[0]) == 0, "stat the file");
report(st[0].st_nlink == 1, "hard link count is decreased"); report(st[0].st_nlink == 1, "hard link count is decreased");
// Clean up the temporary file. // Clean up the temporary file.
report(unlink("/usr/foo") == 0, "remove the file"); report(unlink(oldpath) == 0, "remove the file");
// Report results. // Report results.
printf("SUMMARY: %d tests, %d failures\n", tests, fails); printf("SUMMARY: %d tests, %d failures\n", tests, fails);
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment