Skip to content

Instantly share code, notes, and snippets.

@hellais
Last active July 26, 2018 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hellais/b56043d57eb5be885958e80b3665bfe2 to your computer and use it in GitHub Desktop.
Save hellais/b56043d57eb5be885958e80b3665bfe2 to your computer and use it in GitHub Desktop.
Test Tor API
- running test_get_tor_version()
Tor version 0.3.5.0-alpha-dev (git-9ae35975402a823a).
- running test_get_tor_version_many()
Jul 26 16:01:29.901 [err] tor_assertion_failed_: Bug: src/feature/hs/hs_circuitmap.c:571: hs_circuitmap_init: Assertion !the_hs_circuitmap failed; aborting. (on Tor 0.3.5.0-alpha-dev 9ae35975402a823a)
Jul 26 16:01:29.901 [err] Bug: Assertion !the_hs_circuitmap failed in hs_circuitmap_init at src/feature/hs/hs_circuitmap.c:571. Stack trace: (on Tor 0.3.5.0-alpha-dev 9ae35975402a823a)
Jul 26 16:01:29.901 [err] Bug: 0 libtor.0.dylib 0x000000010f28441c log_backtrace_impl + 76 (on Tor 0.3.5.0-alpha-dev 9ae35975402a823a)
Jul 26 16:01:29.901 [err] Bug: 1 libtor.0.dylib 0x000000010f27e336 tor_assertion_failed_ + 278 (on Tor 0.3.5.0-alpha-dev 9ae35975402a823a)
Jul 26 16:01:29.901 [err] Bug: 2 libtor.0.dylib 0x000000010f107c0f hs_circuitmap_init + 95 (on Tor 0.3.5.0-alpha-dev 9ae35975402a823a)
Jul 26 16:01:29.901 [err] Bug: 3 libtor.0.dylib 0x000000010f111ccb hs_init + 27 (on Tor 0.3.5.0-alpha-dev 9ae35975402a823a)
Jul 26 16:01:29.901 [err] Bug: 4 libtor.0.dylib 0x000000010f0151d1 tor_init + 225 (on Tor 0.3.5.0-alpha-dev 9ae35975402a823a)
Jul 26 16:01:29.901 [err] Bug: 5 libtor.0.dylib 0x000000010f0162c6 tor_run_main + 182 (on Tor 0.3.5.0-alpha-dev 9ae35975402a823a)
Jul 26 16:01:29.901 [err] Bug: 6 libffi.dylib 0x00007fff8b88ff1c ffi_call_unix64 + 76 (on Tor 0.3.5.0-alpha-dev 9ae35975402a823a)
Jul 26 16:01:29.901 [err] Bug: 7 ??? 0x000000010e6fea28 0x0 + 4537182760 (on Tor 0.3.5.0-alpha-dev 9ae35975402a823a)
zsh: abort python test_tor_api.py
#!/usr/bin/env python
import os
import sys
import tempfile
from cffi import FFI
#LIB_PATH = "libtor_api.0.dylib"
LIB_PATH = "libtor.0.dylib"
def load_lib():
ffi = FFI()
# This is the output of: `cc -E tor_api.h`
ffi.cdef("""typedef struct tor_main_configuration_t tor_main_configuration_t;
tor_main_configuration_t *tor_main_configuration_new(void);
# 49 "tor_api.h"
int tor_main_configuration_set_command_line(tor_main_configuration_t *cfg,
int argc, char *argv[]);
void tor_main_configuration_free(tor_main_configuration_t *cfg);
# 86 "tor_api.h"
int tor_run_main(const tor_main_configuration_t *);
# 98 "tor_api.h"
int tor_main(int argc, char **argv);""")
lib = ffi.dlopen(LIB_PATH)
return ffi, lib
ffi, lib = load_lib()
def test_get_tor_version():
argv_plist = [
ffi.new("char[]", b""),
ffi.new("char[]", b"--version")
]
argv = ffi.new("char*[]", argv_plist)
argc = ffi.cast("int", 2)
cfg = lib.tor_main_configuration_new()
assert lib.tor_main_configuration_set_command_line(cfg, argc, argv) == 0
assert lib.tor_run_main(cfg) == 0
lib.tor_main_configuration_free(cfg)
def test_get_tor_version_many():
for i in range(10):
test_get_tor_version()
def test_all():
print("- running test_get_tor_version()")
test_get_tor_version()
print("- running test_get_tor_version_many()")
test_get_tor_version_many()
if __name__ == "__main__":
test_all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment