Loading...
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | #include <unistd.h> #include <stdio.h> #include <signal.h> #include <darwintest.h> #include <darwintest_utils.h> /* * We're going to inject ECC errors into shared library text, so don't * run with other tests. */ T_GLOBAL_META(T_META_RUN_CONCURRENTLY(false), T_META_OWNER("josephb_22"), T_META_NAMESPACE("xnu.vm"), T_META_RADAR_COMPONENT_NAME("xnu"), T_META_RADAR_COMPONENT_VERSION("VM")); /* * No system(3c) on watchOS, so provide our own. * returns -1 if fails to run * returns 0 if process exits normally. * returns +n if process exits due to signal N */ static int my_system(const char *command, const char *arg) { pid_t pid; int status = 0; int signal = 0; int ret; const char *argv[] = { command, /* "-v", uncomment if debugging the tests */ arg, NULL }; if (dt_launch_tool(&pid, (char **)(void *)argv, FALSE, NULL, NULL)) { return -1; } ret = dt_waitpid(pid, &status, &signal, 100); if (signal != 0) { return signal; } else if (status != 0) { return status; } return 0; } /* * The tests are run in the following order: * * - call foo (i.e. private text page) * - Inject ECC error into foo, then call foo * * - call atan (i.e. shared text page) * - inject ecc error into atan, then call atan * * atan() was picked as a shared region function that isn't likely used by any normal daemons. * * - reference to clean data page * - reference to clean data page with injected error * * - reference to dirty data page * - reference to dirty data page with injected error * * - copyout to page * - copyout to a page with injected error */ static void test_body(bool corrected) { int ret; /* * test of process text page */ ret = my_system("./ecc_test_helper", "foo"); T_QUIET; T_ASSERT_EQ(ret, 0, "First call of foo"); ret = my_system("./ecc_test_helper", "Xfoo"); T_QUIET; T_ASSERT_EQ(ret, 0, "Failed to recover from ECC to clean app text page"); ret = my_system("./ecc_test_helper", "foo"); T_QUIET; T_ASSERT_EQ(ret, 0, "Fixed call of foo"); /* * test of shared library text page */ ret = my_system("./ecc_test_helper", "atan"); T_QUIET; T_ASSERT_EQ(ret, 0, "First call of atan"); ret = my_system("./ecc_test_helper", "Xatan"); T_QUIET; T_ASSERT_EQ(ret, 0, "Failed to recover from ECC to clean shared region page"); ret = my_system("./ecc_test_helper", "atan"); T_QUIET; T_ASSERT_EQ(ret, 0, "Fixed call of atan"); /* * test of clean data page */ ret = my_system("./ecc_test_helper", "clean"); T_QUIET; T_ASSERT_EQ(ret, 0, "First call of clean"); ret = my_system("./ecc_test_helper", "Xclean"); T_QUIET; T_ASSERT_EQ(ret, 0, "Failed to recover from ECC to clean page"); ret = my_system("./ecc_test_helper", "clean"); T_QUIET; T_ASSERT_EQ(ret, 0, "Fixed call of clean"); /* * test of dirty data page */ ret = my_system("./ecc_test_helper", "Xdirty"); if (corrected) { T_QUIET; T_ASSERT_EQ(ret, 0, "Corrected ECC read of dirty failed"); } else { T_QUIET; T_ASSERT_NE(ret, 0, "Read of Uncorrected ECC dirty data didn't fail"); } /* * test of ecc during copyout */ ret = my_system("./ecc_test_helper", "Xcopyout"); if (corrected) { T_QUIET; T_ASSERT_EQ(ret, 0, "Corrected ECC copyout failed"); } else { T_QUIET; T_ASSERT_NE(ret, 0, "Uncorrected ECC copyout didn't fail"); /* not recoverable */ } } T_DECL(ecc_uncorrected_test, "test detection/recovery from ECC uncorrected errors", T_META_IGNORECRASHES(".*ecc_test_helper.*"), T_META_ASROOT(true), T_META_ENABLED(FALSE)) /* once other support lands, change to T_META_ENABLED(TARGET_CPU_ARM64 && TARGET_OS_OSX) */ { int err; uint value = 0; size_t s = sizeof value; /* * Only run on systems which support retired pages. */ err = sysctlbyname("vm.retired_pages_count", &value, &s, NULL, 0); if (err) { T_SKIP("ECC not supported"); } /* * Set testing mode to acc */ value = 0; err = sysctlbyname("vm.test_ecc_dcs", NULL, NULL, &value, s); if (err) { T_SKIP("Failed to clear dcs mode"); } /* * Set testing mode to uncorrected. */ value = 0; err = sysctlbyname("vm.test_corrected_ecc", NULL, NULL, &value, s); if (err) { T_SKIP("Failed to set uncorrected mode"); } test_body(false); } T_DECL(ecc_corrected_test, "test detection/recovery from ECC corrected errors", T_META_IGNORECRASHES(".*ecc_test_helper.*"), T_META_ASROOT(true), T_META_ENABLED(FALSE)) /* once other support lands, change to T_META_ENABLED(TARGET_CPU_ARM64 && TARGET_OS_OSX) */ { int err; uint value = 0; size_t s = sizeof value; /* * Only run on systems which support retired pages. */ err = sysctlbyname("vm.retired_pages_count", &value, &s, NULL, 0); if (err) { T_SKIP("ECC not supported"); } /* * Set testing mode to acc */ value = 0; err = sysctlbyname("vm.test_ecc_dcs", NULL, NULL, &value, s); if (err) { T_SKIP("Failed to clear dcs mode"); } /* * Set testing mode to corrected. */ value = 1; err = sysctlbyname("vm.test_corrected_ecc", NULL, NULL, &value, s); if (err) { T_SKIP("Failed to set corrected mode"); } test_body(true); } T_DECL(dcs_uncorrected_test, "test detection/recovery from ECC uncorrected errors via dcs", T_META_IGNORECRASHES(".*ecc_test_helper.*"), T_META_ASROOT(true), T_META_ENABLED(FALSE)) /* once other support lands, change to T_META_ENABLED(TARGET_CPU_ARM64 && TARGET_OS_OSX) */ { int err; uint value = 0; size_t s = sizeof value; /* * Only run on systems which support retired pages. */ err = sysctlbyname("vm.retired_pages_count", &value, &s, NULL, 0); if (err) { T_SKIP("ECC not supported"); } /* * Set testing mode to dcs */ value = 1; err = sysctlbyname("vm.test_ecc_dcs", NULL, NULL, &value, s); if (err) { T_SKIP("Failed to set dcs mode"); } /* * Set testing mode to uncorrected. */ value = 0; err = sysctlbyname("vm.test_corrected_ecc", NULL, NULL, &value, s); if (err) { T_SKIP("Failed to set uncorrected mode"); } test_body(false); } T_DECL(dcs_corrected_test, "test detection/recovery from ECC corrected errors via dcs", T_META_IGNORECRASHES(".*ecc_test_helper.*"), T_META_ASROOT(true), T_META_ENABLED(FALSE)) /* once other support lands, change to T_META_ENABLED(TARGET_CPU_ARM64 && TARGET_OS_OSX) */ { int err; uint value = 0; size_t s = sizeof value; /* * Only run on systems which support retired pages. */ err = sysctlbyname("vm.retired_pages_count", &value, &s, NULL, 0); if (err) { T_SKIP("ECC not supported"); } /* * Set testing mode to dcs */ value = 1; err = sysctlbyname("vm.test_ecc_dcs", NULL, NULL, &value, s); if (err) { T_SKIP("Failed to set dcs mode"); } /* * Set testing mode to corrected. */ value = 1; err = sysctlbyname("vm.test_corrected_ecc", NULL, NULL, &value, s); if (err) { T_SKIP("Failed to set corrected mode"); } test_body(true); } |