Mercurial
changeset 129:f7860f491a8c
--amend
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Thu, 08 Jan 2026 19:21:22 -0800 |
| parents | 7eb79fd91c7e |
| children | b230a743a01e |
| files | .bazelrc gara/gara mrjunejune/python_server.py mrjunejune/test/BUILD mrjunejune/test/auto_generated_test.c mrjunejune/test/create_snapshots.c mrjunejune/test/snapshots/blog.snapshot mrjunejune/test/snapshots/talk.snapshot mrjunejune/test/test.h |
| diffstat | 9 files changed, 603 insertions(+), 213 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.bazelrc Thu Jan 08 19:21:22 2026 -0800 @@ -0,0 +1,5 @@ +# Auto-select config based on host OS +common --enable_platform_specific_config + +# Suppress duplicate library warnings from openssl BCR module on macOS +build:macos --linkopt=-Wl,-no_warn_duplicate_libraries
--- a/mrjunejune/python_server.py Thu Jan 08 19:20:56 2026 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -from cffi import FFI -import os - -ffi = FFI() -ffi.cdef("void start_server(void);") - -# Bazel runs binaries from a sandbox, so use runfiles to locate the .so -import pathlib -runfiles_dir = pathlib.Path(__file__).parent -libpath = runfiles_dir / "mrjunejune_server_so.so" - -C = ffi.dlopen(str(libpath)) -C.start_server() -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mrjunejune/test/BUILD Thu Jan 08 19:21:22 2026 -0800 @@ -0,0 +1,48 @@ +load("@rules_cc//cc:cc_binary.bzl", "cc_binary") +load("@rules_cc//cc:cc_test.bzl", "cc_test") +load("//gui_ze:gui_ze.bzl", "move_files_into_dir", "bundle") + +# Files needed for test +filegroup( + name = "test_snapshots", + srcs = glob(["snapshots/**"]), +) + +filegroup( + name = "test_files", + srcs = [ + "shiba.webp", + "test_avi.avi", + ], +) + +# To create a snapsho to compare +cc_binary( + name = "create_snapshots", + srcs = ["auto_generated_test.c", "test.h"], + deps = ["//seobeo:seobeo_tcp_client"], + data = [ + "//mrjunejune:mrjunejune_server", + "//mrjunejune:src_files", + ], + args = ["$(location //mrjunejune:mrjunejune_server)"], +) + +# Tests +cc_test( + name = "integration_test", + srcs = [ + "integration_test.c", + "test.h" + ], + deps = ["//seobeo:seobeo_tcp_client"], + data = [ + "//mrjunejune:mrjunejune_server", + "//mrjunejune:src_files", + ":test_snapshots", + ":test_files", + ], + size = "large", + timeout = "long", + args = ["$(location //mrjunejune:mrjunejune_server)"], +)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mrjunejune/test/auto_generated_test.c Thu Jan 08 19:21:22 2026 -0800 @@ -0,0 +1,45 @@ +// Auto-generated test file +// Source: /Users/mrjunejune/zenbu/mrjunejune/main.c +// DO NOT EDIT - Regenerate with: bazel run //seobeo:test_generator + +#include "mrjunejune/test/test.h" + +#define TEST_HOST "127.0.0.1" +#define TEST_PORT "6969" + +int main(int argc, char *argv[]) +{ + printf("=== Auto-generated Snapshot Creator ===\n\n"); + + const char *server_binary = "./server"; + if (argc > 1) server_binary = argv[1]; + + pid_t server_pid = start_test_server(server_binary); + if (server_pid < 0) return 1; + + SnapshotConfig configs[] = { + {"/", 200, SNAPSHOT_DIR, TEST_HOST, TEST_PORT}, + {"/index.html", 301, SNAPSHOT_DIR, TEST_HOST, TEST_PORT}, + {"/resume", 200, SNAPSHOT_DIR, TEST_HOST, TEST_PORT}, + {"/resume/index.html", 301, SNAPSHOT_DIR, TEST_HOST, TEST_PORT}, + {"/tools", 200, SNAPSHOT_DIR, TEST_HOST, TEST_PORT}, + {"/tools/index.html", 301, SNAPSHOT_DIR, TEST_HOST, TEST_PORT}, + {"/tools/markdown_to_html", 200, SNAPSHOT_DIR, TEST_HOST, TEST_PORT}, + {"/tools/markdown_to_html/index.html", 301, SNAPSHOT_DIR, TEST_HOST, TEST_PORT}, + {"/tools/file_converter", 200, SNAPSHOT_DIR, TEST_HOST, TEST_PORT}, + {"/tools/file_converter/index.html", 301, SNAPSHOT_DIR, TEST_HOST, TEST_PORT}, + // TODO: POST route - POST /api/convert/image-to-webp - requires request body + // TODO: POST route - POST /api/convert/video-to-mp4 - requires request body + // TODO: Dynamic route - GET /api/download/:filename - fill in actual path + {"/blog", 200, SNAPSHOT_DIR, TEST_HOST, TEST_PORT}, + // TODO: Dynamic route - GET /blog/:blog_id - fill in actual path + {"/talk", 200, SNAPSHOT_DIR, TEST_HOST, TEST_PORT}, + {"/talk/index.html", 301, SNAPSHOT_DIR, TEST_HOST, TEST_PORT}, + }; + + int count = sizeof(configs) / sizeof(configs[0]); + int result = Seobeo_Snapshots_Create_Batch(configs, count); + + stop_test_server(server_pid); + return result; +}
--- a/mrjunejune/test/create_snapshots.c Thu Jan 08 19:20:56 2026 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,199 +0,0 @@ -#include "seobeo/seobeo.h" -#include "seobeo/snapshot_creator.h" -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/wait.h> -#include <signal.h> - -#define TEST_PORT "6969" -#define TEST_HOST "127.0.0.1" -#define SNAPSHOT_DIR "mrjunejune/test/snapshots" - -// Start the server process -static pid_t start_server(const char *server_binary) -{ - pid_t server_pid = fork(); - - if (server_pid < 0) - { - perror("fork"); - return -1; - } - - if (server_pid == 0) - { - // Child process - run server - printf("Starting server on port %s...\n", TEST_PORT); - execl(server_binary, server_binary, NULL); - perror("execl failed"); - exit(1); - } - - // Parent - verify server started - printf("Server started (PID: %d)\n", server_pid); - - usleep(100000); - int status; - pid_t result = waitpid(server_pid, &status, WNOHANG); - if (result != 0) - { - if (WIFEXITED(status)) - { - fprintf(stderr, "Server exited with code: %d\n", WEXITSTATUS(status)); - } - else if (WIFSIGNALED(status)) - { - fprintf(stderr, "Server killed by signal: %d\n", WTERMSIG(status)); - } - return -1; - } - - sleep(2); - printf("Server ready\n\n"); - - return server_pid; -} - -// Stop the server process -static void stop_server_test(pid_t server_pid) -{ - if (server_pid > 0) - { - printf("\nStopping server (PID: %d)...\n", server_pid); - kill(server_pid, SIGTERM); - waitpid(server_pid, NULL, 0); - printf("Server stopped\n"); - } -} - -int main(int argc, char *argv[]) -{ - printf("=== Seobeo Snapshot Creator ===\n\n"); - - // Get workspace directory (where the source files are) - const char *workspace_dir = getenv("BUILD_WORKSPACE_DIRECTORY"); - if (!workspace_dir) - { - fprintf(stderr, "Error: BUILD_WORKSPACE_DIRECTORY not set\n"); - fprintf(stderr, "This binary must be run with 'bazel run'\n"); - return 1; - } - - // Construct full path to snapshot directory - char snapshot_path[1024]; - snprintf(snapshot_path, sizeof(snapshot_path), "%s/%s", workspace_dir, SNAPSHOT_DIR); - - // Get server binary path - const char *server_binary = "./mrjunejune_server"; - if (argc > 1) - { - server_binary = argv[1]; - } - - printf("Workspace: %s\n", workspace_dir); - printf("Server binary: %s\n", server_binary); - printf("Snapshot directory: %s\n\n", snapshot_path); - - // Start server - pid_t server_pid = start_server(server_binary); - if (server_pid < 0) - { - fprintf(stderr, "Failed to start server\n"); - return 1; - } - - // Define snapshots to create - paths that should succeed (200 OK) - SnapshotConfig success_snapshots[] = { - {"/", 200, snapshot_path, TEST_HOST, TEST_PORT}, - {"/resume", 200, snapshot_path, TEST_HOST, TEST_PORT}, - {"/tools", 200, snapshot_path, TEST_HOST, TEST_PORT}, - {"/tools/markdown_to_html", 200, snapshot_path, TEST_HOST, TEST_PORT}, - {"/tools/file_converter", 200, snapshot_path, TEST_HOST, TEST_PORT}, - }; - int num_success = sizeof(success_snapshots) / sizeof(success_snapshots[0]); - - // Define snapshots for redirect endpoints (301) - SnapshotConfig redirect_snapshots[] = { - {"/index.html", 301, snapshot_path, TEST_HOST, TEST_PORT}, - {"/resume/index.html", 301, snapshot_path, TEST_HOST, TEST_PORT}, - {"/tools/index.html", 301, snapshot_path, TEST_HOST, TEST_PORT}, - {"/tools/markdown_to_html/index.html", 301, snapshot_path, TEST_HOST, TEST_PORT}, - {"/tools/file_converter/index.html", 301, snapshot_path, TEST_HOST, TEST_PORT}, - }; - int num_redirects = sizeof(redirect_snapshots) / sizeof(redirect_snapshots[0]); - - SnapshotConfig error_snapshots[] = { - {"/nonexistent", 404, snapshot_path, TEST_HOST, TEST_PORT}, - {"/does/not/exist", 404, snapshot_path, TEST_HOST, TEST_PORT}, - {"/missing.html", 404, snapshot_path, TEST_HOST, TEST_PORT}, - }; - int num_errors = sizeof(error_snapshots) / sizeof(error_snapshots[0]); - - int total_failed = 0; - int total_passed = 0; - - // Create success snapshots - printf("Creating snapshots for successful paths:\n\n"); - for (int i = 0; i < num_success; i++) - { - if (Seobeo_Snapshot_Create(&success_snapshots[i]) == 0) - { - total_passed++; - } - else - { - total_failed++; - } - } - - // Create redirect snapshots - printf("\nCreating snapshots for redirect paths:\n\n"); - for (int i = 0; i < num_redirects; i++) - { - if (Seobeo_Snapshot_Create(&redirect_snapshots[i]) == 0) - { - total_passed++; - } - else - { - total_failed++; - } - } - - // Create error snapshots - printf("\nCreating snapshots for error paths:\n\n"); - for (int i = 0; i < num_errors; i++) - { - if (Seobeo_Snapshot_Create(&error_snapshots[i]) == 0) - { - total_passed++; - } - else - { - total_failed++; - } - } - - // Stop server - stop_server_test(server_pid); - - // Print summary - printf("\n=== Summary ===\n"); - printf("Snapshots created: %d\n", total_passed); - printf("Failed: %d\n", total_failed); - - if (total_failed == 0) - { - printf("\n✓ All snapshots created successfully!\n"); - printf("\nSnapshots saved to: %s/\n", snapshot_path); - printf("\nRun tests to verify:\n"); - printf(" bazel test //mrjunejune:integration_test\n"); - return 0; - } - else - { - printf("\n✗ Some snapshots failed\n"); - return 1; - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mrjunejune/test/snapshots/blog.snapshot Thu Jan 08 19:21:22 2026 -0800 @@ -0,0 +1,208 @@ +<!doctype html> +<html lang="en"> + <head> + <meta charset="UTF-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<link rel="icon" type="image/svg+xml" href="/public/epi_all_colors.svg"> + +<link rel="preload" href="/public/fonts/Roboto-Regular.ttf" as="font" crossorigin> +<link rel="preload" href="/public/fonts/Roboto-Thin.ttf"as="font" crossorigin> + +<!-- <link rel="preload" href="/public/fonts/atkinson-regular.woff" as="font" type="font/woff" crossorigin> --> +<!-- <link rel="preload" href="/public/fonts/atkinson-bold.woff" as="font" type="font/woff" crossorigin> --> + +<!-- <link rel="preload" href="/public/fonts/more-sugar.extras.otf" as="font" type="font/otf" crossorigin> --> +<link rel="preload" href="/public/fonts/more-sugar.regular.otf" as="font" type="font/otf" crossorigin> +<link rel="preload" href="/public/fonts/more-sugar.thin.otf" as="font" type="font/otf" crossorigin> + +<link rel="preload" href="/base.css" as="style" /> +<link rel="stylesheet" href="/base.css" /> + + + </head> + <body> + <style> + :root { + --header-background: var(--white); + --header-color: rgb(var(--black)); + --link-hover-accent: var(--awesome); + } + + /* Fixed icon in top left corner */ + #themeToggle { + position: fixed; + top: 20px; + left: 20px; + background: var(--header-background); + display: flex; + align-items: center; + border-radius: 50%; + cursor: pointer; + z-index: 1000; + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); + transition: transform 0.2s ease; + } + + #themeToggle:hover { + transform: scale(1.05); + } + + /* Professional header */ + header { + margin: auto; + padding: 1.5em 1em; + font-family: "More", sans-serif; + box-shadow: 0 2px 8px rgba(var(--black), 5%); + width: 720px; + max-width: calc(100% - 2em); + text-align: center; + } + + header h1 { + margin: 0; + font-size: 1.8em; + font-weight: 700; + letter-spacing: -0.5px; + } + + header h1 a { + text-decoration: none; + color: var(--header-color); + } + + header h1 a::before { + display: none; + } + + /* Mobile responsiveness */ + @media (max-width: 720px) { + #themeToggle { + top: 15px; + left: 15px; + } + + header { + padding: 1em; + } + + header h1 { + font-size: 1.5em; + } + } + + @media (max-width: 480px) { + #themeToggle { + top: 10px; + left: 10px; + } + + #themeToggle img { + height: 40px; + width: 40px; + } + + header h1 { + font-size: 1.3em; + } + } + + #logo { + width: 300px; + } + + /* 1. DEFINE THE DEFAULTS (Light Mode) */ + :root { + --logo-invert: invert(0); + --epi-grayscale: grayscale(0) brightness(1); + } + + /* 2. MANUAL DARK OVERRIDE */ + html.dark { + --logo-invert: invert(1); + --epi-grayscale: grayscale(1); + } + + /* 3. MANUAL LIGHT OVERRIDE */ + html.light-mode { + --logo-invert: invert(0); + --epi-grayscale: brightness(2.9) grayscale(1); + } + + /* 4. SYSTEM PREFERENCE */ + @media (prefers-color-scheme: dark) { + :root:not(.light-mode) { + --logo-invert: invert(1); + } + } + + /* 5. APPLY TO ELEMENTS */ + #logo { + -webkit-filter: var(--logo-invert); + filter: var(--logo-invert); + transition: filter 0.3s ease; + } + + .epi-logo { + -webkit-filter: var(--epi-grayscale); + filter: var(--epi-grayscale); + transition: filter 0.3s ease; + } +</style> + +<div id="themeToggle"> + <img id="epiChan" class="epi-logo" aria-label="Toggle dark mode" src="/public/epi_all_colors.svg" height="50" width="50"> +</div> + +<header> + <h1><a href="/">MrJuneJune</a></h1> +</header> +<script src="/index.js"></script> + + + <main> + <h1 class="title" style="margin-bottom: 20px;"> Blogs </h1> + <ul style="list-style: none;"> + <li style="margin-bottom: 20px;"> + <span> January 08 2026 </span> + <p><h4><a href="/blog/websocket-demystified">Websocket Demystified</a></h4></p> + </li> + <li style="margin-bottom: 20px;"> + <span> January 02 2026 </span> + <p><h4><a href="/blog/my-seobeo-journey">Creating Network Library in C</a></h4></p> + </li> + <li style="margin-bottom: 20px;"> + <span> Apr 12 2025 </span> + <p><h4><a href="/blog/wsl2-ssh">WSL2 Cloudtop Setup</a></h4></p> + </li> + <li style="margin-bottom: 20px;"> + <span> Dec 10 2024 </span> + <p><h4><a href="/blog/multithread-in-js">MultiThreading in JS</a></h4></p> + </li> + <li style="margin-bottom: 20px;"> + <span> Nov 23 2024 </span> + <p><h4><a href="/blog/thoughts-on-tdd">My thoughts on TDD</a></h4></p> + </li> + <li style="margin-bottom: 20px;"> + <span> Nov 21 2024 </span> + <p><h4><a href="/blog/optimizing-grass-rendering">Optimizing Random Placement with Colour Noise</a></h4></p> + </li> + <li style="margin-bottom: 20px;"> + <span> Nov 17 2024 </span> + <p><h4><a href="/blog/thoughts-on-ide">My thoughts on IDE</a></h4></p> + </li> + <li style="margin-bottom: 20px;"> + <span> Nov 16 2024 </span> + <p><h4><a href="/blog/optimizing-data-structures">Optimizing Data Structure for Performance</a></h4></p> + </li> + <li style="margin-bottom: 20px;"> + <span> Nov 13 2024 </span> + <p><h4><a href="/blog/wasm-bunny">WASM using c3</a></h4></p> + </li> + </ul> + </main> + <div style="display: flex; align-items: center; justify-content: center; margin: 30px 0px;"> + <small>© 2026 June Park</small> +</div> + + </body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mrjunejune/test/snapshots/talk.snapshot Thu Jan 08 19:21:22 2026 -0800 @@ -0,0 +1,223 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <title>Talk!</title> + <meta charset="UTF-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<link rel="icon" type="image/svg+xml" href="/public/epi_all_colors.svg"> + +<link rel="preload" href="/public/fonts/Roboto-Regular.ttf" as="font" crossorigin> +<link rel="preload" href="/public/fonts/Roboto-Thin.ttf"as="font" crossorigin> + +<!-- <link rel="preload" href="/public/fonts/atkinson-regular.woff" as="font" type="font/woff" crossorigin> --> +<!-- <link rel="preload" href="/public/fonts/atkinson-bold.woff" as="font" type="font/woff" crossorigin> --> + +<!-- <link rel="preload" href="/public/fonts/more-sugar.extras.otf" as="font" type="font/otf" crossorigin> --> +<link rel="preload" href="/public/fonts/more-sugar.regular.otf" as="font" type="font/otf" crossorigin> +<link rel="preload" href="/public/fonts/more-sugar.thin.otf" as="font" type="font/otf" crossorigin> + +<link rel="preload" href="/base.css" as="style" /> +<link rel="stylesheet" href="/base.css" /> + + + <style> + body { font-family: sans-serif; padding: 20px; } + #messages { height: 200px; border: 1px solid #ccc; overflow-y: scroll; margin-bottom: 10px; padding: 10px; } + #chat { display: flex; gap: 10px; } + input { flex-grow: 1; } + </style> +</head> +<body> + <style> + :root { + --header-background: var(--white); + --header-color: rgb(var(--black)); + --link-hover-accent: var(--awesome); + } + + /* Fixed icon in top left corner */ + #themeToggle { + position: fixed; + top: 20px; + left: 20px; + background: var(--header-background); + display: flex; + align-items: center; + border-radius: 50%; + cursor: pointer; + z-index: 1000; + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); + transition: transform 0.2s ease; + } + + #themeToggle:hover { + transform: scale(1.05); + } + + /* Professional header */ + header { + margin: auto; + padding: 1.5em 1em; + font-family: "More", sans-serif; + box-shadow: 0 2px 8px rgba(var(--black), 5%); + width: 720px; + max-width: calc(100% - 2em); + text-align: center; + } + + header h1 { + margin: 0; + font-size: 1.8em; + font-weight: 700; + letter-spacing: -0.5px; + } + + header h1 a { + text-decoration: none; + color: var(--header-color); + } + + header h1 a::before { + display: none; + } + + /* Mobile responsiveness */ + @media (max-width: 720px) { + #themeToggle { + top: 15px; + left: 15px; + } + + header { + padding: 1em; + } + + header h1 { + font-size: 1.5em; + } + } + + @media (max-width: 480px) { + #themeToggle { + top: 10px; + left: 10px; + } + + #themeToggle img { + height: 40px; + width: 40px; + } + + header h1 { + font-size: 1.3em; + } + } + + #logo { + width: 300px; + } + + /* 1. DEFINE THE DEFAULTS (Light Mode) */ + :root { + --logo-invert: invert(0); + --epi-grayscale: grayscale(0) brightness(1); + } + + /* 2. MANUAL DARK OVERRIDE */ + html.dark { + --logo-invert: invert(1); + --epi-grayscale: grayscale(1); + } + + /* 3. MANUAL LIGHT OVERRIDE */ + html.light-mode { + --logo-invert: invert(0); + --epi-grayscale: brightness(2.9) grayscale(1); + } + + /* 4. SYSTEM PREFERENCE */ + @media (prefers-color-scheme: dark) { + :root:not(.light-mode) { + --logo-invert: invert(1); + } + } + + /* 5. APPLY TO ELEMENTS */ + #logo { + -webkit-filter: var(--logo-invert); + filter: var(--logo-invert); + transition: filter 0.3s ease; + } + + .epi-logo { + -webkit-filter: var(--epi-grayscale); + filter: var(--epi-grayscale); + transition: filter 0.3s ease; + } +</style> + +<div id="themeToggle"> + <img id="epiChan" class="epi-logo" aria-label="Toggle dark mode" src="/public/epi_all_colors.svg" height="50" width="50"> +</div> + +<header> + <h1><a href="/">MrJuneJune</a></h1> +</header> +<script src="/index.js"></script> + + + <h1>Talks</h1> + + <div id="messages"></div> + + <div id="chat"> + <input type="text" id="messageInput" placeholder="Type a message..."> + <button id="sendBtn">Send</button> + </div> + <div style="display: flex; align-items: center; justify-content: center; margin: 30px 0px;"> + <small>© 2026 June Park</small> +</div> + + <script> + const ws = new WebSocket('ws://localhost:6969/echo'); + const messagesDiv = document.getElementById('messages'); + + ws.onopen = () => { + console.log('Connected!'); + appendMessage('System: Connected to server'); + }; + + ws.onmessage = (event) => { + console.log('Received:', event.data); + appendMessage('Server: ' + event.data); + }; + + // Function to send message + sendBtn.onclick = () => { + const message = messageInput.value; + if (message) { + ws.send(message); + appendMessage('You: ' + message); + messageInput.value = ''; // Clear input + } + }; + + // Helper to show messages on screen + function appendMessage(text) { + const msg = document.createElement('p'); + msg.textContent = text; + messagesDiv.appendChild(msg); + messagesDiv.scrollTop = messagesDiv.scrollHeight; + } + + messageInput.addEventListener('keydown', (event) => { + if (event.key === 'Enter' && !event.shiftKey) + { + event.preventDefault(); + sendBtn.click(); + } + }); + </script> +</body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mrjunejune/test/test.h Thu Jan 08 19:21:22 2026 -0800 @@ -0,0 +1,74 @@ +#include "seobeo/seobeo.h" +#include "seobeo/snapshot_creator.h" +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/wait.h> +#include <signal.h> + +#define TEST_PORT "6969" +#define TEST_HOST "127.0.0.1" +#define TEST_URL "http://127.0.0.1:6969" +#define MAX_RESPONSE_SIZE (1024 * 1024) +#ifndef SNAPSHOT_DIR + #define SNAPSHOT_DIR "mrjunejune/test/snapshots" +#endif + +pid_t start_test_server(const char *server_binary); +void stop_test_server(pid_t server_pid); + + +pid_t start_test_server(const char *server_binary) +{ + pid_t server_pid = fork(); + + if (server_pid < 0) + { + perror("fork"); + return -1; + } + + if (server_pid == 0) + { + printf("Starting server on port %s...\n", TEST_PORT); + execl(server_binary, server_binary, NULL); + perror("execl failed"); + exit(1); + } + + printf("Server started (PID: %d)\n", server_pid); + + usleep(100000); + int status; + pid_t result = waitpid(server_pid, &status, WNOHANG); + if (result != 0) + { + if (WIFEXITED(status)) + { + fprintf(stderr, "Server exited immediately with code: %d\n", WEXITSTATUS(status)); + } + else if (WIFSIGNALED(status)) + { + fprintf(stderr, "Server was killed by signal: %d\n", WTERMSIG(status)); + } + return -1; + } + + sleep(2); + printf("Server ready\n\n"); + + return server_pid; +} + +void stop_test_server(pid_t server_pid) +{ + if (server_pid > 0) + { + printf("\nStopping server (PID: %d)...\n", server_pid); + kill(server_pid, SIGTERM); + waitpid(server_pid, NULL, 0); + printf("Server stopped\n"); + } +} + +