Skip to content

Commit

Permalink
tests: add new runner
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-pierre committed Nov 23, 2024
1 parent fccfa33 commit aebcef8
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 27 deletions.
7 changes: 0 additions & 7 deletions .busted

This file was deleted.

2 changes: 1 addition & 1 deletion .ci/test_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if [ "${EMULATE_READER}" = "1" ]; then
# install test data
travis_retry make test-data
# finally make test
travis_retry make --assume-old=all test
travis_retry make --assume-old=all test T="-o '${PWD}/test-results.xml'"
) || exit_code=1
else
if [ "${TARGET}" = "android" ] && [ -f build/luajit ]; then
Expand Down
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ jobs:
ccache_maxsize:
type: string
default: "128M"
save_tests:
type: boolean
default: false
executor: << parameters.executor >>
resource_class: medium
environment:
Expand Down Expand Up @@ -197,6 +200,15 @@ jobs:
- run:
name: Test
command: source .ci/test_script.sh
- when:
condition: << parameters.save_tests >>
steps:
- store_test_results:
name: Store tests results
path: test-results.xml
- store_artifacts:
name: Upload tests results to artifacts
path: test-results.xml
# }}}

# }}}
Expand Down Expand Up @@ -225,19 +237,22 @@ workflows:
only: master
requires:
- lint
save_tests: true

- build_and_test:
name: emu_gcc_ninja_debug
executor: emu_gcc_ninja_debug
requires:
- lint
ccache_maxsize: "512M"
save_tests: true

- build_and_test:
name: emu_clang_ninja
executor: emu_clang_ninja
requires:
- lint
save_tests: true

