Mercurial
annotate mrjunejune/test/test.h @ 202:b9b184b3303c
[Notes] Images get processed and it is properly fetched. Thank you.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Sun, 15 Feb 2026 09:12:57 -0800 |
| parents | f3084bca7317 |
| children |
| rev | line source |
|---|---|
| 129 | 1 #include "seobeo/seobeo.h" |
| 2 #include "seobeo/snapshot_creator.h" | |
| 3 #include <stdio.h> | |
| 4 #include <stdlib.h> | |
| 5 #include <unistd.h> | |
| 6 #include <sys/wait.h> | |
| 7 #include <signal.h> | |
| 8 | |
| 9 #define TEST_PORT "6969" | |
| 10 #define TEST_HOST "127.0.0.1" | |
| 11 #define TEST_URL "http://127.0.0.1:6969" | |
| 12 #define MAX_RESPONSE_SIZE (1024 * 1024) | |
| 13 #ifndef SNAPSHOT_DIR | |
|
168
f3084bca7317
[Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents:
145
diff
changeset
|
14 #define SNAPSHOT_DIR "/home/june/zenbu/mrjunejune/test/snapshots" |
| 129 | 15 #endif |
| 16 | |
| 17 pid_t start_test_server(const char *server_binary) | |
| 18 { | |
| 19 pid_t server_pid = fork(); | |
| 20 | |
| 21 if (server_pid < 0) | |
| 22 { | |
| 23 perror("fork"); | |
| 24 return -1; | |
| 25 } | |
| 26 | |
| 27 if (server_pid == 0) | |
| 28 { | |
| 29 printf("Starting server on port %s...\n", TEST_PORT); | |
| 30 execl(server_binary, server_binary, NULL); | |
| 31 perror("execl failed"); | |
| 32 exit(1); | |
| 33 } | |
| 34 | |
| 35 printf("Server started (PID: %d)\n", server_pid); | |
| 36 | |
| 37 usleep(100000); | |
| 38 int status; | |
| 39 pid_t result = waitpid(server_pid, &status, WNOHANG); | |
| 40 if (result != 0) | |
| 41 { | |
| 42 if (WIFEXITED(status)) | |
| 43 { | |
| 44 fprintf(stderr, "Server exited immediately with code: %d\n", WEXITSTATUS(status)); | |
| 45 } | |
| 46 else if (WIFSIGNALED(status)) | |
| 47 { | |
| 48 fprintf(stderr, "Server was killed by signal: %d\n", WTERMSIG(status)); | |
| 49 } | |
| 50 return -1; | |
| 51 } | |
| 52 | |
| 53 sleep(2); | |
| 54 printf("Server ready\n\n"); | |
| 55 | |
| 56 return server_pid; | |
| 57 } | |
| 58 | |
| 59 void stop_test_server(pid_t server_pid) | |
| 60 { | |
| 61 if (server_pid > 0) | |
| 62 { | |
| 63 printf("\nStopping server (PID: %d)...\n", server_pid); | |
| 64 kill(server_pid, SIGTERM); | |
| 65 waitpid(server_pid, NULL, 0); | |
| 66 printf("Server stopped\n"); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 |