Exemplo n.º 1
0
    def test_apicalls_children(self):
        # given
        expected_grandchild_api = ("printf", ["grandchild started\n"], 19)
        expected_child_api = ("printf", ["child started\n"], 14)
        expected_parent_api = ("printf", ["parent started\n"], 15)
        pids = Set()
        output = []
        # when
        for call in apicalls(self.current_target(), run_as_root=False):
            output.append(call)
            pids.add(call.pid)

        matched_grandchild = [
            x for x in output
            if (x.api, x.args, x.retval) == expected_grandchild_api
        ]
        matched_child = [
            x for x in output
            if (x.api, x.args, x.retval) == expected_child_api
        ]
        matched_parent = [
            x for x in output
            if (x.api, x.args, x.retval) == expected_parent_api
        ]
        # then
        self.assertEqual(len(matched_grandchild), 1)
        self.assertEqual(len(matched_child), 1)
        self.assertEqual(len(matched_parent), 1)
Exemplo n.º 2
0
 def test_apicalls_root(self):
     # given
     expected_api = ("printf", ["I'm root!\n"], 10)
     output = []
     # when
     for call in apicalls(self.current_target(), run_as_root=True):
         output.append(call)
     # then
     matched = [x for x in output if (x.api, x.args, x.retval) == expected_api]
     self.assertEqual(len(matched), 1)
Exemplo n.º 3
0
 def test_apicalls_basic(self):
     # given
     expected_api = ("system", ["whoami"], 0)
     output = []
     # when
     for call in apicalls(self.current_target()):
         output.append(call)
     # then
     matched = [x for x in output if (x.api, x.args, x.retval) == expected_api]
     self.assertEqual(len(matched), 1)
Exemplo n.º 4
0
 def test_apicalls_errno_root(self):
     # given
     expected_api = ("fopen", ["doesn't matter", "r"], 0, 2)
     # when
     output = []
     for call in apicalls(self.current_target(), run_as_root=True):
         output.append(call)
     matched = [x for x in output if (x.api, x.args, x.retval, x.errno) == expected_api]
     # then
     self.assertEqual(len(matched), 1)
Exemplo n.º 5
0
 def test_apicalls_from_dynamic_library_root(self):
     # given
     expected_api = ("rb_isalpha", ["a"], 1)
     # when
     output = []
     for call in apicalls(self.current_target(), run_as_root=True):
         output.append(call)
     matched = [x for x in output if (x.api, x.args, x.retval) == expected_api]
     # then
     self.assertEqual(len(matched), 1)
Exemplo n.º 6
0
 def test_apicalls_with_args(self):
     # given
     expected_api = ("atoi", ["666"])
     args = ["666", "-k", "bar"]
     output = []
     # when
     for call in apicalls(self.current_target(), args=args):
         output.append(call)
     # then
     matched = [x for x in output if (x.api, x.args) == expected_api]
     self.assertEqual(len(matched), 1)
Exemplo n.º 7
0
 def test_apicalls_with_args(self):
     # given
     expected_api = ("atoi", ["666"])
     args = ["666", "-k", "bar"]
     output = []
     # when
     for call in apicalls(self.current_target(), args=args):
         output.append(call)
     # then
     matched = [x for x in output if (x.api, x.args) == expected_api]
     self.assertEqual(len(matched), 1)
Exemplo n.º 8
0
 def test_apicalls_root(self):
     # given
     expected_api = ("printf", ["I'm root!\n"], 10)
     output = []
     # when
     for call in apicalls(self.current_target(), run_as_root=True):
         output.append(call)
     # then
     matched = [
         x for x in output if (x.api, x.args, x.retval) == expected_api
     ]
     self.assertEqual(len(matched), 1)
Exemplo n.º 9
0
 def test_apicalls_from_dynamic_library_root(self):
     # given
     expected_api = ("rb_isalpha", ["a"], 1)
     # when
     output = []
     for call in apicalls(self.current_target(), run_as_root=True):
         output.append(call)
     matched = [
         x for x in output if (x.api, x.args, x.retval) == expected_api
     ]
     # then
     self.assertEqual(len(matched), 1)
Exemplo n.º 10
0
 def test_apicalls_basic(self):
     # given
     expected_api = ("system", ["whoami"], 0)
     output = []
     # when
     for call in apicalls(self.current_target()):
         output.append(call)
     # then
     matched = [
         x for x in output if (x.api, x.args, x.retval) == expected_api
     ]
     self.assertEqual(len(matched), 1)
Exemplo n.º 11
0
 def test_apicalls_errno_root(self):
     # given
     expected_api = ("fopen", ["doesn't matter", "r"], 0, 2)
     # when
     output = []
     for call in apicalls(self.current_target(), run_as_root=True):
         output.append(call)
     matched = [
         x for x in output
         if (x.api, x.args, x.retval, x.errno) == expected_api
     ]
     # then
     self.assertEqual(len(matched), 1)
Exemplo n.º 12
0
    def test_apicalls_children_root(self):
        # given
        expected_grandchild_api = ("printf", ["grandchild started\n"], 19)
        expected_child_api = ("printf", ["child started\n"], 14)
        expected_parent_api = ("printf", ["parent started\n"], 15)
        pids = Set()
        output = []
        # when
        for call in apicalls(self.current_target(), run_as_root=True):
            output.append(call)
            pids.add(call.pid)

        matched_grandchild = [x for x in output if (x.api, x.args, x.retval) == expected_grandchild_api]
        matched_child = [x for x in output if (x.api, x.args, x.retval) == expected_child_api]
        matched_parent = [x for x in output if (x.api, x.args, x.retval) == expected_parent_api]
        # then
        self.assertEqual(len(matched_grandchild), 1)
        self.assertEqual(len(matched_child), 1)
        self.assertEqual(len(matched_parent), 1)
Exemplo n.º 13
0
 def test_apicalls_without_target(self):
     with self.assertRaisesRegexp(Exception,
                                  "Invalid target for apicalls()"):
         for call in apicalls(None):
             pass
Exemplo n.º 14
0
 def test_apicalls_without_target(self):
     with self.assertRaisesRegexp(Exception, "Invalid target for apicalls()"):
         for call in apicalls(None):
             pass