summaryrefslogtreecommitdiffhomepage
path: root/test/kernel_test/scheduler.test.cc
blob: 58cf6017148e1d9aea710dd735f659309f30d729 (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
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
/// \file scheduler.test.cc
/// \brief Scheduler and debugging API tests.
/// \author Amlal El Mahrouss (amlal at nekernel dot org)

#include <libSystem/SystemKit/System.h>
#include <public/frameworks/KernelTest.fwrk/headers/TestCase.h>

/// \note SchedGetCurrentProcessID tests
KT_DECL_TEST(SchedGetCurrentPIDValid, []() -> bool {
  UIntPtr pid = SchedGetCurrentProcessID();
  return pid > 0;
});

/// \note SchedSetAffinity/SchedGetAffinity tests
KT_DECL_TEST(SchedSetAffinityValid, []() -> bool {
  UIntPtr     pid = SchedGetCurrentProcessID();
  AffinityRef affinity;

  SInt32 result = SchedSetAffinity(pid, 1, &affinity);
  return result >= 0;
});

KT_DECL_TEST(SchedGetAffinityValid, []() -> bool {
  UIntPtr     pid = SchedGetCurrentProcessID();
  AffinityRef affinity;

  SInt32 result = SchedGetAffinity(pid, &affinity);
  return result >= 0;
});

KT_DECL_TEST(SchedSetAffinityInvalid, []() -> bool {
  AffinityRef affinity;
  SInt32      result = SchedSetAffinity(0, 1, &affinity);
  return result < 0;
});

KT_DECL_TEST(SchedGetAffinityInvalid, []() -> bool {
  AffinityRef affinity;
  SInt32      result = SchedGetAffinity(0, &affinity);
  return result < 0;
});

KT_DECL_TEST(SchedAffinityRoundTrip, []() -> bool {
  UIntPtr     pid = SchedGetCurrentProcessID();
  AffinityRef affinity_set;
  AffinityRef affinity_get;

  SchedSetAffinity(pid, 2, &affinity_set);
  SInt32 result = SchedGetAffinity(pid, &affinity_get);

  return result >= 0;
});

/// \note SchedFireSignal tests
KT_DECL_TEST(SchedFireSignalValid, []() -> bool {
  UIntPtr pid    = SchedGetCurrentProcessID();
  SInt32  result = SchedFireSignal(pid, 1);
  return result >= 0;
});

KT_DECL_TEST(SchedFireSignalInvalid, []() -> bool {
  SInt32 result = SchedFireSignal(0, 1);
  return result < 0;
});

/// \note SchedReadMemory/SchedWriteMemory tests
KT_DECL_TEST(SchedReadMemoryValid, []() -> bool {
  UIntPtr pid    = SchedGetCurrentProcessID();
  SInt32  result = SchedReadMemory(pid, 0x1000, 64);
  return result >= 0;
});

KT_DECL_TEST(SchedWriteMemoryValid, []() -> bool {
  UIntPtr pid    = SchedGetCurrentProcessID();
  SInt32  result = SchedWriteMemory(pid, 0x1000, 0x42);
  return result >= 0;
});

KT_DECL_TEST(SchedReadMemoryInvalid, []() -> bool {
  SInt32 result = SchedReadMemory(0, 0x1000, 64);
  return result < 0;
});

KT_DECL_TEST(SchedWriteMemoryInvalid, []() -> bool {
  SInt32 result = SchedWriteMemory(0, 0x1000, 0x42);
  return result < 0;
});

/// \brief Run scheduler tests.
SInt32 KT_TEST_MAIN() {
  KT_RUN_TEST(SchedGetCurrentPIDValid);

  KT_RUN_TEST(SchedSetAffinityValid);
  KT_RUN_TEST(SchedGetAffinityValid);
  KT_RUN_TEST(SchedSetAffinityInvalid);
  KT_RUN_TEST(SchedGetAffinityInvalid);
  KT_RUN_TEST(SchedAffinityRoundTrip);

  KT_RUN_TEST(SchedFireSignalValid);
  KT_RUN_TEST(SchedFireSignalInvalid);

  KT_RUN_TEST(SchedReadMemoryValid);
  KT_RUN_TEST(SchedWriteMemoryValid);
  KT_RUN_TEST(SchedReadMemoryInvalid);
  KT_RUN_TEST(SchedWriteMemoryInvalid);

  return KT_TEST_SUCCESS;
}