feat: ports - zlib, libwapcaplet, libparserutils

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018Ae69wJS7sueQMUwNxV3nX
This commit is contained in:
2026-08-07 20:11:55 +02:00
co-authored by Claude Opus 5
parent 48e97f4e09
commit acb169e2c4
13 changed files with 358 additions and 4 deletions
+49
View File
@@ -0,0 +1,49 @@
# Smoke test for the ports sysroot.
#
# Links one program against every library port and exercises a little of each,
# printing PASS/FAIL per library. Building it proves the sysroot's headers and
# archives resolve; RUNNING it on MontaukOS is the only way to prove the code
# is correct, since none of this can execute on the build host.
#
# make -C test build out/test/porttest.elf
# make -C test install copy it into the MontaukOS ramdisk as a system
# program, then rebuild the image and run
# `porttest.elf` from the terminal
# make -C test uninstall remove it again (do this before cutting a
# release -- it is not an app bundle, so it
# carries no .port marker and the release step
# will NOT prune it automatically)
PORT_NAME := porttest
include ../mk/port.mk
SYSROOT_LIBS := \
$(PORT_SYSROOT_LIB)/libparserutils.a \
$(PORT_SYSROOT_LIB)/libwapcaplet.a \
$(PORT_SYSROOT_LIB)/libz.a
TEST_ELF := $(OUTDIR)/test/porttest.elf
CFLAGS := -std=gnu11 $(PORT_CFLAGS_COMMON) -Wall
.PHONY: all clean install uninstall
all: $(TEST_ELF)
$(TEST_ELF): porttest.c $(SYSROOT_LIBS) $(LIBC_A) Makefile
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(PORT_LDFLAGS_COMMON) porttest.c \
$(SDK_LIB)/libc/crt1.o $(SYSROOT_LIBS) $(LIBC_A) -o $@
@echo "Built: $@"
install: $(TEST_ELF)
cp $(TEST_ELF) $(MONTAUKOS)/programs/bin/os/porttest.elf
@echo "installed: 0:/os/porttest.elf - rebuild the image, then run 'porttest.elf'"
@echo "REMINDER: 'make -C test uninstall' before cutting a release ISO."
uninstall:
rm -f $(MONTAUKOS)/programs/bin/os/porttest.elf
@echo "removed: $(MONTAUKOS)/programs/bin/os/porttest.elf"
clean:
rm -rf $(OUTDIR)/test
+61
View File
@@ -0,0 +1,61 @@
#include <libwapcaplet/libwapcaplet.h>
#include <parserutils/parserutils.h>
#include <parserutils/charset/utf8.h>
#include <parserutils/utils/buffer.h>
#include <zlib.h>
#include <stdio.h>
#include <string.h>
int main(void) {
lwc_string *a = NULL, *b = NULL;
bool same = false;
parserutils_buffer *buf = NULL;
size_t len = 0;
unsigned char comp[128];
uLongf clen = sizeof(comp);
int gzok = 0;
const char *s = "MontaukOS";
/* libwapcaplet: interning must make equal strings identical */
lwc_intern_string("netsurf", 7, &a);
lwc_intern_string("netsurf", 7, &b);
/* assign the result: the macro ends in a comma expression, so discarding
it warns under -Wall */
lwc_error lwcerr = lwc_string_isequal(a, b, &same);
(void) lwcerr;
/* libparserutils: buffer + utf8 length */
parserutils_buffer_create(&buf);
parserutils_buffer_append(buf, (const uint8_t *)s, strlen(s));
parserutils_charset_utf8_length((const uint8_t *)s, strlen(s), &len);
/* zlib: gzip-wrapper inflate is the path NetSurf uses for
Content-Encoding: gzip, so exercise that rather than plain compress() */
{
z_stream z; unsigned char back[128]; int r;
memset(&z, 0, sizeof(z));
deflateInit2(&z, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15+16, 8,
Z_DEFAULT_STRATEGY);
z.next_in = (Bytef *)s; z.avail_in = strlen(s);
z.next_out = comp; z.avail_out = sizeof(comp);
deflate(&z, Z_FINISH); clen = z.total_out; deflateEnd(&z);
memset(&z, 0, sizeof(z));
inflateInit2(&z, 15+16);
z.next_in = comp; z.avail_in = clen;
z.next_out = back; z.avail_out = sizeof(back);
r = inflate(&z, Z_FINISH); inflateEnd(&z);
gzok = (r == Z_STREAM_END && z.total_out == strlen(s) &&
memcmp(back, s, strlen(s)) == 0);
}
printf("libwapcaplet: intern-equal=%s length=%zu\n",
same ? "PASS" : "FAIL", (size_t)lwc_string_length(a));
printf("libparserutils: buffer=%zu utf8len=%zu %s\n",
buf->length, len,
(buf->length == strlen(s) && len == strlen(s)) ? "PASS" : "FAIL");
printf("zlib %s: gzip roundtrip %lu->%lu %s\n",
zlibVersion(), (unsigned long)strlen(s), (unsigned long)clen,
gzok ? "PASS" : "FAIL");
lwc_string_unref(a); lwc_string_unref(b);
parserutils_buffer_destroy(buf);
return 0;
}