Skip to content

Commit

Permalink
Added missing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrodin authored and kaoudis committed Jan 25, 2023
1 parent bb2540e commit 7dbc84b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/test_assert.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <cassert>
#include <unistd.h>

int main(int argc, char *argv[]) {

char data[2];
read(0, data, sizeof(data));

// This will terminate the program unexpectedly (tdag sizes might not be updated).
assert(data[0] == data[1]);

}
32 changes: 32 additions & 0 deletions tests/test_assert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from pathlib import Path
import subprocess
import pytest
from polytracker import taint_dag, PolyTrackerTrace
from typing import cast


@pytest.mark.program_trace("test_assert.cpp")
def test_assert(instrumented_binary: Path, trace_file: Path):
stdin_data = "ab"

subprocess.run(
[str(instrumented_binary)],
input=stdin_data.encode("utf-8"),
env={"POLYDB": str(trace_file), "POLYTRACKER_STDIN_SOURCE": str(1)},
)
program_trace = PolyTrackerTrace.load(trace_file)
assert isinstance(program_trace, taint_dag.TDProgramTrace)

tdfile = program_trace.tdfile
assert tdfile.label_count == 4

t1 = cast(taint_dag.TDSourceNode, tdfile.decode_node(1))
assert isinstance(t1, taint_dag.TDSourceNode)

t2 = cast(taint_dag.TDSourceNode, tdfile.decode_node(2))
assert isinstance(t2, taint_dag.TDSourceNode)

t3 = cast(taint_dag.TDSourceNode, tdfile.decode_node(3))
assert isinstance(t3, taint_dag.TDRangeNode)
assert t3.first == 1
assert t3.last == 2

0 comments on commit 7dbc84b

Please sign in to comment.