Compare commits
1 Commits
ec586105b4
...
24f7141c98
| Author | SHA1 | Date | |
|---|---|---|---|
|
24f7141c98
|
@@ -24,16 +24,38 @@
|
||||
/* Number of ports reserved per test group; allows skipping TIME_WAIT ports */
|
||||
#define PORTS_PER_GROUP 50
|
||||
|
||||
/* Base port and fallback scan range for stabber */
|
||||
#define BASE_PORT 5230
|
||||
#define FALLBACK_PORT_RANGE (TEST_GROUPS * PORTS_PER_GROUP)
|
||||
|
||||
/* Shutdown polling: interval and maximum attempts before escalating signals */
|
||||
#define SHUTDOWN_POLL_MS 50
|
||||
#define SHUTDOWN_POLL_MAX 100 /* 100 x 50ms = 5s */
|
||||
#define SIGTERM_POLL_MAX 20 /* 20 x 50ms = 1s */
|
||||
#define MS_TO_US 1000
|
||||
#define SHUTDOWN_POLL_MS 50
|
||||
#define SHUTDOWN_POLL_MAX 100 /* 100 x 50ms = 5s */
|
||||
#define SIGTERM_POLL_MAX 20 /* 20 x 50ms = 1s */
|
||||
#define QUIT_GRACE_MS 100 /* grace for /quit to be read from pty */
|
||||
#define INIT_WAIT_MS 50 /* wait for child process to initialize */
|
||||
#define INPUT_DELAY_MS 10 /* let profanity process input */
|
||||
#define OUTPUT_POLL_MS 50 /* polling interval for output checks */
|
||||
#define READ_TIMEOUT_MS 100 /* select() timeout for pty reads */
|
||||
|
||||
/* Expect timeouts (seconds) */
|
||||
#define EXPECT_TIMEOUT_DEFAULT 30
|
||||
#define EXPECT_TIMEOUT_CONNECT 60
|
||||
|
||||
/* Terminal dimensions for forkpty */
|
||||
#define PTY_ROWS 24
|
||||
#define PTY_COLS 300
|
||||
|
||||
/* Preprocessor stringification (for setenv from numeric #define) */
|
||||
#define STRINGIFY_(x) #x
|
||||
#define STRINGIFY(x) STRINGIFY_(x)
|
||||
|
||||
char *config_orig;
|
||||
char *data_orig;
|
||||
|
||||
int fd = 0;
|
||||
int stub_port = 5230;
|
||||
int stub_port = BASE_PORT;
|
||||
pid_t child_pid = 0;
|
||||
|
||||
/*
|
||||
@@ -53,7 +75,7 @@ static char output_buffer[OUTPUT_BUF_SIZE];
|
||||
static size_t output_len = 0;
|
||||
|
||||
/* Timeout for expect operations in seconds */
|
||||
static int expect_timeout = 30;
|
||||
static int expect_timeout = EXPECT_TIMEOUT_DEFAULT;
|
||||
|
||||
gboolean
|
||||
_create_dir(const char *name)
|
||||
@@ -175,8 +197,8 @@ _read_output(int timeout_ms)
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(fd, &readfds);
|
||||
|
||||
tv.tv_sec = timeout_ms / 1000;
|
||||
tv.tv_usec = (timeout_ms % 1000) * 1000;
|
||||
tv.tv_sec = timeout_ms / MS_TO_US;
|
||||
tv.tv_usec = (timeout_ms % MS_TO_US) * MS_TO_US;
|
||||
|
||||
int ret = select(fd + 1, &readfds, NULL, NULL, &tv);
|
||||
if (ret <= 0) {
|
||||
@@ -207,8 +229,8 @@ void
|
||||
prof_start(void)
|
||||
{
|
||||
struct winsize ws;
|
||||
ws.ws_row = 24;
|
||||
ws.ws_col = 300; /* Match COLUMNS=300 from start_profanity.sh */
|
||||
ws.ws_row = PTY_ROWS;
|
||||
ws.ws_col = PTY_COLS;
|
||||
ws.ws_xpixel = 0;
|
||||
ws.ws_ypixel = 0;
|
||||
|
||||
@@ -225,7 +247,7 @@ prof_start(void)
|
||||
|
||||
if (child_pid == 0) {
|
||||
/* Child process */
|
||||
setenv("COLUMNS", "300", 1);
|
||||
setenv("COLUMNS", STRINGIFY(PTY_COLS), 1);
|
||||
setenv("TERM", "xterm", 1);
|
||||
|
||||
execl("./profanity", "./profanity", "-l", "DEBUG", NULL);
|
||||
@@ -241,7 +263,7 @@ prof_start(void)
|
||||
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
||||
|
||||
/* Brief wait for process to initialize */
|
||||
usleep(50000); /* 50ms */
|
||||
usleep(INIT_WAIT_MS * MS_TO_US);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -257,11 +279,11 @@ init_prof_test(void **state)
|
||||
|
||||
/* Calculate port base: each build uses a different range of
|
||||
* TEST_GROUPS * PORTS_PER_GROUP ports.
|
||||
* Build 0 (local/default): 5230-5429, Full: 5230-5429, Minimal: 5430-5629, etc.
|
||||
* Build 0 (local/default): BASE_PORT..+199, Full: same, Minimal: +200, etc.
|
||||
* Build 0 and Full share the same range because build 0 is for local runs
|
||||
* or sequential run (no parallel builds), while Full/Minimal/NoEncrypt/Default
|
||||
* are used in CI where they run in parallel. */
|
||||
int port_base = 5230 + ((build_idx > 0 ? build_idx - 1 : 0) * TEST_GROUPS * PORTS_PER_GROUP);
|
||||
int port_base = BASE_PORT + ((build_idx > 0 ? build_idx - 1 : 0) * TEST_GROUPS * PORTS_PER_GROUP);
|
||||
|
||||
/* Each group gets a dedicated range of ports for parallel execution.
|
||||
* Group 1: port_base..port_base+PORTS_PER_GROUP-1
|
||||
@@ -286,7 +308,7 @@ init_prof_test(void **state)
|
||||
|
||||
/* Fallback to dynamic allocation if static failed or group=0 */
|
||||
if (!started) {
|
||||
for (int p = port_base; p < port_base + 200; ++p) {
|
||||
for (int p = port_base; p < port_base + FALLBACK_PORT_RANGE; ++p) {
|
||||
if (stbbr_start(STBBR_LOGDEBUG, p, 0) == 0) {
|
||||
stub_port = p;
|
||||
started = TRUE;
|
||||
@@ -366,7 +388,7 @@ close_prof_test(void **state)
|
||||
/* Close pty master after brief grace — child gets SIGHUP which
|
||||
* accelerates shutdown instead of waiting for XMPP disconnect
|
||||
* timeout (~5s). */
|
||||
usleep(100000); /* 100ms grace for /quit to be read from pty buffer */
|
||||
usleep(QUIT_GRACE_MS * MS_TO_US);
|
||||
close(fd);
|
||||
fd = 0;
|
||||
int exited = 0;
|
||||
@@ -375,13 +397,13 @@ close_prof_test(void **state)
|
||||
exited = 1;
|
||||
break;
|
||||
}
|
||||
usleep(SHUTDOWN_POLL_MS * 1000);
|
||||
usleep(SHUTDOWN_POLL_MS * MS_TO_US);
|
||||
}
|
||||
if (!exited) {
|
||||
kill(child_pid, SIGTERM);
|
||||
for (int i = 0; i < SIGTERM_POLL_MAX; i++) {
|
||||
if (waitpid(child_pid, NULL, WNOHANG) != 0) { exited = 1; break; }
|
||||
usleep(SHUTDOWN_POLL_MS * 1000);
|
||||
usleep(SHUTDOWN_POLL_MS * MS_TO_US);
|
||||
}
|
||||
if (!exited) {
|
||||
kill(child_pid, SIGKILL);
|
||||
@@ -412,7 +434,7 @@ prof_input(const char *input)
|
||||
g_string_free(inp_str, TRUE);
|
||||
|
||||
/* Small delay to let profanity process input */
|
||||
usleep(10000);
|
||||
usleep(INPUT_DELAY_MS * MS_TO_US);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -426,7 +448,7 @@ prof_output_exact(const char *text)
|
||||
|
||||
while (time(NULL) - start < expect_timeout) {
|
||||
/* Read any available output */
|
||||
while (_read_output(100) > 0) {
|
||||
while (_read_output(READ_TIMEOUT_MS) > 0) {
|
||||
/* Keep reading while data available */
|
||||
}
|
||||
|
||||
@@ -435,7 +457,7 @@ prof_output_exact(const char *text)
|
||||
return 1;
|
||||
}
|
||||
|
||||
usleep(50000); /* 50ms */
|
||||
usleep(OUTPUT_POLL_MS * MS_TO_US);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -460,7 +482,7 @@ prof_output_regex(const char *pattern)
|
||||
|
||||
while (time(NULL) - start < expect_timeout) {
|
||||
/* Read any available output */
|
||||
while (_read_output(100) > 0) {
|
||||
while (_read_output(READ_TIMEOUT_MS) > 0) {
|
||||
/* Keep reading while data available */
|
||||
}
|
||||
|
||||
@@ -471,7 +493,7 @@ prof_output_regex(const char *pattern)
|
||||
return 1;
|
||||
}
|
||||
|
||||
usleep(50000); /* 50ms */
|
||||
usleep(OUTPUT_POLL_MS * MS_TO_US);
|
||||
}
|
||||
|
||||
/* Timeout reached - log diagnostic info */
|
||||
@@ -513,12 +535,12 @@ prof_connect_with_roster(const char *roster)
|
||||
assert_true(prof_output_regex("password:"));
|
||||
prof_input("password");
|
||||
|
||||
expect_timeout = 60;
|
||||
expect_timeout = EXPECT_TIMEOUT_CONNECT;
|
||||
assert_true(prof_output_regex("Connecting as stabber@localhost"));
|
||||
assert_true(prof_output_regex("logged in successfully"));
|
||||
assert_true(prof_output_regex(".+online.+ \\(priority 0\\)\\."));
|
||||
|
||||
expect_timeout = 60;
|
||||
expect_timeout = EXPECT_TIMEOUT_CONNECT;
|
||||
// Wait for presence stanza to be sent (content-based, not ID-based)
|
||||
// Match the actual attribute order from stanza_attach_caps
|
||||
assert_true(stbbr_received(
|
||||
@@ -537,7 +559,7 @@ prof_timeout(int timeout)
|
||||
void
|
||||
prof_timeout_reset(void)
|
||||
{
|
||||
expect_timeout = 60;
|
||||
expect_timeout = EXPECT_TIMEOUT_CONNECT;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user