1import nose
2import angr
3import os
4
5import logging
6l = logging.getLogger('angr.tests.test_multi_open_file')
7
8test_location = os.path.dirname(os.path.realpath(__file__))
9
10def test_multi_open_file():
11    test_bin = os.path.join(test_location, "..", "..", "binaries", "tests", "x86_64", "test_multi_open_file")
12    b = angr.Project(test_bin)
13
14    pg = b.factory.simulation_manager()
15    pg.active[0].options.discard("LAZY_SOLVES")
16    pg.explore()
17
18    nose.tools.assert_equal(len(pg.deadended), 1)
19
20    # See the source file in binaries/tests_src/test_multi_open_file.c
21    # for the tests run
22    for p in pg.deadended:
23        nose.tools.assert_true(p.posix.dumps(2) == b"")
24
25        # Check that the temp file was deleted
26        nose.tools.assert_equal(p.fs._files, {})
27
28        # Check that the deleted temp file contained the appropriate string
29        for event in p.history.events:
30            if event.type == 'fs_unlink':
31                simfile = p.fs.unlinks[event.objects['unlink_idx']][1]
32                nose.tools.assert_equal(simfile.concretize(), b'foobar and baz')
33                break
34        else:
35            assert False
36
37
38if __name__ == "__main__":
39    test_multi_open_file()
40