Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:16

0001 //Test of the external CICADA model emulation model loading and model unloading
0002 //Developed by Andrew Loeliger, Princeton University, Feb 23, 2023
0003 
0004 //We can't test a load of a bad model here, since that is a segfault, not an exception, which is
0005 //OS level and cppunit cannot test against that in any way that qualifies as a success
0006 
0007 //TODO: However, it would be good in the future to assure that loading multiple CICADA models at the
0008 //same time have the correct function symbols assigned to each simultaneously
0009 //i.e. CICADA_v1's predict is not overwritten by CICADA_v2's predict if it is loaded later with a
0010 //CICADA_v1 still around
0011 
0012 //TODO: might also be nice to have a test for model integrity? Known test cases producing known outputs?
0013 //This may not be appropriate for unit testing however.
0014 
0015 #include "ap_fixed.h"
0016 #include "hls4ml/emulator.h"
0017 
0018 #include "cppunit/extensions/HelperMacros.h"
0019 #include <memory>
0020 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
0021 
0022 class test_CICADA : public CppUnit::TestFixture {
0023   CPPUNIT_TEST_SUITE(test_CICADA);
0024   CPPUNIT_TEST(doModelV1Load);
0025   CPPUNIT_TEST(doModelV2Load);
0026   CPPUNIT_TEST(doMultiModelLoad);
0027   CPPUNIT_TEST_SUITE_END();
0028 
0029 public:
0030   void doModelV1Load();
0031   void doModelV2Load();
0032   void doMultiModelLoad();
0033 };
0034 
0035 CPPUNIT_TEST_SUITE_REGISTRATION(test_CICADA);
0036 
0037 void test_CICADA::doModelV1Load() {
0038   auto loader = hls4mlEmulator::ModelLoader("CICADAModel_v1");
0039   auto model = loader.load_model();
0040 }
0041 
0042 void test_CICADA::doModelV2Load() {
0043   auto loader = hls4mlEmulator::ModelLoader("CICADAModel_v2");
0044   auto model = loader.load_model();
0045 }
0046 
0047 void test_CICADA::doMultiModelLoad() {
0048   auto loader_v1 = hls4mlEmulator::ModelLoader("CICADAModel_v1");
0049   auto loader_v2 = hls4mlEmulator::ModelLoader("CICADAModel_v2");
0050   auto model_v1 = loader_v1.load_model();
0051   auto model_v2 = loader_v2.load_model();
0052 }