summaryrefslogtreecommitdiff
path: root/tests/unit/map65/test_map65_half_symbol_scheduler.cpp
blob: 984c37a848686b14d6f1d6293a526afb1629c8ba (plain)
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
#include "half_symbol_scheduler.h"

#include <QtTest/QtTest>

class TestMap65HalfSymbolScheduler final : public QObject
{
  Q_OBJECT

private slots:
  void retries_busy_half_symbols ();
  void catches_up_one_half_symbol_at_a_time ();
  void resets_for_the_next_period ();
};

void TestMap65HalfSymbolScheduler::retries_busy_half_symbols ()
{
  Map65HalfSymbolScheduler scheduler;
  std::atomic_bool busy {false};

  QVERIFY (scheduler.claim_next (1, busy));
  QCOMPARE (scheduler.scheduled_half_symbol (), 1);
  QVERIFY (!scheduler.claim_next (2, busy));
  QCOMPARE (scheduler.scheduled_half_symbol (), 1);

  busy.store (false, std::memory_order_release);
  QVERIFY (scheduler.claim_next (2, busy));
  QCOMPARE (scheduler.scheduled_half_symbol (), 2);
}

void TestMap65HalfSymbolScheduler::catches_up_one_half_symbol_at_a_time ()
{
  Map65HalfSymbolScheduler scheduler;
  std::atomic_bool busy {false};

  for (int expected = 1; expected <= 5; ++expected)
    {
      QVERIFY (scheduler.claim_next (5, busy));
      QCOMPARE (scheduler.scheduled_half_symbol (), expected);
      busy.store (false, std::memory_order_release);
    }

  QVERIFY (!scheduler.claim_next (5, busy));
  QVERIFY (!busy.load (std::memory_order_acquire));
}

void TestMap65HalfSymbolScheduler::resets_for_the_next_period ()
{
  Map65HalfSymbolScheduler scheduler;
  std::atomic_bool busy {false};

  QVERIFY (scheduler.claim_next (1, busy));
  busy.store (false, std::memory_order_release);
  scheduler.reset ();

  QCOMPARE (scheduler.scheduled_half_symbol (), 0);
  QVERIFY (scheduler.claim_next (1, busy));
}

QTEST_GUILESS_MAIN (TestMap65HalfSymbolScheduler)

#include "test_map65_half_symbol_scheduler.moc"