-
Notifications
You must be signed in to change notification settings - Fork 22
/
channelAccessIFTest.cpp
2426 lines (1793 loc) · 79.3 KB
/
channelAccessIFTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// disable buggy boost enable_shared_from_this assert code
#define BOOST_DISABLE_ASSERTS
#include <stdlib.h>
#include <time.h>
#include <vector>
#include <map>
#include <math.h>
#include <epicsExit.h>
#include <epicsUnitTest.h>
#include <testMain.h>
#include <pv/logger.h>
#include <pv/pvAccess.h>
#include <pv/serverContext.h>
#include <pv/clientFactory.h>
#include <pv/clientContextImpl.h>
#include <pv/standardPVField.h>
#include <pv/pvTimeStamp.h>
#include <pv/current_function.h>
#include "channelAccessIFTest.h"
//#define ENABLE_STRESS_TESTS
#define TESTSERVERNOMAIN
#include "testServer.cpp"
namespace TR1 = std::tr1;
// int value, 1Hz increment by one
const std::string ChannelAccessIFTest::TEST_COUNTER_CHANNEL_NAME = "testCounter";
// int value, increment on process
const std::string ChannelAccessIFTest::TEST_SIMPLECOUNTER_CHANNEL_NAME = "testSimpleCounter";
// double value, NTScalar
const std::string ChannelAccessIFTest::TEST_CHANNEL_NAME = "testValue";
// double value
const std::string ChannelAccessIFTest::TEST_VALUEONLY_CHANNEL_NAME = "testValueOnly";
// RPC sum service: int a + int b -> int c
const std::string ChannelAccessIFTest::TEST_SUMRPC_CHANNEL_NAME = "testSum";
// double[] value
const std::string ChannelAccessIFTest::TEST_ARRAY_CHANNEL_NAME = "testArray1";
#ifdef ENABLE_STRESS_TESTS
#define EXTRA_STRESS_TESTS 5
#else
#define EXTRA_STRESS_TESTS 0
#endif
/// test if values are equal within a given tolerance
template <typename T>
inline bool compareWithTol(const T v1, const T v2, const T tol)
{
return (std::fabs(v1 - v2) <= tol);
}
int ChannelAccessIFTest::runAllTest() {
testPlan(152+EXTRA_STRESS_TESTS);
epics::pvAccess::Configuration::shared_pointer base_config(ConfigurationBuilder()
//.add("EPICS_PVA_DEBUG", "3")
.add("EPICS_PVAS_INTF_ADDR_LIST", "127.0.0.1")
.add("EPICS_PVA_ADDR_LIST", "127.0.0.1")
.add("EPICS_PVA_AUTO_ADDR_LIST","0")
.add("EPICS_PVA_SERVER_PORT", "0")
.add("EPICS_PVA_BROADCAST_PORT", "0")
.push_map()
.build());
TestServer::shared_pointer tstserv(new TestServer(base_config));
testDiag("TestServer on ports TCP=%u UDP=%u",
tstserv->getServerPort(),
tstserv->getBroadcastPort());
ConfigurationFactory::registerConfiguration("pvAccess-client",
ConfigurationBuilder()
.push_config(base_config)
//.add("EPICS_PVA_DEBUG", "3")
.add("EPICS_PVA_BROADCAST_PORT", tstserv->getBroadcastPort())
.push_map()
.build());
epics::pvAccess::ClientFactory::start();
m_provider = ChannelProviderRegistry::clients()->getProvider("pva");
test_implementation();
test_providerName();
test_createEmptyChannel();
test_createChannelWithInvalidPriority();
test_createChannel();
test_findEmptyChannel();
test_findChannel();
test_channel();
test_channelGetWithInvalidChannelAndRequester();
test_channelGetNoProcess();
test_channelGetIntProcess();
test_channelGetTestNoConnection();
test_channelGetNotYetConnected();
test_channelPutWithInvalidChannelAndRequester();
test_channelPutNoProcess();
test_channelPutIntProcess();
test_channelPutTestNoConnection();
test_channelPutNotYetConnected();
test_channelGetFieldAll();
test_channelGetFieldValue();
test_channelGetFieldInvalid();
test_channelProcesstWithInvalidRequesterAndRequest();
test_channelProcess();
test_channelProcessNoConnection();
test_channelPutGetWithInvalidRequesterAndRequest();
test_channelPutGetNoProcess_putGet();
test_channelPutGetNoProcess_getPut();
test_channelPutGetNoProcess_getGet();
test_channelPutGetNoProcess_destroy();
test_channelPutGetIntProcess();
test_channelRPC();
test_channelRPC_destroy();
test_channelRPCWithInvalidRequesterAndRequest();
test_channelMonitorWithInvalidRequesterAndRequest();
test_channelMonitor(1);
test_channelArray();
test_channelArray_destroy();
test_channelArrayTestNoConnection();
#ifdef ENABLE_STRESS_TESTS
test_stressPutAndGetLargeArray();
test_stressConnectDisconnect();
test_stressConnectGetDisconnect();
test_stressMonitorAndProcess();
#endif
test_recreateChannelOnDestroyedProvider();
return testDone();
}
Channel::shared_pointer ChannelAccessIFTest::createChannel(string channelName, bool debug )
{
TR1::shared_ptr<SyncChannelRequesterImpl> channelReq(new SyncChannelRequesterImpl(debug));
Channel::shared_pointer channel = getChannelProvider()->createChannel(channelName, channelReq);
return channel;
}
Channel::shared_pointer ChannelAccessIFTest::syncCreateChannel(string channelName, bool debug )
{
TR1::shared_ptr<SyncChannelRequesterImpl> channelReq(new SyncChannelRequesterImpl(debug));
Channel::shared_pointer channel = getChannelProvider()->createChannel(channelName, channelReq);
bool isConnected = channelReq->waitUntilStateChange(getTimeoutSec());
if (!isConnected) {
std::cerr << "[" << channelName << "] failed to connect to the channel. " << std::endl;
return TR1::shared_ptr<Channel>();
}
return channel;
}
SyncChannelGetRequesterImpl::shared_pointer ChannelAccessIFTest::syncCreateChannelGet(
Channel::shared_pointer const & channel, string const & request, bool debug )
{
TR1::shared_ptr<SyncChannelGetRequesterImpl>
channelGetReq(new SyncChannelGetRequesterImpl(channel->getChannelName(), debug));
PVStructure::shared_pointer pvRequest = createRequest(request);
ChannelGet::shared_pointer op(channel->createChannelGet(channelGetReq,pvRequest));
bool succStatus = channelGetReq->waitUntilGetDone(getTimeoutSec());
if (!succStatus) {
std::cerr << "[" << channel->getChannelName() << "] failed to get. " << std::endl;
return TR1::shared_ptr<SyncChannelGetRequesterImpl>();
}
return channelGetReq;
}
SyncChannelPutRequesterImpl::shared_pointer ChannelAccessIFTest::syncCreateChannelPut(
Channel::shared_pointer const & channel, string const & request, bool debug )
{
TR1::shared_ptr<SyncChannelPutRequesterImpl>
channelPutReq(new SyncChannelPutRequesterImpl(channel->getChannelName(), debug));
PVStructure::shared_pointer pvRequest = createRequest(request);
ChannelPut::shared_pointer op(channel->createChannelPut(channelPutReq,pvRequest));
bool succStatus = channelPutReq->waitUntilConnected(getTimeoutSec());
if (!succStatus) {
std::cerr << "[" << channel->getChannelName() << "] failed to create a put channel. " << std::endl;
return TR1::shared_ptr<SyncChannelPutRequesterImpl>();
}
return channelPutReq;
}
SyncChannelPutGetRequesterImpl::shared_pointer ChannelAccessIFTest::syncCreateChannelPutGet(
Channel::shared_pointer const & channel, string const & request, bool debug )
{
TR1::shared_ptr<SyncChannelPutGetRequesterImpl>
channelPutGetReq(new SyncChannelPutGetRequesterImpl(debug));
PVStructure::shared_pointer pvRequest = createRequest(request);
ChannelPutGet::shared_pointer op(channel->createChannelPutGet(channelPutGetReq,pvRequest));
bool succStatus = channelPutGetReq->waitUntilConnected(getTimeoutSec());
if (!succStatus) {
std::cerr << "[" << channel->getChannelName() << "] failed to create a put get channel. " << std::endl;
return TR1::shared_ptr<SyncChannelPutGetRequesterImpl>();
}
return channelPutGetReq;
}
SyncChannelRPCRequesterImpl::shared_pointer ChannelAccessIFTest::syncCreateChannelRPC(
Channel::shared_pointer const & channel, bool debug )
{
TR1::shared_ptr<SyncChannelRPCRequesterImpl>
channelRPCReq(new SyncChannelRPCRequesterImpl(debug));
PVStructure::shared_pointer pvRequest = CreateRequest::create()->createRequest(string());
ChannelRPC::shared_pointer op(channel->createChannelRPC(channelRPCReq, pvRequest));
bool succStatus = channelRPCReq->waitUntilConnected(getTimeoutSec());
if (!succStatus) {
std::cerr << "[" << channel->getChannelName() << "] failed to create a RPC channel. " << std::endl;
return TR1::shared_ptr<SyncChannelRPCRequesterImpl>();
}
return channelRPCReq;
}
SyncMonitorRequesterImpl::shared_pointer ChannelAccessIFTest::syncCreateChannelMonitor(
Channel::shared_pointer const & channel, string const & request, bool debug )
{
TR1::shared_ptr<SyncMonitorRequesterImpl> monitorReq(new SyncMonitorRequesterImpl(debug));
PVStructure::shared_pointer pvRequest = createRequest(request);
Monitor::shared_pointer op(channel->createMonitor(monitorReq, pvRequest));
bool succStatus = monitorReq->waitUntilConnected(getTimeoutSec());
if (!succStatus) {
std::cerr << "[" << channel->getChannelName() << "] failed to create a monitor channel. " << std::endl;
return TR1::shared_ptr<SyncMonitorRequesterImpl>();
}
return monitorReq;
}
SyncChannelArrayRequesterImpl::shared_pointer ChannelAccessIFTest::syncCreateChannelArray(
Channel::shared_pointer const & channel, PVStructure::shared_pointer pvRequest, bool debug )
{
TR1::shared_ptr<SyncChannelArrayRequesterImpl> arrayReq(new SyncChannelArrayRequesterImpl(debug));
ChannelArray::shared_pointer op(channel->createChannelArray(arrayReq, pvRequest));
bool succStatus = arrayReq->waitUntilConnected(getTimeoutSec());
if (!succStatus) {
std::cerr << "[" << channel->getChannelName() << "] failed to create an array channel. " << std::endl;
return TR1::shared_ptr<SyncChannelArrayRequesterImpl>();
}
return arrayReq;
}
void ChannelAccessIFTest::test_implementation() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
testOk(getChannelProvider().get() != 0, "%s: channel provider is provided", CURRENT_FUNCTION );
ChannelProvider::shared_pointer cp1 = getChannelProvider();
ChannelProvider::shared_pointer cp2 = getChannelProvider();
testOk(cp1 == cp2, "%s: calling getChannelProvider twice", CURRENT_FUNCTION);
testOk(getTimeoutSec() > 0, "%s: timeout is set", CURRENT_FUNCTION);
}
void ChannelAccessIFTest::test_providerName() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
testOk(!getChannelProvider()->getProviderName().empty(), "%s: provider name is set", CURRENT_FUNCTION);
testOk(getChannelProvider()->getProviderName()== getChannelProvider()->getProviderName(),
"%s: calling getProviderName twice should return the same provider", CURRENT_FUNCTION);
}
void ChannelAccessIFTest::test_createEmptyChannel() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
TR1::shared_ptr<SyncChannelRequesterImpl> channelReq(new SyncChannelRequesterImpl());
try {
Channel::shared_pointer channel = getChannelProvider()->createChannel(std::string(), channelReq);
testFail("%s: empty channel name should not be allowed", CURRENT_FUNCTION);
return;
} catch(std::runtime_error &) {
}
testOk(channelReq->getCreatedCount() == 0,
"%s: checking for empty channel name", CURRENT_FUNCTION);
}
void ChannelAccessIFTest::test_createChannelWithInvalidPriority() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
TR1::shared_ptr<SyncChannelRequesterImpl> channelReq(new SyncChannelRequesterImpl());
try {
Channel::shared_pointer channel = getChannelProvider()->createChannel(std::string(), channelReq,
ChannelProvider::PRIORITY_MIN - 1 );
testFail("%s: invalid priority should not be allowed when creating a channel",CURRENT_FUNCTION);
return;
} catch(std::runtime_error &) {
}
testOk(channelReq->getCreatedCount() == 0,
"%s: checking for invalid priority when creating a new channel",CURRENT_FUNCTION);
}
void ChannelAccessIFTest::test_createChannel() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
TR1::shared_ptr<SyncChannelRequesterImpl> channelReq(new SyncChannelRequesterImpl());
Channel::shared_pointer channel = getChannelProvider()->createChannel(TEST_COUNTER_CHANNEL_NAME, channelReq);
testDiag("Channel to '%s', wait for connect", TEST_COUNTER_CHANNEL_NAME.c_str());
bool succStatus = channelReq->waitUntilStateChange(getTimeoutSec());
if (!succStatus) {
std::cerr << "[" << TEST_COUNTER_CHANNEL_NAME << "] failed to connect. " << std::endl;
testFail("%s: could not create a channel", CURRENT_FUNCTION);
return;
}
channel->destroy();
testOk(channelReq->getStatus().isSuccess(), "%s: create a channel", CURRENT_FUNCTION);
}
void ChannelAccessIFTest::test_recreateChannelOnDestroyedProvider() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
if (isLocal()) {
testOk(true, "%s: recreating channel on destroyed provider", CURRENT_FUNCTION);
return;
}
ChannelProvider::shared_pointer provider = getChannelProvider();
provider->destroy();
try {
test_createChannel();
testFail("%s: exception expected when creating a channel on destroyed context", CURRENT_FUNCTION);
} catch(std::runtime_error &) {
}
}
void ChannelAccessIFTest::test_findEmptyChannel() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
try {
TR1::shared_ptr<SyncChannelFindRequesterImpl> channelFindReq(new SyncChannelFindRequesterImpl());
getChannelProvider()->channelFind(std::string(), channelFindReq);
testFail("%s: empty channel name shoud never be allowed when searching for channels", CURRENT_FUNCTION);
return;
} catch(std::runtime_error &) {
}
testOk(true, "%s: finding an empty channel", CURRENT_FUNCTION);
}
void ChannelAccessIFTest::test_findChannel() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
TR1::shared_ptr<SyncChannelFindRequesterImpl> channelFindReq(new SyncChannelFindRequesterImpl());
getChannelProvider()->channelFind(TEST_COUNTER_CHANNEL_NAME, channelFindReq);
bool isFindResult = channelFindReq->waitUntilFindResult(getTimeoutSec());
if (!isFindResult) {
std::cerr << "[" << TEST_COUNTER_CHANNEL_NAME << "] failed to connect. " << std::endl;
testFail("%s: could not find a channel", CURRENT_FUNCTION);
return;
}
testSkip(1, "finding a channel not implemented");
}
void ChannelAccessIFTest::test_channel() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
TR1::shared_ptr<SyncChannelRequesterImpl> channelReq(new SyncChannelRequesterImpl());
Channel::shared_pointer channel = getChannelProvider()->createChannel(TEST_COUNTER_CHANNEL_NAME, channelReq);
bool succStatus = channelReq->waitUntilStateChange(getTimeoutSec());
if (!succStatus) {
std::cerr << "[" << channel->getChannelName() << "] failed to connect. " << std::endl;
testFail("%s: could not create a channel", CURRENT_FUNCTION);
return;
}
testOk(channelReq->getCreatedCount() == 1, "%s: channel created count", CURRENT_FUNCTION);
testOk(channelReq->getStatus().isSuccess(), "%s: succ created a channel", CURRENT_FUNCTION);
testOk(channelReq->getStateChangeCount() == 1, "%s: channel state change count", CURRENT_FUNCTION);
testOk(channel->getChannelName() == TEST_COUNTER_CHANNEL_NAME, "%s: channel name match", CURRENT_FUNCTION);
testOk(channel->getChannelRequester() == channelReq, "%s: channel requesters match", CURRENT_FUNCTION);
//testOk(channel->getRequesterName() == channelRequesterPtr->getRequesterName(),
// " channel requester's name match");
testSkip(1, "channel requester's name mismatch");
testOk(channel->getProvider() == getChannelProvider(), "%s: channel provider match", CURRENT_FUNCTION);
testOk(!channel->getRemoteAddress().empty(), "%s: channel remote address set", CURRENT_FUNCTION);
testOk(channel->isConnected(), "%s: channel connected ", CURRENT_FUNCTION);
testOk(channel->getConnectionState() == Channel::CONNECTED ,
"%s: channel connection state connected ", CURRENT_FUNCTION);
testDiag("%s: destroying the channel", CURRENT_FUNCTION);
channel->destroy();
succStatus = channelReq->waitUntilStateChange(getTimeoutSec());
if (!succStatus) {
std::cerr << "[" << channel->getChannelName() << "] failed to register a destroy event " << std::endl;
testFail("%s: a destroy event was not caught for the testing channel ", CURRENT_FUNCTION);
return;
}
testOk(channelReq->getCreatedCount() == 1,
"%s: channel created count should be the same on the destroyed channel", CURRENT_FUNCTION);
testOk(channelReq->getStateChangeCount() == 3,
"%s: channel state change count should increase on the destroyed channel", CURRENT_FUNCTION);
testOk(!channel->isConnected(), "%s: channel should not be connected ", CURRENT_FUNCTION);
testOk(channel->getConnectionState() == Channel::DESTROYED ,
"%s: channel connection state DESTROYED ", CURRENT_FUNCTION);
testDiag("%s: destroying the channel yet again", CURRENT_FUNCTION);
channel->destroy();
succStatus = channelReq->waitUntilStateChange(getTimeoutSec());
if (succStatus) {
std::cerr << "[" << channel->getChannelName() << "] registered a duplicate destroy event " << std::endl;
testFail("%s: a destroy event was caught for the testing channel that was destroyed twice ",
CURRENT_FUNCTION);
return;
}
testOk(channelReq->getCreatedCount() == 1,
"%s: channel created count should be the same on the yet again destroyed channel", CURRENT_FUNCTION);
testOk(!channel->isConnected(), "%s: yet again destroyed channel should not be connected ", CURRENT_FUNCTION);
testOk(channel->getConnectionState() == Channel::DESTROYED ,
"%s: yet again destroyed channel connection state DESTROYED ", CURRENT_FUNCTION);
}
void ChannelAccessIFTest::test_channelGetWithInvalidChannelAndRequester() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
Channel::shared_pointer channel = syncCreateChannel(TEST_CHANNEL_NAME);
if (!channel.get()) {
testFail("%s: channel not created ", CURRENT_FUNCTION);
return;
}
testSkip(1, " creating a channel get with a null channel");
//SyncChannelGetRequesterImpl::shared_pointer channelGetReq = synCreateChannelGet(Channel::shared_pointer(),
// string("field(timeStamp,value)"));
testSkip(1, " creating a channel get with an empty request");
//SyncChannelGetRequesterImpl::shared_pointer channelGetReq = syncCreateChannelGet(Channel::shared_pointer(),
// string());
channel->destroy();
}
void ChannelAccessIFTest::test_channelGetNoProcess() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
string request = "field(timeStamp,value)";
Channel::shared_pointer channel = syncCreateChannel(TEST_VALUEONLY_CHANNEL_NAME);
if (!channel.get()) {
testFail("%s: channel not created ", CURRENT_FUNCTION);
return;
}
testDiag("start Get");
SyncChannelGetRequesterImpl::shared_pointer channelGetReq = syncCreateChannelGet(channel,request);
if (!channelGetReq.get()) {
testFail("%s: channel get not created ", CURRENT_FUNCTION);
return;
}
testOk(channelGetReq->getBitSet()->cardinality() == 1, "%s: bitset cardinality", CURRENT_FUNCTION);
testOk(channelGetReq->getBitSet()->get(0) == true, "%s: bitset get(0)", CURRENT_FUNCTION);
bool succStatus = channelGetReq->syncGet(false, getTimeoutSec());
if (!succStatus) {
testFail("%s: sync get failed ", CURRENT_FUNCTION);
return;
}
testOk(channelGetReq->getBitSet()->cardinality() == 0,
"%s: bitset cardinality after first sync get", CURRENT_FUNCTION);
succStatus = channelGetReq->syncGet(false, getTimeoutSec());
if (!succStatus) {
testFail("%s: sync get failed ", CURRENT_FUNCTION);
return;
}
testOk(channelGetReq->getBitSet()->cardinality() == 0,
"%s: bitset cardinality after second sync get", CURRENT_FUNCTION);
channelGetReq->getChannelGet()->destroy();
testOk(channelGetReq->syncGet(false, getTimeoutSec()) == false,
"%s: after the channel get destroy, sync get must fail", CURRENT_FUNCTION);
channel->destroy();
}
void ChannelAccessIFTest::test_channelGetIntProcess() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
Channel::shared_pointer channel = syncCreateChannel(TEST_SIMPLECOUNTER_CHANNEL_NAME);
if (!channel.get()) {
testFail("%s: channel not created ", CURRENT_FUNCTION);
return;
}
test_channelGetIntProcessInternal(channel, CURRENT_FUNCTION);
channel->destroy();
}
void ChannelAccessIFTest::test_channelGetNotYetConnected() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
Channel::shared_pointer channel = createChannel(TEST_SIMPLECOUNTER_CHANNEL_NAME);
if (!channel.get()) {
testFail("%s: channel not created ", CURRENT_FUNCTION);
return;
}
test_channelGetIntProcessInternal(channel, CURRENT_FUNCTION);
channel->destroy();
}
void ChannelAccessIFTest::test_channelGetIntProcessInternal(Channel::shared_pointer channel,
string const & testMethodName) {
string request = "record[process=true]field(timeStamp,value)";
SyncChannelGetRequesterImpl::shared_pointer channelGetReq = syncCreateChannelGet(channel, request);
if (!channelGetReq.get()) {
testFail("%s: channel get not created ", testMethodName.c_str());
return;
}
TR1::shared_ptr<PVInt> value = channelGetReq->getPVStructure()->getSubField<PVInt>("value");
PVTimeStamp pvTimeStamp;
testOk(pvTimeStamp.attach(channelGetReq->getPVStructure()->getSubField<PVStructure>("timeStamp")),
"%s: attaching a timestamp", testMethodName.c_str());
TimeStamp timeStamp;
bool succStatus = channelGetReq->syncGet(false, getTimeoutSec());
if (!succStatus) {
testFail("%s: sync get failed ", testMethodName.c_str());
return;
}
pvTimeStamp.get(timeStamp);
testOk(channelGetReq->getBitSet()->cardinality() == 1, "%s: bitset cardinality", testMethodName.c_str());
testOk(channelGetReq->getBitSet()->get(0) == true, "%s: bitset get(0)", testMethodName.c_str());
int numOfTimes = 3;
for (int i = 0; i < numOfTimes; i++) {
int previousValue = value->get();
TimeStamp previousTimestamp = timeStamp;
epicsThreadSleep(1.0);
bool succStatus = channelGetReq->syncGet(false, getTimeoutSec());
if (!succStatus) {
testFail("%s: sync get failed ", testMethodName.c_str());
return;
}
pvTimeStamp.get(timeStamp);
double deltaT = TimeStamp::diff(timeStamp, previousTimestamp);
testOk((previousValue +1) == value->get(), "%s: testing the counter value change %d == %d",
testMethodName.c_str(), previousValue +1, (int)value->get());
testOk(deltaT > 0.1 && deltaT < 20.0,
"%s: timestamp change was %g", testMethodName.c_str(), deltaT);
}
channelGetReq->getChannelGet()->destroy();
testOk(channelGetReq->syncGet(false, getTimeoutSec()) == false,
"%s: after the channel get destroy, sync get must fail", testMethodName.c_str());
channel->destroy();
}
void ChannelAccessIFTest::test_channelGetTestNoConnection() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
string request = "field(timeStamp,value)";
Channel::shared_pointer channel = syncCreateChannel(TEST_COUNTER_CHANNEL_NAME);
if (!channel.get()) {
testFail("%s: channel not created ", CURRENT_FUNCTION);
return;
}
SyncChannelGetRequesterImpl::shared_pointer channelGetReq = syncCreateChannelGet(channel, request);
if (!channelGetReq.get()) {
testFail("%s: channel get not created ", CURRENT_FUNCTION);
return;
}
channel->destroy();
bool succStatus = channelGetReq->syncGet(false, getTimeoutSec());
if (!succStatus) {
testOk(true, "%s: get failed on destroy channel ", CURRENT_FUNCTION);
}
else {
testFail("%s: get should fail on destroy channel ", CURRENT_FUNCTION);
}
}
void ChannelAccessIFTest::test_channelPutWithInvalidChannelAndRequester() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
Channel::shared_pointer channel = syncCreateChannel(TEST_CHANNEL_NAME);
if (!channel.get()) {
testFail("%s: channel not created ", CURRENT_FUNCTION);
return;
}
testSkip(1, " creating a channel put with a null channel: seg fault");
//SyncChannelPutRequesterImpl::shared_pointer channelPutReq = syncCreateChannelPut(Channel::shared_pointer(),
// string("field(timeStamp,value)"));
testSkip(1, " creating a channel put with an empty request: seg fault");
//SyncChannelPutRequesterImpl::shared_pointer channelPutReq1 = syncCreateChannelPut(channel,
// string());
channel->destroy();
}
void ChannelAccessIFTest::test_channelPutNoProcess() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
string request = "field(value)";
Channel::shared_pointer channel = syncCreateChannel(TEST_CHANNEL_NAME);
if (!channel.get()) {
testFail("%s: channel not created ", CURRENT_FUNCTION);
return;
}
SyncChannelPutRequesterImpl::shared_pointer channelPutReq = syncCreateChannelPut(channel,request);
if (!channelPutReq.get()) {
testFail("%s: channel put not created ", CURRENT_FUNCTION);
return;
}
// first do a get to get pvStrcuture
bool succStatus = channelPutReq->syncGet(getTimeoutSec());
if (!succStatus) {
testFail("%s: sync get failed ", CURRENT_FUNCTION);
return;
}
TR1::shared_ptr<PVDouble> value = channelPutReq->getPVStructure()->getSubField<PVDouble>("value");
if (!value.get()) {
testFail("%s: getting double value field failed ", CURRENT_FUNCTION);
return;
}
double initVal = 123.0;
value->put(initVal);
channelPutReq->getBitSet()->set(value->getFieldOffset());
/*bool*/ succStatus = channelPutReq->syncPut(false, getTimeoutSec());
if (!succStatus) {
testFail("%s: sync put failed ", CURRENT_FUNCTION);
return;
}
succStatus = channelPutReq->syncGet(getTimeoutSec());
if (!succStatus) {
testFail("%s: sync get failed ", CURRENT_FUNCTION);
return;
}
testOk(initVal == value->get(), "%s: initial value matches the get value ", CURRENT_FUNCTION);
value->put(initVal + 2);
channelPutReq->getBitSet()->clear();
succStatus = channelPutReq->syncPut(false, getTimeoutSec());
if (!succStatus) {
testFail("%s: second sync put failed ", CURRENT_FUNCTION);
return;
}
succStatus = channelPutReq->syncGet(getTimeoutSec());
if (!succStatus) {
testFail("%s: second sync get failed ", CURRENT_FUNCTION);
return;
}
if (isLocal()) {
testOk(initVal+2 == value->get(),
"%s: value should not change since bitset is not set unless is local ", CURRENT_FUNCTION);
}
else {
testOk(initVal == value->get(), "%s: value should not change since bitset is not set ", CURRENT_FUNCTION);
}
value->put(initVal + 1);
channelPutReq->getBitSet()->set(value->getFieldOffset());
succStatus = channelPutReq->syncPut(false, getTimeoutSec());
if (!succStatus) {
testFail("%s: third sync put failed ", CURRENT_FUNCTION);
return;
}
succStatus = channelPutReq->syncGet(getTimeoutSec());
if (!succStatus) {
testFail("%s: third sync get failed ", CURRENT_FUNCTION);
return;
}
testOk(initVal+1 == value->get(), "%s: changed value matches the get value ", CURRENT_FUNCTION);
testDiag("%s: Ok, let's destroy the put channel", CURRENT_FUNCTION);
succStatus = channelPutReq->syncPut(true, getTimeoutSec());
if (!succStatus) {
testFail("%s: destroying sync put failed ", CURRENT_FUNCTION);
return;
}
channelPutReq->getChannelPut()->destroy();
succStatus = channelPutReq->syncPut(true, getTimeoutSec());
if (!succStatus) {
testOk(true, "%s: put on destroyed put channel should not succeed ", CURRENT_FUNCTION);
}
else {
testFail("%s: put on destroyed put channel did succeed ", CURRENT_FUNCTION);
}
channel->destroy();
}
void ChannelAccessIFTest::test_channelPutIntProcess() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
Channel::shared_pointer channel = syncCreateChannel(TEST_SIMPLECOUNTER_CHANNEL_NAME);
if (!channel.get()) {
testFail("%s: channel not created ", CURRENT_FUNCTION);
return;
}
test_channelPutIntProcessInternal(channel, CURRENT_FUNCTION);
channel->destroy();
}
void ChannelAccessIFTest::test_channelPutNotYetConnected() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
Channel::shared_pointer channel = createChannel(TEST_SIMPLECOUNTER_CHANNEL_NAME);
if (!channel.get()) {
testFail("%s: channel not created ", CURRENT_FUNCTION);
return;
}
test_channelPutIntProcessInternal(channel, CURRENT_FUNCTION);
channel->destroy();
}
void ChannelAccessIFTest::test_channelPutIntProcessInternal(Channel::shared_pointer channel,
string const & testMethodName) {
string request = "record[process=true]field(value)";
SyncChannelPutRequesterImpl::shared_pointer channelPutReq = syncCreateChannelPut(channel,request);
if (!channelPutReq.get()) {
testFail("%s: channel put not created ", testMethodName.c_str());
return;
}
// first do a get to get pvStructure
bool succStatus = channelPutReq->syncGet(getTimeoutSec());
if (!succStatus) {
testFail("%s: sync get failed ", testMethodName.c_str());
return;
}
TR1::shared_ptr<PVInt> value = channelPutReq->getPVStructure()->getSubField<PVInt>("value");
if (!value.get()) {
testFail("%s: getting int value field failed ", testMethodName.c_str());
return;
}
int initVal = 3;
value->put(initVal);
channelPutReq->getBitSet()->set(value->getFieldOffset());
/*bool*/ succStatus = channelPutReq->syncPut(false, getTimeoutSec());
if (!succStatus) {
testFail("%s: sync put failed ", testMethodName.c_str());
return;
}
succStatus = channelPutReq->syncGet(getTimeoutSec());
if (!succStatus) {
testFail("%s: sync get failed ", testMethodName.c_str());
return;
}
testOk(initVal + 1 == value->get(), "%s: value changed +1 due to processing ", testMethodName.c_str());
value->put(initVal + 3);
channelPutReq->getBitSet()->clear();
succStatus = channelPutReq->syncPut(false, getTimeoutSec());
if (!succStatus) {
testFail("%s: second sync put failed ", testMethodName.c_str());
return;
}
succStatus = channelPutReq->syncGet(getTimeoutSec());
if (!succStatus) {
testFail("%s: second sync get failed ", testMethodName.c_str());
return;
}
if (isLocal()) {
testOk(initVal+4 == value->get(),
"%s: value changed due to processing unless is local ", testMethodName.c_str());
}
else {
testOk(initVal+2 == value->get(), "%s: value not changed ", testMethodName.c_str());
}
testDiag("%s: Ok, let's destroy the put channel", testMethodName.c_str());
succStatus = channelPutReq->syncPut(true, getTimeoutSec());
if (!succStatus) {
testFail("%s: destroying sync put failed ", testMethodName.c_str());
return;
}
channelPutReq->getChannelPut()->destroy();
succStatus = channelPutReq->syncPut(true, getTimeoutSec());
if (!succStatus) {
testOk(true, "%s: put on destroyed put channel should not succeed ", testMethodName.c_str());
}
else {
testFail("%s: put on destroyed put channel did succeed ", testMethodName.c_str());
}
channel->destroy();
}
void ChannelAccessIFTest::test_channelPutTestNoConnection() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
string request = "field(timeStamp,value)";
Channel::shared_pointer channel = syncCreateChannel(TEST_COUNTER_CHANNEL_NAME);
if (!channel.get()) {
testFail("%s: channel not created ", CURRENT_FUNCTION);
return;
}
SyncChannelPutRequesterImpl::shared_pointer channelPutReq = syncCreateChannelPut(channel, request);
if (!channelPutReq.get()) {
testFail("%s: channel put not created ", CURRENT_FUNCTION);
return;
}
channel->destroy();
bool succStatus = channelPutReq->syncPut(false, getTimeoutSec());
if (!succStatus) {
testOk(true, "%s: put failed on destroy channel ", CURRENT_FUNCTION);
}
else {
testFail("%s: put should fail on destroy channel ", CURRENT_FUNCTION);
}
channel->destroy();
}
void ChannelAccessIFTest::test_channelGetFieldAll() {
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
Channel::shared_pointer channel = syncCreateChannel(TEST_COUNTER_CHANNEL_NAME);
if (!channel.get()) {
testFail("%s: channel not created ", CURRENT_FUNCTION);
return;
}
TR1::shared_ptr<SyncGetFieldRequesterImpl>
channelGetFieldReq(new SyncGetFieldRequesterImpl());
channel->getField(channelGetFieldReq, string());
bool succStatus = channelGetFieldReq->waitUntilGetDone(getTimeoutSec());
if (!succStatus) {
testFail("%s: get all fields failed ", CURRENT_FUNCTION);
}
else {
testOk(true, "%s: get all fields succeeded ", CURRENT_FUNCTION);
testOk(channelGetFieldReq->getField()->getType() == structure,
"%s: field type is structure ", CURRENT_FUNCTION);
}
channel->destroy();
}