This 2018 article explains how you can dynamically switch the audio output between hdmi and analogue on a Raspberry Pi. From the command line use
amixer cset numid=3 2 for hdmi and
amixer cset numid=3 1 for analogue. This information is no longer in the current version of that page, so may no longer work. The May 2020 blog says they have changed the sound architecture to handle the hdmi and analogue output as 2 independent devices: YouAlsa card 0 will be HDMI, and card 1 will be the headphone jack. The default is 0, but to use 1 you can create a ~/.asoundrc file with
defaults.pcm.card 1 defaults.ctl.card 1 This presumably requires you to login again.
You can generate a stereo test tone with another command from alsa-utils:
speaker-test -c 2 -s 1 -t sine -f 440