bcc-lua: Add test for standalone `bcc-lua`
authorVicent Marti <tanoku@gmail.com>
Thu, 31 Mar 2016 06:22:45 +0000 (08:22 +0200)
committerVicent Marti <tanoku@gmail.com>
Fri, 1 Apr 2016 14:24:16 +0000 (16:24 +0200)
tests/lua/CMakeLists.txt
tests/lua/test_standalone.sh [new file with mode: 0755]

index 52c3826..0a01bfc 100644 (file)
@@ -9,4 +9,7 @@ if(LUAJIT)
 
        add_test(NAME lua_test_dump WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
                COMMAND ${TEST_WRAPPER} lua_test_dump sudo ${LUAJIT} test_dump.lua)
+
+       add_test(NAME lua_test_standalone WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+               COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_standalone.sh)
 endif()
diff --git a/tests/lua/test_standalone.sh b/tests/lua/test_standalone.sh
new file mode 100755 (executable)
index 0000000..4e45a77
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/bash
+# Copyright (c) GitHub, Inc.
+# Licensed under the Apache License, Version 2.0 (the "License")
+
+set -xe
+cd "src/lua"
+
+function fail {
+    echo "test failed: $1" >&2
+    exit 1
+}
+
+if [[ ! -x bcc-lua ]]; then
+    echo "bcc-lua not built --- skipping"
+    exit 0
+fi
+
+if ldd bcc-lua | grep -q luajit; then
+    fail "bcc-lua depends on libluajit"
+fi
+
+rm -f libbcc.so probe.lua
+echo "return function(BPF) print(\"Hello world\") end" > probe.lua
+
+if ./bcc-lua "probe.lua"; then
+    fail "bcc-lua runs without libbcc.so"
+fi
+
+if ! env LIBBCC_SO_PATH=../cc/libbcc.so ./bcc-lua "probe.lua"; then
+    fail "bcc-lua cannot load libbcc.so through the environment"
+fi
+
+ln -s ../cc/libbcc.so
+
+if ! ./bcc-lua "probe.lua"; then
+    fail "bcc-lua cannot find local libbcc.so"
+fi
+
+PROBE="../../../examples/lua/offcputime.lua"
+
+if ! sudo ./bcc-lua "$PROBE" -d 1 >/dev/null 2>/dev/null; then
+    fail "bcc-lua cannot run complex probes"
+fi
+
+rm -f libbcc.so probe.lua