interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / tests / dagsim / parse_diff.c

39 lines · 1750 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2#include "dagsim.h"
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6int oracle_ds_parse_text(const char *, ds_model *, char *, size_t);
7int main(int argc, char **argv) {
8 static ds_model a, b;
9 int failures = 0;
10 for (int i = 1; i < argc; i++) {
11 FILE *f = fopen(argv[i], "rb"); if (!f) return 2;
12 if (fseek(f, 0, SEEK_END)) return 2;
13 long n = ftell(f); if (n < 0) return 2;
14 rewind(f); char *s = malloc((size_t)n + 1); if (!s) return 2;
15 if (fread(s, 1, (size_t)n, f) != (size_t)n) return 2;
16 fclose(f); s[n] = 0;
17 char ea[256] = {0}, eb[256] = {0};
18 int ra = ds_parse_text(s, &a, ea, sizeof ea);
19 int rb = oracle_ds_parse_text(s, &b, eb, sizeof eb);
20 if (n >= 1048576) {
21 if (ra != DS_PARSE_ERROR || strcmp(ea, "file size out of range")) failures++;
22 free(s); continue; /* documented bounded-view refusal, not C grammar */
23 }
24 if (getenv("DS_PARSE_RED") && !rb) b.version ^= 1;
25 if (ra != rb || strcmp(ea, eb) || (!ra && memcmp(&a, &b, sizeof a))) {
26 fprintf(stderr, "%s: production %d '%s'; oracle %d '%s'\n", argv[i], ra, ea, rb, eb);
27 if (!ra && !rb) {
28 const unsigned char *pa = (const unsigned char *)&a, *pb = (const unsigned char *)&b;
29 for (size_t k = 0; k < sizeof a; k++) if (pa[k] != pb[k]) {
30 fprintf(stderr, "first model byte %zu: %u != %u\n", k, pa[k], pb[k]); break;
31 }
32 }
33 failures++;
34 }
35 free(s);
36 }
37 printf("parse differential: %d cases, %d failures\n", argc - 1, failures);
38 return failures ? 1 : 0;
39}