apps+base: Remove many legacy test apps
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e72bc55c6f
commit
ce3542e2bd
@ -28,8 +28,6 @@ luna_app(stat.cpp stat)
|
||||
luna_app(uname.cpp uname)
|
||||
luna_app(base64.cpp base64)
|
||||
luna_app(login.cpp login)
|
||||
luna_app(ipc-test.cpp ipc-test)
|
||||
luna_app(signal-test.cpp signal-test)
|
||||
luna_app(mount.cpp mount)
|
||||
luna_app(umount.cpp umount)
|
||||
luna_app(ps.cpp ps)
|
||||
@ -41,10 +39,5 @@ luna_app(pivot_root.cpp pivot_root)
|
||||
luna_app(cp.cpp cp)
|
||||
luna_app(kill.cpp kill)
|
||||
luna_app(gol.cpp gol)
|
||||
luna_app(buffer-test.cpp buffer-test)
|
||||
luna_app(socket-test.cpp socket-test)
|
||||
luna_app(socket-client.cpp socket-client)
|
||||
luna_app(input.cpp input)
|
||||
luna_app(shmem-test.cpp shmem-test)
|
||||
luna_app(touch.cpp touch)
|
||||
luna_app(free.cpp free)
|
||||
|
@ -1,27 +0,0 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
fprintf(stderr, "Writing incomplete line to stdout (_IOLBF=%d)...\n", stdout->_buf.mode);
|
||||
fputs("hi!", stdout);
|
||||
sleep(3);
|
||||
putchar('\n');
|
||||
fprintf(stderr, "Incomplete line should have been written.\n");
|
||||
|
||||
FILE* f = fopen("/dev/console", "w+");
|
||||
assert(f);
|
||||
assert(setvbuf(f, NULL, _IOFBF, 0) == 0);
|
||||
|
||||
fprintf(stderr, "Writing long text to file (_IOFBF=%d)...\n", f->_buf.mode);
|
||||
|
||||
fputs("Hello world!\nHow are you doing!\nThis is a test for many lines of buffering.\n", f);
|
||||
|
||||
sleep(3);
|
||||
fflush(f);
|
||||
|
||||
fprintf(stderr, "Long text should have been written.\n");
|
||||
|
||||
fclose(f);
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
#include <errno.h>
|
||||
#include <luna/String.h>
|
||||
#include <moon/Keyboard.h>
|
||||
#include <moon/Mouse.h>
|
||||
#include <os/File.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/poll.h>
|
||||
#include <unistd.h>
|
||||
|
||||
Result<void> process_mouse_packet(const moon::MousePacket& packet)
|
||||
{
|
||||
bool right = packet.buttons & moon::MouseButton::Right;
|
||||
bool left = packet.buttons & moon::MouseButton::Left;
|
||||
bool middle = packet.buttons & moon::MouseButton::Middle;
|
||||
|
||||
Vector<StringView> buttons;
|
||||
if (right) TRY(buttons.try_append("RIGHT"_sv));
|
||||
if (left) TRY(buttons.try_append("LEFT"_sv));
|
||||
if (middle) TRY(buttons.try_append("MIDDLE"_sv));
|
||||
|
||||
String button_string;
|
||||
if (!buttons.size()) button_string = TRY(String::from_cstring("NONE"));
|
||||
else
|
||||
button_string = TRY(String::join(buttons, " | "_sv));
|
||||
|
||||
os::println("Mouse packet: xdelta=%d, ydelta=%d, buttons=(%s)", packet.xdelta, packet.ydelta,
|
||||
button_string.chars());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<int> luna_main(int, char**)
|
||||
{
|
||||
auto mouse = TRY(os::File::open("/dev/mouse", os::File::ReadOnly));
|
||||
mouse->set_buffer(os::File::NotBuffered);
|
||||
|
||||
auto keyboard = TRY(os::File::open("/dev/kbd", os::File::ReadOnly));
|
||||
keyboard->set_buffer(os::File::NotBuffered);
|
||||
|
||||
ioctl(STDIN_FILENO, TTYSETGFX, 1);
|
||||
|
||||
while (1)
|
||||
{
|
||||
struct pollfd fds[] = {
|
||||
{ .fd = mouse->fd(), .events = POLLIN, .revents = 0 },
|
||||
{ .fd = keyboard->fd(), .events = POLLIN, .revents = 0 },
|
||||
};
|
||||
|
||||
int rc = poll(fds, 2, 1000);
|
||||
if (!rc) continue;
|
||||
if (rc < 0) { os::println("poll: error: %s", strerror(errno)); }
|
||||
|
||||
if (fds[0].revents & POLLIN)
|
||||
{
|
||||
moon::MousePacket packet;
|
||||
TRY(mouse->read_typed(packet));
|
||||
TRY(process_mouse_packet(packet));
|
||||
}
|
||||
if (fds[1].revents & POLLIN)
|
||||
{
|
||||
moon::KeyboardPacket packet;
|
||||
TRY(keyboard->read_typed(packet));
|
||||
os::println("Keyboard packet: %s key %u", packet.released ? "released" : "pressed", packet.key);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int pfds[2];
|
||||
|
||||
if (pipe(pfds) < 0)
|
||||
{
|
||||
perror("pipe");
|
||||
return 1;
|
||||
}
|
||||
|
||||
pid_t child = fork();
|
||||
if (child == 0)
|
||||
{
|
||||
close(pfds[1]);
|
||||
|
||||
char buffer[4096];
|
||||
size_t nread = read(pfds[0], buffer, sizeof(buffer) - 1);
|
||||
buffer[nread] = 0;
|
||||
close(pfds[0]);
|
||||
|
||||
puts(buffer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if (child == -1)
|
||||
{
|
||||
perror("fork");
|
||||
return 1;
|
||||
}
|
||||
|
||||
close(pfds[0]);
|
||||
|
||||
const char* string = "Hello from a child process who just received this message from its parent!";
|
||||
write(pfds[1], string, strlen(string));
|
||||
close(pfds[1]);
|
||||
|
||||
wait(NULL);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
pledge("stdio rpath wpath cpath proc", nullptr);
|
||||
|
||||
int fd = shm_open("/shared", O_CREAT | O_RDWR, 0666);
|
||||
if (fd < 0)
|
||||
{
|
||||
perror("shm_open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ftruncate(fd, PAGE_SIZE);
|
||||
|
||||
void* address = mmap(nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (address == MAP_FAILED)
|
||||
{
|
||||
perror("mmap");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* ptr = (char*)address;
|
||||
|
||||
printf("the value is %c\n", *ptr);
|
||||
|
||||
*ptr = 'a';
|
||||
|
||||
pid_t child = fork();
|
||||
if (child < 0)
|
||||
{
|
||||
perror("fork");
|
||||
return 1;
|
||||
}
|
||||
if (child == 0)
|
||||
{
|
||||
*ptr = 'e';
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
waitpid(child, NULL, 0);
|
||||
|
||||
printf("the value is %c\n", *ptr);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void handler(int)
|
||||
{
|
||||
puts("I caught a segfault!");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
struct sigaction sa;
|
||||
sa.sa_handler = handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_RESETHAND;
|
||||
sigaction(SIGSEGV, &sa, NULL);
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wnonnull"
|
||||
char* str = nullptr;
|
||||
memset(str, 0, 2);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
#include <os/ArgumentParser.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
Result<int> luna_main(int argc, char** argv)
|
||||
{
|
||||
StringView message;
|
||||
|
||||
os::ArgumentParser parser;
|
||||
parser.add_description("A UNIX domain socket client, to test said sockets.");
|
||||
parser.add_system_program_info("socket-client"_sv);
|
||||
parser.add_positional_argument(message, "message"_sv, "exit"_sv);
|
||||
parser.parse(argc, argv);
|
||||
|
||||
int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sockfd < 0)
|
||||
{
|
||||
perror("socket");
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct sockaddr_un un;
|
||||
un.sun_family = AF_UNIX;
|
||||
strncpy(un.sun_path, "/tmp/local.sock", sizeof(un.sun_path));
|
||||
|
||||
if (connect(sockfd, (struct sockaddr*)&un, sizeof(un)) < 0)
|
||||
{
|
||||
perror("connect");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char buf[4096];
|
||||
ssize_t nread = read(sockfd, buf, sizeof(buf) - 1);
|
||||
if (nread > 0)
|
||||
{
|
||||
buf[nread] = 0;
|
||||
printf("Message from server: %s\n", buf);
|
||||
}
|
||||
|
||||
write(sockfd, message.chars(), message.length());
|
||||
|
||||
close(sockfd);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
setgid(1000);
|
||||
setuid(1000);
|
||||
|
||||
remove("/tmp/local.sock");
|
||||
|
||||
int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sockfd < 0)
|
||||
{
|
||||
perror("socket");
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct sockaddr_un un;
|
||||
un.sun_family = AF_UNIX;
|
||||
strncpy(un.sun_path, "/tmp/local.sock", sizeof(un.sun_path));
|
||||
|
||||
if (bind(sockfd, (struct sockaddr*)&un, sizeof(un)) < 0)
|
||||
{
|
||||
perror("bind");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (listen(sockfd, 10) < 0)
|
||||
{
|
||||
perror("listen");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
int fd = accept(sockfd, NULL, NULL);
|
||||
if (fd < 0)
|
||||
{
|
||||
perror("accept");
|
||||
return 1;
|
||||
}
|
||||
|
||||
puts("New connection from client, sending hello");
|
||||
|
||||
const char* message = "Hello, client!";
|
||||
write(fd, message, strlen(message));
|
||||
|
||||
puts("Now waiting for client to message back");
|
||||
|
||||
char buf[4096];
|
||||
ssize_t nread = read(fd, buf, sizeof(buf) - 1);
|
||||
if (nread >= 0)
|
||||
{
|
||||
buf[nread] = 0;
|
||||
printf("Message from client: %s\n", buf);
|
||||
if (!strcasecmp(buf, "exit"))
|
||||
{
|
||||
close(fd);
|
||||
close(sockfd);
|
||||
remove("/tmp/local.sock");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else { printf("Error reading from client: %s\n", strerror(errno)); }
|
||||
|
||||
puts("Transmission ended, closing connection");
|
||||
|
||||
close(fd);
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
Name=listen
|
||||
Description=Start a Unix domain socket test server.
|
||||
Command=/usr/bin/socket-test
|
||||
StandardOutput=/dev/uart0
|
||||
StandardError=/dev/uart0
|
||||
Restart=true
|
Loading…
Reference in New Issue
Block a user