Squash commits for public release
This commit is contained in:
9
test/kernel/fs/BUILD.gn
Normal file
9
test/kernel/fs/BUILD.gn
Normal file
@@ -0,0 +1,9 @@
|
||||
group("fs") {
|
||||
deps = [
|
||||
"//test/kernel/fs/cwd:cwd",
|
||||
"//test/kernel/fs/dirfile:dirfile",
|
||||
"//test/kernel/fs/dup:dup",
|
||||
"//test/kernel/fs/fourfiles:fourfiles",
|
||||
"//test/kernel/fs/procfs:procfs",
|
||||
]
|
||||
}
|
||||
8
test/kernel/fs/cwd/BUILD.gn
Normal file
8
test/kernel/fs/cwd/BUILD.gn
Normal file
@@ -0,0 +1,8 @@
|
||||
import("//build/test/TEMPLATE.gni")
|
||||
|
||||
xOS_test("cwd") {
|
||||
test_bundle = "kernel/fs/cwd"
|
||||
sources = [ "main.c" ]
|
||||
configs = [ "//build/userland:userland_flags" ]
|
||||
deplibs = [ "libc" ]
|
||||
}
|
||||
25
test/kernel/fs/cwd/main.c
Normal file
25
test/kernel/fs/cwd/main.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char buf[256];
|
||||
|
||||
#define ANSWER "/test_bin/kernel$fs$cwd"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int fd = 0;
|
||||
fd = open("/proc/self/exe", O_RDONLY);
|
||||
int rd = read(fd, buf, 256);
|
||||
if (rd != strlen(ANSWER)) {
|
||||
TestErr("Wrong len");
|
||||
}
|
||||
|
||||
if (strncmp(buf, ANSWER, rd)) {
|
||||
TestErr("Wrong path");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
8
test/kernel/fs/dirfile/BUILD.gn
Normal file
8
test/kernel/fs/dirfile/BUILD.gn
Normal file
@@ -0,0 +1,8 @@
|
||||
import("//build/test/TEMPLATE.gni")
|
||||
|
||||
xOS_test("dirfile") {
|
||||
test_bundle = "kernel/fs/dirfile"
|
||||
sources = [ "main.c" ]
|
||||
configs = [ "//build/userland:userland_flags" ]
|
||||
deplibs = [ "libc" ]
|
||||
}
|
||||
39
test/kernel/fs/dirfile/main.c
Normal file
39
test/kernel/fs/dirfile/main.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char buf[512];
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open("dirfile", 0);
|
||||
if (fd >= 0) {
|
||||
TestErr("opened dirfile which does not exist");
|
||||
}
|
||||
fd = open("dirfile", O_CREAT);
|
||||
if (fd < 0) {
|
||||
TestErr("cannot create dirfile");
|
||||
}
|
||||
if (chdir("dirfile") == 0) {
|
||||
TestErr("chdir dirfile succeeded");
|
||||
}
|
||||
if (unlink("dirfile") != 0) {
|
||||
TestErr("unlink dirfile succeeded");
|
||||
}
|
||||
|
||||
fd = open(".", O_RDWR);
|
||||
if (fd >= 0) {
|
||||
TestErr("open . for writing succeeded");
|
||||
}
|
||||
fd = open(".", O_RDONLY);
|
||||
if (write(fd, "x", 1) > 0) {
|
||||
TestErr("write . succeeded");
|
||||
}
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
8
test/kernel/fs/dup/BUILD.gn
Normal file
8
test/kernel/fs/dup/BUILD.gn
Normal file
@@ -0,0 +1,8 @@
|
||||
import("//build/test/TEMPLATE.gni")
|
||||
|
||||
xOS_test("dup") {
|
||||
test_bundle = "kernel/fs/dup"
|
||||
sources = [ "main.c" ]
|
||||
configs = [ "//build/userland:userland_flags" ]
|
||||
deplibs = [ "libc" ]
|
||||
}
|
||||
40
test/kernel/fs/dup/main.c
Normal file
40
test/kernel/fs/dup/main.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int fd = -1;
|
||||
fd = open("/boot/kernel.config", O_RDONLY);
|
||||
if (fd < 0) {
|
||||
TestErr("Can't open kernel.config");
|
||||
}
|
||||
|
||||
int dupfd = dup(fd);
|
||||
if (dupfd < 0) {
|
||||
TestErr("Can't dup file");
|
||||
}
|
||||
|
||||
int err = write(dupfd, "abcd", 5);
|
||||
if (!err) {
|
||||
TestErr("Succesfully write to read only file");
|
||||
}
|
||||
|
||||
stat_t stat;
|
||||
if (fstat(fd, &stat) < 0) {
|
||||
TestErr("Can't read fstat of orig file");
|
||||
}
|
||||
|
||||
stat_t newstat;
|
||||
if (fstat(dupfd, &newstat) < 0) {
|
||||
TestErr("Can't read fstat of dup file");
|
||||
}
|
||||
|
||||
if (memcmp(&stat, &newstat, sizeof(stat_t)) != 0) {
|
||||
TestErr("Different stat info of files");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
8
test/kernel/fs/fourfiles/BUILD.gn
Normal file
8
test/kernel/fs/fourfiles/BUILD.gn
Normal file
@@ -0,0 +1,8 @@
|
||||
import("//build/test/TEMPLATE.gni")
|
||||
|
||||
xOS_test("fourfiles") {
|
||||
test_bundle = "kernel/fs/fourfiles"
|
||||
sources = [ "main.c" ]
|
||||
configs = [ "//build/userland:userland_flags" ]
|
||||
deplibs = [ "libc" ]
|
||||
}
|
||||
67
test/kernel/fs/fourfiles/main.c
Normal file
67
test/kernel/fs/fourfiles/main.c
Normal file
@@ -0,0 +1,67 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char buf[512];
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int fd, pid, i, j, n, total, pi;
|
||||
char* names[] = { "f0.e", "f1.e", "f2.e", "f3.e" };
|
||||
char* fname;
|
||||
int pids[4];
|
||||
|
||||
for (pi = 0; pi < 4; pi++) {
|
||||
fname = names[pi];
|
||||
unlink(fname);
|
||||
|
||||
pid = fork();
|
||||
pids[pi] = pid;
|
||||
if (pid < 0) {
|
||||
TestErr("fork failed");
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
fd = open(fname, O_CREAT | O_RDWR, 0600);
|
||||
if (fd < 0) {
|
||||
TestErr("create failed");
|
||||
}
|
||||
|
||||
memset(buf, '0' + pi, 512);
|
||||
for (i = 0; i < 12; i++) {
|
||||
if ((n = write(fd, buf, 500)) != 500) {
|
||||
TestErr("write failed");
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
for (pi = 0; pi < 4; pi++) {
|
||||
wait(pids[pi]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
fname = names[i];
|
||||
fd = open(fname, O_RDONLY);
|
||||
total = 0;
|
||||
while ((n = read(fd, buf, sizeof(buf))) > 0) {
|
||||
for (j = 0; j < n; j++) {
|
||||
if (buf[j] != '0' + i) {
|
||||
TestErr("wrong char");
|
||||
}
|
||||
}
|
||||
total += n;
|
||||
}
|
||||
close(fd);
|
||||
if (total != 12 * 500) {
|
||||
TestErr("wrong length");
|
||||
}
|
||||
unlink(fname);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
8
test/kernel/fs/procfs/BUILD.gn
Normal file
8
test/kernel/fs/procfs/BUILD.gn
Normal file
@@ -0,0 +1,8 @@
|
||||
import("//build/test/TEMPLATE.gni")
|
||||
|
||||
xOS_test("procfs") {
|
||||
test_bundle = "kernel/fs/procfs"
|
||||
sources = [ "main.c" ]
|
||||
configs = [ "//build/userland:userland_flags" ]
|
||||
deplibs = [ "libc" ]
|
||||
}
|
||||
21
test/kernel/fs/procfs/main.c
Normal file
21
test/kernel/fs/procfs/main.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int fd = 0;
|
||||
fd = open("/proc/stat", O_RDWR);
|
||||
if (fd > 0) {
|
||||
TestErr("Opened /proc/stat for write");
|
||||
}
|
||||
|
||||
fd = open("/proc/stat", O_RDONLY);
|
||||
if (fd <= 0) {
|
||||
TestErr("Can't open /proc/stat for read");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user