Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
xlz-jbleclere committed Sep 1, 2020
1 parent 81ddb1a commit 52b20b5
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 12 deletions.
13 changes: 7 additions & 6 deletions include/accelize/drm/ParameterKey.def
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ PARAMETERKEY_ITEM( token_validity ) ///< Read-only, return the v
PARAMETERKEY_ITEM( token_time_left ) ///< Read-only, return the number of seconds left until the current token expires
PARAMETERKEY_ITEM( frequency_detection_method ) ///< Read-only, return the method index used to detect the DRM frequency
PARAMETERKEY_ITEM( bypass_frequency_detection ) ///< Read-only, return true if the frequency detection system is disabled, false otherwise
PARAMETERKEY_ITEM( log_file_path ) ///< Read-(write), read (and write) the logging file path: default path is "./drm_lib.log". Can be set only from configuration file (no override from C/C++ code)
PARAMETERKEY_ITEM( log_file_type ) ///< Read-(write), read (and write) the logging file type 0=no logging file, 1=basic file, 2=rotation file. Set only from configuration file (no override from C code)
PARAMETERKEY_ITEM( log_file_rotating_size ) ///< Read-(write), read (and write) the logging rotating file size in KB: default=1024KB (1MB). Set only from configuration file (no override from C code)
PARAMETERKEY_ITEM( log_file_rotating_num ) ///< Read-(write), read (and write) the logging rotating number of backup files: default=3. Set only from configuration file (no override from C code)
PARAMETERKEY_ITEM( log_file_path ) ///< Read-(write), read (and write) the logging file path: default path is "./drm_lib.log". Can be set only from configuration file (no override from user code)
PARAMETERKEY_ITEM( log_file_type ) ///< Read-(write), read (and write) the logging file type 0=no logging file, 1=basic file, 2=rotation file. Set only from configuration file (no override from user code)
PARAMETERKEY_ITEM( log_file_rotating_size ) ///< Read-(write), read (and write) the logging rotating file size in KB: default=1024KB (1MB). Set only from configuration file (no override from user code)
PARAMETERKEY_ITEM( log_file_rotating_num ) ///< Read-(write), read (and write) the logging rotating number of backup files: default=3. Set only from configuration file (no override from user code)
PARAMETERKEY_ITEM( log_file_verbosity ) ///< Read-write, read and write the logging verbosity on the file: 0=trace, 6=quiet
PARAMETERKEY_ITEM( log_file_format ) ///< Read-write, read and write the logging file format. Refer to spdlog reference manual (https://github.com/gabime/spdlog/wiki/3.-Custom-formatting)
PARAMETERKEY_ITEM( log_verbosity ) ///< Read-write, read and write the logging verbosity on the stdout/stderr: 0=trace, 6=quiet
Expand All @@ -29,7 +29,7 @@ PARAMETERKEY_ITEM( custom_field ) ///< Read-write, only for te
PARAMETERKEY_ITEM( mailbox_data ) ///< Read-write, only for testing, read or write values to Mailbox read-write memory in DRM Controller
PARAMETERKEY_ITEM( ws_retry_period_long ) ///< Read-write, read and write the time in seconds before the next request attempt to the Web Server when the time left before timeout is long
PARAMETERKEY_ITEM( ws_retry_period_short ) ///< Read-write, read and write the time in seconds before the next request attempt to the Web Server when the time left before timeout is short
PARAMETERKEY_ITEM( ws_request_timeout ) ///< Read-(write), read (and write) the maximum period of time in seconds for the request to complete. Can be set only from configuration file (no override from C/C++ code)
PARAMETERKEY_ITEM( ws_request_timeout ) ///< Read-(write), read (and write) the maximum period of time in seconds for the request to complete. Can be set only from configuration file (no override from user code)
PARAMETERKEY_ITEM( log_message_level ) ///< Read-write, only for testing, read and write the log level used with log_message parameter to set the message level
PARAMETERKEY_ITEM( list_all ) ///< Read-only, list all parameter keys available
PARAMETERKEY_ITEM( dump_all ) ///< Read-only, read all parameter key values
Expand All @@ -47,5 +47,6 @@ PARAMETERKEY_ITEM( health_period ) ///< Read-only, return the c
PARAMETERKEY_ITEM( health_retry ) ///< Read-only, return the current value of the health retry timeout
PARAMETERKEY_ITEM( health_retry_sleep ) ///< Read-only, return the current value of the health retry sleep
PARAMETERKEY_ITEM( ws_api_retry_duration ) ///< Read-write, read and write the period of time in seconds during which retries occur on activate and deactivate functions
PARAMETERKEY_ITEM( host_data_verbosity ) ///< Read-(write), read (and write) the level of verbosity for the amont of host and card data collected. Set only from configuration file (no override from C code)
PARAMETERKEY_ITEM( host_data_verbosity ) ///< Read-(write), read (and write) the level of verbosity for the amont of host and card data collected. Set only from configuration file (no override from user code)
PARAMETERKEY_ITEM( host_data ) ///< Read-only, read the host and card information
PARAMETERKEY_ITEM( log_file_append ) ///< Read-(write), read (and write) the appending parameter for the basic logging file. Set only from configuration file (no override from user code)
12 changes: 9 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ def pytest_addoption(parser):
parser.addoption(
"--no_clear_fpga", action="store_true", help='Bypass clearing of FPGA at start-up')
parser.addoption(
"--logfile", action="store_true", help='Save log to file')
"--logfile", nargs='?', type=str, const='', default=None, help='Save log to file path.')
parser.addoption(
"--logfilelevel", action="store", type=int, default=1, choices=(0,1,2,3,4,5), help='Specify verbosity for --logfile')
parser.addoption(
"--logfileappend", action="store_true", default=False, help='Append log message to same file. File path is specified by --logfile')
parser.addoption(
"--proxy_debug", action="store_true", default=False,
help='Activate debug for proxy')
Expand Down Expand Up @@ -781,10 +783,14 @@ def conf_json(request, pytestconfig, tmpdir):
log_param['log_format'] = '%Y-%m-%d %H:%M:%S.%e - %18s:%-4# [%=8l] %=6t, %v'
else:
log_param['log_format'] = '[%^%=8l%$] %-6t, %v'
if pytestconfig.getoption("logfile"):
if pytestconfig.getoption("logfile") is not None:
log_param['log_file_type'] = 1
log_param['log_file_path'] = realpath("./tox_drmlib_t%f_pid%d.log" % (time(), getpid()))
if len(pytestconfig.getoption("logfile")) != 0:
log_param['log_file_path'] = pytestconfig.getoption("logfilepath")
else:
log_param['log_file_path'] = realpath("./tox_drmlib_t%f_pid%d.log" % (time(), getpid()))
log_param['log_file_verbosity'] = pytestconfig.getoption("logfilelevel")
log_param['log_file_append'] = True if pytestconfig.getoption("logfileappend") else False
# Save config to JSON file
json_conf = ConfJson(tmpdir, pytestconfig.getoption("server"), settings=log_param, design=design_param)
json_conf.save()
Expand Down
70 changes: 70 additions & 0 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,76 @@ def test_file_types(accelize_drm, conf_json, cred_json, async_handler):
remove(f)


