minecraft-pi-reborn/mods/src/test/test.c

60 lines
1.4 KiB
C
Raw Normal View History

2021-01-31 02:32:20 +00:00
#define _GNU_SOURCE
2021-01-27 16:13:06 +00:00
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <time.h>
2021-01-27 21:26:19 +00:00
#include <libreborn/libreborn.h>
2021-01-27 16:13:06 +00:00
#include "../init/init.h"
// Types
typedef long long time64_t;
struct timespec64 {
time64_t tv_sec;
long tv_nsec;
};
typedef long int time32_t;
struct timespec32 {
time32_t tv_sec;
long tv_nsec;
};
void run_tests() {
// Test clock_gettime64
2021-01-31 02:32:20 +00:00
{
struct timespec64 ts64;
long out = syscall(SYS_clock_gettime64, CLOCK_MONOTONIC, &ts64);
if (out != 0) {
if (errno == ENOSYS) {
// clock_gettime64 Unsupported, Testing clock_gettime
struct timespec32 ts32;
out = syscall(SYS_clock_gettime, CLOCK_MONOTONIC, &ts32);
if (out != 0) {
// Failure
ERR("Unable To Run clock_gettime Syscall: %s", strerror(errno));
}
} else {
2021-01-27 16:13:06 +00:00
// Failure
2021-01-31 02:32:20 +00:00
ERR("Unable To Run clock_gettime64 Syscall: %s", strerror(errno));
2021-01-27 16:13:06 +00:00
}
2021-01-31 02:32:20 +00:00
}
}
2021-02-10 20:47:38 +00:00
// Test ~/.minecraft-pi Permissions
2021-01-31 02:32:20 +00:00
{
char *path = NULL;
2021-02-10 20:47:38 +00:00
asprintf(&path, "%s/.minecraft-pi", getenv("HOME"));
2021-02-16 17:26:40 +00:00
ALLOC_CHECK(path);
2021-01-31 02:32:20 +00:00
int ret = access(path, R_OK | W_OK);
free(path);
if (ret != 0) {
2021-01-27 16:13:06 +00:00
// Failure
2021-01-31 02:32:20 +00:00
ERR("%s", "Invalid ~/.minecraft-pi Permissions");
2021-01-27 16:13:06 +00:00
}
}
}