diff --git a/test/aswm/test_aswm.c b/test/aswm/test_aswm.c index db3c2c7..d8cc434 100644 --- a/test/aswm/test_aswm.c +++ b/test/aswm/test_aswm.c @@ -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(); } diff --git a/test/test_set_up.c b/test/test_set_up.c index 6ece3f2..1dfcf44 100644 --- a/test/test_set_up.c +++ b/test/test_set_up.c @@ -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 diff --git a/test/test_set_up.h b/test/test_set_up.h index 53a95ca..53cbbe5 100644 --- a/test/test_set_up.h +++ b/test/test_set_up.h @@ -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();