-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/P16-53-system-tests' into 'master'
Resolve P16-53 "Feature/ system tests" Closes P16-53 See merge request pixie/pixie_sdk!18
- Loading branch information
Showing
11 changed files
with
761 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// @file configuration.hpp | ||
// @brief Namespace and functions commonly used by the utilities programs. | ||
// @author S. V. Paulauskas <[email protected]> | ||
// @date November 13, 2020 | ||
|
||
#ifndef PIXIE_SDK_CONFIGURATION_HPP | ||
#define PIXIE_SDK_CONFIGURATION_HPP | ||
|
||
#include <algorithm> | ||
#include <exception> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <string> | ||
|
||
namespace xia { | ||
namespace configuration { | ||
class Configuration { | ||
public: | ||
unsigned short numModules; | ||
unsigned short* slot_map; | ||
std::string ComFPGAConfigFile; | ||
std::string SPFPGAConfigFile; | ||
std::string TrigFPGAConfigFile; | ||
std::string DSPCodeFile; | ||
std::string DSPParFile; | ||
std::string DSPVarFile; | ||
}; | ||
|
||
Configuration read_configuration_file(const std::string& config_file_name) { | ||
std::ifstream input(config_file_name, std::ios::in); | ||
|
||
if (input.fail()) { | ||
std::stringstream errmsg; | ||
errmsg << "Could not open " << config_file_name << "!"; | ||
throw std::invalid_argument(errmsg.str()); | ||
} | ||
|
||
xia::configuration::Configuration cfg; | ||
input >> cfg.numModules; | ||
cfg.slot_map = new unsigned short[cfg.numModules + 1]; | ||
for (size_t i = 0; i < cfg.numModules; i++) | ||
input >> cfg.slot_map[i]; | ||
|
||
input >> cfg.ComFPGAConfigFile >> cfg.SPFPGAConfigFile >> cfg.TrigFPGAConfigFile >> cfg.DSPCodeFile >> | ||
cfg.DSPParFile >> cfg.DSPVarFile; | ||
|
||
input.close(); | ||
return cfg; | ||
} | ||
} //namespace config | ||
} // namespace xia | ||
|
||
#endif //SOFTWARE_HELPER_FUNCTIONS_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,2 @@ | ||
#------------- BUILD TESTS -------------------------- | ||
add_executable(test test.cpp | ||
unit/app/test_pixie16app.cpp | ||
unit/app/test_utilities.cpp | ||
unit/sys/test_pixie16sys.cpp | ||
unit/sys/test_tools.cpp | ||
unit/sys/test_i2cm24c64.cpp | ||
unit/sys/test_communication.cpp) | ||
target_include_directories(test PUBLIC | ||
${PROJECT_SOURCE_DIR}/sdk/include | ||
${PROJECT_SOURCE_DIR}/vendor/analog_devices | ||
${PROJECT_SOURCE_DIR}/vendor/doctest | ||
${PLX_INCLUDE_DIR}) | ||
IF(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13") | ||
target_link_directories(test PUBLIC ${PLX_LIBRARY_DIR}) | ||
ENDIF() | ||
|
||
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") | ||
target_link_libraries(test PUBLIC PixieSDK ${PLX_SHARED_LIB} dl m) | ||
target_compile_definitions(test PUBLIC PLX_LITTLE_ENDIAN PCI_CODE PLX_LINUX PRINT_DEBUG_MSG) | ||
target_compile_options(test PUBLIC -g -Wall) | ||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") | ||
target_link_libraries(test PUBLIC PixieSDK ${PLX_SHARED_LIB} winmm) | ||
target_compile_definitions(test PUBLIC PLX_LITTLE_ENDIAN PCI_CODE PLX_WINDOWS PRINT_DEBUG_MSG) | ||
endif () | ||
|
||
add_subdirectory(unit) | ||
add_subdirectory(system) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
list(APPEND SYSTEM_TESTS test_memory_reads_and_writes) | ||
|
||
foreach (PROG IN LISTS SYSTEM_TESTS) | ||
add_executable(${PROG} src/${PROG}.cpp) | ||
target_include_directories(${PROG} PUBLIC ${PROJECT_SOURCE_DIR}/common ${PROJECT_SOURCE_DIR}/vendor/args) | ||
|
||
IF (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13") | ||
target_link_directories(${PROG} PUBLIC PLX_LIBRARY_DIR) | ||
ENDIF () | ||
|
||
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") | ||
target_link_libraries(${PROG} PUBLIC PixieSDK ${PLX_SHARED_LIB} dl m) | ||
target_compile_definitions(${PROG} PUBLIC PLX_LITTLE_ENDIAN PCI_CODE PLX_LINUX PRINT_DEBUG_MSG) | ||
target_compile_options(${PROG} PUBLIC -g -Wall) | ||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") | ||
target_link_libraries(${PROG} PUBLIC PixieSDK ${PLX_SHARED_LIB} winmm) | ||
target_compile_definitions(${PROG} PUBLIC PLX_LITTLE_ENDIAN PCI_CODE PLX_WINDOWS PRINT_DEBUG_MSG) | ||
endif () | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,275 @@ | ||
/*---------------------------------------------------------------------- | ||
* Copyright (c) 2005 - 2020 XIA LLC | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, | ||
* with or without modification, are permitted provided | ||
* that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above | ||
* copyright notice, this list of conditions and the | ||
* following disclaimer. | ||
* * Redistributions in binary form must reproduce the | ||
* above copyright notice, this list of conditions and the | ||
* following disclaimer in the documentation and/or other | ||
* materials provided with the distribution. | ||
* * Neither the name of XIA LLC nor the names of its | ||
* contributors may be used to endorse or promote | ||
* products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | ||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF | ||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
* SUCH DAMAGE. | ||
*----------------------------------------------------------------------*/ | ||
#include "pixie16app_export.h" | ||
#include "pixie16sys_export.h" | ||
#include "pixie16app_common.h" | ||
|
||
#include <sstream> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <cstdio> | ||
#include <signal.h> | ||
#include <cstring> | ||
#include <string> | ||
#include <math.h> | ||
|
||
#ifdef _WINDOWS | ||
#include <windows.h> | ||
#else | ||
#include <unistd.h> | ||
#endif | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
unsigned short NumModules; | ||
unsigned short *PXISlotMap; | ||
char ComFPGAConfigFile[80]; | ||
char SPFPGAConfigFile[80]; | ||
char TrigFPGAConfigFile[80]; | ||
char DSPCodeFile[80]; | ||
char DSPParFile[80]; | ||
char DSPVarFile[80]; | ||
char ErrMSG[256]; | ||
int retval=0; | ||
unsigned int nFIFOWords[24]; | ||
unsigned int *lmdata; | ||
const unsigned long readthresh=16384; | ||
const unsigned int eventlen=2516; | ||
unsigned int readevents; | ||
unsigned int totalerrors; | ||
|
||
////////read cfg file (cfgPixie16.txt)/////////////////////////////////// | ||
const char config[20]="cfgPixie16.txt"; | ||
|
||
ifstream input; | ||
char *temp = new char[80]; | ||
input.open (config, ios::in); | ||
|
||
if (input.fail ()) | ||
{ | ||
cout << "can't open the config file ! " << config << endl << flush; | ||
return false; | ||
} | ||
|
||
input >> NumModules; | ||
cout << "\n\n" << NumModules << " modules, in slots:"; | ||
input.getline (temp, 80); | ||
PXISlotMap = new unsigned short[NumModules+1]; | ||
for (int i = 0; i < NumModules; i++) | ||
{ | ||
input >> PXISlotMap[i]; | ||
input.getline (temp, 80); | ||
cout << PXISlotMap[i] << " "; | ||
} | ||
|
||
//==== This code is necessary if modules are installed in two crates ====// | ||
//input >> PXISlotMap[NumModules]; | ||
//input.getline (temp, 80); | ||
//cout << PXISlotMap[NumModules] << " "; | ||
|
||
cout << endl << "Firmware files: \n"; | ||
input >> ComFPGAConfigFile; | ||
input.getline (temp, 80); | ||
cout << "ComFPGAConfigFile: " << ComFPGAConfigFile << endl; | ||
input >> SPFPGAConfigFile; | ||
input.getline (temp, 80); | ||
cout << "SPFPGAConfigFile: " << SPFPGAConfigFile << endl; | ||
input >> TrigFPGAConfigFile; | ||
input.getline (temp, 80); | ||
cout << "TrigFPGAConfigFile: " << TrigFPGAConfigFile << endl; | ||
input >> DSPCodeFile; | ||
input.getline (temp, 80); | ||
cout << "DSPCodeFile: " << DSPCodeFile << endl; | ||
input >> DSPParFile; | ||
input.getline (temp, 80); | ||
cout << "DSPParFile: " << DSPParFile << endl; | ||
input >> DSPVarFile; | ||
input.getline (temp, 80); | ||
cout << "DSPVarFile: " << DSPVarFile << endl; | ||
input.close(); | ||
input.clear(); | ||
|
||
//////////////////////////////////////////////////////////////////// | ||
cout<<"-----------------------------------------\n"; | ||
cout<<"Booting...\n"; | ||
|
||
retval = Pixie16InitSystem (NumModules, PXISlotMap, 0); | ||
if (retval < 0) | ||
{ | ||
sprintf (ErrMSG, "*ERROR* Pixie16InitSystem failed, retval = %d", retval); | ||
Pixie_Print_MSG (ErrMSG); | ||
return -1; | ||
} | ||
else | ||
{ | ||
cout<<"Init OK "<<retval<<endl; | ||
} | ||
|
||
/////////////////////////////////////////////////// | ||
// Here we use Boot Pattern 0x70, i.e. only loads the | ||
// DSP parameters, Program FIPPIS and Set DACs, etc. We assume | ||
// the Pixie-16 modules have been booted using either nscope or | ||
// other programs. The truth is we don't need to reboot the | ||
// Pixie-16 modules each time when we try to acquire data. | ||
|
||
retval = Pixie16BootModule (ComFPGAConfigFile, SPFPGAConfigFile, TrigFPGAConfigFile, | ||
DSPCodeFile, DSPParFile, DSPVarFile, NumModules, 0x70); | ||
if (retval < 0) | ||
{ | ||
sprintf (ErrMSG, "*ERROR* Pixie16BootModule failed, retval = %d", retval); | ||
Pixie_Print_MSG (ErrMSG); | ||
return -2; | ||
} | ||
else | ||
{ | ||
cout<<"Boot OK "<<retval<<endl; | ||
} | ||
|
||
// Adjust DC-Offsets | ||
for(int k=0; k<NumModules; k++) | ||
{ | ||
retval = Pixie16AdjustOffsets(k); | ||
if (retval < 0) | ||
{ | ||
sprintf (ErrMSG, "*ERROR* Pixie16AdjustOffsets in module %d failed, retval = %d", k, retval); | ||
Pixie_Print_MSG (ErrMSG); | ||
return -6; | ||
} | ||
} | ||
|
||
/////////////////////////////////////////////////// | ||
// Synchronize modules | ||
int modnum = 0; | ||
retval = Pixie16WriteSglModPar ("SYNCH_WAIT", 1, modnum); | ||
if(retval<0) | ||
cout<<"Synch Wait problem "<<retval<<endl; | ||
else | ||
cout<<"Synch Wait OK "<<retval<<endl; | ||
|
||
retval = Pixie16WriteSglModPar ("IN_SYNCH", 0, modnum); | ||
if(retval<0) | ||
cout<<"In Sync problem "<<retval<<endl; | ||
else | ||
cout<<"In Synch OK "<<retval<<endl; | ||
////////////////////////////// | ||
|
||
retval = Pixie16StartListModeRun (NumModules, 0x100, NEW_RUN); | ||
if (retval < 0) | ||
{ | ||
sprintf (ErrMSG, "*ERROR* Pixie16StartListModeRun failed, retval = %d", retval); | ||
Pixie_Print_MSG (ErrMSG); | ||
return -3; | ||
} | ||
else | ||
cout<<"List Mode started OK "<<retval<<endl<<flush; | ||
|
||
usleep(100000); //delay for the DSP run start | ||
|
||
if( (lmdata = (unsigned int *)malloc(sizeof(unsigned int) * 131072)) == NULL) | ||
{ | ||
printf("failed to allocate memory block lmdata\n"); | ||
return -4; | ||
} | ||
|
||
// Clear counters to 0 (counters keep track of how many words each module has read) | ||
for(int k=0; k<NumModules; k++) | ||
{ | ||
nFIFOWords[k] = 0; | ||
} | ||
|
||
readevents = 0; | ||
totalerrors = 0; | ||
|
||
////////////////////////////////////////////// | ||
// Acquiring data | ||
while(1) | ||
{ | ||
for(int k=0; k<NumModules; k++) | ||
{ | ||
retval=Pixie_Read_ExtFIFOStatus(&nFIFOWords[k], k); | ||
if(retval<0) | ||
{ | ||
sprintf (ErrMSG, "*ERROR* read Pixie status failed, retval = %d", retval); | ||
Pixie_Print_MSG (ErrMSG); | ||
return -5; | ||
} | ||
if(nFIFOWords[k] > readthresh) | ||
{ | ||
retval = Pixie_ExtFIFO_Read(lmdata, eventlen, k); | ||
if(retval < 0) | ||
{ | ||
sprintf(ErrMSG, "*ERROR* Pixie_ExtFIFO_Read failed in module %d, retval = %d", k, retval); | ||
Pixie_Print_MSG(ErrMSG); | ||
retval = Pixie16EndRun(0); | ||
if(retval < 0) | ||
{ | ||
free(lmdata); | ||
printf("end run #1 failed, retval=%d\n", retval); | ||
return -6; | ||
} | ||
free(lmdata); | ||
return -7; | ||
} | ||
|
||
// Data check | ||
if(((lmdata[0] & 0xF0) >> 4) != (unsigned int)(k+2)) | ||
{ | ||
totalerrors ++; | ||
printf("read data error: slot number %d, total # of errors=%d\n", (lmdata[0] & 0xF0) / 16, totalerrors); | ||
} | ||
if(((lmdata[0] & 0xF00) >> 8) != 0) | ||
{ | ||
totalerrors ++; | ||
printf("read data error: crate number %d, total # of errors=%d\n", (lmdata[0] & 0xF0) / 16, totalerrors); | ||
} | ||
|
||
readevents ++; | ||
|
||
if(fmod(readevents, 1000) == 0) | ||
{ | ||
printf("read %d events, total # of errors=%d\n", readevents, totalerrors); | ||
} | ||
} | ||
} | ||
if(readevents >= 4294967294) | ||
break; | ||
} | ||
|
||
cout<<"Run ended \n"<<flush; | ||
exit(1); | ||
|
||
} |
Oops, something went wrong.