diff options
| author | Darius Makovsky <traveltissues@protonmail.com> | 2019-12-24 12:00:38 +0000 |
|---|---|---|
| committer | Darius Makovsky <traveltissues@protonmail.com> | 2020-01-08 13:46:58 +0000 |
| commit | d3529b9d9a20b727914da0b04889bc6277f6238f (patch) | |
| tree | a9029039b8f32b2f019fae3ec50c0c487e984159 | |
| parent | c80fe229f75980787d338f919c78126733ce72ab (diff) | |
| download | buildstream-d3529b9d9a20b727914da0b04889bc6277f6238f.tar.gz | |
tests: improve RE workspace test
tests: additional incremental test
test: incremental conditions are not effective until modification
| -rw-r--r-- | tests/remoteexecution/workspace.py | 115 |
1 files changed, 61 insertions, 54 deletions
diff --git a/tests/remoteexecution/workspace.py b/tests/remoteexecution/workspace.py index b810bf18f..356d30bf2 100644 --- a/tests/remoteexecution/workspace.py +++ b/tests/remoteexecution/workspace.py @@ -2,6 +2,7 @@ # pylint: disable=redefined-outer-name import os +import re import shutil import pytest @@ -14,7 +15,8 @@ pytestmark = pytest.mark.remoteexecution DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project") MKFILEAM = os.path.join("src", "Makefile.am") MKFILE = os.path.join("src", "Makefile") -MAIN = os.path.join("src", "main.o") +MAINO = os.path.join("src", "main.o") +MAIN = os.path.join("src", "main.c") CFGMARK = "config-time" BLDMARK = "build-time" @@ -30,7 +32,7 @@ def files(): "configure.ac", "compile", "src", - os.path.join("src", "main.c"), + MAIN, MKFILEAM, "Makefile.am", ] @@ -55,7 +57,7 @@ def files(): os.path.join("src", ".deps"), os.path.join("src", ".deps", "main.Po"), MKFILE, - MAIN, + MAINO, CFGMARK, BLDMARK, os.path.join("src", "Makefile.in"), @@ -132,6 +134,7 @@ def check_buildtree( inp_times = [] gen_times = [] output = result.output.splitlines() + maino = os.sep + os.path.join("src", "hello") for line in output: assert "::" in line @@ -143,8 +146,12 @@ def check_buildtree( if incremental: if fname in input_files: + if fname != os.sep + MAIN: + typical_inptime = mtime inp_times.append(mtime) else: + if fname != maino: + typical_gentime = mtime gen_times.append(mtime) # all expected files should have been found @@ -152,17 +159,12 @@ def check_buildtree( assert filename in buildtree if incremental: - # at least inputs should be older than generated files - assert not any([inp_time > gen_time for inp_time in inp_times for gen_time in gen_times]) - - makefile = os.sep + "Makefile" - makefile_am = os.sep + "Makefile.am" - mainc = os.sep + os.path.join("src", "main.c") - maino = os.sep + os.path.join("src", "hello") - testfiles = [makefile, makefile_am, mainc, maino] - if all([testfile in buildtree for testfile in testfiles]): - assert buildtree[makefile] < buildtree[makefile_am] - assert buildtree[mainc] < buildtree[maino] + # the source file was changed so should be more recent than other input files + # it should be older than the main object. + # The main object should be more recent than generated files. + assert buildtree[os.sep + MAIN] > typical_inptime + assert buildtree[maino] > buildtree[os.sep + MAIN] + assert buildtree[maino] > typical_gentime return buildtree @@ -178,7 +180,7 @@ def get_timemark(cli, project, element_name, marker): @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize( - "modification", [pytest.param("none"), pytest.param("content"), pytest.param("time"),], + "modification", [pytest.param("content"), pytest.param("time"),], ) @pytest.mark.parametrize( "buildtype", @@ -190,10 +192,7 @@ def get_timemark(cli, project, element_name, marker): ], ) def test_workspace_build(cli, tmpdir, datafiles, modification, buildtype): - incremental = False - if buildtype == "incremental": - incremental = True - + incremental = buildtype == "incremental" project = str(datafiles) checkout = os.path.join(cli.directory, "checkout") workspace = os.path.join(cli.directory, "workspace") @@ -229,14 +228,17 @@ def test_workspace_build(cli, tmpdir, datafiles, modification, buildtype): # build the element and cache the buildtree result = cli.run(project=project, args=build) result.assert_success() + assert cli.get_element_state(project, element_name) == "cached" + build_key = cli.get_element_key(project, element_name) # check that the local workspace is unchanged assert_contains(workspace, input_files, strict=True) assert ws_times == get_mtimes(workspace) # check modified workspace dir was cached and save the time - # build was run - build_mtimes = check_buildtree(cli, project, element_name, input_files, generated_files, incremental=incremental) + # build was run. Incremental build conditions do not apply since the workspace + # was initially opened using magic timestamps. + build_times = check_buildtree(cli, project, element_name, input_files, generated_files, incremental=False) build_timemark = get_timemark(cli, project, element_name, (os.sep + BLDMARK)) # check that the artifacts are available @@ -248,45 +250,50 @@ def test_workspace_build(cli, tmpdir, datafiles, modification, buildtype): # rebuild the element result = cli.run(project=project, args=build) result.assert_success() - # this should all be cached - # so the buildmark time should be the same - rebuild_mtimes = check_buildtree(cli, project, element_name, input_files, generated_files, incremental=incremental) + assert cli.get_element_state(project, element_name) == "cached" + rebuild_key = cli.get_element_key(project, element_name) + assert rebuild_key == build_key + rebuild_times = check_buildtree(cli, project, element_name, input_files, generated_files, incremental=False) rebuild_timemark = get_timemark(cli, project, element_name, (os.sep + BLDMARK)) + # buildmark time should be the same assert build_timemark == rebuild_timemark - assert build_mtimes == rebuild_mtimes + # the build was re-executed on a workspace source caching buildtrees so the times should be updated + assert all([rebuild_times[fname] > build_times[fname] for fname in rebuild_times]) # modify the open workspace and rebuild - if modification != "none": - assert os.path.exists(newfile_path) - - if modification == "time": - # touch a file in the workspace and save the mtime - os.utime(newfile_path) - - elif modification == "content": - # change a source file - with open(newfile_path, "w") as fdata: - fdata.write("anotherstring") - - # refresh input times - ws_times = get_mtimes(workspace) + main_path = os.path.join(workspace, MAIN) + assert os.path.exists(main_path) + + if modification == "time": + # touch a file in the workspace and save the mtime + os.utime(main_path) + touched_time = os.stat(main_path).st_mtime + + elif modification == "content": + # change a source file (there's a race here but it's not serious) + with open(main_path, "r") as fdata: + data = fdata.readlines() + with open(main_path, "w") as fdata: + for line in data: + fdata.write(re.sub(r"Hello", "Goodbye", line)) + touched_time = os.stat(main_path).st_mtime + + # refresh input times + ws_times = get_mtimes(workspace) - # rebuild the element - result = cli.run(project=project, args=build) - result.assert_success() + # rebuild the element + result = cli.run(project=project, args=build) + result.assert_success() - rebuild_mtimes = check_buildtree( - cli, project, element_name, input_files, generated_files, incremental=incremental - ) - rebuild_timemark = get_timemark(cli, project, element_name, (os.sep + BLDMARK)) - assert build_timemark != rebuild_timemark + rebuild_mtimes = check_buildtree(cli, project, element_name, input_files, generated_files, incremental=incremental) + rebuild_timemark = get_timemark(cli, project, element_name, (os.sep + BLDMARK)) + assert build_timemark < rebuild_timemark - # check the times of the changed files - if incremental: - touched_time = os.stat(newfile_path).st_mtime - assert rebuild_mtimes[newfile] == touched_time + # check the times of the changed files + if incremental: + assert rebuild_mtimes[os.sep + MAIN] == touched_time - # Check workspace is unchanged - assert_contains(workspace, input_files, strict=True) - assert ws_times == get_mtimes(workspace) + # Check workspace is unchanged + assert_contains(workspace, input_files, strict=True) + assert ws_times == get_mtimes(workspace) |
