-
-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Running a `./pants lint` across the whole repo revealed an issue accessing a non-existant `self.linker.platform` attribute in `LinkSharedLibraries`. Add basic unit tests to exercise task execution with a full cache miss and then a full hit.
- Loading branch information
Showing
7 changed files
with
164 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
python_tests( | ||
dependencies=[ | ||
':native_task_test_base', | ||
'src/python/pants/backend/native/targets', | ||
'src/python/pants/backend/native/tasks', | ||
], | ||
tags={'platform_specific_behavior'}, | ||
) | ||
|
||
python_library( | ||
name='native_task_test_base', | ||
sources=['native_task_test_base.py'], | ||
dependencies=[ | ||
'src/python/pants/backend/native', | ||
'src/python/pants/backend/native/targets', | ||
'tests/python/pants_test:task_test_base', | ||
], | ||
) |
45 changes: 45 additions & 0 deletions
45
tests/python/pants_test/backend/native/tasks/native_task_test_base.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# coding=utf-8 | ||
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from textwrap import dedent | ||
|
||
from pants.backend.native import register | ||
from pants.backend.native.targets.native_library import CppLibrary | ||
from pants_test.task_test_base import TaskTestBase | ||
|
||
|
||
class NativeTaskTestBase(TaskTestBase): | ||
|
||
@classmethod | ||
def rules(cls): | ||
return super(NativeTaskTestBase, cls).rules() + register.rules() | ||
|
||
def create_simple_cpp_library(self, **kwargs): | ||
self.create_file('src/cpp/test/test.hpp', contents=dedent(""" | ||
#ifndef __TEST_HPP__ | ||
#define __TEST_HPP__ | ||
int test(int); | ||
extern "C" int test_exported(int); | ||
#endif | ||
""")) | ||
self.create_file('src/cpp/test/test.cpp', contents=dedent(""" | ||
#include "test.hpp" | ||
int test(int x) { | ||
return x / 137; | ||
} | ||
extern "C" int test_exported(int x) { | ||
return test(x * 42); | ||
} | ||
""")) | ||
return self.make_target(spec='src/cpp/test', | ||
target_type=CppLibrary, | ||
sources=['test.hpp', 'test.cpp'], | ||
**kwargs) |
34 changes: 34 additions & 0 deletions
34
tests/python/pants_test/backend/native/tasks/test_cpp_compile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# coding=utf-8 | ||
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import os | ||
|
||
from pants.backend.native.tasks.cpp_compile import CppCompile | ||
from pants.backend.native.tasks.native_external_library_fetch import NativeExternalLibraryFetch | ||
from pants_test.backend.native.tasks.native_task_test_base import NativeTaskTestBase | ||
|
||
|
||
class CppCompileTest(NativeTaskTestBase): | ||
@classmethod | ||
def task_type(cls): | ||
return CppCompile | ||
|
||
def test_caching(self): | ||
cpp = self.create_simple_cpp_library() | ||
|
||
native_elf_fetch_task_type = self.synthesize_task_subtype(NativeExternalLibraryFetch, | ||
'native_elf_fetch_scope') | ||
|
||
context = self.context(target_roots=[cpp], for_task_types=[native_elf_fetch_task_type]) | ||
|
||
native_elf_fetch = native_elf_fetch_task_type(context, | ||
os.path.join(self.pants_workdir, | ||
'native_elf_fetch')) | ||
native_elf_fetch.execute() | ||
|
||
cpp_compile = self.create_task(context) | ||
cpp_compile.execute() | ||
cpp_compile.execute() |
40 changes: 40 additions & 0 deletions
40
tests/python/pants_test/backend/native/tasks/test_link_shared_libraries.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# coding=utf-8 | ||
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import os | ||
|
||
from pants.backend.native.targets.native_artifact import NativeArtifact | ||
from pants.backend.native.tasks.cpp_compile import CppCompile | ||
from pants.backend.native.tasks.link_shared_libraries import LinkSharedLibraries | ||
from pants.backend.native.tasks.native_external_library_fetch import NativeExternalLibraryFetch | ||
from pants_test.backend.native.tasks.native_task_test_base import NativeTaskTestBase | ||
|
||
|
||
class LinkSharedLibrariesTest(NativeTaskTestBase): | ||
@classmethod | ||
def task_type(cls): | ||
return LinkSharedLibraries | ||
|
||
def test_caching(self): | ||
cpp = self. create_simple_cpp_library(ctypes_native_library=NativeArtifact(lib_name='test'),) | ||
|
||
native_elf_fetch_task_type = self.synthesize_task_subtype(NativeExternalLibraryFetch, | ||
'native_elf_fetch_scope') | ||
cpp_compile_task_type = self.synthesize_task_subtype(CppCompile, 'cpp_compile_scope') | ||
context = self.context(target_roots=[cpp], | ||
for_task_types=[native_elf_fetch_task_type, cpp_compile_task_type]) | ||
|
||
native_elf_fetch = native_elf_fetch_task_type(context, | ||
os.path.join(self.pants_workdir, | ||
'native_elf_fetch')) | ||
native_elf_fetch.execute() | ||
|
||
cpp_compile = cpp_compile_task_type(context, os.path.join(self.pants_workdir, 'cpp_compile')) | ||
cpp_compile.execute() | ||
|
||
link_shared_libraries = self.create_task(context) | ||
link_shared_libraries.execute() | ||
link_shared_libraries.execute() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters