Skip to content

Commit

Permalink
one test
Browse files Browse the repository at this point in the history
  • Loading branch information
carmeli-tamir committed Nov 22, 2019
1 parent 5660ed9 commit be4d1f5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ python:
- "3.6"

before_install:
- sudo apt-get -y install python3-pytest
- export DST_PROJECT=$PWD
- export LINUX_VERSION="linux-4.19.84"
- export KDIR=$PWD/$LINUX_VERSION
Expand All @@ -27,4 +28,5 @@ install:
- source repo.sh -i

script:
- echo "Succesfully compiled skunk.ko"
- cd user/test
- pytest -v
7 changes: 2 additions & 5 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
- Make travis ci
- check that skunk.py works after updating protobuf submodule (re compile protobuf)
- RE-create the protobuf-c PR and reference to old PR.0
- Check the kernel compiles using https://github.com/ZeekHuge/BeagleScope/blob/port_to_4.4.12-ti-r31%2B/.travis.yml
- TODO: commit the changes to repo.sh and .gitmodules and recheck the build https://travis-ci.com/carmeli-tamir/skunk/builds/135796888
- Check the python code works
- Implement tests for all 3 cases
- combine tests and setup?
- Improve documentation and open project to the public
- Reduce permissions for /dev/skunk
- Re-write skunk.py as a class
Expand Down
1 change: 0 additions & 1 deletion user/skunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def run_skunk():
ret = call_function_two_arg(skunk_device, "kallsyms_lookup_name",
1, skunk_pb2.FunctionCall.eight_byte,
"kallsyms_lookup_name", skunk_pb2.Argument.string)

print("Got adress of {}".format(hex(2**64 + ret.eight_byte))) # Printing 2's complement of the address

ret = call_function_two_arg(skunk_device, "round_jiffies",
Expand Down
55 changes: 55 additions & 0 deletions user/test/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import unittest
from unittest.mock import patch

import skunk
import skunk_pb2


class TestCalls(unittest.TestCase):

@staticmethod
def build_return_value(status, eight_byte, has_string):
return_kallsym_adress = skunk_pb2.ReturnValue()
return_kallsym_adress.status = status
return_kallsym_adress.eight_byte = eight_byte
return_kallsym_adress.has_string = has_string

return skunk.binary_length_and_value(return_kallsym_adress.SerializeToString(), return_kallsym_adress.ByteSize())

@staticmethod
def build_function_call_1_arg(return_type, function_name, arg_type, arg_value):
func_with_one_arg = skunk_pb2.FunctionCall()
func_with_one_arg.returnType = return_type
func_with_one_arg.numberOfArguments = 1
func_with_one_arg.name = function_name
func_with_one_arg.arg1.type = arg_type

if arg_type == skunk_pb2.Argument.string:
func_with_one_arg.arg1.arg_string = arg_value
elif arg_type == skunk_pb2.Argument.eight_byte:
func_with_one_arg.arg1.arg_eight_byte = arg_value
else:
raise ValueError("Unsupported argument type")

return skunk.binary_length_and_value(func_with_one_arg.SerializeToString(), func_with_one_arg.ByteSize())

@patch('skunk.fcntl')
def test_call_kallsyms(self, mock_requests):
ioctl_ret = self.build_return_value(skunk_pb2.ReturnValue.Success, 0x1ee7, False)
mock_requests.ioctl.return_value = ioctl_ret

ret = skunk.call_function_two_arg(
None,
"kallsyms_lookup_name",
1,
skunk_pb2.FunctionCall.eight_byte,
"kallsyms_lookup_name",
skunk_pb2.Argument.string
)

mock_requests.ioctl.assert_called_once_with(
None,
0xc008ee00,
self.build_function_call_1_arg(skunk_pb2.FunctionCall.eight_byte, "kallsyms_lookup_name", skunk_pb2.Argument.string, "kallsyms_lookup_name")
)
assert ret.eight_byte == 0x1ee7

0 comments on commit be4d1f5

Please sign in to comment.