Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP/TEST: Instrumentedfile #67

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
872 changes: 141 additions & 731 deletions python_src/program_markers/instrumenter.py

Large diffs are not rendered by default.

788 changes: 788 additions & 0 deletions python_src/program_markers/iprogram.py

Large diffs are not rendered by default.

318 changes: 201 additions & 117 deletions python_src/program_markers/markers.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion python_src/test/dce_and_vr_instrument_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_instrumentation() -> None:
)
)

assert all_markers == set(iprogram.enabled_markers)
assert all_markers == set(iprogram.enabled_markers())

gcc = get_system_gcc_O0()
assert all_markers == set(iprogram.find_non_eliminated_markers(gcc))
Expand Down
91 changes: 50 additions & 41 deletions python_src/test/dce_instrumenter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,21 @@
ObjectCompilationOutput,
SourceProgram,
)
from program_markers.instrumenter import (
find_non_eliminated_markers_impl,
instrument_program,
rename_markers,
)
from program_markers.instrumenter import instrument_program
from program_markers.iprogram import find_non_eliminated_markers_impl, rename_markers
from program_markers.markers import (
AsmCommentEmptyOperandsStrategy,
AsmCommentGlobalOutOperandStrategy,
AsmCommentLocalOutOperandStrategy,
AsmCommentStaticVolatileGlobalOutOperandStrategy,
AsmCommentStrategy,
AsmCommentVolatileGlobalOutOperandStrategy,
AsmCommentDetectionStrategy,
AsmCommentEmptyOperandsDetectionStrategy,
AsmCommentGlobalOutOperandDetectionStrategy,
AsmCommentLocalOutOperandDetectionStrategy,
AsmCommentStaticVolatileGlobalOutOperandDetectionStrategy,
AsmCommentVolatileGlobalOutOperandDetectionStrategy,
DCEMarker,
FunctionCallStrategy,
GlobalIntStrategy,
GlobalVolatileIntStrategy,
LocalVolatileIntStrategy,
StaticVolatileGlobalIntStrategy,
FunctionCallDetectionStrategy,
GlobalIntDetectionStrategy,
GlobalVolatileIntDetectionStrategy,
LocalVolatileIntDetectionStrategy,
StaticVolatileGlobalIntDetectionStrategy,
)

