Project
Loading...
Searching...
No Matches
test_TimesliceIndex.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include <catch_amalgamated.hpp>
15
16TEST_CASE("TestBasics")
17{
18 using namespace o2::framework;
19 std::vector<InputChannelInfo> infos{1};
20 TimesliceIndex index{1, infos};
21 TimesliceSlot slot;
22
23 REQUIRE(index.size() == 0);
24 index.resize(10);
25 REQUIRE(index.size() == 10);
26 REQUIRE(index.isValid({0}) == false);
27 REQUIRE(index.isDirty({0}) == false);
28 index.associate(TimesliceId{10}, TimesliceSlot{0});
29 REQUIRE(index.isValid(TimesliceSlot{0}));
30 REQUIRE(index.isDirty({0}) == true);
31 index.associate(TimesliceId{20}, TimesliceSlot{0});
32 REQUIRE(index.isValid(TimesliceSlot{0}));
33 REQUIRE(VariableContextHelpers::getTimeslice(index.getVariablesForSlot(TimesliceSlot{0})).value == 20);
34 REQUIRE(index.isDirty(TimesliceSlot{0}));
35 index.associate(TimesliceId{1}, TimesliceSlot{1});
36 REQUIRE(VariableContextHelpers::getTimeslice(index.getVariablesForSlot(TimesliceSlot{0})).value == 20);
37 REQUIRE(VariableContextHelpers::getTimeslice(index.getVariablesForSlot(TimesliceSlot{1})).value == 1);
38 REQUIRE(index.isValid(TimesliceSlot{2}) == false);
39 slot = TimesliceSlot{0};
40 REQUIRE(index.isDirty(slot));
41 slot = TimesliceSlot{2};
42 REQUIRE(index.isValid(slot) == false);
43 REQUIRE(index.isDirty(slot) == false);
44 index.markAsInvalid(slot);
45 REQUIRE(index.isDirty(slot) == false);
46 REQUIRE(index.isValid(slot) == false);
47}
48
49TEST_CASE("TestLRUReplacement")
50{
51 using namespace o2::framework;
52 std::vector<InputChannelInfo> infos{1};
53 TimesliceIndex index{1, infos};
54 index.resize(3);
56
57 {
58 context.put({0, uint64_t{10}});
59 context.commit();
60 auto [action, slot] = index.replaceLRUWith(context, {10});
61 REQUIRE(slot.index == 0);
62 REQUIRE(action == TimesliceIndex::ActionTaken::ReplaceUnused);
63 }
64 {
65 context.put({0, uint64_t{20}});
66 context.commit();
67 auto [action, slot] = index.replaceLRUWith(context, {20});
68 REQUIRE(slot.index == 1);
69 REQUIRE(action == TimesliceIndex::ActionTaken::ReplaceUnused);
70 }
71 {
72 context.put({0, uint64_t{30}});
73 context.commit();
74 auto [action, slot] = index.replaceLRUWith(context, {30});
75 REQUIRE(slot.index == 2);
76 REQUIRE(action == TimesliceIndex::ActionTaken::ReplaceUnused);
77 }
78 {
79 context.put({0, uint64_t{40}});
80 context.commit();
81 auto [action, slot] = index.replaceLRUWith(context, {40});
82 REQUIRE(slot.index == TimesliceSlot::INVALID);
83 REQUIRE(action == TimesliceIndex::ActionTaken::Wait);
84 }
85 {
86 context.put({0, uint64_t{50}});
87 context.commit();
88 auto [action, slot] = index.replaceLRUWith(context, {50});
89 REQUIRE(slot.index == TimesliceSlot::INVALID);
90 REQUIRE(action == TimesliceIndex::ActionTaken::Wait);
91 }
92 {
93 context.put({0, uint64_t{10}});
94 context.commit();
95 auto [action, slot] = index.replaceLRUWith(context, {10});
96 REQUIRE(slot.index == TimesliceSlot::INVALID);
97 REQUIRE(action == TimesliceIndex::ActionTaken::Wait);
98 }
99}
100
103TEST_CASE("TestOldestPossibleTimeslice")
104{
105 using namespace o2::framework;
106 std::vector<InputChannelInfo> infos{2};
107 TimesliceIndex index{2, infos};
108
109 index.resize(3);
110
112 {
113 context.put({0, uint64_t{9}});
114 context.commit();
115 auto [action, slot] = index.replaceLRUWith(context, {9});
116 index.markAsDirty(slot, true);
117 auto oldest = index.setOldestPossibleInput({9}, {0});
118 for (size_t i = 0; i < 3; ++i) {
119 bool invalidated = index.validateSlot(TimesliceSlot{i}, oldest.timeslice);
120 INFO("Slot " << i << " valid: " << invalidated);
121 }
122 index.updateOldestPossibleOutput(false);
123 REQUIRE(slot.index == 1);
124 REQUIRE(action == TimesliceIndex::ActionTaken::ReplaceUnused);
125 }
126 {
127 context.put({0, uint64_t{10}});
128 context.commit();
129 auto [action, slot] = index.replaceLRUWith(context, {10});
130 index.markAsDirty(slot, true);
131 auto oldest = index.setOldestPossibleInput({10}, {1});
132 for (size_t i = 0; i < 3; ++i) {
133 bool invalidated = index.validateSlot(TimesliceSlot{i}, oldest.timeslice);
134 }
135 REQUIRE(slot.index == 0);
136 REQUIRE(action == TimesliceIndex::ActionTaken::ReplaceUnused);
137 }
138
139 REQUIRE(index.getOldestPossibleInput().timeslice.value == 9);
140 REQUIRE(index.getOldestPossibleOutput().timeslice.value == 0);
141 auto oldest = index.setOldestPossibleInput({10}, {0});
142 for (size_t i = 0; i < 3; ++i) {
143 bool invalidated = index.validateSlot(TimesliceSlot{i}, oldest.timeslice);
144 }
145 index.updateOldestPossibleOutput(false);
146 REQUIRE(index.getOldestPossibleInput().timeslice.value == 10);
147 REQUIRE(index.getOldestPossibleOutput().timeslice.value == 9);
148 oldest = index.setOldestPossibleInput({11}, {1});
149 for (size_t i = 0; i < 3; ++i) {
150 bool invalidated = index.validateSlot(TimesliceSlot{i}, oldest.timeslice);
151 }
152 index.updateOldestPossibleOutput(false);
153 REQUIRE(index.getOldestPossibleInput().timeslice.value == 10);
154 REQUIRE(index.getOldestPossibleOutput().timeslice.value == 9);
155 // We fake the fact that we have processed the slot 0;
156 index.markAsDirty({1}, false);
157 index.updateOldestPossibleOutput(false);
158 REQUIRE(index.getOldestPossibleOutput().timeslice.value == 9);
159 index.markAsInvalid({1});
160 index.updateOldestPossibleOutput(false);
161 REQUIRE(index.getOldestPossibleOutput().timeslice.value == 10);
162}
int32_t i
GLuint index
Definition glcorearb.h:781
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("TestBasics")