# }}}

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jobs:
packages=(
autoconf
automake
bash
binutils
cmake
coreutils
Expand Down
35 changes: 25 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ $(OUTPUT_DIR)/ffi
$(OUTPUT_DIR)/fonts/
$(STAGING_DIR)/
endef
ifneq (,$(EMULATE_READER))
define SKELETON +=
$(OUTPUT_DIR)/spec/base
endef
endif

skeleton: $(strip $(SKELETON))

Expand All @@ -136,16 +131,36 @@ ifneq (,$(EMULATE_READER))

download-all: test-data

$(OUTPUT_DIR)/.busted: | $(OUTPUT_DIR)/
$(SYMLINK) $(KOR_BASE)/.busted $@

$(OUTPUT_DIR)/spec/base: | $(OUTPUT_DIR)/spec/
$(SYMLINK) $(KOR_BASE)/spec $@

$(OUTPUT_DIR)/spec/config.lua: | $(OUTPUT_DIR)/spec/
$(SYMLINK) $(KOR_BASE)/test-runner/busted_config.lua $@

$(OUTPUT_DIR)/spec/meson.build: | $(OUTPUT_DIR)/spec/
$(SYMLINK) $(KOR_BASE)/test-runner/meson.build $@

$(OUTPUT_DIR)/spec/runtests: | $(OUTPUT_DIR)/spec/
$(SYMLINK) $(KOR_BASE)/test-runner/runtests $@

$(BASE_PREFIX)test: $(BASE_PREFIX)all test-data
cd $(OUTPUT_DIR) && $(BUSTED_LUAJIT) $(BUSTED_OVERRIDES)
$(RUNTESTS) $(OUTPUT_DIR) base $T

define test_data_common
$(OUTPUT_DIR)/spec/config.lua
$(OUTPUT_DIR)/spec/meson.build
$(OUTPUT_DIR)/spec/runtests
endef

skeleton: $(strip $(test_data_common))

define test_data_base
$(OUTPUT_DIR)/data/tessdata/eng.traineddata
$(OUTPUT_DIR)/fonts/droid/DroidSansMono.ttf
$(OUTPUT_DIR)/spec/base
endef

test-data: $(OUTPUT_DIR)/.busted $(OUTPUT_DIR)/data/tessdata/eng.traineddata $(OUTPUT_DIR)/spec/base $(OUTPUT_DIR)/fonts/droid/DroidSansMono.ttf
test-data: $(strip $(test_data_common) $(test_data_base))

TESSDATA_FILE = $(THIRDPARTY_DIR)/tesseract/build/downloads/eng.traineddata
TESSDATA_FILE_URL = https://github.com/tesseract-ocr/tessdata/raw/4.1.0/$(notdir $(TESSDATA_FILE))
Expand Down
15 changes: 6 additions & 9 deletions Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,21 +1076,18 @@ endif

ifneq (,$(EMULATE_READER))

define busted_fn
busted() {(
define runtests_fn
runtests() {(
kodir="$$1";
shift 1;
export LUA_CPATH='./?.so;$(abspath $(SPEC_ROCKS_DIR)/lib/lua/5.1/?.so)';
export LUA_PATH='./?.lua;$(abspath $(SPEC_ROCKS_DIR)/share/lua/5.1/?.lua);$(abspath $(SPEC_ROCKS_DIR)/share/lua/5.1/?/init.lua)';
export TESSDATA_DIR="$$PWD/data";
./luajit -e 'require "busted.runner" {standalone = false}' /dev/null
--exclude-tags=notest
--helper=ffi/loadlib.lua
--output=gtest
--sort-files
"$$@";
"$$kodir/spec/runtests" $(PARALLEL_JOBS:%=-j%) "$$@";
)}
endef

BUSTED_LUAJIT = $(strip $(busted_fn)); busted
RUNTESTS = $(strip $(runtests_fn)); runtests

endif

Expand Down
1 change: 1 addition & 0 deletions cache-key.base
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# Excludes.
!*.lua
!/ffi-cdecl/**
!/test-runner/**
!/utils/bincheck/*

# Exceptions.
Expand Down
25 changes: 25 additions & 0 deletions test-runner/busted_config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- vim: ft=lua

local lfs = require("lfs")

local testsuites = {}
local roots = {}
local lpaths = {}
for entry in lfs.dir("spec") do
if not string.match(entry, "^[.]") then
local testroot = "spec/" .. entry .. "/unit"
local testpath = testroot .. "/?.lua"
testsuites[entry] = {}
testsuites[entry].ROOT = {testroot}
testsuites[entry].lpath = testpath
table.insert(roots, testroot)
table.insert(lpaths, testpath)
end
end

testsuites.all = {
ROOT = roots,
lpath = table.concat(lpaths, ";"),
}

return testsuites
71 changes: 71 additions & 0 deletions test-runner/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
project('koreader-testrunner', version: '0.1')

kodir = get_option('prefix')
testdir = 'spec'

fs = import('fs')

find = find_program('find')
luajit = find_program(kodir / 'luajit')

_testroot = kodir / testdir
foreach _testpath : run_command(
find, '-L', _testroot,
'-type', 'f',
'(',
'-name', '*_bench.lua',
'-o',
'-name', '*_spec.lua',
')',
'-print0',
check: true,
).stdout().strip('\0').split('\0')
assert(_testpath.startswith(_testroot))
# Fugly, but no `str.length()`…
_testpath = _testpath.replace(_testroot + '/', '')
_parts = _testpath.split('/')
_suite = _parts[0]
assert(_suite != '')
_is_bench = _parts[-1].endswith('_bench.lua')
if _is_bench
_test = _parts[-1].substring(0, -10)
# message('benchmark:', _suite, _test)
else
_test = _parts[-1].substring(0, -9)
_id = _suite / _test
# message('test:', _suite, _test)
endif
_args = [
'-e', 'require "busted.runner" {standalone = false}', '/dev/null',
'--output=gtest', '-Xoutput=--color',
'--run=' + _suite,
testdir / _testpath,
]
_env = environment()
_env.set('KO_HOME', meson.current_build_dir() / '_'.join(_suite, _test))
# Don't fail the testsuite on ASAN detected leaks.
_env.prepend('LSAN_OPTIONS', 'exitcode=0', separator: ' ')
if _is_bench
benchmark(
_test,
luajit,
args: _args,
env: _env,
protocol: 'exitcode',
suite: _suite,
timeout: 0,
workdir: fs.parent(luajit.full_path()),
)
else
test(
_test,
luajit,
args: _args,
env: _env,
protocol: 'exitcode',
suite: _suite,
timeout: 5 * 60,
workdir: fs.parent(luajit.full_path()),
)
endif
endforeach
Loading

0 comments on commit aebcef8

Please sign in to comment.