mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:17:35 +00:00
Tests: Establish root Tests directory, move Userland/Tests there
With the goal of centralizing all tests in the system, this is a first step to establish a Tests sub-tree. It will contain all of the unit tests and test harnesses for the various components in the system.
This commit is contained in:
parent
6e641fadfa
commit
fd0dbd1ebf
49 changed files with 1 additions and 1 deletions
76
Tests/Kernel/unveil-symlinks.cpp
Normal file
76
Tests/Kernel/unveil-symlinks.cpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
rmdir("/tmp/foo/1");
|
||||
rmdir("/tmp/foo");
|
||||
unlink("/tmp/bar");
|
||||
|
||||
if (mkdir("/tmp/foo", 0755) < 0) {
|
||||
perror("mkdir");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mkdir("/tmp/foo/1", 0755) < 0) {
|
||||
perror("mkdir");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (symlink("/tmp/foo", "/tmp/bar")) {
|
||||
perror("symlink");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (unveil("/tmp/foo", "r") < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (unveil(nullptr, nullptr) < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fd = open("/tmp/foo/1", O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
return 1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
fd = open("/tmp/bar/1", O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
fprintf(stderr, "FAIL, symlink was not unveiled\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (chdir("/tmp")) {
|
||||
perror("chdir");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fd = open("./foo/1", O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
return 1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
fd = open("./bar/1", O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
fprintf(stderr, "FAIL, symlink was not unveiled\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("PASS\n");
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue