From 1ec985d0809f9880badf1188a4aaa6c3f005923e Mon Sep 17 00:00:00 2001
From: Rich Lane <rlane@bigswitch.com>
Date: Mon, 14 Sep 2015 17:21:39 -0700
Subject: [PATCH] add test for dump_func method

---
 tests/CMakeLists.txt           |  1 +
 tests/python/CMakeLists.txt    |  5 +++++
 tests/python/test_dump_func.py | 24 ++++++++++++++++++++++++
 tests/wrapper.sh.in            |  7 +++++++
 4 files changed, 37 insertions(+)
 create mode 100644 tests/python/CMakeLists.txt
 create mode 100755 tests/python/test_dump_func.py

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 8a10a0a1..bd66f842 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -5,3 +5,4 @@ configure_file(wrapper.sh.in "${CMAKE_CURRENT_BINARY_DIR}/wrapper.sh" @ONLY)
 set(TEST_WRAPPER ${CMAKE_CURRENT_BINARY_DIR}/wrapper.sh)
 
 add_subdirectory(cc)
+add_subdirectory(python)
diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt
new file mode 100644
index 00000000..911abbf1
--- /dev/null
+++ b/tests/python/CMakeLists.txt
@@ -0,0 +1,5 @@
+# Copyright (c) PLUMgrid, Inc.
+# Licensed under the Apache License, Version 2.0 (the "License")
+
+add_test(NAME py_test_dump_func WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+  COMMAND ${TEST_WRAPPER} py_dump_func simple ${CMAKE_CURRENT_SOURCE_DIR}/test_dump_func.py)
diff --git a/tests/python/test_dump_func.py b/tests/python/test_dump_func.py
new file mode 100755
index 00000000..a8ca5052
--- /dev/null
+++ b/tests/python/test_dump_func.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+# Copyright (c) PLUMgrid, Inc.
+# Licensed under the Apache License, Version 2.0 (the "License")
+
+# test program for the 'dump_func' method
+
+from bcc import BPF
+from unittest import main, TestCase
+
+class TestDumpFunc(TestCase):
+    def test_return(self):
+        b = BPF(text="""
+            int entry(void)
+            {
+                return 1;
+            }""")
+
+        self.assertEquals(
+            "\xb7\x00\x00\x00\x01\x00\x00\x00" +
+            "\x95\x00\x00\x00\x00\x00\x00\x00",
+            b.dump_func("entry"))
+
+if __name__ == "__main__":
+    main()
diff --git a/tests/wrapper.sh.in b/tests/wrapper.sh.in
index 61757998..49d49bee 100755
--- a/tests/wrapper.sh.in
+++ b/tests/wrapper.sh.in
@@ -39,6 +39,10 @@ function sudo_run() {
   sudo bash -c "PYTHONPATH=$PYTHONPATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH $cmd $1 $2"
   return $?
 }
+function simple_run() {
+  PYTHONPATH=$PYTHONPATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH $cmd $1 $2
+  return $?
+}
 
 case $kind in
   namespace)
@@ -47,6 +51,9 @@ case $kind in
   sudo)
     sudo_run $@
     ;;
+  simple)
+    simple_run $@
+    ;;
   *)
     echo "Invalid kind $kind"
     exit 1
-- 
2.30.9