Commit e79676a7 authored by 4ast's avatar 4ast

Merge pull request #181 from iovisor/bblanco_dev

Reorganize cmake, some cleanups and test fixes.
parents 5d89d5fd 63640471
...@@ -7,7 +7,8 @@ set(CMAKE_BUILD_TYPE Release) ...@@ -7,7 +7,8 @@ set(CMAKE_BUILD_TYPE Release)
enable_testing() enable_testing()
include(scripts/GetGitRevisionDescription.cmake) include(cmake/GetGitRevisionDescription.cmake)
include(cmake/version.cmake)
get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS) get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
if(LIB64) if(LIB64)
set(LIBSUFFIX 64) set(LIBSUFFIX 64)
...@@ -45,7 +46,6 @@ set(CMAKE_C_FLAGS "-Wall") ...@@ -45,7 +46,6 @@ set(CMAKE_C_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall") set(CMAKE_CXX_FLAGS "-std=c++11 -Wall")
endif() endif()
add_subdirectory(scripts)
add_subdirectory(examples) add_subdirectory(examples)
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(tests) add_subdirectory(tests)
...@@ -19,7 +19,5 @@ endif() ...@@ -19,7 +19,5 @@ endif()
# strip leading 'v', and make unique for the tag # strip leading 'v', and make unique for the tag
message(STATUS "Revision is ${REVISION}") message(STATUS "Revision is ${REVISION}")
set(REVISION "${REVISION}" PARENT_SCOPE)
# rpm/deb packaging uses this, only works on whole tag numbers # rpm/deb packaging uses this, only works on whole tag numbers
string(SUBSTRING "${GIT_TAG_LAST}" 1 -1 REVISION_LAST) string(SUBSTRING "${GIT_TAG_LAST}" 1 -1 REVISION_LAST)
set(REVISION_LAST "${REVISION_LAST}" PARENT_SCOPE)
...@@ -26,94 +26,6 @@ ...@@ -26,94 +26,6 @@
namespace ebpf { namespace ebpf {
class Exception : public std::exception {
public:
virtual ~Exception() throw() {}
};
class StringException : public Exception {
public:
StringException() : errstr_("unknown") {}
virtual ~StringException() throw() {}
explicit StringException(const std::string& s) : errstr_(s) {}
explicit StringException(const char* s) : errstr_(s) {}
template <typename... Args>
StringException(const char* s, Args... args) {
char x[1024];
snprintf(x, sizeof(x), s, args...);
errstr_.assign(x);
}
virtual const char* what() const throw() {
return errstr_.c_str();
}
protected:
std::string errstr_;
};
class ErrnoException : public StringException {
public:
ErrnoException() : StringException(strerror(errno)) {}
explicit ErrnoException(const std::string& s) : StringException(s + ": " + strerror(errno)) {}
explicit ErrnoException(const std::string& s, int err) : StringException(s + ": " + strerror(err)) {}
};
class SystemException : public StringException {
public:
explicit SystemException(int status) {
if (status == -1) {
errstr_.assign("command not found");
} else {
errstr_.assign("command exited with ");
errstr_ += std::to_string(WEXITSTATUS(status));
}
}
SystemException(int status, const std::string& s) {
if (status == -1) {
errstr_.assign("command not found");
} else {
errstr_.assign("command exited with ");
errstr_ += std::to_string(WEXITSTATUS(status));
}
errstr_ += "; " + s + ": " + strerror(errno);
}
};
class CompilerException : public StringException {
public:
explicit CompilerException(const std::string& s) : StringException(s) {}
template <typename... Args>
CompilerException(const char* s, Args... args) : StringException(s, args...) {}
};
class WatermarkException : public Exception {
public:
WatermarkException() {}
virtual const char* what() const throw() {
return "Reached High Watermark";
}
};
class TerminateException : public Exception {
public:
TerminateException() {}
virtual const char* what() const throw() {
return "Terminated";
}
};
class StatusException : public Exception {
public:
explicit StatusException(int st, const std::string &msg) : st_(st), msg_(msg) {}
virtual const char* what() const throw() {
return msg_.c_str();
}
int status() const { return st_; }
const std::string & message() { return msg_; }
protected:
int st_;
std::string msg_;
};
template <typename... Args> template <typename... Args>
std::tuple<int, std::string> mkstatus(int ret, const char *fmt, Args... args) { std::tuple<int, std::string> mkstatus(int ret, const char *fmt, Args... args) {
char buf[1024]; char buf[1024];
...@@ -129,22 +41,6 @@ static inline std::tuple<int, std::string> mkstatus(int ret) { ...@@ -129,22 +41,6 @@ static inline std::tuple<int, std::string> mkstatus(int ret) {
return std::make_tuple(ret, std::string()); return std::make_tuple(ret, std::string());
} }
#define TRYT(CMD) \
do { \
int __status = (CMD); \
if (__status != 0) { \
throw StatusException(__status); \
} \
} while (0)
#define TRY2T(CMD) \
do { \
std::tuple<int, std::string> __stp = (CMD); \
if (std::get<0>(__stp) != 0) { \
throw StatusException(std::get<0>(__stp)); \
} \
} while (0)
#define TRY(CMD) \ #define TRY(CMD) \
do { \ do { \
int __status = (CMD); \ int __status = (CMD); \
......
...@@ -26,13 +26,13 @@ class TestTracingEvent(TestCase): ...@@ -26,13 +26,13 @@ class TestTracingEvent(TestCase):
def setUp(self): def setUp(self):
b = BPF(text=text, debug=0) b = BPF(text=text, debug=0)
self.stats = b.get_table("stats") self.stats = b.get_table("stats")
b.attach_kprobe(event="schedule+50", fn_name="count_sched", pid=0, cpu=-1) b.attach_kprobe(event="finish_task_switch", fn_name="count_sched", pid=0, cpu=-1)
def test_sched1(self): def test_sched1(self):
for i in range(0, 100): for i in range(0, 100):
sleep(0.01) sleep(0.01)
for key, leaf in self.stats.items(): for key, leaf in self.stats.items():
print("ptr %x:" % key.ptr, "stat1 %x" % leaf.stat1) print("ptr %x:" % key.ptr, "stat1 %d" % leaf.stat1)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment