cleanup: remove test programs/libraries
This commit is contained in:
@@ -1,76 +0,0 @@
|
||||
# Makefile for test_dialogs
|
||||
# Copyright (c) 2026 Daniel Hammer
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
.SUFFIXES:
|
||||
|
||||
TOOLCHAIN_PREFIX := $(shell cd ../../.. && pwd)/toolchain/local/bin/x86_64-elf-
|
||||
ifneq ($(wildcard $(TOOLCHAIN_PREFIX)gcc),)
|
||||
CXX := $(TOOLCHAIN_PREFIX)g++
|
||||
else
|
||||
CXX := g++
|
||||
endif
|
||||
|
||||
PROG_INC := ../../include
|
||||
LINK_LD := ../../link.ld
|
||||
BINDIR := ../../bin
|
||||
OBJDIR := obj
|
||||
LIBDIR := ../../lib
|
||||
|
||||
CXXFLAGS := \
|
||||
-std=gnu++20 \
|
||||
-g -O2 -pipe \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-Wno-unused-parameter \
|
||||
-Wno-unused-function \
|
||||
-nostdinc \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-fno-stack-check \
|
||||
-fno-PIC \
|
||||
-fno-rtti \
|
||||
-fno-exceptions \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
-m64 \
|
||||
-march=x86-64 \
|
||||
-msse \
|
||||
-msse2 \
|
||||
-mno-red-zone \
|
||||
-mcmodel=small \
|
||||
-I $(PROG_INC) \
|
||||
-isystem $(PROG_INC)/libc \
|
||||
-isystem ../../../kernel/freestnd-c-hdrs/x86_64/include \
|
||||
-isystem ../../../kernel/freestnd-cxx-hdrs/x86_64/include
|
||||
|
||||
LDFLAGS := \
|
||||
-nostdlib \
|
||||
-static \
|
||||
-Wl,--build-id=none \
|
||||
-Wl,--gc-sections \
|
||||
-Wl,-m,elf_x86_64 \
|
||||
-z max-page-size=0x1000 \
|
||||
-T $(LINK_LD)
|
||||
|
||||
SRCS := main.cpp
|
||||
OBJS := $(addprefix $(OBJDIR)/,$(SRCS:.cpp=.o))
|
||||
|
||||
TARGET := $(BINDIR)/os/test_dialogs.elf
|
||||
LOADER_LIB := $(LIBDIR)/libloader/liblibloader.a
|
||||
LIBC_LIB := $(LIBDIR)/libc/liblibc.a
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJS) $(LINK_LD) Makefile $(LOADER_LIB) $(LIBC_LIB)
|
||||
mkdir -p $(BINDIR)/os
|
||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(LOADER_LIB) $(LIBC_LIB) -o $@
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp Makefile
|
||||
mkdir -p $(OBJDIR)
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR) $(TARGET)
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* main.cpp
|
||||
* Minimal libdialogs message box test
|
||||
* Copyright (c) 2026 Daniel Hammer
|
||||
*/
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <gui/dialogs.hpp>
|
||||
|
||||
extern "C" void _start() {
|
||||
auto result = gui::dialogs::message_box(
|
||||
"Close Document",
|
||||
"Discard unsaved changes?",
|
||||
gui::dialogs::MESSAGE_BOX_YES_NO_CANCEL);
|
||||
|
||||
if (result == gui::dialogs::MESSAGE_BOX_RESULT_YES) {
|
||||
/* discard and close */
|
||||
}
|
||||
montauk::exit(0);
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
# Makefile for test_dl
|
||||
|
||||
ARCH := x86_64
|
||||
|
||||
TOOLCHAIN_PREFIX := $(shell cd ../../.. && pwd)/toolchain/local/bin/x86_64-elf-
|
||||
CXX := $(TOOLCHAIN_PREFIX)g++
|
||||
|
||||
override CXXFLAGS := \
|
||||
-std=gnu++20 \
|
||||
-g -O2 -pipe \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-nostdinc \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-fno-stack-check \
|
||||
-fno-PIC \
|
||||
-fno-rtti \
|
||||
-fno-exceptions \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
-m64 \
|
||||
-march=x86-64 \
|
||||
-mno-80387 \
|
||||
-mno-mmx \
|
||||
-mno-sse \
|
||||
-mno-sse2 \
|
||||
-mno-red-zone \
|
||||
-mcmodel=small \
|
||||
-I ../../include \
|
||||
-isystem ../../include/libc \
|
||||
-isystem ../../include/montauk \
|
||||
-isystem ../../../kernel/freestnd-c-hdrs/x86_64/include \
|
||||
-isystem ../../../kernel/freestnd-cxx-hdrs/x86_64/include
|
||||
|
||||
override LDFLAGS := \
|
||||
-nostdlib \
|
||||
-static \
|
||||
-Wl,--build-id=none \
|
||||
-Wl,--gc-sections \
|
||||
-Wl,-m,elf_x86_64 \
|
||||
-z max-page-size=0x1000 \
|
||||
-T ../../link.ld
|
||||
|
||||
BINDIR := ../../bin/os
|
||||
LOADER_LIB := ../../lib/libloader/liblibloader.a
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(BINDIR)/test_dl.elf
|
||||
|
||||
$(BINDIR)/test_dl.elf: main.cpp Makefile $(LOADER_LIB) ../../lib/libc/liblibc.a
|
||||
@mkdir -p $(BINDIR)
|
||||
$(CXX) $(CXXFLAGS) -c main.cpp -o main.o
|
||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) main.o $(LOADER_LIB) ../../lib/libc/liblibc.a -o $@
|
||||
rm -f main.o
|
||||
|
||||
clean:
|
||||
rm -f $(BINDIR)/test_dl.elf
|
||||
@@ -1,187 +0,0 @@
|
||||
/*
|
||||
* test_dl.cpp
|
||||
* Test application for dynamic library loading
|
||||
* Copyright (c) 2026 Daniel Hammer
|
||||
*/
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <libloader/libloader.h>
|
||||
|
||||
// Forward declarations
|
||||
static void print_int(int val);
|
||||
static void print_hex(uint64_t val);
|
||||
|
||||
extern "C" void _start() {
|
||||
montauk::print("=== Dynamic Library Test ===\n\n");
|
||||
|
||||
// Test loading libmath
|
||||
montauk::print("Loading libmath...\n");
|
||||
LibHandle* lib = libloader::dlopen("0:/os/libmath.lib");
|
||||
if (!lib) {
|
||||
montauk::print("ERROR: Failed to load libmath.lib\n");
|
||||
montauk::exit(1);
|
||||
}
|
||||
montauk::print("Library loaded successfully!\n\n");
|
||||
|
||||
// Test dlsym for various functions
|
||||
montauk::print("Resolving symbols...\n");
|
||||
|
||||
// math_add
|
||||
typedef int (*math_fn_t)(int, int);
|
||||
math_fn_t math_add = (math_fn_t)libloader::dlsym(lib, "math_add");
|
||||
if (!math_add) {
|
||||
montauk::print("ERROR: Failed to resolve math_add\n");
|
||||
montauk::exit(1);
|
||||
}
|
||||
montauk::print(" math_add: OK\n");
|
||||
|
||||
// math_mul
|
||||
math_fn_t math_mul = (math_fn_t)libloader::dlsym(lib, "math_mul");
|
||||
if (!math_mul) {
|
||||
montauk::print("ERROR: Failed to resolve math_mul\n");
|
||||
montauk::exit(1);
|
||||
}
|
||||
montauk::print(" math_mul: OK\n");
|
||||
|
||||
// math_max
|
||||
typedef int (*math_max_t)(int, int);
|
||||
math_max_t math_max = (math_max_t)libloader::dlsym(lib, "math_max");
|
||||
if (!math_max) {
|
||||
montauk::print("ERROR: Failed to resolve math_max\n");
|
||||
montauk::exit(1);
|
||||
}
|
||||
montauk::print(" math_max: OK\n\n");
|
||||
|
||||
// Test the functions
|
||||
montauk::print("Testing library functions:\n");
|
||||
|
||||
// Test add: 10 + 5 = 15
|
||||
int a = 10, b = 5;
|
||||
int result = math_add(a, b);
|
||||
montauk::print(" math_add(10, 5) = ");
|
||||
print_int(result);
|
||||
montauk::print("\n");
|
||||
|
||||
// Test mul: 7 * 6 = 42
|
||||
result = math_mul(7, 6);
|
||||
montauk::print(" math_mul(7, 6) = ");
|
||||
print_int(result);
|
||||
montauk::print("\n");
|
||||
|
||||
// Test max: max(100, 200) = 200
|
||||
result = math_max(100, 200);
|
||||
montauk::print(" math_max(100, 200) = ");
|
||||
print_int(result);
|
||||
montauk::print("\n\n");
|
||||
|
||||
// Unload the library
|
||||
montauk::print("Unloading library...\n");
|
||||
libloader::dlclose(lib);
|
||||
montauk::print("Library unloaded.\n");
|
||||
|
||||
// Test loading libhello (GUI library)
|
||||
montauk::print("\nLoading libhello (GUI library)...\n");
|
||||
LibHandle* hellolib = libloader::dlopen("0:/os/libhello.lib");
|
||||
if (!hellolib) {
|
||||
montauk::print("ERROR: Failed to load libhello.lib\n");
|
||||
montauk::exit(1);
|
||||
}
|
||||
montauk::print("Library loaded successfully!\n\n");
|
||||
|
||||
// Resolve hello_run
|
||||
typedef int (*hello_run_t)(void);
|
||||
hello_run_t hello_run = (hello_run_t)libloader::dlsym(hellolib, "hello_run");
|
||||
if (!hello_run) {
|
||||
montauk::print("ERROR: Failed to resolve hello_run\n");
|
||||
montauk::exit(1);
|
||||
}
|
||||
montauk::print(" hello_run: OK\n\n");
|
||||
|
||||
// Debug: print hello_run address
|
||||
montauk::print(" DEBUG: hello_run @ ");
|
||||
print_hex((uint64_t)hello_run);
|
||||
montauk::print("\n\n");
|
||||
|
||||
// Test heap allocations in the shared library
|
||||
montauk::print("Testing heap allocations in libhello...\n");
|
||||
typedef int (*malloc_test_t)(void);
|
||||
malloc_test_t malloc_test = (malloc_test_t)libloader::dlsym(hellolib, "hello_malloc_test");
|
||||
if (!malloc_test) {
|
||||
montauk::print("ERROR: Failed to resolve hello_malloc_test\n");
|
||||
libloader::dlclose(hellolib);
|
||||
montauk::exit(1);
|
||||
}
|
||||
montauk::print(" hello_malloc_test: OK\n");
|
||||
|
||||
int malloc_result = malloc_test();
|
||||
if (malloc_result != 0) {
|
||||
montauk::print("ERROR: heap allocation test in libhello failed\n");
|
||||
libloader::dlclose(hellolib);
|
||||
montauk::exit(1);
|
||||
}
|
||||
montauk::print(" heap allocation test: PASSED\n\n");
|
||||
|
||||
// Run the GUI demo (this creates a window and event loop)
|
||||
montauk::print("Running GUI demo...\n");
|
||||
hello_run();
|
||||
|
||||
// Unload the library
|
||||
montauk::print("GUI demo closed.\n");
|
||||
montauk::print("Unloading library...\n");
|
||||
libloader::dlclose(hellolib);
|
||||
montauk::print("Library unloaded.\n");
|
||||
|
||||
montauk::print("\n=== All tests passed! ===\n");
|
||||
montauk::exit(0);
|
||||
}
|
||||
|
||||
// Simple integer to string conversion for printing
|
||||
static void print_int(int val) {
|
||||
char buf[16];
|
||||
int idx = 0;
|
||||
bool neg = false;
|
||||
|
||||
if (val < 0) {
|
||||
neg = true;
|
||||
val = -val;
|
||||
}
|
||||
|
||||
if (val == 0) {
|
||||
buf[idx++] = '0';
|
||||
} else {
|
||||
while (val > 0) {
|
||||
buf[idx++] = '0' + (val % 10);
|
||||
val /= 10;
|
||||
}
|
||||
}
|
||||
|
||||
if (neg) {
|
||||
montauk::putchar('-');
|
||||
}
|
||||
|
||||
for (int i = idx - 1; i >= 0; i--) {
|
||||
montauk::putchar(buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Print hex value (uppercase, with 0x prefix)
|
||||
static void print_hex(uint64_t val) {
|
||||
montauk::print("0x");
|
||||
char buf[20];
|
||||
int idx = 0;
|
||||
|
||||
if (val == 0) {
|
||||
buf[idx++] = '0';
|
||||
} else {
|
||||
while (val > 0) {
|
||||
int digit = val & 0xF;
|
||||
buf[idx++] = (digit < 10) ? ('0' + digit) : ('A' + digit - 10);
|
||||
val >>= 4;
|
||||
}
|
||||
}
|
||||
|
||||
// Reverse the buffer
|
||||
for (int i = idx - 1; i >= 0; i--) {
|
||||
montauk::putchar(buf[i]);
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* main.cpp
|
||||
* Threading smoke test for MontaukOS.
|
||||
* Copyright (c) 2026 Daniel Hammer
|
||||
*
|
||||
* Spawns two worker threads that increment a shared counter under a
|
||||
* userspace mutex, joins them, and reports the result.
|
||||
*/
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <montauk/thread.h>
|
||||
|
||||
using montauk::Mutex;
|
||||
|
||||
static constexpr int ITERS_PER_THREAD = 100000;
|
||||
|
||||
struct WorkerState {
|
||||
Mutex* lock;
|
||||
int* counter;
|
||||
int delta;
|
||||
};
|
||||
|
||||
static int worker(void* raw) {
|
||||
auto* s = (WorkerState*)raw;
|
||||
for (int i = 0; i < ITERS_PER_THREAD; i++) {
|
||||
s->lock->lock();
|
||||
*(s->counter) += s->delta;
|
||||
s->lock->unlock();
|
||||
}
|
||||
return s->delta;
|
||||
}
|
||||
|
||||
static void print_int(int v) {
|
||||
char buf[16];
|
||||
int n = 0;
|
||||
if (v == 0) {
|
||||
buf[n++] = '0';
|
||||
} else {
|
||||
bool neg = v < 0;
|
||||
unsigned int u = neg ? (unsigned int)(-(long long)v) : (unsigned int)v;
|
||||
char tmp[16]; int t = 0;
|
||||
while (u) { tmp[t++] = (char)('0' + (u % 10)); u /= 10; }
|
||||
if (neg) buf[n++] = '-';
|
||||
while (t) buf[n++] = tmp[--t];
|
||||
}
|
||||
buf[n] = '\0';
|
||||
montauk::print(buf);
|
||||
}
|
||||
|
||||
extern "C" void _start() {
|
||||
Mutex lock;
|
||||
int counter = 0;
|
||||
|
||||
WorkerState a{&lock, &counter, +1};
|
||||
WorkerState b{&lock, &counter, +2};
|
||||
|
||||
int tidA = montauk::thread_spawn(worker, &a);
|
||||
int tidB = montauk::thread_spawn(worker, &b);
|
||||
if (tidA < 0 || tidB < 0) {
|
||||
montauk::print("threadtest: spawn failed\n");
|
||||
montauk::exit(1);
|
||||
}
|
||||
|
||||
montauk::print("threadtest: spawned tids ");
|
||||
print_int(tidA);
|
||||
montauk::print(" and ");
|
||||
print_int(tidB);
|
||||
montauk::print("\n");
|
||||
|
||||
int codeA = -1, codeB = -1;
|
||||
if (montauk::thread_join(tidA, &codeA) != 0) {
|
||||
montauk::print("threadtest: join A failed\n");
|
||||
montauk::exit(2);
|
||||
}
|
||||
if (montauk::thread_join(tidB, &codeB) != 0) {
|
||||
montauk::print("threadtest: join B failed\n");
|
||||
montauk::exit(3);
|
||||
}
|
||||
|
||||
int expected = ITERS_PER_THREAD * (1 + 2);
|
||||
montauk::print("threadtest: counter=");
|
||||
print_int(counter);
|
||||
montauk::print(" expected=");
|
||||
print_int(expected);
|
||||
montauk::print(" codes=");
|
||||
print_int(codeA);
|
||||
montauk::print("/");
|
||||
print_int(codeB);
|
||||
montauk::print("\n");
|
||||
|
||||
if (counter != expected) {
|
||||
montauk::print("threadtest: FAIL (counter mismatch)\n");
|
||||
montauk::exit(4);
|
||||
}
|
||||
if (codeA != 1 || codeB != 2) {
|
||||
montauk::print("threadtest: FAIL (exit codes)\n");
|
||||
montauk::exit(5);
|
||||
}
|
||||
montauk::print("threadtest: PASS\n");
|
||||
montauk::exit(0);
|
||||
}
|
||||
Reference in New Issue
Block a user