from .utils import get_system_gcc_O0, get_system_gcc_O3
Expand All @@ -37,7 +34,11 @@ def test_parsing_with_tailcalls() -> None:
"""
markers = (DCEMarker.from_str("DCEMarker0_"),)
assert (
set(find_non_eliminated_markers_impl(asm, markers, FunctionCallStrategy()))
set(
find_non_eliminated_markers_impl(
asm, markers, FunctionCallDetectionStrategy()
)
)
) == set((DCEMarker.from_str("DCEMarker0_"),))

asm = """
Expand All @@ -50,7 +51,11 @@ def test_parsing_with_tailcalls() -> None:
jmp DCEMarker0_
"""
assert (
set(find_non_eliminated_markers_impl(asm, markers, FunctionCallStrategy()))
set(
find_non_eliminated_markers_impl(
asm, markers, FunctionCallDetectionStrategy()
)
)
) == set((DCEMarker.from_str("DCEMarker0_"),))


Expand All @@ -69,7 +74,7 @@ def test_instrumentation() -> None:
)
assert set(
(DCEMarker.from_str("DCEMarker0_"), DCEMarker.from_str("DCEMarker1_"))
) == set(iprogram.enabled_markers)
) == set(iprogram.enabled_markers())

gcc = get_system_gcc_O0()
assert set(
Expand Down Expand Up @@ -105,8 +110,10 @@ def test_disable_markers() -> None:
iprogram.disable_markers((DCEMarker.from_str("DCEMarker2_"),))

iprogram0 = iprogram.disable_markers((DCEMarker.from_str("DCEMarker1_"),))
assert set((DCEMarker.from_str("DCEMarker1_"),)) == set(iprogram0.disabled_markers)
assert set((DCEMarker.from_str("DCEMarker0_"),)) == set(iprogram0.enabled_markers)
assert set((DCEMarker.from_str("DCEMarker1_"),)) == set(
iprogram0.disabled_markers()
)
assert set((DCEMarker.from_str("DCEMarker0_"),)) == set(iprogram0.enabled_markers())
assert set((DCEMarker.from_str("DCEMarker0_"),)) == set(
iprogram0.find_non_eliminated_markers(gcc)
)
Expand All @@ -120,7 +127,9 @@ def test_disable_markers() -> None:
assert iprogram0 == iprogram0.disable_markers((DCEMarker.from_str("DCEMarker1_"),))

iprogram1 = iprogram.disable_markers((DCEMarker.from_str("DCEMarker0_"),))
assert set((DCEMarker.from_str("DCEMarker0_"),)) == set(iprogram1.disabled_markers)
assert set((DCEMarker.from_str("DCEMarker0_"),)) == set(
iprogram1.disabled_markers()
)
assert set((DCEMarker.from_str("DCEMarker1_"),)) == set(
iprogram1.find_non_eliminated_markers(gcc)
)
Expand All @@ -137,7 +146,7 @@ def test_disable_markers() -> None:
DCEMarker.from_str("DCEMarker0_"),
DCEMarker.from_str("DCEMarker1_"),
)
) == set(iprogram1_1.disabled_markers)
) == set(iprogram1_1.disabled_markers())
assert set() == set(iprogram1_1.find_non_eliminated_markers(gcc))
assert set(
(
Expand All @@ -157,7 +166,7 @@ def test_disable_markers() -> None:
DCEMarker.from_str("DCEMarker0_"),
DCEMarker.from_str("DCEMarker1_"),
)
) == set(iprogram2.disabled_markers)
) == set(iprogram2.disabled_markers())
assert set(()) == set(iprogram2.find_non_eliminated_markers(gcc))
assert set(
(DCEMarker.from_str("DCEMarker0_"), DCEMarker.from_str("DCEMarker1_"))
Expand Down Expand Up @@ -192,9 +201,9 @@ def test_unreachable() -> None:
# Making the same marker unreachable twice shouldn't have any effect
iprogram == iprogram.make_markers_unreachable((DCEMarker.from_str("DCEMarker1_"),))
assert set((DCEMarker.from_str("DCEMarker1_"),)) == set(
iprogram.unreachable_markers
iprogram.unreachable_markers()
)
assert set((DCEMarker.from_str("DCEMarker0_"),)) == set(iprogram.enabled_markers)
assert set((DCEMarker.from_str("DCEMarker0_"),)) == set(iprogram.enabled_markers())

asm = gcc.compile_program(iprogram, ASMCompilationOutput()).output.read()
assert "bar" not in asm
Expand Down Expand Up @@ -227,9 +236,9 @@ def test_disable_and_unreachable() -> None:
# We can't make ureachable a marker that was already disabled
iprogram.make_markers_unreachable((DCEMarker.from_str("DCEMarker0_"),))
assert set((DCEMarker.from_str("DCEMarker1_"),)) == set(
iprogram.unreachable_markers
iprogram.unreachable_markers()
)
assert set((DCEMarker.from_str("DCEMarker0_"),)) == set(iprogram.disabled_markers)
assert set((DCEMarker.from_str("DCEMarker0_"),)) == set(iprogram.disabled_markers())

assert set(()) == set(iprogram.find_non_eliminated_markers(gcc))
assert set(
Expand Down Expand Up @@ -265,17 +274,17 @@ def test_strategies() -> None:
)

all_marker_strategies = (
FunctionCallStrategy(),
AsmCommentStrategy(),
AsmCommentEmptyOperandsStrategy(),
AsmCommentLocalOutOperandStrategy(),
AsmCommentGlobalOutOperandStrategy(),
AsmCommentVolatileGlobalOutOperandStrategy(),
AsmCommentStaticVolatileGlobalOutOperandStrategy(),
LocalVolatileIntStrategy(),
GlobalVolatileIntStrategy(),
GlobalIntStrategy(),
StaticVolatileGlobalIntStrategy(),
FunctionCallDetectionStrategy(),
AsmCommentDetectionStrategy(),
AsmCommentEmptyOperandsDetectionStrategy(),
AsmCommentLocalOutOperandDetectionStrategy(),
AsmCommentGlobalOutOperandDetectionStrategy(),
AsmCommentVolatileGlobalOutOperandDetectionStrategy(),
AsmCommentStaticVolatileGlobalOutOperandDetectionStrategy(),
LocalVolatileIntDetectionStrategy(),
GlobalVolatileIntDetectionStrategy(),
GlobalIntDetectionStrategy(),
StaticVolatileGlobalIntDetectionStrategy(),
)
gcc = get_system_gcc_O3()

Expand Down Expand Up @@ -310,10 +319,10 @@ def test_marker_renaming() -> None:

assert set(
(DCEMarker.from_str("DCEMarker0_"), DCEMarker.from_str("DCEMarker1_"))
) == set(iprogram0.enabled_markers)
) == set(iprogram0.enabled_markers())
assert set(
(DCEMarker.from_str("DCEMarker2_"), DCEMarker.from_str("DCEMarker3_"))
) == set(iprogram1.enabled_markers)
) == set(iprogram1.enabled_markers())

assert DCEMarker.from_str("DCEMarker2_").macro() in iprogram1.code
assert DCEMarker.from_str("DCEMarker3_").macro() in iprogram1.code
Expand Down
56 changes: 12 additions & 44 deletions python_src/test/instrumented_program_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import pytest
from diopter.compiler import Language
from program_markers.instrumenter import InstrumentedProgram
from program_markers.markers import DCEMarker, FunctionCallStrategy
from program_markers.iprogram import InstrumentedProgram
from program_markers.markers import (
DCEMarker,
EnableEmitter,
FunctionCallDetectionStrategy,
)


def make_marker(i: int) -> DCEMarker:
Expand All @@ -11,48 +15,12 @@ def make_marker(i: int) -> DCEMarker:
def test_no_duplicate_marker_ids() -> None:
with pytest.raises(AssertionError):
InstrumentedProgram(
marker_strategy=FunctionCallStrategy(),
marker_strategy=FunctionCallDetectionStrategy(),
language=Language.C,
code="bla bla",
enabled_markers=(make_marker(1), make_marker(1)),
)
with pytest.raises(AssertionError):
InstrumentedProgram(
marker_strategy=FunctionCallStrategy(),
language=Language.C,
code="bla bla",
enabled_markers=(make_marker(1),),
disabled_markers=(make_marker(1),),
)
with pytest.raises(AssertionError):
InstrumentedProgram(
marker_strategy=FunctionCallStrategy(),
language=Language.C,
code="bla bla",
enabled_markers=(make_marker(1),),
unreachable_markers=(make_marker(1),),
)
with pytest.raises(AssertionError):
InstrumentedProgram(
marker_strategy=FunctionCallStrategy(),
language=Language.C,
code="bla bla",
enabled_markers=(make_marker(1),),
aborted_markers=(make_marker(1),),
)
with pytest.raises(AssertionError):
InstrumentedProgram(
marker_strategy=FunctionCallStrategy(),
language=Language.C,
code="bla bla",
enabled_markers=(make_marker(1),),
tracked_markers=(make_marker(1),),
)
with pytest.raises(AssertionError):
InstrumentedProgram(
marker_strategy=FunctionCallStrategy(),
language=Language.C,
code="bla bla",
enabled_markers=(make_marker(1),),
tracked_for_refinement_markers=(make_marker(1),),
markers=(make_marker(1), make_marker(1)),
directive_emitters={
make_marker(1): EnableEmitter(FunctionCallDetectionStrategy()),
make_marker(1): EnableEmitter(FunctionCallDetectionStrategy()),
},
)
10 changes: 5 additions & 5 deletions python_src/test/preprocessing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ def test_preprocessing() -> None:
)
m0 = DCEMarker.from_str("DCEMarker0_")
m1 = DCEMarker.from_str("DCEMarker1_")
assert set((m0, m1)) == set(iprogram.all_markers())
assert set((m0, m1)) == set(iprogram.markers)
gcc = get_system_gcc_O0()

# preprocess without any disabled or unreachable markers
iprogram_p = iprogram.preprocess_disabled_and_unreachable_markers(gcc)
assert set((m0, m1)) == set(iprogram_p.all_markers())
assert set((m0, m1)) == set(iprogram_p.markers)
assert set((m0, m1)) == set(iprogram_p.find_non_eliminated_markers(gcc))
assert set() == set(iprogram_p.find_eliminated_markers(gcc))

# preprocess with an unreachable marker
iprogram_u = iprogram.make_markers_unreachable(
[m0]
).preprocess_disabled_and_unreachable_markers(gcc)
assert set((m1,)) == set(iprogram_u.all_markers())
assert set((m1,)) == set(iprogram_u.markers)
assert set((m1,)) == set(iprogram_u.find_non_eliminated_markers(gcc))
assert set() == set(iprogram_u.find_eliminated_markers(gcc))
assert "__builtin_unreachable()" in iprogram_u.code
Expand All @@ -43,7 +43,7 @@ def test_preprocessing() -> None:
iprogram_d = iprogram.disable_markers(
[m1]
).preprocess_disabled_and_unreachable_markers(gcc)
assert set((m0,)) == set(iprogram_d.all_markers())
assert set((m0,)) == set(iprogram_d.markers)
assert set((m0,)) == set(iprogram_d.find_non_eliminated_markers(gcc))
assert set() == set(iprogram_d.find_eliminated_markers(gcc))
assert m0.macro() in iprogram_d.code
Expand All @@ -55,7 +55,7 @@ def test_preprocessing() -> None:
.disable_markers([m0])
.preprocess_disabled_and_unreachable_markers(gcc)
)
assert set() == set(iprogram_ud.all_markers())
assert set() == set(iprogram_ud.markers)
assert set() == set(iprogram_ud.find_non_eliminated_markers(gcc))
assert set() == set(iprogram_ud.find_eliminated_markers(gcc))
assert m0.macro() not in iprogram_ud.code
Expand Down
Loading