🧑‍💻 Check for Xephyr availability before running tests

This commit is contained in:
Paul Breugnot 2025-03-02 09:11:31 +01:00
parent 599610fd6f
commit b47ccfd93a
3 changed files with 24 additions and 4 deletions

View file

@ -10,7 +10,8 @@ clock_t USER_DELAY = 1 * CLOCKS_PER_SEC;
void run_aswm(void) {
int stat_loc;
// Ensures aswm is running
// A return value of 0 indicates that the status of aswm_pid is not yet
// available, i.e. aswm is running
TEST_ASSERT_EQUAL_INT(0, waitpid(aswm_pid, &stat_loc, WNOHANG));
}
@ -139,9 +140,11 @@ void create_multiple_resizeable_top_level_window(void) {
int main(void) {
UNITY_BEGIN();
set_up_test_logger();
RUN_TEST(run_aswm);
RUN_TEST(create_single_resizeable_top_level_window);
RUN_TEST(create_multiple_resizeable_top_level_window);
if(check_xephyr_available()) {
RUN_TEST(run_aswm);
RUN_TEST(create_single_resizeable_top_level_window);
RUN_TEST(create_multiple_resizeable_top_level_window);
}
tear_down_test_logger();
return UNITY_END();
}

View file

@ -44,7 +44,23 @@ void tear_down_test_logger(void) {
zlog_fini();
}
bool check_xephyr_available() {
xephyr_pid = fork();
if(xephyr_pid == 0) {
char* args[] = {"which", "Xephyr", NULL};
execvp(args[0], args);
}
int stat_loc;
waitpid(xephyr_pid, &stat_loc, 0);
if(stat_loc != 0) {
zlog_error(test_log, "Xephyr executable not found. Make sure it is installed and available in your PATH.");
return false;
}
return true;
}
void setUp(void) {
tmpnam(display_fd); // Creates a temporary file name
sprintf(display_name, ":%u", display_count); // Loads initial display count
// in display name

View file

@ -17,6 +17,7 @@ extern Display* test_display;
extern Window test_root;
extern zlog_category_t *test_log;
bool check_xephyr_available();
void set_up_test_logger();
void tear_down_test_logger();