1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:57:44 +00:00

Userland: Replace most printf-style APIs with AK::Format APIs :^)

This commit is contained in:
Linus Groh 2021-05-31 15:43:25 +01:00
parent 4f1889c2cb
commit f5c35fccca
75 changed files with 642 additions and 644 deletions

View file

@ -15,20 +15,20 @@
#include <sys/uio.h>
#include <unistd.h>
#define EXPECT_ERROR_2(err, syscall, arg1, arg2) \
do { \
rc = syscall(arg1, arg2); \
if (rc >= 0 || errno != err) { \
fprintf(stderr, __FILE__ ":%d: Expected " #err ": " #syscall "(%p, %p), got rc=%d, errno=%d\n", __LINE__, (const void*)(arg1), (const void*)arg2, rc, errno); \
} \
#define EXPECT_ERROR_2(err, syscall, arg1, arg2) \
do { \
rc = syscall(arg1, arg2); \
if (rc >= 0 || errno != err) { \
warnln(__FILE__ ":{}: Expected " #err ": " #syscall "({:p}, {:p}), got rc={}, errno={}", __LINE__, (const void*)(arg1), (const void*)arg2, rc, errno); \
} \
} while (0)
#define EXPECT_ERROR_3(err, syscall, arg1, arg2, arg3) \
do { \
rc = syscall(arg1, arg2, arg3); \
if (rc >= 0 || errno != err) { \
fprintf(stderr, __FILE__ ":%d: Expected " #err ": " #syscall "(%p, %p, %p), got rc=%d, errno=%d\n", __LINE__, (const void*)(arg1), (const void*)(arg2), (const void*)(arg3), rc, errno); \
} \
#define EXPECT_ERROR_3(err, syscall, arg1, arg2, arg3) \
do { \
rc = syscall(arg1, arg2, arg3); \
if (rc >= 0 || errno != err) { \
warnln(__FILE__ ":{}: Expected " #err ": " #syscall "({:p}, {:p}, {:p}), got rc={}, errno={}", __LINE__, (const void*)(arg1), (const void*)(arg2), (const void*)(arg3), rc, errno); \
} \
} while (0)
static void test_read_from_directory()
@ -92,7 +92,7 @@ static void test_read_past_eof()
if (rc < 0)
perror("read");
if (rc > 0)
fprintf(stderr, "read %d bytes past EOF\n", rc);
warnln("read {} bytes past EOF", rc);
rc = close(fd);
VERIFY(rc == 0);
}
@ -121,11 +121,11 @@ static void test_mmap_directory()
VERIFY(fd >= 0);
auto* ptr = mmap(nullptr, 4096, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0);
if (ptr != MAP_FAILED) {
fprintf(stderr, "Boo! mmap() of a directory succeeded!\n");
warnln("Boo! mmap() of a directory succeeded!");
return;
}
if (errno != ENODEV) {
fprintf(stderr, "Boo! mmap() of a directory gave errno=%d instead of ENODEV!\n", errno);
warnln("Boo! mmap() of a directory gave errno={} instead of ENODEV!", errno);
return;
}
close(fd);
@ -145,7 +145,7 @@ static void test_tmpfs_read_past_end()
char buffer[16];
int nread = read(fd, buffer, sizeof(buffer));
if (nread != 0) {
fprintf(stderr, "Expected 0-length read past end of file in /tmp\n");
warnln("Expected 0-length read past end of file in /tmp");
}
close(fd);
}
@ -161,7 +161,7 @@ static void test_procfs_read_past_end()
char buffer[16];
int nread = read(fd, buffer, sizeof(buffer));
if (nread != 0) {
fprintf(stderr, "Expected 0-length read past end of file in /proc\n");
warnln("Expected 0-length read past end of file in /proc");
}
close(fd);
}
@ -178,7 +178,7 @@ static void test_open_create_device()
}
if (st.st_mode != 0100600) {
fprintf(stderr, "Expected mode 0100600 after attempt to create a device node with open(O_CREAT), mode=%o\n", st.st_mode);
warnln("Expected mode 0100600 after attempt to create a device node with open(O_CREAT), mode={:o}", st.st_mode);
}
unlink("/tmp/fakedevice");
close(fd);
@ -198,7 +198,7 @@ static void test_unlink_symlink()
rc = unlink("/tmp/linky");
if (rc < 0) {
perror("unlink");
fprintf(stderr, "Expected unlink() of a symlink into an unreadable directory to succeed!\n");
warnln("Expected unlink() of a symlink into an unreadable directory to succeed!");
}
}
@ -213,11 +213,11 @@ static void test_eoverflow()
char buffer[16];
rc = read(fd, buffer, sizeof(buffer));
if (rc >= 0 || errno != EOVERFLOW) {
fprintf(stderr, "Expected EOVERFLOW when trying to read past INT32_MAX\n");
warnln("Expected EOVERFLOW when trying to read past INT32_MAX");
}
rc = write(fd, buffer, sizeof(buffer));
if (rc >= 0 || errno != EOVERFLOW) {
fprintf(stderr, "Expected EOVERFLOW when trying to write past INT32_MAX\n");
warnln("Expected EOVERFLOW when trying to write past INT32_MAX");
}
close(fd);
}
@ -235,7 +235,7 @@ static void test_rmdir_while_inside_dir()
int fd = open("x", O_CREAT | O_RDWR, 0600);
if (fd >= 0 || errno != ENOENT) {
fprintf(stderr, "Expected ENOENT when trying to create a file inside a deleted directory. Got %d with errno=%d\n", fd, errno);
warnln("Expected ENOENT when trying to create a file inside a deleted directory. Got {} with errno={}", fd, errno);
}
rc = chdir("/home/anon");
@ -258,14 +258,14 @@ static void test_writev()
VERIFY_NOT_REACHED();
}
if (nwritten != 12) {
fprintf(stderr, "Didn't write 12 bytes to pipe with writev\n");
warnln("Didn't write 12 bytes to pipe with writev");
VERIFY_NOT_REACHED();
}
char buffer[32];
int nread = read(pipefds[0], buffer, sizeof(buffer));
if (nread != 12 || memcmp(buffer, "HelloFriends", 12)) {
fprintf(stderr, "Didn't read the expected data from pipe after writev\n");
warnln("Didn't read the expected data from pipe after writev");
VERIFY_NOT_REACHED();
}