Add test suite for timezone tests

Previously, when testing the clock command of x52cli, we had forced the
system timezone to UTC. As a result, the offset calculations for clocks
2 and 3 were never computed and always resulted in 0, which hid the bug
when the local time and local standard time did not match (#20).

This commit adds a test case that uses faketime to test setting the
clock to local (Pacific Time) and verifying that the offsets are
computed correctly. Given that the bug is still present as of this
commit, add the test suite to XFAIL_TESTS as well, so that it doesn't
break the CI build.
pull/22/head
nirenjan 2020-06-02 14:48:46 -07:00
parent 7ae5cad0cc
commit 79bd8466c1
3 changed files with 93 additions and 1 deletions

View File

@ -13,7 +13,12 @@ TESTS = \
libx52/test_brightness.sh \ libx52/test_brightness.sh \
libx52/test_indicator.sh \ libx52/test_indicator.sh \
libx52/test_mfd.sh \ libx52/test_mfd.sh \
libx52/test_clock.sh libx52/test_clock.sh \
libx52/test_timezone.sh
# NOTE: Timezone tests currently fail when local time is daylight time. Once
# this is fixed, remove the line below.
XFAIL_TESTS = libx52/test_timezone.sh
EXTRA_DIST = common_infra.sh $(TESTS) EXTRA_DIST = common_infra.sh $(TESTS)

View File

@ -106,6 +106,25 @@ find_programs()
fi fi
} }
# This is for additional programs that are not needed by every test case
require_programs()
{
local skip=false
for prog in "$@"
do
if ! command -v "$prog"
then
echo "Required program '$prog' not found, skipping test suite"
skip=true
fi
done
if $skip
then
exit $EXIT_SKIP
fi
}
setup_preload() setup_preload()
{ {
# Find the libusb stub library # Find the libusb stub library

View File

@ -0,0 +1,68 @@
#!/bin/bash
# Timezone tests
#
# Copyright (C) 2020 Nirenjan Krishnan (nirenjan@nirenjan.org)
#
# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0
source $(dirname $0)/../common_infra.sh
require_programs faketime
TEST_SUITE_ID="libx52 timezone tests"
# Use the America/Los_Angeles timezone
# Standard time is UTC-08:00, Daylight time is UTC-07:00
export TZ=America/Los_Angeles
# All timezone tests use DD-MM-YY and 12hr format
timezone_test()
{
local datetime="$1"
TEST_ID="Test setting clock to '$(date --date="$datetime")'"
local dd=$(date --date="$datetime" +%_d)
local mm=$(date --date="$datetime" +%_m)
local yy=$(date --date="$datetime" +%_y)
local hr=$(date --date="$datetime" +%_H)
local mn=$(date --date="$datetime" +%_M)
local off
if [[ "$(date --date="$datetime" +%Z)" == 'PDT' ]]
then
# Pacific Daylight Time
# Default offset for clocks 2 & 3 should be +420 minutes
off=420
else
# Pacific Standard time
# Default offset for clocks 2 & 3 should be +480 minutes
off=480
fi
local clock_value=$(($hr * 256 + $mn))
local date_value=$(($mm * 256 + $dd))
local year_value=$yy
expect_pattern \
$X52_CLOCK_DATE_INDEX $(printf '%04x' $date_value) \
$X52_CLOCK_YEAR_INDEX $(printf '%04x' $year_value) \
$X52_CLOCK_1_INDEX $(printf '%04x' $clock_value) \
$X52_CLOCK_2_INDEX $(printf '%04x' $off) \
$X52_CLOCK_3_INDEX $(printf '%04x' $off) \
faketime "$datetime" $X52CLI clock local 12hr ddmmyy
verify_output
}
# Check timezone test for 14:15:16 on the 13th day of every month from
# January 2017 to December 2019
for year in $(seq 2017 2019)
do
for month in $(seq 1 12)
do
timezone_test "$(printf '%d-%02d-13 14:15:16' $year $month)"
done
done
verify_test_suite