Skip to content

Commit

Permalink
Test dark mode too.
Browse files Browse the repository at this point in the history
  • Loading branch information
porridge committed Jul 14, 2023
1 parent 05b1f9f commit bd8f906
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ jobs:
-s "-screen 0 1024x768x24 -fbdir $AUTOPKGTEST_TMP" \
./test_e2e.py
- name: Run GUI tests in dark mode
run: |
export AUTOPKGTEST_ARTIFACTS=`pwd`/artifacts/dark
mkdir -p $AUTOPKGTEST_ARTIFACTS
export AUTOPKGTEST_TMP=/tmp
export AUTOPKGTEST_BAMBAM_PROGRAM=./bambam.py
xvfb-run \
-e $AUTOPKGTEST_ARTIFACTS/xvfb-run.stderr \
-s "-screen 0 1024x768x24 -fbdir $AUTOPKGTEST_TMP" \
./test_e2e.py --no-expect-light-mode -- --dark
- name: Run GUI tests with deterministic sounds
run: |
export AUTOPKGTEST_ARTIFACTS=`pwd`/artifacts/deterministic
Expand Down
31 changes: 19 additions & 12 deletions test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('--expect-audio-output', action=argparse.BooleanOptionalAction, default=True)
parser.add_argument('--expect-sounds', action=argparse.BooleanOptionalAction, default=True)
parser.add_argument('--expect-light-mode', action=argparse.BooleanOptionalAction, default=True)
parser.add_argument('--sdl-audio-driver', default='disk')
parser.add_argument('bambam_args', nargs='*')
args = parser.parse_args()
Expand All @@ -65,8 +66,8 @@ def main():
await_welcome_screen()
send_keycodes('space') # any keypress should do
check_still_running(bambam)
await_blank_screen()
test_functionality(bambam, args.expect_sounds)
await_blank_screen(args.expect_light_mode)
test_functionality(bambam, args.expect_sounds, args.expect_light_mode)
shut_bambam_down(bambam)
logging.info('Waiting for game to exit cleanly.')
exit_code = bambam.wait(timeout=_EXIT_SECONDS)
Expand Down Expand Up @@ -109,21 +110,27 @@ def await_welcome_screen():
'after polling %d times every %f seconds.' % (attempt_count, sleep_delay))


def await_blank_screen():
logging.info('Polling to observe a mostly-white screen (which means that welcome screen was cleared).')
def await_blank_screen(expect_light: bool):
attempt_count = 40
sleep_delay = 0.25
if expect_light:
def check(c): return c >= 248
comment = 'mostly white screen'
else:
def check(c): return c < 2
comment = 'mostly black screen'
logging.info('Polling to observe a %s (which means that welcome screen was cleared).', comment)
for attempt in range(attempt_count):
current_average_color = get_average_color()
logging.info('On attempt %d the average screen color was %s.', attempt, current_average_color)
if all(color_component >= 248 for color_component in current_average_color):
logging.info('Found mostly white screen, looks like bambam cleared the welcome screen OK.')
if all(check(color_component) for color_component in current_average_color):
logging.info('Found %s, looks like bambam cleared the welcome screen OK.', comment)
take_screenshot('blank')
return
time.sleep(sleep_delay)
raise Exception(
'Failed to see bambam clear the startup screen and display mostly-white background, '
'after polling %d times every %f seconds.' % (attempt_count, sleep_delay))
'Failed to see bambam clear the startup screen and display %s, '
'after polling %d times every %f seconds.' % (comment, attempt_count, sleep_delay))


def check_still_running(bambam: subprocess.Popen):
Expand All @@ -132,7 +139,7 @@ def check_still_running(bambam: subprocess.Popen):
raise Exception('Bambam unexpectedly exited with code %d' % bambam.returncode)


def test_functionality(bambam: subprocess.Popen, try_unmute: bool):
def test_functionality(bambam: subprocess.Popen, try_unmute: bool, expect_light: bool):
check_still_running(bambam)
logging.info('Exercising runtime mute.')
send_keycodes('m', 'u')
Expand All @@ -150,15 +157,15 @@ def test_functionality(bambam: subprocess.Popen, try_unmute: bool):
time.sleep(0.25) # let the event propagate and bambam process it (leave some time for sound to play)
# Do not bother checking screen if bambam crashed.
check_still_running(bambam)
if is_screen_colorful_enough(attempt):
if is_screen_colorful_enough(attempt, expect_light):
take_screenshot('success')
return
raise Exception('Failed to see a colorful enough screen after %d key presses.' % (attempt_count * 2))


def is_screen_colorful_enough(attempt):
def is_screen_colorful_enough(attempt, expect_light: bool):
r, g, b = get_average_color()
if any(color < 10 for color in (r, g, b)):
if any(color < 30 for color in (r, g, b)):
logging.info('On attempt %d the average screen color was too close to black: %d,%d,%d.', attempt, r, g, b)
return False
if any(color > 225 for color in (r, g, b)):
Expand Down

0 comments on commit bd8f906

Please sign in to comment.