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 / platform_linux_rest.c

68 lines · 3048 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2#ifndef _GNU_SOURCE
3#define _GNU_SOURCE
4#endif
5#include <stdint.h>
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9#include <unistd.h>
10#include <sys/mman.h>
11#include "omega_gpu_platform_linux_rest_oracle.h"
12#ifndef PLAT_REST_IMPL
13#define PLAT_REST_IMPL "cudapp_om_plat_rest.c"
14#endif
15#include PLAT_REST_IMPL
16static int one(uint64_t mode, const uint64_t m[16], int red) {
17 uint64_t q[16]={0}, expected[16]={0}, result;
18 uint64_t reference=plat_rest_c(mode,m,expected);
19 if(omega_plat_rest(&result,mode,m,16,q,16) || result!=reference+(unsigned)red ||
20 memcmp(q,expected,sizeof q)) {
21 fprintf(stderr,"FAIL platform rest mode=%llu m0=%llu m1=%llu\n",
22 (unsigned long long)mode,(unsigned long long)m[0],(unsigned long long)m[1]);
23 return 1;
24 }
25 return 0;
26}
27int main(int argc,char **argv) {
28 (void)argv;
29 const uint64_t values[]={0,1,2,3,4,5,6,7,8,9,10,11,12,46,47,48,57,58,59,63,64,65,
30 99,100,101,102,103,108,109,110,
31 999,1000,1001,4095,4096,4097,65535,65536,65537,268435455,268435456,268435457,
32 UINT32_MAX-1,UINT32_MAX,(uint64_t)UINT32_MAX+1,
33 (UINT64_C(1)<<40)-4097,(UINT64_C(1)<<40)-4096,(UINT64_C(1)<<40)-4095,
34 (UINT64_C(1)<<40)-1,UINT64_C(1)<<40,(UINT64_C(1)<<40)+1,UINT64_MAX-1,UINT64_MAX};
35 uint64_t seeds[14][16]={{4096,268435456},{6,'m','e','m','f','d',':'},
36 {1,1,1,1,2,256},{1,1},{1000},{0,8},{4,1,0,0},{0,0},{1},{1000000},
37 {64,5},{UINT32_MAX},{1,1,3,MAP_SHARED,MAP_SHARED,MAP_ANONYMOUS},{0}};
38 for(unsigned mode=0;mode<14;++mode) for(unsigned field=0;field<16;++field)
39 for(unsigned i=0;i<sizeof values/sizeof values[0];++i) {
40 uint64_t m[16]; memcpy(m,seeds[mode],sizeof m); m[field]=values[i];
41 if(one(mode,m,argc>1)) return 1;
42 }
43 uint64_t m[16]={0};
44 if(one(UINT64_MAX,m,0)) return 1;
45 uint64_t full[16]={4,1,1,1};
46 if(one(6,full,0)) return 1; /* All extra slots occupied: loop exhausts its full extent. */
47 uint64_t result,q[16];
48 if(omega_plat_rest(&result,0,m,15,q,16)!=32) return 1;
49 if(omega_plat_rest(&result,0,m,16,q,15)!=32) return 1;
50 int fd=memfd_create("platform-rest",MFD_CLOEXEC);
51 if(fd<0) { perror("memfd_create"); return 1; }
52 char path[64], link[64]={0};
53 snprintf(path,sizeof path,"/proc/self/fd/%d",fd);
54 ssize_t n=readlink(path,link,sizeof link-1);
55 close(fd);
56 if(n<7) { perror("readlink"); return 1; }
57 m[0]=(uint64_t)n;
58 for(unsigned i=0;i<7;++i) m[i+1]=(unsigned char)link[i];
59 if(omega_plat_rest(&result,1,m,16,q,16) || result!=1) {
60 fputs("FAIL platform rest live memfd marker\n",stderr); return 1;
61 }
62 if(n>=6 && !memcmp(link,"memfd:",6)) {
63 fputs("FAIL platform rest old marker negative control\n",stderr); return 1;
64 }
65 puts("PASS platform rest live memfd: original marker parser rejected real /memfd: link");
66 puts("PASS platform rest source-partition differential and ABI refusals");
67 return 0;
68}