Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/tests/runtime/artifact_text_unit.c # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / runtime / artifact_text_unit.c` 79 lines · 3203 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 #include "cudapp_native.h" 3 #include 4 #include 5 #include 6 7 static int decimal(const char *s, uint32_t *out) { 8 uint32_t x = 0; int d = 0; 9 while (*s >= '0' && *s <= '9') { 10 if (++d > 9) return 0; 11 x = x * 10u + (uint32_t)(*s++ - '0'); 12 } 13 if (!d || *s) return 0; 14 *out = x; return 1; 15 } 16 static int oracle(unsigned mode, const char *s, uint32_t *out, unsigned n) { 17 if (mode == 0) { 18 for (; *s; ++s) if ((unsigned char)*s < 32 || (unsigned char)*s == 127) return 0; 19 return 1; 20 } 21 if (mode == 1) { 22 if (strlen(s) != 64) return 0; 23 for (; *s; ++s) if (!((*s >= '0' && *s <= '9') || (*s >= 'a' && *s <= 'f'))) return 0; 24 return 1; 25 } 26 char copy[128]; size_t len = strlen(s); 27 if (mode == 2 && len >= 64) return 0; 28 if (len >= sizeof copy) return 0; 29 memcpy(copy, s, len + 1); 30 char *p = copy; 31 for (unsigned i = 0; i < n; ++i) { 32 char *q = strchr(p, mode == 3 ? '.' : ','); 33 if (i + 1 < n) { if (!q) return 0; *q = 0; } 34 else if (q) return 0; 35 if (!decimal(p, out + i)) return 0; 36 if (q) p = q + 1; 37 } 38 return 1; 39 } 40 static int omega(unsigned mode, const char *s, uint32_t *out, unsigned n) { 41 uint64_t state[8] = {0}, status; state[3] = n; 42 for (const unsigned char *p = (const unsigned char *)s;; ++p) { 43 if (omega_artifact_parse(&status, mode, *p, state, 8) || status == 2) return 0; 44 if (mode >= 2 && (status == 1 || status == 3)) out[state[2] - (status == 3)] = (uint32_t)state[4]; 45 if (status == 1) return 1; 46 } 47 } 48 static void check(unsigned mode, const char *s, unsigned n, int *bad) { 49 uint32_t a[8] = {0}, b[8] = {0}; 50 int ca = oracle(mode, s, a, n), cb = omega(mode, s, b, n); 51 if (ca != cb || (ca && memcmp(a, b, n * sizeof *a))) { 52 fprintf(stderr, "ARTIFACT TEXT differential FAIL mode=%u n=%u len=%zu\n", mode, n, strlen(s)); ++*bad; 53 } 54 } 55 int main(void) { 56 int bad = 0; 57 const char *edges[] = {"", "0", "1", "`999999999`", "`1000000000`", "`000000000`", "`0000000000`", "-1", "+1", " 1", "1 ", "1,2,3", "1.2.3", "0.0.0", "`999999999`.`999999999`.`999999999`", "1.2.3.", "1.2", "1..3", "1,2,", "1,,3", "1,2,3,4", "\n", "\r", "\177"}; 58 for (unsigned mode = 0; mode < 4; ++mode) 59 for (unsigned n = 1; n <= 8; ++n) 60 for (unsigned i = 0; i < sizeof edges / sizeof *edges; ++i) check(mode, edges[i], n, &bad); 61 char s[96]; 62 for (unsigned c = 1; c <= 255; ++c) { 63 memset(s, 'a', 64); s[64] = 0; s[31] = (char)c; 64 check(0, s, 1, &bad); check(1, s, 1, &bad); 65 } 66 uint64_t rng = UINT64_C(0xb709e28515); 67 for (unsigned i = 0; i < 100000; ++i) { 68 rng = rng * UINT64_C(`6364136223846793005`) + 1; 69 unsigned len = (unsigned)(rng >> 32) % 90; 70 for (unsigned j = 0; j < len; ++j) { 71 rng = rng * UINT64_C(`6364136223846793005`) + 1; 72 s[j] = (char)(rng >> 32); 73 } 74 s[len] = 0; 75 for (unsigned mode = 0; mode < 4; ++mode) check(mode, s, 1 + i % 8, &bad); 76 } 77 if (bad) return 1; 78 puts("ARTIFACT TEXT differential PASS"); return 0; 79 }