SMBusData crash test
This commit is contained in:
@@ -1,17 +1,9 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
cmake_policy(SET CMP0020 NEW)
|
||||||
|
|
||||||
project(multithread_experiments)
|
project(multithread_experiments)
|
||||||
cmake_minimum_required(VERSION 2.8.6)
|
|
||||||
|
|
||||||
option(USE_SMSDK "Use libraries from SMSDK directory" 1)
|
find_package(SM REQUIRED)
|
||||||
if(USE_SMSDK)
|
|
||||||
set(PATH_TO_SMSDK $ENV{SMSDK_DIR})
|
|
||||||
set(SM_BIN_DIR $ENV{SM_BIN_DIR})
|
|
||||||
set(PIP_DIR ${PATH_TO_SMSDK})
|
|
||||||
set(SMBRICKS_INCLUDES ${PATH_TO_SMSDK}/include/SMBricks)
|
|
||||||
set(SMBRICKS_LIB_DIR ${PATH_TO_SMSDK}/lib)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
find_package(PIP REQUIRED)
|
|
||||||
find_package(QAD REQUIRED)
|
|
||||||
|
|
||||||
if (CMAKE_BUILD_TYPE MATCHES Debug)
|
if (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -fPIC -std=c++11")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -fPIC -std=c++11")
|
||||||
@@ -21,7 +13,7 @@ else()
|
|||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -fPIC")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -fPIC")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include_directories(experiments ${PIP_INCLUDES} ${PROJECT_SOURCE_DIR})
|
include_directories(experiments ${SMBRICKS_INCLUDES} ${PIP_INCLUDES} ${PROJECT_SOURCE_DIR})
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
include_directories(can)
|
include_directories(can)
|
||||||
@@ -51,4 +43,7 @@ add_executable(vectors experiments/vectors.cpp)
|
|||||||
target_link_libraries(vectors ${PIP_LIBRARY})
|
target_link_libraries(vectors ${PIP_LIBRARY})
|
||||||
|
|
||||||
add_executable(block_choice experiments/block_choice.cpp)
|
add_executable(block_choice experiments/block_choice.cpp)
|
||||||
target_link_libraries(block_choice ${PIP_LIBRARY})
|
target_link_libraries(block_choice ${PIP_LIBRARY})
|
||||||
|
|
||||||
|
add_executable(smbusdata_crash_test experiments/smbusdata_crash_test.cpp)
|
||||||
|
target_link_libraries(smbusdata_crash_test SMBricks_shared ${PIP_LIBRARY} ${PIP_CONCURRENT_LIBRARY} ${PIP_CRYPT_LIBRARY})
|
||||||
77
experiments/smbusdata_crash_test.cpp
Normal file
77
experiments/smbusdata_crash_test.cpp
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#include <sm_base.h>
|
||||||
|
#include <executor.h>
|
||||||
|
|
||||||
|
struct SomeLargeData {
|
||||||
|
uint8_t data[4]{};
|
||||||
|
|
||||||
|
SomeLargeData() { memset(data, 0xff, sizeof(data)); }
|
||||||
|
|
||||||
|
~SomeLargeData() {
|
||||||
|
memset(data, 0x00, sizeof(data));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline PIByteArray & operator <<(PIByteArray & s, const SomeLargeData & v) {
|
||||||
|
s << PIByteArray::RawData(v.data, sizeof(v.data));
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline PIByteArray & operator >>(PIByteArray & s, SomeLargeData & v) {
|
||||||
|
if (s.size() < sizeof(v.data)) {
|
||||||
|
piCout << "Error in operator >> for SomeLargeData";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
s >> PIByteArray::RawData(v.data, sizeof(v.data));
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
REGISTER_BUS_TYPE(SomeLargeData)
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::atomic_bool is_end(false);
|
||||||
|
PIThreadPoolExecutor executor(4);
|
||||||
|
PIBlockingDequeue<SMBlockData> out_dequeue;
|
||||||
|
PIBlockingDequeue<SMBlockData> in_dequeue;
|
||||||
|
|
||||||
|
executor.execute([&](){
|
||||||
|
while (true) {
|
||||||
|
bool is_ok;
|
||||||
|
SMBlockData data;
|
||||||
|
data = in_dequeue.poll(100, data, &is_ok);
|
||||||
|
if (!is_ok) {
|
||||||
|
if (is_end) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
out_dequeue.offer(data, 100);
|
||||||
|
if (!is_ok) {
|
||||||
|
if (is_end) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
SomeLargeData content;
|
||||||
|
int iteration_count = 100 * 1000;
|
||||||
|
for (int i = 0; i < iteration_count / 20; ++i) {
|
||||||
|
for (int j = 0; j < 20; ++j) {
|
||||||
|
SMBlockData block_data(j+1);
|
||||||
|
for (int k = 0; k < j+1; ++k) {
|
||||||
|
block_data[k].sharedData<SomeLargeData>() = content;
|
||||||
|
}
|
||||||
|
// bus_data << SMBusData::create(content);
|
||||||
|
in_dequeue.offer(block_data.clone());
|
||||||
|
}
|
||||||
|
for (int j = 0; j < 20; ++j) {
|
||||||
|
auto block_data = out_dequeue.take();
|
||||||
|
if (block_data[0].isInvalid()) {
|
||||||
|
piCout << "Error: bus_data is invalid";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// printf("It's alive! %d\n", i);
|
||||||
|
}
|
||||||
|
|
||||||
|
is_end = true;
|
||||||
|
executor.shutdownNow();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user