def test_file_append(accelize_drm, conf_json, cred_json, async_handler):
"""Test logging file append mode"""
driver = accelize_drm.pytest_fpga_driver[0]
async_cb = async_handler.create()

log_path = accelize_drm.create_log_path(whoami())
log_type= 1

async_cb.reset()
conf_json.reset()
conf_json['settings']['log_verbosity'] = 6
conf_json['settings']['log_file_path'] = log_path
conf_json['settings']['log_file_type'] = log_type
conf_json['settings']['log_file_append'] = True
conf_json.save()

nb_loop = 5
for i in range(nb_loop):
drm_manager = accelize_drm.DrmManager(
conf_json.path,
cred_json.path,
driver.read_register_callback,
driver.write_register_callback,
async_cb.callback
)
del drm_manager
wait_func_true(lambda: isfile(log_path), 10)
async_cb.assert_NoError()
assert len(glob(log_path)) == 1
with open(log_path, 'rt') as f:
log_content = f.read()
assert len(findall(r'Installed versions', log_content)) == nb_loop
remove(log_path)


def test_file_truncate(accelize_drm, conf_json, cred_json, async_handler):
"""Test logging file truncate mode"""
driver = accelize_drm.pytest_fpga_driver[0]
async_cb = async_handler.create()

log_path = accelize_drm.create_log_path(whoami())
log_type= 1

