Skip to content

Commit cb7ee82

Browse files
committed
Tests: Added several oscillator unit tests.
1 parent d191950 commit cb7ee82

10 files changed

Lines changed: 501 additions & 0 deletions

tests/unit/Oscillator_1.test

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
%description:
2+
Tests constant drift oscillator.
3+
4+
%includes:
5+
#include "inet/clock/contract/IOscillator.h"
6+
7+
using namespace omnetpp;
8+
using namespace inet;
9+
10+
%file: TestNetwork.ned
11+
12+
import inet.clock.oscillator.ConstantDriftOscillator;
13+
14+
network TestNetwork
15+
{
16+
submodules:
17+
test: Test;
18+
oscillator: ConstantDriftOscillator;
19+
}
20+
21+
%inifile: omnetpp.ini
22+
[General]
23+
ned-path = .;../../../../src;../../lib
24+
network = TestNetwork
25+
26+
*.oscillator.nominalTickLength = 1ps
27+
28+
%activity:
29+
30+
#define CHECK(x) { auto r = oscillator->x; std::cout << #x << " -> "<< r << std::endl; }
31+
32+
auto oscillator = check_and_cast<IOscillator *>(cSimulation::getActiveSimulation()->getModuleByPath("oscillator"));
33+
CHECK(computeTicksForInterval(0));
34+
CHECK(computeTicksForInterval(0.000000000001));
35+
CHECK(computeTicksForInterval(0.000000001));
36+
CHECK(computeTicksForInterval(1));
37+
38+
CHECK(computeIntervalForTicks(0));
39+
CHECK(computeIntervalForTicks(1));
40+
CHECK(computeIntervalForTicks(1000));
41+
CHECK(computeIntervalForTicks(1000000000000));
42+
43+
%contains-regex: stdout
44+
.*?computeTicksForInterval\(0\) -> 0
45+
.*?computeTicksForInterval\(0.000000000001\) -> 1
46+
.*?computeTicksForInterval\(0.000000001\) -> 1000
47+
.*?computeTicksForInterval\(1\) -> 1000000000000
48+
.*?computeIntervalForTicks\(0\) -> 0
49+
.*?computeIntervalForTicks\(1\) -> 0.000000000001
50+
.*?computeIntervalForTicks\(1000\) -> 0.000000001
51+
.*?computeIntervalForTicks\(1000000000000\) -> 1
52+
$

