| THM1176InstrumentDriver 1.2 C++ API for Metrolab THM1176

Loading...
Searching...
No Matches
CTHM1176TimeoutHandlingTest.cpp
Go to the documentation of this file.
1// Copyright (c) 2020 Metrolab Technology S.A., Geneva, Switzerland (www.metrolab.com)
2// See the included file LICENSE.txt for the licensing conditions.
3
7
8#include "gtest/gtest.h"
9#include "THM1176TestUtilities.h"
10
11#include <ctime>
12#include <thread>
13
14 using namespace MTL::Instrument;
15 using namespace MTL::Instrument::THM1176Types;
16
18 class CTHM1176TimeoutHandlingTest : public ::testing::Test
19{
20 protected:
21 static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager;
22 static CTHM1176Instrument<THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS> * pTHM1176;
23
24 static void SetUpTestCase()
25 {
26 ASSERT_EQ(true, ConnectToTHM1176(pResourceManager, pTHM1176));
27 ASSERT_NE(nullptr, pResourceManager);
28 ASSERT_NE(nullptr, pTHM1176);
29 ASSERT_EQ(true, pTHM1176->IsOpen());
30 ASSERT_EQ(true, pTHM1176->Reset());
31 }
32
33 static void TearDownTestCase()
34 {
35 delete pTHM1176;
36 pTHM1176 = nullptr;
37 delete pResourceManager;
38 pResourceManager = nullptr;
39 }
40
41 virtual void SetUp()
42 {
43 // Reset the instrument.
44 ASSERT_NE(pTHM1176, nullptr);
45 ASSERT_EQ(true, pTHM1176->Reset());
46 }
47};
48THM1176_TEST_RESOURCE_MANAGER_CLASS * CTHM1176TimeoutHandlingTest::pResourceManager = nullptr;
49 CTHM1176Instrument<THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS> * CTHM1176TimeoutHandlingTest::pTHM1176 = nullptr;
50
52 TEST_F(CTHM1176TimeoutHandlingTest, ReadWithTimeout)
53{
54 // Reset the instrument.
55 ASSERT_EQ(true, pTHM1176->Reset());
56
57 // Set up a timed trigger of 1 measurement / second.
58 sInputTrigger<uParm> l_Trig;
59 l_Trig.Source = kInputTrigSrcTimer;
60 l_Trig.Period_s = 1.;
61 l_Trig.Count = 1;
62 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
63
64 // Set the timeout to 1 second.
65 pTHM1176->SetTimeout(1000);
66
67 // Measure multiple with with NoMeasurements = 3, DefaultParms=false.
68 // This should complete successfully, working through the timeouts.
69 CFluxList l_Bx, l_By, l_Bz;
70 ASSERT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 3, false));
71}
72
73 static void l_LaunchMeasurement(CTHM1176Instrument<THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS> * pTHM1176)
74{
75 // Measure multiple with with NoMeasurements = 4096, DefaultParms=false.
76 CFluxList l_Bx, l_By, l_Bz;
77 pTHM1176->Measure(l_Bx, l_By, l_Bz, 4096, false);
78}
79
81 TEST_F(CTHM1176TimeoutHandlingTest, DISABLED_AbortRead)
82{
83 // Reset the instrument.
84 ASSERT_EQ(true, pTHM1176->Reset());
85
86 // Set up a timed trigger of 1 measurement / second.
87 sInputTrigger<uParm> l_Trig;
88 l_Trig.Source = kInputTrigSrcTimer;
89 l_Trig.Period_s = 1.;
90 l_Trig.Count = 1;
91 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
92
93 // Set the timeout to 1 second.
94 pTHM1176->SetTimeout(1000);
95
96 // An AbortRead without an ongoing Read should fail.
97 ASSERT_EQ(false, pTHM1176->AbortRead());
98
99 // Launch the measurement in another thread.
100 std::thread l_MeasurementThread(l_LaunchMeasurement, pTHM1176);
101
102 // Wait a second for the measurement to start.
103 std::this_thread::sleep_for(std::chrono::seconds(1));
104
105 // Try to abort the measurement.
106 ASSERT_EQ(true, pTHM1176->AbortRead());
107
108 // Wait for the measurement thread to finish execution.
109 l_MeasurementThread.join();
110
111 // Perform a plain-jane measurement to ensure the instrument is
112 // left in a usable state.
113 CFluxList l_Bx, l_By, l_Bz;
114 ASSERT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz));
115}
TEST_F
TEST_F(CTHM1176TimeoutHandlingTest, ReadWithTimeout)
Definition CTHM1176TimeoutHandlingTest.cpp:52
l_LaunchMeasurement
static void l_LaunchMeasurement(CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > *pTHM1176)
Definition CTHM1176TimeoutHandlingTest.cpp:73
THM1176TestUtilities.h
Utility functions used to test THM1176 API.
ConnectToTHM1176
bool ConnectToTHM1176(THM1176_TEST_RESOURCE_MANAGER_CLASS *&rpResourceManager, CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > *&rpTHM1176)
Connect to a THM1176.
Definition THM1176TestUtilities.cpp:41
CTHM1176TimeoutHandlingTest
Test THM1176 API: Handling timeouts on long acquisitions.
Definition CTHM1176TimeoutHandlingTest.cpp:19
CTHM1176TimeoutHandlingTest::TearDownTestCase
static void TearDownTestCase()
Definition CTHM1176TimeoutHandlingTest.cpp:33
CTHM1176TimeoutHandlingTest::pResourceManager
static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager
Definition CTHM1176TimeoutHandlingTest.cpp:21
CTHM1176TimeoutHandlingTest::pTHM1176
static CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > * pTHM1176
Definition CTHM1176TimeoutHandlingTest.cpp:22
CTHM1176TimeoutHandlingTest::SetUp
virtual void SetUp()
Definition CTHM1176TimeoutHandlingTest.cpp:41
CTHM1176TimeoutHandlingTest::SetUpTestCase
static void SetUpTestCase()
Definition CTHM1176TimeoutHandlingTest.cpp:24
MTL::Instrument::CTHM1176Instrument
THM1176 instrument class.
Definition THM1176.h:98
MTL::Instrument::CTHM1176Instrument::Measure
bool Measure(tFlux &rBx, tFlux &rBy, tFlux &rBz, bool DefaultParms=true, eUnits Units=kT, tFlux ExpectedField=0., unsigned int NoDigits=0)
High-level measurement: single measurement.
Definition THM1176.cpp:1773
MTL::Instrument::THM1176Types::CFluxList
List of flux density values.
Definition THM1176Types.h:170
MTL::Instrument::THM1176Types
Definition THM1176TypeConversions.h:20
MTL::Instrument::THM1176Types::kInputTrigSrcTimer
@ kInputTrigSrcTimer
Timed trigger: start measurement at regular intervals.
Definition THM1176Types.h:419
MTL::Instrument
Definition THM1176.h:74
MTL::Instrument::THM1176Types::sInputTrigger
Input trigger parameter.
Definition THM1176Types.h:426
MTL::Instrument::THM1176Types::sInputTrigger::Count
ParmType< U16 > Count
Trigger count: take this many measurements before sending results.
Definition THM1176Types.h:429
MTL::Instrument::THM1176Types::sInputTrigger::Source
eInputTriggerSource Source
Trigger source.
Definition THM1176Types.h:427
MTL::Instrument::THM1176Types::sInputTrigger::Period_s
ParmType< F64 > Period_s
Trigger period, for timed trigger.
Definition THM1176Types.h:428