summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-10-10 15:54:43 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2017-10-10 18:05:15 +0200
commitcf7110f02f793c791b7227bf1579eaaa81d3fd30 (patch)
treeef57c33ee67c015885402ce9bde62f695541b92e
parent84f8f634584e22a557bf50f077fb15967311908d (diff)
downloadlibnitrokey-cf7110f02f793c791b7227bf1579eaaa81d3fd30.tar.gz
libnitrokey-cf7110f02f793c791b7227bf1579eaaa81d3fd30.tar.bz2
Add DEBUG_L1 level and set it as default for Python tests
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--NK_C_API.cc6
-rw-r--r--NK_C_API.h8
-rw-r--r--include/log.h1
-rw-r--r--log.cc2
-rw-r--r--unittest/conftest.py8
5 files changed, 22 insertions, 3 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index 822c95d..e730bae 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -296,6 +296,12 @@ extern "C" {
m->set_debug(state);
}
+
+ NK_C_API void NK_set_debug_level(const int level) {
+ auto m = NitrokeyManager::instance();
+ m->set_loglevel(level);
+ }
+
NK_C_API int NK_totp_set_time(uint64_t time) {
auto m = NitrokeyManager::instance();
return get_without_result([&]() {
diff --git a/NK_C_API.h b/NK_C_API.h
index 18f8d0a..3742b43 100644
--- a/NK_C_API.h
+++ b/NK_C_API.h
@@ -14,11 +14,17 @@ extern "C" {
#endif
/**
* Set debug level of messages written on stderr
- * @param state state=True - all messages, state=False - only errors level
+ * @param state state=True - most messages, state=False - only errors level
*/
NK_C_API void NK_set_debug(bool state);
/**
+ * Set debug level of messages written on stderr
+ * @param level (int) 0-lowest verbosity, 5-highest verbosity
+ */
+ NK_C_API void NK_set_debug_level(const int level);
+
+ /**
* Connect to device of given model. Currently library can be connected only to one device at once.
* @param device_model char 'S': Nitrokey Storage, 'P': Nitrokey Pro
* @return 1 if connected, 0 if wrong model or cannot connect
diff --git a/include/log.h b/include/log.h
index 80e5097..a97ff25 100644
--- a/include/log.h
+++ b/include/log.h
@@ -19,6 +19,7 @@ namespace nitrokey {
ERROR,
WARNING,
INFO,
+ DEBUG_L1,
DEBUG,
DEBUG_L2
};
diff --git a/log.cc b/log.cc
index 7d61a0d..c29b85b 100644
--- a/log.cc
+++ b/log.cc
@@ -14,6 +14,8 @@ namespace nitrokey {
std::string LogHandler::loglevel_to_str(Loglevel lvl) {
switch (lvl) {
+ case Loglevel::DEBUG_L1:
+ return std::string("DEBUG_L1");
case Loglevel::DEBUG_L2:
return std::string("DEBUG_L2");
case Loglevel::DEBUG:
diff --git a/unittest/conftest.py b/unittest/conftest.py
index 8c9899c..ef4539c 100644
--- a/unittest/conftest.py
+++ b/unittest/conftest.py
@@ -20,14 +20,17 @@ def C(request):
with open(fp, 'r') as f:
declarations = f.readlines()
+ cnt = 0
a = iter(declarations)
for declaration in a:
if declaration.strip().startswith('NK_C_API'):
declaration = declaration.replace('NK_C_API', '').strip()
while ';' not in declaration:
declaration += (next(a)).strip()
- print(declaration)
+ # print(declaration)
ffi.cdef(declaration, override=True)
+ cnt +=1
+ print('Imported {} declarations'.format(cnt))
C = None
import os, sys
@@ -73,6 +76,7 @@ def C(request):
print('Finished')
request.addfinalizer(fin)
- C.NK_set_debug(True)
+ # C.NK_set_debug(True)
+ C.NK_set_debug_level(3)
return C