Skip to content

Commit c9b5a33

Browse files
author
Stephen Miller
committed
Create macro for unsigned integer comparisons
Cpputest doesn't have one for this case, but it makes reading error codes a lot easier. I've swapped most error checks to use this new macro.
1 parent ac3d4b1 commit c9b5a33

File tree

14 files changed

+913
-850
lines changed

14 files changed

+913
-850
lines changed

tests/memory_test_100/code/test.cpp

Lines changed: 651 additions & 651 deletions
Large diffs are not rendered by default.

tests/memory_test_100/code/test.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
#include "CppUTest/TestHarness.h"
2+
3+
#define UNSIGNED_INT_EQUALS(expected, actual) _unsigned_int_equals(expected, actual);
4+
5+
void _unsigned_int_equals(uint32_t expected, uint32_t actual) {
6+
UNSIGNED_LONGS_EQUAL(expected, actual);
7+
}
8+
9+
// Function definitions (with modified types to improve testability)
110
extern "C" {
211
// Direct memory functions
312
uint64_t sceKernelGetDirectMemorySize();

tests/memory_test_170/code/test.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,39 @@ TEST(MemoryTests, FW170Test) {
2424
// Null address with MAP_FIXED is now prohibited from the libkernel side.
2525
uint64_t addr = 0;
2626
result = sceKernelMapDirectMemory(&addr, 0x4000, 3, 0x10, phys_addr, 0);
27-
LONGS_EQUAL(ORBIS_KERNEL_ERROR_EINVAL, result);
27+
UNSIGNED_INT_EQUALS(ORBIS_KERNEL_ERROR_EINVAL, result);
2828

2929
result = sceKernelMapNamedDirectMemory(&addr, 0x4000, 3, 0x10, phys_addr, 0, "name");
30-
LONGS_EQUAL(ORBIS_KERNEL_ERROR_EINVAL, result);
30+
UNSIGNED_INT_EQUALS(ORBIS_KERNEL_ERROR_EINVAL, result);
3131

3232
result = sceKernelMapFlexibleMemory(&addr, 0x4000, 3, 0x10);
33-
LONGS_EQUAL(ORBIS_KERNEL_ERROR_EINVAL, result);
33+
UNSIGNED_INT_EQUALS(ORBIS_KERNEL_ERROR_EINVAL, result);
3434

3535
result = sceKernelMapNamedFlexibleMemory(&addr, 0x4000, 3, 0x10, "name");
36-
LONGS_EQUAL(ORBIS_KERNEL_ERROR_EINVAL, result);
36+
UNSIGNED_INT_EQUALS(ORBIS_KERNEL_ERROR_EINVAL, result);
3737

3838
result = sceKernelReserveVirtualRange(&addr, 0x4000, 0x10, 0);
39-
LONGS_EQUAL(ORBIS_KERNEL_ERROR_EINVAL, result);
39+
UNSIGNED_INT_EQUALS(ORBIS_KERNEL_ERROR_EINVAL, result);
4040

4141
result = sceKernelMapNamedSystemFlexibleMemory(&addr, 0x4000, 3, 0x10, "name");
42-
LONGS_EQUAL(ORBIS_KERNEL_ERROR_EINVAL, result);
42+
UNSIGNED_INT_EQUALS(ORBIS_KERNEL_ERROR_EINVAL, result);
4343

4444
// Note: Pool 1 should match sceKernelMapDirectMemory behavior.
4545
result = sceKernelInternalMapDirectMemory(1, &addr, 0x4000, 3, 0x10, phys_addr, 0);
46-
LONGS_EQUAL(ORBIS_KERNEL_ERROR_EINVAL, result);
46+
UNSIGNED_INT_EQUALS(ORBIS_KERNEL_ERROR_EINVAL, result);
4747

4848
result = sceKernelInternalMapNamedDirectMemory(1, &addr, 0x4000, 3, 0x10, phys_addr, 0, "name");
49-
LONGS_EQUAL(ORBIS_KERNEL_ERROR_EINVAL, result);
49+
UNSIGNED_INT_EQUALS(ORBIS_KERNEL_ERROR_EINVAL, result);
5050

5151
// mmap and sceKernelMemoryPoolReserve both still reach the mmap syscall, but error there like fw 1.00 does.
5252
result = sceKernelMmap(addr, 0x4000, 3, 0x1010, -1, 0, &addr);
53-
LONGS_EQUAL(ORBIS_KERNEL_ERROR_EINVAL, result);
53+
UNSIGNED_INT_EQUALS(ORBIS_KERNEL_ERROR_EINVAL, result);
5454

5555
result = sceKernelMemoryPoolReserve(addr, 0x4000, 0, 0x10, &addr);
56-
LONGS_EQUAL(ORBIS_KERNEL_ERROR_EINVAL, result);
56+
UNSIGNED_INT_EQUALS(ORBIS_KERNEL_ERROR_EINVAL, result);
5757

5858
result = sceKernelReleaseDirectMemory(phys_addr, 0x4000);
59-
LONGS_EQUAL(0, result);
59+
UNSIGNED_INT_EQUALS(0, result);
6060
}
6161

6262
// Test behavior that changed in firmware 2.00, these differences should not be present here.
@@ -120,77 +120,77 @@ TEST(MemoryTests, FW200Test) {
120120
uint64_t base_addr = 0x2000000000;
121121
uint64_t addr = base_addr;
122122
int32_t result = map_func(&addr, 0x20000, -1, 0x100000, 0x10);
123-
LONGS_EQUAL(0, result);
123+
UNSIGNED_INT_EQUALS(0, result);
124124

125125
addr = base_addr + 0x80000;
126126
result = map_func(&addr, 0x20000, -1, 0x180000, 0x10);
127-
LONGS_EQUAL(0, result);
127+
UNSIGNED_INT_EQUALS(0, result);
128128

129129
addr = base_addr + 0x20000;
130130
result = map_func(&addr, 0x20000, -1, 0x120000, 0x10);
131-
LONGS_EQUAL(0, result);
131+
UNSIGNED_INT_EQUALS(0, result);
132132

133133
addr = base_addr + 0x60000;
134134
result = map_func(&addr, 0x20000, -1, 0x160000, 0x10);
135-
LONGS_EQUAL(0, result);
135+
UNSIGNED_INT_EQUALS(0, result);
136136

137137
mem_scan();
138138

139139
// On firmware 2.00, there will be 2 mappings. Here, there should be 4.
140140
uint64_t start_addr;
141141
uint64_t end_addr;
142142
result = sceKernelQueryMemoryProtection(base_addr, &start_addr, &end_addr, nullptr);
143-
LONGS_EQUAL(0, result);
143+
UNSIGNED_INT_EQUALS(0, result);
144144
LONGS_EQUAL(base_addr, start_addr);
145145
LONGS_EQUAL(base_addr + 0x20000, end_addr);
146146

147147
result = sceKernelQueryMemoryProtection(base_addr + 0x20000, &start_addr, &end_addr, nullptr);
148-
LONGS_EQUAL(0, result);
148+
UNSIGNED_INT_EQUALS(0, result);
149149
LONGS_EQUAL(base_addr + 0x20000, start_addr);
150150
LONGS_EQUAL(base_addr + 0x40000, end_addr);
151151

152152
result = sceKernelQueryMemoryProtection(base_addr + 0x60000, &start_addr, &end_addr, nullptr);
153-
LONGS_EQUAL(0, result);
153+
UNSIGNED_INT_EQUALS(0, result);
154154
LONGS_EQUAL(base_addr + 0x60000, start_addr);
155155
LONGS_EQUAL(base_addr + 0x80000, end_addr);
156156

157157
result = sceKernelQueryMemoryProtection(base_addr + 0x80000, &start_addr, &end_addr, nullptr);
158-
LONGS_EQUAL(0, result);
158+
UNSIGNED_INT_EQUALS(0, result);
159159
LONGS_EQUAL(base_addr + 0x80000, start_addr);
160160
LONGS_EQUAL(base_addr + 0xa0000, end_addr);
161161

162162
// Test making a mapping in between these other mappings.
163163
addr = base_addr + 0x40000;
164164
result = map_func(&addr, 0x20000, -1, 0x140000, 0x10);
165-
LONGS_EQUAL(0, result);
165+
UNSIGNED_INT_EQUALS(0, result);
166166

167167
// There should now be 5 mappings.
168168
result = sceKernelQueryMemoryProtection(base_addr, &start_addr, &end_addr, nullptr);
169-
LONGS_EQUAL(0, result);
169+
UNSIGNED_INT_EQUALS(0, result);
170170
LONGS_EQUAL(base_addr, start_addr);
171171
LONGS_EQUAL(base_addr + 0x20000, end_addr);
172172

173173
result = sceKernelQueryMemoryProtection(base_addr + 0x20000, &start_addr, &end_addr, nullptr);
174-
LONGS_EQUAL(0, result);
174+
UNSIGNED_INT_EQUALS(0, result);
175175
LONGS_EQUAL(base_addr + 0x20000, start_addr);
176176
LONGS_EQUAL(base_addr + 0x40000, end_addr);
177177

178178
result = sceKernelQueryMemoryProtection(base_addr + 0x40000, &start_addr, &end_addr, nullptr);
179-
LONGS_EQUAL(0, result);
179+
UNSIGNED_INT_EQUALS(0, result);
180180
LONGS_EQUAL(base_addr + 0x40000, start_addr);
181181
LONGS_EQUAL(base_addr + 0x60000, end_addr);
182182

183183
result = sceKernelQueryMemoryProtection(base_addr + 0x60000, &start_addr, &end_addr, nullptr);
184-
LONGS_EQUAL(0, result);
184+
UNSIGNED_INT_EQUALS(0, result);
185185
LONGS_EQUAL(base_addr + 0x60000, start_addr);
186186
LONGS_EQUAL(base_addr + 0x80000, end_addr);
187187

188188
result = sceKernelQueryMemoryProtection(base_addr + 0x80000, &start_addr, &end_addr, nullptr);
189-
LONGS_EQUAL(0, result);
189+
UNSIGNED_INT_EQUALS(0, result);
190190
LONGS_EQUAL(base_addr + 0x80000, start_addr);
191191
LONGS_EQUAL(base_addr + 0xa0000, end_addr);
192192

193193
// Unmap testing memory.
194194
result = unmap_func(base_addr, 0xa0000);
195-
LONGS_EQUAL(0, result);
195+
UNSIGNED_INT_EQUALS(0, result);
196196
}

tests/memory_test_170/code/test.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
#include "CppUTest/TestHarness.h"
2+
3+
#define UNSIGNED_INT_EQUALS(expected, actual) _unsigned_int_equals(expected, actual);
4+
5+
void _unsigned_int_equals(uint32_t expected, uint32_t actual) {
6+
UNSIGNED_LONGS_EQUAL(expected, actual);
7+
}
8+
9+
// Function definitions (with modified types to improve testability)
110
extern "C" {
211
// Direct memory functions
312
uint64_t sceKernelGetDirectMemorySize();

tests/memory_test_200/code/test.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,81 +77,81 @@ TEST(MemoryTests, FW200Test) {
7777
uint64_t base_addr = 0x2000000000;
7878
uint64_t addr = base_addr;
7979
int32_t result = map_func(&addr, 0x20000, -1, 0x100000, 0x10);
80-
LONGS_EQUAL(0, result);
80+
UNSIGNED_INT_EQUALS(0, result);
8181

8282
addr = base_addr + 0x80000;
8383
result = map_func(&addr, 0x20000, -1, 0x180000, 0x10);
84-
LONGS_EQUAL(0, result);
84+
UNSIGNED_INT_EQUALS(0, result);
8585

8686
addr = base_addr + 0x20000;
8787
result = map_func(&addr, 0x20000, -1, 0x120000, 0x10);
88-
LONGS_EQUAL(0, result);
88+
UNSIGNED_INT_EQUALS(0, result);
8989

9090
addr = base_addr + 0x60000;
9191
result = map_func(&addr, 0x20000, -1, 0x160000, 0x10);
92-
LONGS_EQUAL(0, result);
92+
UNSIGNED_INT_EQUALS(0, result);
9393

9494
mem_scan();
9595

9696
// There should be two observable mappings.
9797
uint64_t start_addr;
9898
uint64_t end_addr;
9999
result = sceKernelQueryMemoryProtection(base_addr, &start_addr, &end_addr, nullptr);
100-
LONGS_EQUAL(0, result);
100+
UNSIGNED_INT_EQUALS(0, result);
101101
LONGS_EQUAL(base_addr, start_addr);
102102
LONGS_EQUAL(base_addr + 0x40000, end_addr);
103103

104104
result = sceKernelQueryMemoryProtection(base_addr + 0x60000, &start_addr, &end_addr, nullptr);
105-
LONGS_EQUAL(0, result);
105+
UNSIGNED_INT_EQUALS(0, result);
106106
LONGS_EQUAL(base_addr + 0x60000, start_addr);
107107
LONGS_EQUAL(base_addr + 0xa0000, end_addr);
108108

109109
// Test making a mapping in between these other mappings.
110110
addr = base_addr + 0x40000;
111111
result = map_func(&addr, 0x20000, -1, 0x140000, 0x10);
112-
LONGS_EQUAL(0, result);
112+
UNSIGNED_INT_EQUALS(0, result);
113113

114114
// Mappings all merge together.
115115
result = sceKernelQueryMemoryProtection(base_addr, &start_addr, &end_addr, nullptr);
116-
LONGS_EQUAL(0, result);
116+
UNSIGNED_INT_EQUALS(0, result);
117117
LONGS_EQUAL(base_addr, start_addr);
118118
LONGS_EQUAL(base_addr + 0xa0000, end_addr);
119119

120120
// Unmap testing memory.
121121
result = unmap_func(base_addr, 0xa0000);
122-
LONGS_EQUAL(0, result);
122+
UNSIGNED_INT_EQUALS(0, result);
123123
}
124124

125125
// Test behavior that changed in firmware 2.50, to verify the changes aren't visible here.
126126
TEST(MemoryTests, FW250Test) {
127127
int64_t phys_addr = 0;
128128
int32_t result = sceKernelAllocateMainDirectMemory(0x10000, 0, 0, &phys_addr);
129-
LONGS_EQUAL(0, result);
129+
UNSIGNED_INT_EQUALS(0, result);
130130
uint64_t addr = 0;
131131
result = sceKernelMapDirectMemory(&addr, 0x10000, 3, 0, phys_addr, 0);
132-
LONGS_EQUAL(0, result);
132+
UNSIGNED_INT_EQUALS(0, result);
133133
// Starting with firmware 2.50, several direct memory functions that previously called sys_mmap will now use sceKernelMapDirectMemory2 instead.
134134
// This behavior will not be present here, which can be identified through overlapping dmem use.
135135

136136
// All of these mappings would fail on firmware 2.50, but succeed on anything below that.
137137
result = sceKernelMapDirectMemory(&addr, 0x10000, 3, 0, phys_addr, 0);
138-
LONGS_EQUAL(0, result);
138+
UNSIGNED_INT_EQUALS(0, result);
139139
result = sceKernelMunmap(addr, 0x10000);
140-
LONGS_EQUAL(0, result);
140+
UNSIGNED_INT_EQUALS(0, result);
141141
result = sceKernelMapNamedDirectMemory(&addr, 0x10000, 3, 0, phys_addr, 0, "name");
142-
LONGS_EQUAL(0, result);
142+
UNSIGNED_INT_EQUALS(0, result);
143143
result = sceKernelMunmap(addr, 0x10000);
144-
LONGS_EQUAL(0, result);
144+
UNSIGNED_INT_EQUALS(0, result);
145145
result = sceKernelInternalMapDirectMemory(1, &addr, 0x10000, 3, 0, phys_addr, 0);
146-
LONGS_EQUAL(0, result);
146+
UNSIGNED_INT_EQUALS(0, result);
147147
result = sceKernelMunmap(addr, 0x10000);
148-
LONGS_EQUAL(0, result);
148+
UNSIGNED_INT_EQUALS(0, result);
149149
result = sceKernelInternalMapNamedDirectMemory(1, &addr, 0x10000, 3, 0, phys_addr, 0, "name");
150-
LONGS_EQUAL(0, result);
150+
UNSIGNED_INT_EQUALS(0, result);
151151
result = sceKernelMunmap(addr, 0x10000);
152-
LONGS_EQUAL(0, result);
152+
UNSIGNED_INT_EQUALS(0, result);
153153

154154
// This will unmap all memory tied to this physical area.
155155
result = sceKernelReleaseDirectMemory(phys_addr, 0x10000);
156-
LONGS_EQUAL(0, result);
156+
UNSIGNED_INT_EQUALS(0, result);
157157
}

tests/memory_test_200/code/test.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
#include "CppUTest/TestHarness.h"
2+
3+
#define UNSIGNED_INT_EQUALS(expected, actual) _unsigned_int_equals(expected, actual);
4+
5+
void _unsigned_int_equals(uint32_t expected, uint32_t actual) {
6+
UNSIGNED_LONGS_EQUAL(expected, actual);
7+
}
8+
9+
// Function definitions (with modified types to improve testability)
110
extern "C" {
211
// Direct memory functions
312
uint64_t sceKernelGetDirectMemorySize();

0 commit comments

Comments
 (0)