cleanup: remove test programs/libraries

This commit is contained in:
2026-07-08 10:06:07 +02:00
parent a39bc77ea5
commit 75ef340359
17 changed files with 6 additions and 835 deletions
+5 -22
View File
@@ -59,7 +59,7 @@ BINDIR := bin
PROGRAMS := $(notdir $(wildcard src/*))
# Programs with custom Makefiles (built separately).
CUSTOM_BUILDS := 2048 doom fetch wiki wikipedia weather imageviewer fontpreview spreadsheet wordprocessor pdfviewer disks devexplorer installer audio music video bluetooth network terminal klog procmgr powermgr calculator charmap desktop login shell rpgdemo paint tcc lua screenshot texteditor mandelbrot printers timezone printd printctl dialogs test_dialogs test_dl libloader libhello crashpad
CUSTOM_BUILDS := 2048 doom fetch wiki wikipedia weather imageviewer fontpreview spreadsheet wordprocessor pdfviewer disks devexplorer installer audio music video bluetooth network terminal klog procmgr powermgr calculator charmap desktop login shell rpgdemo paint tcc lua screenshot texteditor mandelbrot printers timezone printd printctl dialogs libloader crashpad
SYSTEM_PROGRAMS := $(filter-out $(CUSTOM_BUILDS),$(PROGRAMS))
# Build targets: system programs go to bin/os/, apps go to bin/apps/<name>/.
@@ -89,9 +89,9 @@ CONFIGDIR := data/config
CONFIGSRC := $(wildcard $(CONFIGDIR)/*.toml)
CONFIGDST := $(patsubst $(CONFIGDIR)/%,$(BINDIR)/config/%,$(CONFIGSRC))
.PHONY: all clean 2048 doom fetch wiki wikipedia weather imageviewer fontpreview spreadsheet wordprocessor pdfviewer disks devexplorer installer audio music video bluetooth network terminal klog procmgr powermgr calculator charmap login desktop shell rpgdemo paint tcc lua screenshot texteditor mandelbrot printers timezone printd printctl dialogs icons fonts configs bearssl libc tls libjpeg libjpegwrite install-apps libloader libs libhello test_dialogs test_dl crashpad check-syscalls gen-syscalls
.PHONY: all clean 2048 doom fetch wiki wikipedia weather imageviewer fontpreview spreadsheet wordprocessor pdfviewer disks devexplorer installer audio music video bluetooth network terminal klog procmgr powermgr calculator charmap login desktop shell rpgdemo paint tcc lua screenshot texteditor mandelbrot printers timezone printd printctl dialogs icons fonts configs bearssl libc tls libjpeg libjpegwrite install-apps libloader libs crashpad check-syscalls gen-syscalls
all: bearssl libc libjpeg libjpegwrite tls libloader libs libhello $(TARGETS) fetch wiki wikipedia weather imageviewer fontpreview spreadsheet wordprocessor pdfviewer disks devexplorer installer audio music video bluetooth network terminal klog procmgr powermgr calculator charmap 2048 doom rpgdemo paint tcc lua screenshot texteditor mandelbrot printers timezone printd printctl dialogs login desktop shell icons fonts install-apps test_dialogs test_dl crashpad $(MANDST) $(WWWDST) $(CA_CERTS) $(CONFIGDST) $(FWDST)
all: bearssl libc libjpeg libjpegwrite tls libloader libs $(TARGETS) fetch wiki wikipedia weather imageviewer fontpreview spreadsheet wordprocessor pdfviewer disks devexplorer installer audio music video bluetooth network terminal klog procmgr powermgr calculator charmap 2048 doom rpgdemo paint tcc lua screenshot texteditor mandelbrot printers timezone printd printctl dialogs login desktop shell icons fonts install-apps crashpad $(MANDST) $(WWWDST) $(CA_CERTS) $(CONFIGDST) $(FWDST)
# Build BearSSL static library (cross-compiled for freestanding x86_64).
BEARSSL_INCLUDES := -isystem $(shell cd .. && pwd)/kernel/freestnd-c-hdrs/x86_64/include -isystem $(abspath include/libc)
@@ -112,21 +112,16 @@ libc:
tls: bearssl libc
$(MAKE) -C lib/tls
# Build libloader static library (used by test_dl).
# Build libloader static library (used by the applet shared libs).
libloader: libc
$(MAKE) -C src/libloader
# Build shared libraries (libmath.lib etc).
# Build shared libraries (applet .lib files).
libs: libloader
$(MAKE) -C libs/libmath
$(MAKE) -C libs/libnetworkapplet
$(MAKE) -C libs/libprintersapplet
$(MAKE) -C libs/libtimezonesapplet
# Build libhello shared GUI library.
libhello: libloader
$(MAKE) -C libs/libhello
# Build fetch via its own Makefile (depends on bearssl, libc, and tls).
fetch: bearssl libc tls
$(MAKE) -C src/fetch
@@ -326,14 +321,6 @@ dialogs:
crashpad: libc
$(MAKE) -C src/crashpad
# Build test_dl (dynamic loading test app, depends on libloader and shared libs).
test_dl: libloader libs libhello
$(MAKE) -C src/test_dl
# Build test_dialogs (minimal libdialogs message box test).
test_dialogs: libc libloader dialogs
$(MAKE) -C src/test_dialogs
# Install app bundles (manifests, icons, data files) into bin/apps/<name>/.
install-apps: 2048 doom rpgdemo paint spreadsheet wordprocessor weather wikipedia imageviewer fontpreview pdfviewer disks devexplorer installer audio music video bluetooth network terminal klog procmgr powermgr calculator charmap screenshot texteditor mandelbrot printers timezone crashpad
../scripts/install_apps.sh
@@ -415,10 +402,6 @@ clean:
$(MAKE) -C src/dialogs clean
$(MAKE) -C src/crashpad clean
$(MAKE) -C src/libloader clean
$(MAKE) -C libs/libmath clean
$(MAKE) -C libs/libhello clean
$(MAKE) -C libs/libnetworkapplet clean
$(MAKE) -C libs/libprintersapplet clean
$(MAKE) -C libs/libtimezonesapplet clean
$(MAKE) -C src/test_dialogs clean
$(MAKE) -C src/test_dl clean
-74
View File
@@ -1,74 +0,0 @@
# Makefile for libhello shared library
# Builds libhello.lib as an ELF shared object (ET_DYN).
# Target architecture.
ARCH := x86_64
# Toolchain
TOOLCHAIN_PREFIX := $(shell cd ../../.. && pwd)/toolchain/local/bin/x86_64-elf-
CXX := $(TOOLCHAIN_PREFIX)g++
LD := $(TOOLCHAIN_PREFIX)ld
NM := $(TOOLCHAIN_PREFIX)nm
STRIP := $(TOOLCHAIN_PREFIX)strip
# Compiler flags: freestanding, no stdlib
# Build as PIC so the final ET_DYN image can be relocated by the kernel loader.
override CXXFLAGS := \
-std=gnu++20 \
-g -O2 -pipe \
-Wall \
-Wextra \
-nostdinc \
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-fPIC \
-fno-rtti \
-fno-exceptions \
-ffunction-sections \
-fdata-sections \
-m64 \
-march=x86-64 \
-mno-80387 \
-mno-mmx \
-mno-red-zone \
-mcmodel=small \
-I ../../include \
-isystem ../../include/libc \
-isystem ../../include/montauk \
-isystem ../../include/gui \
-isystem ../../../kernel/freestnd-c-hdrs/x86_64/include \
-isystem ../../../kernel/freestnd-cxx-hdrs/x86_64/include
# Linker flags for a bare-metal ELF shared object.
override LDFLAGS := \
-shared \
--build-id=none \
--hash-style=sysv \
-m elf_x86_64 \
-z max-page-size=0x1000
# Output
OUTDIR := ../../bin/os
LIBNAME := libhello
LIBSRC := src/libhello.cpp
.PHONY: all clean
all: $(OUTDIR)/$(LIBNAME).lib
$(OUTDIR):
mkdir -p $@
src/libhello.o: src/libhello.cpp Makefile | $(OUTDIR)
$(CXX) $(CXXFLAGS) -c src/libhello.cpp -o $@
src/stb_truetype_impl.o: src/stb_truetype_impl.cpp Makefile | $(OUTDIR)
$(CXX) $(CXXFLAGS) -c src/stb_truetype_impl.cpp -o $@
$(OUTDIR)/$(LIBNAME).lib: src/libhello.o src/stb_truetype_impl.o
rm -f $(OUTDIR)/$(LIBNAME).lib.sym
$(LD) $(LDFLAGS) src/libhello.o src/stb_truetype_impl.o -o $@
clean:
rm -rf ../../bin/os/$(LIBNAME).lib ../../bin/os/$(LIBNAME).lib.sym src/libhello.o src/stb_truetype_impl.o
-13
View File
@@ -1,13 +0,0 @@
SECTIONS
{
. = 0x400000;
.text : {
*(.text)
}
.eh_frame : {
*(.eh_frame)
}
.rodata : {
*(.rodata)
}
}
-118
View File
@@ -1,118 +0,0 @@
/*
* libhello.cpp
* Sample shared GUI library for MontaukOS
* Creates a window and renders text as a demo of the shared library + GUI system
* Copyright (c) 2026 Daniel Hammer
*/
#include <montauk/syscall.h>
#include <gui/truetype.hpp>
// Heap allocation test - allocates, writes, reads, frees
// Returns 0 on success, -1 on failure
extern "C" int hello_malloc_test() {
// Test 1: Allocate 256 bytes
void* buf = montauk::malloc(256);
if (!buf) {
montauk::print(" [libhello] malloc(256) failed\n");
return -1;
}
// Test 2: Write a pattern and verify it
uint8_t* bytes = (uint8_t*)buf;
for (int i = 0; i < 256; i++) {
bytes[i] = (uint8_t)(i & 0xFF);
}
for (int i = 0; i < 256; i++) {
if (bytes[i] != (uint8_t)(i & 0xFF)) {
montauk::print(" [libhello] read verification failed\n");
montauk::mfree(buf);
return -1;
}
}
montauk::mfree(buf);
return 0;
}
extern "C" int hello_run() {
// Create window
static constexpr int kInitialWidth = 320;
static constexpr int kInitialHeight = 200;
static constexpr uint32_t kBackgroundColor = 0xFFFFFFFF;
montauk::abi::WinCreateResult wres;
if (montauk::win_create("libhello Demo", kInitialWidth, kInitialHeight, &wres) < 0 || wres.id < 0) {
return -1;
}
int winId = wres.id;
uint32_t* pixels = (uint32_t*)(uintptr_t)wres.pixelVa;
int width = kInitialWidth;
int height = kInitialHeight;
gui::TrueTypeFont* font = (gui::TrueTypeFont*)montauk::malloc(sizeof(gui::TrueTypeFont));
if (!font) {
montauk::win_destroy(winId);
return -1;
}
montauk::memset(font, 0, sizeof(gui::TrueTypeFont));
if (!font->init("0:/fonts/Roboto-Medium.ttf")) {
montauk::mfree(font);
montauk::win_destroy(winId);
return -1;
}
// Simple render - fill with a color pattern
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
pixels[y * width + x] = kBackgroundColor;
}
}
// Render text using TrueType
gui::Color text_color;
text_color.r = 0x11;
text_color.g = 0x11;
text_color.b = 0x11;
text_color.a = 255;
font->draw_to_buffer(pixels, width, height, 20, 20, "Hello from libhello!", text_color, 16);
// Present the initial frame
montauk::win_present(winId);
// Event loop
while (true) {
montauk::abi::WinEvent ev;
int r = montauk::win_poll(winId, &ev);
if (r < 0) {
break;
}
if (r == 0) {
montauk::sleep_ms(16);
continue;
}
if (ev.type == 3) { // close
break;
}
if (ev.type == 2) { // resize
width = ev.resize.w;
height = ev.resize.h;
pixels = (uint32_t*)(uintptr_t)montauk::win_resize(winId, width, height);
// Re-render on resize
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
pixels[y * width + x] = kBackgroundColor;
}
}
font->draw_to_buffer(pixels, width, height, 20, 20, "Hello from libhello!", text_color, 16);
montauk::win_present(winId);
}
}
montauk::win_destroy(winId);
montauk::mfree(font);
return 0;
}
Binary file not shown.
@@ -1,33 +0,0 @@
/*
* stb_truetype_impl.cpp
* Single compilation unit for stb_truetype in libhello
* Copyright (c) 2026 Daniel Hammer
*/
#include <cstdint>
#include <cstddef>
#include <montauk/heap.h>
#include <montauk/string.h>
#include <gui/stb_math.h>
#define STBTT_ifloor(x) ((int) stb_floor(x))
#define STBTT_iceil(x) ((int) stb_ceil(x))
#define STBTT_sqrt(x) stb_sqrt(x)
#define STBTT_pow(x,y) stb_pow(x,y)
#define STBTT_fmod(x,y) stb_fmod(x,y)
#define STBTT_cos(x) stb_cos(x)
#define STBTT_acos(x) stb_acos(x)
#define STBTT_fabs(x) stb_fabs(x)
#define STBTT_malloc(x,u) ((void)(u), montauk::malloc(x))
#define STBTT_free(x,u) ((void)(u), montauk::mfree(x))
#define STBTT_memcpy(d,s,n) montauk::memcpy(d,s,n)
#define STBTT_memset(d,v,n) montauk::memset(d,v,n)
#define STBTT_strlen(x) montauk::slen(x)
#define STBTT_assert(x) ((void)(x))
#define STB_TRUETYPE_IMPLEMENTATION
#include <gui/stb_truetype.h>
Binary file not shown.
-66
View File
@@ -1,66 +0,0 @@
# Makefile for libmath shared library
# Builds libmath.lib as an ELF shared object (ET_DYN).
# Target architecture.
ARCH := x86_64
# Toolchain
TOOLCHAIN_PREFIX := $(shell cd ../../.. && pwd)/toolchain/local/bin/x86_64-elf-
CXX := $(TOOLCHAIN_PREFIX)g++
LD := $(TOOLCHAIN_PREFIX)ld
NM := $(TOOLCHAIN_PREFIX)nm
STRIP := $(TOOLCHAIN_PREFIX)strip
# Compiler flags: freestanding, no stdlib
# Build as PIC so the final ET_DYN image can be relocated by the kernel loader.
override CXXFLAGS := \
-std=gnu++20 \
-g -O2 -pipe \
-Wall \
-Wextra \
-nostdinc \
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-fPIC \
-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
# Linker flags for a bare-metal ELF shared object.
override LDFLAGS := \
-shared \
--build-id=none \
--hash-style=sysv \
-m elf_x86_64 \
-z max-page-size=0x1000
# Output
OUTDIR := ../../bin/os
LIBNAME := libmath
LIBSRC := src/libmath.cpp
.PHONY: all clean
all: $(OUTDIR)/$(LIBNAME).lib
$(OUTDIR)/$(LIBNAME).lib: $(LIBSRC) Makefile
@mkdir -p $(OUTDIR)
rm -f $(OUTDIR)/$(LIBNAME).lib.sym
$(CXX) $(CXXFLAGS) -c $(LIBSRC) -o src/libmath.o
$(LD) $(LDFLAGS) src/libmath.o -o $@
clean:
rm -rf ../../bin/os/$(LIBNAME).lib ../../bin/os/$(LIBNAME).lib.sym src/libmath.o
-10
View File
@@ -1,10 +0,0 @@
SECTIONS
{
. = 0x400000;
.text : {
*(.text)
}
.eh_frame : {
*(.eh_frame)
}
}
-55
View File
@@ -1,55 +0,0 @@
/*
* libmath.cpp
* Sample shared math library for MontaukOS
* Copyright (c) 2026 Daniel Hammer
*/
extern "C" {
// Basic math functions
int math_add(int a, int b) {
return a + b;
}
int math_sub(int a, int b) {
return a - b;
}
int math_mul(int a, int b) {
return a * b;
}
int math_div(int a, int b) {
if (b == 0) return 0;
return a / b;
}
int math_mod(int a, int b) {
if (b == 0) return 0;
return a % b;
}
// Comparison
int math_max(int a, int b) {
return (a > b) ? a : b;
}
int math_min(int a, int b) {
return (a < b) ? a : b;
}
int math_abs(int a) {
return (a < 0) ? -a : a;
}
// Utility
int math_pow(int base, int exp) {
int result = 1;
for (int i = 0; i < exp; i++) {
result *= base;
}
return result;
}
} // extern "C"
Binary file not shown.
-76
View File
@@ -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)
-20
View File
@@ -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);
}
-59
View File
@@ -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
-187
View File
@@ -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]);
}
}
-101
View File
@@ -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);
}