async_cb.reset()
conf_json.reset()
conf_json['settings']['log_verbosity'] = 6
conf_json['settings']['log_file_path'] = log_path
conf_json['settings']['log_file_type'] = log_type
conf_json['settings']['log_file_append'] = False
conf_json.save()

nb_loop = 5
for i in range(nb_loop):
drm_manager = accelize_drm.DrmManager(
conf_json.path,
cred_json.path,
driver.read_register_callback,
driver.write_register_callback,
async_cb.callback
)
del drm_manager
wait_func_true(lambda: isfile(log_path), 10)
async_cb.assert_NoError()
assert len(glob(log_path)) == 1
with open(log_path, 'rt') as f:
log_content = f.read()
assert len(findall(r'Installed versions', log_content)) == 1
remove(log_path)


def test_file_rotating_parameters(accelize_drm, conf_json, cred_json, async_handler):
"""Test logging file rotating parameters"""
driver = accelize_drm.pytest_fpga_driver[0]
Expand Down
3 changes: 1 addition & 2 deletions tests/test_metered_mode_on_hw.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ def test_metered_start_stop_in_raw(accelize_drm, conf_json, cred_json, async_han
assert not drm_manager.get('license_status')
activators.autotest(is_activated=False)
activators[0].generate_coin(1000)
activators[0].check_coin(drm_manager.get('metered_data'))
drm_manager.activate()
assert drm_manager.get('metered_data') == 0
activators[0].check_coin(drm_manager.get('metered_data'))
drm_manager.deactivate()
assert not drm_manager.get('license_status')
activators.autotest(is_activated=False)
assert drm_manager.get('metered_data') == 0
async_cb.assert_NoError()
finally:
drm_manager.deactivate()
Expand Down
51 changes: 50 additions & 1 deletion tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
'health_retry_sleep',
'ws_api_retry_duration',
'host_data_verbosity',
'host_data'
'host_data',
'log_file_append'
)


Expand Down Expand Up @@ -495,6 +496,36 @@ def test_parameter_key_modification_with_config_file(accelize_drm, conf_json, cr
async_cb.assert_NoError()
print("Test parameter 'host_data_verbosity': PASS")

# Test parameter: log_file_append
async_cb.reset()
conf_json.reset()
expectVal = False
conf_json['settings'] = {'log_file_append': expectVal}
conf_json.save()
drm_manager = accelize_drm.DrmManager(
conf_json.path,
cred_json.path,
driver.read_register_callback,
driver.write_register_callback,
async_cb.callback
)
assert drm_manager.get('log_file_append') == expectVal

conf_json.reset()
expectVal = True
conf_json['settings'] = {'log_file_append': expectVal}
conf_json.save()
drm_manager = accelize_drm.DrmManager(
conf_json.path,
cred_json.path,
driver.read_register_callback,
driver.write_register_callback,
async_cb.callback
)
assert drm_manager.get('log_file_append') == expectVal
async_cb.assert_NoError()
print("Test parameter 'log_file_append': PASS")

# Test unsupported parameter
async_cb.reset()
conf_json.reset()
Expand Down Expand Up @@ -1018,6 +1049,24 @@ def test_parameter_key_modification_with_get_set(accelize_drm, conf_json, cred_j
async_cb.assert_NoError()
print("Test parameter 'host_data': PASS")

# Test parameter: log_file_append
async_cb.reset()
conf_json.reset()
conf_json['settings'] = {'log_file_append': False}
conf_json.save()
drm_manager = accelize_drm.DrmManager(
conf_json.path,
cred_json.path,
driver.read_register_callback,
driver.write_register_callback,
async_cb.callback
)
assert drm_manager.get('log_file_append') == False
with pytest.raises(accelize_drm.exceptions.DRMBadArg) as excinfo:
drm_manager.set(log_file_append=True)
async_cb.assert_NoError()
print("Test parameter 'log_file_append': PASS")


def test_configuration_file_with_bad_authentication(accelize_drm, conf_json, cred_json,
async_handler):
Expand Down

0 comments on commit 52b20b5

Please sign in to comment.