exein-io / pulsar

A modular and blazing fast runtime security tool for the IoT, powered by eBPF.
https://pulsar.sh
Other
905 stars 51 forks source link

Error when running cargo test #3

Closed MatteoNardi closed 2 years ago

MatteoNardi commented 2 years ago

Running cargo test from the root folder or from validatron/derive fails with:

/home/matteo/projects/pulsar/target/debug/deps/validatron_derive-572b783d107d6cc9: error while loading shared libraries: libtest-efede371ca078f25.so: cannot open shared object file: No such file or directory
error: test failed, to rerun pass '--lib'

validatron_derive uses proc macros. Maybe this adds the extra dependency causing the issue. The missing libtest shared library could be found inside ~/.rustup/toolchains/.

I tried copying validatron_derive to a clean workspace and I couldn't reproduce the issue. It turns out the problem comes from our .cargo/config file:

[target.x86_64-unknown-linux-gnu]
runner = 'sudo -E'

Running all our artifacts with sudo during development was convenient since eBPF needs roots permissions to be loaded, but maybe it's time to find a better solution.

We could remove the runner config and explicitly call sudo. For binaries like pulsar-exec this is not an issue since the path is fixed (eg. cargo build && sudo ./target/debug/pulsar-exec). The problem arises for tests, where the path is automatically generated, making it hard to run it with two commands. Unfortunately, replacing unit tests with integration tests won't change the fact we have a random name, like target/debug/deps/integration_test-74139a0d8fe9d447. One possible workaround would be making the test suite a separate binary. Another solution would be to make a test_suite binary which calls the individual modules tests, enabling a specific feature flag.

Let me know what you think, maybe we can come up with better solution.

MatteoNardi commented 2 years ago

Yesterday I was talking to @banditopazzo about this issue and we kind of agreed that it would be better to run the test suit with something different from cargo test. Probably the best solution would be to make an xtask for it.

The default test harness (libtest) doesn't seem to be extensible (See https://www.infinyon.com/blog/2021/04/rust-custom-test-harness/). I definitely want to maintain most of its features though, filtering support in particular is a must-have.

These are the alternatives which came up in my search:

Currently, the solution I have in mind would be something like this: