Nugget
Loading...
Searching...
No Matches
qsort.c
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2020 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
28
29// clang-format off
30
32 static int icmp(const void * a, const void * b) {
33 return *(const int *) a - *(const int *) b;
34 }
35)
36
37CESTER_TEST(qsortWithNumbers, test_instance,
38 static const int sorted[] = {
39 127,
40 257,
41 509,
42 1021,
43 2053,
44 4099,
45 8191,
46 16381,
47 32771,
48 65537,
49 131071,
50 262147,
51 524287,
52 1048573,
53 2097143,
54 4194301,
55 };
56 int input[] = {
57 2097143,
58 8191,
59 509,
60 1021,
61 257,
62 65537,
63 4099,
64 1048573,
65 524287,
66 127,
67 131071,
68 4194301,
69 16381,
70 32771,
71 2053,
72 262147,
73 };
74
75 static const int size = sizeof(input) / sizeof(input[0]);
76
77 syscall_qsort(input, size, sizeof(input[0]), icmp);
78
79 for (int i = 0; i < size; i++) {
80 cester_assert_int_eq(sorted[i], input[i]);
81 }
82)
83
85 static int scmp(const void * a, const void * b) {
86 return syscall_strcmp(*(const char **) a, *(const char **) b);
87 }
88)
89
90CESTER_TEST(qsortWithStrings, test_instance,
91 static const char * const sorted[] = {
92 "arch",
93 "authority",
94 "calculating",
95 "duck",
96 "dysfunctional",
97 "embarrassed",
98 "fish",
99 "flow",
100 "hanging",
101 "help",
102 "helpful",
103 "linen",
104 "materialistic",
105 "outstanding",
106 "parched",
107 "purple",
108 "remain",
109 "robin",
110 "skilly",
111 "spiteful",
112 "stove",
113 "undesirable",
114 "wry",
115 };
116 const char * input[] = {
117 "stove",
118 "calculating",
119 "duck",
120 "undesirable",
121 "skilly",
122 "robin",
123 "linen",
124 "help",
125 "materialistic",
126 "parched",
127 "hanging",
128 "outstanding",
129 "spiteful",
130 "remain",
131 "authority",
132 "helpful",
133 "wry",
134 "purple",
135 "fish",
136 "embarrassed",
137 "arch",
138 "flow",
139 "dysfunctional",
140 };
141
142 static const int size = sizeof(input) / sizeof(input[0]);
143
144 syscall_qsort(input, size, sizeof(input[0]), scmp);
145
146 for (int i = 0; i < size; i++) {
147 cester_assert_str_equal(sorted[i], input[i]);
148 }
149)
CESTER_TEST(cpu_cop0_basic_write_bp, cpu_tests, uint32_t expectedEPC;uint32_t t;volatile uint32_t *ptr=(volatile uint32_t *) 0x58; *ptr=1;__asm__ volatile("" " lui %0, 0b1100101010000000\n" " mtc0 %0, $7\n" " li %0, 0x58\n" " mtc0 %0, $5\n" " li %0, 0xfffffff0\n" " mtc0 %0, $9\n" :"=r"(t));cester_assert_uint_eq(1, *ptr);__asm__ volatile("la %0, 1f\n1:\nsw $0, 0x58($0)" :"=r"(expectedEPC));__asm__ volatile("mtc0 $0, $7\n");cester_assert_uint_eq(0, *ptr);cester_assert_uint_eq(1, s_got40);cester_assert_uint_eq(0, s_got80);cester_assert_uint_eq(0x40, s_from);cester_assert_uint_eq(expectedEPC, s_epc);) CESTER_TEST(cpu_cop0_kseg_write_bp
cester_assert_int_eq(0, hi)
test_instance
Definition longjmp.c:37
CESTER_BODY(static int icmp(const void *a, const void *b) { return *(const int *) a - *(const int *) b;})
Definition qsort.c:31
syscall_qsort(input, size, sizeof(input[0]), icmp)
int input[]
Definition qsort.c:56
cester_assert_str_equal("ssssssss", b)
char b[9]
Definition string.c:47
static int size
Definition string.h:32