Files
ps5-pkg-manager/tests/test_install_process.c
Mateusz Najdek 43b6568b2f Release v1.3.0 (#18)
* Fix repeated SMB scans and add manual package browsing

* Run package installs in fresh helper processes

Launch an embedded helper through elfldr for each install and exchange requests over loopback IPC. Link the helper with the same system service dependencies as pkgmgr so AppInstUtil starts on supported firmware.

* Reduce installer log memory and diagnostic noise

* Test real helper ELF launcher handoff

* Prepare 1.3.0 release documentation

* Add large catalog mode to frontend mock

* Update docs

* Fix dirty build metadata in releases

* Include changelog section in release notes
2026-09-25 12:33:36 +02:00

73 lines
2.2 KiB
C

/* Exercise the real ELF upload and IPC callback against a fake elfldr. */
#include "install_process.h"
#include "install_ipc.h"
#include <arpa/inet.h>
#include <assert.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
void install_log(const char *fmt, ...) {
(void)fmt;
}
static int listener(int port) {
int fd = socket(AF_INET, SOCK_STREAM, 0);
assert(fd >= 0);
int opt = 1;
assert(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == 0);
struct sockaddr_in addr = {.sin_family = AF_INET, .sin_port = htons(port)};
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
assert(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0);
assert(listen(fd, 1) == 0);
return fd;
}
static void *fake_elfldr(void *arg) {
int listen_fd = *(int *)arg;
int upload = accept(listen_fd, NULL, NULL);
assert(upload >= 0);
unsigned char elf[8] = {0};
size_t got = 0;
for (;;) {
ssize_t n = read(upload, elf + got, sizeof(elf) - got);
assert(n >= 0);
if (n == 0) break; /* The upload side must be shut down. */
got += (size_t)n;
assert(got < sizeof(elf));
}
assert(got == 4 && memcmp(elf, "\177ELF", 4) == 0);
assert(write(upload, "helper started\n", 15) == 15);
int callback = socket(AF_INET, SOCK_STREAM, 0);
assert(callback >= 0);
struct sockaddr_in addr = {.sin_family = AF_INET, .sin_port = htons(INSTALL_IPC_PORT)};
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
assert(connect(callback, (struct sockaddr *)&addr, sizeof(addr)) == 0);
close(callback);
close(upload);
return NULL;
}
int main(void) {
int elfldr = listener(ELFLDR_PORT);
pthread_t worker;
assert(pthread_create(&worker, NULL, fake_elfldr, &elfldr) == 0);
int ipc_fd = -1;
assert(install_process_start(&ipc_fd) == 0);
assert(ipc_fd >= 0);
close(ipc_fd);
assert(pthread_join(worker, NULL) == 0);
close(elfldr);
ipc_fd = 123;
assert(install_process_start(&ipc_fd) == -1);
assert(ipc_fd == -1);
puts("Install launcher: ELF upload, half-close, IPC callback and missing elfldr passed");
return 0;
}