skip to content
==> tests/file.c <==
1/* The app's file reading, and a whole conforming and a bad PTX through the rules. */
2#include "mesh/check.h"
3#include "mesh/ptx_float_rules.h"
4
5#include "../src/read.h"
6
7#include <stdio.h>
8#include <stdlib.h>
9#include <unistd.h>
10
11int main(void) {
12    char path[] = "/tmp/mesh-ptx-float-check-XXXXXX";
13    int fd = mkstemp(path);
14    CHECK(fd >= 0);
15    const char *bad = ".version 7.1\n.target sm_86\n\tfma.rn.f32 %r1, %r2, %r3, %r4;\n";
16    CHECK(write(fd, bad, strlen(bad)) == (ssize_t)strlen(bad));
17    close(fd);
18    size_t len = 0;
19    char *t = mesh_ptx_read_file(path, &len);
20    CHECK(t && len == strlen(bad));
21    char *report = NULL;
22    size_t rl = 0;
23    FILE *m = open_memstream(&report, &rl);
24    CHECK_I(mesh_ptx_float_check(path, t, len, m), 1);
25    fclose(m);
26    char want[256];
27    snprintf(want, sizeof want, "%s:3: fused multiply-add: \tfma.rn.f32 %%r1, %%r2, %%r3, %%r4;\n", path);
28    CHECK_S(report, want);
29    free(report);
30    free(t);
31    unlink(path);
32    CHECK(mesh_ptx_read_file("/nonexistent/x.ptx", &len) == NULL);
33    return mesh_check_done();
34}