Skip to content

Commit

Permalink
Migrate to libfaketime (ignored by GCC builds on macOS)
Browse files Browse the repository at this point in the history
  • Loading branch information
hartwork committed Nov 25, 2023
1 parent 524e706 commit 7076977
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/linux_and_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ jobs:
pkg-config
- name: Install build dependencies
if: "${{ runner.os == 'macOS' }}"
if: "${{ runner.os == 'macOS' && contains(matrix.cxx, 'clang') }}"
run: |-
brew tap homebrew/cask-fonts
brew install \
agg \
asciinema \
coreutils \
font-liberation \
imagemagick
imagemagick \
libfaketime
- name: Install build dependency Clang ${{ matrix.clang_major_version }}
if: "${{ runner.os == 'Linux' && contains(matrix.cxx, 'clang') }}"
Expand Down Expand Up @@ -111,20 +112,20 @@ jobs:
[[ "$(find ROOT/ -not -type d | tee /dev/stderr)" == '' ]] # i.e. fail CI if leftover files
- name: 'Run UI tests'
if: "${{ runner.os == 'macOS' }}"
if: "${{ runner.os == 'macOS' && contains(matrix.cxx, 'clang') }}"
run: |-
./recordings/record.sh
- name: 'Upload UI test renderings for inspection'
if: "${{ runner.os == 'macOS' }}"
if: "${{ runner.os == 'macOS' && contains(matrix.cxx, 'clang') }}"
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: ttyplot_ui_test_${{ github.sha }}_${{ matrix.runs-on }}_${{ matrix.cc }}
path: recordings/actual*
if-no-files-found: error

- name: 'Evaluate UI test results'
if: "${{ runner.os == 'macOS' }}"
if: "${{ runner.os == 'macOS' && contains(matrix.cxx, 'clang') }}"
run: |-
set -o pipefail
Expand Down
25 changes: 24 additions & 1 deletion recordings/record.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,30 @@ agg_bin_dir="${HOME}/.cargo/bin" # if a local build
export PATH="${ttyplot_bin_dir}:${PATH}:${agg_bin_dir}"

# Consistent clock display for reproducibility
export FAKETIME=yesplease
export FAKETIME="@1970-01-01 00:00:00"
case "$(uname -s)" in
Darwin)
# From https://github.com/wolfcw/libfaketime/blob/master/README.OSX
export DYLD_FORCE_FLAT_NAMESPACE=1
export DYLD_INSERT_LIBRARIES=/usr/local/lib/faketime/libfaketime.1.dylib
;;
Linux)
libfaketime_candidates=(
# Gentoo
/usr/lib64/libfaketime.so
# Debian, Ubuntu
/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1
)
for libfaketime in "${libfaketime_candidates[@]}"; do
[[ -e ${libfaketime} ]] && break
done
export LD_PRELOAD="${libfaketime}"
;;
*)
echo 'Operating system not supported.' >&2
exit 1
;;
esac


cd "${self_dir}"
Expand Down
16 changes: 2 additions & 14 deletions ttyplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

sigset_t sigmsk;
chtype plotchar, max_errchar, min_errchar;
time_t t0,t1,t2,td;
time_t t1,t2,td;
struct tm *lt;
double max=FLT_MIN;
double softmax=FLT_MIN, hardmax=FLT_MAX, hardmin=0.0;
Expand Down Expand Up @@ -195,13 +195,7 @@ void paint_plot(void) {

mvaddstr(height-1, width-strlen(verstring)-1, verstring);

if (t0 == 0) { // regular clock
lt = localtime(&t1);
} else { // fake time for UI testing
const time_t with_app_start_at_epoch = t1 - t0;
lt = gmtime(&with_app_start_at_epoch);
}

lt=localtime(&t1);
asctime_r(lt, ls);
mvaddstr(height-2, width-strlen(ls), ls);

Expand Down Expand Up @@ -257,12 +251,6 @@ int main(int argc, char *argv[]) {
int show_ver;
int show_usage;

// To ease UI testing, display a clock starting at
// "Thu Jan 1 00:00:00 1970" when variable FAKETIME is set
if (getenv("FAKETIME") != NULL) {
time(&t0);
}

plotchar=T_VLINE;
max_errchar='e';
min_errchar='v';
Expand Down

0 comments on commit 7076977

Please sign in to comment.