LF OS
Hobby operating system for amd64 with high ambitions
Loading...
Searching...
No Matches
runner.cxx
Go to the documentation of this file.
1#define _TESTRUNNER
2
3#include <iostream>
4#include <dlfcn.h>
5#include <stdarg.h>
6
7#include <gtest/gtest.h>
8
9#define LFOS_API __attribute__((visibility("default")))
10
11extern "C" {
12 #include "lfostest.h"
13 #include "../allocator.h"
14
16
18 .alloc = [](allocator_t* alloc, size_t size) -> void* {
19 alloc->tag += size;
20 uint8_t* data = new uint8_t[size + sizeof(size_t)];
21 (reinterpret_cast<size_t*>(data))[0] = size;
22 return data+sizeof(size_t);
23 },
24 .dealloc = [](allocator_t* alloc, void* ptr) -> void {
25 size_t* data = reinterpret_cast<size_t*>(reinterpret_cast<uint8_t*>(ptr) - sizeof(size_t));
26 alloc->tag -= *data;
27 delete[] data;
28 }
29 };
30
31 LFOS_API void panic_message(const char* message) {
32 fprintf(stderr, "Panic() called: %s\n", message);
33 exit(-1);
34 }
35
36 LFOS_API void panic() {
37 panic_message("Unknown error");
38 }
39
40 LFOS_API int ksnprintf(char* buffer, int buffer_size, const char* format, ...) {
41 va_list args;
42 va_start(args, format);
43 int count = vsnprintf(buffer, buffer_size, format, args);
44 va_end(args);
45
46 return count;
47 }
48}
49
50int main(int argc, char* argv[]) {
51 dlopen(NULL, RTLD_NOW | RTLD_NOLOAD | RTLD_GLOBAL);
52
53 testing::InitGoogleTest(&argc, argv);
54
55 for(int i = 1; i < argc; ++i) {
56 if(!dlopen(argv[i], RTLD_NOW)) {
57 char* error = dlerror();
58
59 if(!error) {
60 error = (char*)"Unknown error";
61 }
62
63 std::cerr << "Could not load testlib \"" << argv[i] << "\": " << error << std::endl;
64 abort();
65 }
66 }
67
68 return RUN_ALL_TESTS();
69}
uint64_t size_t
Definition arch.h:18
unsigned long uint64_t
Definition arch.h:14
unsigned char uint8_t
Definition arch.h:5
allocator_t * alloc
uint16_t size
Size of the loaded file.
Definition loader.h:5
#define LFOS_API
Definition runner.cxx:9
int main(int argc, char *argv[])
Definition runner.cxx:50
LFOS_API void panic()
Definition runner.cxx:36
LFOS_API void panic_message(const char *message)
Definition runner.cxx:31
LFOS_API allocator_t kernel_alloc
Definition runner.cxx:17
LFOS_API uint64_t scheduler_current_process
Definition runner.cxx:15
LFOS_API int ksnprintf(char *buffer, int buffer_size, const char *format,...)
Definition runner.cxx:40
#define va_start(ap, X)
Definition stdarg.h:6
#define va_end(ap)
Definition stdarg.h:8
__builtin_va_list va_list
Definition stdarg.h:4
uint64_t tag
Definition allocator.h:12
void *(* alloc)(struct allocator *alloc, size_t size)
Definition allocator.h:9
static bool struct Message * message
Definition syscalls.h:338
static uint16_t bool uint64_t * error
Definition syscalls.h:126
static enum @5 format