def test_add_parameter(self): setup = Setup() setup._setup = dummy_setup() setup.add_parameter('app1', 'func3', 2, '%s') expected = { 'app1': { 'func1': { 'traced': False, 'parameters': {}, 'mangled': 'mangledfunc1' }, 'func3': { 'traced': False, 'parameters': { 2: '%s' }, 'mangled': 'mangledfunc3' } }, 'app2': { 'func2': { 'traced': False, 'parameters': {}, 'mangled': 'mangledfunc2' }, } } self.assertEqual(setup._setup, expected)
def test_remove_parameter(self): setup = Setup() setup._setup = { 'app': { 'func': { 'traced': False, 'parameters': { 1: '%s', 4: '%d' } } } } setup.remove_parameter('app', 'func', 4) expected = { 'app': { 'func': { 'traced': False, 'parameters': { 1: '%s' } } } } self.assertEqual(setup._setup, expected)
def test_get_apps(self): setup = Setup() setup._setup = dummy_setup() result = setup.get_apps() self.assertEqual(result, ['app1', 'app2'])
def test_setup_function_to_trace_with_mangled_name(self): setup = Setup() setup._setup = dummy_setup() setup.setup_function_to_trace('app1', 'mangledfunc1') expected = { 'app1': { 'func1': { 'traced': True, 'parameters': {}, 'mangled': 'mangledfunc1' }, 'func3': { 'traced': False, 'parameters': {}, 'mangled': 'mangledfunc3' } }, 'app2': { 'func2': { 'traced': False, 'parameters': {}, 'mangled': 'mangledfunc2' }, } } self.assertEqual(setup._setup, expected)
def test_get_parameters(self): setup = Setup() setup._setup = {'app': {'func': {'traced': False, 'parameters': {1: '%s', 4: '%d'}, 'offset': 0}}} result = setup.get_parameters('app', 'func') self.assertEqual(result, {1: '%s', 4: '%d'})
def test_remove_function_from_trace_with_mangled_name(self): setup = Setup() setup._setup = dummy_setup() setup.setup_function_to_trace('app1', 'func1') setup.remove_function_from_trace('app1', 'mangledfunc1') self.assertEqual(setup._setup, dummy_setup())
def test_get_setup_of_app(self): setup = Setup() setup._setup = dummy_setup() result = setup.get_setup_of_app('app1') expected = { 'func1': {'traced': False, 'parameters': {}, 'mangled': 'mangledfunc1', 'offset': 0}, 'func3': {'traced': False, 'parameters': {}, 'mangled': 'mangledfunc3', 'offset': 0} } self.assertEqual(result, expected)
def test_remove_function_from_trace_with_mangled_name(self, get_offset_for_function): setup = Setup() setup._setup = dummy_setup() setup.setup_function_to_trace('app1', 'func1') setup.remove_function_from_trace('app1', 'mangledfunc1') expected_setup = dummy_setup() expected_setup['app1']['func1']['offset'] = 8 self.assertEqual(setup._setup, expected_setup)
def test_remove_app(self): setup = Setup() setup._setup = dummy_setup() setup.remove_app('app2') expected = { 'app1': { 'func1': {'traced': False, 'parameters': {}, 'mangled': 'mangledfunc1', 'offset': 0}, 'func3': {'traced': False, 'parameters': {}, 'mangled': 'mangledfunc3', 'offset': 0} } } self.assertEqual(setup._setup, expected)
def test_setup_function_to_trace_with_demangled_name(self, get_offset_for_function): setup = Setup() setup._setup = dummy_setup() setup.setup_function_to_trace('app1', 'func1') expected = { 'app1': { 'func1': {'traced': True, 'parameters': {}, 'mangled': 'mangledfunc1', 'offset': 8}, 'func3': {'traced': False, 'parameters': {}, 'mangled': 'mangledfunc3', 'offset': 0} }, 'app2': { 'func2': {'traced': False, 'parameters': {}, 'mangled': 'mangledfunc2', 'offset': 0} } } self.assertEqual(setup._setup, expected)
def test_generate_bcc_args_with_multiple_values(self): setup = Setup() setup._setup = { 'app1': { 'func1': { 'mangled': 'mangled1', 'traced': True, 'parameters': { 4: '%s', 2: '%d' } }, 'func2': { 'mangled': 'mangled2', 'traced': False, 'parameters': {} } }, 'app2': { 'func3': { 'mangled': 'mangled3', 'traced': True, 'parameters': { 1: '%s', 5: '%d' } }, 'func4': { 'mangled': 'mangled4', 'traced': True, 'parameters': { 1: '%s', 2: '%f' } } } } result = setup.generate_bcc_args() expected = [ 'app1:mangled1 "%s %d", arg4, arg2', 'app2:mangled3 "%s %d", arg1, arg5', 'app2:mangled4 "%s %f", arg1, arg2', ] self.assertEqual(result, expected)
def test_init_binary_raises_error_if_binary_already_added(self): setup = Setup() setup._setup = dummy_setup() with self.assertRaises(BinaryAlreadyAddedError): setup.initialize_binary('app1')
def test_remove_function_from_trace_raises_error_if_function_not_exists( self): setup = Setup() setup._setup = dummy_setup() with self.assertRaises(FunctionNotInBinaryError): setup.remove_function_from_trace('app1', 'func4')