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
CUDApp / tests / leftovers_test.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include <stdint.h> |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | #include <limits.h> |
| 6 | #define CUDAPP_MIGRATION_PENDING_LEFTOVERS 1 |
| 7 | #define omega_path_byte oracle_path_byte |
| 8 | #define omega_path_copy oracle_path_copy |
| 9 | #include "omega_path_check.h" |
| 10 | #undef omega_path_byte |
| 11 | #undef omega_path_copy |
| 12 | #undef CUDAPP_MIGRATION_PENDING_LEFTOVERS |
| 13 | #undef OMEGA_PATH_CHECK_H |
| 14 | #include "omega_path_check.h" |
| 15 | #ifdef LEFTOVERS_ORACLE |
| 16 | #define CUDAPP_MIGRATION_PENDING_LEFTOVERS 1 |
| 17 | #endif |
| 18 | #include "omega_numeric_lifecycle.h" |
| 19 | #include "omega_gpu_q36_native.h" |
| 20 | #ifdef LEFTOVERS_ORACLE |
| 21 | #undef CUDAPP_MIGRATION_PENDING_LEFTOVERS |
| 22 | #endif |
| 23 | atomic_int omega_numeric_native_state; |
| 24 | static unsigned checks; |
| 25 | #define CHECK(x) do { ++checks; if (!(x)) { fprintf(stderr,"FAIL line %d\n",__LINE__); return 1; } } while (0) |
| 26 | static int path(const char *s, size_t cap) { |
| 27 | char a[64], b[64]; memset(a, 85, sizeof a); memset(b, 85, sizeof b); |
| 28 | int ar = oracle_path_copy(a, cap, s), br = omega_path_copy(b, cap, s); |
| 29 | #ifdef LEFTOVERS_RED |
| 30 | br ^= 1; |
| 31 | #endif |
| 32 | CHECK(ar == br); |
| 33 | /* Refusals promise an empty string, not equality of scratch bytes. */ |
| 34 | CHECK(cap == 0 || strcmp(a, b) == 0); |
| 35 | return 0; |
| 36 | } |
| 37 | int main(void) { |
| 38 | const char *cases[] = {NULL,"","/",".","..","...","a/../b","../","a/..","a/./b","a//b/","/..","/a/b","a b","a\nb","AZaz09._-/+,=@:~","..a","a..","a/.../b"}; |
| 39 | for (size_t i=0;i<sizeof cases/sizeof *cases;++i) |
| 40 | for (size_t cap=0;cap<=32;++cap) CHECK(path(cases[i],cap)==0); |
| 41 | CHECK(omega_path_copy(NULL, 1, "a") == -1); |
| 42 | CHECK(oracle_path_copy(NULL, 1, "a") == -1); |
| 43 | for (int c=-1;c<=256;++c) CHECK(oracle_path_byte(c)==omega_path_byte(c)); |
| 44 | char s[3]={0,'x',0}; |
| 45 | for (unsigned c=1;c<=255;++c) { s[0]=(char)c; CHECK(path(s,3)==0); } |
| 46 | uint64_t r=99; |
| 47 | CHECK(omega_leftovers(NULL, 0, 0, 0, 0, 0)==OMEGA_BAD_ARG); |
| 48 | CHECK(omega_leftovers(&r,1,0,'a',UINT64_MAX,UINT64_MAX)==0 && r==4); |
| 49 | CHECK(omega_leftovers(&r,1,0,'a',UINT32_MAX,UINT32_MAX)==0 && r==4); |
| 50 | const int ord[]={INT_MIN,-1,0,1,INT_MAX}; |
| 51 | for (unsigned i=0;i<sizeof ord/sizeof *ord;++i) { |
| 52 | CHECK(omega_leftovers(&r,2,(uint64_t)(int64_t)ord[i],0,0,0)==0); |
| 53 | CHECK(r==(ord[i]<0?(uint64_t)(int64_t)ord[i]:0)); |
| 54 | CHECK(omega_q36_native_record_status(ord[i])==(ord[i]<0?ord[i]:0)); |
| 55 | } |
| 56 | for (unsigned st=0;st<4;++st) { |
| 57 | atomic_store(&omega_numeric_native_state,st); |
| 58 | CHECK(omega_numeric_native_uncertain()==(st==2)); |
| 59 | CHECK(omega_numeric_native_acquire()==(st==0?0:-1)); |
| 60 | CHECK(atomic_load(&omega_numeric_native_state)==(st==0?1:(int)st)); |
| 61 | omega_numeric_native_release(); |
| 62 | CHECK(atomic_load(&omega_numeric_native_state)==(st<=1?0:(int)st)); |
| 63 | omega_numeric_native_poison(); omega_numeric_native_release(); |
| 64 | CHECK(omega_numeric_native_uncertain()); |
| 65 | } |
| 66 | const uint64_t values[]={0,1,31,32,33,UINT32_MAX-1ULL,UINT32_MAX,UINT32_MAX+1ULL,INT64_MAX,1ULL<<63,UINT64_MAX}; |
| 67 | for (unsigned i=0;i<sizeof values/sizeof *values;++i) { |
| 68 | for (unsigned p=0;p<2;++p) { |
| 69 | CHECK(omega_leftovers(&r,5,values[i],p,0,0)==0); |
| 70 | CHECK(r==(values[i]==0?1:(values[i]>>63||!p?UINT64_MAX:0))); |
| 71 | } |
| 72 | for (unsigned j=0;j<sizeof values/sizeof *values;++j) { |
| 73 | CHECK(omega_leftovers(&r,6,values[i],values[j],0,0)==0); |
| 74 | CHECK(r==(values[j]<values[i] && values[j]<32)); |
| 75 | } |
| 76 | } |
| 77 | printf("LEFTOVERS PASS checks=%u\n",checks); |
| 78 | return 0; |
| 79 | } |