tests/unit/Oscillator_10.test

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
%description:
2+
Tests constant drift oscillator emitting numTicks signals.
3+
4+
%includes:
5+
#include "inet/clock/contract/IOscillator.h"
6+
7+
using namespace omnetpp;
8+
using namespace inet;
9+
10+
%file: TestNetwork.ned
11+
12+
import inet.clock.oscillator.ConstantDriftOscillator;
13+
14+
network TestNetwork
15+
{
16+
submodules:
17+
oscillator: ConstantDriftOscillator;
18+
}
19+
20+
%inifile: omnetpp.ini
21+
[General]
22+
ned-path = .;../../../../src;../../lib
23+
network = TestNetwork
24+
sim-time-limit = 1.3s
25+
cmdenv-express-mode = false
26+
cmdenv-log-prefix = "%t: "
27+
28+
*.oscillator.emitNumTicksSignal = true
29+
*.oscillator.nominalTickLength = 1ms
30+
*.oscillator.driftRate = -500000 ppm
31+
*.oscillator.tickOffset = 300us
32+
33+
%# remove formatting
34+
%subst: /\x1B\[[0-9;]*m//
35+
36+
%contains-regex: stdout
37+
0: Initialized oscillator.*?numTicks = 0\.
38+
39+
%contains-regex: stdout
40+
0\.0017: Handling oscillator tick event.*?numTicks = 1\.
41+
42+
%contains-regex: stdout
43+
0\.0037: Handling oscillator tick event.*?numTicks = 2\.
44+
45+
%contains-regex: stdout
46+
1\.0017: Handling oscillator tick event.*?numTicks = 501\.

tests/unit/Oscillator_2.test

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
%description:
2+
Tests constant drift oscillator.
3+
4+
%includes:
5+
#include "inet/clock/contract/IOscillator.h"
6+
7+
using namespace omnetpp;
8+
using namespace inet;
9+
10+
%file: TestNetwork.ned
11+
12+
import inet.clock.oscillator.ConstantDriftOscillator;
13+
14+
network TestNetwork
15+
{
16+
submodules:
17+
test: Test;
18+
oscillator: ConstantDriftOscillator;
19+
}
20+
21+
%inifile: omnetpp.ini
22+
[General]
23+
ned-path = .;../../../../src;../../lib
24+
network = TestNetwork
25+
26+
*.oscillator.nominalTickLength = 1ms
27+
28+
%activity:
29+
30+
#define CHECK(x) { auto r = oscillator->x; std::cout << #x << " -> "<< r << std::endl; }
31+
32+
auto oscillator = check_and_cast<IOscillator *>(cSimulation::getActiveSimulation()->getModuleByPath("oscillator"));
33+
CHECK(computeTicksForInterval(0));
34+
CHECK(computeTicksForInterval(0.000999999));
35+
CHECK(computeTicksForInterval(0.001));
36+
CHECK(computeTicksForInterval(0.999999));
37+
CHECK(computeTicksForInterval(1));
38+
39+
CHECK(computeIntervalForTicks(0));
40+
CHECK(computeIntervalForTicks(1));
41+
CHECK(computeIntervalForTicks(1000));
42+
43+
%contains-regex: stdout
44+
.*?computeTicksForInterval\(0\) -> 0
45+
.*?computeTicksForInterval\(0.000999999\) -> 0
46+
.*?computeTicksForInterval\(0.001\) -> 1
47+
.*?computeTicksForInterval\(0.999999\) -> 999
48+
.*?computeTicksForInterval\(1\) -> 1000
49+
.*?computeIntervalForTicks\(0\) -> 0
50+
.*?computeIntervalForTicks\(1\) -> 0.001
51+
.*?computeIntervalForTicks\(1000\) -> 1
52+
$

tests/unit/Oscillator_3.test

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
%description:
2+
Tests constant drift oscillator.
3+
4+
%includes:
5+
#include "inet/clock/contract/IOscillator.h"
6+
7+
using namespace omnetpp;
8+
using namespace inet;
9+
10+
%file: TestNetwork.ned
11+
12+
import inet.clock.oscillator.ConstantDriftOscillator;
13+
14+
network TestNetwork
15+
{
16+
submodules:
17+
test: Test;
18+
oscillator: ConstantDriftOscillator;
19+
}
20+
21+
%inifile: omnetpp.ini
22+
[General]
23+
ned-path = .;../../../../src;../../lib
24+
network = TestNetwork
25+
26+
*.oscillator.nominalTickLength = 1ms
27+
*.oscillator.driftRate = -500000 ppm
28+
29+
%activity:
30+
31+
#define CHECK(x) { auto r = oscillator->x; std::cout << #x << " -> "<< r << std::endl; }
32+
33+
auto oscillator = check_and_cast<IOscillator *>(cSimulation::getActiveSimulation()->getModuleByPath("oscillator"));
34+
CHECK(computeTicksForInterval(0));
35+
CHECK(computeTicksForInterval(0.001));
36+
CHECK(computeTicksForInterval(0.001999999));
37+
CHECK(computeTicksForInterval(0.002));
38+
CHECK(computeTicksForInterval(1));
39+
40+
CHECK(computeIntervalForTicks(0));
41+
CHECK(computeIntervalForTicks(1));
42+
CHECK(computeIntervalForTicks(1000));
43+
44+
%contains-regex: stdout
45+
.*?computeTicksForInterval\(0\) -> 0
46+
.*?computeTicksForInterval\(0.001\) -> 0
47+
.*?computeTicksForInterval\(0.001999999\) -> 0
48+
.*?computeTicksForInterval\(0.002\) -> 1
49+
.*?computeTicksForInterval\(1\) -> 500
50+
.*?computeIntervalForTicks\(0\) -> 0
51+
.*?computeIntervalForTicks\(1\) -> 0.002
52+
.*?computeIntervalForTicks\(1000\) -> 2
53+
$

tests/unit/Oscillator_4.test

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
%description:
2+
Tests constant drift oscillator.
3+
4+
%includes:
5+
#include "inet/clock/contract/IOscillator.h"
6+
7+
using namespace omnetpp;
8+
using namespace inet;
9+
10+
%file: TestNetwork.ned
11+
12+
import inet.clock.oscillator.ConstantDriftOscillator;
13+
14+
network TestNetwork
15+
{
16+
submodules:
17+
test: Test;
18+
oscillator: ConstantDriftOscillator;
19+
}
20+
21+
%inifile: omnetpp.ini
22+
[General]
23+
ned-path = .;../../../../src;../../lib
24+
network = TestNetwork
25+
26+
*.oscillator.nominalTickLength = 1ms
27+
*.oscillator.tickOffset = 300us
28+
29+
%activity:
30+
31+
#define CHECK(x) { auto r = oscillator->x; std::cout << #x << " -> "<< r << std::endl; }
32+
33+
auto oscillator = check_and_cast<IOscillator *>(cSimulation::getActiveSimulation()->getModuleByPath("oscillator"));
34+
CHECK(computeTicksForInterval(0));
35+
CHECK(computeTicksForInterval(0.0006999999));
36+
CHECK(computeTicksForInterval(0.0007));
37+
CHECK(computeTicksForInterval(0.001));
38+
CHECK(computeTicksForInterval(0.9996999999));
39+
CHECK(computeTicksForInterval(0.9997));
40+
CHECK(computeTicksForInterval(1));
41+
42+
CHECK(computeIntervalForTicks(0));
43+
CHECK(computeIntervalForTicks(1));
44+
CHECK(computeIntervalForTicks(1000));
45+
46+
%contains-regex: stdout
47+
.*?computeTicksForInterval\(0\) -> 0
48+
.*?computeTicksForInterval\(0.0006999999\) -> 0
49+
.*?computeTicksForInterval\(0.0007\) -> 1
50+
.*?computeTicksForInterval\(0.001\) -> 1
51+
.*?computeTicksForInterval\(0.9996999999\) -> 999
52+
.*?computeTicksForInterval\(0.9997\) -> 1000
53+
.*?computeTicksForInterval\(1\) -> 1000
54+
.*?computeIntervalForTicks\(0\) -> 0
55+
.*?computeIntervalForTicks\(1\) -> 0.0007
56+
.*?computeIntervalForTicks\(1000\) -> 0.9997
57+
$

tests/unit/Oscillator_5.test

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
%description:
2+
Tests constant drift oscillator.
3+
4+
%includes:
5+
#include "inet/clock/contract/IOscillator.h"
6+
7+
using namespace omnetpp;
8+
using namespace inet;
9+
10+
%file: TestNetwork.ned
11+
12+
import inet.clock.oscillator.ConstantDriftOscillator;
13+
14+
network TestNetwork
15+
{
16+
submodules:
17+
test: Test;
18+
oscillator: ConstantDriftOscillator;
19+
}
20+
21+
%inifile: omnetpp.ini
22+
[General]
23+
ned-path = .;../../../../src;../../lib
24+
network = TestNetwork
25+
26+
*.oscillator.nominalTickLength = 1ms
27+
*.oscillator.driftRate = -500000 ppm
28+
*.oscillator.tickOffset = 300us
29+
30+
%activity:
31+
32+
#define CHECK(x) { auto r = oscillator->x; std::cout << #x << " -> "<< r << std::endl; }
33+
34+
auto oscillator = check_and_cast<IOscillator *>(cSimulation::getActiveSimulation()->getModuleByPath("oscillator"));
35+
CHECK(computeTicksForInterval(0));
36+
CHECK(computeTicksForInterval(0.0016999999));
37+
CHECK(computeTicksForInterval(0.0017));
38+
CHECK(computeTicksForInterval(0.0036999999));
39+
CHECK(computeTicksForInterval(0.0037));
40+
CHECK(computeTicksForInterval(0.9996999999));
41+
CHECK(computeTicksForInterval(0.9997));
42+
CHECK(computeTicksForInterval(1.9996999999));
43+
CHECK(computeTicksForInterval(1.9997));
44+
45+
CHECK(computeIntervalForTicks(0));
46+
CHECK(computeIntervalForTicks(1));
47+
CHECK(computeIntervalForTicks(2));
48+
CHECK(computeIntervalForTicks(500));
49+
CHECK(computeIntervalForTicks(1000));
50+
51+
%contains-regex: stdout
52+
.*?computeTicksForInterval\(0\) -> 0
53+
.*?computeTicksForInterval\(0.0016999999\) -> 0
54+
.*?computeTicksForInterval\(0.0017\) -> 1
55+
.*?computeTicksForInterval\(0.0036999999\) -> 1
56+
.*?computeTicksForInterval\(0.0037\) -> 2
57+
.*?computeTicksForInterval\(0.9996999999\) -> 499
58+
.*?computeTicksForInterval\(0.9997\) -> 500
59+
.*?computeTicksForInterval\(1.9996999999\) -> 999
60+
.*?computeTicksForInterval\(1.9997\) -> 1000
61+
.*?computeIntervalForTicks\(0\) -> 0
62+
.*?computeIntervalForTicks\(1\) -> 0.0017
63+
.*?computeIntervalForTicks\(2\) -> 0.0037
64+
.*?computeIntervalForTicks\(500\) -> 0.9997
65+
.*?computeIntervalForTicks\(1000\) -> 1.9997
66+
$

tests/unit/Oscillator_6.test

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
%description:
2+
Tests constant drift oscillator.
3+
4+
%includes:
5+
#include "inet/clock/contract/IOscillator.h"
6+
7+
using namespace omnetpp;
8+
using namespace inet;
9+
10+
%file: TestNetwork.ned
11+
12+
import inet.clock.oscillator.ConstantDriftOscillator;
13+
14+
network TestNetwork
15+
{
16+
submodules:
17+
test: Test;
18+
oscillator: ConstantDriftOscillator;
19+
}
20+
21+
%inifile: omnetpp.ini
22+
[General]
23+
ned-path = .;../../../../src;../../lib
24+
network = TestNetwork
25+
26+
*.oscillator.nominalTickLength = 2ps
27+
*.oscillator.driftRate = 1000000 ppm
28+
29+
%activity:
30+
31+
#define CHECK(x) { auto r = oscillator->x; std::cout << #x << " -> "<< r << std::endl; }
32+
33+
auto oscillator = check_and_cast<IOscillator *>(cSimulation::getActiveSimulation()->getModuleByPath("oscillator"));
34+
CHECK(computeTicksForInterval(0));
35+
36+
CHECK(computeIntervalForTicks(0));
37+
38+
%contains-regex: stdout
39+
.*?computeTicksForInterval\(0\) -> 0
40+
.*?computeIntervalForTicks\(0\) -> 0
41+
$

0 commit comments

Comments
 (0)