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

Commit

Permalink
Debug unittest. Add 1st draft of migration page to doc
Browse files Browse the repository at this point in the history
  • Loading branch information
xlz-jbleclere committed Aug 28, 2020
1 parent a94547c commit 80e3b58
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
* Mon Aug 31 2020 Accelize v2.5.0
- NEW: Add support of the asynchronous metering mechanism
- NEW: Use host and card information when XRT utilities are installed
- NEW: Include DRM Library settings in requests
- NEW: Support the new data format in the ROM of the DRM Controller
- FIX: Retry on API call handles loss of requests

* Thu Apr 30 2020 Accelize v2.4.1
- FIX: Correct BIST to allow HDK v3.x

Expand Down
4 changes: 2 additions & 2 deletions doc/drm_library_integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ FPGA C library driver.
// Instantiate DrmManager with previously defined functions and
// configuration files
DrmManager *drm_manager = NULL;
DrmManager* drm_manager = NULL;
int ctx = 0;
if ( DrmManager_alloc(
Expand Down Expand Up @@ -139,7 +139,7 @@ FPGA C library driver.
"./cred.json",

// Read/write register functions callbacks
[&](uint32_t offset, uint32_t * value) {
[&](uint32_t offset, uint32_t* value) {
return fpga_read_register( drm_controller_base_addr + offset, value );
},

Expand Down
180 changes: 180 additions & 0 deletions doc/drm_migration_description.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
DRM Migration description
=========================

DRM API upgrade
---------------

From v1.x to 2.x
~~~~~~~~~~~~~~~~

.. code-block:: c
:caption: In C
#include "accelize/drmc.h"
struct sUserContext user_ctx = ...; // sUserContext is any structure the User may want to create
MeteringSessionManager* p_drm = NULL;
DRMLibErrorCode retcode;
// Callbacks implementation
int read_fpga_register_callback( uint32_t register offset, uint32_t* returned data, void* user_p) {...}
int write_fpga_register_callback( uint32_t register offset, uint32_t data to write, void* user_p) {...}
void drm_error_callback( const char* error message, void* user_p ) {...}
// API Methods
printf( "%s\n", DRMLib_get_version() );
MeteringSessionManager_alloc( &p_drm,
"path_to_conf_file",
"path_to_cred_file",
read_fpga_register_callback,
write_fpga_register_callback,
drm_error_callback,
&user_ctx
);
retcode = MeteringSessionManager_start_session( p_drm );
retcode = MeteringSessionManager_stop_session( p_drm );
retcode = MeteringSessionManager_pause_session( p_drm );
retcode = MeteringSessionManager_resume_session( p_drm );
retcode = MeteringSessionManager_auto_start_session( p_drm );
retcode = MeteringSessionManager_dump_drm_hw_report( p_drm );
retcode = MeteringSessionManager_free( &p_drm );
Shall be replaced by:

.. code-block:: c
:caption: In C
#include "accelize/drmc.h"
struct sUserContext user_ctx = ...; // sUserContext is any structure the User may want to create
DrmManager* p_drm = NULL;
DRM_ErrorCode retcode;
bool resume_pause_flag = false; // true=enable pause/resume mode, false=disable pause/resume flag
char* json_string = nullptr;
// Callbacks implementation
int read_fpga_register_callback( uint32_t register offset, uint32_t* returned data, void* user_p) {...}
int write_fpga_register_callback( uint32_t register offset, uint32_t data to write, void* user_p) {...}
void drm_error_callback( const char* error message, void* user_p ) {...}
// API Methods
printf( "%s\n", DrmManager_getApiVersion() );
DRM_ErrorCode DrmManager_alloc( &p_drm,
"path_to_conf_file",
"path_to_cred_file",
read_fpga_register_callback,
write_fpga_register_callback,
drm_error_callback,
&user_ctx
);
retcode = DrmManager_activate( p_drm, resume_pause_flag );
retcode = DrmManager_deactivate( p_drm, resume_pause_flag );
retcode = DrmManager_get_json_string( p_drm, "{\"hw_report\":\"\"}", json_string );
retcode = DrmManager_free( &p_drm );
delete json_string;
.. code-block:: c++
:caption: In C++

#include <iostream>
#include <string>
#include "accelize/drm.h"

namespace cpp = Accelize::DRMLib;

struct sUserContext user_ctx = ...; // sUserContext is any structure the User may want to create

// Callbacks implementation
int read_fpga_register_callback( uint32_t register offset, uint32_t* returned data, void* user_p) {...}
int write_fpga_register_callback( uint32_t register offset, uint32_t data to write, void* user_p) {...}
void drm_error_callback( const char* error message, void* user_p ) {...}

// API Methods
try {
std::cout << cpp::getVersion() << std::endl;

cpp::MeteringSessionManager* p_drm = new cpp::MeteringSessionManager(
"path_to_conf_file",
"path_to_cred_file",
[&]( uint32_t offset, uint32_t* value ) { return read_fpga_register_callback( offset, value, &user_ctx ); },
[&]( uint32_t offset, uint32_t value ) { return write_fpga_register_callback( offset, value, &user_ctx ); },
[&]( const std::string& msg ) { drm_error_callback( msg.c_str(), &user_ctx ); }
);
p_drm->start_session();
p_drm->auto_start_session();
p_drm->resume_session();
p_drm->pause_session();
p_drm->stop_session();
p_drm->dump_drm_hw_report( std::cout );

} catch( const cpp:Exception& e ) {
std::cout << e.what() << std::endl;
}


Shall be replaced by:

.. code-block:: c++
:caption: In C++

#include <iostream>
#include <string>
#include "accelize/drm.h"

namespace cpp = Accelize::DRMLib;

struct sUserContext user_ctx = ...; // sUserContext is any structure the User may want to create
bool resume_pause_flag = false; // true=enable pause/resume mode, false=disable pause/resume flag
char* json_string = nullptr;

// Callback definition
int read_fpga_register_callback( uint32_t register offset, uint32_t* returned data, void* user_p) {...}
int write_fpga_register_callback( uint32_t register offset, uint32_t data to write, void* user_p) {...}
void drm_error_callback( const char* error message, void* user_p ) {...}

// API Methods
try {
std::cout << cpp::getApiVersion() << std::endl;

cpp::DrmManager* p_drm = new cpp::DrmManager(
"path_to_conf_file",
"path_to_cred_file",
[&]( uint32_t offset, uint32_t* value ) { return read_fpga_register_callback( offset, value, &user_ctx ); },
[&]( uint32_t offset, uint32_t value ) { return write_fpga_register_callback( offset, value, &user_ctx ); },
[&]( const std::string& msg ) { drm_error_callback( msg.c_str(), &user_ctx ); }
);
p_drm->activate( resume_pause_flag );
p_drm->deactivate( resume_pause_flag );
p_drm->get<std::string>( cpp::ParameterKey::hw_report );

} catch( const cpp:Exception& e ) {
std::cout << e.what() << std::endl;
}


For more information about the API in your favorite language, refer to :doc:`drm_library_api`.


DRM HDK upgrade
---------------


From v2.x to 3.x
~~~~~~~~~~~~~~~~



From v3.x to 4.x
~~~~~~~~~~~~~~~~





1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Glossary

drm_library_build
drm_sw_advanced_description
drm_migration


.. toctree::
Expand Down
7 changes: 7 additions & 0 deletions tests/test_host_card_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
Test host and card information releated feature
"""
import pytest
from os import environ


def test_host_data_verbosity(accelize_drm, conf_json, cred_json, async_handler):
"""
Test all supported verbosity
"""
if 'XRT_PATH' not in environ:
pytest.skip("XRT_PATH is not defined: skip host and card tests")

driver = accelize_drm.pytest_fpga_driver[0]
async_cb = async_handler.create()
async_cb.reset()
Expand Down Expand Up @@ -65,6 +69,9 @@ def test_format(accelize_drm, conf_json, cred_json, async_handler):
"""
Test the format in the request is as expected
"""
if 'XRT_PATH' not in environ:
pytest.skip("XRT_PATH is not defined: skip host and card tests")

driver = accelize_drm.pytest_fpga_driver[0]
async_cb = async_handler.create()
async_cb.reset()
Expand Down
9 changes: 6 additions & 3 deletions tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Test node-locked behavior of DRM Library.
"""
import pytest
from os import remove, getpid
from os import remove, getpid, environ
from os.path import isfile, realpath
from re import match, search, finditer
from time import sleep, time
Expand Down Expand Up @@ -1008,8 +1008,11 @@ def test_parameter_key_modification_with_get_set(accelize_drm, conf_json, cred_j
driver.write_register_callback,
async_cb.callback
)
assert type(drm_manager.get('host_data')) == dict
assert len(drm_manager.get('host_data'))
if 'XRT_PATH' in environ:
assert type(drm_manager.get('host_data')) == dict
assert len(drm_manager.get('host_data'))
else:
assert drm_manager.get('host_data') is None
with pytest.raises(accelize_drm.exceptions.DRMBadArg) as excinfo:
drm_manager.set(host_data={'test':'test'})
async_cb.assert_NoError()
Expand Down

0 comments on commit 80e3b58

Please sign in to comment.